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.

132 lines
3.9KB

  1. #! /usr/bin/env python
  2. # per rosengren 2011
  3. from os import sep, readlink
  4. from os.path import abspath
  5. from waflib import Logs
  6. from waflib.TaskGen import feature, after_method
  7. from waflib.Task import Task, always_run
  8. def options(opt):
  9. grp = opt.add_option_group('Bjam Options')
  10. grp.add_option('--bjam_src', default=None, help='You can find it in <boost root>/tools/jam/src')
  11. grp.add_option('--bjam_uname', default='linuxx86_64', help='bjam is built in <src>/bin.<uname>/bjam')
  12. grp.add_option('--bjam_config', default=None)
  13. grp.add_option('--bjam_toolset', default=None)
  14. def configure(cnf):
  15. if not cnf.env.BJAM_SRC:
  16. cnf.env.BJAM_SRC = cnf.options.bjam_src
  17. if not cnf.env.BJAM_UNAME:
  18. cnf.env.BJAM_UNAME = cnf.options.bjam_uname
  19. try:
  20. cnf.find_program('bjam', path_list=[
  21. cnf.env.BJAM_SRC + sep + 'bin.' + cnf.env.BJAM_UNAME
  22. ])
  23. except Exception as e:
  24. cnf.env.BJAM = None
  25. if not cnf.env.BJAM_CONFIG:
  26. cnf.env.BJAM_CONFIG = cnf.options.bjam_config
  27. if not cnf.env.BJAM_TOOLSET:
  28. cnf.env.BJAM_TOOLSET = cnf.options.bjam_toolset
  29. @feature('bjam')
  30. @after_method('process_rule')
  31. def process_bjam(self):
  32. if not self.bld.env.BJAM:
  33. self.create_task('bjam_creator')
  34. self.create_task('bjam_build')
  35. self.create_task('bjam_installer')
  36. if getattr(self, 'always', False):
  37. always_run(bjam_creator)
  38. always_run(bjam_build)
  39. always_run(bjam_installer)
  40. class bjam_creator(Task):
  41. ext_out = 'bjam_exe'
  42. vars=['BJAM_SRC', 'BJAM_UNAME']
  43. def run(self):
  44. env = self.env
  45. gen = self.generator
  46. path = gen.path
  47. bld = gen.bld
  48. bjam = gen.bld.root.find_dir(env.BJAM_SRC)
  49. if not bjam:
  50. Logs.error('Can not find bjam source')
  51. return -1
  52. bjam_exe_relpath = 'bin.' + env.BJAM_UNAME + '/bjam'
  53. bjam_exe = bjam.find_resource(bjam_exe_relpath)
  54. if bjam_exe:
  55. env.BJAM = bjam_exe.srcpath()
  56. return 0
  57. bjam_cmd = ['./build.sh']
  58. Logs.debug('runner: ' + bjam.srcpath() + '> ' + str(bjam_cmd))
  59. result = self.exec_command(bjam_cmd, cwd=bjam.srcpath())
  60. if not result == 0:
  61. Logs.error('bjam failed')
  62. return -1
  63. bjam_exe = bjam.find_resource(bjam_exe_relpath)
  64. if bjam_exe:
  65. env.BJAM = bjam_exe.srcpath()
  66. return 0
  67. Logs.error('bjam failed')
  68. return -1
  69. class bjam_build(Task):
  70. ext_in = 'bjam_exe'
  71. ext_out = 'install'
  72. vars = ['BJAM_TOOLSET']
  73. def run(self):
  74. env = self.env
  75. gen = self.generator
  76. path = gen.path
  77. bld = gen.bld
  78. if hasattr(gen, 'root'):
  79. build_root = path.find_node(gen.root)
  80. else:
  81. build_root = path
  82. jam = bld.srcnode.find_resource(env.BJAM_CONFIG)
  83. if jam:
  84. Logs.debug('bjam: Using jam configuration from ' + jam.srcpath())
  85. jam_rel = jam.relpath_gen(build_root)
  86. else:
  87. Logs.warn('No build configuration in build_config/user-config.jam. Using default')
  88. jam_rel = None
  89. bjam_exe = bld.srcnode.find_node(env.BJAM)
  90. if not bjam_exe:
  91. Logs.error('env.BJAM is not set')
  92. return -1
  93. bjam_exe_rel = bjam_exe.relpath_gen(build_root)
  94. cmd = ([bjam_exe_rel] +
  95. (['--user-config=' + jam_rel] if jam_rel else []) +
  96. ['--stagedir=' + path.get_bld().path_from(build_root)] +
  97. ['--debug-configuration'] +
  98. ['--with-' + lib for lib in self.generator.target] +
  99. (['toolset=' + env.BJAM_TOOLSET] if env.BJAM_TOOLSET else []) +
  100. ['link=' + 'shared'] +
  101. ['variant=' + 'release']
  102. )
  103. Logs.debug('runner: ' + build_root.srcpath() + '> ' + str(cmd))
  104. ret = self.exec_command(cmd, cwd=build_root.srcpath())
  105. if ret != 0:
  106. return ret
  107. self.set_outputs(path.get_bld().ant_glob('lib/*') + path.get_bld().ant_glob('bin/*'))
  108. return 0
  109. class bjam_installer(Task):
  110. ext_in = 'install'
  111. def run(self):
  112. gen = self.generator
  113. path = gen.path
  114. for idir, pat in (('${LIBDIR}', 'lib/*'), ('${BINDIR}', 'bin/*')):
  115. files = []
  116. for n in path.get_bld().ant_glob(pat):
  117. try:
  118. t = readlink(n.srcpath())
  119. gen.bld.symlink_as(sep.join([idir, n.name]), t, postpone=False)
  120. except OSError:
  121. files.append(n)
  122. gen.bld.install_files(idir, files, postpone=False)
  123. return 0