comparison man/make-stds.texi @ 398:74fd4e045ea6 r21-2-29

Import from CVS: tag r21-2-29
author cvs
date Mon, 13 Aug 2007 11:13:30 +0200
parents cc15677e0335
children de805c49cfc1
comparison
equal deleted inserted replaced
397:f4aeb21a5bad 398:74fd4e045ea6
19 @ifclear CODESTD 19 @ifclear CODESTD
20 chapter 20 chapter
21 @end ifclear 21 @end ifclear
22 @end iftex 22 @end iftex
23 describes conventions for writing the Makefiles for GNU programs. 23 describes conventions for writing the Makefiles for GNU programs.
24 Using Automake will help you write a Makefile that follows these
25 conventions.
24 26
25 @menu 27 @menu
26 * Makefile Basics:: General Conventions for Makefiles 28 * Makefile Basics:: General Conventions for Makefiles
27 * Utilities in Makefiles:: Utilities in Makefiles 29 * Utilities in Makefiles:: Utilities in Makefiles
28 * Command Variables:: Variables for Specifying Commands 30 * Command Variables:: Variables for Specifying Commands
29 * Directory Variables:: Variables for Installation Directories 31 * Directory Variables:: Variables for Installation Directories
30 * Standard Targets:: Standard Targets for Users 32 * Standard Targets:: Standard Targets for Users
33 * Install Command Categories:: Three categories of commands in the `install'
34 rule: normal, pre-install and post-install.
31 @end menu 35 @end menu
32 36
33 @node Makefile Basics 37 @node Makefile Basics
34 @section General Conventions for Makefiles 38 @section General Conventions for Makefiles
35 39
63 make, please make sure that it uses @file{./} if the program is built as 67 make, please make sure that it uses @file{./} if the program is built as
64 part of the make or @file{$(srcdir)/} if the file is an unchanging part 68 part of the make or @file{$(srcdir)/} if the file is an unchanging part
65 of the source code. Without one of these prefixes, the current search 69 of the source code. Without one of these prefixes, the current search
66 path is used. 70 path is used.
67 71
68 The distinction between @file{./} and @file{$(srcdir)/} is important 72 The distinction between @file{./} (the @dfn{build directory}) and
69 when using the @samp{--srcdir} option to @file{configure}. A rule of 73 @file{$(srcdir)/} (the @dfn{source directory}) is important because
70 the form: 74 users can build in a separate directory using the @samp{--srcdir} option
75 to @file{configure}. A rule of the form:
71 76
72 @smallexample 77 @smallexample
73 foo.1 : foo.man sedscript 78 foo.1 : foo.man sedscript
74 sed -e sedscript foo.man > foo.1 79 sed -e sedscript foo.man > foo.1
75 @end smallexample 80 @end smallexample
76 81
77 @noindent 82 @noindent
78 will fail when the current directory is not the source directory, 83 will fail when the build directory is not the source directory, because
79 because @file{foo.man} and @file{sedscript} are not in the current 84 @file{foo.man} and @file{sedscript} are in the the source directory.
80 directory.
81 85
82 When using GNU @code{make}, relying on @samp{VPATH} to find the source 86 When using GNU @code{make}, relying on @samp{VPATH} to find the source
83 file will work in the case where there is a single dependency file, 87 file will work in the case where there is a single dependency file,
84 since the @code{make} automatic variable @samp{$<} will represent the 88 since the @code{make} automatic variable @samp{$<} will represent the
85 source file wherever it is. (Many versions of @code{make} set @samp{$<} 89 source file wherever it is. (Many versions of @code{make} set @samp{$<}
107 @smallexample 111 @smallexample
108 foo.1 : foo.man sedscript 112 foo.1 : foo.man sedscript
109 sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@ 113 sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@
110 @end smallexample 114 @end smallexample
111 115
116 GNU distributions usually contain some files which are not source
117 files---for example, Info files, and the output from Autoconf, Automake,
118 Bison or Flex. Since these files normally appear in the source
119 directory, they should always appear in the source directory, not in the
120 build directory. So Makefile rules to update them should put the
121 updated files in the source directory.
122
123 However, if a file does not appear in the distribution, then the
124 Makefile should not put it in the source directory, because building a
125 program in ordinary circumstances should not modify the source directory
126 in any way.
127
112 Try to make the build and installation targets, at least (and all their 128 Try to make the build and installation targets, at least (and all their
113 subtargets) work correctly with a parallel @code{make}. 129 subtargets) work correctly with a parallel @code{make}.
114 130
115 @node Utilities in Makefiles 131 @node Utilities in Makefiles
116 @section Utilities in Makefiles 132 @section Utilities in Makefiles
120 special features of @code{ksh} or @code{bash}. 136 special features of @code{ksh} or @code{bash}.
121 137
122 The @code{configure} script and the Makefile rules for building and 138 The @code{configure} script and the Makefile rules for building and
123 installation should not use any utilities directly except these: 139 installation should not use any utilities directly except these:
124 140
141 @c dd find
142 @c gunzip gzip md5sum
143 @c mkfifo mknod tee uname
144
125 @example 145 @example
126 cat cmp cp echo egrep expr false grep 146 cat cmp cp diff echo egrep expr false grep install-info
127 ln mkdir mv pwd rm rmdir sed test touch true 147 ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
128 @end example 148 @end example
149
150 The compression program @code{gzip} can be used in the @code{dist} rule.
129 151
130 Stick to the generally supported options for these programs. For 152 Stick to the generally supported options for these programs. For
131 example, don't use @samp{mkdir -p}, convenient as it may be, because 153 example, don't use @samp{mkdir -p}, convenient as it may be, because
132 most systems don't support it. 154 most systems don't support it.
133 155
138 and related programs, but should do so via @code{make} variables so that the 160 and related programs, but should do so via @code{make} variables so that the
139 user can substitute alternatives. Here are some of the programs we 161 user can substitute alternatives. Here are some of the programs we
140 mean: 162 mean:
141 163
142 @example 164 @example
143 ar bison cc flex install ld lex 165 ar bison cc flex install ld ldconfig lex
144 make makeinfo ranlib texi2dvi yacc 166 make makeinfo ranlib texi2dvi yacc
145 @end example 167 @end example
146 168
147 Use the following @code{make} variables: 169 Use the following @code{make} variables to run those programs:
148 170
149 @example 171 @example
150 $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LEX) 172 $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
151 $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC) 173 $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
152 @end example 174 @end example
153 175
154 When you use @code{ranlib}, you should make sure nothing bad happens if 176 When you use @code{ranlib} or @code{ldconfig}, you should make sure
155 the system does not have @code{ranlib}. Arrange to ignore an error 177 nothing bad happens if the system does not have the program in question.
156 from that command, and print a message before the command to tell the 178 Arrange to ignore an error from that command, and print a message before
157 user that failure of the @code{ranlib} command does not mean a problem. 179 the command to tell the user that failure of this command does not mean
158 (The Autoconf @samp{AC_PROG_RANLIB} macro can help with this.) 180 a problem. (The Autoconf @samp{AC_PROG_RANLIB} macro can help with
181 this.)
159 182
160 If you use symbolic links, you should implement a fallback for systems 183 If you use symbolic links, you should implement a fallback for systems
161 that don't have symbolic links. 184 that don't have symbolic links.
185
186 Additional utilities that can be used via Make variables are:
187
188 @example
189 chgrp chmod chown mknod
190 @end example
162 191
163 It is ok to use other utilities in Makefile portions (or scripts) 192 It is ok to use other utilities in Makefile portions (or scripts)
164 intended only for particular systems where you know those utilities 193 intended only for particular systems where you know those utilities
165 exist. 194 exist.
166 195
180 don't need to replace them with other programs. 209 don't need to replace them with other programs.
181 210
182 Each program-name variable should come with an options variable that is 211 Each program-name variable should come with an options variable that is
183 used to supply options to the program. Append @samp{FLAGS} to the 212 used to supply options to the program. Append @samp{FLAGS} to the
184 program-name variable name to get the options variable name---for 213 program-name variable name to get the options variable name---for
185 example, @code{BISONFLAGS}. (The name @code{CFLAGS} is an exception to 214 example, @code{BISONFLAGS}. (The names @code{CFLAGS} for the C
186 this rule, but we keep it because it is standard.) Use @code{CPPFLAGS} 215 compiler, @code{YFLAGS} for yacc, and @code{LFLAGS} for lex, are
187 in any compilation command that runs the preprocessor, and use 216 exceptions to this rule, but we keep them because they are standard.)
188 @code{LDFLAGS} in any compilation command that does linking as well as 217 Use @code{CPPFLAGS} in any compilation command that runs the
189 in any direct use of @code{ld}. 218 preprocessor, and use @code{LDFLAGS} in any compilation command that
219 does linking as well as in any direct use of @code{ld}.
190 220
191 If there are C compiler options that @emph{must} be used for proper 221 If there are C compiler options that @emph{must} be used for proper
192 compilation of certain files, do not include them in @code{CFLAGS}. 222 compilation of certain files, do not include them in @code{CFLAGS}.
193 Users expect to be able to specify @code{CFLAGS} freely themselves. 223 Users expect to be able to specify @code{CFLAGS} freely themselves.
194 Instead, arrange to pass the necessary options to the C compiler 224 Instead, arrange to pass the necessary options to the C compiler
210 240
211 Put @code{CFLAGS} last in the compilation command, after other variables 241 Put @code{CFLAGS} last in the compilation command, after other variables
212 containing compiler options, so the user can use @code{CFLAGS} to 242 containing compiler options, so the user can use @code{CFLAGS} to
213 override the others. 243 override the others.
214 244
245 @code{CFLAGS} should be used in every invocation of the C compiler,
246 both those which do compilation and those which do linking.
247
215 Every Makefile should define the variable @code{INSTALL}, which is the 248 Every Makefile should define the variable @code{INSTALL}, which is the
216 basic command for installing a file into the system. 249 basic command for installing a file into the system.
217 250
218 Every Makefile should also define the variables @code{INSTALL_PROGRAM} 251 Every Makefile should also define the variables @code{INSTALL_PROGRAM}
219 and @code{INSTALL_DATA}. (The default for each of these should be 252 and @code{INSTALL_DATA}. (The default for each of these should be
222 respectively. Use these variables as follows: 255 respectively. Use these variables as follows:
223 256
224 @example 257 @example
225 $(INSTALL_PROGRAM) foo $(bindir)/foo 258 $(INSTALL_PROGRAM) foo $(bindir)/foo
226 $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a 259 $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
260 @end example
261
262 Optionally, you may prepend the value of @code{DESTDIR} to the target
263 filename. Doing this allows the installer to create a snapshot of the
264 installation to be copied onto the real target filesystem later. Do not
265 set the value of @code{DESTDIR} in your Makefile, and do not include it
266 in any installed files. With support for @code{DESTDIR}, the above
267 examples become:
268
269 @example
270 $(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo
271 $(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a
227 @end example 272 @end example
228 273
229 @noindent 274 @noindent
230 Always use a file name, not a directory name, as the second argument of 275 Always use a file name, not a directory name, as the second argument of
231 the installation commands. Use a separate command for each file to be 276 the installation commands. Use a separate command for each file to be
250 below. The default value of @code{prefix} should be @file{/usr/local}. 295 below. The default value of @code{prefix} should be @file{/usr/local}.
251 When building the complete GNU system, the prefix will be empty and 296 When building the complete GNU system, the prefix will be empty and
252 @file{/usr} will be a symbolic link to @file{/}. 297 @file{/usr} will be a symbolic link to @file{/}.
253 (If you are using Autoconf, write it as @samp{@@prefix@@}.) 298 (If you are using Autoconf, write it as @samp{@@prefix@@}.)
254 299
300 Running @samp{make install} with a different value of @code{prefix}
301 from the one used to build the program should @var{not} recompile
302 the program.
303
255 @item exec_prefix 304 @item exec_prefix
256 A prefix used in constructing the default values of some of the 305 A prefix used in constructing the default values of some of the
257 variables listed below. The default value of @code{exec_prefix} should 306 variables listed below. The default value of @code{exec_prefix} should
258 be @code{$(prefix)}. 307 be @code{$(prefix)}.
259 (If you are using Autoconf, write it as @samp{@@exec_prefix@@}.) 308 (If you are using Autoconf, write it as @samp{@@exec_prefix@@}.)
260 309
261 Generally, @code{$(exec_prefix)} is used for directories that contain 310 Generally, @code{$(exec_prefix)} is used for directories that contain
262 machine-specific files (such as executables and subroutine libraries), 311 machine-specific files (such as executables and subroutine libraries),
263 while @code{$(prefix)} is used directly for other directories. 312 while @code{$(prefix)} is used directly for other directories.
313
314 Running @samp{make install} with a different value of @code{exec_prefix}
315 from the one used to build the program should @var{not} recompile the
316 program.
264 @end table 317 @end table
265 318
266 Executable programs are installed in one of the following directories. 319 Executable programs are installed in one of the following directories.
267 320
268 @table @samp 321 @table @samp
326 here. All the files in this directory should be ordinary ASCII text 379 here. All the files in this directory should be ordinary ASCII text
327 files. This directory should normally be @file{/usr/local/etc}, but 380 files. This directory should normally be @file{/usr/local/etc}, but
328 write it as @file{$(prefix)/etc}. 381 write it as @file{$(prefix)/etc}.
329 (If you are using Autoconf, write it as @samp{@@sysconfdir@@}.) 382 (If you are using Autoconf, write it as @samp{@@sysconfdir@@}.)
330 383
331 @c rewritten to avoid overfull hbox --tower 384 Do not install executables here in this directory (they probably belong
332 Do not install executables 385 in @file{$(libexecdir)} or @file{$(sbindir)}). Also do not install
333 @c here 386 files that are modified in the normal course of their use (programs
334 in this directory (they probably 387 whose purpose is to change the configuration of the system excluded).
335 belong in @file{$(libexecdir)} or @file{$(sbindir)}). Also do not 388 Those probably belong in @file{$(localstatedir)}.
336 install files that are modified in the normal course of their use
337 (programs whose purpose is to change the configuration of the system
338 excluded). Those probably belong in @file{$(localstatedir)}.
339 389
340 @item sharedstatedir 390 @item sharedstatedir
341 The directory for installing architecture-independent data files which 391 The directory for installing architecture-independent data files which
342 the programs modify while they run. This should normally be 392 the programs modify while they run. This should normally be
343 @file{/usr/local/com}, but write it as @file{$(prefix)/com}. 393 @file{/usr/local/com}, but write it as @file{$(prefix)/com}.
364 The directory for installing the Info files for this package. By 414 The directory for installing the Info files for this package. By
365 default, it should be @file{/usr/local/info}, but it should be written 415 default, it should be @file{/usr/local/info}, but it should be written
366 as @file{$(prefix)/info}. 416 as @file{$(prefix)/info}.
367 (If you are using Autoconf, write it as @samp{@@infodir@@}.) 417 (If you are using Autoconf, write it as @samp{@@infodir@@}.)
368 418
419 @item lispdir
420 The directory for installing any Emacs Lisp files in this package. By
421 default, it should be @file{/usr/local/share/emacs/site-lisp}, but it
422 should be written as @file{$(prefix)/share/emacs/site-lisp}.
423
424 If you are using Autoconf, write the default as @samp{@@lispdir@@}.
425 In order to make @samp{@@lispdir@@} work, you need the following lines
426 in your @file{configure.in} file:
427
428 @example
429 lispdir='$@{datadir@}/emacs/site-lisp'
430 AC_SUBST(lispdir)
431 @end example
432
369 @item includedir 433 @item includedir
370 @c rewritten to avoid overfull hbox --roland 434 @c rewritten to avoid overfull hbox --roland
371 The directory for installing header files to be included by user 435 The directory for installing header files to be included by user
372 programs with the C @samp{#include} preprocessor directive. This 436 programs with the C @samp{#include} preprocessor directive. This
373 should normally be @file{/usr/local/include}, but write it as 437 should normally be @file{/usr/local/include}, but write it as
374 @file{$(prefix)/include}. 438 @file{$(prefix)/include}.
375 (If you are using Autoconf, write it as @samp{@@includedir@@}.) 439 (If you are using Autoconf, write it as @samp{@@includedir@@}.)
376 440
377 Most compilers other than GCC do not look for header files in 441 Most compilers other than GCC do not look for header files in directory
378 @file{/usr/local/include}. So installing the header files this way is 442 @file{/usr/local/include}. So installing the header files this way is
379 only useful with GCC. Sometimes this is not a problem because some 443 only useful with GCC. Sometimes this is not a problem because some
380 libraries are only really intended to work with GCC. But some libraries 444 libraries are only really intended to work with GCC. But some libraries
381 are intended to work with other compilers. They should install their 445 are intended to work with other compilers. They should install their
382 header files in two places, one specified by @code{includedir} and one 446 header files in two places, one specified by @code{includedir} and one
524 Here is a sample rule to install an Info file: 588 Here is a sample rule to install an Info file:
525 589
526 @comment This example has been carefully formatted for the Make manual. 590 @comment This example has been carefully formatted for the Make manual.
527 @comment Please do not reformat it without talking to roland@gnu.ai.mit.edu. 591 @comment Please do not reformat it without talking to roland@gnu.ai.mit.edu.
528 @smallexample 592 @smallexample
529 $(infodir)/foo.info: foo.info 593 $(DESTDIR)$(infodir)/foo.info: foo.info
594 $(POST_INSTALL)
530 # There may be a newer info file in . than in srcdir. 595 # There may be a newer info file in . than in srcdir.
531 -if test -f foo.info; then d=.; \ 596 -if test -f foo.info; then d=.; \
532 else d=$(srcdir); fi; \ 597 else d=$(srcdir); fi; \
533 $(INSTALL_DATA) $$d/foo.info $@@; \ 598 $(INSTALL_DATA) $$d/foo.info $(DESTDIR)$@@; \
534 # Run install-info only if it exists. 599 # Run install-info only if it exists.
535 # Use `if' instead of just prepending `-' to the 600 # Use `if' instead of just prepending `-' to the
536 # line so we notice real errors from install-info. 601 # line so we notice real errors from install-info.
537 # We use `$(SHELL) -c' because some shells do not 602 # We use `$(SHELL) -c' because some shells do not
538 # fail gracefully when there is an unknown command. 603 # fail gracefully when there is an unknown command.
539 if $(SHELL) -c 'install-info --version' \ 604 if $(SHELL) -c 'install-info --version' \
540 >/dev/null 2>&1; then \ 605 >/dev/null 2>&1; then \
541 install-info --dir-file=$(infodir)/dir \ 606 install-info --dir-file=$(DESTDIR)$(infodir)/dir \
542 $(infodir)/foo.info; \ 607 $(DESTDIR)$(infodir)/foo.info; \
543 else true; fi 608 else true; fi
544 @end smallexample 609 @end smallexample
545 610
611 When writing the @code{install} target, you must classify all the
612 commands into three categories: normal ones, @dfn{pre-installation}
613 commands and @dfn{post-installation} commands. @xref{Install Command
614 Categories}.
615
546 @item uninstall 616 @item uninstall
547 Delete all the installed files that the @samp{install} target would 617 Delete all the installed files---the copies that the @samp{install}
548 create (but not the noninstalled files such as @samp{make all} would 618 target creates.
549 create).
550 619
551 This rule should not modify the directories where compilation is done, 620 This rule should not modify the directories where compilation is done,
552 only the directories where files are installed. 621 only the directories where files are installed.
553 622
623 The uninstallation commands are divided into three categories, just like
624 the installation commands. @xref{Install Command Categories}.
625
554 @item install-strip 626 @item install-strip
555 Like @code{install}, but strip the executable files while installing 627 Like @code{install}, but strip the executable files while installing
556 them. The definition of this target can be very simple: 628 them. In many cases, the definition of this target can be very simple:
557 629
558 @smallexample 630 @smallexample
559 install-strip: 631 install-strip:
560 $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \ 632 $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
561 install 633 install
636 @noindent 708 @noindent
637 You must define the variable @code{MAKEINFO} in the Makefile. It should 709 You must define the variable @code{MAKEINFO} in the Makefile. It should
638 run the @code{makeinfo} program, which is part of the Texinfo 710 run the @code{makeinfo} program, which is part of the Texinfo
639 distribution. 711 distribution.
640 712
713 Normally a GNU distribution comes with Info files, and that means the
714 Info files are present in the source directory. Therefore, the Make
715 rule for an info file should update it in the source directory. When
716 users build the package, ordinarily Make will not update the Info files
717 because they will already be up to date.
718
641 @item dvi 719 @item dvi
642 Generate DVI files for all Texinfo documentation. 720 Generate DVI files for all Texinfo documentation.
643 For example: 721 For example:
644 722
645 @smallexample 723 @smallexample
667 745
668 The easiest way to do this is to create a subdirectory appropriately 746 The easiest way to do this is to create a subdirectory appropriately
669 named, use @code{ln} or @code{cp} to install the proper files in it, and 747 named, use @code{ln} or @code{cp} to install the proper files in it, and
670 then @code{tar} that subdirectory. 748 then @code{tar} that subdirectory.
671 749
672 Compress the tar file with @code{gzip}. For example, the actual 750 Compress the tar file file with @code{gzip}. For example, the actual
673 distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}. 751 distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}.
674 752
675 The @code{dist} target should explicitly depend on all non-source files 753 The @code{dist} target should explicitly depend on all non-source files
676 that are in the distribution, to make sure they are up to date in the 754 that are in the distribution, to make sure they are up to date in the
677 distribution. 755 distribution.
718 @end smallexample 796 @end smallexample
719 797
720 This rule should not modify the directories where compilation is done. 798 This rule should not modify the directories where compilation is done.
721 It should do nothing but create installation directories. 799 It should do nothing but create installation directories.
722 @end table 800 @end table
801
802 @node Install Command Categories
803 @section Install Command Categories
804
805 @cindex pre-installation commands
806 @cindex post-installation commands
807 When writing the @code{install} target, you must classify all the
808 commands into three categories: normal ones, @dfn{pre-installation}
809 commands and @dfn{post-installation} commands.
810
811 Normal commands move files into their proper places, and set their
812 modes. They may not alter any files except the ones that come entirely
813 from the package they belong to.
814
815 Pre-installation and post-installation commands may alter other files;
816 in particular, they can edit global configuration files or data bases.
817
818 Pre-installation commands are typically executed before the normal
819 commands, and post-installation commands are typically run after the
820 normal commands.
821
822 The most common use for a post-installation command is to run
823 @code{install-info}. This cannot be done with a normal command, since
824 it alters a file (the Info directory) which does not come entirely and
825 solely from the package being installed. It is a post-installation
826 command because it needs to be done after the normal command which
827 installs the package's Info files.
828
829 Most programs don't need any pre-installation commands, but we have the
830 feature just in case it is needed.
831
832 To classify the commands in the @code{install} rule into these three
833 categories, insert @dfn{category lines} among them. A category line
834 specifies the category for the commands that follow.
835
836 A category line consists of a tab and a reference to a special Make
837 variable, plus an optional comment at the end. There are three
838 variables you can use, one for each category; the variable name
839 specifies the category. Category lines are no-ops in ordinary execution
840 because these three Make variables are normally undefined (and you
841 @emph{should not} define them in the makefile).
842
843 Here are the three possible category lines, each with a comment that
844 explains what it means:
845
846 @smallexample
847 $(PRE_INSTALL) # @r{Pre-install commands follow.}
848 $(POST_INSTALL) # @r{Post-install commands follow.}
849 $(NORMAL_INSTALL) # @r{Normal commands follow.}
850 @end smallexample
851
852 If you don't use a category line at the beginning of the @code{install}
853 rule, all the commands are classified as normal until the first category
854 line. If you don't use any category lines, all the commands are
855 classified as normal.
856
857 These are the category lines for @code{uninstall}:
858
859 @smallexample
860 $(PRE_UNINSTALL) # @r{Pre-uninstall commands follow.}
861 $(POST_UNINSTALL) # @r{Post-uninstall commands follow.}
862 $(NORMAL_UNINSTALL) # @r{Normal commands follow.}
863 @end smallexample
864
865 Typically, a pre-uninstall command would be used for deleting entries
866 from the Info directory.
867
868 If the @code{install} or @code{uninstall} target has any dependencies
869 which act as subroutines of installation, then you should start
870 @emph{each} dependency's commands with a category line, and start the
871 main target's commands with a category line also. This way, you can
872 ensure that each command is placed in the right category regardless of
873 which of the dependencies actually run.
874
875 Pre-installation and post-installation commands should not run any
876 programs except for these:
877
878 @example
879 [ basename bash cat chgrp chmod chown cmp cp dd diff echo
880 egrep expand expr false fgrep find getopt grep gunzip gzip
881 hostname install install-info kill ldconfig ln ls md5sum
882 mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
883 test touch true uname xargs yes
884 @end example
885
886 @cindex binary packages
887 The reason for distinguishing the commands in this way is for the sake
888 of making binary packages. Typically a binary package contains all the
889 executables and other files that need to be installed, and has its own
890 method of installing them---so it does not need to run the normal
891 installation commands. But installing the binary package does need to
892 execute the pre-installation and post-installation commands.
893
894 Programs to build binary packages work by extracting the
895 pre-installation and post-installation commands. Here is one way of
896 extracting the pre-installation commands:
897
898 @smallexample
899 make -n install -o all \
900 PRE_INSTALL=pre-install \
901 POST_INSTALL=post-install \
902 NORMAL_INSTALL=normal-install \
903 | gawk -f pre-install.awk
904 @end smallexample
905
906 @noindent
907 where the file @file{pre-install.awk} could contain this:
908
909 @smallexample
910 $0 ~ /^\t[ \t]*(normal_install|post_install)[ \t]*$/ @{on = 0@}
911 on @{print $0@}
912 $0 ~ /^\t[ \t]*pre_install[ \t]*$/ @{on = 1@}
913 @end smallexample
914
915 The resulting file of pre-installation commands is executed as a shell
916 script as part of installing the binary package.