1 | # $Id: GCC3.kmk 300 2005-06-23 18:36:41Z bird $
|
---|
2 | ## @file
|
---|
3 | #
|
---|
4 | # kBuild Tool Config - Generic GCC.
|
---|
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 |
|
---|
27 | TOOL_GCC3 := Generic GCC v3
|
---|
28 |
|
---|
29 | TOOL_GCC3_CC := gcc$(HOSTSUFF_EXE)
|
---|
30 | TOOL_GCC3_COBJSUFF := .o
|
---|
31 | TOOL_GCC3_CFLAGS := -g
|
---|
32 | TOOL_GCC3_CFLAGS.debug := -O0
|
---|
33 | TOOL_GCC3_CFLAGS.release := -O2
|
---|
34 | TOOL_GCC3_CFLAGS.profile := -O2 #-pg
|
---|
35 | TOOL_GCC3_CINCS :=
|
---|
36 | TOOL_GCC3_CDEFS :=
|
---|
37 |
|
---|
38 | TOOL_GCC3_CXX := g++$(HOSTSUFF_EXE)
|
---|
39 | TOOL_GCC3_CXXOBJSUFF := .o
|
---|
40 | TOOL_GCC3_CXXOBJSUFF := .o
|
---|
41 | TOOL_GCC3_CXXFLAGS := -g
|
---|
42 | TOOL_GCC3_CXXFLAGS.debug := -O0
|
---|
43 | TOOL_GCC3_CXXFLAGS.release := -O2
|
---|
44 | TOOL_GCC3_CXXFLAGS.profile := -O2 #-pg
|
---|
45 | TOOL_GCC3_CXXINCS :=
|
---|
46 | TOOL_GCC3_CXXDEFS :=
|
---|
47 |
|
---|
48 | TOOL_GCC3_AS := as$(HOSTSUFF_EXE)
|
---|
49 | TOOL_GCC3_ASOBJSUFF := .o
|
---|
50 |
|
---|
51 | TOOL_GCC3_AR := ar$(HOSTSUFF_EXE)
|
---|
52 | TOOL_GCC3_ARFLAGS := cr
|
---|
53 | TOOL_GCC3_ARLIBSUFF := .a
|
---|
54 |
|
---|
55 | TOOL_GCC3_LD := g++$(HOSTSUFF_EXE)
|
---|
56 | TOOL_GCC3_LD_SYSMOD := ld$(HOSTSUFF_EXE)
|
---|
57 | TOOL_GCC3_LDFLAGS :=
|
---|
58 | TOOL_GCC3_LDFLAGS.debug := -g
|
---|
59 | TOOL_GCC3_LDFLAGS.release := -s
|
---|
60 | ifndef TOOL_GCC3_LDFLAGS.$(BUILD_TARGET)
|
---|
61 | TOOL_GCC3_LDFLAGS.dll := -shared
|
---|
62 | else
|
---|
63 | TOOL_GCC3_LDFLAGS.dll := $(TOOL_GCC3_LDFLAGS.$(BUILD_TARGET))
|
---|
64 | endif
|
---|
65 | TOOL_GCC3_LDFLAGS.sysmod := -r
|
---|
66 | TOOL_GCC3_LD_SONAME = -Wl,-soname=$(firstword $($(1)_SONAME.$(BUILD_TARGET).$(BUILD_TYPE)) $($(1)_SONAME.$(BUILD_TARGET)) $($(1)_SONAME.$(BUILD_TYPE)) $($(1)_SONAME) $(notdir $(2)))
|
---|
67 | ifeq ($(BUILD_TARGET),os2)
|
---|
68 | TOOL_GCC3_LD_MAP = -Zmap=$(1)
|
---|
69 | else
|
---|
70 | TOOL_GCC3_LD_MAP = -Wl,-Map -Wl,$(1) -Wl,--cref
|
---|
71 | endif
|
---|
72 | ifeq ($(BUILD_TARGET),os2)
|
---|
73 | TOOL_GCC3_LD_SYSMOD_MAP = -Zmap=$(1)
|
---|
74 | else
|
---|
75 | TOOL_GCC3_LD_SYSMOD_MAP = -Map $(1) --cref
|
---|
76 | endif
|
---|
77 | ifdef SLKRUNS
|
---|
78 | TOOL_GCC3_CC += -fmessage-length=0
|
---|
79 | TOOL_GCC3_CXX += -fmessage-length=0
|
---|
80 | endif
|
---|
81 |
|
---|
82 |
|
---|
83 | ## Compile C source.
|
---|
84 | # @param $(target) Normalized main target name.
|
---|
85 | # @param $(source) Source filename (relative).
|
---|
86 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
87 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
88 | # @param $(flags) Flags.
|
---|
89 | # @param $(defs) Definitions. No -D or something.
|
---|
90 | # @param $(incs) Includes. No -I or something.
|
---|
91 | # @param $(dirdep) Directory creation dependency.
|
---|
92 | # @param $(deps) Other dependencies.
|
---|
93 | #
|
---|
94 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
95 | # @param $(objsuff) Object suffix.
|
---|
96 | define TOOL_GCC3_COMPILE_C
|
---|
97 | #$ (warning dbg: TOOL_GCC3_COMPILE_C: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
|
---|
98 | $(obj): $(deps) $(source) | $(dirdep)
|
---|
99 | $(call MSG_L2,Compiling $$@ using GCC3)
|
---|
100 | $(TOOL_GCC3_CC) -c\
|
---|
101 | $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
|
---|
102 | -Wp,-MD,$(dep) -Wp,-MT,$$@ \
|
---|
103 | -o $$@\
|
---|
104 | $(call ABSPATH,$(source))
|
---|
105 |
|
---|
106 | endef
|
---|
107 |
|
---|
108 |
|
---|
109 | ## Compile C++ source.
|
---|
110 | # @param $(target) Normalized main target name.
|
---|
111 | # @param $(source) Source filename (relative).
|
---|
112 | # @param $(obj) Object file name. This shall be (re)created by the compilation.
|
---|
113 | # @param $(dep) Dependcy file. This shall be (re)created by the compilation.
|
---|
114 | # @param $(flags) Flags.
|
---|
115 | # @param $(defs) Definitions. No -D or something.
|
---|
116 | # @param $(incs) Includes. No -I or something.
|
---|
117 | # @param $(dirdep) Directory creation dependency.
|
---|
118 | # @param $(deps) Other dependencies.
|
---|
119 | #
|
---|
120 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
121 | # @param $(objsuff) Object suffix.
|
---|
122 | define TOOL_GCC3_COMPILE_CXX
|
---|
123 | #$ (warning dbg: TOOL_GCC3_COMPILE_CXX: target=$(target) source=$(source) obj=$(obj) dep=$(dep) flags=$(flags) defs=$(defs) incs=$(incs) dirdep=$(dirdep) outbase=$(outbase) objsuff=$(objsuff))
|
---|
124 | $(obj): $(deps) $(source) | $(dirdep)
|
---|
125 | $(call MSG_L2,Compiling $$@ using GCC3)
|
---|
126 | $(TOOL_GCC3_CXX) -c\
|
---|
127 | $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
|
---|
128 | -Wp,-MD,$(dep) -Wp,-MT,$$@ \
|
---|
129 | -o $$@\
|
---|
130 | $(call ABSPATH,$(source))
|
---|
131 |
|
---|
132 | endef
|
---|
133 |
|
---|
134 |
|
---|
135 | ## Link library
|
---|
136 | # @param $(target) Normalized main target name.
|
---|
137 | # @param $(lib) Library name.
|
---|
138 | # @param $(objs) Object files to put in the library.
|
---|
139 | # @param $(flags) Flags.
|
---|
140 | # @param $(dirdep) Directory creation dependency.
|
---|
141 | # @param $(deps) Other dependencies.
|
---|
142 | # @param $(othersrc) Unhandled sources.
|
---|
143 | #
|
---|
144 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
145 |
|
---|
146 | define TOOL_GCC3_LINK_LIBRARY_ADDMOD
|
---|
147 |
|
---|
148 | echo "ADDMOD $(o)" >> $$@.ar-script
|
---|
149 | endef
|
---|
150 |
|
---|
151 | define TOOL_GCC3_LINK_LIBRARY_EXPAND_LIB
|
---|
152 |
|
---|
153 | $(MKDIR) -p $(dir $(outbase))ar.extract/$(notdir $(srclib))
|
---|
154 | cd $(dir $(outbase))ar.extract/$(notdir $(srclib)) && $(TOOL_GCC3_AR) x $(srclib)
|
---|
155 | for o in `$(TOOL_GCC3_AR) t $(srclib)`; do echo "ADDMOD $(dir $(outbase))ar.extract/$(notdir $(srclib))/$$$${o}" >> $$@.ar-script; done
|
---|
156 | endef
|
---|
157 |
|
---|
158 | define TOOL_GCC3_LINK_LIBRARY
|
---|
159 | #$ (warning dbg: TOOL_GCC3_LINK_LIBRARY: target=$(target) lib=$(lib) objs=$(objs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
|
---|
160 | $(lib): $(deps) $(objs) $(filter %.a %.lib,$(othersrc)) | $(dirdep)
|
---|
161 | $(call MSG_L1,Creating Library $$@)
|
---|
162 | $(RM) -f $$@
|
---|
163 | ifneq ($(strip $(filter %.a %.lib,$(othersrc))),)
|
---|
164 | echo "CREATE $$@" > $$@.ar-script
|
---|
165 | $(foreach o, $(objs),$(TOOL_GCC3_LINK_LIBRARY_ADDMOD))
|
---|
166 | $(foreach srclib, $(filter %.a %.lib,$(othersrc)),$(TOOL_GCC3_LINK_LIBRARY_EXPAND_LIB))
|
---|
167 | echo "SAVE" >> $$@.ar-script
|
---|
168 | echo "END" >> $$@.ar-script
|
---|
169 | $(TOOL_GCC3_AR) -M < $$@.ar-script
|
---|
170 | $(RM) -Rf "$(dir $(outbase))ar.extract/"
|
---|
171 | else
|
---|
172 | $(TOOL_GCC3_AR) $(flags) $$@ $(objs)
|
---|
173 | endif
|
---|
174 |
|
---|
175 | endef
|
---|
176 |
|
---|
177 |
|
---|
178 | ## Link program
|
---|
179 | # @param $(target) Normalized main target name.
|
---|
180 | # @param $(exe) Program name.
|
---|
181 | # @param $(objs) Object files to link together.
|
---|
182 | # @param $(libs) Libraries to search.
|
---|
183 | # @param $(libpath) Library search paths.
|
---|
184 | # @param $(flags) Flags.
|
---|
185 | # @param $(dirdep) Directory creation dependency.
|
---|
186 | # @param $(deps) Other dependencies.
|
---|
187 | # @param $(othersrc) Unhandled sources.
|
---|
188 | # @param $(custom_pre) Custom step invoked before linking.
|
---|
189 | # @param $(custom_post) Custom step invoked after linking.
|
---|
190 | #
|
---|
191 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
192 | define TOOL_GCC3_LINK_PROGRAM
|
---|
193 | #$ (warning dbg: TOOL_GCC3_LINK_PROGRAM: target=$(target) exe=$(exe) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
|
---|
194 | $(exe): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
|
---|
195 | $(call MSG_L1,Creating Program $$@)
|
---|
196 | ifneq ($(custom_pre),)
|
---|
197 | $(eval $(custom_pre))
|
---|
198 | endif
|
---|
199 | $(RM) -f $$@
|
---|
200 | $(TOOL_GCC3_LD) $(flags) -o $$@ $(objs) \
|
---|
201 | $(foreach p,$(libpath), -L$(p)) \
|
---|
202 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib))) \
|
---|
203 | $(call TOOL_GCC3_LD_MAP,$(outbase).map)
|
---|
204 | ifneq ($(custom_post),)
|
---|
205 | $(eval $(custom_post))
|
---|
206 | endif
|
---|
207 | _OUT_FILES += $(outbase).map
|
---|
208 |
|
---|
209 | endef
|
---|
210 |
|
---|
211 |
|
---|
212 | ## Link DLL
|
---|
213 | # @param $(target) Normalized main target name.
|
---|
214 | # @param $(dll) Program name.
|
---|
215 | # @param $(objs) Object files to link together.
|
---|
216 | # @param $(libs) Libraries to search.
|
---|
217 | # @param $(libpath) Library search paths.
|
---|
218 | # @param $(flags) Flags.
|
---|
219 | # @param $(dirdep) Directory creation dependency.
|
---|
220 | # @param $(deps) Other dependencies.
|
---|
221 | # @param $(othersrc) Unhandled sources.
|
---|
222 | # @param $(custom_pre) Custom step invoked before linking.
|
---|
223 | # @param $(custom_post) Custom step invoked after linking.
|
---|
224 | #
|
---|
225 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
226 | define TOOL_GCC3_LINK_DLL
|
---|
227 | #$ (warning dbg: TOOL_GCC3_LINK_PROGRAM: target=$(target) dll=$(dll) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) deffile=$(deffile) outbase=$(outbase))
|
---|
228 | $(dll): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
|
---|
229 | $(call MSG_L1,Creating Program $$@)
|
---|
230 | ifneq ($(custom_pre),)
|
---|
231 | $(eval $(custom_pre))
|
---|
232 | endif
|
---|
233 | $(RM) -f $$@
|
---|
234 | $(TOOL_GCC3_LD) $(TOOL_GCC3_LDFLAGS.dll) $(flags) -o $$@ \
|
---|
235 | $(if $(filter linux, $(BUILD_TARGET)),$(call TOOL_GCC3_LD_SONAME,$(target),$(dll))) \
|
---|
236 | $(objs) \
|
---|
237 | $(foreach p,$(libpath), -L$(p)) \
|
---|
238 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib))) \
|
---|
239 | $(call TOOL_GCC3_LD_MAP,$(outbase).map)
|
---|
240 | ifneq ($(custom_post),)
|
---|
241 | $(eval $(custom_post))
|
---|
242 | endif
|
---|
243 | _OUT_FILES += $(outbase).map
|
---|
244 |
|
---|
245 | endef
|
---|
246 |
|
---|
247 | ## Link system module (windows aka driver, linux aka kernel module)
|
---|
248 | # @param $(target) Normalized main target name.
|
---|
249 | # @param $(sys) System module name.
|
---|
250 | # @param $(objs) Object files to link together.
|
---|
251 | # @param $(libs) Libraries to search.
|
---|
252 | # @param $(libpath) Library search paths.
|
---|
253 | # @param $(flags) Flags.
|
---|
254 | # @param $(dirdep) Directory creation dependency.
|
---|
255 | # @param $(deps) Other dependencies.
|
---|
256 | # @param $(othersrc) Unhandled sources.
|
---|
257 | # @param $(custom_pre) Custom step invoked before linking.
|
---|
258 | # @param $(custom_post) Custom step invoked after linking.
|
---|
259 | #
|
---|
260 | # @param $(outbase) Output basename (full). Use this for list files and such.
|
---|
261 | define TOOL_GCC3_LINK_SYSMOD
|
---|
262 | #$ (warning dbg: TOOL_GCC3_LINK_SYSMOD: target=$(target) sys=$(sys) objs=$(objs) libs=$(libs) deps=$(deps) flags=$(flags) dirdep=$(dirdep) othersrc=$(othersrc) outbase=$(outbase))
|
---|
263 | $(sys): $(deps) $(objs) $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib))) | $(dirdep)
|
---|
264 | $(call MSG_L1,Creating Program $$@)
|
---|
265 | ifneq ($(custom_pre),)
|
---|
266 | $(eval $(custom_pre))
|
---|
267 | endif
|
---|
268 | $(RM) -f $$@
|
---|
269 | $(TOOL_GCC3_LD_SYSMOD) $(TOOL_GCC3_LDFLAGS.sysmod) $(flags) -o $$@ $(objs) \
|
---|
270 | $(foreach p,$(libpath), -L$(p)) \
|
---|
271 | $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(basename $(lib))), $(lib))) \
|
---|
272 | $(call TOOL_GCC3_LD_SYSMOD_MAP,$(outbase).map)
|
---|
273 | ifneq ($(custom_post),)
|
---|
274 | $(eval $(custom_post))
|
---|
275 | endif
|
---|
276 | _OUT_FILES += $(outbase).map
|
---|
277 |
|
---|
278 | endef
|
---|
279 |
|
---|