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