1 # Copyright 2021 Nikita Kniazev
2 # Copyright 2020 Rene Rivera
3 # Copyright (c) 2003 Michael Stevens
4 # Copyright (c) 2010-2011 Bryce Lelbach (blelbach@cct.lsu.edu, maintainer)
6 # Use, modification and distribution is subject to the Boost Software
7 # License Version 1.0. (See accompanying file LICENSE.txt or
8 # https://www.bfgroup.xyz/b2/LICENSE.txt)
13 import toolset : flags ;
26 feature.extend-subfeature toolset clang : platform : linux ;
28 toolset.inherit-generators clang-linux
29 <toolset>clang <toolset-clang:platform>linux : gcc
30 : gcc.mingw.link gcc.mingw.link.dll gcc.cygwin.link gcc.cygwin.link.dll ;
31 generators.override clang-linux.prebuilt : builtin.lib-generator ;
32 generators.override clang-linux.prebuilt : builtin.prebuilt ;
33 generators.override clang-linux.searched-lib-generator : searched-lib-generator ;
35 # Override default do-nothing generators.
36 generators.override clang-linux.compile.c.pch : pch.default-c-pch-generator ;
37 generators.override clang-linux.compile.c++.pch : pch.default-cpp-pch-generator ;
39 toolset.inherit-rules clang-linux : gcc ;
40 toolset.inherit-flags clang-linux : gcc
42 <threading>multi/<target-os>windows
43 <lto>on/<lto-mode>full
47 if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ] {
48 .debug-configuration = true ;
51 rule init ( version ? : command * : options * ) {
52 command = [ common.find-compiler clang-linux : clang++ : $(version) : $(command) ] ;
53 local command-string = [ common.make-command-string $(command) ] ;
54 if ! $(version) { # ?= operator does not short-circuit
55 version ?= [ get-short-version $(command-string) ] ;
58 local condition = [ common.check-init-parameters clang-linux
59 : version $(version) ] ;
61 common.handle-options clang-linux : $(condition) : $(command) : $(options) ;
62 clang.init-cxxstd-flags clang-linux : $(condition) : $(version) ;
64 # Support for gcc root as the backend, this is mainly useful for clang/gcc on Windows
65 # since on Linux gcc will be the default compiler already located on the PATH.
66 # On Windows it is possible to have multiple versions of mingw(-64)/gcc installed
67 # in different directories. The <root>option can be given so that the gcc backend
68 # can be found at runtime, while the $(command) can be a script that sets the
69 # PATH for both the clang directory and the backende gcc directory
70 # before calling clang++ when compiling/linking.
72 local root = [ feature.get-values <root> : $(options) ] ;
76 # On multilib 64-bit boxes, there are both 32-bit and 64-bit libraries
77 # and all must be added to LD_LIBRARY_PATH. The linker will pick the
78 # right onces. Note that we do not provide a clean way to build a 32-bit
79 # binary using a 64-bit compiler, but user can always pass -m32
81 local lib_path = $(root)/bin $(root)/lib $(root)/lib32 $(root)/lib64 ;
82 if $(.debug-configuration)
84 ECHO "notice:" using gcc libraries with clang"::" $(condition) "::" $(lib_path) ;
86 toolset.flags clang-linux.link RUN_PATH $(condition) : $(lib_path) ;
90 local archiver = [ feature.get-values <archiver> : $(options) ] ;
91 if ( ! $(archiver) ) && $(root)
93 archiver = $(root)/bin/ar ;
95 toolset.flags clang-linux.archive .AR $(condition) : $(archiver[1]) ;
98 rule get-full-version ( command-string )
100 return [ common.match-command-output version : "version ([0-9.]+)"
101 : "$(command-string) --version" ] ;
104 rule get-short-version ( command-string : single-digit-since ? )
106 local version = [ get-full-version $(command-string) ] ;
107 version = [ SPLIT_BY_CHARACTERS $(version) : . ] ;
110 if [ version.version-less $(version) : $(single-digit-since:E=4) ]
112 return $(version[1-2]:J=.) ;
115 return $(version[1]) ;
118 ###############################################################################
121 local all-os = [ feature.values <target-os> ] ;
123 # note: clang silently ignores some of these inlining options
124 # For clang, 'on' and 'full' are identical.
125 toolset.flags clang-linux.compile OPTIONS <inlining>full : -Wno-inline ;
127 toolset.flags clang-linux.compile OPTIONS <threading>multi/<target-os>windows : -pthread ;
128 toolset.flags clang-linux.link OPTIONS <threading>multi/<target-os>windows : -pthread ;
131 toolset.flags clang-linux.compile OPTIONS <lto>on/<lto-mode>thin : -flto=thin ;
132 toolset.flags clang-linux.link OPTIONS <lto>on/<lto-mode>thin : -flto=thin ;
134 toolset.flags clang-linux.compile OPTIONS <lto>on/<lto-mode>full : -flto=full ;
135 toolset.flags clang-linux.link OPTIONS <lto>on/<lto-mode>full : -flto=full ;
138 toolset.flags clang-linux.compile OPTIONS <stdlib>gnu <stdlib>gnu11 : -stdlib=libstdc++ ;
139 toolset.flags clang-linux.link OPTIONS <stdlib>gnu <stdlib>gnu11 : -stdlib=libstdc++ ;
141 toolset.flags clang-linux.compile OPTIONS <stdlib>libc++ : -stdlib=libc++ ;
142 toolset.flags clang-linux.link OPTIONS <stdlib>libc++ : -stdlib=libc++ ;
144 # Enable response file control
145 toolset.flags clang-linux RESPONSE_FILE_SUB <response-file>auto : a ;
146 toolset.flags clang-linux RESPONSE_FILE_SUB <response-file>file : f ;
147 toolset.flags clang-linux RESPONSE_FILE_SUB <response-file>contents : c ;
149 # Used in actions for multi argument options
151 ###############################################################################
152 # C and C++ compilation
154 rule compile.c++ ( targets * : sources * : properties * ) {
155 DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
158 actions compile.c++ bind PCH_FILE
160 "$(CONFIG_COMMAND)" -c -x c++ $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -Xclang$(_)-include-pch$(_)-Xclang$(_)"$(PCH_FILE)" -include"$(FORCE_INCLUDES)" -o "$(<)" "$(>)"
163 rule compile.c ( targets * : sources * : properties * )
165 DEPENDS $(<) : [ on $(<) return $(PCH_FILE) ] ;
168 actions compile.c bind PCH_FILE
170 "$(CONFIG_COMMAND)" -c -x c $(OPTIONS) $(USER_OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -Xclang$(_)-include-pch$(_)-Xclang$(_)"$(PCH_FILE)" -include"$(FORCE_INCLUDES)" -c -o "$(<)" "$(>)"
173 ###############################################################################
176 local soname-os = [ set.difference $(all-os) : windows ] ;
177 toolset.flags clang-linux.link SONAME_OPT <target-os>$(soname-os) : "-Wl,-soname -Wl," ;
179 actions link bind LIBRARIES {
180 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" @($(<[1]:T).rsp:O=FC:<=@":>=":E=-Wl,-R$(_)-Wl,$(RPATH) -Wl,-rpath-link$(_)-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)
183 actions link.dll bind LIBRARIES {
184 "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -o "$(<)" @($(<[1]:T).rsp:O=FC:<=@":>=":E=-Wl,-R$(_)-Wl,$(RPATH) $(SONAME_OPT)$(<[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)