diff options
author | Nao Pross <naopross@thearcway.org> | 2019-01-22 03:49:31 +0100 |
---|---|---|
committer | Nao Pross <naopross@thearcway.org> | 2019-01-22 03:59:11 +0100 |
commit | 1868b6ded77e95155c5101eca1b21aafa45cbd44 (patch) | |
tree | 410df3c8d9efce82d48394a31a14d205b5851e41 | |
parent | Re-implement flattask.h in task.hpp (diff) | |
download | flatland-1868b6ded77e95155c5101eca1b21aafa45cbd44.tar.gz flatland-1868b6ded77e95155c5101eca1b21aafa45cbd44.zip |
Add configuration for Ninja build system
Run configure.py to generate a build.ninja file to build with ninja.
$ ./configure.py
$ ninja
Ninja can also build individual targets, for example
$ ninja bin/libflatland.so
$ ninja bin/test/test1
-rw-r--r-- | .gitignore | 4 | ||||
-rwxr-xr-x | configure.py | 45 | ||||
-rw-r--r-- | ninja/rules.ninja | 23 |
3 files changed, 72 insertions, 0 deletions
@@ -1,2 +1,6 @@ bin/** **/*.swp + +.ninja_deps +.ninja_log +build.ninja diff --git a/configure.py b/configure.py new file mode 100755 index 0000000..1cb3fd7 --- /dev/null +++ b/configure.py @@ -0,0 +1,45 @@ +#! /usr/bin/env python3 +import os +import re + +def find_sources(path): + sources = tuple(filter(lambda f: f.endswith(".cpp"), os.listdir(path))) + objects = tuple(map(lambda f: re.sub(".cpp$", ".o", f), sources)) + + # add path prefix to files + sources = tuple(map(lambda f: path + "/" + f, sources)) + objects = tuple(map(lambda f: "bin/" + path + "/" + f, objects)) + + return sources, objects + + +with open("build.ninja", "w") as bf: + + # find engine sources + sources, objects = find_sources("engine") + + # include rules + print("include ninja/rules.ninja\n", file=bf) + + # create build directories + print("build bin/engine: mkdir\n", file=bf) + print("build bin/test: mkdir\n", file=bf) + + + # build engine files + for s, o in zip(sources, objects): + print("build {}: cpp {}".format(o, s), file=bf) + + # build engine library + print("\nbuild bin/libflatland.so: link-shared " + " ".join(objects) + "\n", file=bf) + + + # find test sources + sources, objects = find_sources("test") + binaries = tuple(map(lambda f: re.sub(".o$", "", f), objects)) + + # build tests + for s, o, b in zip(sources, objects, binaries): + print("build {}: cpp {}".format(o, s), file=bf) + print("build {}: link {}".format(b, o), file=bf) + print(" lflags = $lflags ../bin/libflatland.so\n", file=bf) diff --git a/ninja/rules.ninja b/ninja/rules.ninja new file mode 100644 index 0000000..2a56923 --- /dev/null +++ b/ninja/rules.ninja @@ -0,0 +1,23 @@ +includes = -I engine/include +cflags = -Wall -pedantic -fPIC -std=c++17 $includes + +libs = +lflags = -lSDL2 $libs + +flags = -fdiagnostics-color + +rule mkdir + command = mkdir -p $out + description = creating directory $out + +rule cpp + command = g++ $flags $cflags -c $in -o $out $lflags + description = compiling $in + +rule link + command = g++ $flags $cflags -o $out $in $lflags + description = linking $out + +rule link-shared + command = g++ $flags $cflags -shared -o $out $in $lflags + description = linking $out |