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

Last change on this file since 3566 was 3566, checked in by bird, 3 years ago

tools/G*.kmk,header.kmk: Use qaddprefix in sh-mode for -D and -I processing, just like VCC14*.kmk does. Forced update of header.kmk so KMK_REVISION can be used to detect the changes.

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