source: trunk/kBuild/footer.kmk@ 416

Last change on this file since 416 was 414, checked in by bird, 20 years ago

Packing pass change - uses PACKING var. Added mode,uid and gid to file INSTALLS.

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