source: trunk/kBuild/footer.kmk@ 220

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

Fixed more pass order shit.

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