• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2$(if $(filter $(MAKE_VERSION),3.81),,\
3  $(error These makefile templates requires GNU make version 3.81.))
4
5default:
6
7.PHONY:: FORCE
8
9FORCE:
10
11ifeq ($(strip $(SHOW_CMDS)),)
12quiet := @
13else
14quiet :=
15endif
16
17include $(MK)/basic_defs.mk
18
19#########################################################
20
21# $(call normalize_path,path)
22define normalize_path
23	$(subst \,/,$1)
24endef
25
26
27SRC_ROOT ?= $(PROJECT_DIR)
28
29SRC_ROOT := $(strip $(call normalize_path,$(SRC_ROOT)))
30
31# $(info Entry point curdir = $(CURDIR))
32
33define install-hdr
34  $(quiet) $(INSTALL) $(INSTALL_OPTS) $(1) $(2)
35endef
36
37
38
39
40define OBJ_TEMPLATE
41$(2)/%.$(OBJ_EXT): $(1)/%.cpp
42	$$(call make-cpp-obj-and-depend,$$<,$$@,$$(subst .$(OBJ_EXT),.d,$$@),$$(XFLAGS))
43
44$(2)/%.$(OBJ_EXT): $(1)/%.s
45	$$(call make-asm-obj,$$<,$$@,$$(subst .$(OBJ_EXT),.d,$$@),$$(XFLAGS))
46
47$(2)/%.$(OBJ_EXT): $(1)/%.c
48	$$(call make-c-obj-and-depend,$$<,$$@,$$(subst .$(OBJ_EXT),.d,$$@),$$(XFLAGS))
49endef
50
51
52HOST_ARCH := $(shell uname)
53ifeq ($(HOST_ARCH),Linux)
54    HOST_ARCH := linux
55endif
56ifeq ($(HOST_ARCH),WindowsNT)
57    HOST_ARCH := win32
58endif
59
60
61ifndef ARCHITECTURE
62 ifdef ARCH
63   ARCHITECTURE := $(ARCH)
64 else
65   ARCHITECTURE := $(HOST_ARCH)
66 endif
67endif
68
69BUILD_ARCH := $(ARCHITECTURE)
70
71include $(MK)/$(HOST_ARCH).mk
72
73include $(MK)/$(TOOLSET).mk
74
75# optionally include platform settings
76-include $(MK)/platforms/$(BUILD_ARCH).mk
77
78
79ifeq ($(strip $(BUILD_TARGET)),)
80  OUTPUT_DIR_COMPONENT := $(BUILD_ARCH)
81else
82  OUTPUT_DIR_COMPONENT := $(BUILD_ARCH)/$(BUILD_TARGET)
83endif
84
85BUILD_ROOT := $(subst \,/,$(BUILD_ROOT))
86SRC_ROOT   := $(strip $(call clean-path,$(SRC_ROOT)))
87BUILD_ROOT := $(strip $(call clean-path,$(BUILD_ROOT)))
88
89
90$(if $(findstring $(SRC_ROOT),$(CURDIR)),,$(error The source root, $(SRC_ROOT), is not a prefix of the current dir $(CURDIR)))
91
92DESTDIR := $(BUILD_ROOT)/installed_lib/$(OUTPUT_DIR_COMPONENT)
93INCDESTDIR := $(subst \,/,$(BUILD_ROOT)/installed_include)
94
95ifneq ($(strip $(MK_INFO)),)
96$(info HOST_ARCH = $(HOST_ARCH))
97$(info BUILD_ARCH = $(BUILD_ARCH))
98ifneq (strip($(BUILD_TARGET)),)
99$(info BUILD_TARGET = $(BUILD_TARGET))
100endif
101$(info TOOLSET = $(TOOLSET))
102$(info BUILD_ROOT = $(BUILD_ROOT))
103$(info INCDESTDIR = $(INCDESTDIR))
104endif
105
106# $(call delete_file,file_name)
107define delete_file
108	$(shell $(RM) $1)
109endef
110
111# $(call create_objdir,$(@D))
112define create_objdir
113	$(shell $(MKDIR) $1)
114endef
115
116$(INCDESTDIR)/ALL_HDRS_INSTALLED:
117	@echo Making sure all headers are installed...
118	$(call create_objdir,$(@D))
119	$(quiet) touch $@
120
121$(DESTDIR)/ALL_LIBS_INSTALLED:
122	@echo Making sure all libs are installed...
123	$(call create_objdir,$(@D))
124	$(quiet) touch $@
125
126
127ifneq ($(strip $(BUILD_ROOT)),)
128clean::
129	$(quiet) $(RMDIR) $(BUILD_ROOT)
130endif
131CMD_COMPLETION_TARGETS += clean
132
133define generate_dep
134	@echo "\$$(warning reading DEP)" > DEP
135endef
136
137
138ifneq "$(MAKECMDGOALS)" "clean"
139  ifneq "$(MAKECMDGOALS)" "completion_targets"
140    ifneq "$(MAKECMDGOALS)" "android_make"
141      # include ALL_HDR_INSTALLED file
142      include $(INCDESTDIR)/ALL_HDRS_INSTALLED
143      include $(DESTDIR)/ALL_LIBS_INSTALLED
144    endif
145  endif
146endif
147
148
149#########################################################
150
151#ifeq ($(strip $(COMBINED_COMPILE_AND_DEPEND)),)
152ifndef combined-cxx-compile-depend
153  $(info default definition of combined-cxx-compile-depend)
154  define combined-cxx-compile-depend
155    $(call make-depend,$1,$2,$3,$4)
156    $(quiet) $(CXX) $4 $(CPPFLAGS) $(INCDIRS) $(CXXFLAGS) $(CO)$2 $1
157  endef
158endif
159
160
161# $(call make-cpp-obj-and-depend,source-file,object-file,depend-file,xflags)
162define make-cpp-obj-and-depend
163	@echo Building $2
164	@echo Using $1
165	$(call create_objdir,$(@D))
166	$(call combined-cxx-compile-depend,$1,$2,$3,$4)
167	@echo Done
168endef
169
170define make-asm-obj
171	@echo Building $2
172	@echo Using $1
173	$(call create_objdir,$(@D))
174	$(call assembly-compile,$1,$2,$3,$4)
175endef
176# the following was needed to map cygwin paths back to dos shell
177# 	$(quiet) $(CXX) $(CPPFLAGS) $(CXXFLAGS) $(call map_name,$4) $(CO)$(call map_name,$2) $(call map_name,$1)
178
179#########################################################
180
181# ifeq ($(strip $(COMBINED_COMPILE_AND_DEPEND)),)
182ifndef combined-cc-compile-depend
183  $(info default definition of combined-cc-compile-depend)
184  define combined-cc-compile-depend
185    $(call make-depend,$1,$2,$3,$4)
186    $(quiet) $(CC) $4 $(CPPFLAGS) $(INCDIRS) $(CXXFLAGS) $(CO)$2 $1
187  endef
188endif
189
190
191# $(call make-c-obj-and-depend,source-file,object-file,depend-file,xflags)
192define make-c-obj-and-depend
193	@echo Building $2
194	@echo Using $1
195	$(call create_objdir,$(@D))
196	$(call combined-cc-compile-depend,$1,$2,$3,$4)
197	@echo Done
198endef
199
200#########################################################
201#
202# gnu-win32 make seems to hold the file handle on the directory open after a wildcard operation
203# and that interfered with removing the directory.
204# Hence we would avoid any wildcard operation in doing make clean.
205#
206define set-src-and-obj-names
207SRC_FILENAMES := $(notdir $1)
208REMOTE_SRCS := $$(filter-out $$(SRC_FILENAMES), $1)
209
210REMOTE_DIRS := $$(sort $$(abspath $$(addprefix $2/,$$(dir $$(REMOTE_SRCS)))))
211
212CSRCS := $$(filter %.c,$$(SRC_FILENAMES))
213CCSRCS := $$(filter %.cc,$$(SRC_FILENAMES))
214CPPSRCS := $$(filter %.cpp,$$(SRC_FILENAMES))
215CXXSRCS := $$(filter %.C,$$(SRC_FILENAMES))
216ASMSRCS := $$(filter %.s,$$(SRC_FILENAMES))
217COBJS  := $$(CSRCS:%.c=$$(OBJDIR)/%.$$(OBJ_EXT))
218CPPOBJS := $$(CPPSRCS:%.cpp=$$(OBJDIR)/%.$$(OBJ_EXT))
219CXXOBJS := $$(CXXSRCS:%.C=$$(OBJDIR)/%.$$(OBJ_EXT))
220CCOBJS := $$(CCSRCS:%.cc=$$(OBJDIR)/%.$$(OBJ_EXT))
221ASMOBJS := $$(ASMSRCS:%.s=$$(OBJDIR)/%.$$(OBJ_EXT))
222COMPILED_OBJS := $$(COBJS) $$(CXXOBJS) $$(CCOBJS) $$(CPPOBJS) $$(ASMOBJS)
223
224DEPS := $$(COMPILED_OBJS:%.$$(OBJ_EXT)=%.d)
225ifneq "$(MAKECMDGOALS)" "clean"
226  FOUND_DEPS := $$(wildcard $$(DEPS))
227endif
228MISSING_DEPS := $$(filter-out $$(FOUND_DEPS), $$(DEPS))
229FORCED_OBJS := $$(MISSING_DEPS:%.d=%.$$(OBJ_EXT))
230
231endef
232
233
234
235
236
237#########################################################
238
239LIB_DIRS += $(LIBCOMPFLAG)$(BUILD_ROOT)/installed_lib/$(OUTPUT_DIR_COMPONENT)
240
241
242
243-include $(MK)/dot.mk
244
245DOCDESTDIR := $(BUILD_ROOT)/doc
246
247docs: $(DOCDESTDIR)/ALL_DOCS_INSTALLED
248
249$(DOCDESTDIR)/ALL_DOCS_INSTALLED:
250	@echo Making sure all docs are installed...
251	$(call create_objdir,$(@D))
252	$(quiet) touch $@
253
254.PHONY:: docs
255
256
257completion_targets:
258	@echo $(call purge_duplicates,$(CMD_COMPLETION_TARGETS))
259
260.PHONY:: completion_targets
261
262