# -*-python-*-
# vim: ts=4

import handlerbase, program

class AssemblerHandler(handlerbase.HandlerBase):
	def __init__(self):
		pass

	def extensions(self):
		return ['.s', '.S']

	def source(self, prog, base, ext):
		line = 'set '
		if prog.type == program.PTYPE_LTLIBRARY:
			line = line + "$(LIBTOOL) --mode=compile "

		line = line + "$(CCAS) "
		line += prog.handle_variable("CCASFLAGS")
		if prog.type == program.PTYPE_LTLIBRARY:
			line = line + "-o $@ "

		rulef = prog.amfile.rulef
		
		line = line + "-c `test -f $< || echo '%s'`$< ;\\" % rulef.source
		lines = [ "@$(V_ECHO) 'assembling %s'; \\" % (rulef.source + base + ext), line, '$(V_EXEC)']
		rulef.insertTarget(rulef.build + base + prog.objext,
						   rulef.source + base + ext,
						   lines)

		prog.amfile.translate_target(base + ext)
		prog.amfile.translate_target(base + prog.objext)
		
		rulef.add_define(prog.amfile.canon_subdir + "_" + prog.canon_name + "_nofinal_OBJECTS",
						 rulef.build + base + prog.objext)

register_handler(AssemblerHandler())
