首页 > 解决方案 > 使文件变量为空

问题描述

在这里,我试图从看起来像这样的 makefile 构建一个目标。

VER := 13.1-9.6
V1 = $(word 1,$(subst -, ,$(VER)))
V2 = $(word 2,$(subst -, ,$(VER)))
hello:
    cp ./path/file.txt ./path/file_$(V1).txt;
    cp ./path/file.txt ./path/file_$(V2).txt;

在这里,只想将“13.1-9.6”拆分为“13.1”和“9.6”,最后创建两个文件。

但得到以下输出

cp ./path/file.txt ./path/file_.txt;
cp ./path/file.txt ./path/file_.txt;

这里有什么问题,为什么变量是空的?

我在 Freebsd 11.4-RELEASE

的输出gmake -v

GNU Make 4.2.1
Built for amd64-portbld-freebsd11.3
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

标签: makefilegnu-make

解决方案


我无法重现这个,所以我不知道发生了什么。也许 FreeBSD 的人对 GNU make 应用了一些本地补丁来修改它的行为,或者你在你的设置中做了一些不同的事情。

$ make --version
GNU Make 4.2.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

~$ cat Makefile
VER := 13.1-9.6
V1 = $(word 1,$(subst -, ,$(VER)))
V2 = $(word 2,$(subst -, ,$(VER)))
hello:
        : cp ./path/file.txt ./path/file_$(V1).txt;
        : cp ./path/file.txt ./path/file_$(V2).txt;

~$ make
: cp ./path/file.txt ./path/file_13.1.txt;
: cp ./path/file.txt ./path/file_9.6.txt;

推荐阅读