source: trunk/kBuild/footer.kmk@ 222

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

Needed -> bldprogs.

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