【发布时间】:2017-01-15 14:05:41
【问题描述】:
我正在尝试编写一个生成程序集文件的 makefile (通过使用 -S 标志调用 gcc),然后修改生成的 s.-files 然后编译它。为了找到一种方法,我做了一个简短的样本 当我准确列出 .s-sourcefiles 的名称(main.s、mod1.s 等)时,makefile 可以正常工作。
objects = main.o mod1.o
assembly = main.s mod1.s
app : $(objects)
gcc -o app $(objects)
chmod +x app
%.s : %.c
gcc -S $<
# here some code will be called to modify
# the .s file for some experimental purpose ..
main.o : main.s
gcc -c main.s
mod1.o : mod1.s
gcc -c mod1.s
cleanobj :
rm app $(objects)
cleanass :
rm $(assembly)
cleanall : cleanobj cleanass
这按预期工作。 但是当我定义依赖时 更通用一点(“%.o : %.s”) 不再生成程序集 (.s) 文件:
objects = main.o mod1.o
assembly = main.s mod1.s
app : $(objects)
gcc -o app $(objects)
chmod +x app
%.s : %.c
gcc -S $<
# here some code will be called to modify
# the .s file for some experimental purpose ..
%.o : %.s
gcc -c $<
cleanobj :
rm app $(objects)
cleanass :
rm $(assembly)
cleanall : cleanobj cleanass
任何解释,即想法如何实施这些步骤?
【问题讨论】:
标签: gcc makefile compilation