fix math test gen script
[libc-test] / Makefile.inc
index bfdc3dc..f23381b 100644 (file)
@@ -1,52 +1,26 @@
-# gnu makefile
-# when included in src/*/Makefile then it builds a binary locally
-# when included in ./Makefile then all tests are linked into one binary
-
-ROOTDIR ?= ../..
-ifeq ($(ROOTDIR), .)
-SRCS = $(sort $(wildcard src/*/*.c))
-else
-SRCS = $(sort $(wildcard *.c))
-endif
-OBJS = $(SRCS:.c=.o)
-
-usemusl = yes
-prefix = /usr/local/musl
-includedir = $(prefix)/include
-libdir = $(prefix)/lib
--include $(ROOTDIR)/Makefile.conf
-
-
-CFLAGS += -g -std=c99 -pipe -Wall
-LDFLAGS += -g
-INC += -I$(ROOTDIR)/common
-
-ifeq ($(usemusl), yes)
-CC=gcc
-LIBCC=$(shell gcc -print-file-name=libgcc.a |sed 's,/libgcc.a,,')
-#LIBCC=$(shell pcc -v /dev/null 2>&1 |sed -n 's,/crtbegin.o.*,,;s,.* /,/,p')
-CFLAGS  += -nostdinc -ffreestanding -fno-stack-protector
-LDFLAGS += -nostdlib -Wl,-e,_start,-Bstatic $(libdir)/crti.o $(libdir)/crt1.o $(libdir)/crtn.o -L $(libdir) -lc -L $(LIBCC) -l$(CC)
-INC     += -isystem $(includedir)
-endif
-
-all: t
-
+CFLAGS+=-g -pipe -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wno-unused-function -Wno-missing-braces
+LDFLAGS+=-g
+
+SRC=$(sort $(wildcard *.c))
+OBJ=$(SRC:.c=.o)
+DSOOBJ=$(filter %_dso.o,$(OBJ))
+# TODO: fix this hack
+BINOBJ=$(filter-out $(NONBIN),$(filter-out %_dso.o,$(OBJ)))
+DSO=$(DSOOBJ:.o=.so)
+BIN=$(BINOBJ:.o=)
+
+ROOT=../..
+include $(ROOT)/config.mak
+
+all: $(BIN) $(DSO)
+run: all
+       @N=0; for i in $(BIN);do ./$$i || N=$$((N+1)); done; [ "$$N" = 0 ] && echo PASS || echo FAILS: $$N
 clean:
-       rm -f $(OBJS) t main.o main.h
-
-.c.o:
-       $(CC) $(CFLAGS) $(INC) -c -o $@ $<
-
-$(OBJS): $(ROOTDIR)/common/test.h
-
-main.h: $(OBJS)
-       nm -f posix $+ |awk '/^test/ && $$2=="T"{print "T(" $$1 ")"}' >main.h
-
-main.o: $(ROOTDIR)/common/main.c $(ROOTDIR)/common/test.h main.h
-       $(CC) $(CFLAGS) $(INC) -I. -c -o $@ $<
-
-t: $(OBJS) main.o
-       $(CC) $+ $(LDFLAGS) -o $@
-
-.PHONY: all clean
+       rm -f $(OBJ) $(DSO) $(BIN)
+
+$(OBJ): test.h
+$(DSOOBJ): CFLAGS += -fPIC
+%.so: %.o
+       $(CC) $(LDFLAGS) -shared -o $@ $<
+%: %.o
+       $(CC) $(LDFLAGS) -o $@ $(patsubst %.so,./%.so,$+)