xref: /freebsd/contrib/arm-optimized-routines/string/Dir.mk (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
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-test-srcs := $(wildcard $(S)/test/*.c)
17string-bench-srcs := $(wildcard $(S)/bench/*.c)
18
19string-includes := $(patsubst $(S)/%,build/%,$(wildcard $(S)/include/*.h))
20
21string-libs := \
22	build/lib/libstringlib.so \
23	build/lib/libstringlib.a \
24
25string-tests := \
26	build/bin/test/memcpy \
27	build/bin/test/memmove \
28	build/bin/test/memset \
29	build/bin/test/memchr \
30	build/bin/test/memrchr \
31	build/bin/test/memcmp \
32	build/bin/test/__mtag_tag_region \
33	build/bin/test/__mtag_tag_zero_region \
34	build/bin/test/strcpy \
35	build/bin/test/stpcpy \
36	build/bin/test/strcmp \
37	build/bin/test/strchr \
38	build/bin/test/strrchr \
39	build/bin/test/strchrnul \
40	build/bin/test/strlen \
41	build/bin/test/strnlen \
42	build/bin/test/strncmp
43
44string-benches := \
45	build/bin/bench/memcpy \
46	build/bin/bench/strlen
47
48string-lib-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-lib-srcs)))
49string-test-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-test-srcs)))
50string-bench-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-bench-srcs)))
51
52string-objs := \
53	$(string-lib-objs) \
54	$(string-lib-objs:%.o=%.os) \
55	$(string-test-objs) \
56	$(string-bench-objs)
57
58string-files := \
59	$(string-objs) \
60	$(string-libs) \
61	$(string-tests) \
62	$(string-benches) \
63	$(string-includes) \
64
65all-string: $(string-libs) $(string-tests) $(string-benches) $(string-includes)
66
67$(string-objs): $(string-includes)
68$(string-objs): CFLAGS_ALL += $(string-cflags)
69
70$(string-test-objs): CFLAGS_ALL += -D_GNU_SOURCE
71
72build/lib/libstringlib.so: $(string-lib-objs:%.o=%.os)
73	$(CC) $(CFLAGS_ALL) $(LDFLAGS) -shared -o $@ $^
74
75build/lib/libstringlib.a: $(string-lib-objs)
76	rm -f $@
77	$(AR) rc $@ $^
78	$(RANLIB) $@
79
80build/bin/test/%: $(B)/test/%.o build/lib/libstringlib.a
81	$(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS)
82
83build/bin/bench/%: $(B)/bench/%.o build/lib/libstringlib.a
84	$(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS)
85
86build/include/%.h: $(S)/include/%.h
87	cp $< $@
88
89build/bin/%.sh: $(S)/test/%.sh
90	cp $< $@
91
92string-tests-out = $(string-tests:build/bin/test/%=build/string/test/%.out)
93
94build/string/test/%.out: build/bin/test/%
95	$(EMULATOR) $^ | tee $@.tmp
96	mv $@.tmp $@
97
98check-string: $(string-tests-out)
99	! grep FAIL $^
100
101bench-string: $(string-benches)
102	$(EMULATOR) build/bin/bench/strlen
103	$(EMULATOR) build/bin/bench/memcpy
104
105install-string: \
106 $(string-libs:build/lib/%=$(DESTDIR)$(libdir)/%) \
107 $(string-includes:build/include/%=$(DESTDIR)$(includedir)/%)
108
109clean-string:
110	rm -f $(string-files)
111endif
112
113.PHONY: all-string bench-string check-string install-string clean-string
114