1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
# (C) Copyright David Abrahams 2001. Permission to copy, use, modify, sell and
# distribute this software is granted provided this copyright notice appears in
# all copies. This software is provided "as is" without express or implied
# warranty, and with no claim as to its suitability for any purpose.
import modules ;
# Return the value(s) of the given environment variable(s) at the time
# bjam was invoked.
rule environ ( variable-names + )
{
return [ modules.peek .ENVIRON : $(variable-names) ] ;
}
.name = [ modules.peek : OS ] ;
.platform = [ modules.peek : OSPLAT ] ;
.version = [ modules.peek : OSVER ] ;
local rule constant ( c )
{
# First look for platform-specific name, then general value
local variables = .$(c)-$(.name) .$(c) ;
local result = $($(variables)) ;
return $(result[1]) ;
}
rule get-constant ( )
{
# Find the name of the constant being accessed, which is
# equal to the name used to invoke us.
local bt = [ BACKTRACE 1 ] ;
local rulename = [ MATCH ([^.]*)$ : $(bt[4]) ] ;
return [ constant $(rulename) ] ;
}
# export all the common constants
.constants = name platform version shared-library-path-variable path-separator ;
for local constant in $(.constants)
{
IMPORT $(__name__) : get-constant : $(__name__) : $(constant) ;
}
EXPORT $(__name__) : $(.constants) ;
.shared-library-path-variable-NT = PATH ;
.path-separator-NT = ";" ;
.expand-variable-prefix-NT = % ;
.expand-variable-suffix-NT = % ;
.shared-library-path-variable-CYGWIN = PATH ;
.path-separator-CYGWIN = ":" ;
.expand-variable-prefix-CYGWIN = $ ;
.expand-variable-suffix-CYGWIN = "" ;
.shared-library-path-variable-MACOSX = DYLD_LIBRARY_PATH ;
.shared-library-path-variable = LD_LIBRARY_PATH ;
.path-separator = ":" ;
.expand-variable-prefix = $ ;
.expand-variable-suffix = "" ;
if $(.name) = NT
{
local home = [ environ HOMEDRIVE HOMEPATH ] ;
.home-directories = $(home[1])$(home[2]) [ environ HOME ] ;
}
else
{
.home-directories = [ environ HOME ] ;
}
# Can't use 'constant' mechanism because it only returns 1-element
# values.
rule home-directories ( )
{
return $(.home-directories) ;
}
# Return the string needed to represent the expansion of the named
# shell variable.
rule expand-variable ( variable )
{
local prefix = [ constant expand-variable-prefix ] ;
local suffix = [ constant expand-variable-suffix ] ;
return $(prefix)$(variable)$(suffix) ;
}
# Returns true if running on windows, whether in cygwin or not.
rule on-windows
{
local result ;
if [ modules.peek : NT ]
{
result = true ;
}
else if [ modules.peek : UNIX ]
{
switch [ modules.peek : JAMUNAME ]
{
case CYGWIN* :
{
result = true ;
}
}
}
return $(result) ;
}
if ! [ on-windows ]
{
.on-unix = 1 ;
}
rule on-unix
{
return $(.on-unix) ;
}
import regex ;
rule __test__
{
import assert ;
rule identity ( args * ) { return $(args) ; }
if ! ( --quiet in [ modules.peek : ARGV ] )
{
ECHO os: name= [ name ] ;
ECHO os: version= [ version ] ;
}
assert.true name ;
}
|