source: trunk/kBuild/footer.kmk@ 454

Last change on this file since 454 was 450, checked in by bird, 19 years ago

Fixed regression/bug from the inherit defaults change - we didn't include the default tool anylonger.

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