source: trunk/kBuild/footer.kmk@ 460

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

fixed sdks and tools inclusion.

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