Imported Upstream version 1.51.0
[platform/upstream/boost.git] / tools / build / src / util / os.jam
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
11 # Return the value(s) of the given environment variable(s) at the time bjam was
12 # invoked.
13 rule 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
23 local 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
32 rule 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 ;
44 for local constant in $(.constants)
45 {
46     IMPORT $(__name__) : get-constant : $(__name__) : $(constant) ;
47 }
48 EXPORT $(__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.
53 if $(.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 # Default constants
79 .shared-library-path-variable = LD_LIBRARY_PATH ;
80 .path-separator = ":" ;
81 .expand-variable-prefix = $ ;
82 .expand-variable-suffix = "" ;
83 .executable-path-variable = PATH ;
84 .executable-suffix = "" ;
85
86
87 # Return a list of the directories in the PATH. Yes, that information is (sort
88 # of) available in the global module, but jam code can change those values, and
89 # it isn't always clear what case/capitalization to use when looking. This rule
90 # is a more reliable way to get there.
91 rule executable-path ( )
92 {
93     return [ string.words [ environ [ constant executable-path-variable ] ]
94         : [ constant path-separator ] ] ;
95 }
96
97
98 # Initialize the list of home directories for the current user depending on the
99 # OS.
100 if $(.name) = NT
101 {
102     local home = [ environ HOMEDRIVE HOMEPATH ] ;
103     .home-directories = $(home[1])$(home[2]) [ environ HOME ] [ environ USERPROFILE ] ;
104 }
105 else
106 {
107     .home-directories = [ environ HOME ] ;
108 }
109
110
111 # Can't use 'constant' mechanism because it only returns 1-element values.
112 rule home-directories ( )
113 {
114     return $(.home-directories) ;
115 }
116
117
118 # Return the string needed to represent the expansion of the named shell
119 # variable.
120 rule expand-variable ( variable )
121 {
122     local prefix = [ constant expand-variable-prefix ] ;
123     local suffix = [ constant expand-variable-suffix ] ;
124     return $(prefix)$(variable)$(suffix) ;
125 }
126
127
128 # Returns true if running on windows, whether in cygwin or not.
129 rule on-windows ( )
130 {
131     local result ;
132     if [ modules.peek : NT ]
133     {
134         result = true ;
135     }
136     else if [ modules.peek : UNIX ]
137     {
138         switch [ modules.peek : JAMUNAME ]
139         {
140             case CYGWIN* :
141             {
142                 result = true ;
143             }
144         }
145     }
146     return $(result) ;
147 }
148
149
150 if ! [ on-windows ]
151 {
152     .on-unix = 1 ;
153 }
154
155
156 rule on-unix
157 {
158     return $(.on-unix) ;
159 }
160
161
162 rule __test__
163 {
164     import assert ;
165     if ! ( --quiet in [ modules.peek : ARGV ] )
166     {
167         ECHO os: name= [ name ] ;
168         ECHO os: version= [ version ] ;
169     }
170     assert.true name ;
171 }