gcj.py 2.4 KB

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