Use pathlib to get file stem to build D interface filename. Add new DINTFOR and varia...
[scons.git] / SCons / Tool / gdc.py
blob4a99edc3ffc47f09664d0c808a1a106a0399bc16
1 # MIT License
3 # Copyright The SCons Foundation
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
17 # KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
18 # WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 """SCons.Tool.gdc
26 Tool-specific initialization for the GDC compiler.
27 (https://github.com/D-Programming-GDC/GDC)
29 Developed by Russel Winder (russel@winder.org.uk)
30 2012-05-09 onwards
32 Compiler variables:
33 DC - The name of the D compiler to use. Defaults to gdc.
34 DPATH - List of paths to search for import modules.
35 DVERSIONS - List of version tags to enable when compiling.
36 DDEBUG - List of debug tags to enable when compiling.
38 Linker related variables:
39 LIBS - List of library files to link in.
40 DLINK - Name of the linker to use. Defaults to gdc.
41 DLINKFLAGS - List of linker flags.
43 Lib tool variables:
44 DLIB - Name of the lib tool to use. Defaults to lib.
45 DLIBFLAGS - List of flags to pass to the lib tool.
46 LIBS - Same as for the linker. (libraries to pull into the .lib)
47 """
49 import SCons.Action
50 import SCons.Defaults
51 import SCons.Tool
53 import SCons.Tool.DCommon as DCommon
54 import SCons.Tool.linkCommon
57 def generate(env) -> None:
58 static_obj, shared_obj = SCons.Tool.createObjBuilders(env)
60 static_obj.add_action('.d', SCons.Defaults.DAction)
61 shared_obj.add_action('.d', SCons.Defaults.ShDAction)
62 static_obj.add_emitter('.d', DCommon.DStaticObjectEmitter)
63 shared_obj.add_emitter('.d', DCommon.DSharedObjectEmitter)
65 env['DC'] = env.Detect('gdc') or 'gdc'
66 env['DCOM'] = '$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -c -o $TARGET $SOURCES'
67 env['_DINCFLAGS'] = '${_concat(DINCPREFIX, DPATH, DINCSUFFIX, __env__, RDirs, TARGET, SOURCE)}'
68 env['_DVERFLAGS'] = '${_concat(DVERPREFIX, DVERSIONS, DVERSUFFIX, __env__)}'
69 env['_DDEBUGFLAGS'] = '${_concat(DDEBUGPREFIX, DDEBUG, DDEBUGSUFFIX, __env__)}'
70 env['_DINTFDIR'] = "${DI_FILE_DIR and DINTFDIRPREFIX+DI_FILE_DIR+DINTFDIRSUFFIX}"
71 env['_DFLAGS'] = '${_concat(DFLAGPREFIX, DFLAGS, DFLAGSUFFIX, __env__)}'
73 env['SHDC'] = '$DC'
74 env['SHDCOM'] = '$SHDC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS $_DINTFDIR -fPIC -c -o $TARGET $SOURCES'
76 env['DPATH'] = ['#/']
77 env['DFLAGS'] = []
78 env['DVERSIONS'] = []
79 env['DDEBUG'] = []
80 env['DINTFDIR'] = []
82 if env['DC']:
83 DCommon.addDPATHToEnv(env, env['DC'])
85 env['DINCPREFIX'] = '-I'
86 env['DINCSUFFIX'] = ''
87 env['DVERPREFIX'] = '-fversion='
88 env['DVERSUFFIX'] = ''
89 env['DDEBUGPREFIX'] = '-fdebug='
90 env['DDEBUGSUFFIX'] = ''
91 env['DFLAGPREFIX'] = '-'
92 env['DFLAGSUFFIX'] = ''
93 env['DFILESUFFIX'] = '.d'
94 env['DI_FILE_DIR'] = ''
95 env['DI_FILE_SUFFIX'] = '.di'
96 env['DINTFDIRPREFIX'] = '-Hd'
97 env['DINTFDIRSUFFIX'] = ''
99 env['DLINK'] = '$DC'
100 env['DLINKFLAGS'] = SCons.Util.CLVar('')
101 env['DLINKCOM'] = '$DLINK -o $TARGET $DLINKFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
103 env['SHDLINK'] = '$DC'
104 env['SHDLINKFLAGS'] = SCons.Util.CLVar('$DLINKFLAGS -shared -shared-libphobos')
105 env['SHDLINKCOM'] = '$DLINK -o $TARGET $SHDLINKFLAGS $__SHDLIBVERSIONFLAGS $__RPATH $SOURCES $_LIBDIRFLAGS $_LIBFLAGS'
107 env['DLIB'] = 'lib' if env['PLATFORM'] == 'win32' else 'ar cr'
108 env['DLIBCOM'] = '$DLIB $_DLIBFLAGS {0}$TARGET $SOURCES $_DLINKLIBFLAGS'.format('-c ' if env['PLATFORM'] == 'win32' else '')
110 env['_DLIBFLAGS'] = '${_concat(DLIBFLAGPREFIX, DLIBFLAGS, DLIBFLAGSUFFIX, __env__)}'
112 env['DLIBFLAGPREFIX'] = '-'
113 env['DLIBFLAGSUFFIX'] = ''
114 env['DLINKFLAGPREFIX'] = '-'
115 env['DLINKFLAGSUFFIX'] = ''
117 # __RPATH is set to $_RPATH in the platform specification if that
118 # platform supports it.
119 env['RPATHPREFIX'] = '-Wl,-rpath='
120 env['RPATHSUFFIX'] = ''
121 env['_RPATH'] = '${_concat(RPATHPREFIX, RPATH, RPATHSUFFIX, __env__)}'
123 # Support for versioned libraries
124 env['_SHDLIBVERSIONFLAGS'] = '$SHDLIBVERSIONFLAGS -Wl,-soname=$_SHLIBSONAME'
126 env['BUILDERS']['ProgramAllAtOnce'] = SCons.Builder.Builder(
127 action='$DC $_DINCFLAGS $_DVERFLAGS $_DDEBUGFLAGS $_DFLAGS -o $TARGET $DLINKFLAGS $__DRPATH $SOURCES $_DLIBDIRFLAGS $_DLIBFLAGS',
128 emitter=DCommon.allAtOnceEmitter,
132 def exists(env):
133 return env.Detect('gdc')
136 # Local Variables:
137 # tab-width:4
138 # indent-tabs-mode:nil
139 # End:
140 # vim: set expandtab tabstop=4 shiftwidth=4: