source: trunk/kBuild/footer.kmk@ 221

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

_BLD_* attributes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 51.8 KB
RevLine 
[72]1# $Id: footer.kmk 221 2005-02-08 17:22:53Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
[189]6# Copyright (c) 2004 knut st. osmundsen <bird-srcspam@anduin.net>
[72]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
[106]13# the Free Software Foundation; either version source of the License, or
[72]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
[106]23# Foundation, Inc., 59 Temple Place, Suite typetype0, Boston, MA 0sourcetargettargettarget-targettype07 USA
[72]24#
25#
26
27ifndef __footer_kmk__
28# start-of-file-content
29
30#
31# Variables.
[73]32# (Some of these need initialization before including definitions using them.)
[72]33#
34
35# all targets.
[138]36ALL_TARGETS := \
[189]37 $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)) \
38 $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)) \
39 $(DLLS) $(DLLS.$(BUILD_TARGET)) \
40 $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)) \
41 $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)) \
42 $(OTHERS) $(OTHERS.$(BUILD_TARGET))
[72]43
[75]44# dependency files.
45_DEPFILES :=
46
47# All kind of output files except for _OBJS and _DEPFILES.
48# Compiling or linking definition outputting other things that $@ and any
49# required dependency file must add those output files to this variable.
50_OUT_FILES :=
51
[72]52# all of a type
[219]53_OBJS :=
54_LIBS :=
55_DLLS :=
56_PROGRAMS :=
57_SYSMODS :=
58_DIRS :=
[189]59_IMPORT_LIBS :=
[72]60
[220]61# misc
62pass_prev :=
63
64
[72]65# all objs of a specific target
66define def_objs_var
[106]67_OBJS_$target :=
[72]68endef
69$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
70
71#
[73]72# Basic macros
73#
74
75## Figure out the tool for a source
[106]76# @param $target source file
77# @param $source normalized main target
78# @param $type tooltype
[79]79_SOURCE_TOOL = $(strip $(firstword \
[106]80 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) \
81 $($(target)_$(source)_$(type)TOOL) \
82 $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
83 $($(target)_$(source)_TOOL) \
84 $($(target)_$(type)TOOL.$(BUILD_TARGET)) \
85 $($(target)_$(type)TOOL) \
86 $($(target)_TOOL.$(BUILD_TARGET)) \
87 $($(target)_TOOL) \
88 $($(source)_$(type)TOOL.$(BUILD_TARGET)) \
89 $($(source)_$(type)TOOL) \
90 $($(source)_TOOL.$(BUILD_TARGET)) \
91 $($(source)_TOOL) \
92 $($(type)TOOL.$(BUILD_TARGET)) \
93 $($(type)TOOL) \
94 $(TOOL.$(BUILD_TARGET)) \
95 $(TOOL) ))
[73]96
[106]97_SOURCE_TOOL_OLD = $(strip $(firstword \
98 $($(target)_$(source)_$(type)TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET)) \
99 $($(target)_$(source)_$(type)TOOL) $($target_$source_TOOL) \
100 $($(target)_$(type)TOOL.$(BUILD_TARGET)) $($(target)_TOOL.$(BUILD_TARGET)) \
101 $($(target)_$(type)TOOL) $($target_TOOL) \
102 $($(source)_$(type)TOOL.$(BUILD_TARGET)) $($(source)_TOOL.$(BUILD_TARGET)) \
103 $($(source)_$(type)TOOL) $($(source)_TOOL) \
104 $($(type)TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET)) \
105 $($(type)TOOL) $(TOOL) ))
[183]106
[78]107## Figure out the tool for a target.
[106]108# @param $target normalized target.
109# @param $source tooltype.
[79]110_TARGET_TOOL = $(strip $(firstword \
[106]111 $($(target)_$(source)TOOL.$(BUILD_TARGET)) \
112 $($(target)_$(source)TOOL) \
113 $($(target)_TOOL.$(BUILD_TARGET)) \
114 $($(target)_TOOL) \
115 $($(source)TOOL) \
116 $($(source)TOOL.$(BUILD_TARGET)) \
117 $(TOOL.$(BUILD_TARGET)) \
118 $(TOOL) \
[79]119 ))
[183]120
[148]121## Removes the drive letter from a path (if it has one)
122# @param $1 the path
123no-drive=$(word $(words $(subst :, ,$(1))),$(subst :, ,$(1)))
[78]124
[148]125## Removes the root slash from a path (if it has one)
126# @param $1 the path
127no-root-slash=$(patsubst /%,%,$(1))
128
[73]129## Figure out where to put object files.
[110]130# @param $1 source file
131# @param $2 normalized main target
[148]132_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))
[73]133
134## Figure out where to put object files.
[110]135# @param $1 real target name.
136# @param $2 normalized main target
[148]137_TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(1))))
[73]138
139
140#
[185]141# Check syntax which leads to weird syntax errors.
142#
143
144## Check
145# @param $(target) Target name.
146define def_check_target
147ifneq ("$($(target)_TEMPLATE)","$(strip $($(target)_TEMPLATE))")
148$$(error $(target) have an incorrect template name. Remove any tabs!)
149endif
150endef
151$(foreach target, $(ALL_TARGETS),$(eval $(def_check_target)))
152
153
154#
[72]155# Include templates
156#
157_TEMPLATES := $(TEMPLATE)
158define def_templates
159ifdef $(target)_TEMPLATE
160_TEMPLATES += $($(target)_TEMPLATE)
161endif
162endef
163$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
164_TEMPLATES := $(sort $(_TEMPLATES))
165# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
166
167define def_templates_include
168ifndef TEMPLATE_$(template)
169include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
170endif
171endef
172$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
173
[74]174
[72]175#
176# Common Inheritance
177#
178
179## Inherit defaults property
180# @param $(prop) Property name
181# @param $(target) Target name.
182define def_inherit_defaults_one
[74]183ifndef $(target)_$(prop)
[109]184ifndef $(target)_$(prop).$(BUILD_TARGET)
[72]185ifdef $(prop)
[105]186$$(eval $(target)_$(prop) := $($(prop)))
[72]187endif
[109]188ifdef $(prop).$(BUILD_TARGET)
189$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(prop).$(BUILD_TARGET)))
[72]190endif
[109]191endif
192endif
[72]193endef
194
195## Inherit default properties for one target.
196# A bit tricky this one, but it depends a bit on whether or not TEMPLATE
197# is inherited from the default properties.
198# @param $(target) Target name
[78]199#
[72]200define def_inherit_defaults
201ifdef $(target)_TEMPLATE
[107]202ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_TOOL) $(TEMPLATE_$($(target)_TEMPLATE)_TOOL.$(BUILD_TARGET))),)
[109]203$$(foreach prop,TOOL, $$(eval $$(def_inherit_defaults_one)))
[72]204endif
[107]205ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_SDKS) $(TEMPLATE_$($(target)_TEMPLATE)_SDKS.$(BUILD_TARGET))),)
[109]206$$(foreach prop,SDKS, $$(eval $$(def_inherit_defaults_one)))
[72]207endif
208else
[109]209$$(foreach prop,TEMPLATE TOOL SDKS, $$(eval $$(def_inherit_defaults_one)))
[72]210endif
211endef
212# Inherit default properties.
[109]213# !!!!!!THIS IS MESSY AND NOT NECESSARY!!!!!!
[105]214$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_defaults)))
[72]215
216
[78]217## Inherit one template property in a accumulative manner.
[72]218# @param $(prop) Property name
219# @param $(target) Target name
[78]220# @todo fix the precedence order for some properties.
[72]221define def_inherit_template_one
[78]222ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[72]223ifndef $(target)_$(prop)
[106]224#$$ (warning dbgtarget: $(target)_$(prop):='$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
[105]225$$(target)_$$(prop) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop))
[72]226endif
227endif
[79]228ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
229ifndef $(target)_$(prop).$(BUILD_TARGET)
[106]230#$$ (warning dbgsource: $(target)_$(prop).$(BUILD_TARGET)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
[105]231$$(target)_$$(prop).$$(BUILD_TARGET) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop).$$(BUILD_TARGET))
[79]232endif
233endif
[72]234endef
235
[183]236## Inherit one template property.
[78]237# @param $(prop) Property name
238# @param $(target) Target name
239define def_inherit_template_one_accumulate
240ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[106]241#$$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
[105]242$$(eval $(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
[106]243#$$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
[78]244endif
[79]245ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
[105]246#$$ (warning dbg4: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
247$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)))
[79]248endif
249ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)
[105]250#$$ (warning dbg5: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU))
251$$(eval $(target)_$(prop).$(BUILD_TARGET_CPU) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)))
[79]252endif
253ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)
[105]254#$$ (warning dbg6: TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH))
255$$(eval $(target)_$(prop).$(BUILD_TARGET_ARCH) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)))
[79]256endif
[78]257endef
258
[106]259
[72]260## Inherit template properties for on target.
261# @param $(target) Target name.
262define def_inherit_template
[105]263$$(foreach prop, TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL\
264 ,$$(eval $$(def_inherit_template_one)))
265$$(foreach prop,SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS LDFLAGS LIBS LIBPATH \
266 ,$$(eval $$(def_inherit_template_one_accumulate)))
[72]267endef
268# Inherit template properties
[105]269$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_template)))
[72]270
271
272#
273# Include tools
[183]274#
[72]275_TOOLS := $(TOOL)
276define def_tools_target_source
[78]277$(foreach tool,\
[79]278 $($(source)_TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET))\
[78]279 $($(source)_TOOL) $($(target)_$(source)_TOOL)\
[79]280 $($(source)_CTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CTOOL.$(BUILD_TARGET))\
[78]281 $($(source)_CTOOL) $($(target)_$(source)_CTOOL)\
[79]282 $($(source)_CXXTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CXXTOOL.$(BUILD_TARGET))\
[78]283 $($(source)_CXXTOOL) $($(target)_$(source)_CXXTOOL)\
[79]284 $($(source)_ASTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ASTOOL.$(BUILD_TARGET))\
[78]285 $($(source)_ASTOOL) $($(target)_$(source)_ASTOOL)\
[79]286 $($(source)_ARTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ARTOOL.$(BUILD_TARGET))\
[78]287 $($(source)_ARTOOL) $($(target)_$(source)_ARTOOL)\
[79]288 $($(source)_LDTOOL.$(BUILD_TARGET)) $($(target)_$(source)_LDTOOL.$(BUILD_TARGET))\
[78]289 $($(source)_LDTOOL) $($(target)_$(source)_LDTOOL)\
290 ,$(eval _TOOLS += $(tool)))
[72]291endef
292define def_tools_target
[78]293$(foreach tool,\
[79]294 $($(target)_TOOL.$(BUILD_TARGET))\
[78]295 $($(target)_TOOL)\
[79]296 $($(target)_CTOOL.$(BUILD_TARGET))\
[78]297 $($(target)_CTOOL)\
[79]298 $($(target)_CXXTOOL.$(BUILD_TARGET))\
[78]299 $($(target)_CXXTOOL)\
[79]300 $($(target)_ASTOOL.$(BUILD_TARGET))\
[78]301 $($(target)_ASTOOL)\
[79]302 $($(target)_ARTOOL.$(BUILD_TARGET))\
[78]303 $($(target)_ARTOOL)\
[79]304 $($(target)_LDTOOL.$(BUILD_TARGET))\
[78]305 $($(target)_LDTOOL)\
[79]306 ,$(eval _TOOLS += $(tool)))
[220]307$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TYPE)) \
[120]308 , $(eval $(def_tools_target_source)))
[72]309endef
310$(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
311_TOOLS := $(sort $(_TOOLS))
312
313define def_tools_include
314ifndef TOOL_$(tool)
315include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
316endif
317endef
318$(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
319
320
321#
322# Include SDKs
[73]323#
[72]324_SDKS := $(SDKS)
325define def_sdks_target_source
[220]326$(foreach sdk, $($(source)_SDKS) $($(source)_SDKS.$(BUILD_TARGET)) $($(source)_SDKS.$(BUILD_TYPE)) \
327 $($(target)_$(source)_SDKS) $($(target)_$(source)_SDKS.$(BUILD_TARGET)) $($(target)_$(source)_SDKS.$(BUILD_TYPE)), \
[72]328 $(eval _SDKS += $(sdk)))
329endef
330define def_sdks_target
[220]331$(foreach sdk, $($(target)_SDKS) $($(target)_SDKS.$(BUILD_TARGET)) $($(target)_SDKS.$(BUILD_TYPE))\
[122]332 , $(eval _SDKS += $(sdk)))
[220]333$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TYPE))\
[120]334 , $(eval $(def_sdks_target_source)))
[72]335endef
336$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
337_SDKS := $(sort $(_SDKS))
338
[122]339define def_sdks_include_one
[72]340ifndef SDK_$(sdk)
341include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
342endif
343endef
[122]344$(foreach sdk, $(_SDKS), $(eval $(def_sdks_include_one)))
[72]345
[73]346#
347# Object processing.
348#
[72]349
[205]350
[73]351## Generic macro for processing C, C++ and Assembly sources.
352# @param $(target) Normalized target name.
353# @param $(source) Source file name.
354# @param $(type) Source type. {C,CXX,AS}
[221]355# @param bld_type Build type.
356# @param bld_trg Build target.
357# @param bld_trg_arch Build target arch.
358# @param bld_trg_cpu Build target cpu.
[72]359#
[73]360# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
[105]361# @remark I now have a clue. Have to use $$ if not.
[73]362define def_target_source_c_cpp_asm
[105]363#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
[73]364
[78]365$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target),$(type)))
[111]366$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
367$(eval PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase))))
368$(eval dirdep := $(dir $(outbase)).dir_created)
[73]369$(eval defs :=\
[78]370 $(TOOL_$(tool)_DEFS)\
[221]371 $(TOOL_$(tool)_DEFS.$(bld_type))\
372 $(TOOL_$(tool)_DEFS.$(bld_trg))\
373 $(TOOL_$(tool)_DEFS.$(bld_trg_arch))\
374 $(TOOL_$(tool)_DEFS.$(bld_trg_cpu))\
[74]375 $(TOOL_$(tool)_$(type)DEFS)\
[221]376 $(TOOL_$(tool)_$(type)DEFS.$(bld_type))\
377 $(foreach sdk, $(SDKS.$(bld_trg)) \
378 $(SDKS.$(bld_type)) \
[78]379 $(SDKS),\
380 $(SDK_$(sdk)_DEFS)\
[221]381 $(SDK_$(sdk)_DEFS.$(bld_type))\
382 $(SDK_$(sdk)_DEFS.$(bld_trg))\
383 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
384 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
[78]385 $(SDK_$(sdk)_$(type)DEFS)\
[221]386 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
387 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
388 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
389 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]390 $(DEFS)\
[221]391 $(DEFS.$(bld_type))\
392 $(DEFS.$(bld_trg))\
393 $(DEFS.$(bld_trg_arch))\
394 $(DEFS.$(bld_trg_cpu))\
[78]395 $($(type)DEFS)\
[221]396 $($(type)DEFS.$(bld_type))\
397 $($(type)DEFS.$(bld_trg))\
398 $($(type)DEFS.$(bld_trg_arch))\
399 $($(type)DEFS.$(bld_trg_cpu))\
400 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
401 $($(target)_SDKS.$(bld_type)) \
[78]402 $($(target)_SDKS),\
403 $(SDK_$(sdk)_DEFS)\
[221]404 $(SDK_$(sdk)_DEFS.$(bld_type))\
405 $(SDK_$(sdk)_DEFS.$(bld_trg))\
406 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
407 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
[78]408 $(SDK_$(sdk)_$(type)DEFS)\
[221]409 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
410 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
411 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
412 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]413 $($(target)_DEFS)\
[221]414 $($(target)_DEFS.$(bld_type))\
415 $($(target)_DEFS.$(bld_trg))\
416 $($(target)_DEFS.$(bld_trg_arch))\
417 $($(target)_DEFS.$(bld_trg_cpu))\
[78]418 $($(target)_$(type)DEFS)\
[221]419 $($(target)_$(type)DEFS.$(bld_type))\
420 $($(target)_$(type)DEFS.$(bld_trg))\
421 $($(target)_$(type)DEFS.$(bld_trg_arch))\
422 $($(target)_$(type)DEFS.$(bld_trg_cpu))\
423 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
424 $($(source)_SDKS.$(bld_type)) \
[78]425 $($(source)_SDKS),\
426 $(SDK_$(sdk)_DEFS)\
[221]427 $(SDK_$(sdk)_DEFS.$(bld_type))\
428 $(SDK_$(sdk)_DEFS.$(bld_trg))\
429 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
430 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
[78]431 $(SDK_$(sdk)_$(type)DEFS)\
[221]432 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
433 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
434 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
435 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]436 $($(source)_DEFS)\
[221]437 $($(source)_DEFS.$(bld_type))\
438 $($(source)_DEFS.$(bld_trg))\
439 $($(source)_DEFS.$(bld_trg_arch))\
440 $($(source)_DEFS.$(bld_trg_cpu))\
[73]441 $($(source)_$(type)DEFS)\
[221]442 $($(source)_$(type)DEFS.$(bld_type))\
443 $($(source)_$(type)DEFS.$(bld_trg))\
444 $($(source)_$(type)DEFS.$(bld_trg_arch))\
445 $($(source)_$(type)DEFS.$(bld_trg_cpu))\
446 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
447 $($(target)_$(source)_SDKS.$(bld_type)) \
[78]448 $($(target)_$(source)_SDKS),\
449 $(SDK_$(sdk)_DEFS)\
[221]450 $(SDK_$(sdk)_DEFS.$(bld_type))\
451 $(SDK_$(sdk)_DEFS.$(bld_trg))\
452 $(SDK_$(sdk)_DEFS.$(bld_trg_arch))\
453 $(SDK_$(sdk)_DEFS.$(bld_trg_cpu))\
[78]454 $(SDK_$(sdk)_$(type)DEFS)\
[221]455 $(SDK_$(sdk)_$(type)DEFS.$(bld_type))\
456 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg))\
457 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_arch))\
458 $(SDK_$(sdk)_$(type)DEFS.$(bld_trg_cpu)))\
[74]459 $($(target)_$(source)_DEFS)\
[221]460 $($(target)_$(source)_DEFS.$(bld_type))\
461 $($(target)_$(source)_DEFS.$(bld_trg))\
462 $($(target)_$(source)_DEFS.$(bld_trg_arch))\
463 $($(target)_$(source)_DEFS.$(bld_trg_cpu))\
[74]464 $($(target)_$(source)_$(type)DEFS)\
[221]465 $($(target)_$(source)_$(type)DEFS.$(bld_type))\
466 $($(target)_$(source)_$(type)DEFS.$(bld_trg))\
467 $($(target)_$(source)_$(type)DEFS.$(bld_trg_arch))\
468 $($(target)_$(source)_$(type)DEFS.$(bld_trg_cpu))\
[73]469 )
470$(eval incs :=\
[221]471 $($(target)_$(source)_$(type)INCS.$(bld_trg_cpu))\
472 $($(target)_$(source)_$(type)INCS.$(bld_trg_arch))\
473 $($(target)_$(source)_$(type)INCS.$(bld_trg))\
474 $($(target)_$(source)_$(type)INCS.$(bld_type))\
[73]475 $($(target)_$(source)_$(type)INCS)\
[221]476 $($(target)_$(source)_INCS.$(bld_trg_cpu))\
477 $($(target)_$(source)_INCS.$(bld_trg_arch))\
478 $($(target)_$(source)_INCS.$(bld_trg))\
479 $($(target)_$(source)_INCS.$(bld_type))\
[73]480 $($(target)_$(source)_INCS)\
[221]481 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
482 $($(target)_$(source)_SDKS.$(bld_type)) \
[133]483 $($(target)_$(source)_SDKS),\
[221]484 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
485 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
486 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
487 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
[78]488 $(SDK_$(sdk)_$(type)INCS)\
[221]489 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
490 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
491 $(SDK_$(sdk)_INCS.$(bld_trg))\
492 $(SDK_$(sdk)_INCS.$(bld_type))\
[78]493 $(SDK_$(sdk)_INCS))\
[221]494 $($(source)_$(type)INCS.$(bld_trg_cpu))\
495 $($(source)_$(type)INCS.$(bld_trg_arch))\
496 $($(source)_$(type)INCS.$(bld_trg))\
497 $($(source)_$(type)INCS.$(bld_type))\
[73]498 $($(source)_$(type)INCS)\
[221]499 $($(source)_INCS.$(bld_trg_cpu))\
500 $($(source)_INCS.$(bld_trg_arch))\
501 $($(source)_INCS.$(bld_trg))\
502 $($(source)_INCS.$(bld_type))\
[73]503 $($(source)_INCS)\
[221]504 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
505 $($(source)_SDKS.$(bld_type)) \
[78]506 $($(source)_SDKS),\
[221]507 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
508 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
509 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
510 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
[78]511 $(SDK_$(sdk)_$(type)INCS)\
[221]512 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
513 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
514 $(SDK_$(sdk)_INCS.$(bld_trg))\
515 $(SDK_$(sdk)_INCS.$(bld_type))\
[78]516 $(SDK_$(sdk)_INCS))\
[221]517 $($(target)_$(type)INCS.$(bld_trg_cpu))\
518 $($(target)_$(type)INCS.$(bld_trg_arch))\
519 $($(target)_$(type)INCS.$(bld_trg))\
520 $($(target)_$(type)INCS.$(bld_type))\
[73]521 $($(target)_$(type)INCS)\
[221]522 $($(target)_INCS.$(bld_trg_cpu))\
523 $($(target)_INCS.$(bld_trg_arch))\
524 $($(target)_INCS.$(bld_trg))\
525 $($(target)_INCS.$(bld_type))\
[73]526 $($(target)_INCS)\
[221]527 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
528 $($(target)_SDKS.$(bld_type)) \
[78]529 $($(target)_SDKS),\
[221]530 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
531 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
532 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
533 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
[78]534 $(SDK_$(sdk)_$(type)INCS)\
[221]535 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
536 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
537 $(SDK_$(sdk)_INCS.$(bld_trg))\
538 $(SDK_$(sdk)_INCS.$(bld_type))\
[78]539 $(SDK_$(sdk)_INCS))\
[221]540 $(INCS.$(bld_trg_cpu))\
541 $(INCS.$(bld_trg_arch))\
542 $(INCS.$(bld_trg))\
543 $(INCS.$(bld_type))\
[73]544 $(INCS)\
[221]545 $(foreach sdk, $(SDKS.$(bld_trg)) \
546 $(SDKS.$(bld_type)) \
[78]547 $(SDKS),\
[221]548 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_cpu))\
549 $(SDK_$(sdk)_$(type)INCS.$(bld_trg_arch))\
550 $(SDK_$(sdk)_$(type)INCS.$(bld_trg))\
551 $(SDK_$(sdk)_$(type)INCS.$(bld_type))\
[78]552 $(SDK_$(sdk)_$(type)INCS)\
[221]553 $(SDK_$(sdk)_INCS.$(bld_trg_cpu))\
554 $(SDK_$(sdk)_INCS.$(bld_trg_arch))\
555 $(SDK_$(sdk)_INCS.$(bld_trg))\
556 $(SDK_$(sdk)_INCS.$(bld_type))\
[78]557 $(SDK_$(sdk)_INCS))\
[221]558 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_cpu))\
559 $(TOOL_$(tool)_$(type)INCS.$(bld_trg_arch))\
560 $(TOOL_$(tool)_$(type)INCS.$(bld_trg))\
561 $(TOOL_$(tool)_$(type)INCS.$(bld_type))\
[73]562 $(TOOL_$(tool)_$(type)INCS)\
563 )
564$(eval flags :=\
565 $(TOOL_$(tool)_$(type)FLAGS)\
[221]566 $(TOOL_$(tool)_$(type)FLAGS.$(bld_type))\
567 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg))\
568 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_arch))\
569 $(TOOL_$(tool)_$(type)FLAGS.$(bld_trg_cpu))\
[73]570 $($(type)FLAGS)\
[221]571 $($(type)FLAGS.$(bld_type))\
572 $($(type)FLAGS.$(bld_trg))\
573 $($(type)FLAGS.$(bld_trg_arch))\
574 $($(type)FLAGS.$(bld_trg_cpu))\
[73]575 $($(target)_$(type)FLAGS)\
[221]576 $($(target)_$(type)FLAGS.$(bld_type))\
577 $($(target)_$(type)FLAGS.$(bld_trg))\
578 $($(target)_$(type)FLAGS.$(bld_trg_arch))\
579 $($(target)_$(type)FLAGS.$(bld_trg_cpu))\
[73]580 $($(source)_$(type)FLAGS)\
[221]581 $($(source)_$(type)FLAGS.$(bld_type))\
582 $($(source)_$(type)FLAGS.$(bld_trg))\
583 $($(source)_$(type)FLAGS.$(bld_trg_arch))\
584 $($(source)_$(type)FLAGS.$(bld_trg_cpu))\
[73]585 $($(target)_$(source)_$(type)FLAGS)\
[221]586 $($(target)_$(source)_$(type)FLAGS.$(bld_type))\
587 $($(target)_$(source)_$(type)FLAGS.$(bld_trg))\
588 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_arch))\
589 $($(target)_$(source)_$(type)FLAGS.$(bld_trg_cpu))\
[73]590 )
[74]591$(eval objsuff := $(firstword \
[221]592 $($(target)_$(source)_OBJSUFF.$(bld_trg))\
[74]593 $($(target)_$(source)_OBJSUFF)\
[221]594 $($(source)_OBJSUFF.$(bld_trg))\
[74]595 $($(source)_OBJSUFF)\
[221]596 $($(target)_OBJSUFF.$(bld_trg))\
[74]597 $($(target)_OBJSUFF)\
[221]598 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
[74]599 $(TOOL_$(tool)_$(type)OBJSUFF)\
600 $(SUFF_OBJ)\
601 ))
[73]602$(eval obj := $(outbase)$(objsuff))
[74]603$(eval dep := $(outbase)$(SUFF_DEP))
[184]604$(eval deps := \
605 $($(target)_$(source)_DEPS)\
[221]606 $($(target)_$(source)_DEPS.$(bld_type))\
607 $($(target)_$(source)_DEPS.$(bld_trg))\
608 $($(target)_$(source)_DEPS.$(bld_trg_arch))\
609 $($(target)_$(source)_DEPS.$(bld_trg_cpu))\
[184]610 $($(source)_DEPS)\
[221]611 $($(source)_DEPS.$(bld_type))\
612 $($(source)_DEPS.$(bld_trg))\
[184]613 $($(target)_DEPS)\
[221]614 $($(target)_DEPS.$(bld_trg_arch))\
615 $($(target)_DEPS.$(bld_trg_cpu)))
[73]616
[184]617
618#$ (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))
[97]619ifndef TOOL_$(tool)_COMPILE_$(type)
620$$(warning kBuild: TOOL_$(tool)_COMPILE_$(type) is not defined. source=$(source) target=$(target) )
621$$(warning kBuild: tools: \
[221]622 1 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
[106]623 2 $($(target)_$(source)_$(type)TOOL) \
[221]624 3 $($(target)_$(source)_TOOL.$(bld_trg)) \
[106]625 4 $($(target)_$(source)_TOOL) \
[221]626 5 $($(target)_$(type)TOOL.$(bld_trg)) \
[106]627 6 $($(target)_$(type)TOOL) \
[221]628 7 $($(target)_TOOL.$(bld_trg)) \
[106]629 8 $($(target)_TOOL) \
[221]630 9 $($(source)_$(type)TOOL.$(bld_trg)) \
[106]631 10 $($(source)_$(type)TOOL) \
[221]632 11 $($(source)_TOOL.$(bld_trg)) \
[106]633 12 $($(source)_TOOL) \
[221]634 13 $($(type)TOOL.$(bld_trg)) \
[106]635 14 $($(type)TOOL) \
[221]636 15 $(TOOL.$(bld_trg)) \
[106]637 16 $(TOOL) )
[97]638endif
[73]639$(eval $(TOOL_$(tool)_COMPILE_$(type)))
640
[207]641$$(basename $$(notdir $$(obj))).o::
[219]642 + $$(MAKE) -B -f $$(MAKEFILE) $(obj)
[207]643$$(basename $$(notdir $$(obj))).obj::
[219]644 + $$(MAKE) -B -f $$(MAKEFILE) $(obj)
[205]645
[73]646$(eval _OBJS_$(target) += $(obj))
647$(eval _DEPFILES += $(dep))
648
649endef
650
651## Generic macro for processing all target sources.
[74]652# @param $(target) Normalized target name.
[73]653define def_target_sources
654#$ (warning def_target_sources)
655# C sources
[221]656$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
[73]657 ,$(eval $(def_target_source_c_cpp_asm)) ))
658
659# C++ sources
[221]660$(foreach type,CXX,$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
[73]661 ,$(eval $(def_target_source_c_cpp_asm)) ))
662
663# ASM sources
[221]664$(foreach type,AS,$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
[73]665 ,$(eval $(def_target_source_c_cpp_asm)) ))
666endef
667
668
669#
[219]670# NEEDED
671#
672
673## Needed (one).
674# @param $(target) Normalized target (program) name.
675define def_needed
676# basics
677$(eval tool := $(call _TARGET_TOOL,$(target),LD))
678$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
679$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
[220]680$(eval bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)))
[221]681$(eval bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_PLATFORM)))
682$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_PLATFORM_ARCH)))
683$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_PLATFORM_CPU)))
[219]684$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(HOSTSUFF_EXE)))
685$(eval exe := $(outbase)$(exesuff))
686$(eval TARGET_$(target) := $(exe))
687
688# source -> object
689$(eval $(def_target_sources))
690
691# more library stuff.
692$(eval tool := $(call _TARGET_TOOL,$(target),LD))
693$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
694$(eval objs = $(_OBJS_$(target)))
695$(eval flags :=\
696 $(TOOL_$(tool)_LDFLAGS)\
[220]697 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
698 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
[221]699 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
700 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[219]701 $(LDFLAGS)\
[220]702 $(LDFLAGS.$(bld_type))\
703 $(LDFLAGS.$(bld_trg))\
[221]704 $(LDFLAGS.$(bld_trg_arch))\
705 $(LDFLAGS.$(bld_trg_cpu))\
[219]706 $($(target)_LDFLAGS)\
[220]707 $($(target)_LDFLAGS.$(bld_type))\
708 $($(target)_LDFLAGS.$(bld_trg))\
[221]709 $($(target)_LDFLAGS.$(bld_trg_arch))\
710 $($(target)_LDFLAGS.$(bld_trg_cpu))\
[219]711)
712$(eval libs :=\
[221]713 $($(target)_LIBS.$(bld_trg_cpu))\
714 $($(target)_LIBS.$(bld_trg_arch))\
[220]715 $($(target)_LIBS.$(bld_trg))\
716 $($(target)_LIBS.$(bld_type))\
[219]717 $($(target)_LIBS)\
[220]718 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
719 $($(target)_SDKS.$(bld_type)) \
[219]720 $($(target)_SDKS),\
[221]721 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
722 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
[220]723 $(SDK_$(sdk)_LIBS.$(bld_trg))\
724 $(SDK_$(sdk)_LIBS.$(bld_type))\
[219]725 $(SDK_$(sdk)_LIBS))\
[221]726 $(LIBS.$(bld_trg_cpu))\
727 $(LIBS.$(bld_trg_arch))\
[220]728 $(LIBS.$(bld_trg))\
729 $(LIBS.$(bld_type))\
[219]730 $(LIBS)\
[220]731 $(foreach sdk, $(SDKS.$(bld_trg)) \
732 $(SDKS.$(bld_type)) \
[219]733 $(SDKS),\
[221]734 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
735 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
[220]736 $(SDK_$(sdk)_LIBS.$(bld_trg))\
737 $(SDK_$(sdk)_LIBS.$(bld_type))\
[219]738 $(SDK_$(sdk)_LIBS))\
[221]739 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
740 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
[220]741 $(TOOL_$(tool)_LIBS.$(bld_trg))\
742 $(TOOL_$(tool)_LIBS.$(bld_type))\
[219]743 $(TOOL_$(tool)_LIBS)\
744)
745$(eval libpath :=\
[221]746 $($(target)_LIBPATH.$(bld_trg_cpu))\
747 $($(target)_LIBPATH.$(bld_trg_arch))\
[220]748 $($(target)_LIBPATH.$(bld_trg))\
749 $($(target)_LIBPATH.$(bld_type))\
[219]750 $($(target)_LIBPATH)\
[220]751 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
752 $($(target)_SDKS.$(bld_type)) \
[219]753 $($(target)_SDKS),\
[221]754 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
755 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
[220]756 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
757 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
[219]758 $(SDK_$(sdk)_LIBPATH))\
[221]759 $(LIBPATH.$(bld_trg_cpu))\
760 $(LIBPATH.$(bld_trg_arch))\
[220]761 $(LIBPATH.$(bld_trg))\
762 $(LIBPATH.$(bld_type))\
[219]763 $(LIBPATH)\
[220]764 $(foreach sdk, $(SDKS.$(bld_trg)) \
765 $(SDKS.$(bld_type)) \
[219]766 $(SDKS),\
[221]767 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
768 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
[220]769 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
770 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
[219]771 $(SDK_$(sdk)_LIBPATH))\
[221]772 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
773 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
[220]774 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
775 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[219]776 $(TOOL_$(tool)_LIBPATH)\
777)
778$(eval dirdep := $(dir $(exe)).dir_created)
779## @todo fix dependencies
780$(eval deps := $($(target)_DEPS))
781#
782$(eval custom_pre := $(strip $(firstword
[220]783 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
784 $($(target)_CUSTOM_PRE.$(bld_trg))\
785 $($(target)_CUSTOM_PRE.$(bld_type))\
[219]786 $($(target)_CUSTOM_PRE)\
[220]787 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
788 $(CUSTOM_PRE.$(bld_trg))\
789 $(CUSTOM_PRE.$(bld_type))\
[219]790 $(CUSTOM_PRE)\
791)))
792$(eval custom_post := $(strip $(firstword
[220]793 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
794 $($(target)_CUSTOM_POST.$(bld_trg))\
795 $($(target)_CUSTOM_POST.$(bld_type))\
[219]796 $($(target)_CUSTOM_POST)\
[220]797 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
798 $(CUSTOM_POST.$(bld_trg))\
799 $(CUSTOM_POST.$(bld_type))\
[219]800 $(CUSTOM_POST)\
801)))
[220]802$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
[219]803
804$(eval $(TOOL_$(tool)_LINK_PROGRAM))
805# publish rule (still need work)
806ifndef $(target)_INST
807$(eval pubexe := $(PATH_BIN)/$(notdir $(exe)))
808$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
809 $(CP) $(exe) $(pubexe)
810
811_NEEDED += $(pubexe)
812_OUT_FILES += $(exe) $(pubexe)
813else
814_NEEDED += $(exe)
815_OUT_FILES += $(exe)
816endif
817_OBJS += $(_OBJS_$(target))
818endef
819
820# Process needed.
821$(foreach target, $(NEEDED) $(NEEDED.$(BUILD_TARGET)), $(eval $(def_needed)))
822
823
824
825#
[72]826# LIBRARIES
[73]827#
[72]828
829## Library (one).
[74]830# @param $(target) Normalized library (target) name.
[72]831define def_lib
[145]832# library basics
[78]833$(eval tool := $(call _TARGET_TOOL,$(target),AR))
834ifeq ($(tool),)
835$$(error kBuild: Library target $(target) doesn't have a tool defined!)
836endif
[111]837## @todo prefix
838$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
839$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
[221]840$(eval bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)))
841$(eval bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET)))
842$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)))
843$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU)))
[126]844$(eval libsuff := $(firstword\
[221]845 $($(target)_LIBSUFF.$(bld_trg))\
[126]846 $($(target)_LIBSUFF)\
[221]847 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
[126]848 $(TOOL_$(tool)_ARLIBSUFF)\
849 $(SUFF_LIB)\
850))
[111]851$(eval lib := $(outbase)$(libsuff))
[183]852$(eval TARGET_$(target) := $(lib))
[145]853
854# source -> object
855$(eval $(def_target_sources))
856
857# library linking
858$(eval tool := $(call _TARGET_TOOL,$(target),AR))
[146]859$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
[74]860$(eval flags :=\
861 $(TOOL_$(tool)_ARFLAGS)\
[221]862 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
[74]863 $(ARFLAGS)\
[221]864 $(ARFLAGS.$(bld_type))\
[74]865 $($(target)_ARFLAGS)\
[221]866 $($(target)_ARFLAGS.$(bld_type))\
[74]867 )
[73]868$(eval objs = $(_OBJS_$(target)))
[221]869$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
[73]870$(eval dirdep := $(dir $(lib)).dir_created)
[78]871## @todo fix dependencies on makefiles an such
[184]872$(eval deps := $($(target)_DEPS))
[72]873
[73]874$(eval $(TOOL_$(tool)_LINK_LIBRARY))
[72]875
[126]876# publish rule (still need work)
[131]877ifndef $(target)_NOINST
[126]878$(eval publib := $(PATH_LIB)/$(notdir $(lib)))
879$(publib) : $(lib) $(dir $(publib)).dir_created
[130]880 $(CP) $(lib) $(publib)
[183]881
[126]882_LIBS += $(publib)
883_OUT_FILES += $(lib) $(publib)
884else
[73]885_LIBS += $(lib)
[75]886_OUT_FILES += $(lib)
[126]887endif
888_OBJS += $(_OBJS_$(target))
[72]889endef
890
891# Process libraries
[138]892$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(def_lib)))
[72]893
894
895
896#
[189]897# DLLS
[72]898#
899
[189]900## DLL (one).
[74]901# @param $(target) Normalized target (program) name.
[189]902define def_dll
903# dllmod basics
[78]904$(eval tool := $(call _TARGET_TOOL,$(target),LD))
[111]905$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
906$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
[221]907$(eval bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)))
908$(eval bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET)))
909$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)))
910$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU)))
[189]911$(eval dllsuff := $(firstword $($(target)_DLLSUFF) $($(target)_DLLSUFF) $(TOOL_$(tool)_LDDLLSUFF) $(SUFF_DLL)))
912$(eval dll := $(outbase)$(dllsuff))
913$(eval TARGET_$(target) := $(dll))
[145]914
915# source -> object
916$(eval $(def_target_sources))
917
[189]918# dllmod linking.
[145]919$(eval tool := $(call _TARGET_TOOL,$(target),LD))
[146]920$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
[111]921$(eval objs = $(_OBJS_$(target)))
[74]922$(eval flags :=\
923 $(TOOL_$(tool)_LDFLAGS)\
[221]924 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
925 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
926 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
927 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[74]928 $(LDFLAGS)\
[221]929 $(LDFLAGS.$(bld_type))\
930 $(LDFLAGS.$(bld_trg))\
931 $(LDFLAGS.$(bld_trg_arch))\
932 $(LDFLAGS.$(bld_trg_cpu))\
[74]933 $($(target)_LDFLAGS)\
[221]934 $($(target)_LDFLAGS.$(bld_type))\
935 $($(target)_LDFLAGS.$(bld_trg))\
936 $($(target)_LDFLAGS.$(bld_trg_arch))\
937 $($(target)_LDFLAGS.$(bld_trg_cpu))\
[74]938)
939$(eval libs :=\
[221]940 $($(target)_LIBS.$(bld_trg_cpu))\
941 $($(target)_LIBS.$(bld_trg_arch))\
942 $($(target)_LIBS.$(bld_trg))\
943 $($(target)_LIBS.$(bld_type))\
[74]944 $($(target)_LIBS)\
[221]945 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
946 $($(target)_SDKS.$(bld_type)) \
[122]947 $($(target)_SDKS),\
[221]948 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
949 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
950 $(SDK_$(sdk)_LIBS.$(bld_trg))\
951 $(SDK_$(sdk)_LIBS.$(bld_type))\
[122]952 $(SDK_$(sdk)_LIBS))\
[221]953 $(LIBS.$(bld_trg_cpu))\
954 $(LIBS.$(bld_trg_arch))\
955 $(LIBS.$(bld_trg))\
956 $(LIBS.$(bld_type))\
[74]957 $(LIBS)\
[221]958 $(foreach sdk, $(SDKS.$(bld_trg)) \
959 $(SDKS.$(bld_type)) \
[122]960 $(SDKS),\
[221]961 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
962 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
963 $(SDK_$(sdk)_LIBS.$(bld_trg))\
964 $(SDK_$(sdk)_LIBS.$(bld_type))\
[122]965 $(SDK_$(sdk)_LIBS))\
[221]966 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
967 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
968 $(TOOL_$(tool)_LIBS.$(bld_trg))\
969 $(TOOL_$(tool)_LIBS.$(bld_type))\
[74]970 $(TOOL_$(tool)_LIBS)\
971)
972$(eval libpath :=\
[221]973 $($(target)_LIBPATH.$(bld_trg_cpu))\
974 $($(target)_LIBPATH.$(bld_trg_arch))\
975 $($(target)_LIBPATH.$(bld_trg))\
976 $($(target)_LIBPATH.$(bld_type))\
[74]977 $($(target)_LIBPATH)\
[221]978 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
979 $($(target)_SDKS.$(bld_type)) \
[122]980 $($(target)_SDKS),\
[221]981 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
982 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
983 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
984 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
[122]985 $(SDK_$(sdk)_LIBPATH))\
[221]986 $(LIBPATH.$(bld_trg_cpu))\
987 $(LIBPATH.$(bld_trg_arch))\
988 $(LIBPATH.$(bld_trg))\
989 $(LIBPATH.$(bld_type))\
[74]990 $(LIBPATH)\
[221]991 $(foreach sdk, $(SDKS.$(bld_trg)) \
992 $(SDKS.$(bld_type)) \
[122]993 $(SDKS),\
[221]994 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
995 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
996 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
997 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
[122]998 $(SDK_$(sdk)_LIBPATH))\
[221]999 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1000 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1001 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1002 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[74]1003 $(TOOL_$(tool)_LIBPATH)\
1004)
[189]1005$(eval dirdep := $(dir $(dll)).dir_created)
[74]1006## @todo fix dependencies
[184]1007$(eval deps := $($(target)_DEPS))
[74]1008#
1009$(eval custom_pre := $(strip $(firstword
[221]1010 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1011 $($(target)_CUSTOM_PRE.$(bld_trg))\
1012 $($(target)_CUSTOM_PRE.$(bld_type))\
[74]1013 $($(target)_CUSTOM_PRE)\
[221]1014 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1015 $(CUSTOM_PRE.$(bld_trg))\
1016 $(CUSTOM_PRE.$(bld_type))\
[74]1017 $(CUSTOM_PRE)\
1018)))
1019$(eval custom_post := $(strip $(firstword
[221]1020 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1021 $($(target)_CUSTOM_POST.$(bld_trg))\
1022 $($(target)_CUSTOM_POST.$(bld_type))\
[74]1023 $($(target)_CUSTOM_POST)\
[221]1024 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1025 $(CUSTOM_POST.$(bld_trg))\
1026 $(CUSTOM_POST.$(bld_type))\
[74]1027 $(CUSTOM_POST)\
1028)))
[221]1029$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
[72]1030
[189]1031ifndef TOOL_$(tool)_LINK_DLL
1032$$(warning kBuild: TOOL_$(tool)_LINK_DLL is not defined. target=$(target) )
1033$$(warning kBuild: tools: \
[221]1034 1 $($(target)_$(source)TOOL.$(bld_trg)) \
[189]1035 2 $($(target)_$(source)TOOL) \
[221]1036 3 $($(target)_TOOL.$(bld_trg)) \
[189]1037 4 $($(target)_TOOL) \
1038 5 $($(source)TOOL) \
[221]1039 6 $($(source)TOOL.$(bld_trg)) \
1040 7 $(TOOL.$(bld_trg)) \
[189]1041 8 $(TOOL) )
1042endif
1043
1044$(eval $(TOOL_$(tool)_LINK_DLL))
1045
1046
[130]1047# publish rule (still need work)
[131]1048ifndef $(target)_NOINST
[189]1049$(eval pubdll := $(PATH_BIN)/$(notdir $(dll)))
1050$(pubdll) : $(dll) $(dir $(pubdll)).dir_created
1051 $(CP) $(dll) $(pubdll)
[183]1052
[189]1053$(eval TARGET_PUB_$(target) := $(pubdll))
1054_DLLS += $(pubdll)
1055_OUT_FILES += $(dll) $(pubdll)
[130]1056else
[189]1057_DLLS += $(dll)
1058_OUT_FILES += $(dll)
[130]1059endif
[74]1060_OBJS += $(_OBJS_$(target))
1061endef
1062
[189]1063# Process dlls
1064$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(def_dll)))
[74]1065
1066
1067
[72]1068#
[189]1069# Process import libraries.
[72]1070#
[219]1071# - On OS/2 and windows these are libraries.
[189]1072# - On other platforms they are fake DLLs.
1073ifeq ($(subst win32,os2,$(BUILD_TARGET)),os2)
1074$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_lib)))
1075else
1076$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval $(def_dll)))
1077endif
1078$(foreach target, $(IMPORT_LIBS) $(IMPORT_LIBS.$(BUILD_TARGET)), $(eval _IMPORT_LIBS += $(firstword $(TARGET_PUB_$(target)) $(TARGET_$(target)))))
[72]1079
[219]1080
[189]1081
1082#
1083# PROGRAMS
1084#
1085
1086## Program (one).
[130]1087# @param $(target) Normalized target (program) name.
[189]1088define def_program
1089# basics
[130]1090$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1091$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1092$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
[221]1093$(eval bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)))
1094$(eval bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET)))
1095$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)))
1096$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU)))
[189]1097$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
1098$(eval exe := $(outbase)$(exesuff))
1099$(eval TARGET_$(target) := $(exe))
[145]1100
1101# source -> object
1102$(eval $(def_target_sources))
1103
[189]1104# more library stuff.
[145]1105$(eval tool := $(call _TARGET_TOOL,$(target),LD))
[146]1106$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
[130]1107$(eval objs = $(_OBJS_$(target)))
1108$(eval flags :=\
1109 $(TOOL_$(tool)_LDFLAGS)\
[221]1110 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1111 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1112 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
1113 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[130]1114 $(LDFLAGS)\
[221]1115 $(LDFLAGS.$(bld_type))\
1116 $(LDFLAGS.$(bld_trg))\
1117 $(LDFLAGS.$(bld_trg_arch))\
1118 $(LDFLAGS.$(bld_trg_cpu))\
[130]1119 $($(target)_LDFLAGS)\
[221]1120 $($(target)_LDFLAGS.$(bld_type))\
1121 $($(target)_LDFLAGS.$(bld_trg))\
1122 $($(target)_LDFLAGS.$(bld_trg_arch))\
1123 $($(target)_LDFLAGS.$(bld_trg_cpu))\
[130]1124)
1125$(eval libs :=\
[221]1126 $($(target)_LIBS.$(bld_trg_cpu))\
1127 $($(target)_LIBS.$(bld_trg_arch))\
1128 $($(target)_LIBS.$(bld_trg))\
1129 $($(target)_LIBS.$(bld_type))\
[130]1130 $($(target)_LIBS)\
[221]1131 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1132 $($(target)_SDKS.$(bld_type)) \
[130]1133 $($(target)_SDKS),\
[221]1134 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1135 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1136 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1137 $(SDK_$(sdk)_LIBS.$(bld_type))\
[130]1138 $(SDK_$(sdk)_LIBS))\
[221]1139 $(LIBS.$(bld_trg_cpu))\
1140 $(LIBS.$(bld_trg_arch))\
1141 $(LIBS.$(bld_trg))\
1142 $(LIBS.$(bld_type))\
[130]1143 $(LIBS)\
[221]1144 $(foreach sdk, $(SDKS.$(bld_trg)) \
1145 $(SDKS.$(bld_type)) \
[130]1146 $(SDKS),\
[221]1147 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1148 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1149 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1150 $(SDK_$(sdk)_LIBS.$(bld_type))\
[130]1151 $(SDK_$(sdk)_LIBS))\
[221]1152 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1153 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1154 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1155 $(TOOL_$(tool)_LIBS.$(bld_type))\
[130]1156 $(TOOL_$(tool)_LIBS)\
1157)
1158$(eval libpath :=\
[221]1159 $($(target)_LIBPATH.$(bld_trg_cpu))\
1160 $($(target)_LIBPATH.$(bld_trg_arch))\
1161 $($(target)_LIBPATH.$(bld_trg))\
1162 $($(target)_LIBPATH.$(bld_type))\
[130]1163 $($(target)_LIBPATH)\
[221]1164 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1165 $($(target)_SDKS.$(bld_type)) \
[130]1166 $($(target)_SDKS),\
[221]1167 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1168 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1169 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1170 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
[130]1171 $(SDK_$(sdk)_LIBPATH))\
[221]1172 $(LIBPATH.$(bld_trg_cpu))\
1173 $(LIBPATH.$(bld_trg_arch))\
1174 $(LIBPATH.$(bld_trg))\
1175 $(LIBPATH.$(bld_type))\
[130]1176 $(LIBPATH)\
[221]1177 $(foreach sdk, $(SDKS.$(bld_trg)) \
1178 $(SDKS.$(bld_type)) \
[130]1179 $(SDKS),\
[221]1180 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1181 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1182 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1183 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
[130]1184 $(SDK_$(sdk)_LIBPATH))\
[221]1185 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1186 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1187 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1188 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[130]1189 $(TOOL_$(tool)_LIBPATH)\
1190)
[189]1191$(eval dirdep := $(dir $(exe)).dir_created)
[130]1192## @todo fix dependencies
[184]1193$(eval deps := $($(target)_DEPS))
[130]1194#
1195$(eval custom_pre := $(strip $(firstword
[221]1196 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1197 $($(target)_CUSTOM_PRE.$(bld_trg))\
1198 $($(target)_CUSTOM_PRE.$(bld_type))\
[130]1199 $($(target)_CUSTOM_PRE)\
[221]1200 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1201 $(CUSTOM_PRE.$(bld_trg))\
1202 $(CUSTOM_PRE.$(bld_type))\
[130]1203 $(CUSTOM_PRE)\
1204)))
1205$(eval custom_post := $(strip $(firstword
[221]1206 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1207 $($(target)_CUSTOM_POST.$(bld_trg))\
1208 $($(target)_CUSTOM_POST.$(bld_type))\
[130]1209 $($(target)_CUSTOM_POST)\
[221]1210 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1211 $(CUSTOM_POST.$(bld_trg))\
1212 $(CUSTOM_POST.$(bld_type))\
[130]1213 $(CUSTOM_POST)\
1214)))
[221]1215$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
[72]1216
[189]1217$(eval $(TOOL_$(tool)_LINK_PROGRAM))
[130]1218# publish rule (still need work)
[131]1219ifndef $(target)_NOINST
[189]1220$(eval pubexe := $(PATH_BIN)/$(notdir $(exe)))
1221$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
1222 $(CP) $(exe) $(pubexe)
[183]1223
[219]1224_PROGRAMS += $(pubexe)
[189]1225_OUT_FILES += $(exe) $(pubexe)
[130]1226else
[219]1227_PROGRAMS += $(exe)
[189]1228_OUT_FILES += $(exe)
[130]1229endif
1230_OBJS += $(_OBJS_$(target))
1231endef
1232
[189]1233# Process libraries
1234$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(def_program)))
[130]1235
1236
[189]1237
[72]1238#
[83]1239# SYSMODS
[72]1240#
1241
[130]1242## System module (one).
[83]1243# @param $(target) Normalized target (program) name.
1244define def_sysmod
[145]1245# sysmod basics
[83]1246$(eval tool := $(call _TARGET_TOOL,$(target),LD))
[111]1247$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1248$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
[221]1249$(eval bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)))
1250$(eval bld_trg := $(firstword $($(target)_BLD_TRG) $(BUILD_TARGET)))
1251$(eval bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(BUILD_TARGET_ARCH)))
1252$(eval bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU) $(BUILD_TARGET_CPU)))
[111]1253$(eval syssuff := $(firstword $($(target)_SYSSUFF) $($(target)_SYSSUFF) $(TOOL_$(tool)_LDSYSSUFF) $(SUFF_SYS)))
1254$(eval sys := $(outbase)$(syssuff))
[183]1255$(eval TARGET_$(target) := $(sys))
[145]1256
1257# source -> object
1258$(eval $(def_target_sources))
1259
1260# sysmod linking
1261$(eval tool := $(call _TARGET_TOOL,$(target),LD))
[146]1262$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
[111]1263$(eval objs = $(_OBJS_$(target)))
[83]1264$(eval flags :=\
1265 $(TOOL_$(tool)_LDFLAGS)\
[221]1266 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
1267 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
1268 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
1269 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
[83]1270 $(LDFLAGS)\
[221]1271 $(LDFLAGS.$(bld_type))\
1272 $(LDFLAGS.$(bld_trg))\
1273 $(LDFLAGS.$(bld_trg_arch))\
1274 $(LDFLAGS.$(bld_trg_cpu))\
[83]1275 $($(target)_LDFLAGS)\
[221]1276 $($(target)_LDFLAGS.$(bld_type))\
1277 $($(target)_LDFLAGS.$(bld_trg))\
1278 $($(target)_LDFLAGS.$(bld_trg_arch))\
1279 $($(target)_LDFLAGS.$(bld_trg_cpu))\
[83]1280)
1281$(eval libs :=\
[221]1282 $($(target)_LIBS.$(bld_trg_cpu))\
1283 $($(target)_LIBS.$(bld_trg_arch))\
1284 $($(target)_LIBS.$(bld_trg))\
1285 $($(target)_LIBS.$(bld_type))\
[83]1286 $($(target)_LIBS)\
[221]1287 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1288 $($(target)_SDKS.$(bld_type)) \
[122]1289 $($(target)_SDKS),\
[221]1290 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1291 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1292 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1293 $(SDK_$(sdk)_LIBS.$(bld_type))\
[122]1294 $(SDK_$(sdk)_LIBS))\
[221]1295 $(LIBS.$(bld_trg_cpu))\
1296 $(LIBS.$(bld_trg_arch))\
1297 $(LIBS.$(bld_trg))\
1298 $(LIBS.$(bld_type))\
[83]1299 $(LIBS)\
[221]1300 $(foreach sdk, $(SDKS.$(bld_trg)) \
1301 $(SDKS.$(bld_type)) \
[122]1302 $(SDKS),\
[221]1303 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
1304 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
1305 $(SDK_$(sdk)_LIBS.$(bld_trg))\
1306 $(SDK_$(sdk)_LIBS.$(bld_type))\
[122]1307 $(SDK_$(sdk)_LIBS))\
[221]1308 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
1309 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
1310 $(TOOL_$(tool)_LIBS.$(bld_trg))\
1311 $(TOOL_$(tool)_LIBS.$(bld_type))\
[83]1312 $(TOOL_$(tool)_LIBS)\
1313)
1314$(eval libpath :=\
[221]1315 $($(target)_LIBPATH.$(bld_trg_cpu))\
1316 $($(target)_LIBPATH.$(bld_trg_arch))\
1317 $($(target)_LIBPATH.$(bld_trg))\
1318 $($(target)_LIBPATH.$(bld_type))\
[83]1319 $($(target)_LIBPATH)\
[221]1320 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1321 $($(target)_SDKS.$(bld_type)) \
[122]1322 $($(target)_SDKS),\
[221]1323 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1324 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1325 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1326 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
[122]1327 $(SDK_$(sdk)_LIBPATH))\
[221]1328 $(LIBPATH.$(bld_trg_cpu))\
1329 $(LIBPATH.$(bld_trg_arch))\
1330 $(LIBPATH.$(bld_trg))\
1331 $(LIBPATH.$(bld_type))\
[83]1332 $(LIBPATH)\
[221]1333 $(foreach sdk, $(SDKS.$(bld_trg)) \
1334 $(SDKS.$(bld_type)) \
[122]1335 $(SDKS),\
[221]1336 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
1337 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
1338 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
1339 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
[122]1340 $(SDK_$(sdk)_LIBPATH))\
[221]1341 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
1342 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
1343 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
1344 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
[83]1345 $(TOOL_$(tool)_LIBPATH)\
1346)
1347$(eval dirdep := $(dir $(sys)).dir_created)
1348## @todo fix dependencies
[184]1349$(eval deps := $($(target)_DEPS))
[83]1350#
1351$(eval custom_pre := $(strip $(firstword
[221]1352 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1353 $($(target)_CUSTOM_PRE.$(bld_trg))\
1354 $($(target)_CUSTOM_PRE.$(bld_type))\
[83]1355 $($(target)_CUSTOM_PRE)\
[221]1356 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1357 $(CUSTOM_PRE.$(bld_trg))\
1358 $(CUSTOM_PRE.$(bld_type))\
[83]1359 $(CUSTOM_PRE)\
1360)))
1361$(eval custom_post := $(strip $(firstword
[221]1362 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1363 $($(target)_CUSTOM_POST.$(bld_trg))\
1364 $($(target)_CUSTOM_POST.$(bld_type))\
[83]1365 $($(target)_CUSTOM_POST)\
[221]1366 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1367 $(CUSTOM_POST.$(bld_trg))\
1368 $(CUSTOM_POST.$(bld_type))\
[83]1369 $(CUSTOM_POST)\
1370)))
[221]1371$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
[72]1372
[106]1373ifndef TOOL_$(tool)_LINK_SYSMOD
1374$$(warning kBuild: TOOL_$(tool)_LINK_SYSMOD is not defined. target=$(target) )
1375$$(warning kBuild: tools: \
[221]1376 1 $($(target)_$(source)TOOL.$(bld_trg)) \
[106]1377 2 $($(target)_$(source)TOOL) \
[221]1378 3 $($(target)_TOOL.$(bld_trg)) \
[106]1379 4 $($(target)_TOOL) \
1380 5 $($(source)TOOL) \
[221]1381 6 $($(source)TOOL.$(bld_trg)) \
1382 7 $(TOOL.$(bld_trg)) \
[106]1383 8 $(TOOL) )
[183]1384endif
[106]1385
[83]1386$(eval $(TOOL_$(tool)_LINK_SYSMOD))
1387
[130]1388# publish rule (still need work)
[131]1389ifndef $(target)_NOINST
1390$(eval pubsys := $(PATH_BIN)/$(notdir $(sys)))
1391$(pubsys): $(sys) $(dir $(pubsys)).dir_created
[130]1392 $(CP) $(sys) $(pubsys)
[183]1393
[131]1394$(eval _SYSMODS += $(pubsys))
1395$(eval _OUT_FILES += $(sys) $(pubsys))
[130]1396else
[131]1397$(eval _SYSMODS += $(sys))
1398$(eval _OUT_FILES += $(sys))
[130]1399endif
1400_OBJS += $(_OBJS_$(target))
[83]1401endef
1402
[130]1403# Process sysmods
[138]1404$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(def_sysmod)))
[83]1405
1406
1407
[72]1408#
1409# OTHERS
1410#
[190]1411_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET))
[72]1412
1413
1414
1415#
1416# DOCS
1417#
1418
1419
1420#
1421# Directories.
1422#
[130]1423_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(sort $(dir $(_OUT_FILES) $(_OBJS)))))
[72]1424
1425define def_createdir
1426$(dirfile):
[219]1427 $(call MSG_L1,Creating directory $$(@D))
[72]1428 $(MKDIR) -p $$(@D)
[73]1429 @echo dir_created > $$@
[72]1430endef
1431
1432$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
1433
[183]1434
[72]1435#
[75]1436# Include dependency files.
[72]1437#
[75]1438$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
[72]1439
[183]1440
[75]1441#
1442# PASSES (including directory and makefile walking)
1443#
1444# Do all the default passes if it's unspecified.
[72]1445
[98]1446#PASSES ?= needed libraries binaries others publish
[221]1447PASSES ?= needed libraries dlls binaries others
[98]1448
[221]1449## @todo figure out a generic way of configuring how pass works!
1450
[75]1451## Proritized list of the default makefile when walking subdirectories.
1452# The user can overload this list.
1453DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
[72]1454
[75]1455## Subdir
1456# @param $(pass) Lowercase pass name.
1457# @param $(PASS) Uppercase pass name.
1458# @param $(subdir) Subdirectory
1459# @param $(tag) tag to attach to the rule name.
1460define def_pass_subdir
[219]1461pass_$(pass)$(tag):: $(dep)
1462 + $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
[75]1463endef
[72]1464
[75]1465## Submakefile
1466# @param $(pass) Lowercase pass name.
1467# @param $(PASS) Uppercase pass name.
1468# @param $(makefile) Makefile.
1469# @param $(tag) tag to attach to the rule name.
1470define def_pass_makefile
[219]1471pass_$(pass)$(tag):: $(dep)
1472 + $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
[75]1473endef
[73]1474
[74]1475
[75]1476## Execute a pass.
1477# @param $(pass) Lowercase pass name.
1478# @param $(PASS) Uppercase pass name.
1479define def_pass
[183]1480$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)))
1481$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)))
1482$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)))
1483$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)))
[75]1484
1485$(eval tag:=_before)
[219]1486$(eval dep:=)
[183]1487$(foreach subdir,$(SUBDIRS_$(PASS)) $(SUBDIRS_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1488$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)) $(MAKEFILES_BEFORE_$(PASS).$(BUILD_TARGET)),$(eval $(def_pass_makefile)))
[75]1489
1490$(eval tag:=_after)
[219]1491$(eval dep:=pass_$(pass)_doit)
[183]1492$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)) $(SUBDIRS_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_subdir)))
1493$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)) $(MAKEFILES_AFTER_$(PASS).$(BUILD_TARGET)) ,$(eval $(def_pass_makefile)))
[75]1494
1495.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1496.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
[220]1497pass_$(pass)_this: pass_$(pass)_before
1498 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1499pass_$(pass)_after:: pass_$(pass)_this
[219]1500pass_$(pass): pass_$(pass)_after
[75]1501
[183]1502endef
1503
1504
[75]1505## PASS: needed
1506# This pass builds targets which are required for building the rest.
1507pass_needed_doit: $(_NEEDEDS)
1508pass := needed
1509PASS := NEEDED
1510$(eval $(def_pass))
1511
1512## PASS: libraries
1513# This pass builds library targets.
1514pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1515pass := libraries
1516PASS := LIBRARIES
1517$(eval $(def_pass))
1518
1519## PASS: binaries
[189]1520# This pass builds dll targets.
1521pass_dlls_doit: $(_DLLS) $(_OTHER_DLLS)
1522pass := dlls
1523PASS := DLLS
1524$(eval $(def_pass))
1525
1526## PASS: binaries
1527# This pass builds binary targets, i.e. programs, system modules and stuff.
[219]1528pass_binaries_doit: $(_PROGRAMS) $(_SYSMODS) $(_OTHER_BINARIES)
[75]1529pass := binaries
1530PASS := BINARIES
1531$(eval $(def_pass))
1532
1533## PASS: others
[83]1534# This pass builds other targets.
[75]1535pass_others_doit: $(_OTHERS)
1536pass := others
1537PASS := OTHERS
1538$(eval $(def_pass))
1539
1540## PASS: publish
1541# This pass installs the built entities to a sandbox area.
1542pass_publish_doit: publish
1543publish::
1544pass := publish
1545PASS := PUBLISH
[76]1546# $(sort).. not nice.
[183]1547SUBDIRS_PUBLISH ?= $(sort $(SUBDIRS) $(SUBDIRS.$(BUILD_TARGET)) $(SUBDIRS_LIBRARIES) $(SUBDIRS_LIBRARIES.$(BUILD_TARGET)) $(SUBDIRS_BINARIES) $(SUBDIRS_BINARIES.$(BUILD_TARGET)) $(SUBDIRS_OTHERS) $(SUBDIRS_OTHERS.$(BUILD_TARGET)))
1548SUBDIRS_AFTER_PUBLISH ?= $(sort $(SUBDIRS_AFTER) $(SUBDIRS_AFTER.$(BUILD_TARGET)) $(SUBDIRS_AFTER_LIBRARIES) $(SUBDIRS_AFTER_LIBRARIES.$(BUILD_TARGET)) $(SUBDIRS_AFTER_BINARIES) $(SUBDIRS_AFTER_BINARIES.$(BUILD_TARGET)) $(SUBDIRS_AFTER_OTHERS) $(SUBDIRS_AFTER_OTHERS.$(BUILD_TARGET)))
1549MAKEFILES_BEFORE_PUBLISH?= $(sort $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_LIBRARIES) $(MAKEFILES_BEFORE_LIBRARIES.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_BINARIES) $(MAKEFILES_BEFORE_BINARIES.$(BUILD_TARGET)) $(MAKEFILES_BEFORE_OTHERS) $(MAKEFILES_BEFORE_OTHERS.$(BUILD_TARGET)))
1550MAKEFILES_AFTER_PUBLISH ?= $(sort $(MAKEFILES_AFTER) $(MAKEFILES_AFTER.$(BUILD_TARGET)) $(MAKEFILES_AFTER_LIBRARIES) $(MAKEFILES_AFTER_LIBRARIES.$(BUILD_TARGET)) $(MAKEFILES_AFTER_BINARIES) $(MAKEFILES_AFTER_BINARIES.$(BUILD_TARGET)) $(MAKEFILES_AFTER_OTHERS) $(MAKEFILES_AFTER_OTHERS.$(BUILD_TARGET)))
[75]1551$(eval $(def_pass))
1552
1553## PASS: packing
1554# This pass processes custom packing rules.
1555pass_packing_doit: packing
1556packing::
1557pass := packing
1558PASS := PACKING
1559$(eval $(def_pass))
1560
1561## PASS: clean
1562# This pass removes all generated files.
1563pass_clean_doit:
[136]1564 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES) $(OTHER_CLEAN)
[75]1565pass := clean
1566PASS := CLEAN
1567$(eval $(def_pass))
1568clean: pass_clean
[183]1569
[75]1570## PASS: nothing
1571# This pass just walks the tree.
1572pass_nothing_doit:
[219]1573 $(call MSG_L1,Did nothing in $(CURDIR))
[75]1574pass := nothing
1575PASS := NOTHING
1576$(eval $(def_pass))
1577nothing: pass_nothing
1578
[78]1579
[219]1580## Pass order
1581# @param $(pass) Current pass name.
1582# @param $(prev_pass) The previous pass name.
1583define def_pass_order
1584pass_$(pass)_order: $(pass_prev)
1585 $(call MSG_L1,Pass $(pass))
1586 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)
1587.NOTPARALLEL: pass_$(pass)_order
1588$(eval pass_prev := pass_$(pass)_order)
1589endef
[183]1590
[219]1591## PASS: order
1592# Use dependencies to ensure correct pass order.
1593pass_prev :=
1594$(foreach pass,$(PASSES),$(eval $(def_pass_order)))
1595
1596
[75]1597#
1598# THE MAIN RULES
1599#
[219]1600all_recursive: $(pass_prev)
[75]1601
[130]1602rebuild: clean
[219]1603 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
[78]1604
1605
[75]1606# misc shortcuts.
1607target: needed libraries binaries others
1608objects: $(_OBJS)
[189]1609libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
[205]1610dlls: $(_DLLS)
[219]1611programs: $(_PROGRAMS)
[205]1612sysmods: $(_SYSMODS)
[75]1613
1614
[72]1615# end-of-file-content
[106]1616__footer_kmk__ := target
[72]1617endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.