| 1 | # Copyright 2001, 2002, 2003, 2005 Dave Abrahams |
|---|
| 2 | # Copyright 2006 Rene Rivera |
|---|
| 3 | # Copyright 2003, 2005 Vladimir Prus |
|---|
| 4 | # Distributed under the Boost Software License, Version 1.0. |
|---|
| 5 | # (See accompanying file LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 6 | |
|---|
| 7 | import modules ; |
|---|
| 8 | import string ; |
|---|
| 9 | |
|---|
| 10 | # Return the value(s) of the given environment variable(s) at the time |
|---|
| 11 | # bjam was invoked. |
|---|
| 12 | rule environ ( variable-names + ) |
|---|
| 13 | { |
|---|
| 14 | return [ modules.peek .ENVIRON : $(variable-names) ] ; |
|---|
| 15 | } |
|---|
| 16 | |
|---|
| 17 | .name = [ modules.peek : OS ] ; |
|---|
| 18 | .platform = [ modules.peek : OSPLAT ] ; |
|---|
| 19 | .version = [ modules.peek : OSVER ] ; |
|---|
| 20 | |
|---|
| 21 | local rule constant ( c : os ? ) |
|---|
| 22 | { |
|---|
| 23 | os ?= $(.name) ; |
|---|
| 24 | # First look for platform-specific name, then general value |
|---|
| 25 | local variables = .$(c)-$(os) .$(c) ; |
|---|
| 26 | local result = $($(variables)) ; |
|---|
| 27 | return $(result[1]) ; |
|---|
| 28 | } |
|---|
| 29 | |
|---|
| 30 | rule get-constant ( os ? ) |
|---|
| 31 | { |
|---|
| 32 | # Find the name of the constant being accessed, which is |
|---|
| 33 | # equal to the name used to invoke us. |
|---|
| 34 | local bt = [ BACKTRACE 1 ] ; |
|---|
| 35 | local rulename = [ MATCH ([^.]*)$ : $(bt[4]) ] ; |
|---|
| 36 | return [ constant $(rulename) : $(os) ] ; |
|---|
| 37 | } |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | # export all the common constants |
|---|
| 41 | .constants = name platform version shared-library-path-variable path-separator executable-path-variable executable-suffix ; |
|---|
| 42 | for local constant in $(.constants) |
|---|
| 43 | { |
|---|
| 44 | IMPORT $(__name__) : get-constant : $(__name__) : $(constant) ; |
|---|
| 45 | } |
|---|
| 46 | EXPORT $(__name__) : $(.constants) ; |
|---|
| 47 | |
|---|
| 48 | .executable-path-variable-NT = PATH ; |
|---|
| 49 | # On Windows the case and capitalization of PATH is not always |
|---|
| 50 | # predictable, so let's find out what variable name was really set. |
|---|
| 51 | if $(.name) = NT |
|---|
| 52 | { |
|---|
| 53 | for local n in [ VARNAMES .ENVIRON ] |
|---|
| 54 | { |
|---|
| 55 | if $(n:L) = path |
|---|
| 56 | { |
|---|
| 57 | .executable-path-variable-NT = $(n) ; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | # Specific constants for various platforms. There's no need to define |
|---|
| 63 | # any constant whose value would be the same as the default, below. |
|---|
| 64 | .shared-library-path-variable-NT = $(.executable-path-variable-NT) ; |
|---|
| 65 | .path-separator-NT = ";" ; |
|---|
| 66 | .expand-variable-prefix-NT = % ; |
|---|
| 67 | .expand-variable-suffix-NT = % ; |
|---|
| 68 | .executable-suffix-NT = .exe ; |
|---|
| 69 | |
|---|
| 70 | .shared-library-path-variable-CYGWIN = PATH ; |
|---|
| 71 | |
|---|
| 72 | .shared-library-path-variable-MACOSX = DYLD_LIBRARY_PATH ; |
|---|
| 73 | |
|---|
| 74 | .shared-library-path-variable-AIX = LIBPATH ; |
|---|
| 75 | |
|---|
| 76 | # Default constants |
|---|
| 77 | .shared-library-path-variable = LD_LIBRARY_PATH ; |
|---|
| 78 | .path-separator = ":" ; |
|---|
| 79 | .expand-variable-prefix = $ ; |
|---|
| 80 | .expand-variable-suffix = "" ; |
|---|
| 81 | .executable-path-variable = PATH ; |
|---|
| 82 | .executable-suffix = "" ; |
|---|
| 83 | |
|---|
| 84 | # Return a list of the directories in the PATH. Yes, that information |
|---|
| 85 | # is (sort of) available in the global module, but jam code can change |
|---|
| 86 | # those values, and it isn't always clear what case/capitalization to |
|---|
| 87 | # use when looking. This rule is a more reliable way to get there. |
|---|
| 88 | rule executable-path ( ) |
|---|
| 89 | { |
|---|
| 90 | return [ string.words [ environ [ constant executable-path-variable ] ] |
|---|
| 91 | : [ constant path-separator ] ] ; |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | if $(.name) = NT |
|---|
| 95 | { |
|---|
| 96 | local home = [ environ HOMEDRIVE HOMEPATH ] ; |
|---|
| 97 | .home-directories = $(home[1])$(home[2]) [ environ HOME ] [ environ USERPROFILE ] ; |
|---|
| 98 | } |
|---|
| 99 | else |
|---|
| 100 | { |
|---|
| 101 | .home-directories = [ environ HOME ] ; |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | # Can't use 'constant' mechanism because it only returns 1-element |
|---|
| 105 | # values. |
|---|
| 106 | rule home-directories ( ) |
|---|
| 107 | { |
|---|
| 108 | return $(.home-directories) ; |
|---|
| 109 | } |
|---|
| 110 | # Return the string needed to represent the expansion of the named |
|---|
| 111 | # shell variable. |
|---|
| 112 | rule expand-variable ( variable ) |
|---|
| 113 | { |
|---|
| 114 | local prefix = [ constant expand-variable-prefix ] ; |
|---|
| 115 | local suffix = [ constant expand-variable-suffix ] ; |
|---|
| 116 | return $(prefix)$(variable)$(suffix) ; |
|---|
| 117 | } |
|---|
| 118 | |
|---|
| 119 | # Returns true if running on windows, whether in cygwin or not. |
|---|
| 120 | rule on-windows |
|---|
| 121 | { |
|---|
| 122 | local result ; |
|---|
| 123 | if [ modules.peek : NT ] |
|---|
| 124 | { |
|---|
| 125 | result = true ; |
|---|
| 126 | } |
|---|
| 127 | else if [ modules.peek : UNIX ] |
|---|
| 128 | { |
|---|
| 129 | switch [ modules.peek : JAMUNAME ] |
|---|
| 130 | { |
|---|
| 131 | case CYGWIN* : |
|---|
| 132 | { |
|---|
| 133 | result = true ; |
|---|
| 134 | } |
|---|
| 135 | } |
|---|
| 136 | } |
|---|
| 137 | return $(result) ; |
|---|
| 138 | } |
|---|
| 139 | |
|---|
| 140 | if ! [ on-windows ] |
|---|
| 141 | { |
|---|
| 142 | .on-unix = 1 ; |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | rule on-unix |
|---|
| 146 | { |
|---|
| 147 | return $(.on-unix) ; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | |
|---|
| 151 | import regex ; |
|---|
| 152 | |
|---|
| 153 | rule __test__ |
|---|
| 154 | { |
|---|
| 155 | import assert ; |
|---|
| 156 | rule identity ( args * ) { return $(args) ; } |
|---|
| 157 | |
|---|
| 158 | if ! ( --quiet in [ modules.peek : ARGV ] ) |
|---|
| 159 | { |
|---|
| 160 | ECHO os: name= [ name ] ; |
|---|
| 161 | ECHO os: version= [ version ] ; |
|---|
| 162 | } |
|---|
| 163 | assert.true name ; |
|---|
| 164 | } |
|---|