aboutsummaryrefslogtreecommitdiff
path: root/ninja.m4
blob: 77812a02681e1a6bb1399b3cb4a4b950b5c0de89 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
changequote([,])

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:     obj msgpack.c

build $bin/libmsgpack.a:  ar $bin/msgpack.o
build $bin/libmsgpack.so: cc $bin/msgpack.o
  cflags = $cflags -fPIC -shared
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: 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

ifdef([PROD], [default header], [default test])

# 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 | clean
], [dnl
build prod: gen | clean
  m4flags = -D [PROD]
])