131914882SAlex Richardson# Makefile fragment - requires GNU make 231914882SAlex Richardson# 3*072a4ba8SAndrew Turner# Copyright (c) 2019-2022, Arm Limited. 4*072a4ba8SAndrew Turner# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 531914882SAlex Richardson 631914882SAlex RichardsonS := $(srcdir)/math 731914882SAlex RichardsonB := build/math 831914882SAlex Richardson 931914882SAlex Richardsonmath-lib-srcs := $(wildcard $(S)/*.[cS]) 1031914882SAlex Richardsonmath-test-srcs := \ 1131914882SAlex Richardson $(S)/test/mathtest.c \ 1231914882SAlex Richardson $(S)/test/mathbench.c \ 1331914882SAlex Richardson $(S)/test/ulp.c \ 1431914882SAlex Richardson 1531914882SAlex Richardsonmath-test-host-srcs := $(wildcard $(S)/test/rtest/*.[cS]) 1631914882SAlex Richardson 1731914882SAlex Richardsonmath-includes := $(patsubst $(S)/%,build/%,$(wildcard $(S)/include/*.h)) 18*072a4ba8SAndrew Turnermath-test-includes := $(patsubst $(S)/%,build/include/%,$(wildcard $(S)/test/*.h)) 1931914882SAlex Richardson 2031914882SAlex Richardsonmath-libs := \ 2131914882SAlex Richardson build/lib/libmathlib.so \ 2231914882SAlex Richardson build/lib/libmathlib.a \ 2331914882SAlex Richardson 2431914882SAlex Richardsonmath-tools := \ 2531914882SAlex Richardson build/bin/mathtest \ 2631914882SAlex Richardson build/bin/mathbench \ 2731914882SAlex Richardson build/bin/mathbench_libc \ 2831914882SAlex Richardson build/bin/runulp.sh \ 2931914882SAlex Richardson build/bin/ulp \ 3031914882SAlex Richardson 3131914882SAlex Richardsonmath-host-tools := \ 3231914882SAlex Richardson build/bin/rtest \ 3331914882SAlex Richardson 3431914882SAlex Richardsonmath-lib-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-lib-srcs))) 3531914882SAlex Richardsonmath-test-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-test-srcs))) 3631914882SAlex Richardsonmath-host-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-test-host-srcs))) 3731914882SAlex Richardsonmath-target-objs := $(math-lib-objs) $(math-test-objs) 3831914882SAlex Richardsonmath-objs := $(math-target-objs) $(math-target-objs:%.o=%.os) $(math-host-objs) 3931914882SAlex Richardson 4031914882SAlex Richardsonmath-files := \ 4131914882SAlex Richardson $(math-objs) \ 4231914882SAlex Richardson $(math-libs) \ 4331914882SAlex Richardson $(math-tools) \ 4431914882SAlex Richardson $(math-host-tools) \ 4531914882SAlex Richardson $(math-includes) \ 46*072a4ba8SAndrew Turner $(math-test-includes) \ 4731914882SAlex Richardson 48*072a4ba8SAndrew Turnerall-math: $(math-libs) $(math-tools) $(math-includes) $(math-test-includes) 4931914882SAlex Richardson 50*072a4ba8SAndrew Turner$(math-objs): $(math-includes) $(math-test-includes) 5131914882SAlex Richardson$(math-objs): CFLAGS_ALL += $(math-cflags) 5231914882SAlex Richardson$(B)/test/mathtest.o: CFLAGS_ALL += -fmath-errno 5331914882SAlex Richardson$(math-host-objs): CC = $(HOST_CC) 5431914882SAlex Richardson$(math-host-objs): CFLAGS_ALL = $(HOST_CFLAGS) 5531914882SAlex Richardson 5631914882SAlex Richardson$(B)/test/ulp.o: $(S)/test/ulp.h 5731914882SAlex Richardson 5831914882SAlex Richardsonbuild/lib/libmathlib.so: $(math-lib-objs:%.o=%.os) 5931914882SAlex Richardson $(CC) $(CFLAGS_ALL) $(LDFLAGS) -shared -o $@ $^ 6031914882SAlex Richardson 6131914882SAlex Richardsonbuild/lib/libmathlib.a: $(math-lib-objs) 6231914882SAlex Richardson rm -f $@ 6331914882SAlex Richardson $(AR) rc $@ $^ 6431914882SAlex Richardson $(RANLIB) $@ 6531914882SAlex Richardson 6631914882SAlex Richardson$(math-host-tools): HOST_LDLIBS += -lm -lmpfr -lmpc 6731914882SAlex Richardson$(math-tools): LDLIBS += $(math-ldlibs) -lm 6831914882SAlex Richardson 6931914882SAlex Richardsonbuild/bin/rtest: $(math-host-objs) 7031914882SAlex Richardson $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(HOST_LDLIBS) 7131914882SAlex Richardson 7231914882SAlex Richardsonbuild/bin/mathtest: $(B)/test/mathtest.o build/lib/libmathlib.a 7331914882SAlex Richardson $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 7431914882SAlex Richardson 7531914882SAlex Richardsonbuild/bin/mathbench: $(B)/test/mathbench.o build/lib/libmathlib.a 7631914882SAlex Richardson $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 7731914882SAlex Richardson 7831914882SAlex Richardson# This is not ideal, but allows custom symbols in mathbench to get resolved. 7931914882SAlex Richardsonbuild/bin/mathbench_libc: $(B)/test/mathbench.o build/lib/libmathlib.a 8031914882SAlex Richardson $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $< $(LDLIBS) -lc build/lib/libmathlib.a -lm 8131914882SAlex Richardson 8231914882SAlex Richardsonbuild/bin/ulp: $(B)/test/ulp.o build/lib/libmathlib.a 8331914882SAlex Richardson $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 8431914882SAlex Richardson 8531914882SAlex Richardsonbuild/include/%.h: $(S)/include/%.h 8631914882SAlex Richardson cp $< $@ 8731914882SAlex Richardson 88*072a4ba8SAndrew Turnerbuild/include/test/%.h: $(S)/test/%.h 89*072a4ba8SAndrew Turner cp $< $@ 90*072a4ba8SAndrew Turner 9131914882SAlex Richardsonbuild/bin/%.sh: $(S)/test/%.sh 9231914882SAlex Richardson cp $< $@ 9331914882SAlex Richardson 9431914882SAlex Richardsonmath-tests := $(wildcard $(S)/test/testcases/directed/*.tst) 9531914882SAlex Richardsonmath-rtests := $(wildcard $(S)/test/testcases/random/*.tst) 9631914882SAlex Richardson 9731914882SAlex Richardsoncheck-math-test: $(math-tools) 9831914882SAlex Richardson cat $(math-tests) | $(EMULATOR) build/bin/mathtest $(math-testflags) 9931914882SAlex Richardson 10031914882SAlex Richardsoncheck-math-rtest: $(math-host-tools) $(math-tools) 10131914882SAlex Richardson cat $(math-rtests) | build/bin/rtest | $(EMULATOR) build/bin/mathtest $(math-testflags) 10231914882SAlex Richardson 10331914882SAlex Richardsoncheck-math-ulp: $(math-tools) 104*072a4ba8SAndrew Turner ULPFLAGS="$(math-ulpflags)" WANT_SIMD_EXCEPT="$(WANT_SIMD_EXCEPT)" build/bin/runulp.sh $(EMULATOR) 10531914882SAlex Richardson 10631914882SAlex Richardsoncheck-math: check-math-test check-math-rtest check-math-ulp 10731914882SAlex Richardson 10831914882SAlex Richardsoninstall-math: \ 10931914882SAlex Richardson $(math-libs:build/lib/%=$(DESTDIR)$(libdir)/%) \ 11031914882SAlex Richardson $(math-includes:build/include/%=$(DESTDIR)$(includedir)/%) 11131914882SAlex Richardson 11231914882SAlex Richardsonclean-math: 11331914882SAlex Richardson rm -f $(math-files) 11431914882SAlex Richardson 11531914882SAlex Richardson.PHONY: all-math check-math-test check-math-rtest check-math-ulp check-math install-math clean-math 116