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

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

Oops.

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