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