1 # Copyright 2020 Rene Rivera
2 # Copyright (c) 2003 Michael Stevens
3 # Copyright (c) 2010-2011 Bryce Lelbach (blelbach@cct.lsu.edu, maintainer)
5 # Use, modification and distribution is subject to the Boost Software
6 # License Version 1.0. (See accompanying file LICENSE_1_0.txt or
7 # http://www.boost.org/LICENSE_1_0.txt)
12 import toolset : flags ;
24 feature.extend-subfeature toolset clang : platform : linux ;
26 toolset.inherit-generators clang-linux
27 <toolset>clang <toolset-clang:platform>linux : gcc
28 : gcc.mingw.link gcc.mingw.link.dll gcc.cygwin.link gcc.cygwin.link.dll ;
29 generators.override clang-linux.prebuilt : builtin.lib-generator ;
30 generators.override clang-linux.prebuilt : builtin.prebuilt ;
31 generators.override clang-linux.searched-lib-generator : searched-lib-generator ;
33 # Override default do-nothing generators.
34 generators.override clang-linux.compile.c.pch : pch.default-c-pch-generator ;
35 generators.override clang-linux.compile.c++.pch : pch.default-cpp-pch-generator ;
37 type.set-generated-target-suffix PCH
38 : <toolset>clang <toolset-clang:platform>linux : pth ;
40 toolset.inherit-rules clang-linux : gcc ;
41 toolset.inherit-flags clang-linux : gcc
43 <threading>multi/<target-os>windows
44 <lto>on/<lto-mode>full
48 if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ] {
49 .debug-configuration = true ;
52 rule init ( version ? : command * : options * ) {
53 command = [ common.get-invocation-command clang-linux : clang++
56 # Determine the version
58 local command-string = \"$(command)\" ;
59 command-string = $(command-string:J=" ") ;
60 version ?= [ MATCH "version ([0-9.]+)"
61 : [ SHELL "$(command-string) --version" ] ] ;
64 local condition = [ common.check-init-parameters clang-linux
65 : version $(version) ] ;
67 common.handle-options clang-linux : $(condition) : $(command) : $(options) ;
68 clang.init-cxxstd-flags clang-linux : $(condition) : $(version) ;
70 # Support for gcc root as the backend, this is mainly useful for clang/gcc on Windows
71 # since on Linux gcc will be the default compiler already located on the PATH.
72 # On Windows it is possible to have multiple versions of mingw(-64)/gcc installed
73 # in different directories. The <root>option can be given so that the gcc backend
74 # can be found at runtime, while the $(command) can be a script that sets the
75 # PATH for both the clang directory and the backende gcc directory
76 # before calling clang++ when compiling/linking.
78 local root = [ feature.get-values <root> : $(options) ] ;
82 # On multilib 64-bit boxes, there are both 32-bit and 64-bit libraries
83 # and all must be added to LD_LIBRARY_PATH. The linker will pick the
84 # right onces. Note that we do not provide a clean way to build a 32-bit
85 # binary using a 64-bit compiler, but user can always pass -m32
87 local lib_path = $(root)/bin $(root)/lib $(root)/lib32 $(root)/lib64 ;
88 if $(.debug-configuration)
90 ECHO "notice:" using gcc libraries with clang"::" $(condition) "::" $(lib_path) ;
92 toolset.flags clang-linux.link RUN_PATH $(condition) : $(lib_path) ;
96 local ranlib = [ feature.get-values <ranlib> : $(options) ] ;
97 if ( ! $(ranlib) ) && $(root)
99 ranlib = $(root)/bin/ranlib ;
101 toolset.flags clang-linux.archive .RANLIB $(condition) : $(ranlib[1]) ;
104 local archiver = [ feature.get-values <archiver> : $(options) ] ;
105 if ( ! $(archiver) ) && $(root)
107 archiver = $(root)/bin/ar ;
109 toolset.flags clang-linux.archive .AR $(condition) : $(archiver[1]) ;
112 ###############################################################################
115 # note: clang silently ignores some of these inlining options
116 # For clang, 'on' and 'full' are identical.
117 toolset.flags clang-linux.compile OPTIONS <inlining>full : -Wno-inline ;
119 toolset.flags clang-linux.compile OPTIONS <threading>multi/<target-os>windows : -pthread ;
120 toolset.flags clang-linux.link OPTIONS <threading>multi/<target-os>windows : -pthread ;
123 toolset.flags clang-linux.compile OPTIONS <lto>on/<lto-mode>thin : -flto=thin ;
124 toolset.flags clang-linux.link OPTIONS <lto>on/<lto-mode>thin : -flto=thin ;
126 toolset.flags clang-linux.compile OPTIONS <lto>on/<lto-mode>full : -flto=full ;
127 toolset.flags clang-linux.link OPTIONS <lto>on/<lto-mode>full : -flto=full ;
130 toolset.flags clang-linux.compile OPTIONS <stdlib>gnu <stdlib>gnu11 : -stdlib=libstdc++ ;
131 toolset.flags clang-linux.link OPTIONS <stdlib>gnu <stdlib>gnu11 : -stdlib=libstdc++ ;
133 toolset.flags clang-linux.compile OPTIONS <stdlib>libc++ : -stdlib=libc++ ;
134 toolset.flags clang-linux.link OPTIONS <stdlib>libc++ : -stdlib=libc++ ;
136 ###############################################################################
137 # C and C++ compilation
139 rule compile.c++ ( targets * : sources * : properties * ) {
140 local pch-file = [ on $(<) return $(PCH_FILE) ] ;
143 DEPENDS $(<) : $(pch-file) ;
144 clang-linux.compile.c++.with-pch $(targets) : $(sources) ;
147 clang-linux.compile.c++.without-pch $(targets) : $(sources) ;
151 actions compile.c++.without-pch {
152 "$(CONFIG_COMMAND)" -c -x c++ $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -o "$(<)" "$(>)"
155 actions compile.c++.with-pch bind PCH_FILE
157 "$(CONFIG_COMMAND)" -c -x c++ $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -Xclang -include-pch -Xclang "$(PCH_FILE)" -include"$(FORCE_INCLUDES)" -o "$(<)" "$(>)"
160 rule compile.c ( targets * : sources * : properties * )
162 local pch-file = [ on $(<) return $(PCH_FILE) ] ;
165 DEPENDS $(<) : $(pch-file) ;
166 clang-linux.compile.c.with-pch $(targets) : $(sources) ;
169 clang-linux.compile.c.without-pch $(targets) : $(sources) ;
173 actions compile.c.without-pch
175 "$(CONFIG_COMMAND)" -c -x c $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -c -o "$(<)" "$(>)"
178 actions compile.c.with-pch bind PCH_FILE
180 "$(CONFIG_COMMAND)" -c -x c $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -Xclang -include-pch -Xclang "$(PCH_FILE)" -include"$(FORCE_INCLUDES)" -c -o "$(<)" "$(>)"
183 ###############################################################################
186 RM = [ common.rm-command ] ;
188 rule compile.c++.pch ( targets * : sources * : properties * ) {
191 actions compile.c++.pch {
192 $(RM) -f "$(<)" && "$(CONFIG_COMMAND)" -c -x c++-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -Xclang -emit-pch -o "$(<)" "$(>)"
195 rule compile.c.pch ( targets * : sources * : properties * ) {
198 actions compile.c.pch
200 $(RM) -f "$(<)" && "$(CONFIG_COMMAND)" -c -x c-header $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -include"$(FORCE_INCLUDES)" -Xclang -emit-pch -o "$(<)" "$(>)"
203 ###############################################################################
208 rule link ( targets * : sources * : properties * ) {
209 SPACE on $(targets) = " " ;
210 JAM_SEMAPHORE on $(targets) = <s>clang-linux-link-semaphore ;
213 local pselect = [ property.select <target-os> : $(properties) ] ;
218 local tosv = [ feature.get-values <target-os> : $(pselect) ] ;
225 else if [ os.name ] in NT
231 link-w $(targets) : $(sources) ;
235 link-o $(targets) : $(sources) ;
239 rule link.dll ( targets * : sources * : properties * ) {
240 SPACE on $(targets) = " " ;
241 JAM_SEMAPHORE on $(targets) = <s>clang-linux-link-semaphore ;
244 local pselect = [ property.select <target-os> : $(properties) ] ;
249 local tosv = [ feature.get-values <target-os> : $(pselect) ] ;
256 else if [ os.name ] in NT
262 link.dll-w $(targets) : $(sources) ;
266 link.dll-o $(targets) : $(sources) ;
270 # Target OS is not Windows, needs the RPATH stuff
271 actions link-o bind LIBRARIES {
272 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" @"@($(<[1]:T).rsp:E=-Wl,-R$(SPACE)-Wl,"$(RPATH)" -Wl,-rpath-link$(SPACE)-Wl,"$(RPATH_LINK)" $(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)
275 # Target OS is not Windows, needs the RPATH and SONAME stuff
276 actions link.dll-o bind LIBRARIES {
277 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" @"@($(<[1]:T).rsp:E=-Wl,-R$(SPACE)-Wl,"$(RPATH)" -Wl,-soname$(SPACE)-Wl,$(<[1]:D=) -shared $(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)
280 # Target OS is Windows, does not need the RPATH stuff
281 actions link-w bind LIBRARIES {
282 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" @"@($(<[1]:T).rsp: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)
285 # Target OS is Windows, does not need the RPATH and SONAME stuff
286 actions link.dll-w bind LIBRARIES {
287 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" -shared @"@($(<[1]:T).rsp: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)