1 @comment This file is included by both standards.texi and make.texinfo.
2 @comment It was broken out of standards.texi on 1/6/93 by roland.
4 @node Makefile Conventions
5 @chapter Makefile Conventions
6 @comment standards.texi does not print an index, but make.texinfo does.
7 @cindex makefile, conventions for
8 @cindex conventions for makefiles
9 @cindex standards for makefiles
23 describes conventions for writing the Makefiles for GNU programs.
26 * Makefile Basics:: General Conventions for Makefiles
27 * Utilities in Makefiles:: Utilities in Makefiles
28 * Command Variables:: Variables for Specifying Commands
29 * Directory Variables:: Variables for Installation Directories
30 * Standard Targets:: Standard Targets for Users
31 * Install Command Categories:: Three categories of commands in the `install'
32 rule: normal, pre-install and post-install.
36 @section General Conventions for Makefiles
38 Every Makefile should contain this line:
45 to avoid trouble on systems where the @code{SHELL} variable might be
46 inherited from the environment. (This is never a problem with GNU
49 Different @code{make} programs have incompatible suffix lists and
50 implicit rules, and this sometimes creates confusion or misbehavior. So
51 it is a good idea to set the suffix list explicitly using only the
52 suffixes you need in the particular Makefile, like this:
60 The first line clears out the suffix list, the second introduces all
61 suffixes which may be subject to implicit rules in this Makefile.
63 Don't assume that @file{.} is in the path for command execution. When
64 you need to run programs that are a part of your package during the
65 make, please make sure that it uses @file{./} if the program is built as
66 part of the make or @file{$(srcdir)/} if the file is an unchanging part
67 of the source code. Without one of these prefixes, the current search
70 The distinction between @file{./} (the @dfn{build directory}) and
71 @file{$(srcdir)/} (the @dfn{source directory}) is important because
72 users can build in a separate directory using the @samp{--srcdir} option
73 to @file{configure}. A rule of the form:
76 foo.1 : foo.man sedscript
77 sed -e sedscript foo.man > foo.1
81 will fail when the build directory is not the source directory, because
82 @file{foo.man} and @file{sedscript} are in the the source directory.
84 When using GNU @code{make}, relying on @samp{VPATH} to find the source
85 file will work in the case where there is a single dependency file,
86 since the @code{make} automatic variable @samp{$<} will represent the
87 source file wherever it is. (Many versions of @code{make} set @samp{$<}
88 only in implicit rules.) A Makefile target like
92 $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
96 should instead be written as
100 $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@@
104 in order to allow @samp{VPATH} to work correctly. When the target has
105 multiple dependencies, using an explicit @samp{$(srcdir)} is the easiest
106 way to make the rule work well. For example, the target above for
107 @file{foo.1} is best written as:
110 foo.1 : foo.man sedscript
111 sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@
114 GNU distributions usually contain some files which are not source
115 files---for example, Info files, and the output from Autoconf, Automake,
116 Bison or Flex. Since these files normally appear in the source
117 directory, they should always appear in the source directory, not in the
118 build directory. So Makefile rules to update them should put the
119 updated files in the source directory.
121 However, if a file does not appear in the distribution, then the
122 Makefile should not put it in the source directory, because building a
123 program in ordinary circumstances should not modify the source directory
126 Try to make the build and installation targets, at least (and all their
127 subtargets) work correctly with a parallel @code{make}.
129 @node Utilities in Makefiles
130 @section Utilities in Makefiles
132 Write the Makefile commands (and any shell scripts, such as
133 @code{configure}) to run in @code{sh}, not in @code{csh}. Don't use any
134 special features of @code{ksh} or @code{bash}.
136 The @code{configure} script and the Makefile rules for building and
137 installation should not use any utilities directly except these:
140 @c gunzip gzip md5sum
141 @c mkfifo mknod tee uname
144 cat cmp cp diff echo egrep expr false grep install-info
145 ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
148 The compression program @code{gzip} can be used in the @code{dist} rule.
150 Stick to the generally supported options for these programs. For
151 example, don't use @samp{mkdir -p}, convenient as it may be, because
152 most systems don't support it.
154 It is a good idea to avoid creating symbolic links in makefiles, since a
155 few systems don't support them.
157 The Makefile rules for building and installation can also use compilers
158 and related programs, but should do so via @code{make} variables so that the
159 user can substitute alternatives. Here are some of the programs we
163 ar bison cc flex install ld ldconfig lex
164 make makeinfo ranlib texi2dvi yacc
167 Use the following @code{make} variables to run those programs:
170 $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
171 $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
174 When you use @code{ranlib} or @code{ldconfig}, you should make sure
175 nothing bad happens if the system does not have the program in question.
176 Arrange to ignore an error from that command, and print a message before
177 the command to tell the user that failure of this command does not mean
178 a problem. (The Autoconf @samp{AC_PROG_RANLIB} macro can help with
181 If you use symbolic links, you should implement a fallback for systems
182 that don't have symbolic links.
184 Additional utilities that can be used via Make variables are:
187 chgrp chmod chown mknod
190 It is ok to use other utilities in Makefile portions (or scripts)
191 intended only for particular systems where you know those utilities
194 @node Command Variables
195 @section Variables for Specifying Commands
197 Makefiles should provide variables for overriding certain commands, options,
200 In particular, you should run most utility programs via variables.
201 Thus, if you use Bison, have a variable named @code{BISON} whose default
202 value is set with @samp{BISON = bison}, and refer to it with
203 @code{$(BISON)} whenever you need to use Bison.
205 File management utilities such as @code{ln}, @code{rm}, @code{mv}, and
206 so on, need not be referred to through variables in this way, since users
207 don't need to replace them with other programs.
209 Each program-name variable should come with an options variable that is
210 used to supply options to the program. Append @samp{FLAGS} to the
211 program-name variable name to get the options variable name---for
212 example, @code{BISONFLAGS}. (The name @code{CFLAGS} is an exception to
213 this rule, but we keep it because it is standard.) Use @code{CPPFLAGS}
214 in any compilation command that runs the preprocessor, and use
215 @code{LDFLAGS} in any compilation command that does linking as well as
216 in any direct use of @code{ld}.
218 If there are C compiler options that @emph{must} be used for proper
219 compilation of certain files, do not include them in @code{CFLAGS}.
220 Users expect to be able to specify @code{CFLAGS} freely themselves.
221 Instead, arrange to pass the necessary options to the C compiler
222 independently of @code{CFLAGS}, by writing them explicitly in the
223 compilation commands or by defining an implicit rule, like this:
227 ALL_CFLAGS = -I. $(CFLAGS)
229 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
232 Do include the @samp{-g} option in @code{CFLAGS}, because that is not
233 @emph{required} for proper compilation. You can consider it a default
234 that is only recommended. If the package is set up so that it is
235 compiled with GCC by default, then you might as well include @samp{-O}
236 in the default value of @code{CFLAGS} as well.
238 Put @code{CFLAGS} last in the compilation command, after other variables
239 containing compiler options, so the user can use @code{CFLAGS} to
242 Every Makefile should define the variable @code{INSTALL}, which is the
243 basic command for installing a file into the system.
245 Every Makefile should also define the variables @code{INSTALL_PROGRAM}
246 and @code{INSTALL_DATA}. (The default for each of these should be
247 @code{$(INSTALL)}.) Then it should use those variables as the commands
248 for actual installation, for executables and nonexecutables
249 respectively. Use these variables as follows:
252 $(INSTALL_PROGRAM) foo $(bindir)/foo
253 $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
257 Always use a file name, not a directory name, as the second argument of
258 the installation commands. Use a separate command for each file to be
261 @node Directory Variables
262 @section Variables for Installation Directories
264 Installation directories should always be named by variables, so it is
265 easy to install in a nonstandard place. The standard names for these
266 variables are described below. They are based on a standard filesystem
267 layout; variants of it are used in SVR4, 4.4BSD, Linux, Ultrix v4, and
268 other modern operating systems.
270 These two variables set the root for the installation. All the other
271 installation directories should be subdirectories of one of these two,
272 and nothing should be directly installed into these two directories.
276 A prefix used in constructing the default values of the variables listed
277 below. The default value of @code{prefix} should be @file{/usr/local}.
278 When building the complete GNU system, the prefix will be empty and
279 @file{/usr} will be a symbolic link to @file{/}.
280 (If you are using Autoconf, write it as @samp{@@prefix@@}.)
283 A prefix used in constructing the default values of some of the
284 variables listed below. The default value of @code{exec_prefix} should
286 (If you are using Autoconf, write it as @samp{@@exec_prefix@@}.)
288 Generally, @code{$(exec_prefix)} is used for directories that contain
289 machine-specific files (such as executables and subroutine libraries),
290 while @code{$(prefix)} is used directly for other directories.
293 Executable programs are installed in one of the following directories.
297 The directory for installing executable programs that users can run.
298 This should normally be @file{/usr/local/bin}, but write it as
299 @file{$(exec_prefix)/bin}.
300 (If you are using Autoconf, write it as @samp{@@bindir@@}.)
303 The directory for installing executable programs that can be run from
304 the shell, but are only generally useful to system administrators. This
305 should normally be @file{/usr/local/sbin}, but write it as
306 @file{$(exec_prefix)/sbin}.
307 (If you are using Autoconf, write it as @samp{@@sbindir@@}.)
310 @comment This paragraph adjusted to avoid overfull hbox --roland 5jul94
311 The directory for installing executable programs to be run by other
312 programs rather than by users. This directory should normally be
313 @file{/usr/local/libexec}, but write it as @file{$(exec_prefix)/libexec}.
314 (If you are using Autoconf, write it as @samp{@@libexecdir@@}.)
317 Data files used by the program during its execution are divided into
318 categories in two ways.
322 Some files are normally modified by programs; others are never normally
323 modified (though users may edit some of these).
326 Some files are architecture-independent and can be shared by all
327 machines at a site; some are architecture-dependent and can be shared
328 only by machines of the same kind and operating system; others may never
329 be shared between two machines.
332 This makes for six different possibilities. However, we want to
333 discourage the use of architecture-dependent files, aside from object
334 files and libraries. It is much cleaner to make other data files
335 architecture-independent, and it is generally not hard.
337 Therefore, here are the variables Makefiles should use to specify
342 The directory for installing read-only architecture independent data
343 files. This should normally be @file{/usr/local/share}, but write it as
344 @file{$(prefix)/share}.
345 (If you are using Autoconf, write it as @samp{@@datadir@@}.)
346 As a special exception, see @file{$(infodir)}
347 and @file{$(includedir)} below.
350 The directory for installing read-only data files that pertain to a
351 single machine--that is to say, files for configuring a host. Mailer
352 and network configuration files, @file{/etc/passwd}, and so forth belong
353 here. All the files in this directory should be ordinary ASCII text
354 files. This directory should normally be @file{/usr/local/etc}, but
355 write it as @file{$(prefix)/etc}.
356 (If you are using Autoconf, write it as @samp{@@sysconfdir@@}.)
358 @c rewritten to avoid overfull hbox --tower
359 Do not install executables
361 in this directory (they probably
362 belong in @file{$(libexecdir)} or @file{$(sbindir)}). Also do not
363 install files that are modified in the normal course of their use
364 (programs whose purpose is to change the configuration of the system
365 excluded). Those probably belong in @file{$(localstatedir)}.
368 The directory for installing architecture-independent data files which
369 the programs modify while they run. This should normally be
370 @file{/usr/local/com}, but write it as @file{$(prefix)/com}.
371 (If you are using Autoconf, write it as @samp{@@sharedstatedir@@}.)
374 The directory for installing data files which the programs modify while
375 they run, and that pertain to one specific machine. Users should never
376 need to modify files in this directory to configure the package's
377 operation; put such configuration information in separate files that go
378 in @file{$(datadir)} or @file{$(sysconfdir)}. @file{$(localstatedir)}
379 should normally be @file{/usr/local/var}, but write it as
380 @file{$(prefix)/var}.
381 (If you are using Autoconf, write it as @samp{@@localstatedir@@}.)
384 The directory for object files and libraries of object code. Do not
385 install executables here, they probably ought to go in @file{$(libexecdir)}
386 instead. The value of @code{libdir} should normally be
387 @file{/usr/local/lib}, but write it as @file{$(exec_prefix)/lib}.
388 (If you are using Autoconf, write it as @samp{@@libdir@@}.)
391 The directory for installing the Info files for this package. By
392 default, it should be @file{/usr/local/info}, but it should be written
393 as @file{$(prefix)/info}.
394 (If you are using Autoconf, write it as @samp{@@infodir@@}.)
397 The directory for installing any Emacs Lisp files in this package. By
398 default, it should be @file{/usr/local/share/emacs/site-lisp}, but it
399 should be written as @file{$(prefix)/share/emacs/site-lisp}.
401 If you are using Autoconf, write the default as @samp{@@lispdir@@}.
402 In order to make @samp{@@lispdir@@} work, you need the following lines
403 in your @file{configure.in} file:
406 lispdir='$@{datadir@}/emacs/site-lisp'
411 @c rewritten to avoid overfull hbox --roland
412 The directory for installing header files to be included by user
413 programs with the C @samp{#include} preprocessor directive. This
414 should normally be @file{/usr/local/include}, but write it as
415 @file{$(prefix)/include}.
416 (If you are using Autoconf, write it as @samp{@@includedir@@}.)
418 Most compilers other than GCC do not look for header files in
419 @file{/usr/local/include}. So installing the header files this way is
420 only useful with GCC. Sometimes this is not a problem because some
421 libraries are only really intended to work with GCC. But some libraries
422 are intended to work with other compilers. They should install their
423 header files in two places, one specified by @code{includedir} and one
424 specified by @code{oldincludedir}.
427 The directory for installing @samp{#include} header files for use with
428 compilers other than GCC. This should normally be @file{/usr/include}.
429 (If you are using Autoconf, you can write it as @samp{@@oldincludedir@@}.)
431 The Makefile commands should check whether the value of
432 @code{oldincludedir} is empty. If it is, they should not try to use
433 it; they should cancel the second installation of the header files.
435 A package should not replace an existing header in this directory unless
436 the header came from the same package. Thus, if your Foo package
437 provides a header file @file{foo.h}, then it should install the header
438 file in the @code{oldincludedir} directory if either (1) there is no
439 @file{foo.h} there or (2) the @file{foo.h} that exists came from the Foo
442 To tell whether @file{foo.h} came from the Foo package, put a magic
443 string in the file---part of a comment---and @code{grep} for that string.
446 Unix-style man pages are installed in one of the following:
450 The top-level directory for installing the man pages (if any) for this
451 package. It will normally be @file{/usr/local/man}, but you should
452 write it as @file{$(prefix)/man}.
453 (If you are using Autoconf, write it as @samp{@@mandir@@}.)
456 The directory for installing section 1 man pages. Write it as
457 @file{$(mandir)/man1}.
459 The directory for installing section 2 man pages. Write it as
460 @file{$(mandir)/man2}
463 @strong{Don't make the primary documentation for any GNU software be a
464 man page. Write a manual in Texinfo instead. Man pages are just for
465 the sake of people running GNU software on Unix, which is a secondary
469 The file name extension for the installed man page. This should contain
470 a period followed by the appropriate digit; it should normally be @samp{.1}.
473 The file name extension for installed section 1 man pages.
475 The file name extension for installed section 2 man pages.
477 Use these names instead of @samp{manext} if the package needs to install man
478 pages in more than one section of the manual.
481 And finally, you should set the following variable:
485 The directory for the sources being compiled. The value of this
486 variable is normally inserted by the @code{configure} shell script.
487 (If you are using Autconf, use @samp{srcdir = @@srcdir@@}.)
493 @c I have changed some of the comments here slightly to fix an overfull
494 @c hbox, so the make manual can format correctly. --roland
495 # Common prefix for installation directories.
496 # NOTE: This directory must exist when you start the install.
498 exec_prefix = $(prefix)
499 # Where to put the executable for the command `gcc'.
500 bindir = $(exec_prefix)/bin
501 # Where to put the directories used by the compiler.
502 libexecdir = $(exec_prefix)/libexec
503 # Where to put the Info files.
504 infodir = $(prefix)/info
507 If your program installs a large number of files into one of the
508 standard user-specified directories, it might be useful to group them
509 into a subdirectory particular to that program. If you do this, you
510 should write the @code{install} rule to create these subdirectories.
512 Do not expect the user to include the subdirectory name in the value of
513 any of the variables listed above. The idea of having a uniform set of
514 variable names for installation directories is to enable the user to
515 specify the exact same values for several different GNU packages. In
516 order for this to be useful, all the packages must be designed so that
517 they will work sensibly when the user does so.
519 @node Standard Targets
520 @section Standard Targets for Users
522 All GNU programs should have the following targets in their Makefiles:
526 Compile the entire program. This should be the default target. This
527 target need not rebuild any documentation files; Info files should
528 normally be included in the distribution, and DVI files should be made
529 only when explicitly asked for.
531 By default, the Make rules should compile and link with @samp{-g}, so
532 that executable programs have debugging symbols. Users who don't mind
533 being helpless can strip the executables later if they wish.
536 Compile the program and copy the executables, libraries, and so on to
537 the file names where they should reside for actual use. If there is a
538 simple test to verify that a program is properly installed, this target
539 should run that test.
541 Do not strip executables when installing them. Devil-may-care users can
542 use the @code{install-strip} target to do that.
544 If possible, write the @code{install} target rule so that it does not
545 modify anything in the directory where the program was built, provided
546 @samp{make all} has just been done. This is convenient for building the
547 program under one user name and installing it under another.
549 The commands should create all the directories in which files are to be
550 installed, if they don't already exist. This includes the directories
551 specified as the values of the variables @code{prefix} and
552 @code{exec_prefix}, as well as all subdirectories that are needed.
553 One way to do this is by means of an @code{installdirs} target
556 Use @samp{-} before any command for installing a man page, so that
557 @code{make} will ignore any errors. This is in case there are systems
558 that don't have the Unix man page documentation system installed.
560 The way to install Info files is to copy them into @file{$(infodir)}
561 with @code{$(INSTALL_DATA)} (@pxref{Command Variables}), and then run
562 the @code{install-info} program if it is present. @code{install-info}
563 is a program that edits the Info @file{dir} file to add or update the
564 menu entry for the given Info file; it is part of the Texinfo package.
565 Here is a sample rule to install an Info file:
567 @comment This example has been carefully formatted for the Make manual.
568 @comment Please do not reformat it without talking to roland@gnu.ai.mit.edu.
570 $(infodir)/foo.info: foo.info
572 # There may be a newer info file in . than in srcdir.
573 -if test -f foo.info; then d=.; \
574 else d=$(srcdir); fi; \
575 $(INSTALL_DATA) $$d/foo.info $@@; \
576 # Run install-info only if it exists.
577 # Use `if' instead of just prepending `-' to the
578 # line so we notice real errors from install-info.
579 # We use `$(SHELL) -c' because some shells do not
580 # fail gracefully when there is an unknown command.
581 if $(SHELL) -c 'install-info --version' \
582 >/dev/null 2>&1; then \
583 install-info --dir-file=$(infodir)/dir \
584 $(infodir)/foo.info; \
588 When writing the @code{install} target, you must classify all the
589 commands into three categories: normal ones, @dfn{pre-installation}
590 commands and @dfn{post-installation} commands. @xref{Install Command
594 Delete all the installed files---the copies that the @samp{install}
597 This rule should not modify the directories where compilation is done,
598 only the directories where files are installed.
600 The uninstallation commands are divided into three categories, just like
601 the installation commands. @xref{Install Command Categories}.
604 Like @code{install}, but strip the executable files while installing
605 them. In many cases, the definition of this target can be very simple:
609 $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
613 Normally we do not recommend stripping an executable unless you are sure
614 the program has no bugs. However, it can be reasonable to install a
615 stripped executable for actual execution while saving the unstripped
616 executable elsewhere in case there is a bug.
618 @comment The gratuitous blank line here is to make the table look better
619 @comment in the printed Make manual. Please leave it in.
622 Delete all files from the current directory that are normally created by
623 building the program. Don't delete the files that record the
624 configuration. Also preserve files that could be made by building, but
625 normally aren't because the distribution comes with them.
627 Delete @file{.dvi} files here if they are not part of the distribution.
630 Delete all files from the current directory that are created by
631 configuring or building the program. If you have unpacked the source
632 and built the program without creating any other files, @samp{make
633 distclean} should leave only the files that were in the distribution.
636 Like @samp{clean}, but may refrain from deleting a few files that people
637 normally don't want to recompile. For example, the @samp{mostlyclean}
638 target for GCC does not delete @file{libgcc.a}, because recompiling it
639 is rarely necessary and takes a lot of time.
641 @item maintainer-clean
642 Delete almost everything from the current directory that can be
643 reconstructed with this Makefile. This typically includes everything
644 deleted by @code{distclean}, plus more: C source files produced by
645 Bison, tags tables, Info files, and so on.
647 The reason we say ``almost everything'' is that running the command
648 @samp{make maintainer-clean} should not delete @file{configure} even if
649 @file{configure} can be remade using a rule in the Makefile. More generally,
650 @samp{make maintainer-clean} should not delete anything that needs to
651 exist in order to run @file{configure} and then begin to build the
652 program. This is the only exception; @code{maintainer-clean} should
653 delete everything else that can be rebuilt.
655 The @samp{maintainer-clean} target is intended to be used by a maintainer of
656 the package, not by ordinary users. You may need special tools to
657 reconstruct some of the files that @samp{make maintainer-clean} deletes.
658 Since these files are normally included in the distribution, we don't
659 take care to make them easy to reconstruct. If you find you need to
660 unpack the full distribution again, don't blame us.
662 To help make users aware of this, the commands for the special
663 @code{maintainer-clean} target should start with these two:
666 @@echo 'This command is intended for maintainers to use; it'
667 @@echo 'deletes files that may need special tools to rebuild.'
671 Update a tags table for this program.
675 Generate any Info files needed. The best way to write the rules is as
681 foo.info: foo.texi chap1.texi chap2.texi
682 $(MAKEINFO) $(srcdir)/foo.texi
686 You must define the variable @code{MAKEINFO} in the Makefile. It should
687 run the @code{makeinfo} program, which is part of the Texinfo
690 Normally a GNU distribution comes with Info files, and that means the
691 Info files are present in the source directory. Therefore, the Make
692 rule for an info file should update it in the source directory. When
693 users build the package, ordinarily Make will not update the Info files
694 because they will already be up to date.
697 Generate DVI files for all Texinfo documentation.
703 foo.dvi: foo.texi chap1.texi chap2.texi
704 $(TEXI2DVI) $(srcdir)/foo.texi
708 You must define the variable @code{TEXI2DVI} in the Makefile. It should
709 run the program @code{texi2dvi}, which is part of the Texinfo
710 distribution.@footnote{@code{texi2dvi} uses @TeX{} to do the real work
711 of formatting. @TeX{} is not distributed with Texinfo.} Alternatively,
712 write just the dependencies, and allow GNU @code{make} to provide the command.
715 Create a distribution tar file for this program. The tar file should be
716 set up so that the file names in the tar file start with a subdirectory
717 name which is the name of the package it is a distribution for. This
718 name can include the version number.
720 For example, the distribution tar file of GCC version 1.40 unpacks into
721 a subdirectory named @file{gcc-1.40}.
723 The easiest way to do this is to create a subdirectory appropriately
724 named, use @code{ln} or @code{cp} to install the proper files in it, and
725 then @code{tar} that subdirectory.
727 Compress the tar file file with @code{gzip}. For example, the actual
728 distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}.
730 The @code{dist} target should explicitly depend on all non-source files
731 that are in the distribution, to make sure they are up to date in the
734 @xref{Releases, , Making Releases}.
737 @xref{Releases, , Making Releases, standards, GNU Coding Standards}.
741 Perform self-tests (if any). The user must build the program before
742 running the tests, but need not install the program; you should write
743 the self-tests so that they work when the program is built but not
747 The following targets are suggested as conventional names, for programs
748 in which they are useful.
752 Perform installation tests (if any). The user must build and install
753 the program before running the tests. You should not assume that
754 @file{$(bindir)} is in the search path.
757 It's useful to add a target named @samp{installdirs} to create the
758 directories where files are installed, and their parent directories.
759 There is a script called @file{mkinstalldirs} which is convenient for
760 this; you can find it in the Texinfo package.
761 @c It's in /gd/gnu/lib/mkinstalldirs.
762 You can use a rule like this:
764 @comment This has been carefully formatted to look decent in the Make manual.
765 @comment Please be sure not to make it extend any further to the right.--roland
767 # Make sure all installation directories (e.g. $(bindir))
768 # actually exist by making them if necessary.
769 installdirs: mkinstalldirs
770 $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
771 $(libdir) $(infodir) \
775 This rule should not modify the directories where compilation is done.
776 It should do nothing but create installation directories.
779 @node Install Command Categories
780 @section Install Command Categories
782 @cindex pre-installation commands
783 @cindex post-installation commands
784 When writing the @code{install} target, you must classify all the
785 commands into three categories: normal ones, @dfn{pre-installation}
786 commands and @dfn{post-installation} commands.
788 Normal commands move files into their proper places, and set their
789 modes. They may not alter any files except the ones that come entirely
790 from the package they belong to.
792 Pre-installation and post-installation commands may alter other files;
793 in particular, they can edit global configuration files or data bases.
795 Pre-installation commands are typically executed before the normal
796 commands, and post-installation commands are typically run after the
799 The most common use for a post-installation command is to run
800 @code{install-info}. This cannot be done with a normal command, since
801 it alters a file (the Info directory) which does not come entirely and
802 solely from the package being installed. It is a post-installation
803 command because it needs to be done after the normal command which
804 installs the package's Info files.
806 Most programs don't need any pre-installation commands, but we have the
807 feature just in case it is needed.
809 To classify the commands in the @code{install} rule into these three
810 categories, insert @dfn{category lines} among them. A category line
811 specifies the category for the commands that follow.
813 A category line consists of a tab and a reference to a special Make
814 variable, plus an optional comment at the end. There are three
815 variables you can use, one for each category; the variable name
816 specifies the category. Category lines are no-ops in ordinary execution
817 because these three Make variables are normally undefined (and you
818 @emph{should not} define them in the makefile).
820 Here are the three possible category lines, each with a comment that
821 explains what it means:
824 $(PRE_INSTALL) # @r{Pre-install commands follow.}
825 $(POST_INSTALL) # @r{Post-install commands follow.}
826 $(NORMAL_INSTALL) # @r{Normal commands follow.}
829 If you don't use a category line at the beginning of the @code{install}
830 rule, all the commands are classified as normal until the first category
831 line. If you don't use any category lines, all the commands are
832 classified as normal.
834 These are the category lines for @code{uninstall}:
837 $(PRE_UNINSTALL) # @r{Pre-uninstall commands follow.}
838 $(POST_UNINSTALL) # @r{Post-uninstall commands follow.}
839 $(NORMAL_UNINSTALL) # @r{Normal commands follow.}
842 Typically, a pre-uninstall command would be used for deleting entries
843 from the Info directory.
845 If the @code{install} or @code{uninstall} target has any dependencies
846 which act as subroutines of installation, then you should start
847 @emph{each} dependency's commands with a category line, and start the
848 main target's commands with a category line also. This way, you can
849 ensure that each command is placed in the right category regardless of
850 which of the dependencies actually run.
852 Pre-installation and post-installation commands should not run any
853 programs except for these:
856 [ basename bash cat chgrp chmod chown cmp cp dd diff echo
857 egrep expand expr false fgrep find getopt grep gunzip gzip
858 hostname install install-info kill ldconfig ln ls md5sum
859 mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
860 test touch true uname xargs yes
863 @cindex binary packages
864 The reason for distinguishing the commands in this way is for the sake
865 of making binary packages. Typically a binary package contains all the
866 executables and other files that need to be installed, and has its own
867 method of installing them---so it does not need to run the normal
868 installation commands. But installing the binary package does need to
869 execute the pre-installation and post-installation commands.
871 Programs to build binary packages work by extracting the
872 pre-installation and post-installation commands. Here is one way of
873 extracting the pre-installation commands:
876 make -n install -o all \
877 PRE_INSTALL=pre-install \
878 POST_INSTALL=post-install \
879 NORMAL_INSTALL=normal-install \
880 | gawk -f pre-install.awk
884 where the file @file{pre-install.awk} could contain this:
887 $0 ~ /^\t[ \t]*(normal_install|post_install)[ \t]*$/ @{on = 0@}
889 $0 ~ /^\t[ \t]*pre_install[ \t]*$/ @{on = 1@}
892 The resulting file of pre-installation commands is executed as a shell
893 script as part of installing the binary package.