You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
6.2 KiB

6 years ago
  1. from __future__ import print_function
  2. """SCons.Tool.dmd
  3. Tool-specific initialization for the Digital Mars D compiler.
  4. (http://digitalmars.com/d)
  5. Originally coded by Andy Friesen (andy@ikagames.com)
  6. 15 November 2003
  7. Evolved by Russel Winder (russel@winder.org.uk)
  8. 2010-02-07 onwards
  9. Compiler variables:
  10. DC - The name of the D compiler to use. Defaults to dmd or gdmd,
  11. whichever is found.
  12. DPATH - List of paths to search for import modules.
  13. DVERSIONS - List of version tags to enable when compiling.
  14. DDEBUG - List of debug tags to enable when compiling.
  15. Linker related variables:
  16. LIBS - List of library files to link in.
  17. DLINK - Name of the linker to use. Defaults to dmd or gdmd,
  18. whichever is found.
  19. DLINKFLAGS - List of linker flags.
  20. Lib tool variables:
  21. DLIB - Name of the lib tool to use. Defaults to lib.
  22. DLIBFLAGS - List of flags to pass to the lib tool.
  23. LIBS - Same as for the linker. (libraries to pull into the .lib)
  24. """
  25. #
  26. # Copyright (c) 2001 - 2017 The SCons Foundation
  27. #
  28. # Permission is hereby granted, free of charge, to any person obtaining
  29. # a copy of this software and associated documentation files (the
  30. # "Software"), to deal in the Software without restriction, including
  31. # without limitation the rights to use, copy, modify, merge, publish,
  32. # distribute, sublicense, and/or sell copies of the Software, and to
  33. # permit persons to whom the Software is furnished to do so, subject to
  34. # the following conditions:
  35. #
  36. # The above copyright notice and this permission notice shall be included
  37. # in all copies or substantial portions of the Software.
  38. #
  39. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
  40. # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  41. # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  42. # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  43. # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  44. # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  45. # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  46. #
  47. __revision__ = "src/engine/SCons/Tool/dmd.py rel_3.0.0:4395:8972f6a2f699 2017/09/18 12:59:24 bdbaddog"
  48. import os
  49. import subprocess
  50. import SCons.Action
  51. import SCons.Builder
  52. import SCons.Defaults
  53. import SCons.Scanner.D
  54. import SCons.Tool
  55. import SCons.Tool.DCommon as DCommon
  56. def generate(env):
  57. static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
  58. static_obj.add_action('.d', SCons.Defaults.DAction)
  59. shared_obj.add_action('.d', SCons.Defaults.ShDAction)
  60. static_obj.add_emitter('.d', SCons.Defaults.StaticObjectEmitter)
  61. shared_obj.add_emitter('.d', SCons.Defaults.SharedObjectEmitter)
  62. env['DC'] = env.Detect(['dmd', 'ldmd2', 'gdmd']) or 'dmd'
  63. env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -of$TARGET $SOURCES'
  64. env['_DINCFLAGS'] = '${_concat(DINCPREFIX, DPATH, DINCSUFFIX, __env__, RDirs, TARGET, SOURCE)}'
  65. env['_DVERFLAGS'] = '${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__)}'
  66. env['_DDEBUGFLAGS'] = '${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)}'
  67. env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}'
  68. env['SHDC'] = '$DC'
  69. env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -fPIC -of$TARGET $SOURCES'
  70. env['DPATH'] = ['#/']
  71. env['DFLAGS'] = []
  72. env['DVERSIONS'] = []
  73. env['DDEBUG'] = []
  74. if env['DC']:
  75. DCommon.addDPATHToEnv(env, env['DC'])
  76. env['DINCPREFIX'] = '-I'
  77. env['DINCSUFFIX'] = ''
  78. env['DVERPREFIX'] = '-version='
  79. env['DVERSUFFIX'] = ''
  80. env['DDEBUGPREFIX'] = '-debug='
  81. env['DDEBUGSUFFIX'] = ''
  82. env['DFLAGPREFIX'] = '-'
  83. env['DFLAGSUFFIX'] = ''
  84. env['DFILESUFFIX'] = '.d'
  85. env['DLINK'] = '$DC'
  86. env['DLINKFLAGS'] = SCons.Util.CLVar('')
  87. env['DLINKCOM'] = '$DLINK -of$TARGET $DLINKFLAGS $__DRPATH $SOURCES $_DLIBDIRFLAGS $_DLIBFLAGS'
  88. env['SHDLINK'] = '$DC'
  89. env['SHDLINKFLAGS'] = SCons.Util.CLVar('$DLINKFLAGS -shared -defaultlib=libphobos2.so')
  90. env['SHDLINKCOM'] = '$DLINK -of$TARGET $SHDLINKFLAGS $__SHDLIBVERSIONFLAGS $__DRPATH $SOURCES $_DLIBDIRFLAGS $_DLIBFLAGS'
  91. env['DLIBLINKPREFIX'] = '' if env['PLATFORM'] == 'win32' else '-L-l'
  92. env['DLIBLINKSUFFIX'] = '.lib' if env['PLATFORM'] == 'win32' else ''
  93. env['_DLIBFLAGS'] = '${_stripixes(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}'
  94. env['DLIBDIRPREFIX'] = '-L-L'
  95. env['DLIBDIRSUFFIX'] = ''
  96. env['_DLIBDIRFLAGS'] = '${_concat(DLIBDIRPREFIX, LIBPATH, DLIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)}'
  97. env['DLIB'] = 'lib' if env['PLATFORM'] == 'win32' else 'ar cr'
  98. env['DLIBCOM'] = '$DLIB $_DLIBFLAGS {0}$TARGET $SOURCES $_DLIBFLAGS'.format('-c ' if env['PLATFORM'] == 'win32' else '')
  99. # env['_DLIBFLAGS'] = '${_concat(DLIBFLAGPREFIX, DLIBFLAGS, DLIBFLAGSUFFIX, __env__)}'
  100. env['DLIBFLAGPREFIX'] = '-'
  101. env['DLIBFLAGSUFFIX'] = ''
  102. # __RPATH is set to $_RPATH in the platform specification if that
  103. # platform supports it.
  104. env['DRPATHPREFIX'] = '-L-rpath,' if env['PLATFORM'] == 'darwin' else '-L-rpath='
  105. env['DRPATHSUFFIX'] = ''
  106. env['_DRPATH'] = '${_concat(DRPATHPREFIX, RPATH, DRPATHSUFFIX, __env__)}'
  107. # Support for versioned libraries
  108. env['_SHDLIBVERSIONFLAGS'] = '$SHDLIBVERSIONFLAGS -L-soname=$_SHDLIBSONAME'
  109. env['_SHDLIBSONAME'] = '${DShLibSonameGenerator(__env__,TARGET)}'
  110. # NOTE: this is a quick hack, the soname will only work if there is
  111. # c/c++ linker loaded which provides callback for the ShLibSonameGenerator
  112. env['DShLibSonameGenerator'] = SCons.Tool.ShLibSonameGenerator
  113. # NOTE: this is only for further reference, currently $SHDLIBVERSION does
  114. # not work, the user must use $SHLIBVERSION
  115. env['SHDLIBVERSION'] = '$SHLIBVERSION'
  116. env['SHDLIBVERSIONFLAGS'] = []
  117. env['BUILDERS']['ProgramAllAtOnce'] = SCons.Builder.Builder(
  118. action='$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -of$TARGET $DLINKFLAGS $__DRPATH $SOURCES $_DLIBDIRFLAGS $_DLIBFLAGS',
  119. emitter=DCommon.allAtOnceEmitter,
  120. )
  121. def exists(env):
  122. return env.Detect(['dmd', 'ldmd2', 'gdmd'])
  123. # Local Variables:
  124. # tab-width:4
  125. # indent-tabs-mode:nil
  126. # End:
  127. # vim: set expandtab tabstop=4 shiftwidth=4: