Blame Makefile.inc

nsz 7308b3
# gnu makefile
nsz 7308b3
# when included in src/*/Makefile then it builds a binary locally
nsz 7308b3
# when included in ./Makefile then all tests are linked into one binary
nsz 7308b3
nsz 7308b3
ROOTDIR ?= ../..
nsz 7308b3
ifeq ($(ROOTDIR), .)
nsz 7308b3
SRCS = $(sort $(wildcard src/*/*.c))
nsz 7308b3
else
nsz 7308b3
SRCS = $(sort $(wildcard *.c))
nsz 7308b3
endif
nsz 7308b3
OBJS = $(SRCS:.c=.o)
nsz 7308b3
nsz 7308b3
usemusl = yes
nsz 7308b3
prefix = /usr/local/musl
nsz 7308b3
includedir = $(prefix)/include
nsz 7308b3
libdir = $(prefix)/lib
nsz 7308b3
-include $(ROOTDIR)/Makefile.conf
nsz 7308b3
nsz a520c1
AR=ar
nsz a520c1
RANLIB=ranlib
nsz 7308b3
nsz 7308b3
CFLAGS += -g -std=c99 -pipe -Wall
nsz 7308b3
LDFLAGS += -g
nsz 7308b3
INC += -I$(ROOTDIR)/common
nsz 7308b3
nsz 7308b3
ifeq ($(usemusl), yes)
nsz 7308b3
CC=gcc
nsz 7308b3
LIBCC=$(shell gcc -print-file-name=libgcc.a |sed 's,/libgcc.a,,')
nsz 7308b3
#LIBCC=$(shell pcc -v /dev/null 2>&1 |sed -n 's,/crtbegin.o.*,,;s,.* /,/,p')
nsz 7308b3
CFLAGS  += -nostdinc -ffreestanding -fno-stack-protector
nsz 7308b3
LDFLAGS += -nostdlib -Wl,-e,_start,-Bstatic $(libdir)/crti.o $(libdir)/crt1.o $(libdir)/crtn.o -L $(libdir) -lc -L $(LIBCC) -l$(CC)
nsz 7308b3
INC     += -isystem $(includedir)
nsz 7308b3
endif
nsz 7308b3
nsz a520c1
all: t b
nsz 7308b3
nsz 7308b3
clean:
nsz a520c1
	rm -f $(OBJS) t main.o main.h b bench.o tests.a
nsz 7308b3
nsz 7308b3
.c.o:
nsz 7308b3
	$(CC) $(CFLAGS) $(INC) -c -o $@ $<
nsz 7308b3
nsz 7308b3
$(OBJS): $(ROOTDIR)/common/test.h
nsz 7308b3
nsz 7308b3
main.h: $(OBJS)
nsz a520c1
	nm -f posix $+ |awk ' \
nsz a520c1
		/^test/ && $$2=="T"{print "T(" $$1 ")"} \
nsz a520c1
		/^bench/ && $$2=="T"{print "B(" $$1 ")"} \
nsz a520c1
	' >main.h
nsz a520c1
nsz a520c1
tests.a: $(OBJS)
nsz a520c1
	$(AR) rc $@ $+
nsz a520c1
	$(RANLIB) $@
nsz 7308b3
nsz 7308b3
main.o: $(ROOTDIR)/common/main.c $(ROOTDIR)/common/test.h main.h
nsz 7308b3
	$(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
nsz 7308b3
nsz a520c1
t: main.o tests.a
nsz 7308b3
	$(CC) $+ $(LDFLAGS) -o $@
nsz 7308b3
nsz a520c1
bench.o: $(ROOTDIR)/common/bench.c $(ROOTDIR)/common/test.h main.h
nsz a520c1
	$(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
nsz a520c1
nsz a520c1
b: bench.o tests.a
nsz a520c1
	$(CC) $+ $(LDFLAGS) -lrt -o $@
nsz a520c1
nsz 7308b3
.PHONY: all clean