waf

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

gcj.py (2497B)


      1 #!/usr/bin/env python
      2 # encoding: utf-8
      3 # Thomas Nagy, 2006-2008 (ita)
      4 
      5 """
      6 Native compilation using gcj
      7 
      8 highly experimental, and gcj sucks anyway
      9 """
     10 
     11 import os, re
     12 from waflib.Configure import conf
     13 from waflib import TaskGen, Task, Utils, Node
     14 from waflib.TaskGen import feature, before, after
     15 from waflib.Tools import ccroot
     16 
     17 def configure(conf):
     18 	conf.find_program('gcj', var='GCJ')
     19 	conf.env.GCJLINK = conf.env.GCJ
     20 	conf.env.GCJLINKFLAGS_gcj_shlib = ['-shared']
     21 	conf.env.GCJFLAGS_gcj_shlib = ['-fPIC']
     22 
     23 class gcj(Task.Task):
     24 	run_str = '${GCJ} ${GCJFLAGS} -classpath ${CLASSPATH} -c -o ${TGT} ${SRC}'
     25 
     26 class gcj_program(ccroot.link_task):
     27 	run_str = '${GCJLINK} ${GCJLINKFLAGS} ${SRC} -o ${TGT}'
     28 	color   = 'YELLOW'
     29 
     30 class gcj_shlib(gcj_program):
     31 	pass
     32 
     33 ccroot.USELIB_VARS['gcj'] = set(['CLASSPATH', 'JAVACFLAGS', 'GCJFLAGS'])
     34 ccroot.USELIB_VARS['gcj_program'] = set(['CLASSPATH', 'JAVACFLAGS', 'GCJLINKFLAGS'])
     35 ccroot.USELIB_VARS['gcj_shlib'] = set(['CLASSPATH', 'JAVACFLAGS', 'GCJLINKFLAGS'])
     36 feature('gcj_program', 'gcj_shlib')(ccroot.apply_link)
     37 feature('gcj_program', 'gcj_shlib')(ccroot.propagate_uselib_vars)
     38 
     39 @feature('gcj')
     40 @after('propagate_uselib_vars', 'apply_gcj')
     41 def set_gcj_classpath(self):
     42 	lst = [isinstance(x, str) and x or x.abspath() for x in self.env.CLASSPATH]
     43 	self.env.CLASSPATH = os.pathsep.join(lst) + os.pathsep
     44 
     45 @feature('gcj')
     46 @before('apply_java')
     47 def apply_gcj(self):
     48 	if 'javac' in self.features:
     49 		self.bld.fatal('feature gcj_native is not compatible with javac %r' % self)
     50 
     51 	srcdir = getattr(self, 'srcdir', '')
     52 	if isinstance(srcdir, Node.Node):
     53 		srcdir = [srcdir]
     54 
     55 	tmp = []
     56 	for x in Utils.to_list(srcdir):
     57 		if isinstance(x, Node.Node):
     58 			y = x
     59 		else:
     60 			y = self.path.find_dir(x)
     61 			if not y:
     62 				self.bld.fatal('Could not find the folder %s from %s' % (x, self.path))
     63 		tmp.append(y)
     64 
     65 	nodes = []
     66 	for x in tmp:
     67 		nodes.extend(x.ant_glob('**/*.java'))
     68 
     69 	if not getattr(self, 'gcjonce', None):
     70 		for x in nodes:
     71 			self.create_compiled_task('gcj', x)
     72 
     73 #############################################################
     74 # gcj is still beta software
     75 # and this workaround cannot work for shared object (-fPIC)
     76 
     77 class fix_dummy(Task.Task):
     78 	run_str = 'objcopy -L _ZGr8_$$_dummy ${SRC}'
     79 	before  = ['gcj_program', 'gcj_shlib']
     80 
     81 @feature('gcj')
     82 @after('apply_gcj')
     83 def gcj_developers_like_duplicate_dummy_symbols(self):
     84 	if self.env.FIX_DUMMY:
     85 		for tsk in self.compiled_tasks:
     86 			if isinstance(tsk, gcj):
     87 				self.create_task('fix_dummy', tsk.outputs[0])
     88