HP-UX Reference (11i v2 04/09) - 1 User Commands A-M (vol 1)

m
make(1) make(1)
Double suffix inference rules (
.c.o) define how to build x.o from x.c. Single suffix inference rules (
.c)
define how to build
x
from x.c. In effect, the first suffix is null. Single suffix rules are useful for building
targets from only one source file; e.g., shell procedures and simple C programs.
A tilde in the above rules refers to an SCCS file (see sccsfile(4)). Thus, the rule
.c˜.o would transform
an SCCS C source file into an object file (
.o). Since the s. of the SCCS files is a prefix, it is incompati-
ble with
make’s suffix point-of-view. Hence, the tilde is a way of changing any file reference into an
SCCS file reference.
A rule to create a file with suffix
.o from a file with suffix .c is specified as an entry with
.c.o as the
target and no dependents. Shell commands associated with the target define the rule for making a
.o file
from a
.c file. Any target name that has no slashes in it and starts with a dot is identified as an infer-
ence (implicit) rule instead of a target (explicit) rule. Targets with one dot are single suffix inference
rules; targets with two dots are double suffix inference rules. Users can, in a makefile, define additional
inference rules and either redefine or cancel default inference rules.
The default inference rule for changing a
.c file into a .o file might look like this:
.c.o:
$(CC) $(CFLAGS) -c $<
and the default inference rule for changing a
yacc file to a C object file might look like this:
.y.o:
$(YACC) $(YFLAGS) $<
$(CC) $(CFLAGS) -c y.tab.c
rm y.tab.c
mv y.tab.o $@
Certain macros are used in the default inference rules to permit the inclusion of optional matter in any
resulting commands. For example, CFLAGS, LDFLAGS, and YFLAGS are used for compiler options to
cc(1), lex(1), and yacc(1), respectively.
LDFLAGS is commonly used to designate linker/loader options.
These macros are automatically defined by
make but can be redefined by the user in the makefile.
The macro
LIBS is, by convention, used to specify the order of inclusion of any special libraries during
the linking phase of compilation. To specify a particular order of inclusion for a particular set of
libraries, the existing single suffix rule for a .c file,
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@
can be redefined as
$(CC) $(CFLAGS) $< $(LDFLAGS) -o $@ $(LIBS)
as well as defining LIBS in the makefile.
There are also some special built-in macros used in the inference rules (
@, <). See the Built-in Macros
subsection.
If a target does not have explicit dependents, or if a dependent does not also have a target that matches it
with associated explicit rules,
make looks for the first inference rule that matches both the target’s
(dependent’s) suffix (which may be null) and a file which matches the other suffix of the rule. Since it con-
ducts this search by going through the list of .SUFFIXES values front to back, the order in which .SUF-
FIXES is defined is significant.
To print out the rules compiled into the
make on any machine, type:
make -fp - 2>/dev/null </dev/null
Since make defines an inference rule .c.o, the example in the General Description subsection can be
rewritten more simply:
OBJS = a.o b.o
pgm: $(OBJS)
cc $(OBJS) -o pgm
$(OBJS): incl.h
Libraries
If a target or dependent name contains parentheses, it is assumed to be an archive library, the string
within parentheses referring to a member within the library. Thus lib(file.o) and
$(LIB)(file.o) both refer to an archive library that contains file.o (this assumes the LIB macro
has been previously defined). The expression $(LIB)(file1.o file2.o) is not valid. Rules
Section 1−−568 Hewlett-Packard Company − 6 − HP-UX 11i Version 2: September 2004