bench: pass N as argument, update readme
[libc-test] / Makefile.inc
1 # gnu makefile
2 # when included in src/*/Makefile then it builds a binary locally
3 # when included in ./Makefile then all tests are linked into one binary
4
5 ROOTDIR ?= ../..
6 ifeq ($(ROOTDIR), .)
7 SRCS = $(sort $(wildcard src/*/*.c))
8 else
9 SRCS = $(sort $(wildcard *.c))
10 endif
11 OBJS = $(SRCS:.c=.o)
12
13 usemusl = yes
14 prefix = /usr/local/musl
15 includedir = $(prefix)/include
16 libdir = $(prefix)/lib
17 -include $(ROOTDIR)/Makefile.conf
18
19 AR=ar
20 RANLIB=ranlib
21
22 CFLAGS += -g -std=c99 -pipe -Wall
23 LDFLAGS += -g
24 INC += -I$(ROOTDIR)/common
25
26 ifeq ($(usemusl), yes)
27 CC=gcc
28 LIBCC=$(shell gcc -print-file-name=libgcc.a |sed 's,/libgcc.a,,')
29 #LIBCC=$(shell pcc -v /dev/null 2>&1 |sed -n 's,/crtbegin.o.*,,;s,.* /,/,p')
30 CFLAGS  += -nostdinc -ffreestanding -fno-stack-protector
31 LDFLAGS += -nostdlib -Wl,-e,_start,-Bstatic $(libdir)/crti.o $(libdir)/crt1.o $(libdir)/crtn.o -L $(libdir) -lc -L $(LIBCC) -l$(CC)
32 INC     += -isystem $(includedir)
33 endif
34
35 all: t b
36
37 clean:
38         rm -f $(OBJS) t t.o b b.o tests.a tests.h
39
40 .c.o:
41         $(CC) $(CFLAGS) $(INC) -c -o $@ $<
42
43 $(OBJS): $(ROOTDIR)/common/test.h $(ROOTDIR)/Makefile.conf
44
45 tests.h: $(OBJS)
46         nm -f posix $+ |awk ' \
47                 /^test/ && $$2=="T"{print "T(" $$1 ")"} \
48                 /^bench/ && $$2=="T"{print "B(" $$1 ")"} \
49         ' >tests.h
50
51 tests.a: $(OBJS)
52         $(AR) rc $@ $+
53         $(RANLIB) $@
54
55 t.o: $(ROOTDIR)/common/t.c $(ROOTDIR)/common/test.h tests.h
56         $(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
57
58 t: t.o tests.a
59         $(CC) $+ $(LDFLAGS) -o $@
60
61 b.o: $(ROOTDIR)/common/b.c $(ROOTDIR)/common/test.h tests.h
62         $(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
63
64 b: b.o tests.a
65         $(CC) $+ $(LDFLAGS) -lrt -o $@
66
67 .PHONY: all clean