Simple and easy-to-understand Makefile entry (11) — summary of make command parameters and options, summary of special targets in make

1. Summary of make command parameters and options

In the execution makecommand, sometimes you need to add the following parameters option to ensure the implementation of our programs, such as

  • The parameters used only to print the command but not to execute are -n;
  • The parameter options for only executing the command without printing the command are -s;
  • The path parameter options that include other files are -include;

Lists about makewhat parameters you can use options and their functions yes.

Parameter options Features
-b,-m Ignore, provide compatibility with other versions of make
-B,–always-make Mandatory rebuild all rule targets, and does not decide whether to rebuild target files based on rule dependency descriptions.
-C DIR , –directory = DIR Before reading the Makefile, enter the directory DIR, and then execute make. When there are multiple "-C" options, the final working directory of make is the relative path of the first directory.
-d Make prints out all debugging information during the execution process, including those files that make thinks need to be rebuilt, those files that need to be compared with the last modification time, the result of the comparison, the commands used to rebuild the target, regret rules, and so on. Using the "-d" option, we can see all the information in the process of making the dependency chain and rebuilding the target.
–debug[=OPTIONS] Debugging information is output when make is executed. You can use "OPTIONS" to control the level of debugging information. The default is "OPTIONS=b", the possible values ​​of "OPTIONS" are the following, the first letter is valid: all, basic, verbose, implicit, jobs, makefile.
-e,–enveronment -overrides Use the environment variable definition to override the variable definition of the same name in the Makefile.
-f=FILE,–file=FILE,–makefile=FILE Specify the file "FILE" as the Makefile executed by make
-p,–help Print help information.
-i,–ignore-errors Ignore the error in the execution of the rule command during execution.
-I DIR , –include-dir = DIR Specify the search directory that contains the Makefile. When another "include" file appears in the Makefile, it will be searched under the "DIR" directory. When multiple "-i" specify directories, the directories are searched in the specified order.
-j [JOBS] , - jobs [= JOBS] You can specify the number of commands to be executed at the same time. Without "-j", the number of commands executed will be the maximum possible number allowed by the system. When there are multiple "-j" targets, the JOBS number specified by the last target is valid.
-k,–keep-going The execution of make is not terminated when a command error is executed. Make will execute all commands as much as possible until a well-known error occurs.
-l load,–load-average=[=LOAD],–max-load[=LOAD] Tell make when there are other tasks to execute, if the system load exceeds "LOAD", no new tasks will be started. If the parameter "-l" of "LOAD" is not specified, the restriction specified by "-l" will be cancelled.
-n,–just-print,–dry-run Only the executed commands are printed, but the commands are not executed.
-o FILE,–old-file=FILE,–assume-old=FILE The specified "FILE" file does not need to be rebuilt, even if its dependencies have expired; at the same time, any targets of this dependent file are not rebuilt. Note: This parameter will not be passed to the subdirectory process through the variable "MAKEFLAGS".
-p,–print-date-base Before the command is executed, print out all the data of the Makefile read by make, and print out the version information of make at the same time. If you only need to print these data information, you can use the "make -qp" command to view the preset rules and variables before make is executed. You can use the command "make -p -f /dev/null"
-q,-question It is called "question mode"; no commands are run and there is no output. make only returns a query status. Return status 0 means that there is no target to rebuild, return status 1 means there is a target that needs to be rebuilt, and return status 2 means an error has occurred.
-r,–no-builtin-rules Cancel all built-in function rules, but you can use pattern rules in Makefile to define rules. At the same time, the option "-r" will cancel the implicit suffix list of all suffix rules. Similarly, we can use ".SUFFIXES" in Makefile to define our suffix name rules. The "-r" option does not cancel the implicit variables embedded in make.
-R,–no-builtin-variabes Cancel the hidden variables embedded in make, but we can clearly define some variables in the Makefile. Note: "-R" and "-r" options are turned on at the same time, because there are no hidden variables, the implicit rules will lose their meaning.
-s,–silent,–quiet Cancel printing during command execution.
-S,–no-keep-going,–stop Cancel the "-k" option. During the recursive make process, the sub-make inherits the upper command line option through the "MAKEFLAGS" variable. We can use the "-S" option in the sub-make to cancel the "-k" option passed by the upper layer, or cancel the "-k" option in the system environment variable "MAKEFLAGS".
-t,–touch It has the same function as the touch command of Linux, updating the timestamp of all target files to the current system time. Prevent make from rebuilding all obsolete object files.
-v,version View the version information of make.
-w,–print-directory Print the working directory before make enters a subdirectory to read the Makefile. This option can help us debug the Makefile and track positioning errors. This option is turned on by default when using the "-C" option.
–no-print-directory Cancel the "-w" option. It can be used in the process of recursive make call to cancel the default "-w" function of the "-C" parameter.
-W FILE,–what-if=FILE,–new-file=FILE,–assume-file=FILE 设定文件 “FILE” 的时间戳为当前的时间,但不更改文件实际的最后修改时间。此选项主要是为了实现对所有依赖于文件 “FILE” 的目标的强制重建。
–warn-undefined-variables 在发现 Makefile 中存在没有定义的变量进行引用时给出告警信息。此功能可以帮助我们在调试一个存在多级嵌套变量引用的复杂 Makefile。但是建议在书写的时候尽量避免超过三级以上的变量嵌套引用。

2. 特殊的目标

名称 功能
.PHONY: 这个目标的所有依赖被作为伪目标。伪目标是这样一个目标:当使用 make 命令行指定此目标时,这个目标所在的规则定义的命令、无论目标文件是否存在都会被无条件执行。
.SUFFIXES: 这个目标的所有依赖指出了一系列在后缀规则中需要检查的后缀名
.DEFAULT: Makefile 中,这个特殊目标所在规则定义的命令,被用在重建那些没有具体规则的目标,就是说一个文件作为某个规则的依赖,却不是另外一个规则的目标时,make 程序无法找到重建此文件的规则,这种情况就执行 “.DEFAULT” 所指定的命令。
.PRECIOUS: 这个特殊目标所在的依赖文件在 make 的过程中会被特殊处理:当命令执行的过程中断时,make 不会删除它们。而且如果目标的依赖文件是中间过程文件,同样这些文件不会被删除。
.INTERMEDIATE: 这个特殊目标的依赖文件在 make 执行时被作为中间文件对待。没有任何依赖文件的这个目标没有意义。
.SECONDARY: 这个特殊目标的依赖文件被作为中过程的文件对待。但是这些文件不会被删除。这个目标没有任何依赖文件的含义是:将所有的文件视为中间文件。
.IGNORE 这个目标的依赖文件忽略创建这个文件所执行命令的错误,给此目标指定命令是没有意义的。当此目标没有依赖文件时,将忽略所有命令执行的错误。
.DELETE_ON_ERROR: 如果在 Makefile 中存在特殊的目标 “.DELETE_ON_ERROR” ,make 在执行过程中,荣国规则的命令执行错误,将删除已经被修改的目标文件。
.LOW_RESOLUTION_TIME: 这个目标的依赖文件被 make 认为是低分辨率时间戳文件,给这个目标指定命令是没有意义的。通常的目标都是高分辨率时间戳。
.SILENT: 出现在此目标 “.SILENT” 的依赖文件列表中的文件,make 在创建这些文件时,不打印出此文件所执行的命令。同样,给目标 “SILENT” 指定命令行是没有意义的。
.EXPORT_ALL_VARIABLES: 此目标应该作为一个简单的没有依赖的目标,它的功能是将之后的所有变量传递给子 make 进程。
.NOTPARALLEL: Makefile 中如果出现这个特殊目标,则所有的命令按照串行的方式执行,即使是存在 make 的命令行参数 “-j” 。但在递归调用的子make进程中,命令行可以并行执行。此目标不应该有依赖文件,所有出现的依赖文件将会被忽略。

Guess you like

Origin blog.csdn.net/wohu1104/article/details/111086037