source: trunk/kBuild/tools/GXX64.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: 15.6 KB
Line 
1# $Id: GXX64.kmk 3566 2022-06-13 15:37:08Z bird $
2## @file
3# kBuild Tool Config - Generic 64-bit GCC v3.2.x or later using the system GCC, 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_GXX64 := Generic 64-bit GCC v3.2.x or later using the system GCC, for building C++ code. \
35 More or less Linux/ELF specfic.
36
37# Tool Specific Properties
38ifndef TOOL_GXX64_PREFIX
39 TOOL_GXX64_PREFIX :=
40endif
41ifndef TOOL_GXX64_SUFFIX
42 TOOL_GXX64_SUFFIX := $(HOSTSUFF_EXE)
43endif
44if1of ($(KBUILD_HOST), solaris)
45 TOOL_GXX64_PREFIX2 ?= g
46else
47 TOOL_GXX64_PREFIX2 ?=
48endif
49TOOL_GXX64_SUFFIX2 ?= $(HOSTSUFF_EXE)
50TOOL_GXX64_PREFIX3 ?=
51TOOL_GXX64_SUFFIX3 ?= $(HOSTSUFF_EXE)
52TOOL_GXX64_CC ?= $(TOOL_GXX64_PREFIX)gcc$(TOOL_GXX64_SUFFIX) -m64
53TOOL_GXX64_CXX ?= $(TOOL_GXX64_PREFIX)g++$(TOOL_GXX64_SUFFIX) -m64
54TOOL_GXX64_PCH ?= $(TOOL_GXX64_CXX)
55TOOL_GXX64_AS ?= $(TOOL_GXX64_PREFIX)gcc$(TOOL_GXX64_SUFFIX) -m64
56TOOL_GXX64_AR ?= $(TOOL_GXX64_PREFIX2)ar$(TOOL_GXX64_SUFFIX2)
57TOOL_GXX64_LD ?= $(TOOL_GXX64_PREFIX)g++$(TOOL_GXX64_SUFFIX) -m64
58if1of ($(KBUILD_HOST), solaris)
59 TOOL_GXX64_LD_SYSMOD ?= $(TOOL_GXX64_PREFIX3)ld$(TOOL_GXX64_SUFFIX3)
60else
61 TOOL_GXX64_LD_SYSMOD ?= $(TOOL_GXX64_PREFIX2)ld$(TOOL_GXX64_SUFFIX2)
62endif
63ifndef TOOL_GXX64_LDFLAGS.$(KBUILD_TARGET)
64 TOOL_GXX64_LDFLAGS.dll ?= -shared
65else
66 TOOL_GXX64_LDFLAGS.dll ?= $(TOOL_GXX64_LDFLAGS.$(KBUILD_TARGET))
67endif
68TOOL_GXX64_LDFLAGS.sysmod ?= -r -m elf_x86_64$(if-expr "$(KBUILD_TARGET)" == "freebsd" || "$(KBUILD_TARGET)" == "gnukfbsd",_fbsd,)
69TOOL_GXX64_LD_SONAME ?= -Wl,-soname=$(firstword $($(1)_SONAME.$(KBUILD_TARGET).$(KBUILD_TYPE)) $($(1)_SONAME.$(KBUILD_TARGET)) $($(1)_SONAME.$(KBUILD_TYPE)) $($(1)_SONAME) $(notdir $(2)))
70ifeq ($(KBUILD_TARGET),os2)
71 TOOL_GXX64_LD_MAP ?= -Zmap=$(1)
72else
73 TOOL_GXX64_LD_MAP ?=
74endif
75ifeq ($(KBUILD_TARGET),os2)
76 TOOL_GXX64_LD_SYSMOD_MAP ?= -Zmap=$(1)
77else
78 TOOL_GXX64_LD_SYSMOD_MAP ?=
79endif
80TOOL_GXX64_OBJCOPY ?= $(TOOL_GXX64_PREFIX2)objcopy$(TOOL_GXX64_SUFFIX2)
81
82ifdef SLKRUNS
83 TOOL_GXX64_CC += -fmessage-length=0
84 TOOL_GXX64_CXX += -fmessage-length=0
85endif
86
87# General Properties used by kBuild
88TOOL_GXX64_COBJSUFF ?= .o
89TOOL_GXX64_CFLAGS ?=
90TOOL_GXX64_CFLAGS.debug ?= -g
91TOOL_GXX64_CFLAGS.profile ?= -O2 #-g -pg
92TOOL_GXX64_CFLAGS.release ?= -O2
93TOOL_GXX64_CINCS ?=
94TOOL_GXX64_CDEFS ?=
95
96TOOL_GXX64_CXXOBJSUFF ?= .o
97TOOL_GXX64_CXXFLAGS ?=
98TOOL_GXX64_CXXFLAGS.debug ?= -g
99TOOL_GXX64_CXXFLAGS.profile ?= -O2 #-g -pg
100TOOL_GXX64_CXXFLAGS.release ?= -O2
101TOOL_GXX64_CXXINCS ?=
102TOOL_GXX64_CXXDEFS ?=
103
104TOOL_GXX64_PCHOBJSUFF ?= .h.gch
105TOOL_GXX64_PCHFLAGS ?= $(TOOL_GXX64_CXXFLAGS)
106TOOL_GXX64_PCHFLAGS.debug ?= $(TOOL_GXX64_CXXFLAGS.debug)
107TOOL_GXX64_PCHFLAGS.profile ?= $(TOOL_GXX64_CXXFLAGS.profile)
108TOOL_GXX64_PCHFLAGS.release ?= $(TOOL_GXX64_CXXFLAGS.release)
109TOOL_GXX64_PCHINCS ?= $(TOOL_GXX64_CXXINCS)
110TOOL_GXX64_PCHDEFS ?= $(TOOL_GXX64_CXXDEFS)
111
112TOOL_GXX64_ASFLAGS ?= -x assembler-with-cpp
113TOOL_GXX64_ASFLAGS.debug ?= -g
114TOOL_GXX64_ASFLAGS.profile ?= -g
115TOOL_GXX64_ASOBJSUFF ?= .o
116
117TOOL_GXX64_ARFLAGS ?= cr
118TOOL_GXX64_ARLIBSUFF ?= .a
119
120TOOL_GXX64_LDFLAGS ?=
121TOOL_GXX64_LDFLAGS.debug ?= -g
122TOOL_GXX64_LDFLAGS.profile ?= -g
123
124
125## Compile C source.
126# @param $(target) Normalized main target name.
127# @param $(source) Source filename (relative).
128# @param $(obj) Object file name. This shall be (re)created by the compilation.
129# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
130# @param $(flags) Flags.
131# @param $(defs) Definitions. No -D or something.
132# @param $(incs) Includes. No -I or something.
133# @param $(dirdep) Directory creation dependency.
134# @param $(deps) Other dependencies.
135#
136# @param $(outbase) Output basename (full). Use this for list files and such.
137# @param $(objsuff) Object suffix.
138TOOL_GXX64_COMPILE_C_DEPEND =
139TOOL_GXX64_COMPILE_C_DEPORD =
140TOOL_GXX64_COMPILE_C_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).i,)
141TOOL_GXX64_COMPILE_C_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
142define TOOL_GXX64_COMPILE_C_CMDS
143if "$(use_objcache)" != ""
144 $(QUIET)$(KOBJCACHE) -f $(outbase).koc -d $(PATH_OBJCACHE) -t $(bld_trg).$(bld_trg_arch) -p\
145 --kObjCache-cpp $(outbase).i\
146 $(TOOL_GXX64_CC) -E -o -\
147 $(flags) $(qaddprefix sh,-I, $(incs)) $(qaddprefix sh,-D, $(defs))\
148 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
149 $(abspath $(source))\
150 --kObjCache-cc $(obj)\
151 $(TOOL_GXX64_CC) -c\
152 $(flags) -fpreprocessed -x c\
153 -o $(obj)\
154 -
155else
156 $(QUIET)$(TOOL_GXX64_CC) -c\
157 $(flags) $(qaddprefix sh,-I, $(incs)) $(qaddprefix sh,-D, $(defs))\
158 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
159 -o $(obj)\
160 $(abspath $(source))
161endif
162 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
163endef
164
165
166## Compile C++ source.
167# @param $(target) Normalized main target name.
168# @param $(source) Source filename (relative).
169# @param $(obj) Object file name. This shall be (re)created by the compilation.
170# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
171# @param $(flags) Flags.
172# @param $(defs) Definitions. No -D or something.
173# @param $(incs) Includes. No -I or something.
174# @param $(dirdep) Directory creation dependency.
175# @param $(deps) Other dependencies.
176# @param $(outbase) Output basename (full). Use this for list files and such.
177# @param $(objsuff) Object suffix.
178TOOL_GXX64_COMPILE_CXX_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).ii,)
179TOOL_GXX64_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
180TOOL_GXX64_COMPILE_CXX_DEPORD =
181TOOL_GXX64_COMPILE_CXX_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
182define TOOL_GXX64_COMPILE_CXX_CMDS
183if "$(use_objcache)" != ""
184 $(QUIET)$(KOBJCACHE) -f $(outbase).koc -d $(PATH_OBJCACHE) -t $(bld_trg).$(bld_trg_arch) -p\
185 --kObjCache-cpp $(outbase).ii\
186 $(TOOL_GXX64_CXX) -E -o - $(if-expr defined($(target)_PCH_HDR)\
187 ,-fpch-preprocess -Winvalid-pch -I$($(target)_1_GCC_PCH_DIR) -include $(basename $($(target)_1_GCC_PCH_FILE)),)\
188 $(flags) $(qaddprefix sh,-I, $(incs)) $(qaddprefix sh,-D, $(defs))\
189 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
190 $(abspath $(source))\
191 --kObjCache-cc $(obj)\
192 $(TOOL_GXX64_CXX) -c\
193 $(flags) -fpreprocessed $(if-expr defined($(target)_PCH_HDR),-fpch-preprocess,) -x c++\
194 -o $(obj)\
195 -
196else
197 $(QUIET)$(TOOL_GXX64_CXX) -c\
198 $(flags) $(qaddprefix sh,-I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(qaddprefix sh,-D, $(defs))\
199 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
200 -o $(obj) $(if-expr defined($(target)_PCH_HDR) \
201 ,-Winvalid-pch -include $(basename $($(target)_1_GCC_PCH_FILE)),) \
202 $(abspath $(source))
203endif
204 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
205endef
206
207
208## Precompile C++ header.
209# @param $(target) Normalized main target name.
210# @param $(source) Source filename (relative).
211# @param $(obj) Object file name. This shall be (re)created by the compilation.
212# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
213# @param $(flags) Flags.
214# @param $(defs) Definitions. No -D or something.
215# @param $(incs) Includes. No -I or something.
216# @param $(dirdep) Directory creation dependency.
217# @param $(deps) Other dependencies.
218# @param $(outbase) Output basename (full). Use this for list files and such.
219# @param $(objsuff) Object suffix.
220TOOL_GXX64_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
221TOOL_GXX64_COMPILE_PCH_DEPEND =
222TOOL_GXX64_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
223define TOOL_GXX64_COMPILE_PCH_CMDS
224 $(QUIET)$(TOOL_GXX64_PCH) -c\
225 $(flags) $(qaddprefix sh,-I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(qaddprefix sh,-D, $(defs))\
226 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
227 -o $(obj)\
228 $(abspath $(source))
229 $(INSTALL) --hard-link-files-when-possible -m 0644 -- "$(obj)" "$($(target)_1_GCC_PCH_FILE)"
230 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
231endef
232
233
234## Compile Assembly source.
235# @param $(target) Normalized main target name.
236# @param $(source) Source filename (relative).
237# @param $(obj) Object file name. This shall be (re)created by the compilation.
238# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
239# @param $(flags) Flags.
240# @param $(defs) Definitions. No -D or something.
241# @param $(incs) Includes. No -I or something.
242# @param $(dirdep) Directory creation dependency.
243# @param $(deps) Other dependencies.
244# @param $(outbase) Output basename (full). Use this for list files and such.
245# @param $(objsuff) Object suffix.
246#
247TOOL_GXX64_COMPILE_AS_OUTPUT =
248TOOL_GXX64_COMPILE_AS_DEPEND =
249TOOL_GXX64_COMPILE_AS_DEPORD =
250define TOOL_GXX64_COMPILE_AS_CMDS
251 $(QUIET)$(TOOL_GXX64_AS) -c\
252 $(flags) $(qaddprefix sh,-I, $(incs)) $(qaddprefix sh,-D, $(defs))\
253 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
254 -o $(obj)\
255 $(abspath $(source))
256 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
257endef
258
259
260## Link library
261# @param $(target) Normalized main target name.
262# @param $(out) Library name.
263# @param $(objs) Object files to put in the library.
264# @param $(flags) Flags.
265# @param $(dirdep) Directory creation dependency.
266# @param $(deps) Other dependencies.
267# @param $(othersrc) Unhandled sources.
268# @param $(outbase) Output basename (full). Use this for list files and such.
269TOOL_GXX64_LINK_LIBRARY_OUTPUT = $(out).ar-script
270TOOL_GXX64_LINK_LIBRARY_DEPEND = $(othersrc)
271TOOL_GXX64_LINK_LIBRARY_DEPORD =
272define TOOL_GXX64_LINK_LIBRARY_CMDS
273 $(QUIET)$(APPEND) $(out).ar-script 'CREATE $(out)'
274 $(QUIET)$(APPEND) -n $(out).ar-script \
275 $(foreach o,$(filter-out %.h.gch,$(objs)), 'ADDMOD $(o)') \
276 $(foreach o,$(othersrc), 'ADDLIB $(o)')
277 $(QUIET)$(APPEND) $(out).ar-script 'SAVE'
278 $(QUIET)$(APPEND) $(out).ar-script 'END'
279 $(QUIET)$(REDIRECT) -rti $(out).ar-script -- $(TOOL_GXX64_AR) -M
280endef
281
282
283## Link program
284# @param $(target) Normalized main target name.
285# @param $(out) Program name.
286# @param $(objs) Object files to link together.
287# @param $(libs) Libraries to search.
288# @param $(libpath) Library search paths.
289# @param $(flags) Flags.
290# @param $(dirdep) Directory creation dependency.
291# @param $(deps) Other dependencies.
292# @param $(othersrc) Unhandled sources.
293# @param $(custom_pre) Custom step invoked before linking.
294# @param $(custom_post) Custom step invoked after linking.
295# @param $(outbase) Output basename (full). Use this for list files and such.
296TOOL_GXX64_LINK_PROGRAM_OUTPUT =
297TOOL_GXX64_LINK_PROGRAM_OUTPUT_MAYBE = $(outbase).map
298TOOL_GXX64_LINK_PROGRAM_OUTPUT_DEBUG = $(outbase).debug
299TOOL_GXX64_LINK_PROGRAM_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
300TOOL_GXX64_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
301TOOL_GXX64_LINK_PROGRAM_DEPORD =
302define TOOL_GXX64_LINK_PROGRAM_CMDS
303 $(QUIET)$(TOOL_GXX64_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
304 $(foreach p,$(libpath), -L$(p))\
305 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
306 $(call TOOL_GXX64_LD_MAP,$(outbase).map)
307 ifeq ($(ld_debug),split)
308 $(QUIET)$(TOOL_GXX64_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
309 $(QUIET)$(CHMOD) a-x $(outbase).debug
310 $(QUIET)$(TOOL_GXX64_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
311 endif
312endef
313
314
315## Link DLL
316# @param $(target) Normalized main target name.
317# @param $(out) Program name.
318# @param $(objs) Object files to link together.
319# @param $(libs) Libraries to search.
320# @param $(libpath) Library search paths.
321# @param $(flags) Flags.
322# @param $(dirdep) Directory creation dependency.
323# @param $(deps) Other dependencies.
324# @param $(othersrc) Unhandled sources.
325# @param $(custom_pre) Custom step invoked before linking.
326# @param $(custom_post) Custom step invoked after linking.
327# @param $(outbase) Output basename (full). Use this for list files and such.
328TOOL_GXX64_LINK_DLL_OUTPUT =
329TOOL_GXX64_LINK_DLL_OUTPUT_MAYBE = $(outbase).map
330TOOL_GXX64_LINK_DLL_OUTPUT_DEBUG = $(outbase).debug
331TOOL_GXX64_LINK_DLL_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
332TOOL_GXX64_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
333TOOL_GXX64_LINK_DLL_DEPORD =
334define TOOL_GXX64_LINK_DLL_CMDS
335 $(QUIET)$(TOOL_GXX64_LD) $(TOOL_GXX64_LDFLAGS.dll) $(flags) -o $(out)\
336 $(if $(filter-out win os2, $(KBUILD_TARGET)),$(call TOOL_GXX64_LD_SONAME,$(target),$(out)))\
337 $(filter-out %.h.gch,$(objs))\
338 $(foreach p,$(libpath), -L$(p))\
339 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
340 $(call TOOL_GXX64_LD_MAP,$(outbase).map)
341 ifeq ($(ld_debug),split)
342 $(QUIET)$(TOOL_GXX64_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
343 $(QUIET)$(CHMOD) a-x $(outbase).debug
344 $(QUIET)$(TOOL_GXX64_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
345 endif
346endef
347
348
349## Link system module (windows aka driver, linux aka kernel module)
350# @param $(target) Normalized main target name.
351# @param $(out) System module name.
352# @param $(objs) Object files to link together.
353# @param $(libs) Libraries to search.
354# @param $(libpath) Library search paths.
355# @param $(flags) Flags.
356# @param $(dirdep) Directory creation dependency.
357# @param $(deps) Other dependencies.
358# @param $(othersrc) Unhandled sources.
359# @param $(custom_pre) Custom step invoked before linking.
360# @param $(custom_post) Custom step invoked after linking.
361# @param $(outbase) Output basename (full). Use this for list files and such.
362TOOL_GXX64_LINK_SYSMOD_OUTPUT =
363TOOL_GXX64_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).map
364TOOL_GXX64_LINK_SYSMOD_OUTPUT_DEBUG = $(outbase).debug
365TOOL_GXX64_LINK_SYSMOD_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
366TOOL_GXX64_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
367TOOL_GXX64_LINK_SYSMOD_DEPORD =
368define TOOL_GXX64_LINK_SYSMOD_CMDS
369 $(QUIET)$(TOOL_GXX64_LD_SYSMOD) $(TOOL_GXX64_LDFLAGS.sysmod) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
370 $(foreach p,$(libpath), -L$(p))\
371 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
372 $(call TOOL_GXX64_LD_SYSMOD_MAP,$(outbase).map)
373 ifeq ($(ld_debug),split)
374 $(QUIET)$(TOOL_GXX64_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
375 $(QUIET)$(CHMOD) a-x $(outbase).debug
376 $(QUIET)$(TOOL_GXX64_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
377 endif
378endef
379
Note: See TracBrowser for help on using the repository browser.