1# Makefile fragment - requires GNU make 2# 3# Copyright (c) 2019-2024, Arm Limited. 4# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 5 6PLM := $(srcdir)/pl/math 7AOR := $(srcdir)/math 8B := build/pl/math 9 10pl-lib-srcs := $(wildcard $(PLM)/*.[cS]) 11 12ifeq ($(WANT_SVE_MATH), 0) 13pl-lib-srcs := $(filter-out $(PLM)/sv_%, $(pl-lib-srcs)) 14endif 15 16math-test-srcs := \ 17 $(AOR)/test/mathtest.c \ 18 $(AOR)/test/mathbench.c \ 19 $(AOR)/test/ulp.c \ 20 21math-test-host-srcs := $(wildcard $(AOR)/test/rtest/*.[cS]) 22 23pl-includes := $(patsubst $(PLM)/%,build/pl/%,$(wildcard $(PLM)/include/*.h)) 24pl-test-includes := $(patsubst $(PLM)/%,build/pl/include/%,$(wildcard $(PLM)/test/*.h)) 25 26pl-libs := \ 27 build/pl/lib/libmathlib.so \ 28 build/pl/lib/libmathlib.a \ 29 30math-tools := \ 31 build/pl/bin/mathtest \ 32 build/pl/bin/mathbench \ 33 build/pl/bin/mathbench_libc \ 34 build/pl/bin/runulp.sh \ 35 build/pl/bin/ulp \ 36 37math-host-tools := \ 38 build/pl/bin/rtest \ 39 40pl-lib-objs := $(patsubst $(PLM)/%,$(B)/%.o,$(basename $(pl-lib-srcs))) 41math-test-objs := $(patsubst $(AOR)/%,$(B)/%.o,$(basename $(math-test-srcs))) 42math-host-objs := $(patsubst $(AOR)/%,$(B)/%.o,$(basename $(math-test-host-srcs))) 43pl-target-objs := $(pl-lib-objs) $(math-test-objs) 44pl-objs := $(pl-target-objs) $(pl-target-objs:%.o=%.os) $(math-host-objs) 45 46pl/math-files := \ 47 $(pl-objs) \ 48 $(pl-libs) \ 49 $(math-tools) \ 50 $(math-host-tools) \ 51 $(pl-includes) \ 52 $(pl-test-includes) \ 53 54all-pl/math: $(pl-libs) $(math-tools) $(pl-includes) $(pl-test-includes) 55 56$(pl-objs): $(pl-includes) $(pl-test-includes) 57$(pl-objs): CFLAGS_PL += $(math-cflags) 58$(B)/test/mathtest.o: CFLAGS_PL += -fmath-errno 59$(math-host-objs): CC = $(HOST_CC) 60$(math-host-objs): CFLAGS_PL = $(HOST_CFLAGS) 61 62$(B)/sv_%: CFLAGS_PL += $(math-sve-cflags) 63 64ulp-funcs-dir = build/pl/test/ulp-funcs/ 65ulp-wrappers-dir = build/pl/test/ulp-wrappers/ 66mathbench-funcs-dir = build/pl/test/mathbench-funcs/ 67plsig-dirs = $(ulp-funcs-dir) $(ulp-wrappers-dir) $(mathbench-funcs-dir) 68 69$(plsig-dirs): 70 mkdir -p $@ 71 72ulp-funcs = $(patsubst $(PLM)/%,$(ulp-funcs-dir)%,$(basename $(pl-lib-srcs))) 73ulp-wrappers = $(patsubst $(PLM)/%,$(ulp-wrappers-dir)%,$(basename $(pl-lib-srcs))) 74mathbench-funcs = $(patsubst $(PLM)/%,$(mathbench-funcs-dir)%,$(basename $(pl-lib-srcs))) 75plsig-autogen-files = $(ulp-funcs) $(ulp-wrappers) $(mathbench-funcs) 76 77$(ulp-funcs): PLSIG_DIRECTIVE = EMIT_ULP_FUNCS 78$(ulp-wrappers): PLSIG_DIRECTIVE = EMIT_ULP_WRAPPERS 79$(mathbench-funcs): PLSIG_DIRECTIVE = EMIT_MATHBENCH_FUNCS 80 81.SECONDEXPANSION: 82$(plsig-autogen-files): %: $(PLM)/$$(notdir $$@).c | $$(dir $$@) 83 $(CC) $< $(CFLAGS_PL) -D$(PLSIG_DIRECTIVE) -E -o - | { grep PL_SIG || true; } | cut -f 2- -d ' ' > $@ 84 85build/pl/include/test/ulp_funcs_gen.h: $(ulp-funcs) 86 cat $^ | sort -u > $@ 87 88build/pl/include/test/ulp_wrappers_gen.h: $(ulp-wrappers) 89 cat $^ > $@ 90 91build/pl/include/test/mathbench_funcs_gen.h: $(mathbench-funcs) 92 cat $^ | sort -u > $@ 93 94$(B)/test/ulp.o: $(AOR)/test/ulp.h build/pl/include/test/ulp_funcs_gen.h build/pl/include/test/ulp_wrappers_gen.h 95$(B)/test/ulp.o: CFLAGS_PL += -I build/pl/include/test 96 97$(B)/test/mathbench.o: build/pl/include/test/mathbench_funcs_gen.h 98$(B)/test/mathbench.o: CFLAGS_PL += -I build/pl/include/test 99 100build/pl/lib/libmathlib.so: $(pl-lib-objs:%.o=%.os) 101 $(CC) $(CFLAGS_PL) $(LDFLAGS) -shared -o $@ $^ 102 103build/pl/lib/libmathlib.a: $(pl-lib-objs) 104 rm -f $@ 105 $(AR) rc $@ $^ 106 $(RANLIB) $@ 107 108$(math-host-tools): HOST_LDLIBS += -lm -lmpfr -lmpc 109$(math-tools): LDLIBS += $(math-ldlibs) -lm 110# math-sve-cflags should be empty if WANT_SVE_MATH is not enabled 111$(math-tools): CFLAGS_PL += $(math-sve-cflags) 112 113# Some targets to build pl/math/test from math/test sources 114build/pl/math/test/%.o: $(srcdir)/math/test/%.S 115 $(CC) $(CFLAGS_PL) -c -o $@ $< 116 117build/pl/math/test/%.o: $(srcdir)/math/test/%.c 118 $(CC) $(CFLAGS_PL) -c -o $@ $< 119 120build/pl/math/test/%.os: $(srcdir)/math/test/%.S 121 $(CC) $(CFLAGS_PL) -c -o $@ $< 122 123build/pl/math/test/%.os: $(srcdir)/math/test/%.c 124 $(CC) $(CFLAGS_PL) -c -o $@ $< 125 126# Some targets to build pl/ sources using appropriate flags 127build/pl/%.o: $(srcdir)/pl/%.S 128 $(CC) $(CFLAGS_PL) -c -o $@ $< 129 130build/pl/%.o: $(srcdir)/pl/%.c 131 $(CC) $(CFLAGS_PL) -c -o $@ $< 132 133build/pl/%.os: $(srcdir)/pl/%.S 134 $(CC) $(CFLAGS_PL) -c -o $@ $< 135 136build/pl/%.os: $(srcdir)/pl/%.c 137 $(CC) $(CFLAGS_PL) -c -o $@ $< 138 139build/pl/bin/rtest: $(math-host-objs) 140 $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(HOST_LDLIBS) 141 142build/pl/bin/mathtest: $(B)/test/mathtest.o build/pl/lib/libmathlib.a 143 $(CC) $(CFLAGS_PL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 144 145build/pl/bin/mathbench: $(B)/test/mathbench.o build/pl/lib/libmathlib.a 146 $(CC) $(CFLAGS_PL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 147 148# This is not ideal, but allows custom symbols in mathbench to get resolved. 149build/pl/bin/mathbench_libc: $(B)/test/mathbench.o build/pl/lib/libmathlib.a 150 $(CC) $(CFLAGS_PL) $(LDFLAGS) -static -o $@ $< $(LDLIBS) -lc build/pl/lib/libmathlib.a -lm 151 152build/pl/bin/ulp: $(B)/test/ulp.o build/pl/lib/libmathlib.a 153 $(CC) $(CFLAGS_PL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 154 155build/pl/include/%.h: $(PLM)/include/%.h 156 cp $< $@ 157 158build/pl/include/test/%.h: $(PLM)/test/%.h 159 cp $< $@ 160 161build/pl/bin/%.sh: $(PLM)/test/%.sh 162 cp $< $@ 163 164pl-math-tests := $(wildcard $(PLM)/test/testcases/directed/*.tst) 165pl-math-rtests := $(wildcard $(PLM)/test/testcases/random/*.tst) 166 167check-pl/math-test: $(math-tools) 168 cat $(pl-math-tests) | $(EMULATOR) build/pl/bin/mathtest $(math-testflags) 169 170check-pl/math-rtest: $(math-host-tools) $(math-tools) 171 cat $(pl-math-rtests) | build/pl/bin/rtest | $(EMULATOR) build/pl/bin/mathtest $(math-testflags) 172 173ulp-input-dir=$(B)/test/inputs 174$(ulp-input-dir): 175 mkdir -p $@ 176 177math-lib-lims = $(patsubst $(PLM)/%,$(ulp-input-dir)/%.ulp,$(basename $(pl-lib-srcs))) 178math-lib-fenvs = $(patsubst $(PLM)/%,$(ulp-input-dir)/%.fenv,$(basename $(pl-lib-srcs))) 179math-lib-itvs = $(patsubst $(PLM)/%,$(ulp-input-dir)/%.itv,$(basename $(pl-lib-srcs))) 180 181ulp-inputs = $(math-lib-lims) $(math-lib-fenvs) $(math-lib-itvs) 182 183$(ulp-inputs): CFLAGS_PL += -I$(PLM) -I$(PLM)/include $(math-cflags) 184 185$(ulp-input-dir)/%.ulp: $(PLM)/%.c | $(ulp-input-dir) 186 $(CC) -I$(PLM)/test $(CFLAGS_PL) $< -o - -E | { grep -o "PL_TEST_ULP [^ ]* [^ ]*" || true; } > $@ 187 188$(ulp-input-dir)/%.fenv: $(PLM)/%.c | $(ulp-input-dir) 189 $(CC) -I$(PLM)/test $(CFLAGS_PL) $< -o - -E | { grep -o "PL_TEST_EXPECT_FENV_ENABLED [^ ]*" || true; } > $@ 190 191$(ulp-input-dir)/%.itv: $(PLM)/%.c | $(ulp-input-dir) 192 $(CC) -I$(PLM)/test $(CFLAGS_PL) $< -o - -E | { grep "PL_TEST_INTERVAL " || true; } | sed "s/ PL_TEST_INTERVAL/\nPL_TEST_INTERVAL/g" > $@ 193 194ulp-lims := $(ulp-input-dir)/limits 195$(ulp-lims): $(math-lib-lims) 196 cat $^ | sed "s/PL_TEST_ULP //g;s/^ *//g" > $@ 197 198fenv-exps := $(ulp-input-dir)/fenv 199$(fenv-exps): $(math-lib-fenvs) 200 cat $^ | sed "s/PL_TEST_EXPECT_FENV_ENABLED //g;s/^ *//g" > $@ 201 202ulp-itvs := $(ulp-input-dir)/intervals 203$(ulp-itvs): $(math-lib-itvs) 204 cat $^ | sort -u | sed "s/PL_TEST_INTERVAL //g" > $@ 205 206check-pl/math-ulp: $(math-tools) $(ulp-lims) $(fenv-exps) $(ulp-itvs) 207 WANT_SVE_MATH=$(WANT_SVE_MATH) \ 208 ULPFLAGS="$(math-ulpflags)" \ 209 LIMITS=../../../$(ulp-lims) \ 210 INTERVALS=../../../$(ulp-itvs) \ 211 FENV=../../../$(fenv-exps) \ 212 FUNC=$(func) \ 213 PRED=$(pred) \ 214 build/pl/bin/runulp.sh $(EMULATOR) 215 216check-pl/math: check-pl/math-test check-pl/math-rtest check-pl/math-ulp 217 218$(DESTDIR)$(libdir)/pl/%.so: build/pl/lib/%.so 219 $(INSTALL) -D $< $@ 220 221$(DESTDIR)$(libdir)/pl/%: build/pl/lib/% 222 $(INSTALL) -m 644 -D $< $@ 223 224$(DESTDIR)$(includedir)/pl/%: build/pl/include/% 225 $(INSTALL) -m 644 -D $< $@ 226 227install-pl/math: \ 228 $(pl-libs:build/pl/lib/%=$(DESTDIR)$(libdir)/pl/%) \ 229 $(pl-includes:build/pl/include/%=$(DESTDIR)$(includedir)/pl/%) 230 231clean-pl/math: 232 rm -f $(pl/math-files) 233 234.PHONY: all-pl/math check-pl/math-test check-pl/math-rtest check-pl/math-ulp check-pl/math install-pl/math clean-pl/math 235