dmd.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python
  2. # encoding: utf-8
  3. # Carlos Rafael Giani, 2007 (dv)
  4. # Thomas Nagy, 2008-2018 (ita)
  5. import sys
  6. from waflib.Tools import ar, d
  7. from waflib.Configure import conf
  8. @conf
  9. def find_dmd(conf):
  10. """
  11. Finds the program *dmd*, *dmd2*, or *ldc* and set the variable *D*
  12. """
  13. conf.find_program(['dmd', 'dmd2', 'ldc'], var='D')
  14. # make sure that we're dealing with dmd1, dmd2, or ldc(1)
  15. out = conf.cmd_and_log(conf.env.D + ['--help'])
  16. if out.find("D Compiler v") == -1:
  17. out = conf.cmd_and_log(conf.env.D + ['-version'])
  18. if out.find("based on DMD v1.") == -1:
  19. conf.fatal("detected compiler is not dmd/ldc")
  20. @conf
  21. def common_flags_ldc(conf):
  22. """
  23. Sets the D flags required by *ldc*
  24. """
  25. v = conf.env
  26. v.DFLAGS = ['-d-version=Posix']
  27. v.LINKFLAGS = []
  28. v.DFLAGS_dshlib = ['-relocation-model=pic']
  29. @conf
  30. def common_flags_dmd(conf):
  31. """
  32. Set the flags required by *dmd* or *dmd2*
  33. """
  34. v = conf.env
  35. v.D_SRC_F = ['-c']
  36. v.D_TGT_F = '-of%s'
  37. v.D_LINKER = v.D
  38. v.DLNK_SRC_F = ''
  39. v.DLNK_TGT_F = '-of%s'
  40. v.DINC_ST = '-I%s'
  41. v.DSHLIB_MARKER = v.DSTLIB_MARKER = ''
  42. v.DSTLIB_ST = v.DSHLIB_ST = '-L-l%s'
  43. v.DSTLIBPATH_ST = v.DLIBPATH_ST = '-L-L%s'
  44. v.LINKFLAGS_dprogram= ['-quiet']
  45. v.DFLAGS_dshlib = ['-fPIC']
  46. v.LINKFLAGS_dshlib = ['-L-shared']
  47. v.DHEADER_ext = '.di'
  48. v.DFLAGS_d_with_header = ['-H', '-Hf']
  49. v.D_HDR_F = '%s'
  50. def configure(conf):
  51. """
  52. Configuration for *dmd*, *dmd2*, and *ldc*
  53. """
  54. conf.find_dmd()
  55. if sys.platform == 'win32':
  56. out = conf.cmd_and_log(conf.env.D + ['--help'])
  57. if out.find('D Compiler v2.') > -1:
  58. conf.fatal('dmd2 on Windows is not supported, use gdc or ldc2 instead')
  59. conf.load('ar')
  60. conf.load('d')
  61. conf.common_flags_dmd()
  62. conf.d_platform_flags()
  63. if str(conf.env.D).find('ldc') > -1:
  64. conf.common_flags_ldc()