* check-module: Add copyright notice.
[pspp] / doc / make-stds.texi
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.
3
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
10
11 @c Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001,
12 @c 2004, 2005, 2006 Free Software Foundation, Inc.
13
14 @c Permission is granted to copy, distribute and/or modify this document
15 @c under the terms of the GNU Free Documentation License, Version 1.1
16 @c or any later version published by the Free Software Foundation;
17 @c with no Invariant Sections, with no
18 @c Front-Cover Texts, and with no Back-Cover Texts.
19 @c A copy of the license is included in the section entitled ``GNU
20 @c Free Documentation License''.
21
22 This
23 @ifinfo
24 node
25 @end ifinfo
26 @iftex
27 @ifset CODESTD
28 section
29 @end ifset
30 @ifclear CODESTD
31 chapter
32 @end ifclear
33 @end iftex
34 describes conventions for writing the Makefiles for GNU programs.
35 Using Automake will help you write a Makefile that follows these
36 conventions.
37
38 @menu
39 * Makefile Basics::             General conventions for Makefiles.
40 * Utilities in Makefiles::      Utilities to be used in Makefiles.
41 * Command Variables::           Variables for specifying commands.
42 * Directory Variables::         Variables for installation directories.
43 * DESTDIR::                     Supporting staged installs.
44 * Standard Targets::            Standard targets for users.
45 * Install Command Categories::  Three categories of commands in the `install'
46                                   rule: normal, pre-install and post-install.
47 @end menu
48
49 @node Makefile Basics
50 @section General Conventions for Makefiles
51
52 Every Makefile should contain this line:
53
54 @example
55 SHELL = /bin/sh
56 @end example
57
58 @noindent
59 to avoid trouble on systems where the @code{SHELL} variable might be
60 inherited from the environment.  (This is never a problem with GNU
61 @code{make}.)
62
63 Different @code{make} programs have incompatible suffix lists and
64 implicit rules, and this sometimes creates confusion or misbehavior.  So
65 it is a good idea to set the suffix list explicitly using only the
66 suffixes you need in the particular Makefile, like this:
67
68 @example
69 .SUFFIXES:
70 .SUFFIXES: .c .o
71 @end example
72
73 @noindent
74 The first line clears out the suffix list, the second introduces all
75 suffixes which may be subject to implicit rules in this Makefile.
76
77 Don't assume that @file{.} is in the path for command execution.  When
78 you need to run programs that are a part of your package during the
79 make, please make sure that it uses @file{./} if the program is built as
80 part of the make or @file{$(srcdir)/} if the file is an unchanging part
81 of the source code.  Without one of these prefixes, the current search
82 path is used.
83
84 The distinction between @file{./} (the @dfn{build directory}) and
85 @file{$(srcdir)/} (the @dfn{source directory}) is important because
86 users can build in a separate directory using the @samp{--srcdir} option
87 to @file{configure}.  A rule of the form:
88
89 @smallexample
90 foo.1 : foo.man sedscript
91         sed -e sedscript foo.man > foo.1
92 @end smallexample
93
94 @noindent
95 will fail when the build directory is not the source directory, because
96 @file{foo.man} and @file{sedscript} are in the source directory.
97
98 When using GNU @code{make}, relying on @samp{VPATH} to find the source
99 file will work in the case where there is a single dependency file,
100 since the @code{make} automatic variable @samp{$<} will represent the
101 source file wherever it is.  (Many versions of @code{make} set @samp{$<}
102 only in implicit rules.)  A Makefile target like
103
104 @smallexample
105 foo.o : bar.c
106         $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
107 @end smallexample
108
109 @noindent
110 should instead be written as
111
112 @smallexample
113 foo.o : bar.c
114         $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@@
115 @end smallexample
116
117 @noindent
118 in order to allow @samp{VPATH} to work correctly.  When the target has
119 multiple dependencies, using an explicit @samp{$(srcdir)} is the easiest
120 way to make the rule work well.  For example, the target above for
121 @file{foo.1} is best written as:
122
123 @smallexample
124 foo.1 : foo.man sedscript
125         sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@@
126 @end smallexample
127
128 GNU distributions usually contain some files which are not source
129 files---for example, Info files, and the output from Autoconf, Automake,
130 Bison or Flex.  Since these files normally appear in the source
131 directory, they should always appear in the source directory, not in the
132 build directory.  So Makefile rules to update them should put the
133 updated files in the source directory.
134
135 However, if a file does not appear in the distribution, then the
136 Makefile should not put it in the source directory, because building a
137 program in ordinary circumstances should not modify the source directory
138 in any way.
139
140 Try to make the build and installation targets, at least (and all their
141 subtargets) work correctly with a parallel @code{make}.
142
143 @node Utilities in Makefiles
144 @section Utilities in Makefiles
145
146 Write the Makefile commands (and any shell scripts, such as
147 @code{configure}) to run in @code{sh}, not in @code{csh}.  Don't use any
148 special features of @code{ksh} or @code{bash}.
149
150 The @code{configure} script and the Makefile rules for building and
151 installation should not use any utilities directly except these:
152
153 @c dd find
154 @c gunzip gzip md5sum
155 @c mkfifo mknod tee uname
156
157 @example
158 cat cmp cp diff echo egrep expr false grep install-info
159 ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
160 @end example
161
162 The compression program @code{gzip} can be used in the @code{dist} rule.
163
164 Stick to the generally supported options for these programs.  For
165 example, don't use @samp{mkdir -p}, convenient as it may be, because
166 most systems don't support it.
167
168 It is a good idea to avoid creating symbolic links in makefiles, since a
169 few systems don't support them.
170
171 The Makefile rules for building and installation can also use compilers
172 and related programs, but should do so via @code{make} variables so that the
173 user can substitute alternatives.  Here are some of the programs we
174 mean:
175
176 @example
177 ar bison cc flex install ld ldconfig lex
178 make makeinfo ranlib texi2dvi yacc
179 @end example
180
181 Use the following @code{make} variables to run those programs:
182
183 @example
184 $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
185 $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
186 @end example
187
188 When you use @code{ranlib} or @code{ldconfig}, you should make sure
189 nothing bad happens if the system does not have the program in question.
190 Arrange to ignore an error from that command, and print a message before
191 the command to tell the user that failure of this command does not mean
192 a problem.  (The Autoconf @samp{AC_PROG_RANLIB} macro can help with
193 this.)
194
195 If you use symbolic links, you should implement a fallback for systems
196 that don't have symbolic links.
197
198 Additional utilities that can be used via Make variables are:
199
200 @example
201 chgrp chmod chown mknod
202 @end example
203
204 It is ok to use other utilities in Makefile portions (or scripts)
205 intended only for particular systems where you know those utilities
206 exist.
207
208 @node Command Variables
209 @section Variables for Specifying Commands
210
211 Makefiles should provide variables for overriding certain commands, options,
212 and so on.
213
214 In particular, you should run most utility programs via variables.
215 Thus, if you use Bison, have a variable named @code{BISON} whose default
216 value is set with @samp{BISON = bison}, and refer to it with
217 @code{$(BISON)} whenever you need to use Bison.
218
219 File management utilities such as @code{ln}, @code{rm}, @code{mv}, and
220 so on, need not be referred to through variables in this way, since users
221 don't need to replace them with other programs.
222
223 Each program-name variable should come with an options variable that is
224 used to supply options to the program.  Append @samp{FLAGS} to the
225 program-name variable name to get the options variable name---for
226 example, @code{BISONFLAGS}.  (The names @code{CFLAGS} for the C
227 compiler, @code{YFLAGS} for yacc, and @code{LFLAGS} for lex, are
228 exceptions to this rule, but we keep them because they are standard.)
229 Use @code{CPPFLAGS} in any compilation command that runs the
230 preprocessor, and use @code{LDFLAGS} in any compilation command that
231 does linking as well as in any direct use of @code{ld}.
232
233 If there are C compiler options that @emph{must} be used for proper
234 compilation of certain files, do not include them in @code{CFLAGS}.
235 Users expect to be able to specify @code{CFLAGS} freely themselves.
236 Instead, arrange to pass the necessary options to the C compiler
237 independently of @code{CFLAGS}, by writing them explicitly in the
238 compilation commands or by defining an implicit rule, like this:
239
240 @smallexample
241 CFLAGS = -g
242 ALL_CFLAGS = -I. $(CFLAGS)
243 .c.o:
244         $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
245 @end smallexample
246
247 Do include the @samp{-g} option in @code{CFLAGS}, because that is not
248 @emph{required} for proper compilation.  You can consider it a default
249 that is only recommended.  If the package is set up so that it is
250 compiled with GCC by default, then you might as well include @samp{-O}
251 in the default value of @code{CFLAGS} as well.
252
253 Put @code{CFLAGS} last in the compilation command, after other variables
254 containing compiler options, so the user can use @code{CFLAGS} to
255 override the others.
256
257 @code{CFLAGS} should be used in every invocation of the C compiler,
258 both those which do compilation and those which do linking.
259
260 Every Makefile should define the variable @code{INSTALL}, which is the
261 basic command for installing a file into the system.
262
263 Every Makefile should also define the variables @code{INSTALL_PROGRAM}
264 and @code{INSTALL_DATA}.  (The default for @code{INSTALL_PROGRAM} should
265 be @code{$(INSTALL)}; the default for @code{INSTALL_DATA} should be
266 @code{$@{INSTALL@} -m 644}.)  Then it should use those variables as the
267 commands for actual installation, for executables and non-executables
268 respectively.  Minimal use of these variables is as follows:
269
270 @example
271 $(INSTALL_PROGRAM) foo $(bindir)/foo
272 $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
273 @end example
274
275 However, it is preferable to support a @code{DESTDIR} prefix on the
276 target files, as explained in the next section.
277
278 @noindent
279 Always use a file name, not a directory name, as the second argument of
280 the installation commands.  Use a separate command for each file to be
281 installed.
282
283
284 @node DESTDIR
285 @section @code{DESTDIR}: support for staged installs
286
287 @vindex DESTDIR
288 @cindex staged installs
289 @cindex installations, staged
290
291 @code{DESTDIR} is a variable prepended to each installed target file,
292 like this:
293
294 @example
295 $(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo
296 $(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a
297 @end example
298
299 The @code{DESTDIR} variable is specified by the user, either to the
300 @file{configure} script or, more commonly, on the @code{make} command
301 line.  For example:
302
303 @example
304 make DESTDIR=/tmp/stage install
305 @end example
306
307 @noindent
308 @code{DESTDIR} should be supported only in the @code{install*} and
309 @code{uninstall*} targets, as those are the only targets where it is
310 useful.
311
312 If your installation step would normally install
313 @file{/usr/local/bin/foo} and @file{/usr/local/lib/libfoo.a}, then an
314 installation invoked as in the example above would install
315 @file{/tmp/stage/usr/local/bin/foo} and
316 @file{/tmp/stage/usr/local/lib/libfoo.a} instead.
317
318 Prepending the variable @code{DESTDIR} to each target in this way
319 provides for @dfn{staged installs}, where the installed files are not
320 placed directly into their expected location but are instead copied
321 into a temporary location (@code{DESTDIR}).  However, installed files
322 maintain their relative directory structure and any embedded file names
323 will not be modified.
324
325 You should not set the value of @code{DESTDIR} in your @file{Makefile}
326 at all; then the files are installed into their expected locations by
327 default.  Also, specifying @code{DESTDIR} should not change the
328 operation of the software in any way, so its value should not be
329 included in any file contents.
330
331 @code{DESTDIR} support is commonly used in package creation.  It is
332 also helpful to users who want to understand what a given package will
333 install where, and to allow users who don't normally have permissions
334 to install into protected areas to build and install before gaining
335 those permissions.  Finally, it can be useful with tools such as
336 @code{stow}, where code is installed in one place but made to appear
337 to be installed somewhere else using symbolic links or special mount
338 operations.  So, we strongly recommend GNU packages support
339 @code{DESTDIR}, though it is not an absolute requirement.
340
341
342 @node Directory Variables
343 @section Variables for Installation Directories
344
345 Installation directories should always be named by variables, so it is
346 easy to install in a nonstandard place.  The standard names for these
347 variables and the values they should have in GNU packages are
348 described below.  They are based on a standard file system layout;
349 variants of it are used in GNU/Linux and other modern operating
350 systems.
351
352 Installers are expected to override these values when calling
353 @command{make} (e.g., @kbd{make prefix=/usr install} or
354 @command{configure} (e.g., @kbd{configure --prefix=/usr}).  GNU
355 packages should not try to guess which value should be appropriate for
356 these variables on the system they are being installed onto: use the
357 default settings specified here so that all GNU packages behave
358 identically, allowing the installer to achieve any desired layout.
359
360 These first two variables set the root for the installation.  All the
361 other installation directories should be subdirectories of one of
362 these two, and nothing should be directly installed into these two
363 directories.
364
365 @table @code
366 @item prefix
367 @vindex prefix
368 A prefix used in constructing the default values of the variables listed
369 below.  The default value of @code{prefix} should be @file{/usr/local}.
370 When building the complete GNU system, the prefix will be empty and
371 @file{/usr} will be a symbolic link to @file{/}.
372 (If you are using Autoconf, write it as @samp{@@prefix@@}.)
373
374 Running @samp{make install} with a different value of @code{prefix} from
375 the one used to build the program should @emph{not} recompile the
376 program.
377
378 @item exec_prefix
379 @vindex exec_prefix
380 A prefix used in constructing the default values of some of the
381 variables listed below.  The default value of @code{exec_prefix} should
382 be @code{$(prefix)}.
383 (If you are using Autoconf, write it as @samp{@@exec_prefix@@}.)
384
385 Generally, @code{$(exec_prefix)} is used for directories that contain
386 machine-specific files (such as executables and subroutine libraries),
387 while @code{$(prefix)} is used directly for other directories.
388
389 Running @samp{make install} with a different value of @code{exec_prefix}
390 from the one used to build the program should @emph{not} recompile the
391 program.
392 @end table
393
394 Executable programs are installed in one of the following directories.
395
396 @table @code
397 @item bindir
398 @vindex bindir
399 The directory for installing executable programs that users can run.
400 This should normally be @file{/usr/local/bin}, but write it as
401 @file{$(exec_prefix)/bin}.
402 (If you are using Autoconf, write it as @samp{@@bindir@@}.)
403
404 @item sbindir
405 @vindex sbindir
406 The directory for installing executable programs that can be run from
407 the shell, but are only generally useful to system administrators.  This
408 should normally be @file{/usr/local/sbin}, but write it as
409 @file{$(exec_prefix)/sbin}.
410 (If you are using Autoconf, write it as @samp{@@sbindir@@}.)
411
412 @item libexecdir
413 @vindex libexecdir
414 @comment This paragraph adjusted to avoid overfull hbox --roland 5jul94
415 The directory for installing executable programs to be run by other
416 programs rather than by users.  This directory should normally be
417 @file{/usr/local/libexec}, but write it as @file{$(exec_prefix)/libexec}.
418 (If you are using Autoconf, write it as @samp{@@libexecdir@@}.)
419
420 The definition of @samp{libexecdir} is the same for all packages, so
421 you should install your data in a subdirectory thereof.  Most packages
422 install their data under @file{$(libexecdir)/@var{package-name}/},
423 possibly within additional subdirectories thereof, such as
424 @file{$(libexecdir)/@var{package-name}/@var{machine}/@var{version}}.
425 @end table
426
427 Data files used by the program during its execution are divided into
428 categories in two ways.
429
430 @itemize @bullet
431 @item
432 Some files are normally modified by programs; others are never normally
433 modified (though users may edit some of these).
434
435 @item
436 Some files are architecture-independent and can be shared by all
437 machines at a site; some are architecture-dependent and can be shared
438 only by machines of the same kind and operating system; others may never
439 be shared between two machines.
440 @end itemize
441
442 This makes for six different possibilities.  However, we want to
443 discourage the use of architecture-dependent files, aside from object
444 files and libraries.  It is much cleaner to make other data files
445 architecture-independent, and it is generally not hard.
446
447 Here are the variables Makefiles should use to specify directories
448 to put these various kinds of files in:
449
450 @table @samp
451 @item datarootdir
452 The root of the directory tree for read-only architecture-independent
453 data files.  This should normally be @file{/usr/local/share}, but
454 write it as @file{$(prefix)/share}.  (If you are using Autoconf, write
455 it as @samp{@@datarootdir@@}.)  @samp{datadir}'s default value is
456 based on this variable; so are @samp{infodir}, @samp{mandir}, and
457 others.
458
459 @item datadir
460 The directory for installing idiosyncratic read-only
461 architecture-independent data files for this program.  This is usually
462 the same place as @samp{datarootdir}, but we use the two separate
463 variables so that you can move these program-specific files without
464 altering the location for Info files, man pages, etc.
465
466 This should normally be @file{/usr/local/share}, but write it as
467 @file{$(datarootdir)}.  (If you are using Autoconf, write it as
468 @samp{@@datadir@@}.)
469
470 The definition of @samp{datadir} is the same for all packages, so you
471 should install your data in a subdirectory thereof.  Most packages
472 install their data under @file{$(datadir)/@var{package-name}/}.
473
474 @item sysconfdir
475 The directory for installing read-only data files that pertain to a
476 single machine--that is to say, files for configuring a host.  Mailer
477 and network configuration files, @file{/etc/passwd}, and so forth belong
478 here.  All the files in this directory should be ordinary ASCII text
479 files.  This directory should normally be @file{/usr/local/etc}, but
480 write it as @file{$(prefix)/etc}.
481 (If you are using Autoconf, write it as @samp{@@sysconfdir@@}.)
482
483 Do not install executables here in this directory (they probably belong
484 in @file{$(libexecdir)} or @file{$(sbindir)}).  Also do not install
485 files that are modified in the normal course of their use (programs
486 whose purpose is to change the configuration of the system excluded).
487 Those probably belong in @file{$(localstatedir)}.
488
489 @item sharedstatedir
490 The directory for installing architecture-independent data files which
491 the programs modify while they run.  This should normally be
492 @file{/usr/local/com}, but write it as @file{$(prefix)/com}.
493 (If you are using Autoconf, write it as @samp{@@sharedstatedir@@}.)
494
495 @item localstatedir
496 The directory for installing data files which the programs modify while
497 they run, and that pertain to one specific machine.  Users should never
498 need to modify files in this directory to configure the package's
499 operation; put such configuration information in separate files that go
500 in @file{$(datadir)} or @file{$(sysconfdir)}.  @file{$(localstatedir)}
501 should normally be @file{/usr/local/var}, but write it as
502 @file{$(prefix)/var}.
503 (If you are using Autoconf, write it as @samp{@@localstatedir@@}.)
504 @end table
505
506 These variables specify the directory for installing certain specific
507 types of files, if your program has them.  Every GNU package should
508 have Info files, so every program needs @samp{infodir}, but not all
509 need @samp{libdir} or @samp{lispdir}.
510
511 @table @samp
512 @item includedir
513 @c rewritten to avoid overfull hbox --roland
514 The directory for installing header files to be included by user
515 programs with the C @samp{#include} preprocessor directive.  This
516 should normally be @file{/usr/local/include}, but write it as
517 @file{$(prefix)/include}.
518 (If you are using Autoconf, write it as @samp{@@includedir@@}.)
519
520 Most compilers other than GCC do not look for header files in directory
521 @file{/usr/local/include}.  So installing the header files this way is
522 only useful with GCC.  Sometimes this is not a problem because some
523 libraries are only really intended to work with GCC.  But some libraries
524 are intended to work with other compilers.  They should install their
525 header files in two places, one specified by @code{includedir} and one
526 specified by @code{oldincludedir}.
527
528 @item oldincludedir
529 The directory for installing @samp{#include} header files for use with
530 compilers other than GCC.  This should normally be @file{/usr/include}.
531 (If you are using Autoconf, you can write it as @samp{@@oldincludedir@@}.)
532
533 The Makefile commands should check whether the value of
534 @code{oldincludedir} is empty.  If it is, they should not try to use
535 it; they should cancel the second installation of the header files.
536
537 A package should not replace an existing header in this directory unless
538 the header came from the same package.  Thus, if your Foo package
539 provides a header file @file{foo.h}, then it should install the header
540 file in the @code{oldincludedir} directory if either (1) there is no
541 @file{foo.h} there or (2) the @file{foo.h} that exists came from the Foo
542 package.
543
544 To tell whether @file{foo.h} came from the Foo package, put a magic
545 string in the file---part of a comment---and @code{grep} for that string.
546
547 @item docdir
548 The directory for installing documentation files (other than Info) for
549 this package.  By default, it should be
550 @file{/usr/local/share/doc/@var{yourpkg}}, but it should be written as
551 @file{$(datarootdir)/doc/@var{yourpkg}}.  (If you are using Autoconf,
552 write it as @samp{@@docdir@@}.)  The @var{yourpkg} subdirectory, which
553 may include a version number, prevents collisions among files with
554 common names, such as @file{README}.
555
556 @item infodir
557 The directory for installing the Info files for this package.  By
558 default, it should be @file{/usr/local/share/info}, but it should be
559 written as @file{$(datarootdir)/info}.  (If you are using Autoconf,
560 write it as @samp{@@infodir@@}.)  @code{infodir} is separate from
561 @code{docdir} for compatibility with existing practice.
562
563 @item htmldir
564 @itemx dvidir
565 @itemx pdfdir
566 @itemx psdir
567 Directories for installing documentation files in the particular
568 format.  They should all be set to @code{$(docdir)} by default.  (If
569 you are using Autoconf, write them as @samp{@@htmldir@@},
570 @samp{@@dvidir@@}, etc.)  Packages which supply several translations
571 of their documentation should install them in
572 @samp{$(htmldir)/}@var{ll}, @samp{$(pdfdir)/}@var{ll}, etc. where
573 @var{ll} is a locale abbreviation such as @samp{en} or @samp{pt_BR}.
574
575 @item libdir
576 The directory for object files and libraries of object code.  Do not
577 install executables here, they probably ought to go in @file{$(libexecdir)}
578 instead.  The value of @code{libdir} should normally be
579 @file{/usr/local/lib}, but write it as @file{$(exec_prefix)/lib}.
580 (If you are using Autoconf, write it as @samp{@@libdir@@}.)
581
582 @item lispdir
583 The directory for installing any Emacs Lisp files in this package.  By
584 default, it should be @file{/usr/local/share/emacs/site-lisp}, but it
585 should be written as @file{$(datarootdir)/emacs/site-lisp}.
586
587 If you are using Autoconf, write the default as @samp{@@lispdir@@}.
588 In order to make @samp{@@lispdir@@} work, you need the following lines
589 in your @file{configure.in} file:
590
591 @example
592 lispdir='$@{datarootdir@}/emacs/site-lisp'
593 AC_SUBST(lispdir)
594 @end example
595
596 @item localedir
597 The directory for installing locale-specific message catalogs for this
598 package.  By default, it should be @file{/usr/local/share/locale}, but
599 it should be written as @file{$(datarootdir)/locale}.  (If you are
600 using Autoconf, write it as @samp{@@localedir@@}.)  This directory
601 usually has a subdirectory per locale.
602 @end table
603
604 Unix-style man pages are installed in one of the following:
605
606 @table @samp
607 @item mandir
608 The top-level directory for installing the man pages (if any) for this
609 package.  It will normally be @file{/usr/local/share/man}, but you
610 should write it as @file{$(datarootdir)/man}.  (If you are using
611 Autoconf, write it as @samp{@@mandir@@}.)
612
613 @item man1dir
614 The directory for installing section 1 man pages.  Write it as
615 @file{$(mandir)/man1}.
616 @item man2dir
617 The directory for installing section 2 man pages.  Write it as
618 @file{$(mandir)/man2}
619 @item @dots{}
620
621 @strong{Don't make the primary documentation for any GNU software be a
622 man page.  Write a manual in Texinfo instead.  Man pages are just for
623 the sake of people running GNU software on Unix, which is a secondary
624 application only.}
625
626 @item manext
627 The file name extension for the installed man page.  This should contain
628 a period followed by the appropriate digit; it should normally be @samp{.1}.
629
630 @item man1ext
631 The file name extension for installed section 1 man pages.
632 @item man2ext
633 The file name extension for installed section 2 man pages.
634 @item @dots{}
635 Use these names instead of @samp{manext} if the package needs to install man
636 pages in more than one section of the manual.
637 @end table
638
639 And finally, you should set the following variable:
640
641 @table @samp
642 @item srcdir
643 The directory for the sources being compiled.  The value of this
644 variable is normally inserted by the @code{configure} shell script.
645 (If you are using Autoconf, use @samp{srcdir = @@srcdir@@}.)
646 @end table
647
648 For example:
649
650 @smallexample
651 @c I have changed some of the comments here slightly to fix an overfull
652 @c hbox, so the make manual can format correctly. --roland
653 # Common prefix for installation directories.
654 # NOTE: This directory must exist when you start the install.
655 prefix = /usr/local
656 datarootdir = $(prefix)/share
657 datadir = $(datarootdir)
658 exec_prefix = $(prefix)
659 # Where to put the executable for the command `gcc'.
660 bindir = $(exec_prefix)/bin
661 # Where to put the directories used by the compiler.
662 libexecdir = $(exec_prefix)/libexec
663 # Where to put the Info files.
664 infodir = $(datarootdir)/info
665 @end smallexample
666
667 If your program installs a large number of files into one of the
668 standard user-specified directories, it might be useful to group them
669 into a subdirectory particular to that program.  If you do this, you
670 should write the @code{install} rule to create these subdirectories.
671
672 Do not expect the user to include the subdirectory name in the value of
673 any of the variables listed above.  The idea of having a uniform set of
674 variable names for installation directories is to enable the user to
675 specify the exact same values for several different GNU packages.  In
676 order for this to be useful, all the packages must be designed so that
677 they will work sensibly when the user does so.
678
679 At times, not all of these variables may be implemented in the current
680 release of Autoconf and/or Automake; but as of Autoconf@tie{}2.60, we
681 believe all of them are.  When any are missing, the descriptions here
682 serve as specifications for what Autoconf will implement.  As a
683 programmer, you can either use a development version of Autoconf or
684 avoid using these variables until a stable release is made which
685 supports them.
686
687
688 @node Standard Targets
689 @section Standard Targets for Users
690
691 All GNU programs should have the following targets in their Makefiles:
692
693 @table @samp
694 @item all
695 Compile the entire program.  This should be the default target.  This
696 target need not rebuild any documentation files; Info files should
697 normally be included in the distribution, and DVI (and other
698 documentation format) files should be made only when explicitly asked
699 for.
700
701 By default, the Make rules should compile and link with @samp{-g}, so
702 that executable programs have debugging symbols.  Users who don't mind
703 being helpless can strip the executables later if they wish.
704
705 @item install
706 Compile the program and copy the executables, libraries, and so on to
707 the file names where they should reside for actual use.  If there is a
708 simple test to verify that a program is properly installed, this target
709 should run that test.
710
711 Do not strip executables when installing them.  Devil-may-care users can
712 use the @code{install-strip} target to do that.
713
714 If possible, write the @code{install} target rule so that it does not
715 modify anything in the directory where the program was built, provided
716 @samp{make all} has just been done.  This is convenient for building the
717 program under one user name and installing it under another.
718
719 The commands should create all the directories in which files are to be
720 installed, if they don't already exist.  This includes the directories
721 specified as the values of the variables @code{prefix} and
722 @code{exec_prefix}, as well as all subdirectories that are needed.
723 One way to do this is by means of an @code{installdirs} target
724 as described below.
725
726 Use @samp{-} before any command for installing a man page, so that
727 @code{make} will ignore any errors.  This is in case there are systems
728 that don't have the Unix man page documentation system installed.
729
730 The way to install Info files is to copy them into @file{$(infodir)}
731 with @code{$(INSTALL_DATA)} (@pxref{Command Variables}), and then run
732 the @code{install-info} program if it is present.  @code{install-info}
733 is a program that edits the Info @file{dir} file to add or update the
734 menu entry for the given Info file; it is part of the Texinfo package.
735 Here is a sample rule to install an Info file:
736
737 @comment This example has been carefully formatted for the Make manual.
738 @comment Please do not reformat it without talking to bug-make@gnu.org.
739 @smallexample
740 $(DESTDIR)$(infodir)/foo.info: foo.info
741         $(POST_INSTALL)
742 # There may be a newer info file in . than in srcdir.
743         -if test -f foo.info; then d=.; \
744          else d=$(srcdir); fi; \
745         $(INSTALL_DATA) $$d/foo.info $(DESTDIR)$@@; \
746 # Run install-info only if it exists.
747 # Use `if' instead of just prepending `-' to the
748 # line so we notice real errors from install-info.
749 # We use `$(SHELL) -c' because some shells do not
750 # fail gracefully when there is an unknown command.
751         if $(SHELL) -c 'install-info --version' \
752            >/dev/null 2>&1; then \
753           install-info --dir-file=$(DESTDIR)$(infodir)/dir \
754                        $(DESTDIR)$(infodir)/foo.info; \
755         else true; fi
756 @end smallexample
757
758 When writing the @code{install} target, you must classify all the
759 commands into three categories: normal ones, @dfn{pre-installation}
760 commands and @dfn{post-installation} commands.  @xref{Install Command
761 Categories}.
762
763 @item install-html
764 @itemx install-dvi
765 @itemx install-pdf
766 @itemx install-ps
767 These targets install documentation in formats other than Info;
768 they're intended to be called explicitly by the person installing the
769 package, if that format is desired.  GNU prefers Info files, so these
770 must be installed by the @code{install} target.
771
772 When you have many documentation files to install, we recommend that
773 you avoid collisions and clutter by arranging for these targets to
774 install in subdirectories of the appropriate installation directory,
775 such as @code{htmldir}.  As one example, if your package has multiple
776 manuals, and you wish to install HTML documentation with many files
777 (such as the ``split'' mode output by @code{makeinfo --html}), you'll
778 certainly want to use subdirectories, or two nodes with the same name
779 in different manuals will overwrite each other.
780
781 Please make these @code{install-@var{format}} targets invoke the 
782 commands for the @var{format} target, for example, by making
783 @var{format} a dependency.
784
785 @item uninstall
786 Delete all the installed files---the copies that the @samp{install}
787 and @samp{install-*} targets create.
788
789 This rule should not modify the directories where compilation is done,
790 only the directories where files are installed.
791
792 The uninstallation commands are divided into three categories, just like
793 the installation commands.  @xref{Install Command Categories}.
794
795 @item install-strip
796 Like @code{install}, but strip the executable files while installing
797 them.  In simple cases, this target can use the @code{install} target in
798 a simple way:
799
800 @smallexample
801 install-strip:
802         $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
803                 install
804 @end smallexample
805
806 But if the package installs scripts as well as real executables, the
807 @code{install-strip} target can't just refer to the @code{install}
808 target; it has to strip the executables but not the scripts.
809
810 @code{install-strip} should not strip the executables in the build
811 directory which are being copied for installation.  It should only strip
812 the copies that are installed.
813
814 Normally we do not recommend stripping an executable unless you are sure
815 the program has no bugs.  However, it can be reasonable to install a
816 stripped executable for actual execution while saving the unstripped
817 executable elsewhere in case there is a bug.
818
819 @comment The gratuitous blank line here is to make the table look better
820 @comment in the printed Make manual.  Please leave it in.
821 @item clean
822
823 Delete all files in the current directory that are normally created by
824 building the program.  Also delete files in other directories if they
825 are created by this makefile.  However, don't delete the files that
826 record the configuration.  Also preserve files that could be made by
827 building, but normally aren't because the distribution comes with
828 them.  There is no need to delete parent directories that were created
829 with @samp{mkdir -p}, since they could have existed anyway.
830
831 Delete @file{.dvi} files here if they are not part of the distribution.
832
833 @item distclean
834 Delete all files in the current directory (or created by this
835 makefile) that are created by configuring or building the program.  If
836 you have unpacked the source and built the program without creating
837 any other files, @samp{make distclean} should leave only the files
838 that were in the distribution.  However, there is no need to delete
839 parent directories that were created with @samp{mkdir -p}, since they
840 could have existed anyway.
841
842 @item mostlyclean
843 Like @samp{clean}, but may refrain from deleting a few files that people
844 normally don't want to recompile.  For example, the @samp{mostlyclean}
845 target for GCC does not delete @file{libgcc.a}, because recompiling it
846 is rarely necessary and takes a lot of time.
847
848 @item maintainer-clean
849 Delete almost everything that can be reconstructed with this Makefile.
850 This typically includes everything deleted by @code{distclean}, plus
851 more: C source files produced by Bison, tags tables, Info files, and
852 so on.
853
854 The reason we say ``almost everything'' is that running the command
855 @samp{make maintainer-clean} should not delete @file{configure} even
856 if @file{configure} can be remade using a rule in the Makefile.  More
857 generally, @samp{make maintainer-clean} should not delete anything
858 that needs to exist in order to run @file{configure} and then begin to
859 build the program.  Also, there is no need to delete parent
860 directories that were created with @samp{mkdir -p}, since they could
861 have existed anyway.  These are the only exceptions;
862 @code{maintainer-clean} should delete everything else that can be
863 rebuilt.
864
865 The @samp{maintainer-clean} target is intended to be used by a maintainer of
866 the package, not by ordinary users.  You may need special tools to
867 reconstruct some of the files that @samp{make maintainer-clean} deletes.
868 Since these files are normally included in the distribution, we don't
869 take care to make them easy to reconstruct.  If you find you need to
870 unpack the full distribution again, don't blame us.
871
872 To help make users aware of this, the commands for the special
873 @code{maintainer-clean} target should start with these two:
874
875 @smallexample
876 @@echo 'This command is intended for maintainers to use; it'
877 @@echo 'deletes files that may need special tools to rebuild.'
878 @end smallexample
879
880 @item TAGS
881 Update a tags table for this program.
882 @c ADR: how?
883
884 @item info
885 Generate any Info files needed.  The best way to write the rules is as
886 follows:
887
888 @smallexample
889 info: foo.info
890
891 foo.info: foo.texi chap1.texi chap2.texi
892         $(MAKEINFO) $(srcdir)/foo.texi
893 @end smallexample
894
895 @noindent
896 You must define the variable @code{MAKEINFO} in the Makefile.  It should
897 run the @code{makeinfo} program, which is part of the Texinfo
898 distribution.
899
900 Normally a GNU distribution comes with Info files, and that means the
901 Info files are present in the source directory.  Therefore, the Make
902 rule for an info file should update it in the source directory.  When
903 users build the package, ordinarily Make will not update the Info files
904 because they will already be up to date.
905
906 @item dvi
907 @itemx html
908 @itemx pdf
909 @itemx ps
910 Generate documentation files in the given format.  These targets
911 should always exist, but any or all can be a no-op if the given output
912 format cannot be generated.  These targets should not be dependencies
913 of the @code{all} target; the user must manually invoke them.
914
915 Here's an example rule for generating DVI files from Texinfo:
916
917 @smallexample
918 dvi: foo.dvi
919
920 foo.dvi: foo.texi chap1.texi chap2.texi
921         $(TEXI2DVI) $(srcdir)/foo.texi
922 @end smallexample
923
924 @noindent
925 You must define the variable @code{TEXI2DVI} in the Makefile.  It should
926 run the program @code{texi2dvi}, which is part of the Texinfo
927 distribution.@footnote{@code{texi2dvi} uses @TeX{} to do the real work
928 of formatting. @TeX{} is not distributed with Texinfo.}  Alternatively,
929 write just the dependencies, and allow GNU @code{make} to provide the command.
930
931 Here's another example, this one for generating HTML from Texinfo:
932
933 @smallexample
934 html: foo.html
935
936 foo.html: foo.texi chap1.texi chap2.texi
937         $(TEXI2HTML) $(srcdir)/foo.texi
938 @end smallexample
939
940 @noindent
941 Again, you would define the variable @code{TEXI2HTML} in the Makefile;
942 for example, it might run @code{makeinfo --no-split --html}
943 (@command{makeinfo} is part of the Texinfo distribution).
944
945 @item dist
946 Create a distribution tar file for this program.  The tar file should be
947 set up so that the file names in the tar file start with a subdirectory
948 name which is the name of the package it is a distribution for.  This
949 name can include the version number.
950
951 For example, the distribution tar file of GCC version 1.40 unpacks into
952 a subdirectory named @file{gcc-1.40}.
953
954 The easiest way to do this is to create a subdirectory appropriately
955 named, use @code{ln} or @code{cp} to install the proper files in it, and
956 then @code{tar} that subdirectory.
957
958 Compress the tar file with @code{gzip}.  For example, the actual
959 distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}.
960
961 The @code{dist} target should explicitly depend on all non-source files
962 that are in the distribution, to make sure they are up to date in the
963 distribution.
964 @ifset CODESTD
965 @xref{Releases, , Making Releases}.
966 @end ifset
967 @ifclear CODESTD
968 @xref{Releases, , Making Releases, standards, GNU Coding Standards}.
969 @end ifclear
970
971 @item check
972 Perform self-tests (if any).  The user must build the program before
973 running the tests, but need not install the program; you should write
974 the self-tests so that they work when the program is built but not
975 installed.
976 @end table
977
978 The following targets are suggested as conventional names, for programs
979 in which they are useful.
980
981 @table @code
982 @item installcheck
983 Perform installation tests (if any).  The user must build and install
984 the program before running the tests.  You should not assume that
985 @file{$(bindir)} is in the search path.
986
987 @item installdirs
988 It's useful to add a target named @samp{installdirs} to create the
989 directories where files are installed, and their parent directories.
990 There is a script called @file{mkinstalldirs} which is convenient for
991 this; you can find it in the Texinfo package.
992 @c It's in /gd/gnu/lib/mkinstalldirs.
993 You can use a rule like this:
994
995 @comment This has been carefully formatted to look decent in the Make manual.
996 @comment Please be sure not to make it extend any further to the right.--roland
997 @smallexample
998 # Make sure all installation directories (e.g. $(bindir))
999 # actually exist by making them if necessary.
1000 installdirs: mkinstalldirs
1001         $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
1002                                 $(libdir) $(infodir) \
1003                                 $(mandir)
1004 @end smallexample
1005
1006 @noindent
1007 or, if you wish to support @env{DESTDIR},
1008
1009 @smallexample
1010 # Make sure all installation directories (e.g. $(bindir))
1011 # actually exist by making them if necessary.
1012 installdirs: mkinstalldirs
1013         $(srcdir)/mkinstalldirs \
1014             $(DESTDIR)$(bindir) $(DESTDIR)$(datadir) \
1015             $(DESTDIR)$(libdir) $(DESTDIR)$(infodir) \
1016             $(DESTDIR)$(mandir)
1017 @end smallexample
1018
1019 This rule should not modify the directories where compilation is done.
1020 It should do nothing but create installation directories.
1021 @end table
1022
1023 @node Install Command Categories
1024 @section Install Command Categories
1025
1026 @cindex pre-installation commands
1027 @cindex post-installation commands
1028 When writing the @code{install} target, you must classify all the
1029 commands into three categories: normal ones, @dfn{pre-installation}
1030 commands and @dfn{post-installation} commands.
1031
1032 Normal commands move files into their proper places, and set their
1033 modes.  They may not alter any files except the ones that come entirely
1034 from the package they belong to.
1035
1036 Pre-installation and post-installation commands may alter other files;
1037 in particular, they can edit global configuration files or data bases.
1038
1039 Pre-installation commands are typically executed before the normal
1040 commands, and post-installation commands are typically run after the
1041 normal commands.
1042
1043 The most common use for a post-installation command is to run
1044 @code{install-info}.  This cannot be done with a normal command, since
1045 it alters a file (the Info directory) which does not come entirely and
1046 solely from the package being installed.  It is a post-installation
1047 command because it needs to be done after the normal command which
1048 installs the package's Info files.
1049
1050 Most programs don't need any pre-installation commands, but we have the
1051 feature just in case it is needed.
1052
1053 To classify the commands in the @code{install} rule into these three
1054 categories, insert @dfn{category lines} among them.  A category line
1055 specifies the category for the commands that follow.
1056
1057 A category line consists of a tab and a reference to a special Make
1058 variable, plus an optional comment at the end.  There are three
1059 variables you can use, one for each category; the variable name
1060 specifies the category.  Category lines are no-ops in ordinary execution
1061 because these three Make variables are normally undefined (and you
1062 @emph{should not} define them in the makefile).
1063
1064 Here are the three possible category lines, each with a comment that
1065 explains what it means:
1066
1067 @smallexample
1068         $(PRE_INSTALL)     # @r{Pre-install commands follow.}
1069         $(POST_INSTALL)    # @r{Post-install commands follow.}
1070         $(NORMAL_INSTALL)  # @r{Normal commands follow.}
1071 @end smallexample
1072
1073 If you don't use a category line at the beginning of the @code{install}
1074 rule, all the commands are classified as normal until the first category
1075 line.  If you don't use any category lines, all the commands are
1076 classified as normal.
1077
1078 These are the category lines for @code{uninstall}:
1079
1080 @smallexample
1081         $(PRE_UNINSTALL)     # @r{Pre-uninstall commands follow.}
1082         $(POST_UNINSTALL)    # @r{Post-uninstall commands follow.}
1083         $(NORMAL_UNINSTALL)  # @r{Normal commands follow.}
1084 @end smallexample
1085
1086 Typically, a pre-uninstall command would be used for deleting entries
1087 from the Info directory.
1088
1089 If the @code{install} or @code{uninstall} target has any dependencies
1090 which act as subroutines of installation, then you should start
1091 @emph{each} dependency's commands with a category line, and start the
1092 main target's commands with a category line also.  This way, you can
1093 ensure that each command is placed in the right category regardless of
1094 which of the dependencies actually run.
1095
1096 Pre-installation and post-installation commands should not run any
1097 programs except for these:
1098
1099 @example
1100 [ basename bash cat chgrp chmod chown cmp cp dd diff echo
1101 egrep expand expr false fgrep find getopt grep gunzip gzip
1102 hostname install install-info kill ldconfig ln ls md5sum
1103 mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
1104 test touch true uname xargs yes
1105 @end example
1106
1107 @cindex binary packages
1108 The reason for distinguishing the commands in this way is for the sake
1109 of making binary packages.  Typically a binary package contains all the
1110 executables and other files that need to be installed, and has its own
1111 method of installing them---so it does not need to run the normal
1112 installation commands.  But installing the binary package does need to
1113 execute the pre-installation and post-installation commands.
1114
1115 Programs to build binary packages work by extracting the
1116 pre-installation and post-installation commands.  Here is one way of
1117 extracting the pre-installation commands (the @option{-s} option to
1118 @command{make} is needed to silence messages about entering
1119 subdirectories):
1120
1121 @smallexample
1122 make -s -n install -o all \
1123       PRE_INSTALL=pre-install \
1124       POST_INSTALL=post-install \
1125       NORMAL_INSTALL=normal-install \
1126   | gawk -f pre-install.awk
1127 @end smallexample
1128
1129 @noindent
1130 where the file @file{pre-install.awk} could contain this:
1131
1132 @smallexample
1133 $0 ~ /^(normal-install|post-install)[ \t]*$/ @{on = 0@}
1134 on @{print $0@}
1135 $0 ~ /^pre-install[ \t]*$/ @{on = 1@}
1136 @end smallexample