source: trunk/kBuild/footer.kmk@ 449

Last change on this file since 449 was 447, checked in by bird, 19 years ago

corrected bldprogs to inherit .$(BUILD_PLATFORM) instead of .$(BUILD_TARGET) from the template. Also fixed incorrect inheritance of the default template/tool.

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