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