source: trunk/kBuild/tools/GXX32.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.8 KB
Line 
1# $Id: GXX32.kmk 3391 2020-06-30 08:08:15Z bird $
2## @file
3# kBuild Tool Config - Generic 32-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_GXX32 := Generic 32-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_GXX32_PREFIX
39 TOOL_GXX32_PREFIX :=
40endif
41ifndef TOOL_GXX32_SUFFIX
42 TOOL_GXX32_SUFFIX := $(HOSTSUFF_EXE)
43endif
44TOOL_GXX32_CC ?= $(TOOL_GXX32_PREFIX)gcc$(TOOL_GXX32_SUFFIX) -m32
45TOOL_GXX32_CXX ?= $(TOOL_GXX32_PREFIX)g++$(TOOL_GXX32_SUFFIX) -m32
46TOOL_GXX32_PCH ?= $(TOOL_GXX32_CXX)
47TOOL_GXX32_AS ?= $(TOOL_GXX32_PREFIX)gcc$(TOOL_GXX32_SUFFIX) -m32
48if1of ($(KBUILD_TARGET),solaris)
49 TOOL_GXX32_AR ?= $(TOOL_GXX32_PREFIX)gar$(TOOL_GXX32_SUFFIX)
50else
51 TOOL_GXX32_AR ?= $(TOOL_GXX32_PREFIX)ar$(TOOL_GXX32_SUFFIX)
52endif
53TOOL_GXX32_LD ?= $(TOOL_GXX32_PREFIX)g++$(TOOL_GXX32_SUFFIX) -m32
54TOOL_GXX32_LD_SYSMOD ?= $(TOOL_GXX32_PREFIX)ld$(TOOL_GXX32_SUFFIX)
55ifndef TOOL_GXX32_LDFLAGS.$(KBUILD_TARGET)
56 TOOL_GXX32_LDFLAGS.dll ?= -shared
57else
58 TOOL_GXX32_LDFLAGS.dll ?= $(TOOL_GXX32_LDFLAGS.$(KBUILD_TARGET))
59endif
60TOOL_GXX32_LDFLAGS.sysmod ?= -r -m elf_i386$(if-expr "$(KBUILD_TARGET)" == "freebsd" || "$(KBUILD_TARGET)" == "gnukfbsd",_fbsd,)
61TOOL_GXX32_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_GXX32_LD_MAP ?= -Zmap=$(1)
64else
65 TOOL_GXX32_LD_MAP ?=
66endif
67ifeq ($(KBUILD_TARGET),os2)
68 TOOL_GXX32_LD_SYSMOD_MAP ?= -Zmap=$(1)
69else
70 TOOL_GXX32_LD_SYSMOD_MAP ?=
71endif
72if1of ($(KBUILD_HOST), solaris)
73 TOOL_GXX32_OBJCOPY ?= $(TOOL_GXX32_PREFIX)gobjcopy$(TOOL_GXX32_SUFFIX)
74else
75 TOOL_GXX32_OBJCOPY ?= $(TOOL_GXX32_PREFIX)objcopy$(TOOL_GXX32_SUFFIX)
76endif
77
78ifdef SLKRUNS
79 TOOL_GXX32_CC += -fmessage-length=0
80 TOOL_GXX32_CXX += -fmessage-length=0
81endif
82
83# General Properties used by kBuild
84TOOL_GXX32_COBJSUFF ?= .o
85TOOL_GXX32_CFLAGS ?=
86TOOL_GXX32_CFLAGS.debug ?= -g
87TOOL_GXX32_CFLAGS.profile ?= -O2 #-g -pg
88TOOL_GXX32_CFLAGS.release ?= -O2
89TOOL_GXX32_CINCS ?=
90TOOL_GXX32_CDEFS ?=
91
92TOOL_GXX32_CXXOBJSUFF ?= .o
93TOOL_GXX32_CXXFLAGS ?=
94TOOL_GXX32_CXXFLAGS.debug ?= -g
95TOOL_GXX32_CXXFLAGS.profile ?= -O2 #-g -pg
96TOOL_GXX32_CXXFLAGS.release ?= -O2
97TOOL_GXX32_CXXINCS ?=
98TOOL_GXX32_CXXDEFS ?=
99
100TOOL_GXX32_PCHOBJSUFF ?= .h.gch
101TOOL_GXX32_PCHFLAGS ?= $(TOOL_GXX32_CXXFLAGS)
102TOOL_GXX32_PCHFLAGS.debug ?= $(TOOL_GXX32_CXXFLAGS.debug)
103TOOL_GXX32_PCHFLAGS.profile ?= $(TOOL_GXX32_CXXFLAGS.profile)
104TOOL_GXX32_PCHFLAGS.release ?= $(TOOL_GXX32_CXXFLAGS.release)
105TOOL_GXX32_PCHINCS ?= $(TOOL_GXX32_CXXINCS)
106TOOL_GXX32_PCHDEFS ?= $(TOOL_GXX32_CXXDEFS)
107
108TOOL_GXX32_ASFLAGS ?= -x assembler-with-cpp
109TOOL_GXX32_ASFLAGS.debug ?= -g
110TOOL_GXX32_ASFLAGS.profile ?= -g
111TOOL_GXX32_ASOBJSUFF ?= .o
112
113TOOL_GXX32_ARFLAGS ?= cr
114TOOL_GXX32_ARLIBSUFF ?= .a
115
116TOOL_GXX32_LDFLAGS ?=
117TOOL_GXX32_LDFLAGS.debug ?= -g
118TOOL_GXX32_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_GXX32_COMPILE_C_DEPEND =
135TOOL_GXX32_COMPILE_C_DEPORD =
136TOOL_GXX32_COMPILE_C_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).i,)
137TOOL_GXX32_COMPILE_C_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
138define TOOL_GXX32_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_GXX32_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_GXX32_CC) -c\
148 $(flags) -fpreprocessed -x c\
149 -o $(obj)\
150 -
151else
152 $(QUIET)$(TOOL_GXX32_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_GXX32_COMPILE_CXX_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).ii,)
175TOOL_GXX32_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
176TOOL_GXX32_COMPILE_CXX_DEPORD =
177TOOL_GXX32_COMPILE_CXX_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
178define TOOL_GXX32_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_GXX32_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_GXX32_CXX) -c\
189 $(flags) -fpreprocessed $(if-expr defined($(target)_PCH_HDR),-fpch-preprocess,) -x c++\
190 -o $(obj)\
191 -
192else
193 $(QUIET)$(TOOL_GXX32_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_GXX32_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
217TOOL_GXX32_COMPILE_PCH_DEPEND =
218TOOL_GXX32_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
219define TOOL_GXX32_COMPILE_PCH_CMDS
220 $(QUIET)$(TOOL_GXX32_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_GXX32_COMPILE_AS_OUTPUT =
244TOOL_GXX32_COMPILE_AS_DEPEND =
245TOOL_GXX32_COMPILE_AS_DEPORD =
246define TOOL_GXX32_COMPILE_AS_CMDS
247 $(QUIET)$(TOOL_GXX32_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_GXX32_LINK_LIBRARY_OUTPUT = $(out).ar-script
266TOOL_GXX32_LINK_LIBRARY_DEPEND = $(othersrc)
267TOOL_GXX32_LINK_LIBRARY_DEPORD =
268define TOOL_GXX32_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,$(filter-out %.def %.imp %.dll,$(othersrc)), 'ADDLIB $(o)')
273 $(if $(filter %.def %.imp %.dll,$(othersrc))\
274 ,$(TOOL_GXX32_AR_IMP) -o $(outbase).imp.a $(filter %.def %.imp %.dll,$(othersrc))\
275 $(NL)$(TAB)$(QUIET)$(APPEND) $(out).ar-script 'ADDLIB $(outbase).imp.a')
276 $(QUIET)$(APPEND) $(out).ar-script 'SAVE'
277 $(QUIET)$(APPEND) $(out).ar-script 'END'
278 $(QUIET)$(REDIRECT) -rti $(out).ar-script -- $(TOOL_GXX32_AR) -M
279endef
280
281
282## Link program
283# @param $(target) Normalized main target name.
284# @param $(out) Program name.
285# @param $(objs) Object files to link together.
286# @param $(libs) Libraries to search.
287# @param $(libpath) Library search paths.
288# @param $(flags) Flags.
289# @param $(dirdep) Directory creation dependency.
290# @param $(deps) Other dependencies.
291# @param $(othersrc) Unhandled sources.
292# @param $(custom_pre) Custom step invoked before linking.
293# @param $(custom_post) Custom step invoked after linking.
294# @param $(outbase) Output basename (full). Use this for list files and such.
295TOOL_GXX32_LINK_PROGRAM_OUTPUT =
296TOOL_GXX32_LINK_PROGRAM_OUTPUT_MAYBE = $(outbase).map
297TOOL_GXX32_LINK_PROGRAM_OUTPUT_DEBUG = $(outbase).debug
298TOOL_GXX32_LINK_PROGRAM_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
299TOOL_GXX32_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
300 $(filter %.def, $(othersrc))
301TOOL_GXX32_LINK_PROGRAM_DEPORD =
302define TOOL_GXX32_LINK_PROGRAM_CMDS
303 $(QUIET)$(TOOL_GXX32_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_GXX32_LD_MAP,$(outbase).map)
307 ifeq ($(ld_debug),split)
308 $(QUIET)$(TOOL_GXX32_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
309 $(QUIET)$(CHMOD) a-x $(outbase).debug
310 $(QUIET)$(TOOL_GXX32_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_GXX32_LINK_DLL_OUTPUT =
329TOOL_GXX32_LINK_DLL_OUTPUT_MAYBE = $(outbase).map
330TOOL_GXX32_LINK_DLL_OUTPUT_DEBUG = $(outbase).debug
331TOOL_GXX32_LINK_DLL_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
332TOOL_GXX32_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
333 $(filter %.def, $(othersrc))
334TOOL_GXX32_LINK_DLL_DEPORD =
335define TOOL_GXX32_LINK_DLL_CMDS
336 $(QUIET)$(TOOL_GXX32_LD) $(TOOL_GXX32_LDFLAGS.dll) $(flags) -o $(out)\
337 $(if $(filter-out win os2, $(KBUILD_TARGET)),$(call TOOL_GXX32_LD_SONAME,$(target),$(out)))\
338 $(filter-out %.h.gch,$(objs))\
339 $(foreach p,$(libpath), -L$(p))\
340 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
341 $(call TOOL_GXX32_LD_MAP,$(outbase).map)
342 ifeq ($(ld_debug),split)
343 $(QUIET)$(TOOL_GXX32_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
344 $(QUIET)$(CHMOD) a-x $(outbase).debug
345 $(QUIET)$(TOOL_GXX32_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
346 endif
347endef
348
349
350## Link system module (windows aka driver, linux aka kernel module)
351# @param $(target) Normalized main target name.
352# @param $(out) System module name.
353# @param $(objs) Object files to link together.
354# @param $(libs) Libraries to search.
355# @param $(libpath) Library search paths.
356# @param $(flags) Flags.
357# @param $(dirdep) Directory creation dependency.
358# @param $(deps) Other dependencies.
359# @param $(othersrc) Unhandled sources.
360# @param $(custom_pre) Custom step invoked before linking.
361# @param $(custom_post) Custom step invoked after linking.
362# @param $(outbase) Output basename (full). Use this for list files and such.
363TOOL_GXX32_LINK_SYSMOD_OUTPUT =
364TOOL_GXX32_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).map
365TOOL_GXX32_LINK_SYSMOD_OUTPUT_DEBUG = $(outbase).debug
366TOOL_GXX32_LINK_SYSMOD_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
367TOOL_GXX32_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
368 $(filter %.def, $(othersrc))
369TOOL_GXX32_LINK_SYSMOD_DEPORD =
370define TOOL_GXX32_LINK_SYSMOD_CMDS
371 $(QUIET)$(TOOL_GXX32_LD_SYSMOD) $(TOOL_GXX32_LDFLAGS.sysmod) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
372 $(filter %.def, $(othersrc))\
373 $(foreach p,$(libpath), -L$(p))\
374 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
375 $(call TOOL_GXX32_LD_SYSMOD_MAP,$(outbase).map)
376 ifeq ($(ld_debug),split)
377 $(QUIET)$(TOOL_GXX32_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
378 $(QUIET)$(CHMOD) a-x $(outbase).debug
379 $(QUIET)$(TOOL_GXX32_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
380 endif
381endef
382
Note: See TracBrowser for help on using the repository browser.