如何在我的Makefile中自动将".s"添加到目标? [英] How can I automatically add '.s' to a target in my Makefile?

查看:83
本文介绍了如何在我的Makefile中自动将".s"添加到目标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个虚假的debugasm目标. 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆