1#  Copyright (c) 2001 David Abrahams.
2#  Copyright (c) 2002-2003 Rene Rivera.
3#  Copyright (c) 2002-2003 Vladimir Prus.
4#
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)
8
9import "class" : new ;
10import common ;
11import errors ;
12import feature ;
13import generators ;
14import os ;
15import property ;
16import set ;
17import toolset ;
18import type ;
19import unix ;
20
21feature.extend toolset : qcc ;
22
23toolset.inherit-generators qcc : unix : unix.link unix.link.dll ;
24toolset.inherit-flags qcc : unix ;
25toolset.inherit-rules qcc : unix ;
26
27# Initializes the qcc toolset for the given version. If necessary, command may
28# be used to specify where the compiler is located. The parameter 'options' is a
29# space-delimited list of options, each one being specified as
30# <option-name>option-value. Valid option names are: cxxflags, linkflags and
31# linker-type. Accepted values for linker-type are gnu and sun, gnu being the
32# default.
33#
34# Example:
35#   using qcc : 3.4 : : <cxxflags>foo <linkflags>bar <linker-type>sun ;
36#
37rule init ( version ? : command * : options * )
38{
39    local condition = [ common.check-init-parameters qcc : version $(version) ] ;
40    local command = [ common.get-invocation-command qcc : QCC : $(command) ] ;
41    common.handle-options qcc : $(condition) : $(command) : $(options) ;
42}
43
44
45generators.register-c-compiler qcc.compile.c++ : CPP : OBJ : <toolset>qcc ;
46generators.register-c-compiler qcc.compile.c   : C   : OBJ : <toolset>qcc ;
47generators.register-c-compiler qcc.compile.asm : ASM : OBJ : <toolset>qcc ;
48
49
50# Declare flags for compilation.
51toolset.flags qcc.compile OPTIONS <debug-symbols>on : -gstabs+ ;
52
53# Declare flags and action for compilation.
54toolset.flags qcc.compile OPTIONS <optimization>off : -O0 ;
55toolset.flags qcc.compile OPTIONS <optimization>speed : -O3 ;
56toolset.flags qcc.compile OPTIONS <optimization>space : -Os ;
57
58toolset.flags qcc.compile OPTIONS <inlining>off : -Wc,-fno-inline ;
59toolset.flags qcc.compile OPTIONS <inlining>on : -Wc,-Wno-inline ;
60toolset.flags qcc.compile OPTIONS <inlining>full : -Wc,-finline-functions -Wc,-Wno-inline ;
61
62toolset.flags qcc.compile OPTIONS <warnings>off : -w ;
63toolset.flags qcc.compile OPTIONS <warnings>all : -Wc,-Wall ;
64toolset.flags qcc.compile OPTIONS <warnings-as-errors>on : -Wc,-Werror ;
65
66toolset.flags qcc.compile OPTIONS <profiling>on : -p ;
67
68toolset.flags qcc.compile OPTIONS <local-visibility>hidden : -fvisibility=hidden ;
69toolset.flags qcc.compile.c++ OPTIONS <local-visibility>hidden : -fvisibility-inlines-hidden ;
70toolset.flags qcc.compile OPTIONS <local-visibility>protected : -fvisibility=protected ;
71toolset.flags qcc.compile OPTIONS <local-visibility>global : -fvisibility=default ;
72
73toolset.flags qcc.compile OPTIONS <cflags> ;
74toolset.flags qcc.compile.c++ OPTIONS <cxxflags> ;
75toolset.flags qcc.compile DEFINES <define> ;
76toolset.flags qcc.compile INCLUDES <include> ;
77
78toolset.flags qcc.compile OPTIONS <link>shared : -shared ;
79
80toolset.flags qcc.compile.c++ TEMPLATE_DEPTH <c++-template-depth> ;
81
82
83rule compile.c++
84{
85    # Here we want to raise the template-depth parameter value to something
86    # higher than the default value of 17. Note that we could do this using the
87    # feature.set-default rule but we do not want to set the default value for
88    # all toolsets as well.
89    #
90    # TODO: This 'modified default' has been inherited from some 'older Boost
91    # Build implementation' and has most likely been added to make some Boost
92    # library parts compile correctly. We should see what exactly prompted this
93    # and whether we can get around the problem more locally.
94    local template-depth = [ on $(1) return $(TEMPLATE_DEPTH) ] ;
95    if ! $(template-depth)
96    {
97        TEMPLATE_DEPTH on $(1) = 128 ;
98    }
99}
100
101actions compile.c++
102{
103    "$(CONFIG_COMMAND)" -Wc,-ftemplate-depth-$(TEMPLATE_DEPTH) $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
104}
105
106actions compile.c
107{
108    "$(CONFIG_COMMAND)" -lang-c $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
109}
110
111actions compile.asm
112{
113    "$(CONFIG_COMMAND)" $(OPTIONS) -D$(DEFINES) -I"$(INCLUDES)" -c -o "$(<)" "$(>)"
114}
115
116
117# The class checking that we do not try to use the <runtime-link>static property
118# while creating or using a shared library, since it is not supported by qcc/
119# /libc.
120#
121class qcc-linking-generator : unix-linking-generator
122{
123    rule generated-targets ( sources + : property-set : project name ? )
124    {
125        if <runtime-link>static in [ $(property-set).raw ]
126        {
127            local m ;
128            if [ id ] = "qcc.link.dll"
129            {
130                m = "on qcc, DLL can't be build with <runtime-link>static" ;
131            }
132            if ! $(m)
133            {
134                for local s in $(sources)
135                {
136                    local type = [ $(s).type ] ;
137                    if $(type) && [ type.is-derived $(type) SHARED_LIB ]
138                    {
139                        m = "on qcc, using DLLS together with the <runtime-link>static options is not possible " ;
140                    }
141                }
142            }
143            if $(m)
144            {
145                errors.user-error $(m) : "It is suggested to use"
146                    "<runtime-link>static together with <link>static." ;
147            }
148        }
149
150        return [ unix-linking-generator.generated-targets
151            $(sources) : $(property-set) : $(project) $(name) ] ;
152    }
153}
154
155generators.register [ new qcc-linking-generator qcc.link : LIB OBJ : EXE
156    : <toolset>qcc ] ;
157
158generators.register [ new qcc-linking-generator qcc.link.dll : LIB OBJ
159    : SHARED_LIB : <toolset>qcc ] ;
160
161generators.override qcc.prebuilt : builtin.prebuilt ;
162generators.override qcc.searched-lib-generator : searched-lib-generator ;
163
164
165# Declare flags for linking.
166# First, the common flags.
167toolset.flags qcc.link OPTIONS <debug-symbols>on : -gstabs+ ;
168toolset.flags qcc.link OPTIONS <profiling>on : -p ;
169toolset.flags qcc.link OPTIONS <linkflags> ;
170toolset.flags qcc.link LINKPATH <library-path> ;
171toolset.flags qcc.link FINDLIBS-ST <find-static-library> ;
172toolset.flags qcc.link FINDLIBS-SA <find-shared-library> ;
173toolset.flags qcc.link LIBRARIES <library-file> ;
174
175toolset.flags qcc.link FINDLIBS-SA : m ;
176
177# For <runtime-link>static we made sure there are no dynamic libraries in the
178# link.
179toolset.flags qcc.link OPTIONS <runtime-link>static : -static ;
180
181# Assuming this is just like with gcc.
182toolset.flags qcc.link RPATH : <dll-path> : unchecked ;
183toolset.flags qcc.link RPATH_LINK : <xdll-path> : unchecked ;
184
185
186# Declare actions for linking.
187#
188rule link ( targets * : sources * : properties * )
189{
190    SPACE on $(targets) = " " ;
191    # Serialize execution of the 'link' action, since running N links in
192    # parallel is just slower. For now, serialize only qcc links while it might
193    # be a good idea to serialize all links.
194    JAM_SEMAPHORE on $(targets) = <s>qcc-link-semaphore ;
195}
196
197actions link bind LIBRARIES
198{
199    "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -Wl,-rpath-link$(SPACE)-Wl,"$(RPATH_LINK)" -o "$(<)" "$(>)" "$(LIBRARIES)" -l$(FINDLIBS-ST) -l$(FINDLIBS-SA) $(OPTIONS)
200}
201
202
203# Always remove archive and start again. Here is the rationale from Andre Hentz:
204# I had a file, say a1.c, that was included into liba.a. I moved a1.c to a2.c,
205# updated my Jamfiles and rebuilt. My program was crashing with absurd errors.
206# After some debugging I traced it back to the fact that a1.o was *still* in
207# liba.a
208RM = [ common.rm-command ] ;
209if [ os.name ] = NT
210{
211    RM = "if exist \"$(<[1])\" DEL \"$(<[1])\""  ;
212}
213
214
215# Declare action for creating static libraries. The 'r' letter means to add
216# files to the archive with replacement. Since we remove the archive, we do not
217# care about replacement, but there is no option to "add without replacement".
218# The 'c' letter suppresses warnings in case the archive does not exists yet.
219# That warning is produced only on some platforms, for whatever reasons.
220#
221# Use qcc driver to create archive, see
222#     http://www.qnx.com/developers/docs/6.3.2/neutrino/utilities/q/qcc.html
223actions piecemeal archive
224{
225    $(RM) "$(<)"
226    "$(CONFIG_COMMAND)" -A "$(<)" "$(>)"
227}
228
229
230rule link.dll ( targets * : sources * : properties * )
231{
232    SPACE on $(targets) = " " ;
233    JAM_SEMAPHORE on $(targets) = <s>qcc-link-semaphore ;
234}
235
236
237# Differ from 'link' above only by -shared.
238#
239actions link.dll bind LIBRARIES
240{
241    "$(CONFIG_COMMAND)" -L"$(LINKPATH)" -Wl,-R$(SPACE)-Wl,"$(RPATH)" -o "$(<)" -Wl,-h$(SPACE)-Wl,$(<[1]:D=) -shared "$(>)"  "$(LIBRARIES)" -l$(FINDLIBS-ST) -l$(FINDLIBS-SA) $(OPTIONS)
242}
243