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
Line 
1# $Id: footer.kmk 221 2005-02-08 17:22:53Z bird $
2## @file
3#
4# kBuild - File included at top of makefile.
5#
6# Copyright (c) 2004 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 typetype0, Boston, MA 0sourcetargettargettarget-targettype07 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 $(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))
43
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
52# all of a type
53_OBJS :=
54_LIBS :=
55_DLLS :=
56_PROGRAMS :=
57_SYSMODS :=
58_DIRS :=
59_IMPORT_LIBS :=
60
61# misc
62pass_prev :=
63
64
65# all objs of a specific target
66define def_objs_var
67_OBJS_$target :=
68endef
69$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
70
71#
72# Basic macros
73#
74
75## Figure out the tool for a source
76# @param $target source file
77# @param $source normalized main target
78# @param $type tooltype
79_SOURCE_TOOL = $(strip $(firstword \
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) ))
96
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) ))
106
107## Figure out the tool for a target.
108# @param $target normalized target.
109# @param $source tooltype.
110_TARGET_TOOL = $(strip $(firstword \
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) \
119 ))
120
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)))
124
125## Removes the root slash from a path (if it has one)
126# @param $1 the path
127no-root-slash=$(patsubst /%,%,$(1))
128
129## Figure out where to put object files.
130# @param $1 source file
131# @param $2 normalized main target
132_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(patsubst $(PATH_TARGET)/$(2)/%,gen/%,$(1)))))
133
134## Figure out where to put object files.
135# @param $1 real target name.
136# @param $2 normalized main target
137_TARGET_BASE = $(PATH_TARGET)/$(2)/$(call no-root-slash,$(call no-drive,$(basename $(1))))
138
139
140#
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#
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
174
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
183ifndef $(target)_$(prop)
184ifndef $(target)_$(prop).$(BUILD_TARGET)
185ifdef $(prop)
186$$(eval $(target)_$(prop) := $($(prop)))
187endif
188ifdef $(prop).$(BUILD_TARGET)
189$$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(prop).$(BUILD_TARGET)))
190endif
191endif
192endif
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
199#
200define def_inherit_defaults
201ifdef $(target)_TEMPLATE
202ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_TOOL) $(TEMPLATE_$($(target)_TEMPLATE)_TOOL.$(BUILD_TARGET))),)
203$$(foreach prop,TOOL, $$(eval $$(def_inherit_defaults_one)))
204endif
205ifeq ($(strip $(TEMPLATE_$($(target)_TEMPLATE)_SDKS) $(TEMPLATE_$($(target)_TEMPLATE)_SDKS.$(BUILD_TARGET))),)
206$$(foreach prop,SDKS, $$(eval $$(def_inherit_defaults_one)))
207endif
208else
209$$(foreach prop,TEMPLATE TOOL SDKS, $$(eval $$(def_inherit_defaults_one)))
210endif
211endef
212# Inherit default properties.
213# !!!!!!THIS IS MESSY AND NOT NECESSARY!!!!!!
214$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_defaults)))
215
216
217## Inherit one template property in a accumulative manner.
218# @param $(prop) Property name
219# @param $(target) Target name
220# @todo fix the precedence order for some properties.
221define def_inherit_template_one
222ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
223ifndef $(target)_$(prop)
224#$$ (warning dbgtarget: $(target)_$(prop):='$(TEMPLATE_$($(target)_TEMPLATE)_$(prop))' TEMPLATE_$($(target)_TEMPLATE)_$(prop))
225$$(target)_$$(prop) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop))
226endif
227endif
228ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
229ifndef $(target)_$(prop).$(BUILD_TARGET)
230#$$ (warning dbgsource: $(target)_$(prop).$(BUILD_TARGET)="TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)" TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET))
231$$(target)_$$(prop).$$(BUILD_TARGET) := $$(TEMPLATE_$$($$(target)_TEMPLATE)_$$(prop).$$(BUILD_TARGET))
232endif
233endif
234endef
235
236## Inherit one template property.
237# @param $(prop) Property name
238# @param $(target) Target name
239define def_inherit_template_one_accumulate
240ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
241#$$ (warning dbgtype: TEMPLATE_$($(target)_TEMPLATE)_$(prop) $(target)_$(prop)=$($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
242$$(eval $(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
243#$$ (warning dbgtype: $(target)_$(prop)=$($(target)_$(prop)))
244endif
245ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
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)))
248endif
249ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)
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)))
252endif
253ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)
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)))
256endif
257endef
258
259
260## Inherit template properties for on target.
261# @param $(target) Target name.
262define def_inherit_template
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)))
267endef
268# Inherit template properties
269$(foreach target, $(ALL_TARGETS),$(eval $(def_inherit_template)))
270
271
272#
273# Include tools
274#
275_TOOLS := $(TOOL)
276define def_tools_target_source
277$(foreach tool,\
278 $($(source)_TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET))\
279 $($(source)_TOOL) $($(target)_$(source)_TOOL)\
280 $($(source)_CTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CTOOL.$(BUILD_TARGET))\
281 $($(source)_CTOOL) $($(target)_$(source)_CTOOL)\
282 $($(source)_CXXTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CXXTOOL.$(BUILD_TARGET))\
283 $($(source)_CXXTOOL) $($(target)_$(source)_CXXTOOL)\
284 $($(source)_ASTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ASTOOL.$(BUILD_TARGET))\
285 $($(source)_ASTOOL) $($(target)_$(source)_ASTOOL)\
286 $($(source)_ARTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ARTOOL.$(BUILD_TARGET))\
287 $($(source)_ARTOOL) $($(target)_$(source)_ARTOOL)\
288 $($(source)_LDTOOL.$(BUILD_TARGET)) $($(target)_$(source)_LDTOOL.$(BUILD_TARGET))\
289 $($(source)_LDTOOL) $($(target)_$(source)_LDTOOL)\
290 ,$(eval _TOOLS += $(tool)))
291endef
292define def_tools_target
293$(foreach tool,\
294 $($(target)_TOOL.$(BUILD_TARGET))\
295 $($(target)_TOOL)\
296 $($(target)_CTOOL.$(BUILD_TARGET))\
297 $($(target)_CTOOL)\
298 $($(target)_CXXTOOL.$(BUILD_TARGET))\
299 $($(target)_CXXTOOL)\
300 $($(target)_ASTOOL.$(BUILD_TARGET))\
301 $($(target)_ASTOOL)\
302 $($(target)_ARTOOL.$(BUILD_TARGET))\
303 $($(target)_ARTOOL)\
304 $($(target)_LDTOOL.$(BUILD_TARGET))\
305 $($(target)_LDTOOL)\
306 ,$(eval _TOOLS += $(tool)))
307$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TYPE)) \
308 , $(eval $(def_tools_target_source)))
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
323#
324_SDKS := $(SDKS)
325define def_sdks_target_source
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)), \
328 $(eval _SDKS += $(sdk)))
329endef
330define def_sdks_target
331$(foreach sdk, $($(target)_SDKS) $($(target)_SDKS.$(BUILD_TARGET)) $($(target)_SDKS.$(BUILD_TYPE))\
332 , $(eval _SDKS += $(sdk)))
333$(foreach source, $($(target)_SOURCES) $($(target)_SOURCES.$(BUILD_TARGET)) $($(target)_SOURCES.$(BUILD_TYPE))\
334 , $(eval $(def_sdks_target_source)))
335endef
336$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
337_SDKS := $(sort $(_SDKS))
338
339define def_sdks_include_one
340ifndef SDK_$(sdk)
341include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
342endif
343endef
344$(foreach sdk, $(_SDKS), $(eval $(def_sdks_include_one)))
345
346#
347# Object processing.
348#
349
350
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}
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.
359#
360# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
361# @remark I now have a clue. Have to use $$ if not.
362define def_target_source_c_cpp_asm
363#$ (warning dbg: def_target_source_c_cpp_asm: source='$(source)' target='$(target)' type='$(type)')
364
365$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target),$(type)))
366$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
367$(eval PATH_$(target)_$(source) := $(patsubst %/,%,$(dir $(outbase))))
368$(eval dirdep := $(dir $(outbase)).dir_created)
369$(eval defs :=\
370 $(TOOL_$(tool)_DEFS)\
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))\
375 $(TOOL_$(tool)_$(type)DEFS)\
376 $(TOOL_$(tool)_$(type)DEFS.$(bld_type))\
377 $(foreach sdk, $(SDKS.$(bld_trg)) \
378 $(SDKS.$(bld_type)) \
379 $(SDKS),\
380 $(SDK_$(sdk)_DEFS)\
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))\
385 $(SDK_$(sdk)_$(type)DEFS)\
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)))\
390 $(DEFS)\
391 $(DEFS.$(bld_type))\
392 $(DEFS.$(bld_trg))\
393 $(DEFS.$(bld_trg_arch))\
394 $(DEFS.$(bld_trg_cpu))\
395 $($(type)DEFS)\
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)) \
402 $($(target)_SDKS),\
403 $(SDK_$(sdk)_DEFS)\
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))\
408 $(SDK_$(sdk)_$(type)DEFS)\
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)))\
413 $($(target)_DEFS)\
414 $($(target)_DEFS.$(bld_type))\
415 $($(target)_DEFS.$(bld_trg))\
416 $($(target)_DEFS.$(bld_trg_arch))\
417 $($(target)_DEFS.$(bld_trg_cpu))\
418 $($(target)_$(type)DEFS)\
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)) \
425 $($(source)_SDKS),\
426 $(SDK_$(sdk)_DEFS)\
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))\
431 $(SDK_$(sdk)_$(type)DEFS)\
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)))\
436 $($(source)_DEFS)\
437 $($(source)_DEFS.$(bld_type))\
438 $($(source)_DEFS.$(bld_trg))\
439 $($(source)_DEFS.$(bld_trg_arch))\
440 $($(source)_DEFS.$(bld_trg_cpu))\
441 $($(source)_$(type)DEFS)\
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)) \
448 $($(target)_$(source)_SDKS),\
449 $(SDK_$(sdk)_DEFS)\
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))\
454 $(SDK_$(sdk)_$(type)DEFS)\
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)))\
459 $($(target)_$(source)_DEFS)\
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))\
464 $($(target)_$(source)_$(type)DEFS)\
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))\
469 )
470$(eval incs :=\
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))\
475 $($(target)_$(source)_$(type)INCS)\
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))\
480 $($(target)_$(source)_INCS)\
481 $(foreach sdk, $($(target)_$(source)_SDKS.$(bld_trg)) \
482 $($(target)_$(source)_SDKS.$(bld_type)) \
483 $($(target)_$(source)_SDKS),\
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))\
488 $(SDK_$(sdk)_$(type)INCS)\
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))\
493 $(SDK_$(sdk)_INCS))\
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))\
498 $($(source)_$(type)INCS)\
499 $($(source)_INCS.$(bld_trg_cpu))\
500 $($(source)_INCS.$(bld_trg_arch))\
501 $($(source)_INCS.$(bld_trg))\
502 $($(source)_INCS.$(bld_type))\
503 $($(source)_INCS)\
504 $(foreach sdk, $($(source)_SDKS.$(bld_trg)) \
505 $($(source)_SDKS.$(bld_type)) \
506 $($(source)_SDKS),\
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))\
511 $(SDK_$(sdk)_$(type)INCS)\
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))\
516 $(SDK_$(sdk)_INCS))\
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))\
521 $($(target)_$(type)INCS)\
522 $($(target)_INCS.$(bld_trg_cpu))\
523 $($(target)_INCS.$(bld_trg_arch))\
524 $($(target)_INCS.$(bld_trg))\
525 $($(target)_INCS.$(bld_type))\
526 $($(target)_INCS)\
527 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
528 $($(target)_SDKS.$(bld_type)) \
529 $($(target)_SDKS),\
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))\
534 $(SDK_$(sdk)_$(type)INCS)\
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))\
539 $(SDK_$(sdk)_INCS))\
540 $(INCS.$(bld_trg_cpu))\
541 $(INCS.$(bld_trg_arch))\
542 $(INCS.$(bld_trg))\
543 $(INCS.$(bld_type))\
544 $(INCS)\
545 $(foreach sdk, $(SDKS.$(bld_trg)) \
546 $(SDKS.$(bld_type)) \
547 $(SDKS),\
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))\
552 $(SDK_$(sdk)_$(type)INCS)\
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))\
557 $(SDK_$(sdk)_INCS))\
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))\
562 $(TOOL_$(tool)_$(type)INCS)\
563 )
564$(eval flags :=\
565 $(TOOL_$(tool)_$(type)FLAGS)\
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))\
570 $($(type)FLAGS)\
571 $($(type)FLAGS.$(bld_type))\
572 $($(type)FLAGS.$(bld_trg))\
573 $($(type)FLAGS.$(bld_trg_arch))\
574 $($(type)FLAGS.$(bld_trg_cpu))\
575 $($(target)_$(type)FLAGS)\
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))\
580 $($(source)_$(type)FLAGS)\
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))\
585 $($(target)_$(source)_$(type)FLAGS)\
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))\
590 )
591$(eval objsuff := $(firstword \
592 $($(target)_$(source)_OBJSUFF.$(bld_trg))\
593 $($(target)_$(source)_OBJSUFF)\
594 $($(source)_OBJSUFF.$(bld_trg))\
595 $($(source)_OBJSUFF)\
596 $($(target)_OBJSUFF.$(bld_trg))\
597 $($(target)_OBJSUFF)\
598 $(TOOL_$(tool)_$(type)OBJSUFF.$(bld_trg))\
599 $(TOOL_$(tool)_$(type)OBJSUFF)\
600 $(SUFF_OBJ)\
601 ))
602$(eval obj := $(outbase)$(objsuff))
603$(eval dep := $(outbase)$(SUFF_DEP))
604$(eval deps := \
605 $($(target)_$(source)_DEPS)\
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))\
610 $($(source)_DEPS)\
611 $($(source)_DEPS.$(bld_type))\
612 $($(source)_DEPS.$(bld_trg))\
613 $($(target)_DEPS)\
614 $($(target)_DEPS.$(bld_trg_arch))\
615 $($(target)_DEPS.$(bld_trg_cpu)))
616
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))
619ifndef TOOL_$(tool)_COMPILE_$(type)
620$$(warning kBuild: TOOL_$(tool)_COMPILE_$(type) is not defined. source=$(source) target=$(target) )
621$$(warning kBuild: tools: \
622 1 $($(target)_$(source)_$(type)TOOL.$(bld_trg)) \
623 2 $($(target)_$(source)_$(type)TOOL) \
624 3 $($(target)_$(source)_TOOL.$(bld_trg)) \
625 4 $($(target)_$(source)_TOOL) \
626 5 $($(target)_$(type)TOOL.$(bld_trg)) \
627 6 $($(target)_$(type)TOOL) \
628 7 $($(target)_TOOL.$(bld_trg)) \
629 8 $($(target)_TOOL) \
630 9 $($(source)_$(type)TOOL.$(bld_trg)) \
631 10 $($(source)_$(type)TOOL) \
632 11 $($(source)_TOOL.$(bld_trg)) \
633 12 $($(source)_TOOL) \
634 13 $($(type)TOOL.$(bld_trg)) \
635 14 $($(type)TOOL) \
636 15 $(TOOL.$(bld_trg)) \
637 16 $(TOOL) )
638endif
639$(eval $(TOOL_$(tool)_COMPILE_$(type)))
640
641$$(basename $$(notdir $$(obj))).o::
642 + $$(MAKE) -B -f $$(MAKEFILE) $(obj)
643$$(basename $$(notdir $$(obj))).obj::
644 + $$(MAKE) -B -f $$(MAKEFILE) $(obj)
645
646$(eval _OBJS_$(target) += $(obj))
647$(eval _DEPFILES += $(dep))
648
649endef
650
651## Generic macro for processing all target sources.
652# @param $(target) Normalized target name.
653define def_target_sources
654#$ (warning def_target_sources)
655# C sources
656$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
657 ,$(eval $(def_target_source_c_cpp_asm)) ))
658
659# C++ sources
660$(foreach type,CXX,$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
661 ,$(eval $(def_target_source_c_cpp_asm)) ))
662
663# ASM sources
664$(foreach type,AS,$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type)))\
665 ,$(eval $(def_target_source_c_cpp_asm)) ))
666endef
667
668
669#
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))))
680$(eval bld_type := $(firstword $($(target)_BLD_TYPE) $(BUILD_TYPE)))
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)))
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)\
697 $(TOOL_$(tool)_LDFLAGS.$(bld_type))\
698 $(TOOL_$(tool)_LDFLAGS.$(bld_trg))\
699 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_arch))\
700 $(TOOL_$(tool)_LDFLAGS.$(bld_trg_cpu))\
701 $(LDFLAGS)\
702 $(LDFLAGS.$(bld_type))\
703 $(LDFLAGS.$(bld_trg))\
704 $(LDFLAGS.$(bld_trg_arch))\
705 $(LDFLAGS.$(bld_trg_cpu))\
706 $($(target)_LDFLAGS)\
707 $($(target)_LDFLAGS.$(bld_type))\
708 $($(target)_LDFLAGS.$(bld_trg))\
709 $($(target)_LDFLAGS.$(bld_trg_arch))\
710 $($(target)_LDFLAGS.$(bld_trg_cpu))\
711)
712$(eval libs :=\
713 $($(target)_LIBS.$(bld_trg_cpu))\
714 $($(target)_LIBS.$(bld_trg_arch))\
715 $($(target)_LIBS.$(bld_trg))\
716 $($(target)_LIBS.$(bld_type))\
717 $($(target)_LIBS)\
718 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
719 $($(target)_SDKS.$(bld_type)) \
720 $($(target)_SDKS),\
721 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
722 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
723 $(SDK_$(sdk)_LIBS.$(bld_trg))\
724 $(SDK_$(sdk)_LIBS.$(bld_type))\
725 $(SDK_$(sdk)_LIBS))\
726 $(LIBS.$(bld_trg_cpu))\
727 $(LIBS.$(bld_trg_arch))\
728 $(LIBS.$(bld_trg))\
729 $(LIBS.$(bld_type))\
730 $(LIBS)\
731 $(foreach sdk, $(SDKS.$(bld_trg)) \
732 $(SDKS.$(bld_type)) \
733 $(SDKS),\
734 $(SDK_$(sdk)_LIBS.$(bld_trg_cpu))\
735 $(SDK_$(sdk)_LIBS.$(bld_trg_arch))\
736 $(SDK_$(sdk)_LIBS.$(bld_trg))\
737 $(SDK_$(sdk)_LIBS.$(bld_type))\
738 $(SDK_$(sdk)_LIBS))\
739 $(TOOL_$(tool)_LIBS.$(bld_trg_cpu))\
740 $(TOOL_$(tool)_LIBS.$(bld_trg_arch))\
741 $(TOOL_$(tool)_LIBS.$(bld_trg))\
742 $(TOOL_$(tool)_LIBS.$(bld_type))\
743 $(TOOL_$(tool)_LIBS)\
744)
745$(eval libpath :=\
746 $($(target)_LIBPATH.$(bld_trg_cpu))\
747 $($(target)_LIBPATH.$(bld_trg_arch))\
748 $($(target)_LIBPATH.$(bld_trg))\
749 $($(target)_LIBPATH.$(bld_type))\
750 $($(target)_LIBPATH)\
751 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
752 $($(target)_SDKS.$(bld_type)) \
753 $($(target)_SDKS),\
754 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
755 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
756 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
757 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
758 $(SDK_$(sdk)_LIBPATH))\
759 $(LIBPATH.$(bld_trg_cpu))\
760 $(LIBPATH.$(bld_trg_arch))\
761 $(LIBPATH.$(bld_trg))\
762 $(LIBPATH.$(bld_type))\
763 $(LIBPATH)\
764 $(foreach sdk, $(SDKS.$(bld_trg)) \
765 $(SDKS.$(bld_type)) \
766 $(SDKS),\
767 $(SDK_$(sdk)_LIBPATH.$(bld_trg_cpu))\
768 $(SDK_$(sdk)_LIBPATH.$(bld_trg_arch))\
769 $(SDK_$(sdk)_LIBPATH.$(bld_trg))\
770 $(SDK_$(sdk)_LIBPATH.$(bld_type))\
771 $(SDK_$(sdk)_LIBPATH))\
772 $(TOOL_$(tool)_LIBPATH.$(bld_trg_cpu))\
773 $(TOOL_$(tool)_LIBPATH.$(bld_trg_arch))\
774 $(TOOL_$(tool)_LIBPATH.$(bld_trg))\
775 $(TOOL_$(tool)_LIBPATH.$(bld_type))\
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
783 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
784 $($(target)_CUSTOM_PRE.$(bld_trg))\
785 $($(target)_CUSTOM_PRE.$(bld_type))\
786 $($(target)_CUSTOM_PRE)\
787 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
788 $(CUSTOM_PRE.$(bld_trg))\
789 $(CUSTOM_PRE.$(bld_type))\
790 $(CUSTOM_PRE)\
791)))
792$(eval custom_post := $(strip $(firstword
793 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
794 $($(target)_CUSTOM_POST.$(bld_trg))\
795 $($(target)_CUSTOM_POST.$(bld_type))\
796 $($(target)_CUSTOM_POST)\
797 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
798 $(CUSTOM_POST.$(bld_trg))\
799 $(CUSTOM_POST.$(bld_type))\
800 $(CUSTOM_POST)\
801)))
802$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
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#
826# LIBRARIES
827#
828
829## Library (one).
830# @param $(target) Normalized library (target) name.
831define def_lib
832# library basics
833$(eval tool := $(call _TARGET_TOOL,$(target),AR))
834ifeq ($(tool),)
835$$(error kBuild: Library target $(target) doesn't have a tool defined!)
836endif
837## @todo prefix
838$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
839$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
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)))
844$(eval libsuff := $(firstword\
845 $($(target)_LIBSUFF.$(bld_trg))\
846 $($(target)_LIBSUFF)\
847 $(TOOL_$(tool)_ARLIBSUFF.$(bld_trg))\
848 $(TOOL_$(tool)_ARLIBSUFF)\
849 $(SUFF_LIB)\
850))
851$(eval lib := $(outbase)$(libsuff))
852$(eval TARGET_$(target) := $(lib))
853
854# source -> object
855$(eval $(def_target_sources))
856
857# library linking
858$(eval tool := $(call _TARGET_TOOL,$(target),AR))
859$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
860$(eval flags :=\
861 $(TOOL_$(tool)_ARFLAGS)\
862 $(TOOL_$(tool)_ARFLAGS.$(bld_type))\
863 $(ARFLAGS)\
864 $(ARFLAGS.$(bld_type))\
865 $($(target)_ARFLAGS)\
866 $($(target)_ARFLAGS.$(bld_type))\
867 )
868$(eval objs = $(_OBJS_$(target)))
869$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
870$(eval dirdep := $(dir $(lib)).dir_created)
871## @todo fix dependencies on makefiles an such
872$(eval deps := $($(target)_DEPS))
873
874$(eval $(TOOL_$(tool)_LINK_LIBRARY))
875
876# publish rule (still need work)
877ifndef $(target)_NOINST
878$(eval publib := $(PATH_LIB)/$(notdir $(lib)))
879$(publib) : $(lib) $(dir $(publib)).dir_created
880 $(CP) $(lib) $(publib)
881
882_LIBS += $(publib)
883_OUT_FILES += $(lib) $(publib)
884else
885_LIBS += $(lib)
886_OUT_FILES += $(lib)
887endif
888_OBJS += $(_OBJS_$(target))
889endef
890
891# Process libraries
892$(foreach target, $(LIBRARIES) $(LIBRARIES.$(BUILD_TARGET)), $(eval $(def_lib)))
893
894
895
896#
897# DLLS
898#
899
900## DLL (one).
901# @param $(target) Normalized target (program) name.
902define def_dll
903# dllmod basics
904$(eval tool := $(call _TARGET_TOOL,$(target),LD))
905$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
906$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
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)))
911$(eval dllsuff := $(firstword $($(target)_DLLSUFF) $($(target)_DLLSUFF) $(TOOL_$(tool)_LDDLLSUFF) $(SUFF_DLL)))
912$(eval dll := $(outbase)$(dllsuff))
913$(eval TARGET_$(target) := $(dll))
914
915# source -> object
916$(eval $(def_target_sources))
917
918# dllmod linking.
919$(eval tool := $(call _TARGET_TOOL,$(target),LD))
920$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
921$(eval objs = $(_OBJS_$(target)))
922$(eval flags :=\
923 $(TOOL_$(tool)_LDFLAGS)\
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))\
928 $(LDFLAGS)\
929 $(LDFLAGS.$(bld_type))\
930 $(LDFLAGS.$(bld_trg))\
931 $(LDFLAGS.$(bld_trg_arch))\
932 $(LDFLAGS.$(bld_trg_cpu))\
933 $($(target)_LDFLAGS)\
934 $($(target)_LDFLAGS.$(bld_type))\
935 $($(target)_LDFLAGS.$(bld_trg))\
936 $($(target)_LDFLAGS.$(bld_trg_arch))\
937 $($(target)_LDFLAGS.$(bld_trg_cpu))\
938)
939$(eval libs :=\
940 $($(target)_LIBS.$(bld_trg_cpu))\
941 $($(target)_LIBS.$(bld_trg_arch))\
942 $($(target)_LIBS.$(bld_trg))\
943 $($(target)_LIBS.$(bld_type))\
944 $($(target)_LIBS)\
945 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
946 $($(target)_SDKS.$(bld_type)) \
947 $($(target)_SDKS),\
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))\
952 $(SDK_$(sdk)_LIBS))\
953 $(LIBS.$(bld_trg_cpu))\
954 $(LIBS.$(bld_trg_arch))\
955 $(LIBS.$(bld_trg))\
956 $(LIBS.$(bld_type))\
957 $(LIBS)\
958 $(foreach sdk, $(SDKS.$(bld_trg)) \
959 $(SDKS.$(bld_type)) \
960 $(SDKS),\
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))\
965 $(SDK_$(sdk)_LIBS))\
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))\
970 $(TOOL_$(tool)_LIBS)\
971)
972$(eval libpath :=\
973 $($(target)_LIBPATH.$(bld_trg_cpu))\
974 $($(target)_LIBPATH.$(bld_trg_arch))\
975 $($(target)_LIBPATH.$(bld_trg))\
976 $($(target)_LIBPATH.$(bld_type))\
977 $($(target)_LIBPATH)\
978 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
979 $($(target)_SDKS.$(bld_type)) \
980 $($(target)_SDKS),\
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))\
985 $(SDK_$(sdk)_LIBPATH))\
986 $(LIBPATH.$(bld_trg_cpu))\
987 $(LIBPATH.$(bld_trg_arch))\
988 $(LIBPATH.$(bld_trg))\
989 $(LIBPATH.$(bld_type))\
990 $(LIBPATH)\
991 $(foreach sdk, $(SDKS.$(bld_trg)) \
992 $(SDKS.$(bld_type)) \
993 $(SDKS),\
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))\
998 $(SDK_$(sdk)_LIBPATH))\
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))\
1003 $(TOOL_$(tool)_LIBPATH)\
1004)
1005$(eval dirdep := $(dir $(dll)).dir_created)
1006## @todo fix dependencies
1007$(eval deps := $($(target)_DEPS))
1008#
1009$(eval custom_pre := $(strip $(firstword
1010 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1011 $($(target)_CUSTOM_PRE.$(bld_trg))\
1012 $($(target)_CUSTOM_PRE.$(bld_type))\
1013 $($(target)_CUSTOM_PRE)\
1014 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1015 $(CUSTOM_PRE.$(bld_trg))\
1016 $(CUSTOM_PRE.$(bld_type))\
1017 $(CUSTOM_PRE)\
1018)))
1019$(eval custom_post := $(strip $(firstword
1020 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1021 $($(target)_CUSTOM_POST.$(bld_trg))\
1022 $($(target)_CUSTOM_POST.$(bld_type))\
1023 $($(target)_CUSTOM_POST)\
1024 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1025 $(CUSTOM_POST.$(bld_trg))\
1026 $(CUSTOM_POST.$(bld_type))\
1027 $(CUSTOM_POST)\
1028)))
1029$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
1030
1031ifndef TOOL_$(tool)_LINK_DLL
1032$$(warning kBuild: TOOL_$(tool)_LINK_DLL is not defined. target=$(target) )
1033$$(warning kBuild: tools: \
1034 1 $($(target)_$(source)TOOL.$(bld_trg)) \
1035 2 $($(target)_$(source)TOOL) \
1036 3 $($(target)_TOOL.$(bld_trg)) \
1037 4 $($(target)_TOOL) \
1038 5 $($(source)TOOL) \
1039 6 $($(source)TOOL.$(bld_trg)) \
1040 7 $(TOOL.$(bld_trg)) \
1041 8 $(TOOL) )
1042endif
1043
1044$(eval $(TOOL_$(tool)_LINK_DLL))
1045
1046
1047# publish rule (still need work)
1048ifndef $(target)_NOINST
1049$(eval pubdll := $(PATH_BIN)/$(notdir $(dll)))
1050$(pubdll) : $(dll) $(dir $(pubdll)).dir_created
1051 $(CP) $(dll) $(pubdll)
1052
1053$(eval TARGET_PUB_$(target) := $(pubdll))
1054_DLLS += $(pubdll)
1055_OUT_FILES += $(dll) $(pubdll)
1056else
1057_DLLS += $(dll)
1058_OUT_FILES += $(dll)
1059endif
1060_OBJS += $(_OBJS_$(target))
1061endef
1062
1063# Process dlls
1064$(foreach target, $(DLLS) $(DLLS.$(BUILD_TARGET)), $(eval $(def_dll)))
1065
1066
1067
1068#
1069# Process import libraries.
1070#
1071# - On OS/2 and windows these are libraries.
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)))))
1079
1080
1081
1082#
1083# PROGRAMS
1084#
1085
1086## Program (one).
1087# @param $(target) Normalized target (program) name.
1088define def_program
1089# basics
1090$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1091$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1092$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
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)))
1097$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
1098$(eval exe := $(outbase)$(exesuff))
1099$(eval TARGET_$(target) := $(exe))
1100
1101# source -> object
1102$(eval $(def_target_sources))
1103
1104# more library stuff.
1105$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1106$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1107$(eval objs = $(_OBJS_$(target)))
1108$(eval flags :=\
1109 $(TOOL_$(tool)_LDFLAGS)\
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))\
1114 $(LDFLAGS)\
1115 $(LDFLAGS.$(bld_type))\
1116 $(LDFLAGS.$(bld_trg))\
1117 $(LDFLAGS.$(bld_trg_arch))\
1118 $(LDFLAGS.$(bld_trg_cpu))\
1119 $($(target)_LDFLAGS)\
1120 $($(target)_LDFLAGS.$(bld_type))\
1121 $($(target)_LDFLAGS.$(bld_trg))\
1122 $($(target)_LDFLAGS.$(bld_trg_arch))\
1123 $($(target)_LDFLAGS.$(bld_trg_cpu))\
1124)
1125$(eval libs :=\
1126 $($(target)_LIBS.$(bld_trg_cpu))\
1127 $($(target)_LIBS.$(bld_trg_arch))\
1128 $($(target)_LIBS.$(bld_trg))\
1129 $($(target)_LIBS.$(bld_type))\
1130 $($(target)_LIBS)\
1131 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1132 $($(target)_SDKS.$(bld_type)) \
1133 $($(target)_SDKS),\
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))\
1138 $(SDK_$(sdk)_LIBS))\
1139 $(LIBS.$(bld_trg_cpu))\
1140 $(LIBS.$(bld_trg_arch))\
1141 $(LIBS.$(bld_trg))\
1142 $(LIBS.$(bld_type))\
1143 $(LIBS)\
1144 $(foreach sdk, $(SDKS.$(bld_trg)) \
1145 $(SDKS.$(bld_type)) \
1146 $(SDKS),\
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))\
1151 $(SDK_$(sdk)_LIBS))\
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))\
1156 $(TOOL_$(tool)_LIBS)\
1157)
1158$(eval libpath :=\
1159 $($(target)_LIBPATH.$(bld_trg_cpu))\
1160 $($(target)_LIBPATH.$(bld_trg_arch))\
1161 $($(target)_LIBPATH.$(bld_trg))\
1162 $($(target)_LIBPATH.$(bld_type))\
1163 $($(target)_LIBPATH)\
1164 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1165 $($(target)_SDKS.$(bld_type)) \
1166 $($(target)_SDKS),\
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))\
1171 $(SDK_$(sdk)_LIBPATH))\
1172 $(LIBPATH.$(bld_trg_cpu))\
1173 $(LIBPATH.$(bld_trg_arch))\
1174 $(LIBPATH.$(bld_trg))\
1175 $(LIBPATH.$(bld_type))\
1176 $(LIBPATH)\
1177 $(foreach sdk, $(SDKS.$(bld_trg)) \
1178 $(SDKS.$(bld_type)) \
1179 $(SDKS),\
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))\
1184 $(SDK_$(sdk)_LIBPATH))\
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))\
1189 $(TOOL_$(tool)_LIBPATH)\
1190)
1191$(eval dirdep := $(dir $(exe)).dir_created)
1192## @todo fix dependencies
1193$(eval deps := $($(target)_DEPS))
1194#
1195$(eval custom_pre := $(strip $(firstword
1196 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1197 $($(target)_CUSTOM_PRE.$(bld_trg))\
1198 $($(target)_CUSTOM_PRE.$(bld_type))\
1199 $($(target)_CUSTOM_PRE)\
1200 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1201 $(CUSTOM_PRE.$(bld_trg))\
1202 $(CUSTOM_PRE.$(bld_type))\
1203 $(CUSTOM_PRE)\
1204)))
1205$(eval custom_post := $(strip $(firstword
1206 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1207 $($(target)_CUSTOM_POST.$(bld_trg))\
1208 $($(target)_CUSTOM_POST.$(bld_type))\
1209 $($(target)_CUSTOM_POST)\
1210 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1211 $(CUSTOM_POST.$(bld_trg))\
1212 $(CUSTOM_POST.$(bld_type))\
1213 $(CUSTOM_POST)\
1214)))
1215$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
1216
1217$(eval $(TOOL_$(tool)_LINK_PROGRAM))
1218# publish rule (still need work)
1219ifndef $(target)_NOINST
1220$(eval pubexe := $(PATH_BIN)/$(notdir $(exe)))
1221$(pubexe) : $(exe) $(dir $(pubexe)).dir_created
1222 $(CP) $(exe) $(pubexe)
1223
1224_PROGRAMS += $(pubexe)
1225_OUT_FILES += $(exe) $(pubexe)
1226else
1227_PROGRAMS += $(exe)
1228_OUT_FILES += $(exe)
1229endif
1230_OBJS += $(_OBJS_$(target))
1231endef
1232
1233# Process libraries
1234$(foreach target, $(PROGRAMS) $(PROGRAMS.$(BUILD_TARGET)), $(eval $(def_program)))
1235
1236
1237
1238#
1239# SYSMODS
1240#
1241
1242## System module (one).
1243# @param $(target) Normalized target (program) name.
1244define def_sysmod
1245# sysmod basics
1246$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1247$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1248$(eval PATH_$(target) := $(patsubst %/,%,$(dir $(outbase))))
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)))
1253$(eval syssuff := $(firstword $($(target)_SYSSUFF) $($(target)_SYSSUFF) $(TOOL_$(tool)_LDSYSSUFF) $(SUFF_SYS)))
1254$(eval sys := $(outbase)$(syssuff))
1255$(eval TARGET_$(target) := $(sys))
1256
1257# source -> object
1258$(eval $(def_target_sources))
1259
1260# sysmod linking
1261$(eval tool := $(call _TARGET_TOOL,$(target),LD))
1262$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
1263$(eval objs = $(_OBJS_$(target)))
1264$(eval flags :=\
1265 $(TOOL_$(tool)_LDFLAGS)\
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))\
1270 $(LDFLAGS)\
1271 $(LDFLAGS.$(bld_type))\
1272 $(LDFLAGS.$(bld_trg))\
1273 $(LDFLAGS.$(bld_trg_arch))\
1274 $(LDFLAGS.$(bld_trg_cpu))\
1275 $($(target)_LDFLAGS)\
1276 $($(target)_LDFLAGS.$(bld_type))\
1277 $($(target)_LDFLAGS.$(bld_trg))\
1278 $($(target)_LDFLAGS.$(bld_trg_arch))\
1279 $($(target)_LDFLAGS.$(bld_trg_cpu))\
1280)
1281$(eval libs :=\
1282 $($(target)_LIBS.$(bld_trg_cpu))\
1283 $($(target)_LIBS.$(bld_trg_arch))\
1284 $($(target)_LIBS.$(bld_trg))\
1285 $($(target)_LIBS.$(bld_type))\
1286 $($(target)_LIBS)\
1287 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1288 $($(target)_SDKS.$(bld_type)) \
1289 $($(target)_SDKS),\
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))\
1294 $(SDK_$(sdk)_LIBS))\
1295 $(LIBS.$(bld_trg_cpu))\
1296 $(LIBS.$(bld_trg_arch))\
1297 $(LIBS.$(bld_trg))\
1298 $(LIBS.$(bld_type))\
1299 $(LIBS)\
1300 $(foreach sdk, $(SDKS.$(bld_trg)) \
1301 $(SDKS.$(bld_type)) \
1302 $(SDKS),\
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))\
1307 $(SDK_$(sdk)_LIBS))\
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))\
1312 $(TOOL_$(tool)_LIBS)\
1313)
1314$(eval libpath :=\
1315 $($(target)_LIBPATH.$(bld_trg_cpu))\
1316 $($(target)_LIBPATH.$(bld_trg_arch))\
1317 $($(target)_LIBPATH.$(bld_trg))\
1318 $($(target)_LIBPATH.$(bld_type))\
1319 $($(target)_LIBPATH)\
1320 $(foreach sdk, $($(target)_SDKS.$(bld_trg)) \
1321 $($(target)_SDKS.$(bld_type)) \
1322 $($(target)_SDKS),\
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))\
1327 $(SDK_$(sdk)_LIBPATH))\
1328 $(LIBPATH.$(bld_trg_cpu))\
1329 $(LIBPATH.$(bld_trg_arch))\
1330 $(LIBPATH.$(bld_trg))\
1331 $(LIBPATH.$(bld_type))\
1332 $(LIBPATH)\
1333 $(foreach sdk, $(SDKS.$(bld_trg)) \
1334 $(SDKS.$(bld_type)) \
1335 $(SDKS),\
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))\
1340 $(SDK_$(sdk)_LIBPATH))\
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))\
1345 $(TOOL_$(tool)_LIBPATH)\
1346)
1347$(eval dirdep := $(dir $(sys)).dir_created)
1348## @todo fix dependencies
1349$(eval deps := $($(target)_DEPS))
1350#
1351$(eval custom_pre := $(strip $(firstword
1352 $($(target)_CUSTOM_PRE.$(bld_trg).$(bld_type))\
1353 $($(target)_CUSTOM_PRE.$(bld_trg))\
1354 $($(target)_CUSTOM_PRE.$(bld_type))\
1355 $($(target)_CUSTOM_PRE)\
1356 $(CUSTOM_PRE.$(bld_trg).$(bld_type))\
1357 $(CUSTOM_PRE.$(bld_trg))\
1358 $(CUSTOM_PRE.$(bld_type))\
1359 $(CUSTOM_PRE)\
1360)))
1361$(eval custom_post := $(strip $(firstword
1362 $($(target)_CUSTOM_POST.$(bld_trg).$(bld_type))\
1363 $($(target)_CUSTOM_POST.$(bld_trg))\
1364 $($(target)_CUSTOM_POST.$(bld_type))\
1365 $($(target)_CUSTOM_POST)\
1366 $(CUSTOM_POST.$(bld_trg).$(bld_type))\
1367 $(CUSTOM_POST.$(bld_trg))\
1368 $(CUSTOM_POST.$(bld_type))\
1369 $(CUSTOM_POST)\
1370)))
1371$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES) $($(target)_SOURCES.$(bld_trg)) $($(target)_SOURCES.$(bld_type))))
1372
1373ifndef TOOL_$(tool)_LINK_SYSMOD
1374$$(warning kBuild: TOOL_$(tool)_LINK_SYSMOD is not defined. target=$(target) )
1375$$(warning kBuild: tools: \
1376 1 $($(target)_$(source)TOOL.$(bld_trg)) \
1377 2 $($(target)_$(source)TOOL) \
1378 3 $($(target)_TOOL.$(bld_trg)) \
1379 4 $($(target)_TOOL) \
1380 5 $($(source)TOOL) \
1381 6 $($(source)TOOL.$(bld_trg)) \
1382 7 $(TOOL.$(bld_trg)) \
1383 8 $(TOOL) )
1384endif
1385
1386$(eval $(TOOL_$(tool)_LINK_SYSMOD))
1387
1388# publish rule (still need work)
1389ifndef $(target)_NOINST
1390$(eval pubsys := $(PATH_BIN)/$(notdir $(sys)))
1391$(pubsys): $(sys) $(dir $(pubsys)).dir_created
1392 $(CP) $(sys) $(pubsys)
1393
1394$(eval _SYSMODS += $(pubsys))
1395$(eval _OUT_FILES += $(sys) $(pubsys))
1396else
1397$(eval _SYSMODS += $(sys))
1398$(eval _OUT_FILES += $(sys))
1399endif
1400_OBJS += $(_OBJS_$(target))
1401endef
1402
1403# Process sysmods
1404$(foreach target, $(SYSMODS) $(SYSMODS.$(BUILD_TARGET)), $(eval $(def_sysmod)))
1405
1406
1407
1408#
1409# OTHERS
1410#
1411_OTHERS = $(OTHERS) $(OTHERS.$(BUILD_TARGET))
1412
1413
1414
1415#
1416# DOCS
1417#
1418
1419
1420#
1421# Directories.
1422#
1423_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(sort $(dir $(_OUT_FILES) $(_OBJS)))))
1424
1425define def_createdir
1426$(dirfile):
1427 $(call MSG_L1,Creating directory $$(@D))
1428 $(MKDIR) -p $$(@D)
1429 @echo dir_created > $$@
1430endef
1431
1432$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
1433
1434
1435#
1436# Include dependency files.
1437#
1438$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
1439
1440
1441#
1442# PASSES (including directory and makefile walking)
1443#
1444# Do all the default passes if it's unspecified.
1445
1446#PASSES ?= needed libraries binaries others publish
1447PASSES ?= needed libraries dlls binaries others
1448
1449## @todo figure out a generic way of configuring how pass works!
1450
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
1454
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
1461pass_$(pass)$(tag):: $(dep)
1462 + $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
1463endef
1464
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
1471pass_$(pass)$(tag):: $(dep)
1472 + $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
1473endef
1474
1475
1476## Execute a pass.
1477# @param $(pass) Lowercase pass name.
1478# @param $(PASS) Uppercase pass name.
1479define def_pass
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)))
1484
1485$(eval tag:=_before)
1486$(eval dep:=)
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)))
1489
1490$(eval tag:=_after)
1491$(eval dep:=pass_$(pass)_doit)
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)))
1494
1495.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
1496.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
1497pass_$(pass)_this: pass_$(pass)_before
1498 + $(QUIET)$$(MAKE) -f $$(MAKEFILE) pass_$(pass)_doit
1499pass_$(pass)_after:: pass_$(pass)_this
1500pass_$(pass): pass_$(pass)_after
1501
1502endef
1503
1504
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
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.
1528pass_binaries_doit: $(_PROGRAMS) $(_SYSMODS) $(_OTHER_BINARIES)
1529pass := binaries
1530PASS := BINARIES
1531$(eval $(def_pass))
1532
1533## PASS: others
1534# This pass builds other targets.
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
1546# $(sort).. not nice.
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)))
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:
1564 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES) $(OTHER_CLEAN)
1565pass := clean
1566PASS := CLEAN
1567$(eval $(def_pass))
1568clean: pass_clean
1569
1570## PASS: nothing
1571# This pass just walks the tree.
1572pass_nothing_doit:
1573 $(call MSG_L1,Did nothing in $(CURDIR))
1574pass := nothing
1575PASS := NOTHING
1576$(eval $(def_pass))
1577nothing: pass_nothing
1578
1579
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
1590
1591## PASS: order
1592# Use dependencies to ensure correct pass order.
1593pass_prev :=
1594$(foreach pass,$(PASSES),$(eval $(def_pass_order)))
1595
1596
1597#
1598# THE MAIN RULES
1599#
1600all_recursive: $(pass_prev)
1601
1602rebuild: clean
1603 + $(MAKE) -f $(firstword $(MAKEFILE_LIST)) all_recursive
1604
1605
1606# misc shortcuts.
1607target: needed libraries binaries others
1608objects: $(_OBJS)
1609libraries: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
1610dlls: $(_DLLS)
1611programs: $(_PROGRAMS)
1612sysmods: $(_SYSMODS)
1613
1614
1615# end-of-file-content
1616__footer_kmk__ := target
1617endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.