diff options
author | kartofen <mladenovnasko0@gmail.com> | 2025-03-30 14:43:55 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2025-03-30 14:43:55 +0300 |
commit | 5fba9e4d7492ca07d619999120b42495cf3df7c7 (patch) | |
tree | e9fa5290ca06610553797b5e943238e772d69a1d | |
parent | 9c6e78990e76367e683a429cd5a9637b1ac94542 (diff) |
can build as a single header
-rw-r--r-- | msgpack.h | 4 | ||||
-rw-r--r-- | ninja.m4 | 57 |
2 files changed, 43 insertions, 18 deletions
@@ -242,4 +242,8 @@ static const char * const msgpack_error_string[] = { #define MSGPACK_CHECK2(call, arg, body_suc, body_err) \ __MSGPACK_CHECK_DEFER(call, body_suc, body_err, __EXPAND arg) +#ifdef MSGPACK_IMPLEMENTATION +// include(SOURCE) +#endif + #endif @@ -4,41 +4,62 @@ cflags = ifdef([PROD], [], [-std=c99 -Wall -Wextra -g -D_DEFAULT_SOURCE]) bin = bin m4flags = +# build as library + rule cc + command = gcc $cflags $in -o $out +rule obj command = gcc -MD -MF $out.d $cflags -c $in -o $out depfile = $out.d rule ar command = ar rcs $out $in +rule m4 + command = m4 $m4flags $in > $out -build $bin/msgpack.o: cc msgpack.c -build $bin/msgpack.a: ar $bin/msgpack.o -build $bin/msgpack.so: cc msgpack.c +build $bin/msgpack.o: obj msgpack.c + +build $bin/libmsgpack.a: ar $bin/msgpack.o +build $bin/libmsgpack.so: cc $bin/msgpack.o cflags = $cflags -fPIC -shared - -rule elf - command = gcc $cflags $in -o $out -rule run +build $bin/libmsgpack.h: m4 msgpack.h | msgpack.c + m4flags = -D SOURCE=msgpack.c + +# testing + +rule valgrind command = valgrind -s --leak-check=full --show-leak-kinds=all $in - -build $bin/test.o: cc test.c -build $bin/test: elf $bin/msgpack.o $bin/test.o + +build $bin/test.o: obj test.c +build $bin/test: cc msgpack.c $bin/test.o + +# named targets + +rule cpy + command = cp $in $out +build $bin/msgpack.h: cpy msgpack.h + +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 test: valgrind $bin/test -build static: phony $bin/msgpack.a -build shared: phony $bin/msgpack.so -build header: phony # TODO write it -build test: run $bin/test +ifdef([PROD], [default header], [default test]) -ifdef([PROD], [default test], [default header]) +# regeneration rule gen command = m4 $m4flags ninja.m4 > build.ninja generator = 1 - + build build.ninja: gen | ninja.m4 +rule _clean + command = ninja -t clean +build clean: _clean + ifdef([PROD], [dnl -build dev: gen +build dev: gen | clean ], [dnl -build prod: gen +build prod: gen | clean m4flags = -D [PROD] ]) |