source: trunk/kBuild/footer.kmk@ 267

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

allow obj and o.

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