comparison man/make-stds.texi @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
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.
26 24
27 @menu 25 @menu
28 * Makefile Basics:: General Conventions for Makefiles 26 * Makefile Basics:: General Conventions for Makefiles
29 * Utilities in Makefiles:: Utilities in Makefiles 27 * Utilities in Makefiles:: Utilities in Makefiles
30 * Command Variables:: Variables for Specifying Commands 28 * Command Variables:: Variables for Specifying Commands
31 * Directory Variables:: Variables for Installation Directories 29 * Directory Variables:: Variables for Installation Directories
32 * Standard Targets:: Standard Targets for Users 30 * 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.
35 @end menu 31 @end menu
36 32
37 @node Makefile Basics 33 @node Makefile Basics
38 @section General Conventions for Makefiles 34 @section General Conventions for Makefiles
39 35
67 make, please make sure that it uses @file{./} if the program is built as 63 make, please make sure that it uses @file{./} if the program is built as
68 part of the make or @file{$(srcdir)/} if the file is an unchanging part 64 part of the make or @file{$(srcdir)/} if the file is an unchanging part
69 of the source code. Without one of these prefixes, the current search 65 of the source code. Without one of these prefixes, the current search
70 path is used. 66 path is used.
71 67
72 The distinction between @file{./} (the @dfn{build directory}) and 68 The distinction between @file{./} and @file{$(srcdir)/} is important
73 @file{$(srcdir)/} (the @dfn{source directory}) is important because 69 when using the @samp{--srcdir} option to @file{configure}. A rule of
74 users can build in a separate directory using the @samp{--srcdir} option 70 the form:
75 to @file{configure}. A rule of the form:
76 71
77 @smallexample 72 @smallexample
78 foo.1 : foo.man sedscript 73 foo.1 : foo.man sedscript
79 sed -e sedscript foo.man > foo.1 74 sed -e sedscript foo.man > foo.1
80 @end smallexample 75 @end smallexample
81 76
82 @noindent 77 @noindent
83 will fail when the build directory is not the source directory, because 78 will fail when the current directory is not the source directory,
84 @file{foo.man} and @file{sedscript} are in the the source directory. 79 because @file{foo.man} and @file{sedscript} are not in the current
80 directory.
85 81
86 When using GNU @code{make}, relying on @samp{VPATH} to find the source 82 When using GNU @code{make}, relying on @samp{VPATH} to find the source
87 file will work in the case where there is a single dependency file, 83 file will work in the case where there is a single dependency file,
88 since the @code{make} automatic variable @samp{$<} will represent the 84 since the @code{make} automatic variable @samp{$<} will represent the
89 source file wherever it is. (Many versions of @code{make} set @samp{$<} 85 source file wherever it is. (Many versions of @code{make} set @samp{$<}
111 @smallexample 107 @smallexample
112 foo.1 : foo.man sedscript 108 foo.1 : foo.man sedscript
113 sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@ 109 sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@
114 @end smallexample 110 @end smallexample
115 111
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
128 Try to make the build and installation targets, at least (and all their 112 Try to make the build and installation targets, at least (and all their
129 subtargets) work correctly with a parallel @code{make}. 113 subtargets) work correctly with a parallel @code{make}.
130 114
131 @node Utilities in Makefiles 115 @node Utilities in Makefiles
132 @section Utilities in Makefiles 116 @section Utilities in Makefiles
136 special features of @code{ksh} or @code{bash}. 120 special features of @code{ksh} or @code{bash}.
137 121
138 The @code{configure} script and the Makefile rules for building and 122 The @code{configure} script and the Makefile rules for building and
139 installation should not use any utilities directly except these: 123 installation should not use any utilities directly except these:
140 124
141 @c dd find
142 @c gunzip gzip md5sum
143 @c mkfifo mknod tee uname
144
145 @example 125 @example
146 cat cmp cp diff echo egrep expr false grep install-info 126 cat cmp cp echo egrep expr false grep
147 ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true 127 ln mkdir mv pwd rm rmdir sed test touch true
148 @end example 128 @end example
149
150 The compression program @code{gzip} can be used in the @code{dist} rule.
151 129
152 Stick to the generally supported options for these programs. For 130 Stick to the generally supported options for these programs. For
153 example, don't use @samp{mkdir -p}, convenient as it may be, because 131 example, don't use @samp{mkdir -p}, convenient as it may be, because
154 most systems don't support it. 132 most systems don't support it.
155 133
160 and related programs, but should do so via @code{make} variables so that the 138 and related programs, but should do so via @code{make} variables so that the
161 user can substitute alternatives. Here are some of the programs we 139 user can substitute alternatives. Here are some of the programs we
162 mean: 140 mean:
163 141
164 @example 142 @example
165 ar bison cc flex install ld ldconfig lex 143 ar bison cc flex install ld lex
166 make makeinfo ranlib texi2dvi yacc 144 make makeinfo ranlib texi2dvi yacc
167 @end example 145 @end example
168 146
169 Use the following @code{make} variables to run those programs: 147 Use the following @code{make} variables:
170 148
171 @example 149 @example
172 $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX) 150 $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LEX)
173 $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC) 151 $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
174 @end example 152 @end example
175 153
176 When you use @code{ranlib} or @code{ldconfig}, you should make sure 154 When you use @code{ranlib}, you should make sure nothing bad happens if
177 nothing bad happens if the system does not have the program in question. 155 the system does not have @code{ranlib}. Arrange to ignore an error
178 Arrange to ignore an error from that command, and print a message before 156 from that command, and print a message before the command to tell the
179 the command to tell the user that failure of this command does not mean 157 user that failure of the @code{ranlib} command does not mean a problem.
180 a problem. (The Autoconf @samp{AC_PROG_RANLIB} macro can help with 158 (The Autoconf @samp{AC_PROG_RANLIB} macro can help with this.)
181 this.)
182 159
183 If you use symbolic links, you should implement a fallback for systems 160 If you use symbolic links, you should implement a fallback for systems
184 that don't have symbolic links. 161 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
191 162
192 It is ok to use other utilities in Makefile portions (or scripts) 163 It is ok to use other utilities in Makefile portions (or scripts)
193 intended only for particular systems where you know those utilities 164 intended only for particular systems where you know those utilities
194 exist. 165 exist.
195 166
209 don't need to replace them with other programs. 180 don't need to replace them with other programs.
210 181
211 Each program-name variable should come with an options variable that is 182 Each program-name variable should come with an options variable that is
212 used to supply options to the program. Append @samp{FLAGS} to the 183 used to supply options to the program. Append @samp{FLAGS} to the
213 program-name variable name to get the options variable name---for 184 program-name variable name to get the options variable name---for
214 example, @code{BISONFLAGS}. (The names @code{CFLAGS} for the C 185 example, @code{BISONFLAGS}. (The name @code{CFLAGS} is an exception to
215 compiler, @code{YFLAGS} for yacc, and @code{LFLAGS} for lex, are 186 this rule, but we keep it because it is standard.) Use @code{CPPFLAGS}
216 exceptions to this rule, but we keep them because they are standard.) 187 in any compilation command that runs the preprocessor, and use
217 Use @code{CPPFLAGS} in any compilation command that runs the 188 @code{LDFLAGS} in any compilation command that does linking as well as
218 preprocessor, and use @code{LDFLAGS} in any compilation command that 189 in any direct use of @code{ld}.
219 does linking as well as in any direct use of @code{ld}.
220 190
221 If there are C compiler options that @emph{must} be used for proper 191 If there are C compiler options that @emph{must} be used for proper
222 compilation of certain files, do not include them in @code{CFLAGS}. 192 compilation of certain files, do not include them in @code{CFLAGS}.
223 Users expect to be able to specify @code{CFLAGS} freely themselves. 193 Users expect to be able to specify @code{CFLAGS} freely themselves.
224 Instead, arrange to pass the necessary options to the C compiler 194 Instead, arrange to pass the necessary options to the C compiler
240 210
241 Put @code{CFLAGS} last in the compilation command, after other variables 211 Put @code{CFLAGS} last in the compilation command, after other variables
242 containing compiler options, so the user can use @code{CFLAGS} to 212 containing compiler options, so the user can use @code{CFLAGS} to
243 override the others. 213 override the others.
244 214
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
248 Every Makefile should define the variable @code{INSTALL}, which is the 215 Every Makefile should define the variable @code{INSTALL}, which is the
249 basic command for installing a file into the system. 216 basic command for installing a file into the system.
250 217
251 Every Makefile should also define the variables @code{INSTALL_PROGRAM} 218 Every Makefile should also define the variables @code{INSTALL_PROGRAM}
252 and @code{INSTALL_DATA}. (The default for each of these should be 219 and @code{INSTALL_DATA}. (The default for each of these should be
255 respectively. Use these variables as follows: 222 respectively. Use these variables as follows:
256 223
257 @example 224 @example
258 $(INSTALL_PROGRAM) foo $(bindir)/foo 225 $(INSTALL_PROGRAM) foo $(bindir)/foo
259 $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a 226 $(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
272 @end example 227 @end example
273 228
274 @noindent 229 @noindent
275 Always use a file name, not a directory name, as the second argument of 230 Always use a file name, not a directory name, as the second argument of
276 the installation commands. Use a separate command for each file to be 231 the installation commands. Use a separate command for each file to be
295 below. The default value of @code{prefix} should be @file{/usr/local}. 250 below. The default value of @code{prefix} should be @file{/usr/local}.
296 When building the complete GNU system, the prefix will be empty and 251 When building the complete GNU system, the prefix will be empty and
297 @file{/usr} will be a symbolic link to @file{/}. 252 @file{/usr} will be a symbolic link to @file{/}.
298 (If you are using Autoconf, write it as @samp{@@prefix@@}.) 253 (If you are using Autoconf, write it as @samp{@@prefix@@}.)
299 254
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
304 @item exec_prefix 255 @item exec_prefix
305 A prefix used in constructing the default values of some of the 256 A prefix used in constructing the default values of some of the
306 variables listed below. The default value of @code{exec_prefix} should 257 variables listed below. The default value of @code{exec_prefix} should
307 be @code{$(prefix)}. 258 be @code{$(prefix)}.
308 (If you are using Autoconf, write it as @samp{@@exec_prefix@@}.) 259 (If you are using Autoconf, write it as @samp{@@exec_prefix@@}.)
309 260
310 Generally, @code{$(exec_prefix)} is used for directories that contain 261 Generally, @code{$(exec_prefix)} is used for directories that contain
311 machine-specific files (such as executables and subroutine libraries), 262 machine-specific files (such as executables and subroutine libraries),
312 while @code{$(prefix)} is used directly for other directories. 263 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.
317 @end table 264 @end table
318 265
319 Executable programs are installed in one of the following directories. 266 Executable programs are installed in one of the following directories.
320 267
321 @table @samp 268 @table @samp
379 here. All the files in this directory should be ordinary ASCII text 326 here. All the files in this directory should be ordinary ASCII text
380 files. This directory should normally be @file{/usr/local/etc}, but 327 files. This directory should normally be @file{/usr/local/etc}, but
381 write it as @file{$(prefix)/etc}. 328 write it as @file{$(prefix)/etc}.
382 (If you are using Autoconf, write it as @samp{@@sysconfdir@@}.) 329 (If you are using Autoconf, write it as @samp{@@sysconfdir@@}.)
383 330
384 Do not install executables here in this directory (they probably belong 331 @c rewritten to avoid overfull hbox --tower
385 in @file{$(libexecdir)} or @file{$(sbindir)}). Also do not install 332 Do not install executables
386 files that are modified in the normal course of their use (programs 333 @c here
387 whose purpose is to change the configuration of the system excluded). 334 in this directory (they probably
388 Those probably belong in @file{$(localstatedir)}. 335 belong in @file{$(libexecdir)} or @file{$(sbindir)}). Also do not
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)}.
389 339
390 @item sharedstatedir 340 @item sharedstatedir
391 The directory for installing architecture-independent data files which 341 The directory for installing architecture-independent data files which
392 the programs modify while they run. This should normally be 342 the programs modify while they run. This should normally be
393 @file{/usr/local/com}, but write it as @file{$(prefix)/com}. 343 @file{/usr/local/com}, but write it as @file{$(prefix)/com}.
414 The directory for installing the Info files for this package. By 364 The directory for installing the Info files for this package. By
415 default, it should be @file{/usr/local/info}, but it should be written 365 default, it should be @file{/usr/local/info}, but it should be written
416 as @file{$(prefix)/info}. 366 as @file{$(prefix)/info}.
417 (If you are using Autoconf, write it as @samp{@@infodir@@}.) 367 (If you are using Autoconf, write it as @samp{@@infodir@@}.)
418 368
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
433 @item includedir 369 @item includedir
434 @c rewritten to avoid overfull hbox --roland 370 @c rewritten to avoid overfull hbox --roland
435 The directory for installing header files to be included by user 371 The directory for installing header files to be included by user
436 programs with the C @samp{#include} preprocessor directive. This 372 programs with the C @samp{#include} preprocessor directive. This
437 should normally be @file{/usr/local/include}, but write it as 373 should normally be @file{/usr/local/include}, but write it as
438 @file{$(prefix)/include}. 374 @file{$(prefix)/include}.
439 (If you are using Autoconf, write it as @samp{@@includedir@@}.) 375 (If you are using Autoconf, write it as @samp{@@includedir@@}.)
440 376
441 Most compilers other than GCC do not look for header files in directory 377 Most compilers other than GCC do not look for header files in
442 @file{/usr/local/include}. So installing the header files this way is 378 @file{/usr/local/include}. So installing the header files this way is
443 only useful with GCC. Sometimes this is not a problem because some 379 only useful with GCC. Sometimes this is not a problem because some
444 libraries are only really intended to work with GCC. But some libraries 380 libraries are only really intended to work with GCC. But some libraries
445 are intended to work with other compilers. They should install their 381 are intended to work with other compilers. They should install their
446 header files in two places, one specified by @code{includedir} and one 382 header files in two places, one specified by @code{includedir} and one
505 441
506 @table @samp 442 @table @samp
507 @item srcdir 443 @item srcdir
508 The directory for the sources being compiled. The value of this 444 The directory for the sources being compiled. The value of this
509 variable is normally inserted by the @code{configure} shell script. 445 variable is normally inserted by the @code{configure} shell script.
510 (If you are using Autoconf, use @samp{srcdir = @@srcdir@@}.) 446 (If you are using Autconf, use @samp{srcdir = @@srcdir@@}.)
511 @end table 447 @end table
512 448
513 For example: 449 For example:
514 450
515 @smallexample 451 @smallexample
588 Here is a sample rule to install an Info file: 524 Here is a sample rule to install an Info file:
589 525
590 @comment This example has been carefully formatted for the Make manual. 526 @comment This example has been carefully formatted for the Make manual.
591 @comment Please do not reformat it without talking to roland@gnu.ai.mit.edu. 527 @comment Please do not reformat it without talking to roland@gnu.ai.mit.edu.
592 @smallexample 528 @smallexample
593 $(DESTDIR)$(infodir)/foo.info: foo.info 529 $(infodir)/foo.info: foo.info
594 $(POST_INSTALL)
595 # There may be a newer info file in . than in srcdir. 530 # There may be a newer info file in . than in srcdir.
596 -if test -f foo.info; then d=.; \ 531 -if test -f foo.info; then d=.; \
597 else d=$(srcdir); fi; \ 532 else d=$(srcdir); fi; \
598 $(INSTALL_DATA) $$d/foo.info $(DESTDIR)$@@; \ 533 $(INSTALL_DATA) $$d/foo.info $@@; \
599 # Run install-info only if it exists. 534 # Run install-info only if it exists.
600 # Use `if' instead of just prepending `-' to the 535 # Use `if' instead of just prepending `-' to the
601 # line so we notice real errors from install-info. 536 # line so we notice real errors from install-info.
602 # We use `$(SHELL) -c' because some shells do not 537 # We use `$(SHELL) -c' because some shells do not
603 # fail gracefully when there is an unknown command. 538 # fail gracefully when there is an unknown command.
604 if $(SHELL) -c 'install-info --version' \ 539 if $(SHELL) -c 'install-info --version' \
605 >/dev/null 2>&1; then \ 540 >/dev/null 2>&1; then \
606 install-info --dir-file=$(DESTDIR)$(infodir)/dir \ 541 install-info --dir-file=$(infodir)/dir \
607 $(DESTDIR)$(infodir)/foo.info; \ 542 $(infodir)/foo.info; \
608 else true; fi 543 else true; fi
609 @end smallexample 544 @end smallexample
610 545
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
616 @item uninstall 546 @item uninstall
617 Delete all the installed files---the copies that the @samp{install} 547 Delete all the installed files that the @samp{install} target would
618 target creates. 548 create (but not the noninstalled files such as @samp{make all} would
549 create).
619 550
620 This rule should not modify the directories where compilation is done, 551 This rule should not modify the directories where compilation is done,
621 only the directories where files are installed. 552 only the directories where files are installed.
622 553
623 The uninstallation commands are divided into three categories, just like
624 the installation commands. @xref{Install Command Categories}.
625
626 @item install-strip 554 @item install-strip
627 Like @code{install}, but strip the executable files while installing 555 Like @code{install}, but strip the executable files while installing
628 them. In many cases, the definition of this target can be very simple: 556 them. The definition of this target can be very simple:
629 557
630 @smallexample 558 @smallexample
631 install-strip: 559 install-strip:
632 $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \ 560 $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
633 install 561 install
708 @noindent 636 @noindent
709 You must define the variable @code{MAKEINFO} in the Makefile. It should 637 You must define the variable @code{MAKEINFO} in the Makefile. It should
710 run the @code{makeinfo} program, which is part of the Texinfo 638 run the @code{makeinfo} program, which is part of the Texinfo
711 distribution. 639 distribution.
712 640
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
719 @item dvi 641 @item dvi
720 Generate DVI files for all Texinfo documentation. 642 Generate DVI files for all Texinfo documentation.
721 For example: 643 For example:
722 644
723 @smallexample 645 @smallexample
745 667
746 The easiest way to do this is to create a subdirectory appropriately 668 The easiest way to do this is to create a subdirectory appropriately
747 named, use @code{ln} or @code{cp} to install the proper files in it, and 669 named, use @code{ln} or @code{cp} to install the proper files in it, and
748 then @code{tar} that subdirectory. 670 then @code{tar} that subdirectory.
749 671
750 Compress the tar file file with @code{gzip}. For example, the actual 672 Compress the tar file with @code{gzip}. For example, the actual
751 distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}. 673 distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}.
752 674
753 The @code{dist} target should explicitly depend on all non-source files 675 The @code{dist} target should explicitly depend on all non-source files
754 that are in the distribution, to make sure they are up to date in the 676 that are in the distribution, to make sure they are up to date in the
755 distribution. 677 distribution.
796 @end smallexample 718 @end smallexample
797 719
798 This rule should not modify the directories where compilation is done. 720 This rule should not modify the directories where compilation is done.
799 It should do nothing but create installation directories. 721 It should do nothing but create installation directories.
800 @end table 722 @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.