Skip to content
This repository has been archived by the owner on Nov 26, 2022. It is now read-only.

Commit

Permalink
initial scratch
Browse files Browse the repository at this point in the history
  • Loading branch information
raywan committed May 15, 2019
0 parents commit 96baad9
Show file tree
Hide file tree
Showing 13 changed files with 4,088 additions and 0 deletions.
712 changes: 712 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "include/rw"]
path = include/rw
url = git@github.com:raywan/rw.git
33 changes: 33 additions & 0 deletions build.ninja
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# THIS FILE IS GENERATED BY configure.py
# EDITS WILL BE OVERWRITTEN

ninja_required_version = 1.9
cc = g++
cflags = -std=c++11 -O3 -pthread -march=native -Iinclude
project_name = toy
src_dir = src
bin_dir = bin
build_dir = build

rule compile
command = $cc $cflags -c $in -o $out -MMD -MF $out.d
depfile = $out.d
rule link
command = $cc $in -o $bin_dir/$out
rule clean_all
command = rm -rf $build_dir $bin_dir $project_name
rule make_dirs
command = mkdir -p $build_dir $bin_dir
rule create_sym_link
command = ln -sf $bin_dir/$project_name $project_name

build dirs: make_dirs
build fresh: clean_all
build sym: create_sym_link
build build/mesh.o: compile src/mesh.cpp
build build/main.o: compile src/main.cpp
build toy: link build/mesh.o build/main.o

default dirs
default toy
default sym
91 changes: 91 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/python

import os
import fnmatch
from ninja_syntax import Writer

PROJECT_NAME = "toy"

CC = "g++"
CFLAGS = [
"-std=c++11",
"-O3",
"-pthread",
"-march=native",
"-Iinclude",
]

SRC_DIR = "src"
BUILD_DIR = "build"
BIN_DIR = "bin"

with open('build.ninja', 'w') as build_file:
n = Writer(build_file)

n.comment("THIS FILE IS GENERATED BY configure.py")
n.comment("EDITS WILL BE OVERWRITTEN")
n.newline()

#############################################################################
# VARIABLES
#############################################################################

n.variable(key="ninja_required_version", value="1.9");

n.variable(key="cc", value=CC);
n.variable(key="cflags", value=' '.join(CFLAGS))
n.variable(key="project_name", value=PROJECT_NAME)
n.variable(key="src_dir", value=SRC_DIR)
n.variable(key="bin_dir", value=BIN_DIR)
n.variable(key="build_dir", value=BUILD_DIR)

n.newline()

#############################################################################
# RULES
#############################################################################

n.rule("compile",
command="$cc $cflags -c $in -o $out -MMD -MF $out.d",
depfile="$out.d"
)

n.rule("link", command="$cc $in -o $bin_dir/$out")

n.rule("clean_all", command="rm -rf $build_dir $bin_dir $project_name")
n.rule("make_dirs", command="mkdir -p $build_dir $bin_dir")
n.rule("create_sym_link", command="ln -sf $bin_dir/$project_name $project_name")

n.newline()

#############################################################################
# BUILDS
#############################################################################

n.build(outputs="dirs", rule="make_dirs")
n.build(outputs="fresh", rule="clean_all")
n.build(outputs="sym", rule="create_sym_link")

sources = []
for root, dirnames, filenames in os.walk(SRC_DIR):
for filename in fnmatch.filter(filenames, '*.cpp'):
sources.append(os.path.join(root, filename))

for source in sources:
n.build(outputs=source.replace(".cpp", ".o").replace('src', BUILD_DIR),
rule="compile",
inputs=source
)

o_files = [x.replace(".cpp", ".o").replace('src', BUILD_DIR) for x in sources]
n.build(outputs=PROJECT_NAME, rule="link", inputs=o_files)

n.newline()

#############################################################################
# DEFAULTS
#############################################################################

n.default("dirs")
n.default(PROJECT_NAME)
n.default("sym")
1 change: 1 addition & 0 deletions include/rw
Submodule rw added at c8d151
Loading

0 comments on commit 96baad9

Please sign in to comment.