summaryrefslogtreecommitdiff
path: root/engine/SCons/Tool/dmd.py
diff options
context:
space:
mode:
authorJörg Frings-Fürst <jff@merkur>2014-07-26 11:45:48 +0200
committerJörg Frings-Fürst <jff@merkur>2014-07-26 11:45:48 +0200
commit99469e37d07b9f326c5b2c8157566f2f512cdc56 (patch)
tree475c0ae1b3b3b8be085b54420894896688ea363c /engine/SCons/Tool/dmd.py
parent2176ae74d2f856582dd1e498a63a31949a7e19e2 (diff)
parent7c6b954c00c2a2eed2e975ec797216c515cd249d (diff)
Merge tag 'upstream/2.3.2'
Upstream version 2.3.2
Diffstat (limited to 'engine/SCons/Tool/dmd.py')
-rw-r--r--engine/SCons/Tool/dmd.py194
1 files changed, 54 insertions, 140 deletions
diff --git a/engine/SCons/Tool/dmd.py b/engine/SCons/Tool/dmd.py
index 67355b1..aae9a27 100644
--- a/engine/SCons/Tool/dmd.py
+++ b/engine/SCons/Tool/dmd.py
@@ -3,14 +3,14 @@
Tool-specific initialization for the Digital Mars D compiler.
(http://digitalmars.com/d)
-Coded by Andy Friesen (andy@ikagames.com)
+Originally coded by Andy Friesen (andy@ikagames.com)
15 November 2003
-Amended by Russel Winder (russel@russel.org.uk)
-2010-02-07
+Evolved by Russel Winder (russel@winder.org.uk)
+2010-02-07 onwards
There are a number of problems with this script at this point in time.
-The one that irritates me the most is the Windows linker setup. The D
+The one that irritates the most is the Windows linker setup. The D
linker doesn't have a way to add lib paths on the commandline, as far
as I can see. You have to specify paths relative to the SConscript or
use absolute paths. To hack around it, add '#/blah'. This will link
@@ -18,14 +18,15 @@ blah.lib from the directory where SConstruct resides.
Compiler variables:
DC - The name of the D compiler to use. Defaults to dmd or gdmd,
- whichever is found.
+ whichever is found.
DPATH - List of paths to search for import modules.
DVERSIONS - List of version tags to enable when compiling.
DDEBUG - List of debug tags to enable when compiling.
Linker related variables:
LIBS - List of library files to link in.
- DLINK - Name of the linker to use. Defaults to dmd or gdmd.
+ DLINK - Name of the linker to use. Defaults to dmd or gdmd,
+ whichever is found.
DLINKFLAGS - List of linker flags.
Lib tool variables:
@@ -35,7 +36,7 @@ Lib tool variables:
"""
#
-# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 The SCons Foundation
+# Copyright (c) 2001 - 2014 The SCons Foundation
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
@@ -57,9 +58,10 @@ Lib tool variables:
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
-__revision__ = "src/engine/SCons/Tool/dmd.py 2014/03/02 14:18:15 garyo"
+__revision__ = "src/engine/SCons/Tool/dmd.py 2014/07/05 09:42:21 garyo"
import os
+import subprocess
import SCons.Action
import SCons.Builder
@@ -67,57 +69,36 @@ import SCons.Defaults
import SCons.Scanner.D
import SCons.Tool
-# Adapted from c++.py
-def isD(source):
- if not source:
- return 0
+import SCons.Tool.DCommon
- for s in source:
- if s.sources:
- ext = os.path.splitext(str(s.sources[0]))[1]
- if ext == '.d':
- return 1
- return 0
-
-smart_link = {}
-
-smart_lib = {}
def generate(env):
- global smart_link
- global smart_lib
-
static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
- DAction = SCons.Action.Action('$DCOM', '$DCOMSTR')
-
- static_obj.add_action('.d', DAction)
- shared_obj.add_action('.d', DAction)
+ static_obj.add_action('.d', SCons.Defaults.DAction)
+ shared_obj.add_action('.d', SCons.Defaults.ShDAction)
static_obj.add_emitter('.d', SCons.Defaults.StaticObjectEmitter)
shared_obj.add_emitter('.d', SCons.Defaults.SharedObjectEmitter)
- dc = env.Detect(['dmd', 'gdmd'])
- env['DC'] = dc
+ env['DC'] = env.Detect(['dmd', 'gdmd'])
env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -of$TARGET $SOURCES'
env['_DINCFLAGS'] = '$( ${_concat(DINCPREFIX, DPATH, DINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
env['_DVERFLAGS'] = '$( ${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__)} $)'
env['_DDEBUGFLAGS'] = '$( ${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)} $)'
env['_DFLAGS'] = '$( ${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)} $)'
+ env['SHDC'] = '$DC'
+ env['SHDCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -fPIC -of$TARGET $SOURCES'
+
env['DPATH'] = ['#/']
env['DFLAGS'] = []
env['DVERSIONS'] = []
env['DDEBUG'] = []
- if dc:
- # Add the path to the standard library.
- # This is merely for the convenience of the dependency scanner.
- dmd_path = env.WhereIs(dc)
- if dmd_path:
- x = dmd_path.rindex(dc)
- phobosDir = dmd_path[:x] + '/../src/phobos'
- if os.path.isdir(phobosDir):
- env.Append(DPATH = [phobosDir])
+ env['STATIC_AND_SHARED_OBJECTS_ARE_THE_SAME'] = 0
+
+ if env['DC']:
+ SCons.Tool.DCommon.addDPATHToEnv(env, env['DC'])
env['DINCPREFIX'] = '-I'
env['DINCSUFFIX'] = ''
@@ -129,106 +110,39 @@ def generate(env):
env['DFLAGSUFFIX'] = ''
env['DFILESUFFIX'] = '.d'
- # Need to use the Digital Mars linker/lib on windows.
- # *nix can just use GNU link.
- if env['PLATFORM'] == 'win32':
- env['DLINK'] = '$DC'
- env['DLINKCOM'] = '$DLINK -of$TARGET $SOURCES $DFLAGS $DLINKFLAGS $_DLINKLIBFLAGS'
- env['DLIB'] = 'lib'
- env['DLIBCOM'] = '$DLIB $_DLIBFLAGS -c $TARGET $SOURCES $_DLINKLIBFLAGS'
-
- env['_DLINKLIBFLAGS'] = '$( ${_concat(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
- env['_DLIBFLAGS'] = '$( ${_concat(DLIBFLAGPREFIX, DLIBFLAGS, DLIBFLAGSUFFIX, __env__)} $)'
- env['DLINKFLAGS'] = []
- env['DLIBLINKPREFIX'] = ''
- env['DLIBLINKSUFFIX'] = '.lib'
- env['DLIBFLAGPREFIX'] = '-'
- env['DLIBFLAGSUFFIX'] = ''
- env['DLINKFLAGPREFIX'] = '-'
- env['DLINKFLAGSUFFIX'] = ''
-
- SCons.Tool.createStaticLibBuilder(env)
-
- # Basically, we hijack the link and ar builders with our own.
- # these builders check for the presence of D source, and swap out
- # the system's defaults for the Digital Mars tools. If there's no D
- # source, then we silently return the previous settings.
- linkcom = env.get('LINKCOM')
- try:
- env['SMART_LINKCOM'] = smart_link[linkcom]
- except KeyError:
- def _smartLink(source, target, env, for_signature,
- defaultLinker=linkcom):
- if isD(source):
- # XXX I'm not sure how to add a $DLINKCOMSTR variable
- # so that it works with this _smartLink() logic,
- # and I don't have a D compiler/linker to try it out,
- # so we'll leave it alone for now.
- return '$DLINKCOM'
- else:
- return defaultLinker
- env['SMART_LINKCOM'] = smart_link[linkcom] = _smartLink
-
- arcom = env.get('ARCOM')
- try:
- env['SMART_ARCOM'] = smart_lib[arcom]
- except KeyError:
- def _smartLib(source, target, env, for_signature,
- defaultLib=arcom):
- if isD(source):
- # XXX I'm not sure how to add a $DLIBCOMSTR variable
- # so that it works with this _smartLib() logic, and
- # I don't have a D compiler/archiver to try it out,
- # so we'll leave it alone for now.
- return '$DLIBCOM'
- else:
- return defaultLib
- env['SMART_ARCOM'] = smart_lib[arcom] = _smartLib
-
- # It is worth noting that the final space in these strings is
- # absolutely pivotal. SCons sees these as actions and not generators
- # if it is not there. (very bad)
- env['ARCOM'] = '$SMART_ARCOM '
- env['LINKCOM'] = '$SMART_LINKCOM '
- else: # assuming linux
- linkcom = env.get('LINKCOM')
- try:
- env['SMART_LINKCOM'] = smart_link[linkcom]
- except KeyError:
- def _smartLink(source, target, env, for_signature,
- defaultLinker=linkcom, dc=dc):
- if isD(source):
- try:
- libs = env['LIBS']
- except KeyError:
- libs = []
- if dc == 'dmd':
- # TODO: This assumes that the dmd executable is in the
- # bin directory and that the libraries are in a peer
- # directory lib. This true of the Digital Mars
- # distribution but . . .
- import glob
- dHome = env.WhereIs(dc).replace('/dmd' , '/..')
- if glob.glob(dHome + '/lib/*phobos2*'):
- if 'phobos2' not in libs:
- env.Append(LIBPATH = [dHome + '/lib'])
- env.Append(LIBS = ['phobos2'])
- # TODO: Find out when there will be a
- # 64-bit version of D.
- env.Append(LINKFLAGS = ['-m32'])
- else:
- if 'phobos' not in libs:
- env.Append(LIBS = ['phobos'])
- elif dc is 'gdmd':
- env.Append(LIBS = ['gphobos'])
- if 'pthread' not in libs:
- env.Append(LIBS = ['pthread'])
- if 'm' not in libs:
- env.Append(LIBS = ['m'])
- return defaultLinker
- env['SMART_LINKCOM'] = smart_link[linkcom] = _smartLink
-
- env['LINKCOM'] = '$SMART_LINKCOM '
+ env['DLINK'] = '$DC'
+ env['DLINKFLAGS'] = SCons.Util.CLVar('')
+ env['DLINKCOM'] = '$DLINK -of$TARGET $DLINKFLAGS $__DRPATH $SOURCES $_DLIBDIRFLAGS $_DLIBFLAGS'
+
+ env['DSHLINK'] = '$DC'
+ env['DSHLINKFLAGS'] = SCons.Util.CLVar('$DLINKFLAGS -shared -defaultlib=libphobos2.so')
+ env['SHDLINKCOM'] = '$DLINK -of$TARGET $DSHLINKFLAGS $__DRPATH $SOURCES $_DLIBDIRFLAGS $_DLIBFLAGS'
+
+ env['DLIBLINKPREFIX'] = '' if env['PLATFORM'] == 'win32' else '-L-l'
+ env['DLIBLINKSUFFIX'] = '.lib' if env['PLATFORM'] == 'win32' else ''
+ env['_DLIBFLAGS'] = '${_stripixes(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, LIBPREFIXES, LIBSUFFIXES, __env__)}'
+
+ env['DLIBDIRPREFIX'] = '-L-L'
+ env['DLIBDIRSUFFIX'] = ''
+ env['_DLIBDIRFLAGS'] = '$( ${_concat(DLIBDIRPREFIX, LIBPATH, DLIBDIRSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
+
+
+ env['DLIB'] = 'lib' if env['PLATFORM'] == 'win32' else 'ar cr'
+ env['DLIBCOM'] = '$DLIB $_DLIBFLAGS {} $TARGET $SOURCES $_DLIBFLAGS'.format('-c' if env['PLATFORM'] == 'win32' else '')
+
+ #env['_DLIBFLAGS'] = '$( ${_concat(DLIBFLAGPREFIX, DLIBFLAGS, DLIBFLAGSUFFIX, __env__)} $)'
+
+ env['DLIBFLAGPREFIX'] = '-'
+ env['DLIBFLAGSUFFIX'] = ''
+
+ # __RPATH is set to $_RPATH in the platform specification if that
+ # platform supports it.
+ env['DRPATHPREFIX'] = '-L-rpath='
+ env['DRPATHSUFFIX'] = ''
+ env['_DRPATH'] = '${_concat(DRPATHPREFIX, RPATH, DRPATHSUFFIX, __env__)}'
+
+ SCons.Tool.createStaticLibBuilder(env)
+
def exists(env):
return env.Detect(['dmd', 'gdmd'])