‘install-dvi’ ‘install-pdf’ ‘install-ps’
These targets install documentation in formats other than Info; they’re intended to be called explicitly by the person installing the package, if that format is desired. GNU prefers Info files, so these must be installed by the install target.
When you have many documentation files to install, we recommend that you avoid collisions and clutter by arranging for these targets to install in subdi- rectories of the appropriate installation directory, such as htmldir. As one example, if your package has multiple manuals, and you wish to install HTML documentation with many files (such as the “split” mode output by makeinfo --html), you’ll certainly want to use subdirectories, or two nodes with the same name in different manuals will overwrite each other.
Please make theseinstall-formattargets invoke the commands for theformat
target, for example, by making format a dependency. ‘uninstall’
Delete all the installed files—the copies that the ‘install’ and ‘install-*’ targets create.
This rule should not modify the directories where compilation is done, only the directories where files are installed.
The uninstallation commands are divided into three categories, just like the in- stallation commands. SeeSection 15.7 [Install Command Categories], page 162. ‘install-strip’
Like install, but strip the executable files while installing them. In simple
cases, this target can use the installtarget in a simple way: install-strip:
$(MAKE) INSTALL_PROGRAM=’$(INSTALL_PROGRAM) -s’ \ install
But if the package installs scripts as well as real executables, theinstall-strip target can’t just refer to theinstall target; it has to strip the executables but not the scripts.
install-stripshould not strip the executables in the build directory which are
being copied for installation. It should only strip the copies that are installed. Normally we do not recommend stripping an executable unless you are sure the program has no bugs. However, it can be reasonable to install a stripped exe- cutable for actual execution while saving the unstripped executable elsewhere in case there is a bug.
‘clean’ Delete all files in the current directory that are normally created by building the program. Also delete files in other directories if they are created by this makefile. However, don’t delete the files that record the configuration. Also preserve files that could be made by building, but normally aren’t because the distribution comes with them. There is no need to delete parent directories that were created with ‘mkdir -p’, since they could have existed anyway. Delete .dvi files here if they are not part of the distribution.
‘distclean’
Delete all files in the current directory (or created by this makefile) that are created by configuring or building the program. If you have unpacked the source and built the program without creating any other files, ‘make distclean’ should leave only the files that were in the distribution. However, there is no need to delete parent directories that were created with ‘mkdir -p’, since they could have existed anyway.
‘mostlyclean’
Like ‘clean’, but may refrain from deleting a few files that people normally don’t want to recompile. For example, the ‘mostlyclean’ target for GCC does not delete libgcc.a, because recompiling it is rarely necessary and takes a lot of time.
‘maintainer-clean’
Delete almost everything that can be reconstructed with this Makefile. This typically includes everything deleted by distclean, plus more: C source files produced by Bison, tags tables, Info files, and so on.
The reason we say “almost everything” is that running the command ‘make
maintainer-clean’ should not deleteconfigureeven if configurecan be re-
made using a rule in the Makefile. More generally, ‘make maintainer-clean’ should not delete anything that needs to exist in order to run configure and then begin to build the program. Also, there is no need to delete parent direc- tories that were created with ‘mkdir -p’, since they could have existed anyway. These are the only exceptions;maintainer-cleanshould delete everything else that can be rebuilt.
The ‘maintainer-clean’ target is intended to be used by a maintainer of the package, not by ordinary users. You may need special tools to reconstruct some of the files that ‘make maintainer-clean’ deletes. Since these files are normally included in the distribution, we don’t take care to make them easy to reconstruct. If you find you need to unpack the full distribution again, don’t blame us.
To help make users aware of this, the commands for the special
maintainer-clean target should start with these two:
@echo ’This command is intended for maintainers to use; it’ @echo ’deletes files that may need special tools to rebuild.’ ‘TAGS’ Update a tags table for this program.
‘info’ Generate any Info files needed. The best way to write the rules is as follows: info: foo.info
foo.info: foo.texi chap1.texi chap2.texi $(MAKEINFO) $(srcdir)/foo.texi
You must define the variable MAKEINFO in the Makefile. It should run the
makeinfo program, which is part of the Texinfo distribution.
Normally a GNU distribution comes with Info files, and that means the Info files are present in the source directory. Therefore, the Make rule for an info file should update it in the source directory. When users build the package, ordinarily Make will not update the Info files because they will already be up to date.
‘dvi’ ‘html’ ‘pdf’
‘ps’ Generate documentation files in the given format. These targets should always exist, but any or all can be a no-op if the given output format cannot be
generated. These targets should not be dependencies of the all target; the user must manually invoke them.
Here’s an example rule for generating DVI files from Texinfo: dvi: foo.dvi
foo.dvi: foo.texi chap1.texi chap2.texi $(TEXI2DVI) $(srcdir)/foo.texi
You must define the variable TEXI2DVI in the Makefile. It should run the program texi2dvi, which is part of the Texinfo distribution. (texi2dvi uses TEX to do the real work of formatting. TEX is not distributed with Texinfo.) Alternatively, write only the dependencies, and allow GNUmaketo provide the command.
Here’s another example, this one for generating HTML from Texinfo: html: foo.html
foo.html: foo.texi chap1.texi chap2.texi $(TEXI2HTML) $(srcdir)/foo.texi
Again, you would define the variable TEXI2HTML in the Makefile; for example, it might run makeinfo --no-split --html (makeinfo is part of the Texinfo distribution).
‘dist’ Create a distribution tar file for this program. The tar file should be set up so that the file names in the tar file start with a subdirectory name which is the name of the package it is a distribution for. This name can include the version number.
For example, the distribution tar file of GCC version 1.40 unpacks into a sub- directory named gcc-1.40.
The easiest way to do this is to create a subdirectory appropriately named, use ln orcp to install the proper files in it, and thentar that subdirectory. Compress the tar file with gzip. For example, the actual distribution file for GCC version 1.40 is called gcc-1.40.tar.gz. It is ok to support other free compression formats as well.
The disttarget should explicitly depend on all non-source files that are in the distribution, to make sure they are up to date in the distribution. See Section “Making Releases” in GNU Coding Standards.
‘check’ Perform self-tests (if any). The user must build the program before running the tests, but need not install the program; you should write the self-tests so that they work when the program is built but not installed.
The following targets are suggested as conventional names, for programs in which they are useful.
installcheck
Perform installation tests (if any). The user must build and install the program before running the tests. You should not assume that $(bindir) is in the search path.
installdirs
It’s useful to add a target named ‘installdirs’ to create the directories where files are installed, and their parent directories. There is a script called
mkinstalldirs which is convenient for this; you can find it in the Gnulib
package. You can use a rule like this:
# Make sure all installation directories (e.g. $(bindir)) # actually exist by making them if necessary.
installdirs: mkinstalldirs
$(srcdir)/mkinstalldirs $(bindir) $(datadir) \ $(libdir) $(infodir) \ $(mandir)
or, if you wish to support DESTDIR(strongly encouraged), # Make sure all installation directories (e.g. $(bindir)) # actually exist by making them if necessary.
installdirs: mkinstalldirs $(srcdir)/mkinstalldirs \
$(DESTDIR)$(bindir) $(DESTDIR)$(datadir) \ $(DESTDIR)$(libdir) $(DESTDIR)$(infodir) \ $(DESTDIR)$(mandir)
This rule should not modify the directories where compilation is done. It should do nothing but create installation directories.
15.7 Install Command Categories
When writing theinstalltarget, you must classify all the commands into three categories: normal ones,pre-installation commands and post-installation commands.
Normal commands move files into their proper places, and set their modes. They may not alter any files except the ones that come entirely from the package they belong to.
Pre-installation and post-installation commands may alter other files; in particular, they can edit global configuration files or data bases.
Pre-installation commands are typically executed before the normal commands, and post-installation commands are typically run after the normal commands.
The most common use for a post-installation command is to run install-info. This cannot be done with a normal command, since it alters a file (the Info directory) which does not come entirely and solely from the package being installed. It is a post-installation command because it needs to be done after the normal command which installs the package’s Info files.
Most programs don’t need any pre-installation commands, but we have the feature just in case it is needed.
To classify the commands in theinstallrule into these three categories, insertcategory lines among them. A category line specifies the category for the commands that follow.
A category line consists of a tab and a reference to a special Make variable, plus an optional comment at the end. There are three variables you can use, one for each category; the variable name specifies the category. Category lines are no-ops in ordinary execution because these three Make variables are normally undefined (and youshould notdefine them in the makefile).
Here are the three possible category lines, each with a comment that explains what it means:
$(PRE_INSTALL) # Pre-install commands follow. $(POST_INSTALL) # Post-install commands follow. $(NORMAL_INSTALL) # Normal commands follow.
If you don’t use a category line at the beginning of theinstall rule, all the commands are classified as normal until the first category line. If you don’t use any category lines, all the commands are classified as normal.
These are the category lines for uninstall:
$(PRE_UNINSTALL) # Pre-uninstall commands follow. $(POST_UNINSTALL) # Post-uninstall commands follow. $(NORMAL_UNINSTALL) # Normal commands follow.
Typically, a pre-uninstall command would be used for deleting entries from the Info directory.
If the install or uninstall target has any dependencies which act as subroutines of installation, then you should start each dependency’s commands with a category line, and start the main target’s commands with a category line also. This way, you can ensure that each command is placed in the right category regardless of which of the dependencies actually run.
Pre-installation and post-installation commands should not run any programs except for these:
[ basename bash cat chgrp chmod chown cmp cp dd diff echo egrep expand expr false fgrep find getopt grep gunzip gzip hostname install install-info kill ldconfig ln ls md5sum mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee test touch true uname xargs yes
The reason for distinguishing the commands in this way is for the sake of making binary packages. Typically a binary package contains all the executables and other files that need to be installed, and has its own method of installing them—so it does not need to run the normal installation commands. But installing the binary package does need to execute the pre-installation and post-installation commands.
Programs to build binary packages work by extracting the pre-installation and post- installation commands. Here is one way of extracting the pre-installation commands (the -s option to makeis needed to silence messages about entering subdirectories):
make -s -n install -o all \ PRE_INSTALL=pre-install \ POST_INSTALL=post-install \ NORMAL_INSTALL=normal-install \ | gawk -f pre-install.awk
where the file pre-install.awkcould contain this: $0 ~ /^(normal-install|post-install)[ \t]*$/ {on = 0} on {print $0}
Appendix A Quick Reference
This appendix summarizes the directives, text manipulation functions, and special variables which GNU make understands. See Section 4.8 [Special Targets], page 32, Section 10.2 [Catalogue of Built-In Rules], page 112, and Section 9.7 [Summary of Options], page 104, for other summaries.
Here is a summary of the directives GNU make recognizes:
definevariable definevariable= definevariable:= definevariable::= definevariable+= definevariable?=
endef Define multi-line variables.
SeeSection 6.8 [Multi-Line], page 69.
undefinevariable
Undefining variables.
SeeSection 6.9 [Undefine Directive], page 69.
ifdefvariable ifndefvariable ifeq (a,b) ifeq "a" "b" ifeq ’a’ ’b’ ifneq (a,b) ifneq "a" "b" ifneq ’a’ ’b’ else
endif Conditionally evaluate part of the makefile.
SeeChapter 7 [Conditionals], page 77.
include file
-includefile
sincludefile
Include another makefile.
SeeSection 3.3 [Including Other Makefiles], page 13.
overridevariable-assignment
Define a variable, overriding any previous definition, even one from the com- mand line.
SeeSection 6.7 [The overrideDirective], page 68.
export Tell maketo export all variables to child processes by default.
exportvariable
exportvariable-assignment
unexportvariable
Tell makewhether or not to export a particular variable to child processes. SeeSection 5.7.2 [Communicating Variables to a Sub-make], page 52.
private variable-assignment
Do not allow this variable assignment to be inherited by prerequisites. SeeSection 6.13 [Suppressing Inheritance], page 72.
vpathpattern path
Specify a search path for files matching a ‘%’ pattern. SeeSection 4.4.2 [The vpathDirective], page 26.
vpathpattern
Remove all search paths previously specified forpattern.
vpath Remove all search paths previously specified in anyvpath directive.
Here is a summary of the built-in functions (see Chapter 8 [Functions], page 83):
$(subst from,to,text)
Replace fromwithto intext.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(patsubstpattern,replacement,text)
Replace words matching patternwithreplacement intext.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(strip string)
Remove excess whitespace characters from string.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(findstring find,text)
Locate find intext.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(filterpattern...,text)
Select words in textthat match one of the patternwords.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(filter-out pattern...,text)
Select words in textthat do not match any of thepattern words.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(sortlist)
Sort the words in list lexicographically, removing duplicates.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(wordn,text)
Extract thenth word (one-origin) of text.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(words text)
Count the number of words intext.
$(wordlists,e,text)
Returns the list of words in textfrom s toe.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(firstwordnames...)
Extract the first word of names.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(lastwordnames...)
Extract the last word of names.
SeeSection 8.2 [Functions for String Substitution and Analysis], page 84.
$(dirnames...)
Extract the directory part of each file name.
SeeSection 8.3 [Functions for File Names], page 87.
$(notdirnames...)
Extract the non-directory part of each file name. SeeSection 8.3 [Functions for File Names], page 87.
$(suffixnames...)
Extract the suffix (the last ‘.’ and following characters) of each file name. SeeSection 8.3 [Functions for File Names], page 87.
$(basenamenames...)
Extract the base name (name without suffix) of each file name. SeeSection 8.3 [Functions for File Names], page 87.
$(addsuffixsuffix,names...)
Append suffix to each word innames.
SeeSection 8.3 [Functions for File Names], page 87.
$(addprefixprefix,names...)
Prepend prefix to each word innames.
SeeSection 8.3 [Functions for File Names], page 87.
$(joinlist1,list2)
Join two parallel lists of words.
SeeSection 8.3 [Functions for File Names], page 87.
$(wildcardpattern...)
Find file names matching a shell file name pattern (not a ‘%’ pattern). SeeSection 4.3.3 [The Functionwildcard], page 24.
$(realpathnames...)
For each file name innames, expand to an absolute name that does not contain
any .,.., nor symlinks.
SeeSection 8.3 [Functions for File Names], page 87.
$(abspath names...)
For each file name innames, expand to an absolute name that does not contain any .or.. components, but preserves symlinks.
$(error text...)
When this function is evaluated,make generates a fatal error with the message
text.
SeeSection 8.12 [Functions That Control Make], page 96.
$(warning text...)
When this function is evaluated, make generates a warning with the message
text.
SeeSection 8.12 [Functions That Control Make], page 96.
$(shell command)
Execute a shell command and return its output. SeeSection 8.13 [Theshell Function], page 97.
$(originvariable)
Return a string describing how the make variablevariable was defined. SeeSection 8.10 [TheoriginFunction], page 94.
$(flavorvariable)
Return a string describing the flavor of the make variablevariable. SeeSection 8.11 [TheflavorFunction], page 95.
$(foreach var,words,text)
Evaluate text with var bound to each word in words, and concatenate the results.
SeeSection 8.5 [The foreach Function], page 90. $(if condition,then-part[,else-part])
Evaluate the condition condition; if it’s non-empty substitute the expansion of the then-part otherwise substitute the expansion of theelse-part.
SeeSection 8.4 [Functions for Conditionals], page 89. $(or condition1[,condition2[,condition3...]])
Evaluate each condition conditionN one at a time; substitute the first non- empty expansion. If all expansions are empty, substitute the empty string. SeeSection 8.4 [Functions for Conditionals], page 89.
$(andcondition1[,condition2[,condition3...]])
Evaluate each condition conditionN one at a time; if any expansion results in the empty string substitute the empty string. If all expansions result in a non- empty string, substitute the expansion of the last condition.
SeeSection 8.4 [Functions for Conditionals], page 89.
$(callvar,param,...)
Evaluate the variable var replacing any references to$(1),$(2)with the first, second, etc. paramvalues.
SeeSection 8.7 [The call Function], page 92.
$(evaltext)
Evaluate text then read the results as makefile commands. Expands to the empty string.
$(fileop filename,text)
Expand the arguments, then open the file filename using mode op and write
text to that file.
SeeSection 8.6 [The file Function], page 91.
$(value var)
Evaluates to the contents of the variable var, with no expansion performed on it.
SeeSection 8.8 [The value Function], page 93.
Here is a summary of the automatic variables. SeeSection 10.5.3 [Automatic Variables], page 120, for full information.
$@ The file name of the target.
$% The target member name, when the target is an archive member.
$< The name of the first prerequisite.
$? The names of all the prerequisites that are newer than the target, with spaces between them. For prerequisites which are archive members, only the named member is used (see Chapter 11 [Archives], page 129).
$^
$+ The names of all the prerequisites, with spaces between them. For prerequisites which are archive members, only the named member is used (see Chapter 11 [Archives], page 129). The value of $^ omits duplicate prerequisites, while $+ retains them and preserves their order.
$* The stem with which an implicit rule matches (seeSection 10.5.4 [How Patterns Match], page 122).
$(@D)
$(@F) The directory part and the file-within-directory part of $@.
$(*D)
$(*F) The directory part and the file-within-directory part of $*.
$(%D)
$(%F) The directory part and the file-within-directory part of $%.
$(<D)
$(<F) The directory part and the file-within-directory part of $<.
$(^D)
$(^F) The directory part and the file-within-directory part of $^.
$(+D)
$(+F) The directory part and the file-within-directory part of $+.