你可以看到尽管 make 命令不会编译任何文件,然而 make -B 会强制编译所有的目标文件以及最终的执行文件。
3. 使用 -d 选项打印调试信息
如果你想知道 make 执行时实际做了什么,使用 -d 选项。
这是一个例子:
$ make -d | more GNU Make 3.81 Copyright (C) 2006 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. This program built for x86_64-pc-linux-gnu Reading makefiles… Reading makefile `Makefile'… Updating makefiles…. Considering target file `Makefile'. Looking for an implicit rule for `Makefile'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.o'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.c'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cc'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.C'. Trying pattern rule with stem `Makefile'. Trying implicit prerequisite `Makefile.cpp'. Trying pattern rule with stem `Makefile'. --More--
这是很长的输出,你也看到我使用了 more 命令来一页一页显示输出。
4. 使用 -C 选项改变目录
你可以为 make 命令提供不同的目录路径,在寻找 Makefile 之前会切换目录的。
这是一个目录,假设你就在当前目录下:
$ ls file file2 frnd frnd1.cpp log1.txt log3.txt log5.txt file1 file name with spaces frnd1 frnd.cpp log2.txt log4.txt
但是你想运行的 make 命令的 Makefile 文件保存在 ../make-dir/ 目录下,你可以这样做:
$ make -C ../make-dir/ make: Entering directory `/home/himanshu/practice/make-dir' make: Nothing to be done for `all'. make: Leaving directory `/home/himanshu/practice/make-dir
你能看到 make 命令首先切到特定的目录下,在那执行,然后再切换回来。
5. 通过 -f 选项将其它文件看作 Makefile
如果你想将重命名 Makefile 文件,比如取名为 my_makefile 或者其它的名字,我们想让 make 将它也当成 Makefile,可以使用 -f 选项。
make -f my_makefile
通过这种方法,make 命令会选择扫描 my_makefile 来代替 Makefile。
以上就是本文的详细内容,希望对大家的学习有所帮助。








