diff options
-rw-r--r-- | Makefile | 56 | ||||
-rw-r--r-- | config.mk.dist | 48 | ||||
-rw-r--r-- | math/Dir.mk | 98 | ||||
-rw-r--r-- | string/Dir.mk | 47 |
4 files changed, 137 insertions, 112 deletions
@@ -9,31 +9,23 @@ bindir = $(prefix)/bin libdir = $(prefix)/lib includedir = $(prefix)/include -# Build targets -ALL_OBJS = $(math-objs) $(string-objs) -ALL_INCLUDES = $(math-includes) $(string-includes) -ALL_LIBS = $(math-libs) $(string-libs) -ALL_TOOLS = $(math-tools) $(string-tools) -HOST_TOOLS = $(math-host-tools) - # Configure these in config.mk, do not make changes in this file. +SUBS = math string HOST_CC = cc HOST_CFLAGS = -std=c99 -O2 HOST_LDFLAGS = HOST_LDLIBS = EMULATOR = +CPPFLAGS = CFLAGS = -std=c99 -O2 +CFLAGS_SHARED = -fPIC +CFLAGS_ALL = -Ibuild/include $(CPPFLAGS) $(CFLAGS) LDFLAGS = LDLIBS = -CPPFLAGS = AR = $(CROSS_COMPILE)ar RANLIB = $(CROSS_COMPILE)ranlib INSTALL = install -CFLAGS_SHARED = -fPIC -CFLAGS_ALL = -Ibuild/include $(CPPFLAGS) $(CFLAGS) -LDFLAGS_ALL = $(LDFLAGS) - all: -include config.mk @@ -41,17 +33,25 @@ all: include $(srcdir)/math/Dir.mk include $(srcdir)/string/Dir.mk -all: all-math all-string - -DIRS = $(dir $(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(ALL_INCLUDES)) -ALL_DIRS = $(sort $(DIRS:%/=%)) - -$(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(ALL_OBJS:%.o=%.os) $(ALL_INCLUDES): | $(ALL_DIRS) - -$(ALL_DIRS): +# Required targets of subproject foo: +# all-foo +# check-foo +# clean-foo +# install-foo +# Required make variables of subproject foo: +# foo-files: Built files (all in build/). +# Make variables used by subproject foo: +# foo-...: Variables defined in foo/Dir.mk or by config.mk. + +all: $(SUBS:%=all-%) + +ALL_FILES = $(foreach sub,$(SUBS),$($(sub)-files)) +DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_FILES)))) +$(ALL_FILES): | $(DIRS) +$(DIRS): mkdir -p $@ -$(ALL_OBJS:%.o=%.os): CFLAGS_ALL += $(CFLAGS_SHARED) +$(filter %.os,$(ALL_FILES)): CFLAGS_ALL += $(CFLAGS_SHARED) build/%.o: $(srcdir)/%.S $(CC) $(CFLAGS_ALL) -c -o $@ $< @@ -65,7 +65,7 @@ build/%.os: $(srcdir)/%.S build/%.os: $(srcdir)/%.c $(CC) $(CFLAGS_ALL) -c -o $@ $< -clean: +clean: $(SUBS:%=clean-%) rm -rf build distclean: clean @@ -83,14 +83,8 @@ $(DESTDIR)$(libdir)/%: build/lib/% $(DESTDIR)$(includedir)/%: build/include/% $(INSTALL) -m 644 -D $< $@ -install-tools: $(ALL_TOOLS:build/bin/%=$(DESTDIR)$(bindir)/%) - -install-libs: $(ALL_LIBS:build/lib/%=$(DESTDIR)$(libdir)/%) - -install-headers: $(ALL_INCLUDES:build/include/%=$(DESTDIR)$(includedir)/%) - -install: install-libs install-headers +install: $(SUBS:%=install-%) -check: check-math check-string +check: $(SUBS:%=check-%) -.PHONY: all clean distclean install install-tools install-libs install-headers check +.PHONY: all clean distclean install check diff --git a/config.mk.dist b/config.mk.dist index f9f268b..301b5f9 100644 --- a/config.mk.dist +++ b/config.mk.dist @@ -1,8 +1,11 @@ # Example config.mk # -# Copyright (c) 2018, Arm Limited. +# Copyright (c) 2018-2019, Arm Limited. # SPDX-License-Identifier: MIT +# Subprojects to build +SUBS = math string + HOST_CC = gcc HOST_CFLAGS = -std=c99 -O2 HOST_CFLAGS += -Wall -Wno-unused-function @@ -19,31 +22,34 @@ CFLAGS += -g # Optimize the shared libraries on aarch64 assuming they fit in 1M. #CFLAGS_SHARED = -fPIC -mcmodel=tiny +# Use for cross compilation with gcc. +#CROSS_COMPILE = aarch64-none-linux-gnu- + +# Use with cross testing. +#EMULATOR = qemu-aarch64-static +#EMULATOR = sh -c 'scp $$1 user@host:/dir && ssh user@host /dir/"$$@"' -- + +# Additional flags for subprojects. +math-cflags = +math-ldlibs = +math-ulpflags = +math-testflags = +string-cflags = + # Use if mpfr is available on the target for ulp error checking. -#LDLIBS += -lmpfr -lgmp -#CFLAGS += -DUSE_MPFR +#math-ldlibs += -lmpfr -lgmp +#math-cflags += -DUSE_MPFR # Use with gcc. -CFLAGS += -frounding-math -fexcess-precision=standard -fno-stack-protector -CFLAGS += -ffp-contract=fast -fno-math-errno +math-cflags += -frounding-math -fexcess-precision=standard -fno-stack-protector +math-cflags += -ffp-contract=fast -fno-math-errno # Use with clang. -#CFLAGS += -ffp-contract=fast - -# Additional CFLAGS for subprojects. -#math-cflags = -#string-cflags = - -# Disable fenv checks -#ULPFLAGS = -q -f -#MATHTESTFLAGS = -nostatus +#math-cflags += -ffp-contract=fast # Disable vector math code -#CFLAGS += -DWANT_VMATH=0 - -# Use for cross compilation with gcc. -#CROSS_COMPILE = aarch64-none-linux-gnu- +#math-cflags += -DWANT_VMATH=0 -# Use with cross testing. -#EMULATOR = qemu-aarch64-static -#EMULATOR = sh -c 'scp $$1 user@host:/dir && ssh user@host /dir/"$$@"' -- +# Disable fenv checks +#math-ulpflags = -q -f +#math-testflags = -nostatus diff --git a/math/Dir.mk b/math/Dir.mk index a533e1e..3b841ab 100644 --- a/math/Dir.mk +++ b/math/Dir.mk @@ -3,15 +3,18 @@ # Copyright (c) 2019, Arm Limited. # SPDX-License-Identifier: MIT -math-lib-srcs := $(wildcard $(srcdir)/math/*.[cS]) +S := $(srcdir)/math +B := build/math + +math-lib-srcs := $(wildcard $(S)/*.[cS]) math-test-srcs := \ - $(srcdir)/math/test/mathtest.c \ - $(srcdir)/math/test/mathbench.c \ - $(srcdir)/math/test/ulp.c \ + $(S)/test/mathtest.c \ + $(S)/test/mathbench.c \ + $(S)/test/ulp.c \ + +math-test-host-srcs := $(wildcard $(S)/test/rtest/*.[cS]) -math-test-host-srcs := $(wildcard $(srcdir)/math/test/rtest/*.[cS]) -math-includes-src := $(wildcard $(srcdir)/math/include/*.h) -math-includes := $(math-includes-src:$(srcdir)/math/%=build/%) +math-includes := $(patsubst $(S)/%,build/%,$(wildcard $(S)/include/*.h)) math-libs := \ build/lib/libmathlib.so \ @@ -27,34 +30,31 @@ math-tools := \ math-host-tools := \ build/bin/rtest \ -math-lib-base := $(basename $(math-lib-srcs)) -math-lib-objs := $(math-lib-base:$(srcdir)/%=build/%.o) -math-test-base := $(basename $(math-test-srcs)) -math-test-objs := $(math-test-base:$(srcdir)/%=build/%.o) -math-test-host-base := $(basename $(math-test-host-srcs)) -math-test-host-objs := $(math-test-host-base:$(srcdir)/%=build/%.o) +math-lib-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-lib-srcs))) +math-test-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-test-srcs))) +math-host-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(math-test-host-srcs))) +math-target-objs := $(math-lib-objs) $(math-test-objs) +math-objs := $(math-target-objs) $(math-target-objs:%.o=%.os) $(math-host-objs) -math-target-objs := \ - $(math-lib-objs) \ - $(math-test-objs) \ - -math-objs := $(math-target-objs) $(math-test-host-objs) +math-files := \ + $(math-objs) \ + $(math-libs) \ + $(math-tools) \ + $(math-host-tools) \ + $(math-includes) \ all-math: $(math-libs) $(math-tools) $(math-includes) -TESTS = $(wildcard $(srcdir)/math/test/testcases/directed/*.tst) -RTESTS = $(wildcard $(srcdir)/math/test/testcases/random/*.tst) - -$(math-target-objs) $(math-objs:%.o=%.os): $(math-includes) -$(math-target-objs) $(math-objs:%.o=%.os): CFLAGS_ALL += $(math-cflags) -build/math/test/mathtest.o: CFLAGS_ALL += -fmath-errno -$(math-test-host-objs): CC = $(HOST_CC) -$(math-test-host-objs): CFLAGS_ALL = $(HOST_CFLAGS) +$(math-objs): $(math-includes) +$(math-objs): CFLAGS_ALL += $(math-cflags) +$(B)/test/mathtest.o: CFLAGS_ALL += -fmath-errno +$(math-host-objs): CC = $(HOST_CC) +$(math-host-objs): CFLAGS_ALL = $(HOST_CFLAGS) -build/math/test/ulp.o: $(srcdir)/math/test/ulp.h +$(B)/test/ulp.o: $(S)/test/ulp.h build/lib/libmathlib.so: $(math-lib-objs:%.o=%.os) - $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -shared -o $@ $^ + $(CC) $(CFLAGS_ALL) $(LDFLAGS) -shared -o $@ $^ build/lib/libmathlib.a: $(math-lib-objs) rm -f $@ @@ -62,39 +62,49 @@ build/lib/libmathlib.a: $(math-lib-objs) $(RANLIB) $@ $(math-host-tools): HOST_LDLIBS += -lm -lmpfr -lmpc -$(math-tools): LDLIBS += -lm +$(math-tools): LDLIBS += $(math-ldlibs) -lm -build/bin/rtest: $(math-test-host-objs) +build/bin/rtest: $(math-host-objs) $(HOST_CC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o $@ $^ $(HOST_LDLIBS) -build/bin/mathtest: build/math/test/mathtest.o build/lib/libmathlib.a - $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -static -o $@ $^ $(LDLIBS) +build/bin/mathtest: $(B)/test/mathtest.o build/lib/libmathlib.a + $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) -build/bin/mathbench: build/math/test/mathbench.o build/lib/libmathlib.a - $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -static -o $@ $^ $(LDLIBS) +build/bin/mathbench: $(B)/test/mathbench.o build/lib/libmathlib.a + $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) # This is not ideal, but allows custom symbols in mathbench to get resolved. -build/bin/mathbench_libc: build/math/test/mathbench.o build/lib/libmathlib.a - $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -static -o $@ $< $(LDLIBS) -lc build/lib/libmathlib.a -lm +build/bin/mathbench_libc: $(B)/test/mathbench.o build/lib/libmathlib.a + $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $< $(LDLIBS) -lc build/lib/libmathlib.a -lm -build/bin/ulp: build/math/test/ulp.o build/lib/libmathlib.a - $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -static -o $@ $^ $(LDLIBS) +build/bin/ulp: $(B)/test/ulp.o build/lib/libmathlib.a + $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) -build/include/%.h: $(srcdir)/math/include/%.h +build/include/%.h: $(S)/include/%.h cp $< $@ -build/bin/%.sh: $(srcdir)/math/test/%.sh +build/bin/%.sh: $(S)/test/%.sh cp $< $@ +math-tests := $(wildcard $(S)/test/testcases/directed/*.tst) +math-rtests := $(wildcard $(S)/test/testcases/random/*.tst) + check-math-test: $(math-tools) - cat $(TESTS) | $(EMULATOR) build/bin/mathtest $(MATHTESTFLAGS) + cat $(math-tests) | $(EMULATOR) build/bin/mathtest $(math-testflags) check-math-rtest: $(math-host-tools) $(math-tools) - cat $(RTESTS) | build/bin/rtest | $(EMULATOR) build/bin/mathtest $(MATHTESTFLAGS) + cat $(math-rtests) | build/bin/rtest | $(EMULATOR) build/bin/mathtest $(math-testflags) check-math-ulp: $(math-tools) - ULPFLAGS="$(ULPFLAGS)" build/bin/runulp.sh $(EMULATOR) + ULPFLAGS="$(math-ulpflags)" build/bin/runulp.sh $(EMULATOR) check-math: check-math-test check-math-rtest check-math-ulp -.PHONY: all-math check-math-test check-math-rtest check-math-ulp check-math +install-math: \ + $(math-libs:build/lib/%=$(DESTDIR)$(libdir)/%) \ + $(math-includes:build/include/%=$(DESTDIR)$(includedir)/%) + +clean-math: + rm -f $(math-files) + +.PHONY: all-math check-math-test check-math-rtest check-math-ulp check-math install-math clean-math diff --git a/string/Dir.mk b/string/Dir.mk index 0aac3f9..470917a 100644 --- a/string/Dir.mk +++ b/string/Dir.mk @@ -3,10 +3,13 @@ # Copyright (c) 2019, Arm Limited. # SPDX-License-Identifier: MIT -string-lib-srcs := $(wildcard $(srcdir)/string/*.[cS]) -string-includes-src := $(wildcard $(srcdir)/string/include/*.h) -string-includes := $(string-includes-src:$(srcdir)/string/%=build/%) -string-test-srcs := $(wildcard $(srcdir)/string/test/*.c) +S := $(srcdir)/string +B := build/string + +string-lib-srcs := $(wildcard $(S)/*.[cS]) +string-test-srcs := $(wildcard $(S)/test/*.c) + +string-includes := $(patsubst $(S)/%,build/%,$(wildcard $(S)/include/*.h)) string-libs := \ build/lib/libstringlib.so \ @@ -27,35 +30,40 @@ string-tools := \ build/bin/test/strnlen \ build/bin/test/strncmp -string-lib-base := $(basename $(string-lib-srcs)) -string-lib-objs := $(string-lib-base:$(srcdir)/%=build/%.o) -string-test-base := $(basename $(string-test-srcs)) -string-test-objs := $(string-test-base:$(srcdir)/%=build/%.o) +string-lib-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-lib-srcs))) +string-test-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-test-srcs))) string-objs := \ $(string-lib-objs) \ + $(string-lib-objs:%.o=%.os) \ $(string-test-objs) \ +string-files := \ + $(string-objs) \ + $(string-libs) \ + $(string-tools) \ + $(string-includes) \ + all-string: $(string-libs) $(string-tools) $(string-includes) -$(string-objs) $(string-objs:%.o=%.os): $(string-includes) -$(string-objs) $(string-objs:%.o=%.os): CFLAGS_ALL += $(string-cflags) +$(string-objs): $(string-includes) +$(string-objs): CFLAGS_ALL += $(string-cflags) build/lib/libstringlib.so: $(string-lib-objs:%.o=%.os) - $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -shared -o $@ $^ + $(CC) $(CFLAGS_ALL) $(LDFLAGS) -shared -o $@ $^ build/lib/libstringlib.a: $(string-lib-objs) rm -f $@ $(AR) rc $@ $^ $(RANLIB) $@ -build/bin/test/%: build/string/test/%.o build/lib/libstringlib.a - $(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -static -o $@ $^ $(LDLIBS) +build/bin/test/%: $(B)/test/%.o build/lib/libstringlib.a + $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) -build/include/%.h: $(srcdir)/string/include/%.h +build/include/%.h: $(S)/include/%.h cp $< $@ -build/bin/%.sh: $(srcdir)/string/test/%.sh +build/bin/%.sh: $(S)/test/%.sh cp $< $@ check-string: $(string-tools) @@ -73,4 +81,11 @@ check-string: $(string-tools) $(EMULATOR) build/bin/test/strnlen $(EMULATOR) build/bin/test/strncmp -.PHONY: all-string check-string +install-string: \ + $(string-libs:build/lib/%=$(DESTDIR)$(libdir)/%) \ + $(string-includes:build/include/%=$(DESTDIR)$(includedir)/%) + +clean-string: + rm -f $(string-files) + +.PHONY: all-string check-string install-string clean-string |