summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2019-01-22 15:44:00 +0100
committerNao Pross <naopross@thearcway.org>2019-01-22 15:44:35 +0100
commit0af63017da578e5838f9b9dde6fdcc58f71fb235 (patch)
tree0d19309b8a38adcc141c9671e978ff274119aef7
parentRename library from libwrapsdl2 to libwsdl2 (diff)
downloadlibwsdl2-0af63017da578e5838f9b9dde6fdcc58f71fb235.tar.gz
libwsdl2-0af63017da578e5838f9b9dde6fdcc58f71fb235.zip
Add ninja build files and configure script, remove makefile
Diffstat (limited to '')
-rw-r--r--.gitignore4
-rwxr-xr-xconfigure.py45
-rw-r--r--makefile27
-rw-r--r--ninja/rules.ninja27
4 files changed, 75 insertions, 28 deletions
diff --git a/.gitignore b/.gitignore
index efeaaa5..7563251 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,5 +1,7 @@
build
-test/build
+
+.ninja*
+build.ninja
**/*.swp
**/*.sublime*
diff --git a/configure.py b/configure.py
new file mode 100755
index 0000000..681861b
--- /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: "build/" + path + "/" + f, objects))
+
+ return sources, objects
+
+
+with open("build.ninja", "w") as bf:
+
+ # find engine sources
+ sources, objects = find_sources(".")
+
+ # include rules
+ print("include ninja/rules.ninja\n", file=bf)
+
+ # create build directories
+ print("build build/: mkdir\n", file=bf)
+ print("build build/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 build/libwsdl2.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 build/libwsdl2.so\n", file=bf)
diff --git a/makefile b/makefile
deleted file mode 100644
index ed5420a..0000000
--- a/makefile
+++ /dev/null
@@ -1,27 +0,0 @@
-# Compiler
-CPP := c++
-CFLAGS := -Wall -pedantic -std=c++17 -fPIC -shared -I include -DDEBUG -DWRAPSDL2_EXCEPTIONS
-LFLAGS := -lSDL2
-
-SRCS := $(wildcard *.cpp)
-OBJS := $(patsubst %.cpp,build/%.o,$(SRCS))
-
-# Recipes
-all: build/libwrapsdl2.so
- $(MAKE) -C test
-
-.PHONY: test-all
-.ONESHELL:
-test-all:
- cd test
- ./build/window_test
-
-
-build/libwrapsdl2.so: $(OBJS)
- $(CPP) $(CFLAGS) -o $@ $(LFLAGS) $(OBJS)
-
-build/%.o: %.cpp build
- $(CPP) $(CFLAGS) -o $@ -c $<
-
-build:
- mkdir -p build
diff --git a/ninja/rules.ninja b/ninja/rules.ninja
new file mode 100644
index 0000000..9bdcf64
--- /dev/null
+++ b/ninja/rules.ninja
@@ -0,0 +1,27 @@
+includes = -I include
+cflags = -Wall -Werror -pedantic -fPIC -std=c++17 -DDEBUG $includes
+
+libs = -lSDL2 -lpthread
+lflags = $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 shared object $out
+
+rule link-static
+ command = ar rvs $out $in
+ description = creating archive $out