d.py 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Carlos Rafael Giani, 2007 (dv)
  4. # Thomas Nagy, 2007-2018 (ita)
  5. from waflib import Utils, Task, Errors
  6. from waflib.TaskGen import taskgen_method, feature, extension
  7. from waflib.Tools import d_scan, d_config
  8. from waflib.Tools.ccroot import link_task, stlink_task
  9. class d(Task.Task):
  10. "Compile a d file into an object file"
  11. color = 'GREEN'
  12. run_str = '${D} ${DFLAGS} ${DINC_ST:INCPATHS} ${D_SRC_F:SRC} ${D_TGT_F:TGT}'
  13. scan = d_scan.scan
  14. class d_with_header(d):
  15. "Compile a d file and generate a header"
  16. run_str = '${D} ${DFLAGS} ${DINC_ST:INCPATHS} ${D_HDR_F:tgt.outputs[1].bldpath()} ${D_SRC_F:SRC} ${D_TGT_F:tgt.outputs[0].bldpath()}'
  17. class d_header(Task.Task):
  18. "Compile d headers"
  19. color = 'BLUE'
  20. run_str = '${D} ${D_HEADER} ${SRC}'
  21. class dprogram(link_task):
  22. "Link object files into a d program"
  23. run_str = '${D_LINKER} ${LINKFLAGS} ${DLNK_SRC_F}${SRC} ${DLNK_TGT_F:TGT} ${RPATH_ST:RPATH} ${DSTLIB_MARKER} ${DSTLIBPATH_ST:STLIBPATH} ${DSTLIB_ST:STLIB} ${DSHLIB_MARKER} ${DLIBPATH_ST:LIBPATH} ${DSHLIB_ST:LIB}'
  24. inst_to = '${BINDIR}'
  25. class dshlib(dprogram):
  26. "Link object files into a d shared library"
  27. inst_to = '${LIBDIR}'
  28. class dstlib(stlink_task):
  29. "Link object files into a d static library"
  30. pass # do not remove
  31. @extension('.d', '.di', '.D')
  32. def d_hook(self, node):
  33. """
  34. Compile *D* files. To get .di files as well as .o files, set the following::
  35. def build(bld):
  36. bld.program(source='foo.d', target='app', generate_headers=True)
  37. """
  38. ext = Utils.destos_to_binfmt(self.env.DEST_OS) == 'pe' and 'obj' or 'o'
  39. out = '%s.%d.%s' % (node.name, self.idx, ext)
  40. def create_compiled_task(self, name, node):
  41. task = self.create_task(name, node, node.parent.find_or_declare(out))
  42. try:
  43. self.compiled_tasks.append(task)
  44. except AttributeError:
  45. self.compiled_tasks = [task]
  46. return task
  47. if getattr(self, 'generate_headers', None):
  48. tsk = create_compiled_task(self, 'd_with_header', node)
  49. tsk.outputs.append(node.change_ext(self.env.DHEADER_ext))
  50. else:
  51. tsk = create_compiled_task(self, 'd', node)
  52. return tsk
  53. @taskgen_method
  54. def generate_header(self, filename):
  55. """
  56. See feature request #104::
  57. def build(bld):
  58. tg = bld.program(source='foo.d', target='app')
  59. tg.generate_header('blah.d')
  60. # is equivalent to:
  61. #tg = bld.program(source='foo.d', target='app', header_lst='blah.d')
  62. :param filename: header to create
  63. :type filename: string
  64. """
  65. try:
  66. self.header_lst.append([filename, self.install_path])
  67. except AttributeError:
  68. self.header_lst = [[filename, self.install_path]]
  69. @feature('d')
  70. def process_header(self):
  71. """
  72. Process the attribute 'header_lst' to create the d header compilation tasks::
  73. def build(bld):
  74. bld.program(source='foo.d', target='app', header_lst='blah.d')
  75. """
  76. for i in getattr(self, 'header_lst', []):
  77. node = self.path.find_resource(i[0])
  78. if not node:
  79. raise Errors.WafError('file %r not found on d obj' % i[0])
  80. self.create_task('d_header', node, node.change_ext('.di'))