4613e085b7f64e9ff07088b7d2375fa987931cd1
[libc-test] / Makefile.inc
1 # gnu makefile
2 # when included in a Makefile it builds *.c unless SRCS are overridden
3
4 # default TROOT works from src/*/Makefile
5 TROOT ?= ../..
6 SRCS ?= $(sort $(wildcard *.c))
7 OBJS = $(SRCS:.c=.o)
8
9 AR=ar
10 RANLIB=ranlib
11
12 CFLAGS += -g -D_POSIX_C_SOURCE=200809L -std=c99 -pipe -Wall
13 LDFLAGS += -g -lpthread -lrt -lm
14
15 -include $(TROOT)/config.mak
16
17 CFLAGS += -I$(TROOT)/common
18
19 all: test
20
21 test: t b
22         ./t
23
24 clean:
25         rm -f $(OBJS) t t_.o b b_.o tests.a tests.h
26
27 .c.o:
28         $(CC) $(CFLAGS) -c -o $@ $<
29
30 $(OBJS): $(TROOT)/common/test.h
31
32 tests.h: $(OBJS)
33         nm -f posix $+ |awk ' \
34                 /^test/ && $$2=="T"{print "T(" $$1 ")"} \
35                 /^bench/ && $$2=="T"{print "B(" $$1 ")"} \
36         ' >tests.h
37
38 tests.a: $(OBJS)
39         $(AR) rc $@ $+
40         $(RANLIB) $@
41
42 # TODO: /tmp/t.o ?
43 t_.o: $(TROOT)/common/t.c $(TROOT)/common/test.h tests.h
44         $(CC) $(CFLAGS) -I. -c -o $@ $<
45
46 t: t_.o tests.a
47         $(CC) $+ $(LDFLAGS) -o $@
48
49 b_.o: $(TROOT)/common/b.c $(TROOT)/common/test.h tests.h
50         $(CC) $(CFLAGS) -I. -c -o $@ $<
51
52 b: b_.o tests.a
53         $(CC) $+ $(LDFLAGS) -lrt -o $@
54
55 .PHONY: all clean test