source: trunk/kBuild/footer.kmk@ 206

Last change on this file since 206 was 205, checked in by bird, 21 years ago

.o aliases for compilation from the editor.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.6 KB
Line 
1# $Id: footer.kmk 205 2004-12-29 19:42:46Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
6# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
7#
8#
9# This file is part of kBuild.
10#
11# kBuild is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version source of the License, or
14# (at your option) any later version.
15#
16# kBuild is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with kBuild; if not, write to the Free Software
23# Foundation, Inc., 59 Temple Place, Suite typetype0, Boston, MA 0sourcetargettargettarget-targettype07 USA
24#
25#
26
27ifndef __footer_kmk__
28# start-of-file-content
29
30#
31# Variables.
32# (Some of these need initialization before including definitions using them.)
33#
34
35# all targets.
36ALL_TARGETS := \
37 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) \
38 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) \
39 $(DLLS) $(DLLS.$(BUILD_TARGET)) \
40 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) \
41 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) \
42 $(OTHERS) $(OTHERS.$(BUILD_TARGET))
43
44# dependency files.
45_DEPFILES :=
46
47# All kind of output files except for _OBJS and _DEPFILES.
48# Compiling or linking definition outputting other things that $@ and any
49# required dependency file must add those output files to this variable.
50_OUT_FILES :=
51
52# all of a type
53_OBJS :=
54_LIBS :=
55_DLLS :=
56_EXES :=
57_SYSMODS:=
58_DIRS :=
59_IMPORT_LIBS :=
60
61# all objs of a specific target
62define def_objs_var
63_OBJS_$target :=
64endef
65$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
66
67#
68# Basic macros
69#
70
71## Figure out the tool for a source
72# @param $target source file
73# @param $source normalized main target
74# @param $type tooltype
75_SOURCE_TOOL = $(strip $(firstword \
76 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) \
77 $($(target)_$(source)_$(type)TOOL) \
78 $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
79 $($(target)_$(source)_TOOL) \
80 $($(target)_$(type)TOOL.$(BUILD_TARGET)) \
81 $($(target)_$(type)TOOL) \
82 $($(target)_TOOL.$(BUILD_TARGET)) \
83 $($(target)_TOOL) \
84 $($(source)_$(type)TOOL.$(BUILD_TARGET)) \
85 $($(source)_$(type)TOOL) \
86 $($(source)_TOOL.$(BUILD_TARGET)) \
87 $($(source)_TOOL) \
88 $($(type)TOOL.$(BUILD_TARGET)) \
89 $($(type)TOOL) \
90 $(TOOL.$(BUILD_TARGET)) \
91 $(TOOL) ))
92
93_SOURCE_TOOL_OLD = $(strip $(firstword \
94 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
95 $($(target)_$(source)_$(type)TOOL) $($target_$source_TOOL) \
96 $($(target)_$(type)TOOL.$(BUILD_TARGET)) $($(target)_TOOL.$(BUILD_TARGET)) \
97 $($(target)_$(type)TOOL) $($target_TOOL) \
98 $($(source)_$(type)TOOL.$(BUILD_TARGET)) $($(source)_TOOL.$(BUILD_TARGET)) \
99 $($(source)_$(type)TOOL) $($(source)_TOOL) \
100 $($(type)TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET)) \
101 $($(type)TOOL) $(TOOL) ))
102
103## Figure out the tool for a target.
104# @param $target normalized target.
105# @param $source tooltype.
106_TARGET_TOOL = $(strip $(firstword \
107 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
108 $($(target)_$(source)TOOL) \
109 $($(target)_TOOL.$(BUILD_TARGET)) \
110 $($(target)_TOOL) \
111 $($(source)TOOL) \
112 $($(source)TOOL.$(BUILD_TARGET)) \
113 $(TOOL.$(BUILD_TARGET)) \
114 $(TOOL) \
115 ))
116
117## Removes the drive letter from a path (if it has one)
118# @param $1 the path
119no-drive=$(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
120
121## Removes the root slash from a path (if it has one)
122# @param $1 the path
123no-root-slash=$(patsubst /%,%,$(1))
124
125## Figure out where to put object files.
126# @param $1 source file
127# @param $2 normalized main target
128_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))
129
130## Figure out where to put object files.
131# @param $1 real target name.
132# @param $2 normalized main target
133_TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(1))))
134
135
136#
137# Check syntax which leads to weird syntax errors.
138#
139
140## Check
141# @param $(target) Target name.
142define def_check_target
143ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))")
144$$(error $(target) have an incorrect template name. Remove any tabs!)
145endif
146endef
147$(foreach target, $(ALL_TARGETS),$(eval $(def_check_target)))
148
149
150#
151# Include templates
152#
153_TEMPLATES := $(TEMPLATE)
154define def_templates
155ifdef $(target)_TEMPLATE
156_TEMPLATES += $($(target)_TEMPLATE)
157endif
158endef
159$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
160_TEMPLATES := $(sort $(_TEMPLATES))
161# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
162
163define def_templates_include
164ifndef TEMPLATE_$(template)
165include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
166endif
167endef
168$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
169
170
171#
172# Common Inheritance
173#
174
175## Inherit defaults property
176# @param $(prop) Property name
177# @param $(target) Target name.
178define def_inherit_defaults_one
179ifndef $(target)_$(prop)
180ifndef $(target)_$(prop).$(BUILD_TARGET)
181ifdef $(prop)
182$$(eval $(target)_$(prop) := $($(prop)))
183endif
184ifdef $(prop).$(BUILD_TARGET)
185$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(prop).$(BUILD_TARGET)))
186endif
187endif
188endif
189endef
190
191## Inherit default properties for one target.
192# A bit tricky this one, but it depends a bit on whether or not TEMPLATE
193# is inherited from the default properties.
194# @param $(target) Target name
195#
196define def_inherit_defaults
197ifdef $(target)_TEMPLATE
198ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_TOOL) $(TEMPLATE_$($(target)_TEMPLATE)_TOOL.$(BUILD_TARGET))),)
199$$(foreach prop,TOOL, $$(eval $$(def_inherit_defaults_one)))
200endif
201ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_SDKS) $(TEMPLATE_$($(target)_TEMPLATE)_SDKS.$(BUILD_TARGET))),)
202$$(foreach prop,SDKS, $$(eval $$(def_inherit_defaults_one)))
203endif
204else
205$$(foreach prop,TEMPLATE TOOL SDKS, $$(eval $$(def_inherit_defaults_one)))
206endif
207endef
208# Inherit default properties.
209# !!!!!!THIS IS MESSY AND NOT NECESSARY!!!!!!
210$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_defaults)))
211
212
213## Inherit one template property in a accumulative manner.
214# @param $(prop) Property name
215# @param $(target) Target name
216# @todo fix the precedence order for some properties.
217define def_inherit_template_one
218ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
219ifndef $(target)_$(prop)
220#$$ (warning dbgtarget: $(target)_$(prop):='$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
221$$(target)_$$(prop) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop))
222endif
223endif
224ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
225ifndef $(target)_$(prop).$(BUILD_TARGET)
226#$$ (warning dbgsource: $(target)_$(prop).$(BUILD_TARGET)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
227$$(target)_$$(prop).$$(BUILD_TARGET) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop).$$(BUILD_TARGET))
228endif
229endif
230endef
231
232## Inherit one template property.
233# @param $(prop) Property name
234# @param $(target) Target name
235define def_inherit_template_one_accumulate
236ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
237#$$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
238$$(eval $(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
239#$$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
240endif
241ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
242#$$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
243$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)))
244endif
245ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)
246#$$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU))
247$$(eval $(target)_$(prop).$(BUILD_TARGET_CPU) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)))
248endif
249ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)
250#$$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
251$$(eval $(target)_$(prop).$(BUILD_TARGET_ARCH) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)))
252endif
253endef
254
255
256## Inherit template properties for on target.
257# @param $(target) Target name.
258define def_inherit_template
259$$(foreach prop, TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL\
260 ,$$(eval $$(def_inherit_template_one)))
261$$(foreach prop,SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS LDFLAGS LIBS LIBPATH \
262 ,$$(eval $$(def_inherit_template_one_accumulate)))
263endef
264# Inherit template properties
265$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_template)))
266
267
268#
269# Include tools
270#
271_TOOLS := $(TOOL)
272define def_tools_target_source
273$(foreach tool,\
274 $($(source)_TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET))\
275 $($(source)_TOOL) $($(target)_$(source)_TOOL)\
276 $($(source)_CTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CTOOL.$(BUILD_TARGET))\
277 $($(source)_CTOOL) $($(target)_$(source)_CTOOL)\
278 $($(source)_CXXTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CXXTOOL.$(BUILD_TARGET))\
279 $($(source)_CXXTOOL) $($(target)_$(source)_CXXTOOL)\
280 $($(source)_ASTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ASTOOL.$(BUILD_TARGET))\
281 $($(source)_ASTOOL) $($(target)_$(source)_ASTOOL)\
282 $($(source)_ARTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ARTOOL.$(BUILD_TARGET))\
283 $($(source)_ARTOOL) $($(target)_$(source)_ARTOOL)\
284 $($(source)_LDTOOL.$(BUILD_TARGET)) $($(target)_$(source)_LDTOOL.$(BUILD_TARGET))\
285 $($(source)_LDTOOL) $($(target)_$(source)_LDTOOL)\
286 ,$(eval _TOOLS += $(tool)))
287endef
288define def_tools_target
289$(foreach tool,\
290 $($(target)_TOOL.$(BUILD_TARGET))\
291 $($(target)_TOOL)\
292 $($(target)_CTOOL.$(BUILD_TARGET))\
293 $($(target)_CTOOL)\
294 $($(target)_CXXTOOL.$(BUILD_TARGET))\
295 $($(target)_CXXTOOL)\
296 $($(target)_ASTOOL.$(BUILD_TARGET))\
297 $($(target)_ASTOOL)\
298 $($(target)_ARTOOL.$(BUILD_TARGET))\
299 $($(target)_ARTOOL)\
300 $($(target)_LDTOOL.$(BUILD_TARGET))\
301 $($(target)_LDTOOL)\
302 ,$(eval _TOOLS += $(tool)))
303$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)) \
304 , $(eval $(def_tools_target_source)))
305endef
306$(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
307_TOOLS := $(sort $(_TOOLS))
308
309define def_tools_include
310ifndef TOOL_$(tool)
311include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
312endif
313endef
314$(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
315
316
317#
318# Include SDKs
319#
320_SDKS := $(SDKS)
321define def_sdks_target_source
322$(foreach sdk, $($(source)_SDKS) $($(source)_SDKS.$(BUILD_TARGET)) $($(source)_SDKS.$(BUILD_MODE)) \
323 $($(target)_$(source)_SDKS) $($(target)_$(source)_SDKS.$(BUILD_TARGET)) $($(target)_$(source)_SDKS.$(BUILD_MODE)), \
324 $(eval _SDKS += $(sdk)))
325endef
326define def_sdks_target
327$(foreach sdk, $($(target)_SDKS) $($(target)_SDKS.$(BUILD_TARGET)) $($(target)_SDKS.$(BUILD_MODE))\
328 , $(eval _SDKS += $(sdk)))
329$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))\
330 , $(eval $(def_sdks_target_source)))
331endef
332$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
333_SDKS := $(sort $(_SDKS))
334
335define def_sdks_include_one
336ifndef SDK_$(sdk)
337include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
338endif
339endef
340$(foreach sdk, $(_SDKS), $(eval $(def_sdks_include_one)))
341
342#
343# Object processing.
344#
345
346
347## Generic macro for processing C, C++ and Assembly sources.
348# @param $(target) Normalized target name.
349# @param $(source) Source file name.
350# @param $(type) Source type. {C,CXX,AS}
351#
352# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
353# @remark I now have a clue. Have to use $$ if not.
354define def_target_source_c_cpp_asm
355#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
356
357$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target),$(type)))
358$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
359$(eval PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase))))
360$(eval dirdep := $(dir $(outbase)).dir_created)
361$(eval defs :=\
362 $(TOOL_$(tool)_DEFS)\
363 $(TOOL_$(tool)_DEFS.$(BUILD_TYPE))\
364 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET))\
365 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_ARCH))\
366 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_CPU))\
367 $(TOOL_$(tool)_$(type)DEFS)\
368 $(TOOL_$(tool)_$(type)DEFS.$(BUILD_TYPE))\
369 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
370 $(SDKS.$(BUILD_TYPE)) \
371 $(SDKS),\
372 $(SDK_$(sdk)_DEFS)\
373 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
374 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
375 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
376 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))\
377 $(SDK_$(sdk)_$(type)DEFS)\
378 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
379 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
380 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
381 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
382 $(DEFS)\
383 $(DEFS.$(BUILD_TYPE))\
384 $(DEFS.$(BUILD_TARGET))\
385 $(DEFS.$(BUILD_TARGET_ARCH))\
386 $(DEFS.$(BUILD_TARGET_CPU))\
387 $($(type)DEFS)\
388 $($(type)DEFS.$(BUILD_TYPE))\
389 $($(type)DEFS.$(BUILD_TARGET))\
390 $($(type)DEFS.$(BUILD_TARGET_ARCH))\
391 $($(type)DEFS.$(BUILD_TARGET_CPU))\
392 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
393 $($(target)_SDKS.$(BUILD_TYPE)) \
394 $($(target)_SDKS),\
395 $(SDK_$(sdk)_DEFS)\
396 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
397 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
398 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
399 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))\
400 $(SDK_$(sdk)_$(type)DEFS)\
401 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
402 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
403 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
404 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
405 $($(target)_DEFS)\
406 $($(target)_DEFS.$(BUILD_TYPE))\
407 $($(target)_DEFS.$(BUILD_TARGET))\
408 $($(target)_DEFS.$(BUILD_TARGET_ARCH))\
409 $($(target)_DEFS.$(BUILD_TARGET_CPU))\
410 $($(target)_$(type)DEFS)\
411 $($(target)_$(type)DEFS.$(BUILD_TYPE))\
412 $($(target)_$(type)DEFS.$(BUILD_TARGET))\
413 $($(target)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
414 $($(target)_$(type)DEFS.$(BUILD_TARGET_CPU))\
415 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
416 $($(source)_SDKS.$(BUILD_TYPE)) \
417 $($(source)_SDKS),\
418 $(SDK_$(sdk)_DEFS)\
419 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
420 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
421 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
422 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))\
423 $(SDK_$(sdk)_$(type)DEFS)\
424 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
425 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
426 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
427 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
428 $($(source)_DEFS)\
429 $($(source)_DEFS.$(BUILD_TYPE))\
430 $($(source)_DEFS.$(BUILD_TARGET))\
431 $($(source)_DEFS.$(BUILD_TARGET_ARCH))\
432 $($(source)_DEFS.$(BUILD_TARGET_CPU))\
433 $($(source)_$(type)DEFS)\
434 $($(source)_$(type)DEFS.$(BUILD_TYPE))\
435 $($(source)_$(type)DEFS.$(BUILD_TARGET))\
436 $($(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
437 $($(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
438 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
439 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
440 $($(target)_$(source)_SDKS),\
441 $(SDK_$(sdk)_DEFS)\
442 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
443 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
444 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
445 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))\
446 $(SDK_$(sdk)_$(type)DEFS)\
447 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
448 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
449 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
450 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
451 $($(target)_$(source)_DEFS)\
452 $($(target)_$(source)_DEFS.$(BUILD_TYPE))\
453 $($(target)_$(source)_DEFS.$(BUILD_TARGET))\
454 $($(target)_$(source)_DEFS.$(BUILD_TARGET_ARCH))\
455 $($(target)_$(source)_DEFS.$(BUILD_TARGET_CPU))\
456 $($(target)_$(source)_$(type)DEFS)\
457 $($(target)_$(source)_$(type)DEFS.$(BUILD_TYPE))\
458 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET))\
459 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
460 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
461 )
462$(eval incs :=\
463 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
464 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
465 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET))\
466 $($(target)_$(source)_$(type)INCS.$(BUILD_TYPE))\
467 $($(target)_$(source)_$(type)INCS)\
468 $($(target)_$(source)_INCS.$(BUILD_TARGET_CPU))\
469 $($(target)_$(source)_INCS.$(BUILD_TARGET_ARCH))\
470 $($(target)_$(source)_INCS.$(BUILD_TARGET))\
471 $($(target)_$(source)_INCS.$(BUILD_TYPE))\
472 $($(target)_$(source)_INCS)\
473 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
474 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
475 $($(target)_$(source)_SDKS),\
476 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
477 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
478 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
479 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
480 $(SDK_$(sdk)_$(type)INCS)\
481 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
482 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
483 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
484 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
485 $(SDK_$(sdk)_INCS))\
486 $($(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
487 $($(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
488 $($(source)_$(type)INCS.$(BUILD_TARGET))\
489 $($(source)_$(type)INCS.$(BUILD_TYPE))\
490 $($(source)_$(type)INCS)\
491 $($(source)_INCS.$(BUILD_TARGET_CPU))\
492 $($(source)_INCS.$(BUILD_TARGET_ARCH))\
493 $($(source)_INCS.$(BUILD_TARGET))\
494 $($(source)_INCS.$(BUILD_TYPE))\
495 $($(source)_INCS)\
496 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
497 $($(source)_SDKS.$(BUILD_TYPE)) \
498 $($(source)_SDKS),\
499 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
500 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
501 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
502 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
503 $(SDK_$(sdk)_$(type)INCS)\
504 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
505 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
506 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
507 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
508 $(SDK_$(sdk)_INCS))\
509 $($(target)_$(type)INCS.$(BUILD_TARGET_CPU))\
510 $($(target)_$(type)INCS.$(BUILD_TARGET_ARCH))\
511 $($(target)_$(type)INCS.$(BUILD_TARGET))\
512 $($(target)_$(type)INCS.$(BUILD_TYPE))\
513 $($(target)_$(type)INCS)\
514 $($(target)_INCS.$(BUILD_TARGET_CPU))\
515 $($(target)_INCS.$(BUILD_TARGET_ARCH))\
516 $($(target)_INCS.$(BUILD_TARGET))\
517 $($(target)_INCS.$(BUILD_TYPE))\
518 $($(target)_INCS)\
519 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
520 $($(target)_SDKS.$(BUILD_TYPE)) \
521 $($(target)_SDKS),\
522 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
523 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
524 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
525 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
526 $(SDK_$(sdk)_$(type)INCS)\
527 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
528 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
529 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
530 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
531 $(SDK_$(sdk)_INCS))\
532 $(INCS.$(BUILD_TARGET_CPU))\
533 $(INCS.$(BUILD_TARGET_ARCH))\
534 $(INCS.$(BUILD_TARGET))\
535 $(INCS.$(BUILD_TYPE))\
536 $(INCS)\
537 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
538 $(SDKS.$(BUILD_TYPE)) \
539 $(SDKS),\
540 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
541 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
542 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
543 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
544 $(SDK_$(sdk)_$(type)INCS)\
545 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
546 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
547 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
548 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
549 $(SDK_$(sdk)_INCS))\
550 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_CPU))\
551 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_ARCH))\
552 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET))\
553 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TYPE))\
554 $(TOOL_$(tool)_$(type)INCS)\
555 )
556$(eval flags :=\
557 $(TOOL_$(tool)_$(type)FLAGS)\
558 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
559 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET))\
560 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
561 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
562 $($(type)FLAGS)\
563 $($(type)FLAGS.$(BUILD_TYPE))\
564 $($(type)FLAGS.$(BUILD_TARGET))\
565 $($(type)FLAGS.$(BUILD_TARGET_ARCH))\
566 $($(type)FLAGS.$(BUILD_TARGET_CPU))\
567 $($(target)_$(type)FLAGS)\
568 $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
569 $($(target)_$(type)FLAGS.$(BUILD_TARGET))\
570 $($(target)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
571 $($(target)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
572 $($(source)_$(type)FLAGS)\
573 $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
574 $($(source)_$(type)FLAGS.$(BUILD_TARGET))\
575 $($(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
576 $($(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
577 $($(target)_$(source)_$(type)FLAGS)\
578 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
579 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET))\
580 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
581 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
582 )
583$(eval objsuff := $(firstword \
584 $($(target)_$(source)_OBJSUFF.$(BUILD_TARGET))\
585 $($(target)_$(source)_OBJSUFF)\
586 $($(source)_OBJSUFF.$(BUILD_TARGET))\
587 $($(source)_OBJSUFF)\
588 $($(target)_OBJSUFF.$(BUILD_TARGET))\
589 $($(target)_OBJSUFF)\
590 $(TOOL_$(tool)_$(type)OBJSUFF.$(BUILD_TARGET))\
591 $(TOOL_$(tool)_$(type)OBJSUFF)\
592 $(SUFF_OBJ)\
593 ))
594$(eval obj := $(outbase)$(objsuff))
595$(eval dep := $(outbase)$(SUFF_DEP))
596$(eval deps := \
597 $($(target)_$(source)_DEPS)\
598 $($(target)_$(source)_DEPS.$(BUILD_TYPE))\
599 $($(target)_$(source)_DEPS.$(BUILD_TARGET))\
600 $($(target)_$(source)_DEPS.$(BUILD_TARGET_ARCH))\
601 $($(target)_$(source)_DEPS.$(BUILD_TARGET_CPU))\
602 $($(source)_DEPS)\
603 $($(source)_DEPS.$(BUILD_TYPE))\
604 $($(source)_DEPS.$(BUILD_TARGET))\
605 $($(target)_DEPS)\
606 $($(target)_DEPS.$(BUILD_TARGET_ARCH))\
607 $($(target)_DEPS.$(BUILD_TARGET_CPU)))
608
609
610#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff) deps=$(deps))
611ifndef TOOL_$(tool)_COMPILE_$(type)
612$$(warning kBuild: TOOL_$(tool)_COMPILE_$(type) is not defined. source=$(source) target=$(target) )
613$$(warning kBuild: tools: \
614 1 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) \
615 2 $($(target)_$(source)_$(type)TOOL) \
616 3 $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
617 4 $($(target)_$(source)_TOOL) \
618 5 $($(target)_$(type)TOOL.$(BUILD_TARGET)) \
619 6 $($(target)_$(type)TOOL) \
620 7 $($(target)_TOOL.$(BUILD_TARGET)) \
621 8 $($(target)_TOOL) \
622 9 $($(source)_$(type)TOOL.$(BUILD_TARGET)) \
623 10 $($(source)_$(type)TOOL) \
624 11 $($(source)_TOOL.$(BUILD_TARGET)) \
625 12 $($(source)_TOOL) \
626 13 $($(type)TOOL.$(BUILD_TARGET)) \
627 14 $($(type)TOOL) \
628 15 $(TOOL.$(BUILD_TARGET)) \
629 16 $(TOOL) )
630endif
631$(eval $(TOOL_$(tool)_COMPILE_$(type)))
632
633$$(notdir $$(obj))::
634 $$(MAKE) -B -f $$(MAKEFILE) $(obj)
635
636$(eval _OBJS_$(target) += $(obj))
637$(eval _DEPFILES += $(dep))
638
639endef
640
641## Generic macro for processing all target sources.
642# @param $(target) Normalized target name.
643define def_target_sources
644#$ (warning def_target_sources)
645# C sources
646$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
647 ,$(eval $(def_target_source_c_cpp_asm)) ))
648
649# C++ sources
650$(foreach type,CXX,$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
651 ,$(eval $(def_target_source_c_cpp_asm)) ))
652
653# ASM sources
654$(foreach type,AS,$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
655 ,$(eval $(def_target_source_c_cpp_asm)) ))
656endef
657
658
659#
660# LIBRARIES
661#
662
663## Library (one).
664# @param $(target) Normalized library (target) name.
665define def_lib
666# library basics
667$(eval tool := $(call _TARGET_TOOL,$(target),AR))
668ifeq ($(tool),)
669$$(error kBuild: Library target $(target) doesn't have a tool defined!)
670endif
671## @todo prefix
672$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
673$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
674$(eval libsuff := $(firstword\
675 $($(target)_LIBSUFF.$(BUILD_TARGET))\
676 $($(target)_LIBSUFF)\
677 $(TOOL_$(tool)_ARLIBSUFF.$(BUILD_TARGET))\
678 $(TOOL_$(tool)_ARLIBSUFF)\
679 $(SUFF_LIB)\
680))
681$(eval lib := $(outbase)$(libsuff))
682$(eval TARGET_$(target) := $(lib))
683
684# source -> object
685$(eval $(def_target_sources))
686
687# library linking
688$(eval tool := $(call _TARGET_TOOL,$(target),AR))
689$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
690$(eval flags :=\
691 $(TOOL_$(tool)_ARFLAGS)\
692 $(TOOL_$(tool)_ARFLAGS.$(BUILD_TYPE))\
693 $(ARFLAGS)\
694 $(ARFLAGS.$(BUILD_TYPE))\
695 $($(target)_ARFLAGS)\
696 $($(target)_ARFLAGS.$(BUILD_TYPE))\
697 )
698$(eval objs = $(_OBJS_$(target)))
699$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
700$(eval dirdep := $(dir $(lib)).dir_created)
701## @todo fix dependencies on makefiles an such
702$(eval deps := $($(target)_DEPS))
703
704$(eval $(TOOL_$(tool)_LINK_LIBRARY))
705
706# publish rule (still need work)
707ifndef $(target)_NOINST
708$(eval publib := $(PATH_LIB)/$(notdir $(lib)))
709$(publib) : $(lib) $(dir $(publib)).dir_created
710 $(CP) $(lib) $(publib)
711
712_LIBS += $(publib)
713_OUT_FILES += $(lib) $(publib)
714else
715_LIBS += $(lib)
716_OUT_FILES += $(lib)
717endif
718_OBJS += $(_OBJS_$(target))
719endef
720
721# Process libraries
722$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(def_lib)))
723
724
725
726#
727# DLLS
728#
729
730## DLL (one).
731# @param $(target) Normalized target (program) name.
732define def_dll
733# dllmod basics
734$(eval tool := $(call _TARGET_TOOL,$(target),LD))
735$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
736$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
737$(eval dllsuff := $(firstword $($(target)_DLLSUFF) $($(target)_DLLSUFF) $(TOOL_$(tool)_LDDLLSUFF) $(SUFF_DLL)))
738$(eval dll := $(outbase)$(dllsuff))
739$(eval TARGET_$(target) := $(dll))
740
741# source -> object
742$(eval $(def_target_sources))
743
744# dllmod linking.
745$(eval tool := $(call _TARGET_TOOL,$(target),LD))
746$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
747$(eval objs = $(_OBJS_$(target)))
748$(eval flags :=\
749 $(TOOL_$(tool)_LDFLAGS)\
750 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
751 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
752 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
753 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
754 $(LDFLAGS)\
755 $(LDFLAGS.$(BUILD_TYPE))\
756 $(LDFLAGS.$(BUILD_TARGET))\
757 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
758 $(LDFLAGS.$(BUILD_TARGET_CPU))\
759 $($(target)_LDFLAGS)\
760 $($(target)_LDFLAGS.$(BUILD_TYPE))\
761 $($(target)_LDFLAGS.$(BUILD_TARGET))\
762 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
763 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
764)
765$(eval libs :=\
766 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
767 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
768 $($(target)_LIBS.$(BUILD_TARGET))\
769 $($(target)_LIBS.$(BUILD_TYPE))\
770 $($(target)_LIBS)\
771 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
772 $($(target)_SDKS.$(BUILD_TYPE)) \
773 $($(target)_SDKS),\
774 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
775 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
776 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
777 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
778 $(SDK_$(sdk)_LIBS))\
779 $(LIBS.$(BUILD_TARGET_CPU))\
780 $(LIBS.$(BUILD_TARGET_ARCH))\
781 $(LIBS.$(BUILD_TARGET))\
782 $(LIBS.$(BUILD_TYPE))\
783 $(LIBS)\
784 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
785 $(SDKS.$(BUILD_TYPE)) \
786 $(SDKS),\
787 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
788 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
789 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
790 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
791 $(SDK_$(sdk)_LIBS))\
792 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
793 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
794 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
795 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
796 $(TOOL_$(tool)_LIBS)\
797)
798$(eval libpath :=\
799 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
800 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
801 $($(target)_LIBPATH.$(BUILD_TARGET))\
802 $($(target)_LIBPATH.$(BUILD_TYPE))\
803 $($(target)_LIBPATH)\
804 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
805 $($(target)_SDKS.$(BUILD_TYPE)) \
806 $($(target)_SDKS),\
807 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
808 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
809 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
810 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
811 $(SDK_$(sdk)_LIBPATH))\
812 $(LIBPATH.$(BUILD_TARGET_CPU))\
813 $(LIBPATH.$(BUILD_TARGET_ARCH))\
814 $(LIBPATH.$(BUILD_TARGET))\
815 $(LIBPATH.$(BUILD_TYPE))\
816 $(LIBPATH)\
817 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
818 $(SDKS.$(BUILD_TYPE)) \
819 $(SDKS),\
820 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
821 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
822 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
823 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
824 $(SDK_$(sdk)_LIBPATH))\
825 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
826 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
827 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
828 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
829 $(TOOL_$(tool)_LIBPATH)\
830)
831$(eval dirdep := $(dir $(dll)).dir_created)
832## @todo fix dependencies
833$(eval deps := $($(target)_DEPS))
834#
835$(eval custom_pre := $(strip $(firstword
836 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
837 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
838 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
839 $($(target)_CUSTOM_PRE)\
840 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
841 $(CUSTOM_PRE.$(BUILD_TARGET))\
842 $(CUSTOM_PRE.$(BUILD_TYPE))\
843 $(CUSTOM_PRE)\
844)))
845$(eval custom_post := $(strip $(firstword
846 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
847 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
848 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
849 $($(target)_CUSTOM_POST)\
850 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
851 $(CUSTOM_POST.$(BUILD_TARGET))\
852 $(CUSTOM_POST.$(BUILD_TYPE))\
853 $(CUSTOM_POST)\
854)))
855$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
856
857ifndef TOOL_$(tool)_LINK_DLL
858$$(warning kBuild: TOOL_$(tool)_LINK_DLL is not defined. target=$(target) )
859$$(warning kBuild: tools: \
860 1 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
861 2 $($(target)_$(source)TOOL) \
862 3 $($(target)_TOOL.$(BUILD_TARGET)) \
863 4 $($(target)_TOOL) \
864 5 $($(source)TOOL) \
865 6 $($(source)TOOL.$(BUILD_TARGET)) \
866 7 $(TOOL.$(BUILD_TARGET)) \
867 8 $(TOOL) )
868endif
869
870$(eval $(TOOL_$(tool)_LINK_DLL))
871
872
873# publish rule (still need work)
874ifndef $(target)_NOINST
875$(eval pubdll := $(PATH_BIN)/$(notdir $(dll)))
876$(pubdll) : $(dll) $(dir $(pubdll)).dir_created
877 $(CP) $(dll) $(pubdll)
878
879$(eval TARGET_PUB_$(target) := $(pubdll))
880_DLLS += $(pubdll)
881_OUT_FILES += $(dll) $(pubdll)
882else
883_DLLS += $(dll)
884_OUT_FILES += $(dll)
885endif
886_OBJS += $(_OBJS_$(target))
887endef
888
889# Process dlls
890$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(def_dll)))
891
892
893
894#
895# Process import libraries.
896#
897# - On OS/2 and windows these are libraries.
898# - On other platforms they are fake DLLs.
899ifeq ($(subst win32,os2,$(BUILD_TARGET)),os2)
900$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_lib)))
901else
902$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_dll)))
903endif
904$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval _IMPORT_LIBS += $(firstword $(TARGET_PUB_$(target)) $(TARGET_$(target)))))
905
906
907#
908# PROGRAMS
909#
910
911## Program (one).
912# @param $(target) Normalized target (program) name.
913define def_program
914# basics
915$(eval tool := $(call _TARGET_TOOL,$(target),LD))
916$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
917$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
918$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
919$(eval exe := $(outbase)$(exesuff))
920$(eval TARGET_$(target) := $(exe))
921
922# source -> object
923$(eval $(def_target_sources))
924
925# more library stuff.
926$(eval tool := $(call _TARGET_TOOL,$(target),LD))
927$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
928$(eval objs = $(_OBJS_$(target)))
929$(eval flags :=\
930 $(TOOL_$(tool)_LDFLAGS)\
931 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
932 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
933 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
934 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
935 $(LDFLAGS)\
936 $(LDFLAGS.$(BUILD_TYPE))\
937 $(LDFLAGS.$(BUILD_TARGET))\
938 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
939 $(LDFLAGS.$(BUILD_TARGET_CPU))\
940 $($(target)_LDFLAGS)\
941 $($(target)_LDFLAGS.$(BUILD_TYPE))\
942 $($(target)_LDFLAGS.$(BUILD_TARGET))\
943 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
944 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
945)
946$(eval libs :=\
947 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
948 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
949 $($(target)_LIBS.$(BUILD_TARGET))\
950 $($(target)_LIBS.$(BUILD_TYPE))\
951 $($(target)_LIBS)\
952 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
953 $($(target)_SDKS.$(BUILD_TYPE)) \
954 $($(target)_SDKS),\
955 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
956 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
957 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
958 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
959 $(SDK_$(sdk)_LIBS))\
960 $(LIBS.$(BUILD_TARGET_CPU))\
961 $(LIBS.$(BUILD_TARGET_ARCH))\
962 $(LIBS.$(BUILD_TARGET))\
963 $(LIBS.$(BUILD_TYPE))\
964 $(LIBS)\
965 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
966 $(SDKS.$(BUILD_TYPE)) \
967 $(SDKS),\
968 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
969 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
970 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
971 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
972 $(SDK_$(sdk)_LIBS))\
973 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
974 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
975 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
976 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
977 $(TOOL_$(tool)_LIBS)\
978)
979$(eval libpath :=\
980 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
981 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
982 $($(target)_LIBPATH.$(BUILD_TARGET))\
983 $($(target)_LIBPATH.$(BUILD_TYPE))\
984 $($(target)_LIBPATH)\
985 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
986 $($(target)_SDKS.$(BUILD_TYPE)) \
987 $($(target)_SDKS),\
988 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
989 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
990 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
991 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
992 $(SDK_$(sdk)_LIBPATH))\
993 $(LIBPATH.$(BUILD_TARGET_CPU))\
994 $(LIBPATH.$(BUILD_TARGET_ARCH))\
995 $(LIBPATH.$(BUILD_TARGET))\
996 $(LIBPATH.$(BUILD_TYPE))\
997 $(LIBPATH)\
998 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
999 $(SDKS.$(BUILD_TYPE)) \
1000 $(SDKS),\
1001 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
1002 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
1003 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1004 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1005 $(SDK_$(sdk)_LIBPATH))\
1006 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
1007 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
1008 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
1009 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
1010 $(TOOL_$(tool)_LIBPATH)\
1011)
1012$(eval dirdep := $(dir $(exe)).dir_created)
1013## @todo fix dependencies
1014$(eval deps := $($(target)_DEPS))
1015#
1016$(eval custom_pre := $(strip $(firstword
1017 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1018 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
1019 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
1020 $($(target)_CUSTOM_PRE)\
1021 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1022 $(CUSTOM_PRE.$(BUILD_TARGET))\
1023 $(CUSTOM_PRE.$(BUILD_TYPE))\
1024 $(CUSTOM_PRE)\
1025)))
1026$(eval custom_post := $(strip $(firstword
1027 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1028 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
1029 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
1030 $($(target)_CUSTOM_POST)\
1031 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1032 $(CUSTOM_POST.$(BUILD_TARGET))\
1033 $(CUSTOM_POST.$(BUILD_TYPE))\
1034 $(CUSTOM_POST)\
1035)))
1036$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
1037
1038$(eval $(TOOL_$(tool)_LINK_PROGRAM))
1039# publish rule (still need work)
1040ifndef $(target)_NOINST
1041$(eval pubexe := $(PATH_BIN)/$(notdir $(exe)))
1042$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
1043 $(CP) $(exe) $(pubexe)
1044
1045_DLLS += $(pubexe)
1046_OUT_FILES += $(exe) $(pubexe)
1047else
1048_DLLS += $(exe)
1049_OUT_FILES += $(exe)
1050endif
1051_OBJS += $(_OBJS_$(target))
1052endef
1053
1054# Process libraries
1055$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(def_program)))
1056
1057
1058
1059#
1060# SYSMODS
1061#
1062
1063## System module (one).
1064# @param $(target) Normalized target (program) name.
1065define def_sysmod
1066# sysmod basics
1067$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1068$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1069$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
1070$(eval syssuff := $(firstword $($(target)_SYSSUFF) $($(target)_SYSSUFF) $(TOOL_$(tool)_LDSYSSUFF) $(SUFF_SYS)))
1071$(eval sys := $(outbase)$(syssuff))
1072$(eval TARGET_$(target) := $(sys))
1073
1074# source -> object
1075$(eval $(def_target_sources))
1076
1077# sysmod linking
1078$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1079$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1080$(eval objs = $(_OBJS_$(target)))
1081$(eval flags :=\
1082 $(TOOL_$(tool)_LDFLAGS)\
1083 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
1084 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
1085 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
1086 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
1087 $(LDFLAGS)\
1088 $(LDFLAGS.$(BUILD_TYPE))\
1089 $(LDFLAGS.$(BUILD_TARGET))\
1090 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
1091 $(LDFLAGS.$(BUILD_TARGET_CPU))\
1092 $($(target)_LDFLAGS)\
1093 $($(target)_LDFLAGS.$(BUILD_TYPE))\
1094 $($(target)_LDFLAGS.$(BUILD_TARGET))\
1095 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
1096 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
1097)
1098$(eval libs :=\
1099 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
1100 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
1101 $($(target)_LIBS.$(BUILD_TARGET))\
1102 $($(target)_LIBS.$(BUILD_TYPE))\
1103 $($(target)_LIBS)\
1104 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
1105 $($(target)_SDKS.$(BUILD_TYPE)) \
1106 $($(target)_SDKS),\
1107 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
1108 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
1109 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
1110 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
1111 $(SDK_$(sdk)_LIBS))\
1112 $(LIBS.$(BUILD_TARGET_CPU))\
1113 $(LIBS.$(BUILD_TARGET_ARCH))\
1114 $(LIBS.$(BUILD_TARGET))\
1115 $(LIBS.$(BUILD_TYPE))\
1116 $(LIBS)\
1117 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
1118 $(SDKS.$(BUILD_TYPE)) \
1119 $(SDKS),\
1120 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
1121 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
1122 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
1123 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
1124 $(SDK_$(sdk)_LIBS))\
1125 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
1126 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
1127 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
1128 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
1129 $(TOOL_$(tool)_LIBS)\
1130)
1131$(eval libpath :=\
1132 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
1133 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
1134 $($(target)_LIBPATH.$(BUILD_TARGET))\
1135 $($(target)_LIBPATH.$(BUILD_TYPE))\
1136 $($(target)_LIBPATH)\
1137 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
1138 $($(target)_SDKS.$(BUILD_TYPE)) \
1139 $($(target)_SDKS),\
1140 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
1141 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
1142 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1143 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1144 $(SDK_$(sdk)_LIBPATH))\
1145 $(LIBPATH.$(BUILD_TARGET_CPU))\
1146 $(LIBPATH.$(BUILD_TARGET_ARCH))\
1147 $(LIBPATH.$(BUILD_TARGET))\
1148 $(LIBPATH.$(BUILD_TYPE))\
1149 $(LIBPATH)\
1150 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
1151 $(SDKS.$(BUILD_TYPE)) \
1152 $(SDKS),\
1153 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
1154 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
1155 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1156 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1157 $(SDK_$(sdk)_LIBPATH))\
1158 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
1159 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
1160 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
1161 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
1162 $(TOOL_$(tool)_LIBPATH)\
1163)
1164$(eval dirdep := $(dir $(sys)).dir_created)
1165## @todo fix dependencies
1166$(eval deps := $($(target)_DEPS))
1167#
1168$(eval custom_pre := $(strip $(firstword
1169 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1170 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
1171 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
1172 $($(target)_CUSTOM_PRE)\
1173 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1174 $(CUSTOM_PRE.$(BUILD_TARGET))\
1175 $(CUSTOM_PRE.$(BUILD_TYPE))\
1176 $(CUSTOM_PRE)\
1177)))
1178$(eval custom_post := $(strip $(firstword
1179 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1180 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
1181 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
1182 $($(target)_CUSTOM_POST)\
1183 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1184 $(CUSTOM_POST.$(BUILD_TARGET))\
1185 $(CUSTOM_POST.$(BUILD_TYPE))\
1186 $(CUSTOM_POST)\
1187)))
1188$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
1189
1190ifndef TOOL_$(tool)_LINK_SYSMOD
1191$$(warning kBuild: TOOL_$(tool)_LINK_SYSMOD is not defined. target=$(target) )
1192$$(warning kBuild: tools: \
1193 1 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
1194 2 $($(target)_$(source)TOOL) \
1195 3 $($(target)_TOOL.$(BUILD_TARGET)) \
1196 4 $($(target)_TOOL) \
1197 5 $($(source)TOOL) \
1198 6 $($(source)TOOL.$(BUILD_TARGET)) \
1199 7 $(TOOL.$(BUILD_TARGET)) \
1200 8 $(TOOL) )
1201endif
1202
1203$(eval $(TOOL_$(tool)_LINK_SYSMOD))
1204
1205# publish rule (still need work)
1206ifndef $(target)_NOINST
1207$(eval pubsys := $(PATH_BIN)/$(notdir $(sys)))
1208$(pubsys): $(sys) $(dir $(pubsys)).dir_created
1209 $(CP) $(sys) $(pubsys)
1210
1211$(eval _SYSMODS += $(pubsys))
1212$(eval _OUT_FILES += $(sys) $(pubsys))
1213else
1214$(eval _SYSMODS += $(sys))
1215$(eval _OUT_FILES += $(sys))
1216endif
1217_OBJS += $(_OBJS_$(target))
1218endef
1219
1220# Process sysmods
1221$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(def_sysmod)))
1222
1223
1224
1225#
1226# OTHERS
1227#
1228_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET))
1229
1230
1231
1232#
1233# DOCS
1234#
1235
1236
1237#
1238# Directories.
1239#
1240_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(sort $(dir $(_OUT_FILES) $(_OBJS)))))
1241
1242define def_createdir
1243$(dirfile):
1244 $(call MSG_Ltarget,Creating directory $$(@D))
1245 $(MKDIR) -p $$(@D)
1246 @echo dir_created > $$@
1247endef
1248
1249$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
1250
1251
1252#
1253# Include dependency files.
1254#
1255$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1256
1257
1258#
1259# PASSES (including directory and makefile walking)
1260#
1261# Do all the default passes if it's unspecified.
1262
1263#PASSES ?= needed libraries binaries others publish
1264PASSES ?= libraries dlls binaries others
1265
1266## Proritized list of the default makefile when walking subdirectories.
1267# The user can overload this list.
1268DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
1269
1270## Subdir
1271# @param $(pass) Lowercase pass name.
1272# @param $(PASS) Uppercase pass name.
1273# @param $(subdir) Subdirectory
1274# @param $(tag) tag to attach to the rule name.
1275define def_pass_subdir
1276pass_$(pass)$(tag)::
1277 $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
1278endef
1279
1280## Submakefile
1281# @param $(pass) Lowercase pass name.
1282# @param $(PASS) Uppercase pass name.
1283# @param $(makefile) Makefile.
1284# @param $(tag) tag to attach to the rule name.
1285define def_pass_makefile
1286pass_$(pass)$(tag)::
1287 $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
1288endef
1289
1290
1291## Execute a pass.
1292# @param $(pass) Lowercase pass name.
1293# @param $(PASS) Uppercase pass name.
1294define def_pass
1295$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)))
1296$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)))
1297$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
1298$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)))
1299
1300$(eval tag:=_before)
1301$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1302$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
1303
1304$(eval tag:=_after)
1305$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1306$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
1307
1308.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1309.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
1310pass_$(pass): \
1311 pass_$(pass)_before \
1312 pass_$(pass)_doit \
1313 pass_$(pass)_after
1314
1315endef
1316
1317
1318## PASS: needed
1319# This pass builds targets which are required for building the rest.
1320pass_needed_doit: $(_NEEDEDS)
1321pass := needed
1322PASS := NEEDED
1323$(eval $(def_pass))
1324
1325## PASS: libraries
1326# This pass builds library targets.
1327pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1328pass := libraries
1329PASS := LIBRARIES
1330$(eval $(def_pass))
1331
1332## PASS: binaries
1333# This pass builds dll targets.
1334pass_dlls_doit: $(_DLLS) $(_OTHER_DLLS)
1335pass := dlls
1336PASS := DLLS
1337$(eval $(def_pass))
1338
1339## PASS: binaries
1340# This pass builds binary targets, i.e. programs, system modules and stuff.
1341pass_binaries_doit: $(_EXES) $(_SYSMODS) $(_OTHER_BINARIES)
1342pass := binaries
1343PASS := BINARIES
1344$(eval $(def_pass))
1345
1346## PASS: others
1347# This pass builds other targets.
1348pass_others_doit: $(_OTHERS)
1349pass := others
1350PASS := OTHERS
1351$(eval $(def_pass))
1352
1353## PASS: publish
1354# This pass installs the built entities to a sandbox area.
1355pass_publish_doit: publish
1356publish::
1357pass := publish
1358PASS := PUBLISH
1359# $(sort).. not nice.
1360SUBDIRS_PUBLISH ?= $(sort $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS_LIBRARIES) $(SUBDIRS_LIBRARIES.$(BUILD_TARGET)) $(SUBDIRS_BINARIES) $(SUBDIRS_BINARIES.$(BUILD_TARGET)) $(SUBDIRS_OTHERS) $(SUBDIRS_OTHERS.$(BUILD_TARGET)))
1361SUBDIRS_AFTER_PUBLISH ?= $(sort $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER_LIBRARIES) $(SUBDIRS_AFTER_LIBRARIES.$(BUILD_TARGET)) $(SUBDIRS_AFTER_BINARIES) $(SUBDIRS_AFTER_BINARIES.$(BUILD_TARGET)) $(SUBDIRS_AFTER_OTHERS) $(SUBDIRS_AFTER_OTHERS.$(BUILD_TARGET)))
1362MAKEFILES_BEFORE_PUBLISH?= $(sort $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_LIBRARIES) $(MAKEFILES_BEFORE_LIBRARIES.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_BINARIES) $(MAKEFILES_BEFORE_BINARIES.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_OTHERS) $(MAKEFILES_BEFORE_OTHERS.$(BUILD_TARGET)))
1363MAKEFILES_AFTER_PUBLISH ?= $(sort $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER_LIBRARIES) $(MAKEFILES_AFTER_LIBRARIES.$(BUILD_TARGET)) $(MAKEFILES_AFTER_BINARIES) $(MAKEFILES_AFTER_BINARIES.$(BUILD_TARGET)) $(MAKEFILES_AFTER_OTHERS) $(MAKEFILES_AFTER_OTHERS.$(BUILD_TARGET)))
1364$(eval $(def_pass))
1365
1366## PASS: packing
1367# This pass processes custom packing rules.
1368pass_packing_doit: packing
1369packing::
1370pass := packing
1371PASS := PACKING
1372$(eval $(def_pass))
1373
1374## PASS: clean
1375# This pass removes all generated files.
1376pass_clean_doit:
1377 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES) $(OTHER_CLEAN)
1378pass := clean
1379PASS := CLEAN
1380$(eval $(def_pass))
1381clean: pass_clean
1382
1383## PASS: nothing
1384# This pass just walks the tree.
1385pass_nothing_doit:
1386 $(call MSG_Ltarget,Did nothing in $(CURDIR))
1387pass := nothing
1388PASS := NOTHING
1389$(eval $(def_pass))
1390nothing: pass_nothing
1391
1392
1393
1394#
1395# THE MAIN RULES
1396#
1397all_recursive: $(foreach pass,$(PASSES),pass_$(pass))
1398
1399rebuild: clean
1400 $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
1401
1402
1403# misc shortcuts.
1404target: needed libraries binaries others
1405objects: $(_OBJS)
1406libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1407dlls: $(_DLLS)
1408programs: $(_EXES)
1409sysmods: $(_SYSMODS)
1410
1411
1412# end-of-file-content
1413__footer_kmk__ := target
1414endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.