1 # Copyright (C) Christopher Currie 2003. Permission to copy, use,
2 # modify, sell and distribute this software is granted provided this
3 # copyright notice appears in all copies. This software is provided
4 # "as is" without express or implied warranty, and with no claim as
5 # to its suitability for any purpose.
9 [[bbv2.reference.tools.compiler.sun]]
12 The `sun` module supports the
13 http://developers.sun.com/sunstudio/index.jsp[Sun Studio] C++ compilers
16 The module is initialized using the following syntax:
19 using sun : [version] : [c++-compile-command] : [compiler options] ;
22 This statement may be repeated several times, if you want to configure
23 several versions of the compiler.
25 If the command is not specified, B2 will search for a binary
26 named `CC` in `/opt/SUNWspro/bin` and in PATH.
28 When using this compiler on complex C++ code, such as the
29 http://boost.org[Boost C++ library], it is recommended to specify the
30 following options when initializing the `sun` module:
33 -library=stlport4 -features=tmplife -features=tmplrefstatic
36 See the http://blogs.sun.com/sga/entry/command_line_options[Sun C++
37 Frontend Tales] for details.
39 The following options can be provided, using
40 _`<option-name>option-value syntax`_:
43 Specifies additional compiler flags that will be used when compiling C
47 Specifies additional compiler flags that will be used when compiling C++
51 Specifies additional compiler flags that will be used when compiling both C
55 Specifies additional command line options that will be passed to the linker.
57 Starting with Sun Studio 12, you can create 64-bit applications by using
58 the `address-model=64` property.
65 import toolset : flags ;
70 feature.extend toolset : sun ;
71 toolset.inherit sun : unix ;
72 generators.override sun.prebuilt : builtin.lib-generator ;
73 generators.override sun.prebuilt : builtin.prebuilt ;
74 generators.override sun.searched-lib-generator : searched-lib-generator ;
77 rule init ( version ? : command * : options * )
80 common.check-init-parameters sun : version $(version) ] ;
82 command = [ common.get-invocation-command sun : CC
83 : $(command) : "/opt/SUNWspro/bin" ] ;
85 # Even if the real compiler is not found, put CC to
86 # command line so that user see command line that would have being executed.
89 common.handle-options sun : $(condition) : $(command) : $(options) ;
91 command_c = $(command[1--2]) $(command[-1]:B=cc) ;
93 toolset.flags sun CONFIG_C_COMMAND $(condition) : $(command_c) ;
97 generators.register-c-compiler sun.compile.c : C : OBJ : <toolset>sun ;
98 generators.register-c-compiler sun.compile.c++ : CPP : OBJ : <toolset>sun ;
100 # Declare flags and actions for compilation
101 flags sun.compile OPTIONS <debug-symbols>on : -g ;
102 flags sun.compile OPTIONS <profiling>on : -xprofile=tcov ;
103 flags sun.compile OPTIONS <optimization>speed : -xO4 ;
104 flags sun.compile OPTIONS <optimization>space : -xO2 -xspace ;
105 flags sun.compile OPTIONS <threading>multi : -mt ;
106 flags sun.compile OPTIONS <warnings>off : -erroff ;
107 flags sun.compile OPTIONS <warnings>on : -erroff=%none ;
108 flags sun.compile OPTIONS <warnings>all : -erroff=%none ;
109 flags sun.compile OPTIONS <warnings>extra : -erroff=%none ;
110 flags sun.compile OPTIONS <warnings>pedantic : -erroff=%none ;
111 flags sun.compile OPTIONS <warnings-as-errors>on : -errwarn ;
113 flags sun.compile OPTIONS <local-visibility>hidden : -xldscope=hidden ;
114 flags sun.compile OPTIONS <local-visibility>protected : -xldscope=symbolic ;
115 flags sun.compile OPTIONS <local-visibility>global : -xldscope=global ;
117 flags sun.compile.c++ OPTIONS <inlining>off : +d ;
119 # There are no less than 5 standard library options:
120 # 1) The default, which uses an old version of the Rogue Wave std lib,
121 # also available via -std=sun03.
122 # 2) C++03 mode + STLport, selected via the -library option.
123 # 3) C++03 mode plus the Apache std lib, selected via the -library option.
124 # 4) C++03 or C++11 in g++ compatibility mode, and GNU libstdc++3, selected via -std=c++03/11.
126 # Note that the -std, -library and -compat compiler switches appear to be largely mutually
127 # incompatible, and that going forward the -std switch seems to be the preferred one.
129 # See http://docs.oracle.com/cd/E37069_01/html/E37075/bkamw.html#OSSCPgnaof
132 flags sun.compile.c++ OPTIONS <stdlib>sun-stlport : -library=stlport4 -compat=5 -features=zla ;
133 flags sun.link OPTIONS <stdlib>sun-stlport : -library=stlport4 -compat=5 ;
135 flags sun.compile.c++ OPTIONS <stdlib>apache : -library=stdcxx4 -compat=5 -features=zla ;
136 flags sun.link OPTIONS <stdlib>apache : -library=stdcxx4 -compat=5 ;
138 flags sun.compile.c++ OPTIONS <stdlib>gnu : -std=c++03 ;
139 flags sun.compile.c++ DEFINES <stdlib>gnu : _GLIBCXX_USE_CXX11_ABI=0 ;
140 flags sun.link OPTIONS <stdlib>gnu : -std=c++03 ;
142 flags sun.compile.c++ OPTIONS <stdlib>gnu11 : -std=c++11 ;
143 flags sun.compile.c++ DEFINES <stdlib>gnu11 : _GLIBCXX_USE_CXX11_ABI=1 ;
144 flags sun.link OPTIONS <stdlib>gnu11 : -std=c++11 ;
146 # The -m32 and -m64 options are supported starting
147 # with Sun Studio 12. On earlier compilers, the
148 # 'address-model' feature is not supported and should not
149 # be used. Instead, use -xarch=generic64 command line
151 # See http://svn.boost.org/trac/boost/ticket/1186
153 flags sun OPTIONS <address-model>32 : -m32 ;
154 flags sun OPTIONS <address-model>64 : -m64 ;
155 # On sparc, there's a difference between -Kpic
156 # and -KPIC. The first is slightly more efficient,
157 # but has the limits on the size of GOT table.
158 # For minimal fuss on user side, we use -KPIC here.
159 # See http://svn.boost.org/trac/boost/ticket/1186#comment:6
160 # for detailed explanation.
161 flags sun OPTIONS <link>shared : -KPIC ;
163 flags sun.compile OPTIONS <cflags> ;
164 flags sun.compile.c++ OPTIONS <cxxflags> ;
165 flags sun.compile DEFINES <define> ;
166 flags sun.compile INCLUDES <include> ;
170 "$(CONFIG_C_COMMAND)" $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
175 "$(CONFIG_COMMAND)" $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
178 # Declare flags and actions for linking
179 flags sun.link OPTIONS <debug-symbols>on : -g ;
180 # Strip the binary when no debugging is needed
181 flags sun.link OPTIONS <debug-symbols>off : -s ;
182 flags sun.link OPTIONS <profiling>on : -xprofile=tcov ;
183 flags sun.link OPTIONS <threading>multi : -mt ;
184 flags sun.link OPTIONS <linkflags> ;
185 flags sun.link LINKPATH <library-path> ;
186 flags sun.link FINDLIBS-ST <find-static-library> ;
187 flags sun.link FINDLIBS-SA <find-shared-library> ;
188 flags sun.link LIBRARIES <library-file> ;
189 flags sun.link LINK-RUNTIME <runtime-link>static : static ;
190 flags sun.link LINK-RUNTIME <runtime-link>shared : dynamic ;
191 flags sun.link RPATH <dll-path> ;
192 # On gcc, there are separate options for dll path at runtime and
193 # link time. On Solaris, there's only one: -R, so we have to use
194 # it, even though it's bad idea.
195 flags sun.link RPATH <xdll-path> ;
197 # The POSIX real-time library is always needed (nanosleep, clock_gettime etc.)
198 flags sun.link FINDLIBS-SA : rt ;
200 rule link ( targets * : sources * : properties * )
202 SPACE on $(targets) = " " ;
205 actions link bind LIBRARIES
207 "$(CONFIG_COMMAND)" $(OPTIONS) -L"$(LINKPATH)" -R"$(RPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -Bdynamic -l$(FINDLIBS-SA) -Bstatic -l$(FINDLIBS-ST) -B$(LINK-RUNTIME)
210 # Slight mods for dlls
211 rule link.dll ( targets * : sources * : properties * )
213 SPACE on $(targets) = " " ;
216 actions link.dll bind LIBRARIES
218 "$(CONFIG_COMMAND)" $(OPTIONS) -L"$(LINKPATH)" -R"$(RPATH)" -o "$(<)" -h$(<[1]:D=) -G "$(>)" "$(LIBRARIES)" -Bdynamic -l$(FINDLIBS-SA) -Bstatic -l$(FINDLIBS-ST) -B$(LINK-RUNTIME)
221 # Declare action for creating static libraries
222 actions piecemeal archive
224 "$(CONFIG_COMMAND)" -xar -o "$(<)" "$(>)"