Predefined rules
By itself, make knows already that in order to create a .o
file, it must use cc -c on the corresponding .c file. These
rules are built into make, and you can take advantage of this to
shorten your
Makefile. If you just indicate just the .h files
in the dependency line of the Makefile that the current target is
dependent on, make will know that the corresponding .c file
is already required. You don't even need to include the command for the
compiler.
This reduces our Makefile further, as shown:
OBJECTS = data.o main.o io.o
project1: $(OBJECTS)
cc $(OBJECTS) -o project1
data.o: data.h
main.o: data.h io.h
io.o: io.h
One thing to consider, however, is that when you are compiling programs
on
Wiliki, you may wish to add a CFLAGS macro at the top
of your
Makefile to enable the compiler to use ANSI standard C compilation.
The macro looks like this:
CFLAGS=-Aa -D_HPUX_SOURCE
This will allow make to use ANSI C with the predefined rules.
PreviousNextIndex
Last updated on Wednesday, June 21, 1995 by
Ben
Y. Yoshino
Copyright © 1995 University of Hawai`i, College of Engineering,
Computer Facility
All rights reserved.