source: trunk/kBuild/tools/GXX3.kmk@ 3391

Last change on this file since 3391 was 3391, checked in by bird, 5 years ago

tools/GXX*: Added _PREFIX/_SUFFIX properties to all g++ tools. Some minor fixes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.8 KB
Line 
1# $Id: GXX3.kmk 3391 2020-06-30 08:08:15Z bird $
2## @file
3# kBuild Tool Config - Generic GCC v3.2+ using the system GCC and Binutils, for building C++ code.
4#
5
6#
7# Copyright (c) 2004-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
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# As a special exception you are granted permission to include this file, via
27# the kmk include directive, as you wish without this in itself causing the
28# resulting makefile, program or whatever to be covered by the GPL license.
29# This exception does not however invalidate any other reasons why the makefile,
30# program, whatever should not be covered the GPL.
31#
32#
33
34TOOL_GXX3 := Generic GCC v3.2.x or later using the system GCC and Binutils, for building C++ code.
35
36# Tool Specific Properties
37ifndef TOOL_GXX3_PREFIX
38 TOOL_GXX3_PREFIX :=
39endif
40ifndef TOOL_GXX3_SUFFIX
41 TOOL_GXX3_SUFFIX := $(HOSTSUFF_EXE)
42endif
43TOOL_GXX3_CC ?= $(TOOL_GXX3_PREFIX)gcc$(TOOL_GXX3_SUFFIX)
44TOOL_GXX3_CXX ?= $(TOOL_GXX3_PREFIX)g++$(TOOL_GXX3_SUFFIX)
45TOOL_GXX3_PCH ?= $(TOOL_GXX3_CXX)
46TOOL_GXX3_AS ?= $(TOOL_GXX3_PREFIX)gcc$(TOOL_GXX3_SUFFIX)
47if1of ($(KBUILD_TARGET),solaris)
48 TOOL_GXX3_AR ?= $(TOOL_GXX3_PREFIX)gar$(TOOL_GXX3_SUFFIX)
49else
50 TOOL_GXX3_AR ?= $(TOOL_GXX3_PREFIX)ar$(TOOL_GXX3_SUFFIX)
51endif
52ifeq ($(KBUILD_TARGET),os2)
53 TOOL_GXX3_AR_IMP ?= $(TOOL_GXX3_PREFIX)emximp$(TOOL_GXX3_SUFFIX)
54else
55 TOOL_GXX3_AR_IMP ?= $(ECHO) not supported!
56endif
57TOOL_GXX3_LD ?= $(TOOL_GXX3_PREFIX)g++$(TOOL_GXX3_SUFFIX)
58TOOL_GXX3_LD_SYSMOD ?= $(TOOL_GXX3_PREFIX)ld$(TOOL_GXX3_SUFFIX)
59ifndef TOOL_GXX3_LDFLAGS.$(KBUILD_TARGET)
60 TOOL_GXX3_LDFLAGS.dll ?= -shared
61else
62 TOOL_GXX3_LDFLAGS.dll ?= $(TOOL_GXX3_LDFLAGS.$(KBUILD_TARGET))
63endif
64TOOL_GXX3_LDFLAGS.sysmod ?= -r
65TOOL_GXX3_LD_SONAME ?= -Wl,-soname=$(firstword $($(1)_SONAME.$(KBUILD_TARGET).$(KBUILD_TYPE)) $($(1)_SONAME.$(KBUILD_TARGET)) $($(1)_SONAME.$(KBUILD_TYPE)) $($(1)_SONAME) $(notdir $(2)))
66ifeq ($(KBUILD_TARGET),os2)
67 TOOL_GXX3_LD_MAP ?= -Zmap=$(1)
68 TOOL_GXX3_LD_SYSMOD_MAP ?= -Zmap=$(1)
69else
70 TOOL_GXX3_LD_MAP ?=
71 TOOL_GXX3_LD_SYSMOD_MAP ?=
72endif
73if1of ($(KBUILD_HOST), solaris)
74 TOOL_GXX3_OBJCOPY ?= $(TOOL_GXX3_PREFIX)gobjcopy$(TOOL_GXX3_SUFFIX)
75else
76 TOOL_GXX3_OBJCOPY ?= $(TOOL_GXX3_PREFIX)objcopy$(TOOL_GXX3_SUFFIX)
77endif
78
79ifdef SLKRUNS
80 TOOL_GXX3_CC += -fmessage-length=0
81 TOOL_GXX3_CXX += -fmessage-length=0
82 TOOL_GXX3_PCH += -fmessage-length=0
83endif
84
85# General Properties used by kBuild
86TOOL_GXX3_COBJSUFF ?= .o
87TOOL_GXX3_CFLAGS ?=
88TOOL_GXX3_CFLAGS.debug ?= -g
89TOOL_GXX3_CFLAGS.profile ?= -O2 #-g -pg
90TOOL_GXX3_CFLAGS.release ?= -O2
91TOOL_GXX3_CINCS ?=
92TOOL_GXX3_CDEFS ?=
93
94TOOL_GXX3_CXXOBJSUFF ?= .o
95TOOL_GXX3_CXXFLAGS ?=
96TOOL_GXX3_CXXFLAGS.debug ?= -g
97TOOL_GXX3_CXXFLAGS.profile ?= -O2 #-g -pg
98TOOL_GXX3_CXXFLAGS.release ?= -O2
99TOOL_GXX3_CXXINCS ?=
100TOOL_GXX3_CXXDEFS ?=
101
102TOOL_GXX3_PCHOBJSUFF ?= .h.gch
103TOOL_GXX3_PCHFLAGS ?= $(TOOL_GXX3_CXXFLAGS)
104TOOL_GXX3_PCHFLAGS.debug ?= $(TOOL_GXX3_CXXFLAGS.debug)
105TOOL_GXX3_PCHFLAGS.profile ?= $(TOOL_GXX3_CXXFLAGS.profile)
106TOOL_GXX3_PCHFLAGS.release ?= $(TOOL_GXX3_CXXFLAGS.release)
107TOOL_GXX3_PCHINCS ?= $(TOOL_GXX3_CXXINCS)
108TOOL_GXX3_PCHDEFS ?= $(TOOL_GXX3_CXXDEFS)
109
110TOOL_GXX3_ASFLAGS ?= -x assembler-with-cpp
111TOOL_GXX3_ASFLAGS.debug ?= -g
112TOOL_GXX3_ASFLAGS.profile ?= -g
113TOOL_GXX3_ASOBJSUFF ?= .o
114
115TOOL_GXX3_ARFLAGS ?= cr
116TOOL_GXX3_ARLIBSUFF ?= .a
117
118TOOL_GXX3_LDFLAGS ?=
119TOOL_GXX3_LDFLAGS.debug ?= -g
120TOOL_GXX3_LDFLAGS.profile ?= -g
121
122
123## Compile C source.
124# @param $(target) Normalized main target name.
125# @param $(source) Source filename (relative).
126# @param $(obj) Object file name. This shall be (re)created by the compilation.
127# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
128# @param $(flags) Flags.
129# @param $(defs) Definitions. No -D or something.
130# @param $(incs) Includes. No -I or something.
131# @param $(dirdep) Directory creation dependency.
132# @param $(deps) Other dependencies.
133#
134# @param $(outbase) Output basename (full). Use this for list files and such.
135# @param $(objsuff) Object suffix.
136TOOL_GXX3_COMPILE_C_DEPEND =
137TOOL_GXX3_COMPILE_C_DEPORD =
138TOOL_GXX3_COMPILE_C_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).i,)
139TOOL_GXX3_COMPILE_C_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
140define TOOL_GXX3_COMPILE_C_CMDS
141if "$(use_objcache)" != ""
142 $(QUIET)$(KOBJCACHE) -f $(outbase).koc -d $(PATH_OBJCACHE) -t $(bld_trg).$(bld_trg_arch) -p\
143 --kObjCache-cpp $(outbase).i\
144 $(TOOL_GXX3_CC) -E -o -\
145 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
146 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
147 $(abspath $(source))\
148 --kObjCache-cc $(obj)\
149 $(TOOL_GXX3_CC) -c\
150 $(flags) -fpreprocessed -x c\
151 -o $(obj)\
152 -
153else
154 $(QUIET)$(TOOL_GXX3_CC) -c\
155 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
156 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
157 -o $(obj)\
158 $(abspath $(source))
159endif
160 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
161endef
162
163
164## Compile C++ source.
165# @param $(target) Normalized main target name.
166# @param $(source) Source filename (relative).
167# @param $(obj) Object file name. This shall be (re)created by the compilation.
168# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
169# @param $(flags) Flags.
170# @param $(defs) Definitions. No -D or something.
171# @param $(incs) Includes. No -I or something.
172# @param $(dirdep) Directory creation dependency.
173# @param $(deps) Other dependencies.
174# @param $(outbase) Output basename (full). Use this for list files and such.
175# @param $(objsuff) Object suffix.
176TOOL_GXX3_COMPILE_CXX_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).ii,)
177TOOL_GXX3_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
178TOOL_GXX3_COMPILE_CXX_DEPORD =
179TOOL_GXX3_COMPILE_CXX_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
180define TOOL_GXX3_COMPILE_CXX_CMDS
181if "$(use_objcache)" != ""
182 $(QUIET)$(KOBJCACHE) -f $(outbase).koc -d $(PATH_OBJCACHE) -t $(bld_trg).$(bld_trg_arch) -p\
183 --kObjCache-cpp $(outbase).ii\
184 $(TOOL_GXX3_CXX) -E -o - $(if-expr defined($(target)_PCH_HDR)\
185 ,-fpch-preprocess -Winvalid-pch -I$($(target)_1_GCC_PCH_DIR) -include $(basename $($(target)_1_GCC_PCH_FILE)),)\
186 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
187 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
188 $(abspath $(source))\
189 --kObjCache-cc $(obj)\
190 $(TOOL_GXX3_CXX) -c\
191 $(flags) -fpreprocessed $(if-expr defined($(target)_PCH_HDR),-fpch-preprocess,) -x c++\
192 -o $(obj)\
193 -
194else
195 $(QUIET)$(TOOL_GXX3_CXX) -c\
196 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -D, $(defs))\
197 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
198 -o $(obj) $(if-expr defined($(target)_PCH_HDR) \
199 ,-Winvalid-pch -include $(basename $($(target)_1_GCC_PCH_FILE)),) \
200 $(abspath $(source))
201endif
202 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
203endef
204
205
206## Precompile C++ header.
207# @param $(target) Normalized main target name.
208# @param $(source) Source filename (relative).
209# @param $(obj) Object file name. This shall be (re)created by the compilation.
210# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
211# @param $(flags) Flags.
212# @param $(defs) Definitions. No -D or something.
213# @param $(incs) Includes. No -I or something.
214# @param $(dirdep) Directory creation dependency.
215# @param $(deps) Other dependencies.
216# @param $(outbase) Output basename (full). Use this for list files and such.
217# @param $(objsuff) Object suffix.
218TOOL_GXX3_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
219TOOL_GXX3_COMPILE_PCH_DEPEND =
220TOOL_GXX3_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
221define TOOL_GXX3_COMPILE_PCH_CMDS
222 $(QUIET)$(TOOL_GXX3_PCH) -c\
223 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -D, $(defs))\
224 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
225 -o $(obj)\
226 $(abspath $(source))
227 $(INSTALL) --hard-link-files-when-possible -m 0644 -- "$(obj)" "$($(target)_1_GCC_PCH_FILE)"
228 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
229endef
230
231
232## Compile Assembly source.
233# @param $(target) Normalized main target name.
234# @param $(source) Source filename (relative).
235# @param $(obj) Object file name. This shall be (re)created by the compilation.
236# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
237# @param $(flags) Flags.
238# @param $(defs) Definitions. No -D or something.
239# @param $(incs) Includes. No -I or something.
240# @param $(dirdep) Directory creation dependency.
241# @param $(deps) Other dependencies.
242# @param $(outbase) Output basename (full). Use this for list files and such.
243# @param $(objsuff) Object suffix.
244#
245TOOL_GXX3_COMPILE_AS_OUTPUT =
246TOOL_GXX3_COMPILE_AS_DEPEND =
247TOOL_GXX3_COMPILE_AS_DEPORD =
248define TOOL_GXX3_COMPILE_AS_CMDS
249 $(QUIET)$(TOOL_GXX3_AS) -c\
250 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
251 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
252 -o $(obj)\
253 $(abspath $(source))
254 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
255endef
256
257
258## Link library
259# @param $(target) Normalized main target name.
260# @param $(out) Library name.
261# @param $(objs) Object files to put in the library.
262# @param $(flags) Flags.
263# @param $(dirdep) Directory creation dependency.
264# @param $(deps) Other dependencies.
265# @param $(othersrc) Unhandled sources.
266# @param $(outbase) Output basename (full). Use this for list files and such.
267TOOL_GXX3_LINK_LIBRARY_OUTPUT = $(out).ar-script
268TOOL_GXX3_LINK_LIBRARY_OUTPUT_MAYBE = $(outbase).imp.a
269TOOL_GXX3_LINK_LIBRARY_DEPEND = $(othersrc)
270TOOL_GXX3_LINK_LIBRARY_DEPORD =
271define TOOL_GXX3_LINK_LIBRARY_CMDS
272 $(QUIET)$(APPEND) $(out).ar-script 'CREATE $(out)'
273 $(QUIET)$(APPEND) -n $(out).ar-script \
274 $(foreach o,$(filter-out %.h.gch,$(objs)), 'ADDMOD $(o)') \
275 $(foreach o,$(filter-out %.def %.imp %.dll,$(othersrc)), 'ADDLIB $(o)')
276 $(if $(filter %.def %.imp %.dll,$(othersrc))\
277 ,$(TOOL_GXX3_AR_IMP) -o $(outbase).imp.a $(filter %.def %.imp %.dll,$(othersrc))\
278 $(NL)$(TAB)$(QUIET)$(APPEND) $(out).ar-script 'ADDLIB $(outbase).imp.a')
279 $(QUIET)$(APPEND) $(out).ar-script 'SAVE'
280 $(QUIET)$(APPEND) $(out).ar-script 'END'
281 $(QUIET)$(REDIRECT) -rti $(out).ar-script -- $(TOOL_GXX3_AR) -M
282endef
283
284
285## Link program
286# @param $(target) Normalized main target name.
287# @param $(out) Program name.
288# @param $(objs) Object files to link together.
289# @param $(libs) Libraries to search.
290# @param $(libpath) Library search paths.
291# @param $(flags) Flags.
292# @param $(dirdep) Directory creation dependency.
293# @param $(deps) Other dependencies.
294# @param $(othersrc) Unhandled sources.
295# @param $(custom_pre) Custom step invoked before linking.
296# @param $(custom_post) Custom step invoked after linking.
297# @param $(outbase) Output basename (full). Use this for list files and such.
298TOOL_GXX3_LINK_PROGRAM_OUTPUT =
299TOOL_GXX3_LINK_PROGRAM_OUTPUT_MAYBE = $(outbase).map
300TOOL_GXX3_LINK_PROGRAM_OUTPUT_DEBUG = $(outbase).debug
301TOOL_GXX3_LINK_PROGRAM_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
302TOOL_GXX3_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
303 $(filter %.def, $(othersrc))
304TOOL_GXX3_LINK_PROGRAM_DEPORD =
305define TOOL_GXX3_LINK_PROGRAM_CMDS
306 $(QUIET)$(TOOL_GXX3_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
307 $(filter %.def, $(othersrc))\
308 $(foreach p,$(libpath), -L$(p))\
309 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
310 $(call TOOL_GXX3_LD_MAP,$(outbase).map)
311 ifeq ($(ld_debug),split)
312 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
313 $(QUIET)$(CHMOD) a-x $(outbase).debug
314 $(QUIET)$(TOOL_GXX3_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
315 endif
316endef
317
318
319## Link DLL
320# @param $(target) Normalized main target name.
321# @param $(out) Program name.
322# @param $(objs) Object files to link together.
323# @param $(libs) Libraries to search.
324# @param $(libpath) Library search paths.
325# @param $(flags) Flags.
326# @param $(dirdep) Directory creation dependency.
327# @param $(deps) Other dependencies.
328# @param $(othersrc) Unhandled sources.
329# @param $(custom_pre) Custom step invoked before linking.
330# @param $(custom_post) Custom step invoked after linking.
331# @param $(outbase) Output basename (full). Use this for list files and such.
332TOOL_GXX3_LINK_DLL_OUTPUT =
333TOOL_GXX3_LINK_DLL_OUTPUT_MAYBE = $(outbase).map
334TOOL_GXX3_LINK_DLL_OUTPUT_DEBUG = $(outbase).debug
335TOOL_GXX3_LINK_DLL_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
336TOOL_GXX3_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
337 $(filter %.def, $(othersrc))
338TOOL_GXX3_LINK_DLL_DEPORD =
339define TOOL_GXX3_LINK_DLL_CMDS
340 $(QUIET)$(TOOL_GXX3_LD) $(TOOL_GXX3_LDFLAGS.dll) $(flags) -o $(out)\
341 $(if $(filter-out win os2, $(KBUILD_TARGET)),$(call TOOL_GXX3_LD_SONAME,$(target),$(out)))\
342 $(filter-out %.h.gch,$(objs))\
343 $(filter %.def, $(othersrc))\
344 $(foreach p,$(libpath), -L$(p))\
345 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
346 $(call TOOL_GXX3_LD_MAP,$(outbase).map)
347 ifeq ($(ld_debug),split)
348 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
349 $(QUIET)$(CHMOD) a-x $(outbase).debug
350 $(QUIET)$(TOOL_GXX3_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
351 endif
352endef
353
354
355## Link system module (windows aka driver, linux aka kernel module)
356# @param $(target) Normalized main target name.
357# @param $(out) System module name.
358# @param $(objs) Object files to link together.
359# @param $(libs) Libraries to search.
360# @param $(libpath) Library search paths.
361# @param $(flags) Flags.
362# @param $(dirdep) Directory creation dependency.
363# @param $(deps) Other dependencies.
364# @param $(othersrc) Unhandled sources.
365# @param $(custom_pre) Custom step invoked before linking.
366# @param $(custom_post) Custom step invoked after linking.
367# @param $(outbase) Output basename (full). Use this for list files and such.
368TOOL_GXX3_LINK_SYSMOD_OUTPUT =
369TOOL_GXX3_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).map
370TOOL_GXX3_LINK_SYSMOD_OUTPUT_DEBUG = $(outbase).debug
371TOOL_GXX3_LINK_SYSMOD_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
372TOOL_GXX3_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
373 $(filter %.def, $(othersrc))
374TOOL_GXX3_LINK_SYSMOD_DEPORD =
375define TOOL_GXX3_LINK_SYSMOD_CMDS
376 $(QUIET)$(TOOL_GXX3_LD_SYSMOD) $(TOOL_GXX3_LDFLAGS.sysmod) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
377 $(filter %.def, $(othersrc))\
378 $(foreach p,$(libpath), -L$(p))\
379 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
380 $(call TOOL_GXX3_LD_SYSMOD_MAP,$(outbase).map)
381 ifeq ($(ld_debug),split)
382 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
383 $(QUIET)$(CHMOD) a-x $(outbase).debug
384 $(QUIET)$(TOOL_GXX3_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
385 endif
386endef
387
Note: See TracBrowser for help on using the repository browser.