【发布时间】:2017-09-02 01:05:06
【问题描述】:
我编写了一个简单的 shell 脚本(称为 test.sh)来使用两个不同的编译器(g++ 和 clang++)编译一个测试 C++ 文件,并放入一些 echo 语句来比较输出。在命令行上,我不小心输入了make test,即使那个目录中没有 Makefile。它没有抱怨没有 Makefile 或没有定义目标,而是执行了以下命令(我的系统正在运行带有 GNU Make 4.1 的 64 位 Debian stretch 操作系统):
user@hostname test_dir$ make test
cat test.sh >test
chmod a+x test
user@hostname test_dir$
对此感到好奇,我制作了另一个 shell 脚本 (other.sh) 并做了同样的事情。
这是我的
other.sh文件:
#!/bin/bash
echo ""
echo "This is another test script!"
echo ""
命令行:
user@hostname test_dir$ make other
cat other.sh >other
chmod a+x other
user@hostname test_dir$
我的问题是为什么make 在终端中运行make 命令时会自动创建一个可执行脚本(没有.sh 扩展名)?这是正常/预期/标准行为吗?我可以在所有 Linux 机器上依赖这种行为吗?
附带问题/注意:是否有支持的“隐式后缀”列表,make 将自动为其创建可执行文件?
【问题讨论】:
-
如果你正在使用 gnu-make(你可能是),你可以运行
make -d other来查看它会尝试的所有后缀的详细列表。 -
来自我的信息页面:
The default suffix list is:.out'、.a',.ln'、.o',.c'、.cc',.C'、.cpp',.p'、@987654339 @.F'、.m',.r'、.y',.l'、.ym',.lm'、.s',.S'、.mod',.sym'、.def',.h'、.info',.dvi'、.tex',.texinfo'、.texi',.txinfo'、.w',.ch'、.web',.sh'、.elc',.el'。` -
谁认为反引号是一个可以放入文档的好字符!?