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