1# Copyright (C) Reece H Dunn 2004 2# Distributed under the Boost Software License, Version 1.0. 3# (See accompanying file LICENSE_1_0.txt or copy at 4# http://www.boost.org/LICENSE_1_0.txt) 5 6#| tag::doc[] 7 8[[bbv2.reference.tools.compiler.cw]] 9= Code Warrior 10 11The `cw` module support CodeWarrior compiler, originally produced by 12Metrowerks and presently developed by Freescale. B2 supports 13only the versions of the compiler that target x86 processors. All such 14versions were released by Metrowerks before acquisition and are not sold 15any longer. The last version known to work is 9.4. 16 17The module is initialized using the following syntax: 18 19---- 20using cw : [version] : [c++-compile-command] : [compiler options] ; 21---- 22 23This statement may be repeated several times, if you want to configure 24several versions of the compiler. 25 26If the command is not specified, B2 will search for a binary 27named `mwcc` in default installation paths and in PATH. 28 29The following options can be provided, using 30_`<option-name>option-value syntax`_: 31 32`cflags`:: 33Specifies additional compiler flags that will be used when compiling C 34sources. 35 36`cxxflags`:: 37Specifies additional compiler flags that will be used when compiling C++ 38sources. 39 40`compileflags`:: 41Specifies additional compiler flags that will be used when compiling both C 42and C++ sources. 43 44`linkflags`:: 45Specifies additional command line options that will be passed to the linker. 46 47`setup`:: 48 The command that sets up environment variables prior to invoking the 49 compiler. If not specified, `cwenv.bat` alongside the compiler binary 50 will be used. 51`compiler`:: 52 The command that compiles C and C++ sources. If not specified, `mwcc` 53 will be used. The command will be invoked after the setup script was 54 executed and adjusted the PATH variable. 55`linker`:: 56 The command that links executables and dynamic libraries. If not 57 specified, `mwld` will be used. The command will be invoked after the 58 setup script was executed and adjusted the PATH variable. 59 60|# # end::doc[] 61 62# based on the msvc.jam toolset 63 64import property ; 65import generators ; 66import os ; 67import type ; 68import toolset : flags ; 69import errors : error ; 70import feature : feature get-values ; 71import path ; 72import sequence : unique ; 73import common ; 74 75if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ] 76{ 77 .debug-configuration = true ; 78} 79 80feature.extend toolset : cw ; 81 82toolset.add-requirements <toolset>cw,<runtime-link>shared:<threading>multi ; 83 84nl = " 85" ; 86 87rule init ( version ? : command * : options * ) 88{ 89 # TODO: fix the $(command[1]) = $(compiler) issue 90 91 setup = [ get-values <setup> : $(options) ] ; 92 setup ?= cwenv.bat ; 93 compiler = [ get-values <compiler> : $(options) ] ; 94 compiler ?= mwcc ; 95 linker = [ get-values <linker> : $(options) ] ; 96 linker ?= mwld ; 97 98 local condition = [ common.check-init-parameters cw : 99 version $(version) ] ; 100 101 command = [ common.get-invocation-command cw : mwcc.exe : $(command) : 102 [ default-paths $(version) ] ] ; 103 104 common.handle-options cw : $(condition) : $(command) : $(options) ; 105 106 local root = [ feature.get-values <root> : $(options) ] ; 107 if $(command) 108 { 109 command = [ common.get-absolute-tool-path $(command[-1]) ] ; 110 } 111 local tool-root = $(command) ; 112 113 setup = $(tool-root)\\$(setup) ; 114 115 # map the batch file in setup so it can be executed 116 117 other-tools = $(tool-root:D) ; 118 root ?= $(other-tools:D) ; 119 120 flags cw.link RUN_PATH $(condition) : 121 "$(root)\\Win32-x86 Support\\Libraries\\Runtime" 122 "$(root)\\Win32-x86 Support\\Libraries\\Runtime\\Libs\\MSL_All-DLLs" ; 123 124 setup = "set \"CWFOLDER="$(root)"\" && call \""$(setup)"\" > nul " ; 125 126 if [ os.name ] = NT 127 { 128 setup = $(setup)" 129" ; 130 } 131 else 132 { 133 setup = "cmd /S /C "$(setup)" \"&&\" " ; 134 } 135 136 # bind the setup command to the tool so it can be executed before the 137 # command 138 139 local prefix = $(setup) ; 140 141 flags cw.compile .CC $(condition) : $(prefix)$(compiler) ; 142 flags cw.link .LD $(condition) : $(prefix)$(linker) ; 143 flags cw.archive .LD $(condition) : $(prefix)$(linker) ; 144 145 if [ MATCH "^([89]\\.)" : $(version) ] 146 { 147 if [ os.name ] = NT 148 { 149 # The runtime libraries 150 flags cw.compile CFLAGS <runtime-link>static/<threading>single/<runtime-debugging>off : -runtime ss ; 151 flags cw.compile CFLAGS <runtime-link>static/<threading>single/<runtime-debugging>on : -runtime ssd ; 152 153 flags cw.compile CFLAGS <runtime-link>static/<threading>multi/<runtime-debugging>off : -runtime sm ; 154 flags cw.compile CFLAGS <runtime-link>static/<threading>multi/<runtime-debugging>on : -runtime smd ; 155 156 flags cw.compile CFLAGS <runtime-link>shared/<runtime-debugging>off : -runtime dm ; 157 flags cw.compile CFLAGS <runtime-link>shared/<runtime-debugging>on : -runtime dmd ; 158 } 159 } 160} 161 162 163local rule default-paths ( version ? ) # FIXME 164{ 165 local possible-paths ; 166 local ProgramFiles = [ common.get-program-files-dir ] ; 167 168 # TODO: add support for cw8 and cw9 detection 169 170 local version-6-path = $(ProgramFiles)"\\Metrowerks\\CodeWarrior" ; 171 possible-paths += $(version-6-path) ; 172 173 # perform post-processing 174 175 possible-paths 176 = $(possible-paths)"\\Other Metrowerks Tools\\Command Line Tools" ; 177 178 possible-paths += [ modules.peek : PATH Path path ] ; 179 180 return $(possible-paths) ; 181} 182 183 184 185 186## declare generators 187 188generators.register-c-compiler cw.compile.c++ : CPP : OBJ : <toolset>cw ; 189generators.register-c-compiler cw.compile.c : C : OBJ : <toolset>cw ; 190 191generators.register-linker cw.link 192 : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB 193 : EXE 194 : <toolset>cw 195 ; 196generators.register-linker cw.link.dll 197 : OBJ SEARCHED_LIB STATIC_LIB IMPORT_LIB 198 : SHARED_LIB IMPORT_LIB 199 : <toolset>cw 200 ; 201 202generators.register-archiver cw.archive 203 : OBJ 204 : STATIC_LIB 205 : <toolset>cw 206 ; 207 208## compilation phase 209 210flags cw WHATEVER <toolset-cw:version> ; 211 212flags cw.compile CFLAGS <debug-symbols>on : -g ; 213flags cw.compile CFLAGS <optimization>off : -O0 ; 214flags cw.compile CFLAGS <optimization>speed : -O4,p ; 215flags cw.compile CFLAGS <optimization>space : -O4,s ; 216flags cw.compile CFLAGS <inlining>off : -inline off ; 217flags cw.compile CFLAGS <inlining>on : -inline on ; 218flags cw.compile CFLAGS <inlining>full : -inline all ; 219flags cw.compile CFLAGS <exception-handling>off : -Cpp_exceptions off ; 220 221 222flags cw.compile CFLAGS <rtti>on : -RTTI on ; 223flags cw.compile CFLAGS <rtti>off : -RTTI off ; 224 225flags cw.compile CFLAGS <warnings>on : -w on ; 226flags cw.compile CFLAGS <warnings>off : -w off ; 227flags cw.compile CFLAGS <warnings>all : -w all ; 228flags cw.compile CFLAGS <warnings>extra : -w all ; 229flags cw.compile CFLAGS <warnings>pedantic : -w all ; 230flags cw.compile CFLAGS <warnings-as-errors>on : -w error ; 231 232flags cw.compile USER_CFLAGS <cflags> : ; 233flags cw.compile.c++ USER_CFLAGS <cxxflags> : ; 234 235flags cw.compile DEFINES <define> ; 236flags cw.compile UNDEFS <undef> ; 237flags cw.compile INCLUDES <include> ; 238 239actions compile.c 240{ 241 $(.CC) -c -cwd include -lang c -U$(UNDEFS) $(CFLAGS) $(USER_CFLAGS) -I- -o "$(<)" @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES)")" 242} 243actions compile.c++ 244{ 245 $(.CC) -c -cwd include -lang c++ -U$(UNDEFS) $(CFLAGS) $(USER_CFLAGS) -I- -o "$(<)" @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)-D$(DEFINES) $(nl)"-I$(INCLUDES)")" 246} 247 248## linking phase 249 250flags cw.link DEF_FILE <def-file> ; 251 252flags cw LINKFLAGS : -search ; 253flags cw LINKFLAGS <debug-symbols>on : -g ; 254flags cw LINKFLAGS <user-interface>console : -subsystem console ; 255flags cw LINKFLAGS <user-interface>gui : -subsystem windows ; 256flags cw LINKFLAGS <user-interface>wince : -subsystem wince ; 257flags cw LINKFLAGS <user-interface>native : -subsystem native ; 258flags cw LINKFLAGS <user-interface>auto : -subsystem auto ; 259 260flags cw LINKFLAGS <main-target-type>LIB/<link>static : -library ; 261 262flags cw.link USER_LINKFLAGS <linkflags> ; 263flags cw.link LINKPATH <library-path> ; 264 265flags cw.link FINDLIBS_ST <find-static-library> ; 266flags cw.link FINDLIBS_SA <find-shared-library> ; 267flags cw.link LIBRARY_OPTION <toolset>cw : "" : unchecked ; 268flags cw.link LIBRARIES_MENTIONED_BY_FILE : <library-file> ; 269 270rule link.dll ( targets + : sources * : properties * ) 271{ 272 DEPENDS $(<) : [ on $(<) return $(DEF_FILE) ] ; 273} 274 275if [ os.name ] in NT 276{ 277 actions archive 278 { 279 if exist "$(<[1])" DEL "$(<[1])" 280 $(.LD) -library -o "$(<[1])" @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")" 281 } 282} 283else # cygwin 284{ 285 actions archive 286 { 287 _bbv2_out_="$(<)" 288 if test -f "$_bbv2_out_" ; then 289 _bbv2_existing_="$(<:W)" 290 fi 291 $(.LD) -library -o "$(<:W)" $_bbv2_existing_ @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")" 292 } 293} 294 295actions link bind DEF_FILE 296{ 297 $(.LD) -o "$(<[1]:W)" -L"$(LINKPATH)" $(LINKFLAGS) $(USER_LINKFLAGS) @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")" 298} 299 300actions link.dll bind DEF_FILE 301{ 302 $(.LD) -shared -o "$(<[1]:W)" -implib "$(<[2]:W)" -L"$(LINKPATH)" $(LINKFLAGS) -f"$(DEF_FILE)" $(USER_LINKFLAGS) @"@($(<[1]:W).rsp:E=$(nl)"$(>)" $(nl)$(LIBRARIES_MENTIONED_BY_FILE) $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_ST:S=.lib)" $(nl)"$(LIBRARY_OPTION)$(FINDLIBS_SA:S=.lib)")" 303} 304 305