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