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

📄 common.jam

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 JAM
📖 第 1 页 / 共 2 页
字号:
# Copyright 2003, 2005 Dave Abrahams# Copyright 2005, 2006 Rene Rivera# Copyright 2005 Toon Knapen# Copyright 2002, 2003, 2004, 2005, 2006 Vladimir Prus# 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)#   Provides actions common to all toolsets, such as creating directories and# removing files.import os ;import modules ;import utility ;import print ;import type ;import feature ;import errors ;import path ;import sequence ;import toolset ;import virtual-target ;if [ MATCH (--debug-configuration) : [ modules.peek : ARGV ] ]{    .debug-configuration = true ;}if [ MATCH (--show-configuration) : [ modules.peek : ARGV ] ]{    .show-configuration = true ;}# Configurations## The following class helps to manage toolset configurations. Each configuration# has a unique ID and one or more parameters. A typical example of a unique ID# is a condition generated by 'common.check-init-parameters' rule. Other kinds# of IDs can be used. Parameters may include any details about the configuration# like 'command', 'path', etc.## A toolset configuration may be in one of the following states:##   - registered#       Configuration has been registered (e.g. explicitly or by auto-detection#       code) but has not yet been marked as used, i.e. 'toolset.using' rule has#       not yet been called for it.#   - used#       Once called 'toolset.using' rule marks the configuration as 'used'.## The main difference between the states above is that while a configuration is# 'registered' its options can be freely changed. This is useful in particular# for autodetection code - all detected configurations may be safely overwritten# by user code.class configurations{    import errors ;    rule __init__ ( )    {    }    # Registers a configuration.    #    # Returns 'true' if the configuration has been added and an empty value if    # it already exists. Reports an error if the configuration is 'used'.    #    rule register ( id )    {        if $(id) in $(self.used)        {            errors.error "common: the configuration '$(id)' is in use" ;        }        local retval ;        if ! $(id) in $(self.all)        {            self.all += $(id) ;            # Indicate that a new configuration has been added.            retval = true ;        }        return $(retval) ;    }    # Mark a configuration as 'used'.    #    # Returns 'true' if the state of the configuration has been changed to    # 'used' and an empty value if it the state has not been changed. Reports an    # error if the configuration is not known.    #    rule use ( id )    {        if ! $(id) in $(self.all)        {            errors.error "common: the configuration '$(id)' is not known" ;        }        local retval ;        if ! $(id) in $(self.used)        {            self.used += $(id) ;            # Indicate that the configuration has been marked as 'used'.            retval = true ;        }        return $(retval) ;    }    # Return all registered configurations.    #    rule all ( )    {        return $(self.all) ;    }    # Return all used configurations.    #    rule used ( )    {        return $(self.used) ;    }    # Returns the value of a configuration parameter.    #    rule get ( id : param )    {        return $(self.$(param).$(id)) ;    }    # Sets the value of a configuration parameter.    #    rule set ( id : param : value * )    {        self.$(param).$(id) = $(value) ;    }}# The rule for checking toolset parameters. Trailing parameters should all be# parameter name/value pairs. The rule will check that each parameter either has# a value in each invocation or has no value in each invocation. Also, the rule# will check that the combination of all parameter values is unique in all# invocations.## Each parameter name corresponds to a subfeature. This rule will declare a# subfeature the first time a non-empty parameter value is passed and will# extend it with all the values.## The return value from this rule is a condition to be used for flags settings.#rule check-init-parameters ( toolset requirement * : * ){    local sig = $(toolset) ;    local condition = <toolset>$(toolset) ;    local subcondition ;    for local index in 2 3 4 5 6 7 8 9    {        local name = $($(index)[1]) ;        local value = $($(index)[2]) ;        if $(value)-is-not-empty        {            condition = $(condition)-$(value) ;            if $(.had-unspecified-value.$(toolset).$(name))            {                errors.user-error                    "$(toolset) initialization: parameter '$(name)'"                    "inconsistent" : "no value was specified in earlier"                    "initialization" : "an explicit value is specified now" ;            }            # The below logic is for intel compiler. It calls this rule with            # 'intel-linux' and 'intel-win' as toolset, so we need to get the            # base part of toolset name. We can not pass 'intel' as toolset            # because in that case it will be impossible to register versionless            # intel-linux and intel-win toolsets of a specific version.            local t = $(toolset) ;            local m = [ MATCH ([^-]*)- : $(toolset) ] ;            if $(m)            {                t = $(m[1]) ;            }            if ! $(.had-value.$(toolset).$(name))            {                if ! $(.declared-subfeature.$(t).$(name))                {                    feature.subfeature toolset $(t) : $(name) : : propagated ;                    .declared-subfeature.$(t).$(name) = true ;                }                .had-value.$(toolset).$(name) = true ;            }            feature.extend-subfeature toolset $(t) : $(name) : $(value) ;            subcondition += <toolset-$(t):$(name)>$(value) ;        }        else        {            if $(.had-value.$(toolset).$(name))            {                errors.user-error                    "$(toolset) initialization: parameter '$(name)'"                    "inconsistent" : "an explicit value was specified in an"                    "earlier initialization" : "no value is specified now" ;            }            .had-unspecified-value.$(toolset).$(name) = true ;        }        sig = $(sig)$(value:E="")- ;    }    if $(sig) in $(.all-signatures)    {        local message =            "duplicate initialization of $(toolset) with the following parameters: " ;        for local index in 2 3 4 5 6 7 8 9        {            local p = $($(index)) ;            if $(p)            {                message += "$(p[1]) = $(p[2]:E=<unspecified>)" ;            }        }        message += "previous initialization at $(.init-loc.$(sig))" ;        errors.user-error            $(message[1]) : $(message[2]) : $(message[3]) : $(message[4]) :            $(message[5]) : $(message[6]) : $(message[7]) : $(message[8]) ;    }    .all-signatures += $(sig) ;    .init-loc.$(sig) = [ errors.nearest-user-location ] ;    # If we have a requirement, this version should only be applied under that    # condition. To accomplish this we add a toolset requirement that imposes    # the toolset subcondition, which encodes the version.    if $(requirement)    {        local r = <toolset>$(toolset) $(requirement) ;        r = $(r:J=,) ;        toolset.add-requirements $(r):$(subcondition) ;    }    # We add the requirements, if any, to the condition to scope the toolset    # variables and options to this specific version.    condition += $(requirement) ;    if $(.show-configuration)    {        ECHO notice: $(condition) ;    }    return $(condition:J=/) ;}# A helper rule to get the command to invoke some tool. If# 'user-provided-command' is not given, tries to find binary named 'tool' in# PATH and in the passed 'additional-path'. Otherwise, verifies that the first# element of 'user-provided-command' is an existing program.## This rule returns the command to be used when invoking the tool. If we can not# find the tool, a warning is issued. If 'path-last' is specified, PATH is# checked after 'additional-paths' when searching for 'tool'.#rule get-invocation-command-nodefault ( toolset : tool :    user-provided-command * : additional-paths * : path-last ? ){    local command ;    if ! $(user-provided-command)    {        command = [ find-tool $(tool) : $(additional-paths) : $(path-last) ] ;        if ! $(command) && $(.debug-configuration)        {            ECHO "warning: toolset $(toolset) initialization: can not find tool $(tool)" ;            ECHO "warning: initialized from" [ errors.nearest-user-location ] ;        }    }    else    {        command = [ check-tool $(user-provided-command) ] ;        if ! $(command) && $(.debug-configuration)        {            ECHO "warning: toolset $(toolset) initialization: " ;            ECHO "warning: can not find user-provided command " '$(user-provided-command)' ;            ECHO "warning: initialized from" [ errors.nearest-user-location ] ;        }    }    return $(command) ;}# Same as get-invocation-command-nodefault, except that if no tool is found,# returns either the user-provided-command, if present, or the 'tool' parameter.#rule get-invocation-command ( toolset : tool : user-provided-command * :    additional-paths * : path-last ? ){    local result = [ get-invocation-command-nodefault $(toolset) : $(tool) :        $(user-provided-command) : $(additional-paths) : $(path-last) ] ;    if ! $(result)    {        if $(user-provided-command)        {            result = $(user-provided-command) ;        }        else        {            result = $(tool) ;        }    }    return $(result) ;}# Given an invocation command return the absolute path to the command. This# works even if command has no path element and was found on the PATH.#rule get-absolute-tool-path ( command ){    if $(command:D)    {        return $(command:D) ;    }    else    {        local m = [ GLOB [ modules.peek : PATH Path path ] : $(command) $(command).exe ] ;        return $(m[1]:D) ;    }}# Attempts to find tool (binary) named 'name' in PATH and in 'additional-paths'.# If found in PATH, returns 'name' and if found in additional paths, returns# absolute name. If the tool is found in several directories, returns the# first path found. Otherwise, returns an empty string. If 'path-last' is# specified, PATH is searched after 'additional-paths'.#local rule find-tool ( name : additional-paths * : path-last ? ){    local path = [ path.programs-path ] ;    local match = [ path.glob $(path) : $(name) $(name).exe ] ;    local additional-match = [ path.glob $(additional-paths) : $(name) $(name).exe ] ;    local result ;    if $(path-last)    {        result = $(additional-match) ;        if ! $(result) && $(match)        {            result = $(name) ;        }    }    else    {        if $(match)        {            result = $(name) ;        }        else        {            result = $(additional-match) ;        }    }    if $(result)    {        return [ path.native $(result[1]) ] ;    }}# Checks if 'command' can be found either in path or is a full name to an# existing file.#local rule check-tool-aux ( command ){    if $(command:D)    {        if [ path.exists $(command) ]            # Both NT and Cygwin will run .exe files by their unqualified names.            || ( [ os.on-windows ] && [ path.exists $(command).exe ] )            # Only NT will run .bat & .cmd files by their unqualified names.            || ( ( [ os.name ] = NT ) && ( [ path.exists $(command).bat ] ||                [ path.exists $(command).cmd ] ) )        {            return $(command) ;        }    }    else    {        if [ GLOB [ modules.peek : PATH Path path ] : $(command) ]        {            return $(command) ;        }    }}# Checks that a tool can be invoked by 'command'. If command is not an absolute# path, checks if it can be found in 'path'. If comand is an absolute path,# check that it exists. Returns 'command' if ok or empty string otherwise.#local rule check-tool ( xcommand + ){    if [ check-tool-aux $(xcommand[1]) ] ||       [ check-tool-aux $(xcommand[-1]) ]    {        return $(xcommand) ;    }}# Handle common options for toolset, specifically sets the following flag# variables:# - CONFIG_COMMAND to $(command)# - OPTIONS for compile         to the value of <compileflags> in $(options)# - OPTIONS for compile.c       to the value of <cflags>       in $(options)# - OPTIONS for compile.c++     to the value of <cxxflags>     in $(options)# - OPTIONS for compile.fortran to the value of <fflags>       in $(options)# - OPTIONS for link            to the value of <linkflags>    in $(options)#rule handle-options ( toolset : condition * : command * : options * ){    if $(.debug-configuration)    {        ECHO "notice: will use '$(command)' for $(toolset), condition $(condition:E=(empty))" ;    }    #   The last parameter ('unchecked') says it is OK to set flags for another    # module.    toolset.flags $(toolset) CONFIG_COMMAND $(condition) : $(command)        : unchecked ;    toolset.flags $(toolset).compile         OPTIONS $(condition) :        [ feature.get-values <compileflags> : $(options) ] : unchecked ;    toolset.flags $(toolset).compile.c       OPTIONS $(condition) :        [ feature.get-values <cflags>       : $(options) ] : unchecked ;    toolset.flags $(toolset).compile.c++     OPTIONS $(condition) :        [ feature.get-values <cxxflags>     : $(options) ] : unchecked ;    toolset.flags $(toolset).compile.fortran OPTIONS $(condition) :        [ feature.get-values <fflags>       : $(options) ] : unchecked ;    toolset.flags $(toolset).link            OPTIONS $(condition) :        [ feature.get-values <linkflags>    : $(options) ] : unchecked ;}# Returns the location of the "program files" directory on a Windows platform.#rule get-program-files-dir ( ){    local ProgramFiles = [ modules.peek : ProgramFiles ] ;    if $(ProgramFiles)    {        ProgramFiles = "$(ProgramFiles:J= )" ;    }    else    {        ProgramFiles = "c:\\Program Files" ;    }    return $(ProgramFiles) ;}if [ os.name ] = NT{    RM = del /f /q ;    CP = copy ;    IGNORE = "2>nul >nul & setlocal" ;    LN ?= $(CP) ;}else{

⌨️ 快捷键说明

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