File: Makefile

package info (click to toggle)
libfiu 1.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 768 kB
  • sloc: ansic: 2,633; python: 973; makefile: 599; sh: 309
file content (135 lines) | stat: -rw-r--r-- 3,106 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135

CFLAGS += -std=c99 -pedantic -Wall
ALL_CFLAGS = -I../libfiu/ -L../libfiu/ \
	-D_XOPEN_SOURCE=600 -D_GNU_SOURCE -fPIC -DFIU_ENABLE=1 $(CFLAGS)

ifdef DEBUG
ALL_CFLAGS += -g
endif

ifdef PROFILE
ALL_CFLAGS += -g -pg -fprofile-arcs -ftest-coverage
endif

ifneq ($(V), 1)
	NICE_CC = @echo "  CC  $@"; $(CC)
	NICE_RUN = @echo "  RUN $<"; \
		   LD_LIBRARY_PATH=../libfiu/ \
		   LD_PRELOAD=./libs/fiu_run_preload.so:./libs/fiu_posix_preload.so
	NICE_PY = @echo "  PY  $<"; ./wrap-python 3
	NICE_LN = @echo "  LN $@"; ln -f
else
	NICE_CC = $(CC)
	NICE_RUN = LD_LIBRARY_PATH=../libfiu/ \
		   LD_PRELOAD=./libs/fiu_run_preload.so:./libs/fiu_posix_preload.so
	NICE_PY = ./wrap-python 3
	NICE_LN = ln -f
endif

default: tests

all: tests

tests: c-tests py-tests gen-tests utils-tests collisions-tests


# Link the libraries to a single place, some of the tests need this.
libs:
	mkdir -p libs/

libs/fiu_posix_preload.so: ../preload/posix/fiu_posix_preload.so libs
	$(NICE_LN) $< libs/

libs/fiu_run_preload.so: ../preload/run/fiu_run_preload.so libs
	$(NICE_LN) $< libs/

lnlibs: libs/fiu_posix_preload.so libs/fiu_run_preload.so


#
# C tests
#

C_SRCS := $(wildcard test-*.c)
C_OBJS := $(patsubst %.c,%.o,$(C_SRCS))
C_BINS := $(patsubst %.c,%,$(C_SRCS))

c-tests: $(patsubst %.c,c-run-%,$(C_SRCS))

test-%: test-%.c build-flags
	$(NICE_CC) $(ALL_CFLAGS) $< -lfiu -lpthread -o $@

# Tests that use the stack need special build flags, as some common
# optimizations can cause them to fail.
# -rdynamic: Adds all symbols to the dynamic symbol table. This option is
#    needed for backtrace() to work properly.
# -fno-optimize-sibling-calls: This optimization can turn some calls into
#    direct jumps, which leaves caller information out of the stack frame and
#    makes functions not appear in the backtrace. We disable it.
test-enable_stac%: test-enable_stac%.c build-flags
	$(NICE_CC) $(ALL_CFLAGS) \
		-rdynamic -fno-optimize-sibling-calls $< -lfiu -lpthread -o $@

c-run-%: % lnlibs
	$(NICE_RUN) ./$<


BF = $(ALL_CFLAGS) ~ $(PREFIX)
build-flags: .force-build-flags
	@if [ x"$(BF)" != x"`cat build-flags 2>/dev/null`" ]; then \
		if [ -f build-flags ]; then \
			echo "build flags changed, rebuilding"; \
		fi; \
		echo "$(BF)" > build-flags; \
	fi


#
# Python tests
#

PY_TESTS := $(wildcard test-*.py)

py-tests: $(patsubst %.py,py-run-%,$(PY_TESTS))

py-run-%: %.py lnlibs small-cat
	$(NICE_PY) ./$<

small-cat: small-cat.c
	$(NICE_CC) $(ALL_CFLAGS) $< -o $@

#
# Sub-directory tests
#

gen-tests:
	$(MAKE) -C generated

utils-tests:
	$(MAKE) -C utils

collisions-tests:
	$(MAKE) -C collisions

#
# Cleanup
#

# Normally, $C_OBJS and $C_BINS are removed by make after building,
# since here they're considered "intermediate files"; however we
# also remove them when cleaning just in case.
clean:
	rm -f $(C_OBJS) $(C_BINS)
	rm -rf libs/ small-cat
	rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out build-flags
	$(MAKE) -C generated clean
	$(MAKE) -C collisions clean
	$(MAKE) -C utils clean

FORCE:

.PHONY: default all clean \
	tests c-tests py-tests gen-tests utils-tests \
	.force-build-flags