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