llvm-project
101 строка · 2.6 Кб
1# Makefile fragment - requires GNU make
2#
3# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4# See https://llvm.org/LICENSE.txt for license information.
5# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
7S := $(srcdir)/string
8B := build/string
9
10ifeq ($(ARCH),)
11all-string check-string install-string clean-string:
12@echo "*** Please set ARCH in config.mk. ***"
13@exit 1
14else
15
16string-lib-srcs := $(wildcard $(S)/$(ARCH)/*.[cS])
17string-test-srcs := $(wildcard $(S)/test/*.c)
18
19string-includes := $(patsubst $(S)/%,build/%,$(wildcard $(S)/include/*.h))
20
21string-libs := \
22build/lib/libstringlib.so \
23build/lib/libstringlib.a \
24
25string-tools := \
26build/bin/test/memcpy \
27build/bin/test/memmove \
28build/bin/test/memset \
29build/bin/test/memchr \
30build/bin/test/memcmp \
31build/bin/test/strcpy \
32build/bin/test/stpcpy \
33build/bin/test/strcmp \
34build/bin/test/strchr \
35build/bin/test/strrchr \
36build/bin/test/strchrnul \
37build/bin/test/strlen \
38build/bin/test/strnlen \
39build/bin/test/strncmp
40
41string-lib-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-lib-srcs)))
42string-test-objs := $(patsubst $(S)/%,$(B)/%.o,$(basename $(string-test-srcs)))
43
44string-objs := \
45$(string-lib-objs) \
46$(string-lib-objs:%.o=%.os) \
47$(string-test-objs) \
48
49string-files := \
50$(string-objs) \
51$(string-libs) \
52$(string-tools) \
53$(string-includes) \
54
55all-string: $(string-libs) $(string-tools) $(string-includes)
56
57$(string-objs): $(string-includes)
58$(string-objs): CFLAGS_ALL += $(string-cflags)
59
60build/lib/libstringlib.so: $(string-lib-objs:%.o=%.os)
61$(CC) $(CFLAGS_ALL) $(LDFLAGS) -shared -o $@ $^
62
63build/lib/libstringlib.a: $(string-lib-objs)
64rm -f $@
65$(AR) rc $@ $^
66$(RANLIB) $@
67
68build/bin/test/%: $(B)/test/%.o build/lib/libstringlib.a
69$(CC) $(CFLAGS_ALL) $(LDFLAGS) -static -o $@ $^ $(LDLIBS)
70
71build/include/%.h: $(S)/include/%.h
72cp $< $@
73
74build/bin/%.sh: $(S)/test/%.sh
75cp $< $@
76
77check-string: $(string-tools)
78$(EMULATOR) build/bin/test/memcpy
79$(EMULATOR) build/bin/test/memmove
80$(EMULATOR) build/bin/test/memset
81$(EMULATOR) build/bin/test/memchr
82$(EMULATOR) build/bin/test/memcmp
83$(EMULATOR) build/bin/test/strcpy
84$(EMULATOR) build/bin/test/stpcpy
85$(EMULATOR) build/bin/test/strcmp
86$(EMULATOR) build/bin/test/strchr
87$(EMULATOR) build/bin/test/strrchr
88$(EMULATOR) build/bin/test/strchrnul
89$(EMULATOR) build/bin/test/strlen
90$(EMULATOR) build/bin/test/strnlen
91$(EMULATOR) build/bin/test/strncmp
92
93install-string: \
94$(string-libs:build/lib/%=$(DESTDIR)$(libdir)/%) \
95$(string-includes:build/include/%=$(DESTDIR)$(includedir)/%)
96
97clean-string:
98rm -f $(string-files)
99endif
100
101.PHONY: all-string check-string install-string clean-string
102