|
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 |
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 |
7308b3 |
all: t
|
|
nsz |
7308b3 |
|
|
nsz |
7308b3 |
clean:
|
|
nsz |
7308b3 |
rm -f $(OBJS) t main.o main.h
|
|
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 |
7308b3 |
nm -f posix $+ |awk '/^test/ && $$2=="T"{print "T(" $$1 ")"}' >main.h
|
|
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 |
7308b3 |
t: $(OBJS) main.o
|
|
nsz |
7308b3 |
$(CC) $+ $(LDFLAGS) -o $@
|
|
nsz |
7308b3 |
|
|
nsz |
7308b3 |
.PHONY: all clean
|