1# Makefile - requires GNU make 2# 3# Copyright (c) 2018, Arm Limited. 4# SPDX-License-Identifier: MIT 5 6srcdir = . 7prefix = /usr 8bindir = $(prefix)/bin 9libdir = $(prefix)/lib 10includedir = $(prefix)/include 11 12MATH_SRCS = $(wildcard $(srcdir)/math/*.[cS]) 13MATH_BASE = $(basename $(MATH_SRCS)) 14MATH_OBJS = $(MATH_BASE:$(srcdir)/%=build/%.o) 15RTEST_SRCS = $(wildcard $(srcdir)/test/rtest/*.[cS]) 16RTEST_BASE = $(basename $(RTEST_SRCS)) 17RTEST_OBJS = $(RTEST_BASE:$(srcdir)/%=build/%.o) 18ALL_OBJS = $(MATH_OBJS) \ 19 $(RTEST_OBJS) \ 20 build/test/mathtest.o \ 21 build/test/mathbench.o \ 22 23INCLUDES = $(wildcard $(srcdir)/math/include/*.h) 24ALL_INCLUDES = $(INCLUDES:$(srcdir)/math/%=build/%) 25 26ALL_LIBS = \ 27 build/lib/libmathlib.so \ 28 build/lib/libmathlib.a \ 29 30ALL_TOOLS = \ 31 build/bin/mathtest \ 32 build/bin/mathbench \ 33 build/bin/mathbench_libc \ 34 35HOST_TOOLS = \ 36 build/bin/rtest \ 37 38TESTS = $(wildcard $(srcdir)/test/testcases/directed/*.tst) 39RTESTS = $(wildcard $(srcdir)/test/testcases/random/*.tst) 40 41# Configure these in config.mk, do not make changes in this file. 42HOST_CC = cc 43HOST_CFLAGS = -std=c99 -O2 44HOST_LDFLAGS = 45HOST_LDLIBS = -lm -lmpfr -lmpc 46EMULATOR = 47CFLAGS = -std=c99 -O2 48LDFLAGS = 49LDLIBS = -lm 50CPPFLAGS = 51AR = $(CROSS_COMPILE)ar 52RANLIB = $(CROSS_COMPILE)ranlib 53INSTALL = install 54 55CFLAGS_ALL = -I$(srcdir)/math/include $(CPPFLAGS) $(CFLAGS) 56LDFLAGS_ALL = $(LDFLAGS) 57 58-include config.mk 59 60all: $(ALL_LIBS) $(ALL_TOOLS) $(ALL_INCLUDES) 61 62DIRS = $(dir $(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(ALL_INCLUDES)) 63ALL_DIRS = $(sort $(DIRS:%/=%)) 64 65$(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(ALL_OBJS:%.o=%.os) $(ALL_INCLUDES): | $(ALL_DIRS) 66 67$(ALL_DIRS): 68 mkdir -p $@ 69 70$(ALL_OBJS:%.o=%.os): CFLAGS_ALL += -fPIC 71 72$(RTEST_OBJS): CC = $(HOST_CC) 73$(RTEST_OBJS): CFLAGS_ALL = $(HOST_CFLAGS) 74 75build/test/mathtest.o: CFLAGS_ALL += -fmath-errno 76 77build/%.o: $(srcdir)/%.S 78 $(CC) $(CFLAGS_ALL) -c -o $@ $< 79 80build/%.o: $(srcdir)/%.c 81 $(CC) $(CFLAGS_ALL) -c -o $@ $< 82 83build/%.os: $(srcdir)/%.S 84 $(CC) $(CFLAGS_ALL) -c -o $@ $< 85 86build/%.os: $(srcdir)/%.c 87 $(CC) $(CFLAGS_ALL) -c -o $@ $< 88 89build/lib/libmathlib.so: $(MATH_OBJS:%.o=%.os) 90 $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -shared -o $@ $^ 91 92build/lib/libmathlib.a: $(MATH_OBJS) 93 rm -f $@ 94 $(AR) rc $@ $^ 95 $(RANLIB) $@ 96 97build/bin/rtest: $(RTEST_OBJS) 98 $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(HOST_LDLIBS) 99 100build/bin/mathtest: build/test/mathtest.o build/lib/libmathlib.a 101 $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -static -o $@ $^ $(LDLIBS) 102 103build/bin/mathbench: build/test/mathbench.o build/lib/libmathlib.a 104 $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -static -o $@ $^ $(LDLIBS) 105 106build/bin/mathbench_libc: build/test/mathbench.o 107 $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -static -o $@ $^ $(LDLIBS) 108 109build/include/%.h: $(srcdir)/math/include/%.h 110 cp $< $@ 111 112clean: 113 rm -rf build 114 115distclean: clean 116 rm -f config.mk 117 118$(DESTDIR)$(bindir)/%: build/bin/% 119 $(INSTALL) -D $< $@ 120 121$(DESTDIR)$(libdir)/%.so: build/lib/%.so 122 $(INSTALL) -D $< $@ 123 124$(DESTDIR)$(libdir)/%: build/lib/% 125 $(INSTALL) -m 644 -D $< $@ 126 127$(DESTDIR)$(includedir)/%: build/include/% 128 $(INSTALL) -m 644 -D $< $@ 129 130install-tools: $(ALL_TOOLS:build/bin/%=$(DESTDIR)$(bindir)/%) 131 132install-libs: $(ALL_LIBS:build/lib/%=$(DESTDIR)$(libdir)/%) 133 134install-headers: $(ALL_INCLUDES:build/include/%=$(DESTDIR)$(includedir)/%) 135 136install: install-libs install-headers 137 138check: $(ALL_TOOLS) 139 cat $(TESTS) | $(EMULATOR) build/bin/mathtest 140 141rcheck: $(HOST_TOOLS) $(ALL_TOOLS) 142 cat $(RTESTS) | build/bin/rtest | $(EMULATOR) build/bin/mathtest 143 144check-all: check rcheck 145 146.PHONY: all clean distclean install install-tools install-libs install-headers check rcheck check-all 147