source: trunk/kBuild/footer.kmk@ 240

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

BLDPROGS must inherit stuff too.

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