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.

69 lines
2.0KB

  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. """
  4. Compile whole groups of C/C++ files at once.
  5. def build(bld):
  6. bld.load('compiler_cxx unity')
  7. """
  8. import sys
  9. from waflib import Task, Options
  10. from waflib.Tools import c_preproc
  11. from waflib import TaskGen
  12. MAX_BATCH = 50
  13. def options(opt):
  14. global MAX_BATCH
  15. opt.add_option('--batchsize', action='store', dest='batchsize', type='int', default=MAX_BATCH, help='batch size (0 for no batch)')
  16. class unity(Task.Task):
  17. color = 'BLUE'
  18. scan = c_preproc.scan
  19. def run(self):
  20. lst = ['#include "%s"\n' % node.abspath() for node in self.inputs]
  21. txt = ''.join(lst)
  22. self.outputs[0].write(txt)
  23. @TaskGen.taskgen_method
  24. def batch_size(self):
  25. return getattr(Options.options, 'batchsize', MAX_BATCH)
  26. def make_batch_fun(ext):
  27. # this generic code makes this quite unreadable, defining the function two times might have been better
  28. def make_batch(self, node):
  29. cnt = self.batch_size()
  30. if cnt <= 1:
  31. return self.create_compiled_task(ext, node)
  32. x = getattr(self, 'master_%s' % ext, None)
  33. if not x or len(x.inputs) >= cnt:
  34. x = self.create_task('unity')
  35. setattr(self, 'master_%s' % ext, x)
  36. cnt_cur = getattr(self, 'cnt_%s' % ext, 0)
  37. cxxnode = node.parent.find_or_declare('unity_%s_%d_%d.%s' % (self.idx, cnt_cur, cnt, ext))
  38. x.outputs = [cxxnode]
  39. setattr(self, 'cnt_%s' % ext, cnt_cur + 1)
  40. self.create_compiled_task(ext, cxxnode)
  41. x.inputs.append(node)
  42. return make_batch
  43. def enable_support(cc, cxx):
  44. if cxx or not cc:
  45. make_cxx_batch = TaskGen.extension('.cpp', '.cc', '.cxx', '.C', '.c++')(make_batch_fun('cxx'))
  46. if cc:
  47. make_c_batch = TaskGen.extension('.c')(make_batch_fun('c'))
  48. else:
  49. TaskGen.task_gen.mappings['.c'] = TaskGen.task_gen.mappings['.cpp']
  50. has_c = '.c' in TaskGen.task_gen.mappings or 'waflib.Tools.compiler_c' in sys.modules
  51. has_cpp = '.cpp' in TaskGen.task_gen.mappings or 'waflib.Tools.compiler_cxx' in sys.modules
  52. enable_support(has_c, has_cpp) # by default
  53. def build(bld):
  54. # it is best to do this
  55. enable_support(bld.env.CC_NAME, bld.env.CXX_NAME)