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