aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2025-03-30 14:43:55 +0300
committerkartofen <mladenovnasko0@gmail.com>2025-03-30 14:43:55 +0300
commit5fba9e4d7492ca07d619999120b42495cf3df7c7 (patch)
treee9fa5290ca06610553797b5e943238e772d69a1d
parent9c6e78990e76367e683a429cd5a9637b1ac94542 (diff)
can build as a single header
-rw-r--r--msgpack.h4
-rw-r--r--ninja.m457
2 files changed, 43 insertions, 18 deletions
diff --git a/msgpack.h b/msgpack.h
index 7eff711..8bb4514 100644
--- a/msgpack.h
+++ b/msgpack.h
@@ -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
diff --git a/ninja.m4 b/ninja.m4
index 98824ff..77812a0 100644
--- a/ninja.m4
+++ b/ninja.m4
@@ -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]
])