source: trunk/kBuild/footer.kmk@ 391

Last change on this file since 391 was 388, checked in by bird, 20 years ago

A bit of parallel hacking.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 51.4 KB
Line 
1# $Id: footer.kmk 388 2006-01-12 04:04:51Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
6# Copyright (c) 2004-2005 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 330, Boston, MA 02111-1307 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 $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)) \
38 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) \
39 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) \
40 $(DLLS) $(DLLS.$(BUILD_TARGET)) \
41 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) \
42 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) \
43 $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)) \
44 $(OTHERS) $(OTHERS.$(BUILD_TARGET))
45
46# dependency files.
47_DEPFILES :=
48
49# included dependency files.
50_DEPFILES_INCLUDED :=
51
52
53# All kind of output files except for _OBJS and _DEPFILES.
54# Compiling or linking definition outputting other things that $@ and any
55# required dependency file must add those output files to this variable.
56_OUT_FILES :=
57
58# Files which only requires cleaning up.
59_CLEAN_FILES :=
60
61# all of a type
62_OBJS :=
63_BLDPROGS :=
64_LIBS :=
65_DLLS :=
66_PROGRAMS :=
67_SYSMODS :=
68_INSTALLS :=
69_INSTALLS_DIRS :=
70_OTHERS :=
71_DIRS := $(PATH_TARGET)/ $(PATH_TARGET)
72_IMPORT_LIBS :=
73
74# misc
75pass_prev :=
76
77
78#
79# Basic macros
80#
81
82## Figure out the tool for a source
83# @param $target source file
84# @param $source normalized main target
85# @param $type tooltype
86# @param bld_trg build target.
87_SOURCE_TOOL = $(strip $(firstword \
88 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
89 $($(target)_$(source)_$(type)TOOL) \
90 $($(target)_$(source)_TOOL.$(bld_trg)) \
91 $($(target)_$(source)_TOOL) \
92 $($(target)_$(type)TOOL.$(bld_trg)) \
93 $($(target)_$(type)TOOL) \
94 $($(target)_TOOL.$(bld_trg)) \
95 $($(target)_TOOL) \
96 $($(source)_$(type)TOOL.$(bld_trg)) \
97 $($(source)_$(type)TOOL) \
98 $($(source)_TOOL.$(bld_trg)) \
99 $($(source)_TOOL) \
100 $($(type)TOOL.$(bld_trg)) \
101 $($(type)TOOL) \
102 $(TOOL.$(bld_trg)) \
103 $(TOOL) ))
104
105## Figure out the tool for a target.
106# @param $target normalized target.
107# @param $source tooltype.
108# @param bld_trg build target.
109_TARGET_TOOL = $(strip $(firstword \
110 $($(target)_$(source)TOOL.$(bld_trg)) \
111 $($(target)_$(source)TOOL) \
112 $($(target)_TOOL.$(bld_trg)) \
113 $($(target)_TOOL) \
114 $($(source)TOOL.$(bld_trg)) \
115 $($(source)TOOL) \
116 $(TOOL.$(bld_trg)) \
117 $(TOOL) \
118 ))
119
120## Removes the drive letter from a path (if it has one)
121# @param $1 the path
122no-drive=$(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
123
124## Removes the root slash from a path (if it has one)
125# @param $1 the path
126no-root-slash=$(patsubst /%,%,$(1))
127
128## Figure out where to put object files.
129# @param $1 source file
130# @param $2 normalized main target
131# @remark There are two major hacks here:
132# 1. Source files in the output directory are translated into a gen/ subdir.
133# 2. Catch anyone specifying $(PATH_CURRENT)/sourcefile.c.
134_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename \
135 $(patsubst $(PATH_ROOT)/%,%,$(patsubst $(PATH_CURRENT)/%,%,$(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))))
136
137## Figure out where to put object files.
138# @param $1 real target name.
139# @param $2 normalized main target
140_TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(1))))
141
142
143## Figure out the actual name of an installed file.
144# @param $1 The file to install.
145# @param $2 The target name.
146# @param $3 The _INST value (can be empty).
147# @param $4 The default directory to use when $3 is empty.
148_INSTALL_FILE = $(patsubst %/,%/$(notdir $(1)),$(if $(3),$(PATH_INS)/$(3),$(4)/))
149
150
151#
152# Check syntax which leads to weird syntax errors.
153#
154
155## Check
156# @param $(target) Target name.
157define def_check_target
158ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))")
159$$(error $(target) have an incorrect template name. Remove any tabs!)
160endif
161endef
162$(foreach target, $(ALL_TARGETS),$(eval $(def_check_target)))
163
164
165#
166# Include templates
167#
168_TEMPLATES := $(TEMPLATE)
169define def_templates
170ifdef $(target)_TEMPLATE
171_TEMPLATES += $($(target)_TEMPLATE)
172endif
173endef
174$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
175_TEMPLATES := $(sort $(_TEMPLATES))
176# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
177
178define def_templates_include
179ifndef TEMPLATE_$(template)
180include $(firstword $(foreach path, $(TEMPLATE_PATHS) $(PATH_KBUILD)/templates/, $(wildcard $(path)/$(template).kmk)))
181endif
182endef
183$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
184
185
186#
187# Common Inheritance
188#
189
190## Inherit defaults property
191# @param $(prop) Property name
192# @param $(target) Target name.
193define def_inherit_defaults_one
194ifndef $(target)_$(prop)
195ifndef $(target)_$(prop).$(BUILD_TARGET)
196ifdef $(prop)
197$$(eval $(target)_$(prop) := $($(prop)))
198endif
199ifdef $(prop).$(BUILD_TARGET)
200$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(prop).$(BUILD_TARGET)))
201endif
202endif
203endif
204endef
205
206## Inherit default properties for one target.
207# A bit tricky this one, but it depends a bit on whether or not TEMPLATE
208# is inherited from the default properties.
209# @param $(target) Target name
210#
211define def_inherit_defaults
212ifdef $(target)_TEMPLATE
213ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_TOOL) $(TEMPLATE_$($(target)_TEMPLATE)_TOOL.$(BUILD_TARGET))),)
214$$(foreach prop,TOOL, $$(eval $$(def_inherit_defaults_one)))
215endif
216ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_SDKS) $(TEMPLATE_$($(target)_TEMPLATE)_SDKS.$(BUILD_TARGET))),)
217$$(foreach prop,SDKS, $$(eval $$(def_inherit_defaults_one)))
218endif
219else
220$$(foreach prop,TEMPLATE TOOL SDKS, $$(eval $$(def_inherit_defaults_one)))
221endif
222endef
223# Inherit default properties.
224# !!!!!!THIS IS MESSY AND NOT NECESSARY!!!!!!
225$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_defaults)))
226
227
228## Inherit one template property in a non-accumulative manner.
229# @param $(prop) Property name
230# @param $(target) Target name
231# @todo fix the precedence order for some properties.
232define def_inherit_template_one
233ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
234ifndef $(target)_$(prop)
235$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
236#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
237endif
238endif
239ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
240ifndef $(target)_$(prop).$(BUILD_TARGET)
241#$ (warning dbgsource: $(target)_$(prop).$(BUILD_TARGET)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
242$(target)_$(prop).$(BUILD_TARGET) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
243endif
244endif
245endef
246
247## Inherit one template property in a non-accumulative manner, deferred expansion.
248# @param 1: $(prop) Property name
249# @param 2: $(target) Target name
250# @todo fix the precedence order for some properties.
251# @remark this define relies on double evaluation
252define def_inherit_template_one_deferred
253ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
254ifndef $(target)_$(prop)
255$(target)_$(prop) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
256#$ (warning dbgtarget: $(target)_$(prop):='$(value $(target)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
257endif
258endif
259ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
260ifndef $(target)_$(prop).$(BUILD_TARGET)
261#$ (warning dbgsource: $(target)_$(prop).$(BUILD_TARGET)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
262$(target)_$(prop).$(BUILD_TARGET) = $$(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
263endif
264endif
265endef
266
267## Inherit one template property.
268# @param $(prop) Property name
269# @param $(target) Target name
270define def_inherit_template_one_accumulate
271ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
272#$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
273$(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
274#$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
275endif
276ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE)
277#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
278$(target)_$(prop).$(BUILD_TYPE) := $($(target)_$(prop).$(BUILD_TYPE)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TYPE))
279endif
280ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
281#$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
282$(target)_$(prop).$(BUILD_TARGET) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
283endif
284ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)
285#$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU))
286$(target)_$(prop).$(BUILD_TARGET_CPU) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU))
287endif
288ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)
289#$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
290$(target)_$(prop).$(BUILD_TARGET_ARCH) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
291endif
292endef
293
294## Inherit template properties for on target.
295# @param $(target) Target name.
296define def_inherit_template
297$(foreach prop,$(PROPS_SINGLE),$(eval $(value def_inherit_template_one)))
298$(foreach prop,$(PROPS_DEFERRED),$(eval $(def_inherit_template_one_deferred))) # exploits the 2 evaluation, so no value!
299$(foreach prop,$(PROPS_ACCUMULATE),$(eval $(value def_inherit_template_one_accumulate)))
300endef
301
302# Inherit template properties
303$(foreach target, $(ALL_TARGETS),$(eval $(value def_inherit_template)))
304
305
306#
307# Include tools
308#
309_TOOLS := $(TOOL)
310define def_tools_target_source
311$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
312 $($(source)_$(prop).$(BUILD_TARGET)) \
313 $($(target)_$(source)_$(prop).$(BUILD_TARGET)) \
314 $($(source)_$(prop)) \
315 $($(target)_$(source)_$(prop))))
316endef
317
318define def_tools_target
319$(eval _TOOLS += $(foreach prop, $(PROPS_TOOLS), \
320 $($(target)_$(prop).$(BUILD_TARGET)) \
321 $($(target)_$(prop))))
322$(foreach source, \
323 $($(target)_SOURCES.$(BUILD_TARGET)) \
324 $($(target)_SOURCES.$(BUILD_TYPE)) \
325 $($(target)_SOURCES) \
326 , $(eval $(value def_tools_target_source)))
327endef
328
329$(foreach target, $(ALL_TARGETS), $(eval $(value def_tools_target)))
330_TOOLS := $(sort $(_TOOLS))
331
332define def_tools_include
333ifndef TOOL_$(tool)
334TOOL_$(tool)_KMK_FILE := $(firstword $(foreach path, $(TOOL_PATHS) $(PATH_KBUILD)/tools, $(wildcard $(path)/$(tool).kmk)))
335ifeq ($(TOOL_$(tool)_KMK_FILE),)
336$(error kBuild: Cannot find include file for the tool '$(tool)'! Searched: $(TOOL_PATHS) $(PATH_KBUILD)/tools)
337endif
338include $(TOOL_$(tool)_KMK_FILE)
339endif
340endef
341$(foreach tool, $(_TOOLS), $(eval $(value def_tools_include)))
342
343
344#
345# Include SDKs
346#
347_SDKS := $(SDKS)
348define def_sdks_target_source
349$(foreach sdk, $($(source)_SDKS) $($(source)_SDKS.$(BUILD_TARGET)) $($(source)_SDKS.$(BUILD_TYPE)) \
350 $($(target)_$(source)_SDKS) $($(target)_$(source)_SDKS.$(BUILD_TARGET)) $($(target)_$(source)_SDKS.$(BUILD_TYPE)), \
351 $(eval _SDKS += $(sdk)))
352endef
353define def_sdks_target
354$(foreach sdk, $($(target)_SDKS) $($(target)_SDKS.$(BUILD_TARGET)) $($(target)_SDKS.$(BUILD_TYPE))\
355 , $(eval _SDKS += $(sdk)))
356$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TYPE))\
357 , $(eval $(def_sdks_target_source)))
358endef
359$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
360_SDKS := $(sort $(_SDKS))
361
362define def_sdks_include_one
363ifndef SDK_$(sdk)
364SDK_$(sdk)_KMK_FILE := $(firstword $(foreach path, $(SDK_PATHS) $(PATH_KBUILD)/sdks, $(wildcard $(path)/$(sdk).kmk)))
365ifeq ($(SDK_$(sdk)_KMK_FILE),)
366$(error kBuild: Cannot find include file for the SDK '$(sdk)'! Searched: $(SDK_PATHS) $(PATH_KBUILD)/sdks)
367endif
368include $(SDK_$(sdk)_KMK_FILE)
369endif
370endef
371$(foreach sdk, $(_SDKS), $(eval $(value def_sdks_include_one)))
372
373
374#
375# Object processing.
376#
377
378## wrapper the compile command dependency check.
379ifndef NO_COMPILE_CMDS_DEPS
380_DEP_COMPILE_CMDS = $(if $(subst $(strip $($(target)_$(source)_CMDS_PREV_)),,$(strip $($(target)_$(source)_CMDS_))),FORCE,)
381else
382_DEP_COMPILE_CMDS =
383endif
384
385## Generates the rules for building a specific object, and the '::' aliases
386# for building a source file.
387# @param $(obj) The object file.
388define def_target_source_rule
389$(obj) $($(target)_$(source)_OUTPUT_): \
390 $($(target)_$(source)_DEPEND_) \
391 $(_DEP_COMPILE_CMDS) \
392 | \
393 $($(target)_$(source)_DEPORD_)
394 $(call MSG_L1,Creating $$@)
395 $(RM) -f $(dep) $(out) $($(target)_$(source)_OUTPUT_)
396 $(custom_pre)
397
398$($(target)_$(source)_CMDS_)
399
400 $(custom_post)
401ifndef NO_COMPILE_CMDS_DEPS
402 @$(APPEND) "$(dep)"
403 @$(APPEND) "$(dep)" 'define $(target)_$(source)_CMDS_PREV_'
404 @$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_$(source)_CMDS_))'
405 @$(APPEND) "$(dep)" 'endef'
406endif
407
408$(basename $(notdir $(obj))).o::
409 + $$(MAKE) -B -f $$(MAKEFILE) $(obj)
410$(basename $$(notdir $$(obj))).obj::
411 + $$(MAKE) -B -f $$(MAKEFILE) $(obj)
412endef
413
414
415## wrapper the link command dependency check.
416ifndef NO_COMPILE_CMDS_DEPS
417_DEP_LINK_CMDS = $(if $(subst $(strip $($(target)_CMDS_PREV_)),,$(strip $($(target)_CMDS_))),FORCE,)
418else
419_DEP_LINK_CMDS =
420endif
421
422## Generate the link rule for a target.
423# @param $(target) The normalized target name.
424# @param $(dirdep) Directories we depend upon begin created before linking.
425# @param $(dep) The name of the dependency file.
426# @param $(out)
427# @param $($(target)_OUTPUT_) Output files from the link.
428# @param $($(target)_DEPEND_) Dependencies.
429# @param $($(target)_DEPORD_) Dependencies which should only affect build order.
430# @param $($(target)_CMDS_) The link commands.
431# @param $($(target)_CMDS_PREV_) The link commands from the previous run.
432define def_link_rule
433$(out) $($(target)_OUTPUT_): \
434 $($(target)_DEPEND_) \
435 $(_DEP_LINK_CMDS) \
436 | \
437 $($(target)_DEPORD_)
438 $(call MSG_L1,Creating $$@)
439 $(RM) -f $(dep) $($(target)_OUTPUT_)
440 $(custom_pre)
441
442$($(target)_CMDS_)
443
444 $(custom_post)
445ifndef NO_LINK_CMDS_DEP
446 @$(APPEND) "$(dep)" 'define $(target)_CMDS_PREV_'
447 @$(APPEND) "$(dep)" '$(subst $(NL),'$(NL)$(TAB)@$(APPEND) "$(dep)" ',$($(target)_CMDS_))'
448 @$(APPEND) "$(dep)" 'endef'
449endif
450
451$(basename $(notdir $(out)))::
452 + $$(MAKE) -B -f $$(MAKEFILE) $(out)
453endef
454
455
456## Generate the link & lib install rule
457# @param $(target) Normalized target name.
458# @param $(out) The build target.
459# @param $(INSTARGET_$(target)) The installation targets.
460# @param $(mode) The file mode (optional)
461define def_link_install_rule
462$(INSTARGET_$(target)) : $(out) | $(call DIRDEP,$(dir $(INSTARGET_$(target))))
463 $(INSTALL) $$(if $(mode),-m $(mode)) $(out) $$@
464endef
465
466
467
468## Generic macro for processing C, C++ and Assembly sources.
469# @param $(target) Normalized target name.
470# @param $(source) Source file name.
471# @param $(type) Source type. {C,CXX,AS}
472# @param bld_type Build type.
473# @param bld_trg Build target.
474# @param bld_trg_arch Build target arch.
475# @param bld_trg_cpu Build target cpu.
476#
477# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
478# @remark I now have a clue. Have to use $$ if not.
479define def_target_source_c_cpp_asm
480#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
481
482tool := $(call _SOURCE_TOOL,$(source),$(target),$(type))
483outbase := $(call _OBJECT_BASE,$(source),$(target))
484PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase)))
485dirdep := $(call DIRDEP,$(dir $(outbase)))
486defs :=\
487 $(TOOL_$(tool)_DEFS)\
488 $(TOOL_$(tool)_DEFS.$(bld_type))\
489 $(TOOL_$(tool)_DEFS.$(bld_trg))\
490 $(TOOL_$(tool)_DEFS.$(bld_trg_arch))\
491 $(TOOL_$(tool)_DEFS.$(bld_trg_cpu))\
492 $(TOOL_$(tool)_$(type)DEFS)\
493 $(TOOL_$(tool)_$(type)DEFS.$(bld_type))\
494 $(foreach sdk, $(SDKS.$(bld_trg)) \
495 $(SDKS.$(bld_type)) \
496 $(SDKS),\
497 $(SDK_$(sdk)_DEFS)\
498 $(SDK_$(sdk)_DEFS.$(bld_type))\
499 $(SDK_$(sdk)_DEFS.$(bld_trg))\
500 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
501 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
502 $(SDK_$(sdk)_$(type)DEFS)\
503 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
504 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
505 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
506 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
507 $(DEFS)\
508 $(DEFS.$(bld_type))\
509 $(DEFS.$(bld_trg))\
510 $(DEFS.$(bld_trg_arch))\
511 $(DEFS.$(bld_trg_cpu))\
512 $($(type)DEFS)\
513 $($(type)DEFS.$(bld_type))\
514 $($(type)DEFS.$(bld_trg))\
515 $($(type)DEFS.$(bld_trg_arch))\
516 $($(type)DEFS.$(bld_trg_cpu))\
517 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
518 $($(target)_SDKS.$(bld_type)) \
519 $($(target)_SDKS),\
520 $(SDK_$(sdk)_DEFS)\
521 $(SDK_$(sdk)_DEFS.$(bld_type))\
522 $(SDK_$(sdk)_DEFS.$(bld_trg))\
523 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
524 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
525 $(SDK_$(sdk)_$(type)DEFS)\
526 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
527 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
528 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
529 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
530 $($(target)_DEFS)\
531 $($(target)_DEFS.$(bld_type))\
532 $($(target)_DEFS.$(bld_trg))\
533 $($(target)_DEFS.$(bld_trg_arch))\
534 $($(target)_DEFS.$(bld_trg_cpu))\
535 $($(target)_$(type)DEFS)\
536 $($(target)_$(type)DEFS.$(bld_type))\
537 $($(target)_$(type)DEFS.$(bld_trg))\
538 $($(target)_$(type)DEFS.$(bld_trg_arch))\
539 $($(target)_$(type)DEFS.$(bld_trg_cpu))\
540 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
541 $($(source)_SDKS.$(bld_type)) \
542 $($(source)_SDKS),\
543 $(SDK_$(sdk)_DEFS)\
544 $(SDK_$(sdk)_DEFS.$(bld_type))\
545 $(SDK_$(sdk)_DEFS.$(bld_trg))\
546 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
547 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
548 $(SDK_$(sdk)_$(type)DEFS)\
549 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
550 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
551 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
552 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
553 $($(source)_DEFS)\
554 $($(source)_DEFS.$(bld_type))\
555 $($(source)_DEFS.$(bld_trg))\
556 $($(source)_DEFS.$(bld_trg_arch))\
557 $($(source)_DEFS.$(bld_trg_cpu))\
558 $($(source)_$(type)DEFS)\
559 $($(source)_$(type)DEFS.$(bld_type))\
560 $($(source)_$(type)DEFS.$(bld_trg))\
561 $($(source)_$(type)DEFS.$(bld_trg_arch))\
562 $($(source)_$(type)DEFS.$(bld_trg_cpu))\
563 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
564 $($(target)_$(source)_SDKS.$(bld_type)) \
565 $($(target)_$(source)_SDKS),\
566 $(SDK_$(sdk)_DEFS)\
567 $(SDK_$(sdk)_DEFS.$(bld_type))\
568 $(SDK_$(sdk)_DEFS.$(bld_trg))\
569 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
570 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
571 $(SDK_$(sdk)_$(type)DEFS)\
572 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
573 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
574 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
575 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
576 $($(target)_$(source)_DEFS)\
577 $($(target)_$(source)_DEFS.$(bld_type))\
578 $($(target)_$(source)_DEFS.$(bld_trg))\
579 $($(target)_$(source)_DEFS.$(bld_trg_arch))\
580 $($(target)_$(source)_DEFS.$(bld_trg_cpu))\
581 $($(target)_$(source)_$(type)DEFS)\
582 $($(target)_$(source)_$(type)DEFS.$(bld_type))\
583 $($(target)_$(source)_$(type)DEFS.$(bld_trg))\
584 $($(target)_$(source)_$(type)DEFS.$(bld_trg_arch))\
585 $($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))
586incs :=\
587 $($(target)_$(source)_$(type)INCS.$(bld_trg_cpu))\
588 $($(target)_$(source)_$(type)INCS.$(bld_trg_arch))\
589 $($(target)_$(source)_$(type)INCS.$(bld_trg))\
590 $($(target)_$(source)_$(type)INCS.$(bld_type))\
591 $($(target)_$(source)_$(type)INCS)\
592 $($(target)_$(source)_INCS.$(bld_trg_cpu))\
593 $($(target)_$(source)_INCS.$(bld_trg_arch))\
594 $($(target)_$(source)_INCS.$(bld_trg))\
595 $($(target)_$(source)_INCS.$(bld_type))\
596 $($(target)_$(source)_INCS)\
597 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
598 $($(target)_$(source)_SDKS.$(bld_type)) \
599 $($(target)_$(source)_SDKS),\
600 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
601 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
602 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
603 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
604 $(SDK_$(sdk)_$(type)INCS)\
605 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
606 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
607 $(SDK_$(sdk)_INCS.$(bld_trg))\
608 $(SDK_$(sdk)_INCS.$(bld_type))\
609 $(SDK_$(sdk)_INCS))\
610 $($(source)_$(type)INCS.$(bld_trg_cpu))\
611 $($(source)_$(type)INCS.$(bld_trg_arch))\
612 $($(source)_$(type)INCS.$(bld_trg))\
613 $($(source)_$(type)INCS.$(bld_type))\
614 $($(source)_$(type)INCS)\
615 $($(source)_INCS.$(bld_trg_cpu))\
616 $($(source)_INCS.$(bld_trg_arch))\
617 $($(source)_INCS.$(bld_trg))\
618 $($(source)_INCS.$(bld_type))\
619 $($(source)_INCS)\
620 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
621 $($(source)_SDKS.$(bld_type)) \
622 $($(source)_SDKS),\
623 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
624 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
625 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
626 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
627 $(SDK_$(sdk)_$(type)INCS)\
628 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
629 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
630 $(SDK_$(sdk)_INCS.$(bld_trg))\
631 $(SDK_$(sdk)_INCS.$(bld_type))\
632 $(SDK_$(sdk)_INCS))\
633 $($(target)_$(type)INCS.$(bld_trg_cpu))\
634 $($(target)_$(type)INCS.$(bld_trg_arch))\
635 $($(target)_$(type)INCS.$(bld_trg))\
636 $($(target)_$(type)INCS.$(bld_type))\
637 $($(target)_$(type)INCS)\
638 $($(target)_INCS.$(bld_trg_cpu))\
639 $($(target)_INCS.$(bld_trg_arch))\
640 $($(target)_INCS.$(bld_trg))\
641 $($(target)_INCS.$(bld_type))\
642 $($(target)_INCS)\
643 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
644 $($(target)_SDKS.$(bld_type)) \
645 $($(target)_SDKS),\
646 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
647 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
648 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
649 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
650 $(SDK_$(sdk)_$(type)INCS)\
651 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
652 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
653 $(SDK_$(sdk)_INCS.$(bld_trg))\
654 $(SDK_$(sdk)_INCS.$(bld_type))\
655 $(SDK_$(sdk)_INCS))\
656 $(INCS.$(bld_trg_cpu))\
657 $(INCS.$(bld_trg_arch))\
658 $(INCS.$(bld_trg))\
659 $(INCS.$(bld_type))\
660 $(INCS)\
661 $(foreach sdk, $(SDKS.$(bld_trg)) \
662 $(SDKS.$(bld_type)) \
663 $(SDKS),\
664 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
665 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
666 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
667 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
668 $(SDK_$(sdk)_$(type)INCS)\
669 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
670 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
671 $(SDK_$(sdk)_INCS.$(bld_trg))\
672 $(SDK_$(sdk)_INCS.$(bld_type))\
673 $(SDK_$(sdk)_INCS))\
674 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_cpu))\
675 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_arch))\
676 $(TOOL_$(tool)_$(type)INCS.$(bld_trg))\
677 $(TOOL_$(tool)_$(type)INCS.$(bld_type))\
678 $(TOOL_$(tool)_$(type)INCS)
679flags :=\
680 $(TOOL_$(tool)_$(type)FLAGS)\
681 $(TOOL_$(tool)_$(type)FLAGS.$(bld_type))\
682 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg))\
683 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_arch))\
684 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_cpu))\
685 $($(type)FLAGS)\
686 $($(type)FLAGS.$(bld_type))\
687 $($(type)FLAGS.$(bld_trg))\
688 $($(type)FLAGS.$(bld_trg_arch))\
689 $($(type)FLAGS.$(bld_trg_cpu))\
690 $($(target)_$(type)FLAGS)\
691 $($(target)_$(type)FLAGS.$(bld_type))\
692 $($(target)_$(type)FLAGS.$(bld_trg))\
693 $($(target)_$(type)FLAGS.$(bld_trg_arch))\
694 $($(target)_$(type)FLAGS.$(bld_trg_cpu))\
695 $($(source)_$(type)FLAGS)\
696 $($(source)_$(type)FLAGS.$(bld_type))\
697 $($(source)_$(type)FLAGS.$(bld_trg))\
698 $($(source)_$(type)FLAGS.$(bld_trg_arch))\
699 $($(source)_$(type)FLAGS.$(bld_trg_cpu))\
700 $($(target)_$(source)_$(type)FLAGS)\
701 $($(target)_$(source)_$(type)FLAGS.$(bld_type))\
702 $($(target)_$(source)_$(type)FLAGS.$(bld_trg))\
703 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_arch))\
704 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))
705objsuff := $(firstword \
706 $($(target)_$(source)_OBJSUFF.$(bld_trg))\
707 $($(target)_$(source)_OBJSUFF)\
708 $($(source)_OBJSUFF.$(bld_trg))\
709 $($(source)_OBJSUFF)\
710 $($(target)_OBJSUFF.$(bld_trg))\
711 $($(target)_OBJSUFF)\
712 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
713 $(TOOL_$(tool)_$(type)OBJSUFF)\
714 $(SUFF_OBJ))
715obj := $(outbase)$(objsuff)
716deps := \
717 $($(target)_$(source)_DEPS)\
718 $($(target)_$(source)_DEPS.$(bld_type))\
719 $($(target)_$(source)_DEPS.$(bld_trg))\
720 $($(target)_$(source)_DEPS.$(bld_trg_arch))\
721 $($(target)_$(source)_DEPS.$(bld_trg_cpu))\
722 $($(source)_DEPS)\
723 $($(source)_DEPS.$(bld_type))\
724 $($(source)_DEPS.$(bld_trg))\
725 $($(source)_DEPS.$(bld_trg_arch))\
726 $($(source)_DEPS.$(bld_trg_cpu))\
727 $($(target)_DEPS)\
728 $($(target)_DEPS.$(bld_type))\
729 $($(target)_DEPS.$(bld_trg_arch))\
730 $($(target)_DEPS.$(bld_trg_cpu))
731
732# dependencies
733dep := $(obj)$(SUFF_DEP)
734ifndef NO_COMPILE_DEPS
735_DEPFILES_INCLUDED += $(dep)
736$(if $(wildcard $(dep)),$(eval include $(dep)))
737endif
738
739#$ (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))
740ifndef TOOL_$(tool)_COMPILE_$(type)_CMDS
741$(warning kBuild: tools: \
742 1 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
743 2 $($(target)_$(source)_$(type)TOOL) \
744 3 $($(target)_$(source)_TOOL.$(bld_trg)) \
745 4 $($(target)_$(source)_TOOL) \
746 5 $($(target)_$(type)TOOL.$(bld_trg)) \
747 6 $($(target)_$(type)TOOL) \
748 7 $($(target)_TOOL.$(bld_trg)) \
749 8 $($(target)_TOOL) \
750 9 $($(source)_$(type)TOOL.$(bld_trg)) \
751 10 $($(source)_$(type)TOOL) \
752 11 $($(source)_TOOL.$(bld_trg)) \
753 12 $($(source)_TOOL) \
754 13 $($(type)TOOL.$(bld_trg)) \
755 14 $($(type)TOOL) \
756 15 $(TOOL.$(bld_trg)) \
757 16 $(TOOL) )
758$(error kBuild: TOOL_$(tool)_COMPILE_$(type)_CMDS is not defined. source=$(source) target=$(target) )
759endif
760
761# call the tool
762$(target)_$(source)_CMDS_ := $(TOOL_$(tool)_COMPILE_$(type)_CMDS)
763$(target)_$(source)_OUTPUT_ := $(TOOL_$(tool)_COMPILE_$(type)_OUTPUT)
764$(target)_$(source)_DEPEND_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPEND) $(deps) $(source)
765$(target)_$(source)_DEPORD_ := $(TOOL_$(tool)_COMPILE_$(type)_DEPORD) $(dirdep)
766
767# generate the compile rule.
768$(eval $(def_target_source_rule))
769
770_OUT_FILES += $($(target)_$(source)_OUTPUT_)
771$(target)_OBJS_ += $(obj)
772
773endef
774
775## Generic macro for processing all target sources.
776# @param $(target) Normalized target name.
777define def_target_sources
778#$ (warning def_target_sources)
779# C sources
780type := C
781$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
782 ,$(eval $(value def_target_source_c_cpp_asm)) )
783
784# C++ sources
785type := CXX
786$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
787 ,$(eval $(value def_target_source_c_cpp_asm)) )
788
789# ASM sources
790type := AS
791$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)))\
792 ,$(eval $(value def_target_source_c_cpp_asm)) )
793
794endef
795
796
797
798## Generic macro for generating the install rule(s) for a target
799# and update the globals with default out.
800#
801# @param $(target) Normalized target name.
802# @param $(out) The output file.
803# @param $(definst) The default _INST value.
804# @param $(typevar) The name of the variable with all the root targets of its type.
805# @obsolete
806define def_target_install_pluss
807ifndef $(target)_NOINST
808INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
809 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
810
811$(eval $(def_link_install_rule))
812
813_INSTALLS += $(INSTARGET_$(target))
814
815ifdef KBUILD_DO_AUTO_INSTALL
816$(typevar) += $(INSTARGET_$(target))
817else
818$(typevar) += $(out)
819endif
820else # _NOINST
821$(typevar) += $(out)
822endif
823
824_OUT_FILES += $(out)
825_CLEAN_FILES += $($(target)_CLEAN)
826_OBJS += $($(target)_OBJS_)
827
828endef
829
830
831
832#
833# LIBRARIES
834#
835
836## Library (one).
837# @param $(target) Normalized library (target) name.
838define def_lib
839# library basics
840## @todo prefix
841bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
842bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
843bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
844bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
845tool := $(call _TARGET_TOOL,$(target),AR)
846ifeq ($(tool),)
847$(error kBuild: Library target $(target) does not have a tool defined!)
848endif
849outbase := $(call _TARGET_BASE,$(target),$(target))
850PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
851suff := $(firstword\
852 $($(target)_LIBSUFF.$(bld_trg))\
853 $($(target)_LIBSUFF)\
854 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
855 $(TOOL_$(tool)_ARLIBSUFF)\
856 $(SUFF_LIB))
857out := $(outbase)$(suff)
858TARGET_$(target) := $(out)
859$(target)_OBJS_ := $(filter %.o %.obj, \
860 $($(target)_SOURCES) \
861 $($(target)_SOURCES.$(bld_trg)) \
862 $($(target)_SOURCES.$(bld_trg_arch)) \
863 $($(target)_SOURCES.$(bld_trg_cpu)) \
864 $($(target)_SOURCES.$(bld_type)))
865
866
867# source -> object
868$(eval $(value def_target_sources))
869
870# library linking
871tool := $(call _TARGET_TOOL,$(target),AR)
872outbase := $(call _TARGET_BASE,$(target),$(target))
873flags :=\
874 $(TOOL_$(tool)_ARFLAGS)\
875 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
876 $(ARFLAGS)\
877 $(ARFLAGS.$(bld_type))\
878 $($(target)_ARFLAGS)\
879 $($(target)_ARFLAGS.$(bld_type))
880othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
881 $($(target)_SOURCES) \
882 $($(target)_SOURCES.$(bld_trg)) \
883 $($(target)_SOURCES.$(bld_trg_arch)) \
884 $($(target)_SOURCES.$(bld_trg_cpu)) \
885 $($(target)_SOURCES.$(bld_type)))
886objs = $($(target)_OBJS_)
887dirdep := $(call DIRDEP,$(dir $(out)))
888## @todo fix dependencies on makefiles an such
889deps := $($(target)_DEPS)
890
891# dependency file
892dep := $(out)$(SUFF_DEP)
893ifndef NO_LINK_CMDS_DEP
894_DEPFILES_INCLUDED += $(dep)
895$(if $(wildcard $(dep)),$(eval include $(dep)))
896endif
897
898# check that the tool is defined.
899ifndef TOOL_$(tool)_LINK_LIBRARY_CMDS
900$(warning kBuild: tools: \
901 1 $($(target)_$(source)TOOL.$(bld_trg)) \
902 2 $($(target)_$(source)TOOL) \
903 3 $($(target)_TOOL.$(bld_trg)) \
904 4 $($(target)_TOOL) \
905 5 $($(source)TOOL) \
906 6 $($(source)TOOL.$(bld_trg)) \
907 7 $(TOOL.$(bld_trg)) \
908 8 $(TOOL) )
909$(error kBuild: TOOL_$(tool)_LINK_LIBRARY_CMDS isn't defined! target=$(target) )
910endif
911
912# call the tool
913$(target)_CMDS_ := $(TOOL_$(tool)_LINK_LIBRARY_CMDS)
914$(target)_OUTPUT_ := $(TOOL_$(tool)_LINK_LIBRARY_OUTPUT)
915$(target)_DEPEND_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPEND) $(deps) $(objs)
916$(target)_DEPORD_ := $(TOOL_$(tool)_LINK_LIBRARY_DEPORD) $(dirdep)
917
918# generate the link rule.
919$(eval $(def_link_rule))
920
921# installing and globals
922definst := $(PATH_LIB)
923typevar := _LIBS
924$(eval $(value def_target_install_pluss))
925endef
926
927# Process libraries
928mode := 0644
929$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(value def_lib)))
930
931
932#
933# Link operations.
934#
935
936##
937# Link prolog
938#
939# @param $(target) Normalized target name.
940# @param $(EXT) EXE,DLL,SYS.
941# @param $(definst) The default _INST value.
942# @param $(typevar) The name of the variable with all the root targets of its type.
943define def_link_common
944# basics
945bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
946bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_$(bld_trg_base_var)))
947bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_$(bld_trg_base_var)_ARCH))
948bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_$(bld_trg_base_var)_CPU))
949
950tool := $(call _TARGET_TOOL,$(target),LD)
951outbase := $(call _TARGET_BASE,$(target),$(target))
952suff := $(firstword \
953 $($(target)_$(EXT)SUFF) \
954 $($(target)_$(EXT)SUFF) \
955 $(TOOL_$(tool)_LD$(EXT)SUFF) \
956 $($(EXTPRE)SUFF_$(EXT)))
957out := $(outbase)$(suff)
958PATH_$(target) := $(patsubst %/,%,$(dir $(outbase)))
959TARGET_$(target) := $(out)
960$(target)_OBJS_ := $(filter %.o %.obj, \
961 $($(target)_SOURCES) \
962 $($(target)_SOURCES.$(bld_trg)) \
963 $($(target)_SOURCES.$(bld_trg_arch)) \
964 $($(target)_SOURCES.$(bld_trg_cpu)) \
965 $($(target)_SOURCES.$(bld_type)))
966
967# source -> object
968$(eval $(value def_target_sources))
969
970# more library stuff.
971tool := $(call _TARGET_TOOL,$(target),LD)
972outbase := $(call _TARGET_BASE,$(target),$(target))
973flags :=\
974 $(TOOL_$(tool)_LDFLAGS)\
975 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
976 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
977 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
978 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
979 $(LDFLAGS)\
980 $(LDFLAGS.$(bld_type))\
981 $(LDFLAGS.$(bld_trg))\
982 $(LDFLAGS.$(bld_trg_arch))\
983 $(LDFLAGS.$(bld_trg_cpu))\
984 $($(target)_LDFLAGS)\
985 $($(target)_LDFLAGS.$(bld_type))\
986 $($(target)_LDFLAGS.$(bld_trg))\
987 $($(target)_LDFLAGS.$(bld_trg_arch))\
988 $($(target)_LDFLAGS.$(bld_trg_cpu))
989othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm %.o %.obj,\
990 $($(target)_SOURCES)\
991 $($(target)_SOURCES.$(bld_trg)) \
992 $($(target)_SOURCES.$(bld_trg_arch)) \
993 $($(target)_SOURCES.$(bld_trg_cpu)) \
994 $($(target)_SOURCES.$(bld_type)))
995objs = $($(target)_OBJS_)
996libs :=\
997 $($(target)_LIBS.$(bld_trg_cpu))\
998 $($(target)_LIBS.$(bld_trg_arch))\
999 $($(target)_LIBS.$(bld_trg))\
1000 $($(target)_LIBS.$(bld_type))\
1001 $($(target)_LIBS)\
1002 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1003 $($(target)_SDKS.$(bld_type)) \
1004 $($(target)_SDKS),\
1005 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1006 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1007 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1008 $(SDK_$(sdk)_LIBS.$(bld_type))\
1009 $(SDK_$(sdk)_LIBS))\
1010 $(LIBS.$(bld_trg_cpu))\
1011 $(LIBS.$(bld_trg_arch))\
1012 $(LIBS.$(bld_trg))\
1013 $(LIBS.$(bld_type))\
1014 $(LIBS)\
1015 $(foreach sdk, $(SDKS.$(bld_trg)) \
1016 $(SDKS.$(bld_type)) \
1017 $(SDKS),\
1018 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1019 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1020 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1021 $(SDK_$(sdk)_LIBS.$(bld_type))\
1022 $(SDK_$(sdk)_LIBS))\
1023 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1024 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1025 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1026 $(TOOL_$(tool)_LIBS.$(bld_type))\
1027 $(TOOL_$(tool)_LIBS)
1028libpath :=\
1029 $($(target)_LIBPATH.$(bld_trg_cpu))\
1030 $($(target)_LIBPATH.$(bld_trg_arch))\
1031 $($(target)_LIBPATH.$(bld_trg))\
1032 $($(target)_LIBPATH.$(bld_type))\
1033 $($(target)_LIBPATH)\
1034 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1035 $($(target)_SDKS.$(bld_type)) \
1036 $($(target)_SDKS),\
1037 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1038 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1039 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1040 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1041 $(SDK_$(sdk)_LIBPATH))\
1042 $(LIBPATH.$(bld_trg_cpu))\
1043 $(LIBPATH.$(bld_trg_arch))\
1044 $(LIBPATH.$(bld_trg))\
1045 $(LIBPATH.$(bld_type))\
1046 $(LIBPATH)\
1047 $(foreach sdk, $(SDKS.$(bld_trg)) \
1048 $(SDKS.$(bld_type)) \
1049 $(SDKS),\
1050 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1051 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1052 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1053 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
1054 $(SDK_$(sdk)_LIBPATH))\
1055 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1056 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1057 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1058 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
1059 $(TOOL_$(tool)_LIBPATH)
1060dirdep := $(call DIRDEP,$(dir $(out)))
1061## @todo fix dependencies
1062deps := $($(target)_DEPS)
1063
1064## @todo this stuff can't be working.
1065custom_pre := $(strip $(firstword \
1066 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1067 $($(target)_CUSTOM_PRE.$(bld_trg))\
1068 $($(target)_CUSTOM_PRE.$(bld_type))\
1069 $($(target)_CUSTOM_PRE)\
1070 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1071 $(CUSTOM_PRE.$(bld_trg))\
1072 $(CUSTOM_PRE.$(bld_type))\
1073 $(CUSTOM_PRE)\
1074))
1075custom_post := $(strip $(firstword \
1076 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1077 $($(target)_CUSTOM_POST.$(bld_trg))\
1078 $($(target)_CUSTOM_POST.$(bld_type))\
1079 $($(target)_CUSTOM_POST)\
1080 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1081 $(CUSTOM_POST.$(bld_trg))\
1082 $(CUSTOM_POST.$(bld_type))\
1083 $(CUSTOM_POST)\
1084))
1085
1086# installation targets
1087ifndef $(target)_NOINST
1088INSTARGET_$(target) := $(patsubst %/,%/$(notdir $(out)), \
1089 $(if $($(target)_INST), $(addprefix $(PATH_INS)/,$($(target)_INST)), $(definst)/))
1090ifdef KBUILD_DO_AUTO_INSTALL
1091$(typevar) += $(INSTARGET_$(target))
1092else
1093$(typevar) += $(out)
1094endif
1095# generate the install rule
1096$(eval $(def_link_install_rule))
1097
1098else # NOINST
1099INSTARGET_$(target) :=
1100$(typevar) += $(out)
1101endif # NOINST
1102
1103# dependency file
1104dep := $(outbase)$(SUFF_DEP)
1105ifndef NO_LINK_CMDS_DEP
1106_DEPFILES_INCLUDED += $(dep)
1107$(if $(wildcard $(dep)),$(eval include $(dep)))
1108endif
1109
1110# check that the tool is defined.
1111ifndef TOOL_$(tool)_$(tool_do)_CMDS
1112$(warning kBuild: tools: \
1113 1 $($(target)_$(source)TOOL.$(bld_trg)) \
1114 2 $($(target)_$(source)TOOL) \
1115 3 $($(target)_TOOL.$(bld_trg)) \
1116 4 $($(target)_TOOL) \
1117 5 $($(source)TOOL) \
1118 6 $($(source)TOOL.$(bld_trg)) \
1119 7 $(TOOL.$(bld_trg)) \
1120 8 $(TOOL) )
1121$(error kBuild: TOOL_$(tool)_$(tool_do)_CMDS isn't defined! target=$(target) )
1122endif
1123
1124# call the tool
1125$(target)_CMDS_ := $(TOOL_$(tool)_$(tool_do)_CMDS)
1126$(target)_OUTPUT_ := $(TOOL_$(tool)_$(tool_do)_OUTPUT)
1127$(target)_DEPEND_ := $(TOOL_$(tool)_$(tool_do)_DEPEND) $(deps) $(objs)
1128$(target)_DEPORD_ := $(TOOL_$(tool)_$(tool_do)_DEPORD) $(dirdep)
1129
1130# generate the link rule.
1131$(eval $(def_link_rule))
1132
1133
1134# Update globals.
1135_OBJS += $($(target)_OBJS_)
1136_OUT_FILES += $($(target)_OUTPUT_) $(out)
1137_CLEAN_FILES += $($(target)_CLEAN)
1138_INSTALLS += $(INSTARGET_$(target))
1139
1140endef
1141
1142
1143#
1144# BLDPROGS
1145#
1146
1147## Build program (one).
1148# @param $(target) Normalized target (program) name.
1149define def_bldprog
1150
1151# set NOINST if not forced installation.
1152ifndef $(target)_INST
1153$(target)_NOINST := 1
1154endif
1155
1156# do the usual stuff.
1157$(eval $(value def_link_common))
1158
1159endef
1160
1161# Process build programs.
1162EXT := EXE
1163EXTPRE := HOST
1164tool_do := LINK_PROGRAM
1165definst := $(PATH_BIN)
1166typevar := _BLDPROGS
1167mode := 0755
1168bld_trg_base_var := PLATFORM
1169$(foreach target, $(BLDPROGS) $(BLDPROGS.$(BUILD_PLATFORM)), $(eval $(value def_bldprog)))
1170
1171
1172
1173#
1174# DLLS
1175#
1176
1177# Process dlls
1178EXT := DLL
1179EXTPRE :=
1180tool_do := LINK_DLL
1181definst := $(PATH_DLL)
1182typevar := _DLLS
1183mode := 0755
1184bld_trg_base_var := TARGET
1185$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(value def_link_common)))
1186
1187
1188#
1189# Process import libraries.
1190#
1191# - On OS/2 and windows these are libraries.
1192# - On other platforms they are fake DLLs.
1193ifeq ($(subst win32,os2,$(BUILD_TARGET)),os2)
1194$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(value def_lib)))
1195else
1196$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(value def_link_common)))
1197endif
1198$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), \
1199 $(eval _IMPORT_LIBS += $(if $(INSTARGET_$(target)),$(INSTARGET_$(target)), $(TARGET_$(target)))))
1200
1201
1202#
1203# PROGRAMS
1204#
1205
1206# Process programs
1207EXT := EXE
1208EXTPRE :=
1209tool_do := LINK_PROGRAM
1210definst := $(PATH_BIN)
1211typevar := _PROGRAMS
1212mode := 0755
1213bld_trg_base_var := TARGET
1214$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(value def_link_common)))
1215
1216
1217
1218#
1219# SYSMODS
1220#
1221
1222# Process sysmods
1223EXT := SYS
1224EXTPRE :=
1225tool_do := LINK_SYSMOD
1226definst := $(PATH_SYS)
1227typevar := _SYSMODS
1228mode := 0644
1229bld_trg_base_var := TARGET
1230$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(value def_link_common)))
1231
1232
1233#
1234# OTHERS
1235#
1236_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET))
1237
1238
1239#
1240# INSTALLS
1241#
1242
1243## generate the install rule
1244define def_install_src_rule
1245# the install rule
1246$(insdst) : $(srcsrc) | $(call DIRDEP,$(dir $(insdst)))
1247 $$(if $$(filter $(INSTALL),$(inscmd)),,$$(RM) -f $$@)
1248 $(inscmd)
1249endef
1250
1251## install one file
1252define def_install_src
1253
1254# deal with '=>' in the source file name.
1255srcdst := $(subst =>, ,$(src))
1256srcsrc := $(firstword $(srcdst))
1257srcdst := $(word $(words $(srcdst)),$(srcdst))
1258
1259# _INSTFUN
1260ifdef $(srcsrc)_INSTFUN
1261instfun := $(srcsrc)_INSTFUN
1262else
1263ifdef $(target)_INSTFUN
1264instfun := $(target)_INSTFUN
1265else
1266instfun := _INSTALL_FILE
1267endif
1268endif
1269
1270# _INST
1271ifdef $(srcsrc)_INST
1272inst := $(patsubst %/,%,$($(srcsrc)_INST))/$(dir $(srcdst))
1273else
1274ifdef $(target)_INST
1275inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(srcdst))
1276else
1277inst := $(dir $(srcdst))
1278endif
1279endif
1280
1281# calc target
1282insdst := $(call $(instfun),$(srcdst),$(target),$(inst),$(PATH_INS))
1283#$(warning instfun=$(instfun) srcdst=$(srcdst) target=$(target) srcdst=$(srcsrc) inst=$(inst) => insdst=$(insdst))
1284
1285# create the command
1286ifdef $(srcsrc)_INSTALLER
1287inscmd := $(call $(srcsrc)_INSTALLER,$(srcsrc),$(insdst),$(target))
1288else
1289ifdef $(target)_INSTALLER
1290inscmd := $(call $(target)_INSTALLER,$(srcsrc),$(insdst),$(target))
1291else
1292inscmd := $$(INSTALL) $(srcsrc) $(insdst)
1293endif
1294endif
1295
1296# generate the rule (need double evaluation here)
1297$(eval $(def_install_src_rule))
1298
1299INSTARGET_$(target) += $(insdst)
1300endef
1301
1302
1303## generate the symlink rule
1304define def_install_symlink_rule
1305# the install rule
1306$(insdst) : | $(call DIRDEP,$(dir $(insdst)))
1307 $$(RM) -f $$@
1308 $$(LN_SYMLINK) $(symdst) $(insdst)
1309endef
1310
1311## create one symlink
1312define def_install_symlink
1313
1314# deal with '=>' in the source file name.
1315symdst := $(subst =>, ,$(src))
1316symlnk := $(firstword $(symdst))
1317symdst := $(word $(words $(symdst)),$(symdst))
1318
1319# _INSTFUN
1320ifdef $(symlnk)_INSTFUN
1321instfun := $(symlnk)_INSTFUN
1322else
1323ifdef $(target)_INSTFUN
1324instfun := $(target)_INSTFUN
1325else
1326instfun := _INSTALL_FILE
1327endif
1328endif
1329
1330# _INST
1331ifdef $(symlnk)_INST
1332inst := $(patsubst %/,%,$($(symlnk)_INST))/$(dir $(symlnk))
1333else
1334ifdef $(target)_INST
1335inst := $(patsubst %/,%,$($(target)_INST))/$(dir $(symlnk))
1336else
1337inst := $(dir $(symlnk))
1338endif
1339endif
1340
1341# calc target
1342insdst := $(call $(instfun),$(symlnk),$(target),$(inst),$(PATH_INS))
1343#$(warning symlnk=$(symlnk) symdst=$(symdst) insdst=$(insdst) instfun=$(instfun) inst='$(inst)')
1344
1345# generate the rule (need double evaluation here)
1346$(eval $(def_install_symlink_rule))
1347
1348INSTARGET_$(target) += $(insdst)
1349endef
1350
1351
1352## generate the install rule
1353define def_install_directory_rule
1354# the install rule
1355$(insdst):
1356 $(INSTALL) -d \
1357 $(if $(uid),-o $(uid))\
1358 $(if $(gid),-g $(gid))\
1359 $(if $(mode),-m $(mode))\
1360 $(insdst)
1361
1362.NOTPARALLEL: $(insdst)
1363endef
1364
1365
1366## create one directory
1367define def_install_directory
1368
1369# _INST
1370ifdef $(directory)_INST
1371inst := $(PATH_INS)/$(patsubst %/,%,$($(directory)_INST))
1372else
1373ifdef $(target)_INST
1374inst := $(PATH_INS)/$(patsubst %/,%,$($(target)_INST))
1375else
1376inst := $(PATH_INS)
1377endif
1378endif
1379
1380mode := $(firstword \
1381 $($(target)_$(directory)_MODE.$(bld_trg)) \
1382 $($(target)_$(directory)_MODE) \
1383 $($(directory)_MODE.$(bld_trg)) \
1384 $($(directory)_MODE) \
1385 $($(target)_MODE.$(bld_trg)) \
1386 $($(target)_MODE))
1387uid := $(firstword \
1388 $($(target)_$(directory)_UID.$(bld_trg)) \
1389 $($(target)_$(directory)_UID) \
1390 $($(directory)_UID.$(bld_trg)) \
1391 $($(directory)_UID) \
1392 $($(target)_UID.$(bld_trg)) \
1393 $($(target)_UID))
1394gid := $(firstword \
1395 $($(target)_$(directory)_GID.$(bld_trg)) \
1396 $($(target)_$(directory)_GID) \
1397 $($(directory)_GID.$(bld_trg)) \
1398 $($(directory)_GID) \
1399 $($(target)_GID.$(bld_trg)) \
1400 $($(target)_GID))
1401
1402insdst := $(inst)/$(directory)/
1403#$(warning directory=$(directory) inst=$(inst) insdst=$(insdst) mode=$(mode) gid=$(gid) uid=$(uid))
1404
1405# generate the rule (need double evaluation here)
1406$(eval $(def_install_directory_rule))
1407
1408INSTARGET_DIRS_$(target) += $(insdst)
1409endef
1410
1411
1412## process one install target.
1413define def_install
1414bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE))
1415bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))
1416bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH))
1417bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU))
1418
1419INSTARGET_$(target) :=
1420INSTARGET_DIRS_$(target) :=
1421
1422$(foreach directory,$($(target)_DIRS) $($(target)_DIRS.$(bld_trg)) $($(target)_DIRS.$(bld_trg_arch)) $($(target)_DIRS.$(bld_trg_cpu)) $($(target)_DIRS.$(bld_type)), \
1423 $(eval $(value def_install_directory)))
1424
1425$(foreach src,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_trg_arch)) $($(target)_SOURCES.$(bld_trg_cpu)) $($(target)_SOURCES.$(bld_type)), \
1426 $(eval $(value def_install_src)))
1427
1428$(foreach src,$($(target)_SYMLINKS) $($(target)_SYMLINKS.$(bld_trg)) $($(target)_SYMLINKS.$(bld_trg_arch)) $($(target)_SYMLINKS.$(bld_trg_cpu)) $($(target)_SYMLINKS.$(bld_type)), \
1429 $(eval $(value def_install_symlink)))
1430
1431_INSTALLS += $(INSTARGET_$(target)) $($(target)_GOALS)
1432_INSTALLS_DIRS += $(INSTARGET_DIRS_$(target))
1433endef
1434
1435## process all install targets
1436$(foreach target, $(INSTALLS) $(INSTALLS.$(BUILD_TARGET)), \
1437 $(eval $(value def_install)))
1438
1439
1440#
1441# DOCS
1442#
1443
1444
1445#
1446# PACKING
1447#
1448packing::
1449
1450
1451#
1452# DIRECTORIES
1453#
1454_DIR_ALL := $(sort $(addsuffix /,$(patsubst %/,%,$(_DIRS))) $(dir $(_OUT_FILES) $(_OBJS) $(_INSTALLS)))
1455$(foreach directory,$(_INSTALLS_DIRS), $(eval _DIR_ALL := $(filter-out $(directory),$(_DIR_ALL))))
1456
1457
1458define def_mkdir_rule
1459$(directory):
1460 $(call MSG_L1,Creating directory $$@)
1461 $(MKDIR) -p $$@
1462endef
1463
1464$(foreach directory,$(_DIR_ALL),$(eval $(def_mkdir_rule)))
1465
1466
1467#
1468# NOTHING
1469#
1470do-nothing:
1471 $(call MSG_L1,Did nothing in $(CURDIR))
1472
1473
1474#
1475# CLEAN UP
1476#
1477do-clean:
1478 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DEPFILES_INCLUDED) $(_CLEAN_FILES) $(OTHER_CLEAN)
1479
1480
1481#
1482# PASSES (including directory and makefile walking)
1483#
1484
1485## Subdir
1486# @param $(pass) Lowercase pass name.
1487# @param $(PASS) Uppercase pass name.
1488# @param $(subdir) Subdirectory
1489# @param $(tag) tag to attach to the rule name.
1490define def_pass_subdir
1491pass_$(pass)$(tag):: $(dep)
1492 + $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
1493endef
1494
1495## Submakefile
1496# @param $(pass) Lowercase pass name.
1497# @param $(PASS) Uppercase pass name.
1498# @param $(makefile) Makefile.
1499# @param $(tag) tag to attach to the rule name.
1500define def_pass_makefile
1501pass_$(pass)$(tag):: $(dep)
1502 + $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
1503endef
1504
1505## Execute a pass.
1506# @param $(pass) Lowercase pass name.
1507# @param $(PASS) Uppercase pass name.
1508define def_pass_old
1509$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)))
1510$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)))
1511$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
1512$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)))
1513
1514$(eval tag:=_before)
1515$(eval dep:=)
1516$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1517$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
1518
1519$(eval tag:=_after)
1520$(eval dep:=pass_$(pass)_doit)
1521$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1522$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
1523
1524.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1525.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
1526pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
1527pass_$(pass)_this: pass_$(pass)_before
1528 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1529pass_$(pass)_after:: pass_$(pass)_this
1530pass_$(pass): pass_$(pass)_after
1531
1532endef
1533
1534define def_pass
1535$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)))
1536$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)))
1537$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
1538$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)))
1539
1540$(eval tag:=_before)
1541$(eval dep:=)
1542$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1543$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
1544
1545$(eval tag:=_after)
1546$(eval dep:=pass_$(pass)_doit)
1547$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1548$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
1549
1550ifdef KBUILD_SAFE_PARALLEL
1551.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this
1552.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_this pass_$(pass)_doit
1553pass_$(pass)_doit: $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$(var))
1554pass_$(pass)_this: pass_$(pass)_before
1555 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1556pass_$(pass)_after:: pass_$(pass)_this
1557pass_$(pass): pass_$(pass)_after
1558else
1559.NOTPARALLEL: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
1560.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_after pass_$(pass)_doit
1561pass_$(pass)_doit: pass_$(pass)_before \
1562 $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var)))
1563pass_$(pass): \
1564 pass_$(pass)_before \
1565 pass_$(pass)_doit \
1566 pass_$(pass)_after
1567endif
1568
1569#$ (warning pass=$(pass) PASS=$(PASS): $(PASS_$(PASS)_trgs) $(PASS_$(PASS)_trgs) $(foreach var,$(PASS_$(PASS)_vars),$($(var))))
1570endef
1571
1572# Generate the defined passes.
1573$(foreach PASS, $(PASSES), \
1574 $(eval pass := $(PASS_$(PASS)_pass)) \
1575 $(eval $(def_pass)))
1576
1577## Pass order
1578# @param $(pass) Current pass name.
1579# @param $(prev_pass) The previous pass name.
1580define def_pass_order
1581ifdef KBUILD_SAFE_PARALLEL
1582.NOTPARALLEL: pass_$(pass)_order
1583.PHONY: pass_$(pass)_order
1584pass_$(pass)_order: $(pass_prev)
1585 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
1586 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
1587else
1588.NOTPARALLEL: pass_$(pass)_order pass_$(pass)_banner
1589.PHONY: pass_$(pass)_order pass_$(pass)_banner
1590pass_$(pass)_banner:
1591 $(call MSG_L1,Pass - $(if $(PASS_$(PASS)),$(PASS_$(PASS)),$(pass)))
1592pass_$(pass)_order: \
1593 $(pass_prev) \
1594 pass_$(pass)_banner \
1595 pass_$(pass)
1596endif
1597$(eval pass_prev := pass_$(pass)_order)
1598endef
1599
1600## PASS: order
1601# Use dependencies to ensure correct pass order.
1602pass_prev :=
1603$(foreach PASS,$(DEFAULT_PASSES),\
1604 $(eval pass := $(PASS_$(PASS)_pass)) \
1605 $(eval $(def_pass_order)))
1606
1607
1608#
1609# THE MAIN RULES
1610#
1611all_recursive: $(pass_prev)
1612
1613rebuild: clean
1614 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
1615
1616# @todo make this a non-default pass!
1617uninstall:
1618 $(RM) -f $(_INSTALLS)
1619
1620install: pass_installs
1621
1622# misc shortcuts.
1623targets: bldprogs libraries dlls programs sysmods others installs
1624objects: $(_OBJS)
1625bldprogs: $(_BLDPROGS)
1626libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1627dlls: $(_DLLS)
1628programs: $(_PROGRAMS)
1629sysmods: $(_SYSMODS)
1630others: $(_OTHERS)
1631installs: $(_INSTALLS_DIRS) $(_INSTALLS)
1632
1633
1634#
1635# kBuild debugging stuff.
1636#
1637_SPACE := $(subst ., ,.)
1638_TAB := $(subst ., ,.)
1639define _NEWLINE
1640
1641
1642endef
1643NLTAB = $(_NEWLINE)$(TAB)
1644show_targets:
1645 @$(foreach target, $(ALL_TARGETS),\
1646 @$(ECHO) "target: $(target)" $(NLTAB)\
1647 @$(ECHO) " PATH_$(target)=$(PATH_$(target))" $(NLTAB)\
1648 @$(ECHO) " TARGET_$(target)=$(TARGET_$(target))" $(NLTAB)\
1649 @$(ECHO) " INSTARGET_$(target)=$(INSTARGET_$(target))" $(NLTAB)\
1650$(foreach prop,$(PROPS_SINGLE) $(PROPS_ACCUMULATE) OBJS_ CLEAN, \
1651 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1652 $(if $($(target)_$(prop).$(_tmp)),\
1653 @$(ECHO) " $(target)_$(prop).$(_tmp)=$($(target)_$(prop).$(_tmp))" $(NLTAB)) \
1654 $(if $($(target)_$(prop)), $(NLTAB)@$(ECHO) " $(target)_$(prop)=$($(target)_$(prop))" $(NLTAB)) \
1655)\
1656$(foreach prop,$(PROPS_DEFERRED), \
1657 $(eval _tmp:=$(firstword $($(target)_BLD_TRG) $(BUILD_TARGET))) \
1658 $(if $(value $(target)_$(prop).$(_tmp)),\
1659 @$(ECHO) ' $(target)_$(prop).$(_tmp)=$(value $(TARGET)_$(prop).$(_tmp))' $(NLTAB)) \
1660 $(if $(value $(target)_$(prop)), $(NLTAB)@$(ECHO) ' $(target)_$(prop)=$(value $(target)_$(prop))' $(NLTAB)) \
1661))
1662
1663
1664
1665#
1666# Include dependency files.
1667#
1668$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1669
1670
1671# end-of-file-content
1672__footer_kmk__ := target
1673endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.