Makefiles(5) UNIX Programmer's Manual Makefiles(5)
NAME
Makefiles - Contents of ODE Makefiles.
SYNTAX
./Makefile
DESCRIPTION
ODE uses makefiles in its build environment, and, for the
most part, they are standard UNIX files. However there are
three exceptions to this: 1) The user Makefiles in ODE con-
tain lists of files to work on but almost none of the rules
to do the work. Instead, they include common makefiles
which contain the rules. 2) ODE Makefiles use VPATH, a
mechanism for specifying alternate location to search for
files which are not found where expected. 3) The common
makefiles support a syntax which allows a particular flag,
for example OPT_LEVEL, to be made more specific by adding
the name of the file to the target, for example
myfile_OPT_LEVEL.
This manual page describes these exceptions and how they are
used, then gives a brief description of each common makefile
and when it needs to be included. Finally, the manual page
lists and describes the variables which the user can access
to manipulate his build environment.
A user's Makefile can look nearly empty to someone unfami-
liar with ODE Makefiles. For example, the entire Makefile
for fsck is six lines; three lines defining variables:
PROGRAMS = fsck
ILIST = fsck
IDIR = /usr/sbin/
and three lines including the common makefiles standard.mk,
programs.mk, and objects.mk.
From this small bit of information, however, ODE knows how
to build fsck because the rules in programs.mk indicate for
each file defined in PROGRAMS there will be a .c file which
must be turned into a .o file. programs.mk also provides
the rule for doing this, and the rules for taking an object
file and turning it into an executable.
Other information is gathered from the variables as well.
For example, the only file to be installed is fsck, and it
is to reside in /usr/sbin. The owner, group, and mode are
not listed so the defaults listed in standard.mk will be
used.
The fact that some variables are not present provides addi-
tional information. Since SUBDIRS is not defined, there are
no sub-directories to fsck. Similarly, since no export list
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 1
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
exists, there are no headers or libraries to be exported.
Once familiar with the variables ODE uses in its Makefiles
(described below), most of what the user wants to know about
how the contents of the directory are built can be easily
understood. On those occasions when it is important to
understand the exact nature of the rules behind the vari-
ables, the user will need to look at a copy of the common
makefiles. While looking at these makefiles, the user will
see the following syntax frequently:
IMODE=${IMODE?${IMODE}:755}
While confusing at first, this is a relatively straight for-
ward use of the C conditional expression syntax, value ?
exp1 : exp2, where the first expression is evaluated if
value is non-zero, otherwise expression 2 is. In this exam-
ple, IMODE, the modes to give the file at installation time,
is set equal to the value of IMODE if it is already set,
otherwise it sets it to 755. This convention is used to
give IMODE a default if it is not already set. The extra
'$' and curly braces are to make sure the expression is
evaluated at the right time otherwise IMODE would be set to
the literal IMODE.
A more complex example of the same type of syntax which uses
optional specific filenames is EXPDIR. This variable indi-
cates which directory a file will be exported into. It can
be set for a particular file:
file_EXPDIR = /usr/include/sys
for the entire Makefile:
EXPDIR = /usr/include/sdm
or it defaults to the value of IDIR if not set at all. The
definition for this variable found in standard.mk is:
_EXPDIR_=${%_EXPDIR?${%_EXPDIR}:${EXPDIR?${EXPDIR}:${%_IDIR?${%_IDIR}:${IDIR}}}}
_EXPDIR_, the final value of EXPDIR, is determined first by
testing whether %_EXPDIR has been set, where % is a pattern
matching, special character understood by the OSF/1 version
of make. It enables the build process to support the
file_TARGET syntax. If %_EXPDIR has been set, _EXPDIR_ gets
this value. If not, the variable EXPDIR, without a specific
file tag, is tested. Again, if that variable has a value,
_EXPDIR_ is set to it. Finally, if EXPDIR is not set, the
variable %_IDIR is tested and used if set. If not, the
value of IDIR becomes the default value of _EXPDIR_.
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 2
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
The rules themselves are almost always in a generic form.
Thus the rule to turn .c files into .o files as found in
programs.mk is:
${_PROGRAM_C_O_}:
${_CC_} -c ${_CCFLAGS_} $*.c
where ${_PROGRAM_C_O_}: invariably translates to:
.c.o:
Common Makefiles
Most rules applied to targets, for example how to make a
binary from a .c file, are in the common makefiles instead
of the user Makefiles. This has the advantage of being able
to change a rule in one place and have the results pro-
pagated to the entire build.
To get this capability, the user needs to include the
appropriate common makefiles in his Makefile. Rather than
having all possible rules in a single common makefile, they
have been divided up into logical units so the user can more
easily locate and modify the rules.
The statements in the user's Makefiles which include the
common makefiles must appear after the variable definitions,
for example, after 'PROGRAMS= awk sed grep', and before any
target lines, such as 'awk: awk.c awk.h'.
The common makefiles are found in the source directory
/usr/lib/makefiles and are accessed from the user's
Makefiles with a line like:
include ${MAKEFILEPATH}/standard.mk
MAKEFILEPATH is defined in the user's sandbox rc files and
normally has the value:
${MAKETOP}/usr/lib/makefiles
The value of MAKETOP is determined by the program make at
run time and changes depending on the location of the
Makefile in the source tree.
The following is the list of common makefiles available to
the user:
standard.mk
This is the common makefile which provides the rules
needed by all the more specific common makefiles.
Every user Makefile must contain the line:
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 3
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
include ${MAKEFILEPATH}/standard.mk
Among other general definitions, standard.mk defines
build_all as the default target; it sets the defaults
for variables not explicitly defined; it sets the C
compiler variations, the optimization level, and the
flags defined from the command line arguments, the
Makefiles, and the environment. It also includes
definitions for variables like YACC, CC, etc.
standard.mk defines the common targets including: all,
build, tags, lint, clean, rmtarget, clobber, tags,
export, and install. Finally, standard.mk includes the
common makefile passes.mk, the makefile which enables
each of the common targets listed above to descend the
portion of the source tree necessary to complete its
tasks.
passes.mk
passes.mk implements the multi-pass approach to build-
ing OSF/1. At this time, there are three passes for
completing an entire build: one to export headers, a
second to export libraries and crt0, and the final pass
to do the remaining compilation.
Any pass may visit some or all of the tree. In the
current arrangement, the first two passes only search
in selected areas for header files and libraries to
export; the third pass traverses the entire tree.
Other calls, such as clean and install, use the mechan-
ism set up for the compilation pass, as they too
traverse the entire tree. These, however, are indepen-
dent calls to build and are therefore separate passes.
subdirs.mk
subdirs.mk contains the rules and make variables for
calling make in each of the subdirectories. This
makefile must be included in all Makefiles which call
sub-directories. It provides the support for all of
the SUBDIRS variables including EXPINC_SUBDIRS and
EXPLIB_SUBDIRS.
programs.mk
programs.mk contains the rules for constructing execut-
able programs, any object that has a compile/link
cycle. In particular, the variables PROGRAMS and LIBS
are evaluated in this makefile. Makefiles which con-
struct programs (gcc, awk, ld, ...) need to include
this common makefile. Makefiles which construct only
shell scripts or data files do not need to include
programs.mk, however, they do need to include
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 4
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
scripts.mk or datafiles.mk.
If any of the targets in the user's Makefile require
OFILES, that Makefile needs to include objects.mk.
libs.mk
libs.mk contains the rules and variables for construct-
ing libraries. In particular, the variable LIBRARIES
is evaluate in this makefile.
If any of the targets in the user's Makefile require
OFILES, that Makefile needs to include objects.mk.
User Makefiles which construct libraries need to
include libs.mk.
objects.mk
objects.mk provides the rules and variables for con-
structing object files. The .c.o rule is actually con-
tained in programs.mk and libs.mk as these types of
builds have different needs, but the rules to build
lex, yacc, and Pascal are in objects.mk.
Another significant part of this common makefile is
that it sets the final value of OFILES for building,
cleaning, linting, and using tags.
scripts.mk
scripts.mk contains the rules for building sh and csh
scripts. These rules involve passing the scripts
listed in the variable SCRIPTS through sed to remove
all comment lines.
datafiles.mk
datafiles.mk contains the rule and variables for con-
structing those data files which are shipped. These
include printcap, rc, /usr/lib/units, and all of
/usr/include. The rule for building datafiles involves
passing the files listed in the variable DATAFILES
through sed to remove all comment lines. Examples of
such datafiles include: /usr/include/stdio.h,
/etc/passwd, /etc/inetd.conf, and /usr/lib/whatis.
manpages.mk
manpages.mk contains the rules and variables for con-
structing man pages using the various formatting tools
such as nroff and troff. It particular the variables
MANSECTION and NROFFFLAGS are evaluated in this
makefile. This makefile builds man pages by running
them through "nroff -man -h" and placing the output
into the object tree. Regardless of what number suffix
the man page has, the output is numbered 0. For exam-
ple, the original man page for grep is grep.1; the
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 5
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
output will be called grep.0.
depend.mk
This common makefile is not complete yet. When it is,
it will contain generic rules for handling dependen-
cies.
others.mk
This common makefile contains the rules and variables
for constructing things that don't warrant their own
common makefile. Typically, these are targets that use
user-provided rules.
rules.mk
This common makefile contains lines including all the
other common makefiles. It can be used to include all
the common makefiles at once instead of individually.
VARIABLES
This section discusses the uses of the most common variables
found in the ODE Makefiles. Descriptions of these variables
are also included in the template makefile, template.mk, in
the source directory /usr/lib/makefiles. The template file
contains examples of their use and a section which the
developer can use it to begin a new Makefile.
Most of these variables can be used in two forms, as is and
with the name of file in front, for example, LIBS can be set
for all the PROGRAMS in the Makefile with a line like:
LIBS = -lplot -lm
or for just one file by using:
file_LIBS = -lplot -lm
SUBDIRS
This variable lists the sub-directories to descend
into. Typically, the list would not include machine-
dependent directories.
EXPINC_SUBDIRS
This version of SUBDIRS lists the sub-directories to
descend for exporting include files.
EXPLIB_SUBDIRS
This version of SUBDIRS lists the sub-directories to
descend for exporting libraries.
VPATH
This variable provides additional paths in which to
search for files. It can be used to locate
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 6
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
dependencies not found in the current directory.
PROGRAMS
This variable lists the .c files which need to be
built. The variables PROGRAMS and LIBRARIES are mutu-
ally exclusive since they require different ".c.o"
rules.
LIBRARIES
This variable lists the libraries which need to be
built. The variables LIBRARIES and PROGRAMS are mutu-
ally exclusive since they require different ".c.o"
rules.
OBJECTS
This variable is used to specify additional objects
which need to be built for a program. OBJECTS is also
used to specify .o files that are to be released, for
example crt0.o.
SCRIPTS
SCRIPTS should be used to list the .sh and .csh scripts
to be built.
DATAFILES
This variable lists the regular files to be built
including headers.
OTHERS
This variable lists files to be built which do not fall
into another category.
MANPAGES
This variable lists the man pages to be built. It
should be set in all Makefiles that define MANSECTION.
The list of man pages should not contain the filename
suffix: for example, "MANPAGES=bci bcreate" instead of
"MANPAGES=bci.1 bcreate.1".
MSGHDRS
This variable lists all the message headers to be
built.
CATFILES
This variable lists all the catalog files to be built.
INCFLAGS
This variable specifies which directories should be
searched for header files by the ${CC} command. It
format is -I<path> -I<path>.
LIBFLAGS
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 7
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
This variable specifies which directories should be
searched for libraries by the ${CC} command. It format
is -L<path> -L<path>.
INCLUDES
This variable list the header files which should be
exported.
EXPINC_TARGETS
This variable list the header files which should be
exported and is used if INCLUDES is not set.
EXPLIB_TARGETS
This variable list the libraries which should be
exported and is used if LIBRARIES is not set.
EXPDIR
This variable indicates which directory to export the
files into. If it is not set, the value of IDIR is
used.
ILIST
This variable lists the files to install.
IDIR This variable indicates which directory to install the
files into.
IOWNER
This variable indicates the owner of the files
installed. It defaults to bin.
IGROUP
This variable indicates the group of the files
installed. It defaults to bin.
IMODE
This variable indicates the modes of the files
installed. It defaults to 755.
ILINKS
This variable indicates any links which should be
created to the files installed. If the Makefile
installs more than a single file, this variable would
have to be used in the file_ILINKS format.
OPT_LEVEL
This variable is used to determine optimization and
debugging level. It default to -O. The value of this
variable is passed to both the compiler and loader.
CC_OPT_LEVEL
This variable is used to set the optimization level for
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 8
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
the compiler only.
CFLAGS
This variable sets the flags to be passed to the C com-
piler.
YFLAGS
This variable sets the flags to be passed to yacc.
LDFLAGS
This variable sets the flags to be passed to ld.
LINTFLAGS
This variable sets the flags to be passed to lint.
SED_OPTIONS
This variable is used to add sed patterns to the rules
for building scripts and datafiles.
CCTYPE
This variable is used to change the compiler type from
the default ansi. Legal values are writable_strings,
host, and traditional.
HFILES
This variable lists the header files all the object
files in the Makefile depend upon.
LIBS This variable specifies any libraries that the program
should be linked with.
OFILES
This variable specifies the object files for programs
and libraries. If not specified, the name of the pro-
gram or library will be used with .o appended.
GARBAGE
This variable lists the files which are created during
the build process which should be removed after com-
pleting the build.
LINTFILES
This variable lists the files to lint. If not speci-
fied, the files listed in OFILES will be used.
CLEANFILES
This variable lists the files to be removed when the
clean rule is invoked. If not specified, the
objectfiles, and GARBAGE files will be removed.
Additional Variables
These variables are used in the build environment but not
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 9
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
are not always found in Makefiles or are not as common as
those listed above.
ALWAYS
This variable is used for dependencies for rules which
must always be executed. For example,
/usr/include/sys/Makefile has the line:
dir.h: ${ALWAYS}
which forces the file dir.h to always be built. ALWAYS
is defined in standard.mk.
INOBJECTDIR and INOBJECTDIR_OPTIONS
Specifies the sed options used when copying data files
into the object directory.
MAKEPATH
Sets the path used to invoke recursive makes.
MACHINE
This variable holds the machine type the build is run-
ning on. It is the same as the value returned from
/bin/machine.
MANSECTION
This variable should be set in all Makefiles with man
page targets. Its value should be a digit describing
the man page section for all the files.
NROFFFLAGS
This variable is used in manpages.mk to set flags for
nroff. If not defined in the Makefile, NROFFFLAGS
defaults to "-man -h."
Tables
Commands
The following commands are defined in standard.mk. In
almost all cases, the programs are defined as lower
case versions of the upper case name, for example
AR=ar. On occasion, another version of the program is
substituted as: MKCATDEFS=xmkcatdefs.
center; a a a a a. AR AS CC CHMOD CP
ECHO GENCAT GENPATH LD LINT
MAKEPATH MD MIG MKCATDEFS MV
PC RANLIB RELEASE RM SED
SORT TAGS TAR TOUCH TR XSTR YACC
Defaults
Each of the variables listed below has a default value
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 10
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
which will be used if the developer does not override
it. In most cases the user can override it for the
entire Makefile, for example "OPT_LEVEL=" to override
the default optimization, and on a file-by-file basis,
for example "file_OPT_LEVEL=-g" to turn on debugging
for one particular file.
center; cb cb a a. Variable Default = CCTYPE ansi
OPT_LEVEL -O ARCHIVE_FORMAT COFF DEF_LINTFLAGS -hc
IOWNER bin IGROUP bin IMODE 755 I18N_FLAG NLS
DEF_RMFLAGS -ef DEF_ARFLAGS cr DEF_TROFFFLAGS -mm
DEF_NROFFFLAGS -man -h
MACHINE DEPENDENCIES
machdep.mk
Whenever a user's Makefile needs to access a machine
dependent Makefile, that Makefile should be in a sub-
directory named for the machine type and called
machdep.mk, for example, PMAX/machdep.mk. The Makefile
should contain the lists of variables and any rules
which are specific to a particular machine. Generic
content should still be in the user's Makefile.
The machine dependent Makefile is included in the upper
level Makefile by using the following line:
include ${TARGET_MACHINE}/machdep.mk
TARGET_MACHINE
The TARGET_MACHINE variable is expanded into the name
of the target machine, machines like: PMAX, MMAX, and
I386. It is used to reference machine dependent com-
ponents of the system. For instance, a component
called 'mumble' may have two machine-INDEPENDENT
modules, foo and bar, and one machine DEPENDENT module,
baz and bam; one for each architecture. The Makefile
would have lines of the form:
MMAX_OFILES = bam
PMAX_OFILES = baz
OFILES = foo bar ${${TARGET_MACHINE}_OFILES}
If the component had one machine dependent module,
bazm, for each machine, the Makefile would look like:
${${TARGET_MACHINE}_OFILES} = bazm
OFILES = foo bar ${${TARGET_MACHINE}_OFILES}
SITE DEPENDENCIES
Site dependent parts of a makefile are handled by the SITE
variable and by including a site dependent makefile in the
application's Makefile. The developer needs to create a
file named Makefile-SITE where SITE is the name of the site.
This file contains the site specific dependencies, variable
definitions, etc.
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 11
Makefiles(5) UNIX Programmer's Manual Makefiles(5)
The developer also inserts the following line in the
application's Makefile before the standard include lines:
include Makefile-${SITE}
At OSF, the SITE variable is defined in the build's shared
rc file.
READ-ONLY VARIABLES
The following variables are Read Only in the sense that the
user should not change their values. The are set by the
appropriate tools: center; a a a.
ALWAYS MACHINE MAKETOP
SEE ALSO
make(1), build(1)
Printed 1/23/91 $Date: 90/10/07 21:59:20 $ 12