forked from hexengraf/lambari
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
110 lines (92 loc) · 4.18 KB
/
Makefile
File metadata and controls
110 lines (92 loc) · 4.18 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
###################### Copyright (C) 2016 Marleson Graf #######################
######################### <github.com/aszdrick/mkm/> ##########################
############################ <aszdrick@gmail.com> #############################
###############################################################################
## Licensed under the Apache License, Version 2.0 (the "License"); ##
## you may not use this file except in compliance with the License. ##
## You may obtain a copy of the License at ##
## ##
## http://www.apache.org/licenses/LICENSE-2.0 ##
## ##
## Unless required by applicable law or agreed to in writing, software ##
## distributed under the License is distributed on an "AS IS" BASIS, ##
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ##
## See the License for the specific language governing permissions and ##
## limitations under the License. ##
###############################################################################
################################## SCALARS ##################################
# Include all Makefile definitions
-include $(wildcard *.mkd)
# Project files
SRC :=$(shell find $(SRCDIR) -name '*.cpp' 2> /dev/null)
DEP :=$(patsubst %.cpp,$(DEPDIR)/%.d,$(SRC))
OBJ :=$(patsubst %.cpp,$(OBJDIR)/%.o,$(SRC))
# Test files
PUREOBJ :=$(filter-out $(OBJDIR)/$(SRCDIR)/$(MAIN).o,$(OBJ))
TSRC :=$(shell find $(TESTDIR) -name '*.cpp' 2> /dev/null)
TMAIN :=$(wildcard $(TESTDIR)/*.cpp)
TDEP :=$(patsubst %.cpp,$(DEPDIR)/%.d,$(TSRC))
TOBJ :=$(patsubst %.cpp,$(OBJDIR)/%.o,$(TSRC))
TPUREOBJ :=$(filter-out $(patsubst %.cpp,$(OBJDIR)/%.o,$(TMAIN)),$(TOBJ))
TEXEC :=$(patsubst $(TESTDIR)/%.cpp,$(BINDIR)/%,$(TMAIN))
TCALL :=$(patsubst %.cpp,%,$(notdir $(TMAIN)))
# MaKefile eXtension variables
MKXDIR :=mkx
MKXVAR :=$(wildcard $(MKXDIR)/*.mxd)
MKXRULE :=$(wildcard $(MKXDIR)/*.mxr)
MKGNR :=$(wildcard *.make)
# Autogenerated directories, usefull to quickly create directories structure
MAKEDIR :=$(BINDIR) $(SRCDIR) $(HDRDIR)
# Printables
CXXPRINT :=$(CXX)
.PHONY: all makedir clean clean_deps clean_all tests
# Include variables used by Makefile Extensions
-include $(MKXVAR)
# Include any other general extension, may override default rule
-include $(MKGNR)
################################# MAIN RULES ##################################
all: makedir $(EXEC)
# Include rules of Makefile Extensions
-include $(MKXRULE)
$(EXEC): $(OBJ)
@echo "[linking] $@"
@$(CXX) $(OBJ) -o $@ $(LDLIBS) $(LDFLAGS)
$(OBJDIR)/%.o: %.cpp
@echo "[$(CXXPRINT)] $< -> .o"
@mkdir -p $(OBJDIR)/$(*D)
@$(CXX) $(CXXFLAGS) $(INCLUDE) -c $< -o $@
# For each .cpp file, creates a .d file with all dependencies of .cpp,
# including .d as target (to ensure up-to-date dependencies, in case of
# new includes being added)
$(DEPDIR)/%.d: %.cpp
@echo "[makedep] $< -> .d"
@mkdir -p $(DEPDIR)/$(*D)
@$(CXX) -MM -MP -MT "$(OBJDIR)/$*.o $@" -MF "$@" $< $(INCLUDE) $(CXXFLAGS)
makedir: | $(MAKEDIR)
$(MAKEDIR):
@echo "[ mkdir ] Creating directory '$@'"
@mkdir -p $@
################################ TESTS RULES ##################################
tests: makedir $(TCALL) $(TEXEC)
$(foreach t,$(TCALL),$(t): $(PUREOBJ) $(TPUREOBJ) $(OBJDIR)/$(TESTDIR)/$(t).o)
$(TEXEC): LDFLAGS+=-lgtest
$(TEXEC): $(PUREOBJ) $(TPUREOBJ) $(TMAIN)
@echo "[linking] $@"
@$(CXX) $(PUREOBJ) $(TOBJ) -o $@ $(LDLIBS) $(LDFLAGS)
################################ CLEAN RULES ##################################
# Only remove object files
clean: $(MKXCLEAN)
@$(RM) -r $(OBJDIR)
# Remove object, binary and dependency files
clean_all: clean $(MKXCLNALL)
@$(RM) -r $(BINDIR)
@$(RM) -r $(DEPDIR)
################################ PREREQUISITES ################################
# Do not include list of dependencies when they are going to be deleted, i.e.,
# when the target is clean_all
ifneq ($(MAKECMDGOALS), clean_all)
-include $(DEP)
ifeq ($(MAKECMDGOALS), tests)
-include $(TDEP)
endif
endif