waf

FORK: waf with some random patches
git clone https://git.neptards.moe/neptards/waf.git
Log | Files | Refs | README

wscript (3819B)


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