source: trunk/kBuild/footer.kmk@ 74

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

..

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.3 KB
RevLine 
[72]1# $Id: footer.kmk 74 2004-05-31 02:19:05Z 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.
36ALL_TARGETS := $(LIBRARIES) $(PROGRAMS) $(DLLS) $(DRIVERS) $(OTHERS)
37
38# all of a type
39_OBJS :=
40_LIBS :=
41_DLLS :=
42_EXES :=
43_DIRS :=
44
45# all objs of a specific target
46define def_objs_var
47_OBJS_$1 :=
48endef
49$(foreach target, $(ALL_TARGETS), $(eval _OBJS_$(target) := ))
50
[73]51# misc
52type :=
53
54
[72]55#
[73]56# Basic macros
57#
58
59## Figure out the tool for a source
60# @param $1 source file
61# @param $2 normalized main target
[74]62_SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL) $(TOOL))
[73]63
64## Figure out where to put object files.
65# @param $1 source file
66# @param $2 normalized main target
67_OBJECT_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
68
69## Figure out where to put object files.
70# @param $1 real target name.
71# @param $2 normalized main target
72_TARGET_BASE = $(PATH_TARGET)/$(2)/$(basename $(1))
73
74
75#
[72]76# Include templates
77#
78_TEMPLATES := $(TEMPLATE)
79define def_templates
80ifdef $(target)_TEMPLATE
81_TEMPLATES += $($(target)_TEMPLATE)
82endif
83endef
84$(foreach target, $(ALL_TARGETS), $(eval $(def_templates)))
85_TEMPLATES := $(sort $(_TEMPLATES))
86# $ (warning dbg: _TEMPLATES=$(_TEMPLATES))
87
88define def_templates_include
89ifndef TEMPLATE_$(template)
90include $(firstword $(wildcard $(PATH_KBUILD)/templates/$(template).kmk))
91endif
92endef
93$(foreach template, $(_TEMPLATES), $(eval $(def_templates)))
94
[74]95
[72]96#
97# Common Inheritance
98#
99
100## Inherit defaults property
101# @param $(prop) Property name
102# @param $(target) Target name.
103define def_inherit_defaults_one
[74]104ifndef $(target)_$(prop)
[72]105ifdef $(prop)
[74]106$(target)_$(prop) := $($(prop))
[72]107endif
108endif
109endef
110
111## Inherit default properties for one target.
112# A bit tricky this one, but it depends a bit on whether or not TEMPLATE
113# is inherited from the default properties.
114# @param $(target) Target name
115define def_inherit_defaults
116ifdef $(target)_TEMPLATE
117ifndef TEMPLATE_$($(target)_TEMPLATE)_TOOL
118$(foreach prop, TOOL, $(eval $(def_inherit_defaults_one)))
119endif
120ifndef TEMPLATE_$($(target)_TEMPLATE)_SDKS
121$(foreach prop, SDKS, $(eval $(def_inherit_defaults_one)))
122endif
123else
124$(foreach prop, TEMPLATE TOOL SDKS, $(eval $(def_inherit_defaults_one)))
125endif
126endef
127# Inherit default properties.
128$(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_defaults)))
129
130
131## Inherit one template property.
132# @param $(prop) Property name
133# @param $(target) Target name
134define def_inherit_template_one
135ifndef $(target)_$(prop)
136ifdef TEMPLATE_$($(target)_TEMPLATE)_$(prop)
137$(target)_$(prop) := $(TEMPLATE_$($(target)_TEMPLATE)_$(prop))
138endif
139endif
140endef
141
142## Inherit template properties for on target.
143# @param $(target) Target name.
144define def_inherit_template
145$(foreach prop,TOOL SDKS DEFS INCS COPTS CFLAGS CDEFS CINCS CXXOPTS CXXFLAGS CXXDEFS CXXINCS ASOPTS ASFLAGS ASDEFS ASINCS, \
146 $(eval $(def_inherit_template_one)))
147endef
148# Inherit template properties
149$(foreach target, $(ALL_TARGETS), $(eval $(def_inherit_template)))
150
151
152
153#
154# Include tools
155#
156_TOOLS := $(TOOL)
157define def_tools_target_source
158#$ (warning dbg: src=$(source))
159$(foreach tool,$($(source)_TOOL) $($(target)_$(source)_TOOL),\
160 $(eval _TOOLS += $(tool)))
161endef
162define def_tools_target
163#$ (warning dbg: trg=$(target))
164$(foreach tool, $($(target)_TOOL), $(eval _TOOLS += $(tool)))
165$(foreach source, $($(target)_SOURCES), $(eval $(def_tools_target_source)))
166endef
167$(foreach target, $(ALL_TARGETS), $(eval $(def_tools_target)))
168_TOOLS := $(sort $(_TOOLS))
169#$ (warning dbg: _TOOLS=$(_TOOLS))
170
171define def_tools_include
172ifndef TOOL_$(tool)
173include $(firstword $(wildcard $(PATH_KBUILD)/tools/$(tool).kmk))
174endif
175endef
176$(foreach tool, $(_TOOLS), $(eval $(def_tools_include)))
177
178
179#
180# Include SDKs
[73]181#
[72]182_SDKS := $(SDKS)
183define def_sdks_target_source
184$(foreach sdk, $($(source)_SDKS) $($(target)_$(source)_SDKS), \
185 $(eval _SDKS += $(sdk)))
186endef
187define def_sdks_target
188$(foreach sdk, $($(target)_SDKS), $(eval _SDKS += $(sdk)))
189$(foreach source, $($(target)_SOURCES), $(eval $(def_sdks_target_source)))
190endef
191$(foreach target, $(ALL_TARGETS), $(eval $(def_sdks_target)))
192_SDKS := $(sort $(_SDKS))
193#$ (warning dbg: _SDKS=$(_SDKS))
194
195define def_sdks_include
196ifndef SDK_$(sdk)
197include $(firstword $(wildcard $(PATH_KBUILD)/sdks/$(sdk).kmk))
198endif
199endef
200$(foreach sdk, $(_SDKS), $(eval $(def_sdk)))
201
[73]202#
203# Object processing.
204#
[72]205
[73]206## Generic macro for processing C, C++ and Assembly sources.
207# @param $(target) Normalized target name.
208# @param $(source) Source file name.
209# @param $(type) Source type. {C,CXX,AS}
[72]210#
[73]211# @remark I've no clue why I've to $(eval ..) everything in this define. MAKE bug?
212define def_target_source_c_cpp_asm
213#$ (warning dbg: def_target_source_c_cpp_asm: source=$(source) target=$(target) type=$(type))
214
215$(eval tool:=$(call _SOURCE_TOOL,$(source),$(target)))
216$(eval defs :=\
[74]217 $(TOOL_$(tool)_$(type)DEFS)\
218 $(TOOL_$(tool)_$(type)DEFS.$(BUILD_TYPE))\
219 $(DEFS)\
220 $(DEFS.$(BUILD_TYPE))\
221 $($(target)_DEFS)\
222 $($(target)_DEFS.$(BUILD_TYPE))\
223 $($(target)_DEFS.$(BUILD_TARGET))\
224 $($(source)_DEFS)\
225 $($(source)_DEFS.$(BUILD_TYPE))\
226 $($(source)_DEFS.$(BUILD_TARGET))\
[73]227 $($(source)_$(type)DEFS)\
[74]228 $($(source)_$(type)DEFS.$(BUILD_TYPE))\
229 $($(source)_$(type)DEFS.$(BUILD_TARGET))\
[73]230 $($(target)_$(type)DEFS)\
[74]231 $($(target)_$(type)DEFS.$(BUILD_TYPE))\
232 $($(target)_$(type)DEFS.$(BUILD_TARGET))\
233 $($(target)_$(source)_DEFS)\
234 $($(target)_$(source)_DEFS.$(BUILD_TYPE))\
235 $($(target)_$(source)_DEFS.$(BUILD_TARGET))\
236 $($(target)_$(source)_$(type)DEFS)\
237 $($(target)_$(source)_$(type)DEFS.$(BUILD_TYPE))\
238 $($(target)_$(source)_$(type)DEFS.$(BUILD_TARGET))\
[73]239 )
240$(eval incs :=\
[74]241 $($(target)_$(source)_$(type)INCS.$(BUILD_TARGET))\
242 $($(target)_$(source)_$(type)INCS.$(BUILD_TYPE))\
[73]243 $($(target)_$(source)_$(type)INCS)\
[74]244 $($(target)_$(source)_INCS.$(BUILD_TARGET))\
245 $($(target)_$(source)_INCS.$(BUILD_TYPE))\
[73]246 $($(target)_$(source)_INCS)\
[74]247 $($(source)_$(type)INCS.$(BUILD_TARGET))\
248 $($(source)_$(type)INCS.$(BUILD_TYPE))\
[73]249 $($(source)_$(type)INCS)\
[74]250 $($(source)_INCS.$(BUILD_TARGET))\
251 $($(source)_INCS.$(BUILD_TYPE))\
[73]252 $($(source)_INCS)\
[74]253 $($(target)_$(type)INCS.$(BUILD_TARGET))\
254 $($(target)_$(type)INCS.$(BUILD_TYPE))\
[73]255 $($(target)_$(type)INCS)\
[74]256 $($(target)_INCS.$(BUILD_TARGET))\
257 $($(target)_INCS.$(BUILD_TYPE))\
[73]258 $($(target)_INCS)\
[74]259 $(INCS.$(BUILD_TARGET))\
260 $(INCS.$(BUILD_TYPE))\
[73]261 $(INCS)\
[74]262 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TARGET))\
263 $(TOOL_$(tool)_$(type)INCS.$(BUILD_TYPE))\
[73]264 $(TOOL_$(tool)_$(type)INCS)\
265 )
266$(eval flags :=\
267 $(TOOL_$(tool)_$(type)FLAGS)\
268 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
[74]269 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TARGET))\
[73]270 $($(type)FLAGS)\
271 $($(type)FLAGS.$(BUILD_TYPE))\
[74]272 $($(type)FLAGS.$(BUILD_TARGET))\
[73]273 $($(target)_$(type)FLAGS)\
274 $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
[74]275 $($(target)_$(type)FLAGS.$(BUILD_TARGET))\
[73]276 $($(source)_$(type)FLAGS)\
277 $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
[74]278 $($(source)_$(type)FLAGS.$(BUILD_TARGET))\
[73]279 $($(target)_$(source)_$(type)FLAGS)\
280 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
[74]281 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TARGET))\
[73]282 )
283$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
284$(eval dirdep := $(dir $(outbase)).dir_created)
[74]285$(eval objsuff := $(firstword \
286 $($(target)_$(source)_OBJSUFF.$(BUILD_TARGET))\
287 $($(target)_$(source)_OBJSUFF)\
288 $($(source)_OBJSUFF.$(BUILD_TARGET))\
289 $($(source)_OBJSUFF)\
290 $($(target)_OBJSUFF.$(BUILD_TARGET))\
291 $($(target)_OBJSUFF)\
292 $(TOOL_$(tool)_$(type)OBJSUFF.$(BUILD_TARGET))\
293 $(TOOL_$(tool)_$(type)OBJSUFF)\
294 $(SUFF_OBJ)\
295 ))
[73]296$(eval obj := $(outbase)$(objsuff))
[74]297$(eval dep := $(outbase)$(SUFF_DEP))
[73]298
299#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
300$(eval $(TOOL_$(tool)_COMPILE_$(type)))
301
302$(eval _OBJS_$(target) += $(obj))
303$(eval _DEPFILES += $(dep))
304
305endef
306
307## Generic macro for processing all target sources.
[74]308# @param $(target) Normalized target name.
[73]309define def_target_sources
310#$ (warning def_target_sources)
311# C sources
312$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES))\
313 ,$(eval $(def_target_source_c_cpp_asm)) ))
314
315# C++ sources
316$(foreach type,CXX,$(foreach source, $(filter %.cpp, $($(target)_SOURCES)) $(filter %.cxx, $($(target)_SOURCES)) $(filter %.cc, $($(target)_SOURCES))\
317 ,$(eval $(def_target_source_c_cpp_asm)) ))
318
319# ASM sources
320$(foreach type,AS,$(foreach source, $(filter %.asm, $($(target)_SOURCES)) $(filter %.s, $($(target)_SOURCES)) $(filter %.S, $($(target)_SOURCES))\
321 ,$(eval $(def_target_source_c_cpp_asm)) ))
322endef
323
324
325#
[72]326# LIBRARIES
[73]327#
[72]328
329## Library (one).
[74]330# @param $(target) Normalized library (target) name.
[72]331define def_lib
[73]332# source -> object
333$(eval $(def_target_sources))
[72]334
[73]335# library
336$(eval tool := $(firstword $($(target)_TOOL) $(TOOL)))
[74]337$(eval flags :=\
338 $(TOOL_$(tool)_ARFLAGS)\
339 $(TOOL_$(tool)_ARFLAGS.$(BUILD_TYPE))\
340 $(ARFLAGS)\
341 $(ARFLAGS.$(BUILD_TYPE))\
342 $($(target)_ARFLAGS)\
343 $($(target)_ARFLAGS.$(BUILD_TYPE))\
344 )
345$(eval libsuff := $(firstword\
346 $($(target)_LIBSUFF.$(BUILD_TARGET))\
347 $($(target)_LIBSUFF)\
348 $(TOOL_$(tool)_ARLIBSUFF.$(BUILD_TARGET))\
349 $(TOOL_$(tool)_ARLIBSUFF)\
350 $(SUFF_LIB)\
351))
[73]352## @todo prefix
353$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
354$(eval lib := $(outbase)$(libsuff))
355$(eval objs = $(_OBJS_$(target)))
356$(eval dirdep := $(dir $(lib)).dir_created)
357## @todo fix dependencies
358$(eval deps := )
[72]359
[73]360$(eval $(TOOL_$(tool)_LINK_LIBRARY))
[72]361
[73]362_OBJS += $(_OBJS_$(target))
363_LIBS += $(lib)
[72]364endef
365
366# Process libraries
367$(foreach target, $(LIBRARIES), $(eval $(def_lib)))
368
369
370
371#
372# PROGRAMS
373#
374
[74]375## Program (one).
376# @param $(target) Normalized target (program) name.
377define def_program
378# source -> object
379$(eval $(def_target_sources))
[72]380
[74]381# library
382$(eval tool := $(firstword $($(target)_TOOL) $(TOOL)))
383$(eval flags :=\
384 $(TOOL_$(tool)_LDFLAGS)\
385 $(TOOL_$(tool)_LDFLAGS.$(BUILD_TYPE))\
386 $(LDFLAGS)\
387 $(LDFLAGS.$(BUILD_TYPE))\
388 $($(target)_LDFLAGS)\
389 $($(target)_LDFLAGS.$(BUILD_TYPE))\
390)
391$(eval exesuff := $(firstword $($(target)_EXESUFF) $($(target)_EXESUFF) $(TOOL_$(tool)_LDEXESUFF) $(SUFF_EXE)))
392$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
393$(eval exe := $(outbase)$(exesuff))
394$(eval objs = $(_OBJS_$(target)))
395$(eval libs :=\
396 $($(target)_LIBS.$(BUILD_TYPE))\
397 $($(target)_LIBS)\
398 $(LIBS.$(BUILD_TYPE))\
399 $(LIBS)\
400 $(TOOL_$(tool)_LIBS.$(BUILD_TYPE))\
401 $(TOOL_$(tool)_LIBS)\
402)
403$(eval libpath :=\
404 $($(target)_LIBPATH.$(BUILD_TYPE))\
405 $($(target)_LIBPATH)\
406 $(LIBPATH.$(BUILD_TYPE))\
407 $(LIBPATH)\
408 $(TOOL_$(tool)_LIBPATH.$(BUILD_TYPE))\
409 $(TOOL_$(tool)_LIBPATH)\
410)
411$(eval dirdep := $(dir $(exe)).dir_created)
412## @todo fix dependencies
413$(eval deps := )
414#
415$(eval deffile := $(strip $(firstword
416 $($(target)_DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
417 $($(target)_DEFFILE.$(BUILD_TARGET))\
418 $($(target)_DEFFILE.$(BUILD_TYPE))\
419 $($(target)_DEFFILE)\
420 $(DEFFILE.$(BUILD_TARGET).$(BUILD_TYPE))\
421 $(DEFFILE.$(BUILD_TARGET))\
422 $(DEFFILE.$(BUILD_TYPE))\
423 $(DEFFILE)\
424)))
425$(eval custom_pre := $(strip $(firstword
426 $($(target)_CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
427 $($(target)_CUSTOM_PRE.$(BUILD_TARGET))\
428 $($(target)_CUSTOM_PRE.$(BUILD_TYPE))\
429 $($(target)_CUSTOM_PRE)\
430 $(CUSTOM_PRE.$(BUILD_TARGET).$(BUILD_TYPE))\
431 $(CUSTOM_PRE.$(BUILD_TARGET))\
432 $(CUSTOM_PRE.$(BUILD_TYPE))\
433 $(CUSTOM_PRE)\
434)))
435$(eval custom_post := $(strip $(firstword
436 $($(target)_CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
437 $($(target)_CUSTOM_POST.$(BUILD_TARGET))\
438 $($(target)_CUSTOM_POST.$(BUILD_TYPE))\
439 $($(target)_CUSTOM_POST)\
440 $(CUSTOM_POST.$(BUILD_TARGET).$(BUILD_TYPE))\
441 $(CUSTOM_POST.$(BUILD_TARGET))\
442 $(CUSTOM_POST.$(BUILD_TYPE))\
443 $(CUSTOM_POST)\
444)))
[72]445
[74]446$(eval $(TOOL_$(tool)_LINK_PROGRAM))
447
448_OBJS += $(_OBJS_$(target))
449_EXES += $(exe)
450endef
451
452# Process libraries
453$(foreach target, $(PROGRAMS), $(eval $(def_program)))
454
455
456
[72]457#
458# DLLS
459#
460
461
462
463#
464# DRIVERS
465#
466
467
468
469#
470# OTHERS
471#
472
473
474
475#
476# DOCS
477#
478
479
480#
481# Directories.
482#
483_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS))))
484
485define def_createdir
486$(dirfile):
[73]487 $(call MSG_L1,Creating directory $$(@D))
[72]488 $(MKDIR) -p $$(@D)
[73]489 @echo dir_created > $$@
[72]490endef
491
492$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
493
494#
495# THE MAIN RULES
496#
497all_recursive:
498
499
[74]500objects: $(_OBJS)
[73]501 echo "dbg: _OBJS = $(_OBJS)"
[72]502
[74]503libraries: $(_LIBS)
[73]504 echo "dbg: _LIBS = $(_LIBS)"
[72]505
[74]506programs: $(_EXES)
507 echo "dbg: _EXES = $(_EXES)"
[73]508
[74]509
[72]510# end-of-file-content
511__footer_kmk__ := 1
512endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.