aboutsummaryrefslogtreecommitdiff
path: root/ninja.m4
diff options
context:
space:
mode:
Diffstat (limited to 'ninja.m4')
-rw-r--r--ninja.m458
1 files changed, 28 insertions, 30 deletions
diff --git a/ninja.m4 b/ninja.m4
index 7181a00..0992f9a 100644
--- a/ninja.m4
+++ b/ninja.m4
@@ -7,14 +7,12 @@ define([getenv], [
ifelse($2, , [undefine([$1])], [define([$1], [$2])])
])])
-# global vars
getenv([PROD])
-
divert(0)
# building
-cflags = ifdef([PROD], [], [-Wall -Wextra -g]) -std=c99 -D_DEFAULT_SOURCE
+cflags = ifdef([PROD], [-O3], [-Wall -Wextra -g]) -std=c99 -D_DEFAULT_SOURCE
bin = build
m4flags =
@@ -42,52 +40,52 @@ build $bin/libmsgpack.h: m4 headeronly.h.m4 | msgpack.c msgpack.h
# installing
divert(-1)
+getenv([TARGET], [header])
+
getenv([PREFIX], [installdir])
getenv([LIBDIR], [PREFIX/lib])
getenv([INCLUDEDIR], [PREFIX/include])
+
+define([install_file], [
+build $3/$1: install $2/$1
+ dir = $3
+])
divert(0)
-rule cpy_pattern
- command = cp $$(command ls $pattern 2> /dev/null) $dest
-
-build force: phony
-build $bin/files.dd: m4 builtfiles.dd.m4 | force
- m4flags = -D BIN=$bin -D [LIBDIR]=LIBDIR -D [INCLUDEDIR]=INCLUDEDIR
- description = Generate dynamic dependency from the built files
-
-build libs: cpy_pattern || $bin/files.dd
- description = Install library files to 'LIBDIR'
- dyndep = $bin/files.dd
- dest = LIBDIR
- pattern = $bin/*.a $bin/*.so
-build headers: cpy_pattern || $bin/files.dd
- description = Install header files to 'INCLUDEDIR'
- dyndep = $bin/files.dd
- dest = INCLUDEDIR
- pattern = $bin/*.h
+rule install
+ command = install -v -D -t $dir $in
+
+install_file(libmsgpack.h, $bin, INCLUDEDIR)
+install_file(libmsgpack.so, $bin, LIBDIR)
+install_file(libmsgpack.a, $bin, LIBDIR)
+install_file(msgpack.h, $bin, INCLUDEDIR)
# testing
build $bin/test: cc msgpack.c test.c
+ cflags = $cflags -std=gnu99
rule valgrind
command = valgrind -s --leak-check=full --show-leak-kinds=all $in
# named targets
+divert(-1)
+define([target_table], [ifelse(
+ TARGET, [header], [$2/libmsgpack.h],
+ TARGET, [shared], [$1/libmsgpack.so $2/msgpack.h],
+ TARGET, [static], [$1/libmsgpack.a $2/msgpack.h]
+)])
+divert(0)
+
rule ninja_clean
command = ninja -t clean
+build clean: ninja_clean
-build static: phony $bin/libmsgpack.a $bin/msgpack.h
-build shared: phony $bin/libmsgpack.so $bin/msgpack.h
-build header: phony $bin/libmsgpack.h
-
-build install: phony libs headers
-build clean: ninja_clean
-
-build test: valgrind $bin/test
+build test: valgrind $bin/test
-default ifdef([PROD], [static], [test])
+build install: phony target_table(LIBDIR, INCLUDEDIR)
+default ifdef([PROD], [target_table($bin, $bin)], [test])
# regeneration