makefile - 如何从变量中排除文件扩展名后缀
makefile - how to exclude file extension suffix from a variable
下一个 makefile 从其命令行 arg -ARGS 接收要编译的文件。例如
制作 ARGS="out.c"
我想用变量 ARGS 替换创建的可执行文件的名称 "run" 不包括后缀
在这个例子中:运行="out"
all: Task1
Task1: outputs/output.o
gcc -g -m32 -Wall -o run outputs/output.o
outputs/output.o: outputs/${ARGS}
gcc -m32 -g -w -Wall -ansi -c -o outputs/output.o outputs/${ARGS}
.PHONY: clean
run: clean Task1
clean:
rm -f outputs\output.o Task1
如果使用GNU make you need the basename函数,可能会变成$(basename $(AUX))
。也许像 $(*F)
这样的变量也可能有用(请阅读文档)。但是,您的 Makefile
可能是错误的。
我不能提出改进建议,因为你想做什么和发生什么还不清楚。
顺便说一句,使用 remake(如 remake -x
)或至少 make --trace
(使用足够新的 GNU make 4.x)来理解什么 make
正在做以及为什么。
另外,你会发现几个 Makefile
-s 的例子:here & there
等等...不要忘记 make
有许多内置规则,您将通过 运行 make -p
获得它们
阅读 GNU make 的 documentation 和一些教程,以及 Makefile
-s 的一些示例,您不会浪费时间。
按照您的要求进行操作的粗略方法很简单:
EXEC := $(basename $(ARGS))
all: Task1
Task1: outputs/output.o
gcc -g -m32 -Wall -o $(EXEC) outputs/output.o
更好的方法是:
EXEC := $(basename $(ARGS))
all: $(EXEC)
$(EXEC): outputs/output.o
gcc -g -m32 -Wall -o $(EXEC) outputs/output.o
更好的是:
EXEC := $(basename $(ARGS))
all: $(EXEC)
$(EXEC): outputs/output.o
gcc -g -m32 -Wall -o $@ $^
下一个 makefile 从其命令行 arg -ARGS 接收要编译的文件。例如
制作 ARGS="out.c"
我想用变量 ARGS 替换创建的可执行文件的名称 "run" 不包括后缀
在这个例子中:运行="out"
all: Task1
Task1: outputs/output.o
gcc -g -m32 -Wall -o run outputs/output.o
outputs/output.o: outputs/${ARGS}
gcc -m32 -g -w -Wall -ansi -c -o outputs/output.o outputs/${ARGS}
.PHONY: clean
run: clean Task1
clean:
rm -f outputs\output.o Task1
如果使用GNU make you need the basename函数,可能会变成$(basename $(AUX))
。也许像 $(*F)
这样的变量也可能有用(请阅读文档)。但是,您的 Makefile
可能是错误的。
我不能提出改进建议,因为你想做什么和发生什么还不清楚。
顺便说一句,使用 remake(如 remake -x
)或至少 make --trace
(使用足够新的 GNU make 4.x)来理解什么 make
正在做以及为什么。
另外,你会发现几个 Makefile
-s 的例子:here & there
等等...不要忘记 make
有许多内置规则,您将通过 运行 make -p
阅读 GNU make 的 documentation 和一些教程,以及 Makefile
-s 的一些示例,您不会浪费时间。
按照您的要求进行操作的粗略方法很简单:
EXEC := $(basename $(ARGS))
all: Task1
Task1: outputs/output.o
gcc -g -m32 -Wall -o $(EXEC) outputs/output.o
更好的方法是:
EXEC := $(basename $(ARGS))
all: $(EXEC)
$(EXEC): outputs/output.o
gcc -g -m32 -Wall -o $(EXEC) outputs/output.o
更好的是:
EXEC := $(basename $(ARGS))
all: $(EXEC)
$(EXEC): outputs/output.o
gcc -g -m32 -Wall -o $@ $^