-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
80 lines (67 loc) · 2.17 KB
/
makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
-include targets.mk # Userdefined Targets.
-include buildflags.mk # Userdefined Build Flags
-include extraflags.mk # Userdefined Build Flags, not affecting compilation
all: $(target) compile_commands.json
SOURCES != find src -regextype awk -regex '.*\.(c|cc|cpp)'
HEADERS != find include -regextype awk -regex '.*\.(h|hh|hpp)'
OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
DEPENDS := $(addsuffix .d,$(basename $(SOURCES)))
COMPDB := $(addsuffix .compdb,$(SOURCES) $(HEADERS))
PATTERN := %
override LDFLAGS += -L $(realpath .)
override CPPFLAGS += -Iinclude -Isrc
.LIBPATTERNS:=
.PHONY: all clean mostlyclean
.SECONDARY: $(static:%=-l%) $(shared:%=-l%) $(shared) $(static)
.SECONDARY: $(COMPDB) $(OBJECTS)
.DEFAULT_GOAL:=all
# Generate Dependencies
ifneq ($(MAKECMDGOALS:clean%=clean),clean)
-include $(DEPENDS)
%.d: %.c; @$(CC) $(CPPFLAGS) $< -MM -MT $*.o -MT $@ > $@
%.d: %.cc; @$(CXX) $(CPPFLAGS) $< -MM -MT $*.o -MT $@ > $@
%.d: %.cpp; @$(CXX) $(CPPFLAGS) $< -MM -MT $*.o -MT $@ > $@
endif
# Generate compile_commands.json
-include compdb.mk
compile_commands.json: $(COMPDB)
# Depend on buildflags
$(OBJECTS) $(COMPDB): buildflags.mk
# Build Instructions
.SECONDEXPANSION:
$(target): $$(filter src/$$@/%,$(OBJECTS))
$(LINK.o) $^ $(LDLIBS) -o $@
test: export LD_LIBRARY_PATH=$(CURDIR)
test: $(addprefix test_, $(tested))
test_%: %
./$* $(TEST_FLAGS)
# Shared Library Dependency chain
-l%: lib%.so;
$(shared:%=lib%.so): lib%.so: $$*;
$(shared): override CXXFLAGS += -fPIC
$(shared): $$(filter src/$$@/%,$(OBJECTS))
$(LINK.o) -shared -Wl,-soname,lib$@.so $^ $(LDLIBS) -o lib$@.so
# Static Library Dependency chain
-l%: lib%.a;
$(static:%=lib%.a) : lib%.a : $$*;
$(static): $$(filter src/$$@/%,$(OBJECTS))
$(AR) $(ARFLAGS) lib$@.a $?
strip: $(target)
@strip -s $^
profile-generate profile-use: % :
@$(MAKE) clean
@$(MAKE) all CXXFLAGS=-f$*
clang-check: $(SOURCES)
@clang-check -analyze $^
clang-tidy: $(SOURCES)
@clang-tidy -checks='*,-fuchsia-*' $^
clean-depends:
rm -f $(DEPENDS)
clean-compdb:
rm -f $(COMPDB)
@rm -f compile_commands.json
clean-objects:
rm -f $(OBJECTS)
clean: clean-depends clean-compdb clean-objects
rm -f $(target)
rm -f $(shared:%=lib%.so) $(static:%=lib%.a)