source: trunk/kBuild/tools/GCC3.kmk@ 216

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

No map for sys.

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