GNU Make工具(一)简介

GNU Make是什么1

Make有很多版本,其中GNU Make是一个自由软件。这里介绍一下它。
GNU Make是一个控制计算机程序从代码源文件到可执行文件或其他非源文件生成过程的工具。
控制命令通过称为makefile的文件传递给make工具。makefile记录了如何生成可执行文件等命令。

Capabilities of Make

  • Make enables the end user to build and install your package without knowing the details of how that is done – because these details are recorded in the makefile that you supply.

  • Make figures out automatically which files it needs to update, based on which source files have changed. It also automatically determines the proper order for updating files, in case one non-source file depends on another non-source file.
    As a result, if you change a few source files and then run Make, it does not need to recompile all of your program. It updates only those non-source files that depend directly or indirectly on the source files that you changed.

  • Make is not limited to any particular language. For each non-source file in the program, the makefile specifies the shell commands to compute it. These shell commands can run a compiler to produce an object file, the linker to produce an executable, ar to update a library, or TeX or Makeinfo to format documentation.

  • Make is not limited to building a package. You can also use Make to control installing or deinstalling a package, generate tags tables for it, or anything else you want to do often enough to make it worth while writing down how to do it.

和shell脚本一样,make也提供了这样一个方案:
当一个操作序列需要被反复执行的时候,一个好的做法是将它记录下来,下一次自动运行即可。

Make 规则以及目标

A rule in the makefile tells Make how to execute a series of commands in order to build a target file from source files. It also specifies a list of dependencies of the target file. This list should include all files (whether source files or other targets) which are used as inputs to the commands in the rule.

Here is what a simple rule looks like:

target:   dependencies ...
          commands
          ...

target是make指定要更新(生成)的目标。
dependencies指定了目标的依赖文件,比如源文件、库文件或者其他target等。
commands即希望执行的命令。

这段话给出了make更新target文件的条件和顺序。总之,存在被依赖的文件比目标文件新的话,目标文件就会被更新。

Make uses the makefile to figure out which target files ought to be brought up to date, and then determines which of them actually need to be updated. If a target file is newer than all of its dependencies, then it is already up to date, and it does not need to be regenerated. The other target files do need to be updated, but in the right order: each target file must be regenerated before it is used in regenerating other targets.

GNU Make的小特性,可以忽略更新的文件,使得不重新编译工程。

GNU Make also has a few simple features that are very convenient. For example, the -o file option which says ``pretend that source file file has not changed, even though it has changed.’’ This is extremely useful when you add a new macro to a header file. Most versions of Make will assume they must therefore recompile all the source files that use the header file; but GNU Make gives you a way to avoid the recompilation, in the case where you know your change to the header file does not require it.

更多的帮助可以查看以下的地方:

$ info make
$ man make

by looking at /usr/share/doc/make/, /usr/local/doc/make/, or similar directories on your system.
A brief summary is available by running make --help.

GNU Make的manual可以访问这里


  1. https://www.gnu.org/software/make/ ↩︎

猜你喜欢

转载自blog.csdn.net/FJDJFKDJFKDJFKD/article/details/86479281
GNU