]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/tools/build/src/tools/gcc.jam
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / tools / build / src / tools / gcc.jam
CommitLineData
1e59de90 1# Copyright 2021 Nikita Kniazev
7c673cae 2# Copyright 2001 David Abrahams
b32b8144 3# Copyright 2002-2017 Rene Rivera
7c673cae
FG
4# Copyright 2002-2003 Vladimir Prus
5# Copyright 2005 Reece H. Dunn
6# Copyright 2006 Ilya Sokolov
7# Copyright 2007 Roland Schwarz
8# Copyright 2007 Boris Gubenko
9#
10# Distributed under the Boost Software License, Version 1.0.
1e59de90
TL
11# (See accompanying file LICENSE.txt or copy at
12# https://www.bfgroup.xyz/b2/LICENSE.txt)
7c673cae 13
92f5a8d4
TL
14#| tag::doc[]
15
16[[bbv2.reference.tools.compiler.gcc]]
17= GNU C++
18
19The `gcc` module supports the http://gcc.gnu.org[GNU C++ compiler] on
20Linux, a number of Unix-like system including SunOS and on Windows
21(either http://www.cygwin.com[Cygwin] or http://www.mingw.org[MinGW]).
22
23The `gcc` module is initialized using the following syntax:
24
25----
26using gcc : [version] : [c++-compile-command] : [compiler options] ;
27----
28
29This statement may be repeated several times, if you want to configure
30several versions of the compiler.
31
32If the version is not explicitly specified, it will be automatically
33detected by running the compiler with the `-v` option. If the command is
34not specified, the `g++` binary will be searched in PATH.
35
36The following options can be provided, using
37_`<option-name>option-value syntax`_:
38
1e59de90
TL
39`asmflags`::
40Specifies additional compiler flags that will be used when compiling assembler
41sources.
42
92f5a8d4
TL
43`cflags`::
44Specifies additional compiler flags that will be used when compiling C
45sources.
46
47`cxxflags`::
48Specifies additional compiler flags that will be used when compiling C++
49sources.
50
1e59de90
TL
51`fflags`::
52Specifies additional compiler flags that will be used when compiling Fortran
53sources.
54
55`mflags`::
56Specifies additional compiler flags that will be used when compiling
57Objective-C sources.
58
59`mmflags`::
60Specifies additional compiler flags that will be used when compiling
61Objective-C++ sources.
62
92f5a8d4 63`compileflags`::
1e59de90
TL
64Specifies additional compiler flags that will be used when compiling any
65language sources.
92f5a8d4
TL
66
67`linkflags`::
68Specifies additional command line options that will be passed to the linker.
69
70`root`::
71Specifies root directory of the compiler installation. This option is
72necessary only if it is not possible to detect this information from the
73compiler command--for example if the specified compiler command is a user
74script.
75
76`archiver`::
77Specifies the archiver command that is used to produce static
78libraries. Normally, it is autodetected using gcc `-print-prog-name`
79option or defaulted to `ar`, but in some cases you might want to
80override it, for example to explicitly use a system version instead of
81one included with gcc.
82
92f5a8d4
TL
83`rc`::
84Specifies the resource compiler command that will be used with the
85version of gcc that is being configured. This setting makes sense only
86for Windows and only if you plan to use resource files. By default
87`windres` will be used.
88
89`rc-type`::
90Specifies the type of resource compiler. The value can be either
91`windres` for msvc resource compiler, or `rc` for borland's resource
92compiler.
93
94In order to compile 64-bit applications, you have to specify
95`address-model=64`, and the `instruction-set` feature should refer to a 64
96bit processor. Currently, those include `nocona`, `opteron`, `athlon64` and
97`athlon-fx`.
98
99|# # end::doc[]
100
7c673cae
FG
101import "class" : new ;
102import common ;
103import cygwin ;
104import feature ;
105import fortran ;
106import generators ;
107import os ;
108import pch ;
109import property ;
110import property-set ;
111import rc ;
112import regex ;
11fdf7f2 113import sequence ;
7c673cae
FG
114import set ;
115import toolset ;
116import type ;
117import unix ;
b32b8144
FG
118import virtual-target ;
119import errors ;
7c673cae
FG
120
121
122if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]
123{
124 .debug-configuration = true ;
125}
126
127
128feature.extend toolset : gcc ;
7c673cae
FG
129
130toolset.inherit-generators gcc : unix : unix.link unix.link.dll ;
131toolset.inherit-flags gcc : unix ;
132toolset.inherit-rules gcc : unix ;
133
134generators.override gcc.prebuilt : builtin.prebuilt ;
135generators.override gcc.searched-lib-generator : searched-lib-generator ;
136
137# Make gcc toolset object files use the "o" suffix on all platforms.
138type.set-generated-target-suffix OBJ : <toolset>gcc : o ;
139type.set-generated-target-suffix OBJ : <toolset>gcc <target-os>windows : o ;
140type.set-generated-target-suffix OBJ : <toolset>gcc <target-os>cygwin : o ;
141
142
143# Initializes the gcc toolset for the given version. If necessary, command may
144# be used to specify where the compiler is located. The parameter 'options' is a
145# space-delimited list of options, each one specified as
146# <option-name>option-value. Valid option names are: cxxflags, linkflags and
147# linker-type. Accepted linker-type values are aix, darwin, gnu, hpux, osf or
148# sun and the default value will be selected based on the current OS.
149# Example:
150# using gcc : 3.4 : : <cxxflags>foo <linkflags>bar <linker-type>sun ;
151#
152# The compiler command to use is detected in three steps:
153# 1) If an explicit command is specified by the user, it will be used and must
154# be available.
155# 2) If only a certain version is specified, it is enforced:
156# - either the 'g++-VERSION' command must be available
157# - or the default command 'g++' must be available and match the exact
158# version.
159# 3) Without user-provided restrictions use default 'g++'.
160#
b32b8144 161rule init ( version ? : command * : options * : requirement * )
7c673cae 162{
7c673cae
FG
163 # Information about the gcc command...
164 # The command.
1e59de90 165 command = [ common.find-compiler gcc : g++ : $(version) : $(command) ] ;
92f5a8d4 166 # The 'command' variable can have multiple elements but when calling the
7c673cae
FG
167 # SHELL builtin we need a single string, and we need to quote elements
168 # with spaces.
1e59de90 169 local command-string = [ common.make-command-string $(command) ] ;
7c673cae
FG
170 # The root directory of the tool install.
171 local root = [ feature.get-values <root> : $(options) ] ;
172 # The bin directory where to find the command to execute.
173 local bin ;
174 # The compiler flavor.
175 local flavor = [ feature.get-values <flavor> : $(options) ] ;
b32b8144
FG
176 # vxworks build on windows uses csh that is neither mingw or cygwin
177 if [ feature.get-values <target-os> : $(options) ] = vxworks
178 {
179 flavor ?= vxworks ;
180 }
7c673cae
FG
181 # Autodetect the root and bin dir if not given.
182 if $(command)
183 {
184 bin ?= [ common.get-absolute-tool-path $(command[-1]) ] ;
185 root ?= $(bin:D) ;
186 }
11fdf7f2 187 local target-os ;
7c673cae
FG
188 # Autodetect the version and flavor if not given.
189 if $(command)
190 {
191 local machine = [ MATCH "^([^ ]+)" :
192 [ SHELL "$(command-string) -dumpmachine" ] ] ;
1e59de90
TL
193 if ! $(version) { # ?= operator does not short-circuit
194 version ?= [ get-short-version $(command-string) ] ;
195 }
7c673cae
FG
196 switch $(machine:L)
197 {
198 case *mingw* : flavor ?= mingw ;
11fdf7f2
TL
199 case *cygwin* : flavor ?= cygwin ;
200 }
201 switch $(machine:L)
202 {
203 case *mingw* : target-os ?= windows ;
204 case *cygwin* : target-os ?= cygwin ;
205 case *linux* : target-os ?= linux ;
206 # TODO: finish this list.
7c673cae
FG
207 }
208 }
209
210 local condition ;
b32b8144 211 condition = [ common.check-init-parameters gcc $(requirement) : version $(version)
7c673cae
FG
212 : $(condition) ] ;
213
214 common.handle-options gcc : $(condition) : $(command) : $(options) ;
215
11fdf7f2
TL
216 # Set the default target-os for this toolset.
217 if $(target-os) && ! [ feature.get-values <target-os> : $(requirement) ]
218 {
219 local conditionx = [ regex.replace $(condition) "/" "," ] ;
220 toolset.add-defaults $(conditionx)\:<target-os>$(target-os) ;
221 }
7c673cae
FG
222
223 # If gcc is installed in a non-standard location, we would need to add
224 # LD_LIBRARY_PATH when running programs created with it (for unit-test/run
225 # rules).
226 if $(command)
227 {
228 # On multilib 64-bit boxes, there are both 32-bit and 64-bit libraries
229 # and all must be added to LD_LIBRARY_PATH. The linker will pick the
230 # right onces. Note that we do not provide a clean way to build a 32-bit
231 # binary using a 64-bit compiler, but user can always pass -m32
232 # manually.
233 local lib_path = $(root)/bin $(root)/lib $(root)/lib32 $(root)/lib64 ;
234 if $(.debug-configuration)
235 {
11fdf7f2 236 ECHO "notice:" using gcc libraries "::" $(condition) "::" $(lib_path) ;
7c673cae
FG
237 }
238 toolset.flags gcc.link RUN_PATH $(condition) : $(lib_path) ;
239 }
240
241 # If we are not using a system gcc installation we should adjust the various
242 # programs as needed to prefer using their installation specific versions.
243 # This is essential for correct use of MinGW and for cross-compiling.
244
245 # - Archive builder.
246 local archiver = [ common.get-invocation-command gcc
247 : [ .get-prog-name $(command-string) : ar : $(flavor) ]
248 : [ feature.get-values <archiver> : $(options) ]
249 : $(bin)
250 : search-path ] ;
251 toolset.flags gcc.archive .AR $(condition) : $(archiver[1]) ;
252 if $(.debug-configuration)
253 {
11fdf7f2 254 ECHO "notice:" using gcc archiver "::" $(condition) "::" $(archiver[1]) ;
7c673cae 255 }
f67539c2
TL
256 local arflags = [ feature.get-values <arflags> : $(options) ] ;
257 toolset.flags gcc.archive .ARFLAGS $(condition) : $(arflags) ;
7c673cae 258
7c673cae
FG
259 # - Resource compiler.
260 local rc = [ common.get-invocation-command-nodefault gcc : windres :
261 [ feature.get-values <rc> : $(options) ] : $(bin) : search-path ] ;
262 local rc-type = [ feature.get-values <rc-type> : $(options) ] ;
263 rc-type ?= windres ;
264 if ! $(rc)
265 {
266 # If we can not find an RC compiler we fallback to a null one that
267 # creates empty object files. This allows the same Jamfiles to work
268 # across the board. The null RC uses assembler to create the empty
269 # objects, so configure that.
270 rc = [ common.get-invocation-command gcc : as : : $(bin) : search-path ]
271 ;
272 rc-type = null ;
273 }
274 rc.configure $(rc) : $(condition) : <rc-type>$(rc-type) ;
92f5a8d4 275
b32b8144 276 toolset.flags gcc VERSION $(condition) : [ regex.split $(version) "[.]" ] ;
11fdf7f2
TL
277
278 init-cxxstd-flags $(condition) : $(version) ;
7c673cae
FG
279}
280
281if [ os.name ] = NT
282{
283 # This causes single-line command invocation to not go through .bat files,
284 # thus avoiding command-line length limitations.
1e59de90
TL
285 JAMSHELL = [ modules.peek : JAMSHELL ] ;
286 JAMSHELL ?= % ;
7c673cae
FG
287}
288
1e59de90 289rule get-full-version ( command-string )
11fdf7f2
TL
290{
291 # -dumpfullversion is only supported for gcc 7+.
292 # Passing both options works, as the first one that's
293 # recognized will be used.
1e59de90
TL
294 return [ common.match-command-output version : "^([0-9.]+)"
295 : "$(command-string) -dumpfullversion -dumpversion" ] ;
11fdf7f2
TL
296}
297
1e59de90 298rule get-short-version ( command-string : single-digit-since ? )
92f5a8d4 299{
1e59de90
TL
300 local version = [ get-full-version $(command-string) ] ;
301 version = [ SPLIT_BY_CHARACTERS $(version) : . ] ;
302
303 import version ;
304 if [ version.version-less $(version) : $(single-digit-since:E=5) ]
305 {
306 return $(version[1-2]:J=.) ;
307 }
308
309 return $(version[1]) ;
92f5a8d4
TL
310}
311
7c673cae
FG
312# Uses -print-prog-name to get the name of the tool.
313# Converts the path to native form if using cygwin.
314rule .get-prog-name ( command-string : tool : flavor ? )
315{
316 local prog-name = [ NORMALIZE_PATH [ MATCH "(.*)[\n]+" :
317 [ SHELL "$(command-string) -print-prog-name=$(tool)" ] ] ] ;
b32b8144 318
11fdf7f2 319 if $(flavor) = cygwin && [ os.name ] = NT
7c673cae
FG
320 {
321 prog-name = [ cygwin.cygwin-to-windows-path $(prog-name) ] ;
322 }
323 return $(prog-name) ;
324}
325
b32b8144
FG
326###
327### Functions that set options on the targets.
328###
7c673cae 329
11fdf7f2 330local all-os = [ feature.values <target-os> ] ;
7c673cae 331
11fdf7f2 332local rule compile-link-flags ( * )
7c673cae 333{
11fdf7f2
TL
334 toolset.flags gcc.compile OPTIONS $(1) : $(2) ;
335 toolset.flags gcc.link OPTIONS $(1) : $(2) ;
7c673cae
FG
336}
337
b32b8144 338{
11fdf7f2
TL
339 # This logic will add -fPIC for all compilations:
340 #
341 # lib a : a.cpp b ;
342 # obj b : b.cpp ;
343 # exe c : c.cpp a d ;
344 # obj d : d.cpp ;
345 #
346 # This all is fine, except that 'd' will be compiled with -fPIC even
347 # though it is not needed, as 'd' is used only in exe. However, it is
348 # hard to detect where a target is going to be used. Alternatively, we
349 # can set -fPIC only when main target type is LIB but than 'b' would be
350 # compiled without -fPIC which would lead to link errors on x86-64. So,
351 # compile everything with -fPIC.
352 #
353 # Yet another alternative would be to create a propagated <sharedable>
354 # feature and set it when building shared libraries, but that would be
355 # hard to implement and would increase the target path length even more.
b32b8144 356
11fdf7f2
TL
357 # On Windows, fPIC is the default, and specifying -fPIC explicitly leads
358 # to a warning.
359 local non-windows = [ set.difference $(all-os) : cygwin windows ] ;
360 compile-link-flags <link>shared/<target-os>$(non-windows) : -fPIC ;
b32b8144 361}
7c673cae 362
7c673cae 363{
11fdf7f2
TL
364 # Handle address-model
365 compile-link-flags <target-os>aix/<address-model>32 : -maix32 ;
366 compile-link-flags <target-os>aix/<address-model>64 : -maix64 ;
367
368 compile-link-flags <target-os>hpux/<address-model>32 : -milp32 ;
369 compile-link-flags <target-os>hpux/<address-model>64 : -mlp64 ;
370
371 local generic-os = [ set.difference $(all-os) : aix hpux ] ;
372 local arch = power sparc x86 ;
373 compile-link-flags <target-os>$(generic-os)/<architecture>$(arch)/<address-model>32 : -m32 ;
374 compile-link-flags <target-os>$(generic-os)/<architecture>$(arch)/<address-model>64 : -m64 ;
7c673cae
FG
375}
376
7c673cae 377{
11fdf7f2
TL
378 # Handle threading
379 local rule threading-flags ( * )
b32b8144 380 {
11fdf7f2
TL
381 compile-link-flags <threading>multi/$(1) : $(2) ;
382 if $(3)
b32b8144 383 {
11fdf7f2 384 toolset.flags gcc.link FINDLIBS-SA <threading>multi/$(1) : $(3) ;
b32b8144 385 }
b32b8144 386 }
7c673cae 387
11fdf7f2
TL
388 threading-flags <target-os>windows : -mthreads ;
389 threading-flags <target-os>cygwin : -mthreads ;
390 threading-flags <target-os>solaris : -pthreads : rt ;
f67539c2 391 threading-flags <target-os>qnx : -pthread ;
7c673cae 392
11fdf7f2
TL
393 local bsd = [ MATCH ^(.*bsd)$ : $(all-os) ] ;
394 threading-flags <target-os>$(bsd) : -pthread ;
395
1e59de90
TL
396 # iOS doesn't need pthread flag according to the https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/pthread.3.html
397 # The default system libraries include pthread functions. No additional libraries or CFLAGS are necessary to use this API.
398 local no-threading = android beos haiku sgi darwin vxworks iphone appletv ;
f67539c2 399 local threading-generic-os = [ set.difference $(all-os) : $(no-threading) $(bsd) windows cygwin solaris qnx ] ;
11fdf7f2 400 threading-flags <target-os>$(threading-generic-os) : -pthread : rt ;
7c673cae
FG
401}
402
7c673cae 403{
11fdf7f2 404 local rule cxxstd-flags ( * )
b32b8144 405 {
11fdf7f2
TL
406 toolset.flags gcc.compile.c++ OPTIONS $(1) : $(2) ;
407 toolset.flags gcc.link OPTIONS $(1) : $(2) ;
b32b8144 408 }
7c673cae 409
11fdf7f2
TL
410 local cxxstd = [ feature.values <cxxstd> ] ;
411 local dialects = [ feature.values <cxxstd-dialect> ] ;
412 .cxxstd-dialects = [ set.difference $(dialects) : gnu iso ] ;
413 # C++ latest needs to be set up on a per-toolset basis
414 for local std in [ set.difference $(cxxstd) : latest ]
b32b8144 415 {
11fdf7f2
TL
416 cxxstd-flags <cxxstd>$(std)/<cxxstd-dialect>iso : -std=c++$(std) ;
417 cxxstd-flags <cxxstd>$(std)/<cxxstd-dialect>gnu : -std=gnu++$(std) ;
418 # If we see this it's probably a mistake, but
419 # toolset.flags has no way to set up diagnostics.
420 cxxstd-flags <cxxstd>$(std)/<cxxstd-dialect>$(.cxxstd-dialects) : -std=c++$(std) ;
b32b8144 421 }
7c673cae 422
11fdf7f2
TL
423 local rule version-ge ( lhs : rhs )
424 {
425 lhs = [ regex.split $(lhs) "[.]" ] ;
426 rhs = [ regex.split $(rhs) "[.]" ] ;
427 return [ sequence.compare $(rhs) : $(lhs) : numbers.less ] ;
428 }
429 # Version specific flags
430 local rule init-cxxstd-flags ( condition * : version )
b32b8144 431 {
11fdf7f2 432 local std ;
20effc67
TL
433 if [ version-ge $(version) : 10 ] { std = 20 ; }
434 else if [ version-ge $(version) : 8 ] { std = 2a ; }
435 else if [ version-ge $(version) : 6 ] { std = 17 ; }
92f5a8d4 436 else if [ version-ge $(version) : 5 ] { std = 1z ; }
20effc67 437 else if [ version-ge $(version) : 4.9 ] { std = 14 ; }
11fdf7f2
TL
438 else if [ version-ge $(version) : 4.8 ] { std = 1y ; }
439 else if [ version-ge $(version) : 4.7 ] { std = 11 ; }
440 else if [ version-ge $(version) : 3.3 ] { std = 98 ; }
441 if $(std)
442 {
443 cxxstd-flags $(condition)/<cxxstd>latest/<cxxstd-dialect>iso : -std=c++$(std) ;
444 cxxstd-flags $(condition)/<cxxstd>latest/<cxxstd-dialect>gnu : -std=gnu++$(std) ;
445 cxxstd-flags $(condition)/<cxxstd>latest/<cxxstd-dialect>$(.cxxstd-dialects) : -std=c++$(std) ;
446 }
b32b8144
FG
447 }
448}
449
11fdf7f2
TL
450generators.register-c-compiler gcc.compile.c++.preprocess : CPP : PREPROCESSED_CPP : <toolset>gcc ;
451generators.register-c-compiler gcc.compile.c.preprocess : C : PREPROCESSED_C : <toolset>gcc ;
452generators.register-c-compiler gcc.compile.c++ : CPP : OBJ : <toolset>gcc ;
453generators.register-c-compiler gcc.compile.c : C : OBJ : <toolset>gcc ;
454generators.register-c-compiler gcc.compile.asm : ASM : OBJ : <toolset>gcc ;
1e59de90
TL
455generators.register-c-compiler gcc.compile.m : OBJECTIVE_C : OBJ : <toolset>gcc ;
456generators.register-c-compiler gcc.compile.mm : OBJECTIVE_CPP : OBJ : <toolset>gcc ;
11fdf7f2
TL
457
458generators.register [ new fortran-compiling-generator
b32b8144 459 gcc.compile.fortran : FORTRAN FORTRAN90 : OBJ : <toolset>gcc ] ;
7c673cae 460
b32b8144
FG
461rule compile.c++.preprocess ( targets * : sources * : properties * )
462{
7c673cae
FG
463 # Some extensions are compiled as C++ by default. For others, we need to
464 # pass -x c++. We could always pass -x c++ but distcc does not work with it.
465 if ! $(>:S) in .cc .cp .cxx .cpp .c++ .C
466 {
467 LANG on $(<) = "-x c++" ;
468 }
469 DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
470}
471
472rule compile.c.preprocess ( targets * : sources * : properties * )
473{
7c673cae
FG
474 # If we use the name g++ then default file suffix -> language mapping does
475 # not work. So have to pass -x option. Maybe, we can work around this by
476 # allowing the user to specify both C and C++ compiler names.
477 #if $(>:S) != .c
478 #{
479 LANG on $(<) = "-x c" ;
480 #}
481 DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
482}
483
484rule compile.c++ ( targets * : sources * : properties * )
485{
7c673cae
FG
486 # Some extensions are compiled as C++ by default. For others, we need to
487 # pass -x c++. We could always pass -x c++ but distcc does not work with it.
488 if ! $(>:S) in .cc .cp .cxx .cpp .c++ .C
489 {
490 LANG on $(<) = "-x c++" ;
491 }
492 DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
7c673cae
FG
493}
494
495rule compile.c ( targets * : sources * : properties * )
496{
7c673cae
FG
497 # If we use the name g++ then default file suffix -> language mapping does
498 # not work. So have to pass -x option. Maybe, we can work around this by
499 # allowing the user to specify both C and C++ compiler names.
500 #if $(>:S) != .c
501 #{
502 LANG on $(<) = "-x c" ;
503 #}
504 DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
505}
506
507rule compile.fortran ( targets * : sources * : properties * )
508{
7c673cae
FG
509}
510
511actions compile.c++ bind PCH_FILE
512{
1e59de90 513 "$(CONFIG_COMMAND)" $(LANG) -ftemplate-depth-$(TEMPLATE_DEPTH) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -include"$(PCH_FILE:S=)" -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -c -o "$(<:W)" "$(>:W)"
7c673cae
FG
514}
515
516actions compile.c bind PCH_FILE
517{
1e59de90 518 "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -include"$(PCH_FILE:S=)" -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -c -o "$(<)" "$(>)"
7c673cae
FG
519}
520
521actions compile.c++.preprocess bind PCH_FILE
522{
1e59de90 523 "$(CONFIG_COMMAND)" $(LANG) -ftemplate-depth-$(TEMPLATE_DEPTH) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -include"$(PCH_FILE:S=)" -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" "$(>:W)" -E >"$(<:W)"
7c673cae
FG
524}
525
526actions compile.c.preprocess bind PCH_FILE
527{
1e59de90 528 "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -include"$(PCH_FILE:S=)" -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" "$(>)" -E >$(<)
7c673cae
FG
529}
530
531actions compile.fortran
532{
1e59de90 533 "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -include"$(PCH_FILE:S=)" -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
7c673cae
FG
534}
535
536rule compile.asm ( targets * : sources * : properties * )
537{
7c673cae
FG
538 LANG on $(<) = "-x assembler-with-cpp" ;
539}
540
541actions compile.asm
542{
b32b8144 543 "$(CONFIG_COMMAND)" $(LANG) $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
7c673cae
FG
544}
545
1e59de90
TL
546actions compile.m
547{
548 "$(CONFIG_COMMAND)" -x objective-c $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
549}
550
551actions compile.mm
552{
553 "$(CONFIG_COMMAND)" -x objective-c++ $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
554}
555
b32b8144 556###
f67539c2 557### Precompiled header use and generation.
b32b8144
FG
558###
559
560# The compiler looks for a precompiled header in each directory just before it
561# looks for the include file in that directory. The name searched for is the
562# name specified in the #include directive with ".gch" suffix appended. The
563# logic in gcc-pch-generator will make sure that the BASE_PCH suffix is appended
564# to the full header name.
565
566type.set-generated-target-suffix PCH : <toolset>gcc : gch ;
567
568# GCC-specific pch generator.
569class gcc-pch-generator : pch-generator
570{
571 import project ;
572 import property-set ;
573 import type ;
574
575 rule run-pch ( project name ? : property-set : sources + )
576 {
577 # Find the header in sources. Ignore any CPP sources.
578 local header ;
579 for local s in $(sources)
580 {
581 if [ type.is-derived [ $(s).type ] H ]
582 {
583 header = $(s) ;
584 }
585 }
586
b32b8144
FG
587 local pch-file = [ generator.run $(project) $(name) : $(property-set)
588 : $(header) ] ;
589
590 # Return result of base class and pch-file property as
591 # usage-requirements.
592 return
11fdf7f2
TL
593 [ $(pch-file[1]).add-raw <pch-file>$(pch-file[2-]) <cflags>-Winvalid-pch ]
594 $(pch-file[2-])
b32b8144
FG
595 ;
596 }
b32b8144
FG
597}
598
599# Note: the 'H' source type will catch both '.h' header and '.hpp' header. The
600# latter have HPP type, but HPP type is derived from H. The type of compilation
601# is determined entirely by the destination type.
602generators.register [ new gcc-pch-generator gcc.compile.c.pch : H : C_PCH : <pch>on <toolset>gcc ] ;
603generators.register [ new gcc-pch-generator gcc.compile.c++.pch : H : CPP_PCH : <pch>on <toolset>gcc ] ;
604
605# Override default do-nothing generators.
606generators.override gcc.compile.c.pch : pch.default-c-pch-generator ;
607generators.override gcc.compile.c++.pch : pch.default-cpp-pch-generator ;
608
609toolset.flags gcc.compile PCH_FILE <pch>on : <pch-file> ;
610
b32b8144
FG
611actions compile.c++.pch
612{
1e59de90 613 "$(CONFIG_COMMAND)" -x c++-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -c -o "$(<)" "$(>)"
b32b8144
FG
614}
615
616actions compile.c.pch
617{
1e59de90 618 "$(CONFIG_COMMAND)" -x c-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -c -o "$(<)" "$(>)"
b32b8144
FG
619}
620
621###
622### General options, like optimization.
623###
624
625# Declare flags and action for compilation.
626toolset.flags gcc.compile OPTIONS <optimization>off : -O0 ;
627toolset.flags gcc.compile OPTIONS <optimization>speed : -O3 ;
628toolset.flags gcc.compile OPTIONS <optimization>space : -Os ;
629
630toolset.flags gcc.compile OPTIONS <inlining>off : -fno-inline ;
631toolset.flags gcc.compile OPTIONS <inlining>on : -Wno-inline ;
632toolset.flags gcc.compile OPTIONS <inlining>full : -finline-functions -Wno-inline ;
633
634toolset.flags gcc.compile OPTIONS <warnings>off : -w ;
635toolset.flags gcc.compile OPTIONS <warnings>on : -Wall ;
92f5a8d4
TL
636toolset.flags gcc.compile OPTIONS <warnings>all : -Wall ;
637toolset.flags gcc.compile OPTIONS <warnings>extra : -Wall -Wextra ;
638toolset.flags gcc.compile OPTIONS <warnings>pedantic : -Wall -Wextra -pedantic ;
b32b8144
FG
639toolset.flags gcc.compile OPTIONS <warnings-as-errors>on : -Werror ;
640
641toolset.flags gcc.compile OPTIONS <debug-symbols>on : -g ;
642toolset.flags gcc.compile OPTIONS <profiling>on : -pg ;
643
92f5a8d4
TL
644toolset.flags gcc.compile OPTIONS <local-visibility>hidden : -fvisibility=hidden ;
645toolset.flags gcc.compile.c++ OPTIONS <local-visibility>hidden : -fvisibility-inlines-hidden ;
646toolset.flags gcc.compile OPTIONS <local-visibility>protected : -fvisibility=protected ;
647toolset.flags gcc.compile OPTIONS <local-visibility>protected/<target-os>darwin : ;
648toolset.flags gcc.compile OPTIONS <local-visibility>global : -fvisibility=default ;
649
b32b8144 650toolset.flags gcc.compile.c++ OPTIONS <exception-handling>off : -fno-exceptions ;
92f5a8d4
TL
651toolset.flags gcc.compile.c++ OPTIONS <rtti>off : -fno-rtti ;
652
653# sanitizers
654toolset.flags gcc.compile.c++ OPTIONS <address-sanitizer>on : -fsanitize=address -fno-omit-frame-pointer ;
655toolset.flags gcc.compile.c++ OPTIONS <address-sanitizer>norecover : -fsanitize=address -fno-sanitize-recover=address -fno-omit-frame-pointer ;
656toolset.flags gcc.compile.c++ OPTIONS <leak-sanitizer>on : -fsanitize=leak -fno-omit-frame-pointer ;
657toolset.flags gcc.compile.c++ OPTIONS <leak-sanitizer>norecover : -fsanitize=leak -fno-sanitize-recover=leak -fno-omit-frame-pointer ;
658toolset.flags gcc.compile.c++ OPTIONS <thread-sanitizer>on : -fsanitize=thread -fno-omit-frame-pointer ;
659toolset.flags gcc.compile.c++ OPTIONS <thread-sanitizer>norecover : -fsanitize=thread -fno-sanitize-recover=thread -fno-omit-frame-pointer ;
660toolset.flags gcc.compile.c++ OPTIONS <undefined-sanitizer>on : -fsanitize=undefined -fno-omit-frame-pointer ;
661toolset.flags gcc.compile.c++ OPTIONS <undefined-sanitizer>norecover : -fsanitize=undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer ;
662
663toolset.flags gcc.compile.c++ OPTIONS <coverage>on : --coverage ;
b32b8144 664
11fdf7f2
TL
665# configure Dinkum STL to match compiler options
666toolset.flags gcc.compile.c++ DEFINES <rtti>off/<target-os>vxworks : _NO_RTTI ;
667toolset.flags gcc.compile.c++ DEFINES <exception-handling>off/<target-os>vxworks : _NO_EX=1 ;
668
f67539c2
TL
669# LTO
670toolset.flags gcc.compile OPTIONS <lto>on/<lto-mode>full : -flto ;
671toolset.flags gcc.link OPTIONS <lto>on/<lto-mode>full : -flto ;
672
673toolset.flags gcc.compile OPTIONS <lto>on/<lto-mode>fat : -flto -ffat-lto-objects ;
674toolset.flags gcc.link OPTIONS <lto>on/<lto-mode>fat : -flto ;
675
676# ABI selection
677toolset.flags gcc.compile.c++ DEFINES <stdlib>gnu : _GLIBCXX_USE_CXX11_ABI=0 ;
678toolset.flags gcc.compile.c++ DEFINES <stdlib>gnu11 : _GLIBCXX_USE_CXX11_ABI=1 ;
679
b32b8144
FG
680###
681### User free feature options.
682###
683
684toolset.flags gcc.compile USER_OPTIONS <cflags> ;
685toolset.flags gcc.compile.c++ USER_OPTIONS <cxxflags> ;
686toolset.flags gcc.compile.asm USER_OPTIONS <asmflags> ;
687toolset.flags gcc.compile DEFINES <define> ;
688toolset.flags gcc.compile INCLUDES <include> ;
20effc67 689toolset.flags gcc.compile FORCE_INCLUDES <force-include> ;
b32b8144
FG
690toolset.flags gcc.compile.c++ TEMPLATE_DEPTH <c++-template-depth> ;
691toolset.flags gcc.compile.fortran USER_OPTIONS <fflags> ;
1e59de90
TL
692toolset.flags gcc.compile.m USER_OPTIONS <mflags> ;
693toolset.flags gcc.compile.mm USER_OPTIONS <mmflags> ;
b32b8144
FG
694
695###
696### Linking generators and actions.
697###
698
7c673cae
FG
699# Class checking that we do not try to use the <runtime-link>static property
700# while creating or using a shared library, since it is not supported by
701# gcc/libc.
702class gcc-linking-generator : unix-linking-generator
703{
704 rule run ( project name ? : property-set : sources + )
705 {
b32b8144
FG
706 local target-os = [ $(property-set).get <target-os> ] ;
707 local no-static-link = true ;
708 switch $(target-os)
7c673cae 709 {
b32b8144
FG
710 case vms : no-static-link = ;
711 case windows : no-static-link = ;
7c673cae
FG
712 }
713
714 local properties = [ $(property-set).raw ] ;
715 local reason ;
716 if $(no-static-link) && <runtime-link>static in $(properties)
717 {
718 if <link>shared in $(properties)
719 {
720 reason = On gcc, DLLs can not be built with
721 '<runtime-link>static'. ;
722 }
723 else if [ type.is-derived $(self.target-types[1]) EXE ]
724 {
725 for local s in $(sources)
726 {
727 local type = [ $(s).type ] ;
728 if $(type) && [ type.is-derived $(type) SHARED_LIB ]
729 {
730 reason = On gcc, using DLLs together with the
731 '<runtime-link>static' option is not possible. ;
732 }
733 }
734 }
735 }
736 if $(reason)
737 {
11fdf7f2
TL
738 ECHO "warning:" $(reason) ;
739 ECHO "warning:" It is suggested to use '<runtime-link>static' together
7c673cae
FG
740 with '<link>static'. ;
741 }
742 else
743 {
744 return [ unix-linking-generator.run $(project) $(name) :
745 $(property-set) : $(sources) ] ;
746 }
747 }
748}
749
750# The set of permissible input types is different on mingw. So, define two sets
751# of generators, with mingw generators selected when target-os=windows.
752
753local g ;
754g = [ new gcc-linking-generator gcc.mingw.link
755 : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB
756 : EXE
757 : <toolset>gcc <target-os>windows ] ;
20effc67 758$(g).set-rule-name gcc.link.mingw ;
7c673cae
FG
759generators.register $(g) ;
760
761g = [ new gcc-linking-generator gcc.mingw.link.dll
762 : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB
763 : IMPORT_LIB SHARED_LIB
764 : <toolset>gcc <target-os>windows ] ;
20effc67 765$(g).set-rule-name gcc.link.dll.mingw ;
7c673cae
FG
766generators.register $(g) ;
767
768generators.register
769 [ new gcc-linking-generator gcc.link
770 : LIB OBJ
771 : EXE
772 : <toolset>gcc ] ;
773generators.register
774 [ new gcc-linking-generator gcc.link.dll
775 : LIB OBJ
776 : SHARED_LIB
777 : <toolset>gcc ] ;
778
779generators.override gcc.mingw.link : gcc.link ;
780generators.override gcc.mingw.link.dll : gcc.link.dll ;
781
782# Cygwin is similar to msvc and mingw in that it uses import libraries. While in
783# simple cases, it can directly link to a shared library, it is believed to be
784# slower, and not always possible. Define cygwin-specific generators here.
785
786g = [ new gcc-linking-generator gcc.cygwin.link
787 : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB
788 : EXE
789 : <toolset>gcc <target-os>cygwin ] ;
790$(g).set-rule-name gcc.link ;
791generators.register $(g) ;
792
793g = [ new gcc-linking-generator gcc.cygwin.link.dll
794 : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB
795 : IMPORT_LIB SHARED_LIB
796 : <toolset>gcc <target-os>cygwin ] ;
797$(g).set-rule-name gcc.link.dll ;
798generators.register $(g) ;
799
800generators.override gcc.cygwin.link : gcc.link ;
801generators.override gcc.cygwin.link.dll : gcc.link.dll ;
802
803# Declare flags for linking.
804# First, the common flags.
805toolset.flags gcc.link OPTIONS <debug-symbols>on : -g ;
806toolset.flags gcc.link OPTIONS <profiling>on : -pg ;
807toolset.flags gcc.link USER_OPTIONS <linkflags> ;
808toolset.flags gcc.link LINKPATH <library-path> ;
809toolset.flags gcc.link FINDLIBS-ST <find-static-library> ;
810toolset.flags gcc.link FINDLIBS-SA <find-shared-library> ;
811toolset.flags gcc.link LIBRARIES <library-file> ;
812
92f5a8d4
TL
813# Specify compile flags for linker as well as they may be needed for LTO
814toolset.flags gcc.link OPTIONS <local-visibility>hidden : -fvisibility=hidden -fvisibility-inlines-hidden ;
815toolset.flags gcc.link OPTIONS <local-visibility>protected : -fvisibility=protected ;
816toolset.flags gcc.link OPTIONS <local-visibility>protected/<target-os>darwin : ;
817toolset.flags gcc.link OPTIONS <local-visibility>global : -fvisibility=default ;
818
819# sanitizers
820toolset.flags gcc.link OPTIONS <address-sanitizer>on : -fsanitize=address -fno-omit-frame-pointer ;
821toolset.flags gcc.link OPTIONS <address-sanitizer>norecover : -fsanitize=address -fno-sanitize-recover=address -fno-omit-frame-pointer ;
822toolset.flags gcc.link OPTIONS <leak-sanitizer>on : -fsanitize=leak -fno-omit-frame-pointer ;
823toolset.flags gcc.link OPTIONS <leak-sanitizer>norecover : -fsanitize=leak -fno-sanitize-recover=leak -fno-omit-frame-pointer ;
824toolset.flags gcc.link OPTIONS <thread-sanitizer>on : -fsanitize=thread -fno-omit-frame-pointer ;
825toolset.flags gcc.link OPTIONS <thread-sanitizer>norecover : -fsanitize=thread -fno-sanitize-recover=thread -fno-omit-frame-pointer ;
826toolset.flags gcc.link OPTIONS <undefined-sanitizer>on : -fsanitize=undefined -fno-omit-frame-pointer ;
827toolset.flags gcc.link OPTIONS <undefined-sanitizer>norecover : -fsanitize=undefined -fno-sanitize-recover=undefined -fno-omit-frame-pointer ;
828
829toolset.flags gcc.link OPTIONS <coverage>on : --coverage ;
830
7c673cae
FG
831toolset.flags gcc.link.dll .IMPLIB-COMMAND <target-os>windows : "-Wl,--out-implib," ;
832toolset.flags gcc.link.dll .IMPLIB-COMMAND <target-os>cygwin : "-Wl,--out-implib," ;
833
11fdf7f2
TL
834# target specific link flags
835{
836 # aix
837
838 # On AIX we *have* to use the native linker.
839 #
11fdf7f2
TL
840 # The -bnoipath strips the prepending (relative) path of libraries from
841 # the loader section in the target library or executable. Hence, during
842 # load-time LIBPATH (identical to LD_LIBRARY_PATH) or a hard-coded
843 # -blibpath (*similar* to -lrpath/-lrpath-link) is searched. Without
844 # this option, the prepending (relative) path + library name is
845 # hard-coded in the loader section, causing *only* this path to be
846 # searched during load-time. Note that the AIX linker does not have an
847 # -soname equivalent, this is as close as it gets.
848 #
849 # The -bbigtoc option instrcuts the linker to create a TOC bigger than 64k.
92f5a8d4 850 # This is necessary for some submodules such as math, but it does make running
11fdf7f2
TL
851 # the tests a tad slower.
852 #
92f5a8d4 853 # The above options are definitely for AIX 5.x, and most likely also for
11fdf7f2
TL
854 # AIX 4.x and AIX 6.x. For details about the AIX linker see:
855 # http://download.boulder.ibm.com/ibmdl/pub/software/dw/aix/es-aix_ll.pdf
856 #
1e59de90 857 toolset.flags gcc.link OPTIONS <target-os>aix : -Wl,-bnoipath -Wl,-bbigtoc ;
11fdf7f2
TL
858
859 # See note [1]
860 toolset.flags gcc.link OPTIONS <target-os>aix/<runtime-link>static : -static ;
861
862 # darwin
863
864 # On Darwin, the -s option to ld does not work unless we pass -static,
865 # and passing -static unconditionally is a bad idea. So, do not pass -s
866 # at all and darwin.jam will use a separate 'strip' invocation.
867 toolset.flags gcc.link RPATH <target-os>darwin : <dll-path> ;
868 # This does not support -R.
869 toolset.flags gcc.link RPATH_OPTION <target-os>darwin : -rpath ;
870 # -rpath-link is not supported at all.
871
872 # See note [1]
873 toolset.flags gcc.link OPTIONS <target-os>darwin/<runtime-link>static : -static ;
92f5a8d4 874
11fdf7f2
TL
875 # vxworks
876 # On VxWorks we want to reflect what ever special flags have been set in the
877 # environment for the CPU we are targeting in the cross build
878 toolset.flags gcc.link OPTIONS <target-os>vxworks/<strip>on : -Wl,--strip-all ;
879 toolset.flags gcc.link OPTIONS <target-os>vxworks/<link>static : [ os.environ LDFLAGS_STATIC ] ;
880 toolset.flags gcc.link.dll OPTIONS <target-os>vxworks : [ os.environ LDFLAGS_SO ] ;
881 toolset.flags gcc.link OPTIONS <target-os>vxworks/<link>shared : [ os.environ LDFLAGS_DYNAMIC ] ;
92f5a8d4 882
11fdf7f2
TL
883 # default
884
1e59de90 885 local generic-os = [ set.difference $(all-os) : aix darwin vxworks solaris osf hpux iphone appletv ] ;
11fdf7f2
TL
886 # Strip the binary when no debugging is needed. We use --strip-all flag
887 # as opposed to -s since icc (intel's compiler) is generally
888 # option-compatible with and inherits from the gcc toolset, but does not
889 # support -s.
890 toolset.flags gcc.link OPTIONS <target-os>$(generic-os)/<strip>on :
891 -Wl,--strip-all ;
11fdf7f2
TL
892 toolset.flags gcc.link START-GROUP <target-os>$(generic-os) :
893 -Wl,--start-group ;
894 toolset.flags gcc.link END-GROUP <target-os>$(generic-os) : -Wl,--end-group ;
895
1e59de90
TL
896 local rpath-os = [ set.difference $(all-os) : aix darwin vxworks solaris osf hpux windows ] ;
897 toolset.flags gcc.link RPATH <target-os>$(rpath-os) : <dll-path> ;
898 toolset.flags gcc.link RPATH_OPTION <target-os>$(rpath-os) : -rpath ;
899 toolset.flags gcc.link RPATH_LINK <target-os>$(rpath-os) : <xdll-path> ;
900
11fdf7f2
TL
901 # gnu ld has the ability to change the search behaviour for libraries
902 # referenced by the -l switch. These modifiers are -Bstatic and
903 # -Bdynamic and change search for -l switches that follow them. The
904 # following list shows the tried variants. Search stops at the first
905 # variant that has a match.
906 #
907 # *nix: -Bstatic -lxxx
908 # libxxx.a
909 #
910 # *nix: -Bdynamic -lxxx
911 # libxxx.so
912 # libxxx.a
913 #
914 # windows (mingw, cygwin) -Bstatic -lxxx
915 # libxxx.a
916 # xxx.lib
917 #
918 # windows (mingw, cygwin) -Bdynamic -lxxx
919 # libxxx.dll.a
920 # xxx.dll.a
921 # libxxx.a
922 # xxx.lib
923 # cygxxx.dll (*)
924 # libxxx.dll
925 # xxx.dll
926 # libxxx.a
927 #
928 # (*) This is for cygwin
929 # Please note that -Bstatic and -Bdynamic are not a guarantee that a
930 # static or dynamic lib indeed gets linked in. The switches only change
931 # search patterns!
932
933 # On *nix mixing shared libs with static runtime is not a good idea.
934 toolset.flags gcc.link FINDLIBS-ST-PFX <target-os>$(generic-os)/<runtime-link>shared : -Wl,-Bstatic ;
935 toolset.flags gcc.link FINDLIBS-SA-PFX <target-os>$(generic-os)/<runtime-link>shared : -Wl,-Bdynamic ;
936
937 # On windows allow mixing of static and dynamic libs with static
938 # runtime is not a good idea.
939 toolset.flags gcc.link FINDLIBS-ST-PFX <target-os>windows/<runtime-link>static : -Wl,-Bstatic ;
940 toolset.flags gcc.link FINDLIBS-SA-PFX <target-os>windows/<runtime-link>static : -Wl,-Bdynamic ;
941 toolset.flags gcc.link OPTIONS <target-os>windows/<runtime-link>static : -Wl,-Bstatic ;
942
943 toolset.flags gcc.link HAVE_SONAME <target-os>$(generic-os) : "" ;
944 toolset.flags gcc.link SONAME_OPTION <target-os>$(generic-os) : -h ;
945
946 # See note [1]
947 toolset.flags gcc.link OPTIONS <target-os>$(generic-os)/<runtime-link>static : -static ;
948
949 # hpux
950
951 toolset.flags gcc.link OPTIONS <target-os>hpux/<strip>on : -Wl,-s ;
952
92f5a8d4 953 toolset.flags gcc.link HAVE_SONAME <target-os>hpux : "" ;
11fdf7f2
TL
954 toolset.flags gcc.link SONAME_OPTION <target-os>hpux : +h ;
955
956 # osf
957
958 # No --strip-all, just -s.
959 toolset.flags gcc.link OPTIONS <target-os>osf/<strip>on : -Wl,-s ;
960 toolset.flags gcc.link RPATH <target-os>osf : <dll-path> ;
961 # This does not support -R.
962 toolset.flags gcc.link RPATH_OPTION <target-os>osf : -rpath ;
963 # -rpath-link is not supported at all.
964
965 # See note [1]
966 toolset.flags gcc.link OPTIONS <target-os>osf/<runtime-link>static : -static ;
967
968 # sun
969
970 toolset.flags gcc.link OPTIONS <target-os>solaris/<strip>on : -Wl,-s ;
971
972 toolset.flags gcc.link RPATH <target-os>solaris : <dll-path> ;
973 # Solaris linker does not have a separate -rpath-link, but allows using
974 # -L for the same purpose.
975 toolset.flags gcc.link LINKPATH <target-os>solaris : <xdll-path> ;
976
977 # This permits shared libraries with non-PIC code on Solaris.
978 # VP, 2004/09/07: Now that we have -fPIC hardcode in link.dll, the
979 # following is not needed. Whether -fPIC should be hardcoded, is a
980 # separate question.
981 # AH, 2004/10/16: it is still necessary because some tests link against
982 # static libraries that were compiled without PIC.
983 toolset.flags gcc.link OPTIONS <target-os>solaris : -mimpure-text ;
984
985 # See note [1]
986 toolset.flags gcc.link OPTIONS <target-os>solaris/<runtime-link>static : -static ;
b32b8144
FG
987
988 # [1]
989 # For <runtime-link>static we made sure there are no dynamic libraries in the
990 # link. On HP-UX not all system libraries exist as archived libraries (for
991 # example, there is no libunwind.a), so, on this platform, the -static option
992 # cannot be specified.
7c673cae
FG
993}
994
995
996# Enclose the RPATH variable on 'targets' in double quotes, unless it is already
997# enclosed in single quotes. This special casing is done because it is common to
998# pass '$ORIGIN' to linker -- and it has to have single quotes to prevent shell
999# expansion -- and if we add double quotes then the preventing properties of
1000# single quotes disappear.
1001#
1002rule quote-rpath ( targets * )
1003{
1004 local r = [ on $(targets[1]) return $(RPATH) ] ;
1005 if ! [ MATCH ('.*') : $(r) ]
1006 {
1007 r = \"$(r)\" ;
1008 }
1009 RPATH on $(targets) = $(r) ;
1010}
1011
1012# Declare actions for linking.
1013rule link ( targets * : sources * : properties * )
1014{
7c673cae 1015 SPACE on $(targets) = " " ;
7c673cae
FG
1016 quote-rpath $(targets) ;
1017}
1018
20effc67 1019rule link.dll ( targets * : sources * : properties * )
7c673cae 1020{
20effc67 1021 SPACE on $(targets) = " " ;
20effc67 1022 quote-rpath $(targets) ;
7c673cae
FG
1023}
1024
20effc67 1025rule link.mingw ( targets * : sources * : properties * )
b32b8144
FG
1026{
1027 SPACE on $(targets) = " " ;
b32b8144
FG
1028}
1029
20effc67
TL
1030rule link.dll.mingw ( targets * : sources * : properties * )
1031{
1032 SPACE on $(targets) = " " ;
20effc67
TL
1033}
1034
1035actions link.mingw bind LIBRARIES
1036{
1e59de90 1037 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" @($(<:T).rsp:O=FC:<=@":>=":E=$(START-GROUP) "$(>:T)" "$(LIBRARIES:T)" $(FINDLIBS-ST-PFX:T) -l$(FINDLIBS-ST:T) $(FINDLIBS-SA-PFX:T) -l$(FINDLIBS-SA:T) $(END-GROUP)) $(OPTIONS) $(USER_OPTIONS)
20effc67
TL
1038}
1039
1040actions link.dll.mingw bind LIBRARIES
1041{
1e59de90 1042 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" "$(.IMPLIB-COMMAND)$(<[1])" -o "$(<[-1])" -shared @($(<[-1]:T).rsp:O=FC:<=@":>=":E=$(START-GROUP) "$(>:T)" "$(LIBRARIES:T)" $(FINDLIBS-ST-PFX:T) -l$(FINDLIBS-ST:T) $(FINDLIBS-SA-PFX:T) -l$(FINDLIBS-SA:T) $(END-GROUP)) $(OPTIONS) $(USER_OPTIONS)
20effc67
TL
1043}
1044
1045actions link bind LIBRARIES
1046{
1047 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,$(RPATH_OPTION:E=-R)$(SPACE)-Wl,$(RPATH) -Wl,-rpath-link$(SPACE)-Wl,"$(RPATH_LINK)" -o "$(<)" $(START-GROUP) "$(>)" "$(LIBRARIES)" $(FINDLIBS-ST-PFX) -l$(FINDLIBS-ST) $(FINDLIBS-SA-PFX) -l$(FINDLIBS-SA) $(END-GROUP) $(OPTIONS) $(USER_OPTIONS)
1048}
1049
b32b8144
FG
1050actions link.dll bind LIBRARIES
1051{
1052 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,$(RPATH_OPTION:E=-R)$(SPACE)-Wl,$(RPATH) "$(.IMPLIB-COMMAND)$(<[1])" -o "$(<[-1])" $(HAVE_SONAME)-Wl,$(SONAME_OPTION)$(SPACE)-Wl,$(<[-1]:D=) -shared $(START-GROUP) "$(>)" "$(LIBRARIES)" $(FINDLIBS-ST-PFX) -l$(FINDLIBS-ST) $(FINDLIBS-SA-PFX) -l$(FINDLIBS-SA) $(END-GROUP) $(OPTIONS) $(USER_OPTIONS)
1053}
1054
1055###
1056### Archive library generation.
1057###
7c673cae
FG
1058
1059# Default value. Mostly for the sake of intel-linux that inherits from gcc, but
1060# does not have the same logic to set the .AR variable. We can put the same
1061# logic in intel-linux, but that is hardly worth the trouble as on Linux, 'ar'
1062# is always available.
1063.AR = ar ;
1e59de90 1064.ARFLAGS = rsc ;
7c673cae
FG
1065
1066toolset.flags gcc.archive AROPTIONS <archiveflags> ;
1067
1068rule archive ( targets * : sources * : properties * )
1069{
1070 # Always remove archive and start again. Here is the rationale from
1071 #
1072 # Andre Hentz:
1073 #
1074 # I had a file, say a1.c, that was included into liba.a. I moved a1.c to
1075 # a2.c, updated my Jamfiles and rebuilt. My program was crashing with absurd
1076 # errors. After some debugging I traced it back to the fact that a1.o was
1077 # *still* in liba.a
1078 #
1079 # Rene Rivera:
1080 #
1081 # Originally removing the archive was done by splicing an RM onto the
1082 # archive action. That makes archives fail to build on NT when they have
1083 # many files because it will no longer execute the action directly and blow
1084 # the line length limit. Instead we remove the file in a different action,
1085 # just before building the archive.
1086 #
1087 local clean.a = $(targets[1])(clean) ;
1088 TEMPORARY $(clean.a) ;
1089 NOCARE $(clean.a) ;
1090 LOCATE on $(clean.a) = [ on $(targets[1]) return $(LOCATE) ] ;
1091 DEPENDS $(clean.a) : $(sources) ;
1092 DEPENDS $(targets) : $(clean.a) ;
1093 common.RmTemps $(clean.a) : $(targets) ;
1094}
1095
1096# Declare action for creating static libraries.
1097# The letter 'r' means to add files to the archive with replacement. Since we
1098# remove archive, we do not care about replacement, but there is no option "add
1099# without replacement".
1100# The letter 'c' suppresses the warning in case the archive does not exists yet.
1101# That warning is produced only on some platforms, for whatever reasons.
1102#
1103actions piecemeal archive
1104{
f67539c2 1105 "$(.AR)" $(AROPTIONS) $(.ARFLAGS) "$(<)" "$(>)"
7c673cae
FG
1106}
1107
b32b8144
FG
1108###
1109### CPU architecture and instruction set options.
1110###
7c673cae
FG
1111
1112local rule cpu-flags ( toolset variable : architecture : instruction-set + :
1113 values + : default ? )
1114{
1115 if $(default)
1116 {
1117 toolset.flags $(toolset) $(variable)
1118 <architecture>$(architecture)/<instruction-set> : $(values) ;
1119 }
1120 toolset.flags $(toolset) $(variable)
1121 <architecture>/<instruction-set>$(instruction-set)
1122 <architecture>$(architecture)/<instruction-set>$(instruction-set)
1123 : $(values) ;
1124}
1125
1126
1127# Set architecture/instruction-set options.
1128#
1129# x86 and compatible
1130# The 'native' option appeared in gcc 4.2 so we cannot safely use it as default.
1131# Use i686 instead for 32-bit.
1132toolset.flags gcc OPTIONS <architecture>x86/<address-model>32/<instruction-set> : -march=i686 ;
1133cpu-flags gcc OPTIONS : x86 : native : -march=native ;
1134cpu-flags gcc OPTIONS : x86 : i486 : -march=i486 ;
1135cpu-flags gcc OPTIONS : x86 : i586 : -march=i586 ;
1136cpu-flags gcc OPTIONS : x86 : i686 : -march=i686 ;
1137cpu-flags gcc OPTIONS : x86 : pentium : -march=pentium ;
1138cpu-flags gcc OPTIONS : x86 : pentium-mmx : -march=pentium-mmx ;
1139cpu-flags gcc OPTIONS : x86 : pentiumpro : -march=pentiumpro ;
1140cpu-flags gcc OPTIONS : x86 : pentium2 : -march=pentium2 ;
1141cpu-flags gcc OPTIONS : x86 : pentium3 : -march=pentium3 ;
1142cpu-flags gcc OPTIONS : x86 : pentium3m : -march=pentium3m ;
1143cpu-flags gcc OPTIONS : x86 : pentium-m : -march=pentium-m ;
1144cpu-flags gcc OPTIONS : x86 : pentium4 : -march=pentium4 ;
1145cpu-flags gcc OPTIONS : x86 : pentium4m : -march=pentium4m ;
1146cpu-flags gcc OPTIONS : x86 : prescott : -march=prescott ;
1147cpu-flags gcc OPTIONS : x86 : nocona : -march=nocona ;
1148cpu-flags gcc OPTIONS : x86 : core2 : -march=core2 ;
1149cpu-flags gcc OPTIONS : x86 : conroe : -march=core2 ;
1150cpu-flags gcc OPTIONS : x86 : conroe-xe : -march=core2 ;
1151cpu-flags gcc OPTIONS : x86 : conroe-l : -march=core2 ;
1152cpu-flags gcc OPTIONS : x86 : allendale : -march=core2 ;
1153cpu-flags gcc OPTIONS : x86 : wolfdale : -march=core2 -msse4.1 ;
1154cpu-flags gcc OPTIONS : x86 : merom : -march=core2 ;
1155cpu-flags gcc OPTIONS : x86 : merom-xe : -march=core2 ;
1156cpu-flags gcc OPTIONS : x86 : kentsfield : -march=core2 ;
1157cpu-flags gcc OPTIONS : x86 : kentsfield-xe : -march=core2 ;
1158cpu-flags gcc OPTIONS : x86 : yorksfield : -march=core2 ;
1159cpu-flags gcc OPTIONS : x86 : penryn : -march=core2 ;
1160cpu-flags gcc OPTIONS : x86 : corei7 : -march=corei7 ;
1161cpu-flags gcc OPTIONS : x86 : nehalem : -march=corei7 ;
1162cpu-flags gcc OPTIONS : x86 : corei7-avx : -march=corei7-avx ;
1163cpu-flags gcc OPTIONS : x86 : sandy-bridge : -march=corei7-avx ;
1164cpu-flags gcc OPTIONS : x86 : core-avx-i : -march=core-avx-i ;
1165cpu-flags gcc OPTIONS : x86 : ivy-bridge : -march=core-avx-i ;
1166cpu-flags gcc OPTIONS : x86 : haswell : -march=core-avx-i -mavx2 -mfma -mbmi -mbmi2 -mlzcnt ;
b32b8144
FG
1167cpu-flags gcc OPTIONS : x86 : broadwell : -march=broadwell ;
1168cpu-flags gcc OPTIONS : x86 : skylake : -march=skylake ;
1169cpu-flags gcc OPTIONS : x86 : skylake-avx512 : -march=skylake-avx512 ;
1170cpu-flags gcc OPTIONS : x86 : cannonlake : -march=skylake-avx512 -mavx512vbmi -mavx512ifma -msha ;
20effc67
TL
1171cpu-flags gcc OPTIONS : x86 : icelake-client : -march=icelake-client ;
1172cpu-flags gcc OPTIONS : x86 : icelake-server : -march=icelake-server ;
1173cpu-flags gcc OPTIONS : x86 : cascadelake : -march=skylake-avx512 -mavx512vnni ;
1174cpu-flags gcc OPTIONS : x86 : cooperlake : -march=cooperlake ;
1175cpu-flags gcc OPTIONS : x86 : tigerlake : -march=tigerlake ;
7c673cae
FG
1176cpu-flags gcc OPTIONS : x86 : k6 : -march=k6 ;
1177cpu-flags gcc OPTIONS : x86 : k6-2 : -march=k6-2 ;
1178cpu-flags gcc OPTIONS : x86 : k6-3 : -march=k6-3 ;
1179cpu-flags gcc OPTIONS : x86 : athlon : -march=athlon ;
1180cpu-flags gcc OPTIONS : x86 : athlon-tbird : -march=athlon-tbird ;
1181cpu-flags gcc OPTIONS : x86 : athlon-4 : -march=athlon-4 ;
1182cpu-flags gcc OPTIONS : x86 : athlon-xp : -march=athlon-xp ;
1183cpu-flags gcc OPTIONS : x86 : athlon-mp : -march=athlon-mp ;
1184##
1185cpu-flags gcc OPTIONS : x86 : k8 : -march=k8 ;
1186cpu-flags gcc OPTIONS : x86 : opteron : -march=opteron ;
1187cpu-flags gcc OPTIONS : x86 : athlon64 : -march=athlon64 ;
1188cpu-flags gcc OPTIONS : x86 : athlon-fx : -march=athlon-fx ;
1189cpu-flags gcc OPTIONS : x86 : k8-sse3 : -march=k8-sse3 ;
1190cpu-flags gcc OPTIONS : x86 : opteron-sse3 : -march=opteron-sse3 ;
1191cpu-flags gcc OPTIONS : x86 : athlon64-sse3 : -march=athlon64-sse3 ;
1192cpu-flags gcc OPTIONS : x86 : amdfam10 : -march=amdfam10 ;
1193cpu-flags gcc OPTIONS : x86 : barcelona : -march=barcelona ;
1194cpu-flags gcc OPTIONS : x86 : bdver1 : -march=bdver1 ;
1195cpu-flags gcc OPTIONS : x86 : bdver2 : -march=bdver2 ;
1196cpu-flags gcc OPTIONS : x86 : bdver3 : -march=bdver3 ;
b32b8144 1197cpu-flags gcc OPTIONS : x86 : bdver4 : -march=bdver4 ;
7c673cae
FG
1198cpu-flags gcc OPTIONS : x86 : btver1 : -march=btver1 ;
1199cpu-flags gcc OPTIONS : x86 : btver2 : -march=btver2 ;
b32b8144 1200cpu-flags gcc OPTIONS : x86 : znver1 : -march=znver1 ;
20effc67 1201cpu-flags gcc OPTIONS : x86 : znver2 : -march=znver2 ;
7c673cae
FG
1202cpu-flags gcc OPTIONS : x86 : winchip-c6 : -march=winchip-c6 ;
1203cpu-flags gcc OPTIONS : x86 : winchip2 : -march=winchip2 ;
1204cpu-flags gcc OPTIONS : x86 : c3 : -march=c3 ;
1205cpu-flags gcc OPTIONS : x86 : c3-2 : -march=c3-2 ;
20effc67 1206cpu-flags gcc OPTIONS : x86 : c7 : -march=c7 ;
7c673cae
FG
1207##
1208cpu-flags gcc OPTIONS : x86 : atom : -march=atom ;
1209# Sparc
1210cpu-flags gcc OPTIONS : sparc : v7 : -mcpu=v7 : default ;
1211cpu-flags gcc OPTIONS : sparc : cypress : -mcpu=cypress ;
1212cpu-flags gcc OPTIONS : sparc : v8 : -mcpu=v8 ;
1213cpu-flags gcc OPTIONS : sparc : supersparc : -mcpu=supersparc ;
1214cpu-flags gcc OPTIONS : sparc : sparclite : -mcpu=sparclite ;
1215cpu-flags gcc OPTIONS : sparc : hypersparc : -mcpu=hypersparc ;
1216cpu-flags gcc OPTIONS : sparc : sparclite86x : -mcpu=sparclite86x ;
1217cpu-flags gcc OPTIONS : sparc : f930 : -mcpu=f930 ;
1218cpu-flags gcc OPTIONS : sparc : f934 : -mcpu=f934 ;
1219cpu-flags gcc OPTIONS : sparc : sparclet : -mcpu=sparclet ;
1220cpu-flags gcc OPTIONS : sparc : tsc701 : -mcpu=tsc701 ;
1221cpu-flags gcc OPTIONS : sparc : v9 : -mcpu=v9 ;
1222cpu-flags gcc OPTIONS : sparc : ultrasparc : -mcpu=ultrasparc ;
1223cpu-flags gcc OPTIONS : sparc : ultrasparc3 : -mcpu=ultrasparc3 ;
1224# RS/6000 & PowerPC
1225cpu-flags gcc OPTIONS : power : 403 : -mcpu=403 ;
1226cpu-flags gcc OPTIONS : power : 505 : -mcpu=505 ;
1227cpu-flags gcc OPTIONS : power : 601 : -mcpu=601 ;
1228cpu-flags gcc OPTIONS : power : 602 : -mcpu=602 ;
1229cpu-flags gcc OPTIONS : power : 603 : -mcpu=603 ;
1230cpu-flags gcc OPTIONS : power : 603e : -mcpu=603e ;
1231cpu-flags gcc OPTIONS : power : 604 : -mcpu=604 ;
1232cpu-flags gcc OPTIONS : power : 604e : -mcpu=604e ;
1233cpu-flags gcc OPTIONS : power : 620 : -mcpu=620 ;
1234cpu-flags gcc OPTIONS : power : 630 : -mcpu=630 ;
1235cpu-flags gcc OPTIONS : power : 740 : -mcpu=740 ;
1236cpu-flags gcc OPTIONS : power : 7400 : -mcpu=7400 ;
1237cpu-flags gcc OPTIONS : power : 7450 : -mcpu=7450 ;
1238cpu-flags gcc OPTIONS : power : 750 : -mcpu=750 ;
1239cpu-flags gcc OPTIONS : power : 801 : -mcpu=801 ;
1240cpu-flags gcc OPTIONS : power : 821 : -mcpu=821 ;
1241cpu-flags gcc OPTIONS : power : 823 : -mcpu=823 ;
1242cpu-flags gcc OPTIONS : power : 860 : -mcpu=860 ;
1243cpu-flags gcc OPTIONS : power : 970 : -mcpu=970 ;
1244cpu-flags gcc OPTIONS : power : 8540 : -mcpu=8540 ;
1245cpu-flags gcc OPTIONS : power : power : -mcpu=power ;
1246cpu-flags gcc OPTIONS : power : power2 : -mcpu=power2 ;
1247cpu-flags gcc OPTIONS : power : power3 : -mcpu=power3 ;
1248cpu-flags gcc OPTIONS : power : power4 : -mcpu=power4 ;
1249cpu-flags gcc OPTIONS : power : power5 : -mcpu=power5 ;
1250cpu-flags gcc OPTIONS : power : powerpc : -mcpu=powerpc ;
1251cpu-flags gcc OPTIONS : power : powerpc64 : -mcpu=powerpc64 ;
1252cpu-flags gcc OPTIONS : power : rios : -mcpu=rios ;
1253cpu-flags gcc OPTIONS : power : rios1 : -mcpu=rios1 ;
1254cpu-flags gcc OPTIONS : power : rios2 : -mcpu=rios2 ;
1255cpu-flags gcc OPTIONS : power : rsc : -mcpu=rsc ;
1256cpu-flags gcc OPTIONS : power : rs64a : -mcpu=rs64 ;
92f5a8d4
TL
1257cpu-flags gcc OPTIONS : s390x : z196 : -march=z196 ;
1258cpu-flags gcc OPTIONS : s390x : zEC12 : -march=zEC12 ;
1259cpu-flags gcc OPTIONS : s390x : z13 : -march=z13 ;
1260cpu-flags gcc OPTIONS : s390x : z14 : -march=z14 ;
f67539c2 1261cpu-flags gcc OPTIONS : s390x : z15 : -march=z15 ;
1e59de90
TL
1262# ARM
1263cpu-flags gcc OPTIONS : arm : cortex-a9+vfpv3 : -mcpu=cortex-a9 -mfpu=vfpv3 -mfloat-abi=hard ;
1264cpu-flags gcc OPTIONS : arm : cortex-a53 : -mcpu=cortex-a53 ;
1265cpu-flags gcc OPTIONS : arm : cortex-r5 : -mcpu=cortex-r5 ;
1266cpu-flags gcc OPTIONS : arm : cortex-r5+vfpv3-d16 : -mcpu=cortex-r5 -mfpu=vfpv3-d16 -mfloat-abi=hard ;
7c673cae
FG
1267# AIX variant of RS/6000 & PowerPC
1268toolset.flags gcc AROPTIONS <address-model>64/<target-os>aix : "-X64" ;