source: trunk/kBuild/tools/GXX64.kmk@ 3258

Last change on this file since 3258 was 3258, checked in by bird, 7 years ago

tools/*GXX*: Precompiled header and some kObjCache updates.

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