⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cw-tools.jam

📁 C++的一个好库。。。现在很流行
💻 JAM
字号:
#~ Copyright 2004-2005 Rene Rivera.
#~ Distributed under the Boost Software License, Version 1.0.
#~ (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)

# The following #// line will be used by the regression test table generation
# program as the column heading for HTML tables. Must not include version number.
#//<a href="http://www.metrowerks.com/MW/Develop/Desktop/default.htm">Metrowerks<br>CodeWarrior</a>

# For adding framwork libraries; like <framework>Python, <framework>Carbon, etc.
free-feature framework ;

# singleton variables...
set-as-singleton CW_ROOT CWFOLDER CWFolder CWINSTALL ;

flags cw cw-version : $(CW_VERSION) ;
flags cw cw-root : $(CW_ROOT) ;

cw-root ?= $(CWFolder) ;
cw-root ?= $(CWFOLDER) ;

if $(NT)
{
    for local v in 9.0 8.0 7.0 6.0
    {
        cw-root-$(v) ?= [ W32_GETREG "HKEY_LOCAL_MACHINE\\SOFTWARE\\Metrowerks\\CodeWarrior for Windows\\$(v)" : "PATH" ] ;
        cw-version ?= [ conditional $(cw-root-$(v)) : $(v) ] ;
    }
}

cw-root ?= $(cw-root-$(cw-version)) ;

flags cw CFLAGS <cflags> ;
flags cw C++FLAGS <cxxflags> ;
flags cw DEFINES <define> ;
flags cw UNDEFS <undef> ;
flags cw HDRS <include> ;
flags cw SYSHDRS <sysinclude> ;
flags cw LINKFLAGS <linkflags> ;
flags cw ARFLAGS <arflags> ;
flags cw LIBPATH <library-path> ;
flags cw NEEDLIBS <library-file> ;
flags cw FINDLIBS <find-library> ;
flags cw PREFIX <prefix> ;
if $(OS) = MACOSX
{
    flags cw FRAMEWORKS <framework> ;
}

flags cw cw-errors <errors> ;
flags cw cw-warnings <warnings> ;

# Debug information
flags cw CFLAGS <debug-symbols>on : -g ;
flags cw LINKFLAGS <debug-symbols>on : -g ;

# Optimizations
flags cw CFLAGS <optimization>off : -O0 ;
flags cw CFLAGS <optimization>speed : -opt full ;
flags cw CFLAGS <optimization>space : -O4,s "-opt intrinsics" ;

flags cw CFLAGS <inlining>off : -inline off ;
flags cw CFLAGS <inlining>on : -inline on ;
flags cw CFLAGS <inlining>full : -inline auto -inline level=8 ;

# Target type
flags cw LINKFLAGS <target-type>$(SHARED_TYPES) : -shared ;
if $(NT)
{
    flags cw LINKFLAGS <target-type>$(SHARED_TYPES) : "-export dllexport" ;
}

# Some language related options
flags cw CFLAGS <eh-model>msvc : -exc ms ;
flags cw CFLAGS <include-search>directory : "-cwd proj" ;
flags cw CFLAGS <include-search>source : "-cwd source" ;
flags cw CFLAGS <include-search>paths : "-cwd explicit" ;
flags cw CFLAGS <include-search>relative : "-cwd include" ;
flags cw C++FLAGS <rtti>off : "-RTTI off" ;
flags cw C++FLAGS <rtti>on : "-RTTI on" ;
# CodeWarrior on MacOS defaults to wchar_t support off, contrary
# to what it does on Windows. So "fix" this discrepancy. Don't
# bother with OS type just set this to on for all. After all it's
# standard!
flags cw CFLAGS : "-wchar_t on" ;

# OS subsystem target
if $(NT)
{
    flags cw LINKFLAGS <user-interface>console : "-subsystem console" ;
    flags cw LINKFLAGS <user-interface>gui : "-subsystem windows" ;
    flags cw LINKFLAGS <user-interface>wince : "-subsystem wince" ;
    flags cw LINKFLAGS <user-interface>native : "-subsystem native" ;
    flags cw LINKFLAGS <user-interface>auto : "-subsystem auto" ;
}

# Errors, default to maximum 5 errors
flags cw FLAGS : [ conditional $(cw-errors) : "-maxerrors $(cw-errors[1])" : "-maxerrors 5" ] ;

# Warnings, default to maximum 20 warnings
if off in $(cw-warnings)
{
    flags cw FLAGS : "-warnings off" ;
}
else if error in $(cw-warnings)
{
    flags cw FLAGS : "-warnings error" ;
}
else
{
    flags cw FLAGS : "-warnings on" ;
}
if ! ( off in $(cw-warnings) )
{
    if [ MATCH "^([0-9]+)" : $(cw-warnings) ]
    {
        local cw-maxwarnings = [ MATCH "^([0-9]+)" : $(cw-warnings) ] ;
        cw-warnings = [ difference $(cw-warnings) : $(cw-maxwarnings) ] ;
        flags cw FLAGS : "-maxwarnings $(cw-maxwarnings[1])" ;
    }
    else
    {
        flags cw FLAGS : "-maxwarnings 20" ;
    }
}
cw-warnings = [ difference $(cw-warnings) : on off error ] ;
if $(cw-warnings)
{
    flags cw CFLAGS <warnings>no-illegal-pragmas : "-warnings nopragmas" ;
    flags cw CFLAGS <warnings>illegal-pragmas : "-warnings pragmas" ;
    flags cw CFLAGS <warnings>no-empty-declarations : "-warnings noempty" ;
    flags cw CFLAGS <warnings>empty-declarations : "-warnings empty" ;
    flags cw CFLAGS <warnings>no-empty-declarations : "-warnings noempty" ;
    flags cw CFLAGS <warnings>empty-declarations : "-warnings empty" ;
    flags cw CFLAGS <warnings>no-unwanted-effect : "-warnings nounwanted" ;
    flags cw CFLAGS <warnings>unwanted-effect : "-warnings unwanted" ;
    flags cw CFLAGS <warnings>no-unused-arg : "-warnings nounusedarg" ;
    flags cw CFLAGS <warnings>unused-arg : "-warnings unsedarg" ;
    flags cw CFLAGS <warnings>no-unused-var : "-warnings nounusedvar" ;
    flags cw CFLAGS <warnings>unused-var : "-warnings unsedvar" ;
    flags cw CFLAGS <warnings>no-extra-comma : "-warnings nocomma" ;
    flags cw CFLAGS <warnings>extra-comma : "-warnings comma" ;
    flags cw CFLAGS <warnings>no-pedantic : "-warnings nopedantic" ;
    flags cw CFLAGS <warnings>pedantic : "-warnings pedantic" ;
    flags cw CFLAGS <warnings>no-hidden-virtual : "-warnings nohidden" ;
    flags cw CFLAGS <warnings>hidden-virtual : "-warnings hidden" ;
    flags cw CFLAGS <warnings>no-implicit-convert : "-warnings noimplicit" ;
    flags cw CFLAGS <warnings>implicit-convert : "-warnings implicit" ;
    flags cw CFLAGS <warnings>no-not-inlined : "-warnings nonotinlined" ;
    flags cw CFLAGS <warnings>not-inlined : "-warnings notinlined" ;
    flags cw CFLAGS <warnings>no-inconsistent-class : "-warnings nostructclass" ;
    flags cw CFLAGS <warnings>inconsistent-class : "-warnings structclass" ;
    if $(NT)
    {
        flags cw CFLAGS <warnings>no-unused-expresssion : "-warnings nounusedexpr" ;
        flags cw CFLAGS <warnings>unused-expresssion : "-warnings unsedexpr" ;
        flags cw CFLAGS <warnings>no-structure-pad : "-warnings nopadding" ;
        flags cw CFLAGS <warnings>structure-pad : "-warnings padding" ;
        flags cw CFLAGS <warnings>no-unused-return : "-warnings nonotused" ;
        flags cw CFLAGS <warnings>unused-return : "-warnings notused" ;
        flags cw CFLAGS <warnings>no-pointer-conversion : "-warnings noptrintconv" ;
        flags cw CFLAGS <warnings>pointer-conversion : "-warnings ptrintconv" ;
    }
}
else
{
    if $(NT)
    {
        flags cw CFLAGS : "-warnings nounusedexpr,nounused" ;
    }
    else
    {
        flags cw CFLAGS : "-warnings nounused" ;
    }
}

# Search for files in search paths
flags cw LINKFLAGS : -search ;
flags cw ARFLAGS : -search ;

# Version specific options
if $(cw-version) in 8.0 9.0
{
    # Use latest ISO conforming templates
    flags cw C++FLAGS : -iso_templates on ;
    
    if $(NT)
    {
        # The runtime libraries
        flags cw CFLAGS <runtime-link>static/<threading>single/<runtime-build>release : -runtime ss ;
        flags cw CFLAGS <runtime-link>static/<threading>single/<runtime-build>debug : -runtime ssd ;
        
        flags cw CFLAGS <runtime-link>static/<threading>multi/<runtime-build>release : -runtime sm ;
        flags cw CFLAGS <runtime-link>static/<threading>multi/<runtime-build>debug : -runtime smd ;
        
        flags cw CFLAGS <runtime-link>dynamic/<runtime-build>release : -runtime dm ;
        flags cw CFLAGS <runtime-link>dynamic/<runtime-build>debug : -runtime dmd ;
    }
}
if $(NT) && $(cw-version) in 6.0 7.0 8.0
{
    flags cw PREFIX <user-interface>console/<runtime-link>dynamic : UseDLLPrefix.h ;
}
if $(NT) && $(cw-version) in 7.0
{
    # The runtime libraries
    flags cw STDLIBS <runtime-link>static/<runtime-build>release :
        MSL_C_x86.lib MSL_Runtime_x86.lib msl_c++_x86.lib gdi32.lib user32.lib kernel32.lib ;
    flags cw STDLIBS <runtime-link>dynamic/<runtime-build>release :
        MSL_All-DLL_x86.lib gdi32.lib user32.lib kernel32.lib ;
    flags cw STDLIBS <runtime-link>static/<runtime-build>debug :
        MSL_C_x86_D.lib MSL_Runtime_x86_D.lib msl_c++_x86_D.lib gdi32.lib user32.lib kernel32.lib ;
    flags cw STDLIBS <runtime-link>dynamic/<runtime-build>debug :
        MSL_All-DLL_x86_D.lib gdi32.lib user32.lib kernel32.lib ;
}
if $(NT) && $(cw-version) in 6.0
{
    # The runtime libraries
    flags cw STDLIBS <runtime-link>static :
        ansicx86.lib mwcrtl.lib ansicppx86.lib gdi32.lib user32.lib kernel32.lib ;
    flags cw STDLIBS <runtime-link>dynamic :
        mwcrtldll.lib gdi32.lib user32.lib kernel32.lib ;
}

# The paths to system and runtime libraries
if $(NT)
{
    flags cw CW_SETUP : "call \"$(cw-root)\\Other Metrowerks Tools\\Command Line Tools\\cwenv.bat\" -quiet" ;
    # This is needed after the setup because the CW-9 setup erronously sets the
    # ERRORLEVEL pseudo-var directly overriding the real value. The aregument is
    # quoted to prevent the value from getting set to " " because bjam insertes
    # extra spaces at the end of action commands.
    flags cw CW_CLEAR_ERROR : "set \"ERRORLEVEL=\"" ;
    flags cw CW_LINK_SETUP : "set MWWinx86LibraryFiles=" ;
    flags cw CW_IMPLIB_COMMAND : "-implib " ;
    flags cw CW_RUN_PATH :
        "$(cw-root)\\Win32-x86 Support\\Libraries\\Runtime"
        "$(cw-root)\\Win32-x86 Support\\Libraries\\Runtime\\Libs\\MSL_All-DLLs" ;
    
    flags cw STDLIBPATH : "$(cw-root)\\Win32-x86 Support\\Libraries\\Win32 SDK" ;
    flags cw STDLIBPATH <runtime-link>static : "$(cw-root)\\Win32-x86 Support\\Libraries\\Runtime\\Libs" ;
    flags cw STDLIBPATH <runtime-link>dynamic : "$(cw-root)\\Win32-x86 Support\\Libraries\\Runtime\\Libs\\MSL_All-DLLs" ;
}

# Don't wrap tool messages, they just confuse everyone :-)
flags cw FLAGS : -nowraplines ;

flags cw CW_PREFIX : "-prefix " ;

# CodeWarrior has it's own set of standard headers, so ignore the default.
flags cw STDHDRS : ;

# MacOSX.. only the MSL/Carbon/Mach-O combination is working.
if $(OS) = MACOSX
{
    # We use the compiler for both compiles and link, because we may need
    # to compile the console stubs source. The compiler passes all options
    # down to the linker anyway.
    flags cw MWCC : mwcc ;
    flags cw MWLD : mwcc ;
    # For Carbon we need this prefix file to tell CW that's what we are targetting.
    flags cw PREFIX : MSLCarbonPrefix.h ;
    # We need to add the framework, as it's not added automatically.
    flags cw FRAMEWORKS : Carbon ;
    # For comsole apps we need to compile in the MSL functions that will
    # talk to the MacOSX console.
    flags cw LINKFLAGS <user-interface>console :
        "-prefix MSLCarbonPrefix.h"
        "\"$(CWINSTALL)/MSL/MSL_C/MSL_MacOS/Src/console_OS_X.c\"" ;
}

if $(NT)
{
    flags cw MWCC : mwcc ;
    flags cw MWLD : mwld ;
}

#~ flags cw CFLAGS : -verbose ;
#~ flags cw LINKFLAGS : -verbose ;

#### Link ####
rule Link-action
{
    _ on $(<) = " " ;
    gRUN_PATH($(<)) += $(CW_RUN_PATH) ;
    if $(NT)
    {
        # We can't have the mixture of the same libs going in NEEDLIBS and FINDLIBS.
        # So remove the extras from FINDLIBS.
        local find-libs =
            [ difference
                [ on $(<[1]) return $(FINDLIBS) ] :
                $(gTARGET_BASENAME($(gTARGET_SUBVARIANT($(NEEDLIBS))))) ] ;
        FINDLIBS on $(<) = $(find-libs)$(SUFLIB) ;

        CMD on $(<) = "@" ;
        with-command-file cw-Link-action $(<) : $(>) $(NEEDLIBS) $(NEEDIMPS) ;
    }
    else if $(OS) = MACOSX
    {
        local find-libs = [ on $(<[1]) return $(FINDLIBS) ] ;
        FINDLIBS on $(<) = -l$(find-libs) ;

        CMD on $(<) = "" ;
        cw-Link-action $(<) : $(>) $(NEEDLIBS) $(NEEDIMPS) ;
    }
}

actions cw-Link-action
{
    $(CW_SETUP)
    $(CW_CLEAR_ERROR)
    $(CW_LINK_SETUP)$(STDLIBS:J=;)
    $(MWLD) $(FLAGS) $(LINKFLAGS) "-L$(LIBPATH)" "-L$(STDLIBPATH)" -framework$(_)"$(FRAMEWORKS)" $(CW_IMPLIB_COMMAND)"$(<[2])" -o "$(<[1])" $(CMD)"$(>)" "$(FINDLIBS)"
}

#### Cc #####
rule Cc-action
{
    _ on $(<) = " " ;
    cw-Cc-action $(<) : $(>) ;
}

actions cw-Cc-action
{
    $(CW_SETUP)
    $(CW_CLEAR_ERROR)
    $(MWCC) -c -lang c -U$(UNDEFS) -D$(DEFINES) $(FLAGS) $(CFLAGS) "-I$(HDRS)" -I-$(_)"-I$(STDHDRS)" -I-$(_)"-I$(SYSHDRS)" $(CW_PREFIX)"$(PREFIX)" -o "$(<)" "$(>)"
}

#### C++ ####
rule C++-action
{
    _ on $(<) = " " ;
    cw-C++-action $(<) : $(>) ;
}

actions cw-C++-action
{
    $(CW_SETUP)
    $(CW_CLEAR_ERROR)
    $(MWCC) -c -lang c++ -U$(UNDEFS) -D$(DEFINES) $(FLAGS) $(CFLAGS) $(C++FLAGS) "-I$(HDRS)" -I-$(_)"-I$(STDHDRS)" -I-$(_)"-I$(SYSHDRS)" $(CW_PREFIX)"$(PREFIX)" -o "$(<)" "$(>)"
}

#### Archive ####
rule Archive-action
{
    _ on $(<) = " " ;
    if $(NT)
    {
        local find-libs = [ on $(<[1]) return $(FINDLIBS) ] ;
        FINDLIBS on $(<) = $(find-libs)$(SUFLIB) ;

        CMD on $(<) = "@" ;
        with-command-file cw-Archive-action $(<) : $(>) [ on $(<) return $(NEEDLIBS) ] ;
    }
    else if $(OS) = MACOSX
    {
        local find-libs = [ on $(<[1]) return $(FINDLIBS) ] ;
        FINDLIBS on $(<) = -l$(find-libs) ;

        CMD on $(<) = "" ;
        cw-Archive-action $(<) : $(>) [ on $(<) return $(NEEDLIBS) ] ;
    }
}

## CW in general doesn't produce archive that ranlib is intereted in. So
## don't run ranlib.
rule Ranlib-action
{
}

actions together cw-Archive-action
{
    $(CW_SETUP)
    $(CW_CLEAR_ERROR)
    $(MWLD) -library $(FLAGS) $(ARFLAGS) "-L$(LIBPATH)" "-L$(STDLIBPATH)" -o "$(<)" $(CMD)"$(>)" "$(FINDLIBS)"
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -