3 # Thomas Nagy, 2008-2018 (ita)
6 Assembly support, used by tools such as gas and nasm
8 To declare targets using assembly::
15 features='c cstlib asm',
20 features='asm asmprogram',
24 Support for pure asm programs and libraries should also work::
28 conf.find_program('ld', 'ASLINK')
32 features='asm asmprogram',
38 from waflib
import Errors
, Logs
, Task
39 from waflib
.Tools
.ccroot
import link_task
, stlink_task
40 from waflib
.TaskGen
import extension
41 from waflib
.Tools
import c_preproc
43 re_lines
= re
.compile(
44 '^[ \t]*(?:%)[ \t]*(ifdef|ifndef|if|else|elif|endif|include|import|define|undef)[ \t]*(.*)\r*$',
45 re
.IGNORECASE | re
.MULTILINE
)
47 class asm_parser(c_preproc
.c_parser
):
48 def filter_comments(self
, node
):
50 code
= c_preproc
.re_nl
.sub('', code
)
51 code
= c_preproc
.re_cpp
.sub(c_preproc
.repl
, code
)
52 return re_lines
.findall(code
)
56 Compiles asm files by gas/nasm/yasm/...
59 run_str
= '${AS} ${ASFLAGS} ${ASMPATH_ST:INCPATHS} ${ASMDEFINES_ST:DEFINES} ${AS_SRC_F}${SRC} ${AS_TGT_F}${TGT}'
62 if self
.env
.ASM_NAME
== 'gas':
63 return c_preproc
.scan(self
)
64 elif self
.env
.ASM_NAME
== 'nasm':
65 Logs
.warn('The Nasm dependency scanner is incomplete!')
68 incn
= self
.generator
.includes_nodes
69 except AttributeError:
70 raise Errors
.WafError('%r is missing the "asm" feature' % self
.generator
)
72 if c_preproc
.go_absolute
:
75 nodepaths
= [x
for x
in incn
if x
.is_child_of(x
.ctx
.srcnode
) or x
.is_child_of(x
.ctx
.bldnode
)]
77 tmp
= asm_parser(nodepaths
)
78 tmp
.start(self
.inputs
[0], self
.env
)
79 return (tmp
.nodes
, tmp
.names
)
81 @extension('.s', '.S', '.asm', '.ASM', '.spp', '.SPP')
82 def asm_hook(self
, node
):
84 Binds the asm extension to the asm task
86 :param node: input file
87 :type node: :py:class:`waflib.Node.Node`
89 return self
.create_compiled_task('asm', node
)
91 class asmprogram(link_task
):
92 "Links object files into a c program"
93 run_str
= '${ASLINK} ${ASLINKFLAGS} ${ASLNK_TGT_F}${TGT} ${ASLNK_SRC_F}${SRC}'
97 class asmshlib(asmprogram
):
98 "Links object files into a c shared library"
101 class asmstlib(stlink_task
):
102 "Links object files into a c static library"
106 conf
.env
.ASMPATH_ST
= '-I%s'
107 conf
.env
.ASMDEFINES_ST
= '-D%s'