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

📄 python.jam

📁 Boost provides free peer-reviewed portable C++ source libraries. We emphasize libraries that work
💻 JAM
📖 第 1 页 / 共 3 页
字号:
# Copyright 2004 Vladimir Prus.# Distributed under the Boost Software License, Version 1.0. (See# accompanying file LICENSE_1_0.txt or copy at# http://www.boost.org/LICENSE_1_0.txt)# Support for Python and the the Boost.Python library.## This module defines## - a project 'python' with a target 'python' in it, that corresponds to the#   python library## - a main target rule 'python-extension' which can be used to build a python#   extension.## Extensions that use Boost.Python must explicitly link to it.import type ;import testing ;import generators ;import project ;import errors ;import targets ;import "class" : new ;import os ;import common ;import toolset ;import regex ;import numbers ;import string ;import property ;import sequence ;import path ;import feature ;import set ;import builtin ;import version ;# Make this module a project.project.initialize $(__name__) ;project python ;# Save the project so that if 'init' is called several times we define new# targets in the python project, not in whatever project we were called by..project = [ project.current ] ;# Dynamic linker lib. Necessary to specify it explicitly on some platforms.lib dl ;# This contains 'openpty' function need by python. Again, on some system need to# pass this to linker explicitly.lib util ;# Python uses pthread symbols.lib pthread ;# Extra library needed by phtread on some platforms.lib rt ;# The pythonpath feature specifies additional elements for the PYTHONPATH# environment variable, set by run-pyd. For example, pythonpath can be used to# access Python modules that are part of the product being built, but are not# installed in the development system's default paths.feature.feature pythonpath : : free optional path ;# Initializes the Python toolset. Note that all parameters are optional.## - version -- the version of Python to use. Should be in Major.Minor format,#   for example 2.3.  Do not include the subminor version.## - cmd-or-prefix: Preferably, a command that invokes a Python interpreter.#   Alternatively, the installation prefix for Python libraries and includes. If#   empty, will be guessed from the version, the platform's installation#   patterns, and the python executables that can be found in PATH.## - includes: the include path to Python headers. If empty, will be guessed.## - libraries: the path to Python library binaries. If empty, will be guessed.#   On MacOS/Darwin, you can also pass the path of the Python framework.## - condition: if specified, should be a set of properties that are matched#   against the build configuration when Boost.Build selects a Python#   configuration to use.## - extension-suffix: A string to append to the name of extension modules before#   the true filename extension.  Ordinarily we would just compute this based on#   the value of the <python-debugging> feature. However ubuntu's python-dbg#   package uses the windows convention of appending _d to debug-build extension#   modules. We have no way of detecting ubuntu, or of probing python for the#   "_d" requirement, and if you configure and build python using#   --with-pydebug, you'll be using the standard *nix convention. Defaults to ""#   (or "_d" when targeting windows and <python-debugging> is set).## Example usage:##   using python 2.3 ;#   using python 2.3 : /usr/local/bin/python ;#rule init ( version ? : cmd-or-prefix ? : includes * : libraries ?    : condition * : extension-suffix ? ){    project.push-current $(.project) ;    debug-message Configuring python... ;    for local v in version cmd-or-prefix includes libraries condition    {        if $($(v))        {            debug-message "  user-specified "$(v): \"$($(v))\" ;        }    }    configure $(version) : $(cmd-or-prefix) : $(includes) : $(libraries) : $(condition) : $(extension-suffix) ;    project.pop-current ;}# A simpler version of SHELL that grabs stderr as well as stdout, but returns# nothing if there was an error.#local rule shell-cmd ( cmd ){    debug-message running command '$(cmd)" 2>&1"' ;    x = [ SHELL $(cmd)" 2>&1" : exit-status ] ;    if $(x[2]) = 0    {        return $(x[1]) ;    }    else    {        return ;    }}# Try to identify Cygwin symlinks. Invoking such a file directly as an NT# executable from a native Windows build of bjam would be fatal to the bjam# process. One /can/ invoke them through sh.exe or bash.exe, if you can prove# that those are not also symlinks. ;-)## If a symlink is found returns non-empty; we try to extract the target of the# symlink from the file and return that.## Note: 1. only works on NT  2. path is a native path.local rule is-cygwin-symlink ( path ){    local is-symlink = ;    # Look for a file with the given path having the S attribute set, as cygwin    # symlinks do. /-C means "do not use thousands separators in file sizes."    local dir-listing = [ shell-cmd "DIR /-C /A:S \""$(path)"\"" ] ;    if $(dir-listing)    {        # Escape any special regex characters in the base part of the path.        local base-pat = [ regex.escape $(path:D=) : ].[()*+?|\\$^ : \\ ] ;        # Extract the file's size from the directory listing.        local size-of-system-file = [ MATCH "([0-9]+) "$(base-pat) : $(dir-listing) : 1 ] ;        # If the file has a reasonably small size, look for the special symlink        # identification text.        if $(size-of-system-file) && [ numbers.less $(size-of-system-file) 1000 ]        {            local link = [ SHELL "FIND /OFF \"!<symlink>\" \""$(path)"\" 2>&1" ] ;            if $(link[2]) != 0            {                local nl = "" ;                is-symlink = [ MATCH ".*!<symlink>([^"$(nl)"]*)" : $(link[1]) : 1 ] ;                if $(is-symlink)                {                    is-symlink = [ *nix-path-to-native $(is-symlink) ] ;                    is-symlink = $(is-symlink:R=$(path:D)) ;                }            }        }    }    return $(is-symlink) ;}# Append ext to each member of names that does not contain '.'.#local rule default-extension ( names * : ext * ){    local result ;    for local n in $(names)    {        switch $(n)        {            case *.* : result += $(n) ;            case * : result += $(n)$(ext) ;        }    }    return $(result) ;}# Tries to determine whether invoking "cmd" would actually attempt to launch a# cygwin symlink.## Note: only works on NT.#local rule invokes-cygwin-symlink ( cmd ){    local dirs = $(cmd:D) ;    if ! $(dirs)    {        dirs = . [ os.executable-path ] ;    }    local base = [ default-extension $(cmd:D=) : .exe .cmd .bat ] ;    local paths = [ GLOB $(dirs) : $(base) ] ;    if $(paths)    {        # Make sure we have not run into a Cygwin symlink. Invoking such a file        # as an NT executable would be fatal for the bjam process.        return [ is-cygwin-symlink $(paths[1]) ] ;    }}local rule debug-message ( message * ){    if --debug-configuration in [ modules.peek : ARGV ]    {        ECHO notice: [python-cfg] $(message) ;    }}# Like W32_GETREG, except prepend HKEY_CURRENT_USER\SOFTWARE and# HKEY_LOCAL_MACHINE\SOFTWARE to the first argument, returning the first result# found. Also accounts for the fact that on 64-bit machines, 32-bit software has# its own area, under SOFTWARE\Wow6432node.#local rule software-registry-value ( path : data ? ){    local result ;    for local root in HKEY_CURRENT_USER HKEY_LOCAL_MACHINE    {        for local x64elt in "" Wow6432node\\ # Account for 64-bit windows        {            if ! $(result)            {                result = [ W32_GETREG $(root)\\SOFTWARE\\$(x64elt)$(path) : $(data) ] ;            }        }    }    return $(result) ;}.windows-drive-letter-re = ^([A-Za-z]):[\\/](.*) ;.cygwin-drive-letter-re = ^/cygdrive/([a-z])/(.*) ;.working-directory = [ PWD ] ;.working-drive-letter = [ SUBST $(.working-directory) $(.windows-drive-letter-re) $1 ] ;.working-drive-letter ?= [ SUBST $(.working-directory) $(.cygwin-drive-letter-re) $1 ] ;local rule windows-to-cygwin-path ( path ){    # If path is rooted with a drive letter, rewrite it using the /cygdrive    # mountpoint.    local p = [ SUBST $(path:T) $(.windows-drive-letter-re) /cygdrive/$1/$2 ] ;    # Else if path is rooted without a drive letter, use the working directory.    p ?= [ SUBST $(path:T) ^/(.*) /cygdrive/$(.working-drive-letter:L)/$2 ] ;    # Else return the path unchanged.    return $(p:E=$(path:T)) ;}# :W only works in Cygwin builds of bjam.  This one works on NT builds as well.#local rule cygwin-to-windows-path ( path ){    path = $(path:R="") ; # strip any trailing slash    local drive-letter = [ SUBST $(path) $(.cygwin-drive-letter-re) $1:/$2 ] ;    if $(drive-letter)    {        path = $(drive-letter) ;    }    else if $(path:R=/x) = $(path) # already rooted?    {        # Look for a cygwin mount that includes each head sequence in $(path).        local head = $(path) ;        local tail = "" ;        while $(head)        {            local root = [ software-registry-value                "Cygnus Solutions\\Cygwin\\mounts v2\\"$(head) : native ] ;            if $(root)            {                path = $(tail:R=$(root)) ;                head = ;            }            tail = $(tail:R=$(head:D=)) ;            if $(head) = /            {                head = ;            }            else            {                head = $(head:D) ;            }        }    }    return [ regex.replace $(path:R="") / \\ ] ;}# Convert a *nix path to native.#local rule *nix-path-to-native ( path ){    if [ os.name ] = NT    {        path = [ cygwin-to-windows-path $(path) ] ;    }    return $(path) ;}# Convert an NT path to native.#local rule windows-path-to-native ( path ){    if [ os.name ] = NT    {        return $(path) ;    }    else    {        return [ windows-to-cygwin-path $(path) ] ;    }}# Return nonempty if path looks like a windows path, i.e. it starts with a drive# letter or contains backslashes.#local rule guess-windows-path ( path ){    return [ SUBST $(path) ($(.windows-drive-letter-re)|.*([\\]).*) $1 ] ;}local rule path-to-native ( paths * ){    local result ;    for local p in $(paths)    {        if [ guess-windows-path $(p) ]        {            result += [ windows-path-to-native $(p) ] ;        }        else        {            result += [ *nix-path-to-native $(p:T) ] ;        }    }    return $(result) ;}# Validate the version string and extract the major/minor part we care about.#local rule split-version ( version ){    local major-minor = [ MATCH ^([0-9]+)\.([0-9]+)(.*)$ : $(version) : 1 2 3 ] ;    if ! $(major-minor[2]) || $(major-minor[3])    {        ECHO "Warning: \"using python\" expects a two part (major, minor) version number; got" $(version) instead ;        # Add a zero to account for the missing digit if necessary.        major-minor += 0 ;    }    return $(major-minor[1]) $(major-minor[2]) ;}# Build a list of versions from 3.0 down to 1.5. Because bjam can not enumerate# registry sub-keys, we have no way of finding a version with a 2-digit minor# version, e.g. 2.10 -- let us hope that never happens.#.version-countdown = ;for local v in [ numbers.range 15 30 ]{    .version-countdown = [ SUBST $(v) (.)(.*) $1.$2 ] $(.version-countdown) ;}local rule windows-installed-pythons ( version ? ){    version ?= $(.version-countdown) ;    local interpreters ;    for local v in $(version)    {        local install-path = [          software-registry-value "Python\\PythonCore\\"$(v)"\\InstallPath" ] ;

⌨️ 快捷键说明

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