source: trunk/kBuild/footer.kmk@ 215

Last change on this file since 215 was 207, checked in by bird, 21 years ago

.o and .obj editor rules.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.7 KB
Line 
1# $Id: footer.kmk 207 2004-12-29 22:40:11Z 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$$(basename $$(notdir $$(obj))).o::
634 $$(MAKE) -B -f $$(MAKEFILE) $(obj)
635$$(basename $$(notdir $$(obj))).obj::
636 $$(MAKE) -B -f $$(MAKEFILE) $(obj)
637
638$(eval _OBJS_$(target) += $(obj))
639$(eval _DEPFILES += $(dep))
640
641endef
642
643## Generic macro for processing all target sources.
644# @param $(target) Normalized target name.
645define def_target_sources
646#$ (warning def_target_sources)
647# C sources
648$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
649 ,$(eval $(def_target_source_c_cpp_asm)) ))
650
651# C++ sources
652$(foreach type,CXX,$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
653 ,$(eval $(def_target_source_c_cpp_asm)) ))
654
655# ASM sources
656$(foreach type,AS,$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
657 ,$(eval $(def_target_source_c_cpp_asm)) ))
658endef
659
660
661#
662# LIBRARIES
663#
664
665## Library (one).
666# @param $(target) Normalized library (target) name.
667define def_lib
668# library basics
669$(eval tool := $(call _TARGET_TOOL,$(target),AR))
670ifeq ($(tool),)
671$$(error kBuild: Library target $(target) doesn't have a tool defined!)
672endif
673## @todo prefix
674$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
675$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
676$(eval libsuff := $(firstword\
677 $($(target)_LIBSUFF.$(BUILD_TARGET))\
678 $($(target)_LIBSUFF)\
679 $(TOOL_$(tool)_ARLIBSUFF.$(BUILD_TARGET))\
680 $(TOOL_$(tool)_ARLIBSUFF)\
681 $(SUFF_LIB)\
682))
683$(eval lib := $(outbase)$(libsuff))
684$(eval TARGET_$(target) := $(lib))
685
686# source -> object
687$(eval $(def_target_sources))
688
689# library linking
690$(eval tool := $(call _TARGET_TOOL,$(target),AR))
691$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
692$(eval flags :=\
693 $(TOOL_$(tool)_ARFLAGS)\
694 $(TOOL_$(tool)_ARFLAGS.$(BUILD_TYPE))\
695 $(ARFLAGS)\
696 $(ARFLAGS.$(BUILD_TYPE))\
697 $($(target)_ARFLAGS)\
698 $($(target)_ARFLAGS.$(BUILD_TYPE))\
699 )
700$(eval objs = $(_OBJS_$(target)))
701$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
702$(eval dirdep := $(dir $(lib)).dir_created)
703## @todo fix dependencies on makefiles an such
704$(eval deps := $($(target)_DEPS))
705
706$(eval $(TOOL_$(tool)_LINK_LIBRARY))
707
708# publish rule (still need work)
709ifndef $(target)_NOINST
710$(eval publib := $(PATH_LIB)/$(notdir $(lib)))
711$(publib) : $(lib) $(dir $(publib)).dir_created
712 $(CP) $(lib) $(publib)
713
714_LIBS += $(publib)
715_OUT_FILES += $(lib) $(publib)
716else
717_LIBS += $(lib)
718_OUT_FILES += $(lib)
719endif
720_OBJS += $(_OBJS_$(target))
721endef
722
723# Process libraries
724$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(def_lib)))
725
726
727
728#
729# DLLS
730#
731
732## DLL (one).
733# @param $(target) Normalized target (program) name.
734define def_dll
735# dllmod basics
736$(eval tool := $(call _TARGET_TOOL,$(target),LD))
737$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
738$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
739$(eval dllsuff := $(firstword $($(target)_DLLSUFF) $($(target)_DLLSUFF) $(TOOL_$(tool)_LDDLLSUFF) $(SUFF_DLL)))
740$(eval dll := $(outbase)$(dllsuff))
741$(eval TARGET_$(target) := $(dll))
742
743# source -> object
744$(eval $(def_target_sources))
745
746# dllmod linking.
747$(eval tool := $(call _TARGET_TOOL,$(target),LD))
748$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
749$(eval objs = $(_OBJS_$(target)))
750$(eval flags :=\
751 $(TOOL_$(tool)_LDFLAGS)\
752 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
753 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
754 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
755 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
756 $(LDFLAGS)\
757 $(LDFLAGS.$(BUILD_TYPE))\
758 $(LDFLAGS.$(BUILD_TARGET))\
759 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
760 $(LDFLAGS.$(BUILD_TARGET_CPU))\
761 $($(target)_LDFLAGS)\
762 $($(target)_LDFLAGS.$(BUILD_TYPE))\
763 $($(target)_LDFLAGS.$(BUILD_TARGET))\
764 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
765 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
766)
767$(eval libs :=\
768 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
769 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
770 $($(target)_LIBS.$(BUILD_TARGET))\
771 $($(target)_LIBS.$(BUILD_TYPE))\
772 $($(target)_LIBS)\
773 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
774 $($(target)_SDKS.$(BUILD_TYPE)) \
775 $($(target)_SDKS),\
776 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
777 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
778 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
779 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
780 $(SDK_$(sdk)_LIBS))\
781 $(LIBS.$(BUILD_TARGET_CPU))\
782 $(LIBS.$(BUILD_TARGET_ARCH))\
783 $(LIBS.$(BUILD_TARGET))\
784 $(LIBS.$(BUILD_TYPE))\
785 $(LIBS)\
786 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
787 $(SDKS.$(BUILD_TYPE)) \
788 $(SDKS),\
789 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
790 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
791 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
792 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
793 $(SDK_$(sdk)_LIBS))\
794 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
795 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
796 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
797 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
798 $(TOOL_$(tool)_LIBS)\
799)
800$(eval libpath :=\
801 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
802 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
803 $($(target)_LIBPATH.$(BUILD_TARGET))\
804 $($(target)_LIBPATH.$(BUILD_TYPE))\
805 $($(target)_LIBPATH)\
806 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
807 $($(target)_SDKS.$(BUILD_TYPE)) \
808 $($(target)_SDKS),\
809 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
810 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
811 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
812 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
813 $(SDK_$(sdk)_LIBPATH))\
814 $(LIBPATH.$(BUILD_TARGET_CPU))\
815 $(LIBPATH.$(BUILD_TARGET_ARCH))\
816 $(LIBPATH.$(BUILD_TARGET))\
817 $(LIBPATH.$(BUILD_TYPE))\
818 $(LIBPATH)\
819 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
820 $(SDKS.$(BUILD_TYPE)) \
821 $(SDKS),\
822 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
823 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
824 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
825 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
826 $(SDK_$(sdk)_LIBPATH))\
827 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
828 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
829 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
830 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
831 $(TOOL_$(tool)_LIBPATH)\
832)
833$(eval dirdep := $(dir $(dll)).dir_created)
834## @todo fix dependencies
835$(eval deps := $($(target)_DEPS))
836#
837$(eval custom_pre := $(strip $(firstword
838 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
839 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
840 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
841 $($(target)_CUSTOM_PRE)\
842 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
843 $(CUSTOM_PRE.$(BUILD_TARGET))\
844 $(CUSTOM_PRE.$(BUILD_TYPE))\
845 $(CUSTOM_PRE)\
846)))
847$(eval custom_post := $(strip $(firstword
848 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
849 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
850 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
851 $($(target)_CUSTOM_POST)\
852 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
853 $(CUSTOM_POST.$(BUILD_TARGET))\
854 $(CUSTOM_POST.$(BUILD_TYPE))\
855 $(CUSTOM_POST)\
856)))
857$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
858
859ifndef TOOL_$(tool)_LINK_DLL
860$$(warning kBuild: TOOL_$(tool)_LINK_DLL is not defined. target=$(target) )
861$$(warning kBuild: tools: \
862 1 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
863 2 $($(target)_$(source)TOOL) \
864 3 $($(target)_TOOL.$(BUILD_TARGET)) \
865 4 $($(target)_TOOL) \
866 5 $($(source)TOOL) \
867 6 $($(source)TOOL.$(BUILD_TARGET)) \
868 7 $(TOOL.$(BUILD_TARGET)) \
869 8 $(TOOL) )
870endif
871
872$(eval $(TOOL_$(tool)_LINK_DLL))
873
874
875# publish rule (still need work)
876ifndef $(target)_NOINST
877$(eval pubdll := $(PATH_BIN)/$(notdir $(dll)))
878$(pubdll) : $(dll) $(dir $(pubdll)).dir_created
879 $(CP) $(dll) $(pubdll)
880
881$(eval TARGET_PUB_$(target) := $(pubdll))
882_DLLS += $(pubdll)
883_OUT_FILES += $(dll) $(pubdll)
884else
885_DLLS += $(dll)
886_OUT_FILES += $(dll)
887endif
888_OBJS += $(_OBJS_$(target))
889endef
890
891# Process dlls
892$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(def_dll)))
893
894
895
896#
897# Process import libraries.
898#
899# - On OS/2 and windows these are libraries.
900# - On other platforms they are fake DLLs.
901ifeq ($(subst win32,os2,$(BUILD_TARGET)),os2)
902$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_lib)))
903else
904$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_dll)))
905endif
906$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval _IMPORT_LIBS += $(firstword $(TARGET_PUB_$(target)) $(TARGET_$(target)))))
907
908
909#
910# PROGRAMS
911#
912
913## Program (one).
914# @param $(target) Normalized target (program) name.
915define def_program
916# basics
917$(eval tool := $(call _TARGET_TOOL,$(target),LD))
918$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
919$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
920$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
921$(eval exe := $(outbase)$(exesuff))
922$(eval TARGET_$(target) := $(exe))
923
924# source -> object
925$(eval $(def_target_sources))
926
927# more library stuff.
928$(eval tool := $(call _TARGET_TOOL,$(target),LD))
929$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
930$(eval objs = $(_OBJS_$(target)))
931$(eval flags :=\
932 $(TOOL_$(tool)_LDFLAGS)\
933 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
934 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
935 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
936 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
937 $(LDFLAGS)\
938 $(LDFLAGS.$(BUILD_TYPE))\
939 $(LDFLAGS.$(BUILD_TARGET))\
940 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
941 $(LDFLAGS.$(BUILD_TARGET_CPU))\
942 $($(target)_LDFLAGS)\
943 $($(target)_LDFLAGS.$(BUILD_TYPE))\
944 $($(target)_LDFLAGS.$(BUILD_TARGET))\
945 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
946 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
947)
948$(eval libs :=\
949 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
950 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
951 $($(target)_LIBS.$(BUILD_TARGET))\
952 $($(target)_LIBS.$(BUILD_TYPE))\
953 $($(target)_LIBS)\
954 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
955 $($(target)_SDKS.$(BUILD_TYPE)) \
956 $($(target)_SDKS),\
957 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
958 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
959 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
960 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
961 $(SDK_$(sdk)_LIBS))\
962 $(LIBS.$(BUILD_TARGET_CPU))\
963 $(LIBS.$(BUILD_TARGET_ARCH))\
964 $(LIBS.$(BUILD_TARGET))\
965 $(LIBS.$(BUILD_TYPE))\
966 $(LIBS)\
967 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
968 $(SDKS.$(BUILD_TYPE)) \
969 $(SDKS),\
970 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
971 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
972 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
973 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
974 $(SDK_$(sdk)_LIBS))\
975 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
976 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
977 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
978 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
979 $(TOOL_$(tool)_LIBS)\
980)
981$(eval libpath :=\
982 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
983 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
984 $($(target)_LIBPATH.$(BUILD_TARGET))\
985 $($(target)_LIBPATH.$(BUILD_TYPE))\
986 $($(target)_LIBPATH)\
987 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
988 $($(target)_SDKS.$(BUILD_TYPE)) \
989 $($(target)_SDKS),\
990 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
991 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
992 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
993 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
994 $(SDK_$(sdk)_LIBPATH))\
995 $(LIBPATH.$(BUILD_TARGET_CPU))\
996 $(LIBPATH.$(BUILD_TARGET_ARCH))\
997 $(LIBPATH.$(BUILD_TARGET))\
998 $(LIBPATH.$(BUILD_TYPE))\
999 $(LIBPATH)\
1000 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
1001 $(SDKS.$(BUILD_TYPE)) \
1002 $(SDKS),\
1003 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
1004 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
1005 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1006 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1007 $(SDK_$(sdk)_LIBPATH))\
1008 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
1009 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
1010 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
1011 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
1012 $(TOOL_$(tool)_LIBPATH)\
1013)
1014$(eval dirdep := $(dir $(exe)).dir_created)
1015## @todo fix dependencies
1016$(eval deps := $($(target)_DEPS))
1017#
1018$(eval custom_pre := $(strip $(firstword
1019 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1020 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
1021 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
1022 $($(target)_CUSTOM_PRE)\
1023 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1024 $(CUSTOM_PRE.$(BUILD_TARGET))\
1025 $(CUSTOM_PRE.$(BUILD_TYPE))\
1026 $(CUSTOM_PRE)\
1027)))
1028$(eval custom_post := $(strip $(firstword
1029 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1030 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
1031 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
1032 $($(target)_CUSTOM_POST)\
1033 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1034 $(CUSTOM_POST.$(BUILD_TARGET))\
1035 $(CUSTOM_POST.$(BUILD_TYPE))\
1036 $(CUSTOM_POST)\
1037)))
1038$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
1039
1040$(eval $(TOOL_$(tool)_LINK_PROGRAM))
1041# publish rule (still need work)
1042ifndef $(target)_NOINST
1043$(eval pubexe := $(PATH_BIN)/$(notdir $(exe)))
1044$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
1045 $(CP) $(exe) $(pubexe)
1046
1047_DLLS += $(pubexe)
1048_OUT_FILES += $(exe) $(pubexe)
1049else
1050_DLLS += $(exe)
1051_OUT_FILES += $(exe)
1052endif
1053_OBJS += $(_OBJS_$(target))
1054endef
1055
1056# Process libraries
1057$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(def_program)))
1058
1059
1060
1061#
1062# SYSMODS
1063#
1064
1065## System module (one).
1066# @param $(target) Normalized target (program) name.
1067define def_sysmod
1068# sysmod basics
1069$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1070$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1071$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
1072$(eval syssuff := $(firstword $($(target)_SYSSUFF) $($(target)_SYSSUFF) $(TOOL_$(tool)_LDSYSSUFF) $(SUFF_SYS)))
1073$(eval sys := $(outbase)$(syssuff))
1074$(eval TARGET_$(target) := $(sys))
1075
1076# source -> object
1077$(eval $(def_target_sources))
1078
1079# sysmod linking
1080$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1081$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1082$(eval objs = $(_OBJS_$(target)))
1083$(eval flags :=\
1084 $(TOOL_$(tool)_LDFLAGS)\
1085 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
1086 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
1087 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
1088 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
1089 $(LDFLAGS)\
1090 $(LDFLAGS.$(BUILD_TYPE))\
1091 $(LDFLAGS.$(BUILD_TARGET))\
1092 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
1093 $(LDFLAGS.$(BUILD_TARGET_CPU))\
1094 $($(target)_LDFLAGS)\
1095 $($(target)_LDFLAGS.$(BUILD_TYPE))\
1096 $($(target)_LDFLAGS.$(BUILD_TARGET))\
1097 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
1098 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
1099)
1100$(eval libs :=\
1101 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
1102 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
1103 $($(target)_LIBS.$(BUILD_TARGET))\
1104 $($(target)_LIBS.$(BUILD_TYPE))\
1105 $($(target)_LIBS)\
1106 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
1107 $($(target)_SDKS.$(BUILD_TYPE)) \
1108 $($(target)_SDKS),\
1109 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
1110 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
1111 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
1112 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
1113 $(SDK_$(sdk)_LIBS))\
1114 $(LIBS.$(BUILD_TARGET_CPU))\
1115 $(LIBS.$(BUILD_TARGET_ARCH))\
1116 $(LIBS.$(BUILD_TARGET))\
1117 $(LIBS.$(BUILD_TYPE))\
1118 $(LIBS)\
1119 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
1120 $(SDKS.$(BUILD_TYPE)) \
1121 $(SDKS),\
1122 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
1123 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
1124 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
1125 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
1126 $(SDK_$(sdk)_LIBS))\
1127 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
1128 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
1129 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
1130 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
1131 $(TOOL_$(tool)_LIBS)\
1132)
1133$(eval libpath :=\
1134 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
1135 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
1136 $($(target)_LIBPATH.$(BUILD_TARGET))\
1137 $($(target)_LIBPATH.$(BUILD_TYPE))\
1138 $($(target)_LIBPATH)\
1139 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
1140 $($(target)_SDKS.$(BUILD_TYPE)) \
1141 $($(target)_SDKS),\
1142 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
1143 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
1144 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1145 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1146 $(SDK_$(sdk)_LIBPATH))\
1147 $(LIBPATH.$(BUILD_TARGET_CPU))\
1148 $(LIBPATH.$(BUILD_TARGET_ARCH))\
1149 $(LIBPATH.$(BUILD_TARGET))\
1150 $(LIBPATH.$(BUILD_TYPE))\
1151 $(LIBPATH)\
1152 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
1153 $(SDKS.$(BUILD_TYPE)) \
1154 $(SDKS),\
1155 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
1156 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
1157 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1158 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1159 $(SDK_$(sdk)_LIBPATH))\
1160 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
1161 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
1162 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
1163 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
1164 $(TOOL_$(tool)_LIBPATH)\
1165)
1166$(eval dirdep := $(dir $(sys)).dir_created)
1167## @todo fix dependencies
1168$(eval deps := $($(target)_DEPS))
1169#
1170$(eval custom_pre := $(strip $(firstword
1171 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1172 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
1173 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
1174 $($(target)_CUSTOM_PRE)\
1175 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1176 $(CUSTOM_PRE.$(BUILD_TARGET))\
1177 $(CUSTOM_PRE.$(BUILD_TYPE))\
1178 $(CUSTOM_PRE)\
1179)))
1180$(eval custom_post := $(strip $(firstword
1181 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1182 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
1183 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
1184 $($(target)_CUSTOM_POST)\
1185 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1186 $(CUSTOM_POST.$(BUILD_TARGET))\
1187 $(CUSTOM_POST.$(BUILD_TYPE))\
1188 $(CUSTOM_POST)\
1189)))
1190$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
1191
1192ifndef TOOL_$(tool)_LINK_SYSMOD
1193$$(warning kBuild: TOOL_$(tool)_LINK_SYSMOD is not defined. target=$(target) )
1194$$(warning kBuild: tools: \
1195 1 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
1196 2 $($(target)_$(source)TOOL) \
1197 3 $($(target)_TOOL.$(BUILD_TARGET)) \
1198 4 $($(target)_TOOL) \
1199 5 $($(source)TOOL) \
1200 6 $($(source)TOOL.$(BUILD_TARGET)) \
1201 7 $(TOOL.$(BUILD_TARGET)) \
1202 8 $(TOOL) )
1203endif
1204
1205$(eval $(TOOL_$(tool)_LINK_SYSMOD))
1206
1207# publish rule (still need work)
1208ifndef $(target)_NOINST
1209$(eval pubsys := $(PATH_BIN)/$(notdir $(sys)))
1210$(pubsys): $(sys) $(dir $(pubsys)).dir_created
1211 $(CP) $(sys) $(pubsys)
1212
1213$(eval _SYSMODS += $(pubsys))
1214$(eval _OUT_FILES += $(sys) $(pubsys))
1215else
1216$(eval _SYSMODS += $(sys))
1217$(eval _OUT_FILES += $(sys))
1218endif
1219_OBJS += $(_OBJS_$(target))
1220endef
1221
1222# Process sysmods
1223$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(def_sysmod)))
1224
1225
1226
1227#
1228# OTHERS
1229#
1230_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET))
1231
1232
1233
1234#
1235# DOCS
1236#
1237
1238
1239#
1240# Directories.
1241#
1242_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(sort $(dir $(_OUT_FILES) $(_OBJS)))))
1243
1244define def_createdir
1245$(dirfile):
1246 $(call MSG_Ltarget,Creating directory $$(@D))
1247 $(MKDIR) -p $$(@D)
1248 @echo dir_created > $$@
1249endef
1250
1251$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
1252
1253
1254#
1255# Include dependency files.
1256#
1257$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1258
1259
1260#
1261# PASSES (including directory and makefile walking)
1262#
1263# Do all the default passes if it's unspecified.
1264
1265#PASSES ?= needed libraries binaries others publish
1266PASSES ?= libraries dlls binaries others
1267
1268## Proritized list of the default makefile when walking subdirectories.
1269# The user can overload this list.
1270DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
1271
1272## Subdir
1273# @param $(pass) Lowercase pass name.
1274# @param $(PASS) Uppercase pass name.
1275# @param $(subdir) Subdirectory
1276# @param $(tag) tag to attach to the rule name.
1277define def_pass_subdir
1278pass_$(pass)$(tag)::
1279 $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
1280endef
1281
1282## Submakefile
1283# @param $(pass) Lowercase pass name.
1284# @param $(PASS) Uppercase pass name.
1285# @param $(makefile) Makefile.
1286# @param $(tag) tag to attach to the rule name.
1287define def_pass_makefile
1288pass_$(pass)$(tag)::
1289 $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
1290endef
1291
1292
1293## Execute a pass.
1294# @param $(pass) Lowercase pass name.
1295# @param $(PASS) Uppercase pass name.
1296define def_pass
1297$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)))
1298$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)))
1299$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
1300$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)))
1301
1302$(eval tag:=_before)
1303$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1304$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
1305
1306$(eval tag:=_after)
1307$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1308$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
1309
1310.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1311.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
1312pass_$(pass): \
1313 pass_$(pass)_before \
1314 pass_$(pass)_doit \
1315 pass_$(pass)_after
1316
1317endef
1318
1319
1320## PASS: needed
1321# This pass builds targets which are required for building the rest.
1322pass_needed_doit: $(_NEEDEDS)
1323pass := needed
1324PASS := NEEDED
1325$(eval $(def_pass))
1326
1327## PASS: libraries
1328# This pass builds library targets.
1329pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1330pass := libraries
1331PASS := LIBRARIES
1332$(eval $(def_pass))
1333
1334## PASS: binaries
1335# This pass builds dll targets.
1336pass_dlls_doit: $(_DLLS) $(_OTHER_DLLS)
1337pass := dlls
1338PASS := DLLS
1339$(eval $(def_pass))
1340
1341## PASS: binaries
1342# This pass builds binary targets, i.e. programs, system modules and stuff.
1343pass_binaries_doit: $(_EXES) $(_SYSMODS) $(_OTHER_BINARIES)
1344pass := binaries
1345PASS := BINARIES
1346$(eval $(def_pass))
1347
1348## PASS: others
1349# This pass builds other targets.
1350pass_others_doit: $(_OTHERS)
1351pass := others
1352PASS := OTHERS
1353$(eval $(def_pass))
1354
1355## PASS: publish
1356# This pass installs the built entities to a sandbox area.
1357pass_publish_doit: publish
1358publish::
1359pass := publish
1360PASS := PUBLISH
1361# $(sort).. not nice.
1362SUBDIRS_PUBLISH ?= $(sort $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS_LIBRARIES) $(SUBDIRS_LIBRARIES.$(BUILD_TARGET)) $(SUBDIRS_BINARIES) $(SUBDIRS_BINARIES.$(BUILD_TARGET)) $(SUBDIRS_OTHERS) $(SUBDIRS_OTHERS.$(BUILD_TARGET)))
1363SUBDIRS_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)))
1364MAKEFILES_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)))
1365MAKEFILES_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)))
1366$(eval $(def_pass))
1367
1368## PASS: packing
1369# This pass processes custom packing rules.
1370pass_packing_doit: packing
1371packing::
1372pass := packing
1373PASS := PACKING
1374$(eval $(def_pass))
1375
1376## PASS: clean
1377# This pass removes all generated files.
1378pass_clean_doit:
1379 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES) $(OTHER_CLEAN)
1380pass := clean
1381PASS := CLEAN
1382$(eval $(def_pass))
1383clean: pass_clean
1384
1385## PASS: nothing
1386# This pass just walks the tree.
1387pass_nothing_doit:
1388 $(call MSG_Ltarget,Did nothing in $(CURDIR))
1389pass := nothing
1390PASS := NOTHING
1391$(eval $(def_pass))
1392nothing: pass_nothing
1393
1394
1395
1396#
1397# THE MAIN RULES
1398#
1399all_recursive: $(foreach pass,$(PASSES),pass_$(pass))
1400
1401rebuild: clean
1402 $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
1403
1404
1405# misc shortcuts.
1406target: needed libraries binaries others
1407objects: $(_OBJS)
1408libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1409dlls: $(_DLLS)
1410programs: $(_EXES)
1411sysmods: $(_SYSMODS)
1412
1413
1414# end-of-file-content
1415__footer_kmk__ := target
1416endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.