Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 1 | # Makefile fragment - requires GNU make |
| 2 | # |
| 3 | # Copyright (c) 2019, Arm Limited. |
| 4 | # SPDX-License-Identifier: MIT |
| 5 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 6 | S := $(srcdir)/math |
| 7 | B := build/math |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 8 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 9 | math-lib-srcs := $(wildcard $(S)/*.[cS]) |
| 10 | math-test-srcs := \ |
| 11 | $(S)/test/mathtest.c \ |
| 12 | $(S)/test/mathbench.c \ |
| 13 | $(S)/test/ulp.c \ |
| 14 | |
| 15 | math-test-host-srcs := $(wildcard $(S)/test/rtest/*.[cS]) |
| 16 | |
| 17 | math-includes := $(patsubst $(S)/%,build/%,$(wildcard $(S)/include/*.h)) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 18 | |
| 19 | math-libs := \ |
| 20 | build/lib/libmathlib.so \ |
| 21 | build/lib/libmathlib.a \ |
| 22 | |
| 23 | math-tools := \ |
| 24 | build/bin/mathtest \ |
| 25 | build/bin/mathbench \ |
| 26 | build/bin/mathbench_libc \ |
| 27 | build/bin/runulp.sh \ |
| 28 | build/bin/ulp \ |
| 29 | |
| 30 | math-host-tools := \ |
| 31 | build/bin/rtest \ |
| 32 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 33 | math-lib-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-lib-srcs))) |
| 34 | math-test-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-test-srcs))) |
| 35 | math-host-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-test-host-srcs))) |
| 36 | math-target-objs := $(math-lib-objs) $(math-test-objs) |
| 37 | math-objs := $(math-target-objs) $(math-target-objs:%.o=%.os) $(math-host-objs) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 38 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 39 | math-files := \ |
| 40 | $(math-objs) \ |
| 41 | $(math-libs) \ |
| 42 | $(math-tools) \ |
| 43 | $(math-host-tools) \ |
| 44 | $(math-includes) \ |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 45 | |
| 46 | all-math: $(math-libs) $(math-tools) $(math-includes) |
| 47 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 48 | $(math-objs): $(math-includes) |
| 49 | $(math-objs): CFLAGS_ALL += $(math-cflags) |
| 50 | $(B)/test/mathtest.o: CFLAGS_ALL += -fmath-errno |
| 51 | $(math-host-objs): CC = $(HOST_CC) |
| 52 | $(math-host-objs): CFLAGS_ALL = $(HOST_CFLAGS) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 53 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 54 | $(B)/test/ulp.o: $(S)/test/ulp.h |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 55 | |
| 56 | build/lib/libmathlib.so: $(math-lib-objs:%.o=%.os) |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 57 | $(CC) $(CFLAGS_ALL) $(LDFLAGS) -shared -o $@ $^ |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 58 | |
| 59 | build/lib/libmathlib.a: $(math-lib-objs) |
| 60 | rm -f $@ |
| 61 | $(AR) rc $@ $^ |
| 62 | $(RANLIB) $@ |
| 63 | |
| 64 | $(math-host-tools): HOST_LDLIBS += -lm -lmpfr -lmpc |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 65 | $(math-tools): LDLIBS += $(math-ldlibs) -lm |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 66 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 67 | build/bin/rtest: $(math-host-objs) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 68 | $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(HOST_LDLIBS) |
| 69 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 70 | build/bin/mathtest: $(B)/test/mathtest.o build/lib/libmathlib.a |
| 71 | $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 72 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 73 | build/bin/mathbench: $(B)/test/mathbench.o build/lib/libmathlib.a |
| 74 | $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 75 | |
Szabolcs Nagy | a88f3f6 | 2019-10-14 11:55:14 +0100 | [diff] [blame] | 76 | # This is not ideal, but allows custom symbols in mathbench to get resolved. |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 77 | build/bin/mathbench_libc: $(B)/test/mathbench.o build/lib/libmathlib.a |
| 78 | $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $< $(LDLIBS) -lc build/lib/libmathlib.a -lm |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 79 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 80 | build/bin/ulp: $(B)/test/ulp.o build/lib/libmathlib.a |
| 81 | $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 82 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 83 | build/include/%.h: $(S)/include/%.h |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 84 | cp $< $@ |
| 85 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 86 | build/bin/%.sh: $(S)/test/%.sh |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 87 | cp $< $@ |
| 88 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 89 | math-tests := $(wildcard $(S)/test/testcases/directed/*.tst) |
| 90 | math-rtests := $(wildcard $(S)/test/testcases/random/*.tst) |
| 91 | |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 92 | check-math-test: $(math-tools) |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 93 | cat $(math-tests) | $(EMULATOR) build/bin/mathtest $(math-testflags) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 94 | |
| 95 | check-math-rtest: $(math-host-tools) $(math-tools) |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 96 | cat $(math-rtests) | build/bin/rtest | $(EMULATOR) build/bin/mathtest $(math-testflags) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 97 | |
| 98 | check-math-ulp: $(math-tools) |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 99 | ULPFLAGS="$(math-ulpflags)" build/bin/runulp.sh $(EMULATOR) |
Szabolcs Nagy | 0af9fce | 2019-07-18 10:21:43 +0100 | [diff] [blame] | 100 | |
| 101 | check-math: check-math-test check-math-rtest check-math-ulp |
| 102 | |
Szabolcs Nagy | 1fd2aaa | 2019-11-20 18:05:06 +0000 | [diff] [blame] | 103 | install-math: \ |
| 104 | $(math-libs:build/lib/%=$(DESTDIR)$(libdir)/%) \ |
| 105 | $(math-includes:build/include/%=$(DESTDIR)$(includedir)/%) |
| 106 | |
| 107 | clean-math: |
| 108 | rm -f $(math-files) |
| 109 | |
| 110 | .PHONY: all-math check-math-test check-math-rtest check-math-ulp check-math install-math clean-math |