source: trunk/kBuild/footer.kmk@ 219

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

Fixing parallel issues. Working on NEEDED.

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