source: trunk/kBuild/footer.kmk@ 189

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

Hacking import libs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 46.5 KB
Line 
1# $Id: footer.kmk 189 2004-12-14 17:36:58Z 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## Generic macro for processing C, C++ and Assembly sources.
347# @param $(target) Normalized target name.
348# @param $(source) Source file name.
349# @param $(type) Source type. {C,CXX,AS}
350#
351# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
352# @remark I now have a clue. Have to use $$ if not.
353define def_target_source_c_cpp_asm
354#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
355
356$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target),$(type)))
357$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
358$(eval PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase))))
359$(eval dirdep := $(dir $(outbase)).dir_created)
360$(eval defs :=\
361 $(TOOL_$(tool)_DEFS)\
362 $(TOOL_$(tool)_DEFS.$(BUILD_TYPE))\
363 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET))\
364 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_ARCH))\
365 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_CPU))\
366 $(TOOL_$(tool)_$(type)DEFS)\
367 $(TOOL_$(tool)_$(type)DEFS.$(BUILD_TYPE))\
368 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
369 $(SDKS.$(BUILD_TYPE)) \
370 $(SDKS),\
371 $(SDK_$(sdk)_DEFS)\
372 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
373 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
374 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
375 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))\
376 $(SDK_$(sdk)_$(type)DEFS)\
377 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
378 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
379 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
380 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
381 $(DEFS)\
382 $(DEFS.$(BUILD_TYPE))\
383 $(DEFS.$(BUILD_TARGET))\
384 $(DEFS.$(BUILD_TARGET_ARCH))\
385 $(DEFS.$(BUILD_TARGET_CPU))\
386 $($(type)DEFS)\
387 $($(type)DEFS.$(BUILD_TYPE))\
388 $($(type)DEFS.$(BUILD_TARGET))\
389 $($(type)DEFS.$(BUILD_TARGET_ARCH))\
390 $($(type)DEFS.$(BUILD_TARGET_CPU))\
391 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
392 $($(target)_SDKS.$(BUILD_TYPE)) \
393 $($(target)_SDKS),\
394 $(SDK_$(sdk)_DEFS)\
395 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
396 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
397 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
398 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))\
399 $(SDK_$(sdk)_$(type)DEFS)\
400 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
401 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
402 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
403 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
404 $($(target)_DEFS)\
405 $($(target)_DEFS.$(BUILD_TYPE))\
406 $($(target)_DEFS.$(BUILD_TARGET))\
407 $($(target)_DEFS.$(BUILD_TARGET_ARCH))\
408 $($(target)_DEFS.$(BUILD_TARGET_CPU))\
409 $($(target)_$(type)DEFS)\
410 $($(target)_$(type)DEFS.$(BUILD_TYPE))\
411 $($(target)_$(type)DEFS.$(BUILD_TARGET))\
412 $($(target)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
413 $($(target)_$(type)DEFS.$(BUILD_TARGET_CPU))\
414 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
415 $($(source)_SDKS.$(BUILD_TYPE)) \
416 $($(source)_SDKS),\
417 $(SDK_$(sdk)_DEFS)\
418 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
419 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
420 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
421 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))\
422 $(SDK_$(sdk)_$(type)DEFS)\
423 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
424 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
425 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
426 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
427 $($(source)_DEFS)\
428 $($(source)_DEFS.$(BUILD_TYPE))\
429 $($(source)_DEFS.$(BUILD_TARGET))\
430 $($(source)_DEFS.$(BUILD_TARGET_ARCH))\
431 $($(source)_DEFS.$(BUILD_TARGET_CPU))\
432 $($(source)_$(type)DEFS)\
433 $($(source)_$(type)DEFS.$(BUILD_TYPE))\
434 $($(source)_$(type)DEFS.$(BUILD_TARGET))\
435 $($(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
436 $($(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
437 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
438 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
439 $($(target)_$(source)_SDKS),\
440 $(SDK_$(sdk)_DEFS)\
441 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
442 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
443 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
444 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))\
445 $(SDK_$(sdk)_$(type)DEFS)\
446 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
447 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
448 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
449 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
450 $($(target)_$(source)_DEFS)\
451 $($(target)_$(source)_DEFS.$(BUILD_TYPE))\
452 $($(target)_$(source)_DEFS.$(BUILD_TARGET))\
453 $($(target)_$(source)_DEFS.$(BUILD_TARGET_ARCH))\
454 $($(target)_$(source)_DEFS.$(BUILD_TARGET_CPU))\
455 $($(target)_$(source)_$(type)DEFS)\
456 $($(target)_$(source)_$(type)DEFS.$(BUILD_TYPE))\
457 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET))\
458 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
459 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
460 )
461$(eval incs :=\
462 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
463 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
464 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET))\
465 $($(target)_$(source)_$(type)INCS.$(BUILD_TYPE))\
466 $($(target)_$(source)_$(type)INCS)\
467 $($(target)_$(source)_INCS.$(BUILD_TARGET_CPU))\
468 $($(target)_$(source)_INCS.$(BUILD_TARGET_ARCH))\
469 $($(target)_$(source)_INCS.$(BUILD_TARGET))\
470 $($(target)_$(source)_INCS.$(BUILD_TYPE))\
471 $($(target)_$(source)_INCS)\
472 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
473 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
474 $($(target)_$(source)_SDKS),\
475 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
476 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
477 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
478 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
479 $(SDK_$(sdk)_$(type)INCS)\
480 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
481 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
482 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
483 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
484 $(SDK_$(sdk)_INCS))\
485 $($(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
486 $($(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
487 $($(source)_$(type)INCS.$(BUILD_TARGET))\
488 $($(source)_$(type)INCS.$(BUILD_TYPE))\
489 $($(source)_$(type)INCS)\
490 $($(source)_INCS.$(BUILD_TARGET_CPU))\
491 $($(source)_INCS.$(BUILD_TARGET_ARCH))\
492 $($(source)_INCS.$(BUILD_TARGET))\
493 $($(source)_INCS.$(BUILD_TYPE))\
494 $($(source)_INCS)\
495 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
496 $($(source)_SDKS.$(BUILD_TYPE)) \
497 $($(source)_SDKS),\
498 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
499 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
500 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
501 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
502 $(SDK_$(sdk)_$(type)INCS)\
503 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
504 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
505 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
506 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
507 $(SDK_$(sdk)_INCS))\
508 $($(target)_$(type)INCS.$(BUILD_TARGET_CPU))\
509 $($(target)_$(type)INCS.$(BUILD_TARGET_ARCH))\
510 $($(target)_$(type)INCS.$(BUILD_TARGET))\
511 $($(target)_$(type)INCS.$(BUILD_TYPE))\
512 $($(target)_$(type)INCS)\
513 $($(target)_INCS.$(BUILD_TARGET_CPU))\
514 $($(target)_INCS.$(BUILD_TARGET_ARCH))\
515 $($(target)_INCS.$(BUILD_TARGET))\
516 $($(target)_INCS.$(BUILD_TYPE))\
517 $($(target)_INCS)\
518 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
519 $($(target)_SDKS.$(BUILD_TYPE)) \
520 $($(target)_SDKS),\
521 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
522 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
523 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
524 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
525 $(SDK_$(sdk)_$(type)INCS)\
526 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
527 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
528 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
529 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
530 $(SDK_$(sdk)_INCS))\
531 $(INCS.$(BUILD_TARGET_CPU))\
532 $(INCS.$(BUILD_TARGET_ARCH))\
533 $(INCS.$(BUILD_TARGET))\
534 $(INCS.$(BUILD_TYPE))\
535 $(INCS)\
536 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
537 $(SDKS.$(BUILD_TYPE)) \
538 $(SDKS),\
539 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
540 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
541 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
542 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
543 $(SDK_$(sdk)_$(type)INCS)\
544 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
545 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
546 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
547 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
548 $(SDK_$(sdk)_INCS))\
549 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_CPU))\
550 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_ARCH))\
551 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET))\
552 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TYPE))\
553 $(TOOL_$(tool)_$(type)INCS)\
554 )
555$(eval flags :=\
556 $(TOOL_$(tool)_$(type)FLAGS)\
557 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
558 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET))\
559 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
560 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
561 $($(type)FLAGS)\
562 $($(type)FLAGS.$(BUILD_TYPE))\
563 $($(type)FLAGS.$(BUILD_TARGET))\
564 $($(type)FLAGS.$(BUILD_TARGET_ARCH))\
565 $($(type)FLAGS.$(BUILD_TARGET_CPU))\
566 $($(target)_$(type)FLAGS)\
567 $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
568 $($(target)_$(type)FLAGS.$(BUILD_TARGET))\
569 $($(target)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
570 $($(target)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
571 $($(source)_$(type)FLAGS)\
572 $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
573 $($(source)_$(type)FLAGS.$(BUILD_TARGET))\
574 $($(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
575 $($(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
576 $($(target)_$(source)_$(type)FLAGS)\
577 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
578 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET))\
579 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
580 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
581 )
582$(eval objsuff := $(firstword \
583 $($(target)_$(source)_OBJSUFF.$(BUILD_TARGET))\
584 $($(target)_$(source)_OBJSUFF)\
585 $($(source)_OBJSUFF.$(BUILD_TARGET))\
586 $($(source)_OBJSUFF)\
587 $($(target)_OBJSUFF.$(BUILD_TARGET))\
588 $($(target)_OBJSUFF)\
589 $(TOOL_$(tool)_$(type)OBJSUFF.$(BUILD_TARGET))\
590 $(TOOL_$(tool)_$(type)OBJSUFF)\
591 $(SUFF_OBJ)\
592 ))
593$(eval obj := $(outbase)$(objsuff))
594$(eval dep := $(outbase)$(SUFF_DEP))
595$(eval deps := \
596 $($(target)_$(source)_DEPS)\
597 $($(target)_$(source)_DEPS.$(BUILD_TYPE))\
598 $($(target)_$(source)_DEPS.$(BUILD_TARGET))\
599 $($(target)_$(source)_DEPS.$(BUILD_TARGET_ARCH))\
600 $($(target)_$(source)_DEPS.$(BUILD_TARGET_CPU))\
601 $($(source)_DEPS)\
602 $($(source)_DEPS.$(BUILD_TYPE))\
603 $($(source)_DEPS.$(BUILD_TARGET))\
604 $($(target)_DEPS)\
605 $($(target)_DEPS.$(BUILD_TARGET_ARCH))\
606 $($(target)_DEPS.$(BUILD_TARGET_CPU)))
607
608
609#$ (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))
610ifndef TOOL_$(tool)_COMPILE_$(type)
611$$(warning kBuild: TOOL_$(tool)_COMPILE_$(type) is not defined. source=$(source) target=$(target) )
612$$(warning kBuild: tools: \
613 1 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) \
614 2 $($(target)_$(source)_$(type)TOOL) \
615 3 $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
616 4 $($(target)_$(source)_TOOL) \
617 5 $($(target)_$(type)TOOL.$(BUILD_TARGET)) \
618 6 $($(target)_$(type)TOOL) \
619 7 $($(target)_TOOL.$(BUILD_TARGET)) \
620 8 $($(target)_TOOL) \
621 9 $($(source)_$(type)TOOL.$(BUILD_TARGET)) \
622 10 $($(source)_$(type)TOOL) \
623 11 $($(source)_TOOL.$(BUILD_TARGET)) \
624 12 $($(source)_TOOL) \
625 13 $($(type)TOOL.$(BUILD_TARGET)) \
626 14 $($(type)TOOL) \
627 15 $(TOOL.$(BUILD_TARGET)) \
628 16 $(TOOL) )
629endif
630$(eval $(TOOL_$(tool)_COMPILE_$(type)))
631
632$(eval _OBJS_$(target) += $(obj))
633$(eval _DEPFILES += $(dep))
634
635endef
636
637## Generic macro for processing all target sources.
638# @param $(target) Normalized target name.
639define def_target_sources
640#$ (warning def_target_sources)
641# C sources
642$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
643 ,$(eval $(def_target_source_c_cpp_asm)) ))
644
645# C++ sources
646$(foreach type,CXX,$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
647 ,$(eval $(def_target_source_c_cpp_asm)) ))
648
649# ASM sources
650$(foreach type,AS,$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE)))\
651 ,$(eval $(def_target_source_c_cpp_asm)) ))
652endef
653
654
655#
656# LIBRARIES
657#
658
659## Library (one).
660# @param $(target) Normalized library (target) name.
661define def_lib
662# library basics
663$(eval tool := $(call _TARGET_TOOL,$(target),AR))
664ifeq ($(tool),)
665$$(error kBuild: Library target $(target) doesn't have a tool defined!)
666endif
667## @todo prefix
668$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
669$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
670$(eval libsuff := $(firstword\
671 $($(target)_LIBSUFF.$(BUILD_TARGET))\
672 $($(target)_LIBSUFF)\
673 $(TOOL_$(tool)_ARLIBSUFF.$(BUILD_TARGET))\
674 $(TOOL_$(tool)_ARLIBSUFF)\
675 $(SUFF_LIB)\
676))
677$(eval lib := $(outbase)$(libsuff))
678$(eval TARGET_$(target) := $(lib))
679
680# source -> object
681$(eval $(def_target_sources))
682
683# library linking
684$(eval tool := $(call _TARGET_TOOL,$(target),AR))
685$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
686$(eval flags :=\
687 $(TOOL_$(tool)_ARFLAGS)\
688 $(TOOL_$(tool)_ARFLAGS.$(BUILD_TYPE))\
689 $(ARFLAGS)\
690 $(ARFLAGS.$(BUILD_TYPE))\
691 $($(target)_ARFLAGS)\
692 $($(target)_ARFLAGS.$(BUILD_TYPE))\
693 )
694$(eval objs = $(_OBJS_$(target)))
695$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
696$(eval dirdep := $(dir $(lib)).dir_created)
697## @todo fix dependencies on makefiles an such
698$(eval deps := $($(target)_DEPS))
699
700$(eval $(TOOL_$(tool)_LINK_LIBRARY))
701
702# publish rule (still need work)
703ifndef $(target)_NOINST
704$(eval publib := $(PATH_LIB)/$(notdir $(lib)))
705$(publib) : $(lib) $(dir $(publib)).dir_created
706 $(CP) $(lib) $(publib)
707
708_LIBS += $(publib)
709_OUT_FILES += $(lib) $(publib)
710else
711_LIBS += $(lib)
712_OUT_FILES += $(lib)
713endif
714_OBJS += $(_OBJS_$(target))
715endef
716
717# Process libraries
718$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(def_lib)))
719
720
721
722#
723# DLLS
724#
725
726## DLL (one).
727# @param $(target) Normalized target (program) name.
728define def_dll
729# dllmod basics
730$(eval tool := $(call _TARGET_TOOL,$(target),LD))
731$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
732$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
733$(eval dllsuff := $(firstword $($(target)_DLLSUFF) $($(target)_DLLSUFF) $(TOOL_$(tool)_LDDLLSUFF) $(SUFF_DLL)))
734$(eval dll := $(outbase)$(dllsuff))
735$(eval TARGET_$(target) := $(dll))
736
737# source -> object
738$(eval $(def_target_sources))
739
740# dllmod linking.
741$(eval tool := $(call _TARGET_TOOL,$(target),LD))
742$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
743$(eval objs = $(_OBJS_$(target)))
744$(eval flags :=\
745 $(TOOL_$(tool)_LDFLAGS)\
746 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
747 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
748 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
749 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
750 $(LDFLAGS)\
751 $(LDFLAGS.$(BUILD_TYPE))\
752 $(LDFLAGS.$(BUILD_TARGET))\
753 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
754 $(LDFLAGS.$(BUILD_TARGET_CPU))\
755 $($(target)_LDFLAGS)\
756 $($(target)_LDFLAGS.$(BUILD_TYPE))\
757 $($(target)_LDFLAGS.$(BUILD_TARGET))\
758 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
759 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
760)
761$(eval libs :=\
762 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
763 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
764 $($(target)_LIBS.$(BUILD_TARGET))\
765 $($(target)_LIBS.$(BUILD_TYPE))\
766 $($(target)_LIBS)\
767 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
768 $($(target)_SDKS.$(BUILD_TYPE)) \
769 $($(target)_SDKS),\
770 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
771 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
772 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
773 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
774 $(SDK_$(sdk)_LIBS))\
775 $(LIBS.$(BUILD_TARGET_CPU))\
776 $(LIBS.$(BUILD_TARGET_ARCH))\
777 $(LIBS.$(BUILD_TARGET))\
778 $(LIBS.$(BUILD_TYPE))\
779 $(LIBS)\
780 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
781 $(SDKS.$(BUILD_TYPE)) \
782 $(SDKS),\
783 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
784 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
785 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
786 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
787 $(SDK_$(sdk)_LIBS))\
788 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
789 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
790 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
791 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
792 $(TOOL_$(tool)_LIBS)\
793)
794$(eval libpath :=\
795 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
796 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
797 $($(target)_LIBPATH.$(BUILD_TARGET))\
798 $($(target)_LIBPATH.$(BUILD_TYPE))\
799 $($(target)_LIBPATH)\
800 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
801 $($(target)_SDKS.$(BUILD_TYPE)) \
802 $($(target)_SDKS),\
803 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
804 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
805 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
806 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
807 $(SDK_$(sdk)_LIBPATH))\
808 $(LIBPATH.$(BUILD_TARGET_CPU))\
809 $(LIBPATH.$(BUILD_TARGET_ARCH))\
810 $(LIBPATH.$(BUILD_TARGET))\
811 $(LIBPATH.$(BUILD_TYPE))\
812 $(LIBPATH)\
813 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
814 $(SDKS.$(BUILD_TYPE)) \
815 $(SDKS),\
816 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
817 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
818 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
819 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
820 $(SDK_$(sdk)_LIBPATH))\
821 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
822 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
823 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
824 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
825 $(TOOL_$(tool)_LIBPATH)\
826)
827$(eval dirdep := $(dir $(dll)).dir_created)
828## @todo fix dependencies
829$(eval deps := $($(target)_DEPS))
830#
831$(eval custom_pre := $(strip $(firstword
832 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
833 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
834 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
835 $($(target)_CUSTOM_PRE)\
836 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
837 $(CUSTOM_PRE.$(BUILD_TARGET))\
838 $(CUSTOM_PRE.$(BUILD_TYPE))\
839 $(CUSTOM_PRE)\
840)))
841$(eval custom_post := $(strip $(firstword
842 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
843 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
844 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
845 $($(target)_CUSTOM_POST)\
846 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
847 $(CUSTOM_POST.$(BUILD_TARGET))\
848 $(CUSTOM_POST.$(BUILD_TYPE))\
849 $(CUSTOM_POST)\
850)))
851$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
852
853ifndef TOOL_$(tool)_LINK_DLL
854$$(warning kBuild: TOOL_$(tool)_LINK_DLL is not defined. target=$(target) )
855$$(warning kBuild: tools: \
856 1 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
857 2 $($(target)_$(source)TOOL) \
858 3 $($(target)_TOOL.$(BUILD_TARGET)) \
859 4 $($(target)_TOOL) \
860 5 $($(source)TOOL) \
861 6 $($(source)TOOL.$(BUILD_TARGET)) \
862 7 $(TOOL.$(BUILD_TARGET)) \
863 8 $(TOOL) )
864endif
865
866$(eval $(TOOL_$(tool)_LINK_DLL))
867
868
869# publish rule (still need work)
870ifndef $(target)_NOINST
871$(eval pubdll := $(PATH_BIN)/$(notdir $(dll)))
872$(pubdll) : $(dll) $(dir $(pubdll)).dir_created
873 $(CP) $(dll) $(pubdll)
874
875$(eval TARGET_PUB_$(target) := $(pubdll))
876_DLLS += $(pubdll)
877_OUT_FILES += $(dll) $(pubdll)
878else
879_DLLS += $(dll)
880_OUT_FILES += $(dll)
881endif
882_OBJS += $(_OBJS_$(target))
883endef
884
885# Process dlls
886$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(def_dll)))
887
888
889
890#
891# Process import libraries.
892#
893# - On OS/2 and windows these are libraries.
894# - On other platforms they are fake DLLs.
895ifeq ($(subst win32,os2,$(BUILD_TARGET)),os2)
896$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_lib)))
897else
898$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_dll)))
899endif
900$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval _IMPORT_LIBS += $(firstword $(TARGET_PUB_$(target)) $(TARGET_$(target)))))
901
902
903#
904# PROGRAMS
905#
906
907## Program (one).
908# @param $(target) Normalized target (program) name.
909define def_program
910# basics
911$(eval tool := $(call _TARGET_TOOL,$(target),LD))
912$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
913$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
914$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
915$(eval exe := $(outbase)$(exesuff))
916$(eval TARGET_$(target) := $(exe))
917
918# source -> object
919$(eval $(def_target_sources))
920
921# more library stuff.
922$(eval tool := $(call _TARGET_TOOL,$(target),LD))
923$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
924$(eval objs = $(_OBJS_$(target)))
925$(eval flags :=\
926 $(TOOL_$(tool)_LDFLAGS)\
927 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
928 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
929 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
930 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
931 $(LDFLAGS)\
932 $(LDFLAGS.$(BUILD_TYPE))\
933 $(LDFLAGS.$(BUILD_TARGET))\
934 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
935 $(LDFLAGS.$(BUILD_TARGET_CPU))\
936 $($(target)_LDFLAGS)\
937 $($(target)_LDFLAGS.$(BUILD_TYPE))\
938 $($(target)_LDFLAGS.$(BUILD_TARGET))\
939 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
940 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
941)
942$(eval libs :=\
943 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
944 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
945 $($(target)_LIBS.$(BUILD_TARGET))\
946 $($(target)_LIBS.$(BUILD_TYPE))\
947 $($(target)_LIBS)\
948 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
949 $($(target)_SDKS.$(BUILD_TYPE)) \
950 $($(target)_SDKS),\
951 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
952 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
953 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
954 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
955 $(SDK_$(sdk)_LIBS))\
956 $(LIBS.$(BUILD_TARGET_CPU))\
957 $(LIBS.$(BUILD_TARGET_ARCH))\
958 $(LIBS.$(BUILD_TARGET))\
959 $(LIBS.$(BUILD_TYPE))\
960 $(LIBS)\
961 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
962 $(SDKS.$(BUILD_TYPE)) \
963 $(SDKS),\
964 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
965 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
966 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
967 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
968 $(SDK_$(sdk)_LIBS))\
969 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
970 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
971 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
972 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
973 $(TOOL_$(tool)_LIBS)\
974)
975$(eval libpath :=\
976 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
977 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
978 $($(target)_LIBPATH.$(BUILD_TARGET))\
979 $($(target)_LIBPATH.$(BUILD_TYPE))\
980 $($(target)_LIBPATH)\
981 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
982 $($(target)_SDKS.$(BUILD_TYPE)) \
983 $($(target)_SDKS),\
984 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
985 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
986 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
987 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
988 $(SDK_$(sdk)_LIBPATH))\
989 $(LIBPATH.$(BUILD_TARGET_CPU))\
990 $(LIBPATH.$(BUILD_TARGET_ARCH))\
991 $(LIBPATH.$(BUILD_TARGET))\
992 $(LIBPATH.$(BUILD_TYPE))\
993 $(LIBPATH)\
994 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
995 $(SDKS.$(BUILD_TYPE)) \
996 $(SDKS),\
997 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
998 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
999 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1000 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1001 $(SDK_$(sdk)_LIBPATH))\
1002 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
1003 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
1004 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
1005 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
1006 $(TOOL_$(tool)_LIBPATH)\
1007)
1008$(eval dirdep := $(dir $(exe)).dir_created)
1009## @todo fix dependencies
1010$(eval deps := $($(target)_DEPS))
1011#
1012$(eval custom_pre := $(strip $(firstword
1013 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1014 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
1015 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
1016 $($(target)_CUSTOM_PRE)\
1017 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1018 $(CUSTOM_PRE.$(BUILD_TARGET))\
1019 $(CUSTOM_PRE.$(BUILD_TYPE))\
1020 $(CUSTOM_PRE)\
1021)))
1022$(eval custom_post := $(strip $(firstword
1023 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1024 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
1025 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
1026 $($(target)_CUSTOM_POST)\
1027 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1028 $(CUSTOM_POST.$(BUILD_TARGET))\
1029 $(CUSTOM_POST.$(BUILD_TYPE))\
1030 $(CUSTOM_POST)\
1031)))
1032$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
1033
1034$(eval $(TOOL_$(tool)_LINK_PROGRAM))
1035# publish rule (still need work)
1036ifndef $(target)_NOINST
1037$(eval pubexe := $(PATH_BIN)/$(notdir $(exe)))
1038$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
1039 $(CP) $(exe) $(pubexe)
1040
1041_DLLS += $(pubexe)
1042_OUT_FILES += $(exe) $(pubexe)
1043else
1044_DLLS += $(exe)
1045_OUT_FILES += $(exe)
1046endif
1047_OBJS += $(_OBJS_$(target))
1048endef
1049
1050# Process libraries
1051$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(def_program)))
1052
1053
1054
1055#
1056# SYSMODS
1057#
1058
1059## System module (one).
1060# @param $(target) Normalized target (program) name.
1061define def_sysmod
1062# sysmod basics
1063$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1064$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1065$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
1066$(eval syssuff := $(firstword $($(target)_SYSSUFF) $($(target)_SYSSUFF) $(TOOL_$(tool)_LDSYSSUFF) $(SUFF_SYS)))
1067$(eval sys := $(outbase)$(syssuff))
1068$(eval TARGET_$(target) := $(sys))
1069
1070# source -> object
1071$(eval $(def_target_sources))
1072
1073# sysmod linking
1074$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1075$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1076$(eval objs = $(_OBJS_$(target)))
1077$(eval flags :=\
1078 $(TOOL_$(tool)_LDFLAGS)\
1079 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
1080 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
1081 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
1082 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
1083 $(LDFLAGS)\
1084 $(LDFLAGS.$(BUILD_TYPE))\
1085 $(LDFLAGS.$(BUILD_TARGET))\
1086 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
1087 $(LDFLAGS.$(BUILD_TARGET_CPU))\
1088 $($(target)_LDFLAGS)\
1089 $($(target)_LDFLAGS.$(BUILD_TYPE))\
1090 $($(target)_LDFLAGS.$(BUILD_TARGET))\
1091 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
1092 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
1093)
1094$(eval libs :=\
1095 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
1096 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
1097 $($(target)_LIBS.$(BUILD_TARGET))\
1098 $($(target)_LIBS.$(BUILD_TYPE))\
1099 $($(target)_LIBS)\
1100 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
1101 $($(target)_SDKS.$(BUILD_TYPE)) \
1102 $($(target)_SDKS),\
1103 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
1104 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
1105 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
1106 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
1107 $(SDK_$(sdk)_LIBS))\
1108 $(LIBS.$(BUILD_TARGET_CPU))\
1109 $(LIBS.$(BUILD_TARGET_ARCH))\
1110 $(LIBS.$(BUILD_TARGET))\
1111 $(LIBS.$(BUILD_TYPE))\
1112 $(LIBS)\
1113 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
1114 $(SDKS.$(BUILD_TYPE)) \
1115 $(SDKS),\
1116 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_CPU))\
1117 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET_ARCH))\
1118 $(SDK_$(sdk)_LIBS.$(BUILD_TARGET))\
1119 $(SDK_$(sdk)_LIBS.$(BUILD_TYPE))\
1120 $(SDK_$(sdk)_LIBS))\
1121 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_CPU))\
1122 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET_ARCH))\
1123 $(TOOL_$(tool)_LIBS.$(BUILD_TARGET))\
1124 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
1125 $(TOOL_$(tool)_LIBS)\
1126)
1127$(eval libpath :=\
1128 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
1129 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
1130 $($(target)_LIBPATH.$(BUILD_TARGET))\
1131 $($(target)_LIBPATH.$(BUILD_TYPE))\
1132 $($(target)_LIBPATH)\
1133 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
1134 $($(target)_SDKS.$(BUILD_TYPE)) \
1135 $($(target)_SDKS),\
1136 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
1137 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
1138 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1139 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1140 $(SDK_$(sdk)_LIBPATH))\
1141 $(LIBPATH.$(BUILD_TARGET_CPU))\
1142 $(LIBPATH.$(BUILD_TARGET_ARCH))\
1143 $(LIBPATH.$(BUILD_TARGET))\
1144 $(LIBPATH.$(BUILD_TYPE))\
1145 $(LIBPATH)\
1146 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
1147 $(SDKS.$(BUILD_TYPE)) \
1148 $(SDKS),\
1149 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_CPU))\
1150 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET_ARCH))\
1151 $(SDK_$(sdk)_LIBPATH.$(BUILD_TARGET))\
1152 $(SDK_$(sdk)_LIBPATH.$(BUILD_TYPE))\
1153 $(SDK_$(sdk)_LIBPATH))\
1154 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
1155 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
1156 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
1157 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
1158 $(TOOL_$(tool)_LIBPATH)\
1159)
1160$(eval dirdep := $(dir $(sys)).dir_created)
1161## @todo fix dependencies
1162$(eval deps := $($(target)_DEPS))
1163#
1164$(eval custom_pre := $(strip $(firstword
1165 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1166 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
1167 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
1168 $($(target)_CUSTOM_PRE)\
1169 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
1170 $(CUSTOM_PRE.$(BUILD_TARGET))\
1171 $(CUSTOM_PRE.$(BUILD_TYPE))\
1172 $(CUSTOM_PRE)\
1173)))
1174$(eval custom_post := $(strip $(firstword
1175 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1176 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
1177 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
1178 $($(target)_CUSTOM_POST)\
1179 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
1180 $(CUSTOM_POST.$(BUILD_TARGET))\
1181 $(CUSTOM_POST.$(BUILD_TYPE))\
1182 $(CUSTOM_POST)\
1183)))
1184$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_MODE))))
1185
1186ifndef TOOL_$(tool)_LINK_SYSMOD
1187$$(warning kBuild: TOOL_$(tool)_LINK_SYSMOD is not defined. target=$(target) )
1188$$(warning kBuild: tools: \
1189 1 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
1190 2 $($(target)_$(source)TOOL) \
1191 3 $($(target)_TOOL.$(BUILD_TARGET)) \
1192 4 $($(target)_TOOL) \
1193 5 $($(source)TOOL) \
1194 6 $($(source)TOOL.$(BUILD_TARGET)) \
1195 7 $(TOOL.$(BUILD_TARGET)) \
1196 8 $(TOOL) )
1197endif
1198
1199$(eval $(TOOL_$(tool)_LINK_SYSMOD))
1200
1201# publish rule (still need work)
1202ifndef $(target)_NOINST
1203$(eval pubsys := $(PATH_BIN)/$(notdir $(sys)))
1204$(pubsys): $(sys) $(dir $(pubsys)).dir_created
1205 $(CP) $(sys) $(pubsys)
1206
1207$(eval _SYSMODS += $(pubsys))
1208$(eval _OUT_FILES += $(sys) $(pubsys))
1209else
1210$(eval _SYSMODS += $(sys))
1211$(eval _OUT_FILES += $(sys))
1212endif
1213_OBJS += $(_OBJS_$(target))
1214endef
1215
1216# Process sysmods
1217$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(def_sysmod)))
1218
1219
1220
1221#
1222# OTHERS
1223#
1224_OTHERS = $(OTHERS)
1225
1226
1227
1228#
1229# DOCS
1230#
1231
1232
1233#
1234# Directories.
1235#
1236_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(sort $(dir $(_OUT_FILES) $(_OBJS)))))
1237
1238define def_createdir
1239$(dirfile):
1240 $(call MSG_Ltarget,Creating directory $$(@D))
1241 $(MKDIR) -p $$(@D)
1242 @echo dir_created > $$@
1243endef
1244
1245$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
1246
1247
1248#
1249# Include dependency files.
1250#
1251$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1252
1253
1254#
1255# PASSES (including directory and makefile walking)
1256#
1257# Do all the default passes if it's unspecified.
1258
1259#PASSES ?= needed libraries binaries others publish
1260PASSES ?= libraries dlls binaries others
1261
1262## Proritized list of the default makefile when walking subdirectories.
1263# The user can overload this list.
1264DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
1265
1266## Subdir
1267# @param $(pass) Lowercase pass name.
1268# @param $(PASS) Uppercase pass name.
1269# @param $(subdir) Subdirectory
1270# @param $(tag) tag to attach to the rule name.
1271define def_pass_subdir
1272pass_$(pass)$(tag)::
1273 $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
1274endef
1275
1276## Submakefile
1277# @param $(pass) Lowercase pass name.
1278# @param $(PASS) Uppercase pass name.
1279# @param $(makefile) Makefile.
1280# @param $(tag) tag to attach to the rule name.
1281define def_pass_makefile
1282pass_$(pass)$(tag)::
1283 $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
1284endef
1285
1286
1287## Execute a pass.
1288# @param $(pass) Lowercase pass name.
1289# @param $(PASS) Uppercase pass name.
1290define def_pass
1291$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)))
1292$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)))
1293$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
1294$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)))
1295
1296$(eval tag:=_before)
1297$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1298$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
1299
1300$(eval tag:=_after)
1301$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1302$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
1303
1304.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1305.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
1306pass_$(pass): \
1307 pass_$(pass)_before \
1308 pass_$(pass)_doit \
1309 pass_$(pass)_after
1310
1311endef
1312
1313
1314## PASS: needed
1315# This pass builds targets which are required for building the rest.
1316pass_needed_doit: $(_NEEDEDS)
1317pass := needed
1318PASS := NEEDED
1319$(eval $(def_pass))
1320
1321## PASS: libraries
1322# This pass builds library targets.
1323pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1324pass := libraries
1325PASS := LIBRARIES
1326$(eval $(def_pass))
1327
1328## PASS: binaries
1329# This pass builds dll targets.
1330pass_dlls_doit: $(_DLLS) $(_OTHER_DLLS)
1331pass := dlls
1332PASS := DLLS
1333$(eval $(def_pass))
1334
1335## PASS: binaries
1336# This pass builds binary targets, i.e. programs, system modules and stuff.
1337pass_binaries_doit: $(_EXES) $(_SYSMODS) $(_OTHER_BINARIES)
1338pass := binaries
1339PASS := BINARIES
1340$(eval $(def_pass))
1341
1342## PASS: others
1343# This pass builds other targets.
1344pass_others_doit: $(_OTHERS)
1345pass := others
1346PASS := OTHERS
1347$(eval $(def_pass))
1348
1349## PASS: publish
1350# This pass installs the built entities to a sandbox area.
1351pass_publish_doit: publish
1352publish::
1353pass := publish
1354PASS := PUBLISH
1355# $(sort).. not nice.
1356SUBDIRS_PUBLISH ?= $(sort $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS_LIBRARIES) $(SUBDIRS_LIBRARIES.$(BUILD_TARGET)) $(SUBDIRS_BINARIES) $(SUBDIRS_BINARIES.$(BUILD_TARGET)) $(SUBDIRS_OTHERS) $(SUBDIRS_OTHERS.$(BUILD_TARGET)))
1357SUBDIRS_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)))
1358MAKEFILES_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)))
1359MAKEFILES_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)))
1360$(eval $(def_pass))
1361
1362## PASS: packing
1363# This pass processes custom packing rules.
1364pass_packing_doit: packing
1365packing::
1366pass := packing
1367PASS := PACKING
1368$(eval $(def_pass))
1369
1370## PASS: clean
1371# This pass removes all generated files.
1372pass_clean_doit:
1373 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES) $(OTHER_CLEAN)
1374pass := clean
1375PASS := CLEAN
1376$(eval $(def_pass))
1377clean: pass_clean
1378
1379## PASS: nothing
1380# This pass just walks the tree.
1381pass_nothing_doit:
1382 $(call MSG_Ltarget,Did nothing in $(CURDIR))
1383pass := nothing
1384PASS := NOTHING
1385$(eval $(def_pass))
1386nothing: pass_nothing
1387
1388
1389
1390#
1391# THE MAIN RULES
1392#
1393all_recursive: $(foreach pass,$(PASSES),pass_$(pass))
1394
1395rebuild: clean
1396 $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
1397
1398
1399# misc shortcuts.
1400target: needed libraries binaries others
1401objects: $(_OBJS)
1402libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1403dlls: $(_DLLS)
1404programs: $(_EXES)
1405sysmods: $(_SYSMODS)
1406
1407
1408# end-of-file-content
1409__footer_kmk__ := target
1410endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.