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

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

GXX3: Make precompiled headers work with the compiler cache. Though, it turns out to be slower with gcc 8.2.x than regular build w/o precompiled headers, but just to be feature complete...

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.6 KB
Line 
1# $Id: GXX3.kmk 3255 2019-01-02 19:14:57Z bird $
2## @file
3# kBuild Tool Config - Generic GCC v3.2.x 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
37TOOL_GXX3_CC ?= gcc$(HOSTSUFF_EXE)
38TOOL_GXX3_CXX ?= g++$(HOSTSUFF_EXE)
39TOOL_GXX3_PCH ?= $(TOOL_GXX3_CXX)
40TOOL_GXX3_AS ?= gcc$(HOSTSUFF_EXE)
41ifeq ($(KBUILD_TARGET),solaris)
42 TOOL_GXX3_AR ?= gar$(HOSTSUFF_EXE)
43else
44 TOOL_GXX3_AR ?= ar$(HOSTSUFF_EXE)
45endif
46ifeq ($(KBUILD_TARGET),os2)
47 TOOL_GXX3_AR_IMP ?= emximp$(HOSTSTUFF_EXE)
48else
49 TOOL_GXX3_AR_IMP ?= $(ECHO) not supported!
50endif
51TOOL_GXX3_LD ?= g++$(HOSTSUFF_EXE)
52TOOL_GXX3_LD_SYSMOD ?= ld$(HOSTSUFF_EXE)
53ifndef TOOL_GXX3_LDFLAGS.$(KBUILD_TARGET)
54 TOOL_GXX3_LDFLAGS.dll ?= -shared
55else
56 TOOL_GXX3_LDFLAGS.dll ?= $(TOOL_GXX3_LDFLAGS.$(KBUILD_TARGET))
57endif
58TOOL_GXX3_LDFLAGS.sysmod ?= -r
59TOOL_GXX3_LD_SONAME ?= -Wl,-soname=$(firstword $($(1)_SONAME.$(KBUILD_TARGET).$(KBUILD_TYPE)) $($(1)_SONAME.$(KBUILD_TARGET)) $($(1)_SONAME.$(KBUILD_TYPE)) $($(1)_SONAME) $(notdir $(2)))
60ifeq ($(KBUILD_TARGET),os2)
61 TOOL_GXX3_LD_MAP ?= -Zmap=$(1)
62 TOOL_GXX3_LD_SYSMOD_MAP ?= -Zmap=$(1)
63else
64 TOOL_GXX3_LD_MAP ?=
65 TOOL_GXX3_LD_SYSMOD_MAP ?=
66endif
67if1of ($(KBUILD_HOST), solaris)
68 TOOL_GXX3_OBJCOPY ?= gobjcopy$(HOSTSUFF_EXE)
69else
70 TOOL_GXX3_OBJCOPY ?= objcopy$(HOSTSUFF_EXE)
71endif
72
73ifdef SLKRUNS
74 TOOL_GXX3_CC += -fmessage-length=0
75 TOOL_GXX3_CXX += -fmessage-length=0
76 TOOL_GXX3_PCH += -fmessage-length=0
77endif
78
79# General Properties used by kBuild
80TOOL_GXX3_COBJSUFF ?= .o
81TOOL_GXX3_CFLAGS ?=
82TOOL_GXX3_CFLAGS.debug ?= -g
83TOOL_GXX3_CFLAGS.profile ?= -O2 #-g -pg
84TOOL_GXX3_CFLAGS.release ?= -O2
85TOOL_GXX3_CINCS ?=
86TOOL_GXX3_CDEFS ?=
87
88TOOL_GXX3_CXXOBJSUFF ?= .o
89TOOL_GXX3_CXXFLAGS ?=
90TOOL_GXX3_CXXFLAGS.debug ?= -g
91TOOL_GXX3_CXXFLAGS.profile ?= -O2 #-g -pg
92TOOL_GXX3_CXXFLAGS.release ?= -O2
93TOOL_GXX3_CXXINCS ?=
94TOOL_GXX3_CXXDEFS ?=
95
96TOOL_GXX3_PCHOBJSUFF ?= .h.gch
97TOOL_GXX3_PCHFLAGS ?= $(TOOL_GXX3_CXXFLAGS)
98TOOL_GXX3_PCHFLAGS.debug ?= $(TOOL_GXX3_CXXFLAGS.debug)
99TOOL_GXX3_PCHFLAGS.profile ?= $(TOOL_GXX3_CXXFLAGS.profile)
100TOOL_GXX3_PCHFLAGS.release ?= $(TOOL_GXX3_CXXFLAGS.release)
101TOOL_GXX3_PCHINCS ?= $(TOOL_GXX3_CXXINCS)
102TOOL_GXX3_PCHDEFS ?= $(TOOL_GXX3_CXXDEFS)
103
104TOOL_GXX3_ASFLAGS ?= -x assembler-with-cpp
105TOOL_GXX3_ASFLAGS.debug ?= -g
106TOOL_GXX3_ASFLAGS.profile ?= -g
107TOOL_GXX3_ASOBJSUFF ?= .o
108
109TOOL_GXX3_ARFLAGS ?= cr
110TOOL_GXX3_ARLIBSUFF ?= .a
111
112TOOL_GXX3_LDFLAGS ?=
113TOOL_GXX3_LDFLAGS.debug ?= -g
114TOOL_GXX3_LDFLAGS.profile ?= -g
115
116
117## Compile C source.
118# @param $(target) Normalized main target name.
119# @param $(source) Source filename (relative).
120# @param $(obj) Object file name. This shall be (re)created by the compilation.
121# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
122# @param $(flags) Flags.
123# @param $(defs) Definitions. No -D or something.
124# @param $(incs) Includes. No -I or something.
125# @param $(dirdep) Directory creation dependency.
126# @param $(deps) Other dependencies.
127#
128# @param $(outbase) Output basename (full). Use this for list files and such.
129# @param $(objsuff) Object suffix.
130TOOL_GXX3_COMPILE_C_DEPEND =
131TOOL_GXX3_COMPILE_C_DEPORD =
132ifdef KBUILD_USE_KOBJCACHE
133TOOL_GXX3_COMPILE_C_USES_KOBJCACHE = 1
134TOOL_GXX3_COMPILE_C_OUTPUT = $(outbase).i
135define TOOL_GXX3_COMPILE_C_CMDS
136 $(QUIET)$(KOBJCACHE) -f $(outbase).koc -d $(PATH_OBJCACHE) -t $(bld_trg).$(bld_trg_arch) -p\
137 --kObjCache-cpp $(outbase).i\
138 $(TOOL_GXX3_CC) -E -o -\
139 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
140 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
141 $(abspath $(source))\
142 --kObjCache-cc $(obj)\
143 $(TOOL_GXX3_CC) -c\
144 $(flags) -fpreprocessed -x c\
145 -o $(obj)\
146 -
147 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
148endef
149else # !KBUILD_USE_KOBJCACHE
150TOOL_GXX3_COMPILE_C_OUTPUT =
151define TOOL_GXX3_COMPILE_C_CMDS
152 $(QUIET)$(TOOL_GXX3_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))
157 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
158endef
159endif # !KBUILD_USE_KOBJCACHE
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_GXX3_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
175TOOL_GXX3_COMPILE_CXX_DEPORD =
176ifdef KBUILD_USE_KOBJCACHE
177TOOL_GXX3_COMPILE_CXX_USES_KOBJCACHE = 1
178TOOL_GXX3_COMPILE_CXX_OUTPUT = $(outbase).ii
179define TOOL_GXX3_COMPILE_CXX_CMDS
180 $(QUIET)$(KOBJCACHE) -f $(outbase).koc -d $(PATH_OBJCACHE) -t $(bld_trg).$(bld_trg_arch) -p\
181 --kObjCache-cpp $(outbase).ii\
182 $(TOOL_GXX3_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_GXX3_CXX) -c\
189 $(flags) -fpreprocessed $(if-expr defined($(target)_PCH_HDR),-fpch-preprocess,) -x c++\
190 -o $(obj)\
191 -
192 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
193endef
194else # !KBUILD_USE_KOBJCACHE
195TOOL_GXX3_COMPILE_CXX_OUTPUT =
196define TOOL_GXX3_COMPILE_CXX_CMDS
197 $(QUIET)$(TOOL_GXX3_CXX) -c\
198 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -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))
203 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
204endef
205endif # !KBUILD_USE_KOBJCACHE
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_GXX3_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
221TOOL_GXX3_COMPILE_PCH_DEPEND =
222TOOL_GXX3_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
223define TOOL_GXX3_COMPILE_PCH_CMDS
224 $(QUIET)$(TOOL_GXX3_PCH) -c\
225 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -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_GXX3_COMPILE_AS_OUTPUT =
248TOOL_GXX3_COMPILE_AS_DEPEND =
249TOOL_GXX3_COMPILE_AS_DEPORD =
250define TOOL_GXX3_COMPILE_AS_CMDS
251 $(QUIET)$(TOOL_GXX3_AS) -c\
252 $(flags) $(addprefix -I, $(incs)) $(addprefix -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_GXX3_LINK_LIBRARY_OUTPUT = $(out).ar-script
270TOOL_GXX3_LINK_LIBRARY_OUTPUT_MAYBE = $(outbase).imp.a
271TOOL_GXX3_LINK_LIBRARY_DEPEND = $(othersrc)
272TOOL_GXX3_LINK_LIBRARY_DEPORD =
273define TOOL_GXX3_LINK_LIBRARY_CMDS
274 $(QUIET)$(APPEND) $(out).ar-script 'CREATE $(out)'
275 $(QUIET)$(APPEND) -n $(out).ar-script \
276 $(foreach o,$(filter-out %.h.gch,$(objs)), 'ADDMOD $(o)') \
277 $(foreach o,$(filter-out %.def %.imp %.dll,$(othersrc)), 'ADDLIB $(o)')
278 $(if $(filter %.def %.imp %.dll,$(othersrc))\
279 ,$(TOOL_GXX3_AR_IMP) -o $(outbase).imp.a $(filter %.def %.imp %.dll,$(othersrc))\
280 $(NL)$(TAB)$(QUIET)$(APPEND) $(out).ar-script 'ADDLIB $(outbase).imp.a')
281 $(QUIET)$(APPEND) $(out).ar-script 'SAVE'
282 $(QUIET)$(APPEND) $(out).ar-script 'END'
283 $(QUIET)$(REDIRECT) -rti $(out).ar-script -- $(TOOL_GXX3_AR) -M
284endef
285
286
287## Link program
288# @param $(target) Normalized main target name.
289# @param $(out) Program name.
290# @param $(objs) Object files to link together.
291# @param $(libs) Libraries to search.
292# @param $(libpath) Library search paths.
293# @param $(flags) Flags.
294# @param $(dirdep) Directory creation dependency.
295# @param $(deps) Other dependencies.
296# @param $(othersrc) Unhandled sources.
297# @param $(custom_pre) Custom step invoked before linking.
298# @param $(custom_post) Custom step invoked after linking.
299# @param $(outbase) Output basename (full). Use this for list files and such.
300TOOL_GXX3_LINK_PROGRAM_OUTPUT =
301TOOL_GXX3_LINK_PROGRAM_OUTPUT_MAYBE = $(outbase).map
302TOOL_GXX3_LINK_PROGRAM_OUTPUT_DEBUG = $(outbase).debug
303TOOL_GXX3_LINK_PROGRAM_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
304TOOL_GXX3_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
305 $(filter %.def, $(othersrc))
306TOOL_GXX3_LINK_PROGRAM_DEPORD =
307define TOOL_GXX3_LINK_PROGRAM_CMDS
308 $(QUIET)$(TOOL_GXX3_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
309 $(filter %.def, $(othersrc))\
310 $(foreach p,$(libpath), -L$(p))\
311 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
312 $(call TOOL_GXX3_LD_MAP,$(outbase).map)
313 ifeq ($(ld_debug),split)
314 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
315 $(QUIET)$(CHMOD) a-x $(outbase).debug
316 $(QUIET)$(TOOL_GXX3_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
317 endif
318endef
319
320
321## Link DLL
322# @param $(target) Normalized main target name.
323# @param $(out) Program name.
324# @param $(objs) Object files to link together.
325# @param $(libs) Libraries to search.
326# @param $(libpath) Library search paths.
327# @param $(flags) Flags.
328# @param $(dirdep) Directory creation dependency.
329# @param $(deps) Other dependencies.
330# @param $(othersrc) Unhandled sources.
331# @param $(custom_pre) Custom step invoked before linking.
332# @param $(custom_post) Custom step invoked after linking.
333# @param $(outbase) Output basename (full). Use this for list files and such.
334TOOL_GXX3_LINK_DLL_OUTPUT =
335TOOL_GXX3_LINK_DLL_OUTPUT_MAYBE = $(outbase).map
336TOOL_GXX3_LINK_DLL_OUTPUT_DEBUG = $(outbase).debug
337TOOL_GXX3_LINK_DLL_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
338TOOL_GXX3_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
339 $(filter %.def, $(othersrc))
340TOOL_GXX3_LINK_DLL_DEPORD =
341define TOOL_GXX3_LINK_DLL_CMDS
342 $(QUIET)$(TOOL_GXX3_LD) $(TOOL_GXX3_LDFLAGS.dll) $(flags) -o $(out)\
343 $(if $(filter-out win os2, $(KBUILD_TARGET)),$(call TOOL_GXX3_LD_SONAME,$(target),$(out)))\
344 $(filter-out %.h.gch,$(objs))\
345 $(filter %.def, $(othersrc))\
346 $(foreach p,$(libpath), -L$(p))\
347 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
348 $(call TOOL_GXX3_LD_MAP,$(outbase).map)
349 ifeq ($(ld_debug),split)
350 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
351 $(QUIET)$(CHMOD) a-x $(outbase).debug
352 $(QUIET)$(TOOL_GXX3_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
353 endif
354endef
355
356
357## Link system module (windows aka driver, linux aka kernel module)
358# @param $(target) Normalized main target name.
359# @param $(out) System module name.
360# @param $(objs) Object files to link together.
361# @param $(libs) Libraries to search.
362# @param $(libpath) Library search paths.
363# @param $(flags) Flags.
364# @param $(dirdep) Directory creation dependency.
365# @param $(deps) Other dependencies.
366# @param $(othersrc) Unhandled sources.
367# @param $(custom_pre) Custom step invoked before linking.
368# @param $(custom_post) Custom step invoked after linking.
369# @param $(outbase) Output basename (full). Use this for list files and such.
370TOOL_GXX3_LINK_SYSMOD_OUTPUT =
371TOOL_GXX3_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).map
372TOOL_GXX3_LINK_SYSMOD_OUTPUT_DEBUG = $(outbase).debug
373TOOL_GXX3_LINK_SYSMOD_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
374TOOL_GXX3_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
375 $(filter %.def, $(othersrc))
376TOOL_GXX3_LINK_SYSMOD_DEPORD =
377define TOOL_GXX3_LINK_SYSMOD_CMDS
378 $(QUIET)$(TOOL_GXX3_LD_SYSMOD) $(TOOL_GXX3_LDFLAGS.sysmod) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
379 $(filter %.def, $(othersrc))\
380 $(foreach p,$(libpath), -L$(p))\
381 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
382 $(call TOOL_GXX3_LD_SYSMOD_MAP,$(outbase).map)
383 ifeq ($(ld_debug),split)
384 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
385 $(QUIET)$(CHMOD) a-x $(outbase).debug
386 $(QUIET)$(TOOL_GXX3_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
387 endif
388endef
389
Note: See TracBrowser for help on using the repository browser.