source: trunk/kBuild/footer.kmk@ 73

Last change on this file since 73 was 73, 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: 9.2 KB
Line 
1# $Id: footer.kmk 73 2004-05-31 01:11:52Z 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.
32# (Some of these need initialization before including definitions using them.)
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
51# misc
52type :=
53
54
55#
56# Basic macros
57#
58
59## Figure out the tool for a source
60# @param $1 source file
61# @param $2 normalized main target
62_SOURCE_TOOL = $(firstword $($1_$2_TOOL) $($1_TOOL) $($2_TOOL) )
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#
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
95
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
104ifndef $1_$(prop)
105ifdef $(prop)
106$1_$(prop) := $($(prop))
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
181#
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
202#
203# Object processing.
204#
205
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}
210#
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 :=\
217 $($(target)_$(source)_$(type)DEFS)\
218 $($(target)_$(source)_DEFS)\
219 $($(source)_$(type)DEFS)\
220 $($(source)_DEFS)\
221 $($(target)_$(type)DEFS)\
222 $($(target)_DEFS)\
223 $(DEFS)\
224 $(TOOL_$(tool)_$(type)DEFS)\
225 )
226$(eval incs :=\
227 $($(target)_$(source)_$(type)INCS)\
228 $($(target)_$(source)_INCS)\
229 $($(source)_$(type)INCS)\
230 $($(source)_INCS)\
231 $($(target)_$(type)INCS)\
232 $($(target)_INCS)\
233 $(INCS)\
234 $(TOOL_$(tool)_$(type)INCS)\
235 )
236$(eval flags :=\
237 $(TOOL_$(tool)_$(type)FLAGS)\
238 $(TOOL_$(tool)_$(type)FLAGS.$(BUILD_TYPE))\
239 $($(type)FLAGS)\
240 $($(type)FLAGS.$(BUILD_TYPE))\
241 $($(target)_$(type)FLAGS)\
242 $($(target)_$(type)FLAGS.$(BUILD_TYPE))\
243 $($(source)_$(type)FLAGS)\
244 $($(source)_$(type)FLAGS.$(BUILD_TYPE))\
245 $($(target)_$(source)_$(type)FLAGS)\
246 $($(target)_$(source)_$(type)FLAGS.$(BUILD_TYPE))\
247 )
248$(eval outbase := $(call _OBJECT_BASE,$(source),$(target)))
249$(eval dirdep := $(dir $(outbase)).dir_created)
250$(eval objsuff := $(firstword $($(target)_$(source)_OBJSUFF) $($(source)_OBJSUFF) $($(target)_OBJSUFF) $(TOOL_$(tool)_$(type)OBJSUFF) $(SUFF_OBJ)))
251$(eval obj := $(outbase)$(objsuff))
252$(eval depfile := $(outbase)$(SUFF_DEP))
253
254#$ (warning dbg: target=$(target) source=$(source) tool=$(tool) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
255$(eval $(TOOL_$(tool)_COMPILE_$(type)))
256
257$(eval _OBJS_$(target) += $(obj))
258$(eval _DEPFILES += $(dep))
259
260endef
261
262## Generic macro for processing all target sources.
263# @param $target Normalized target name.
264define def_target_sources
265#$ (warning def_target_sources)
266# C sources
267$(foreach type,C,$(foreach source, $(filter %.c, $($(target)_SOURCES))\
268 ,$(eval $(def_target_source_c_cpp_asm)) ))
269
270# C++ sources
271$(foreach type,CXX,$(foreach source, $(filter %.cpp, $($(target)_SOURCES)) $(filter %.cxx, $($(target)_SOURCES)) $(filter %.cc, $($(target)_SOURCES))\
272 ,$(eval $(def_target_source_c_cpp_asm)) ))
273
274# ASM sources
275$(foreach type,AS,$(foreach source, $(filter %.asm, $($(target)_SOURCES)) $(filter %.s, $($(target)_SOURCES)) $(filter %.S, $($(target)_SOURCES))\
276 ,$(eval $(def_target_source_c_cpp_asm)) ))
277endef
278
279
280#
281# LIBRARIES
282#
283
284## Library (one).
285# @param $(lib) Library name
286define def_lib
287# source -> object
288$(eval $(def_target_sources))
289
290# library
291$(eval tool := $(firstword $($(target)_TOOL) $(TOOL)))
292$(eval flags := $($(target)_ARFLAGS) $(ARFLAGS) $(TOOL_$(tool)_ARFLAGS))
293$(eval libsuff := $(firstword $($(target)_LIBSUFF) $($(target)_LIBSUFF) $(TOOL_$(tool)_ARLIBSUFF) $(SUFF_LIB)))
294## @todo prefix
295$(eval outbase := $(call _TARGET_BASE,$(target),$(target)))
296$(eval lib := $(outbase)$(libsuff))
297$(eval objs = $(_OBJS_$(target)))
298$(eval dirdep := $(dir $(lib)).dir_created)
299## @todo fix dependencies
300$(eval deps := )
301
302$(eval $(TOOL_$(tool)_LINK_LIBRARY))
303
304_OBJS += $(_OBJS_$(target))
305_LIBS += $(lib)
306endef
307
308# Process libraries
309$(foreach target, $(LIBRARIES), $(eval $(def_lib)))
310
311
312
313#
314# PROGRAMS
315#
316
317
318
319#
320# DLLS
321#
322
323
324
325#
326# DRIVERS
327#
328
329
330
331#
332# OTHERS
333#
334
335
336
337#
338# DOCS
339#
340
341
342#
343# Directories.
344#
345_DIRFILES := $(sort $(addsuffix /.dir_created,$(_DIRS)) $(addsuffix .dir_created,$(dir $(_OBJS) $(_LIBS) $(_EXES) $(_DLLS))))
346
347define def_createdir
348$(dirfile):
349 $(call MSG_L1,Creating directory $$(@D))
350 $(MKDIR) -p $$(@D)
351 @echo dir_created > $$@
352endef
353
354$(foreach dirfile,$(_DIRFILES),$(eval $(def_createdir)))
355
356#
357# THE MAIN RULES
358#
359all_recursive:
360
361
362objs: $(_OBJS)
363 echo "dbg: _OBJS = $(_OBJS)"
364
365libs: $(_LIBS)
366 echo "dbg: _LIBS = $(_LIBS)"
367
368
369# end-of-file-content
370__footer_kmk__ := 1
371endif # __footer_kmk__
Note: See TracBrowser for help on using the repository browser.