fsc.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Thomas Nagy, 2011 (ita)
  4. """
  5. Experimental F# stuff
  6. FSC="mono /path/to/fsc.exe" waf configure build
  7. """
  8. from waflib import Utils, Task
  9. from waflib.TaskGen import before_method, after_method, feature
  10. from waflib.Tools import ccroot, cs
  11. ccroot.USELIB_VARS['fsc'] = set(['CSFLAGS', 'ASSEMBLIES', 'RESOURCES'])
  12. @feature('fs')
  13. @before_method('process_source')
  14. def apply_fsc(self):
  15. cs_nodes = []
  16. no_nodes = []
  17. for x in self.to_nodes(self.source):
  18. if x.name.endswith('.fs'):
  19. cs_nodes.append(x)
  20. else:
  21. no_nodes.append(x)
  22. self.source = no_nodes
  23. bintype = getattr(self, 'type', self.gen.endswith('.dll') and 'library' or 'exe')
  24. self.cs_task = tsk = self.create_task('fsc', cs_nodes, self.path.find_or_declare(self.gen))
  25. tsk.env.CSTYPE = '/target:%s' % bintype
  26. tsk.env.OUT = '/out:%s' % tsk.outputs[0].abspath()
  27. inst_to = getattr(self, 'install_path', bintype=='exe' and '${BINDIR}' or '${LIBDIR}')
  28. if inst_to:
  29. # note: we are making a copy, so the files added to cs_task.outputs won't be installed automatically
  30. mod = getattr(self, 'chmod', bintype=='exe' and Utils.O755 or Utils.O644)
  31. self.install_task = self.add_install_files(install_to=inst_to, install_from=self.cs_task.outputs[:], chmod=mod)
  32. feature('fs')(cs.use_cs)
  33. after_method('apply_fsc')(cs.use_cs)
  34. feature('fs')(cs.debug_cs)
  35. after_method('apply_fsc', 'use_cs')(cs.debug_cs)
  36. class fsc(Task.Task):
  37. """
  38. Compile F# files
  39. """
  40. color = 'YELLOW'
  41. run_str = '${FSC} ${CSTYPE} ${CSFLAGS} ${ASS_ST:ASSEMBLIES} ${RES_ST:RESOURCES} ${OUT} ${SRC}'
  42. def configure(conf):
  43. """
  44. Find a F# compiler, set the variable FSC for the compiler and FS_NAME (mono or fsc)
  45. """
  46. conf.find_program(['fsc.exe', 'fsharpc'], var='FSC')
  47. conf.env.ASS_ST = '/r:%s'
  48. conf.env.RES_ST = '/resource:%s'
  49. conf.env.FS_NAME = 'fsc'
  50. if str(conf.env.FSC).lower().find('fsharpc') > -1:
  51. conf.env.FS_NAME = 'mono'