我想使用SCons在以下步骤中编译文件:
.c - > .asm(程序集文件) - >的.o
我试图为此定义不同的构建器。
我设法做了类似的事情:.asm - > .o和.c - > .o
我不知道如何让SCons知道从.c文件生成的.asm文件,然后使用对象构建器。
是否有可能为此使用当前的SCons实现?
编辑:这就是我的尝试:
- >要定义两个构建器:构建器1(c_to_asm)旨在执行.c - > .asm步骤 Builder 2(asm_to_o)旨在执行.asm - > .o。在为我的SConscript中定义的所有文件执行这两个构建器后,我希望程序构建器能够创建最终的可执行文件。
SCons.Tool.createProgBuilder(env)
c_to_asm = SCons.Builder.Builder(action = {},
emitter = {},
prefix = '',
suffix = '.asm',
src_builder = '',
source_scanner = '',
single_source = 1)
c_to_asm_action = SCons.Action.Action('c to asm command line', 'Executing .c to .asm builder')
c_to_asm.add_action('.c', c_to_asm_action)
asm_to_o = SCons.Builder.Builder(action = {},
emitter = {},
prefix = '',
suffix = '.o',
src_builder = ['CTOASM'],
source_scanner = '',
single_source = 1)
asm_to_o_action = SCons.Action.Action('asm to o command line', 'Executing .asm to .o builder...')
asm_to_o.add_action('.asm', asm_to_o_action)
env['BUILDERS']['CTOASM'] = c_to_asm
env['BUILDERS']['Object'] = asm_to_o
我看到每个构建器的执行字符串,但没有执行任何命令。
我不知道如何确定这些构建器执行操作的顺序以及如何触发此构建器。
答案 0 :(得分:1)
你的方法有点复杂。从头到尾我会尝试这样的事情(未经测试,但希望能给你一个继续的方向):
import SCons.Action
import SCons.Builder
# Automatically inits "nasm" Tool, if it is in the $PATH
env = Environment()
c_to_asm_action = SCons.Action.Action('c to asm command line', 'Executing .c to .asm builder')
c_to_asm = SCons.Builder.Builder(action = c_to_asm_action,
suffix = '.asm',
single_source = 1)
env['BUILDERS']['CTOASM'] = c_to_asm
# Creates first.asm and second.asm
env.CTOASM(['first.c', 'second.c'])
# Compiles final program, finds the newly created ASM files via Glob
env.Program('foo', Glob('*.asm') + list_of_your_other_sources_and_libs)