VirtualBox

source: kBuild/vendor/gnumake/3.82/doc/make-stds.texi@ 2579

Last change on this file since 2579 was 2579, checked in by bird, 13 years ago

Importing make-3.82.tar.bz2 (md5sum 1a11100f3c63fcf5753818e59d63088f) with --auto-props but no keywords.

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

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette