source: trunk/kBuild/tools/GXX.kmk@ 3393

Last change on this file since 3393 was 3393, checked in by bird, 5 years ago

tools/*GCC|GXX*: More prefix/suffix stuff. Separate for gcc/g++, binutils and other stuff.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.9 KB
Line 
1# $Id: GXX.kmk 3393 2020-06-30 17:11:42Z bird $
2## @file
3# kBuild Tool Config - Generic GCC 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_GXX := Generic GCC using the system GCC, for building C++ code.
35
36# Tool Specific Properties
37ifndef TOOL_GXX_PREFIX
38 TOOL_GXX_PREFIX :=
39endif
40ifndef TOOL_GXX_SUFFIX
41 TOOL_GXX_SUFFIX := $(HOSTSUFF_EXE)
42endif
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)
58TOOL_GXX_LDFLAGS.dll.os2 ?= -Zdll
59TOOL_GXX_LDFLAGS.dll.darwin ?= -dynamiclib
60ifndef TOOL_GXX_LDFLAGS.$(KBUILD_TARGET)
61 TOOL_GXX_LDFLAGS.dll ?= -shared
62else
63 TOOL_GXX_LDFLAGS.dll ?= $(TOOL_GXX_LDFLAGS.$(KBUILD_TARGET))
64endif
65
66# General Properties used by kBuild
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 ?=
74
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 ?=
83
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
92TOOL_GXX_ASFLAGS ?= -x assembler-with-cpp
93TOOL_GXX_ASFLAGS.debug ?= -g
94TOOL_GXX_ASFLAGS.profile ?= -g
95TOOL_GXX_ASOBJSUFF ?= .o
96
97TOOL_GXX_ARFLAGS ?= cr
98TOOL_GXX_ARLIBSUFF ?= .a
99
100TOOL_GXX_LDFLAGS ?=
101TOOL_GXX_LDFLAGS.debug ?= -g
102TOOL_GXX_LDFLAGS.profile ?= -g
103
104
105## Compile C source.
106# @param $(target) Normalized main target name.
107# @param $(source) Source filename (relative).
108# @param $(obj) Object file name. This shall be (re)created by the compilation.
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.
113# @param $(dirdep) Directory creation dependency.
114# @param $(deps) Other dependencies.
115# @param $(outbase) Output basename (full). Use this for list files and such.
116# @param $(objsuff) Object suffix.
117#
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\
123 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
124 -Wp,-MD,$(dep) -Wp,-MT,$(obj) \
125 -o $(obj)\
126 $(abspath $(source))
127 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
128endef
129
130
131## Compile C++ source.
132# @param $(target) Normalized main target name.
133# @param $(source) Source filename (relative).
134# @param $(obj) Object file name. This shall be (re)created by the compilation.
135# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
136# @param $(flags) Flags.
137# @param $(defs) Definitions. No -D or something.
138# @param $(incs) Includes. No -I or something.
139# @param $(dirdep) Directory creation dependency.
140# @param $(deps) Other dependencies.
141#
142# @param $(outbase) Output basename (full). Use this for list files and such.
143# @param $(objsuff) Object suffix.
144TOOL_GXX_COMPILE_CXX_OUTPUT =
145TOOL_GXX_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
146TOOL_GXX_COMPILE_CXX_DEPORD =
147define TOOL_GXX_COMPILE_CXX_CMDS
148 $(QUIET)$(TOOL_GXX_CXX) -c\
149 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -D, $(defs))\
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\
175 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -D, $(defs))\
176 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
177 -o $(obj)\
178 $(abspath $(source))
179 $(INSTALL) --hard-link-files-when-possible -m 0644 -- "$(obj)" "$($(target)_1_GCC_PCH_FILE)"
180 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
181endef
182
183
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#
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\
202 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
203 -Wp,-MD,$(dep) -Wp,-MT,$(obj) \
204 -o $(obj)\
205 $(abspath $(source))
206 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
207endef
208
209
210## Link library
211# @param $(target) Normalized main target name.
212# @param $(out) Library name.
213# @param $(objs) Object files to put in the library.
214# @param $(flags) Flags.
215# @param $(dirdep) Directory creation dependency.
216# @param $(deps) Other dependencies.
217#
218# @param $(outbase) Output basename (full). Use this for list files and such.
219TOOL_GXX_LINK_LIBRARY_OUTPUT =
220TOOL_GXX_LINK_LIBRARY_DEPEND =
221TOOL_GXX_LINK_LIBRARY_DEPORD =
222define TOOL_GXX_LINK_LIBRARY_CMDS
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)))
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/ \
230 && $(TOOL_GXX_AR) x $(abspath $(lib)) \
231 && $(TOOL_GXX_AR) $(flags) $(out) *) \
232 $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))/ar.tmp.dir/* \
233 $(NL)$(TAB)$(QUIET)$(RMDIR) $(dir $(outbase))ar.tmp.dir/)
234 $(QUIET)$(TOOL_GXX_RANLIB) $(out)
235endef
236
237
238## Link program
239# @param $(target) Normalized main target name.
240# @param $(out) Program name.
241# @param $(objs) Object files to link together.
242# @param $(libs) Libraries to search.
243# @param $(libpath) Library search paths.
244# @param $(flags) Flags.
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.
250#
251# @param $(outbase) Output basename (full). Use this for list files and such.
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
256 $(QUIET)$(TOOL_GXX_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs)) \
257 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))
258endef
259
260
261## Link DLL
262# @param $(target) Normalized main target name.
263# @param $(out) Program name.
264# @param $(objs) Object files to link together.
265# @param $(libs) Libraries to search.
266# @param $(libpath) Library search paths.
267# @param $(flags) Flags.
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.
273# @param $(outbase) Output basename (full). Use this for list files and such.
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
278 $(QUIET)$(TOOL_GXX_LD) $(TOOL_GXX_LDFLAGS.dll) $(flags) -o $(out) $(filter-out %.h.gch,$(objs)) \
279 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))
280endef
281
Note: See TracBrowser for help on using the repository browser.