initial commit
[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
20 CFLAGS += -g -std=c99 -pipe -Wall
21 LDFLAGS += -g
22 INC += -I$(ROOTDIR)/common
23
24 ifeq ($(usemusl), yes)
25 CC=gcc
26 LIBCC=$(shell gcc -print-file-name=libgcc.a |sed 's,/libgcc.a,,')
27 #LIBCC=$(shell pcc -v /dev/null 2>&1 |sed -n 's,/crtbegin.o.*,,;s,.* /,/,p')
28 CFLAGS  += -nostdinc -ffreestanding -fno-stack-protector
29 LDFLAGS += -nostdlib -Wl,-e,_start,-Bstatic $(libdir)/crti.o $(libdir)/crt1.o $(libdir)/crtn.o -L $(libdir) -lc -L $(LIBCC) -l$(CC)
30 INC     += -isystem $(includedir)
31 endif
32
33 all: t
34
35 clean:
36         rm -f $(OBJS) t main.o main.h
37
38 .c.o:
39         $(CC) $(CFLAGS) $(INC) -c -o $@ $<
40
41 $(OBJS): $(ROOTDIR)/common/test.h
42
43 main.h: $(OBJS)
44         nm -f posix $+ |awk '/^test/ && $$2=="T"{print "T(" $$1 ")"}' >main.h
45
46 main.o: $(ROOTDIR)/common/main.c $(ROOTDIR)/common/test.h main.h
47         $(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
48
49 t: $(OBJS) main.o
50         $(CC) $+ $(LDFLAGS) -o $@
51
52 .PHONY: all clean