OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [branches/] [newlib/] [newlib/] [etc/] [standards.info] - Blame information for rev 1777

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 56 joel
This is standards.info, produced by Makeinfo version 3.12f from
2
./standards.texi.
3 39 lampret
 
4
START-INFO-DIR-ENTRY
5
* Standards: (standards).        GNU coding standards.
6
END-INFO-DIR-ENTRY
7
 
8
   GNU Coding Standards Copyright (C) 1992, 1993, 1994, 1995, 1996,
9
1997, 1998 Free Software Foundation, Inc.
10
 
11
   Permission is granted to make and distribute verbatim copies of this
12
manual provided the copyright notice and this permission notice are
13
preserved on all copies.
14
 
15
   Permission is granted to copy and distribute modified versions of
16
this manual under the conditions for verbatim copying, provided that
17
the entire resulting derived work is distributed under the terms of a
18
permission notice identical to this one.
19
 
20
   Permission is granted to copy and distribute translations of this
21
manual into another language, under the above conditions for modified
22
versions, except that this permission notice may be stated in a
23
translation approved by the Free Software Foundation.
24
 
25

26
File: standards.info,  Node: Top,  Next: Preface,  Prev: (dir),  Up: (dir)
27
 
28
Version
29
*******
30
 
31
   Last updated March 13, 1998.
32
 
33
* Menu:
34
 
35
* Preface::                     About the GNU Coding Standards
36
* Intellectual Property::       Keeping Free Software Free
37
* Design Advice::               General Program Design
38
* Program Behavior::            Program Behavior for All Programs
39
* Writing C::                   Making The Best Use of C
40
* Documentation::               Documenting Programs
41
* Managing Releases::           The Release Process
42
 
43

44
File: standards.info,  Node: Preface,  Next: Intellectual Property,  Prev: Top,  Up: Top
45
 
46
About the GNU Coding Standards
47
******************************
48
 
49
   The GNU Coding Standards were written by Richard Stallman and other
50
GNU Project volunteers.  Their purpose is to make the GNU system clean,
51
consistent, and easy to install.  This document can also be read as a
52
guide to writing portable, robust and reliable programs.  It focuses on
53
programs written in C, but many of the rules and principles are useful
54
even if you write in another programming language.  The rules often
55
state reasons for writing in a certain way.
56
 
57
   Corrections or suggestions for this document should be sent to
58
.  If you make a suggestion, please include a suggested
59
new wording for it; our time is limited.  We prefer a context diff to
60
the `standards.texi' or `make-stds.texi' files, but if you don't have
61
those files, please mail your suggestion anyway.
62
 
63
   This release of the GNU Coding Standards was last updated March 13,
64
1998.
65
 
66

67
File: standards.info,  Node: Intellectual Property,  Next: Design Advice,  Prev: Preface,  Up: Top
68
 
69
Keeping Free Software Free
70
**************************
71
 
72
   This node discusses how you can make sure that GNU software remains
73
unencumbered.
74
 
75
* Menu:
76
 
77
* Reading Non-Free Code::       Referring to Proprietary Programs
78
* Contributions::               Accepting Contributions
79
 
80

81
File: standards.info,  Node: Reading Non-Free Code,  Next: Contributions,  Up: Intellectual Property
82
 
83
Referring to Proprietary Programs
84
=================================
85
 
86
   Don't in any circumstances refer to Unix source code for or during
87
your work on GNU!  (Or to any other proprietary programs.)
88
 
89
   If you have a vague recollection of the internals of a Unix program,
90
this does not absolutely mean you can't write an imitation of it, but
91
do try to organize the imitation internally along different lines,
92
because this is likely to make the details of the Unix version
93
irrelevant and dissimilar to your results.
94
 
95
   For example, Unix utilities were generally optimized to minimize
96
memory use; if you go for speed instead, your program will be very
97
different.  You could keep the entire input file in core and scan it
98
there instead of using stdio.  Use a smarter algorithm discovered more
99
recently than the Unix program.  Eliminate use of temporary files.  Do
100
it in one pass instead of two (we did this in the assembler).
101
 
102
   Or, on the contrary, emphasize simplicity instead of speed.  For some
103
applications, the speed of today's computers makes simpler algorithms
104
adequate.
105
 
106
   Or go for generality.  For example, Unix programs often have static
107
tables or fixed-size strings, which make for arbitrary limits; use
108
dynamic allocation instead.  Make sure your program handles NULs and
109
other funny characters in the input files.  Add a programming language
110
for extensibility and write part of the program in that language.
111
 
112
   Or turn some parts of the program into independently usable
113
libraries.  Or use a simple garbage collector instead of tracking
114
precisely when to free memory, or use a new GNU facility such as
115
obstacks.
116
 
117

118
File: standards.info,  Node: Contributions,  Prev: Reading Non-Free Code,  Up: Intellectual Property
119
 
120
Accepting Contributions
121
=======================
122
 
123
   If someone else sends you a piece of code to add to the program you
124
are working on, we need legal papers to use it--the same sort of legal
125 56 joel
papers we will need to get from you.  _Each_ significant contributor to
126 39 lampret
a program must sign some sort of legal papers in order for us to have
127
clear title to the program.  The main author alone is not enough.
128
 
129
   So, before adding in any contributions from other people, please tell
130
us, so we can arrange to get the papers.  Then wait until we tell you
131
that we have received the signed papers, before you actually use the
132
contribution.
133
 
134
   This applies both before you release the program and afterward.  If
135
you receive diffs to fix a bug, and they make significant changes, we
136
need legal papers for that change.
137
 
138
   This also applies to comments and documentation files.  For copyright
139
law, comments and code are just text.  Copyright applies to all kinds of
140
text, so we need legal papers for all kinds.
141
 
142
   You don't need papers for changes of a few lines here or there, since
143
they are not significant for copyright purposes.  Also, you don't need
144
papers if all you get from the suggestion is some ideas, not actual code
145
which you use.  For example, if you write a different solution to the
146
problem, you don't need to get papers.
147
 
148
   We know this is frustrating; it's frustrating for us as well.  But if
149
you don't wait, you are going out on a limb--for example, what if the
150
contributor's employer won't sign a disclaimer?  You might have to take
151
that code out again!
152
 
153
   The very worst thing is if you forget to tell us about the other
154
contributor.  We could be very embarrassed in court some day as a
155
result.
156
 
157
   We have more detailed advice for maintainers of programs; if you have
158
reached the stage of actually maintaining a program for GNU (whether
159
released or not), please ask us for a copy.
160
 
161

162
File: standards.info,  Node: Design Advice,  Next: Program Behavior,  Prev: Intellectual Property,  Up: Top
163
 
164
General Program Design
165
**********************
166
 
167
   This node discusses some of the issues you should take into account
168
when designing your program.
169
 
170
* Menu:
171
 
172
* Compatibility::               Compatibility with other implementations
173
* Using Extensions::            Using non-standard features
174
* ANSI C::                      Using ANSI C features
175
* Source Language::             Using languages other than C
176
 
177

178
File: standards.info,  Node: Compatibility,  Next: Using Extensions,  Up: Design Advice
179
 
180
Compatibility with Other Implementations
181
========================================
182
 
183
   With occasional exceptions, utility programs and libraries for GNU
184
should be upward compatible with those in Berkeley Unix, and upward
185
compatible with ANSI C if ANSI C specifies their behavior, and upward
186
compatible with POSIX if POSIX specifies their behavior.
187
 
188
   When these standards conflict, it is useful to offer compatibility
189
modes for each of them.
190
 
191
   ANSI C and POSIX prohibit many kinds of extensions.  Feel free to
192
make the extensions anyway, and include a `--ansi', `--posix', or
193
`--compatible' option to turn them off.  However, if the extension has
194
a significant chance of breaking any real programs or scripts, then it
195
is not really upward compatible.  Try to redesign its interface.
196
 
197
   Many GNU programs suppress extensions that conflict with POSIX if the
198
environment variable `POSIXLY_CORRECT' is defined (even if it is
199
defined with a null value).  Please make your program recognize this
200
variable if appropriate.
201
 
202
   When a feature is used only by users (not by programs or command
203
files), and it is done poorly in Unix, feel free to replace it
204
completely with something totally different and better.  (For example,
205
`vi' is replaced with Emacs.)  But it is nice to offer a compatible
206
feature as well.  (There is a free `vi' clone, so we offer it.)
207
 
208
   Additional useful features not in Berkeley Unix are welcome.
209
 
210

211
File: standards.info,  Node: Using Extensions,  Next: ANSI C,  Prev: Compatibility,  Up: Design Advice
212
 
213
Using Non-standard Features
214
===========================
215
 
216
   Many GNU facilities that already exist support a number of convenient
217
extensions over the comparable Unix facilities.  Whether to use these
218
extensions in implementing your program is a difficult question.
219
 
220
   On the one hand, using the extensions can make a cleaner program.
221
On the other hand, people will not be able to build the program unless
222
the other GNU tools are available.  This might cause the program to
223
work on fewer kinds of machines.
224
 
225
   With some extensions, it might be easy to provide both alternatives.
226
For example, you can define functions with a "keyword" `INLINE' and
227
define that as a macro to expand into either `inline' or nothing,
228
depending on the compiler.
229
 
230
   In general, perhaps it is best not to use the extensions if you can
231
straightforwardly do without them, but to use the extensions if they
232
are a big improvement.
233
 
234
   An exception to this rule are the large, established programs (such
235
as Emacs) which run on a great variety of systems.  Such programs would
236
be broken by use of GNU extensions.
237
 
238
   Another exception is for programs that are used as part of
239
compilation: anything that must be compiled with other compilers in
240
order to bootstrap the GNU compilation facilities.  If these require
241
the GNU compiler, then no one can compile them without having them
242
installed already.  That would be no good.
243
 
244

245
File: standards.info,  Node: ANSI C,  Next: Source Language,  Prev: Using Extensions,  Up: Design Advice
246
 
247
ANSI C and pre-ANSI C
248
=====================
249
 
250
   Do not ever use the "trigraph" feature of ANSI C.
251
 
252
   ANSI C is widespread enough now that it is ok to write new programs
253
that use ANSI C features (and therefore will not work in non-ANSI
254
compilers).  And if a program is already written in ANSI C, there's no
255
need to convert it to support non-ANSI compilers.
256
 
257
   However, it is easy to support non-ANSI compilers in most programs,
258
so you might still consider doing so when you write a program.  Instead
259
of writing function definitions in ANSI prototype form,
260
 
261
     int
262
     foo (int x, int y)
263
     ...
264
 
265
write the definition in pre-ANSI style like this,
266
 
267
     int
268
     foo (x, y)
269
          int x, y;
270
     ...
271
 
272
and use a separate declaration to specify the argument prototype:
273
 
274
     int foo (int, int);
275
 
276
   You need such a declaration anyway, in a header file, to get the
277
benefit of ANSI C prototypes in all the files where the function is
278
called.  And once you have it, you lose nothing by writing the function
279
definition in the pre-ANSI style.
280
 
281
   If you don't know non-ANSI C, there's no need to learn it; just
282
write in ANSI C.
283
 
284

285
File: standards.info,  Node: Source Language,  Prev: ANSI C,  Up: Design Advice
286
 
287
Using Languages Other Than C
288
============================
289
 
290
   Using a language other than C is like using a non-standard feature:
291
it will cause trouble for users.  Even if GCC supports the other
292
language, users may find it inconvenient to have to install the
293
compiler for that other language in order to build your program.  For
294
example, if you write your program in C++, people will have to install
295
the C++ compiler in order to compile your program.  Thus, it is better
296
if you write in C.
297
 
298
   But there are three situations when there is no disadvantage in using
299
some other language:
300
 
301
   * It is okay to use another language if your program contains an
302
     interpreter for that language.
303
 
304
     For example, if your program links with GUILE, it is ok to write
305
     part of the program in Scheme or another language supported by
306
     GUILE.
307
 
308
   * It is okay to use another language in a tool specifically intended
309
     for use with that language.
310
 
311
     This is okay because the only people who want to build the tool
312
     will be those who have installed the other language anyway.
313
 
314
   * If an application is of interest to a narrow community, then
315
     perhaps it's not important if the application is inconvenient to
316
     install.
317
 
318
   C has one other advantage over C++ and other compiled languages: more
319
people know C, so more people will find it easy to read and modify the
320
program if it is written in C.
321
 
322

323
File: standards.info,  Node: Program Behavior,  Next: Writing C,  Prev: Design Advice,  Up: Top
324
 
325
Program Behavior for All Programs
326
*********************************
327
 
328
   This node describes how to write robust software. It also describes
329
general standards for error messages, the command line interface, and
330
how libraries should behave.
331
 
332
* Menu:
333
 
334
* Semantics::                   Writing robust programs
335
* Libraries::                   Library behavior
336
* Errors::                      Formatting error messages
337
* User Interfaces::             Standards for command line interfaces
338
* Option Table::                Table of long options.
339
* Memory Usage::                When and how to care about memory needs
340
 
341

342
File: standards.info,  Node: Semantics,  Next: Libraries,  Up: Program Behavior
343
 
344
Writing Robust Programs
345
=======================
346
 
347 56 joel
   Avoid arbitrary limits on the length or number of _any_ data
348 39 lampret
structure, including file names, lines, files, and symbols, by
349
allocating all data structures dynamically.  In most Unix utilities,
350
"long lines are silently truncated".  This is not acceptable in a GNU
351
utility.
352
 
353
   Utilities reading files should not drop NUL characters, or any other
354 56 joel
nonprinting characters _including those with codes above 0177_.  The
355 39 lampret
only sensible exceptions would be utilities specifically intended for
356
interface to certain types of printers that can't handle those
357
characters.
358
 
359
   Check every system call for an error return, unless you know you
360
wish to ignore errors.  Include the system error text (from `perror' or
361 56 joel
equivalent) in _every_ error message resulting from a failing system
362 39 lampret
call, as well as the name of the file if any and the name of the
363
utility.  Just "cannot open foo.c" or "stat failed" is not sufficient.
364
 
365
   Check every call to `malloc' or `realloc' to see if it returned
366
zero.  Check `realloc' even if you are making the block smaller; in a
367
system that rounds block sizes to a power of 2, `realloc' may get a
368
different block if you ask for less space.
369
 
370
   In Unix, `realloc' can destroy the storage block if it returns zero.
371
GNU `realloc' does not have this bug: if it fails, the original block
372
is unchanged.  Feel free to assume the bug is fixed.  If you wish to
373
run your program on Unix, and wish to avoid lossage in this case, you
374
can use the GNU `malloc'.
375
 
376
   You must expect `free' to alter the contents of the block that was
377
freed.  Anything you want to fetch from the block, you must fetch before
378
calling `free'.
379
 
380
   If `malloc' fails in a noninteractive program, make that a fatal
381
error.  In an interactive program (one that reads commands from the
382
user), it is better to abort the command and return to the command
383
reader loop.  This allows the user to kill other processes to free up
384
virtual memory, and then try the command again.
385
 
386
   Use `getopt_long' to decode arguments, unless the argument syntax
387
makes this unreasonable.
388
 
389
   When static storage is to be written in during program execution, use
390
explicit C code to initialize it.  Reserve C initialized declarations
391
for data that will not be changed.
392
 
393
   Try to avoid low-level interfaces to obscure Unix data structures
394
(such as file directories, utmp, or the layout of kernel memory), since
395
these are less likely to work compatibly.  If you need to find all the
396
files in a directory, use `readdir' or some other high-level interface.
397
These will be supported compatibly by GNU.
398
 
399
   By default, the GNU system will provide the signal handling
400
functions of BSD and of POSIX.  So GNU software should be written to use
401
these.
402
 
403
   In error checks that detect "impossible" conditions, just abort.
404
There is usually no point in printing any message.  These checks
405
indicate the existence of bugs.  Whoever wants to fix the bugs will have
406
to read the source code and run a debugger.  So explain the problem with
407
comments in the source.  The relevant data will be in variables, which
408
are easy to examine with the debugger, so there is no point moving them
409
elsewhere.
410
 
411
   Do not use a count of errors as the exit status for a program.
412 56 joel
_That does not work_, because exit status values are limited to 8 bits
413 39 lampret
(0 through 255).  A single run of the program might have 256 errors; if
414
you try to return 256 as the exit status, the parent process will see 0
415
as the status, and it will appear that the program succeeded.
416
 
417
   If you make temporary files, check the `TMPDIR' environment
418
variable; if that variable is defined, use the specified directory
419
instead of `/tmp'.
420
 
421

422
File: standards.info,  Node: Libraries,  Next: Errors,  Prev: Semantics,  Up: Program Behavior
423
 
424
Library Behavior
425
================
426
 
427
   Try to make library functions reentrant.  If they need to do dynamic
428
storage allocation, at least try to avoid any nonreentrancy aside from
429
that of `malloc' itself.
430
 
431
   Here are certain name conventions for libraries, to avoid name
432
conflicts.
433
 
434
   Choose a name prefix for the library, more than two characters long.
435
All external function and variable names should start with this prefix.
436
In addition, there should only be one of these in any given library
437
member.  This usually means putting each one in a separate source file.
438
 
439
   An exception can be made when two external symbols are always used
440
together, so that no reasonable program could use one without the
441
other; then they can both go in the same file.
442
 
443
   External symbols that are not documented entry points for the user
444
should have names beginning with `_'.  They should also contain the
445
chosen name prefix for the library, to prevent collisions with other
446
libraries.  These can go in the same files with user entry points if
447
you like.
448
 
449
   Static functions and variables can be used as you like and need not
450
fit any naming convention.
451
 
452

453
File: standards.info,  Node: Errors,  Next: User Interfaces,  Prev: Libraries,  Up: Program Behavior
454
 
455
Formatting Error Messages
456
=========================
457
 
458
   Error messages from compilers should look like this:
459
 
460
     SOURCE-FILE-NAME:LINENO: MESSAGE
461
 
462
   Error messages from other noninteractive programs should look like
463
this:
464
 
465
     PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
466
 
467
when there is an appropriate source file, or like this:
468
 
469
     PROGRAM: MESSAGE
470
 
471
when there is no relevant source file.
472
 
473
   In an interactive program (one that is reading commands from a
474
terminal), it is better not to include the program name in an error
475
message.  The place to indicate which program is running is in the
476
prompt or with the screen layout.  (When the same program runs with
477
input from a source other than a terminal, it is not interactive and
478
would do best to print error messages using the noninteractive style.)
479
 
480
   The string MESSAGE should not begin with a capital letter when it
481
follows a program name and/or file name.  Also, it should not end with
482
a period.
483
 
484
   Error messages from interactive programs, and other messages such as
485
usage messages, should start with a capital letter.  But they should not
486
end with a period.
487
 
488

489
File: standards.info,  Node: User Interfaces,  Next: Option Table,  Prev: Errors,  Up: Program Behavior
490
 
491
Standards for Command Line Interfaces
492
=====================================
493
 
494
   Please don't make the behavior of a utility depend on the name used
495
to invoke it.  It is useful sometimes to make a link to a utility with
496
a different name, and that should not change what it does.
497
 
498
   Instead, use a run time option or a compilation switch or both to
499
select among the alternate behaviors.
500
 
501
   Likewise, please don't make the behavior of the program depend on the
502
type of output device it is used with.  Device independence is an
503
important principle of the system's design; do not compromise it merely
504
to save someone from typing an option now and then.
505
 
506
   If you think one behavior is most useful when the output is to a
507
terminal, and another is most useful when the output is a file or a
508
pipe, then it is usually best to make the default behavior the one that
509
is useful with output to a terminal, and have an option for the other
510
behavior.
511
 
512
   Compatibility requires certain programs to depend on the type of
513
output device.  It would be disastrous if `ls' or `sh' did not do so in
514
the way all users expect.  In some of these cases, we supplement the
515
program with a preferred alternate version that does not depend on the
516
output device type.  For example, we provide a `dir' program much like
517
`ls' except that its default output format is always multi-column
518
format.
519
 
520
   It is a good idea to follow the POSIX guidelines for the
521
command-line options of a program.  The easiest way to do this is to use
522
`getopt' to parse them.  Note that the GNU version of `getopt' will
523
normally permit options anywhere among the arguments unless the special
524
argument `--' is used.  This is not what POSIX specifies; it is a GNU
525
extension.
526
 
527
   Please define long-named options that are equivalent to the
528
single-letter Unix-style options.  We hope to make GNU more user
529
friendly this way.  This is easy to do with the GNU function
530
`getopt_long'.
531
 
532
   One of the advantages of long-named options is that they can be
533
consistent from program to program.  For example, users should be able
534
to expect the "verbose" option of any GNU program which has one, to be
535
spelled precisely `--verbose'.  To achieve this uniformity, look at the
536
table of common long-option names when you choose the option names for
537
your program (*note Option Table::.).
538
 
539
   It is usually a good idea for file names given as ordinary arguments
540
to be input files only; any output files would be specified using
541
options (preferably `-o' or `--output').  Even if you allow an output
542
file name as an ordinary argument for compatibility, try to provide an
543
option as another way to specify it.  This will lead to more consistency
544
among GNU utilities, and fewer idiosyncracies for users to remember.
545
 
546
   All programs should support two standard options: `--version' and
547
`--help'.
548
 
549
`--version'
550
     This option should direct the program to information about its
551
     name, version, origin and legal status, all on standard output,
552
     and then exit successfully.  Other options and arguments should be
553
     ignored once this is seen, and the program should not perform its
554
     normal function.
555
 
556
     The first line is meant to be easy for a program to parse; the
557
     version number proper starts after the last space.  In addition,
558
     it contains the canonical name for this program, in this format:
559
 
560
          GNU Emacs 19.30
561
 
562 56 joel
     The program's name should be a constant string; _don't_ compute it
563 39 lampret
     from `argv[0]'.  The idea is to state the standard or canonical
564
     name for the program, not its file name.  There are other ways to
565
     find out the precise file name where a command is found in `PATH'.
566
 
567
     If the program is a subsidiary part of a larger package, mention
568
     the package name in parentheses, like this:
569
 
570
          emacsserver (GNU Emacs) 19.30
571
 
572
     If the package has a version number which is different from this
573
     program's version number, you can mention the package version
574
     number just before the close-parenthesis.
575
 
576
     If you *need* to mention the version numbers of libraries which
577
     are distributed separately from the package which contains this
578
     program, you can do so by printing an additional line of version
579
     info for each library you want to mention.  Use the same format
580
     for these lines as for the first line.
581
 
582
     Please do not mention all of the libraries that the program uses
583
     "just for completeness"--that would produce a lot of unhelpful
584
     clutter.  Please mention library version numbers only if you find
585
     in practice that they are very important to you in debugging.
586
 
587
     The following line, after the version number line or lines, should
588
     be a copyright notice.  If more than one copyright notice is
589
     called for, put each on a separate line.
590
 
591
     Next should follow a brief statement that the program is free
592
     software, and that users are free to copy and change it on certain
593
     conditions.  If the program is covered by the GNU GPL, say so
594
     here.  Also mention that there is no warranty, to the extent
595
     permitted by law.
596
 
597
     It is ok to finish the output with a list of the major authors of
598
     the program, as a way of giving credit.
599
 
600
     Here's an example of output that follows these rules:
601
 
602
          GNU Emacs 19.34.5
603
          Copyright (C) 1996 Free Software Foundation, Inc.
604
          GNU Emacs comes with NO WARRANTY,
605
          to the extent permitted by law.
606
          You may redistribute copies of GNU Emacs
607
          under the terms of the GNU General Public License.
608
          For more information about these matters,
609
          see the files named COPYING.
610
 
611
     You should adapt this to your program, of course, filling in the
612
     proper year, copyright holder, name of program, and the references
613
     to distribution terms, and changing the rest of the wording as
614
     necessary.
615
 
616
     This copyright notice only needs to mention the most recent year in
617
     which changes were made--there's no need to list the years for
618
     previous versions' changes.  You don't have to mention the name of
619
     the program in these notices, if that is inconvenient, since it
620
     appeared in the first line.
621
 
622
`--help'
623
     This option should output brief documentation for how to invoke the
624
     program, on standard output, then exit successfully.  Other
625
     options and arguments should be ignored once this is seen, and the
626
     program should not perform its normal function.
627
 
628
     Near the end of the `--help' option's output there should be a line
629
     that says where to mail bug reports.  It should have this format:
630
 
631
          Report bugs to MAILING-ADDRESS.
632
 
633

634
File: standards.info,  Node: Option Table,  Next: Memory Usage,  Prev: User Interfaces,  Up: Program Behavior
635
 
636
Table of Long Options
637
=====================
638
 
639
   Here is a table of long options used by GNU programs.  It is surely
640
incomplete, but we aim to list all the options that a new program might
641
want to be compatible with.  If you use names not already in the table,
642
please send  a list of them, with their meanings, so we
643
can update the table.
644
 
645
`after-date'
646
     `-N' in `tar'.
647
 
648
`all'
649
     `-a' in `du', `ls', `nm', `stty', `uname', and `unexpand'.
650
 
651
`all-text'
652
     `-a' in `diff'.
653
 
654
`almost-all'
655
     `-A' in `ls'.
656
 
657
`append'
658
     `-a' in `etags', `tee', `time'; `-r' in `tar'.
659
 
660
`archive'
661
     `-a' in `cp'.
662
 
663
`archive-name'
664
     `-n' in `shar'.
665
 
666
`arglength'
667
     `-l' in `m4'.
668
 
669
`ascii'
670
     `-a' in `diff'.
671
 
672
`assign'
673
     `-v' in `gawk'.
674
 
675
`assume-new'
676
     `-W' in Make.
677
 
678
`assume-old'
679
     `-o' in Make.
680
 
681
`auto-check'
682
     `-a' in `recode'.
683
 
684
`auto-pager'
685
     `-a' in `wdiff'.
686
 
687
`auto-reference'
688
     `-A' in `ptx'.
689
 
690
`avoid-wraps'
691
     `-n' in `wdiff'.
692
 
693
`backward-search'
694
     `-B' in `ctags'.
695
 
696
`basename'
697
     `-f' in `shar'.
698
 
699
`batch'
700
     Used in GDB.
701
 
702
`baud'
703
     Used in GDB.
704
 
705
`before'
706
     `-b' in `tac'.
707
 
708
`binary'
709
     `-b' in `cpio' and `diff'.
710
 
711
`bits-per-code'
712
     `-b' in `shar'.
713
 
714
`block-size'
715
     Used in `cpio' and `tar'.
716
 
717
`blocks'
718
     `-b' in `head' and `tail'.
719
 
720
`break-file'
721
     `-b' in `ptx'.
722
 
723
`brief'
724
     Used in various programs to make output shorter.
725
 
726
`bytes'
727
     `-c' in `head', `split', and `tail'.
728
 
729
`c++'
730
     `-C' in `etags'.
731
 
732
`catenate'
733
     `-A' in `tar'.
734
 
735
`cd'
736
     Used in various programs to specify the directory to use.
737
 
738
`changes'
739
     `-c' in `chgrp' and `chown'.
740
 
741
`classify'
742
     `-F' in `ls'.
743
 
744
`colons'
745
     `-c' in `recode'.
746
 
747
`command'
748
     `-c' in `su'; `-x' in GDB.
749
 
750
`compare'
751
     `-d' in `tar'.
752
 
753
`compat'
754
     Used in `gawk'.
755
 
756
`compress'
757
     `-Z' in `tar' and `shar'.
758
 
759
`concatenate'
760
     `-A' in `tar'.
761
 
762
`confirmation'
763
     `-w' in `tar'.
764
 
765
`context'
766
     Used in `diff'.
767
 
768
`copyleft'
769
     `-W copyleft' in `gawk'.
770
 
771
`copyright'
772
     `-C' in `ptx', `recode', and `wdiff'; `-W copyright' in `gawk'.
773
 
774
`core'
775
     Used in GDB.
776
 
777
`count'
778
     `-q' in `who'.
779
 
780
`count-links'
781
     `-l' in `du'.
782
 
783
`create'
784
     Used in `tar' and `cpio'.
785
 
786
`cut-mark'
787
     `-c' in `shar'.
788
 
789
`cxref'
790
     `-x' in `ctags'.
791
 
792
`date'
793
     `-d' in `touch'.
794
 
795
`debug'
796
     `-d' in Make and `m4'; `-t' in Bison.
797
 
798
`define'
799
     `-D' in `m4'.
800
 
801
`defines'
802
     `-d' in Bison and `ctags'.
803
 
804
`delete'
805
     `-D' in `tar'.
806
 
807
`dereference'
808
     `-L' in `chgrp', `chown', `cpio', `du', `ls', and `tar'.
809
 
810
`dereference-args'
811
     `-D' in `du'.
812
 
813
`diacritics'
814
     `-d' in `recode'.
815
 
816
`dictionary-order'
817
     `-d' in `look'.
818
 
819
`diff'
820
     `-d' in `tar'.
821
 
822
`digits'
823
     `-n' in `csplit'.
824
 
825
`directory'
826
     Specify the directory to use, in various programs.  In `ls', it
827
     means to show directories themselves rather than their contents.
828
     In `rm' and `ln', it means to not treat links to directories
829
     specially.
830
 
831
`discard-all'
832
     `-x' in `strip'.
833
 
834
`discard-locals'
835
     `-X' in `strip'.
836
 
837
`dry-run'
838
     `-n' in Make.
839
 
840
`ed'
841
     `-e' in `diff'.
842
 
843
`elide-empty-files'
844
     `-z' in `csplit'.
845
 
846
`end-delete'
847
     `-x' in `wdiff'.
848
 
849
`end-insert'
850
     `-z' in `wdiff'.
851
 
852
`entire-new-file'
853
     `-N' in `diff'.
854
 
855
`environment-overrides'
856
     `-e' in Make.
857
 
858
`eof'
859
     `-e' in `xargs'.
860
 
861
`epoch'
862
     Used in GDB.
863
 
864
`error-limit'
865
     Used in `makeinfo'.
866
 
867
`error-output'
868
     `-o' in `m4'.
869
 
870
`escape'
871
     `-b' in `ls'.
872
 
873
`exclude-from'
874
     `-X' in `tar'.
875
 
876
`exec'
877
     Used in GDB.
878
 
879
`exit'
880
     `-x' in `xargs'.
881
 
882
`exit-0'
883
     `-e' in `unshar'.
884
 
885
`expand-tabs'
886
     `-t' in `diff'.
887
 
888
`expression'
889
     `-e' in `sed'.
890
 
891
`extern-only'
892
     `-g' in `nm'.
893
 
894
`extract'
895
     `-i' in `cpio'; `-x' in `tar'.
896
 
897
`faces'
898
     `-f' in `finger'.
899
 
900
`fast'
901
     `-f' in `su'.
902
 
903
`fatal-warnings'
904
     `-E' in `m4'.
905
 
906
`file'
907
     `-f' in `info', `gawk', Make, `mt', and `tar'; `-n' in `sed'; `-r'
908
     in `touch'.
909
 
910
`field-separator'
911
     `-F' in `gawk'.
912
 
913
`file-prefix'
914
     `-b' in Bison.
915
 
916
`file-type'
917
     `-F' in `ls'.
918
 
919
`files-from'
920
     `-T' in `tar'.
921
 
922
`fill-column'
923
     Used in `makeinfo'.
924
 
925
`flag-truncation'
926
     `-F' in `ptx'.
927
 
928
`fixed-output-files'
929
     `-y' in Bison.
930
 
931
`follow'
932
     `-f' in `tail'.
933
 
934
`footnote-style'
935
     Used in `makeinfo'.
936
 
937
`force'
938
     `-f' in `cp', `ln', `mv', and `rm'.
939
 
940
`force-prefix'
941
     `-F' in `shar'.
942
 
943
`format'
944
     Used in `ls', `time', and `ptx'.
945
 
946
`freeze-state'
947
     `-F' in `m4'.
948
 
949
`fullname'
950
     Used in GDB.
951
 
952
`gap-size'
953
     `-g' in `ptx'.
954
 
955
`get'
956
     `-x' in `tar'.
957
 
958
`graphic'
959
     `-i' in `ul'.
960
 
961
`graphics'
962
     `-g' in `recode'.
963
 
964
`group'
965
     `-g' in `install'.
966
 
967
`gzip'
968
     `-z' in `tar' and `shar'.
969
 
970
`hashsize'
971
     `-H' in `m4'.
972
 
973
`header'
974
     `-h' in `objdump' and `recode'
975
 
976
`heading'
977
     `-H' in `who'.
978
 
979
`help'
980
     Used to ask for brief usage information.
981
 
982
`here-delimiter'
983
     `-d' in `shar'.
984
 
985
`hide-control-chars'
986
     `-q' in `ls'.
987
 
988
`idle'
989
     `-u' in `who'.
990
 
991
`ifdef'
992
     `-D' in `diff'.
993
 
994
`ignore'
995
     `-I' in `ls'; `-x' in `recode'.
996
 
997
`ignore-all-space'
998
     `-w' in `diff'.
999
 
1000
`ignore-backups'
1001
     `-B' in `ls'.
1002
 
1003
`ignore-blank-lines'
1004
     `-B' in `diff'.
1005
 
1006
`ignore-case'
1007
     `-f' in `look' and `ptx'; `-i' in `diff' and `wdiff'.
1008
 
1009
`ignore-errors'
1010
     `-i' in Make.
1011
 
1012
`ignore-file'
1013
     `-i' in `ptx'.
1014
 
1015
`ignore-indentation'
1016
     `-I' in `etags'.
1017
 
1018
`ignore-init-file'
1019
     `-f' in Oleo.
1020
 
1021
`ignore-interrupts'
1022
     `-i' in `tee'.
1023
 
1024
`ignore-matching-lines'
1025
     `-I' in `diff'.
1026
 
1027
`ignore-space-change'
1028
     `-b' in `diff'.
1029
 
1030
`ignore-zeros'
1031
     `-i' in `tar'.
1032
 
1033
`include'
1034
     `-i' in `etags'; `-I' in `m4'.
1035
 
1036
`include-dir'
1037
     `-I' in Make.
1038
 
1039
`incremental'
1040
     `-G' in `tar'.
1041
 
1042
`info'
1043
     `-i', `-l', and `-m' in Finger.
1044
 
1045
`initial'
1046
     `-i' in `expand'.
1047
 
1048
`initial-tab'
1049
     `-T' in `diff'.
1050
 
1051
`inode'
1052
     `-i' in `ls'.
1053
 
1054
`interactive'
1055
     `-i' in `cp', `ln', `mv', `rm'; `-e' in `m4'; `-p' in `xargs';
1056
     `-w' in `tar'.
1057
 
1058
`intermix-type'
1059
     `-p' in `shar'.
1060
 
1061
`jobs'
1062
     `-j' in Make.
1063
 
1064
`just-print'
1065
     `-n' in Make.
1066
 
1067
`keep-going'
1068
     `-k' in Make.
1069
 
1070
`keep-files'
1071
     `-k' in `csplit'.
1072
 
1073
`kilobytes'
1074
     `-k' in `du' and `ls'.
1075
 
1076
`language'
1077
     `-l' in `etags'.
1078
 
1079
`less-mode'
1080
     `-l' in `wdiff'.
1081
 
1082
`level-for-gzip'
1083
     `-g' in `shar'.
1084
 
1085
`line-bytes'
1086
     `-C' in `split'.
1087
 
1088
`lines'
1089
     Used in `split', `head', and `tail'.
1090
 
1091
`link'
1092
     `-l' in `cpio'.
1093
 
1094
`lint'
1095
`lint-old'
1096
     Used in `gawk'.
1097
 
1098
`list'
1099
     `-t' in `cpio'; `-l' in `recode'.
1100
 
1101
`list'
1102
     `-t' in `tar'.
1103
 
1104
`literal'
1105
     `-N' in `ls'.
1106
 
1107
`load-average'
1108
     `-l' in Make.
1109
 
1110
`login'
1111
     Used in `su'.
1112
 
1113
`machine'
1114
     No listing of which programs already use this; someone should
1115
     check to see if any actually do, and tell .
1116
 
1117
`macro-name'
1118
     `-M' in `ptx'.
1119
 
1120
`mail'
1121
     `-m' in `hello' and `uname'.
1122
 
1123
`make-directories'
1124
     `-d' in `cpio'.
1125
 
1126
`makefile'
1127
     `-f' in Make.
1128
 
1129
`mapped'
1130
     Used in GDB.
1131
 
1132
`max-args'
1133
     `-n' in `xargs'.
1134
 
1135
`max-chars'
1136
     `-n' in `xargs'.
1137
 
1138
`max-lines'
1139
     `-l' in `xargs'.
1140
 
1141
`max-load'
1142
     `-l' in Make.
1143
 
1144
`max-procs'
1145
     `-P' in `xargs'.
1146
 
1147
`mesg'
1148
     `-T' in `who'.
1149
 
1150
`message'
1151
     `-T' in `who'.
1152
 
1153
`minimal'
1154
     `-d' in `diff'.
1155
 
1156
`mixed-uuencode'
1157
     `-M' in `shar'.
1158
 
1159
`mode'
1160
     `-m' in `install', `mkdir', and `mkfifo'.
1161
 
1162
`modification-time'
1163
     `-m' in `tar'.
1164
 
1165
`multi-volume'
1166
     `-M' in `tar'.
1167
 
1168
`name-prefix'
1169
     `-a' in Bison.
1170
 
1171
`nesting-limit'
1172
     `-L' in `m4'.
1173
 
1174
`net-headers'
1175
     `-a' in `shar'.
1176
 
1177
`new-file'
1178
     `-W' in Make.
1179
 
1180
`no-builtin-rules'
1181
     `-r' in Make.
1182
 
1183
`no-character-count'
1184
     `-w' in `shar'.
1185
 
1186
`no-check-existing'
1187
     `-x' in `shar'.
1188
 
1189
`no-common'
1190
     `-3' in `wdiff'.
1191
 
1192
`no-create'
1193
     `-c' in `touch'.
1194
 
1195
`no-defines'
1196
     `-D' in `etags'.
1197
 
1198
`no-deleted'
1199
     `-1' in `wdiff'.
1200
 
1201
`no-dereference'
1202
     `-d' in `cp'.
1203
 
1204
`no-inserted'
1205
     `-2' in `wdiff'.
1206
 
1207
`no-keep-going'
1208
     `-S' in Make.
1209
 
1210
`no-lines'
1211
     `-l' in Bison.
1212
 
1213
`no-piping'
1214
     `-P' in `shar'.
1215
 
1216
`no-prof'
1217
     `-e' in `gprof'.
1218
 
1219
`no-regex'
1220
     `-R' in `etags'.
1221
 
1222
`no-sort'
1223
     `-p' in `nm'.
1224
 
1225
`no-split'
1226
     Used in `makeinfo'.
1227
 
1228
`no-static'
1229
     `-a' in `gprof'.
1230
 
1231
`no-time'
1232
     `-E' in `gprof'.
1233
 
1234
`no-timestamp'
1235
     `-m' in `shar'.
1236
 
1237
`no-validate'
1238
     Used in `makeinfo'.
1239
 
1240
`no-wait'
1241
     Used in `emacsclient'.
1242
 
1243
`no-warn'
1244
     Used in various programs to inhibit warnings.
1245
 
1246
`node'
1247
     `-n' in `info'.
1248
 
1249
`nodename'
1250
     `-n' in `uname'.
1251
 
1252
`nonmatching'
1253
     `-f' in `cpio'.
1254
 
1255
`nstuff'
1256
     `-n' in `objdump'.
1257
 
1258
`null'
1259
     `-0' in `xargs'.
1260
 
1261
`number'
1262
     `-n' in `cat'.
1263
 
1264
`number-nonblank'
1265
     `-b' in `cat'.
1266
 
1267
`numeric-sort'
1268
     `-n' in `nm'.
1269
 
1270
`numeric-uid-gid'
1271
     `-n' in `cpio' and `ls'.
1272
 
1273
`nx'
1274
     Used in GDB.
1275
 
1276
`old-archive'
1277
     `-o' in `tar'.
1278
 
1279
`old-file'
1280
     `-o' in Make.
1281
 
1282
`one-file-system'
1283
     `-l' in `tar', `cp', and `du'.
1284
 
1285
`only-file'
1286
     `-o' in `ptx'.
1287
 
1288
`only-prof'
1289
     `-f' in `gprof'.
1290
 
1291
`only-time'
1292
     `-F' in `gprof'.
1293
 
1294
`output'
1295
     In various programs, specify the output file name.
1296
 
1297
`output-prefix'
1298
     `-o' in `shar'.
1299
 
1300
`override'
1301
     `-o' in `rm'.
1302
 
1303
`overwrite'
1304
     `-c' in `unshar'.
1305
 
1306
`owner'
1307
     `-o' in `install'.
1308
 
1309
`paginate'
1310
     `-l' in `diff'.
1311
 
1312
`paragraph-indent'
1313
     Used in `makeinfo'.
1314
 
1315
`parents'
1316
     `-p' in `mkdir' and `rmdir'.
1317
 
1318
`pass-all'
1319
     `-p' in `ul'.
1320
 
1321
`pass-through'
1322
     `-p' in `cpio'.
1323
 
1324
`port'
1325
     `-P' in `finger'.
1326
 
1327
`portability'
1328
     `-c' in `cpio' and `tar'.
1329
 
1330
`posix'
1331
     Used in `gawk'.
1332
 
1333
`prefix-builtins'
1334
     `-P' in `m4'.
1335
 
1336
`prefix'
1337
     `-f' in `csplit'.
1338
 
1339
`preserve'
1340
     Used in `tar' and `cp'.
1341
 
1342
`preserve-environment'
1343
     `-p' in `su'.
1344
 
1345
`preserve-modification-time'
1346
     `-m' in `cpio'.
1347
 
1348
`preserve-order'
1349
     `-s' in `tar'.
1350
 
1351
`preserve-permissions'
1352
     `-p' in `tar'.
1353
 
1354
`print'
1355
     `-l' in `diff'.
1356
 
1357
`print-chars'
1358
     `-L' in `cmp'.
1359
 
1360
`print-data-base'
1361
     `-p' in Make.
1362
 
1363
`print-directory'
1364
     `-w' in Make.
1365
 
1366
`print-file-name'
1367
     `-o' in `nm'.
1368
 
1369
`print-symdefs'
1370
     `-s' in `nm'.
1371
 
1372
`printer'
1373
     `-p' in `wdiff'.
1374
 
1375
`prompt'
1376
     `-p' in `ed'.
1377
 
1378
`query-user'
1379
     `-X' in `shar'.
1380
 
1381
`question'
1382
     `-q' in Make.
1383
 
1384
`quiet'
1385
     Used in many programs to inhibit the usual output.  *Note:* every
1386
     program accepting `--quiet' should accept `--silent' as a synonym.
1387
 
1388
`quiet-unshar'
1389
     `-Q' in `shar'
1390
 
1391
`quote-name'
1392
     `-Q' in `ls'.
1393
 
1394
`rcs'
1395
     `-n' in `diff'.
1396
 
1397
`re-interval'
1398
     Used in `gawk'.
1399
 
1400
`read-full-blocks'
1401
     `-B' in `tar'.
1402
 
1403
`readnow'
1404
     Used in GDB.
1405
 
1406
`recon'
1407
     `-n' in Make.
1408
 
1409
`record-number'
1410
     `-R' in `tar'.
1411
 
1412
`recursive'
1413
     Used in `chgrp', `chown', `cp', `ls', `diff', and `rm'.
1414
 
1415
`reference-limit'
1416
     Used in `makeinfo'.
1417
 
1418
`references'
1419
     `-r' in `ptx'.
1420
 
1421
`regex'
1422
     `-r' in `tac' and `etags'.
1423
 
1424
`release'
1425
     `-r' in `uname'.
1426
 
1427
`reload-state'
1428
     `-R' in `m4'.
1429
 
1430
`relocation'
1431
     `-r' in `objdump'.
1432
 
1433
`rename'
1434
     `-r' in `cpio'.
1435
 
1436
`replace'
1437
     `-i' in `xargs'.
1438
 
1439
`report-identical-files'
1440
     `-s' in `diff'.
1441
 
1442
`reset-access-time'
1443
     `-a' in `cpio'.
1444
 
1445
`reverse'
1446
     `-r' in `ls' and `nm'.
1447
 
1448
`reversed-ed'
1449
     `-f' in `diff'.
1450
 
1451
`right-side-defs'
1452
     `-R' in `ptx'.
1453
 
1454
`same-order'
1455
     `-s' in `tar'.
1456
 
1457
`same-permissions'
1458
     `-p' in `tar'.
1459
 
1460
`save'
1461
     `-g' in `stty'.
1462
 
1463
`se'
1464
     Used in GDB.
1465
 
1466
`sentence-regexp'
1467
     `-S' in `ptx'.
1468
 
1469
`separate-dirs'
1470
     `-S' in `du'.
1471
 
1472
`separator'
1473
     `-s' in `tac'.
1474
 
1475
`sequence'
1476
     Used by `recode' to chose files or pipes for sequencing passes.
1477
 
1478
`shell'
1479
     `-s' in `su'.
1480
 
1481
`show-all'
1482
     `-A' in `cat'.
1483
 
1484
`show-c-function'
1485
     `-p' in `diff'.
1486
 
1487
`show-ends'
1488
     `-E' in `cat'.
1489
 
1490
`show-function-line'
1491
     `-F' in `diff'.
1492
 
1493
`show-tabs'
1494
     `-T' in `cat'.
1495
 
1496
`silent'
1497
     Used in many programs to inhibit the usual output.  *Note:* every
1498
     program accepting `--silent' should accept `--quiet' as a synonym.
1499
 
1500
`size'
1501
     `-s' in `ls'.
1502
 
1503
`sort'
1504
     Used in `ls'.
1505
 
1506
`source'
1507
     `-W source' in `gawk'.
1508
 
1509
`sparse'
1510
     `-S' in `tar'.
1511
 
1512
`speed-large-files'
1513
     `-H' in `diff'.
1514
 
1515
`split-at'
1516
     `-E' in `unshar'.
1517
 
1518
`split-size-limit'
1519
     `-L' in `shar'.
1520
 
1521
`squeeze-blank'
1522
     `-s' in `cat'.
1523
 
1524
`start-delete'
1525
     `-w' in `wdiff'.
1526
 
1527
`start-insert'
1528
     `-y' in `wdiff'.
1529
 
1530
`starting-file'
1531
     Used in `tar' and `diff' to specify which file within a directory
1532
     to start processing with.
1533
 
1534
`statistics'
1535
     `-s' in `wdiff'.
1536
 
1537
`stdin-file-list'
1538
     `-S' in `shar'.
1539
 
1540
`stop'
1541
     `-S' in Make.
1542
 
1543
`strict'
1544
     `-s' in `recode'.
1545
 
1546
`strip'
1547
     `-s' in `install'.
1548
 
1549
`strip-all'
1550
     `-s' in `strip'.
1551
 
1552
`strip-debug'
1553
     `-S' in `strip'.
1554
 
1555
`submitter'
1556
     `-s' in `shar'.
1557
 
1558
`suffix'
1559
     `-S' in `cp', `ln', `mv'.
1560
 
1561
`suffix-format'
1562
     `-b' in `csplit'.
1563
 
1564
`sum'
1565
     `-s' in `gprof'.
1566
 
1567
`summarize'
1568
     `-s' in `du'.
1569
 
1570
`symbolic'
1571
     `-s' in `ln'.
1572
 
1573
`symbols'
1574
     Used in GDB and `objdump'.
1575
 
1576
`synclines'
1577
     `-s' in `m4'.
1578
 
1579
`sysname'
1580
     `-s' in `uname'.
1581
 
1582
`tabs'
1583
     `-t' in `expand' and `unexpand'.
1584
 
1585
`tabsize'
1586
     `-T' in `ls'.
1587
 
1588
`terminal'
1589
     `-T' in `tput' and `ul'.  `-t' in `wdiff'.
1590
 
1591
`text'
1592
     `-a' in `diff'.
1593
 
1594
`text-files'
1595
     `-T' in `shar'.
1596
 
1597
`time'
1598
     Used in `ls' and `touch'.
1599
 
1600
`to-stdout'
1601
     `-O' in `tar'.
1602
 
1603
`total'
1604
     `-c' in `du'.
1605
 
1606
`touch'
1607
     `-t' in Make, `ranlib', and `recode'.
1608
 
1609
`trace'
1610
     `-t' in `m4'.
1611
 
1612
`traditional'
1613
     `-t' in `hello'; `-W traditional' in `gawk'; `-G' in `ed', `m4',
1614
     and `ptx'.
1615
 
1616
`tty'
1617
     Used in GDB.
1618
 
1619
`typedefs'
1620
     `-t' in `ctags'.
1621
 
1622
`typedefs-and-c++'
1623
     `-T' in `ctags'.
1624
 
1625
`typeset-mode'
1626
     `-t' in `ptx'.
1627
 
1628
`uncompress'
1629
     `-z' in `tar'.
1630
 
1631
`unconditional'
1632
     `-u' in `cpio'.
1633
 
1634
`undefine'
1635
     `-U' in `m4'.
1636
 
1637
`undefined-only'
1638
     `-u' in `nm'.
1639
 
1640
`update'
1641
     `-u' in `cp', `ctags', `mv', `tar'.
1642
 
1643
`usage'
1644
     Used in `gawk'; same as `--help'.
1645
 
1646
`uuencode'
1647
     `-B' in `shar'.
1648
 
1649
`vanilla-operation'
1650
     `-V' in `shar'.
1651
 
1652
`verbose'
1653
     Print more information about progress.  Many programs support this.
1654
 
1655
`verify'
1656
     `-W' in `tar'.
1657
 
1658
`version'
1659
     Print the version number.
1660
 
1661
`version-control'
1662
     `-V' in `cp', `ln', `mv'.
1663
 
1664
`vgrind'
1665
     `-v' in `ctags'.
1666
 
1667
`volume'
1668
     `-V' in `tar'.
1669
 
1670
`what-if'
1671
     `-W' in Make.
1672
 
1673
`whole-size-limit'
1674
     `-l' in `shar'.
1675
 
1676
`width'
1677
     `-w' in `ls' and `ptx'.
1678
 
1679
`word-regexp'
1680
     `-W' in `ptx'.
1681
 
1682
`writable'
1683
     `-T' in `who'.
1684
 
1685
`zeros'
1686
     `-z' in `gprof'.
1687
 
1688

1689
File: standards.info,  Node: Memory Usage,  Prev: Option Table,  Up: Program Behavior
1690
 
1691
Memory Usage
1692
============
1693
 
1694
   If it typically uses just a few meg of memory, don't bother making
1695
any effort to reduce memory usage.  For example, if it is impractical
1696
for other reasons to operate on files more than a few meg long, it is
1697
reasonable to read entire input files into core to operate on them.
1698
 
1699
   However, for programs such as `cat' or `tail', that can usefully
1700
operate on very large files, it is important to avoid using a technique
1701
that would artificially limit the size of files it can handle.  If a
1702
program works by lines and could be applied to arbitrary user-supplied
1703
input files, it should keep only a line in memory, because this is not
1704
very hard and users will want to be able to operate on input files that
1705
are bigger than will fit in core all at once.
1706
 
1707
   If your program creates complicated data structures, just make them
1708
in core and give a fatal error if `malloc' returns zero.
1709
 
1710

1711
File: standards.info,  Node: Writing C,  Next: Documentation,  Prev: Program Behavior,  Up: Top
1712
 
1713
Making The Best Use of C
1714
************************
1715
 
1716
   This node provides advice on how best to use the C language when
1717
writing GNU software.
1718
 
1719
* Menu:
1720
 
1721
* Formatting::                  Formatting Your Source Code
1722
* Comments::                    Commenting Your Work
1723
* Syntactic Conventions::       Clean Use of C Constructs
1724
* Names::                       Naming Variables and Functions
1725
* System Portability::          Portability between different operating systems
1726
* CPU Portability::             Supporting the range of CPU types
1727 56 joel
* System Functions::            Portability and ``standard'' library functions
1728 39 lampret
* Internationalization::        Techniques for internationalization
1729
* Mmap::                        How you can safely use `mmap'.
1730
 
1731

1732
File: standards.info,  Node: Formatting,  Next: Comments,  Up: Writing C
1733
 
1734
Formatting Your Source Code
1735
===========================
1736
 
1737
   It is important to put the open-brace that starts the body of a C
1738
function in column zero, and avoid putting any other open-brace or
1739
open-parenthesis or open-bracket in column zero.  Several tools look
1740
for open-braces in column zero to find the beginnings of C functions.
1741
These tools will not work on code not formatted that way.
1742
 
1743
   It is also important for function definitions to start the name of
1744
the function in column zero.  This helps people to search for function
1745
definitions, and may also help certain tools recognize them.  Thus, the
1746
proper format is this:
1747
 
1748
     static char *
1749
     concat (s1, s2)        /* Name starts in column zero here */
1750
          char *s1, *s2;
1751
     {                     /* Open brace in column zero here */
1752
       ...
1753
     }
1754
 
1755
or, if you want to use ANSI C, format the definition like this:
1756
 
1757
     static char *
1758
     concat (char *s1, char *s2)
1759
     {
1760
       ...
1761
     }
1762
 
1763
   In ANSI C, if the arguments don't fit nicely on one line, split it
1764
like this:
1765
 
1766
     int
1767
     lots_of_args (int an_integer, long a_long, short a_short,
1768
                   double a_double, float a_float)
1769
     ...
1770
 
1771
   For the body of the function, we prefer code formatted like this:
1772
 
1773
     if (x < foo (y, z))
1774
       haha = bar[4] + 5;
1775
     else
1776
       {
1777
         while (z)
1778
           {
1779
             haha += foo (z, z);
1780
             z--;
1781
           }
1782
         return ++x + bar ();
1783
       }
1784
 
1785
   We find it easier to read a program when it has spaces before the
1786
open-parentheses and after the commas.  Especially after the commas.
1787
 
1788
   When you split an expression into multiple lines, split it before an
1789
operator, not after one.  Here is the right way:
1790
 
1791
     if (foo_this_is_long && bar > win (x, y, z)
1792
         && remaining_condition)
1793
 
1794
   Try to avoid having two operators of different precedence at the same
1795
level of indentation.  For example, don't write this:
1796
 
1797
     mode = (inmode[j] == VOIDmode
1798
             || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
1799
             ? outmode[j] : inmode[j]);
1800
 
1801
   Instead, use extra parentheses so that the indentation shows the
1802
nesting:
1803
 
1804
     mode = ((inmode[j] == VOIDmode
1805
              || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
1806
             ? outmode[j] : inmode[j]);
1807
 
1808
   Insert extra parentheses so that Emacs will indent the code properly.
1809
For example, the following indentation looks nice if you do it by hand,
1810
but Emacs would mess it up:
1811
 
1812
     v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
1813
         + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
1814
 
1815
   But adding a set of parentheses solves the problem:
1816
 
1817
     v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
1818
          + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
1819
 
1820
   Format do-while statements like this:
1821
 
1822
     do
1823
       {
1824
         a = foo (a);
1825
       }
1826
     while (a > 0);
1827
 
1828
   Please use formfeed characters (control-L) to divide the program into
1829
pages at logical places (but not within a function).  It does not matter
1830
just how long the pages are, since they do not have to fit on a printed
1831
page.  The formfeeds should appear alone on lines by themselves.
1832
 
1833

1834
File: standards.info,  Node: Comments,  Next: Syntactic Conventions,  Prev: Formatting,  Up: Writing C
1835
 
1836
Commenting Your Work
1837
====================
1838
 
1839
   Every program should start with a comment saying briefly what it is
1840
for.  Example: `fmt - filter for simple filling of text'.
1841
 
1842
   Please write the comments in a GNU program in English, because
1843
English is the one language that nearly all programmers in all
1844
countries can read.  If you do not write English well, please write
1845
comments in English as well as you can, then ask other people to help
1846
rewrite them.  If you can't write comments in English, please find
1847
someone to work with you and translate your comments into English.
1848
 
1849
   Please put a comment on each function saying what the function does,
1850
what sorts of arguments it gets, and what the possible values of
1851
arguments mean and are used for.  It is not necessary to duplicate in
1852
words the meaning of the C argument declarations, if a C type is being
1853
used in its customary fashion.  If there is anything nonstandard about
1854
its use (such as an argument of type `char *' which is really the
1855
address of the second character of a string, not the first), or any
1856
possible values that would not work the way one would expect (such as,
1857
that strings containing newlines are not guaranteed to work), be sure
1858
to say so.
1859
 
1860
   Also explain the significance of the return value, if there is one.
1861
 
1862
   Please put two spaces after the end of a sentence in your comments,
1863
so that the Emacs sentence commands will work.  Also, please write
1864
complete sentences and capitalize the first word.  If a lower-case
1865
identifier comes at the beginning of a sentence, don't capitalize it!
1866
Changing the spelling makes it a different identifier.  If you don't
1867
like starting a sentence with a lower case letter, write the sentence
1868
differently (e.g., "The identifier lower-case is ...").
1869
 
1870
   The comment on a function is much clearer if you use the argument
1871
names to speak about the argument values.  The variable name itself
1872
should be lower case, but write it in upper case when you are speaking
1873
about the value rather than the variable itself.  Thus, "the inode
1874
number NODE_NUM" rather than "an inode".
1875
 
1876
   There is usually no purpose in restating the name of the function in
1877
the comment before it, because the reader can see that for himself.
1878
There might be an exception when the comment is so long that the
1879
function itself would be off the bottom of the screen.
1880
 
1881
   There should be a comment on each static variable as well, like this:
1882
 
1883
     /* Nonzero means truncate lines in the display;
1884
        zero means continue them.  */
1885
     int truncate_lines;
1886
 
1887
   Every `#endif' should have a comment, except in the case of short
1888
conditionals (just a few lines) that are not nested.  The comment should
1889 56 joel
state the condition of the conditional that is ending, _including its
1890
sense_.  `#else' should have a comment describing the condition _and
1891
sense_ of the code that follows.  For example:
1892 39 lampret
 
1893
     #ifdef foo
1894
       ...
1895
     #else /* not foo */
1896
       ...
1897
     #endif /* not foo */
1898
     #ifdef foo
1899
       ...
1900
     #endif /* foo */
1901
 
1902
but, by contrast, write the comments this way for a `#ifndef':
1903
 
1904
     #ifndef foo
1905
       ...
1906
     #else /* foo */
1907
       ...
1908
     #endif /* foo */
1909
     #ifndef foo
1910
       ...
1911
     #endif /* not foo */
1912
 
1913

1914
File: standards.info,  Node: Syntactic Conventions,  Next: Names,  Prev: Comments,  Up: Writing C
1915
 
1916
Clean Use of C Constructs
1917
=========================
1918
 
1919
   Please explicitly declare all arguments to functions.  Don't omit
1920
them just because they are `int's.
1921
 
1922
   Declarations of external functions and functions to appear later in
1923
the source file should all go in one place near the beginning of the
1924
file (somewhere before the first function definition in the file), or
1925
else should go in a header file.  Don't put `extern' declarations inside
1926
functions.
1927
 
1928
   It used to be common practice to use the same local variables (with
1929
names like `tem') over and over for different values within one
1930
function.  Instead of doing this, it is better declare a separate local
1931
variable for each distinct purpose, and give it a name which is
1932
meaningful.  This not only makes programs easier to understand, it also
1933
facilitates optimization by good compilers.  You can also move the
1934
declaration of each local variable into the smallest scope that includes
1935
all its uses.  This makes the program even cleaner.
1936
 
1937
   Don't use local variables or parameters that shadow global
1938
identifiers.
1939
 
1940
   Don't declare multiple variables in one declaration that spans lines.
1941
Start a new declaration on each line, instead.  For example, instead of
1942
this:
1943
 
1944
     int    foo,
1945
            bar;
1946
 
1947
write either this:
1948
 
1949
     int foo, bar;
1950
 
1951
or this:
1952
 
1953
     int foo;
1954
     int bar;
1955
 
1956
(If they are global variables, each should have a comment preceding it
1957
anyway.)
1958
 
1959
   When you have an `if'-`else' statement nested in another `if'
1960
statement, always put braces around the `if'-`else'.  Thus, never write
1961
like this:
1962
 
1963
     if (foo)
1964
       if (bar)
1965
         win ();
1966
       else
1967
         lose ();
1968
 
1969
always like this:
1970
 
1971
     if (foo)
1972
       {
1973
         if (bar)
1974
           win ();
1975
         else
1976
           lose ();
1977
       }
1978
 
1979
   If you have an `if' statement nested inside of an `else' statement,
1980
either write `else if' on one line, like this,
1981
 
1982
     if (foo)
1983
       ...
1984
     else if (bar)
1985
       ...
1986
 
1987
with its `then'-part indented like the preceding `then'-part, or write
1988
the nested `if' within braces like this:
1989
 
1990
     if (foo)
1991
       ...
1992
     else
1993
       {
1994
         if (bar)
1995
           ...
1996
       }
1997
 
1998
   Don't declare both a structure tag and variables or typedefs in the
1999
same declaration.  Instead, declare the structure tag separately and
2000
then use it to declare the variables or typedefs.
2001
 
2002
   Try to avoid assignments inside `if'-conditions.  For example, don't
2003
write this:
2004
 
2005
     if ((foo = (char *) malloc (sizeof *foo)) == 0)
2006
       fatal ("virtual memory exhausted");
2007
 
2008
instead, write this:
2009
 
2010
     foo = (char *) malloc (sizeof *foo);
2011
     if (foo == 0)
2012
       fatal ("virtual memory exhausted");
2013
 
2014
   Don't make the program ugly to placate `lint'.  Please don't insert
2015
any casts to `void'.  Zero without a cast is perfectly fine as a null
2016
pointer constant, except when calling a varargs function.
2017
 
2018

2019
File: standards.info,  Node: Names,  Next: System Portability,  Prev: Syntactic Conventions,  Up: Writing C
2020
 
2021
Naming Variables and Functions
2022
==============================
2023
 
2024
   The names of global variables and functions in a program serve as
2025
comments of a sort.  So don't choose terse names--instead, look for
2026
names that give useful information about the meaning of the variable or
2027
function.  In a GNU program, names should be English, like other
2028
comments.
2029
 
2030
   Local variable names can be shorter, because they are used only
2031
within one context, where (presumably) comments explain their purpose.
2032
 
2033
   Please use underscores to separate words in a name, so that the Emacs
2034
word commands can be useful within them.  Stick to lower case; reserve
2035
upper case for macros and `enum' constants, and for name-prefixes that
2036
follow a uniform convention.
2037
 
2038
   For example, you should use names like `ignore_space_change_flag';
2039
don't use names like `iCantReadThis'.
2040
 
2041
   Variables that indicate whether command-line options have been
2042
specified should be named after the meaning of the option, not after
2043
the option-letter.  A comment should state both the exact meaning of
2044
the option and its letter.  For example,
2045
 
2046
     /* Ignore changes in horizontal whitespace (-b).  */
2047
     int ignore_space_change_flag;
2048
 
2049
   When you want to define names with constant integer values, use
2050
`enum' rather than `#define'.  GDB knows about enumeration constants.
2051
 
2052
   Use file names of 14 characters or less, to avoid creating gratuitous
2053
problems on older System V systems.  You can use the program `doschk'
2054
to test for this.  `doschk' also tests for potential name conflicts if
2055
the files were loaded onto an MS-DOS file system--something you may or
2056
may not care about.
2057
 
2058

2059
File: standards.info,  Node: System Portability,  Next: CPU Portability,  Prev: Names,  Up: Writing C
2060
 
2061
Portability between System Types
2062
================================
2063
 
2064
   In the Unix world, "portability" refers to porting to different Unix
2065
versions.  For a GNU program, this kind of portability is desirable, but
2066
not paramount.
2067
 
2068
   The primary purpose of GNU software is to run on top of the GNU
2069
kernel, compiled with the GNU C compiler, on various types of CPU.  The
2070
amount and kinds of variation among GNU systems on different CPUs will
2071
be comparable to the variation among Linux-based GNU systems or among
2072
BSD systems today.  So the kinds of portability that are absolutely
2073
necessary are quite limited.
2074
 
2075
   But many users do run GNU software on non-GNU Unix or Unix-like
2076
systems.  So supporting a variety of Unix-like systems is desirable,
2077
although not paramount.
2078
 
2079
   The easiest way to achieve portability to most Unix-like systems is
2080
to use Autoconf.  It's unlikely that your program needs to know more
2081
information about the host platform than Autoconf can provide, simply
2082
because most of the programs that need such knowledge have already been
2083
written.
2084
 
2085
   Avoid using the format of semi-internal data bases (e.g.,
2086
directories) when there is a higher-level alternative (`readdir').
2087
 
2088
   As for systems that are not like Unix, such as MSDOS, Windows, the
2089
Macintosh, VMS, and MVS, supporting them is usually so much work that it
2090
is better if you don't.
2091
 
2092
   The planned GNU kernel is not finished yet, but you can tell which
2093
facilities it will provide by looking at the GNU C Library Manual.  The
2094
GNU kernel is based on Mach, so the features of Mach will also be
2095
available.  However, if you use Mach features, you'll probably have
2096
trouble debugging your program today.
2097
 
2098

2099
File: standards.info,  Node: CPU Portability,  Next: System Functions,  Prev: System Portability,  Up: Writing C
2100
 
2101
Portability between CPUs
2102
========================
2103
 
2104
   Even GNU systems will differ because of differences among CPU
2105
types--for example, difference in byte ordering and alignment
2106
requirements.  It is absolutely essential to handle these differences.
2107
However, don't make any effort to cater to the possibility that an
2108
`int' will be less than 32 bits.  We don't support 16-bit machines in
2109
GNU.
2110
 
2111
   Don't assume that the address of an `int' object is also the address
2112
of its least-significant byte.  This is false on big-endian machines.
2113
Thus, don't make the following mistake:
2114
 
2115
     int c;
2116
     ...
2117
     while ((c = getchar()) != EOF)
2118
       write(file_descriptor, &c, 1);
2119
 
2120
   When calling functions, you need not worry about the difference
2121
between pointers of various types, or between pointers and integers.
2122
On most machines, there's no difference anyway.  As for the few
2123
machines where there is a difference, all of them support ANSI C, so
2124
you can use prototypes (conditionalized to be active only in ANSI C) to
2125
make the code work on those systems.
2126
 
2127
   In certain cases, it is ok to pass integer and pointer arguments
2128
indiscriminately to the same function, and use no prototype on any
2129
system.  For example, many GNU programs have error-reporting functions
2130
that pass their arguments along to `printf' and friends:
2131
 
2132
     error (s, a1, a2, a3)
2133
          char *s;
2134
          int a1, a2, a3;
2135
     {
2136
       fprintf (stderr, "error: ");
2137
       fprintf (stderr, s, a1, a2, a3);
2138
     }
2139
 
2140
In practice, this works on all machines, and it is much simpler than any
2141 56 joel
"correct" alternative.  Be sure _not_ to use a prototype for such
2142 39 lampret
functions.
2143
 
2144
   However, avoid casting pointers to integers unless you really need
2145
to.  These assumptions really reduce portability, and in most programs
2146
they are easy to avoid.  In the cases where casting pointers to
2147
integers is essential--such as, a Lisp interpreter which stores type
2148
information as well as an address in one word--it is ok to do so, but
2149
you'll have to make explicit provisions to handle different word sizes.
2150
 
2151

2152
File: standards.info,  Node: System Functions,  Next: Internationalization,  Prev: CPU Portability,  Up: Writing C
2153
 
2154
Calling System Functions
2155
========================
2156
 
2157
   C implementations differ substantially.  ANSI C reduces but does not
2158
eliminate the incompatibilities; meanwhile, many users wish to compile
2159
GNU software with pre-ANSI compilers.  This chapter gives
2160
recommendations for how to use the more or less standard C library
2161
functions to avoid unnecessary loss of portability.
2162
 
2163
   * Don't use the value of `sprintf'.  It returns the number of
2164
     characters written on some systems, but not on all systems.
2165
 
2166
   * `main' should be declared to return type `int'.  It should
2167
     terminate either by calling `exit' or by returning the integer
2168
     status code; make sure it cannot ever return an undefined value.
2169
 
2170
   * Don't declare system functions explicitly.
2171
 
2172
     Almost any declaration for a system function is wrong on some
2173
     system.  To minimize conflicts, leave it to the system header
2174
     files to declare system functions.  If the headers don't declare a
2175
     function, let it remain undeclared.
2176
 
2177
     While it may seem unclean to use a function without declaring it,
2178
     in practice this works fine for most system library functions on
2179
     the systems where this really happens; thus, the disadvantage is
2180
     only theoretical.  By contrast, actual declarations have
2181
     frequently caused actual conflicts.
2182
 
2183
   * If you must declare a system function, don't specify the argument
2184
     types.  Use an old-style declaration, not an ANSI prototype.  The
2185
     more you specify about the function, the more likely a conflict.
2186
 
2187
   * In particular, don't unconditionally declare `malloc' or `realloc'.
2188
 
2189
     Most GNU programs use those functions just once, in functions
2190
     conventionally named `xmalloc' and `xrealloc'.  These functions
2191
     call `malloc' and `realloc', respectively, and check the results.
2192
 
2193
     Because `xmalloc' and `xrealloc' are defined in your program, you
2194
     can declare them in other files without any risk of type conflict.
2195
 
2196
     On most systems, `int' is the same length as a pointer; thus, the
2197
     calls to `malloc' and `realloc' work fine.  For the few
2198
     exceptional systems (mostly 64-bit machines), you can use
2199
     *conditionalized* declarations of `malloc' and `realloc'--or put
2200
     these declarations in configuration files specific to those
2201
     systems.
2202
 
2203
   * The string functions require special treatment.  Some Unix systems
2204
     have a header file `string.h'; others have `strings.h'.  Neither
2205
     file name is portable.  There are two things you can do: use
2206
     Autoconf to figure out which file to include, or don't include
2207
     either file.
2208
 
2209
   * If you don't include either strings file, you can't get
2210
     declarations for the string functions from the header file in the
2211
     usual way.
2212
 
2213
     That causes less of a problem than you might think.  The newer ANSI
2214
     string functions should be avoided anyway because many systems
2215
     still don't support them.  The string functions you can use are
2216
     these:
2217
 
2218
          strcpy   strncpy   strcat   strncat
2219
          strlen   strcmp    strncmp
2220
          strchr   strrchr
2221
 
2222
     The copy and concatenate functions work fine without a declaration
2223
     as long as you don't use their values.  Using their values without
2224
     a declaration fails on systems where the width of a pointer
2225
     differs from the width of `int', and perhaps in other cases.  It
2226
     is trivial to avoid using their values, so do that.
2227
 
2228
     The compare functions and `strlen' work fine without a declaration
2229
     on most systems, possibly all the ones that GNU software runs on.
2230
     You may find it necessary to declare them *conditionally* on a few
2231
     systems.
2232
 
2233
     The search functions must be declared to return `char *'.  Luckily,
2234
     there is no variation in the data type they return.  But there is
2235
     variation in their names.  Some systems give these functions the
2236
     names `index' and `rindex'; other systems use the names `strchr'
2237
     and `strrchr'.  Some systems support both pairs of names, but
2238
     neither pair works on all systems.
2239
 
2240
     You should pick a single pair of names and use it throughout your
2241
     program.  (Nowadays, it is better to choose `strchr' and `strrchr'
2242
     for new programs, since those are the standard ANSI names.)
2243
     Declare both of those names as functions returning `char *'.  On
2244
     systems which don't support those names, define them as macros in
2245
     terms of the other pair.  For example, here is what to put at the
2246
     beginning of your file (or in a header) if you want to use the
2247
     names `strchr' and `strrchr' throughout:
2248
 
2249
          #ifndef HAVE_STRCHR
2250
          #define strchr index
2251
          #endif
2252
          #ifndef HAVE_STRRCHR
2253
          #define strrchr rindex
2254
          #endif
2255
 
2256
          char *strchr ();
2257
          char *strrchr ();
2258
 
2259
   Here we assume that `HAVE_STRCHR' and `HAVE_STRRCHR' are macros
2260
defined in systems where the corresponding functions exist.  One way to
2261
get them properly defined is to use Autoconf.
2262
 
2263

2264
File: standards.info,  Node: Internationalization,  Next: Mmap,  Prev: System Functions,  Up: Writing C
2265
 
2266
Internationalization
2267
====================
2268
 
2269
   GNU has a library called GNU gettext that makes it easy to translate
2270
the messages in a program into various languages.  You should use this
2271
library in every program.  Use English for the messages as they appear
2272
in the program, and let gettext provide the way to translate them into
2273
other languages.
2274
 
2275
   Using GNU gettext involves putting a call to the `gettext' macro
2276
around each string that might need translation--like this:
2277
 
2278
     printf (gettext ("Processing file `%s'..."));
2279
 
2280
This permits GNU gettext to replace the string `"Processing file
2281
`%s'..."' with a translated version.
2282
 
2283
   Once a program uses gettext, please make a point of writing calls to
2284
`gettext' when you add new strings that call for translation.
2285
 
2286
   Using GNU gettext in a package involves specifying a "text domain
2287
name" for the package.  The text domain name is used to separate the
2288
translations for this package from the translations for other packages.
2289
Normally, the text domain name should be the same as the name of the
2290
package--for example, `fileutils' for the GNU file utilities.
2291
 
2292
   To enable gettext to work well, avoid writing code that makes
2293
assumptions about the structure of words or sentences.  When you want
2294
the precise text of a sentence to vary depending on the data, use two or
2295
more alternative string constants each containing a complete sentences,
2296
rather than inserting conditionalized words or phrases into a single
2297
sentence framework.
2298
 
2299
   Here is an example of what not to do:
2300
 
2301
     printf ("%d file%s processed", nfiles,
2302
             nfiles != 1 ? "s" : "");
2303
 
2304
The problem with that example is that it assumes that plurals are made
2305
by adding `s'.  If you apply gettext to the format string, like this,
2306
 
2307
     printf (gettext ("%d file%s processed"), nfiles,
2308
             nfiles != 1 ? "s" : "");
2309
 
2310
the message can use different words, but it will still be forced to use
2311
`s' for the plural.  Here is a better way:
2312
 
2313
     printf ((nfiles != 1 ? "%d files processed"
2314
              : "%d file processed"),
2315
             nfiles);
2316
 
2317
This way, you can apply gettext to each of the two strings
2318
independently:
2319
 
2320
     printf ((nfiles != 1 ? gettext ("%d files processed")
2321
              : gettext ("%d file processed")),
2322
             nfiles);
2323
 
2324
This can be any method of forming the plural of the word for "file", and
2325
also handles languages that require agreement in the word for
2326
"processed".
2327
 
2328
   A similar problem appears at the level of sentence structure with
2329
this code:
2330
 
2331
     printf ("#  Implicit rule search has%s been done.\n",
2332
             f->tried_implicit ? "" : " not");
2333
 
2334
Adding `gettext' calls to this code cannot give correct results for all
2335
languages, because negation in some languages requires adding words at
2336
more than one place in the sentence.  By contrast, adding `gettext'
2337
calls does the job straightfowardly if the code starts out like this:
2338
 
2339
     printf (f->tried_implicit
2340
             ? "#  Implicit rule search has been done.\n",
2341
             : "#  Implicit rule search has not been done.\n");
2342
 
2343

2344
File: standards.info,  Node: Mmap,  Prev: Internationalization,  Up: Writing C
2345
 
2346
Mmap
2347
====
2348
 
2349
   Don't assume that `mmap' either works on all files or fails for all
2350
files.  It may work on some files and fail on others.
2351
 
2352
   The proper way to use `mmap' is to try it on the specific file for
2353
which you want to use it--and if `mmap' doesn't work, fall back on
2354
doing the job in another way using `read' and `write'.
2355
 
2356
   The reason this precaution is needed is that the GNU kernel (the
2357
HURD) provides a user-extensible file system, in which there can be many
2358
different kinds of "ordinary files."  Many of them support `mmap', but
2359
some do not.  It is important to make programs handle all these kinds
2360
of files.
2361
 
2362

2363
File: standards.info,  Node: Documentation,  Next: Managing Releases,  Prev: Writing C,  Up: Top
2364
 
2365
Documenting Programs
2366
********************
2367
 
2368
* Menu:
2369
 
2370
* GNU Manuals::                 Writing proper manuals.
2371
* Manual Structure Details::    Specific structure conventions.
2372
* NEWS File::                   NEWS files supplement manuals.
2373
* Change Logs::                 Recording Changes
2374
* Man Pages::                   Man pages are secondary.
2375
* Reading other Manuals::       How far you can go in learning
2376
                                from other manuals.
2377
 
2378

2379
File: standards.info,  Node: GNU Manuals,  Next: Manual Structure Details,  Up: Documentation
2380
 
2381
GNU Manuals
2382
===========
2383
 
2384
   The preferred way to document part of the GNU system is to write a
2385
manual in the Texinfo formatting language.  See the Texinfo manual,
2386
either the hardcopy, or the on-line version available through `info' or
2387
the Emacs Info subsystem (`C-h i').
2388
 
2389
   Programmers often find it most natural to structure the documentation
2390
following the structure of the implementation, which they know.  But
2391
this structure is not necessarily good for explaining how to use the
2392
program; it may be irrelevant and confusing for a user.
2393
 
2394
   At every level, from the sentences in a paragraph to the grouping of
2395
topics into separate manuals, the right way to structure documentation
2396
is according to the concepts and questions that a user will have in mind
2397
when reading it.  Sometimes this structure of ideas matches the
2398
structure of the implementation of the software being documented--but
2399
often they are different.  Often the most important part of learning to
2400
write good documentation is learning to notice when you are structuring
2401
the documentation like the implementation, and think about better
2402
alternatives.
2403
 
2404
   For example, each program in the GNU system probably ought to be
2405
documented in one manual; but this does not mean each program should
2406
have its own manual.  That would be following the structure of the
2407
implementation, rather than the structure that helps the user
2408
understand.
2409
 
2410 56 joel
   Instead, each manual should cover a coherent _topic_.  For example,
2411 39 lampret
instead of a manual for `diff' and a manual for `diff3', we have one
2412
manual for "comparison of files" which covers both of those programs,
2413
as well as `cmp'.  By documenting these programs together, we can make
2414
the whole subject clearer.
2415
 
2416
   The manual which discusses a program should document all of the
2417
program's command-line options and all of its commands.  It should give
2418
examples of their use.  But don't organize the manual as a list of
2419
features.  Instead, organize it logically, by subtopics.  Address the
2420
questions that a user will ask when thinking about the job that the
2421
program does.
2422
 
2423
   In general, a GNU manual should serve both as tutorial and reference.
2424
It should be set up for convenient access to each topic through Info,
2425
and for reading straight through (appendixes aside).  A GNU manual
2426
should give a good introduction to a beginner reading through from the
2427
start, and should also provide all the details that hackers want.
2428
 
2429
   That is not as hard as it first sounds.  Arrange each chapter as a
2430
logical breakdown of its topic, but order the sections, and write their
2431
text, so that reading the chapter straight through makes sense.  Do
2432
likewise when structuring the book into chapters, and when structuring a
2433 56 joel
section into paragraphs.  The watchword is, _at each point, address the
2434
most fundamental and important issue raised by the preceding text._
2435 39 lampret
 
2436
   If necessary, add extra chapters at the beginning of the manual which
2437
are purely tutorial and cover the basics of the subject.  These provide
2438
the framework for a beginner to understand the rest of the manual.  The
2439
Bison manual provides a good example of how to do this.
2440
 
2441
   Don't use Unix man pages as a model for how to write GNU
2442
documentation; most of them are terse, badly structured, and give
2443
inadequate explanation of the underlying concepts.  (There are, of
2444
course exceptions.)  Also Unix man pages use a particular format which
2445
is different from what we use in GNU manuals.
2446
 
2447
   Please do not use the term "pathname" that is used in Unix
2448
documentation; use "file name" (two words) instead.  We use the term
2449
"path" only for search paths, which are lists of file names.
2450
 
2451
   Please do not use the term "illegal" to refer to erroneous input to a
2452
computer program.  Please use "invalid" for this, and reserve the term
2453
"illegal" for violations of law.
2454
 
2455

2456
File: standards.info,  Node: Manual Structure Details,  Next: NEWS File,  Prev: GNU Manuals,  Up: Documentation
2457
 
2458
Manual Structure Details
2459
========================
2460
 
2461
   The title page of the manual should state the version of the
2462
programs or packages documented in the manual.  The Top node of the
2463
manual should also contain this information.  If the manual is changing
2464
more frequently than or independent of the program, also state a version
2465
number for the manual in both of these places.
2466
 
2467
   Each program documented in the manual should should have a node named
2468
`PROGRAM Invocation' or `Invoking PROGRAM'.  This node (together with
2469
its subnodes, if any) should describe the program's command line
2470
arguments and how to run it (the sort of information people would look
2471
in a man page for).  Start with an `@example' containing a template for
2472
all the options and arguments that the program uses.
2473
 
2474
   Alternatively, put a menu item in some menu whose item name fits one
2475
of the above patterns.  This identifies the node which that item points
2476
to as the node for this purpose, regardless of the node's actual name.
2477
 
2478
   There will be automatic features for specifying a program name and
2479
quickly reading just this part of its manual.
2480
 
2481
   If one manual describes several programs, it should have such a node
2482
for each program described.
2483
 
2484

2485
File: standards.info,  Node: NEWS File,  Next: Change Logs,  Prev: Manual Structure Details,  Up: Documentation
2486
 
2487
The NEWS File
2488
=============
2489
 
2490
   In addition to its manual, the package should have a file named
2491
`NEWS' which contains a list of user-visible changes worth mentioning.
2492
In each new release, add items to the front of the file and identify
2493
the version they pertain to.  Don't discard old items; leave them in
2494
the file after the newer items.  This way, a user upgrading from any
2495
previous version can see what is new.
2496
 
2497
   If the `NEWS' file gets very long, move some of the older items into
2498
a file named `ONEWS' and put a note at the end referring the user to
2499
that file.
2500
 
2501

2502
File: standards.info,  Node: Change Logs,  Next: Man Pages,  Prev: NEWS File,  Up: Documentation
2503
 
2504
Change Logs
2505
===========
2506
 
2507
   Keep a change log to describe all the changes made to program source
2508
files.  The purpose of this is so that people investigating bugs in the
2509
future will know about the changes that might have introduced the bug.
2510
Often a new bug can be found by looking at what was recently changed.
2511
More importantly, change logs can help you eliminate conceptual
2512
inconsistencies between different parts of a program, by giving you a
2513
history of how the conflicting concepts arose and who they came from.
2514
 
2515
* Menu:
2516
 
2517
* Change Log Concepts::
2518
* Style of Change Logs::
2519
* Simple Changes::
2520
* Conditional Changes::
2521
 
2522

2523
File: standards.info,  Node: Change Log Concepts,  Next: Style of Change Logs,  Up: Change Logs
2524
 
2525
Change Log Concepts
2526
-------------------
2527
 
2528
   You can think of the change log as a conceptual "undo list" which
2529
explains how earlier versions were different from the current version.
2530
People can see the current version; they don't need the change log to
2531
tell them what is in it.  What they want from a change log is a clear
2532
explanation of how the earlier version differed.
2533
 
2534
   The change log file is normally called `ChangeLog' and covers an
2535
entire directory.  Each directory can have its own change log, or a
2536
directory can use the change log of its parent directory-it's up to you.
2537
 
2538
   Another alternative is to record change log information with a
2539
version control system such as RCS or CVS.  This can be converted
2540
automatically to a `ChangeLog' file.
2541
 
2542
   There's no need to describe the full purpose of the changes or how
2543
they work together.  If you think that a change calls for explanation,
2544
you're probably right.  Please do explain it--but please put the
2545
explanation in comments in the code, where people will see it whenever
2546
they see the code.  For example, "New function" is enough for the
2547
change log when you add a function, because there should be a comment
2548
before the function definition to explain what it does.
2549
 
2550
   However, sometimes it is useful to write one line to describe the
2551
overall purpose of a batch of changes.
2552
 
2553
   The easiest way to add an entry to `ChangeLog' is with the Emacs
2554
command `M-x add-change-log-entry'.  An entry should have an asterisk,
2555
the name of the changed file, and then in parentheses the name of the
2556
changed functions, variables or whatever, followed by a colon.  Then
2557
describe the changes you made to that function or variable.
2558
 
2559

2560
File: standards.info,  Node: Style of Change Logs,  Next: Simple Changes,  Prev: Change Log Concepts,  Up: Change Logs
2561
 
2562
Style of Change Logs
2563
--------------------
2564
 
2565
   Here are some examples of change log entries:
2566
 
2567
     * register.el (insert-register): Return nil.
2568
     (jump-to-register): Likewise.
2569
 
2570
     * sort.el (sort-subr): Return nil.
2571
 
2572
     * tex-mode.el (tex-bibtex-file, tex-file, tex-region):
2573
     Restart the tex shell if process is gone or stopped.
2574
     (tex-shell-running): New function.
2575
 
2576
     * expr.c (store_one_arg): Round size up for move_block_to_reg.
2577
     (expand_call): Round up when emitting USE insns.
2578
     * stmt.c (assign_parms): Round size up for move_block_from_reg.
2579
 
2580
   It's important to name the changed function or variable in full.
2581
Don't abbreviate function or variable names, and don't combine them.
2582
Subsequent maintainers will often search for a function name to find all
2583
the change log entries that pertain to it; if you abbreviate the name,
2584
they won't find it when they search.
2585
 
2586
   For example, some people are tempted to abbreviate groups of function
2587
names by writing `* register.el ({insert,jump-to}-register)'; this is
2588
not a good idea, since searching for `jump-to-register' or
2589
`insert-register' would not find that entry.
2590
 
2591
   Separate unrelated change log entries with blank lines.  When two
2592
entries represent parts of the same change, so that they work together,
2593
then don't put blank lines between them.  Then you can omit the file
2594
name and the asterisk when successive entries are in the same file.
2595
 
2596

2597
File: standards.info,  Node: Simple Changes,  Next: Conditional Changes,  Prev: Style of Change Logs,  Up: Change Logs
2598
 
2599
Simple Changes
2600
--------------
2601
 
2602
   Certain simple kinds of changes don't need much detail in the change
2603
log.
2604
 
2605
   When you change the calling sequence of a function in a simple
2606
fashion, and you change all the callers of the function, there is no
2607
need to make individual entries for all the callers that you changed.
2608
Just write in the entry for the function being called, "All callers
2609
changed."
2610
 
2611
     * keyboard.c (Fcommand_execute): New arg SPECIAL.
2612
     All callers changed.
2613
 
2614
   When you change just comments or doc strings, it is enough to write
2615
an entry for the file, without mentioning the functions.  Just "Doc
2616
fixes" is enough for the change log.
2617
 
2618
   There's no need to make change log entries for documentation files.
2619
This is because documentation is not susceptible to bugs that are hard
2620
to fix.  Documentation does not consist of parts that must interact in a
2621
precisely engineered fashion.  To correct an error, you need not know
2622
the history of the erroneous passage; it is enough to compare what the
2623
documentation says with the way the program actually works.
2624
 
2625

2626
File: standards.info,  Node: Conditional Changes,  Prev: Simple Changes,  Up: Change Logs
2627
 
2628
Conditional Changes
2629
-------------------
2630
 
2631
   C programs often contain compile-time `#if' conditionals.  Many
2632
changes are conditional; sometimes you add a new definition which is
2633
entirely contained in a conditional.  It is very useful to indicate in
2634
the change log the conditions for which the change applies.
2635
 
2636
   Our convention for indicating conditional changes is to use square
2637
brackets around the name of the condition.
2638
 
2639
   Here is a simple example, describing a change which is conditional
2640
but does not have a function or entity name associated with it:
2641
 
2642
     * xterm.c [SOLARIS2]: Include string.h.
2643
 
2644
   Here is an entry describing a new definition which is entirely
2645
conditional.  This new definition for the macro `FRAME_WINDOW_P' is
2646
used only when `HAVE_X_WINDOWS' is defined:
2647
 
2648
     * frame.h [HAVE_X_WINDOWS] (FRAME_WINDOW_P): Macro defined.
2649
 
2650
   Here is an entry for a change within the function `init_display',
2651
whose definition as a whole is unconditional, but the changes themselves
2652
are contained in a `#ifdef HAVE_LIBNCURSES' conditional:
2653
 
2654
     * dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent.
2655
 
2656
   Here is an entry for a change that takes affect only when a certain
2657 56 joel
macro is _not_ defined:
2658 39 lampret
 
2659
     (gethostname) [!HAVE_SOCKETS]: Replace with winsock version.
2660
 
2661

2662
File: standards.info,  Node: Man Pages,  Next: Reading other Manuals,  Prev: Change Logs,  Up: Documentation
2663
 
2664
Man Pages
2665
=========
2666
 
2667
   In the GNU project, man pages are secondary.  It is not necessary or
2668
expected for every GNU program to have a man page, but some of them do.
2669
It's your choice whether to include a man page in your program.
2670
 
2671
   When you make this decision, consider that supporting a man page
2672
requires continual effort each time the program is changed.  The time
2673
you spend on the man page is time taken away from more useful work.
2674
 
2675
   For a simple program which changes little, updating the man page may
2676
be a small job.  Then there is little reason not to include a man page,
2677
if you have one.
2678
 
2679
   For a large program that changes a great deal, updating a man page
2680
may be a substantial burden.  If a user offers to donate a man page,
2681
you may find this gift costly to accept.  It may be better to refuse
2682
the man page unless the same person agrees to take full responsibility
2683
for maintaining it--so that you can wash your hands of it entirely.  If
2684
this volunteer later ceases to do the job, then don't feel obliged to
2685
pick it up yourself; it may be better to withdraw the man page from the
2686
distribution until someone else agrees to update it.
2687
 
2688
   When a program changes only a little, you may feel that the
2689
discrepancies are small enough that the man page remains useful without
2690
updating.  If so, put a prominent note near the beginning of the man
2691
page explaining that you don't maintain it and that the Texinfo manual
2692
is more authoritative.  The note should say how to access the Texinfo
2693
documentation.
2694
 
2695

2696
File: standards.info,  Node: Reading other Manuals,  Prev: Man Pages,  Up: Documentation
2697
 
2698
Reading other Manuals
2699
=====================
2700
 
2701
   There may be non-free books or documentation files that describe the
2702
program you are documenting.
2703
 
2704
   It is ok to use these documents for reference, just as the author of
2705
a new algebra textbook can read other books on algebra.  A large portion
2706
of any non-fiction book consists of facts, in this case facts about how
2707
a certain program works, and these facts are necessarily the same for
2708
everyone who writes about the subject.  But be careful not to copy your
2709
outline structure, wording, tables or examples from preexisting non-free
2710
documentation.  Copying from free documentation may be ok; please check
2711
with the FSF about the individual case.
2712
 
2713

2714
File: standards.info,  Node: Managing Releases,  Prev: Documentation,  Up: Top
2715
 
2716
The Release Process
2717
*******************
2718
 
2719
   Making a release is more than just bundling up your source files in a
2720
tar file and putting it up for FTP.  You should set up your software so
2721
that it can be configured to run on a variety of systems.  Your Makefile
2722
should conform to the GNU standards described below, and your directory
2723
layout should also conform to the standards discussed below.  Doing so
2724
makes it easy to include your package into the larger framework of all
2725
GNU software.
2726
 
2727
* Menu:
2728
 
2729
* Configuration::               How Configuration Should Work
2730
* Makefile Conventions::        Makefile Conventions
2731
* Releases::                    Making Releases
2732
 
2733

2734
File: standards.info,  Node: Configuration,  Next: Makefile Conventions,  Up: Managing Releases
2735
 
2736
How Configuration Should Work
2737
=============================
2738
 
2739
   Each GNU distribution should come with a shell script named
2740
`configure'.  This script is given arguments which describe the kind of
2741
machine and system you want to compile the program for.
2742
 
2743
   The `configure' script must record the configuration options so that
2744
they affect compilation.
2745
 
2746
   One way to do this is to make a link from a standard name such as
2747
`config.h' to the proper configuration file for the chosen system.  If
2748 56 joel
you use this technique, the distribution should _not_ contain a file
2749 39 lampret
named `config.h'.  This is so that people won't be able to build the
2750
program without configuring it first.
2751
 
2752
   Another thing that `configure' can do is to edit the Makefile.  If
2753 56 joel
you do this, the distribution should _not_ contain a file named
2754 39 lampret
`Makefile'.  Instead, it should include a file `Makefile.in' which
2755
contains the input used for editing.  Once again, this is so that people
2756
won't be able to build the program without configuring it first.
2757
 
2758
   If `configure' does write the `Makefile', then `Makefile' should
2759
have a target named `Makefile' which causes `configure' to be rerun,
2760
setting up the same configuration that was set up last time.  The files
2761
that `configure' reads should be listed as dependencies of `Makefile'.
2762
 
2763
   All the files which are output from the `configure' script should
2764
have comments at the beginning explaining that they were generated
2765
automatically using `configure'.  This is so that users won't think of
2766
trying to edit them by hand.
2767
 
2768
   The `configure' script should write a file named `config.status'
2769
which describes which configuration options were specified when the
2770
program was last configured.  This file should be a shell script which,
2771
if run, will recreate the same configuration.
2772
 
2773
   The `configure' script should accept an option of the form
2774
`--srcdir=DIRNAME' to specify the directory where sources are found (if
2775
it is not the current directory).  This makes it possible to build the
2776
program in a separate directory, so that the actual source directory is
2777
not modified.
2778
 
2779
   If the user does not specify `--srcdir', then `configure' should
2780
check both `.' and `..' to see if it can find the sources.  If it finds
2781
the sources in one of these places, it should use them from there.
2782
Otherwise, it should report that it cannot find the sources, and should
2783
exit with nonzero status.
2784
 
2785
   Usually the easy way to support `--srcdir' is by editing a
2786
definition of `VPATH' into the Makefile.  Some rules may need to refer
2787
explicitly to the specified source directory.  To make this possible,
2788
`configure' can add to the Makefile a variable named `srcdir' whose
2789
value is precisely the specified directory.
2790
 
2791
   The `configure' script should also take an argument which specifies
2792
the type of system to build the program for.  This argument should look
2793
like this:
2794
 
2795
     CPU-COMPANY-SYSTEM
2796
 
2797
   For example, a Sun 3 might be `m68k-sun-sunos4.1'.
2798
 
2799
   The `configure' script needs to be able to decode all plausible
2800
alternatives for how to describe a machine.  Thus, `sun3-sunos4.1'
2801
would be a valid alias.  For many programs, `vax-dec-ultrix' would be
2802
an alias for `vax-dec-bsd', simply because the differences between
2803
Ultrix and BSD are rarely noticeable, but a few programs might need to
2804
distinguish them.
2805
 
2806
   There is a shell script called `config.sub' that you can use as a
2807
subroutine to validate system types and canonicalize aliases.
2808
 
2809
   Other options are permitted to specify in more detail the software
2810
or hardware present on the machine, and include or exclude optional
2811
parts of the package:
2812
 
2813
`--enable-FEATURE[=PARAMETER]'
2814
     Configure the package to build and install an optional user-level
2815
     facility called FEATURE.  This allows users to choose which
2816
     optional features to include.  Giving an optional PARAMETER of
2817
     `no' should omit FEATURE, if it is built by default.
2818
 
2819
     No `--enable' option should *ever* cause one feature to replace
2820
     another.  No `--enable' option should ever substitute one useful
2821
     behavior for another useful behavior.  The only proper use for
2822
     `--enable' is for questions of whether to build part of the program
2823
     or exclude it.
2824
 
2825
`--with-PACKAGE'
2826
     The package PACKAGE will be installed, so configure this package
2827
     to work with PACKAGE.
2828
 
2829
     Possible values of PACKAGE include `gnu-as' (or `gas'), `gnu-ld',
2830
     `gnu-libc', `gdb', `x', and `x-toolkit'.
2831
 
2832
     Do not use a `--with' option to specify the file name to use to
2833
     find certain files.  That is outside the scope of what `--with'
2834
     options are for.
2835
 
2836
`--nfp'
2837
     The target machine has no floating point processor.
2838
 
2839
`--gas'
2840
     The target machine assembler is GAS, the GNU assembler.  This is
2841
     obsolete; users should use `--with-gnu-as' instead.
2842
 
2843
`--x'
2844
     The target machine has the X Window System installed.  This is
2845
     obsolete; users should use `--with-x' instead.
2846
 
2847
   All `configure' scripts should accept all of these "detail" options,
2848
whether or not they make any difference to the particular package at
2849
hand.  In particular, they should accept any option that starts with
2850
`--with-' or `--enable-'.  This is so users will be able to configure
2851
an entire GNU source tree at once with a single set of options.
2852
 
2853
   You will note that the categories `--with-' and `--enable-' are
2854
narrow: they *do not* provide a place for any sort of option you might
2855
think of.  That is deliberate.  We want to limit the possible
2856
configuration options in GNU software.  We do not want GNU programs to
2857
have idiosyncratic configuration options.
2858
 
2859
   Packages that perform part of the compilation process may support
2860
cross-compilation.  In such a case, the host and target machines for
2861
the program may be different.  The `configure' script should normally
2862
treat the specified type of system as both the host and the target,
2863
thus producing a program which works for the same type of machine that
2864
it runs on.
2865
 
2866
   The way to build a cross-compiler, cross-assembler, or what have
2867
you, is to specify the option `--host=HOSTTYPE' when running
2868
`configure'.  This specifies the host system without changing the type
2869
of target system.  The syntax for HOSTTYPE is the same as described
2870
above.
2871
 
2872
   Bootstrapping a cross-compiler requires compiling it on a machine
2873
other than the host it will run on.  Compilation packages accept a
2874
configuration option `--build=HOSTTYPE' for specifying the
2875
configuration on which you will compile them, in case that is different
2876
from the host.
2877
 
2878
   Programs for which cross-operation is not meaningful need not accept
2879
the `--host' option, because configuring an entire operating system for
2880
cross-operation is not a meaningful thing.
2881
 
2882
   Some programs have ways of configuring themselves automatically.  If
2883
your program is set up to do this, your `configure' script can simply
2884
ignore most of its arguments.
2885
 
2886

2887
File: standards.info,  Node: Makefile Conventions,  Next: Releases,  Prev: Configuration,  Up: Managing Releases
2888
 
2889
Makefile Conventions
2890
====================
2891
 
2892
   This node describes conventions for writing the Makefiles for GNU
2893
programs.
2894
 
2895
* Menu:
2896
 
2897
* Makefile Basics::             General Conventions for Makefiles
2898
* Utilities in Makefiles::      Utilities in Makefiles
2899
* Command Variables::           Variables for Specifying Commands
2900
* Directory Variables::         Variables for Installation Directories
2901
* Standard Targets::            Standard Targets for Users
2902
* Install Command Categories::  Three categories of commands in the `install'
2903
                                  rule: normal, pre-install and post-install.
2904
 
2905

2906
File: standards.info,  Node: Makefile Basics,  Next: Utilities in Makefiles,  Up: Makefile Conventions
2907
 
2908
General Conventions for Makefiles
2909
---------------------------------
2910
 
2911
   Every Makefile should contain this line:
2912
 
2913
     SHELL = /bin/sh
2914
 
2915
to avoid trouble on systems where the `SHELL' variable might be
2916
inherited from the environment.  (This is never a problem with GNU
2917
`make'.)
2918
 
2919
   Different `make' programs have incompatible suffix lists and
2920
implicit rules, and this sometimes creates confusion or misbehavior.  So
2921
it is a good idea to set the suffix list explicitly using only the
2922
suffixes you need in the particular Makefile, like this:
2923
 
2924
     .SUFFIXES:
2925
     .SUFFIXES: .c .o
2926
 
2927
The first line clears out the suffix list, the second introduces all
2928
suffixes which may be subject to implicit rules in this Makefile.
2929
 
2930
   Don't assume that `.' is in the path for command execution.  When
2931
you need to run programs that are a part of your package during the
2932
make, please make sure that it uses `./' if the program is built as
2933
part of the make or `$(srcdir)/' if the file is an unchanging part of
2934
the source code.  Without one of these prefixes, the current search
2935
path is used.
2936
 
2937
   The distinction between `./' (the "build directory") and
2938
`$(srcdir)/' (the "source directory") is important because users can
2939
build in a separate directory using the `--srcdir' option to
2940
`configure'.  A rule of the form:
2941
 
2942
     foo.1 : foo.man sedscript
2943
             sed -e sedscript foo.man > foo.1
2944
 
2945
will fail when the build directory is not the source directory, because
2946
`foo.man' and `sedscript' are in the the source directory.
2947
 
2948
   When using GNU `make', relying on `VPATH' to find the source file
2949
will work in the case where there is a single dependency file, since
2950
the `make' automatic variable `$<' will represent the source file
2951
wherever it is.  (Many versions of `make' set `$<' only in implicit
2952
rules.)  A Makefile target like
2953
 
2954
     foo.o : bar.c
2955
             $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
2956
 
2957
should instead be written as
2958
 
2959
     foo.o : bar.c
2960
             $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@
2961
 
2962
in order to allow `VPATH' to work correctly.  When the target has
2963
multiple dependencies, using an explicit `$(srcdir)' is the easiest way
2964
to make the rule work well.  For example, the target above for `foo.1'
2965
is best written as:
2966
 
2967
     foo.1 : foo.man sedscript
2968
             sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@
2969
 
2970
   GNU distributions usually contain some files which are not source
2971
files--for example, Info files, and the output from Autoconf, Automake,
2972
Bison or Flex.  Since these files normally appear in the source
2973
directory, they should always appear in the source directory, not in the
2974
build directory.  So Makefile rules to update them should put the
2975
updated files in the source directory.
2976
 
2977
   However, if a file does not appear in the distribution, then the
2978
Makefile should not put it in the source directory, because building a
2979
program in ordinary circumstances should not modify the source directory
2980
in any way.
2981
 
2982
   Try to make the build and installation targets, at least (and all
2983
their subtargets) work correctly with a parallel `make'.
2984
 
2985

2986
File: standards.info,  Node: Utilities in Makefiles,  Next: Command Variables,  Prev: Makefile Basics,  Up: Makefile Conventions
2987
 
2988
Utilities in Makefiles
2989
----------------------
2990
 
2991
   Write the Makefile commands (and any shell scripts, such as
2992
`configure') to run in `sh', not in `csh'.  Don't use any special
2993
features of `ksh' or `bash'.
2994
 
2995
   The `configure' script and the Makefile rules for building and
2996
installation should not use any utilities directly except these:
2997
 
2998
     cat cmp cp diff echo egrep expr false grep install-info
2999
     ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
3000
 
3001
   The compression program `gzip' can be used in the `dist' rule.
3002
 
3003
   Stick to the generally supported options for these programs.  For
3004
example, don't use `mkdir -p', convenient as it may be, because most
3005
systems don't support it.
3006
 
3007
   It is a good idea to avoid creating symbolic links in makefiles,
3008
since a few systems don't support them.
3009
 
3010
   The Makefile rules for building and installation can also use
3011
compilers and related programs, but should do so via `make' variables
3012
so that the user can substitute alternatives.  Here are some of the
3013
programs we mean:
3014
 
3015
     ar bison cc flex install ld ldconfig lex
3016
     make makeinfo ranlib texi2dvi yacc
3017
 
3018
   Use the following `make' variables to run those programs:
3019
 
3020
     $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
3021
     $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
3022
 
3023
   When you use `ranlib' or `ldconfig', you should make sure nothing
3024
bad happens if the system does not have the program in question.
3025
Arrange to ignore an error from that command, and print a message before
3026
the command to tell the user that failure of this command does not mean
3027
a problem.  (The Autoconf `AC_PROG_RANLIB' macro can help with this.)
3028
 
3029
   If you use symbolic links, you should implement a fallback for
3030
systems that don't have symbolic links.
3031
 
3032
   Additional utilities that can be used via Make variables are:
3033
 
3034
     chgrp chmod chown mknod
3035
 
3036
   It is ok to use other utilities in Makefile portions (or scripts)
3037
intended only for particular systems where you know those utilities
3038
exist.
3039
 
3040

3041
File: standards.info,  Node: Command Variables,  Next: Directory Variables,  Prev: Utilities in Makefiles,  Up: Makefile Conventions
3042
 
3043
Variables for Specifying Commands
3044
---------------------------------
3045
 
3046
   Makefiles should provide variables for overriding certain commands,
3047
options, and so on.
3048
 
3049
   In particular, you should run most utility programs via variables.
3050
Thus, if you use Bison, have a variable named `BISON' whose default
3051
value is set with `BISON = bison', and refer to it with `$(BISON)'
3052
whenever you need to use Bison.
3053
 
3054
   File management utilities such as `ln', `rm', `mv', and so on, need
3055
not be referred to through variables in this way, since users don't
3056
need to replace them with other programs.
3057
 
3058
   Each program-name variable should come with an options variable that
3059
is used to supply options to the program.  Append `FLAGS' to the
3060
program-name variable name to get the options variable name--for
3061
example, `BISONFLAGS'.  (The names `CFLAGS' for the C compiler,
3062
`YFLAGS' for yacc, and `LFLAGS' for lex, are exceptions to this rule,
3063 56 joel
but we keep them because they are standard.)  Use `CPPFLAGS' in any
3064 39 lampret
compilation command that runs the preprocessor, and use `LDFLAGS' in
3065
any compilation command that does linking as well as in any direct use
3066
of `ld'.
3067
 
3068 56 joel
   If there are C compiler options that _must_ be used for proper
3069 39 lampret
compilation of certain files, do not include them in `CFLAGS'.  Users
3070
expect to be able to specify `CFLAGS' freely themselves.  Instead,
3071
arrange to pass the necessary options to the C compiler independently
3072
of `CFLAGS', by writing them explicitly in the compilation commands or
3073
by defining an implicit rule, like this:
3074
 
3075
     CFLAGS = -g
3076
     ALL_CFLAGS = -I. $(CFLAGS)
3077
     .c.o:
3078
             $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
3079
 
3080
   Do include the `-g' option in `CFLAGS', because that is not
3081 56 joel
_required_ for proper compilation.  You can consider it a default that
3082 39 lampret
is only recommended.  If the package is set up so that it is compiled
3083
with GCC by default, then you might as well include `-O' in the default
3084
value of `CFLAGS' as well.
3085
 
3086
   Put `CFLAGS' last in the compilation command, after other variables
3087
containing compiler options, so the user can use `CFLAGS' to override
3088
the others.
3089
 
3090
   `CFLAGS' should be used in every invocation of the C compiler, both
3091
those which do compilation and those which do linking.
3092
 
3093
   Every Makefile should define the variable `INSTALL', which is the
3094
basic command for installing a file into the system.
3095
 
3096
   Every Makefile should also define the variables `INSTALL_PROGRAM'
3097
and `INSTALL_DATA'.  (The default for each of these should be
3098
`$(INSTALL)'.)  Then it should use those variables as the commands for
3099
actual installation, for executables and nonexecutables respectively.
3100
Use these variables as follows:
3101
 
3102
     $(INSTALL_PROGRAM) foo $(bindir)/foo
3103
     $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
3104
 
3105
   Optionally, you may prepend the value of `DESTDIR' to the target
3106
filename.  Doing this allows the installer to create a snapshot of the
3107
installation to be copied onto the real target filesystem later.  Do not
3108
set the value of `DESTDIR' in your Makefile, and do not include it in
3109
any installed files.  With support for `DESTDIR', the above examples
3110
become:
3111
 
3112
     $(INSTALL_PROGRAM) foo $(DESTDIR)$(bindir)/foo
3113
     $(INSTALL_DATA) libfoo.a $(DESTDIR)$(libdir)/libfoo.a
3114
 
3115
Always use a file name, not a directory name, as the second argument of
3116
the installation commands.  Use a separate command for each file to be
3117
installed.
3118
 
3119

3120
File: standards.info,  Node: Directory Variables,  Next: Standard Targets,  Prev: Command Variables,  Up: Makefile Conventions
3121
 
3122
Variables for Installation Directories
3123
--------------------------------------
3124
 
3125
   Installation directories should always be named by variables, so it
3126
is easy to install in a nonstandard place.  The standard names for these
3127
variables are described below.  They are based on a standard filesystem
3128
layout; variants of it are used in SVR4, 4.4BSD, Linux, Ultrix v4, and
3129
other modern operating systems.
3130
 
3131
   These two variables set the root for the installation.  All the other
3132
installation directories should be subdirectories of one of these two,
3133
and nothing should be directly installed into these two directories.
3134
 
3135
`prefix'
3136
     A prefix used in constructing the default values of the variables
3137
     listed below.  The default value of `prefix' should be
3138
     `/usr/local'.  When building the complete GNU system, the prefix
3139
     will be empty and `/usr' will be a symbolic link to `/'.  (If you
3140
     are using Autoconf, write it as `@prefix@'.)
3141
 
3142
     Running `make install' with a different value of `prefix' from the
3143
     one used to build the program should NOT recompile the program.
3144
 
3145
`exec_prefix'
3146
     A prefix used in constructing the default values of some of the
3147
     variables listed below.  The default value of `exec_prefix' should
3148
     be `$(prefix)'.  (If you are using Autoconf, write it as
3149
     `@exec_prefix@'.)
3150
 
3151
     Generally, `$(exec_prefix)' is used for directories that contain
3152
     machine-specific files (such as executables and subroutine
3153
     libraries), while `$(prefix)' is used directly for other
3154
     directories.
3155
 
3156
     Running `make install' with a different value of `exec_prefix'
3157
     from the one used to build the program should NOT recompile the
3158
     program.
3159
 
3160
   Executable programs are installed in one of the following
3161
directories.
3162
 
3163
`bindir'
3164
     The directory for installing executable programs that users can
3165
     run.  This should normally be `/usr/local/bin', but write it as
3166
     `$(exec_prefix)/bin'.  (If you are using Autoconf, write it as
3167
     `@bindir@'.)
3168
 
3169
`sbindir'
3170
     The directory for installing executable programs that can be run
3171
     from the shell, but are only generally useful to system
3172
     administrators.  This should normally be `/usr/local/sbin', but
3173
     write it as `$(exec_prefix)/sbin'.  (If you are using Autoconf,
3174
     write it as `@sbindir@'.)
3175
 
3176
`libexecdir'
3177
     The directory for installing executable programs to be run by other
3178
     programs rather than by users.  This directory should normally be
3179
     `/usr/local/libexec', but write it as `$(exec_prefix)/libexec'.
3180
     (If you are using Autoconf, write it as `@libexecdir@'.)
3181
 
3182
   Data files used by the program during its execution are divided into
3183
categories in two ways.
3184
 
3185
   * Some files are normally modified by programs; others are never
3186
     normally modified (though users may edit some of these).
3187
 
3188
   * Some files are architecture-independent and can be shared by all
3189
     machines at a site; some are architecture-dependent and can be
3190
     shared only by machines of the same kind and operating system;
3191
     others may never be shared between two machines.
3192
 
3193
   This makes for six different possibilities.  However, we want to
3194
discourage the use of architecture-dependent files, aside from object
3195
files and libraries.  It is much cleaner to make other data files
3196
architecture-independent, and it is generally not hard.
3197
 
3198
   Therefore, here are the variables Makefiles should use to specify
3199
directories:
3200
 
3201
`datadir'
3202
     The directory for installing read-only architecture independent
3203
     data files.  This should normally be `/usr/local/share', but write
3204
     it as `$(prefix)/share'.  (If you are using Autoconf, write it as
3205 56 joel
     `@datadir@'.)  As a special exception, see `$(infodir)' and
3206 39 lampret
     `$(includedir)' below.
3207
 
3208
`sysconfdir'
3209
     The directory for installing read-only data files that pertain to a
3210
     single machine-that is to say, files for configuring a host.
3211
     Mailer and network configuration files, `/etc/passwd', and so
3212
     forth belong here.  All the files in this directory should be
3213
     ordinary ASCII text files.  This directory should normally be
3214
     `/usr/local/etc', but write it as `$(prefix)/etc'.  (If you are
3215
     using Autoconf, write it as `@sysconfdir@'.)
3216
 
3217
     Do not install executables here in this directory (they probably
3218
     belong in `$(libexecdir)' or `$(sbindir)').  Also do not install
3219
     files that are modified in the normal course of their use (programs
3220
     whose purpose is to change the configuration of the system
3221
     excluded).  Those probably belong in `$(localstatedir)'.
3222
 
3223
`sharedstatedir'
3224
     The directory for installing architecture-independent data files
3225
     which the programs modify while they run.  This should normally be
3226
     `/usr/local/com', but write it as `$(prefix)/com'.  (If you are
3227
     using Autoconf, write it as `@sharedstatedir@'.)
3228
 
3229
`localstatedir'
3230
     The directory for installing data files which the programs modify
3231
     while they run, and that pertain to one specific machine.  Users
3232
     should never need to modify files in this directory to configure
3233
     the package's operation; put such configuration information in
3234
     separate files that go in `$(datadir)' or `$(sysconfdir)'.
3235
     `$(localstatedir)' should normally be `/usr/local/var', but write
3236
     it as `$(prefix)/var'.  (If you are using Autoconf, write it as
3237
     `@localstatedir@'.)
3238
 
3239
`libdir'
3240
     The directory for object files and libraries of object code.  Do
3241
     not install executables here, they probably ought to go in
3242
     `$(libexecdir)' instead.  The value of `libdir' should normally be
3243
     `/usr/local/lib', but write it as `$(exec_prefix)/lib'.  (If you
3244
     are using Autoconf, write it as `@libdir@'.)
3245
 
3246
`infodir'
3247
     The directory for installing the Info files for this package.  By
3248
     default, it should be `/usr/local/info', but it should be written
3249
     as `$(prefix)/info'.  (If you are using Autoconf, write it as
3250
     `@infodir@'.)
3251
 
3252
`lispdir'
3253
     The directory for installing any Emacs Lisp files in this package.
3254
     By default, it should be `/usr/local/share/emacs/site-lisp', but
3255
     it should be written as `$(prefix)/share/emacs/site-lisp'.
3256
 
3257
     If you are using Autoconf, write the default as `@lispdir@'.  In
3258
     order to make `@lispdir@' work, you need the following lines in
3259
     your `configure.in' file:
3260
 
3261
          lispdir='${datadir}/emacs/site-lisp'
3262
          AC_SUBST(lispdir)
3263
 
3264
`includedir'
3265
     The directory for installing header files to be included by user
3266
     programs with the C `#include' preprocessor directive.  This
3267
     should normally be `/usr/local/include', but write it as
3268
     `$(prefix)/include'.  (If you are using Autoconf, write it as
3269
     `@includedir@'.)
3270
 
3271
     Most compilers other than GCC do not look for header files in
3272
     directory `/usr/local/include'.  So installing the header files
3273
     this way is only useful with GCC.  Sometimes this is not a problem
3274
     because some libraries are only really intended to work with GCC.
3275
     But some libraries are intended to work with other compilers.
3276
     They should install their header files in two places, one
3277
     specified by `includedir' and one specified by `oldincludedir'.
3278
 
3279
`oldincludedir'
3280
     The directory for installing `#include' header files for use with
3281
     compilers other than GCC.  This should normally be `/usr/include'.
3282
     (If you are using Autoconf, you can write it as `@oldincludedir@'.)
3283
 
3284
     The Makefile commands should check whether the value of
3285
     `oldincludedir' is empty.  If it is, they should not try to use
3286
     it; they should cancel the second installation of the header files.
3287
 
3288
     A package should not replace an existing header in this directory
3289
     unless the header came from the same package.  Thus, if your Foo
3290
     package provides a header file `foo.h', then it should install the
3291
     header file in the `oldincludedir' directory if either (1) there
3292
     is no `foo.h' there or (2) the `foo.h' that exists came from the
3293
     Foo package.
3294
 
3295
     To tell whether `foo.h' came from the Foo package, put a magic
3296
     string in the file--part of a comment--and `grep' for that string.
3297
 
3298
   Unix-style man pages are installed in one of the following:
3299
 
3300
`mandir'
3301
     The top-level directory for installing the man pages (if any) for
3302
     this package.  It will normally be `/usr/local/man', but you should
3303
     write it as `$(prefix)/man'.  (If you are using Autoconf, write it
3304
     as `@mandir@'.)
3305
 
3306
`man1dir'
3307
     The directory for installing section 1 man pages.  Write it as
3308
     `$(mandir)/man1'.
3309
 
3310
`man2dir'
3311
     The directory for installing section 2 man pages.  Write it as
3312
     `$(mandir)/man2'
3313
 
3314
`...'
3315
     *Don't make the primary documentation for any GNU software be a
3316
     man page.  Write a manual in Texinfo instead.  Man pages are just
3317
     for the sake of people running GNU software on Unix, which is a
3318
     secondary application only.*
3319
 
3320
`manext'
3321
     The file name extension for the installed man page.  This should
3322
     contain a period followed by the appropriate digit; it should
3323
     normally be `.1'.
3324
 
3325
`man1ext'
3326
     The file name extension for installed section 1 man pages.
3327
 
3328
`man2ext'
3329
     The file name extension for installed section 2 man pages.
3330
 
3331
`...'
3332
     Use these names instead of `manext' if the package needs to
3333
     install man pages in more than one section of the manual.
3334
 
3335
   And finally, you should set the following variable:
3336
 
3337
`srcdir'
3338
     The directory for the sources being compiled.  The value of this
3339
     variable is normally inserted by the `configure' shell script.
3340
     (If you are using Autconf, use `srcdir = @srcdir@'.)
3341
 
3342
   For example:
3343
 
3344
     # Common prefix for installation directories.
3345
     # NOTE: This directory must exist when you start the install.
3346
     prefix = /usr/local
3347
     exec_prefix = $(prefix)
3348
     # Where to put the executable for the command `gcc'.
3349
     bindir = $(exec_prefix)/bin
3350
     # Where to put the directories used by the compiler.
3351
     libexecdir = $(exec_prefix)/libexec
3352
     # Where to put the Info files.
3353
     infodir = $(prefix)/info
3354
 
3355
   If your program installs a large number of files into one of the
3356
standard user-specified directories, it might be useful to group them
3357
into a subdirectory particular to that program.  If you do this, you
3358
should write the `install' rule to create these subdirectories.
3359
 
3360
   Do not expect the user to include the subdirectory name in the value
3361
of any of the variables listed above.  The idea of having a uniform set
3362
of variable names for installation directories is to enable the user to
3363
specify the exact same values for several different GNU packages.  In
3364
order for this to be useful, all the packages must be designed so that
3365
they will work sensibly when the user does so.
3366
 
3367

3368
File: standards.info,  Node: Standard Targets,  Next: Install Command Categories,  Prev: Directory Variables,  Up: Makefile Conventions
3369
 
3370
Standard Targets for Users
3371
--------------------------
3372
 
3373
   All GNU programs should have the following targets in their
3374
Makefiles:
3375
 
3376
`all'
3377
     Compile the entire program.  This should be the default target.
3378
     This target need not rebuild any documentation files; Info files
3379
     should normally be included in the distribution, and DVI files
3380
     should be made only when explicitly asked for.
3381
 
3382
     By default, the Make rules should compile and link with `-g', so
3383
     that executable programs have debugging symbols.  Users who don't
3384
     mind being helpless can strip the executables later if they wish.
3385
 
3386
`install'
3387
     Compile the program and copy the executables, libraries, and so on
3388
     to the file names where they should reside for actual use.  If
3389
     there is a simple test to verify that a program is properly
3390
     installed, this target should run that test.
3391
 
3392
     Do not strip executables when installing them.  Devil-may-care
3393
     users can use the `install-strip' target to do that.
3394
 
3395
     If possible, write the `install' target rule so that it does not
3396
     modify anything in the directory where the program was built,
3397
     provided `make all' has just been done.  This is convenient for
3398
     building the program under one user name and installing it under
3399
     another.
3400
 
3401
     The commands should create all the directories in which files are
3402
     to be installed, if they don't already exist.  This includes the
3403
     directories specified as the values of the variables `prefix' and
3404
     `exec_prefix', as well as all subdirectories that are needed.  One
3405
     way to do this is by means of an `installdirs' target as described
3406
     below.
3407
 
3408
     Use `-' before any command for installing a man page, so that
3409
     `make' will ignore any errors.  This is in case there are systems
3410
     that don't have the Unix man page documentation system installed.
3411
 
3412
     The way to install Info files is to copy them into `$(infodir)'
3413
     with `$(INSTALL_DATA)' (*note Command Variables::.), and then run
3414
     the `install-info' program if it is present.  `install-info' is a
3415
     program that edits the Info `dir' file to add or update the menu
3416
     entry for the given Info file; it is part of the Texinfo package.
3417
     Here is a sample rule to install an Info file:
3418
 
3419
          $(DESTDIR)$(infodir)/foo.info: foo.info
3420
                  $(POST_INSTALL)
3421
          # There may be a newer info file in . than in srcdir.
3422
                  -if test -f foo.info; then d=.; \
3423
                   else d=$(srcdir); fi; \
3424
                  $(INSTALL_DATA) $$d/foo.info $(DESTDIR)$@; \
3425
          # Run install-info only if it exists.
3426
          # Use `if' instead of just prepending `-' to the
3427
          # line so we notice real errors from install-info.
3428
          # We use `$(SHELL) -c' because some shells do not
3429
          # fail gracefully when there is an unknown command.
3430
                  if $(SHELL) -c 'install-info --version' \
3431
                     >/dev/null 2>&1; then \
3432
                    install-info --dir-file=$(DESTDIR)$(infodir)/dir \
3433
                                 $(DESTDIR)$(infodir)/foo.info; \
3434
                  else true; fi
3435
 
3436
     When writing the `install' target, you must classify all the
3437
     commands into three categories: normal ones, "pre-installation"
3438
     commands and "post-installation" commands.  *Note Install Command
3439
     Categories::.
3440
 
3441
`uninstall'
3442
     Delete all the installed files--the copies that the `install'
3443
     target creates.
3444
 
3445
     This rule should not modify the directories where compilation is
3446
     done, only the directories where files are installed.
3447
 
3448
     The uninstallation commands are divided into three categories,
3449
     just like the installation commands.  *Note Install Command
3450
     Categories::.
3451
 
3452
`install-strip'
3453
     Like `install', but strip the executable files while installing
3454
     them.  In many cases, the definition of this target can be very
3455
     simple:
3456
 
3457
          install-strip:
3458
                  $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
3459
                          install
3460
 
3461
     Normally we do not recommend stripping an executable unless you
3462
     are sure the program has no bugs.  However, it can be reasonable
3463
     to install a stripped executable for actual execution while saving
3464
     the unstripped executable elsewhere in case there is a bug.
3465
 
3466
`clean'
3467
     Delete all files from the current directory that are normally
3468
     created by building the program.  Don't delete the files that
3469
     record the configuration.  Also preserve files that could be made
3470
     by building, but normally aren't because the distribution comes
3471
     with them.
3472
 
3473
     Delete `.dvi' files here if they are not part of the distribution.
3474
 
3475
`distclean'
3476
     Delete all files from the current directory that are created by
3477
     configuring or building the program.  If you have unpacked the
3478
     source and built the program without creating any other files,
3479
     `make distclean' should leave only the files that were in the
3480
     distribution.
3481
 
3482
`mostlyclean'
3483
     Like `clean', but may refrain from deleting a few files that people
3484
     normally don't want to recompile.  For example, the `mostlyclean'
3485
     target for GCC does not delete `libgcc.a', because recompiling it
3486
     is rarely necessary and takes a lot of time.
3487
 
3488
`maintainer-clean'
3489
     Delete almost everything from the current directory that can be
3490
     reconstructed with this Makefile.  This typically includes
3491
     everything deleted by `distclean', plus more: C source files
3492
     produced by Bison, tags tables, Info files, and so on.
3493
 
3494
     The reason we say "almost everything" is that running the command
3495
     `make maintainer-clean' should not delete `configure' even if
3496
     `configure' can be remade using a rule in the Makefile.  More
3497
     generally, `make maintainer-clean' should not delete anything that
3498
     needs to exist in order to run `configure' and then begin to build
3499
     the program.  This is the only exception; `maintainer-clean' should
3500
     delete everything else that can be rebuilt.
3501
 
3502
     The `maintainer-clean' target is intended to be used by a
3503
     maintainer of the package, not by ordinary users.  You may need
3504
     special tools to reconstruct some of the files that `make
3505
     maintainer-clean' deletes.  Since these files are normally
3506
     included in the distribution, we don't take care to make them easy
3507
     to reconstruct.  If you find you need to unpack the full
3508
     distribution again, don't blame us.
3509
 
3510
     To help make users aware of this, the commands for the special
3511
     `maintainer-clean' target should start with these two:
3512
 
3513
          @echo 'This command is intended for maintainers to use; it'
3514
          @echo 'deletes files that may need special tools to rebuild.'
3515
 
3516
`TAGS'
3517
     Update a tags table for this program.
3518
 
3519
`info'
3520
     Generate any Info files needed.  The best way to write the rules
3521
     is as follows:
3522
 
3523
          info: foo.info
3524
 
3525
          foo.info: foo.texi chap1.texi chap2.texi
3526
                  $(MAKEINFO) $(srcdir)/foo.texi
3527
 
3528
     You must define the variable `MAKEINFO' in the Makefile.  It should
3529
     run the `makeinfo' program, which is part of the Texinfo
3530
     distribution.
3531
 
3532
     Normally a GNU distribution comes with Info files, and that means
3533
     the Info files are present in the source directory.  Therefore,
3534
     the Make rule for an info file should update it in the source
3535
     directory.  When users build the package, ordinarily Make will not
3536
     update the Info files because they will already be up to date.
3537
 
3538
`dvi'
3539
     Generate DVI files for all Texinfo documentation.  For example:
3540
 
3541
          dvi: foo.dvi
3542
 
3543
          foo.dvi: foo.texi chap1.texi chap2.texi
3544
                  $(TEXI2DVI) $(srcdir)/foo.texi
3545
 
3546
     You must define the variable `TEXI2DVI' in the Makefile.  It should
3547
     run the program `texi2dvi', which is part of the Texinfo
3548
     distribution.(1)  Alternatively, write just the dependencies, and
3549
     allow GNU `make' to provide the command.
3550
 
3551
`dist'
3552
     Create a distribution tar file for this program.  The tar file
3553
     should be set up so that the file names in the tar file start with
3554
     a subdirectory name which is the name of the package it is a
3555
     distribution for.  This name can include the version number.
3556
 
3557
     For example, the distribution tar file of GCC version 1.40 unpacks
3558
     into a subdirectory named `gcc-1.40'.
3559
 
3560
     The easiest way to do this is to create a subdirectory
3561
     appropriately named, use `ln' or `cp' to install the proper files
3562
     in it, and then `tar' that subdirectory.
3563
 
3564
     Compress the tar file file with `gzip'.  For example, the actual
3565
     distribution file for GCC version 1.40 is called `gcc-1.40.tar.gz'.
3566
 
3567
     The `dist' target should explicitly depend on all non-source files
3568
     that are in the distribution, to make sure they are up to date in
3569
     the distribution.  *Note Making Releases: Releases.
3570
 
3571
`check'
3572
     Perform self-tests (if any).  The user must build the program
3573
     before running the tests, but need not install the program; you
3574
     should write the self-tests so that they work when the program is
3575
     built but not installed.
3576
 
3577
   The following targets are suggested as conventional names, for
3578
programs in which they are useful.
3579
 
3580
`installcheck'
3581
     Perform installation tests (if any).  The user must build and
3582
     install the program before running the tests.  You should not
3583
     assume that `$(bindir)' is in the search path.
3584
 
3585
`installdirs'
3586
     It's useful to add a target named `installdirs' to create the
3587
     directories where files are installed, and their parent
3588
     directories.  There is a script called `mkinstalldirs' which is
3589
     convenient for this; you can find it in the Texinfo package.  You
3590
     can use a rule like this:
3591
 
3592
          # Make sure all installation directories (e.g. $(bindir))
3593
          # actually exist by making them if necessary.
3594
          installdirs: mkinstalldirs
3595
                  $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
3596
                                          $(libdir) $(infodir) \
3597
                                          $(mandir)
3598
 
3599
     This rule should not modify the directories where compilation is
3600
     done.  It should do nothing but create installation directories.
3601
 
3602
   ---------- Footnotes ----------
3603
 
3604 56 joel
   (1) `texi2dvi' uses TeX to do the real work of formatting. TeX is
3605 39 lampret
not distributed with Texinfo.
3606
 
3607

3608
File: standards.info,  Node: Install Command Categories,  Prev: Standard Targets,  Up: Makefile Conventions
3609
 
3610
Install Command Categories
3611
--------------------------
3612
 
3613
   When writing the `install' target, you must classify all the
3614
commands into three categories: normal ones, "pre-installation"
3615
commands and "post-installation" commands.
3616
 
3617
   Normal commands move files into their proper places, and set their
3618
modes.  They may not alter any files except the ones that come entirely
3619
from the package they belong to.
3620
 
3621
   Pre-installation and post-installation commands may alter other
3622
files; in particular, they can edit global configuration files or data
3623
bases.
3624
 
3625
   Pre-installation commands are typically executed before the normal
3626
commands, and post-installation commands are typically run after the
3627
normal commands.
3628
 
3629
   The most common use for a post-installation command is to run
3630
`install-info'.  This cannot be done with a normal command, since it
3631
alters a file (the Info directory) which does not come entirely and
3632
solely from the package being installed.  It is a post-installation
3633
command because it needs to be done after the normal command which
3634
installs the package's Info files.
3635
 
3636
   Most programs don't need any pre-installation commands, but we have
3637
the feature just in case it is needed.
3638
 
3639
   To classify the commands in the `install' rule into these three
3640
categories, insert "category lines" among them.  A category line
3641
specifies the category for the commands that follow.
3642
 
3643
   A category line consists of a tab and a reference to a special Make
3644
variable, plus an optional comment at the end.  There are three
3645
variables you can use, one for each category; the variable name
3646
specifies the category.  Category lines are no-ops in ordinary execution
3647
because these three Make variables are normally undefined (and you
3648 56 joel
_should not_ define them in the makefile).
3649 39 lampret
 
3650
   Here are the three possible category lines, each with a comment that
3651
explains what it means:
3652
 
3653
             $(PRE_INSTALL)     # Pre-install commands follow.
3654
             $(POST_INSTALL)    # Post-install commands follow.
3655
             $(NORMAL_INSTALL)  # Normal commands follow.
3656
 
3657
   If you don't use a category line at the beginning of the `install'
3658
rule, all the commands are classified as normal until the first category
3659
line.  If you don't use any category lines, all the commands are
3660
classified as normal.
3661
 
3662
   These are the category lines for `uninstall':
3663
 
3664
             $(PRE_UNINSTALL)     # Pre-uninstall commands follow.
3665
             $(POST_UNINSTALL)    # Post-uninstall commands follow.
3666
             $(NORMAL_UNINSTALL)  # Normal commands follow.
3667
 
3668
   Typically, a pre-uninstall command would be used for deleting entries
3669
from the Info directory.
3670
 
3671
   If the `install' or `uninstall' target has any dependencies which
3672 56 joel
act as subroutines of installation, then you should start _each_
3673 39 lampret
dependency's commands with a category line, and start the main target's
3674
commands with a category line also.  This way, you can ensure that each
3675
command is placed in the right category regardless of which of the
3676
dependencies actually run.
3677
 
3678
   Pre-installation and post-installation commands should not run any
3679
programs except for these:
3680
 
3681
     [ basename bash cat chgrp chmod chown cmp cp dd diff echo
3682
     egrep expand expr false fgrep find getopt grep gunzip gzip
3683
     hostname install install-info kill ldconfig ln ls md5sum
3684
     mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
3685
     test touch true uname xargs yes
3686
 
3687
   The reason for distinguishing the commands in this way is for the
3688
sake of making binary packages.  Typically a binary package contains
3689
all the executables and other files that need to be installed, and has
3690
its own method of installing them--so it does not need to run the normal
3691
installation commands.  But installing the binary package does need to
3692
execute the pre-installation and post-installation commands.
3693
 
3694
   Programs to build binary packages work by extracting the
3695
pre-installation and post-installation commands.  Here is one way of
3696
extracting the pre-installation commands:
3697
 
3698
     make -n install -o all \
3699
           PRE_INSTALL=pre-install \
3700
           POST_INSTALL=post-install \
3701
           NORMAL_INSTALL=normal-install \
3702
       | gawk -f pre-install.awk
3703
 
3704
where the file `pre-install.awk' could contain this:
3705
 
3706
     $0 ~ /^\t[ \t]*(normal_install|post_install)[ \t]*$/ {on = 0}
3707
     on {print $0}
3708
     $0 ~ /^\t[ \t]*pre_install[ \t]*$/ {on = 1}
3709
 
3710
   The resulting file of pre-installation commands is executed as a
3711
shell script as part of installing the binary package.
3712
 
3713

3714
File: standards.info,  Node: Releases,  Prev: Makefile Conventions,  Up: Managing Releases
3715
 
3716
Making Releases
3717
===============
3718
 
3719
   Package the distribution of `Foo version 69.96' up in a gzipped tar
3720
file with the name `foo-69.96.tar.gz'.  It should unpack into a
3721
subdirectory named `foo-69.96'.
3722
 
3723
   Building and installing the program should never modify any of the
3724
files contained in the distribution.  This means that all the files
3725
that form part of the program in any way must be classified into "source
3726
files" and "non-source files".  Source files are written by humans and
3727
never changed automatically; non-source files are produced from source
3728
files by programs under the control of the Makefile.
3729
 
3730
   Naturally, all the source files must be in the distribution.  It is
3731
okay to include non-source files in the distribution, provided they are
3732
up-to-date and machine-independent, so that building the distribution
3733
normally will never modify them.  We commonly include non-source files
3734
produced by Bison, `lex', TeX, and `makeinfo'; this helps avoid
3735
unnecessary dependencies between our distributions, so that users can
3736
install whichever packages they want to install.
3737
 
3738
   Non-source files that might actually be modified by building and
3739
installing the program should *never* be included in the distribution.
3740
So if you do distribute non-source files, always make sure they are up
3741
to date when you make a new distribution.
3742
 
3743
   Make sure that the directory into which the distribution unpacks (as
3744
well as any subdirectories) are all world-writable (octal mode 777).
3745
This is so that old versions of `tar' which preserve the ownership and
3746
permissions of the files from the tar archive will be able to extract
3747
all the files even if the user is unprivileged.
3748
 
3749
   Make sure that all the files in the distribution are world-readable.
3750
 
3751
   Make sure that no file name in the distribution is more than 14
3752
characters long.  Likewise, no file created by building the program
3753
should have a name longer than 14 characters.  The reason for this is
3754
that some systems adhere to a foolish interpretation of the POSIX
3755
standard, and refuse to open a longer name, rather than truncating as
3756
they did in the past.
3757
 
3758
   Don't include any symbolic links in the distribution itself.  If the
3759
tar file contains symbolic links, then people cannot even unpack it on
3760
systems that don't support symbolic links.  Also, don't use multiple
3761
names for one file in different directories, because certain file
3762
systems cannot handle this and that prevents unpacking the distribution.
3763
 
3764
   Try to make sure that all the file names will be unique on MS-DOS.  A
3765
name on MS-DOS consists of up to 8 characters, optionally followed by a
3766
period and up to three characters.  MS-DOS will truncate extra
3767
characters both before and after the period.  Thus, `foobarhacker.c'
3768
and `foobarhacker.o' are not ambiguous; they are truncated to
3769
`foobarha.c' and `foobarha.o', which are distinct.
3770
 
3771
   Include in your distribution a copy of the `texinfo.tex' you used to
3772
test print any `*.texinfo' or `*.texi' files.
3773
 
3774
   Likewise, if your program uses small GNU software packages like
3775
regex, getopt, obstack, or termcap, include them in the distribution
3776
file.  Leaving them out would make the distribution file a little
3777
smaller at the expense of possible inconvenience to a user who doesn't
3778
know what other files to get.
3779
 
3780
 
3781

3782
Tag Table:
3783 56 joel
Node: Top964
3784
Node: Preface1507
3785
Node: Intellectual Property2534
3786
Node: Reading Non-Free Code2909
3787
Node: Contributions4641
3788
Node: Design Advice6635
3789
Node: Compatibility7152
3790
Node: Using Extensions8663
3791
Node: ANSI C10165
3792
Node: Source Language11401
3793
Node: Program Behavior12894
3794
Node: Semantics13603
3795
Node: Libraries17357
3796
Node: Errors18592
3797
Node: User Interfaces19815
3798
Node: Option Table26562
3799
Node: Memory Usage40651
3800
Node: Writing C41645
3801
Node: Formatting42486
3802
Node: Comments45758
3803
Node: Syntactic Conventions49056
3804
Node: Names51994
3805
Node: System Portability53730
3806
Node: CPU Portability55506
3807
Node: System Functions57667
3808
Node: Internationalization62771
3809
Node: Mmap65919
3810
Node: Documentation66624
3811
Node: GNU Manuals67182
3812
Node: Manual Structure Details71069
3813
Node: NEWS File72399
3814
Node: Change Logs73080
3815
Node: Change Log Concepts73797
3816
Node: Style of Change Logs75565
3817
Node: Simple Changes77119
3818
Node: Conditional Changes78310
3819
Node: Man Pages79687
3820
Node: Reading other Manuals81306
3821
Node: Managing Releases82090
3822
Node: Configuration82826
3823
Node: Makefile Conventions89766
3824
Node: Makefile Basics90446
3825
Node: Utilities in Makefiles93615
3826
Node: Command Variables95751
3827
Node: Directory Variables99252
3828
Node: Standard Targets110129
3829
Node: Install Command Categories120669
3830
Node: Releases125242
3831 39 lampret

3832
End Tag Table

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.