1#! /usr/bin/env python 2# 3# SCons - a Software Constructor 4# 5# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 The SCons Foundation 6# 7# Permission is hereby granted, free of charge, to any person obtaining 8# a copy of this software and associated documentation files (the 9# "Software"), to deal in the Software without restriction, including 10# without limitation the rights to use, copy, modify, merge, publish, 11# distribute, sublicense, and/or sell copies of the Software, and to 12# permit persons to whom the Software is furnished to do so, subject to 13# the following conditions: 14# 15# The above copyright notice and this permission notice shall be included 16# in all copies or substantial portions of the Software. 17# 18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY 19# KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 20# WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 21# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 22# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 24# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25# 26 27__revision__ = "src/script/scons.py 4369 2009/09/19 16:58:54 scons" 28 29__version__ = "1.2.0.d20090919" 30 31__build__ = "r4369[MODIFIED]" 32 33__buildsys__ = "scons-dev" 34 35__date__ = "2009/09/19 16:58:54" 36 37__developer__ = "scons" 38 39import os 40import os.path 41import sys 42 43############################################################################## 44# BEGIN STANDARD SCons SCRIPT HEADER 45# 46# This is the cut-and-paste logic so that a self-contained script can 47# interoperate correctly with different SCons versions and installation 48# locations for the engine. If you modify anything in this section, you 49# should also change other scripts that use this same header. 50############################################################################## 51 52# Strip the script directory from sys.path() so on case-insensitive 53# (WIN32) systems Python doesn't think that the "scons" script is the 54# "SCons" package. Replace it with our own library directories 55# (version-specific first, in case they installed by hand there, 56# followed by generic) so we pick up the right version of the build 57# engine modules if they're in either directory. 58 59script_dir = sys.path[0] 60 61if script_dir in sys.path: 62 sys.path.remove(script_dir) 63 64libs = [] 65 66if "SCONS_LIB_DIR" in os.environ: 67 libs.append(os.environ["SCONS_LIB_DIR"]) 68 69local_version = 'scons-local-' + __version__ 70local = 'scons-local' 71if script_dir: 72 local_version = os.path.join(script_dir, local_version) 73 local = os.path.join(script_dir, local) 74libs.append(os.path.abspath(local_version)) 75libs.append(os.path.abspath(local)) 76 77scons_version = 'scons-%s' % __version__ 78 79prefs = [] 80 81if sys.platform == 'win32': 82 # sys.prefix is (likely) C:\Python*; 83 # check only C:\Python*. 84 prefs.append(sys.prefix) 85 prefs.append(os.path.join(sys.prefix, 'Lib', 'site-packages')) 86else: 87 # On other (POSIX) platforms, things are more complicated due to 88 # the variety of path names and library locations. Try to be smart 89 # about it. 90 if script_dir == 'bin': 91 # script_dir is `pwd`/bin; 92 # check `pwd`/lib/scons*. 93 prefs.append(os.getcwd()) 94 else: 95 if script_dir == '.' or script_dir == '': 96 script_dir = os.getcwd() 97 head, tail = os.path.split(script_dir) 98 if tail == "bin": 99 # script_dir is /foo/bin; 100 # check /foo/lib/scons*. 101 prefs.append(head) 102 103 head, tail = os.path.split(sys.prefix) 104 if tail == "usr": 105 # sys.prefix is /foo/usr; 106 # check /foo/usr/lib/scons* first, 107 # then /foo/usr/local/lib/scons*. 108 prefs.append(sys.prefix) 109 prefs.append(os.path.join(sys.prefix, "local")) 110 elif tail == "local": 111 h, t = os.path.split(head) 112 if t == "usr": 113 # sys.prefix is /foo/usr/local; 114 # check /foo/usr/local/lib/scons* first, 115 # then /foo/usr/lib/scons*. 116 prefs.append(sys.prefix) 117 prefs.append(head) 118 else: 119 # sys.prefix is /foo/local; 120 # check only /foo/local/lib/scons*. 121 prefs.append(sys.prefix) 122 else: 123 # sys.prefix is /foo (ends in neither /usr or /local); 124 # check only /foo/lib/scons*. 125 prefs.append(sys.prefix) 126 127 temp = map(lambda x: os.path.join(x, 'lib'), prefs) 128 temp.extend(map(lambda x: os.path.join(x, 129 'lib', 130 'python' + sys.version[:3], 131 'site-packages'), 132 prefs)) 133 prefs = temp 134 135 # Add the parent directory of the current python's library to the 136 # preferences. On SuSE-91/AMD64, for example, this is /usr/lib64, 137 # not /usr/lib. 138 try: 139 libpath = os.__file__ 140 except AttributeError: 141 pass 142 else: 143 # Split /usr/libfoo/python*/os.py to /usr/libfoo/python*. 144 libpath, tail = os.path.split(libpath) 145 # Split /usr/libfoo/python* to /usr/libfoo 146 libpath, tail = os.path.split(libpath) 147 # Check /usr/libfoo/scons*. 148 prefs.append(libpath) 149 150# Look first for 'scons-__version__' in all of our preference libs, 151# then for 'scons'. 152libs.extend(map(lambda x: os.path.join(x, scons_version), prefs)) 153libs.extend(map(lambda x: os.path.join(x, 'scons'), prefs)) 154 155sys.path = libs + sys.path 156 157############################################################################## 158# END STANDARD SCons SCRIPT HEADER 159############################################################################## 160 161if __name__ == "__main__": 162 import SCons.Script 163 # this does all the work, and calls sys.exit 164 # with the proper exit status when done. 165 SCons.Script.main() 166 167# Local Variables: 168# tab-width:4 169# indent-tabs-mode:nil 170# End: 171# vim: set expandtab tabstop=4 shiftwidth=4: 172