如何在我的Makefile中自动将".s"添加到目标? [英] How can I automatically add '.s' to a target in my Makefile?
问题描述
我有一个虚假的debug
和asm
目标. debug
通过更新变量CFLAGS
进行工作,然后编译常规目标,该目标使用这些新的CFLAGS
生成调试符号.这可以按预期工作.
I have a phony debug
and asm
target. debug
works by updating the variable CFLAGS
and then compiles the normal target, which uses these new CFLAGS
to produce debug symbols. This works as intended.
类似地,我想定义asm
目标并设置-S
开关,并将输出名称从file
更改为file.s
.但是,最后一部分不起作用,我得到:
Analogously I want to define the asm
target set the -S
switch and to change the output name from file
to file.s
. However, the last part does not work, and I get:
$ make asm -B
gcc -fmessage-length=0 -ansi -pedantic -Werror -Wall -Wextra -Wwrite-strings -Winit-self -Wcast-align -Wcast-qual -Wpointer-arith -Wstrict-aliasing -Wformat=2 -Wmissing-declarations -Wmissing-include-dirs -Wno-unused-parameter -Wuninitialized -Wold-style-definition -Wstrict-prototypes -Wmissing-prototypes -Wdouble-promotion -S -masm=intel file.c -o file
注意最后一部分[..] -S -masm=intel file.c -o file
具有额外的参数,但没有.s
扩展名.
notice the last part [..] -S -masm=intel file.c -o file
with the extra parameters but without the .s
extension.
我想念什么?
Makefile:
TARGET=file
SOURCE=*.c
HEADERS=*.h
TESTS=*.sh
PROJECT=$(TARGET) $(SOURCE) $(HEADERS) $(TESTS) Makefile
CC=gcc
CFLAGS=\
-ansi \
-pedantic \
-Wall \
# makefile-rules that don't produce files directly
.PHONY: default all debug asm
default: $(TARGET)
# Compile
$(TARGET): $(SOURCE) $(HEADERS) $(TESTS)
$(CC) $(CFLAGS) $< -o $@
debug: CFLAGS += -DDEBUG -ggdb
debug: $(TARGET)
asm: CFLAGS +=-S -masm=intel
asm: TARGET +=.s <------------------ THIS LINE !!!!!!
asm: $(TARGET)
推荐答案
您可以在规则中添加$(TARGET).s
目标,并在asm
中使用它:
You could just add a $(TARGET).s
target to the rule and use that in asm
:
$(TARGET) $(TARGET).s: $(SOURCE) $(HEADERS) $(TESTS)
$(CC) $(CFLAGS) $< -o $@
asm: CFLAGS += -S -masm=intel
asm: $(TARGET).s
这篇关于如何在我的Makefile中自动将".s"添加到目标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!