-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon_rules.mk
47 lines (37 loc) · 1.27 KB
/
common_rules.mk
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
NOT_IN_GIT_REPO := $(shell git rev-parse --short HEAD >/dev/null 2>/dev/null; echo $$?)
ifneq ($(NOT_IN_GIT_REPO),0)
GEN_GIT_REV := gen_git_rev
GIT_REVISION := 0
else
GIT_REVISION := $(shell git rev-parse --short HEAD)
REV_NOT_UP_TO_DATE := $(shell grep $(GIT_REVISION) include/git_rev.h >/dev/null 2>/dev/null; echo $$?)
ifneq ($(REV_NOT_UP_TO_DATE),0)
GEN_GIT_REV := gen_git_rev
endif
endif
BINARY_PATH=../bin
TARGET_BINARIES=$(foreach binary,$(TARGETS),$(BINARY_PATH)/$(binary))
# Rules
all : $(GEN_GIT_REV) $(DEPENDENCIES) $(TARGETS) $(TARGET_BINARIES)
$(info Finished building $(TARGETS))
gen_git_rev :
echo "#define GIT_REVISION 0x$(GIT_REVISION)" > include/git_rev.h
# Link the targets (use implicit built-in rule)
$(TARGETS) : % : $(XOBJS) %.o $(A_LIBS)
# Copy the binaries to the binary directory
$(BINARY_PATH)/% : %
cp $< $@
# Do not include the depency rules for "clean"
ifneq ($(MAKECMDGOALS),clean)
-include $(DEPENDENCIES)
endif
# Rules to generate the dependency files
%.d : %.cpp
$(CXX) $(INCLUDE_DIRS) -MG -MP -MM -MT '$(@:.d=.o)' $< -MF $@
%.d : %.c
$(CXX) $(INCLUDE_DIRS) -MG -MP -MM -MT '$(@:.d=.o)' $< -MF $@
# Remove artifacts
clean :
rm -f $(TARGETS) $(DEPENDENCIES) $(CPP_OBJS)
# Rules that don't generate artifacts
.PHONY : all clean gen_git_rev