Whatcha' gonna make?
Make allows you to create, recreate, or update a file based on the existence and/or modification of one or more other files. The simplest way to understand make is to look at a programming example.
In C programming, a C source code file is created with vi or a similar editor. This file usually has the extension .c, so we'll start with a
program called hello.c. The source code is compiled into an object that usually has an .o extension, so in this case the object would be hello.o. The object
file is finally linked into a running program with no extension, which is called hello.
In terms of the make utility, the target hello.o depends upon hello.c, and the target hello depends upon hello.o.
A make file is a script-like file that describes this target/dependency relationship and also provides the commands needed to create or recreate one
target file from one or more other dependent files. The target, the dependency, and the command constitute a make rule. Sample make rules for this simple example are shown in the following listing.
hello.o : hello.c cc -c hello.c hello : hello.o cc hello.o -o hello
In the first rule, hello.o appears on a line followed by a colon and then hello.c. Note that the spaces around the colon are required. This is the make syntax used to indicate that hello.o depends on hello.c. Underneath that line is the command cc -c hello.c, which is the command to be executed if hello.o
needs to be created. The second rule is similar, stating that hello depends on hello.o and if hello is to be created, then the command cc hello.o -o hello will be used to create it.
The make utility uses a default make file that is named, appropriately enough, makefile or Makefile. If you place the lines shown above into a file named makefile, and then into a directory containing the source code hello.c, you can type the command:
make hello
and the hello program will be built. Typing the command a second time will cause a message indicating that the hello program is up to date, as in the following listing:
make hello 'hello' is up to date
What does "up to date" mean? It means that the modification date and timestamp on hello is greater than or equal to the modification date and timestamp
on all the files that hello depends on -- in this case hello.o and ultimately hello.c.
Whenever you run make, it creates an internal table of dependencies and then verifies the creation or modification date and timestamps and works out what
has to be created or recreated. This includes checking to see if a file doesn't exist at all. For example, the first time you run make hello, hello.o does not exist at all and is therefore considered out of date.
Sign up for ITworld's Daily newsletter
Follow ITworld on Twitter @IT_world
On Twitter now
Unix
Powered by Twitter
Esther Schindler
If the comments are ugly, the code is ugly
claird
SVG a graphics format for 21st century
pasmith
Take Chrome OS for a test spin
Sandra Henry-Stocker
Solaris Tip: Have Your Files Changed Since Installation?
jfruh
Android fragments vs. the iPhone monolith
mikelgan
What Gizmodo missed about the Pro WX Wireless USB disk drive
Sidekick: The Good News & the Bad News
Either way you look at it Microsoft Data Center management did not follow standards or best practices in this failure. In which case it makes me wonder more about the outsourcing of corporate data much less personal data.
- mburton325
Join the conversation here
Quick, practical advice for IT pros. Made fresh daily.
Want to cash in on your IT savvy? Send your tip to tips@itworld.com. If we post it, we'll send you a $25 Amazon e-gift card.













