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

Last change on this file since 3357 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: 10.4 KB
Line 
1# $Id: GXX.kmk 3257 2019-01-03 02:46:05Z 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
37TOOL_GXX_CC ?= gcc$(HOSTSUFF_EXE)
38TOOL_GXX_CXX ?= g++$(HOSTSUFF_EXE)
39TOOL_GXX_PCH ?= $(TOOL_GXX_CXX)
40TOOL_GXX_AS ?= gcc$(HOSTSUFF_EXE)
41TOOL_GXX_AR ?= ar$(HOSTSUFF_EXE)
42TOOL_GXX_RANLIB ?= ranlib$(HOSTSUFF_EXE)
43TOOL_GXX_LD ?= g++$(HOSTSUFF_EXE)
44TOOL_GXX_LDFLAGS.dll.os2 ?= -Zdll
45TOOL_GXX_LDFLAGS.dll.darwin ?= -dynamiclib
46ifndef TOOL_GXX_LDFLAGS.$(KBUILD_TARGET)
47TOOL_GXX_LDFLAGS.dll ?= -shared
48else
49TOOL_GXX_LDFLAGS.dll ?= $(TOOL_GXX_LDFLAGS.$(KBUILD_TARGET))
50endif
51
52# General Properties used by kBuild
53TOOL_GXX_COBJSUFF ?= .o
54TOOL_GXX_CFLAGS ?=
55TOOL_GXX_CFLAGS.debug ?= -g
56TOOL_GXX_CFLAGS.profile ?= -g -O2 #-pg
57TOOL_GXX_CFLAGS.release ?= -O2
58TOOL_GXX_CINCS ?=
59TOOL_GXX_CDEFS ?=
60
61TOOL_GXX_CXXOBJSUFF ?= .o
62TOOL_GXX_CXXOBJSUFF ?= .o
63TOOL_GXX_CXXFLAGS ?=
64TOOL_GXX_CXXFLAGS.debug ?= -g -O0
65TOOL_GXX_CXXFLAGS.profile ?= -g -O2 #-pg
66TOOL_GXX_CXXFLAGS.release ?= -O2
67TOOL_GXX_CXXINCS ?=
68TOOL_GXX_CXXDEFS ?=
69
70TOOL_GXX_PCHOBJSUFF ?= .h.gch
71TOOL_GXX_PCHFLAGS ?= $(TOOL_GXX_CXXFLAGS)
72TOOL_GXX_PCHFLAGS.debug ?= $(TOOL_GXX_CXXFLAGS.debug)
73TOOL_GXX_PCHFLAGS.profile ?= $(TOOL_GXX_CXXFLAGS.profile)
74TOOL_GXX_PCHFLAGS.release ?= $(TOOL_GXX_CXXFLAGS.release)
75TOOL_GXX_PCHINCS ?= $(TOOL_GXX_CXXINCS)
76TOOL_GXX_PCHDEFS ?= $(TOOL_GXX_CXXDEFS)
77
78TOOL_GXX_ASFLAGS ?= -x assembler-with-cpp
79TOOL_GXX_ASFLAGS.debug ?= -g
80TOOL_GXX_ASFLAGS.profile ?= -g
81TOOL_GXX_ASOBJSUFF ?= .o
82
83TOOL_GXX_ARFLAGS ?= cr
84TOOL_GXX_ARLIBSUFF ?= .a
85
86TOOL_GXX_LDFLAGS ?=
87TOOL_GXX_LDFLAGS.debug ?= -g
88TOOL_GXX_LDFLAGS.profile ?= -g
89
90
91## Compile C source.
92# @param $(target) Normalized main target name.
93# @param $(source) Source filename (relative).
94# @param $(obj) Object file name. This shall be (re)created by the compilation.
95# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
96# @param $(flags) Flags.
97# @param $(defs) Definitions. No -D or something.
98# @param $(incs) Includes. No -I or something.
99# @param $(dirdep) Directory creation dependency.
100# @param $(deps) Other dependencies.
101# @param $(outbase) Output basename (full). Use this for list files and such.
102# @param $(objsuff) Object suffix.
103#
104TOOL_GXX_COMPILE_C_OUTPUT =
105TOOL_GXX_COMPILE_C_DEPEND =
106TOOL_GXX_COMPILE_C_DEPORD =
107define TOOL_GXX_COMPILE_C_CMDS
108 $(QUIET)$(TOOL_GXX_CC) -c\
109 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
110 -Wp,-MD,$(dep) -Wp,-MT,$(obj) \
111 -o $(obj)\
112 $(abspath $(source))
113 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
114endef
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_GXX_COMPILE_CXX_OUTPUT =
131TOOL_GXX_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
132TOOL_GXX_COMPILE_CXX_DEPORD =
133define TOOL_GXX_COMPILE_CXX_CMDS
134 $(QUIET)$(TOOL_GXX_CXX) -c\
135 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -D, $(defs))\
136 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
137 -o $(obj) $(if-expr defined($(target)_PCH_HDR) \
138 ,-Winvalid-pch -include $(basename $($(target)_1_GCC_PCH_FILE)),) \
139 $(abspath $(source))
140 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
141endef
142
143
144## Precompile C++ header.
145# @param $(target) Normalized main target name.
146# @param $(source) Source filename (relative).
147# @param $(obj) Object file name. This shall be (re)created by the compilation.
148# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
149# @param $(flags) Flags.
150# @param $(defs) Definitions. No -D or something.
151# @param $(incs) Includes. No -I or something.
152# @param $(dirdep) Directory creation dependency.
153# @param $(deps) Other dependencies.
154# @param $(outbase) Output basename (full). Use this for list files and such.
155# @param $(objsuff) Object suffix.
156TOOL_GXX_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
157TOOL_GXX_COMPILE_PCH_DEPEND =
158TOOL_GXX_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
159define TOOL_GXX_COMPILE_PCH_CMDS
160 $(QUIET)$(TOOL_GXX_PCH) -c\
161 $(flags) $(addprefix -I, $($(target)_1_GCC_PCH_DIR) $(incs)) $(addprefix -D, $(defs))\
162 -Wp,-MD,$(dep) -Wp,-MT,$(obj) -Wp,-MP\
163 -o $(obj)\
164 $(abspath $(source))
165 $(INSTALL) --hard-link-files-when-possible -m 0644 -- "$(obj)" "$($(target)_1_GCC_PCH_FILE)"
166 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
167endef
168
169
170## Compile Assembly source.
171# @param $(target) Normalized main target name.
172# @param $(source) Source filename (relative).
173# @param $(obj) Object file name. This shall be (re)created by the compilation.
174# @param $(dep) Dependcy file. This shall be (re)created by the compilation.
175# @param $(flags) Flags.
176# @param $(defs) Definitions. No -D or something.
177# @param $(incs) Includes. No -I or something.
178# @param $(dirdep) Directory creation dependency.
179# @param $(deps) Other dependencies.
180# @param $(outbase) Output basename (full). Use this for list files and such.
181# @param $(objsuff) Object suffix.
182#
183TOOL_GXX_COMPILE_AS_OUTPUT =
184TOOL_GXX_COMPILE_AS_DEPEND =
185TOOL_GXX_COMPILE_AS_DEPORD =
186define TOOL_GXX_COMPILE_AS_CMDS
187 $(QUIET)$(TOOL_GXX_AS) -c\
188 $(flags) $(addprefix -I, $(incs)) $(addprefix -D, $(defs))\
189 -Wp,-MD,$(dep) -Wp,-MT,$(obj) \
190 -o $(obj)\
191 $(abspath $(source))
192 $(QUIET)$(APPEND) -n "$(dep)" "" "$(source):" ""
193endef
194
195
196## Link library
197# @param $(target) Normalized main target name.
198# @param $(out) Library name.
199# @param $(objs) Object files to put in the library.
200# @param $(flags) Flags.
201# @param $(dirdep) Directory creation dependency.
202# @param $(deps) Other dependencies.
203#
204# @param $(outbase) Output basename (full). Use this for list files and such.
205TOOL_GXX_LINK_LIBRARY_OUTPUT =
206TOOL_GXX_LINK_LIBRARY_DEPEND =
207TOOL_GXX_LINK_LIBRARY_DEPORD =
208define TOOL_GXX_LINK_LIBRARY_CMDS
209 $(QUIET)$(TOOL_GXX_AR) $(flags) $(out) $(filter-out %.h.gch,$(objs))
210 $(call xargs,$(QUIET)$(TOOL_GXX_AR) $(flags) $(out),$(filter-out %.h.gch,$(objs)))
211 $(foreach lib,$(othersrc)\
212 ,$(NL)$(TAB)$(call MSG_AR_MERGE,$(target),$(out),$(lib)) \
213 $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))ar.tmp.dir/* \
214 $(NL)$(TAB)$(QUIET)$(MKDIR) -p $(dir $(outbase))/ar.tmp.dir/ \
215 $(NL)$(TAB)$(QUIET)(cd $(dir $(outbase))ar.tmp.dir/ \
216 && $(TOOL_GXX_AR) x $(abspath $(lib)) \
217 && $(TOOL_GXX_AR) $(flags) $(out) *) \
218 $(NL)$(TAB)$(QUIET)$(RM_EXT) -f $(dir $(outbase))/ar.tmp.dir/* \
219 $(NL)$(TAB)$(QUIET)$(RMDIR) $(dir $(outbase))ar.tmp.dir/)
220 $(QUIET)$(TOOL_GXX_RANLIB) $(out)
221endef
222
223
224## Link program
225# @param $(target) Normalized main target name.
226# @param $(out) Program name.
227# @param $(objs) Object files to link together.
228# @param $(libs) Libraries to search.
229# @param $(libpath) Library search paths.
230# @param $(flags) Flags.
231# @param $(dirdep) Directory creation dependency.
232# @param $(deps) Other dependencies.
233# @param $(othersrc) Unhandled sources.
234# @param $(custom_pre) Custom step invoked before linking.
235# @param $(custom_post) Custom step invoked after linking.
236#
237# @param $(outbase) Output basename (full). Use this for list files and such.
238TOOL_GXX_LINK_PROGRAM_OUTPUT =
239TOOL_GXX_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
240TOOL_GXX_LINK_PROGRAM_DEPORD =
241define TOOL_GXX_LINK_PROGRAM_CMDS
242 $(QUIET)$(TOOL_GXX_LD) $(flags) -o $(out) $(filter-out %.h.gch,$(objs)) \
243 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))
244endef
245
246
247## Link DLL
248# @param $(target) Normalized main target name.
249# @param $(out) Program name.
250# @param $(objs) Object files to link together.
251# @param $(libs) Libraries to search.
252# @param $(libpath) Library search paths.
253# @param $(flags) Flags.
254# @param $(dirdep) Directory creation dependency.
255# @param $(deps) Other dependencies.
256# @param $(othersrc) Unhandled sources.
257# @param $(custom_pre) Custom step invoked before linking.
258# @param $(custom_post) Custom step invoked after linking.
259# @param $(outbase) Output basename (full). Use this for list files and such.
260TOOL_GXX_LINK_DLL_OUTPUT =
261TOOL_GXX_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
262TOOL_GXX_LINK_DLL_DEPORD =
263define TOOL_GXX_LINK_DLL_CMDS
264 $(QUIET)$(TOOL_GXX_LD) $(TOOL_GXX_LDFLAGS.dll) $(flags) -o $(out) $(filter-out %.h.gch,$(objs)) \
265 $(foreach lib,$(libs), $(if $(findstring $(lib),$(subst /,x,$(lib))), -l$(patsubst lib%,%,$(lib)), $(lib)))
266endef
267
Note: See TracBrowser for help on using the repository browser.