make is a utility to manage
pojects—programs, libraries, articles, reports, web-sites, and
others—where files must be manipulated according to certain rules.
When make is run, it reads the description of the project
from a makefile and then automatically updates the project,
if necessary, according to the rules in the makefile.
Makefile or makefile. If the makefile is called
SomethingElse then the make utility must be called as
make -f SomethingElse.
A makefile consists of macro definitions and rules. It resembles a cookbook.
CSFLAGS = -optimize+ -platform:armThe macro can then be called as
$(CSFLAGS) and will return
the string -optimize+ -platform:arm.
dish : ingredients
⊣recipe
where the sign ⊣ denotes the (mostly invisible,
unfortunately) tabulator-sign. Yes, by default a recipie starts with the
tabulator-sign. This aspect has been a subject of critisism, so in the
GNU-make version 3.82+ one can change the default tabulator-sign to any
other sign—for example a semicolon ;—by defining a macro
.RECIPEPREFIX := ;.
The rule is interpreted like the following:
The GNU-make manual uses a somewhat different notation,
target : prerequisites
⊣recipe
If the recipie consists of one command only, it can be writte in the same line as the target,
target : prerequisites ; recipe
By default 'make' only builds the first target it finds in the makefile. Therefore if more than one targets must be built one makes a "phoney" target that depends on the targets that must be built by default,
.PHONEY: default default : target1 target2 target3
Suppose we have a project to create a file out.txt with
the text "hello world" using a 'hello world' C#-program wholly contained
in the file "hello.cs".
The makefile for the project could look like this,
out.txt : hello.exe # out.txt depends on bytecode executable hello.exeComments start with the hash-sign,⊣mono hello.exe > out.txt # run hello.exe in mono, redirect output into out.txt hello.exe : hello.cs # bytecode hello.exe depends on source-code hello.cs⊣mcs -out:hello.exe hello.cs # compile hello.cs, output goes to hello.exe .PHONEY:clean # clean is a phoney target clean: # does not depend on anything⊣rm --force out.txt hello.exe # remove the files produced by making
#.