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