third_party:waf: update to upstream 2.0.4 release
[vlendec/samba-autobuild/.git] / third_party / waf / waflib / Tools / dmd.py
1 #! /usr/bin/env python
2 # encoding: utf-8
3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
4
5 #!/usr/bin/env python
6 # encoding: utf-8
7 # Carlos Rafael Giani, 2007 (dv)
8 # Thomas Nagy, 2008-2018 (ita)
9
10 import sys
11 from waflib.Tools import ar, d
12 from waflib.Configure import conf
13
14 @conf
15 def find_dmd(conf):
16         """
17         Finds the program *dmd*, *dmd2*, or *ldc* and set the variable *D*
18         """
19         conf.find_program(['dmd', 'dmd2', 'ldc'], var='D')
20
21         # make sure that we're dealing with dmd1, dmd2, or ldc(1)
22         out = conf.cmd_and_log(conf.env.D + ['--help'])
23         if out.find("D Compiler v") == -1:
24                 out = conf.cmd_and_log(conf.env.D + ['-version'])
25                 if out.find("based on DMD v1.") == -1:
26                         conf.fatal("detected compiler is not dmd/ldc")
27
28 @conf
29 def common_flags_ldc(conf):
30         """
31         Sets the D flags required by *ldc*
32         """
33         v = conf.env
34         v.DFLAGS        = ['-d-version=Posix']
35         v.LINKFLAGS     = []
36         v.DFLAGS_dshlib = ['-relocation-model=pic']
37
38 @conf
39 def common_flags_dmd(conf):
40         """
41         Set the flags required by *dmd* or *dmd2*
42         """
43         v = conf.env
44
45         v.D_SRC_F           = ['-c']
46         v.D_TGT_F           = '-of%s'
47
48         v.D_LINKER          = v.D
49         v.DLNK_SRC_F        = ''
50         v.DLNK_TGT_F        = '-of%s'
51         v.DINC_ST           = '-I%s'
52
53         v.DSHLIB_MARKER = v.DSTLIB_MARKER = ''
54         v.DSTLIB_ST = v.DSHLIB_ST         = '-L-l%s'
55         v.DSTLIBPATH_ST = v.DLIBPATH_ST   = '-L-L%s'
56
57         v.LINKFLAGS_dprogram= ['-quiet']
58
59         v.DFLAGS_dshlib     = ['-fPIC']
60         v.LINKFLAGS_dshlib  = ['-L-shared']
61
62         v.DHEADER_ext       = '.di'
63         v.DFLAGS_d_with_header = ['-H', '-Hf']
64         v.D_HDR_F           = '%s'
65
66 def configure(conf):
67         """
68         Configuration for *dmd*, *dmd2*, and *ldc*
69         """
70         conf.find_dmd()
71
72         if sys.platform == 'win32':
73                 out = conf.cmd_and_log(conf.env.D + ['--help'])
74                 if out.find('D Compiler v2.') > -1:
75                         conf.fatal('dmd2 on Windows is not supported, use gdc or ldc2 instead')
76
77         conf.load('ar')
78         conf.load('d')
79         conf.common_flags_dmd()
80         conf.d_platform_flags()
81
82         if str(conf.env.D).find('ldc') > -1:
83                 conf.common_flags_ldc()
84