tests: Make random tests more robust
[libfiu.git] / tests / Makefile
blobc6efc9a4c6299be7371fb370b0b0587b89a6003b
2 CFLAGS += -std=c99 -pedantic -Wall -rdynamic
3 ALL_CFLAGS = -I../libfiu/ -L../libfiu/ \
4 -D_XOPEN_SOURCE=600 -D_GNU_SOURCE -fPIC -DFIU_ENABLE=1 $(CFLAGS)
6 ifdef DEBUG
7 ALL_CFLAGS += -g
8 endif
10 ifdef PROFILE
11 ALL_CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
12 endif
14 ifneq ($(V), 1)
15 NICE_CC = @echo " CC $@"; $(CC)
16 NICE_RUN = @echo " RUN $<"; LD_LIBRARY_PATH=../libfiu/
17 NICE_PY = @echo " PY $<"; ./wrap-python 2
18 NICE_LN = @echo " LN $@"; ln -f
19 else
20 NICE_CC = $(CC)
21 NICE_RUN = LD_LIBRARY_PATH=../libfiu/
22 NICE_PY = ./wrap-python 2
23 NICE_LN = ln -f
24 endif
26 default: tests
28 all: tests
30 tests: c-tests py-tests gen-tests utils-tests
33 # Link the libraries to a single place, some of the tests need this.
34 libs:
35 mkdir -p libs/
37 libs/fiu_posix_preload.so: ../preload/posix/fiu_posix_preload.so libs
38 $(NICE_LN) $< libs/
40 libs/fiu_run_preload.so: ../preload/run/fiu_run_preload.so libs
41 $(NICE_LN) $< libs/
43 lnlibs: libs/fiu_posix_preload.so libs/fiu_run_preload.so
47 # C tests
50 C_SRCS := $(wildcard test-*.c)
51 C_OBJS := $(patsubst %.c,%.o,$(C_SRCS))
52 C_BINS := $(patsubst %.c,%,$(C_SRCS))
54 c-tests: $(patsubst %.c,c-run-%,$(C_SRCS))
56 test-%: test-%.o build-flags
57 $(NICE_CC) $(ALL_CFLAGS) $< -lfiu -lpthread -o $@
59 c-run-%: %
60 $(NICE_RUN) ./$<
63 BF = $(ALL_CFLAGS) ~ $(PREFIX)
64 build-flags: .force-build-flags
65 @if [ x"$(BF)" != x"`cat build-flags 2>/dev/null`" ]; then \
66 if [ -f build-flags ]; then \
67 echo "build flags changed, rebuilding"; \
68 fi; \
69 echo "$(BF)" > build-flags; \
72 .c.o:
73 $(NICE_CC) $(ALL_CFLAGS) -c $< -o $@
77 # Python tests
80 PY_TESTS := $(wildcard test-*.py)
82 py-tests: $(patsubst %.py,py-run-%,$(PY_TESTS))
84 py-run-%: %.py lnlibs small-cat
85 $(NICE_PY) ./$<
87 small-cat: small-cat.c
88 $(NICE_CC) $(ALL_CFLAGS) $< -o $@
91 # Sub-directory tests
94 gen-tests:
95 $(MAKE) -C generated
97 utils-tests:
98 $(MAKE) -C utils
101 # Cleanup
104 # Normally, $C_OBJS and $C_BINS are removed by make after building,
105 # since here they're considered "intermediate files"; however we
106 # also remove them when cleaning just in case.
107 clean:
108 rm -f $(C_OBJS) $(C_BINS)
109 rm -rf libs/ small-cat
110 rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out build-flags
111 $(MAKE) -C generated clean
113 FORCE:
115 .PHONY: default all clean \
116 tests c-tests py-tests gen-tests utils-tests \
117 .force-build-flags