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 7f409d
LDFLAGS += -g -lpthread -lrt -lm
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 7d87d3
	rm -f $(OBJS) t t.o b b.o tests.a tests.h
nsz 7308b3
nsz 7308b3
.c.o:
nsz 7308b3
	$(CC) $(CFLAGS) $(INC) -c -o $@ $<
nsz 7308b3
nsz 9d224c
$(OBJS): $(ROOTDIR)/common/test.h $(ROOTDIR)/Makefile.conf
nsz 7308b3
nsz 7d87d3
tests.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 7d87d3
	' >tests.h
nsz a520c1
nsz a520c1
tests.a: $(OBJS)
nsz a520c1
	$(AR) rc $@ $+
nsz a520c1
	$(RANLIB) $@
nsz 7308b3
nsz 7d87d3
t.o: $(ROOTDIR)/common/t.c $(ROOTDIR)/common/test.h tests.h
nsz 7308b3
	$(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
nsz 7308b3
nsz 9d224c
t: t.o tests.a
nsz 7308b3
	$(CC) $+ $(LDFLAGS) -o $@
nsz 7308b3
nsz 7d87d3
b.o: $(ROOTDIR)/common/b.c $(ROOTDIR)/common/test.h tests.h
nsz a520c1
	$(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
nsz a520c1
nsz 9d224c
b: b.o tests.a
nsz a520c1
	$(CC) $+ $(LDFLAGS) -lrt -o $@
nsz a520c1
nsz 7308b3
.PHONY: all clean