-
-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathclang-linux.jam
176 lines (144 loc) · 6.12 KB
/
clang-linux.jam
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# Copyright 2021 Nikita Kniazev
# Copyright 2020 Rene Rivera
# Copyright (c) 2003 Michael Stevens
# Copyright (c) 2010-2011 Bryce Lelbach ([email protected], maintainer)
#
# Use, modification and distribution is subject to the Boost Software
# License Version 1.0. (See accompanying file LICENSE.txt or
# https://www.bfgroup.xyz/b2/LICENSE.txt)
#| tag::doc[]
[[b2.reference.tools.compiler.clang-linux]]
= Clang (GCC frontend)
The `clang-linux` module supports Clang with GCC frontend and has the same
options as link:#b2.reference.tools.compiler.gcc[`gcc`] toolset.
|# # end::doc[]
import common ;
import toolset ;
import feature ;
import toolset : flags ;
import clang ;
import gcc ;
import common ;
import errors ;
import generators ;
import type ;
import numbers ;
import os ;
import property ;
import rc ;
import set ;
feature.extend-subfeature toolset clang : platform : linux ;
toolset.inherit-generators clang-linux
<toolset>clang <toolset-clang:platform>linux : gcc
: gcc.mingw.link gcc.mingw.link.dll gcc.cygwin.link gcc.cygwin.link.dll ;
local all-os = [ feature.values <target-os> ] ;
local all-arch = [ feature.values <architecture> ] ;
toolset.inherit-rules clang-linux : gcc ;
toolset.inherit-flags clang-linux : gcc
: <inlining>full
<lto>on/<lto-mode>full
<lto>on/<lto-mode>fat
<target-os>$(all-os)/<address-model>32
<target-os>$(all-os)/<address-model>64
<target-os>$(all-os)/<architecture>$(all-arch)/<address-model>32
<target-os>$(all-os)/<architecture>$(all-arch)/<address-model>64
: INCLUDE-GCH
;
if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ] {
.debug-configuration = true ;
}
rule init ( version ? : command * : options * ) {
command = [ common.find-compiler clang-linux : clang++ : $(version) : $(command) ] ;
local command-string = [ common.make-command-string $(command) ] ;
if ! $(version) { # ?= operator does not short-circuit
version ?= [ get-short-version $(command-string) ] ;
}
local condition = [ common.check-init-parameters clang-linux
: version $(version) ] ;
common.handle-options clang-linux : $(condition) : $(command) : $(options) ;
clang.init-flags clang-linux : $(condition) : $(version) ;
# Support for gcc root as the backend, this is mainly useful for clang/gcc on Windows
# since on Linux gcc will be the default compiler already located on the PATH.
# On Windows it is possible to have multiple versions of mingw(-64)/gcc installed
# in different directories. The <root>option can be given so that the gcc backend
# can be found at runtime, while the $(command) can be a script that sets the
# PATH for both the clang directory and the backende gcc directory
# before calling clang++ when compiling/linking.
local root = [ feature.get-values <root> : $(options) ] ;
if $(root)
{
# On multilib 64-bit boxes, there are both 32-bit and 64-bit libraries
# and all must be added to LD_LIBRARY_PATH. The linker will pick the
# right onces. Note that we do not provide a clean way to build a 32-bit
# binary using a 64-bit compiler, but user can always pass -m32
# manually.
local lib_path = $(root)/bin $(root)/lib $(root)/lib32 $(root)/lib64 ;
if $(.debug-configuration)
{
ECHO "notice:" using gcc libraries with clang"::" $(condition) "::" $(lib_path) ;
}
toolset.flags clang-linux.link RUN_PATH $(condition) : $(lib_path) ;
}
# - Archive builder.
local archiver = [ feature.get-values <archiver> : $(options) ] ;
if ( ! $(archiver) ) && $(root)
{
archiver = $(root)/bin/ar ;
}
toolset.flags clang-linux.archive .AR $(condition) : $(archiver[1]) ;
# - Resource compiler.
local rc = [ common.get-invocation-command-nodefault clang-linux : windres :
[ feature.get-values <rc> : $(options) ] : $(bin) : search-path ] ;
local rc-type = [ feature.get-values <rc-type> : $(options) ] ;
rc-type ?= windres ;
if ! $(rc)
{
# If we can not find an RC compiler we fallback to a null one that
# creates empty object files. This allows the same Jamfiles to work
# across the board. The null RC uses assembler to create the empty
# objects, so configure that.
rc = [ common.get-invocation-command clang-linux : as : : $(bin) : search-path ]
;
rc-type = null ;
}
rc.configure $(rc) : $(condition) : <rc-type>$(rc-type) ;
}
rule get-full-version ( command-string )
{
return [ common.match-command-output version : "version ([0-9.]+)"
: "$(command-string) --version" ] ;
}
rule get-short-version ( command-string : single-digit-since ? )
{
local version = [ get-full-version $(command-string) ] ;
version = [ SPLIT_BY_CHARACTERS $(version) : . ] ;
import version ;
if [ version.version-less $(version) : $(single-digit-since:E=4) ]
{
return $(version[1-2]:J=.) ;
}
return $(version[1]) ;
}
local rule compile-link-flags ( * )
{
toolset.flags clang-linux.compile OPTIONS $(1) : $(2) ;
toolset.flags clang-linux.link OPTIONS $(1) : $(2) ;
}
###############################################################################
# Flags
toolset.flags clang-linux.compile INCLUDE-PCH : -include-pch ;
# note: clang silently ignores some of these inlining options
# For clang, 'on' and 'full' are identical.
toolset.flags clang-linux.compile OPTIONS <inlining>full : -Wno-inline ;
compile-link-flags <address-model>32 : -m32 ;
compile-link-flags <address-model>64 : -m64 ;
# LTO
toolset.flags clang-linux.compile OPTIONS <lto>on/<lto-mode>thin : -flto=thin ;
toolset.flags clang-linux.link OPTIONS <lto>on/<lto-mode>thin : -flto=thin ;
toolset.flags clang-linux.compile OPTIONS <lto>on/<lto-mode>full : -flto=full ;
toolset.flags clang-linux.link OPTIONS <lto>on/<lto-mode>full : -flto=full ;
# stdlib selection
toolset.flags clang-linux.compile OPTIONS <stdlib>gnu <stdlib>gnu11 : -stdlib=libstdc++ ;
toolset.flags clang-linux.link OPTIONS <stdlib>gnu <stdlib>gnu11 : -stdlib=libstdc++ ;
toolset.flags clang-linux.compile OPTIONS <stdlib>libc++ : -stdlib=libc++ ;
toolset.flags clang-linux.link OPTIONS <stdlib>libc++ : -stdlib=libc++ ;