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.

158 lines
6.1 KiB

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