| OLD | NEW | 
|---|
| (Empty) |  | 
|  | 1 """SCons.Tool.dmd | 
|  | 2 | 
|  | 3 Tool-specific initialization for the Digital Mars D compiler. | 
|  | 4 (http://digitalmars.com/d) | 
|  | 5 | 
|  | 6 Coded by Andy Friesen (andy@ikagames.com) | 
|  | 7 15 November 2003 | 
|  | 8 | 
|  | 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. | 
|  | 15 | 
|  | 16 Compiler variables: | 
|  | 17     DC - The name of the D compiler to use.  Defaults to dmd or gdmd, | 
|  | 18     whichever is found. | 
|  | 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. | 
|  | 22 | 
|  | 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. | 
|  | 27 | 
|  | 28 Lib tool variables: | 
|  | 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) | 
|  | 32 """ | 
|  | 33 | 
|  | 34 # | 
|  | 35 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The S
     Cons Foundation | 
|  | 36 # | 
|  | 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: | 
|  | 44 # | 
|  | 45 # The above copyright notice and this permission notice shall be included | 
|  | 46 # in all copies or substantial portions of the Software. | 
|  | 47 # | 
|  | 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. | 
|  | 55 # | 
|  | 56 | 
|  | 57 __revision__ = "src/engine/SCons/Tool/dmd.py 5134 2010/08/16 23:02:40 bdeegan" | 
|  | 58 | 
|  | 59 import os | 
|  | 60 | 
|  | 61 import SCons.Action | 
|  | 62 import SCons.Builder | 
|  | 63 import SCons.Defaults | 
|  | 64 import SCons.Scanner.D | 
|  | 65 import SCons.Tool | 
|  | 66 | 
|  | 67 # Adapted from c++.py | 
|  | 68 def isD(source): | 
|  | 69     if not source: | 
|  | 70         return 0 | 
|  | 71 | 
|  | 72     for s in source: | 
|  | 73         if s.sources: | 
|  | 74             ext = os.path.splitext(str(s.sources[0]))[1] | 
|  | 75             if ext == '.d': | 
|  | 76                 return 1 | 
|  | 77     return 0 | 
|  | 78 | 
|  | 79 smart_link = {} | 
|  | 80 | 
|  | 81 smart_lib = {} | 
|  | 82 | 
|  | 83 def generate(env): | 
|  | 84     global smart_link | 
|  | 85     global smart_lib | 
|  | 86 | 
|  | 87     static_obj, shared_obj = SCons.Tool.createObjBuilders(env) | 
|  | 88 | 
|  | 89     DAction = SCons.Action.Action('$DCOM', '$DCOMSTR') | 
|  | 90 | 
|  | 91     static_obj.add_action('.d', DAction) | 
|  | 92     shared_obj.add_action('.d', DAction) | 
|  | 93     static_obj.add_emitter('.d', SCons.Defaults.StaticObjectEmitter) | 
|  | 94     shared_obj.add_emitter('.d', SCons.Defaults.SharedObjectEmitter) | 
|  | 95 | 
|  | 96     dc = env.Detect(['dmd', 'gdmd']) | 
|  | 97     env['DC'] = dc | 
|  | 98     env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -c -of$TAR
     GET $SOURCES' | 
|  | 99     env['_DINCFLAGS'] = '$( ${_concat(DINCPREFIX, DPATH, DINCSUFFIX, __env__, RD
     irs, TARGET, SOURCE)}  $)' | 
|  | 100     env['_DVERFLAGS'] = '$( ${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__
     )}  $)' | 
|  | 101     env['_DDEBUGFLAGS'] = '$( ${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __en
     v__)} $)' | 
|  | 102     env['_DFLAGS'] = '$( ${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)} $
     )' | 
|  | 103 | 
|  | 104     env['DPATH'] = ['#/'] | 
|  | 105     env['DFLAGS'] = [] | 
|  | 106     env['DVERSIONS'] = [] | 
|  | 107     env['DDEBUG'] = [] | 
|  | 108 | 
|  | 109     if dc: | 
|  | 110         # Add the path to the standard library. | 
|  | 111         # This is merely for the convenience of the dependency scanner. | 
|  | 112         dmd_path = env.WhereIs(dc) | 
|  | 113         if dmd_path: | 
|  | 114             x = dmd_path.rindex(dc) | 
|  | 115             phobosDir = dmd_path[:x] + '/../src/phobos' | 
|  | 116             if os.path.isdir(phobosDir): | 
|  | 117                 env.Append(DPATH = [phobosDir]) | 
|  | 118 | 
|  | 119     env['DINCPREFIX'] = '-I' | 
|  | 120     env['DINCSUFFIX'] = '' | 
|  | 121     env['DVERPREFIX'] = '-version=' | 
|  | 122     env['DVERSUFFIX'] = '' | 
|  | 123     env['DDEBUGPREFIX'] = '-debug=' | 
|  | 124     env['DDEBUGSUFFIX'] = '' | 
|  | 125     env['DFLAGPREFIX'] = '-' | 
|  | 126     env['DFLAGSUFFIX'] = '' | 
|  | 127     env['DFILESUFFIX'] = '.d' | 
|  | 128 | 
|  | 129     # Need to use the Digital Mars linker/lib on windows. | 
|  | 130     # *nix can just use GNU link. | 
|  | 131     if env['PLATFORM'] == 'win32': | 
|  | 132         env['DLINK'] = '$DC' | 
|  | 133         env['DLINKCOM'] = '$DLINK -of$TARGET $SOURCES $DFLAGS $DLINKFLAGS $_DLIN
     KLIBFLAGS' | 
|  | 134         env['DLIB'] = 'lib' | 
|  | 135         env['DLIBCOM'] = '$DLIB $_DLIBFLAGS -c $TARGET $SOURCES $_DLINKLIBFLAGS' | 
|  | 136 | 
|  | 137         env['_DLINKLIBFLAGS'] = '$( ${_concat(DLIBLINKPREFIX, LIBS, DLIBLINKSUFF
     IX, __env__, RDirs, TARGET, SOURCE)} $)' | 
|  | 138         env['_DLIBFLAGS'] = '$( ${_concat(DLIBFLAGPREFIX, DLIBFLAGS, DLIBFLAGSUF
     FIX, __env__)} $)' | 
|  | 139         env['DLINKFLAGS'] = [] | 
|  | 140         env['DLIBLINKPREFIX'] = '' | 
|  | 141         env['DLIBLINKSUFFIX'] = '.lib' | 
|  | 142         env['DLIBFLAGPREFIX'] = '-' | 
|  | 143         env['DLIBFLAGSUFFIX'] = '' | 
|  | 144         env['DLINKFLAGPREFIX'] = '-' | 
|  | 145         env['DLINKFLAGSUFFIX'] = '' | 
|  | 146 | 
|  | 147         SCons.Tool.createStaticLibBuilder(env) | 
|  | 148 | 
|  | 149         # Basically, we hijack the link and ar builders with our own. | 
|  | 150         # these builders check for the presence of D source, and swap out | 
|  | 151         # the system's defaults for the Digital Mars tools.  If there's no D | 
|  | 152         # source, then we silently return the previous settings. | 
|  | 153         linkcom = env.get('LINKCOM') | 
|  | 154         try: | 
|  | 155             env['SMART_LINKCOM'] = smart_link[linkcom] | 
|  | 156         except KeyError: | 
|  | 157             def _smartLink(source, target, env, for_signature, | 
|  | 158                            defaultLinker=linkcom): | 
|  | 159                 if isD(source): | 
|  | 160                     # XXX I'm not sure how to add a $DLINKCOMSTR variable | 
|  | 161                     # so that it works with this _smartLink() logic, | 
|  | 162                     # and I don't have a D compiler/linker to try it out, | 
|  | 163                     # so we'll leave it alone for now. | 
|  | 164                     return '$DLINKCOM' | 
|  | 165                 else: | 
|  | 166                     return defaultLinker | 
|  | 167             env['SMART_LINKCOM'] = smart_link[linkcom] = _smartLink | 
|  | 168 | 
|  | 169         arcom = env.get('ARCOM') | 
|  | 170         try: | 
|  | 171             env['SMART_ARCOM'] = smart_lib[arcom] | 
|  | 172         except KeyError: | 
|  | 173             def _smartLib(source, target, env, for_signature, | 
|  | 174                          defaultLib=arcom): | 
|  | 175                 if isD(source): | 
|  | 176                     # XXX I'm not sure how to add a $DLIBCOMSTR variable | 
|  | 177                     # so that it works with this _smartLib() logic, and | 
|  | 178                     # I don't have a D compiler/archiver to try it out, | 
|  | 179                     # so we'll leave it alone for now. | 
|  | 180                     return '$DLIBCOM' | 
|  | 181                 else: | 
|  | 182                     return defaultLib | 
|  | 183             env['SMART_ARCOM'] = smart_lib[arcom] = _smartLib | 
|  | 184 | 
|  | 185         # It is worth noting that the final space in these strings is | 
|  | 186         # absolutely pivotal.  SCons sees these as actions and not generators | 
|  | 187         # if it is not there. (very bad) | 
|  | 188         env['ARCOM'] = '$SMART_ARCOM ' | 
|  | 189         env['LINKCOM'] = '$SMART_LINKCOM ' | 
|  | 190     else: # assuming linux | 
|  | 191         linkcom = env.get('LINKCOM') | 
|  | 192         try: | 
|  | 193             env['SMART_LINKCOM'] = smart_link[linkcom] | 
|  | 194         except KeyError: | 
|  | 195             def _smartLink(source, target, env, for_signature, | 
|  | 196                            defaultLinker=linkcom, dc=dc): | 
|  | 197                 if isD(source): | 
|  | 198                     try: | 
|  | 199                         libs = env['LIBS'] | 
|  | 200                     except KeyError: | 
|  | 201                         libs = [] | 
|  | 202                     if 'phobos' not in libs and 'gphobos' not in libs: | 
|  | 203                         if dc is 'dmd': | 
|  | 204                             env.Append(LIBS = ['phobos']) | 
|  | 205                         elif dc is 'gdmd': | 
|  | 206                             env.Append(LIBS = ['gphobos']) | 
|  | 207                     if 'pthread' not in libs: | 
|  | 208                         env.Append(LIBS = ['pthread']) | 
|  | 209                     if 'm' not in libs: | 
|  | 210                         env.Append(LIBS = ['m']) | 
|  | 211                 return defaultLinker | 
|  | 212             env['SMART_LINKCOM'] = smart_link[linkcom] = _smartLink | 
|  | 213 | 
|  | 214         env['LINKCOM'] = '$SMART_LINKCOM ' | 
|  | 215 | 
|  | 216 def exists(env): | 
|  | 217     return env.Detect(['dmd', 'gdmd']) | 
|  | 218 | 
|  | 219 # Local Variables: | 
|  | 220 # tab-width:4 | 
|  | 221 # indent-tabs-mode:nil | 
|  | 222 # End: | 
|  | 223 # vim: set expandtab tabstop=4 shiftwidth=4: | 
| OLD | NEW | 
|---|