aboutsummaryrefslogtreecommitdiff
path: root/ninja.m4
blob: 2f2a01ad05bc0f9cda43a64341a6d605209a647c (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
66
67
68
69
70
71
divert(-1)

changequote([,])

define([getenv], [
  define([$1], [esyscmd([echo -n $$1])])
  ifelse($1, , [undefine([$1])])
])

getenv([PROD])
getenv([BIN])

divert(0)

cflags  = ifdef([PROD], [],  [-Wall -Wextra -g]) -std=c99 -D_DEFAULT_SOURCE
bin     = ifdef([BIN], [BIN], [bin])
m4flags = 

# building

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
rule cpy
  command = cp $in $out
  
build $bin/msgpack.o: obj msgpack.c
build $bin/msgpack.h: cpy msgpack.h

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

build $bin/test: cc msgpack.c test.c

rule valgrind
  command = valgrind -s --leak-check=full --show-leak-kinds=all $in

# named targets

rule ninja_clean
  command = ninja -t 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 test:  valgrind $bin/test
build clean: ninja_clean

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

# regeneration

rule regen
  command = m4 ninja.m4 > build.ninja
  generator=1
  
build build.ninja: regen ninja.m4
build configure:   regen