jack2 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.1KB

  1. #!/usr/bin/env python
  2. # encoding: ISO8859-1
  3. # Thomas Nagy, 2005-2015
  4. """
  5. Redistribution and use in source and binary forms, with or without
  6. modification, are permitted provided that the following conditions
  7. are met:
  8. 1. Redistributions of source code must retain the above copyright
  9. notice, this list of conditions and the following disclaimer.
  10. 2. Redistributions in binary form must reproduce the above copyright
  11. notice, this list of conditions and the following disclaimer in the
  12. documentation and/or other materials provided with the distribution.
  13. 3. The name of the author may not be used to endorse or promote products
  14. derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
  19. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  22. HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  23. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  24. IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE.
  26. """
  27. import os, sys, inspect
  28. VERSION="1.8.17"
  29. REVISION="x"
  30. GIT="x"
  31. INSTALL="x"
  32. C1='x'
  33. C2='x'
  34. C3='x'
  35. cwd = os.getcwd()
  36. join = os.path.join
  37. if sys.hexversion<0x206000f:
  38. raise ImportError('Python >= 2.6 is required to create the waf file')
  39. WAF='waf'
  40. def b(x):
  41. return x
  42. if sys.hexversion>0x300000f:
  43. WAF='waf3'
  44. def b(x):
  45. return x.encode()
  46. def err(m):
  47. print(('\033[91mError: %s\033[0m' % m))
  48. sys.exit(1)
  49. def unpack_wafdir(dir, src):
  50. f = open(src,'rb')
  51. c = 'corrupt archive (%d)'
  52. while 1:
  53. line = f.readline()
  54. if not line: err('run waf-light from a folder containing waflib')
  55. if line == b('#==>\n'):
  56. txt = f.readline()
  57. if not txt: err(c % 1)
  58. if f.readline() != b('#<==\n'): err(c % 2)
  59. break
  60. if not txt: err(c % 3)
  61. txt = txt[1:-1].replace(b(C1), b('\n')).replace(b(C2), b('\r')).replace(b(C3), b('\x00'))
  62. import shutil, tarfile
  63. try: shutil.rmtree(dir)
  64. except OSError: pass
  65. try:
  66. for x in ('Tools', 'extras'):
  67. os.makedirs(join(dir, 'waflib', x))
  68. except OSError:
  69. err("Cannot unpack waf lib into %s\nMove waf in a writable directory" % dir)
  70. os.chdir(dir)
  71. tmp = 't.bz2'
  72. t = open(tmp,'wb')
  73. try: t.write(txt)
  74. finally: t.close()
  75. try:
  76. t = tarfile.open(tmp)
  77. except:
  78. try:
  79. os.system('bunzip2 t.bz2')
  80. t = tarfile.open('t')
  81. tmp = 't'
  82. except:
  83. os.chdir(cwd)
  84. try: shutil.rmtree(dir)
  85. except OSError: pass
  86. err("Waf cannot be unpacked, check that bzip2 support is present")
  87. try:
  88. for x in t: t.extract(x)
  89. finally:
  90. t.close()
  91. for x in ('Tools', 'extras'):
  92. os.chmod(join('waflib',x), 493)
  93. if sys.hexversion<0x300000f:
  94. sys.path = [join(dir, 'waflib')] + sys.path
  95. import fixpy2
  96. fixpy2.fixdir(dir)
  97. os.remove(tmp)
  98. os.chdir(cwd)
  99. try: dir = unicode(dir, 'mbcs')
  100. except: pass
  101. try:
  102. from ctypes import windll
  103. windll.kernel32.SetFileAttributesW(dir, 2)
  104. except:
  105. pass
  106. def test(dir):
  107. try:
  108. os.stat(join(dir, 'waflib'))
  109. return os.path.abspath(dir)
  110. except OSError:
  111. pass
  112. def find_lib():
  113. src = os.path.abspath(inspect.getfile(inspect.getmodule(err)))
  114. base, name = os.path.split(src)
  115. #devs use $WAFDIR
  116. w=test(os.environ.get('WAFDIR', ''))
  117. if w: return w
  118. #waf-light
  119. if name.endswith('waf-light'):
  120. w = test(base)
  121. if w: return w
  122. err('waf-light requires waflib -> export WAFDIR=/folder')
  123. dirname = '%s-%s-%s' % (WAF, VERSION, REVISION)
  124. for i in (INSTALL,'/usr','/usr/local','/opt'):
  125. w = test(i + '/lib/' + dirname)
  126. if w: return w
  127. #waf-local
  128. dir = join(base, (sys.platform != 'win32' and '.' or '') + dirname)
  129. w = test(dir)
  130. if w: return w
  131. #unpack
  132. unpack_wafdir(dir, src)
  133. return dir
  134. wafdir = find_lib()
  135. sys.path.insert(0, wafdir)
  136. if __name__ == '__main__':
  137. #import waflib.extras.compat15#PRELUDE
  138. from waflib import Scripting
  139. Scripting.waf_entry_point(cwd, VERSION, wafdir)