1# Makefile fragment - requires GNU make 2# 3# Copyright (c) 2019-2021, Arm Limited. 4# SPDX-License-Identifier: MIT OR Apache-2.0 WITH LLVM-exception 5 6S := $(srcdir)/string 7B := build/string 8 9ifeq ($(ARCH),) 10all-string bench-string check-string install-string clean-string: 11 @echo "*** Please set ARCH in config.mk. ***" 12 @exit 1 13else 14 15string-lib-srcs := $(wildcard $(S)/$(ARCH)/*.[cS]) 16string-lib-srcs += $(wildcard $(S)/$(ARCH)/experimental/*.[cS]) 17string-test-srcs := $(wildcard $(S)/test/*.c) 18string-bench-srcs := $(wildcard $(S)/bench/*.c) 19 20string-arch-include-dir := $(wildcard $(S)/$(ARCH)) 21string-arch-includes := $(wildcard $(S)/$(ARCH)/*.h) 22string-includes := $(patsubst $(S)/%,build/%,$(wildcard $(S)/include/*.h)) 23 24string-libs := \ 25 build/lib/libstringlib.so \ 26 build/lib/libstringlib.a \ 27 28string-tests := \ 29 build/bin/test/memcpy \ 30 build/bin/test/memmove \ 31 build/bin/test/memset \ 32 build/bin/test/memchr \ 33 build/bin/test/memrchr \ 34 build/bin/test/memcmp \ 35 build/bin/test/__mtag_tag_region \ 36 build/bin/test/__mtag_tag_zero_region \ 37 build/bin/test/strcpy \ 38 build/bin/test/stpcpy \ 39 build/bin/test/strcmp \ 40 build/bin/test/strchr \ 41 build/bin/test/strrchr \ 42 build/bin/test/strchrnul \ 43 build/bin/test/strlen \ 44 build/bin/test/strnlen \ 45 build/bin/test/strncmp 46 47string-benches := \ 48 build/bin/bench/memcpy \ 49 build/bin/bench/memset \ 50 build/bin/bench/strlen 51 52string-lib-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-lib-srcs))) 53string-test-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-test-srcs))) 54string-bench-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-bench-srcs))) 55 56string-objs := \ 57 $(string-lib-objs) \ 58 $(string-lib-objs:%.o=%.os) \ 59 $(string-test-objs) \ 60 $(string-bench-objs) 61 62string-files := \ 63 $(string-objs) \ 64 $(string-libs) \ 65 $(string-tests) \ 66 $(string-benches) \ 67 $(string-includes) \ 68 69all-string: $(string-libs) $(string-tests) $(string-benches) $(string-includes) 70 71$(string-objs): $(string-includes) $(string-arch-includes) 72$(string-objs): CFLAGS_ALL += $(string-cflags) -I$(string-arch-include-dir) 73 74$(string-test-objs): CFLAGS_ALL += -D_GNU_SOURCE 75 76build/lib/libstringlib.so: $(string-lib-objs:%.o=%.os) 77 $(CC) $(CFLAGS_ALL) $(LDFLAGS) -shared -o $@ $^ 78 79build/lib/libstringlib.a: $(string-lib-objs) 80 rm -f $@ 81 $(AR) rc $@ $^ 82 $(RANLIB) $@ 83 84build/bin/test/%: $(B)/test/%.o build/lib/libstringlib.a 85 $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 86 87build/bin/bench/%: $(B)/bench/%.o build/lib/libstringlib.a 88 $(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS) 89 90build/include/%.h: $(S)/include/%.h 91 cp $< $@ 92 93build/bin/%.sh: $(S)/test/%.sh 94 cp $< $@ 95 96string-tests-out = $(string-tests:build/bin/test/%=build/string/test/%.out) 97 98build/string/test/%.out: build/bin/test/% 99 $(EMULATOR) $^ | tee $@.tmp 100 mv $@.tmp $@ 101 102check-string: $(string-tests-out) 103 ! grep FAIL $^ 104 105bench-string: $(string-benches) 106 $(EMULATOR) build/bin/bench/strlen 107 $(EMULATOR) build/bin/bench/memcpy 108 $(EMULATOR) build/bin/bench/memset 109 110install-string: \ 111 $(string-libs:build/lib/%=$(DESTDIR)$(libdir)/%) \ 112 $(string-includes:build/include/%=$(DESTDIR)$(includedir)/%) 113 114clean-string: 115 rm -f $(string-files) 116endif 117 118.PHONY: all-string bench-string check-string install-string clean-string 119