Blame make-stds.texi

Packit 1ca270
@comment This file is included by both standards.texi and make.texinfo.
Packit 1ca270
@comment It was broken out of standards.texi on 1/6/93 by roland.
Packit 1ca270
Packit 1ca270
@node Makefile Conventions
Packit 1ca270
@chapter Makefile Conventions
Packit 1ca270
@comment standards.texi does not print an index, but make.texinfo does.
Packit 1ca270
@cindex makefile, conventions for
Packit 1ca270
@cindex conventions for makefiles
Packit 1ca270
@cindex standards for makefiles
Packit 1ca270
Packit 1ca270
This
Packit 1ca270
@ifinfo
Packit 1ca270
node
Packit 1ca270
@end ifinfo
Packit 1ca270
@iftex
Packit 1ca270
@ifset CODESTD
Packit 1ca270
section
Packit 1ca270
@end ifset
Packit 1ca270
@ifclear CODESTD
Packit 1ca270
chapter
Packit 1ca270
@end ifclear
Packit 1ca270
@end iftex
Packit 1ca270
describes conventions for writing the Makefiles for GNU programs.
Packit 1ca270
Packit 1ca270
@menu
Packit 1ca270
* Makefile Basics::		General Conventions for Makefiles
Packit 1ca270
* Utilities in Makefiles::	Utilities in Makefiles
Packit 1ca270
* Command Variables::		Variables for Specifying Commands
Packit 1ca270
* Directory Variables::		Variables for Installation Directories
Packit 1ca270
* Standard Targets::		Standard Targets for Users
Packit 1ca270
* Install Command Categories::  Three categories of commands in the `install'
Packit 1ca270
                                  rule: normal, pre-install and post-install.
Packit 1ca270
@end menu
Packit 1ca270
Packit 1ca270
@node Makefile Basics
Packit 1ca270
@section General Conventions for Makefiles
Packit 1ca270
Packit 1ca270
Every Makefile should contain this line:
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
SHELL = /bin/sh
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
to avoid trouble on systems where the @code{SHELL} variable might be
Packit 1ca270
inherited from the environment.  (This is never a problem with GNU
Packit 1ca270
@code{make}.)
Packit 1ca270
Packit 1ca270
Different @code{make} programs have incompatible suffix lists and
Packit 1ca270
implicit rules, and this sometimes creates confusion or misbehavior.  So
Packit 1ca270
it is a good idea to set the suffix list explicitly using only the
Packit 1ca270
suffixes you need in the particular Makefile, like this:
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
.SUFFIXES:
Packit 1ca270
.SUFFIXES: .c .o
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
The first line clears out the suffix list, the second introduces all
Packit 1ca270
suffixes which may be subject to implicit rules in this Makefile.
Packit 1ca270
Packit 1ca270
Don't assume that @file{.} is in the path for command execution.  When
Packit 1ca270
you need to run programs that are a part of your package during the
Packit 1ca270
make, please make sure that it uses @file{./} if the program is built as
Packit 1ca270
part of the make or @file{$(srcdir)/} if the file is an unchanging part
Packit 1ca270
of the source code.  Without one of these prefixes, the current search
Packit 1ca270
path is used.
Packit 1ca270
Packit 1ca270
The distinction between @file{./} (the @dfn{build directory}) and
Packit 1ca270
@file{$(srcdir)/} (the @dfn{source directory}) is important because
Packit 1ca270
users can build in a separate directory using the @samp{--srcdir} option
Packit 1ca270
to @file{configure}.  A rule of the form:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
foo.1 : foo.man sedscript
Packit 1ca270
        sed -e sedscript foo.man > foo.1
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
will fail when the build directory is not the source directory, because
Packit 1ca270
@file{foo.man} and @file{sedscript} are in the the source directory.
Packit 1ca270
Packit 1ca270
When using GNU @code{make}, relying on @samp{VPATH} to find the source
Packit 1ca270
file will work in the case where there is a single dependency file,
Packit 1ca270
since the @code{make} automatic variable @samp{$<} will represent the
Packit 1ca270
source file wherever it is.  (Many versions of @code{make} set @samp{$<}
Packit 1ca270
only in implicit rules.)  A Makefile target like
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
foo.o : bar.c
Packit 1ca270
        $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
should instead be written as
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
foo.o : bar.c
Packit 1ca270
        $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@@
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
in order to allow @samp{VPATH} to work correctly.  When the target has
Packit 1ca270
multiple dependencies, using an explicit @samp{$(srcdir)} is the easiest
Packit 1ca270
way to make the rule work well.  For example, the target above for
Packit 1ca270
@file{foo.1} is best written as:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
foo.1 : foo.man sedscript
Packit 1ca270
        sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
GNU distributions usually contain some files which are not source
Packit 1ca270
files---for example, Info files, and the output from Autoconf, Automake,
Packit 1ca270
Bison or Flex.  Since these files normally appear in the source
Packit 1ca270
directory, they should always appear in the source directory, not in the
Packit 1ca270
build directory.  So Makefile rules to update them should put the
Packit 1ca270
updated files in the source directory.
Packit 1ca270
Packit 1ca270
However, if a file does not appear in the distribution, then the
Packit 1ca270
Makefile should not put it in the source directory, because building a
Packit 1ca270
program in ordinary circumstances should not modify the source directory
Packit 1ca270
in any way.
Packit 1ca270
Packit 1ca270
Try to make the build and installation targets, at least (and all their
Packit 1ca270
subtargets) work correctly with a parallel @code{make}.
Packit 1ca270
Packit 1ca270
@node Utilities in Makefiles
Packit 1ca270
@section Utilities in Makefiles
Packit 1ca270
Packit 1ca270
Write the Makefile commands (and any shell scripts, such as
Packit 1ca270
@code{configure}) to run in @code{sh}, not in @code{csh}.  Don't use any
Packit 1ca270
special features of @code{ksh} or @code{bash}.
Packit 1ca270
Packit 1ca270
The @code{configure} script and the Makefile rules for building and
Packit 1ca270
installation should not use any utilities directly except these:
Packit 1ca270
Packit 1ca270
@c dd find
Packit 1ca270
@c gunzip gzip md5sum
Packit 1ca270
@c mkfifo mknod tee uname 
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
cat cmp cp diff echo egrep expr false grep install-info
Packit 1ca270
ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
The compression program @code{gzip} can be used in the @code{dist} rule.
Packit 1ca270
Packit 1ca270
Stick to the generally supported options for these programs.  For
Packit 1ca270
example, don't use @samp{mkdir -p}, convenient as it may be, because
Packit 1ca270
most systems don't support it.
Packit 1ca270
Packit 1ca270
It is a good idea to avoid creating symbolic links in makefiles, since a
Packit 1ca270
few systems don't support them.
Packit 1ca270
Packit 1ca270
The Makefile rules for building and installation can also use compilers
Packit 1ca270
and related programs, but should do so via @code{make} variables so that the
Packit 1ca270
user can substitute alternatives.  Here are some of the programs we
Packit 1ca270
mean:
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
ar bison cc flex install ld ldconfig lex
Packit 1ca270
make makeinfo ranlib texi2dvi yacc
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
Use the following @code{make} variables to run those programs:
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
$(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
Packit 1ca270
$(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
When you use @code{ranlib} or @code{ldconfig}, you should make sure
Packit 1ca270
nothing bad happens if the system does not have the program in question.
Packit 1ca270
Arrange to ignore an error from that command, and print a message before
Packit 1ca270
the command to tell the user that failure of this command does not mean
Packit 1ca270
a problem.  (The Autoconf @samp{AC_PROG_RANLIB} macro can help with
Packit 1ca270
this.)
Packit 1ca270
Packit 1ca270
If you use symbolic links, you should implement a fallback for systems
Packit 1ca270
that don't have symbolic links.
Packit 1ca270
Packit 1ca270
Additional utilities that can be used via Make variables are:
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
chgrp chmod chown mknod
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
It is ok to use other utilities in Makefile portions (or scripts)
Packit 1ca270
intended only for particular systems where you know those utilities
Packit 1ca270
exist.
Packit 1ca270
Packit 1ca270
@node Command Variables
Packit 1ca270
@section Variables for Specifying Commands
Packit 1ca270
Packit 1ca270
Makefiles should provide variables for overriding certain commands, options,
Packit 1ca270
and so on.
Packit 1ca270
Packit 1ca270
In particular, you should run most utility programs via variables.
Packit 1ca270
Thus, if you use Bison, have a variable named @code{BISON} whose default
Packit 1ca270
value is set with @samp{BISON = bison}, and refer to it with
Packit 1ca270
@code{$(BISON)} whenever you need to use Bison.
Packit 1ca270
Packit 1ca270
File management utilities such as @code{ln}, @code{rm}, @code{mv}, and
Packit 1ca270
so on, need not be referred to through variables in this way, since users
Packit 1ca270
don't need to replace them with other programs.
Packit 1ca270
Packit 1ca270
Each program-name variable should come with an options variable that is
Packit 1ca270
used to supply options to the program.  Append @samp{FLAGS} to the
Packit 1ca270
program-name variable name to get the options variable name---for
Packit 1ca270
example, @code{BISONFLAGS}.  (The names @code{CFLAGS} for the C
Packit 1ca270
compiler, @code{YFLAGS} for yacc, and @code{LFLAGS} for lex, are
Packit 1ca270
exceptions to this rule, but we keep them because they are standard.)
Packit 1ca270
Use @code{CPPFLAGS} in any compilation command that runs the
Packit 1ca270
preprocessor, and use @code{LDFLAGS} in any compilation command that
Packit 1ca270
does linking as well as in any direct use of @code{ld}.
Packit 1ca270
Packit 1ca270
If there are C compiler options that @emph{must} be used for proper
Packit 1ca270
compilation of certain files, do not include them in @code{CFLAGS}.
Packit 1ca270
Users expect to be able to specify @code{CFLAGS} freely themselves.
Packit 1ca270
Instead, arrange to pass the necessary options to the C compiler
Packit 1ca270
independently of @code{CFLAGS}, by writing them explicitly in the
Packit 1ca270
compilation commands or by defining an implicit rule, like this:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
CFLAGS = -g
Packit 1ca270
ALL_CFLAGS = -I. $(CFLAGS)
Packit 1ca270
.c.o:
Packit 1ca270
        $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
Do include the @samp{-g} option in @code{CFLAGS}, because that is not
Packit 1ca270
@emph{required} for proper compilation.  You can consider it a default
Packit 1ca270
that is only recommended.  If the package is set up so that it is
Packit 1ca270
compiled with GCC by default, then you might as well include @samp{-O}
Packit 1ca270
in the default value of @code{CFLAGS} as well.
Packit 1ca270
Packit 1ca270
Put @code{CFLAGS} last in the compilation command, after other variables
Packit 1ca270
containing compiler options, so the user can use @code{CFLAGS} to
Packit 1ca270
override the others.
Packit 1ca270
Packit 1ca270
@code{CFLAGS} should be used in every invocation of the C compiler,
Packit 1ca270
both those which do compilation and those which do linking.
Packit 1ca270
Packit 1ca270
Every Makefile should define the variable @code{INSTALL}, which is the
Packit 1ca270
basic command for installing a file into the system.
Packit 1ca270
Packit 1ca270
Every Makefile should also define the variables @code{INSTALL_PROGRAM}
Packit 1ca270
and @code{INSTALL_DATA}.  (The default for each of these should be
Packit 1ca270
@code{$(INSTALL)}.)  Then it should use those variables as the commands
Packit 1ca270
for actual installation, for executables and nonexecutables
Packit 1ca270
respectively.  Use these variables as follows:
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
$(INSTALL_PROGRAM) foo $(bindir)/foo
Packit 1ca270
$(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
Always use a file name, not a directory name, as the second argument of
Packit 1ca270
the installation commands.  Use a separate command for each file to be
Packit 1ca270
installed.
Packit 1ca270
Packit 1ca270
@node Directory Variables
Packit 1ca270
@section Variables for Installation Directories
Packit 1ca270
Packit 1ca270
Installation directories should always be named by variables, so it is
Packit 1ca270
easy to install in a nonstandard place.  The standard names for these
Packit 1ca270
variables are described below.  They are based on a standard filesystem
Packit 1ca270
layout; variants of it are used in SVR4, 4.4BSD, Linux, Ultrix v4, and
Packit 1ca270
other modern operating systems.
Packit 1ca270
Packit 1ca270
These two variables set the root for the installation.  All the other
Packit 1ca270
installation directories should be subdirectories of one of these two,
Packit 1ca270
and nothing should be directly installed into these two directories.
Packit 1ca270
Packit 1ca270
@table @samp
Packit 1ca270
@item prefix
Packit 1ca270
A prefix used in constructing the default values of the variables listed
Packit 1ca270
below.  The default value of @code{prefix} should be @file{/usr/local}.
Packit 1ca270
When building the complete GNU system, the prefix will be empty and
Packit 1ca270
@file{/usr} will be a symbolic link to @file{/}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@prefix@@}.)
Packit 1ca270
Packit 1ca270
@item exec_prefix
Packit 1ca270
A prefix used in constructing the default values of some of the
Packit 1ca270
variables listed below.  The default value of @code{exec_prefix} should
Packit 1ca270
be @code{$(prefix)}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@exec_prefix@@}.)
Packit 1ca270
Packit 1ca270
Generally, @code{$(exec_prefix)} is used for directories that contain
Packit 1ca270
machine-specific files (such as executables and subroutine libraries),
Packit 1ca270
while @code{$(prefix)} is used directly for other directories.
Packit 1ca270
@end table
Packit 1ca270
Packit 1ca270
Executable programs are installed in one of the following directories.
Packit 1ca270
Packit 1ca270
@table @samp
Packit 1ca270
@item bindir
Packit 1ca270
The directory for installing executable programs that users can run.
Packit 1ca270
This should normally be @file{/usr/local/bin}, but write it as
Packit 1ca270
@file{$(exec_prefix)/bin}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@bindir@@}.)
Packit 1ca270
Packit 1ca270
@item sbindir
Packit 1ca270
The directory for installing executable programs that can be run from
Packit 1ca270
the shell, but are only generally useful to system administrators.  This
Packit 1ca270
should normally be @file{/usr/local/sbin}, but write it as
Packit 1ca270
@file{$(exec_prefix)/sbin}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@sbindir@@}.)
Packit 1ca270
Packit 1ca270
@item libexecdir
Packit 1ca270
@comment This paragraph adjusted to avoid overfull hbox --roland 5jul94
Packit 1ca270
The directory for installing executable programs to be run by other
Packit 1ca270
programs rather than by users.  This directory should normally be
Packit 1ca270
@file{/usr/local/libexec}, but write it as @file{$(exec_prefix)/libexec}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@libexecdir@@}.)
Packit 1ca270
@end table
Packit 1ca270
Packit 1ca270
Data files used by the program during its execution are divided into
Packit 1ca270
categories in two ways.
Packit 1ca270
Packit 1ca270
@itemize @bullet
Packit 1ca270
@item
Packit 1ca270
Some files are normally modified by programs; others are never normally
Packit 1ca270
modified (though users may edit some of these).
Packit 1ca270
Packit 1ca270
@item
Packit 1ca270
Some files are architecture-independent and can be shared by all
Packit 1ca270
machines at a site; some are architecture-dependent and can be shared
Packit 1ca270
only by machines of the same kind and operating system; others may never
Packit 1ca270
be shared between two machines.
Packit 1ca270
@end itemize
Packit 1ca270
Packit 1ca270
This makes for six different possibilities.  However, we want to
Packit 1ca270
discourage the use of architecture-dependent files, aside from object
Packit 1ca270
files and libraries.  It is much cleaner to make other data files
Packit 1ca270
architecture-independent, and it is generally not hard.
Packit 1ca270
Packit 1ca270
Therefore, here are the variables Makefiles should use to specify
Packit 1ca270
directories:
Packit 1ca270
Packit 1ca270
@table @samp
Packit 1ca270
@item datadir
Packit 1ca270
The directory for installing read-only architecture independent data
Packit 1ca270
files.  This should normally be @file{/usr/local/share}, but write it as
Packit 1ca270
@file{$(prefix)/share}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@datadir@@}.)
Packit 1ca270
As a special exception, see @file{$(infodir)}
Packit 1ca270
and @file{$(includedir)} below.
Packit 1ca270
Packit 1ca270
@item sysconfdir
Packit 1ca270
The directory for installing read-only data files that pertain to a
Packit 1ca270
single machine--that is to say, files for configuring a host.  Mailer
Packit 1ca270
and network configuration files, @file{/etc/passwd}, and so forth belong
Packit 1ca270
here.  All the files in this directory should be ordinary ASCII text
Packit 1ca270
files.  This directory should normally be @file{/usr/local/etc}, but
Packit 1ca270
write it as @file{$(prefix)/etc}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@sysconfdir@@}.)
Packit 1ca270
Packit 1ca270
Do not install executables here in this directory (they probably belong
Packit 1ca270
in @file{$(libexecdir)} or @file{$(sbindir)}).  Also do not install
Packit 1ca270
files that are modified in the normal course of their use (programs
Packit 1ca270
whose purpose is to change the configuration of the system excluded).
Packit 1ca270
Those probably belong in @file{$(localstatedir)}.
Packit 1ca270
Packit 1ca270
@item sharedstatedir
Packit 1ca270
The directory for installing architecture-independent data files which
Packit 1ca270
the programs modify while they run.  This should normally be
Packit 1ca270
@file{/usr/local/com}, but write it as @file{$(prefix)/com}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@sharedstatedir@@}.)
Packit 1ca270
Packit 1ca270
@item localstatedir
Packit 1ca270
The directory for installing data files which the programs modify while
Packit 1ca270
they run, and that pertain to one specific machine.  Users should never
Packit 1ca270
need to modify files in this directory to configure the package's
Packit 1ca270
operation; put such configuration information in separate files that go
Packit 1ca270
in @file{$(datadir)} or @file{$(sysconfdir)}.  @file{$(localstatedir)}
Packit 1ca270
should normally be @file{/usr/local/var}, but write it as
Packit 1ca270
@file{$(prefix)/var}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@localstatedir@@}.)
Packit 1ca270
Packit 1ca270
@item libdir
Packit 1ca270
The directory for object files and libraries of object code.  Do not
Packit 1ca270
install executables here, they probably ought to go in @file{$(libexecdir)}
Packit 1ca270
instead.  The value of @code{libdir} should normally be
Packit 1ca270
@file{/usr/local/lib}, but write it as @file{$(exec_prefix)/lib}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@libdir@@}.)
Packit 1ca270
Packit 1ca270
@item infodir
Packit 1ca270
The directory for installing the Info files for this package.  By
Packit 1ca270
default, it should be @file{/usr/local/info}, but it should be written
Packit 1ca270
as @file{$(prefix)/info}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@infodir@@}.)
Packit 1ca270
Packit 1ca270
@item lispdir
Packit 1ca270
The directory for installing any Emacs Lisp files in this package.  By
Packit 1ca270
default, it should be @file{/usr/local/share/emacs/site-lisp}, but it
Packit 1ca270
should be written as @file{$(prefix)/share/emacs/site-lisp}.
Packit 1ca270
Packit 1ca270
If you are using Autoconf, write the default as @samp{@@lispdir@@}.
Packit 1ca270
In order to make @samp{@@lispdir@@} work, you need the following lines
Packit 1ca270
in your @file{configure.in} file:
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
lispdir='$@{datadir@}/emacs/site-lisp'
Packit 1ca270
AC_SUBST(lispdir)
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
@item includedir
Packit 1ca270
@c rewritten to avoid overfull hbox --roland
Packit 1ca270
The directory for installing header files to be included by user
Packit 1ca270
programs with the C @samp{#include} preprocessor directive.  This
Packit 1ca270
should normally be @file{/usr/local/include}, but write it as
Packit 1ca270
@file{$(prefix)/include}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@includedir@@}.)
Packit 1ca270
Packit 1ca270
Most compilers other than GCC do not look for header files in directory
Packit 1ca270
@file{/usr/local/include}.  So installing the header files this way is
Packit 1ca270
only useful with GCC.  Sometimes this is not a problem because some
Packit 1ca270
libraries are only really intended to work with GCC.  But some libraries
Packit 1ca270
are intended to work with other compilers.  They should install their
Packit 1ca270
header files in two places, one specified by @code{includedir} and one
Packit 1ca270
specified by @code{oldincludedir}.
Packit 1ca270
Packit 1ca270
@item oldincludedir
Packit 1ca270
The directory for installing @samp{#include} header files for use with
Packit 1ca270
compilers other than GCC.  This should normally be @file{/usr/include}.
Packit 1ca270
(If you are using Autoconf, you can write it as @samp{@@oldincludedir@@}.)
Packit 1ca270
Packit 1ca270
The Makefile commands should check whether the value of
Packit 1ca270
@code{oldincludedir} is empty.  If it is, they should not try to use
Packit 1ca270
it; they should cancel the second installation of the header files.
Packit 1ca270
Packit 1ca270
A package should not replace an existing header in this directory unless
Packit 1ca270
the header came from the same package.  Thus, if your Foo package
Packit 1ca270
provides a header file @file{foo.h}, then it should install the header
Packit 1ca270
file in the @code{oldincludedir} directory if either (1) there is no
Packit 1ca270
@file{foo.h} there or (2) the @file{foo.h} that exists came from the Foo
Packit 1ca270
package.
Packit 1ca270
Packit 1ca270
To tell whether @file{foo.h} came from the Foo package, put a magic
Packit 1ca270
string in the file---part of a comment---and @code{grep} for that string.
Packit 1ca270
@end table
Packit 1ca270
Packit 1ca270
Unix-style man pages are installed in one of the following:
Packit 1ca270
Packit 1ca270
@table @samp
Packit 1ca270
@item mandir
Packit 1ca270
The top-level directory for installing the man pages (if any) for this
Packit 1ca270
package.  It will normally be @file{/usr/local/man}, but you should
Packit 1ca270
write it as @file{$(prefix)/man}.
Packit 1ca270
(If you are using Autoconf, write it as @samp{@@mandir@@}.)
Packit 1ca270
Packit 1ca270
@item man1dir
Packit 1ca270
The directory for installing section 1 man pages.  Write it as
Packit 1ca270
@file{$(mandir)/man1}.
Packit 1ca270
@item man2dir
Packit 1ca270
The directory for installing section 2 man pages.  Write it as
Packit 1ca270
@file{$(mandir)/man2}
Packit 1ca270
@item @dots{}
Packit 1ca270
Packit 1ca270
@strong{Don't make the primary documentation for any GNU software be a
Packit 1ca270
man page.  Write a manual in Texinfo instead.  Man pages are just for
Packit 1ca270
the sake of people running GNU software on Unix, which is a secondary
Packit 1ca270
application only.}
Packit 1ca270
Packit 1ca270
@item manext
Packit 1ca270
The file name extension for the installed man page.  This should contain
Packit 1ca270
a period followed by the appropriate digit; it should normally be @samp{.1}.
Packit 1ca270
Packit 1ca270
@item man1ext
Packit 1ca270
The file name extension for installed section 1 man pages.
Packit 1ca270
@item man2ext
Packit 1ca270
The file name extension for installed section 2 man pages.
Packit 1ca270
@item @dots{}
Packit 1ca270
Use these names instead of @samp{manext} if the package needs to install man
Packit 1ca270
pages in more than one section of the manual.
Packit 1ca270
@end table
Packit 1ca270
Packit 1ca270
And finally, you should set the following variable:
Packit 1ca270
Packit 1ca270
@table @samp
Packit 1ca270
@item srcdir
Packit 1ca270
The directory for the sources being compiled.  The value of this
Packit 1ca270
variable is normally inserted by the @code{configure} shell script.
Packit 1ca270
(If you are using Autconf, use @samp{srcdir = @@srcdir@@}.)
Packit 1ca270
@end table
Packit 1ca270
Packit 1ca270
For example:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
@c I have changed some of the comments here slightly to fix an overfull
Packit 1ca270
@c hbox, so the make manual can format correctly. --roland
Packit 1ca270
# Common prefix for installation directories.
Packit 1ca270
# NOTE: This directory must exist when you start the install.
Packit 1ca270
prefix = /usr/local
Packit 1ca270
exec_prefix = $(prefix)
Packit 1ca270
# Where to put the executable for the command `gcc'.
Packit 1ca270
bindir = $(exec_prefix)/bin
Packit 1ca270
# Where to put the directories used by the compiler.
Packit 1ca270
libexecdir = $(exec_prefix)/libexec
Packit 1ca270
# Where to put the Info files.
Packit 1ca270
infodir = $(prefix)/info
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
If your program installs a large number of files into one of the
Packit 1ca270
standard user-specified directories, it might be useful to group them
Packit 1ca270
into a subdirectory particular to that program.  If you do this, you
Packit 1ca270
should write the @code{install} rule to create these subdirectories.
Packit 1ca270
Packit 1ca270
Do not expect the user to include the subdirectory name in the value of
Packit 1ca270
any of the variables listed above.  The idea of having a uniform set of
Packit 1ca270
variable names for installation directories is to enable the user to
Packit 1ca270
specify the exact same values for several different GNU packages.  In
Packit 1ca270
order for this to be useful, all the packages must be designed so that
Packit 1ca270
they will work sensibly when the user does so.
Packit 1ca270
Packit 1ca270
@node Standard Targets
Packit 1ca270
@section Standard Targets for Users
Packit 1ca270
Packit 1ca270
All GNU programs should have the following targets in their Makefiles:
Packit 1ca270
Packit 1ca270
@table @samp
Packit 1ca270
@item all
Packit 1ca270
Compile the entire program.  This should be the default target.  This
Packit 1ca270
target need not rebuild any documentation files; Info files should
Packit 1ca270
normally be included in the distribution, and DVI files should be made
Packit 1ca270
only when explicitly asked for.
Packit 1ca270
Packit 1ca270
By default, the Make rules should compile and link with @samp{-g}, so
Packit 1ca270
that executable programs have debugging symbols.  Users who don't mind
Packit 1ca270
being helpless can strip the executables later if they wish.
Packit 1ca270
Packit 1ca270
@item install
Packit 1ca270
Compile the program and copy the executables, libraries, and so on to
Packit 1ca270
the file names where they should reside for actual use.  If there is a
Packit 1ca270
simple test to verify that a program is properly installed, this target
Packit 1ca270
should run that test.
Packit 1ca270
Packit 1ca270
Do not strip executables when installing them.  Devil-may-care users can
Packit 1ca270
use the @code{install-strip} target to do that.
Packit 1ca270
Packit 1ca270
If possible, write the @code{install} target rule so that it does not
Packit 1ca270
modify anything in the directory where the program was built, provided
Packit 1ca270
@samp{make all} has just been done.  This is convenient for building the
Packit 1ca270
program under one user name and installing it under another.
Packit 1ca270
Packit 1ca270
The commands should create all the directories in which files are to be
Packit 1ca270
installed, if they don't already exist.  This includes the directories
Packit 1ca270
specified as the values of the variables @code{prefix} and
Packit 1ca270
@code{exec_prefix}, as well as all subdirectories that are needed.
Packit 1ca270
One way to do this is by means of an @code{installdirs} target
Packit 1ca270
as described below.
Packit 1ca270
Packit 1ca270
Use @samp{-} before any command for installing a man page, so that
Packit 1ca270
@code{make} will ignore any errors.  This is in case there are systems
Packit 1ca270
that don't have the Unix man page documentation system installed.
Packit 1ca270
Packit 1ca270
The way to install Info files is to copy them into @file{$(infodir)}
Packit 1ca270
with @code{$(INSTALL_DATA)} (@pxref{Command Variables}), and then run
Packit 1ca270
the @code{install-info} program if it is present.  @code{install-info}
Packit 1ca270
is a program that edits the Info @file{dir} file to add or update the
Packit 1ca270
menu entry for the given Info file; it is part of the Texinfo package.
Packit 1ca270
Here is a sample rule to install an Info file:
Packit 1ca270
Packit 1ca270
@comment This example has been carefully formatted for the Make manual.
Packit 1ca270
@comment Please do not reformat it without talking to roland@gnu.ai.mit.edu.
Packit 1ca270
@smallexample
Packit 1ca270
$(infodir)/foo.info: foo.info
Packit 1ca270
        $(POST_INSTALL)
Packit 1ca270
# There may be a newer info file in . than in srcdir.
Packit 1ca270
        -if test -f foo.info; then d=.; \
Packit 1ca270
         else d=$(srcdir); fi; \
Packit 1ca270
        $(INSTALL_DATA) $$d/foo.info $@@; \
Packit 1ca270
# Run install-info only if it exists.
Packit 1ca270
# Use `if' instead of just prepending `-' to the
Packit 1ca270
# line so we notice real errors from install-info.
Packit 1ca270
# We use `$(SHELL) -c' because some shells do not
Packit 1ca270
# fail gracefully when there is an unknown command.
Packit 1ca270
        if $(SHELL) -c 'install-info --version' \
Packit 1ca270
           >/dev/null 2>&1; then \
Packit 1ca270
          install-info --dir-file=$(infodir)/dir \
Packit 1ca270
                       $(infodir)/foo.info; \
Packit 1ca270
        else true; fi
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
When writing the @code{install} target, you must classify all the
Packit 1ca270
commands into three categories: normal ones, @dfn{pre-installation}
Packit 1ca270
commands and @dfn{post-installation} commands.  @xref{Install Command
Packit 1ca270
Categories}.
Packit 1ca270
Packit 1ca270
@item uninstall
Packit 1ca270
Delete all the installed files---the copies that the @samp{install}
Packit 1ca270
target creates.
Packit 1ca270
Packit 1ca270
This rule should not modify the directories where compilation is done,
Packit 1ca270
only the directories where files are installed.
Packit 1ca270
Packit 1ca270
The uninstallation commands are divided into three categories, just like
Packit 1ca270
the installation commands.  @xref{Install Command Categories}.
Packit 1ca270
Packit 1ca270
@item install-strip
Packit 1ca270
Like @code{install}, but strip the executable files while installing
Packit 1ca270
them.  In many cases, the definition of this target can be very simple:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
install-strip:
Packit 1ca270
        $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
Packit 1ca270
                install
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
Normally we do not recommend stripping an executable unless you are sure
Packit 1ca270
the program has no bugs.  However, it can be reasonable to install a
Packit 1ca270
stripped executable for actual execution while saving the unstripped
Packit 1ca270
executable elsewhere in case there is a bug.
Packit 1ca270
Packit 1ca270
@comment The gratuitous blank line here is to make the table look better
Packit 1ca270
@comment in the printed Make manual.  Please leave it in.
Packit 1ca270
@item clean
Packit 1ca270
Packit 1ca270
Delete all files from the current directory that are normally created by
Packit 1ca270
building the program.  Don't delete the files that record the
Packit 1ca270
configuration.  Also preserve files that could be made by building, but
Packit 1ca270
normally aren't because the distribution comes with them.
Packit 1ca270
Packit 1ca270
Delete @file{.dvi} files here if they are not part of the distribution.
Packit 1ca270
Packit 1ca270
@item distclean
Packit 1ca270
Delete all files from the current directory that are created by
Packit 1ca270
configuring or building the program.  If you have unpacked the source
Packit 1ca270
and built the program without creating any other files, @samp{make
Packit 1ca270
distclean} should leave only the files that were in the distribution.
Packit 1ca270
Packit 1ca270
@item mostlyclean
Packit 1ca270
Like @samp{clean}, but may refrain from deleting a few files that people
Packit 1ca270
normally don't want to recompile.  For example, the @samp{mostlyclean}
Packit 1ca270
target for GCC does not delete @file{libgcc.a}, because recompiling it
Packit 1ca270
is rarely necessary and takes a lot of time.
Packit 1ca270
Packit 1ca270
@item maintainer-clean
Packit 1ca270
Delete almost everything from the current directory that can be
Packit 1ca270
reconstructed with this Makefile.  This typically includes everything
Packit 1ca270
deleted by @code{distclean}, plus more: C source files produced by
Packit 1ca270
Bison, tags tables, Info files, and so on.
Packit 1ca270
Packit 1ca270
The reason we say ``almost everything'' is that running the command
Packit 1ca270
@samp{make maintainer-clean} should not delete @file{configure} even if
Packit 1ca270
@file{configure} can be remade using a rule in the Makefile.  More generally,
Packit 1ca270
@samp{make maintainer-clean} should not delete anything that needs to
Packit 1ca270
exist in order to run @file{configure} and then begin to build the
Packit 1ca270
program.  This is the only exception; @code{maintainer-clean} should
Packit 1ca270
delete everything else that can be rebuilt.
Packit 1ca270
Packit 1ca270
The @samp{maintainer-clean} target is intended to be used by a maintainer of
Packit 1ca270
the package, not by ordinary users.  You may need special tools to
Packit 1ca270
reconstruct some of the files that @samp{make maintainer-clean} deletes.
Packit 1ca270
Since these files are normally included in the distribution, we don't
Packit 1ca270
take care to make them easy to reconstruct.  If you find you need to
Packit 1ca270
unpack the full distribution again, don't blame us.
Packit 1ca270
Packit 1ca270
To help make users aware of this, the commands for the special
Packit 1ca270
@code{maintainer-clean} target should start with these two:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
@@echo 'This command is intended for maintainers to use; it'
Packit 1ca270
@@echo 'deletes files that may need special tools to rebuild.'
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
@item TAGS
Packit 1ca270
Update a tags table for this program.
Packit 1ca270
@c ADR: how?
Packit 1ca270
Packit 1ca270
@item info
Packit 1ca270
Generate any Info files needed.  The best way to write the rules is as
Packit 1ca270
follows:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
info: foo.info
Packit 1ca270
Packit 1ca270
foo.info: foo.texi chap1.texi chap2.texi
Packit 1ca270
        $(MAKEINFO) $(srcdir)/foo.texi
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
You must define the variable @code{MAKEINFO} in the Makefile.  It should
Packit 1ca270
run the @code{makeinfo} program, which is part of the Texinfo
Packit 1ca270
distribution.
Packit 1ca270
Packit 1ca270
Normally a GNU distribution comes with Info files, and that means the
Packit 1ca270
Info files are present in the source directory.  Therefore, the Make
Packit 1ca270
rule for an info file should update it in the source directory.  When
Packit 1ca270
users build the package, ordinarily Make will not update the Info files
Packit 1ca270
because they will already be up to date.
Packit 1ca270
Packit 1ca270
@item dvi
Packit 1ca270
Generate DVI files for all Texinfo documentation.
Packit 1ca270
For example:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
dvi: foo.dvi
Packit 1ca270
Packit 1ca270
foo.dvi: foo.texi chap1.texi chap2.texi
Packit 1ca270
        $(TEXI2DVI) $(srcdir)/foo.texi
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
You must define the variable @code{TEXI2DVI} in the Makefile.  It should
Packit 1ca270
run the program @code{texi2dvi}, which is part of the Texinfo
Packit 1ca270
distribution.@footnote{@code{texi2dvi} uses @TeX{} to do the real work
Packit 1ca270
of formatting. @TeX{} is not distributed with Texinfo.}  Alternatively,
Packit 1ca270
write just the dependencies, and allow GNU @code{make} to provide the command.
Packit 1ca270
Packit 1ca270
@item dist
Packit 1ca270
Create a distribution tar file for this program.  The tar file should be
Packit 1ca270
set up so that the file names in the tar file start with a subdirectory
Packit 1ca270
name which is the name of the package it is a distribution for.  This
Packit 1ca270
name can include the version number.
Packit 1ca270
Packit 1ca270
For example, the distribution tar file of GCC version 1.40 unpacks into
Packit 1ca270
a subdirectory named @file{gcc-1.40}.
Packit 1ca270
Packit 1ca270
The easiest way to do this is to create a subdirectory appropriately
Packit 1ca270
named, use @code{ln} or @code{cp} to install the proper files in it, and
Packit 1ca270
then @code{tar} that subdirectory.
Packit 1ca270
Packit 1ca270
Compress the tar file file with @code{gzip}.  For example, the actual
Packit 1ca270
distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}.
Packit 1ca270
Packit 1ca270
The @code{dist} target should explicitly depend on all non-source files
Packit 1ca270
that are in the distribution, to make sure they are up to date in the
Packit 1ca270
distribution.
Packit 1ca270
@ifset CODESTD
Packit 1ca270
@xref{Releases, , Making Releases}.
Packit 1ca270
@end ifset
Packit 1ca270
@ifclear CODESTD
Packit 1ca270
@xref{Releases, , Making Releases, standards, GNU Coding Standards}.
Packit 1ca270
@end ifclear
Packit 1ca270
Packit 1ca270
@item check
Packit 1ca270
Perform self-tests (if any).  The user must build the program before
Packit 1ca270
running the tests, but need not install the program; you should write
Packit 1ca270
the self-tests so that they work when the program is built but not
Packit 1ca270
installed.
Packit 1ca270
@end table
Packit 1ca270
Packit 1ca270
The following targets are suggested as conventional names, for programs
Packit 1ca270
in which they are useful.
Packit 1ca270
Packit 1ca270
@table @code
Packit 1ca270
@item installcheck
Packit 1ca270
Perform installation tests (if any).  The user must build and install
Packit 1ca270
the program before running the tests.  You should not assume that
Packit 1ca270
@file{$(bindir)} is in the search path.
Packit 1ca270
Packit 1ca270
@item installdirs
Packit 1ca270
It's useful to add a target named @samp{installdirs} to create the
Packit 1ca270
directories where files are installed, and their parent directories.
Packit 1ca270
There is a script called @file{mkinstalldirs} which is convenient for
Packit 1ca270
this; you can find it in the Texinfo package.
Packit 1ca270
@c It's in /gd/gnu/lib/mkinstalldirs.
Packit 1ca270
You can use a rule like this:
Packit 1ca270
Packit 1ca270
@comment This has been carefully formatted to look decent in the Make manual.
Packit 1ca270
@comment Please be sure not to make it extend any further to the right.--roland
Packit 1ca270
@smallexample
Packit 1ca270
# Make sure all installation directories (e.g. $(bindir))
Packit 1ca270
# actually exist by making them if necessary.
Packit 1ca270
installdirs: mkinstalldirs
Packit 1ca270
        $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
Packit 1ca270
                                $(libdir) $(infodir) \
Packit 1ca270
                                $(mandir)
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
This rule should not modify the directories where compilation is done.
Packit 1ca270
It should do nothing but create installation directories.
Packit 1ca270
@end table
Packit 1ca270
Packit 1ca270
@node Install Command Categories
Packit 1ca270
@section Install Command Categories
Packit 1ca270
Packit 1ca270
@cindex pre-installation commands
Packit 1ca270
@cindex post-installation commands
Packit 1ca270
When writing the @code{install} target, you must classify all the
Packit 1ca270
commands into three categories: normal ones, @dfn{pre-installation}
Packit 1ca270
commands and @dfn{post-installation} commands.
Packit 1ca270
Packit 1ca270
Normal commands move files into their proper places, and set their
Packit 1ca270
modes.  They may not alter any files except the ones that come entirely
Packit 1ca270
from the package they belong to.
Packit 1ca270
Packit 1ca270
Pre-installation and post-installation commands may alter other files;
Packit 1ca270
in particular, they can edit global configuration files or data bases.
Packit 1ca270
Packit 1ca270
Pre-installation commands are typically executed before the normal
Packit 1ca270
commands, and post-installation commands are typically run after the
Packit 1ca270
normal commands.
Packit 1ca270
Packit 1ca270
The most common use for a post-installation command is to run
Packit 1ca270
@code{install-info}.  This cannot be done with a normal command, since
Packit 1ca270
it alters a file (the Info directory) which does not come entirely and
Packit 1ca270
solely from the package being installed.  It is a post-installation
Packit 1ca270
command because it needs to be done after the normal command which
Packit 1ca270
installs the package's Info files.
Packit 1ca270
Packit 1ca270
Most programs don't need any pre-installation commands, but we have the
Packit 1ca270
feature just in case it is needed.
Packit 1ca270
Packit 1ca270
To classify the commands in the @code{install} rule into these three
Packit 1ca270
categories, insert @dfn{category lines} among them.  A category line
Packit 1ca270
specifies the category for the commands that follow.
Packit 1ca270
Packit 1ca270
A category line consists of a tab and a reference to a special Make
Packit 1ca270
variable, plus an optional comment at the end.  There are three
Packit 1ca270
variables you can use, one for each category; the variable name
Packit 1ca270
specifies the category.  Category lines are no-ops in ordinary execution
Packit 1ca270
because these three Make variables are normally undefined (and you
Packit 1ca270
@emph{should not} define them in the makefile).
Packit 1ca270
Packit 1ca270
Here are the three possible category lines, each with a comment that
Packit 1ca270
explains what it means:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
        $(PRE_INSTALL)     # @r{Pre-install commands follow.}
Packit 1ca270
        $(POST_INSTALL)    # @r{Post-install commands follow.}
Packit 1ca270
        $(NORMAL_INSTALL)  # @r{Normal commands follow.}
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
If you don't use a category line at the beginning of the @code{install}
Packit 1ca270
rule, all the commands are classified as normal until the first category
Packit 1ca270
line.  If you don't use any category lines, all the commands are
Packit 1ca270
classified as normal.
Packit 1ca270
Packit 1ca270
These are the category lines for @code{uninstall}:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
        $(PRE_UNINSTALL)     # @r{Pre-uninstall commands follow.}
Packit 1ca270
        $(POST_UNINSTALL)    # @r{Post-uninstall commands follow.}
Packit 1ca270
        $(NORMAL_UNINSTALL)  # @r{Normal commands follow.}
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
Typically, a pre-uninstall command would be used for deleting entries
Packit 1ca270
from the Info directory.
Packit 1ca270
Packit 1ca270
If the @code{install} or @code{uninstall} target has any dependencies
Packit 1ca270
which act as subroutines of installation, then you should start
Packit 1ca270
@emph{each} dependency's commands with a category line, and start the
Packit 1ca270
main target's commands with a category line also.  This way, you can
Packit 1ca270
ensure that each command is placed in the right category regardless of
Packit 1ca270
which of the dependencies actually run.
Packit 1ca270
Packit 1ca270
Pre-installation and post-installation commands should not run any
Packit 1ca270
programs except for these:
Packit 1ca270
Packit 1ca270
@example
Packit 1ca270
[ basename bash cat chgrp chmod chown cmp cp dd diff echo
Packit 1ca270
egrep expand expr false fgrep find getopt grep gunzip gzip
Packit 1ca270
hostname install install-info kill ldconfig ln ls md5sum
Packit 1ca270
mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
Packit 1ca270
test touch true uname xargs yes
Packit 1ca270
@end example
Packit 1ca270
Packit 1ca270
@cindex binary packages
Packit 1ca270
The reason for distinguishing the commands in this way is for the sake
Packit 1ca270
of making binary packages.  Typically a binary package contains all the
Packit 1ca270
executables and other files that need to be installed, and has its own
Packit 1ca270
method of installing them---so it does not need to run the normal
Packit 1ca270
installation commands.  But installing the binary package does need to
Packit 1ca270
execute the pre-installation and post-installation commands.
Packit 1ca270
Packit 1ca270
Programs to build binary packages work by extracting the
Packit 1ca270
pre-installation and post-installation commands.  Here is one way of
Packit 1ca270
extracting the pre-installation commands:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
make -n install -o all \
Packit 1ca270
      PRE_INSTALL=pre-install \
Packit 1ca270
      POST_INSTALL=post-install \
Packit 1ca270
      NORMAL_INSTALL=normal-install \
Packit 1ca270
  | gawk -f pre-install.awk
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
@noindent
Packit 1ca270
where the file @file{pre-install.awk} could contain this:
Packit 1ca270
Packit 1ca270
@smallexample
Packit 1ca270
$0 ~ /^\t[ \t]*(normal_install|post_install)[ \t]*$/ @{on = 0@}
Packit 1ca270
on @{print $0@}
Packit 1ca270
$0 ~ /^\t[ \t]*pre_install[ \t]*$/ @{on = 1@}
Packit 1ca270
@end smallexample
Packit 1ca270
Packit 1ca270
The resulting file of pre-installation commands is executed as a shell
Packit 1ca270
script as part of installing the binary package.