Blame doc/make-stds.texi

Packit 47b4ca
@comment This file is included by both standards.texi and make.texinfo.
Packit 47b4ca
@comment It was broken out of standards.texi on 1/6/93 by roland.
Packit 47b4ca
Packit 47b4ca
@node Makefile Conventions
Packit 47b4ca
@chapter Makefile Conventions
Packit 47b4ca
@cindex makefile, conventions for
Packit 47b4ca
@cindex conventions for makefiles
Packit 47b4ca
@cindex standards for makefiles
Packit 47b4ca
Packit 47b4ca
@c Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001,
Packit 47b4ca
@c 2004, 2005, 2006, 2007, 2008, 2010 Free Software Foundation, Inc.
Packit 47b4ca
@c
Packit 47b4ca
@c Permission is granted to copy, distribute and/or modify this document
Packit 47b4ca
@c under the terms of the GNU Free Documentation License, Version 1.3
Packit 47b4ca
@c or any later version published by the Free Software Foundation;
Packit 47b4ca
@c with no Invariant Sections, with no
Packit 47b4ca
@c Front-Cover Texts, and with no Back-Cover Texts.
Packit 47b4ca
@c A copy of the license is included in the section entitled ``GNU
Packit 47b4ca
@c Free Documentation License''.
Packit 47b4ca
Packit 47b4ca
This
Packit 47b4ca
@ifinfo
Packit 47b4ca
node
Packit 47b4ca
@end ifinfo
Packit 47b4ca
@iftex
Packit 47b4ca
@ifset CODESTD
Packit 47b4ca
section
Packit 47b4ca
@end ifset
Packit 47b4ca
@ifclear CODESTD
Packit 47b4ca
chapter
Packit 47b4ca
@end ifclear
Packit 47b4ca
@end iftex
Packit 47b4ca
describes conventions for writing the Makefiles for GNU programs.
Packit 47b4ca
Using Automake will help you write a Makefile that follows these
Packit 47b4ca
conventions.  For more information on portable Makefiles, see
Packit 47b4ca
@sc{posix} and @ref{Portable Make, Portable Make Programming,, autoconf,
Packit 47b4ca
Autoconf}.
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
@menu
Packit 47b4ca
* Makefile Basics::             General conventions for Makefiles.
Packit 47b4ca
* Utilities in Makefiles::      Utilities to be used in Makefiles.
Packit 47b4ca
* Command Variables::           Variables for specifying commands.
Packit 47b4ca
* DESTDIR::                     Supporting staged installs.
Packit 47b4ca
* Directory Variables::         Variables for installation directories.
Packit 47b4ca
* Standard Targets::            Standard targets for users.
Packit 47b4ca
* Install Command Categories::  Three categories of commands in the `install'
Packit 47b4ca
                                  rule: normal, pre-install and post-install.
Packit 47b4ca
@end menu
Packit 47b4ca
Packit 47b4ca
@node Makefile Basics
Packit 47b4ca
@section General Conventions for Makefiles
Packit 47b4ca
Packit 47b4ca
Every Makefile should contain this line:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
SHELL = /bin/sh
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
to avoid trouble on systems where the @code{SHELL} variable might be
Packit 47b4ca
inherited from the environment.  (This is never a problem with GNU
Packit 47b4ca
@code{make}.)
Packit 47b4ca
Packit 47b4ca
Different @code{make} programs have incompatible suffix lists and
Packit 47b4ca
implicit rules, and this sometimes creates confusion or misbehavior.  So
Packit 47b4ca
it is a good idea to set the suffix list explicitly using only the
Packit 47b4ca
suffixes you need in the particular Makefile, like this:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
.SUFFIXES:
Packit 47b4ca
.SUFFIXES: .c .o
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
The first line clears out the suffix list, the second introduces all
Packit 47b4ca
suffixes which may be subject to implicit rules in this Makefile.
Packit 47b4ca
Packit 47b4ca
Don't assume that @file{.} is in the path for command execution.  When
Packit 47b4ca
you need to run programs that are a part of your package during the
Packit 47b4ca
make, please make sure that it uses @file{./} if the program is built as
Packit 47b4ca
part of the make or @file{$(srcdir)/} if the file is an unchanging part
Packit 47b4ca
of the source code.  Without one of these prefixes, the current search
Packit 47b4ca
path is used.
Packit 47b4ca
Packit 47b4ca
The distinction between @file{./} (the @dfn{build directory}) and
Packit 47b4ca
@file{$(srcdir)/} (the @dfn{source directory}) is important because
Packit 47b4ca
users can build in a separate directory using the @samp{--srcdir} option
Packit 47b4ca
to @file{configure}.  A rule of the form:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
foo.1 : foo.man sedscript
Packit 47b4ca
        sed -f sedscript foo.man > foo.1
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
will fail when the build directory is not the source directory, because
Packit 47b4ca
@file{foo.man} and @file{sedscript} are in the source directory.
Packit 47b4ca
Packit 47b4ca
When using GNU @code{make}, relying on @samp{VPATH} to find the source
Packit 47b4ca
file will work in the case where there is a single dependency file,
Packit 47b4ca
since the @code{make} automatic variable @samp{$<} will represent the
Packit 47b4ca
source file wherever it is.  (Many versions of @code{make} set @samp{$<}
Packit 47b4ca
only in implicit rules.)  A Makefile target like
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
foo.o : bar.c
Packit 47b4ca
        $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
should instead be written as
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
foo.o : bar.c
Packit 47b4ca
        $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@@
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
in order to allow @samp{VPATH} to work correctly.  When the target has
Packit 47b4ca
multiple dependencies, using an explicit @samp{$(srcdir)} is the easiest
Packit 47b4ca
way to make the rule work well.  For example, the target above for
Packit 47b4ca
@file{foo.1} is best written as:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
foo.1 : foo.man sedscript
Packit 47b4ca
        sed -f $(srcdir)/sedscript $(srcdir)/foo.man > $@@
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
GNU distributions usually contain some files which are not source
Packit 47b4ca
files---for example, Info files, and the output from Autoconf, Automake,
Packit 47b4ca
Bison or Flex.  Since these files normally appear in the source
Packit 47b4ca
directory, they should always appear in the source directory, not in the
Packit 47b4ca
build directory.  So Makefile rules to update them should put the
Packit 47b4ca
updated files in the source directory.
Packit 47b4ca
Packit 47b4ca
However, if a file does not appear in the distribution, then the
Packit 47b4ca
Makefile should not put it in the source directory, because building a
Packit 47b4ca
program in ordinary circumstances should not modify the source directory
Packit 47b4ca
in any way.
Packit 47b4ca
Packit 47b4ca
Try to make the build and installation targets, at least (and all their
Packit 47b4ca
subtargets) work correctly with a parallel @code{make}.
Packit 47b4ca
Packit 47b4ca
@node Utilities in Makefiles
Packit 47b4ca
@section Utilities in Makefiles
Packit 47b4ca
Packit 47b4ca
Write the Makefile commands (and any shell scripts, such as
Packit 47b4ca
@code{configure}) to run under @code{sh} (both the traditional Bourne
Packit 47b4ca
shell and the @sc{posix} shell), not @code{csh}.  Don't use any
Packit 47b4ca
special features of @code{ksh} or @code{bash}, or @sc{posix} features
Packit 47b4ca
not widely supported in traditional Bourne @code{sh}.
Packit 47b4ca
Packit 47b4ca
The @code{configure} script and the Makefile rules for building and
Packit 47b4ca
installation should not use any utilities directly except these:
Packit 47b4ca
Packit 47b4ca
@c dd find
Packit 47b4ca
@c gunzip gzip md5sum
Packit 47b4ca
@c mkfifo mknod tee uname
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
awk cat cmp cp diff echo egrep expr false grep install-info ln ls
Packit 47b4ca
mkdir mv printf pwd rm rmdir sed sleep sort tar test touch tr true
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
Compression programs such as @code{gzip} can be used in the
Packit 47b4ca
@code{dist} rule.
Packit 47b4ca
Packit 47b4ca
Generally, stick to the widely-supported (usually
Packit 47b4ca
@sc{posix}-specified) options and features of these programs.  For
Packit 47b4ca
example, don't use @samp{mkdir -p}, convenient as it may be, because a
Packit 47b4ca
few systems don't support it at all and with others, it is not safe
Packit 47b4ca
for parallel execution.  For a list of known incompatibilities, see
Packit 47b4ca
@ref{Portable Shell, Portable Shell Programming,, autoconf, Autoconf}.
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
It is a good idea to avoid creating symbolic links in makefiles, since a
Packit 47b4ca
few file systems don't support them.
Packit 47b4ca
Packit 47b4ca
The Makefile rules for building and installation can also use compilers
Packit 47b4ca
and related programs, but should do so via @code{make} variables so that the
Packit 47b4ca
user can substitute alternatives.  Here are some of the programs we
Packit 47b4ca
mean:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
ar bison cc flex install ld ldconfig lex
Packit 47b4ca
make makeinfo ranlib texi2dvi yacc
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
Use the following @code{make} variables to run those programs:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
$(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
Packit 47b4ca
$(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
When you use @code{ranlib} or @code{ldconfig}, you should make sure
Packit 47b4ca
nothing bad happens if the system does not have the program in question.
Packit 47b4ca
Arrange to ignore an error from that command, and print a message before
Packit 47b4ca
the command to tell the user that failure of this command does not mean
Packit 47b4ca
a problem.  (The Autoconf @samp{AC_PROG_RANLIB} macro can help with
Packit 47b4ca
this.)
Packit 47b4ca
Packit 47b4ca
If you use symbolic links, you should implement a fallback for systems
Packit 47b4ca
that don't have symbolic links.
Packit 47b4ca
Packit 47b4ca
Additional utilities that can be used via Make variables are:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
chgrp chmod chown mknod
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
It is ok to use other utilities in Makefile portions (or scripts)
Packit 47b4ca
intended only for particular systems where you know those utilities
Packit 47b4ca
exist.
Packit 47b4ca
Packit 47b4ca
@node Command Variables
Packit 47b4ca
@section Variables for Specifying Commands
Packit 47b4ca
Packit 47b4ca
Makefiles should provide variables for overriding certain commands, options,
Packit 47b4ca
and so on.
Packit 47b4ca
Packit 47b4ca
In particular, you should run most utility programs via variables.
Packit 47b4ca
Thus, if you use Bison, have a variable named @code{BISON} whose default
Packit 47b4ca
value is set with @samp{BISON = bison}, and refer to it with
Packit 47b4ca
@code{$(BISON)} whenever you need to use Bison.
Packit 47b4ca
Packit 47b4ca
File management utilities such as @code{ln}, @code{rm}, @code{mv}, and
Packit 47b4ca
so on, need not be referred to through variables in this way, since users
Packit 47b4ca
don't need to replace them with other programs.
Packit 47b4ca
Packit 47b4ca
Each program-name variable should come with an options variable that is
Packit 47b4ca
used to supply options to the program.  Append @samp{FLAGS} to the
Packit 47b4ca
program-name variable name to get the options variable name---for
Packit 47b4ca
example, @code{BISONFLAGS}.  (The names @code{CFLAGS} for the C
Packit 47b4ca
compiler, @code{YFLAGS} for yacc, and @code{LFLAGS} for lex, are
Packit 47b4ca
exceptions to this rule, but we keep them because they are standard.)
Packit 47b4ca
Use @code{CPPFLAGS} in any compilation command that runs the
Packit 47b4ca
preprocessor, and use @code{LDFLAGS} in any compilation command that
Packit 47b4ca
does linking as well as in any direct use of @code{ld}.
Packit 47b4ca
Packit 47b4ca
If there are C compiler options that @emph{must} be used for proper
Packit 47b4ca
compilation of certain files, do not include them in @code{CFLAGS}.
Packit 47b4ca
Users expect to be able to specify @code{CFLAGS} freely themselves.
Packit 47b4ca
Instead, arrange to pass the necessary options to the C compiler
Packit 47b4ca
independently of @code{CFLAGS}, by writing them explicitly in the
Packit 47b4ca
compilation commands or by defining an implicit rule, like this:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
CFLAGS = -g
Packit 47b4ca
ALL_CFLAGS = -I. $(CFLAGS)
Packit 47b4ca
.c.o:
Packit 47b4ca
        $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
Do include the @samp{-g} option in @code{CFLAGS}, because that is not
Packit 47b4ca
@emph{required} for proper compilation.  You can consider it a default
Packit 47b4ca
that is only recommended.  If the package is set up so that it is
Packit 47b4ca
compiled with GCC by default, then you might as well include @samp{-O}
Packit 47b4ca
in the default value of @code{CFLAGS} as well.
Packit 47b4ca
Packit 47b4ca
Put @code{CFLAGS} last in the compilation command, after other variables
Packit 47b4ca
containing compiler options, so the user can use @code{CFLAGS} to
Packit 47b4ca
override the others.
Packit 47b4ca
Packit 47b4ca
@code{CFLAGS} should be used in every invocation of the C compiler,
Packit 47b4ca
both those which do compilation and those which do linking.
Packit 47b4ca
Packit 47b4ca
Every Makefile should define the variable @code{INSTALL}, which is the
Packit 47b4ca
basic command for installing a file into the system.
Packit 47b4ca
Packit 47b4ca
Every Makefile should also define the variables @code{INSTALL_PROGRAM}
Packit 47b4ca
and @code{INSTALL_DATA}.  (The default for @code{INSTALL_PROGRAM} should
Packit 47b4ca
be @code{$(INSTALL)}; the default for @code{INSTALL_DATA} should be
Packit 47b4ca
@code{$@{INSTALL@} -m 644}.)  Then it should use those variables as the
Packit 47b4ca
commands for actual installation, for executables and non-executables
Packit 47b4ca
respectively.  Minimal use of these variables is as follows:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
$(INSTALL_PROGRAM) foo $(bindir)/foo
Packit 47b4ca
$(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
However, it is preferable to support a @code{DESTDIR} prefix on the
Packit 47b4ca
target files, as explained in the next section.
Packit 47b4ca
Packit 47b4ca
It is acceptable, but not required, to install multiple files in one
Packit 47b4ca
command, with the final argument being a directory, as in:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
$(INSTALL_PROGRAM) foo bar baz $(bindir)
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
@node DESTDIR
Packit 47b4ca
@section @code{DESTDIR}: Support for Staged Installs
Packit 47b4ca
Packit 47b4ca
@vindex DESTDIR
Packit 47b4ca
@cindex staged installs
Packit 47b4ca
@cindex installations, staged
Packit 47b4ca
Packit 47b4ca
@code{DESTDIR} is a variable prepended to each installed target file,
Packit 47b4ca
like this:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
$(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo
Packit 47b4ca
$(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
The @code{DESTDIR} variable is specified by the user on the @code{make}
Packit 47b4ca
command line as an absolute file name.  For example:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
make DESTDIR=/tmp/stage install
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
@code{DESTDIR} should be supported only in the @code{install*} and
Packit 47b4ca
@code{uninstall*} targets, as those are the only targets where it is
Packit 47b4ca
useful.
Packit 47b4ca
Packit 47b4ca
If your installation step would normally install
Packit 47b4ca
@file{/usr/local/bin/foo} and @file{/usr/@/local/@/lib/@/libfoo.a}, then an
Packit 47b4ca
installation invoked as in the example above would install
Packit 47b4ca
@file{/tmp/stage/usr/local/bin/foo} and
Packit 47b4ca
@file{/tmp/stage/usr/local/lib/libfoo.a} instead.
Packit 47b4ca
Packit 47b4ca
Prepending the variable @code{DESTDIR} to each target in this way
Packit 47b4ca
provides for @dfn{staged installs}, where the installed files are not
Packit 47b4ca
placed directly into their expected location but are instead copied
Packit 47b4ca
into a temporary location (@code{DESTDIR}).  However, installed files
Packit 47b4ca
maintain their relative directory structure and any embedded file names
Packit 47b4ca
will not be modified.
Packit 47b4ca
Packit 47b4ca
You should not set the value of @code{DESTDIR} in your @file{Makefile}
Packit 47b4ca
at all; then the files are installed into their expected locations by
Packit 47b4ca
default.  Also, specifying @code{DESTDIR} should not change the
Packit 47b4ca
operation of the software in any way, so its value should not be
Packit 47b4ca
included in any file contents.
Packit 47b4ca
Packit 47b4ca
@code{DESTDIR} support is commonly used in package creation.  It is
Packit 47b4ca
also helpful to users who want to understand what a given package will
Packit 47b4ca
install where, and to allow users who don't normally have permissions
Packit 47b4ca
to install into protected areas to build and install before gaining
Packit 47b4ca
those permissions.  Finally, it can be useful with tools such as
Packit 47b4ca
@code{stow}, where code is installed in one place but made to appear
Packit 47b4ca
to be installed somewhere else using symbolic links or special mount
Packit 47b4ca
operations.  So, we strongly recommend GNU packages support
Packit 47b4ca
@code{DESTDIR}, though it is not an absolute requirement.
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
@node Directory Variables
Packit 47b4ca
@section Variables for Installation Directories
Packit 47b4ca
Packit 47b4ca
Installation directories should always be named by variables, so it is
Packit 47b4ca
easy to install in a nonstandard place.  The standard names for these
Packit 47b4ca
variables and the values they should have in GNU packages are
Packit 47b4ca
described below.  They are based on a standard file system layout;
Packit 47b4ca
variants of it are used in GNU/Linux and other modern operating
Packit 47b4ca
systems.
Packit 47b4ca
Packit 47b4ca
Installers are expected to override these values when calling
Packit 47b4ca
@command{make} (e.g., @kbd{make prefix=/usr install} or
Packit 47b4ca
@command{configure} (e.g., @kbd{configure --prefix=/usr}).  GNU
Packit 47b4ca
packages should not try to guess which value should be appropriate for
Packit 47b4ca
these variables on the system they are being installed onto: use the
Packit 47b4ca
default settings specified here so that all GNU packages behave
Packit 47b4ca
identically, allowing the installer to achieve any desired layout.
Packit 47b4ca
Packit 47b4ca
@cindex directories, creating installation
Packit 47b4ca
@cindex installation directories, creating
Packit 47b4ca
All installation directories, and their parent directories, should be
Packit 47b4ca
created (if necessary) before they are installed into.
Packit 47b4ca
Packit 47b4ca
These first two variables set the root for the installation.  All the
Packit 47b4ca
other installation directories should be subdirectories of one of
Packit 47b4ca
these two, and nothing should be directly installed into these two
Packit 47b4ca
directories.
Packit 47b4ca
Packit 47b4ca
@table @code
Packit 47b4ca
@item prefix
Packit 47b4ca
@vindex prefix
Packit 47b4ca
A prefix used in constructing the default values of the variables listed
Packit 47b4ca
below.  The default value of @code{prefix} should be @file{/usr/local}.
Packit 47b4ca
When building the complete GNU system, the prefix will be empty and
Packit 47b4ca
@file{/usr} will be a symbolic link to @file{/}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@prefix@@}.)
Packit 47b4ca
Packit 47b4ca
Running @samp{make install} with a different value of @code{prefix} from
Packit 47b4ca
the one used to build the program should @emph{not} recompile the
Packit 47b4ca
program.
Packit 47b4ca
Packit 47b4ca
@item exec_prefix
Packit 47b4ca
@vindex exec_prefix
Packit 47b4ca
A prefix used in constructing the default values of some of the
Packit 47b4ca
variables listed below.  The default value of @code{exec_prefix} should
Packit 47b4ca
be @code{$(prefix)}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@exec_prefix@@}.)
Packit 47b4ca
Packit 47b4ca
Generally, @code{$(exec_prefix)} is used for directories that contain
Packit 47b4ca
machine-specific files (such as executables and subroutine libraries),
Packit 47b4ca
while @code{$(prefix)} is used directly for other directories.
Packit 47b4ca
Packit 47b4ca
Running @samp{make install} with a different value of @code{exec_prefix}
Packit 47b4ca
from the one used to build the program should @emph{not} recompile the
Packit 47b4ca
program.
Packit 47b4ca
@end table
Packit 47b4ca
Packit 47b4ca
Executable programs are installed in one of the following directories.
Packit 47b4ca
Packit 47b4ca
@table @code
Packit 47b4ca
@item bindir
Packit 47b4ca
@vindex bindir
Packit 47b4ca
The directory for installing executable programs that users can run.
Packit 47b4ca
This should normally be @file{/usr/local/bin}, but write it as
Packit 47b4ca
@file{$(exec_prefix)/bin}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@bindir@@}.)
Packit 47b4ca
Packit 47b4ca
@item sbindir
Packit 47b4ca
@vindex sbindir
Packit 47b4ca
The directory for installing executable programs that can be run from
Packit 47b4ca
the shell, but are only generally useful to system administrators.  This
Packit 47b4ca
should normally be @file{/usr/local/sbin}, but write it as
Packit 47b4ca
@file{$(exec_prefix)/sbin}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@sbindir@@}.)
Packit 47b4ca
Packit 47b4ca
@item libexecdir
Packit 47b4ca
@vindex libexecdir
Packit 47b4ca
@comment This paragraph adjusted to avoid overfull hbox --roland 5jul94
Packit 47b4ca
The directory for installing executable programs to be run by other
Packit 47b4ca
programs rather than by users.  This directory should normally be
Packit 47b4ca
@file{/usr/local/libexec}, but write it as @file{$(exec_prefix)/libexec}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@libexecdir@@}.)
Packit 47b4ca
Packit 47b4ca
The definition of @samp{libexecdir} is the same for all packages, so
Packit 47b4ca
you should install your data in a subdirectory thereof.  Most packages
Packit 47b4ca
install their data under @file{$(libexecdir)/@var{package-name}/},
Packit 47b4ca
possibly within additional subdirectories thereof, such as
Packit 47b4ca
@file{$(libexecdir)/@var{package-name}/@var{machine}/@var{version}}.
Packit 47b4ca
@end table
Packit 47b4ca
Packit 47b4ca
Data files used by the program during its execution are divided into
Packit 47b4ca
categories in two ways.
Packit 47b4ca
Packit 47b4ca
@itemize @bullet
Packit 47b4ca
@item
Packit 47b4ca
Some files are normally modified by programs; others are never normally
Packit 47b4ca
modified (though users may edit some of these).
Packit 47b4ca
Packit 47b4ca
@item
Packit 47b4ca
Some files are architecture-independent and can be shared by all
Packit 47b4ca
machines at a site; some are architecture-dependent and can be shared
Packit 47b4ca
only by machines of the same kind and operating system; others may never
Packit 47b4ca
be shared between two machines.
Packit 47b4ca
@end itemize
Packit 47b4ca
Packit 47b4ca
This makes for six different possibilities.  However, we want to
Packit 47b4ca
discourage the use of architecture-dependent files, aside from object
Packit 47b4ca
files and libraries.  It is much cleaner to make other data files
Packit 47b4ca
architecture-independent, and it is generally not hard.
Packit 47b4ca
Packit 47b4ca
Here are the variables Makefiles should use to specify directories
Packit 47b4ca
to put these various kinds of files in:
Packit 47b4ca
Packit 47b4ca
@table @samp
Packit 47b4ca
@item datarootdir
Packit 47b4ca
The root of the directory tree for read-only architecture-independent
Packit 47b4ca
data files.  This should normally be @file{/usr/local/share}, but
Packit 47b4ca
write it as @file{$(prefix)/share}.  (If you are using Autoconf, write
Packit 47b4ca
it as @samp{@@datarootdir@@}.)  @samp{datadir}'s default value is
Packit 47b4ca
based on this variable; so are @samp{infodir}, @samp{mandir}, and
Packit 47b4ca
others.
Packit 47b4ca
Packit 47b4ca
@item datadir
Packit 47b4ca
The directory for installing idiosyncratic read-only
Packit 47b4ca
architecture-independent data files for this program.  This is usually
Packit 47b4ca
the same place as @samp{datarootdir}, but we use the two separate
Packit 47b4ca
variables so that you can move these program-specific files without
Packit 47b4ca
altering the location for Info files, man pages, etc.
Packit 47b4ca
Packit 47b4ca
@c raggedright  (not until next Texinfo release)
Packit 47b4ca
This should normally be @file{/usr/local/share}, but write it as
Packit 47b4ca
@file{$(datarootdir)}.  (If you are using Autoconf, write it as
Packit 47b4ca
@samp{@@datadir@@}.)
Packit 47b4ca
@c end raggedright
Packit 47b4ca
Packit 47b4ca
The definition of @samp{datadir} is the same for all packages, so you
Packit 47b4ca
should install your data in a subdirectory thereof.  Most packages
Packit 47b4ca
install their data under @file{$(datadir)/@var{package-name}/}.
Packit 47b4ca
Packit 47b4ca
@item sysconfdir
Packit 47b4ca
The directory for installing read-only data files that pertain to a
Packit 47b4ca
single machine--that is to say, files for configuring a host.  Mailer
Packit 47b4ca
and network configuration files, @file{/etc/passwd}, and so forth belong
Packit 47b4ca
here.  All the files in this directory should be ordinary ASCII text
Packit 47b4ca
files.  This directory should normally be @file{/usr/local/etc}, but
Packit 47b4ca
write it as @file{$(prefix)/etc}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@sysconfdir@@}.)
Packit 47b4ca
Packit 47b4ca
Do not install executables here in this directory (they probably belong
Packit 47b4ca
in @file{$(libexecdir)} or @file{$(sbindir)}).  Also do not install
Packit 47b4ca
files that are modified in the normal course of their use (programs
Packit 47b4ca
whose purpose is to change the configuration of the system excluded).
Packit 47b4ca
Those probably belong in @file{$(localstatedir)}.
Packit 47b4ca
Packit 47b4ca
@item sharedstatedir
Packit 47b4ca
The directory for installing architecture-independent data files which
Packit 47b4ca
the programs modify while they run.  This should normally be
Packit 47b4ca
@file{/usr/local/com}, but write it as @file{$(prefix)/com}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@sharedstatedir@@}.)
Packit 47b4ca
Packit 47b4ca
@item localstatedir
Packit 47b4ca
The directory for installing data files which the programs modify while
Packit 47b4ca
they run, and that pertain to one specific machine.  Users should never
Packit 47b4ca
need to modify files in this directory to configure the package's
Packit 47b4ca
operation; put such configuration information in separate files that go
Packit 47b4ca
in @file{$(datadir)} or @file{$(sysconfdir)}.  @file{$(localstatedir)}
Packit 47b4ca
should normally be @file{/usr/local/var}, but write it as
Packit 47b4ca
@file{$(prefix)/var}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@localstatedir@@}.)
Packit 47b4ca
@end table
Packit 47b4ca
Packit 47b4ca
These variables specify the directory for installing certain specific
Packit 47b4ca
types of files, if your program has them.  Every GNU package should
Packit 47b4ca
have Info files, so every program needs @samp{infodir}, but not all
Packit 47b4ca
need @samp{libdir} or @samp{lispdir}.
Packit 47b4ca
Packit 47b4ca
@table @samp
Packit 47b4ca
@item includedir
Packit 47b4ca
The directory for installing header files to be included by user
Packit 47b4ca
programs with the C @samp{#include} preprocessor directive.  This
Packit 47b4ca
should normally be @file{/usr/local/include}, but write it as
Packit 47b4ca
@file{$(prefix)/include}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@includedir@@}.)
Packit 47b4ca
Packit 47b4ca
Most compilers other than GCC do not look for header files in directory
Packit 47b4ca
@file{/usr/local/include}.  So installing the header files this way is
Packit 47b4ca
only useful with GCC.  Sometimes this is not a problem because some
Packit 47b4ca
libraries are only really intended to work with GCC.  But some libraries
Packit 47b4ca
are intended to work with other compilers.  They should install their
Packit 47b4ca
header files in two places, one specified by @code{includedir} and one
Packit 47b4ca
specified by @code{oldincludedir}.
Packit 47b4ca
Packit 47b4ca
@item oldincludedir
Packit 47b4ca
The directory for installing @samp{#include} header files for use with
Packit 47b4ca
compilers other than GCC.  This should normally be @file{/usr/include}.
Packit 47b4ca
(If you are using Autoconf, you can write it as @samp{@@oldincludedir@@}.)
Packit 47b4ca
Packit 47b4ca
The Makefile commands should check whether the value of
Packit 47b4ca
@code{oldincludedir} is empty.  If it is, they should not try to use
Packit 47b4ca
it; they should cancel the second installation of the header files.
Packit 47b4ca
Packit 47b4ca
A package should not replace an existing header in this directory unless
Packit 47b4ca
the header came from the same package.  Thus, if your Foo package
Packit 47b4ca
provides a header file @file{foo.h}, then it should install the header
Packit 47b4ca
file in the @code{oldincludedir} directory if either (1) there is no
Packit 47b4ca
@file{foo.h} there or (2) the @file{foo.h} that exists came from the Foo
Packit 47b4ca
package.
Packit 47b4ca
Packit 47b4ca
To tell whether @file{foo.h} came from the Foo package, put a magic
Packit 47b4ca
string in the file---part of a comment---and @code{grep} for that string.
Packit 47b4ca
Packit 47b4ca
@item docdir
Packit 47b4ca
The directory for installing documentation files (other than Info) for
Packit 47b4ca
this package.  By default, it should be
Packit 47b4ca
@file{/usr/local/share/doc/@var{yourpkg}}, but it should be written as
Packit 47b4ca
@file{$(datarootdir)/doc/@var{yourpkg}}.  (If you are using Autoconf,
Packit 47b4ca
write it as @samp{@@docdir@@}.)  The @var{yourpkg} subdirectory, which
Packit 47b4ca
may include a version number, prevents collisions among files with
Packit 47b4ca
common names, such as @file{README}.
Packit 47b4ca
Packit 47b4ca
@item infodir
Packit 47b4ca
The directory for installing the Info files for this package.  By
Packit 47b4ca
default, it should be @file{/usr/local/share/info}, but it should be
Packit 47b4ca
written as @file{$(datarootdir)/info}.  (If you are using Autoconf,
Packit 47b4ca
write it as @samp{@@infodir@@}.)  @code{infodir} is separate from
Packit 47b4ca
@code{docdir} for compatibility with existing practice.
Packit 47b4ca
Packit 47b4ca
@item htmldir
Packit 47b4ca
@itemx dvidir
Packit 47b4ca
@itemx pdfdir
Packit 47b4ca
@itemx psdir
Packit 47b4ca
Directories for installing documentation files in the particular
Packit 47b4ca
format.  They should all be set to @code{$(docdir)} by default.  (If
Packit 47b4ca
you are using Autoconf, write them as @samp{@@htmldir@@},
Packit 47b4ca
@samp{@@dvidir@@}, etc.)  Packages which supply several translations
Packit 47b4ca
of their documentation should install them in
Packit 47b4ca
@samp{$(htmldir)/}@var{ll}, @samp{$(pdfdir)/}@var{ll}, etc. where
Packit 47b4ca
@var{ll} is a locale abbreviation such as @samp{en} or @samp{pt_BR}.
Packit 47b4ca
Packit 47b4ca
@item libdir
Packit 47b4ca
The directory for object files and libraries of object code.  Do not
Packit 47b4ca
install executables here, they probably ought to go in @file{$(libexecdir)}
Packit 47b4ca
instead.  The value of @code{libdir} should normally be
Packit 47b4ca
@file{/usr/local/lib}, but write it as @file{$(exec_prefix)/lib}.
Packit 47b4ca
(If you are using Autoconf, write it as @samp{@@libdir@@}.)
Packit 47b4ca
Packit 47b4ca
@item lispdir
Packit 47b4ca
The directory for installing any Emacs Lisp files in this package.  By
Packit 47b4ca
default, it should be @file{/usr/local/share/emacs/site-lisp}, but it
Packit 47b4ca
should be written as @file{$(datarootdir)/emacs/site-lisp}.
Packit 47b4ca
Packit 47b4ca
If you are using Autoconf, write the default as @samp{@@lispdir@@}.
Packit 47b4ca
In order to make @samp{@@lispdir@@} work, you need the following lines
Packit 47b4ca
in your @file{configure.in} file:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
lispdir='$@{datarootdir@}/emacs/site-lisp'
Packit 47b4ca
AC_SUBST(lispdir)
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
@item localedir
Packit 47b4ca
The directory for installing locale-specific message catalogs for this
Packit 47b4ca
package.  By default, it should be @file{/usr/local/share/locale}, but
Packit 47b4ca
it should be written as @file{$(datarootdir)/locale}.  (If you are
Packit 47b4ca
using Autoconf, write it as @samp{@@localedir@@}.)  This directory
Packit 47b4ca
usually has a subdirectory per locale.
Packit 47b4ca
@end table
Packit 47b4ca
Packit 47b4ca
Unix-style man pages are installed in one of the following:
Packit 47b4ca
Packit 47b4ca
@table @samp
Packit 47b4ca
@item mandir
Packit 47b4ca
The top-level directory for installing the man pages (if any) for this
Packit 47b4ca
package.  It will normally be @file{/usr/local/share/man}, but you
Packit 47b4ca
should write it as @file{$(datarootdir)/man}.  (If you are using
Packit 47b4ca
Autoconf, write it as @samp{@@mandir@@}.)
Packit 47b4ca
Packit 47b4ca
@item man1dir
Packit 47b4ca
The directory for installing section 1 man pages.  Write it as
Packit 47b4ca
@file{$(mandir)/man1}.
Packit 47b4ca
@item man2dir
Packit 47b4ca
The directory for installing section 2 man pages.  Write it as
Packit 47b4ca
@file{$(mandir)/man2}
Packit 47b4ca
@item @dots{}
Packit 47b4ca
Packit 47b4ca
@strong{Don't make the primary documentation for any GNU software be a
Packit 47b4ca
man page.  Write a manual in Texinfo instead.  Man pages are just for
Packit 47b4ca
the sake of people running GNU software on Unix, which is a secondary
Packit 47b4ca
application only.}
Packit 47b4ca
Packit 47b4ca
@item manext
Packit 47b4ca
The file name extension for the installed man page.  This should contain
Packit 47b4ca
a period followed by the appropriate digit; it should normally be @samp{.1}.
Packit 47b4ca
Packit 47b4ca
@item man1ext
Packit 47b4ca
The file name extension for installed section 1 man pages.
Packit 47b4ca
@item man2ext
Packit 47b4ca
The file name extension for installed section 2 man pages.
Packit 47b4ca
@item @dots{}
Packit 47b4ca
Use these names instead of @samp{manext} if the package needs to install man
Packit 47b4ca
pages in more than one section of the manual.
Packit 47b4ca
@end table
Packit 47b4ca
Packit 47b4ca
And finally, you should set the following variable:
Packit 47b4ca
Packit 47b4ca
@table @samp
Packit 47b4ca
@item srcdir
Packit 47b4ca
The directory for the sources being compiled.  The value of this
Packit 47b4ca
variable is normally inserted by the @code{configure} shell script.
Packit 47b4ca
(If you are using Autoconf, use @samp{srcdir = @@srcdir@@}.)
Packit 47b4ca
@end table
Packit 47b4ca
Packit 47b4ca
For example:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
@c I have changed some of the comments here slightly to fix an overfull
Packit 47b4ca
@c hbox, so the make manual can format correctly. --roland
Packit 47b4ca
# Common prefix for installation directories.
Packit 47b4ca
# NOTE: This directory must exist when you start the install.
Packit 47b4ca
prefix = /usr/local
Packit 47b4ca
datarootdir = $(prefix)/share
Packit 47b4ca
datadir = $(datarootdir)
Packit 47b4ca
exec_prefix = $(prefix)
Packit 47b4ca
# Where to put the executable for the command `gcc'.
Packit 47b4ca
bindir = $(exec_prefix)/bin
Packit 47b4ca
# Where to put the directories used by the compiler.
Packit 47b4ca
libexecdir = $(exec_prefix)/libexec
Packit 47b4ca
# Where to put the Info files.
Packit 47b4ca
infodir = $(datarootdir)/info
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
If your program installs a large number of files into one of the
Packit 47b4ca
standard user-specified directories, it might be useful to group them
Packit 47b4ca
into a subdirectory particular to that program.  If you do this, you
Packit 47b4ca
should write the @code{install} rule to create these subdirectories.
Packit 47b4ca
Packit 47b4ca
Do not expect the user to include the subdirectory name in the value of
Packit 47b4ca
any of the variables listed above.  The idea of having a uniform set of
Packit 47b4ca
variable names for installation directories is to enable the user to
Packit 47b4ca
specify the exact same values for several different GNU packages.  In
Packit 47b4ca
order for this to be useful, all the packages must be designed so that
Packit 47b4ca
they will work sensibly when the user does so.
Packit 47b4ca
Packit 47b4ca
At times, not all of these variables may be implemented in the current
Packit 47b4ca
release of Autoconf and/or Automake; but as of Autoconf@tie{}2.60, we
Packit 47b4ca
believe all of them are.  When any are missing, the descriptions here
Packit 47b4ca
serve as specifications for what Autoconf will implement.  As a
Packit 47b4ca
programmer, you can either use a development version of Autoconf or
Packit 47b4ca
avoid using these variables until a stable release is made which
Packit 47b4ca
supports them.
Packit 47b4ca
Packit 47b4ca
Packit 47b4ca
@node Standard Targets
Packit 47b4ca
@section Standard Targets for Users
Packit 47b4ca
Packit 47b4ca
All GNU programs should have the following targets in their Makefiles:
Packit 47b4ca
Packit 47b4ca
@table @samp
Packit 47b4ca
@item all
Packit 47b4ca
Compile the entire program.  This should be the default target.  This
Packit 47b4ca
target need not rebuild any documentation files; Info files should
Packit 47b4ca
normally be included in the distribution, and DVI (and other
Packit 47b4ca
documentation format) files should be made only when explicitly asked
Packit 47b4ca
for.
Packit 47b4ca
Packit 47b4ca
By default, the Make rules should compile and link with @samp{-g}, so
Packit 47b4ca
that executable programs have debugging symbols.  Otherwise, you are
Packit 47b4ca
essentially helpless in the face of a crash, and it is often far from
Packit 47b4ca
easy to reproduce with a fresh build.
Packit 47b4ca
Packit 47b4ca
@item install
Packit 47b4ca
Compile the program and copy the executables, libraries, and so on to
Packit 47b4ca
the file names where they should reside for actual use.  If there is a
Packit 47b4ca
simple test to verify that a program is properly installed, this target
Packit 47b4ca
should run that test.
Packit 47b4ca
Packit 47b4ca
Do not strip executables when installing them.  This helps eventual
Packit 47b4ca
debugging that may be needed later, and nowadays disk space is cheap
Packit 47b4ca
and dynamic loaders typically ensure debug sections are not loaded during
Packit 47b4ca
normal execution.  Users that need stripped binaries may invoke the
Packit 47b4ca
@code{install-strip} target to do that.
Packit 47b4ca
Packit 47b4ca
If possible, write the @code{install} target rule so that it does not
Packit 47b4ca
modify anything in the directory where the program was built, provided
Packit 47b4ca
@samp{make all} has just been done.  This is convenient for building the
Packit 47b4ca
program under one user name and installing it under another.
Packit 47b4ca
Packit 47b4ca
The commands should create all the directories in which files are to be
Packit 47b4ca
installed, if they don't already exist.  This includes the directories
Packit 47b4ca
specified as the values of the variables @code{prefix} and
Packit 47b4ca
@code{exec_prefix}, as well as all subdirectories that are needed.
Packit 47b4ca
One way to do this is by means of an @code{installdirs} target
Packit 47b4ca
as described below.
Packit 47b4ca
Packit 47b4ca
Use @samp{-} before any command for installing a man page, so that
Packit 47b4ca
@code{make} will ignore any errors.  This is in case there are systems
Packit 47b4ca
that don't have the Unix man page documentation system installed.
Packit 47b4ca
Packit 47b4ca
The way to install Info files is to copy them into @file{$(infodir)}
Packit 47b4ca
with @code{$(INSTALL_DATA)} (@pxref{Command Variables}), and then run
Packit 47b4ca
the @code{install-info} program if it is present.  @code{install-info}
Packit 47b4ca
is a program that edits the Info @file{dir} file to add or update the
Packit 47b4ca
menu entry for the given Info file; it is part of the Texinfo package.
Packit 47b4ca
Packit 47b4ca
Here is a sample rule to install an Info file that also tries to
Packit 47b4ca
handle some additional situations, such as @code{install-info} not
Packit 47b4ca
being present.
Packit 47b4ca
Packit 47b4ca
@comment This example has been carefully formatted for the Make manual.
Packit 47b4ca
@comment Please do not reformat it without talking to bug-make@gnu.org.
Packit 47b4ca
@smallexample
Packit 47b4ca
do-install-info: foo.info installdirs
Packit 47b4ca
        $(NORMAL_INSTALL)
Packit 47b4ca
# Prefer an info file in . to one in srcdir.
Packit 47b4ca
        if test -f foo.info; then d=.; \
Packit 47b4ca
         else d="$(srcdir)"; fi; \
Packit 47b4ca
        $(INSTALL_DATA) $$d/foo.info \
Packit 47b4ca
          "$(DESTDIR)$(infodir)/foo.info"
Packit 47b4ca
# Run install-info only if it exists.
Packit 47b4ca
# Use `if' instead of just prepending `-' to the
Packit 47b4ca
# line so we notice real errors from install-info.
Packit 47b4ca
# Use `$(SHELL) -c' because some shells do not
Packit 47b4ca
# fail gracefully when there is an unknown command.
Packit 47b4ca
        $(POST_INSTALL)
Packit 47b4ca
        if $(SHELL) -c 'install-info --version' \
Packit 47b4ca
           >/dev/null 2>&1; then \
Packit 47b4ca
          install-info --dir-file="$(DESTDIR)$(infodir)/dir" \
Packit 47b4ca
                       "$(DESTDIR)$(infodir)/foo.info"; \
Packit 47b4ca
        else true; fi
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
When writing the @code{install} target, you must classify all the
Packit 47b4ca
commands into three categories: normal ones, @dfn{pre-installation}
Packit 47b4ca
commands and @dfn{post-installation} commands.  @xref{Install Command
Packit 47b4ca
Categories}.
Packit 47b4ca
Packit 47b4ca
@item install-html
Packit 47b4ca
@itemx install-dvi
Packit 47b4ca
@itemx install-pdf
Packit 47b4ca
@itemx install-ps
Packit 47b4ca
These targets install documentation in formats other than Info;
Packit 47b4ca
they're intended to be called explicitly by the person installing the
Packit 47b4ca
package, if that format is desired.  GNU prefers Info files, so these
Packit 47b4ca
must be installed by the @code{install} target.
Packit 47b4ca
Packit 47b4ca
When you have many documentation files to install, we recommend that
Packit 47b4ca
you avoid collisions and clutter by arranging for these targets to
Packit 47b4ca
install in subdirectories of the appropriate installation directory,
Packit 47b4ca
such as @code{htmldir}.  As one example, if your package has multiple
Packit 47b4ca
manuals, and you wish to install HTML documentation with many files
Packit 47b4ca
(such as the ``split'' mode output by @code{makeinfo --html}), you'll
Packit 47b4ca
certainly want to use subdirectories, or two nodes with the same name
Packit 47b4ca
in different manuals will overwrite each other.
Packit 47b4ca
Packit 47b4ca
Please make these @code{install-@var{format}} targets invoke the
Packit 47b4ca
commands for the @var{format} target, for example, by making
Packit 47b4ca
@var{format} a dependency.
Packit 47b4ca
Packit 47b4ca
@item uninstall
Packit 47b4ca
Delete all the installed files---the copies that the @samp{install}
Packit 47b4ca
and @samp{install-*} targets create.
Packit 47b4ca
Packit 47b4ca
This rule should not modify the directories where compilation is done,
Packit 47b4ca
only the directories where files are installed.
Packit 47b4ca
Packit 47b4ca
The uninstallation commands are divided into three categories, just like
Packit 47b4ca
the installation commands.  @xref{Install Command Categories}.
Packit 47b4ca
Packit 47b4ca
@item install-strip
Packit 47b4ca
Like @code{install}, but strip the executable files while installing
Packit 47b4ca
them.  In simple cases, this target can use the @code{install} target in
Packit 47b4ca
a simple way:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
install-strip:
Packit 47b4ca
        $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
Packit 47b4ca
                install
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
But if the package installs scripts as well as real executables, the
Packit 47b4ca
@code{install-strip} target can't just refer to the @code{install}
Packit 47b4ca
target; it has to strip the executables but not the scripts.
Packit 47b4ca
Packit 47b4ca
@code{install-strip} should not strip the executables in the build
Packit 47b4ca
directory which are being copied for installation.  It should only strip
Packit 47b4ca
the copies that are installed.
Packit 47b4ca
Packit 47b4ca
Normally we do not recommend stripping an executable unless you are sure
Packit 47b4ca
the program has no bugs.  However, it can be reasonable to install a
Packit 47b4ca
stripped executable for actual execution while saving the unstripped
Packit 47b4ca
executable elsewhere in case there is a bug.
Packit 47b4ca
Packit 47b4ca
@item clean
Packit 47b4ca
Delete all files in the current directory that are normally created by
Packit 47b4ca
building the program.  Also delete files in other directories if they
Packit 47b4ca
are created by this makefile.  However, don't delete the files that
Packit 47b4ca
record the configuration.  Also preserve files that could be made by
Packit 47b4ca
building, but normally aren't because the distribution comes with
Packit 47b4ca
them.  There is no need to delete parent directories that were created
Packit 47b4ca
with @samp{mkdir -p}, since they could have existed anyway.
Packit 47b4ca
Packit 47b4ca
Delete @file{.dvi} files here if they are not part of the distribution.
Packit 47b4ca
Packit 47b4ca
@item distclean
Packit 47b4ca
Delete all files in the current directory (or created by this
Packit 47b4ca
makefile) that are created by configuring or building the program.  If
Packit 47b4ca
you have unpacked the source and built the program without creating
Packit 47b4ca
any other files, @samp{make distclean} should leave only the files
Packit 47b4ca
that were in the distribution.  However, there is no need to delete
Packit 47b4ca
parent directories that were created with @samp{mkdir -p}, since they
Packit 47b4ca
could have existed anyway.
Packit 47b4ca
Packit 47b4ca
@item mostlyclean
Packit 47b4ca
Like @samp{clean}, but may refrain from deleting a few files that people
Packit 47b4ca
normally don't want to recompile.  For example, the @samp{mostlyclean}
Packit 47b4ca
target for GCC does not delete @file{libgcc.a}, because recompiling it
Packit 47b4ca
is rarely necessary and takes a lot of time.
Packit 47b4ca
Packit 47b4ca
@item maintainer-clean
Packit 47b4ca
Delete almost everything that can be reconstructed with this Makefile.
Packit 47b4ca
This typically includes everything deleted by @code{distclean}, plus
Packit 47b4ca
more: C source files produced by Bison, tags tables, Info files, and
Packit 47b4ca
so on.
Packit 47b4ca
Packit 47b4ca
The reason we say ``almost everything'' is that running the command
Packit 47b4ca
@samp{make maintainer-clean} should not delete @file{configure} even
Packit 47b4ca
if @file{configure} can be remade using a rule in the Makefile.  More
Packit 47b4ca
generally, @samp{make maintainer-clean} should not delete anything
Packit 47b4ca
that needs to exist in order to run @file{configure} and then begin to
Packit 47b4ca
build the program.  Also, there is no need to delete parent
Packit 47b4ca
directories that were created with @samp{mkdir -p}, since they could
Packit 47b4ca
have existed anyway.  These are the only exceptions;
Packit 47b4ca
@code{maintainer-clean} should delete everything else that can be
Packit 47b4ca
rebuilt.
Packit 47b4ca
Packit 47b4ca
The @samp{maintainer-clean} target is intended to be used by a maintainer of
Packit 47b4ca
the package, not by ordinary users.  You may need special tools to
Packit 47b4ca
reconstruct some of the files that @samp{make maintainer-clean} deletes.
Packit 47b4ca
Since these files are normally included in the distribution, we don't
Packit 47b4ca
take care to make them easy to reconstruct.  If you find you need to
Packit 47b4ca
unpack the full distribution again, don't blame us.
Packit 47b4ca
Packit 47b4ca
To help make users aware of this, the commands for the special
Packit 47b4ca
@code{maintainer-clean} target should start with these two:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
@@echo 'This command is intended for maintainers to use; it'
Packit 47b4ca
@@echo 'deletes files that may need special tools to rebuild.'
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@item TAGS
Packit 47b4ca
Update a tags table for this program.
Packit 47b4ca
@c ADR: how?
Packit 47b4ca
Packit 47b4ca
@item info
Packit 47b4ca
Generate any Info files needed.  The best way to write the rules is as
Packit 47b4ca
follows:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
info: foo.info
Packit 47b4ca
Packit 47b4ca
foo.info: foo.texi chap1.texi chap2.texi
Packit 47b4ca
        $(MAKEINFO) $(srcdir)/foo.texi
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
You must define the variable @code{MAKEINFO} in the Makefile.  It should
Packit 47b4ca
run the @code{makeinfo} program, which is part of the Texinfo
Packit 47b4ca
distribution.
Packit 47b4ca
Packit 47b4ca
Normally a GNU distribution comes with Info files, and that means the
Packit 47b4ca
Info files are present in the source directory.  Therefore, the Make
Packit 47b4ca
rule for an info file should update it in the source directory.  When
Packit 47b4ca
users build the package, ordinarily Make will not update the Info files
Packit 47b4ca
because they will already be up to date.
Packit 47b4ca
Packit 47b4ca
@item dvi
Packit 47b4ca
@itemx html
Packit 47b4ca
@itemx pdf
Packit 47b4ca
@itemx ps
Packit 47b4ca
Generate documentation files in the given format.  These targets
Packit 47b4ca
should always exist, but any or all can be a no-op if the given output
Packit 47b4ca
format cannot be generated.  These targets should not be dependencies
Packit 47b4ca
of the @code{all} target; the user must manually invoke them.
Packit 47b4ca
Packit 47b4ca
Here's an example rule for generating DVI files from Texinfo:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
dvi: foo.dvi
Packit 47b4ca
Packit 47b4ca
foo.dvi: foo.texi chap1.texi chap2.texi
Packit 47b4ca
        $(TEXI2DVI) $(srcdir)/foo.texi
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
You must define the variable @code{TEXI2DVI} in the Makefile.  It
Packit 47b4ca
should run the program @code{texi2dvi}, which is part of the Texinfo
Packit 47b4ca
distribution.  (@code{texi2dvi} uses @TeX{} to do the real work of
Packit 47b4ca
formatting. @TeX{} is not distributed with Texinfo.)  Alternatively,
Packit 47b4ca
write only the dependencies, and allow GNU @code{make} to provide the
Packit 47b4ca
command.
Packit 47b4ca
Packit 47b4ca
Here's another example, this one for generating HTML from Texinfo:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
html: foo.html
Packit 47b4ca
Packit 47b4ca
foo.html: foo.texi chap1.texi chap2.texi
Packit 47b4ca
        $(TEXI2HTML) $(srcdir)/foo.texi
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
Again, you would define the variable @code{TEXI2HTML} in the Makefile;
Packit 47b4ca
for example, it might run @code{makeinfo --no-split --html}
Packit 47b4ca
(@command{makeinfo} is part of the Texinfo distribution).
Packit 47b4ca
Packit 47b4ca
@item dist
Packit 47b4ca
Create a distribution tar file for this program.  The tar file should be
Packit 47b4ca
set up so that the file names in the tar file start with a subdirectory
Packit 47b4ca
name which is the name of the package it is a distribution for.  This
Packit 47b4ca
name can include the version number.
Packit 47b4ca
Packit 47b4ca
For example, the distribution tar file of GCC version 1.40 unpacks into
Packit 47b4ca
a subdirectory named @file{gcc-1.40}.
Packit 47b4ca
Packit 47b4ca
The easiest way to do this is to create a subdirectory appropriately
Packit 47b4ca
named, use @code{ln} or @code{cp} to install the proper files in it, and
Packit 47b4ca
then @code{tar} that subdirectory.
Packit 47b4ca
Packit 47b4ca
Compress the tar file with @code{gzip}.  For example, the actual
Packit 47b4ca
distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}.
Packit 47b4ca
It is ok to support other free compression formats as well.
Packit 47b4ca
Packit 47b4ca
The @code{dist} target should explicitly depend on all non-source files
Packit 47b4ca
that are in the distribution, to make sure they are up to date in the
Packit 47b4ca
distribution.
Packit 47b4ca
@ifset CODESTD
Packit 47b4ca
@xref{Releases, , Making Releases}.
Packit 47b4ca
@end ifset
Packit 47b4ca
@ifclear CODESTD
Packit 47b4ca
@xref{Releases, , Making Releases, standards, GNU Coding Standards}.
Packit 47b4ca
@end ifclear
Packit 47b4ca
Packit 47b4ca
@item check
Packit 47b4ca
Perform self-tests (if any).  The user must build the program before
Packit 47b4ca
running the tests, but need not install the program; you should write
Packit 47b4ca
the self-tests so that they work when the program is built but not
Packit 47b4ca
installed.
Packit 47b4ca
@end table
Packit 47b4ca
Packit 47b4ca
The following targets are suggested as conventional names, for programs
Packit 47b4ca
in which they are useful.
Packit 47b4ca
Packit 47b4ca
@table @code
Packit 47b4ca
@item installcheck
Packit 47b4ca
Perform installation tests (if any).  The user must build and install
Packit 47b4ca
the program before running the tests.  You should not assume that
Packit 47b4ca
@file{$(bindir)} is in the search path.
Packit 47b4ca
Packit 47b4ca
@item installdirs
Packit 47b4ca
It's useful to add a target named @samp{installdirs} to create the
Packit 47b4ca
directories where files are installed, and their parent directories.
Packit 47b4ca
There is a script called @file{mkinstalldirs} which is convenient for
Packit 47b4ca
this; you can find it in the Gnulib package.
Packit 47b4ca
You can use a rule like this:
Packit 47b4ca
Packit 47b4ca
@comment This has been carefully formatted to look decent in the Make manual.
Packit 47b4ca
@comment Please be sure not to make it extend any further to the right.--roland
Packit 47b4ca
@smallexample
Packit 47b4ca
# Make sure all installation directories (e.g. $(bindir))
Packit 47b4ca
# actually exist by making them if necessary.
Packit 47b4ca
installdirs: mkinstalldirs
Packit 47b4ca
        $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
Packit 47b4ca
                                $(libdir) $(infodir) \
Packit 47b4ca
                                $(mandir)
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
or, if you wish to support @env{DESTDIR} (strongly encouraged),
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
# Make sure all installation directories (e.g. $(bindir))
Packit 47b4ca
# actually exist by making them if necessary.
Packit 47b4ca
installdirs: mkinstalldirs
Packit 47b4ca
        $(srcdir)/mkinstalldirs \
Packit 47b4ca
            $(DESTDIR)$(bindir) $(DESTDIR)$(datadir) \
Packit 47b4ca
            $(DESTDIR)$(libdir) $(DESTDIR)$(infodir) \
Packit 47b4ca
            $(DESTDIR)$(mandir)
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
This rule should not modify the directories where compilation is done.
Packit 47b4ca
It should do nothing but create installation directories.
Packit 47b4ca
@end table
Packit 47b4ca
Packit 47b4ca
@node Install Command Categories
Packit 47b4ca
@section Install Command Categories
Packit 47b4ca
Packit 47b4ca
@cindex pre-installation commands
Packit 47b4ca
@cindex post-installation commands
Packit 47b4ca
When writing the @code{install} target, you must classify all the
Packit 47b4ca
commands into three categories: normal ones, @dfn{pre-installation}
Packit 47b4ca
commands and @dfn{post-installation} commands.
Packit 47b4ca
Packit 47b4ca
Normal commands move files into their proper places, and set their
Packit 47b4ca
modes.  They may not alter any files except the ones that come entirely
Packit 47b4ca
from the package they belong to.
Packit 47b4ca
Packit 47b4ca
Pre-installation and post-installation commands may alter other files;
Packit 47b4ca
in particular, they can edit global configuration files or data bases.
Packit 47b4ca
Packit 47b4ca
Pre-installation commands are typically executed before the normal
Packit 47b4ca
commands, and post-installation commands are typically run after the
Packit 47b4ca
normal commands.
Packit 47b4ca
Packit 47b4ca
The most common use for a post-installation command is to run
Packit 47b4ca
@code{install-info}.  This cannot be done with a normal command, since
Packit 47b4ca
it alters a file (the Info directory) which does not come entirely and
Packit 47b4ca
solely from the package being installed.  It is a post-installation
Packit 47b4ca
command because it needs to be done after the normal command which
Packit 47b4ca
installs the package's Info files.
Packit 47b4ca
Packit 47b4ca
Most programs don't need any pre-installation commands, but we have the
Packit 47b4ca
feature just in case it is needed.
Packit 47b4ca
Packit 47b4ca
To classify the commands in the @code{install} rule into these three
Packit 47b4ca
categories, insert @dfn{category lines} among them.  A category line
Packit 47b4ca
specifies the category for the commands that follow.
Packit 47b4ca
Packit 47b4ca
A category line consists of a tab and a reference to a special Make
Packit 47b4ca
variable, plus an optional comment at the end.  There are three
Packit 47b4ca
variables you can use, one for each category; the variable name
Packit 47b4ca
specifies the category.  Category lines are no-ops in ordinary execution
Packit 47b4ca
because these three Make variables are normally undefined (and you
Packit 47b4ca
@emph{should not} define them in the makefile).
Packit 47b4ca
Packit 47b4ca
Here are the three possible category lines, each with a comment that
Packit 47b4ca
explains what it means:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
        $(PRE_INSTALL)     # @r{Pre-install commands follow.}
Packit 47b4ca
        $(POST_INSTALL)    # @r{Post-install commands follow.}
Packit 47b4ca
        $(NORMAL_INSTALL)  # @r{Normal commands follow.}
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
If you don't use a category line at the beginning of the @code{install}
Packit 47b4ca
rule, all the commands are classified as normal until the first category
Packit 47b4ca
line.  If you don't use any category lines, all the commands are
Packit 47b4ca
classified as normal.
Packit 47b4ca
Packit 47b4ca
These are the category lines for @code{uninstall}:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
        $(PRE_UNINSTALL)     # @r{Pre-uninstall commands follow.}
Packit 47b4ca
        $(POST_UNINSTALL)    # @r{Post-uninstall commands follow.}
Packit 47b4ca
        $(NORMAL_UNINSTALL)  # @r{Normal commands follow.}
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
Typically, a pre-uninstall command would be used for deleting entries
Packit 47b4ca
from the Info directory.
Packit 47b4ca
Packit 47b4ca
If the @code{install} or @code{uninstall} target has any dependencies
Packit 47b4ca
which act as subroutines of installation, then you should start
Packit 47b4ca
@emph{each} dependency's commands with a category line, and start the
Packit 47b4ca
main target's commands with a category line also.  This way, you can
Packit 47b4ca
ensure that each command is placed in the right category regardless of
Packit 47b4ca
which of the dependencies actually run.
Packit 47b4ca
Packit 47b4ca
Pre-installation and post-installation commands should not run any
Packit 47b4ca
programs except for these:
Packit 47b4ca
Packit 47b4ca
@example
Packit 47b4ca
[ basename bash cat chgrp chmod chown cmp cp dd diff echo
Packit 47b4ca
egrep expand expr false fgrep find getopt grep gunzip gzip
Packit 47b4ca
hostname install install-info kill ldconfig ln ls md5sum
Packit 47b4ca
mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
Packit 47b4ca
test touch true uname xargs yes
Packit 47b4ca
@end example
Packit 47b4ca
Packit 47b4ca
@cindex binary packages
Packit 47b4ca
The reason for distinguishing the commands in this way is for the sake
Packit 47b4ca
of making binary packages.  Typically a binary package contains all the
Packit 47b4ca
executables and other files that need to be installed, and has its own
Packit 47b4ca
method of installing them---so it does not need to run the normal
Packit 47b4ca
installation commands.  But installing the binary package does need to
Packit 47b4ca
execute the pre-installation and post-installation commands.
Packit 47b4ca
Packit 47b4ca
Programs to build binary packages work by extracting the
Packit 47b4ca
pre-installation and post-installation commands.  Here is one way of
Packit 47b4ca
extracting the pre-installation commands (the @option{-s} option to
Packit 47b4ca
@command{make} is needed to silence messages about entering
Packit 47b4ca
subdirectories):
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
make -s -n install -o all \
Packit 47b4ca
      PRE_INSTALL=pre-install \
Packit 47b4ca
      POST_INSTALL=post-install \
Packit 47b4ca
      NORMAL_INSTALL=normal-install \
Packit 47b4ca
  | gawk -f pre-install.awk
Packit 47b4ca
@end smallexample
Packit 47b4ca
Packit 47b4ca
@noindent
Packit 47b4ca
where the file @file{pre-install.awk} could contain this:
Packit 47b4ca
Packit 47b4ca
@smallexample
Packit 47b4ca
$0 ~ /^(normal-install|post-install)[ \t]*$/ @{on = 0@}
Packit 47b4ca
on @{print $0@}
Packit 47b4ca
$0 ~ /^pre-install[ \t]*$/ @{on = 1@}
Packit 47b4ca
@end smallexample