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

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

GXX,GXX3: PCH updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.4 KB
Line 
1# $Id: GXX3.kmk 3257 2019-01-03 02:46:05Z 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 =
132TOOL_GXX3_COMPILE_C_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).i,)
133TOOL_GXX3_COMPILE_C_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
134define TOOL_GXX3_COMPILE_C_CMDS
135if "$(use_objcache)" != ""
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 -
147else
148 $(QUIET)$(TOOL_GXX3_CC) -c\
149 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
150 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
151 -o $(obj)\
152 $(abspath $(source))
153endif
154 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
155endef
156
157
158## Compile C++ source.
159# @param $(target) Normalized main target name.
160# @param $(source) Source filename (relative).
161# @param $(obj) Object file name. This shall be (re)created by the compilation.
162# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
163# @param $(flags) Flags.
164# @param $(defs) Definitions. No -D or something.
165# @param $(incs) Includes. No -I or something.
166# @param $(dirdep) Directory creation dependency.
167# @param $(deps) Other dependencies.
168# @param $(outbase) Output basename (full). Use this for list files and such.
169# @param $(objsuff) Object suffix.
170TOOL_GXX3_COMPILE_CXX_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).ii,)
171TOOL_GXX3_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
172TOOL_GXX3_COMPILE_CXX_DEPORD =
173TOOL_GXX3_COMPILE_CXX_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
174define TOOL_GXX3_COMPILE_CXX_CMDS
175if "$(use_objcache)" != ""
176 $(QUIET)$(KOBJCACHE) -f $(outbase).koc -d $(PATH_OBJCACHE) -t $(bld_trg).$(bld_trg_arch) -p\
177 --kObjCache-cpp $(outbase).ii\
178 $(TOOL_GXX3_CXX) -E -o - $(if-expr defined($(target)_PCH_HDR)\
179 ,-fpch-preprocess -Winvalid-pch -I$($(target)_1_GCC_PCH_DIR) -include $(basename $($(target)_1_GCC_PCH_FILE)),)\
180 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
181 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
182 $(abspath $(source))\
183 --kObjCache-cc $(obj)\
184 $(TOOL_GXX3_CXX) -c\
185 $(flags) -fpreprocessed $(if-expr defined($(target)_PCH_HDR),-fpch-preprocess,) -x c++\
186 -o $(obj)\
187 -
188else
189 $(QUIET)$(TOOL_GXX3_CXX) -c\
190 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -D, $(defs))\
191 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
192 -o $(obj) $(if-expr defined($(target)_PCH_HDR) \
193 ,-Winvalid-pch -include $(basename $($(target)_1_GCC_PCH_FILE)),) \
194 $(abspath $(source))
195endif
196 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
197endef
198
199
200## Precompile C++ header.
201# @param $(target) Normalized main target name.
202# @param $(source) Source filename (relative).
203# @param $(obj) Object file name. This shall be (re)created by the compilation.
204# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
205# @param $(flags) Flags.
206# @param $(defs) Definitions. No -D or something.
207# @param $(incs) Includes. No -I or something.
208# @param $(dirdep) Directory creation dependency.
209# @param $(deps) Other dependencies.
210# @param $(outbase) Output basename (full). Use this for list files and such.
211# @param $(objsuff) Object suffix.
212TOOL_GXX3_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
213TOOL_GXX3_COMPILE_PCH_DEPEND =
214TOOL_GXX3_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
215define TOOL_GXX3_COMPILE_PCH_CMDS
216 $(QUIET)$(TOOL_GXX3_PCH) -c\
217 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -D, $(defs))\
218 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
219 -o $(obj)\
220 $(abspath $(source))
221 $(INSTALL) --hard-link-files-when-possible -m 0644 -- "$(obj)" "$($(target)_1_GCC_PCH_FILE)"
222 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
223endef
224
225
226## Compile Assembly source.
227# @param $(target) Normalized main target name.
228# @param $(source) Source filename (relative).
229# @param $(obj) Object file name. This shall be (re)created by the compilation.
230# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
231# @param $(flags) Flags.
232# @param $(defs) Definitions. No -D or something.
233# @param $(incs) Includes. No -I or something.
234# @param $(dirdep) Directory creation dependency.
235# @param $(deps) Other dependencies.
236# @param $(outbase) Output basename (full). Use this for list files and such.
237# @param $(objsuff) Object suffix.
238#
239TOOL_GXX3_COMPILE_AS_OUTPUT =
240TOOL_GXX3_COMPILE_AS_DEPEND =
241TOOL_GXX3_COMPILE_AS_DEPORD =
242define TOOL_GXX3_COMPILE_AS_CMDS
243 $(QUIET)$(TOOL_GXX3_AS) -c\
244 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
245 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
246 -o $(obj)\
247 $(abspath $(source))
248 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
249endef
250
251
252## Link library
253# @param $(target) Normalized main target name.
254# @param $(out) Library name.
255# @param $(objs) Object files to put in the library.
256# @param $(flags) Flags.
257# @param $(dirdep) Directory creation dependency.
258# @param $(deps) Other dependencies.
259# @param $(othersrc) Unhandled sources.
260# @param $(outbase) Output basename (full). Use this for list files and such.
261TOOL_GXX3_LINK_LIBRARY_OUTPUT = $(out).ar-script
262TOOL_GXX3_LINK_LIBRARY_OUTPUT_MAYBE = $(outbase).imp.a
263TOOL_GXX3_LINK_LIBRARY_DEPEND = $(othersrc)
264TOOL_GXX3_LINK_LIBRARY_DEPORD =
265define TOOL_GXX3_LINK_LIBRARY_CMDS
266 $(QUIET)$(APPEND) $(out).ar-script 'CREATE $(out)'
267 $(QUIET)$(APPEND) -n $(out).ar-script \
268 $(foreach o,$(filter-out %.h.gch,$(objs)), 'ADDMOD $(o)') \
269 $(foreach o,$(filter-out %.def %.imp %.dll,$(othersrc)), 'ADDLIB $(o)')
270 $(if $(filter %.def %.imp %.dll,$(othersrc))\
271 ,$(TOOL_GXX3_AR_IMP) -o $(outbase).imp.a $(filter %.def %.imp %.dll,$(othersrc))\
272 $(NL)$(TAB)$(QUIET)$(APPEND) $(out).ar-script 'ADDLIB $(outbase).imp.a')
273 $(QUIET)$(APPEND) $(out).ar-script 'SAVE'
274 $(QUIET)$(APPEND) $(out).ar-script 'END'
275 $(QUIET)$(REDIRECT) -rti $(out).ar-script -- $(TOOL_GXX3_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_GXX3_LINK_PROGRAM_OUTPUT =
293TOOL_GXX3_LINK_PROGRAM_OUTPUT_MAYBE = $(outbase).map
294TOOL_GXX3_LINK_PROGRAM_OUTPUT_DEBUG = $(outbase).debug
295TOOL_GXX3_LINK_PROGRAM_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
296TOOL_GXX3_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
297 $(filter %.def, $(othersrc))
298TOOL_GXX3_LINK_PROGRAM_DEPORD =
299define TOOL_GXX3_LINK_PROGRAM_CMDS
300 $(QUIET)$(TOOL_GXX3_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
301 $(filter %.def, $(othersrc))\
302 $(foreach p,$(libpath), -L$(p))\
303 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
304 $(call TOOL_GXX3_LD_MAP,$(outbase).map)
305 ifeq ($(ld_debug),split)
306 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
307 $(QUIET)$(CHMOD) a-x $(outbase).debug
308 $(QUIET)$(TOOL_GXX3_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
309 endif
310endef
311
312
313## Link DLL
314# @param $(target) Normalized main target name.
315# @param $(out) Program name.
316# @param $(objs) Object files to link together.
317# @param $(libs) Libraries to search.
318# @param $(libpath) Library search paths.
319# @param $(flags) Flags.
320# @param $(dirdep) Directory creation dependency.
321# @param $(deps) Other dependencies.
322# @param $(othersrc) Unhandled sources.
323# @param $(custom_pre) Custom step invoked before linking.
324# @param $(custom_post) Custom step invoked after linking.
325# @param $(outbase) Output basename (full). Use this for list files and such.
326TOOL_GXX3_LINK_DLL_OUTPUT =
327TOOL_GXX3_LINK_DLL_OUTPUT_MAYBE = $(outbase).map
328TOOL_GXX3_LINK_DLL_OUTPUT_DEBUG = $(outbase).debug
329TOOL_GXX3_LINK_DLL_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
330TOOL_GXX3_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
331 $(filter %.def, $(othersrc))
332TOOL_GXX3_LINK_DLL_DEPORD =
333define TOOL_GXX3_LINK_DLL_CMDS
334 $(QUIET)$(TOOL_GXX3_LD) $(TOOL_GXX3_LDFLAGS.dll) $(flags) -o $(out)\
335 $(if $(filter-out win os2, $(KBUILD_TARGET)),$(call TOOL_GXX3_LD_SONAME,$(target),$(out)))\
336 $(filter-out %.h.gch,$(objs))\
337 $(filter %.def, $(othersrc))\
338 $(foreach p,$(libpath), -L$(p))\
339 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
340 $(call TOOL_GXX3_LD_MAP,$(outbase).map)
341 ifeq ($(ld_debug),split)
342 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
343 $(QUIET)$(CHMOD) a-x $(outbase).debug
344 $(QUIET)$(TOOL_GXX3_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_GXX3_LINK_SYSMOD_OUTPUT =
363TOOL_GXX3_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).map
364TOOL_GXX3_LINK_SYSMOD_OUTPUT_DEBUG = $(outbase).debug
365TOOL_GXX3_LINK_SYSMOD_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
366TOOL_GXX3_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
367 $(filter %.def, $(othersrc))
368TOOL_GXX3_LINK_SYSMOD_DEPORD =
369define TOOL_GXX3_LINK_SYSMOD_CMDS
370 $(QUIET)$(TOOL_GXX3_LD_SYSMOD) $(TOOL_GXX3_LDFLAGS.sysmod) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
371 $(filter %.def, $(othersrc))\
372 $(foreach p,$(libpath), -L$(p))\
373 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
374 $(call TOOL_GXX3_LD_SYSMOD_MAP,$(outbase).map)
375 ifeq ($(ld_debug),split)
376 $(QUIET)$(TOOL_GXX3_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
377 $(QUIET)$(CHMOD) a-x $(outbase).debug
378 $(QUIET)$(TOOL_GXX3_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
379 endif
380endef
381
Note: See TracBrowser for help on using the repository browser.