3 Tool-specific initialization for the Digital Mars D compiler.
4 (http://digitalmars.com/d)
6 Coded by Andy Friesen (andy@ikagames.com)
9 There are a number of problems with this script at this point in time.
10 The one that irritates me the most is the Windows linker setup. The D
11 linker doesn't have a way to add lib paths on the commandline, as far
12 as I can see. You have to specify paths relative to the SConscript or
13 use absolute paths. To hack around it, add '#/blah'. This will link
14 blah.lib from the directory where SConstruct resides.
17 DC - The name of the D compiler to use. Defaults to dmd or gdmd,
19 DPATH - List of paths to search for import modules.
20 DVERSIONS - List of version tags to enable when compiling.
21 DDEBUG - List of debug tags to enable when compiling.
23 Linker related variables:
24 LIBS - List of library files to link in.
25 DLINK - Name of the linker to use. Defaults to dmd or gdmd.
26 DLINKFLAGS - List of linker flags.
29 DLIB - Name of the lib tool to use. Defaults to lib.
30 DLIBFLAGS - List of flags to pass to the lib tool.
31 LIBS - Same as for the linker. (libraries to pull into the .lib)
35 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The SCons Foundation
37 # Permission is hereby granted, free of charge, to any person obtaining
38 # a copy of this software and associated documentation files (the
39 # "Software"), to deal in the Software without restriction, including
40 # without limitation the rights to use, copy, modify, merge, publish,
41 # distribute, sublicense, and/or sell copies of the Software, and to
42 # permit persons to whom the Software is furnished to do so, subject to
43 # the following conditions:
45 # The above copyright notice and this permission notice shall be included
46 # in all copies or substantial portions of the Software.
48 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
49 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
50 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
51 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
52 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
53 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
54 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
57 __revision__ = "src/engine/SCons/Tool/dmd.py 3842 2008/12/20 22:59:52 scons"
65 import SCons.Scanner.D
75 ext = os.path.splitext(str(s.sources[0]))[1]
88 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
90 DAction = SCons.Action.Action('$DCOM', '$DCOMSTR')
92 static_obj.add_action('.d', DAction)
93 shared_obj.add_action('.d', DAction)
94 static_obj.add_emitter('.d', SCons.Defaults.StaticObjectEmitter)
95 shared_obj.add_emitter('.d', SCons.Defaults.SharedObjectEmitter)
97 dc = env.Detect(['dmd', 'gdmd'])
99 env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -of$TARGET $SOURCES'
100 env['_DINCFLAGS'] = '$( ${_concat(DINCPREFIX, DPATH, DINCSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
101 env['_DVERFLAGS'] = '$( ${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__)} $)'
102 env['_DDEBUGFLAGS'] = '$( ${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)} $)'
103 env['_DFLAGS'] = '$( ${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)} $)'
105 env['DPATH'] = ['#/']
107 env['DVERSIONS'] = []
111 # Add the path to the standard library.
112 # This is merely for the convenience of the dependency scanner.
113 dmd_path = env.WhereIs(dc)
115 x = string.rindex(dmd_path, dc)
116 phobosDir = dmd_path[:x] + '/../src/phobos'
117 if os.path.isdir(phobosDir):
118 env.Append(DPATH = [phobosDir])
120 env['DINCPREFIX'] = '-I'
121 env['DINCSUFFIX'] = ''
122 env['DVERPREFIX'] = '-version='
123 env['DVERSUFFIX'] = ''
124 env['DDEBUGPREFIX'] = '-debug='
125 env['DDEBUGSUFFIX'] = ''
126 env['DFLAGPREFIX'] = '-'
127 env['DFLAGSUFFIX'] = ''
128 env['DFILESUFFIX'] = '.d'
130 # Need to use the Digital Mars linker/lib on windows.
131 # *nix can just use GNU link.
132 if env['PLATFORM'] == 'win32':
134 env['DLINKCOM'] = '$DLINK -of$TARGET $SOURCES $DFLAGS $DLINKFLAGS $_DLINKLIBFLAGS'
136 env['DLIBCOM'] = '$DLIB $_DLIBFLAGS -c $TARGET $SOURCES $_DLINKLIBFLAGS'
138 env['_DLINKLIBFLAGS'] = '$( ${_concat(DLIBLINKPREFIX, LIBS, DLIBLINKSUFFIX, __env__, RDirs, TARGET, SOURCE)} $)'
139 env['_DLIBFLAGS'] = '$( ${_concat(DLIBFLAGPREFIX, DLIBFLAGS, DLIBFLAGSUFFIX, __env__)} $)'
140 env['DLINKFLAGS'] = []
141 env['DLIBLINKPREFIX'] = ''
142 env['DLIBLINKSUFFIX'] = '.lib'
143 env['DLIBFLAGPREFIX'] = '-'
144 env['DLIBFLAGSUFFIX'] = ''
145 env['DLINKFLAGPREFIX'] = '-'
146 env['DLINKFLAGSUFFIX'] = ''
148 SCons.Tool.createStaticLibBuilder(env)
150 # Basically, we hijack the link and ar builders with our own.
151 # these builders check for the presence of D source, and swap out
152 # the system's defaults for the Digital Mars tools. If there's no D
153 # source, then we silently return the previous settings.
154 linkcom = env.get('LINKCOM')
156 env['SMART_LINKCOM'] = smart_link[linkcom]
158 def _smartLink(source, target, env, for_signature,
159 defaultLinker=linkcom):
161 # XXX I'm not sure how to add a $DLINKCOMSTR variable
162 # so that it works with this _smartLink() logic,
163 # and I don't have a D compiler/linker to try it out,
164 # so we'll leave it alone for now.
168 env['SMART_LINKCOM'] = smart_link[linkcom] = _smartLink
170 arcom = env.get('ARCOM')
172 env['SMART_ARCOM'] = smart_lib[arcom]
174 def _smartLib(source, target, env, for_signature,
177 # XXX I'm not sure how to add a $DLIBCOMSTR variable
178 # so that it works with this _smartLib() logic, and
179 # I don't have a D compiler/archiver to try it out,
180 # so we'll leave it alone for now.
184 env['SMART_ARCOM'] = smart_lib[arcom] = _smartLib
186 # It is worth noting that the final space in these strings is
187 # absolutely pivotal. SCons sees these as actions and not generators
188 # if it is not there. (very bad)
189 env['ARCOM'] = '$SMART_ARCOM '
190 env['LINKCOM'] = '$SMART_LINKCOM '
191 else: # assuming linux
192 linkcom = env.get('LINKCOM')
194 env['SMART_LINKCOM'] = smart_link[linkcom]
196 def _smartLink(source, target, env, for_signature,
197 defaultLinker=linkcom, dc=dc):
203 if 'phobos' not in libs:
205 env.Append(LIBS = ['phobos'])
207 env.Append(LIBS = ['gphobos'])
208 if 'pthread' not in libs:
209 env.Append(LIBS = ['pthread'])
211 env.Append(LIBS = ['m'])
213 env['SMART_LINKCOM'] = smart_link[linkcom] = _smartLink
215 env['LINKCOM'] = '$SMART_LINKCOM '
218 return env.Detect(['dmd', 'gdmd'])