wscript 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #! /usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2006-2010 (ita)
  4. VERSION='0.0.1'
  5. APPNAME='cc_test'
  6. top = '.'
  7. import waflib.Configure
  8. waflib.Configure.autoconfig = True
  9. def options(opt):
  10. opt.load('compiler_c')
  11. opt.load('gnu_dirs')
  12. def build(bld):
  13. bld.recurse('program stlib shlib stlib2')
  14. lst = 'debug release foo bar one two'.split()
  15. def configure(conf):
  16. conf.load('compiler_c')
  17. conf.check_features()
  18. conf.check_cc(fragment="""#include<stdio.h>\nint main(){fprintf(stderr, "mu"); printf("%d", 22);return 0;}\n""", execute=True, define_name='HAVE_MU')
  19. conf.write_config_header('config.h')
  20. # gotcha - the config.h must be written for each variant
  21. for x in lst:
  22. conf.write_config_header(x + '/config.h')
  23. from waflib import Utils, Build
  24. class buildall_ctx(Build.BuildContext):
  25. cmd = fun = 'buildall'
  26. def compile(self):
  27. pass
  28. def buildall(ctx):
  29. """call 'waf buildall' to build all the variants in parallel"""
  30. timer = Utils.Timer()
  31. threads = []
  32. count = [0]
  33. line_lock = Utils.threading.Lock()
  34. class sub_build(Utils.threading.Thread):
  35. def run(self):
  36. bld = self.bld = self.cls(top_dir=ctx.top_dir, out_dir=ctx.out_dir)
  37. bld.restore()
  38. bld.siblings = threads
  39. bld.count = count
  40. bld.line_lock = line_lock
  41. bld.timer = timer
  42. bld.logger = ctx.logger
  43. bld.load_envs()
  44. bld.targets = ctx.targets
  45. bld.recurse([bld.run_dir])
  46. bld.compile()
  47. for x in lst:
  48. cls = type(Build.BuildContext)(x, (Build.BuildContext,), {'cmd': x, 'variant': x})
  49. cls.progress_line = locked_progress_line
  50. f = sub_build()
  51. f.cls = cls
  52. threads.append(f)
  53. f.start()
  54. for x in threads:
  55. x.join()
  56. def locked_progress_line(self, state, total, col1, col2):
  57. try:
  58. self.line_lock.acquire()
  59. self.count[0] += 1
  60. total = 0
  61. for x in self.siblings:
  62. try:
  63. p = x.bld.producer
  64. except AttributeError:
  65. pass
  66. else:
  67. total += p.total
  68. return Build.BuildContext.progress_line(self, self.count[0], total, col1, col2)
  69. finally:
  70. self.line_lock.release()
  71. class cleanall_ctx(Build.CleanContext):
  72. cmd = fun = 'cleanall'
  73. def cleanall(ctx):
  74. for x in lst:
  75. cls = type(Build.CleanContext)(x, (Build.CleanContext,), {'cmd': x, 'variant': x})
  76. bld = cls(top_dir=ctx.top_dir, out_dir=ctx.out_dir)
  77. bld.restore()
  78. bld.load_envs()
  79. bld.recurse([bld.run_dir])
  80. try:
  81. bld.clean()
  82. finally:
  83. bld.store()
  84. # produces dict/json compatible output
  85. features_str = r'''
  86. #include <stdio.h>
  87. int is_big_endian()
  88. {
  89. long one = 1;
  90. return !(*((char *)(&one)));
  91. }
  92. int main()
  93. {
  94. printf("{");
  95. if (is_big_endian()) printf("\"bigendian\":1,");
  96. else printf("\"bigendian\":0,");
  97. printf("\"int_size\":%lu,", sizeof(int));
  98. printf("\"long_int_size\":%lu,", sizeof(long int));
  99. printf("\"long_long_int_size\":%lu,", sizeof(long long int));
  100. printf("\"double_size\":%lu", sizeof(double));
  101. printf("}");
  102. return 0;
  103. }
  104. '''
  105. def check_features(self):
  106. mp = self.check(fragment=features_str, define_ret=True, execute=True)
  107. try:
  108. mp = mp.decode('utf-8')
  109. except:
  110. pass
  111. t = eval(mp)
  112. try:
  113. is_big = int(t['bigendian'])
  114. except KeyError:
  115. raise Configure.ConfigurationError('endian test failed %s (see the config.log)' % features_str)
  116. if is_big: strbig = 'big endian'
  117. else: strbig = 'little endian'
  118. self.msg('endianness', strbig)
  119. self.msg('int size', t['int_size'])
  120. self.msg('long int size', t['long_int_size'])
  121. self.msg('long long int size', t['long_long_int_size'])
  122. self.msg('double size', t['double_size'])
  123. self.define_cond('IS_BIGENDIAN', is_big)
  124. self.define_cond('INT_SIZE', int(t['int_size']))
  125. self.define_cond('LONG_INT_SIZE', int(t['long_int_size']))
  126. self.define_cond('LONG_LONG_INT_SIZE', int(t['long_long_int_size']))
  127. self.define_cond('DOUBLE_SIZE', int(t['double_size']))
  128. return is_big
  129. from waflib import Configure
  130. Configure.conf(check_features) # bind the method