3 # Carlos Rafael Giani, 2007 (dv)
4 # Thomas Nagy, 2007-2018 (ita)
6 from waflib
import Utils
, Task
, Errors
7 from waflib
.TaskGen
import taskgen_method
, feature
, extension
8 from waflib
.Tools
import d_scan
, d_config
9 from waflib
.Tools
.ccroot
import link_task
, stlink_task
12 "Compile a d file into an object file"
14 run_str
= '${D} ${DFLAGS} ${DINC_ST:INCPATHS} ${D_SRC_F:SRC} ${D_TGT_F:TGT}'
17 class d_with_header(d
):
18 "Compile a d file and generate a header"
19 run_str
= '${D} ${DFLAGS} ${DINC_ST:INCPATHS} ${D_HDR_F:tgt.outputs[1].bldpath()} ${D_SRC_F:SRC} ${D_TGT_F:tgt.outputs[0].bldpath()}'
21 class d_header(Task
.Task
):
24 run_str
= '${D} ${D_HEADER} ${SRC}'
26 class dprogram(link_task
):
27 "Link object files into a d program"
28 run_str
= '${D_LINKER} ${LINKFLAGS} ${DLNK_SRC_F}${SRC} ${DLNK_TGT_F:TGT} ${RPATH_ST:RPATH} ${DSTLIB_MARKER} ${DSTLIBPATH_ST:STLIBPATH} ${DSTLIB_ST:STLIB} ${DSHLIB_MARKER} ${DLIBPATH_ST:LIBPATH} ${DSHLIB_ST:LIB}'
31 class dshlib(dprogram
):
32 "Link object files into a d shared library"
35 class dstlib(stlink_task
):
36 "Link object files into a d static library"
39 @extension('.d', '.di', '.D')
40 def d_hook(self
, node
):
42 Compile *D* files. To get .di files as well as .o files, set the following::
45 bld.program(source='foo.d', target='app', generate_headers=True)
48 ext
= Utils
.destos_to_binfmt(self
.env
.DEST_OS
) == 'pe' and 'obj' or 'o'
49 out
= '%s.%d.%s' % (node
.name
, self
.idx
, ext
)
50 def create_compiled_task(self
, name
, node
):
51 task
= self
.create_task(name
, node
, node
.parent
.find_or_declare(out
))
53 self
.compiled_tasks
.append(task
)
54 except AttributeError:
55 self
.compiled_tasks
= [task
]
58 if getattr(self
, 'generate_headers', None):
59 tsk
= create_compiled_task(self
, 'd_with_header', node
)
60 tsk
.outputs
.append(node
.change_ext(self
.env
.DHEADER_ext
))
62 tsk
= create_compiled_task(self
, 'd', node
)
66 def generate_header(self
, filename
):
68 See feature request #104::
71 tg = bld.program(source='foo.d', target='app')
72 tg.generate_header('blah.d')
74 #tg = bld.program(source='foo.d', target='app', header_lst='blah.d')
76 :param filename: header to create
77 :type filename: string
80 self
.header_lst
.append([filename
, self
.install_path
])
81 except AttributeError:
82 self
.header_lst
= [[filename
, self
.install_path
]]
85 def process_header(self
):
87 Process the attribute 'header_lst' to create the d header compilation tasks::
90 bld.program(source='foo.d', target='app', header_lst='blah.d')
92 for i
in getattr(self
, 'header_lst', []):
93 node
= self
.path
.find_resource(i
[0])
95 raise Errors
.WafError('file %r not found on d obj' % i
[0])
96 self
.create_task('d_header', node
, node
.change_ext('.di'))