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 |
|
---|
34 | TOOL_GXX := Generic GCC using the system GCC, for building C++ code.
|
---|
35 |
|
---|
36 | # Tool Specific Properties
|
---|
37 | TOOL_GXX_CC ?= gcc$(HOSTSUFF_EXE)
|
---|
38 | TOOL_GXX_CXX ?= g++$(HOSTSUFF_EXE)
|
---|
39 | TOOL_GXX_PCH ?= $(TOOL_GXX_CXX)
|
---|
40 | TOOL_GXX_AS ?= gcc$(HOSTSUFF_EXE)
|
---|
41 | TOOL_GXX_AR ?= ar$(HOSTSUFF_EXE)
|
---|
42 | TOOL_GXX_RANLIB ?= ranlib$(HOSTSUFF_EXE)
|
---|
43 | TOOL_GXX_LD ?= g++$(HOSTSUFF_EXE)
|
---|
44 | TOOL_GXX_LDFLAGS.dll.os2 ?= -Zdll
|
---|
45 | TOOL_GXX_LDFLAGS.dll.darwin ?= -dynamiclib
|
---|
46 | ifndef TOOL_GXX_LDFLAGS.$(KBUILD_TARGET)
|
---|
47 | TOOL_GXX_LDFLAGS.dll ?= -shared
|
---|
48 | else
|
---|
49 | TOOL_GXX_LDFLAGS.dll ?= $(TOOL_GXX_LDFLAGS.$(KBUILD_TARGET))
|
---|
50 | endif
|
---|
51 |
|
---|
52 | # General Properties used by kBuild
|
---|
53 | TOOL_GXX_COBJSUFF ?= .o
|
---|
54 | TOOL_GXX_CFLAGS ?=
|
---|
55 | TOOL_GXX_CFLAGS.debug ?= -g
|
---|
56 | TOOL_GXX_CFLAGS.profile ?= -g -O2 #-pg
|
---|
57 | TOOL_GXX_CFLAGS.release ?= -O2
|
---|
58 | TOOL_GXX_CINCS ?=
|
---|
59 | TOOL_GXX_CDEFS ?=
|
---|
60 |
|
---|
61 | TOOL_GXX_CXXOBJSUFF ?= .o
|
---|
62 | TOOL_GXX_CXXOBJSUFF ?= .o
|
---|
63 | TOOL_GXX_CXXFLAGS ?=
|
---|
64 | TOOL_GXX_CXXFLAGS.debug ?= -g -O0
|
---|
65 | TOOL_GXX_CXXFLAGS.profile ?= -g -O2 #-pg
|
---|
66 | TOOL_GXX_CXXFLAGS.release ?= -O2
|
---|
67 | TOOL_GXX_CXXINCS ?=
|
---|
68 | TOOL_GXX_CXXDEFS ?=
|
---|
69 |
|
---|
70 | TOOL_GXX_PCHOBJSUFF ?= .h.gch
|
---|
71 | TOOL_GXX_PCHFLAGS ?= $(TOOL_GXX_CXXFLAGS)
|
---|
72 | TOOL_GXX_PCHFLAGS.debug ?= $(TOOL_GXX_CXXFLAGS.debug)
|
---|
73 | TOOL_GXX_PCHFLAGS.profile ?= $(TOOL_GXX_CXXFLAGS.profile)
|
---|
74 | TOOL_GXX_PCHFLAGS.release ?= $(TOOL_GXX_CXXFLAGS.release)
|
---|
75 | TOOL_GXX_PCHINCS ?= $(TOOL_GXX_CXXINCS)
|
---|
76 | TOOL_GXX_PCHDEFS ?= $(TOOL_GXX_CXXDEFS)
|
---|
77 |
|
---|
78 | TOOL_GXX_ASFLAGS ?= -x assembler-with-cpp
|
---|
79 | TOOL_GXX_ASFLAGS.debug ?= -g
|
---|
80 | TOOL_GXX_ASFLAGS.profile ?= -g
|
---|
81 | TOOL_GXX_ASOBJSUFF ?= .o
|
---|
82 |
|
---|
83 | TOOL_GXX_ARFLAGS ?= cr
|
---|
84 | TOOL_GXX_ARLIBSUFF ?= .a
|
---|
85 |
|
---|
86 | TOOL_GXX_LDFLAGS ?=
|
---|
87 | TOOL_GXX_LDFLAGS.debug ?= -g
|
---|
88 | TOOL_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 | #
|
---|
104 | TOOL_GXX_COMPILE_C_OUTPUT =
|
---|
105 | TOOL_GXX_COMPILE_C_DEPEND =
|
---|
106 | TOOL_GXX_COMPILE_C_DEPORD =
|
---|
107 | define 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):" ""
|
---|
114 | endef
|
---|
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.
|
---|
130 | TOOL_GXX_COMPILE_CXX_OUTPUT =
|
---|
131 | TOOL_GXX_COMPILE_CXX_DEPEND = $($(target)_1_GCC_PCH_FILE)
|
---|
132 | TOOL_GXX_COMPILE_CXX_DEPORD =
|
---|
133 | define 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):" ""
|
---|
141 | endef
|
---|
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.
|
---|
156 | TOOL_GXX_COMPILE_PCH_OUTPUT = $($(target)_1_GCC_PCH_FILE)
|
---|
157 | TOOL_GXX_COMPILE_PCH_DEPEND =
|
---|
158 | TOOL_GXX_COMPILE_PCH_DEPORD = $($(target)_1_GCC_PCH_DIR)
|
---|
159 | define 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):" ""
|
---|
167 | endef
|
---|
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 | #
|
---|
183 | TOOL_GXX_COMPILE_AS_OUTPUT =
|
---|
184 | TOOL_GXX_COMPILE_AS_DEPEND =
|
---|
185 | TOOL_GXX_COMPILE_AS_DEPORD =
|
---|
186 | define 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):" ""
|
---|
193 | endef
|
---|
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.
|
---|
205 | TOOL_GXX_LINK_LIBRARY_OUTPUT =
|
---|
206 | TOOL_GXX_LINK_LIBRARY_DEPEND =
|
---|
207 | TOOL_GXX_LINK_LIBRARY_DEPORD =
|
---|
208 | define 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)
|
---|
221 | endef
|
---|
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.
|
---|
238 | TOOL_GXX_LINK_PROGRAM_OUTPUT =
|
---|
239 | TOOL_GXX_LINK_PROGRAM_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
|
---|
240 | TOOL_GXX_LINK_PROGRAM_DEPORD =
|
---|
241 | define 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)))
|
---|
244 | endef
|
---|
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.
|
---|
260 | TOOL_GXX_LINK_DLL_OUTPUT =
|
---|
261 | TOOL_GXX_LINK_DLL_DEPEND = $(foreach lib,$(libs),$(if $(findstring $(lib),$(subst /,x,$(lib))),, $(lib)))
|
---|
262 | TOOL_GXX_LINK_DLL_DEPORD =
|
---|
263 | define 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)))
|
---|
266 | endef
|
---|
267 |
|
---|