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