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