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. 6 7#| tag::doc[] 8 9[[bbv2.reference.tools.compiler.sun]] 10= Sun Studio 11 12The `sun` module supports the 13http://developers.sun.com/sunstudio/index.jsp[Sun Studio] C++ compilers 14for the Solaris OS. 15 16The module is initialized using the following syntax: 17 18---- 19using sun : [version] : [c++-compile-command] : [compiler options] ; 20---- 21 22This statement may be repeated several times, if you want to configure 23several versions of the compiler. 24 25If the command is not specified, B2 will search for a binary 26named `CC` in `/opt/SUNWspro/bin` and in PATH. 27 28When using this compiler on complex C++ code, such as the 29http://boost.org[Boost C++ library], it is recommended to specify the 30following options when initializing the `sun` module: 31 32---- 33-library=stlport4 -features=tmplife -features=tmplrefstatic 34---- 35 36See the http://blogs.sun.com/sga/entry/command_line_options[Sun C++ 37Frontend Tales] for details. 38 39The following options can be provided, using 40_`<option-name>option-value syntax`_: 41 42`cflags`:: 43Specifies additional compiler flags that will be used when compiling C 44sources. 45 46`cxxflags`:: 47Specifies additional compiler flags that will be used when compiling C++ 48sources. 49 50`compileflags`:: 51Specifies additional compiler flags that will be used when compiling both C 52and C++ sources. 53 54`linkflags`:: 55Specifies additional command line options that will be passed to the linker. 56 57Starting with Sun Studio 12, you can create 64-bit applications by using 58the `address-model=64` property. 59 60|# # end::doc[] 61 62import property ; 63import generators ; 64import os ; 65import toolset : flags ; 66import feature ; 67import type ; 68import common ; 69 70feature.extend toolset : sun ; 71toolset.inherit sun : unix ; 72generators.override sun.prebuilt : builtin.lib-generator ; 73generators.override sun.prebuilt : builtin.prebuilt ; 74generators.override sun.searched-lib-generator : searched-lib-generator ; 75 76 77rule init ( version ? : command * : options * ) 78{ 79 local condition = [ 80 common.check-init-parameters sun : version $(version) ] ; 81 82 command = [ common.get-invocation-command sun : CC 83 : $(command) : "/opt/SUNWspro/bin" ] ; 84 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. 87 command ?= CC ; 88 89 common.handle-options sun : $(condition) : $(command) : $(options) ; 90 91 command_c = $(command[1--2]) $(command[-1]:B=cc) ; 92 93 toolset.flags sun CONFIG_C_COMMAND $(condition) : $(command_c) ; 94} 95 96# Declare generators 97generators.register-c-compiler sun.compile.c : C : OBJ : <toolset>sun ; 98generators.register-c-compiler sun.compile.c++ : CPP : OBJ : <toolset>sun ; 99 100# Declare flags and actions for compilation 101flags sun.compile OPTIONS <debug-symbols>on : -g ; 102flags sun.compile OPTIONS <profiling>on : -xprofile=tcov ; 103flags sun.compile OPTIONS <optimization>speed : -xO4 ; 104flags sun.compile OPTIONS <optimization>space : -xO2 -xspace ; 105flags sun.compile OPTIONS <threading>multi : -mt ; 106flags sun.compile OPTIONS <warnings>off : -erroff ; 107flags sun.compile OPTIONS <warnings>on : -erroff=%none ; 108flags sun.compile OPTIONS <warnings>all : -erroff=%none ; 109flags sun.compile OPTIONS <warnings>extra : -erroff=%none ; 110flags sun.compile OPTIONS <warnings>pedantic : -erroff=%none ; 111flags sun.compile OPTIONS <warnings-as-errors>on : -errwarn ; 112 113flags sun.compile OPTIONS <local-visibility>hidden : -xldscope=hidden ; 114flags sun.compile OPTIONS <local-visibility>protected : -xldscope=symbolic ; 115flags sun.compile OPTIONS <local-visibility>global : -xldscope=global ; 116 117flags sun.compile.c++ OPTIONS <inlining>off : +d ; 118 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. 125# 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. 128# 129# See http://docs.oracle.com/cd/E37069_01/html/E37075/bkamw.html#OSSCPgnaof 130# 131 132flags sun.compile.c++ OPTIONS <stdlib>sun-stlport : -library=stlport4 -compat=5 -features=zla ; 133flags sun.link OPTIONS <stdlib>sun-stlport : -library=stlport4 -compat=5 ; 134 135flags sun.compile.c++ OPTIONS <stdlib>apache : -library=stdcxx4 -compat=5 -features=zla ; 136flags sun.link OPTIONS <stdlib>apache : -library=stdcxx4 -compat=5 ; 137 138flags sun.compile.c++ OPTIONS <stdlib>gnu : -std=c++03 ; 139flags sun.compile.c++ DEFINES <stdlib>gnu : _GLIBCXX_USE_CXX11_ABI=0 ; 140flags sun.link OPTIONS <stdlib>gnu : -std=c++03 ; 141 142flags sun.compile.c++ OPTIONS <stdlib>gnu11 : -std=c++11 ; 143flags sun.compile.c++ DEFINES <stdlib>gnu11 : _GLIBCXX_USE_CXX11_ABI=1 ; 144flags sun.link OPTIONS <stdlib>gnu11 : -std=c++11 ; 145 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 150# option. 151# See http://svn.boost.org/trac/boost/ticket/1186 152# for details. 153flags sun OPTIONS <address-model>32 : -m32 ; 154flags 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. 161flags sun OPTIONS <link>shared : -KPIC ; 162 163flags sun.compile OPTIONS <cflags> ; 164flags sun.compile.c++ OPTIONS <cxxflags> ; 165flags sun.compile DEFINES <define> ; 166flags sun.compile INCLUDES <include> ; 167 168actions compile.c 169{ 170 "$(CONFIG_C_COMMAND)" $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)" 171} 172 173actions compile.c++ 174{ 175 "$(CONFIG_COMMAND)" $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)" 176} 177 178# Declare flags and actions for linking 179flags sun.link OPTIONS <debug-symbols>on : -g ; 180# Strip the binary when no debugging is needed 181flags sun.link OPTIONS <debug-symbols>off : -s ; 182flags sun.link OPTIONS <profiling>on : -xprofile=tcov ; 183flags sun.link OPTIONS <threading>multi : -mt ; 184flags sun.link OPTIONS <linkflags> ; 185flags sun.link LINKPATH <library-path> ; 186flags sun.link FINDLIBS-ST <find-static-library> ; 187flags sun.link FINDLIBS-SA <find-shared-library> ; 188flags sun.link LIBRARIES <library-file> ; 189flags sun.link LINK-RUNTIME <runtime-link>static : static ; 190flags sun.link LINK-RUNTIME <runtime-link>shared : dynamic ; 191flags 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. 195flags sun.link RPATH <xdll-path> ; 196 197# The POSIX real-time library is always needed (nanosleep, clock_gettime etc.) 198flags sun.link FINDLIBS-SA : rt ; 199 200rule link ( targets * : sources * : properties * ) 201{ 202 SPACE on $(targets) = " " ; 203} 204 205actions link bind LIBRARIES 206{ 207 "$(CONFIG_COMMAND)" $(OPTIONS) -L"$(LINKPATH)" -R"$(RPATH)" -o "$(<)" "$(>)" "$(LIBRARIES)" -Bdynamic -l$(FINDLIBS-SA) -Bstatic -l$(FINDLIBS-ST) -B$(LINK-RUNTIME) 208} 209 210# Slight mods for dlls 211rule link.dll ( targets * : sources * : properties * ) 212{ 213 SPACE on $(targets) = " " ; 214} 215 216actions link.dll bind LIBRARIES 217{ 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) 219} 220 221# Declare action for creating static libraries 222actions piecemeal archive 223{ 224 "$(CONFIG_COMMAND)" -xar -o "$(<)" "$(>)" 225} 226 227