source: trunk/kBuild/footer.kmk@ 457

Last change on this file since 457 was 455, checked in by bird, 19 years ago

Added arch and cpu to the template to template inheritance. removed some obsolete stuff.

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