source: trunk/kBuild/tools/GXX.kmk

Last change on this file was 3566, checked in by bird, 3 years ago

tools/G*.kmk,header.kmk: Use qaddprefix in sh-mode for -D and -I processing, just like VCC14*.kmk does. Forced update of header.kmk so KMK_REVISION can be used to detect the changes.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
RevLine 
[72]1# $Id: GXX.kmk 3566 2022-06-13 15:37:08Z bird $
2## @file
[971]3# kBuild Tool Config - Generic GCC using the system GCC, for building C++ code.
[72]4#
[1547]5
6#
[3121]7# Copyright (c) 2004-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
[72]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#
[1547]26# As a special exception you are granted permission to include this file, via
[2243]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.
[1547]29# This exception does not however invalidate any other reasons why the makefile,
30# program, whatever should not be covered the GPL.
31#
32#
[72]33
[971]34TOOL_GXX := Generic GCC using the system GCC, for building C++ code.
[72]35
[667]36# Tool Specific Properties
[3391]37ifndef TOOL_GXX_PREFIX
[3393]38 TOOL_GXX_PREFIX :=
[3391]39endif
40ifndef TOOL_GXX_SUFFIX
[3393]41 TOOL_GXX_SUFFIX := $(HOSTSUFF_EXE)
[3391]42endif
[3393]43if1of ($(KBUILD_HOST), solaris)
44 TOOL_GXX_PREFIX2 ?= g
45else
46 TOOL_GXX_PREFIX2 ?=
47endif
48TOOL_GXX_SUFFIX2 ?= $(HOSTSUFF_EXE)
49TOOL_GXX_PREFIX3 ?=
50TOOL_GXX_SUFFIX3 ?= $(HOSTSUFF_EXE)
51TOOL_GXX_CC ?= $(TOOL_GXX_PREFIX)gcc$(TOOL_GXX_SUFFIX)
52TOOL_GXX_CXX ?= $(TOOL_GXX_PREFIX)g++$(TOOL_GXX_SUFFIX)
53TOOL_GXX_PCH ?= $(TOOL_GXX_CXX)
54TOOL_GXX_AS ?= $(TOOL_GXX_PREFIX)gcc$(TOOL_GXX_SUFFIX)
55TOOL_GXX_AR ?= $(TOOL_GXX_PREFIX2)ar$(TOOL_GXX_SUFFIX2)
56TOOL_GXX_RANLIB ?= $(TOOL_GXX_PREFIX2)ranlib$(TOOL_GXX_SUFFIX2)
57TOOL_GXX_LD ?= $(TOOL_GXX_PREFIX)g++$(TOOL_GXX_SUFFIX)
[3391]58TOOL_GXX_LDFLAGS.dll.os2 ?= -Zdll
[971]59TOOL_GXX_LDFLAGS.dll.darwin ?= -dynamiclib
[1504]60ifndef TOOL_GXX_LDFLAGS.$(KBUILD_TARGET)
[3391]61 TOOL_GXX_LDFLAGS.dll ?= -shared
[667]62else
[3391]63 TOOL_GXX_LDFLAGS.dll ?= $(TOOL_GXX_LDFLAGS.$(KBUILD_TARGET))
[667]64endif
[73]65
[667]66# General Properties used by kBuild
[971]67TOOL_GXX_COBJSUFF ?= .o
68TOOL_GXX_CFLAGS ?=
69TOOL_GXX_CFLAGS.debug ?= -g
70TOOL_GXX_CFLAGS.profile ?= -g -O2 #-pg
71TOOL_GXX_CFLAGS.release ?= -O2
72TOOL_GXX_CINCS ?=
73TOOL_GXX_CDEFS ?=
[72]74
[971]75TOOL_GXX_CXXOBJSUFF ?= .o
76TOOL_GXX_CXXOBJSUFF ?= .o
77TOOL_GXX_CXXFLAGS ?=
78TOOL_GXX_CXXFLAGS.debug ?= -g -O0
79TOOL_GXX_CXXFLAGS.profile ?= -g -O2 #-pg
80TOOL_GXX_CXXFLAGS.release ?= -O2
81TOOL_GXX_CXXINCS ?=
82TOOL_GXX_CXXDEFS ?=
[72]83
[3257]84TOOL_GXX_PCHOBJSUFF ?= .h.gch
85TOOL_GXX_PCHFLAGS ?= $(TOOL_GXX_CXXFLAGS)
86TOOL_GXX_PCHFLAGS.debug ?= $(TOOL_GXX_CXXFLAGS.debug)
87TOOL_GXX_PCHFLAGS.profile ?= $(TOOL_GXX_CXXFLAGS.profile)
88TOOL_GXX_PCHFLAGS.release ?= $(TOOL_GXX_CXXFLAGS.release)
89TOOL_GXX_PCHINCS ?= $(TOOL_GXX_CXXINCS)
90TOOL_GXX_PCHDEFS ?= $(TOOL_GXX_CXXDEFS)
91
[971]92TOOL_GXX_ASFLAGS ?= -x assembler-with-cpp
93TOOL_GXX_ASFLAGS.debug ?= -g
94TOOL_GXX_ASFLAGS.profile ?= -g
95TOOL_GXX_ASOBJSUFF ?= .o
[73]96
[971]97TOOL_GXX_ARFLAGS ?= cr
98TOOL_GXX_ARLIBSUFF ?= .a
[73]99
[971]100TOOL_GXX_LDFLAGS ?=
101TOOL_GXX_LDFLAGS.debug ?= -g
102TOOL_GXX_LDFLAGS.profile ?= -g
[73]103
[74]104
[72]105## Compile C source.
[73]106# @param $(target) Normalized main target name.
107# @param $(source) Source filename (relative).
[235]108# @param $(obj) Object file name. This shall be (re)created by the compilation.
[73]109# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
110# @param $(flags) Flags.
111# @param $(defs) Definitions. No -D or something.
112# @param $(incs) Includes. No -I or something.
[235]113# @param $(dirdep) Directory creation dependency.
114# @param $(deps) Other dependencies.
[73]115# @param $(outbase) Output basename (full). Use this for list files and such.
[235]116# @param $(objsuff) Object suffix.
[380]117#
[971]118TOOL_GXX_COMPILE_C_OUTPUT =
119TOOL_GXX_COMPILE_C_DEPEND =
120TOOL_GXX_COMPILE_C_DEPORD =
121define TOOL_GXX_COMPILE_C_CMDS
122 $(QUIET)$(TOOL_GXX_CC) -c\
[3566]123 $(flags) $(qaddprefix sh,-I, $(incs)) $(qaddprefix sh,-D, $(defs))\
[846]124 -Wp,-MD,$(dep) -Wp,-MT,$(obj) \
125 -o $(obj)\
[697]126 $(abspath $(source))
[2431]127 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
[72]128endef
129
[73]130
[77]131## Compile C++ source.
132# @param $(target) Normalized main target name.
133# @param $(source) Source filename (relative).
[235]134# @param $(obj) Object file name. This shall be (re)created by the compilation.
[3257]135# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
[77]136# @param $(flags) Flags.
137# @param $(defs) Definitions. No -D or something.
138# @param $(incs) Includes. No -I or something.
[235]139# @param $(dirdep) Directory creation dependency.
[3257]140# @param $(deps) Other dependencies.
[77]141#
142# @param $(outbase) Output basename (full). Use this for list files and such.
[235]143# @param $(objsuff) Object suffix.
[971]144TOOL_GXX_COMPILE_CXX_OUTPUT =
[3257]145TOOL_GXX_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
[971]146TOOL_GXX_COMPILE_CXX_DEPORD =
147define TOOL_GXX_COMPILE_CXX_CMDS
148 $(QUIET)$(TOOL_GXX_CXX) -c\
[3566]149 $(flags) $(qaddprefix sh,-I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(qaddprefix sh,-D, $(defs))\
[3257]150 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
151 -o $(obj) $(if-expr defined($(target)_PCH_HDR) \
152 ,-Winvalid-pch -include $(basename $($(target)_1_GCC_PCH_FILE)),) \
153 $(abspath $(source))
154 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
155endef
156
157
158## Precompile C++ header.
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_GXX_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
171TOOL_GXX_COMPILE_PCH_DEPEND =
172TOOL_GXX_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
173define TOOL_GXX_COMPILE_PCH_CMDS
174 $(QUIET)$(TOOL_GXX_PCH) -c\
[3566]175 $(flags) $(qaddprefix sh,-I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(qaddprefix sh,-D, $(defs))\
[3257]176 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
[846]177 -o $(obj)\
[697]178 $(abspath $(source))
[3257]179 $(INSTALL) --hard-link-files-when-possible -m 0644 -- "$(obj)" "$($(target)_1_GCC_PCH_FILE)"
[2431]180 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
[77]181endef
182
183
[465]184## Compile Assembly source.
185# @param $(target) Normalized main target name.
186# @param $(source) Source filename (relative).
187# @param $(obj) Object file name. This shall be (re)created by the compilation.
188# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
189# @param $(flags) Flags.
190# @param $(defs) Definitions. No -D or something.
191# @param $(incs) Includes. No -I or something.
192# @param $(dirdep) Directory creation dependency.
193# @param $(deps) Other dependencies.
194# @param $(outbase) Output basename (full). Use this for list files and such.
195# @param $(objsuff) Object suffix.
196#
[971]197TOOL_GXX_COMPILE_AS_OUTPUT =
198TOOL_GXX_COMPILE_AS_DEPEND =
199TOOL_GXX_COMPILE_AS_DEPORD =
200define TOOL_GXX_COMPILE_AS_CMDS
201 $(QUIET)$(TOOL_GXX_AS) -c\
[3566]202 $(flags) $(qaddprefix sh,-I, $(incs)) $(qaddprefix sh,-D, $(defs))\
[846]203 -Wp,-MD,$(dep) -Wp,-MT,$(obj) \
204 -o $(obj)\
[697]205 $(abspath $(source))
[2431]206 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
[465]207endef
208
209
[73]210## Link library
211# @param $(target) Normalized main target name.
[380]212# @param $(out) Library name.
[73]213# @param $(objs) Object files to put in the library.
214# @param $(flags) Flags.
[235]215# @param $(dirdep) Directory creation dependency.
216# @param $(deps) Other dependencies.
[73]217#
218# @param $(outbase) Output basename (full). Use this for list files and such.
[971]219TOOL_GXX_LINK_LIBRARY_OUTPUT =
220TOOL_GXX_LINK_LIBRARY_DEPEND =
221TOOL_GXX_LINK_LIBRARY_DEPORD =
222define TOOL_GXX_LINK_LIBRARY_CMDS
[3257]223 $(QUIET)$(TOOL_GXX_AR) $(flags) $(out) $(filter-out %.h.gch,$(objs))
224 $(call xargs,$(QUIET)$(TOOL_GXX_AR) $(flags) $(out),$(filter-out %.h.gch,$(objs)))
[846]225 $(foreach lib,$(othersrc)\
226 ,$(NL)$(TAB)$(call MSG_AR_MERGE,$(target),$(out),$(lib)) \
227 $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))ar.tmp.dir/* \
228 $(NL)$(TAB)$(QUIET)$(MKDIR) -p $(dir $(outbase))/ar.tmp.dir/ \
229 $(NL)$(TAB)$(QUIET)(cd $(dir $(outbase))ar.tmp.dir/ \
[971]230 && $(TOOL_GXX_AR) x $(abspath $(lib)) \
231 && $(TOOL_GXX_AR) $(flags) $(out) *) \
[846]232 $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))/ar.tmp.dir/* \
233 $(NL)$(TAB)$(QUIET)$(RMDIR) $(dir $(outbase))ar.tmp.dir/)
[971]234 $(QUIET)$(TOOL_GXX_RANLIB) $(out)
[73]235endef
236
[74]237
238## Link program
239# @param $(target) Normalized main target name.
[353]240# @param $(out) Program name.
[74]241# @param $(objs) Object files to link together.
242# @param $(libs) Libraries to search.
243# @param $(libpath) Library search paths.
244# @param $(flags) Flags.
[235]245# @param $(dirdep) Directory creation dependency.
246# @param $(deps) Other dependencies.
247# @param $(othersrc) Unhandled sources.
248# @param $(custom_pre) Custom step invoked before linking.
249# @param $(custom_post) Custom step invoked after linking.
[74]250#
251# @param $(outbase) Output basename (full). Use this for list files and such.
[971]252TOOL_GXX_LINK_PROGRAM_OUTPUT =
253TOOL_GXX_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
254TOOL_GXX_LINK_PROGRAM_DEPORD =
255define TOOL_GXX_LINK_PROGRAM_CMDS
[3257]256 $(QUIET)$(TOOL_GXX_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs)) \
[1259]257 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))
[74]258endef
259
[130]260
[353]261## Link DLL
[130]262# @param $(target) Normalized main target name.
[353]263# @param $(out) Program name.
[130]264# @param $(objs) Object files to link together.
265# @param $(libs) Libraries to search.
266# @param $(libpath) Library search paths.
267# @param $(flags) Flags.
[235]268# @param $(dirdep) Directory creation dependency.
269# @param $(deps) Other dependencies.
270# @param $(othersrc) Unhandled sources.
271# @param $(custom_pre) Custom step invoked before linking.
272# @param $(custom_post) Custom step invoked after linking.
[380]273# @param $(outbase) Output basename (full). Use this for list files and such.
[971]274TOOL_GXX_LINK_DLL_OUTPUT =
275TOOL_GXX_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
276TOOL_GXX_LINK_DLL_DEPORD =
277define TOOL_GXX_LINK_DLL_CMDS
[3257]278 $(QUIET)$(TOOL_GXX_LD) $(TOOL_GXX_LDFLAGS.dll) $(flags) -o $(out) $(filter-out %.h.gch,$(objs)) \
[1259]279 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))
[130]280endef
281
Note: See TracBrowser for help on using the repository browser.