source: trunk/kBuild/footer.kmk@ 322

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

Enh. the _OBJECT_BASE hack.

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