1# Makefile fragment - requires GNU make 2# 3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4# See https://llvm.org/LICENSE.txt for license information. 5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 7S := $(srcdir)/math 8B := build/math 9 10math-lib-srcs := $(wildcard $(S)/*.[cS]) 11math-test-srcs := \ 12 $(S)/test/mathtest.c \ 13 $(S)/test/mathbench.c \ 14 $(S)/test/ulp.c \ 15 16math-test-host-srcs := $(wildcard $(S)/test/rtest/*.[cS]) 17 18math-includes := $(patsubst $(S)/%,build/%,$(wildcard $(S)/include/*.h)) 19 20math-libs := \ 21 build/lib/libmathlib.so \ 22 build/lib/libmathlib.a \ 23 24math-tools := \ 25 build/bin/mathtest \ 26 build/bin/mathbench \ 27 build/bin/mathbench_libc \ 28 build/bin/runulp.sh \ 29 build/bin/ulp \ 30 31math-host-tools := \ 32 build/bin/rtest \ 33 34math-lib-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-lib-srcs))) 35math-test-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-test-srcs))) 36math-host-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-test-host-srcs))) 37math-target-objs := $(math-lib-objs) $(math-test-objs) 38math-objs := $(math-target-objs) $(math-target-objs:%.o=%.os) $(math-host-objs) 39 40math-files := \ 41 $(math-objs) \ 42 $(math-libs) \ 43 $(math-tools) \ 44 $(math-host-tools) \ 45 $(math-includes) \ 46 47all-math: $(math-libs) $(math-tools) $(math-includes) 48 49$(math-objs): $(math-includes) 50$(math-objs): CFLAGS_ALL += $(math-cflags) 51$(B)/test/mathtest.o: CFLAGS_ALL += -fmath-errno 52$(math-host-objs): CC = $(HOST_CC) 53$(math-host-objs): CFLAGS_ALL = $(HOST_CFLAGS) 54 55$(B)/test/ulp.o: $(S)/test/ulp.h 56 57build/lib/libmathlib.so: $(math-lib-objs:%.o=%.os) 58 $(CC) $(CFLAGS_ALL) $(LDFLAGS) -shared -o $@ $^ 59 60build/lib/libmathlib.a: $(math-lib-objs) 61 rm -f $@ 62 $(AR) rc $@ $^ 63 $(RANLIB) $@ 64 65$(math-host-tools): HOST_LDLIBS += -lm -lmpfr -lmpc 66$(math-tools): LDLIBS += $(math-ldlibs) -lm 67 68build/bin/rtest: $(math-host-objs) 69 $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(HOST_LDLIBS) 70 71build/bin/mathtest: $(B)/test/mathtest.o build/lib/libmathlib.a 72 $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 73 74build/bin/mathbench: $(B)/test/mathbench.o build/lib/libmathlib.a 75 $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 76 77# This is not ideal, but allows custom symbols in mathbench to get resolved. 78build/bin/mathbench_libc: $(B)/test/mathbench.o build/lib/libmathlib.a 79 $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $< $(LDLIBS) -lc build/lib/libmathlib.a -lm 80 81build/bin/ulp: $(B)/test/ulp.o build/lib/libmathlib.a 82 $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 83 84build/include/%.h: $(S)/include/%.h 85 cp $< $@ 86 87build/bin/%.sh: $(S)/test/%.sh 88 cp $< $@ 89 90math-tests := $(wildcard $(S)/test/testcases/directed/*.tst) 91math-rtests := $(wildcard $(S)/test/testcases/random/*.tst) 92 93check-math-test: $(math-tools) 94 cat $(math-tests) | $(EMULATOR) build/bin/mathtest $(math-testflags) 95 96check-math-rtest: $(math-host-tools) $(math-tools) 97 cat $(math-rtests) | build/bin/rtest | $(EMULATOR) build/bin/mathtest $(math-testflags) 98 99check-math-ulp: $(math-tools) 100 ULPFLAGS="$(math-ulpflags)" build/bin/runulp.sh $(EMULATOR) 101 102check-math: check-math-test check-math-rtest check-math-ulp 103 104install-math: \ 105 $(math-libs:build/lib/%=$(DESTDIR)$(libdir)/%) \ 106 $(math-includes:build/include/%=$(DESTDIR)$(includedir)/%) 107 108clean-math: 109 rm -f $(math-files) 110 111.PHONY: all-math check-math-test check-math-rtest check-math-ulp check-math install-math clean-math 112