source: trunk/kBuild/tools/GXX32.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.4 KB
Line 
1# $Id: GXX32.kmk 3258 2019-01-03 05:34:09Z 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
38TOOL_GXX32_CC ?= gcc$(HOSTSUFF_EXE) -m32
39TOOL_GXX32_CXX ?= g++$(HOSTSUFF_EXE) -m32
40TOOL_GXX32_PCH ?= $(TOOL_GXX32_CXX)
41TOOL_GXX32_AS ?= gcc$(HOSTSUFF_EXE) -m32
42TOOL_GXX32_AR ?= ar$(HOSTSUFF_EXE)
43TOOL_GXX32_LD ?= g++$(HOSTSUFF_EXE) -m32
44TOOL_GXX32_LD_SYSMOD ?= ld$(HOSTSUFF_EXE)
45ifndef TOOL_GXX32_LDFLAGS.$(KBUILD_TARGET)
46TOOL_GXX32_LDFLAGS.dll ?= -shared
47else
48TOOL_GXX32_LDFLAGS.dll ?= $(TOOL_GXX32_LDFLAGS.$(KBUILD_TARGET))
49endif
50TOOL_GXX32_LDFLAGS.sysmod ?= -r -m elf_i386$(if-expr "$(KBUILD_TARGET)" == "freebsd" || "$(KBUILD_TARGET)" == "gnukfbsd",_fbsd,)
51TOOL_GXX32_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_GXX32_LD_MAP ?= -Zmap=$(1)
54else
55TOOL_GXX32_LD_MAP ?=
56endif
57ifeq ($(KBUILD_TARGET),os2)
58TOOL_GXX32_LD_SYSMOD_MAP ?= -Zmap=$(1)
59else
60TOOL_GXX32_LD_SYSMOD_MAP ?=
61endif
62if1of ($(KBUILD_HOST), solaris)
63 TOOL_GXX32_OBJCOPY ?= gobjcopy$(HOSTSUFF_EXE)
64else
65 TOOL_GXX32_OBJCOPY ?= objcopy$(HOSTSUFF_EXE)
66endif
67
68ifdef SLKRUNS
69 TOOL_GXX32_CC += -fmessage-length=0
70 TOOL_GXX32_CXX += -fmessage-length=0
71endif
72
73# General Properties used by kBuild
74TOOL_GXX32_COBJSUFF ?= .o
75TOOL_GXX32_CFLAGS ?=
76TOOL_GXX32_CFLAGS.debug ?= -g
77TOOL_GXX32_CFLAGS.profile ?= -O2 #-g -pg
78TOOL_GXX32_CFLAGS.release ?= -O2
79TOOL_GXX32_CINCS ?=
80TOOL_GXX32_CDEFS ?=
81
82TOOL_GXX32_CXXOBJSUFF ?= .o
83TOOL_GXX32_CXXFLAGS ?=
84TOOL_GXX32_CXXFLAGS.debug ?= -g
85TOOL_GXX32_CXXFLAGS.profile ?= -O2 #-g -pg
86TOOL_GXX32_CXXFLAGS.release ?= -O2
87TOOL_GXX32_CXXINCS ?=
88TOOL_GXX32_CXXDEFS ?=
89
90TOOL_GXX32_PCHOBJSUFF ?= .h.gch
91TOOL_GXX32_PCHFLAGS ?= $(TOOL_GXX32_CXXFLAGS)
92TOOL_GXX32_PCHFLAGS.debug ?= $(TOOL_GXX32_CXXFLAGS.debug)
93TOOL_GXX32_PCHFLAGS.profile ?= $(TOOL_GXX32_CXXFLAGS.profile)
94TOOL_GXX32_PCHFLAGS.release ?= $(TOOL_GXX32_CXXFLAGS.release)
95TOOL_GXX32_PCHINCS ?= $(TOOL_GXX32_CXXINCS)
96TOOL_GXX32_PCHDEFS ?= $(TOOL_GXX32_CXXDEFS)
97
98TOOL_GXX32_ASFLAGS ?= -x assembler-with-cpp
99TOOL_GXX32_ASFLAGS.debug ?= -g
100TOOL_GXX32_ASFLAGS.profile ?= -g
101TOOL_GXX32_ASOBJSUFF ?= .o
102
103TOOL_GXX32_ARFLAGS ?= cr
104TOOL_GXX32_ARLIBSUFF ?= .a
105
106TOOL_GXX32_LDFLAGS ?=
107TOOL_GXX32_LDFLAGS.debug ?= -g
108TOOL_GXX32_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_GXX32_COMPILE_C_DEPEND =
125TOOL_GXX32_COMPILE_C_DEPORD =
126TOOL_GXX32_COMPILE_C_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).i,)
127TOOL_GXX32_COMPILE_C_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
128define TOOL_GXX32_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_GXX32_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_GXX32_CC) -c\
138 $(flags) -fpreprocessed -x c\
139 -o $(obj)\
140 -
141else
142 $(QUIET)$(TOOL_GXX32_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_GXX32_COMPILE_CXX_OUTPUT = $(if-expr "$(use_objcache)" != "",$(outbase).ii,)
165TOOL_GXX32_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
166TOOL_GXX32_COMPILE_CXX_DEPORD =
167TOOL_GXX32_COMPILE_CXX_USES_KOBJCACHE = $(if-expr "$(use_objcache)" != "",1,)
168define TOOL_GXX32_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_GXX32_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_GXX32_CXX) -c\
179 $(flags) -fpreprocessed $(if-expr defined($(target)_PCH_HDR),-fpch-preprocess,) -x c++\
180 -o $(obj)\
181 -
182else
183 $(QUIET)$(TOOL_GXX32_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_GXX32_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
207TOOL_GXX32_COMPILE_PCH_DEPEND =
208TOOL_GXX32_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
209define TOOL_GXX32_COMPILE_PCH_CMDS
210 $(QUIET)$(TOOL_GXX32_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_GXX32_COMPILE_AS_OUTPUT =
234TOOL_GXX32_COMPILE_AS_DEPEND =
235TOOL_GXX32_COMPILE_AS_DEPORD =
236define TOOL_GXX32_COMPILE_AS_CMDS
237 $(QUIET)$(TOOL_GXX32_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_GXX32_LINK_LIBRARY_OUTPUT = $(out).ar-script
256TOOL_GXX32_LINK_LIBRARY_DEPEND = $(othersrc)
257TOOL_GXX32_LINK_LIBRARY_DEPORD =
258define TOOL_GXX32_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,$(filter-out %.def %.imp %.dll,$(othersrc)), 'ADDLIB $(o)')
263 $(if $(filter %.def %.imp %.dll,$(othersrc))\
264 ,$(TOOL_GXX32_AR_IMP) -o $(outbase).imp.a $(filter %.def %.imp %.dll,$(othersrc))\
265 $(NL)$(TAB)$(QUIET)$(APPEND) $(out).ar-script 'ADDLIB $(outbase).imp.a')
266 $(QUIET)$(APPEND) $(out).ar-script 'SAVE'
267 $(QUIET)$(APPEND) $(out).ar-script 'END'
268 $(QUIET)$(REDIRECT) -rti $(out).ar-script -- $(TOOL_GXX32_AR) -M
269endef
270
271
272## Link program
273# @param $(target) Normalized main target name.
274# @param $(out) Program name.
275# @param $(objs) Object files to link together.
276# @param $(libs) Libraries to search.
277# @param $(libpath) Library search paths.
278# @param $(flags) Flags.
279# @param $(dirdep) Directory creation dependency.
280# @param $(deps) Other dependencies.
281# @param $(othersrc) Unhandled sources.
282# @param $(custom_pre) Custom step invoked before linking.
283# @param $(custom_post) Custom step invoked after linking.
284# @param $(outbase) Output basename (full). Use this for list files and such.
285TOOL_GXX32_LINK_PROGRAM_OUTPUT =
286TOOL_GXX32_LINK_PROGRAM_OUTPUT_MAYBE = $(outbase).map
287TOOL_GXX32_LINK_PROGRAM_OUTPUT_DEBUG = $(outbase).debug
288TOOL_GXX32_LINK_PROGRAM_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
289TOOL_GXX32_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
290 $(filter %.def, $(othersrc))
291TOOL_GXX32_LINK_PROGRAM_DEPORD =
292define TOOL_GXX32_LINK_PROGRAM_CMDS
293 $(QUIET)$(TOOL_GXX32_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
294 $(foreach p,$(libpath), -L$(p))\
295 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
296 $(call TOOL_GXX32_LD_MAP,$(outbase).map)
297 ifeq ($(ld_debug),split)
298 $(QUIET)$(TOOL_GXX32_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
299 $(QUIET)$(CHMOD) a-x $(outbase).debug
300 $(QUIET)$(TOOL_GXX32_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
301 endif
302endef
303
304
305## Link DLL
306# @param $(target) Normalized main target name.
307# @param $(out) Program name.
308# @param $(objs) Object files to link together.
309# @param $(libs) Libraries to search.
310# @param $(libpath) Library search paths.
311# @param $(flags) Flags.
312# @param $(dirdep) Directory creation dependency.
313# @param $(deps) Other dependencies.
314# @param $(othersrc) Unhandled sources.
315# @param $(custom_pre) Custom step invoked before linking.
316# @param $(custom_post) Custom step invoked after linking.
317# @param $(outbase) Output basename (full). Use this for list files and such.
318TOOL_GXX32_LINK_DLL_OUTPUT =
319TOOL_GXX32_LINK_DLL_OUTPUT_MAYBE = $(outbase).map
320TOOL_GXX32_LINK_DLL_OUTPUT_DEBUG = $(outbase).debug
321TOOL_GXX32_LINK_DLL_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
322TOOL_GXX32_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
323 $(filter %.def, $(othersrc))
324TOOL_GXX32_LINK_DLL_DEPORD =
325define TOOL_GXX32_LINK_DLL_CMDS
326 $(QUIET)$(TOOL_GXX32_LD) $(TOOL_GXX32_LDFLAGS.dll) $(flags) -o $(out)\
327 $(if $(filter-out win os2, $(KBUILD_TARGET)),$(call TOOL_GXX32_LD_SONAME,$(target),$(out)))\
328 $(filter-out %.h.gch,$(objs))\
329 $(foreach p,$(libpath), -L$(p))\
330 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
331 $(call TOOL_GXX32_LD_MAP,$(outbase).map)
332 ifeq ($(ld_debug),split)
333 $(QUIET)$(TOOL_GXX32_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
334 $(QUIET)$(CHMOD) a-x $(outbase).debug
335 $(QUIET)$(TOOL_GXX32_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
336 endif
337endef
338
339
340## Link system module (windows aka driver, linux aka kernel module)
341# @param $(target) Normalized main target name.
342# @param $(out) System module name.
343# @param $(objs) Object files to link together.
344# @param $(libs) Libraries to search.
345# @param $(libpath) Library search paths.
346# @param $(flags) Flags.
347# @param $(dirdep) Directory creation dependency.
348# @param $(deps) Other dependencies.
349# @param $(othersrc) Unhandled sources.
350# @param $(custom_pre) Custom step invoked before linking.
351# @param $(custom_post) Custom step invoked after linking.
352# @param $(outbase) Output basename (full). Use this for list files and such.
353TOOL_GXX32_LINK_SYSMOD_OUTPUT =
354TOOL_GXX32_LINK_SYSMOD_OUTPUT_MAYBE = $(outbase).map
355TOOL_GXX32_LINK_SYSMOD_OUTPUT_DEBUG = $(outbase).debug
356TOOL_GXX32_LINK_SYSMOD_DEBUG_INSTALL_FN = $(2).debug=>$(basename $(3)).debug
357TOOL_GXX32_LINK_SYSMOD_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))\
358 $(filter %.def, $(othersrc))
359TOOL_GXX32_LINK_SYSMOD_DEPORD =
360define TOOL_GXX32_LINK_SYSMOD_CMDS
361 $(QUIET)$(TOOL_GXX32_LD_SYSMOD) $(TOOL_GXX32_LDFLAGS.sysmod) $(flags) -o $(out) $(filter-out %.h.gch,$(objs))\
362 $(filter %.def, $(othersrc))\
363 $(foreach p,$(libpath), -L$(p))\
364 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))\
365 $(call TOOL_GXX32_LD_SYSMOD_MAP,$(outbase).map)
366 ifeq ($(ld_debug),split)
367 $(QUIET)$(TOOL_GXX32_OBJCOPY) --only-keep-debug $(out) $(outbase).debug
368 $(QUIET)$(CHMOD) a-x $(outbase).debug
369 $(QUIET)$(TOOL_GXX32_OBJCOPY) --strip-debug --strip-unneeded --add-gnu-debuglink=$(outbase).debug $(out)
370 endif
371endef
372
Note: See TracBrowser for help on using the repository browser.