Make

From Freephile Wiki
Jump to navigation Jump to search
Text-x-makefile.svg

Intro[edit | edit source]

Make is a utility that is traditionally used in compiling your software. Makefiles are recipes for performing the tasks necessary, including calling the compiler on your source. Recently there have been a number of tools such as Grunt or Gulp used within the node.js community. As pointed out on the node.js page, the venerable make can be used just as effectively without having to learn and depend on a whole new tool for a "Task Runner".

Gnu Make[edit | edit source]

The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them. The manual describes the GNU implementation of make, which was written by Richard Stallman and Roland McGrath, and is currently maintained by Paul Smith. Our examples show C programs, since they are most common, but you can use make with any programming language whose compiler can be run with a shell command. In fact, make is not limited to programs. You can use it to describe any task where some files must be updated automatically from others whenever the others change.

To prepare to use make, you must write a file called the makefile that describes the relationships among files in your program, and the states the commands for updating each file. In a program, typically the executable file is updated from object files, which are in turn made by compiling source files.

Once a suitable makefile exists, each time you change some source files, this simple shell command:

     make

suffices to perform all necessary recompilations. The make program uses the makefile data base and the last-modification times of the files to decide which of the files need to be updated. For each of those files, it issues the commands recorded in the data base.

make executes commands in the makefile to update one or more target names, where name is typically a program. If no -f option is present, make will look for the makefiles GNUmakefile, makefile, and Makefile, in that order.

Normally you should call your makefile either makefile or Makefile. (We recommend Makefile because it appears prominently near the beginning of a directory listing, right near other important files such as README.) The first name checked, GNUmakefile, is not recommended for most makefiles. You should use this name if you have a makefile that is specific to GNU make, and will not be understood by other versions of make. If makefile is `-', the standard input is read.

make updates a target if it depends on prerequisite files that have been modified since the target was last modified, or if the target does not exist.

Targets[edit | edit source]

  • 'all' is the default target
  • 'clean' is the target defined to get rid of all the object files and executables

Example Makefile[edit | edit source]

Learning Make[edit | edit source]

Of course you should read the fine manual. man make Tutorial