source: trunk/kBuild/footer.kmk@ 103

Last change on this file since 103 was 98, checked in by bird, 21 years ago

Skipping a few passes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 31.6 KB
RevLine 
[72]1# $Id: footer.kmk 98 2004-06-11 23:47:19Z 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 2 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 330, Boston, MA 02111-1307 USA
24#
25#
26
27ifndef __footer_kmk__
28# start-of-file-content
29
30#
31# Variables.
[73]32# (Some of these need initialization before including definitions using them.)
[72]33#
34
35# all targets.
[83]36ALL_TARGETS := $(LIBRARIES) $(PROGRAMS) $(DLLS) $(SYSMODS) $(OTHERS)
[72]37
[75]38# dependency files.
39_DEPFILES :=
40
41# All kind of output files except for _OBJS and _DEPFILES.
42# Compiling or linking definition outputting other things that $@ and any
43# required dependency file must add those output files to this variable.
44_OUT_FILES :=
45
[72]46# all of a type
47_OBJS :=
48_LIBS :=
49_DLLS :=
50_EXES :=
[83]51_SYSMODS:=
[72]52_DIRS :=
53
54# all objs of a specific target
55define def_objs_var
56_OBJS_$1 :=
57endef
58$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
59
[73]60
[72]61#
[73]62# Basic macros
63#
64
65## Figure out the tool for a source
66# @param $1 source file
67# @param $2 normalized main target
[78]68# @param $3 tooltype
[79]69_SOURCE_TOOL = $(strip $(firstword \
70 $($1_$2_$(3)TOOL.$(BUILD_TARGET)) $($1_$2_TOOL.$(BUILD_TARGET)) \
71 $($1_$2_$(3)TOOL) $($1_$2_TOOL) \
72 $($1_$(3)TOOL.$(BUILD_TARGET)) $($1_TOOL.$(BUILD_TARGET)) \
73 $($1_$(3)TOOL) $($1_TOOL) \
74 $($2_$(3)TOOL.$(BUILD_TARGET)) $($2_TOOL.$(BUILD_TARGET)) \
75 $($2_$(3)TOOL) $($2_TOOL) \
76 $($(3)TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET)) \
77 $($(3)TOOL) $(TOOL) ))
[73]78
[78]79## Figure out the tool for a target.
80# @param $1 normalized target.
81# @param $2 tooltype.
[79]82_TARGET_TOOL = $(strip $(firstword \
83 $($(1)_$(2)TOOL.$(BUILD_TARGET)) $($(1)_$(2)TOOL) \
84 $($(1)_TOOL.$(BUILD_TARGET)) $($(1)_TOOL) \
85 $($(2)TOOL) $($(2)TOOL.$(BUILD_TARGET)) \
86 $(TOOL.$(BUILD_TARGET)) $(TOOL) \
87 ))
[78]88
[73]89## Figure out where to put object files.
90# @param $1 source file
91# @param $2 normalized main target
92_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
93
94## Figure out where to put object files.
95# @param $1 real target name.
96# @param $2 normalized main target
97_TARGET_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
98
99
100#
[72]101# Include templates
102#
103_TEMPLATES := $(TEMPLATE)
104define def_templates
105ifdef $(target)_TEMPLATE
106_TEMPLATES += $($(target)_TEMPLATE)
107endif
108endef
109$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
110_TEMPLATES := $(sort $(_TEMPLATES))
111# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
112
113define def_templates_include
114ifndef TEMPLATE_$(template)
115include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
116endif
117endef
118$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
119
[74]120
[72]121#
122# Common Inheritance
123#
124
125## Inherit defaults property
126# @param $(prop) Property name
127# @param $(target) Target name.
128define def_inherit_defaults_one
[74]129ifndef $(target)_$(prop)
[72]130ifdef $(prop)
[74]131$(target)_$(prop) := $($(prop))
[72]132endif
133endif
134endef
135
136## Inherit default properties for one target.
137# A bit tricky this one, but it depends a bit on whether or not TEMPLATE
138# is inherited from the default properties.
139# @param $(target) Target name
[78]140#
[72]141define def_inherit_defaults
142ifdef $(target)_TEMPLATE
143ifndef TEMPLATE_$($(target)_TEMPLATE)_TOOL
[78]144$(foreach prop,TOOL, $(eval $(def_inherit_defaults_one)))
[72]145endif
146ifndef TEMPLATE_$($(target)_TEMPLATE)_SDKS
[78]147$(foreach prop,SDKS, $(eval $(def_inherit_defaults_one)))
[72]148endif
149else
[78]150$(foreach prop,TEMPLATE TOOL SDKS,$(eval $(def_inherit_defaults_one)))
[72]151endif
152endef
153# Inherit default properties.
154$(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_defaults)))
155
156
[78]157## Inherit one template property in a accumulative manner.
[72]158# @param $(prop) Property name
159# @param $(target) Target name
[78]160# @todo fix the precedence order for some properties.
[72]161define def_inherit_template_one
[78]162ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
[72]163ifndef $(target)_$(prop)
[78]164$(eval $(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
[72]165endif
166endif
[79]167ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
168ifndef $(target)_$(prop).$(BUILD_TARGET)
169$(eval $(target)_$(prop).$(BUILD_TARGET) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)))
170endif
171endif
[72]172endef
173
[78]174## Inherit one template property.
175# @param $(prop) Property name
176# @param $(target) Target name
177define def_inherit_template_one_accumulate
178ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
179$(eval $(target)_$(prop) := $($(target)_$(prop)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop)))
180endif
[79]181ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)
182$(eval $(target)_$(prop).$(BUILD_TARGET) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET)))
183endif
184ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)
185$(eval $(target)_$(prop).$(BUILD_TARGET_CPU) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_CPU)))
186endif
187ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)
188$(eval $(target)_$(prop).$(BUILD_TARGET_ARCH) := $($(target)_$(prop).$(BUILD_TARGET)) $(TEMPLATE_$($(target)_TEMPLATE)_$(prop).$(BUILD_TARGET_ARCH)))
189endif
[78]190endef
191
[72]192## Inherit template properties for on target.
193# @param $(target) Target name.
194define def_inherit_template
[79]195$(foreach prop, TOOL ARTOOL CTOOL CXXTOOL ASTOOL LDTOOL\
[78]196 ,$(eval $(def_inherit_template_one)))
[94]197$(foreach prop,SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS LDFLAGS LIBS LIBPATH \
[78]198 ,$(eval $(def_inherit_template_one_accumulate)))
[72]199endef
200# Inherit template properties
201$(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_template)))
202
203
204
205#
206# Include tools
207#
208_TOOLS := $(TOOL)
209define def_tools_target_source
[78]210$(foreach tool,\
[79]211 $($(source)_TOOL.$(BUILD_TARGET)) $($(target)_$(source)_TOOL.$(BUILD_TARGET))\
[78]212 $($(source)_TOOL) $($(target)_$(source)_TOOL)\
[79]213 $($(source)_CTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CTOOL.$(BUILD_TARGET))\
[78]214 $($(source)_CTOOL) $($(target)_$(source)_CTOOL)\
[79]215 $($(source)_CXXTOOL.$(BUILD_TARGET)) $($(target)_$(source)_CXXTOOL.$(BUILD_TARGET))\
[78]216 $($(source)_CXXTOOL) $($(target)_$(source)_CXXTOOL)\
[79]217 $($(source)_ASTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ASTOOL.$(BUILD_TARGET))\
[78]218 $($(source)_ASTOOL) $($(target)_$(source)_ASTOOL)\
[79]219 $($(source)_ARTOOL.$(BUILD_TARGET)) $($(target)_$(source)_ARTOOL.$(BUILD_TARGET))\
[78]220 $($(source)_ARTOOL) $($(target)_$(source)_ARTOOL)\
[79]221 $($(source)_LDTOOL.$(BUILD_TARGET)) $($(target)_$(source)_LDTOOL.$(BUILD_TARGET))\
[78]222 $($(source)_LDTOOL) $($(target)_$(source)_LDTOOL)\
223 ,$(eval _TOOLS += $(tool)))
[72]224endef
225define def_tools_target
[78]226$(foreach tool,\
[79]227 $($(target)_TOOL.$(BUILD_TARGET))\
[78]228 $($(target)_TOOL)\
[79]229 $($(target)_CTOOL.$(BUILD_TARGET))\
[78]230 $($(target)_CTOOL)\
[79]231 $($(target)_CXXTOOL.$(BUILD_TARGET))\
[78]232 $($(target)_CXXTOOL)\
[79]233 $($(target)_ASTOOL.$(BUILD_TARGET))\
[78]234 $($(target)_ASTOOL)\
[79]235 $($(target)_ARTOOL.$(BUILD_TARGET))\
[78]236 $($(target)_ARTOOL)\
[79]237 $($(target)_LDTOOL.$(BUILD_TARGET))\
[78]238 $($(target)_LDTOOL)\
[79]239 ,$(eval _TOOLS += $(tool)))
[72]240$(foreach source, $($(target)_SOURCES), $(eval $(def_tools_target_source)))
241endef
242$(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
243_TOOLS := $(sort $(_TOOLS))
244
245define def_tools_include
246ifndef TOOL_$(tool)
247include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
248endif
249endef
250$(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
251
252
253#
254# Include SDKs
[73]255#
[72]256_SDKS := $(SDKS)
257define def_sdks_target_source
258$(foreach sdk, $($(source)_SDKS) $($(target)_$(source)_SDKS), \
259 $(eval _SDKS += $(sdk)))
260endef
261define def_sdks_target
262$(foreach sdk, $($(target)_SDKS), $(eval _SDKS += $(sdk)))
263$(foreach source, $($(target)_SOURCES), $(eval $(def_sdks_target_source)))
264endef
265$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
266_SDKS := $(sort $(_SDKS))
267
268define def_sdks_include
269ifndef SDK_$(sdk)
270include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
271endif
272endef
273$(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
274
[73]275#
276# Object processing.
277#
[72]278
[73]279## Generic macro for processing C, C++ and Assembly sources.
280# @param $(target) Normalized target name.
281# @param $(source) Source file name.
282# @param $(type) Source type. {C,CXX,AS}
[72]283#
[73]284# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
285define def_target_source_c_cpp_asm
286#$ (warning dbg: def_target_source_c_cpp_asm: source=$(source) target=$(target) type=$(type))
287
[78]288$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target),$(type)))
[73]289$(eval defs :=\
[78]290 $(TOOL_$(tool)_DEFS)\
291 $(TOOL_$(tool)_DEFS.$(BUILD_TYPE))\
292 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET))\
293 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_ARCH))\
294 $(TOOL_$(tool)_DEFS.$(BUILD_TARGET_CPU))\
[74]295 $(TOOL_$(tool)_$(type)DEFS)\
296 $(TOOL_$(tool)_$(type)DEFS.$(BUILD_TYPE))\
[78]297 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
298 $(SDKS.$(BUILD_TYPE)) \
299 $(SDKS),\
300 $(SDK_$(sdk)_DEFS)\
301 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
302 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
303 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
304 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
305 $(SDK_$(sdk)_$(type)DEFS)\
306 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
307 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
308 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
309 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
[74]310 $(DEFS)\
311 $(DEFS.$(BUILD_TYPE))\
[78]312 $(DEFS.$(BUILD_TARGET))\
313 $(DEFS.$(BUILD_TARGET_ARCH))\
314 $(DEFS.$(BUILD_TARGET_CPU))\
315 $($(type)DEFS)\
316 $($(type)DEFS.$(BUILD_TYPE))\
317 $($(type)DEFS.$(BUILD_TARGET))\
318 $($(type)DEFS.$(BUILD_TARGET_ARCH))\
319 $($(type)DEFS.$(BUILD_TARGET_CPU))\
320 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
321 $($(target)_SDKS.$(BUILD_TYPE)) \
322 $($(target)_SDKS),\
323 $(SDK_$(sdk)_DEFS)\
324 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
325 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
326 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
327 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
328 $(SDK_$(sdk)_$(type)DEFS)\
329 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
330 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
331 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
332 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
[74]333 $($(target)_DEFS)\
334 $($(target)_DEFS.$(BUILD_TYPE))\
335 $($(target)_DEFS.$(BUILD_TARGET))\
[78]336 $($(target)_DEFS.$(BUILD_TARGET_ARCH))\
337 $($(target)_DEFS.$(BUILD_TARGET_CPU))\
338 $($(target)_$(type)DEFS)\
339 $($(target)_$(type)DEFS.$(BUILD_TYPE))\
340 $($(target)_$(type)DEFS.$(BUILD_TARGET))\
341 $($(target)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
342 $($(target)_$(type)DEFS.$(BUILD_TARGET_CPU))\
343 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
344 $($(source)_SDKS.$(BUILD_TYPE)) \
345 $($(source)_SDKS),\
346 $(SDK_$(sdk)_DEFS)\
347 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
348 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
349 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
350 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
351 $(SDK_$(sdk)_$(type)DEFS)\
352 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
353 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
354 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
355 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
[74]356 $($(source)_DEFS)\
357 $($(source)_DEFS.$(BUILD_TYPE))\
358 $($(source)_DEFS.$(BUILD_TARGET))\
[78]359 $($(source)_DEFS.$(BUILD_TARGET_ARCH))\
360 $($(source)_DEFS.$(BUILD_TARGET_CPU))\
[73]361 $($(source)_$(type)DEFS)\
[74]362 $($(source)_$(type)DEFS.$(BUILD_TYPE))\
363 $($(source)_$(type)DEFS.$(BUILD_TARGET))\
[78]364 $($(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
365 $($(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
366 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
367 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
368 $($(target)_$(source)_SDKS),\
369 $(SDK_$(sdk)_DEFS)\
370 $(SDK_$(sdk)_DEFS.$(BUILD_TYPE))\
371 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET))\
372 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_ARCH))\
373 $(SDK_$(sdk)_DEFS.$(BUILD_TARGET_CPU))
374 $(SDK_$(sdk)_$(type)DEFS)\
375 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TYPE))\
376 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET))\
377 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
378 $(SDK_$(sdk)_$(type)DEFS.$(BUILD_TARGET_CPU)))\
[74]379 $($(target)_$(source)_DEFS)\
380 $($(target)_$(source)_DEFS.$(BUILD_TYPE))\
381 $($(target)_$(source)_DEFS.$(BUILD_TARGET))\
[78]382 $($(target)_$(source)_DEFS.$(BUILD_TARGET_ARCH))\
383 $($(target)_$(source)_DEFS.$(BUILD_TARGET_CPU))\
[74]384 $($(target)_$(source)_$(type)DEFS)\
385 $($(target)_$(source)_$(type)DEFS.$(BUILD_TYPE))\
386 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET))\
[78]387 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_ARCH))\
388 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET_CPU))\
[73]389 )
390$(eval incs :=\
[78]391 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
392 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
[74]393 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET))\
394 $($(target)_$(source)_$(type)INCS.$(BUILD_TYPE))\
[73]395 $($(target)_$(source)_$(type)INCS)\
[78]396 $($(target)_$(source)_INCS.$(BUILD_TARGET_CPU))\
397 $($(target)_$(source)_INCS.$(BUILD_TARGET_ARCH))\
[74]398 $($(target)_$(source)_INCS.$(BUILD_TARGET))\
399 $($(target)_$(source)_INCS.$(BUILD_TYPE))\
[73]400 $($(target)_$(source)_INCS)\
[78]401 $(foreach sdk, $($(target)_$(source)_SDKS.$(BUILD_TARGET)) \
402 $($(target)_$(source)_SDKS.$(BUILD_TYPE)) \
403 $($(target)_$(source)_SDKS),
404 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
405 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
406 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
407 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
408 $(SDK_$(sdk)_$(type)INCS)\
409 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
410 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
411 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
412 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
413 $(SDK_$(sdk)_INCS))\
414 $($(source)_$(type)INCS.$(BUILD_TARGET_CPU))\
415 $($(source)_$(type)INCS.$(BUILD_TARGET_ARCH))\
[74]416 $($(source)_$(type)INCS.$(BUILD_TARGET))\
417 $($(source)_$(type)INCS.$(BUILD_TYPE))\
[73]418 $($(source)_$(type)INCS)\
[78]419 $($(source)_INCS.$(BUILD_TARGET_CPU))\
420 $($(source)_INCS.$(BUILD_TARGET_ARCH))\
[74]421 $($(source)_INCS.$(BUILD_TARGET))\
422 $($(source)_INCS.$(BUILD_TYPE))\
[73]423 $($(source)_INCS)\
[78]424 $(foreach sdk, $($(source)_SDKS.$(BUILD_TARGET)) \
425 $($(source)_SDKS.$(BUILD_TYPE)) \
426 $($(source)_SDKS),\
427 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
428 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
429 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
430 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
431 $(SDK_$(sdk)_$(type)INCS)\
432 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
433 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
434 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
435 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
436 $(SDK_$(sdk)_INCS))\
437 $($(target)_$(type)INCS.$(BUILD_TARGET_CPU))\
438 $($(target)_$(type)INCS.$(BUILD_TARGET_ARCH))\
[74]439 $($(target)_$(type)INCS.$(BUILD_TARGET))\
440 $($(target)_$(type)INCS.$(BUILD_TYPE))\
[73]441 $($(target)_$(type)INCS)\
[78]442 $($(target)_INCS.$(BUILD_TARGET_CPU))\
443 $($(target)_INCS.$(BUILD_TARGET_ARCH))\
[74]444 $($(target)_INCS.$(BUILD_TARGET))\
445 $($(target)_INCS.$(BUILD_TYPE))\
[73]446 $($(target)_INCS)\
[78]447 $(foreach sdk, $($(target)_SDKS.$(BUILD_TARGET)) \
448 $($(target)_SDKS.$(BUILD_TYPE)) \
449 $($(target)_SDKS),\
450 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
451 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
452 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
453 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
454 $(SDK_$(sdk)_$(type)INCS)\
455 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
456 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
457 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
458 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
459 $(SDK_$(sdk)_INCS))\
460 $(INCS.$(BUILD_TARGET_CPU))\
461 $(INCS.$(BUILD_TARGET_ARCH))\
[74]462 $(INCS.$(BUILD_TARGET))\
463 $(INCS.$(BUILD_TYPE))\
[73]464 $(INCS)\
[78]465 $(foreach sdk, $(SDKS.$(BUILD_TARGET)) \
466 $(SDKS.$(BUILD_TYPE)) \
467 $(SDKS),\
468 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_CPU))\
469 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET_ARCH))\
470 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TARGET))\
471 $(SDK_$(sdk)_$(type)INCS.$(BUILD_TYPE))\
472 $(SDK_$(sdk)_$(type)INCS)\
473 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_CPU))\
474 $(SDK_$(sdk)_INCS.$(BUILD_TARGET_ARCH))\
475 $(SDK_$(sdk)_INCS.$(BUILD_TARGET))\
476 $(SDK_$(sdk)_INCS.$(BUILD_TYPE))\
477 $(SDK_$(sdk)_INCS))\
478 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_CPU))\
479 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET_ARCH))\
[74]480 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET))\
481 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TYPE))\
[73]482 $(TOOL_$(tool)_$(type)INCS)\
483 )
484$(eval flags :=\
485 $(TOOL_$(tool)_$(type)FLAGS)\
486 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
[74]487 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET))\
[78]488 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
489 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
[73]490 $($(type)FLAGS)\
491 $($(type)FLAGS.$(BUILD_TYPE))\
[74]492 $($(type)FLAGS.$(BUILD_TARGET))\
[78]493 $($(type)FLAGS.$(BUILD_TARGET_ARCH))\
494 $($(type)FLAGS.$(BUILD_TARGET_CPU))\
[73]495 $($(target)_$(type)FLAGS)\
496 $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
[74]497 $($(target)_$(type)FLAGS.$(BUILD_TARGET))\
[78]498 $($(target)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
499 $($(target)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
[73]500 $($(source)_$(type)FLAGS)\
501 $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
[74]502 $($(source)_$(type)FLAGS.$(BUILD_TARGET))\
[78]503 $($(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
504 $($(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
[73]505 $($(target)_$(source)_$(type)FLAGS)\
506 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
[74]507 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET))\
[78]508 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_ARCH))\
509 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET_CPU))\
[73]510 )
511$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
512$(eval dirdep := $(dir $(outbase)).dir_created)
[74]513$(eval objsuff := $(firstword \
514 $($(target)_$(source)_OBJSUFF.$(BUILD_TARGET))\
515 $($(target)_$(source)_OBJSUFF)\
516 $($(source)_OBJSUFF.$(BUILD_TARGET))\
517 $($(source)_OBJSUFF)\
518 $($(target)_OBJSUFF.$(BUILD_TARGET))\
519 $($(target)_OBJSUFF)\
520 $(TOOL_$(tool)_$(type)OBJSUFF.$(BUILD_TARGET))\
521 $(TOOL_$(tool)_$(type)OBJSUFF)\
522 $(SUFF_OBJ)\
523 ))
[73]524$(eval obj := $(outbase)$(objsuff))
[74]525$(eval dep := $(outbase)$(SUFF_DEP))
[73]526
527#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
[97]528ifndef TOOL_$(tool)_COMPILE_$(type)
529$$(warning kBuild: TOOL_$(tool)_COMPILE_$(type) is not defined. source=$(source) target=$(target) )
530$$(warning kBuild: tools: \
531 1 $($(source)_$(target)_$(type)TOOL.$(BUILD_TARGET)) $($(source)_$(target)_TOOL.$(BUILD_TARGET)) \
532 2 $($(source)_$(target)_$(type)TOOL) $($(source)_$(target)_TOOL) \
533 3 $($(source)_$(type)TOOL.$(BUILD_TARGET)) $($(source)_TOOL.$(BUILD_TARGET)) \
534 4 $($(source)_$(type)TOOL) $($(source)_TOOL) \
535 5 $($(target)_$(type)TOOL.$(BUILD_TARGET)) $($(target)_TOOL.$(BUILD_TARGET)) \
536 6 $($(target)_$(type)TOOL) $($(target)_TOOL) \
537 7 $($(type)TOOL.$(BUILD_TARGET)) $(TOOL.$(BUILD_TARGET)) \
538 8 $($(type)TOOL) $(TOOL))
539endif
[73]540$(eval $(TOOL_$(tool)_COMPILE_$(type)))
541
542$(eval _OBJS_$(target) += $(obj))
543$(eval _DEPFILES += $(dep))
544
545endef
546
547## Generic macro for processing all target sources.
[74]548# @param $(target) Normalized target name.
[73]549define def_target_sources
550#$ (warning def_target_sources)
551# C sources
552$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES))\
553 ,$(eval $(def_target_source_c_cpp_asm)) ))
554
555# C++ sources
[95]556$(foreach type,CXX,$(foreach source, $(filter %.cpp %.cxx %.xx, $($(target)_SOURCES))\
[73]557 ,$(eval $(def_target_source_c_cpp_asm)) ))
558
559# ASM sources
[95]560$(foreach type,AS,$(foreach source, $(filter %.asm %.s %.S, $($(target)_SOURCES))\
[73]561 ,$(eval $(def_target_source_c_cpp_asm)) ))
562endef
563
564
565#
[72]566# LIBRARIES
[73]567#
[72]568
569## Library (one).
[74]570# @param $(target) Normalized library (target) name.
[72]571define def_lib
[73]572# source -> object
573$(eval $(def_target_sources))
[72]574
[73]575# library
[78]576$(eval tool := $(call _TARGET_TOOL,$(target),AR))
577ifeq ($(tool),)
578$$(error kBuild: Library target $(target) doesn't have a tool defined!)
579endif
[74]580$(eval flags :=\
581 $(TOOL_$(tool)_ARFLAGS)\
582 $(TOOL_$(tool)_ARFLAGS.$(BUILD_TYPE))\
583 $(ARFLAGS)\
584 $(ARFLAGS.$(BUILD_TYPE))\
585 $($(target)_ARFLAGS)\
586 $($(target)_ARFLAGS.$(BUILD_TYPE))\
587 )
588$(eval libsuff := $(firstword\
589 $($(target)_LIBSUFF.$(BUILD_TARGET))\
590 $($(target)_LIBSUFF)\
591 $(TOOL_$(tool)_ARLIBSUFF.$(BUILD_TARGET))\
592 $(TOOL_$(tool)_ARLIBSUFF)\
593 $(SUFF_LIB)\
594))
[73]595## @todo prefix
596$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
597$(eval lib := $(outbase)$(libsuff))
598$(eval objs = $(_OBJS_$(target)))
[91]599$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES)))
[73]600$(eval dirdep := $(dir $(lib)).dir_created)
[78]601## @todo fix dependencies on makefiles an such
[73]602$(eval deps := )
[72]603
[73]604$(eval $(TOOL_$(tool)_LINK_LIBRARY))
[72]605
[73]606_OBJS += $(_OBJS_$(target))
607_LIBS += $(lib)
[75]608_OUT_FILES += $(lib)
[72]609endef
610
611# Process libraries
612$(foreach target, $(LIBRARIES), $(eval $(def_lib)))
613
614
615
616#
617# PROGRAMS
618#
619
[74]620## Program (one).
621# @param $(target) Normalized target (program) name.
622define def_program
623# source -> object
624$(eval $(def_target_sources))
[72]625
[74]626# library
[78]627$(eval tool := $(call _TARGET_TOOL,$(target),LD))
[74]628$(eval flags :=\
629 $(TOOL_$(tool)_LDFLAGS)\
630 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
[89]631 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
632 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
633 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
[74]634 $(LDFLAGS)\
635 $(LDFLAGS.$(BUILD_TYPE))\
[89]636 $(LDFLAGS.$(BUILD_TARGET))\
637 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
638 $(LDFLAGS.$(BUILD_TARGET_CPU))\
[74]639 $($(target)_LDFLAGS)\
640 $($(target)_LDFLAGS.$(BUILD_TYPE))\
[89]641 $($(target)_LDFLAGS.$(BUILD_TARGET))\
642 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
643 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
[74]644)
645$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
646$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
647$(eval exe := $(outbase)$(exesuff))
648$(eval objs = $(_OBJS_$(target)))
649$(eval libs :=\
[87]650 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
651 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
652 $($(target)_LIBS.$(BUILD_TARGET))\
[74]653 $($(target)_LIBS.$(BUILD_TYPE))\
654 $($(target)_LIBS)\
[87]655 $(LIBS.$(BUILD_TARGET_CPU))\
656 $(LIBS.$(BUILD_TARGET_ARCH))\
657 $(LIBS.$(BUILD_TARGET))\
[74]658 $(LIBS.$(BUILD_TYPE))\
659 $(LIBS)\
660 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
661 $(TOOL_$(tool)_LIBS)\
662)
663$(eval libpath :=\
[87]664 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
665 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
666 $($(target)_LIBPATH.$(BUILD_TARGET))\
[74]667 $($(target)_LIBPATH.$(BUILD_TYPE))\
668 $($(target)_LIBPATH)\
[87]669 $(LIBPATH.$(BUILD_TARGET_CPU))\
670 $(LIBPATH.$(BUILD_TARGET_ARCH))\
671 $(LIBPATH.$(BUILD_TARGET))\
[74]672 $(LIBPATH.$(BUILD_TYPE))\
673 $(LIBPATH)\
[87]674 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
675 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
676 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
[74]677 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
678 $(TOOL_$(tool)_LIBPATH)\
679)
680$(eval dirdep := $(dir $(exe)).dir_created)
681## @todo fix dependencies
682$(eval deps := )
683#
684$(eval deffile := $(strip $(firstword
685 $($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
686 $($(target)_DEFFILE.$(BUILD_TARGET))\
687 $($(target)_DEFFILE.$(BUILD_TYPE))\
688 $($(target)_DEFFILE)\
689 $(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
690 $(DEFFILE.$(BUILD_TARGET))\
691 $(DEFFILE.$(BUILD_TYPE))\
692 $(DEFFILE)\
693)))
694$(eval custom_pre := $(strip $(firstword
695 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
696 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
697 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
698 $($(target)_CUSTOM_PRE)\
699 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
700 $(CUSTOM_PRE.$(BUILD_TARGET))\
701 $(CUSTOM_PRE.$(BUILD_TYPE))\
702 $(CUSTOM_PRE)\
703)))
704$(eval custom_post := $(strip $(firstword
705 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
706 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
707 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
708 $($(target)_CUSTOM_POST)\
709 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
710 $(CUSTOM_POST.$(BUILD_TARGET))\
711 $(CUSTOM_POST.$(BUILD_TYPE))\
712 $(CUSTOM_POST)\
713)))
[91]714$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES)))
[72]715
[74]716$(eval $(TOOL_$(tool)_LINK_PROGRAM))
717
718_OBJS += $(_OBJS_$(target))
719_EXES += $(exe)
[75]720_OUT_FILES += $(exe)
[74]721endef
722
723# Process libraries
724$(foreach target, $(PROGRAMS), $(eval $(def_program)))
725
726
727
[72]728#
729# DLLS
730#
731
732
733
734#
[83]735# SYSMODS
[72]736#
737
[83]738## System moduler (one).
739# @param $(target) Normalized target (program) name.
740define def_sysmod
741# source -> object
742$(eval $(def_target_sources))
[72]743
[83]744# library
745$(eval tool := $(call _TARGET_TOOL,$(target),LD))
746$(eval flags :=\
747 $(TOOL_$(tool)_LDFLAGS)\
748 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
[89]749 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET))\
750 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_ARCH))\
751 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TARGET_CPU))\
[83]752 $(LDFLAGS)\
753 $(LDFLAGS.$(BUILD_TYPE))\
[89]754 $(LDFLAGS.$(BUILD_TARGET))\
755 $(LDFLAGS.$(BUILD_TARGET_ARCH))\
756 $(LDFLAGS.$(BUILD_TARGET_CPU))\
[83]757 $($(target)_LDFLAGS)\
758 $($(target)_LDFLAGS.$(BUILD_TYPE))\
[89]759 $($(target)_LDFLAGS.$(BUILD_TARGET))\
760 $($(target)_LDFLAGS.$(BUILD_TARGET_ARCH))\
761 $($(target)_LDFLAGS.$(BUILD_TARGET_CPU))\
[83]762)
763$(eval syssuff := $(firstword $($(target)_SYSSUFF) $($(target)_SYSSUFF) $(TOOL_$(tool)_LDSYSSUFF) $(SUFF_SYS)))
764$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
765$(eval sys := $(outbase)$(syssuff))
766$(eval objs = $(_OBJS_$(target)))
767$(eval libs :=\
[87]768 $($(target)_LIBS.$(BUILD_TARGET_CPU))\
769 $($(target)_LIBS.$(BUILD_TARGET_ARCH))\
770 $($(target)_LIBS.$(BUILD_TARGET))\
[83]771 $($(target)_LIBS.$(BUILD_TYPE))\
772 $($(target)_LIBS)\
[87]773 $(LIBS.$(BUILD_TARGET_CPU))\
774 $(LIBS.$(BUILD_TARGET_ARCH))\
775 $(LIBS.$(BUILD_TARGET))\
[83]776 $(LIBS.$(BUILD_TYPE))\
777 $(LIBS)\
778 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
779 $(TOOL_$(tool)_LIBS)\
780)
781$(eval libpath :=\
[87]782 $($(target)_LIBPATH.$(BUILD_TARGET_CPU))\
783 $($(target)_LIBPATH.$(BUILD_TARGET_ARCH))\
784 $($(target)_LIBPATH.$(BUILD_TARGET))\
[83]785 $($(target)_LIBPATH.$(BUILD_TYPE))\
786 $($(target)_LIBPATH)\
[87]787 $(LIBPATH.$(BUILD_TARGET_CPU))\
788 $(LIBPATH.$(BUILD_TARGET_ARCH))\
789 $(LIBPATH.$(BUILD_TARGET))\
[83]790 $(LIBPATH.$(BUILD_TYPE))\
791 $(LIBPATH)\
[87]792 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_CPU))\
793 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET_ARCH))\
794 $(TOOL_$(tool)_LIBPATH.$(BUILD_TARGET))\
[83]795 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
796 $(TOOL_$(tool)_LIBPATH)\
797)
798$(eval dirdep := $(dir $(sys)).dir_created)
799## @todo fix dependencies
800$(eval deps := )
801#
802$(eval deffile := $(strip $(firstword
803 $($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
804 $($(target)_DEFFILE.$(BUILD_TARGET))\
805 $($(target)_DEFFILE.$(BUILD_TYPE))\
806 $($(target)_DEFFILE)\
807 $(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
808 $(DEFFILE.$(BUILD_TARGET))\
809 $(DEFFILE.$(BUILD_TYPE))\
810 $(DEFFILE)\
811)))
812$(eval custom_pre := $(strip $(firstword
813 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
814 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
815 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
816 $($(target)_CUSTOM_PRE)\
817 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
818 $(CUSTOM_PRE.$(BUILD_TARGET))\
819 $(CUSTOM_PRE.$(BUILD_TYPE))\
820 $(CUSTOM_PRE)\
821)))
822$(eval custom_post := $(strip $(firstword
823 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
824 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
825 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
826 $($(target)_CUSTOM_POST)\
827 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
828 $(CUSTOM_POST.$(BUILD_TARGET))\
829 $(CUSTOM_POST.$(BUILD_TYPE))\
830 $(CUSTOM_POST)\
831)))
[91]832$(eval othersrc := $(filter-out %.c %.cpp %.cxx %.cc %.s %.S %.asm,$($(target)_SOURCES)))
[72]833
[83]834$(eval $(TOOL_$(tool)_LINK_SYSMOD))
835
836_OBJS += $(_OBJS_$(target))
837_SYSMODS += $(sys)
838_OUT_FILES += $(sys)
839endef
840
841# Process libraries
842$(foreach target, $(SYSMODS), $(eval $(def_sysmod)))
843
844
845
[72]846#
847# OTHERS
848#
849
850
851
852#
853# DOCS
854#
855
856
857#
858# Directories.
859#
[83]860_OUTPUT_FILES := $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS) $(_SYSMODS)
[75]861_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OUTPUT_FILES))))
[72]862
863define def_createdir
864$(dirfile):
[73]865 $(call MSG_L1,Creating directory $$(@D))
[72]866 $(MKDIR) -p $$(@D)
[73]867 @echo dir_created > $$@
[72]868endef
869
870$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
871
[75]872
[72]873#
[75]874# Include dependency files.
[72]875#
[75]876$(foreach dep,$(wildcard $(_DEPFILES)),$(eval include $(dep)))
[72]877
[75]878
879#
880# PASSES (including directory and makefile walking)
881#
882# Do all the default passes if it's unspecified.
[72]883
[98]884#PASSES ?= needed libraries binaries others publish
885PASSES ?= libraries binaries
886
[75]887## Proritized list of the default makefile when walking subdirectories.
888# The user can overload this list.
889DEFAULT_MAKEFILE ?= Makefile.kmk makefile.kmk Makefile makefile
[72]890
[75]891## Subdir
892# @param $(pass) Lowercase pass name.
893# @param $(PASS) Uppercase pass name.
894# @param $(subdir) Subdirectory
895# @param $(tag) tag to attach to the rule name.
896define def_pass_subdir
897pass_$(pass)$(tag)::
898 $(QUIET)$$(MAKE) -C $(subdir) -f $$(notdir $$(firstword $$(wildcard $$(addprefix $(subdir)/,$$(DEFAULT_MAKEFILE))))) pass_$(pass)
899endef
[72]900
[75]901## Submakefile
902# @param $(pass) Lowercase pass name.
903# @param $(PASS) Uppercase pass name.
904# @param $(makefile) Makefile.
905# @param $(tag) tag to attach to the rule name.
906define def_pass_makefile
907pass_$(pass)$(tag)::
908 $(QUIET)$$(MAKE) -C $(patsubst %/,%,$(dir $(makefile))) -f $(notdir $(makefile)) pass_$(pass)
909endef
[73]910
[74]911
[75]912## Execute a pass.
913# @param $(pass) Lowercase pass name.
914# @param $(PASS) Uppercase pass name.
915define def_pass
916$(eval SUBDIRS_$(PASS) ?= $(SUBDIRS))
917$(eval SUBDIRS_AFTER_$(PASS) ?= $(SUBDIRS_AFTER))
918$(eval MAKEFILES_BEFORE_$(PASS) ?= $(MAKEFILES_BEFORE))
919$(eval MAKEFILES_AFTER_$(PASS) ?= $(MAKEFILES_AFTER))
920
921$(eval tag:=_before)
922$(foreach subdir,$(SUBDIRS_$(PASS)),$(eval $(def_pass_subdir)))
923$(foreach makefile,$(MAKEFILES_BEFORE_$(PASS)),$(eval $(def_pass_makefile)))
924
925$(eval tag:=_after)
926$(foreach subdir,$(SUBDIRS_AFTER_$(PASS)),$(eval $(def_pass_subdir)))
927$(foreach makefile,$(MAKEFILES_AFTER_$(PASS)),$(eval $(def_pass_makefile)))
928
929.NOTPARALLEL: pass_$(pass)_before pass_$(pass)_after
930.PHONY: pass_$(pass) pass_$(pass)_before pass_$(pass)_doit pass_$(pass)_after
931pass_$(pass): \
932 pass_$(pass)_before \
933 pass_$(pass)_doit \
934 pass_$(pass)_after
935
936endef
937
[76]938
[75]939## PASS: needed
940# This pass builds targets which are required for building the rest.
941pass_needed_doit: $(_NEEDEDS)
942pass := needed
943PASS := NEEDED
944$(eval $(def_pass))
945
946## PASS: libraries
947# This pass builds library targets.
948pass_libraries_doit: $(_LIBS) $(_IMPORT_LIBS) $(_OTHER_LIBRARIES)
949pass := libraries
950PASS := LIBRARIES
951$(eval $(def_pass))
952
953## PASS: binaries
[83]954# This pass builds binary targets, i.e. programs, dlls, system modules and stuff.
955pass_binaries_doit: $(_DLLS) $(_EXES) $(_SYSMODS) $(_OTHER_BINARIES)
[75]956pass := binaries
957PASS := BINARIES
958$(eval $(def_pass))
959
960## PASS: others
[83]961# This pass builds other targets.
[75]962pass_others_doit: $(_OTHERS)
963pass := others
964PASS := OTHERS
965$(eval $(def_pass))
966
967## PASS: publish
968# This pass installs the built entities to a sandbox area.
969pass_publish_doit: publish
970publish::
971pass := publish
972PASS := PUBLISH
[76]973# $(sort).. not nice.
[75]974SUBDIRS_PUBLISH ?= $(sort $(SUBDIRS) $(SUBDIRS_LIBRARIES) $(SUBDIRS_BINARIES) $(SUBDIRS_OTHERS))
975SUBDIRS_AFTER_PUBLISH ?= $(sort $(SUBDIRS_AFTER) $(SUBDIRS_AFTER_LIBRARIES) $(SUBDIRS_AFTER_BINARIES) $(SUBDIRS_AFTER_OTHERS))
976MAKEFILES_BEFORE_PUBLISH?= $(sort $(MAKEFILES_BEFORE) $(MAKEFILES_BEFORE_LIBRARIES) $(MAKEFILES_BEFORE_BINARIES) $(MAKEFILES_BEFORE_OTHERS))
977MAKEFILES_AFTER_PUBLISH ?= $(sort $(MAKEFILES_AFTER) $(MAKEFILES_AFTER_LIBRARIES) $(MAKEFILES_AFTER_BINARIES) $(MAKEFILES_AFTER_OTHERS))
978$(eval $(def_pass))
979
980## PASS: packing
981# This pass processes custom packing rules.
982pass_packing_doit: packing
983packing::
984pass := packing
985PASS := PACKING
986$(eval $(def_pass))
987
988## PASS: clean
989# This pass removes all generated files.
990pass_clean_doit:
991 $(RM) -f $(_OUT_FILES) $(_OBJS) $(_DEPFILES) $(_DIRFILES)
992pass := clean
993PASS := CLEAN
994$(eval $(def_pass))
995clean: pass_clean
996
997## PASS: nothing
998# This pass just walks the tree.
999pass_nothing_doit:
1000 $(call MSG_L1,Did nothing in $(CURDIR))
1001pass := nothing
1002PASS := NOTHING
1003$(eval $(def_pass))
1004nothing: pass_nothing
1005
[78]1006
1007
[75]1008#
1009# THE MAIN RULES
1010#
1011all_recursive: $(foreach pass,$(PASSES),pass_$(pass))
1012
[78]1013rebuild: clean all_recursive
1014
1015
[75]1016# misc shortcuts.
1017target: needed libraries binaries others
1018objects: $(_OBJS)
1019programs: $(_EXES)
1020dlls: $(_DLLS)
[83]1021sysmods: $(_SYSMODS)
[75]1022
1023
[72]1024# end-of-file-content
1025__footer_kmk__ := 1
1026endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.