waf/waflib/Tools/dmd.py

81 lines
1.8 KiB
Python
Raw Normal View History

2011-09-10 11:13:51 +02:00
#!/usr/bin/env python
# encoding: utf-8
# Carlos Rafael Giani, 2007 (dv)
2018-01-01 20:53:49 +01:00
# Thomas Nagy, 2008-2018 (ita)
2011-09-10 11:13:51 +02:00
import sys
2011-10-19 04:11:25 +02:00
from waflib.Tools import ar, d
2011-09-10 11:13:51 +02:00
from waflib.Configure import conf
@conf
def find_dmd(conf):
"""
2016-06-25 23:54:12 +02:00
Finds the program *dmd*, *dmd2*, or *ldc* and set the variable *D*
2011-09-10 11:13:51 +02:00
"""
2012-06-21 18:31:52 +02:00
conf.find_program(['dmd', 'dmd2', 'ldc'], var='D')
# make sure that we're dealing with dmd1, dmd2, or ldc(1)
out = conf.cmd_and_log(conf.env.D + ['--help'])
if out.find("D Compiler v") == -1:
out = conf.cmd_and_log(conf.env.D + ['-version'])
2012-06-08 22:58:38 +02:00
if out.find("based on DMD v1.") == -1:
conf.fatal("detected compiler is not dmd/ldc")
2011-09-10 11:13:51 +02:00
@conf
def common_flags_ldc(conf):
"""
2016-06-25 23:54:12 +02:00
Sets the D flags required by *ldc*
2011-09-10 11:13:51 +02:00
"""
v = conf.env
2016-06-25 23:54:12 +02:00
v.DFLAGS = ['-d-version=Posix']
v.LINKFLAGS = []
v.DFLAGS_dshlib = ['-relocation-model=pic']
2011-09-10 11:13:51 +02:00
@conf
def common_flags_dmd(conf):
"""
2012-06-21 18:31:52 +02:00
Set the flags required by *dmd* or *dmd2*
2011-09-10 11:13:51 +02:00
"""
v = conf.env
2016-06-25 23:54:12 +02:00
v.D_SRC_F = ['-c']
v.D_TGT_F = '-of%s'
2011-09-10 11:13:51 +02:00
2016-06-25 23:54:12 +02:00
v.D_LINKER = v.D
v.DLNK_SRC_F = ''
v.DLNK_TGT_F = '-of%s'
v.DINC_ST = '-I%s'
2011-09-10 11:13:51 +02:00
2016-06-25 23:54:12 +02:00
v.DSHLIB_MARKER = v.DSTLIB_MARKER = ''
v.DSTLIB_ST = v.DSHLIB_ST = '-L-l%s'
v.DSTLIBPATH_ST = v.DLIBPATH_ST = '-L-L%s'
2011-09-10 11:13:51 +02:00
2016-06-25 23:54:12 +02:00
v.LINKFLAGS_dprogram= ['-quiet']
2011-09-10 11:13:51 +02:00
2016-06-25 23:54:12 +02:00
v.DFLAGS_dshlib = ['-fPIC']
v.LINKFLAGS_dshlib = ['-L-shared']
2011-09-10 11:13:51 +02:00
2016-06-25 23:54:12 +02:00
v.DHEADER_ext = '.di'
2011-09-10 11:13:51 +02:00
v.DFLAGS_d_with_header = ['-H', '-Hf']
2016-06-25 23:54:12 +02:00
v.D_HDR_F = '%s'
2011-09-10 11:13:51 +02:00
def configure(conf):
"""
2012-06-21 18:31:52 +02:00
Configuration for *dmd*, *dmd2*, and *ldc*
2011-09-10 11:13:51 +02:00
"""
conf.find_dmd()
2011-10-19 04:11:25 +02:00
if sys.platform == 'win32':
out = conf.cmd_and_log(conf.env.D + ['--help'])
2016-06-25 23:54:12 +02:00
if out.find('D Compiler v2.') > -1:
conf.fatal('dmd2 on Windows is not supported, use gdc or ldc2 instead')
2011-10-19 04:11:25 +02:00
conf.load('ar')
conf.load('d')
conf.common_flags_dmd()
conf.d_platform_flags()
if str(conf.env.D).find('ldc') > -1:
conf.common_flags_ldc()
2011-09-10 11:13:51 +02:00