GNU Make[转自GNU]

因明日开始Unix/Linux培训,故而从GNU网站转来这篇Make的Overview。之前在大学,关于体系架构,已经学的一点都不想听了却还是不能做Linux软件开发,所以,这次的培训,我的目标就只锁定在Linux下C/C++程序的编译、运行、安装包的制作。Java已经没有任何问题了,之前在RH上面就已经成功地做了安装虚拟机/编译器,写源程序,编译、运行这一套,也成功的部署了一个WAR文件到Tomcat里面去,所以,Linux上Java的开发,我认为我已经没有关键性问题了。

而寡人之痛,在于C++。

本文原文地址为:

http://www.gnu.org/software/make/

(本转载仅为个人参考之便捷而用、而立)

Simon Jo

 

GNU Make

 [image of the head of a GNU] (no gifs due to patent problems)

 


 

What Is GNU Make?

Make is a tool which controls the generation of executables and other non-source files of a program from the program's source files.

Make gets its knowledge of how to build your program from a file called the makefile, which lists each of the non-source files and how to compute it from other files. When you write a program, you should write a makefile for it, so that it is possible to use Make to build and install the program.

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.
Make Rules and Targets

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
          ...

When you run Make, you can specify particular targets to update; otherwise, Make updates the first target listed in the makefile. Of course, any other target files needed as input for generating these targets must be updated first.

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.

Advantages of GNU Make

GNU Make has many powerful features for use in makefiles, beyond what other Make versions have. It can also regenerate, use, and then delete intermediate files which need not be saved.

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.

However, the most important difference between GNU Make and most versions of Make is that GNU Make is free software.

About GNU Make

Full documentation for GNU make is found in the Make manual, which is included in the GNU Make distribution. You can also buy printed copies of the Make manual from the Free Software Foundation; the money we raise goes to fund free software development.

Alternatively you can browse the online documentation available at www.gnu.org/software/make/manual/

The GNU Make project page on Savannah contains information on the mailing lists, CVS access etc.

You can download GNU Make from the GNU FTP site ftp.gnu.org or one of its mirrors. You can also obtain it by buying the GNU Source Code CD-ROM from the Free Software Foundation; this too helps fund free software development.

You can report problems with GNU Make either through Savannah, or to the bug-make@gnu.org mailing list. You can ask for help writing makefiles or using GNU Make on the help-make@gnu.org mailing list.

GNU Make has been ported to a great many systems. One that poses unique challenges is Microsoft DOS and Windows platforms; because of that there is a GNU Make mailing list dedicated specifically to users of those platforms: make-w32@gnu.org.

All of the above mailing lists are open for posting by non-subscribers. However if you would like to subscribe, or view the archives of the mailing lists, visit the GNU Make mailing lists page on Savannah.

GNU Make was written by Richard Stallman and Roland McGrath. It has been maintained and updated by Paul Smith since version 3.76 (1997).

Makefiles And Conventions

We have developed conventions for how to write Makefiles, which all GNU packages ought to follow. It is a good idea to follow these conventions in your program even if you don't intend it to be GNU software, so that users will be able to build your package just like many other packages, and will not need to learn anything special before doing so.

These conventions are found in the chapter ``Makefile conventions'' (147 k characters) of the GNU Coding Standards (147 k characters).

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值