Debian Codegraph @

doc/standards.texi

raw
1 \input texinfo @c -*-texinfo-*-
2 @c %**start of header
3 @setfilename standards.info
4 @settitle GNU Coding Standards
5 @c This date is automagically updated when you save this file:
6 @set lastupdate July 5, 2025
7 @c %**end of header
8
9 @dircategory GNU organization
10 @direntry
11 * Standards: (standards). GNU coding standards.
12 @end direntry
13
14 @c @setchapternewpage odd
15 @setchapternewpage off
16
17 @c Put everything in one index (arbitrarily chosen to be the concept index).
18 @syncodeindex fn cp
19 @syncodeindex ky cp
20 @syncodeindex pg cp
21 @syncodeindex vr cp
22
23 @c This is used by a cross ref in make-stds.texi
24 @set CODESTD 1
25
26 @copying
27 The GNU coding standards, last updated @value{lastupdate}.
28
29 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
30 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
31 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 Free
32 Software Foundation, Inc.
33
34 Permission is granted to copy, distribute and/or modify this document
35 under the terms of the GNU Free Documentation License, Version 1.3 or
36 any later version published by the Free Software Foundation; with no
37 Invariant Sections, no Front-Cover Texts, and no Back-Cover
38 Texts. A copy of the license is included in the section entitled
39 ``GNU Free Documentation License''.
40 @end copying
41
42 @titlepage
43 @title GNU Coding Standards
44 @author Richard Stallman, et al.
45 @author last updated @value{lastupdate}
46 @page
47 @vskip 0pt plus 1filll
48 @insertcopying
49 @end titlepage
50
51 @contents
52
53 @ifnottex
54 @node Top
55 @top GNU Coding Standards
56
57 @insertcopying
58 @end ifnottex
59
60 @menu
61 * Preface:: About the GNU Coding Standards.
62 * Legal Issues:: Keeping free software free.
63 * Design Advice:: General program design.
64 * Program Behavior:: Program behavior for all programs
65 * Writing C:: Making the best use of C.
66 * Documentation:: Documenting programs.
67 * Managing Releases:: The release process.
68 * References:: Mentioning nonfree software or documentation.
69 * GNU Free Documentation License:: Copying and sharing this manual.
70 * Index::
71
72 @end menu
73
74 @node Preface
75 @chapter About the GNU Coding Standards
76
77 The GNU Coding Standards were written by Richard Stallman and other GNU
78 Project volunteers. Their purpose is to make the GNU system clean,
79 consistent, and easy to install. This document can also be read as a
80 guide to writing portable, robust and reliable programs. It focuses on
81 programs written in C, but many of the rules and principles are useful
82 even if you write in another programming language. The rules often
83 state reasons for writing in a certain way.
84
85 @cindex where to obtain @code{standards.texi}
86 @cindex downloading this manual
87 If you did not obtain this file directly from the GNU project and
88 recently, please check for a newer version. You can get the GNU
89 Coding Standards from the GNU web server in many
90 different formats, including the Texinfo source, PDF, HTML, plain
91 text, and more, at: @uref{https://www.gnu.org/prep/standards/}.
92
93 If you are maintaining an official GNU package, in addition to this
94 document, please read and follow the GNU maintainer information
95 (@pxref{Top, , Contents, maintain, Information for Maintainers of GNU
96 Software}).
97
98 @cindex @code{gnustandards-commit@@gnu.org} mailing list
99 If you want to receive diffs for every change to these GNU documents,
100 join the mailing list @code{gnustandards-commit@@gnu.org}, via the web
101 interface at
102 @url{https://lists.gnu.org/mailman/listinfo/gnustandards-commit}.
103 Archives are also available there.
104
105 @cindex @code{bug-standards@@gnu.org} email address
106 @cindex Savannah repository for gnustandards
107 @cindex gnustandards project repository
108 Please send corrections or suggestions for this document to
109 @email{bug-standards@@gnu.org}. If you make a suggestion, please
110 include a suggested new wording for it, to help us consider the
111 suggestion efficiently. We prefer a context diff to the Texinfo
112 source, but if that's difficult for you, you can make a context diff
113 for some other version of this document, or propose it in any way that
114 makes it clear. The source repository for this document can be found
115 at @url{https://savannah.gnu.org/projects/gnustandards}.
116
117 These standards cover the minimum of what is important when writing a
118 GNU package. Likely, the need for additional standards will come up.
119 Sometimes, you might suggest that such standards be added to this
120 document. If you think your standards would be generally useful, please
121 do suggest them.
122
123 You should also set standards for your package on many questions not
124 addressed or not firmly specified here. The most important point is to
125 be self-consistent---try to stick to the conventions you pick, and try
126 to document them as much as possible. That way, your program will be
127 more maintainable by others.
128
129 The GNU Hello program serves as an example of how to follow the GNU
130 coding standards for a trivial program.
131 @uref{https://www.gnu.org/software/hello/hello.html}.
132
133 This release of the GNU Coding Standards was last updated
134 @value{lastupdate}.
135
136
137 @node Legal Issues
138 @chapter Keeping Free Software Free
139 @cindex legal aspects
140
141 This chapter discusses how you can make sure that GNU software
142 avoids legal difficulties, and other related issues.
143
144 @menu
145 * Reading Nonfree Code:: Referring to proprietary programs.
146 * Contributions:: Accepting contributions.
147 * Trademarks:: How we deal with trademark issues.
148 * Terms to Avoid:: Be careful of certain words!
149 @end menu
150
151 @node Reading Nonfree Code
152 @section Referring to Proprietary Programs
153 @cindex proprietary programs
154 @cindex avoiding proprietary code
155
156 Don't in any circumstances refer to Unix source code for or during
157 your work on GNU! (Or to any other proprietary programs.)
158
159 If you have a vague recollection of the internals of a Unix program,
160 this does not absolutely mean you can't write an imitation of it, but
161 do try to organize the imitation internally along different lines,
162 because this is likely to make the details of the Unix version
163 irrelevant and dissimilar to your results.
164
165 For example, Unix utilities were generally optimized to minimize
166 memory use; if you go for speed instead, your program will be very
167 different. You could keep the entire input file in memory and scan it
168 there instead of using stdio. Use a smarter algorithm discovered more
169 recently than the Unix program. Eliminate use of temporary files. Do
170 it in one pass instead of two (we did this in the assembler).
171
172 Or, on the contrary, emphasize simplicity instead of speed. For some
173 applications, the speed of today's computers makes simpler algorithms
174 adequate.
175
176 Or go for generality. For example, Unix programs often have static
177 tables or fixed-size strings, which make for arbitrary limits; use
178 dynamic allocation instead. Make sure your program handles NULs and
179 other funny characters in the input files. Add a programming language
180 for extensibility and write part of the program in that language.
181
182 Or turn some parts of the program into independently usable libraries.
183 Or use a simple garbage collector instead of tracking precisely when
184 to free memory, or use a new GNU facility such as obstacks.
185
186
187 @node Contributions
188 @section Accepting Contributions
189 @cindex legal papers
190 @cindex accepting contributions
191
192 If the program you are working on is copyrighted by the Free Software
193 Foundation, then when someone else sends you a piece of code to add to
194 the program, we need legal papers to use it---just as we asked you to
195 sign papers initially. @emph{Each} person who makes a nontrivial
196 contribution to a program must sign some sort of legal papers in order
197 for us to have clear title to the program; the main author alone is not
198 enough.
199
200 So, before adding in any contributions from other people, please tell
201 us, so we can arrange to get the papers. Then wait until we tell you
202 that we have received the signed papers, before you actually use the
203 contribution.
204
205 This applies both before you release the program and afterward. If
206 you receive diffs to fix a bug, and they make significant changes, we
207 need legal papers for that change.
208
209 This also applies to comments and documentation files. For copyright
210 law, comments and code are just text. Copyright applies to all kinds of
211 text, so we need legal papers for all kinds.
212
213 We know it is frustrating to ask for legal papers; it's frustrating for
214 us as well. But if you don't wait, you are going out on a limb---for
215 example, what if the contributor's employer won't sign a disclaimer?
216 You might have to take that code out again!
217
218 You don't need papers for changes of a few lines here or there, since
219 they are not significant for copyright purposes. Also, you don't need
220 papers if all you get from the suggestion is some ideas, not actual code
221 which you use. For example, if someone sent you one implementation, but
222 you write a different implementation of the same idea, you don't need to
223 get papers.
224
225 The very worst thing is if you forget to tell us about the other
226 contributor. We could be very embarrassed in court some day as a
227 result.
228
229 We have more detailed advice for maintainers of GNU packages. If you
230 have reached the stage of maintaining a GNU program (whether released
231 or not), please take a look: @pxref{Legal Matters,,, maintain,
232 Information for GNU Maintainers}.
233
234
235 @node Trademarks
236 @section Trademarks
237 @cindex trademarks
238
239 Please do not include any trademark acknowledgments in GNU software
240 packages or documentation.
241
242 Trademark acknowledgments are the statements that such-and-such is a
243 trademark of so-and-so. The GNU Project has no objection to the basic
244 idea of trademarks, but these acknowledgments feel like kowtowing,
245 and there is no legal requirement for them, so we don't use them.
246
247 What is legally required, as regards other people's trademarks, is to
248 avoid using them in ways which a reader might reasonably understand as
249 naming or labeling our own programs or activities. For example, since
250 ``Objective C'' is (or at least was) a trademark, we made sure to say
251 that we provide a ``compiler for the Objective C language'' rather
252 than an ``Objective C compiler''. The latter would have been meant as
253 a shorter way of saying the former, but it does not explicitly state
254 the relationship, so it could be misinterpreted as using ``Objective
255 C'' as a label for the compiler rather than for the language.
256
257 Please don't use ``win'' as an abbreviation for Microsoft Windows in
258 GNU software or documentation. In hacker terminology, calling
259 something a ``win'' is a form of praise. You're free to praise
260 Microsoft Windows on your own if you want, but please don't do so in
261 GNU packages. Please write ``Windows'' in full, or abbreviate it to
262 ``w.'' @xref{System Portability}.
263
264 @node Terms to Avoid
265 @section Terms to Avoid
266
267 Be careful---never use the word ``steward'' to refer to any person
268 involved with developing any free software! An EU directive, the CRA,
269 gives that word a specific legal meaning which imposes requirements
270 that are painful or even impossible.
271
272 @node Design Advice
273 @chapter General Program Design
274 @cindex program design
275
276 This chapter discusses some of the issues you should take into
277 account when designing your program.
278
279 @c Standard or ANSI C
280 @c
281 @c In 1989 the American National Standards Institute (ANSI) standardized
282 @c C as standard X3.159-1989. In December of that year the
283 @c International Standards Organization ISO adopted the ANSI C standard
284 @c making minor changes. In 1990 ANSI then re-adopted ISO standard
285 @c C. This version of C is known as either ANSI C or Standard C.
286
287 @c A major revision of the C Standard appeared in 1999.
288
289 @menu
290 * Source Language:: Which languages to use.
291 * Compatibility:: Compatibility with other implementations.
292 * Using Extensions:: Using non-standard features.
293 * Standard C:: Using standard C features.
294 * Conditional Compilation:: Compiling code only if a conditional is true.
295 @end menu
296
297 @node Source Language
298 @section Which Languages to Use
299 @cindex programming languages
300
301 When you want to use a language that gets compiled and runs at high
302 speed, the best language to use is C@. C++ is ok too, but please don't
303 make heavy use of templates. So is Java, if you compile it.
304
305 When highest efficiency is not required, other languages commonly used
306 in the free software community, such as Lisp, Scheme, Python, Ruby, and
307 Java, are OK too. Scheme, as implemented by GNU@tie{}Guile, plays a
308 particular role in the GNU System: it is the preferred language to
309 extend programs written in C/C++, and also a fine language for a wide
310 range of applications. The more GNU components use Guile and Scheme,
311 the more users are able to extend and combine them (@pxref{The Emacs
312 Thesis,,, guile, GNU Guile Reference Manual}).
313
314 Many programs are designed to be extensible: they include an interpreter
315 for a language that is higher level than C@. Often much of the program
316 is written in that language, too. The Emacs editor pioneered this
317 technique.
318
319 @cindex Guile
320 @cindex GNOME and Guile
321 The standard extensibility interpreter for GNU software is Guile
322 (@uref{https://www.gnu.org/@/software/@/guile/}), which implements the
323 language Scheme (an especially clean and simple dialect of Lisp).
324 Guile also includes bindings for GTK+/GNOME, making it practical to
325 write modern GUI functionality within Guile. We don't reject programs
326 written in other ``scripting languages'' such as Perl and Python, but
327 using Guile is the path that will lead to overall consistency of the
328 GNU system.
329
330
331 @node Compatibility
332 @section Compatibility with Other Implementations
333 @cindex compatibility with C and POSIX standards
334 @cindex C compatibility
335 @cindex POSIX compatibility
336
337 With occasional exceptions, utility programs and libraries for GNU
338 should be upward compatible with those in Berkeley Unix, and upward
339 compatible with Standard C if Standard C specifies their
340 behavior, and upward compatible with POSIX if POSIX specifies
341 their behavior.
342
343 When these standards conflict, it is useful to offer compatibility
344 modes for each of them.
345
346 @cindex options for compatibility
347 Standard C and POSIX prohibit many kinds of extensions. Feel
348 free to make the extensions anyway, and include a @samp{--ansi},
349 @samp{--posix}, or @samp{--compatible} option to turn them off.
350 However, if the extension has a significant chance of breaking any real
351 programs or scripts, then it is not really upward compatible. So you
352 should try to redesign its interface to make it upward compatible.
353
354 @cindex @code{POSIXLY_CORRECT}, environment variable
355 Many GNU programs suppress extensions that conflict with POSIX if the
356 environment variable @code{POSIXLY_CORRECT} is defined (even if it is
357 defined with a null value). Please make your program recognize this
358 variable if appropriate.
359
360 When a feature is used only by users (not by programs or command
361 files), and it is done poorly in Unix, feel free to replace it
362 completely with something totally different and better. (For example,
363 @code{vi} is replaced with Emacs.) But it is nice to offer a compatible
364 feature as well. (There is a free @code{vi} clone, so we offer it.)
365
366 Additional useful features are welcome regardless of whether
367 there is any precedent for them.
368
369 @node Using Extensions
370 @section Using Non-standard Features
371 @cindex non-standard extensions
372
373 Many GNU facilities that already exist support a number of convenient
374 extensions over the comparable Unix facilities. Whether to use these
375 extensions in implementing your program is a difficult question.
376
377 On the one hand, using the extensions can make a cleaner program.
378 On the other hand, people will not be able to build the program
379 unless the other GNU tools are available. This might cause the
380 program to work on fewer kinds of machines.
381
382 With some extensions, it might be easy to provide both alternatives.
383 For example, you can define functions with a ``keyword'' @code{INLINE}
384 and define that as a macro to expand into either @code{inline} or
385 nothing, depending on the compiler.
386
387 In general, perhaps it is best not to use the extensions if you can
388 straightforwardly do without them, but to use the extensions if they
389 are a big improvement.
390
391 An exception to this rule are the large, established programs (such as
392 Emacs) which run on a great variety of systems. Using GNU extensions in
393 such programs would make many users unhappy, so we don't do that.
394
395 Another exception is for programs that are used as part of compilation:
396 anything that must be compiled with other compilers in order to
397 bootstrap the GNU compilation facilities. If these require the GNU
398 compiler, then no one can compile them without having them installed
399 already. That would be extremely troublesome in certain cases.
400
401 @node Standard C
402 @section Standard C
403 @cindex ANSI C standard
404
405 ISO C99 is widespread enough now that it is ok to use its
406 features in programs. There is one exception: do not ever use the
407 ``trigraph'' misfeature introduced by C89 and not removed until C23.
408
409 Not all features of recent Standard C are fully supported on all
410 platforms. If you aim to support compilation by compilers other than
411 GCC, you should generally not require newer Standard C features in
412 your programs, or else use them conditionally on whether the compiler
413 supports them. The same goes for GNU C extensions such as variable
414 length arrays.
415
416 If your program is only meant to compile with GCC, then you can use
417 these features if GCC supports them. Don't use features that GCC does
418 not support, except conditionally as a way to use equivalent features
419 to those that are used when compiling with GCC.
420
421 @cindex function prototypes
422 Before C89, functions needed to be written in the K&R style, like
423 this:
424
425 @example
426 int
427 foo (x, y)
428 int x, y;
429 @dots{}
430 @end example
431
432 @noindent
433 with a separate declaration to specify the argument prototype:
434
435 @example
436 int foo (int, int);
437 @end example
438
439 Until the 2020s, that was the way to get the most portability to
440 different compilers. But not any more.
441
442 Nowadays, it is rare to find a C compiler which fails to support the
443 prototype style of function definition. It is more common to run into
444 a compiler that has dropped support for the old K&R style. Thus, to
445 maximize portability, write function definitions in the Standard C
446 style.
447
448 You generally need a declaration for the function in addition to its
449 definition, usually in a header file, to get the benefit of prototypes
450 in all the files where the function is called.
451
452 @node Conditional Compilation
453 @section Conditional Compilation
454
455 When supporting configuration options already known when building your
456 program we prefer using @code{if (... )} over conditional compilation,
457 as in the former case the compiler is able to perform more extensive
458 checking of all possible code paths.
459
460 For example, please write
461
462 @smallexample
463 if (HAS_FOO)
464 ...
465 else
466 ...
467 @end smallexample
468
469 @noindent
470 instead of:
471
472 @smallexample
473 #ifdef HAS_FOO
474 ...
475 #else
476 ...
477 #endif
478 @end smallexample
479
480 A modern compiler such as GCC will generate exactly the same code in
481 both cases, and we have been using similar techniques with good success
482 in several projects. Of course, the former method assumes that
483 @code{HAS_FOO} is defined as either 0 or 1.
484
485 While this is not a silver bullet solving all portability problems,
486 and is not always appropriate, following this policy would have saved
487 GCC developers many hours, or even days, per year.
488
489 In the case of function-like macros like @code{REVERSIBLE_CC_MODE} in
490 GCC which cannot be simply used in @code{if (...)} statements, there is
491 an easy workaround. Simply introduce another macro
492 @code{HAS_REVERSIBLE_CC_MODE} as in the following example:
493
494 @smallexample
495 #ifdef REVERSIBLE_CC_MODE
496 #define HAS_REVERSIBLE_CC_MODE 1
497 #else
498 #define HAS_REVERSIBLE_CC_MODE 0
499 #endif
500 @end smallexample
501
502 @node Program Behavior
503 @chapter Program Behavior for All Programs
504
505 This chapter describes conventions for writing robust
506 software. It also describes general standards for error messages, the
507 command line interface, and how libraries should behave.
508
509 @menu
510 * Non-GNU Standards:: We consider standards such as POSIX;
511 we don't "obey" them.
512 * Semantics:: Writing robust programs.
513 * Libraries:: Library behavior.
514 * Errors:: Formatting error messages.
515 * User Interfaces:: Standards about interfaces generally.
516 * Finding Program Files:: How to find the program's executable
517 and other files that go with it.
518 * Graphical Interfaces:: Standards for graphical interfaces.
519 * Command-Line Interfaces:: Standards for command line interfaces.
520 * Dynamic Plug-In Interfaces:: Standards for dynamic plug-in interfaces.
521 * Option Table:: Table of long options.
522 * OID Allocations:: Table of OID slots for GNU.
523 * Memory Usage:: When and how to care about memory needs.
524 * File Usage:: Which files to use, and where.
525 @end menu
526
527 @node Non-GNU Standards
528 @section Non-GNU Standards
529
530 The GNU Project regards standards published by other organizations as
531 suggestions, not orders. We consider those standards, but we do not
532 ``obey'' them. In developing a GNU program, you should implement
533 an outside standard's specifications when that makes the GNU system
534 better overall in an objective sense. When it doesn't, you shouldn't.
535
536 In most cases, following published standards is convenient for
537 users---it means that their programs or scripts will work more
538 portably. For instance, GCC implements nearly all the features of
539 Standard C as specified by that standard. C program developers would
540 be unhappy if it did not. And GNU utilities mostly follow
541 specifications of POSIX; shell script writers and users would be
542 unhappy if our programs were incompatible.
543
544 But we do not follow either of these specifications rigidly, and there
545 are specific points on which we decided not to follow them, so as to
546 make the GNU system better for users.
547
548 For instance, Standard C says that nearly all extensions to C are
549 prohibited. How silly! GCC implements many extensions, some of which
550 were later adopted as part of the standard. If you want these
551 constructs to give an error message as ``required'' by the standard,
552 you must specify @samp{--pedantic}, which was implemented only so that
553 we can say ``GCC is a 100% implementation of the standard'', not
554 because there is any reason to actually use it.
555
556 POSIX specifies that @samp{df} and @samp{du} must output sizes by
557 default in units of 512 bytes. What users want is units of 1k, so
558 that is what we do by default. If you want the ridiculous behavior
559 ``required'' by POSIX, you must set the environment variable
560 @samp{POSIXLY_CORRECT} (which was originally going to be named
561 @samp{POSIX_ME_HARDER}).
562
563 GNU utilities also depart from the letter of the POSIX specification
564 when they support long-named command-line options, and intermixing
565 of options with ordinary arguments. This minor incompatibility with
566 POSIX is never a problem in practice, and it is very useful.
567
568 In particular, don't reject a new feature, or remove an old one,
569 merely because a standard says it is ``forbidden'' or ``deprecated''.
570
571
572 @node Semantics
573 @section Writing Robust Programs
574
575 @cindex arbitrary limits on data
576 Avoid arbitrary limits on the length or number of @emph{any} data
577 structure, including file names, lines, files, and symbols, by allocating
578 all data structures dynamically. In most Unix utilities, ``long lines
579 are silently truncated''. This is not acceptable in a GNU utility.
580
581 @cindex @code{NUL} characters
582 @findex libiconv
583 Utilities reading files should not drop NUL characters, or any other
584 nonprinting characters. Programs should work properly with multibyte
585 character encodings, such as UTF-8. You can use libiconv to deal with
586 a range of encodings.
587
588 @cindex error messages
589 Check every system call for an error return, unless you know you wish
590 to ignore errors. Include the system error text (from
591 @code{strerror}, or equivalent) in @emph{every} error message
592 resulting from a failing system call, as well as the name of the file
593 if any and the name of the utility. Just ``cannot open foo.c'' or
594 ``stat failed'' is not sufficient.
595
596 @cindex @code{malloc} return value
597 @cindex memory allocation failure
598 Check every call to @code{malloc} or @code{realloc} to see if it
599 returned @code{NULL}. Check @code{realloc} even if you are making the
600 block smaller; in a system that rounds block sizes to a power of 2,
601 @code{realloc} may get a different block if you ask for less space.
602
603 You must expect @code{free} to alter the contents of the block that was
604 freed. Anything you want to fetch from the block, you must fetch before
605 calling @code{free}.
606
607 If @code{malloc} fails in a noninteractive program, make that a fatal
608 error. In an interactive program (one that reads commands from the
609 user), it is better to abort the command and return to the command
610 reader loop. This allows the user to kill other processes to free up
611 virtual memory, and then try the command again.
612
613 @cindex command-line arguments, decoding
614 Use @code{getopt_long} to decode arguments, unless the argument syntax
615 makes this unreasonable.
616
617 When static storage is to be written in during program execution, use
618 explicit C code to initialize it. This way, restarting the program
619 (without reloading it), or part of it, will reinitialize those
620 variables. Reserve C initialized declarations for data that will not
621 be changed.
622 @c ADR: why?
623
624 Try to avoid low-level interfaces to obscure Unix data structures (such
625 as file directories, utmp, or the layout of kernel memory), since these
626 are less likely to work compatibly. If you need to find all the files
627 in a directory, use @code{readdir} or some other high-level interface.
628 These are supported compatibly by GNU.
629
630 @cindex signal handling
631 The preferred signal handling facilities are the BSD variant of
632 @code{signal}, and the POSIX @code{sigaction} function; the
633 alternative USG @code{signal} interface is an inferior design.
634
635 Nowadays, using the POSIX signal functions may be the easiest way
636 to make a program portable. If you use @code{signal}, then on GNU/Linux
637 systems running GNU libc version 1, you should include
638 @file{bsd/signal.h} instead of @file{signal.h}, so as to get BSD
639 behavior. It is up to you whether to support systems where
640 @code{signal} has only the USG behavior, or give up on them.
641
642 @cindex impossible conditions
643 In error checks that detect ``impossible'' conditions, just abort.
644 There is usually no point in printing any message. These checks
645 indicate the existence of bugs. Whoever wants to fix the bugs will have
646 to read the source code and run a debugger. So explain the problem with
647 comments in the source. The relevant data will be in variables, which
648 are easy to examine with the debugger, so there is no point moving them
649 elsewhere.
650
651 Do not use a count of errors as the exit status for a program.
652 @emph{That does not work}, because exit status values are limited to 8
653 bits (0 through 255). A single run of the program might have 256
654 errors; if you try to return 256 as the exit status, the parent process
655 will see 0 as the status, and it will appear that the program succeeded.
656
657 @cindex temporary files
658 @cindex @code{TMPDIR} environment variable
659 If you make temporary files, check the @code{TMPDIR} environment
660 variable; if that variable is defined, use the specified directory
661 instead of @file{/tmp}.
662
663 In addition, be aware that there is a possible security problem when
664 creating temporary files in world-writable directories. In C, you can
665 avoid this problem by creating temporary files in this manner:
666
667 @example
668 fd = open (filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
669 @end example
670
671 @noindent
672 or by using the @code{mkstemps} function from Gnulib
673 (@pxref{mkstemps,,, gnulib, Gnulib}).
674
675 In bash, use @code{set -C} (long name @code{noclobber}) to avoid this
676 problem. In addition, the @code{mktemp} utility is a more general
677 solution for creating temporary files from shell scripts
678 (@pxref{mktemp invocation,,, coreutils, GNU Coreutils}).
679
680
681 @node Libraries
682 @section Library Behavior
683 @cindex libraries
684
685 Try to make library functions reentrant. If they need to do dynamic
686 storage allocation, at least try to avoid any nonreentrancy aside from
687 that of @code{malloc} itself.
688
689 Here are certain name conventions for libraries, to avoid name
690 conflicts.
691
692 Choose a name prefix for the library, more than two characters long.
693 All external function and variable names should start with this
694 prefix. In addition, there should only be one of these in any given
695 library member. This usually means putting each one in a separate
696 source file.
697
698 An exception can be made when two external symbols are always used
699 together, so that no reasonable program could use one without the
700 other; then they can both go in the same file.
701
702 External symbols that are not documented entry points for the user
703 should have names beginning with @samp{_}. The @samp{_} should be
704 followed by the chosen name prefix for the library, to prevent
705 collisions with other libraries. These can go in the same files with
706 user entry points if you like.
707
708 Static functions and variables can be used as you like and need not
709 fit any naming convention.
710
711 @node Errors
712 @section Formatting Error Messages
713 @cindex formatting error messages
714 @cindex error messages, formatting
715
716 Error messages from compilers should look like this:
717
718 @example
719 @var{sourcefile}:@var{lineno}: @var{message}
720 @end example
721
722 @noindent
723 If you want to mention the column number, use one of these formats:
724
725 @example
726 @var{sourcefile}:@var{lineno}:@var{column}: @var{message}
727 @var{sourcefile}:@var{lineno}.@var{column}: @var{message}
728
729 @end example
730
731 @noindent
732 Line numbers should start from 1 at the beginning of the file, and
733 column numbers should start from 1 at the beginning of the line.
734 (Both of these conventions are chosen for compatibility.) Calculate
735 column numbers assuming that space and all ASCII printing characters
736 have equal width, and assuming tab stops every 8 columns. For
737 non-ASCII characters, Unicode character widths should be used when in
738 a UTF-8 locale; GNU libc and GNU gnulib provide suitable
739 @code{wcwidth} functions.
740
741 The error message can also give both the starting and ending positions
742 of the erroneous text. There are several formats so that you can
743 avoid redundant information such as a duplicate line number.
744 Here are the possible formats:
745
746 @example
747 @var{sourcefile}:@var{line1}.@var{column1}-@var{line2}.@var{column2}: @var{message}
748 @var{sourcefile}:@var{line1}.@var{column1}-@var{column2}: @var{message}
749 @var{sourcefile}:@var{line1}-@var{line2}: @var{message}
750 @end example
751
752 @noindent
753 When an error is spread over several files, you can use this format:
754
755 @example
756 @var{file1}:@var{line1}.@var{column1}-@var{file2}:@var{line2}.@var{column2}: @var{message}
757 @end example
758
759 Error messages from other noninteractive programs should look like this:
760
761 @example
762 @var{program}:@var{sourcefile}:@var{lineno}: @var{message}
763 @end example
764
765 @noindent
766 when there is an appropriate source file, or like this:
767
768 @example
769 @var{program}: @var{message}
770 @end example
771
772 @noindent
773 when there is no relevant source file.
774
775 If you want to mention the column number, use this format:
776
777 @example
778 @var{program}:@var{sourcefile}:@var{lineno}:@var{column}: @var{message}
779 @end example
780
781 In an interactive program (one that is reading commands from a
782 terminal), it is better not to include the program name in an error
783 message. The place to indicate which program is running is in the
784 prompt or with the screen layout. (When the same program runs with
785 input from a source other than a terminal, it is not interactive and
786 would do best to print error messages using the noninteractive style.)
787
788 The string @var{message} should not begin with a capital letter when
789 it follows a program name and/or file name, because that isn't the
790 beginning of a sentence. (The sentence conceptually starts at the
791 beginning of the line.) Also, it should not end with a period.
792
793 Error messages from interactive programs, and other messages such as
794 usage messages, should start with a capital letter. But they should not
795 end with a period.
796
797 @node User Interfaces
798 @section Standards for Interfaces Generally
799
800 @cindex program name and its behavior
801 @cindex behavior, dependent on program's name
802 Please don't make the behavior of a utility depend on the name used to
803 invoke it. It is useful sometimes to make a link to a utility with a
804 different name, and that should not change what it does. Thus, if you
805 make @file{foo} a link to @file{ls}, the program should behave the
806 same regardless of which of those names is used to invoke it.
807
808 Instead, use a run time option or a compilation switch or both to
809 select among the alternate behaviors. You can also build two versions
810 of the program, with different default behaviors, and install them
811 under two different names.
812
813 @cindex output device and program's behavior
814 Likewise, please don't make the behavior of a command-line program
815 depend on the type of output device it gets as standard output or
816 standard input. Device independence is an important principle of the
817 system's design; do not compromise it merely to save someone from
818 typing an option now and then. (Variation in error message syntax
819 when using a terminal is ok, because that is a side issue that people
820 do not depend on.)
821
822 If you think one behavior is most useful when the output is to a
823 terminal, and another is most useful when the output is a file or a
824 pipe, then it is usually best to make the default behavior the one
825 that is useful with output to a terminal, and have an option for the
826 other behavior. You can also build two different versions of the
827 program with different names.
828
829 There is an exception for programs whose output in certain cases is
830 binary data. Sending such output to a terminal is useless and can
831 cause trouble. If such a program normally sends its output to stdout,
832 it should detect, in these cases, when the output is a terminal and
833 give an error message instead. The @code{-f} option should override
834 this exception, thus permitting the output to go to the terminal.
835
836 Compatibility requires certain programs to depend on the type of output
837 device. It would be disastrous if @code{ls} or @code{sh} did not do so
838 in the way all users expect. In some of these cases, we supplement the
839 program with a preferred alternate version that does not depend on the
840 output device type. For example, we provide a @code{dir} program much
841 like @code{ls} except that its default output format is always
842 multi-column format.
843
844 @node Finding Program Files
845 @section Finding the Program's Executable and Associated Files
846
847 A program may need to find the executable file it was started with, so
848 as to relaunch the same program. It may need to find associated
849 files, either source files or files constructed by building, that
850 it uses at run time.
851
852 The way to find them starts with looking at @code{argv[0]}.
853
854 If that string contains a slash, it is by convention the file name of
855 the executable and its directory part is the directory that contained
856 the executable. This is the case when the program was not found
857 through @env{PATH}, which normally means it was built but not
858 installed, and run from the build directory. The program can use the
859 @code{argv[0]} file name to relaunch itself, and can look in its
860 directory part for associated files. If that file name is not
861 absolute, then it is relative to the working directory in which the
862 program started.
863
864 If @code{argv[0]} does not contain a slash, it is a command name whose
865 executable was found via @env{PATH}. The program should search for
866 that name in the directories in @env{PATH}, interpreting @file{.} as
867 the working directory that was current when the program started.
868
869 If this procedure finds the executable, we call the directory it was
870 found in the @dfn{invocation directory}. The program should check
871 for the presence in that directory of the associated files it needs.
872
873 If the program's executable is normally built in a subdirectory of the
874 main build directory, and the main build directory contains associated
875 files (perhaps including subdirectories), the program should look at
876 the parent of the invocation directory, checking for the associated
877 files and subdirectories the main build directory should contain.
878
879 If the invocation directory doesn't contain what's needed, but the
880 executable file name is a symbolic link, the program should try using
881 the link target's containing directory as the invocation directory.
882
883 If this procedure doesn't come up with an invocation directory that is
884 valid---normally the case for an installed program that was found via
885 @env{PATH}---the program should look for the associated files in the
886 directories where the program's makefile installs them.
887 @xref{Directory Variables}.
888
889 Providing valid information in @code{argv[0]} is a convention, not
890 guaranteed. Well-behaved programs that launch other programs, such as
891 shells, follow the convention; your code should follow it too, when
892 launching other programs. But it is always possible to launch the
893 program and give a nonsensical value in @code{argv[0]}.
894
895 Therefore, any program that needs to know the location of its
896 executable, or that of of other associated files, should offer the
897 user environment variables to specify those locations explicitly.
898
899 @strong{Don't give special privilege, such as with the @code{setuid}
900 bit, to programs that will search heuristically for associated files
901 or for their own executables when invoked that way.} Limit that
902 privilege to programs that find associated files in hard-coded
903 installed locations such as under @file{/usr} and @file{/etc}.
904
905 @c ??? Is even that safe, in a setuid program?
906
907 @xref{Bourne Shell Variables,,, bash, Bash Reference Manual},
908 for more information about @env{PATH}.
909
910 @node Graphical Interfaces
911 @section Standards for Graphical Interfaces
912 @cindex graphical user interface
913 @cindex interface styles
914 @cindex user interface styles
915
916 @cindex GTK+
917 @cindex GNUstep
918 When you write a program that provides a graphical user interface,
919 please make it work with the X Window System, using the GTK+ toolkit
920 or the GNUstep toolkit, unless the functionality specifically requires
921 some alternative (for example, ``displaying jpeg images while in
922 console mode'').
923
924 In addition, please provide a command-line interface to control the
925 functionality. (In many cases, the graphical user interface can be a
926 separate program which invokes the command-line program.) This is
927 so that the same jobs can be done from scripts.
928
929 @cindex CORBA
930 @cindex GNOME
931 @cindex D-bus
932 @cindex keyboard interface
933 @cindex library interface
934 Please also consider providing a D-bus interface for use from other
935 running programs, such as within GNOME@. (GNOME used to use CORBA
936 for this, but that is being phased out.) In addition, consider
937 providing a library interface (for use from C), and perhaps a
938 keyboard-driven console interface (for use by users from console
939 mode). Once you are doing the work to provide the functionality and
940 the graphical interface, these won't be much extra work.
941
942 Please make your program interoperate with access technology such as
943 screen readers (see
944 @url{https://www.gnu.org/accessibility/accessibility.html}). This should
945 be automatic if you use GTK+.
946
947 @node Command-Line Interfaces
948 @section Standards for Command Line Interfaces
949 @cindex command-line interface
950
951 @findex getopt
952 It is a good idea to follow the POSIX guidelines for the
953 command-line options of a program. The easiest way to do this is to use
954 @code{getopt} to parse them. Note that the GNU version of @code{getopt}
955 will normally permit options anywhere among the arguments unless the
956 special argument @samp{--} is used. This is not what POSIX
957 specifies; it is a GNU extension.
958
959 @cindex long-named options
960 Please define long-named options that are equivalent to the
961 single-letter Unix-style options. We hope to make GNU more user
962 friendly this way. This is easy to do with the GNU function
963 @code{getopt_long}.
964
965 One of the advantages of long-named options is that they can be
966 consistent from program to program. For example, users should be able
967 to expect the ``verbose'' option of any GNU program which has one, to be
968 spelled precisely @samp{--verbose}. To achieve this uniformity, look at
969 the table of common long-option names when you choose the option names
970 for your program (@pxref{Option Table}).
971
972 It is usually a good idea for file names given as ordinary arguments to
973 be input files only; any output files would be specified using options
974 (preferably @samp{-o} or @samp{--output}). Even if you allow an output
975 file name as an ordinary argument for compatibility, try to provide an
976 option as another way to specify it. This will lead to more consistency
977 among GNU utilities, and fewer idiosyncrasies for users to remember.
978
979 @cindex standard command-line options
980 @cindex options, standard command-line
981 @cindex CGI programs, standard options for
982 @cindex PATH_INFO, specifying standard options as
983 All programs should support two standard options: @samp{--version}
984 and @samp{--help}. CGI programs should accept these as command-line
985 options, and also if given as the @env{PATH_INFO}; for instance,
986 visiting @indicateurl{http://example.org/p.cgi/--help} in a browser should
987 output the same information as invoking @samp{p.cgi --help} from the
988 command line.
989
990 @menu
991 * --version:: The standard output for @option{--version}.
992 * --help:: The standard output for @option{--help}.
993 @end menu
994
995 @node --version
996 @subsection @option{--version}
997
998 @cindex @samp{--version} output
999
1000 The standard @code{--version} option should direct the program to
1001 print information about its name, version, origin and legal status,
1002 all on standard output, and then exit successfully. Other options and
1003 arguments should be ignored once this is seen, and the program should
1004 not perform its normal function.
1005
1006 @cindex canonical name of a program
1007 @cindex program's canonical name
1008 The first line is meant to be easy for a program to parse; the version
1009 number proper starts after the last space. In addition, it contains
1010 the canonical name for this program, in this format:
1011
1012 @example
1013 GNU Emacs 19.30
1014 @end example
1015
1016 @noindent
1017 The program's name should be a constant string; @emph{don't} compute it
1018 from @code{argv[0]}. The idea is to state the standard or canonical
1019 name for the program, not its file name. There are other ways to find
1020 out the precise file name where a command is found in @code{PATH}.
1021
1022 If the program is a subsidiary part of a larger package, mention the
1023 package name in parentheses, like this:
1024
1025 @example
1026 emacsserver (GNU Emacs) 19.30
1027 @end example
1028
1029 @noindent
1030 If the package has a version number which is different from this
1031 program's version number, you can mention the package version number
1032 just before the close-parenthesis.
1033
1034 If you @emph{need} to mention the version numbers of libraries which
1035 are distributed separately from the package which contains this program,
1036 you can do so by printing an additional line of version info for each
1037 library you want to mention. Use the same format for these lines as for
1038 the first line.
1039
1040 Please do not mention all of the libraries that the program uses ``just
1041 for completeness''---that would produce a lot of unhelpful clutter.
1042 Please mention library version numbers only if you find in practice that
1043 they are very important to you in debugging.
1044
1045 The following line, after the version number line or lines, should be a
1046 copyright notice. If more than one copyright notice is called for, put
1047 each on a separate line.
1048
1049 Next should follow a line stating the license, preferably using one of
1050 the abbreviations below, and a brief statement that the program is free
1051 software, and that users are free to copy and change it. Also mention
1052 that there is no warranty, to the extent permitted by law. See
1053 recommended wording below.
1054
1055 It is ok to finish the output with a list of the major authors of the
1056 program, as a way of giving credit.
1057
1058 Here's an example of output that follows these rules:
1059
1060 @smallexample
1061 GNU hello 2.3
1062 Copyright (C) 2007 Free Software Foundation, Inc.
1063 License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
1064 This is free software: you are free to change and redistribute it.
1065 There is NO WARRANTY, to the extent permitted by law.
1066 @end smallexample
1067
1068 You should adapt this to your program, of course, filling in the proper
1069 year, copyright holder, name of program, and the references to
1070 distribution terms, and changing the rest of the wording as necessary.
1071
1072 This copyright notice only needs to mention the most recent year in
1073 which changes were made---there's no need to list the years for previous
1074 versions' changes. You don't have to mention the name of the program in
1075 these notices, if that is inconvenient, since it appeared in the first
1076 line. (The rules are different for copyright notices in source files;
1077 @pxref{Copyright Notices,,,maintain,Information for GNU Maintainers}.)
1078
1079 Translations of the above lines must preserve the validity of the
1080 copyright notices (@pxref{Internationalization}). If the translation's
1081 character set supports it, the @samp{(C)} should be replaced with the
1082 copyright symbol, as follows:
1083
1084 @ifinfo
1085 (the official copyright symbol, which is the letter C in a circle);
1086 @end ifinfo
1087 @ifnotinfo
1088 @copyright{}
1089 @end ifnotinfo
1090
1091 Write the word ``Copyright'' exactly like that, in English. Do not
1092 translate it into another language. International treaties recognize
1093 the English word ``Copyright''; translations into other languages do not
1094 have legal significance.
1095
1096 Finally, here is the table of our suggested license abbreviations.
1097 Any abbreviation can be followed by @samp{v@var{version}[+]}, meaning
1098 that particular version, or later versions with the @samp{+}, as shown
1099 above. In the case of a GNU license, @emph{always} indicate the permitted
1100 versions in this way.
1101
1102 In the case of exceptions for extra permissions with the GPL, we use
1103 @samp{/} for a separator; the version number can follow the license
1104 abbreviation as usual, as in the examples below.
1105
1106 @table @asis
1107 @item GPL
1108 GNU General Public License, @url{https://www.gnu.org/@/licenses/@/gpl.html}.
1109
1110 @item LGPL
1111 GNU Lesser General Public License, @url{https://www.gnu.org/@/licenses/@/lgpl.html}.
1112
1113 @item GPL/Ada
1114 GNU GPL with the exception for Ada.
1115
1116 @item Apache
1117 The Apache Software Foundation license,
1118 @url{https://directory.fsf.org/@/wiki/@/License:Apache2.0}.
1119
1120 @item Artistic
1121 The Artistic license used for Perl,
1122 @url{https://directory.fsf.org/@/wiki/@/License:ArtisticLicense2.0}.
1123
1124 @item Expat
1125 The Expat license, @url{https://directory.fsf.org/@/wiki/@/License:Expat}.
1126
1127 @item MPL
1128 The Mozilla Public License, @url{https://directory.fsf.org/@/wiki/@/License:MPLv2.0}.
1129
1130 @item OBSD
1131 The original (4-clause) BSD license, incompatible with the GNU GPL,@*
1132 @url{https://directory.fsf.org/@/wiki/@/License:BSD_4Clause}.
1133
1134 @item PHP
1135 The license used for PHP, @url{https://directory.fsf.org/@/wiki/@/License:PHPv3.01}.
1136
1137 @item public domain
1138 The non-license that is being in the public domain,@*
1139 @url{https://www.gnu.org/@/licenses/@/license-list.html#PublicDomain}.
1140
1141 @item Python
1142 The license for Python,
1143 @url{https://directory.fsf.org/@/wiki/@/License:Python2.0.1}.
1144
1145 @item RBSD
1146 The revised (3-clause) BSD, compatible with the GNU GPL,@*
1147 @url{https://directory.fsf.org/@/wiki/@/License:BSD_3Clause}.
1148
1149 @item X11
1150 The simple non-copyleft license used for most versions of the X Window
1151 System, @url{https://directory.fsf.org/@/wiki/@/License:X11}.
1152
1153 @item Zlib
1154 The license for Zlib, @url{https://directory.fsf.org/@/wiki/@/License:Zlib}.
1155
1156 @end table
1157
1158 More information about these licenses and many more are on the GNU
1159 licensing web pages,
1160 @url{https://www.gnu.org/@/licenses/@/license-list.html}.
1161
1162
1163 @node --help
1164 @subsection @option{--help}
1165
1166 @cindex @samp{--help} output
1167
1168 The standard @code{--help} option should output brief documentation
1169 for how to invoke the program, on standard output, then exit
1170 successfully. Other options and arguments should be ignored once this
1171 is seen, and the program should not perform its normal function.
1172
1173 @cindex address for bug reports
1174 @cindex bug reports
1175 Near the end of the @samp{--help} option's output, please place lines
1176 giving the email address for bug reports, the package's home page
1177 (normally @indicateurl{https://www.gnu.org/software/@var{pkg}}), and the
1178 general page for help using GNU programs. The format should be like this:
1179
1180 @example
1181 Report bugs to: @var{mailing-address}
1182 @var{pkg} home page: <https://www.gnu.org/software/@var{pkg}/>
1183 General help using GNU software: <https://www.gnu.org/gethelp/>
1184 @end example
1185
1186 It is ok to mention other appropriate mailing lists and web pages.
1187
1188
1189 @node Dynamic Plug-In Interfaces
1190 @section Standards for Dynamic Plug-in Interfaces
1191 @cindex plug-ins
1192 @cindex dynamic plug-ins
1193
1194 Another aspect of keeping free programs free is encouraging
1195 development of free plug-ins, and discouraging development of
1196 proprietary plug-ins. Many GNU programs will not have anything like
1197 plug-ins at all, but those that do should follow these
1198 practices.
1199
1200 First, the general plug-in architecture design should closely tie the
1201 plug-in to the original code, such that the plug-in and the base
1202 program are parts of one extended program. For GCC, for example,
1203 plug-ins receive and modify GCC's internal data structures, and so
1204 clearly form an extended program with the base GCC.
1205
1206 @vindex plugin_is_GPL_compatible
1207 Second, you should require plug-in developers to affirm that their
1208 plug-ins are released under an appropriate license. This should be
1209 enforced with a simple programmatic check. For GCC, again for
1210 example, a plug-in must define the global symbol
1211 @code{plugin_is_GPL_compatible}, thus asserting that the plug-in is
1212 released under a GPL-compatible license (@pxref{Plugins,, Plugins,
1213 gccint, GCC Internals}).
1214
1215 By adding this check to your program you are not creating a new legal
1216 requirement. The GPL itself requires plug-ins to be free software,
1217 licensed compatibly. As long as you have followed the first rule above
1218 to keep plug-ins closely tied to your original program, the GPL and AGPL
1219 already require those plug-ins to be released under a compatible
1220 license. The symbol definition in the plug-in---or whatever equivalent
1221 works best in your program---makes it harder for anyone who might
1222 distribute proprietary plug-ins to legally defend themselves. If a case
1223 about this got to court, we can point to that symbol as evidence that
1224 the plug-in developer understood that the license had this requirement.
1225
1226
1227 @node Option Table
1228 @section Table of Long Options
1229 @cindex long option names
1230 @cindex table of long options
1231
1232 Here is a table of long options used by GNU programs. It is surely
1233 incomplete, but we aim to list all the options that a new program might
1234 want to be compatible with. If you use names not already in the table,
1235 please send @email{bug-standards@@gnu.org} a list of them, with their
1236 meanings, so we can update the table.
1237
1238 @c Please leave newlines between items in this table; it's much easier
1239 @c to update when it isn't completely squashed together and unreadable.
1240 @c When there is more than one short option for a long option name, put
1241 @c a semicolon between the lists of the programs that use them, not a
1242 @c period. --friedman
1243
1244 @table @samp
1245 @item after-date
1246 @samp{-N} in @code{tar}.
1247
1248 @item all
1249 @samp{-a} in @code{du}, @code{ls}, @code{nm}, @code{stty}, @code{uname},
1250 and @code{unexpand}.
1251
1252 @item all-text
1253 @samp{-a} in @code{diff}.
1254
1255 @item almost-all
1256 @samp{-A} in @code{ls}.
1257
1258 @item append
1259 @samp{-a} in @code{etags}, @code{tee}, @code{time};
1260 @samp{-r} in @code{tar}.
1261
1262 @item archive
1263 @samp{-a} in @code{cp}.
1264
1265 @item archive-name
1266 @samp{-n} in @code{shar}.
1267
1268 @item arglength
1269 @samp{-l} in @code{m4}.
1270
1271 @item ascii
1272 @samp{-a} in @code{diff}.
1273
1274 @item assign
1275 @samp{-v} in @code{gawk}.
1276
1277 @item assume-new
1278 @samp{-W} in @code{make}.
1279
1280 @item assume-old
1281 @samp{-o} in @code{make}.
1282
1283 @item auto-check
1284 @samp{-a} in @code{recode}.
1285
1286 @item auto-pager
1287 @samp{-a} in @code{wdiff}.
1288
1289 @item auto-reference
1290 @samp{-A} in @code{ptx}.
1291
1292 @item avoid-wraps
1293 @samp{-n} in @code{wdiff}.
1294
1295 @item background
1296 For server programs, run in the background.
1297
1298 @item backward-search
1299 @samp{-B} in @code{ctags}.
1300
1301 @item basename
1302 @samp{-f} in @code{shar}.
1303
1304 @item batch
1305 Used in GDB.
1306
1307 @item baud
1308 Used in GDB.
1309
1310 @item before
1311 @samp{-b} in @code{tac}.
1312
1313 @item binary
1314 @samp{-b} in @code{cpio} and @code{diff}.
1315
1316 @item bits-per-code
1317 @samp{-b} in @code{shar}.
1318
1319 @item block-size
1320 Used in @code{cpio} and @code{tar}.
1321
1322 @item blocks
1323 @samp{-b} in @code{head} and @code{tail}.
1324
1325 @item break-file
1326 @samp{-b} in @code{ptx}.
1327
1328 @item brief
1329 Used in various programs to make output shorter.
1330
1331 @item bytes
1332 @samp{-c} in @code{head}, @code{split}, and @code{tail}.
1333
1334 @item c@t{++}
1335 @samp{-C} in @code{etags}.
1336
1337 @item catenate
1338 @samp{-A} in @code{tar}.
1339
1340 @item cd
1341 Used in various programs to specify the directory to use.
1342
1343 @item changes
1344 @samp{-c} in @code{chgrp} and @code{chown}.
1345
1346 @item classify
1347 @samp{-F} in @code{ls}.
1348
1349 @item colons
1350 @samp{-c} in @code{recode}.
1351
1352 @item command
1353 @samp{-c} in @code{su};
1354 @samp{-x} in GDB.
1355
1356 @item compare
1357 @samp{-d} in @code{tar}.
1358
1359 @item compat
1360 Used in @code{gawk}.
1361
1362 @item compress
1363 @samp{-Z} in @code{tar} and @code{shar}.
1364
1365 @item concatenate
1366 @samp{-A} in @code{tar}.
1367
1368 @item confirmation
1369 @samp{-w} in @code{tar}.
1370
1371 @item context
1372 Used in @code{diff}.
1373
1374 @item copyleft
1375 @samp{-W copyleft} in @code{gawk}.
1376
1377 @item copyright
1378 @samp{-C} in @code{ptx}, @code{recode}, and @code{wdiff};
1379 @samp{-W copyright} in @code{gawk}.
1380
1381 @item core
1382 Used in GDB.
1383
1384 @item count
1385 @samp{-q} in @code{who}.
1386
1387 @item count-links
1388 @samp{-l} in @code{du}.
1389
1390 @item create
1391 Used in @code{tar} and @code{cpio}.
1392
1393 @item cut-mark
1394 @samp{-c} in @code{shar}.
1395
1396 @item cxref
1397 @samp{-x} in @code{ctags}.
1398
1399 @item date
1400 @samp{-d} in @code{touch}.
1401
1402 @item debug
1403 @samp{-d} in @code{make} and @code{m4};
1404 @samp{-t} in Bison.
1405
1406 @item define
1407 @samp{-D} in @code{m4}.
1408
1409 @item defines
1410 @samp{-d} in Bison and @code{ctags}.
1411
1412 @item delete
1413 @samp{-D} in @code{tar}.
1414
1415 @item dereference
1416 @samp{-L} in @code{chgrp}, @code{chown}, @code{cpio}, @code{du},
1417 @code{ls}, and @code{tar}.
1418
1419 @item dereference-args
1420 @samp{-D} in @code{du}.
1421
1422 @item device
1423 Specify an I/O device (special file name).
1424
1425 @item diacritics
1426 @samp{-d} in @code{recode}.
1427
1428 @item dictionary-order
1429 @samp{-d} in @code{look}.
1430
1431 @item diff
1432 @samp{-d} in @code{tar}.
1433
1434 @item digits
1435 @samp{-n} in @code{csplit}.
1436
1437 @item directory
1438 Specify the directory to use, in various programs. In @code{ls}, it
1439 means to show directories themselves rather than their contents. In
1440 @code{rm} and @code{ln}, it means to not treat links to directories
1441 specially.
1442
1443 @item discard-all
1444 @samp{-x} in @code{strip}.
1445
1446 @item discard-locals
1447 @samp{-X} in @code{strip}.
1448
1449 @item dry-run
1450 @samp{-n} in @code{make}.
1451
1452 @item ed
1453 @samp{-e} in @code{diff}.
1454
1455 @item elide-empty-files
1456 @samp{-z} in @code{csplit}.
1457
1458 @item end-delete
1459 @samp{-x} in @code{wdiff}.
1460
1461 @item end-insert
1462 @samp{-z} in @code{wdiff}.
1463
1464 @item entire-new-file
1465 @samp{-N} in @code{diff}.
1466
1467 @item environment-overrides
1468 @samp{-e} in @code{make}.
1469
1470 @item eof
1471 @samp{-e} in @code{xargs}.
1472
1473 @item epoch
1474 Used in GDB.
1475
1476 @item error-limit
1477 Used in @code{makeinfo}.
1478
1479 @item error-output
1480 @samp{-o} in @code{m4}.
1481
1482 @item escape
1483 @samp{-b} in @code{ls}.
1484
1485 @item exclude-from
1486 @samp{-X} in @code{tar}.
1487
1488 @item exec
1489 Used in GDB.
1490
1491 @item exit
1492 @samp{-x} in @code{xargs}.
1493
1494 @item exit-0
1495 @samp{-e} in @code{unshar}.
1496
1497 @item expand-tabs
1498 @samp{-t} in @code{diff}.
1499
1500 @item expression
1501 @samp{-e} in @code{sed}.
1502
1503 @item extern-only
1504 @samp{-g} in @code{nm}.
1505
1506 @item extract
1507 @samp{-i} in @code{cpio};
1508 @samp{-x} in @code{tar}.
1509
1510 @item faces
1511 @samp{-f} in @code{finger}.
1512
1513 @item fast
1514 @samp{-f} in @code{su}.
1515
1516 @item fatal-warnings
1517 @samp{-E} in @code{m4}.
1518
1519 @item file
1520 @samp{-f} in @code{gawk}, @code{info}, @code{make}, @code{mt},
1521 @code{sed}, and @code{tar}.
1522
1523 @item field-separator
1524 @samp{-F} in @code{gawk}.
1525
1526 @item file-prefix
1527 @samp{-b} in Bison.
1528
1529 @item file-type
1530 @samp{-F} in @code{ls}.
1531
1532 @item files-from
1533 @samp{-T} in @code{tar}.
1534
1535 @item fill-column
1536 Used in @code{makeinfo}.
1537
1538 @item flag-truncation
1539 @samp{-F} in @code{ptx}.
1540
1541 @item fixed-output-files
1542 @samp{-y} in Bison.
1543
1544 @item follow
1545 @samp{-f} in @code{tail}.
1546
1547 @item footnote-style
1548 Used in @code{makeinfo}.
1549
1550 @item force
1551 @samp{-f} in @code{cp}, @code{ln}, @code{mv}, and @code{rm}.
1552
1553 @item force-prefix
1554 @samp{-F} in @code{shar}.
1555
1556 @item foreground
1557 For server programs, run in the foreground;
1558 in other words, don't do anything special to run the server
1559 in the background.
1560
1561 @item format
1562 Used in @code{ls}, @code{time}, and @code{ptx}.
1563
1564 @item freeze-state
1565 @samp{-F} in @code{m4}.
1566
1567 @item fullname
1568 Used in GDB.
1569
1570 @item gap-size
1571 @samp{-g} in @code{ptx}.
1572
1573 @item get
1574 @samp{-x} in @code{tar}.
1575
1576 @item graphic
1577 @samp{-i} in @code{ul}.
1578
1579 @item graphics
1580 @samp{-g} in @code{recode}.
1581
1582 @item group
1583 @samp{-g} in @code{install}.
1584
1585 @item gzip
1586 @samp{-z} in @code{tar} and @code{shar}.
1587
1588 @item hashsize
1589 @samp{-H} in @code{m4}.
1590
1591 @item header
1592 @samp{-h} in @code{objdump} and @code{recode}
1593
1594 @item heading
1595 @samp{-H} in @code{who}.
1596
1597 @item help
1598 Used to ask for brief usage information.
1599
1600 @item here-delimiter
1601 @samp{-d} in @code{shar}.
1602
1603 @item hide-control-chars
1604 @samp{-q} in @code{ls}.
1605
1606 @item html
1607 In @code{makeinfo}, output HTML.
1608
1609 @item idle
1610 @samp{-u} in @code{who}.
1611
1612 @item ifdef
1613 @samp{-D} in @code{diff}.
1614
1615 @item ignore
1616 @samp{-I} in @code{ls};
1617 @samp{-x} in @code{recode}.
1618
1619 @item ignore-all-space
1620 @samp{-w} in @code{diff}.
1621
1622 @item ignore-backups
1623 @samp{-B} in @code{ls}.
1624
1625 @item ignore-blank-lines
1626 @samp{-B} in @code{diff}.
1627
1628 @item ignore-case
1629 @samp{-f} in @code{look} and @code{ptx};
1630 @samp{-i} in @code{diff} and @code{wdiff}.
1631
1632 @item ignore-errors
1633 @samp{-i} in @code{make}.
1634
1635 @item ignore-file
1636 @samp{-i} in @code{ptx}.
1637
1638 @item ignore-indentation
1639 @samp{-I} in @code{etags}.
1640
1641 @item ignore-init-file
1642 @samp{-f} in Oleo.
1643
1644 @item ignore-interrupts
1645 @samp{-i} in @code{tee}.
1646
1647 @item ignore-matching-lines
1648 @samp{-I} in @code{diff}.
1649
1650 @item ignore-space-change
1651 @samp{-b} in @code{diff}.
1652
1653 @item ignore-zeros
1654 @samp{-i} in @code{tar}.
1655
1656 @item include
1657 @samp{-i} in @code{etags};
1658 @samp{-I} in @code{m4}.
1659
1660 @item include-dir
1661 @samp{-I} in @code{make}.
1662
1663 @item incremental
1664 @samp{-G} in @code{tar}.
1665
1666 @item info
1667 @samp{-i}, @samp{-l}, and @samp{-m} in Finger.
1668
1669 @item init-file
1670 In some programs, specify the name of the file to read as the user's
1671 init file.
1672
1673 @item initial
1674 @samp{-i} in @code{expand}.
1675
1676 @item initial-tab
1677 @samp{-T} in @code{diff}.
1678
1679 @item inode
1680 @samp{-i} in @code{ls}.
1681
1682 @item interactive
1683 @samp{-i} in @code{cp}, @code{ln}, @code{mv}, @code{rm};
1684 @samp{-e} in @code{m4};
1685 @samp{-p} in @code{xargs};
1686 @samp{-w} in @code{tar}.
1687
1688 @item intermix-type
1689 @samp{-p} in @code{shar}.
1690
1691 @item iso-8601
1692 Used in @code{date}
1693
1694 @item jobs
1695 @samp{-j} in @code{make}.
1696
1697 @item just-print
1698 @samp{-n} in @code{make}.
1699
1700 @item keep-going
1701 @samp{-k} in @code{make}.
1702
1703 @item keep-files
1704 @samp{-k} in @code{csplit}.
1705
1706 @item kilobytes
1707 @samp{-k} in @code{du} and @code{ls}.
1708
1709 @item language
1710 @samp{-l} in @code{etags}.
1711
1712 @item less-mode
1713 @samp{-l} in @code{wdiff}.
1714
1715 @item level-for-gzip
1716 @samp{-g} in @code{shar}.
1717
1718 @item line-bytes
1719 @samp{-C} in @code{split}.
1720
1721 @item lines
1722 Used in @code{split}, @code{head}, and @code{tail}.
1723
1724 @item link
1725 @samp{-l} in @code{cpio}.
1726
1727 @item lint
1728 @itemx lint-old
1729 Used in @code{gawk}.
1730
1731 @item list
1732 @samp{-t} in @code{cpio};
1733 @samp{-l} in @code{recode}.
1734
1735 @item list
1736 @samp{-t} in @code{tar}.
1737
1738 @item literal
1739 @samp{-N} in @code{ls}.
1740
1741 @item load-average
1742 @samp{-l} in @code{make}.
1743
1744 @item login
1745 Used in @code{su}.
1746
1747 @item machine
1748 Used in @code{uname}.
1749
1750 @item macro-name
1751 @samp{-M} in @code{ptx}.
1752
1753 @item mail
1754 @samp{-m} in @code{hello} and @code{uname}.
1755
1756 @item make-directories
1757 @samp{-d} in @code{cpio}.
1758
1759 @item makefile
1760 @samp{-f} in @code{make}.
1761
1762 @item mapped
1763 Used in GDB.
1764
1765 @item max-args
1766 @samp{-n} in @code{xargs}.
1767
1768 @item max-chars
1769 @samp{-n} in @code{xargs}.
1770
1771 @item max-lines
1772 @samp{-l} in @code{xargs}.
1773
1774 @item max-load
1775 @samp{-l} in @code{make}.
1776
1777 @item max-procs
1778 @samp{-P} in @code{xargs}.
1779
1780 @item mesg
1781 @samp{-T} in @code{who}.
1782
1783 @item message
1784 @samp{-T} in @code{who}.
1785
1786 @item minimal
1787 @samp{-d} in @code{diff}.
1788
1789 @item mixed-uuencode
1790 @samp{-M} in @code{shar}.
1791
1792 @item mode
1793 @samp{-m} in @code{install}, @code{mkdir}, and @code{mkfifo}.
1794
1795 @item modification-time
1796 @samp{-m} in @code{tar}.
1797
1798 @item multi-volume
1799 @samp{-M} in @code{tar}.
1800
1801 @item name-prefix
1802 @samp{-a} in Bison.
1803
1804 @item nesting-limit
1805 @samp{-L} in @code{m4}.
1806
1807 @item net-headers
1808 @samp{-a} in @code{shar}.
1809
1810 @item new-file
1811 @samp{-W} in @code{make}.
1812
1813 @item no-builtin-rules
1814 @samp{-r} in @code{make}.
1815
1816 @item no-character-count
1817 @samp{-w} in @code{shar}.
1818
1819 @item no-check-existing
1820 @samp{-x} in @code{shar}.
1821
1822 @item no-common
1823 @samp{-3} in @code{wdiff}.
1824
1825 @item no-create
1826 @samp{-c} in @code{touch}.
1827
1828 @item no-defines
1829 @samp{-D} in @code{etags}.
1830
1831 @item no-deleted
1832 @samp{-1} in @code{wdiff}.
1833
1834 @item no-dereference
1835 @samp{-d} in @code{cp}.
1836
1837 @item no-inserted
1838 @samp{-2} in @code{wdiff}.
1839
1840 @item no-keep-going
1841 @samp{-S} in @code{make}.
1842
1843 @item no-lines
1844 @samp{-l} in Bison.
1845
1846 @item no-piping
1847 @samp{-P} in @code{shar}.
1848
1849 @item no-prof
1850 @samp{-e} in @code{gprof}.
1851
1852 @item no-regex
1853 @samp{-R} in @code{etags}.
1854
1855 @item no-sort
1856 @samp{-p} in @code{nm}.
1857
1858 @item no-splash
1859 Don't print a startup splash screen.
1860
1861 @item no-split
1862 Used in @code{makeinfo}.
1863
1864 @item no-static
1865 @samp{-a} in @code{gprof}.
1866
1867 @item no-time
1868 @samp{-E} in @code{gprof}.
1869
1870 @item no-timestamp
1871 @samp{-m} in @code{shar}.
1872
1873 @item no-validate
1874 Used in @code{makeinfo}.
1875
1876 @item no-wait
1877 Used in @code{emacsclient}.
1878
1879 @item no-warn
1880 Used in various programs to inhibit warnings.
1881
1882 @item node
1883 @samp{-n} in @code{info}.
1884
1885 @item nodename
1886 @samp{-n} in @code{uname}.
1887
1888 @item nonmatching
1889 @samp{-f} in @code{cpio}.
1890
1891 @item nstuff
1892 @samp{-n} in @code{objdump}.
1893
1894 @item null
1895 @samp{-0} in @code{xargs}.
1896
1897 @item number
1898 @samp{-n} in @code{cat}.
1899
1900 @item number-nonblank
1901 @samp{-b} in @code{cat}.
1902
1903 @item numeric-sort
1904 @samp{-n} in @code{nm}.
1905
1906 @item numeric-uid-gid
1907 @samp{-n} in @code{cpio} and @code{ls}.
1908
1909 @item nx
1910 Used in GDB.
1911
1912 @item old-file
1913 @samp{-o} in @code{make}.
1914
1915 @item one-file-system
1916 @samp{-x} in @code{cp} and @code{du}.
1917
1918 @item only-file
1919 @samp{-o} in @code{ptx}.
1920
1921 @item only-prof
1922 @samp{-f} in @code{gprof}.
1923
1924 @item only-time
1925 @samp{-F} in @code{gprof}.
1926
1927 @item options
1928 @samp{-o} in @code{getopt}, @code{fdlist}, @code{fdmount},
1929 @code{fdmountd}, and @code{fdumount}.
1930
1931 @item output
1932 In various programs, specify the output file name.
1933
1934 @item output-prefix
1935 @samp{-o} in @code{shar}.
1936
1937 @item override
1938 @samp{-o} in @code{rm}.
1939
1940 @item overwrite
1941 @samp{-c} in @code{unshar}.
1942
1943 @item owner
1944 @samp{-o} in @code{install}.
1945
1946 @item paginate
1947 @samp{-l} in @code{diff}.
1948
1949 @item paragraph-indent
1950 Used in @code{makeinfo}.
1951
1952 @item parents
1953 @samp{-p} in @code{mkdir} and @code{rmdir}.
1954
1955 @item pass-all
1956 @samp{-p} in @code{ul}.
1957
1958 @item pass-through
1959 @samp{-p} in @code{cpio}.
1960
1961 @item port
1962 @samp{-P} in @code{finger}.
1963
1964 @item portability
1965 @samp{-c} in @code{cpio}.
1966
1967 @item posix
1968 Used in @code{gawk}.
1969
1970 @item prefix-builtins
1971 @samp{-P} in @code{m4}.
1972
1973 @item prefix
1974 @samp{-f} in @code{csplit}.
1975
1976 @item preserve
1977 Used in @code{tar} and @code{cp}.
1978
1979 @item preserve-environment
1980 @samp{-p} in @code{su}.
1981
1982 @item preserve-modification-time
1983 @samp{-m} in @code{cpio}.
1984
1985 @item preserve-order
1986 @samp{-s} in @code{tar}.
1987
1988 @item preserve-permissions
1989 @samp{-p} in @code{tar}.
1990
1991 @item print
1992 @samp{-l} in @code{diff}.
1993
1994 @item print-chars
1995 @samp{-L} in @code{cmp}.
1996
1997 @item print-data-base
1998 @samp{-p} in @code{make}.
1999
2000 @item print-directory
2001 @samp{-w} in @code{make}.
2002
2003 @item print-file-name
2004 @samp{-o} in @code{nm}.
2005
2006 @item print-symdefs
2007 @samp{-s} in @code{nm}.
2008
2009 @item printer
2010 @samp{-p} in @code{wdiff}.
2011
2012 @item prompt
2013 @samp{-p} in @code{ed}.
2014
2015 @item proxy
2016 Specify an HTTP proxy.
2017
2018 @item query-user
2019 @samp{-X} in @code{shar}.
2020
2021 @item question
2022 @samp{-q} in @code{make}.
2023
2024 @item quiet
2025 Used in many programs to inhibit the usual output. Every
2026 program accepting @samp{--quiet} should accept @samp{--silent} as a
2027 synonym.
2028
2029 @item quiet-unshar
2030 @samp{-Q} in @code{shar}
2031
2032 @item quote-name
2033 @samp{-Q} in @code{ls}.
2034
2035 @item rcs
2036 @samp{-n} in @code{diff}.
2037
2038 @item re-interval
2039 Used in @code{gawk}.
2040
2041 @item read-full-blocks
2042 @samp{-B} in @code{tar}.
2043
2044 @item readnow
2045 Used in GDB.
2046
2047 @item recon
2048 @samp{-n} in @code{make}.
2049
2050 @item record-number
2051 @samp{-R} in @code{tar}.
2052
2053 @item recursive
2054 Used in @code{chgrp}, @code{chown}, @code{cp}, @code{ls}, @code{diff},
2055 and @code{rm}.
2056
2057 @item reference
2058 @samp{-r} in @code{touch}.
2059
2060 @item references
2061 @samp{-r} in @code{ptx}.
2062
2063 @item regex
2064 @samp{-r} in @code{tac} and @code{etags}.
2065
2066 @item release
2067 @samp{-r} in @code{uname}.
2068
2069 @item reload-state
2070 @samp{-R} in @code{m4}.
2071
2072 @item relocation
2073 @samp{-r} in @code{objdump}.
2074
2075 @item rename
2076 @samp{-r} in @code{cpio}.
2077
2078 @item replace
2079 @samp{-i} in @code{xargs}.
2080
2081 @item report-identical-files
2082 @samp{-s} in @code{diff}.
2083
2084 @item reset-access-time
2085 @samp{-a} in @code{cpio}.
2086
2087 @item reverse
2088 @samp{-r} in @code{ls} and @code{nm}.
2089
2090 @item reversed-ed
2091 @samp{-f} in @code{diff}.
2092
2093 @item right-side-defs
2094 @samp{-R} in @code{ptx}.
2095
2096 @item same-order
2097 @samp{-s} in @code{tar}.
2098
2099 @item same-permissions
2100 @samp{-p} in @code{tar}.
2101
2102 @item save
2103 @samp{-g} in @code{stty}.
2104
2105 @item se
2106 Used in GDB.
2107
2108 @item sentence-regexp
2109 @samp{-S} in @code{ptx}.
2110
2111 @item separate-dirs
2112 @samp{-S} in @code{du}.
2113
2114 @item separator
2115 @samp{-s} in @code{tac}.
2116
2117 @item sequence
2118 Used by @code{recode} to choose files or pipes for sequencing passes.
2119
2120 @item shell
2121 @samp{-s} in @code{su}.
2122
2123 @item show-all
2124 @samp{-A} in @code{cat}.
2125
2126 @item show-c-function
2127 @samp{-p} in @code{diff}.
2128
2129 @item show-ends
2130 @samp{-E} in @code{cat}.
2131
2132 @item show-function-line
2133 @samp{-F} in @code{diff}.
2134
2135 @item show-tabs
2136 @samp{-T} in @code{cat}.
2137
2138 @item silent
2139 Used in many programs to inhibit the usual output.
2140 Every program accepting
2141 @samp{--silent} should accept @samp{--quiet} as a synonym.
2142
2143 @item size
2144 @samp{-s} in @code{ls}.
2145
2146 @item socket
2147 Specify a file descriptor for a network server to use for its socket,
2148 instead of opening and binding a new socket. This provides a way to
2149 run, in a non-privileged process, a server that normally needs a
2150 reserved port number.
2151
2152 @item sort
2153 Used in @code{ls}.
2154
2155 @item source
2156 @samp{-W source} in @code{gawk}.
2157
2158 @item sparse
2159 @samp{-S} in @code{tar}.
2160
2161 @item speed-large-files
2162 @samp{-H} in @code{diff}.
2163
2164 @item split-at
2165 @samp{-E} in @code{unshar}.
2166
2167 @item split-size-limit
2168 @samp{-L} in @code{shar}.
2169
2170 @item squeeze-blank
2171 @samp{-s} in @code{cat}.
2172
2173 @item start-delete
2174 @samp{-w} in @code{wdiff}.
2175
2176 @item start-insert
2177 @samp{-y} in @code{wdiff}.
2178
2179 @item starting-file
2180 Used in @code{tar} and @code{diff} to specify which file within
2181 a directory to start processing with.
2182
2183 @item statistics
2184 @samp{-s} in @code{wdiff}.
2185
2186 @item stdin-file-list
2187 @samp{-S} in @code{shar}.
2188
2189 @item stop
2190 @samp{-S} in @code{make}.
2191
2192 @item strict
2193 @samp{-s} in @code{recode}.
2194
2195 @item strip
2196 @samp{-s} in @code{install}.
2197
2198 @item strip-all
2199 @samp{-s} in @code{strip}.
2200
2201 @item strip-debug
2202 @samp{-S} in @code{strip}.
2203
2204 @item submitter
2205 @samp{-s} in @code{shar}.
2206
2207 @item suffix
2208 @samp{-S} in @code{cp}, @code{ln}, @code{mv}.
2209
2210 @item suffix-format
2211 @samp{-b} in @code{csplit}.
2212
2213 @item sum
2214 @samp{-s} in @code{gprof}.
2215
2216 @item summarize
2217 @samp{-s} in @code{du}.
2218
2219 @item symbolic
2220 @samp{-s} in @code{ln}.
2221
2222 @item symbols
2223 Used in GDB and @code{objdump}.
2224
2225 @item synclines
2226 @samp{-s} in @code{m4}.
2227
2228 @item sysname
2229 @samp{-s} in @code{uname}.
2230
2231 @item tabs
2232 @samp{-t} in @code{expand} and @code{unexpand}.
2233
2234 @item tabsize
2235 @samp{-T} in @code{ls}.
2236
2237 @item terminal
2238 @samp{-T} in @code{tput} and @code{ul}.
2239 @samp{-t} in @code{wdiff}.
2240
2241 @item text
2242 @samp{-a} in @code{diff}.
2243
2244 @item text-files
2245 @samp{-T} in @code{shar}.
2246
2247 @item time
2248 Used in @code{ls} and @code{touch}.
2249
2250 @item timeout
2251 Specify how long to wait before giving up on some operation.
2252
2253 @item to-stdout
2254 @samp{-O} in @code{tar}.
2255
2256 @item total
2257 @samp{-c} in @code{du}.
2258
2259 @item touch
2260 @samp{-t} in @code{make}, @code{ranlib}, and @code{recode}.
2261
2262 @item trace
2263 @samp{-t} in @code{m4}.
2264
2265 @item traditional
2266 @samp{-t} in @code{hello};
2267 @samp{-W traditional} in @code{gawk};
2268 @samp{-G} in @code{ed}, @code{m4}, and @code{ptx}.
2269
2270 @item tty
2271 Used in GDB.
2272
2273 @item typedefs
2274 @samp{-t} in @code{ctags}.
2275
2276 @item typedefs-and-c++
2277 @samp{-T} in @code{ctags}.
2278
2279 @item typeset-mode
2280 @samp{-t} in @code{ptx}.
2281
2282 @item uncompress
2283 @samp{-z} in @code{tar}.
2284
2285 @item unconditional
2286 @samp{-u} in @code{cpio}.
2287
2288 @item undefine
2289 @samp{-U} in @code{m4}.
2290
2291 @item undefined-only
2292 @samp{-u} in @code{nm}.
2293
2294 @item update
2295 @samp{-u} in @code{cp}, @code{ctags}, @code{mv}, @code{tar}.
2296
2297 @item usage
2298 Used in @code{gawk}; same as @samp{--help}.
2299
2300 @item uuencode
2301 @samp{-B} in @code{shar}.
2302
2303 @item vanilla-operation
2304 @samp{-V} in @code{shar}.
2305
2306 @item verbose
2307 Print more information about progress. Many programs support this.
2308
2309 @item verify
2310 @samp{-W} in @code{tar}.
2311
2312 @item version
2313 Print the version number.
2314
2315 @item version-control
2316 @samp{-V} in @code{cp}, @code{ln}, @code{mv}.
2317
2318 @item vgrind
2319 @samp{-v} in @code{ctags}.
2320
2321 @item volume
2322 @samp{-V} in @code{tar}.
2323
2324 @item what-if
2325 @samp{-W} in @code{make}.
2326
2327 @item whole-size-limit
2328 @samp{-l} in @code{shar}.
2329
2330 @item width
2331 @samp{-w} in @code{ls} and @code{ptx}.
2332
2333 @item word-regexp
2334 @samp{-W} in @code{ptx}.
2335
2336 @item writable
2337 @samp{-T} in @code{who}.
2338
2339 @item zeros
2340 @samp{-z} in @code{gprof}.
2341 @end table
2342
2343 @node OID Allocations
2344 @section OID Allocations
2345 @cindex OID allocations for GNU
2346 @cindex SNMP
2347 @cindex LDAP
2348 @cindex X.509
2349
2350 The OID (object identifier) 1.3.6.1.4.1.11591 has been assigned to the
2351 GNU Project (thanks to Sergey Poznyakoff). These are used for SNMP,
2352 LDAP, X.509 certificates, and so on. The web site
2353 @url{https://www.alvestrand.no/objectid} has a (voluntary) listing of
2354 many OID assignments.
2355
2356 If you need a new slot for your GNU package, write
2357 @email{maintainers@@gnu.org}. Here is a list of arcs currently
2358 assigned:
2359
2360 @example
2361 @include gnu-oids.texi
2362 @end example
2363
2364
2365 @node Memory Usage
2366 @section Memory Usage
2367 @cindex memory usage
2368
2369 If a program typically uses just a few meg of memory, don't bother making any
2370 effort to reduce memory usage. For example, if it is impractical for
2371 other reasons to operate on files more than a few meg long, it is
2372 reasonable to read entire input files into memory to operate on them.
2373
2374 However, for programs such as @code{cat} or @code{tail}, that can
2375 usefully operate on very large files, it is important to avoid using a
2376 technique that would artificially limit the size of files it can handle.
2377 If a program works by lines and could be applied to arbitrary
2378 user-supplied input files, it should keep only a line in memory, because
2379 this is not very hard and users will want to be able to operate on input
2380 files that are bigger than will fit in memory all at once.
2381
2382 If your program creates complicated data structures, just make them in
2383 memory and give a fatal error if @code{malloc} returns @code{NULL}.
2384
2385 @pindex valgrind
2386 @cindex memory leak
2387 Memory analysis tools such as @command{valgrind} can be useful, but
2388 don't complicate a program merely to avoid their false alarms. For
2389 example, if memory is used until just before a process exits, don't
2390 free it simply to silence such a tool.
2391
2392
2393 @node File Usage
2394 @section File Usage
2395 @cindex file usage
2396
2397 Programs should be prepared to operate when @file{/usr} and @file{/etc}
2398 are read-only file systems. Thus, if the program manages log files,
2399 lock files, backup files, score files, or any other files which are
2400 modified for internal purposes, these files should not be stored in
2401 @file{/usr} or @file{/etc}.
2402
2403 There are two exceptions. @file{/etc} is used to store system
2404 configuration information; it is reasonable for a program to modify
2405 files in @file{/etc} when its job is to update the system configuration.
2406 Also, if the user explicitly asks to modify one file in a directory, it
2407 is reasonable for the program to store other files in the same
2408 directory.
2409
2410 @node Writing C
2411 @chapter Making The Best Use of C
2412
2413 This chapter provides advice on how best to use the C language
2414 when writing GNU software.
2415
2416 @menu
2417 * Formatting:: Formatting your source code.
2418 * Comments:: Commenting your work.
2419 * Syntactic Conventions:: Clean use of C constructs.
2420 * Names:: Naming variables, functions, and files.
2421 * System Portability:: Portability among different operating systems.
2422 * CPU Portability:: Supporting the range of CPU types.
2423 * System Functions:: Portability and ``standard'' library functions.
2424 * Internationalization:: Techniques for internationalization.
2425 * Character Set:: Use ASCII by default.
2426 * Quote Characters:: Use "..." or '...' in the C locale.
2427 * Mmap:: How you can safely use @code{mmap}.
2428 @end menu
2429
2430 @node Formatting
2431 @section Formatting Your Source Code
2432 @cindex formatting source code
2433
2434 @cindex line length
2435 @cindex length of source lines
2436 Please keep the length of source lines to 79 characters or less, for
2437 maximum readability in the widest range of environments.
2438
2439 @cindex open brace
2440 @cindex braces, in C source
2441 @cindex function definitions, formatting
2442 It is important to put the open-brace that starts the body of a C
2443 function in column one, so that they will start a defun. Several
2444 tools look for open-braces in column one to find the beginnings of C
2445 functions. These tools will not work on code not formatted that way.
2446
2447 Avoid putting open-brace, open-parenthesis or open-bracket in column
2448 one when they are inside a function, so that they won't start a defun.
2449 The open-brace that starts a @code{struct} body can go in column one
2450 if you find it useful to treat that definition as a defun.
2451
2452 It is also important for function definitions to start the name of the
2453 function in column one. This helps people to search for function
2454 definitions, and may also help certain tools recognize them. Thus,
2455 using Standard C syntax, the format is this:
2456
2457 @example
2458 static char *
2459 concat (char *s1, char *s2)
2460 @{
2461 @dots{}
2462 @}
2463 @end example
2464
2465 If the arguments don't fit nicely on one line,
2466 split it like this:
2467
2468 @example
2469 int
2470 lots_of_args (int an_integer, long a_long, short a_short,
2471 double a_double, float a_float)
2472 @dots{}
2473 @end example
2474
2475 @cindex @code{struct} types, formatting
2476 @cindex @code{enum} types, formatting
2477 For @code{struct} and @code{enum} types, likewise put the braces in
2478 column one, unless the whole contents fits on one line:
2479
2480 @example
2481 struct foo
2482 @{
2483 int a, b;
2484 @}
2485 @exdent @r{or}
2486 struct foo @{ int a, b; @}
2487 @end example
2488
2489 The rest of this section gives our recommendations for other aspects of
2490 C formatting style, which is also the default style of the @code{indent}
2491 program in version 1.2 and newer. It corresponds to the options
2492
2493 @smallexample
2494 -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
2495 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob
2496 @end smallexample
2497
2498 We don't think of these recommendations as requirements, because it
2499 causes no problems for users if two different programs have different
2500 formatting styles.
2501
2502 But whatever style you use, please use it consistently, since a mixture
2503 of styles within one program tends to look ugly. If you are
2504 contributing changes to an existing program, please follow the style of
2505 that program.
2506
2507 For the body of the function, our recommended style looks like this:
2508
2509 @example
2510 if (x < foo (y, z))
2511 haha = bar[4] + 5;
2512 else
2513 @{
2514 while (z)
2515 @{
2516 haha += foo (z, z);
2517 z--;
2518 @}
2519 return ++x + bar ();
2520 @}
2521 @end example
2522
2523 @cindex spaces before open-paren
2524 We find it easier to read a program when it has spaces before the
2525 open-parentheses and after the commas. Especially after the commas.
2526
2527 When you split an expression into multiple lines, split it
2528 before an operator, not after one. Here is the right way:
2529
2530 @cindex expressions, splitting
2531 @example
2532 if (foo_this_is_long && bar > win (x, y, z)
2533 && remaining_condition)
2534 @end example
2535
2536 Try to avoid having two operators of different precedence at the same
2537 level of indentation. For example, don't write this:
2538
2539 @example
2540 mode = (inmode[j] == VOIDmode
2541 || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
2542 ? outmode[j] : inmode[j]);
2543 @end example
2544
2545 Instead, use extra parentheses so that the indentation shows the nesting:
2546
2547 @example
2548 mode = ((inmode[j] == VOIDmode
2549 || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
2550 ? outmode[j] : inmode[j]);
2551 @end example
2552
2553 Insert extra parentheses so that Emacs will indent the code properly.
2554 For example, the following indentation looks nice if you do it by hand,
2555
2556 @example
2557 v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
2558 + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
2559 @end example
2560
2561 @noindent
2562 but Emacs would alter it. Adding a set of parentheses produces
2563 something that looks equally nice, and which Emacs will preserve:
2564
2565 @example
2566 v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
2567 + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
2568 @end example
2569
2570 Format do-while statements like this:
2571
2572 @example
2573 do
2574 @{
2575 a = foo (a);
2576 @}
2577 while (a > 0);
2578 @end example
2579
2580 @cindex formfeed
2581 @cindex control-L
2582 Please use formfeed characters (control-L) to divide the program into
2583 pages at logical places (but not within a function). It does not matter
2584 just how long the pages are, since they do not have to fit on a printed
2585 page. The formfeeds should appear alone on lines by themselves.
2586
2587 @node Comments
2588 @section Commenting Your Work
2589 @cindex commenting
2590
2591 Every program should start with a comment saying briefly what it is for.
2592 Example: @samp{fmt - filter for simple filling of text}. This comment
2593 should be at the top of the source file containing the @samp{main}
2594 function of the program.
2595
2596 Also, please write a brief comment at the start of each source file,
2597 with the file name and a line or two about the overall purpose of the
2598 file.
2599
2600 Please write the comments in a GNU program in English, because English
2601 is the one language that nearly all programmers in all countries can
2602 read. If you do not write English well, please write comments in
2603 English as well as you can, then ask other people to help rewrite them.
2604 If you can't write comments in English, please find someone to work with
2605 you and translate your comments into English.
2606
2607 Please put a comment on each function saying what the function does,
2608 what sorts of arguments it gets, and what the possible values of
2609 arguments mean and are used for. It is not necessary to duplicate in
2610 words the meaning of the C argument declarations, if a C type is being
2611 used in its customary fashion. If there is anything nonstandard about
2612 its use (such as an argument of type @code{char *} which is really the
2613 address of the second character of a string, not the first), or any
2614 possible values that would not work the way one would expect (such as,
2615 that strings containing newlines are not guaranteed to work), be sure
2616 to say so.
2617
2618 Also explain the significance of the return value, if there is one.
2619
2620 Please put two spaces after the end of a sentence in your comments, so
2621 that the Emacs sentence commands will work. Also, please write
2622 complete sentences and capitalize the first word. If a lower-case
2623 identifier comes at the beginning of a sentence, don't capitalize it!
2624 Changing the spelling makes it a different identifier. If you don't
2625 like starting a sentence with a lower case letter, write the sentence
2626 differently (e.g., ``The identifier lower-case is @dots{}'').
2627
2628 The comment on a function is much clearer if you use the argument
2629 names to speak about the argument values. The variable name itself
2630 should be lower case, but write it in upper case when you are speaking
2631 about the value rather than the variable itself. Thus, ``the inode
2632 number NODE_NUM'' rather than ``an inode''.
2633
2634 There is usually no purpose in restating the name of the function in
2635 the comment before it, because readers can see that for themselves.
2636 There might be an exception when the comment is so long that the function
2637 itself would be off the bottom of the screen.
2638
2639 There should be a comment on each static variable as well, like this:
2640
2641 @example
2642 /* Nonzero means truncate lines in the display;
2643 zero means continue them. */
2644 int truncate_lines;
2645 @end example
2646
2647 @cindex conditionals, comments for
2648 @cindex @code{#endif}, commenting
2649 Every @samp{#endif} should have a comment, except in the case of short
2650 conditionals (just a few lines) that are not nested. The comment should
2651 state the condition of the conditional that is ending, @emph{including
2652 its sense}. @samp{#else} should have a comment describing the condition
2653 @emph{and sense} of the code that follows. For example:
2654
2655 @example
2656 @group
2657 #ifdef foo
2658 @dots{}
2659 #else /* not foo */
2660 @dots{}
2661 #endif /* not foo */
2662 @end group
2663 @group
2664 #ifdef foo
2665 @dots{}
2666 #endif /* foo */
2667 @end group
2668 @end example
2669
2670 @noindent
2671 but, by contrast, write the comments this way for a @samp{#ifndef}:
2672
2673 @example
2674 @group
2675 #ifndef foo
2676 @dots{}
2677 #else /* foo */
2678 @dots{}
2679 #endif /* foo */
2680 @end group
2681 @group
2682 #ifndef foo
2683 @dots{}
2684 #endif /* not foo */
2685 @end group
2686 @end example
2687
2688 @node Syntactic Conventions
2689 @section Clean Use of C Constructs
2690 @cindex syntactic conventions
2691
2692 @cindex implicit @code{int}
2693 @cindex function argument, declaring
2694 Please explicitly declare the types of all objects. For example, you
2695 should explicitly declare all arguments to functions, and you should
2696 declare functions to return @code{int} rather than omitting the
2697 @code{int}.
2698
2699 @cindex compiler warnings
2700 @cindex @samp{-Wall} compiler option
2701 Some programmers like to use the GCC @samp{-Wall} option, and change the
2702 code whenever it issues a warning. If you want to do this, then do.
2703 Other programmers prefer not to use @samp{-Wall}, because it gives
2704 warnings for valid and legitimate code which they do not want to change.
2705 If you want to do this, then do. The compiler should be your servant,
2706 not your master.
2707
2708 @pindex clang
2709 @pindex lint
2710 Don't make the program ugly just to placate static analysis tools such
2711 as @command{lint}, @command{clang}, and GCC with extra warnings
2712 options such as @option{-Wconversion} and @option{-Wundef}. These
2713 tools can help find bugs and unclear code, but they can also generate
2714 so many false alarms that it hurts readability to silence them with
2715 unnecessary casts, wrappers, and other complications. For example,
2716 please don't insert casts to @code{void} or calls to do-nothing
2717 functions merely to pacify a lint checker.
2718
2719 Declarations of external functions and functions to appear later in the
2720 source file should all go in one place near the beginning of the file
2721 (somewhere before the first function definition in the file), or else
2722 should go in a header file. Don't put @code{extern} declarations inside
2723 functions.
2724
2725 @cindex temporary variables
2726 It used to be common practice to use the same local variables (with
2727 names like @code{tem}) over and over for different values within one
2728 function. Instead of doing this, it is better to declare a separate local
2729 variable for each distinct purpose, and give it a name which is
2730 meaningful. This not only makes programs easier to understand, it also
2731 facilitates optimization by good compilers. You can also move the
2732 declaration of each local variable into the smallest scope that includes
2733 all its uses. This makes the program even cleaner.
2734
2735 Don't use local variables or parameters that shadow global identifiers.
2736 GCC's @samp{-Wshadow} option can detect this problem.
2737
2738 @cindex multiple variables in a line
2739 Don't declare multiple variables in one declaration that spans lines.
2740 Start a new declaration on each line, instead. For example, instead
2741 of this:
2742
2743 @example
2744 @group
2745 int foo,
2746 bar;
2747 @end group
2748 @end example
2749
2750 @noindent
2751 write either this:
2752
2753 @example
2754 int foo, bar;
2755 @end example
2756
2757 @noindent
2758 or this:
2759
2760 @example
2761 int foo;
2762 int bar;
2763 @end example
2764
2765 @noindent
2766 (If they are global variables, each should have a comment preceding it
2767 anyway.)
2768
2769 When you have an @code{if}-@code{else} statement nested in another
2770 @code{if} statement, always put braces around the @code{if}-@code{else}.
2771 Thus, never write like this:
2772
2773 @example
2774 if (foo)
2775 if (bar)
2776 win ();
2777 else
2778 lose ();
2779 @end example
2780
2781 @noindent
2782 always like this:
2783
2784 @example
2785 if (foo)
2786 @{
2787 if (bar)
2788 win ();
2789 else
2790 lose ();
2791 @}
2792 @end example
2793
2794 If you have an @code{if} statement nested inside of an @code{else}
2795 statement, either write @code{else if} on one line, like this,
2796
2797 @example
2798 if (foo)
2799 @dots{}
2800 else if (bar)
2801 @dots{}
2802 @end example
2803
2804 @noindent
2805 with its @code{then}-part indented like the preceding @code{then}-part,
2806 or write the nested @code{if} within braces like this:
2807
2808 @example
2809 if (foo)
2810 @dots{}
2811 else
2812 @{
2813 if (bar)
2814 @dots{}
2815 @}
2816 @end example
2817
2818 Don't declare both a structure tag and variables or typedefs in the
2819 same declaration. Instead, declare the structure tag separately
2820 and then use it to declare the variables or typedefs.
2821
2822 Try to avoid assignments inside @code{if}-conditions (assignments
2823 inside @code{while}-conditions are ok). For example, don't write
2824 this:
2825
2826 @example
2827 if ((foo = (char *) malloc (sizeof *foo)) == NULL)
2828 fatal ("virtual memory exhausted");
2829 @end example
2830
2831 @noindent
2832 instead, write this:
2833
2834 @example
2835 foo = (char *) malloc (sizeof *foo);
2836 if (foo == NULL)
2837 fatal ("virtual memory exhausted");
2838 @end example
2839
2840 @node Names
2841 @section Naming Variables, Functions, and Files
2842
2843 @cindex names of variables, functions, and files
2844 The names of global variables and functions in a program serve as
2845 comments of a sort. So don't choose terse names---instead, look for
2846 names that give useful information about the meaning of the variable or
2847 function. In a GNU program, names should be English, like other
2848 comments.
2849
2850 Local variable names can be shorter, because they are used only within
2851 one context, where (presumably) comments explain their purpose.
2852
2853 Try to limit your use of abbreviations in symbol names. It is ok to
2854 make a few abbreviations, explain what they mean, and then use them
2855 frequently, but don't use lots of obscure abbreviations.
2856
2857 Please use underscores to separate words in a name, so that the Emacs
2858 word commands can be useful within them. Stick to lower case; reserve
2859 upper case for macros and @code{enum} constants, and for name-prefixes
2860 that follow a uniform convention.
2861
2862 For example, you should use names like @code{ignore_space_change_flag};
2863 don't use names like @code{iCantReadThis}.
2864
2865 Variables that indicate whether command-line options have been
2866 specified should be named after the meaning of the option, not after
2867 the option-letter. A comment should state both the exact meaning of
2868 the option and its letter. For example,
2869
2870 @example
2871 @group
2872 /* Ignore changes in horizontal whitespace (-b). */
2873 int ignore_space_change_flag;
2874 @end group
2875 @end example
2876
2877 When you want to define names with constant integer values, use
2878 @code{enum} rather than @samp{#define}. GDB knows about enumeration
2879 constants.
2880
2881 @cindex file-name limitations
2882 @pindex doschk
2883 You might want to make sure that none of the file names would conflict
2884 if the files were loaded onto an MS-DOS file system which shortens the
2885 names. You can use the program @code{doschk} to test for this.
2886
2887 Some GNU programs were designed to limit themselves to file names of 14
2888 characters or less, to avoid file name conflicts if they are read into
2889 older System V systems. Please preserve this feature in the existing
2890 GNU programs that have it, but there is no need to do this in new GNU
2891 programs. @code{doschk} also reports file names longer than 14
2892 characters.
2893
2894
2895 @node System Portability
2896 @section Portability between System Types
2897 @cindex portability, between system types
2898
2899 In the Unix world, ``portability'' refers to porting to different Unix
2900 versions. For a GNU program, this kind of portability is desirable, but
2901 not paramount.
2902
2903 The primary purpose of GNU software is to run as part of the GNU
2904 operating system, compiled with GNU compilers, on various types of
2905 hardware. So the kinds of portability that are absolutely necessary
2906 are quite limited. It is important to support Linux-based GNU
2907 systems, since they are the form of GNU that people mainly use.
2908
2909 Making a GNU program operate on operating systems other than the GNU
2910 system is not part of the core goal of developing a GNU package. You
2911 don't ever have to do that. However, users will ask you to do that,
2912 and cooperating with those requests is useful---as long as you don't
2913 let it dominate the project or impede the primary goal.
2914
2915 It is good to support the other free or nearly free operating systems
2916 (for instance, *BSD). Supporting a variety of Unix-like systems is
2917 desirable, although not paramount. It is usually not too hard, so you
2918 may as well do it. But you don't have to consider it an obligation,
2919 if it does turn out to be hard.
2920
2921 For the most part it is good to port the program to more platforms,
2922 but you should not let take up so much of your time that it hinders
2923 you from improving the program in more central ways. If it starts to
2924 do that, please tell users that you don't want to spend any more
2925 time on this---someone else must write that code, debug it, document
2926 it, etc., and then you can install it.
2927
2928 You can reject porting patches for technical reasons too, as with any
2929 other patch that users submit. It is up to you.
2930
2931 @pindex autoconf
2932 The easiest way to achieve portability to most Unix-like systems is to
2933 use Autoconf. It's unlikely that your program needs to know more
2934 information about the host platform than Autoconf can provide, simply
2935 because most of the programs that need such knowledge have already been
2936 written.
2937
2938 Avoid using the format of semi-internal data bases (e.g., directories)
2939 when there is a higher-level alternative (@code{readdir}).
2940
2941 @cindex non-POSIX systems, and portability
2942 As for systems that are not like Unix, such as MS-DOS, Windows, VMS, MVS,
2943 and older Macintosh systems, supporting them is often a lot of work.
2944 When that is the case, it is better to spend your time adding features
2945 that will be useful on GNU and GNU/Linux, rather than on supporting
2946 other incompatible systems.
2947
2948 If you do support Windows, please do not abbreviate it as ``win''.
2949 @xref{Trademarks}.
2950
2951 Usually we write the name ``Windows'' in full, but when brevity is
2952 very important (as in file names and some symbol names), we abbreviate
2953 it to ``w''. In GNU Emacs, for instance, we use @samp{w32} in file
2954 names of Windows-specific files, but the macro for Windows
2955 conditionals is called @code{WINDOWSNT}. In principle there could
2956 also be @samp{w64}.
2957
2958 It is a good idea to define the ``feature test macro''
2959 @code{_GNU_SOURCE} when compiling your C files. When you compile on GNU
2960 or GNU/Linux, this will enable the declarations of GNU library extension
2961 functions, and that will usually give you a compiler error message if
2962 you define the same function names in some other way in your program.
2963 (You don't have to actually @emph{use} these functions, if you prefer
2964 to make the program more portable to other systems.)
2965
2966 But whether or not you use these GNU extensions, you should avoid
2967 using their names for any other meanings. Doing so would make it hard
2968 to move your code into other GNU programs.
2969
2970 @node CPU Portability
2971 @section Portability between CPUs
2972
2973 @cindex data types, and portability
2974 @cindex portability, and data types
2975 Even GNU systems will differ because of differences among CPU
2976 types---for example, difference in byte ordering and alignment
2977 requirements. It is absolutely essential to handle these differences.
2978 However, don't make any effort to cater to the possibility that an
2979 @code{int} will be less than 32 bits. We don't support 16-bit machines
2980 in GNU.
2981
2982 You need not cater to the possibility that @code{long} will be smaller
2983 than pointers and @code{size_t}. We know of one such platform: 64-bit
2984 programs on Microsoft Windows. If you care about making your package
2985 run on Windows using Mingw64, you would need to deal with 8-byte
2986 pointers and 4-byte @code{long}, which would break this code:
2987
2988 @example
2989 printf ("size = %lu\n", (unsigned long) sizeof array);
2990 printf ("diff = %ld\n", (long) (pointer2 - pointer1));
2991 @end example
2992
2993 Whether to support Mingw64, and Windows in general, in your package is
2994 your choice. The GNU Project doesn't say you have any responsibility to
2995 do so. Our goal is to replace proprietary systems, including Windows,
2996 not to enhance them. If people pressure you to make your program run
2997 on Windows, and you are not interested, you can respond with, ``Switch
2998 to GNU/Linux --- your freedom depends on it.''
2999
3000 Predefined file-size types like @code{off_t} are an exception: they are
3001 longer than @code{long} on many platforms, so code like the above won't
3002 work with them. One way to print an @code{off_t} value portably is to
3003 print its digits yourself, one by one.
3004
3005 Don't assume that the address of an @code{int} object is also the
3006 address of its least-significant byte. This is false on big-endian
3007 machines. Thus, don't make the following mistake:
3008
3009 @example
3010 int c;
3011 @dots{}
3012 while ((c = getchar ()) != EOF)
3013 write (file_descriptor, &c, 1);
3014 @end example
3015
3016 @noindent Instead, use @code{unsigned char} as follows. (The @code{unsigned}
3017 is for portability to unusual systems where @code{char} is signed and
3018 where there is integer overflow checking.)
3019
3020 @example
3021 int c;
3022 while ((c = getchar ()) != EOF)
3023 @{
3024 unsigned char u = c;
3025 write (file_descriptor, &u, 1);
3026 @}
3027 @end example
3028
3029 @cindex casting pointers to integers
3030 Avoid casting pointers to integers if you can. Such casts greatly
3031 reduce portability, and in most programs they are easy to avoid. In the
3032 cases where casting pointers to integers is essential---such as, a Lisp
3033 interpreter which stores type information as well as an address in one
3034 word---you'll have to make explicit provisions to handle different word
3035 sizes. You will also need to make provision for systems in which the
3036 normal range of addresses you can get from @code{malloc} starts far away
3037 from zero.
3038
3039
3040 @node System Functions
3041 @section Calling System Functions
3042
3043 @cindex C library functions, and portability
3044 @cindex POSIX functions, and portability
3045 @cindex library functions, and portability
3046 @cindex portability, and library functions
3047
3048 Historically, C implementations differed substantially, and many
3049 systems lacked a full implementation of ANSI/ISO C89. Nowadays,
3050 however, all practical systems have a C89-or-later compiler and GNU C
3051 supports almost all of C23 (with options to select older versions of
3052 the standard). Similarly, most systems implement POSIX.1-2008
3053 libraries and tools, and many have POSIX.1-2017.
3054
3055 Hence, there is little reason to support old C or non-POSIX systems,
3056 and you may want to take advantage of standard C and POSIX to write
3057 clearer, more portable, or faster code. You should use standard
3058 interfaces where possible; but if GNU extensions make your program
3059 more maintainable, powerful, or otherwise better, don't hesitate to
3060 use them. In any case, don't make your own declaration of system
3061 functions; that's a recipe for conflict.
3062
3063 Despite the standards, nearly every library function has some sort of
3064 portability issue on some system or another. Here are some examples:
3065
3066 @table @code
3067 @item open
3068 Names with trailing @code{/}'s are mishandled on many platforms.
3069
3070 @item printf
3071 @code{long double} may be unimplemented; floating values Infinity and
3072 NaN are often mishandled; output for large precisions may be
3073 incorrect.
3074
3075 @item readlink
3076 May return @code{int} instead of @code{ssize_t}.
3077
3078 @item scanf
3079 On Windows, @code{errno} is not set on failure.
3080 @end table
3081
3082 @cindex Gnulib
3083 @uref{https://www.gnu.org/software/gnulib/, Gnulib} is a big help in
3084 this regard. Gnulib provides implementations of standard interfaces
3085 on many of the systems that lack them, including portable
3086 implementations of enhanced GNU interfaces, thereby making their use
3087 portable, and of POSIX interfaces, some of which are missing
3088 even on up-to-date GNU systems.
3089
3090 @findex xmalloc, in Gnulib
3091 @findex error messages, in Gnulib
3092 @findex data structures, in Gnulib
3093 Gnulib also provides many useful non-standard interfaces; for example,
3094 C implementations of standard data structures (hash tables, binary
3095 trees), error-checking wrappers for memory allocation
3096 functions (@code{xmalloc}, @code{xrealloc}), and output of error
3097 messages.
3098
3099 Gnulib integrates with GNU Autoconf and Automake to remove much of the
3100 burden of writing portable code from the programmer: Gnulib makes your
3101 configure script automatically determine what features are missing and
3102 use the Gnulib code to supply the missing pieces.
3103
3104 The Gnulib and Autoconf manuals have extensive sections on
3105 portability: @ref{Top,, Introduction, gnulib, Gnulib} and
3106 @pxref{Portable C and C++,,, autoconf, Autoconf}. Please consult them
3107 for many more details.
3108
3109
3110 @node Internationalization
3111 @section Internationalization
3112 @cindex internationalization
3113
3114 @pindex gettext
3115 GNU has a library called GNU gettext that makes it easy to translate the
3116 messages in a program into various languages. You should use this
3117 library in every program. Use English for the messages as they appear
3118 in the program, and let gettext provide the way to translate them into
3119 other languages.
3120
3121 Using GNU gettext involves putting a call to the @code{gettext} macro
3122 around each string that might need translation---like this:
3123
3124 @example
3125 printf (gettext ("Processing file '%s'..."), file);
3126 @end example
3127
3128 @noindent
3129 This permits GNU gettext to replace the string @code{"Processing file
3130 '%s'..."} with a translated version.
3131
3132 Once a program uses gettext, please make a point of writing calls to
3133 @code{gettext} when you add new strings that call for translation.
3134
3135 Using GNU gettext in a package involves specifying a @dfn{text domain
3136 name} for the package. The text domain name is used to separate the
3137 translations for this package from the translations for other packages.
3138 Normally, the text domain name should be the same as the name of the
3139 package---for example, @samp{coreutils} for the GNU core utilities.
3140
3141 @cindex message text, and internationalization
3142 To enable gettext to work well, avoid writing code that makes
3143 assumptions about the structure of words or sentences. When you want
3144 the precise text of a sentence to vary depending on the data, use two or
3145 more alternative string constants each containing a complete sentences,
3146 rather than inserting conditionalized words or phrases into a single
3147 sentence framework.
3148
3149 Here is an example of what not to do:
3150
3151 @smallexample
3152 printf ("%s is full", capacity > 5000000 ? "disk" : "floppy disk");
3153 @end smallexample
3154
3155 If you apply gettext to all strings, like this,
3156
3157 @smallexample
3158 printf (gettext ("%s is full"),
3159 capacity > 5000000 ? gettext ("disk") : gettext ("floppy disk"));
3160 @end smallexample
3161
3162 @noindent
3163 the translator will hardly know that "disk" and "floppy disk" are meant to
3164 be substituted in the other string. Worse, in some languages (like French)
3165 the construction will not work: the translation of the word "full" depends
3166 on the gender of the first part of the sentence; it happens to be not the
3167 same for "disk" as for "floppy disk".
3168
3169 Complete sentences can be translated without problems:
3170
3171 @example
3172 printf (capacity > 5000000 ? gettext ("disk is full")
3173 : gettext ("floppy disk is full"));
3174 @end example
3175
3176 A similar problem appears at the level of sentence structure with this
3177 code:
3178
3179 @example
3180 printf ("# Implicit rule search has%s been done.\n",
3181 f->tried_implicit ? "" : " not");
3182 @end example
3183
3184 @noindent
3185 Adding @code{gettext} calls to this code cannot give correct results for
3186 all languages, because negation in some languages requires adding words
3187 at more than one place in the sentence. By contrast, adding
3188 @code{gettext} calls does the job straightforwardly if the code starts
3189 out like this:
3190
3191 @example
3192 printf (f->tried_implicit
3193 ? "# Implicit rule search has been done.\n",
3194 : "# Implicit rule search has not been done.\n");
3195 @end example
3196
3197 Another example is this one:
3198
3199 @example
3200 printf ("%d file%s processed", nfiles,
3201 nfiles != 1 ? "s" : "");
3202 @end example
3203
3204 @noindent
3205 The problem with this example is that it assumes that plurals are made
3206 by adding `s'. If you apply gettext to the format string, like this,
3207
3208 @example
3209 printf (gettext ("%d file%s processed"), nfiles,
3210 nfiles != 1 ? "s" : "");
3211 @end example
3212
3213 @noindent
3214 the message can use different words, but it will still be forced to use
3215 `s' for the plural. Here is a better way, with gettext being applied to
3216 the two strings independently:
3217
3218 @example
3219 printf ((nfiles != 1 ? gettext ("%d files processed")
3220 : gettext ("%d file processed")),
3221 nfiles);
3222 @end example
3223
3224 @noindent
3225 But this still doesn't work for languages like Polish, which has three
3226 plural forms: one for nfiles == 1, one for nfiles == 2, 3, 4, 22, 23, 24, ...
3227 and one for the rest. The GNU @code{ngettext} function solves this problem:
3228
3229 @example
3230 printf (ngettext ("%d files processed", "%d file processed", nfiles),
3231 nfiles);
3232 @end example
3233
3234
3235 @node Character Set
3236 @section Character Set
3237 @cindex character set
3238 @cindex encodings
3239 @cindex ASCII characters
3240 @cindex non-ASCII characters
3241
3242 Sticking to the ASCII character set (plain text, 7-bit characters) is
3243 preferred in GNU source code comments, text documents, and other
3244 contexts, unless there is good reason to do something else because of
3245 the application domain. For example, if source code deals with the
3246 French Revolutionary calendar, it is OK if its literal strings contain
3247 accented characters in month names like ``Flor@'eal''. Also, it is OK
3248 (but not required) to use non-ASCII characters to represent proper
3249 names of contributors in change logs (@pxref{Change Logs}).
3250
3251 If you need to use non-ASCII characters, you should normally stick
3252 with one encoding, certainly within a single file. UTF-8 is likely to
3253 be the best choice.
3254
3255
3256 @node Quote Characters
3257 @section Quote Characters
3258 @cindex quote characters
3259 @cindex locale-specific quote characters
3260 @cindex left quote
3261 @cindex right quote
3262 @cindex opening quote
3263 @cindex single quote
3264 @cindex double quote
3265 @cindex grave accent
3266 @set txicodequoteundirected
3267 @set txicodequotebacktick
3268
3269 In the C locale, the output of GNU programs should stick to plain
3270 ASCII for quotation characters in messages to users: preferably 0x22
3271 (@samp{"}) or 0x27 (@samp{'}) for both opening and closing quotes.
3272 Although GNU programs traditionally used 0x60 (@samp{`}) for opening
3273 and 0x27 (@samp{'}) for closing quotes, nowadays quotes @samp{`like
3274 this'} are typically rendered asymmetrically, so quoting @samp{"like
3275 this"} or @samp{'like this'} typically looks better.
3276
3277 It is ok, but not required, for GNU programs to generate
3278 locale-specific quotes in non-C locales. For example:
3279
3280 @example
3281 printf (gettext ("Processing file '%s'..."), file);
3282 @end example
3283
3284 @noindent
3285 Here, a French translation might cause @code{gettext} to return the
3286 string @code{"Traitement de fichier
3287 @guilsinglleft{}@tie{}%s@tie{}@guilsinglright{}..."}, yielding quotes
3288 more appropriate for a French locale.
3289
3290 Sometimes a program may need to use opening and closing quotes
3291 directly. By convention, @code{gettext} translates the string
3292 @samp{"`"} to the opening quote and the string @samp{"'"} to the
3293 closing quote, and a program can use these translations. Generally,
3294 though, it is better to translate quote characters in the context of
3295 longer strings.
3296
3297 If the output of your program is ever likely to be parsed by another
3298 program, it is good to provide an option that makes this parsing
3299 reliable. For example, you could escape special characters using
3300 conventions from the C language or the Bourne shell. See for example
3301 the option @option{--quoting-style} of GNU @code{ls}.
3302
3303 @clear txicodequoteundirected
3304 @clear txicodequotebacktick
3305
3306
3307 @node Mmap
3308 @section Mmap
3309 @findex mmap
3310
3311 If you use @code{mmap} to read or write files, don't assume it either
3312 works on all files or fails for all files. It may work on some files
3313 and fail on others.
3314
3315 The proper way to use @code{mmap} is to try it on the specific file for
3316 which you want to use it---and if @code{mmap} doesn't work, fall back on
3317 doing the job in another way using @code{read} and @code{write}.
3318
3319 The reason this precaution is needed is that the GNU kernel (the HURD)
3320 provides a user-extensible file system, in which there can be many
3321 different kinds of ``ordinary files''. Many of them support
3322 @code{mmap}, but some do not. It is important to make programs handle
3323 all these kinds of files.
3324
3325
3326 @node Documentation
3327 @chapter Documenting Programs
3328 @cindex documentation
3329
3330 A GNU program should ideally come with full free documentation, adequate
3331 for both reference and tutorial purposes. If the package can be
3332 programmed or extended, the documentation should cover programming or
3333 extending it, as well as just using it.
3334
3335 @menu
3336 * GNU Manuals:: Writing proper manuals.
3337 * Doc Strings and Manuals:: Compiling doc strings doesn't make a manual.
3338 * Manual Structure Details:: Specific structure conventions.
3339 * License for Manuals:: Writing the distribution terms for a manual.
3340 * Manual Credits:: Giving credit to documentation contributors.
3341 * Printed Manuals:: Mentioning the printed manual.
3342 * NEWS File:: NEWS files supplement manuals.
3343 * Change Logs:: Recording changes.
3344 * Man Pages:: Man pages are secondary.
3345 * Reading other Manuals:: How far you can go in learning
3346 from other manuals.
3347 @end menu
3348
3349 @node GNU Manuals
3350 @section GNU Manuals
3351
3352 The preferred document format for the GNU system is the Texinfo
3353 formatting language. Every GNU package should (ideally) have
3354 documentation in Texinfo both for reference and for learners. Texinfo
3355 makes it possible to produce a good quality formatted book, using
3356 @TeX{}, and to generate an Info file. It is also possible to generate
3357 HTML output from Texinfo source. See the Texinfo manual, either the
3358 hardcopy, or the on-line version available through @code{info} or the
3359 Emacs Info subsystem (@kbd{C-h i}).
3360
3361 Nowadays some other formats such as Docbook and Sgmltexi can be
3362 converted automatically into Texinfo. It is ok to produce the Texinfo
3363 documentation by conversion this way, as long as it gives good results.
3364
3365 Make sure your manual is clear to a reader who knows nothing about the
3366 topic and reads it straight through. This means covering basic topics
3367 at the beginning, and advanced topics only later. This also means
3368 defining every specialized term when it is first used.
3369
3370 Remember that the audience for a GNU manual (and other GNU
3371 documentation) is global, and that it will be used for years, maybe
3372 decades. This means that the reader could have very different cultural
3373 reference points. Decades from now, all but old folks will have very
3374 different cultural reference points; many things that "everyone knows
3375 about" today may be mostly forgotten.
3376
3377 For this reason, try to avoid writing in a way that depends on
3378 cultural reference points for proper understanding, or that refers to them in
3379 ways that would impede reading for someone that doesn't recognize them.
3380
3381 Likewise, be conservative in your choice of words (aside from technical
3382 terms), linguistic constructs, and spelling: aim to make them
3383 intelligible to readers from ten years ago. In any contest for
3384 trendiness, GNU writing should not even qualify to enter.
3385
3386 It is ok to refer once in a rare while to spatially or temporally
3387 localized reference points or facts, if it is directly pertinent or as
3388 an aside. Changing these few things (which in any case stand out) when
3389 they no longer make sense will not be a lot of work.
3390
3391 By contrast, it is always proper to refer to concepts of GNU and the
3392 free software movement, when they are pertinent. These are a central
3393 part of our message, so we should take advantage of opportunities to
3394 mention them. They are fundamental moral positions, so they will
3395 rarely if ever change.
3396
3397 Programmers tend to carry over the structure of the program as the
3398 structure for its documentation. But this structure is not
3399 necessarily good for explaining how to use the program; it may be
3400 irrelevant and confusing for a user.
3401
3402 Instead, the right way to structure documentation is according to the
3403 concepts and questions that a user will have in mind when reading it.
3404 This principle applies at every level, from the lowest (ordering
3405 sentences in a paragraph) to the highest (ordering of chapter topics
3406 within the manual). Sometimes this structure of ideas matches the
3407 structure of the implementation of the software being documented---but
3408 often they are different. An important part of learning to write good
3409 documentation is to learn to notice when you have unthinkingly
3410 structured the documentation like the implementation, stop yourself,
3411 and look for better alternatives.
3412
3413 For example, each program in the GNU system probably ought to be
3414 documented in one manual; but this does not mean each program should
3415 have its own manual. That would be following the structure of the
3416 implementation, rather than the structure that helps the user
3417 understand.
3418
3419 Instead, each manual should cover a coherent @emph{topic}. For example,
3420 instead of a manual for @code{diff} and a manual for @code{diff3}, we
3421 have one manual for ``comparison of files'' which covers both of those
3422 programs, as well as @code{cmp}. By documenting these programs
3423 together, we can make the whole subject clearer.
3424
3425 The manual which discusses a program should certainly document all of
3426 the program's command-line options and all of its commands. It should
3427 give examples of their use. But don't organize the manual as a list
3428 of features. Instead, organize it logically, by subtopics. Address
3429 the questions that a user will ask when thinking about the job that
3430 the program does. Don't just tell the reader what each feature can
3431 do---say what jobs it is good for, and show how to use it for those
3432 jobs. Explain what is recommended usage, and what kinds of usage
3433 users should avoid.
3434
3435 In general, a GNU manual should serve both as tutorial and reference.
3436 It should be set up for convenient access to each topic through Info,
3437 and for reading straight through (appendixes aside). A GNU manual
3438 should give a good introduction to a beginner reading through from the
3439 start, and should also provide all the details that hackers want.
3440 The Bison manual is a good example of this---please take a look at it
3441 to see what we mean.
3442
3443 That is not as hard as it first sounds. Arrange each chapter as a
3444 logical breakdown of its topic, but order the sections, and write their
3445 text, so that reading the chapter straight through makes sense. Do
3446 likewise when structuring the book into chapters, and when structuring a
3447 section into paragraphs. The watchword is, @emph{at each point, address
3448 the most fundamental and important issue raised by the preceding text.}
3449
3450 If necessary, add extra chapters at the beginning of the manual which
3451 are purely tutorial and cover the basics of the subject. These provide
3452 the framework for a beginner to understand the rest of the manual. The
3453 Bison manual provides a good example of how to do this.
3454
3455 To serve as a reference, a manual should have an Index that lists all
3456 the functions, variables, options, and important concepts that are
3457 part of the program. One combined Index should do for a short manual,
3458 but sometimes for a complex package it is better to use multiple
3459 indices. The Texinfo manual includes advice on preparing good index
3460 entries, see @ref{Index Entries, , Making Index Entries, texinfo, GNU
3461 Texinfo}, and see @ref{Indexing Commands, , Defining the Entries of an
3462 Index, texinfo, GNU Texinfo}.
3463
3464 Don't use Unix man pages as a model for how to write GNU documentation;
3465 most of them are terse, badly structured, and give inadequate
3466 explanation of the underlying concepts. (There are, of course, some
3467 exceptions.) Also, Unix man pages use a particular format which is
3468 different from what we use in GNU manuals.
3469
3470 Please include an email address in the manual for where to report
3471 bugs @emph{in the text of the manual}.
3472
3473 Please do not use the term ``pathname'' that is used in Unix
3474 documentation; use ``file name'' (two words) instead. We use the term
3475 ``path'' only for search paths, which are lists of directory names.
3476
3477 Please do not use the term ``illegal'' to refer to erroneous input to
3478 a computer program. Please use ``invalid'' for this, and reserve the
3479 term ``illegal'' for activities prohibited by law.
3480
3481 Please do not write @samp{()} after a function name just to indicate
3482 it is a function. @code{foo ()} is not a function, it is a function
3483 call with no arguments.
3484
3485 Whenever possible, please stick to the active voice, avoiding the
3486 passive, and use the present tense, not the future tense. For
3487 instance, write ``The function @code{foo} returns a list containing
3488 @var{a} and @var{b}'' rather than ``A list containing @var{a} and
3489 @var{b} will be returned.'' One advantage of the active voice is it
3490 requires you to state the subject of the sentence; with the passive
3491 voice, you might omit the subject, which leads to vagueness.
3492
3493 It is proper to use the future tense when grammar demands it, as in,
3494 ``If you type @kbd{x}, the computer will self-destruct in 10
3495 seconds.''
3496
3497 @node Doc Strings and Manuals
3498 @section Doc Strings and Manuals
3499
3500 Some programming systems, such as Emacs, provide a documentation string
3501 for each function, command or variable. You may be tempted to write a
3502 reference manual by compiling the documentation strings and writing a
3503 little additional text to go around them---but you must not do it. That
3504 approach is a fundamental mistake. The text of well-written
3505 documentation strings will be entirely wrong for a manual.
3506
3507 A documentation string needs to stand alone---when it appears on the
3508 screen, there will be no other text to introduce or explain it.
3509 Meanwhile, it can be rather informal in style.
3510
3511 The text describing a function or variable in a manual must not stand
3512 alone; it appears in the context of a section or subsection. Other text
3513 at the beginning of the section should explain some of the concepts, and
3514 should often make some general points that apply to several functions or
3515 variables. The previous descriptions of functions and variables in the
3516 section will also have given information about the topic. A description
3517 written to stand alone would repeat some of that information; this
3518 redundancy looks bad. Meanwhile, the informality that is acceptable in
3519 a documentation string is totally unacceptable in a manual.
3520
3521 The only good way to use documentation strings in writing a good manual
3522 is to use them as a source of information for writing good text.
3523
3524 @node Manual Structure Details
3525 @section Manual Structure Details
3526 @cindex manual structure
3527
3528 The title page of the manual should state the version of the programs or
3529 packages documented in the manual. The Top node of the manual should
3530 also contain this information. If the manual is changing more
3531 frequently than or independent of the program, also state a version
3532 number for the manual in both of these places.
3533
3534 Each program documented in the manual should have a node named
3535 @samp{@var{program} Invocation} or @samp{Invoking @var{program}}. This
3536 node (together with its subnodes, if any) should describe the program's
3537 command line arguments and how to run it (the sort of information people
3538 would look for in a man page). Start with an @samp{@@example}
3539 containing a template for all the options and arguments that the program
3540 uses.
3541
3542 Alternatively, put a menu item in some menu whose item name fits one of
3543 the above patterns. This identifies the node which that item points to
3544 as the node for this purpose, regardless of the node's actual name.
3545
3546 The @samp{--usage} feature of the Info reader looks for such a node
3547 or menu item in order to find the relevant text, so it is essential
3548 for every Texinfo file to have one.
3549
3550 If one manual describes several programs, it should have such a node for
3551 each program described in the manual.
3552
3553 @node License for Manuals
3554 @section License for Manuals
3555 @cindex license for manuals
3556
3557 Please use the GNU Free Documentation License for all GNU manuals that
3558 are more than a few pages long. Likewise for a collection of short
3559 documents---you only need one copy of the GNU FDL for the whole
3560 collection. For a single short document, you can use a very permissive
3561 non-copyleft license, to avoid taking up space with a long license.
3562
3563 See @uref{https://www.gnu.org/copyleft/fdl-howto.html} for more explanation
3564 of how to employ the GFDL.
3565
3566 Note that it is not obligatory to include a copy of the GNU GPL or GNU
3567 LGPL in a manual whose license is neither the GPL nor the LGPL@. It can
3568 be a good idea to include the program's license in a large manual; in a
3569 short manual, whose size would be increased considerably by including
3570 the program's license, it is probably better not to include it.
3571
3572 @node Manual Credits
3573 @section Manual Credits
3574 @cindex credits for manuals
3575
3576 Please credit the principal human writers of the manual as the authors,
3577 on the title page of the manual. If a company sponsored the work, thank
3578 the company in a suitable place in the manual, but do not cite the
3579 company as an author.
3580
3581 @node Printed Manuals
3582 @section Printed Manuals
3583
3584 The FSF publishes some GNU manuals in printed form. To encourage sales
3585 of these manuals, the on-line versions of the manual should mention at
3586 the very start that the printed manual is available and should point at
3587 information for getting it---for instance, with a link to the page
3588 @url{https://www.gnu.org/order/order.html}. This should not be included
3589 in the printed manual, though, because there it is redundant.
3590
3591 It is also useful to explain in the on-line forms of the manual how the
3592 user can print out the manual from the sources.
3593
3594 @node NEWS File
3595 @section The NEWS File
3596 @cindex @file{NEWS} file
3597
3598 In addition to its manual, the package should have a file named
3599 @file{NEWS} which contains a list of user-visible changes worth
3600 mentioning. In each new release, add items to the front of the file and
3601 identify the version they pertain to. Don't discard old items; leave
3602 them in the file after the newer items. This way, a user upgrading from
3603 any previous version can see what is new.
3604
3605 If the @file{NEWS} file gets very long, move some of the older items
3606 into a file named @file{ONEWS} and put a note at the end referring the
3607 user to that file.
3608
3609 @node Change Logs
3610 @section Change Logs
3611 @cindex change logs
3612
3613 Keep a change log to describe all the changes made to program source
3614 files. The purpose of this is so that people investigating bugs in the
3615 future will know about the changes that might have introduced the bug.
3616 Often a new bug can be found by looking at what was recently changed.
3617 More importantly, change logs can help you eliminate conceptual
3618 inconsistencies between different parts of a program, by giving you a
3619 history of how the conflicting concepts arose, who they came from, and
3620 why the conflicting changes were made.
3621
3622 @cindex software forensics, and change logs
3623 Therefore, change logs should be detailed enough and accurate enough
3624 to provide the information commonly required for such @dfn{software
3625 forensics}. Specifically, change logs should make finding answers to
3626 the following questions easy:
3627
3628 @itemize @bullet
3629 @item
3630 What changes affected a particular source file?
3631
3632 @item
3633 Was a particular source file renamed or moved, and if so, as part of
3634 what change?
3635
3636 @item
3637 What changes affected a given function or macro or definition of a
3638 data structure?
3639
3640 @item
3641 Was a function (or a macro or the definition of a data structure)
3642 renamed or moved from another file, and if so, as part of which
3643 change?
3644
3645 @item
3646 What changes deleted a function (or macro or data structure)?
3647
3648 @item
3649 What was the rationale for a given change, and what were its main
3650 ideas?
3651
3652 @item
3653 Is there any additional information regarding the change, and if so,
3654 where can it be found?
3655 @end itemize
3656
3657 @cindex VCS
3658 @cindex version control system, for keeping change logs
3659 Historically, change logs were maintained on specially formatted
3660 files. Nowadays, projects commonly keep their source files under a
3661 @dfn{version control system} (VCS), such as Git,
3662 Subversion, or Mercurial. If the VCS repository is publicly
3663 accessible, and changes are committed to it separately (one commit for
3664 each logical changeset) and record the authors of each change, then
3665 the information recorded by the VCS can be used to produce
3666 the change logs out of VCS logs, and to answer the above
3667 questions by using the suitable VCS commands. (However, the
3668 VCS log messages still need to provide some supporting
3669 information, as described below.) Projects that maintain such
3670 VCS repositories can decide not to maintain separate change
3671 log files, and instead rely on the VCS to keep the change
3672 logs.
3673
3674 If you decide not to maintain separate change log files, you should
3675 still consider providing them in the release tarballs, for the benefit
3676 of users who'd like to review the change logs without accessing the
3677 project's VCS repository. Scripts exist that can produce
3678 @file{ChangeLog} files from the VCS logs; for example, the
3679 @file{gitlog-to-changelog} script, which is part of Gnulib, can do
3680 that for Git repositories. In Emacs, the command @kbd{C-x v a}
3681 (@code{vc-update-change-log}) does the job of incrementally updating a
3682 @file{ChangeLog} file from the VCS logs.
3683
3684 If separate change log files @emph{are} maintained, they are normally
3685 called @file{ChangeLog}, and each such file covers an entire
3686 directory. Each directory can have its own change log file, or a
3687 directory can use the change log of its parent directory---it's up to
3688 you.
3689
3690 @menu
3691 * Change Log Concepts::
3692 * Style of Change Logs::
3693 * Simple Changes::
3694 * Conditional Changes::
3695 * Indicating the Part Changed::
3696 @end menu
3697
3698 @node Change Log Concepts
3699 @subsection Change Log Concepts and Conventions
3700
3701 @cindex changeset, in a change log
3702 @cindex batch of changes, in a change log
3703 You can think of the change log as a conceptual ``undo list'' which
3704 states how earlier versions were different from the current version.
3705 People can see the current version; they don't need the change log to
3706 tell them what is in it. What they want from a change log is a clear
3707 explanation of how the earlier version differed. Each @dfn{entry} in
3708 a change log describes either an individual change or the smallest
3709 batch of changes that belong together, also known as a @dfn{changeset}.
3710
3711 @cindex title, change log entry
3712 @cindex header line, change log entry
3713 It is a good idea to start the change log entry with a @dfn{header
3714 line}: a single line that is a complete sentence which summarizes the
3715 changeset. If you keep the change log in a VCS, this
3716 should be a requirement, as VCS commands that show the
3717 change log in abbreviated form, such as @kbd{git log --oneline}, treat
3718 the header line specially. (In a @file{ChangeLog} file, the header
3719 line follows a line that says who was the author of the change and
3720 when it was installed.)
3721
3722 @cindex description, change log entry
3723 Follow the change log entry's header line with a description of the
3724 overall change. This should be as long as needed to give a clear
3725 description. Pay special attention to aspects of the changeset not
3726 easily gleaned from the diffs or from the names of modified files and
3727 functions: the overall idea of the change and the need for it, and the
3728 relations, if any, between changes made to different files/functions.
3729 If the change or its reasons were discussed on some public forum, such
3730 as the project's issue tracker or mailing list, it is a good idea to
3731 summarize the main points of that discussion in the change's
3732 description, and include a pointer to that discussion or the issue ID
3733 for those who'd like to read it in full.
3734
3735 The best place to explain how parts of the new code work with other code
3736 is in comments in the code, not in the change log.
3737
3738 If you think that a change calls for explanation of @emph{why} the
3739 change was needed---that is, what problem the old code had such that
3740 it required this change---you're probably right. Please put the
3741 explanation in comments in the code, where people will see it whenever
3742 they see the code. An example of such an explanation is, ``This
3743 function used to be iterative, but that failed when MUMBLE was a
3744 tree.'' (Though such a simple reason would not need this kind of
3745 explanation.)
3746
3747 The best place for other kinds of explanation of the change is in the
3748 change log entry. In particular, comments usually will not say why
3749 some code was deleted or moved to another place---that belongs to the
3750 description of the change which did that.
3751
3752 Following the free-text description of the change, it is a good idea
3753 to give a list of names of the entities or definitions that you
3754 changed, according to the files they are in, and what was changed in
3755 each one. @xref{Style of Change Logs}. If a project uses a modern
3756 VCS to keep the change log information, as described in
3757 @ref{Change Logs}, explicitly listing the files and functions that
3758 were changed is not strictly necessary, and in some cases (like
3759 identical mechanical changes in many places) even tedious. It is up
3760 to you to decide whether to allow your project's developers to omit
3761 the list of changed files and functions from the log entries, and
3762 whether to allow such omissions under some specific conditions.
3763 However, while making this decision, please consider the following
3764 benefits of providing the list of changed entities with each change:
3765
3766 @itemize @bullet
3767 @item
3768 Generation of useful @file{ChangeLog} files from VCS logs
3769 becomes more difficult if the change log entries don't list the
3770 modified functions/macros, because VCS commands cannot
3771 reliably reproduce their names from the commit information alone. For
3772 example, when there is a change in the header part of a function
3773 definition, the heading of the diff hunk as shown in the VCS log
3774 commands will name the wrong function as being modified (usually, the
3775 function defined before the one being modified), so using those diffs
3776 to glean the names of the modified functions will produce inaccurate
3777 results. You will need to use specialized scripts, such as gnulib's
3778 @file{vcs-to-changelog.py}, mentioned below, to solve these
3779 difficulties, and make sure it supports the source languages used by
3780 your project.
3781
3782 @item
3783 While modern VCS commands, such as Git's @kbd{git log -L}
3784 and @kbd{git log -G}, provide powerful means for finding changes that
3785 affected a certain function or macro or data structure (and thus might
3786 make @file{ChangeLog} files unnecessary if you have the repository
3787 available), they can sometimes fail. For example, @kbd{git log -L}
3788 doesn't support syntax of some programming languages out of the box.
3789 Mentioning the modified functions/macros explicitly allows finding the
3790 related changes simply and reliably.
3791
3792 @item
3793 Some VCS commands have difficulties or limitations when
3794 tracking changes across file moves or renames. Again, if the entities
3795 are mentioned explicitly, those difficulties can be overcome.
3796
3797 @item
3798 Users that review changes using the generated @file{ChangeLog} files
3799 may not have the repository and the VCS commands available
3800 to them. Naming the modified entities alleviates that problem.
3801 @end itemize
3802
3803 @noindent
3804 For these reasons, providing lists of modified files and functions
3805 with each change makes the change logs more useful, and we therefore
3806 recommend to include them whenever possible and practical.
3807
3808 It is also possible to generate the lists naming the modified entities
3809 by running a script. One such script is @file{mklog.py} (written in
3810 Python 3); it is used by the @code{GCC} project. Gnulib provides
3811 another variant of such a script, called @file{vcs-to-changelog.py},
3812 part of the @code{vcs-to-changelog} module. Note that these scripts
3813 currently support fewer programming languages than the manual commands
3814 provided by Emacs (@pxref{Style of Change Logs}). Therefore, the
3815 above mentioned method of generating the @code{ChangeLog} file from
3816 the VCS commit history, for instance via the
3817 @code{gitlog-to-changelog} script, usually gives better
3818 results---provided that the contributors stick to providing good
3819 commit messages.
3820
3821 @node Style of Change Logs
3822 @subsection Style of Change Logs
3823 @cindex change logs, style
3824
3825 Here are some simple examples of change log entries, starting with the
3826 header line that says who made the change and when it was installed,
3827 followed by descriptions of specific changes. (These examples are
3828 drawn from Emacs.) Keep in mind that the line which shows the date of
3829 the change and the author's name and email address is needed only in a
3830 separate @file{ChangeLog} file, not when the change logs are kept in a
3831 VCS.
3832
3833 @example
3834 2019-08-29 Noam Postavsky <npostavs@@gmail.com>
3835
3836 Handle completely undecoded input in term (Bug#29918)
3837
3838 * lisp/term.el (term-emulate-terminal): Avoid errors if the whole
3839 decoded string is eight-bit characters. Don't attempt to save the
3840 string for next iteration in that case.
3841 * test/lisp/term-tests.el (term-decode-partial)
3842 (term-undecodable-input): New tests.
3843
3844 2019-06-15 Paul Eggert <eggert@@cs.ucla.edu>
3845
3846 Port to platforms where tputs is in libtinfow
3847
3848 * configure.ac (tputs_library): Also try tinfow, ncursesw (Bug#33977).
3849
3850 2019-02-08 Eli Zaretskii <eliz@@gnu.org>
3851
3852 Improve documentation of 'date-to-time' and 'parse-time-string'
3853
3854 * doc/lispref/os.texi (Time Parsing): Document
3855 'parse-time-string', and refer to it for the description of
3856 the argument of 'date-to-time'.
3857
3858 * lisp/calendar/time-date.el (date-to-time): Refer in the doc
3859 string to 'parse-time-string' for more information about the
3860 format of the DATE argument. (Bug#34303)
3861 @end example
3862
3863 If you mention the names of the modified functions or variables, it's
3864 important to name them in full. Don't abbreviate function or variable
3865 names, and don't combine them. Subsequent maintainers will often
3866 search for a function name to find all the change log entries that
3867 pertain to it; if you abbreviate the name, they won't find it when
3868 they search.
3869
3870 For example, some people are tempted to abbreviate groups of function
3871 names by writing @samp{* register.el (@{insert,jump-to@}-register)};
3872 this is not a good idea, since searching for @code{jump-to-register} or
3873 @code{insert-register} would not find that entry.
3874
3875 Separate unrelated change log entries with blank lines. Don't put
3876 blank lines between individual changes of an entry. You can omit the
3877 file name and the asterisk when successive individual changes are in
3878 the same file.
3879
3880 Break long lists of function names by closing continued lines with
3881 @samp{)}, rather than @samp{,}, and opening the continuation with
3882 @samp{(}. This makes highlighting in Emacs work better.
3883 Here is an example:
3884
3885 @example
3886 * src/keyboard.c (menu_bar_items, tool_bar_items)
3887 (Fexecute_extended_command): Deal with 'keymap' property.
3888 @end example
3889
3890 The easiest way to add an entry to @file{ChangeLog} is with the Emacs
3891 command @kbd{M-x add-change-log-entry}, or its variant @kbd{C-x 4 a}
3892 (@code{add-change-log-entry-other-window}). This automatically
3893 collects the name of the changed file and the changed function or
3894 variable, and formats a change log entry according to the conventions
3895 described above, leaving it up to you to describe the changes you made
3896 to that function or variable.
3897
3898 When you install someone else's changes, put the contributor's name in
3899 the change log entry rather than in the text of the entry. In other
3900 words, write this:
3901
3902 @example
3903 2002-07-14 John Doe <jdoe@@gnu.org>
3904
3905 * sewing.c: Make it sew.
3906 @end example
3907
3908 @noindent
3909 rather than this:
3910
3911 @example
3912 2002-07-14 Usual Maintainer <usual@@gnu.org>
3913
3914 * sewing.c: Make it sew. Patch by jdoe@@gnu.org.
3915 @end example
3916
3917 When committing someone else's changes into a VCS, use the
3918 VCS features to specify the author. For example, with Git,
3919 use @kbd{git commit --author=@var{author}}.
3920
3921 As for the date, that should be the date you applied the change.
3922 (With a VCS, use the appropriate command-line switches,
3923 e.g., @kbd{git commit --date=@var{date}}.)
3924
3925 Modern VCS have commands to apply changes sent via email
3926 (e.g., Git has @kbd{git am}); in that case the author of the changeset
3927 and the date it was made will be automatically gleaned from the email
3928 message and recorded in the repository. If the patches are prepared
3929 with suitable VCS commands, such as @kbd{git format-patch},
3930 the email message body will also have the original author of the
3931 changeset, so resending or forwarding the message will not interfere
3932 with attributing the changes to their author. Thus, we recommend that
3933 you request your contributors to use commands such as @kbd{git
3934 format-patch} to prepare the patches.
3935
3936 @node Simple Changes
3937 @subsection Simple Changes
3938
3939 Certain simple kinds of changes don't need much detail in the change
3940 log.
3941
3942 If the description of the change is short enough, it can serve as its
3943 own header line:
3944
3945 @example
3946 2019-08-29 Eli Zaretskii <eliz@@gnu.org>
3947
3948 * lisp/simple.el (kill-do-not-save-duplicates): Doc fix. (Bug#36827)
3949 @end example
3950
3951 When you change the calling sequence of a function in a simple fashion,
3952 and you change all the callers of the function to use the new calling
3953 sequence, there is no need to make individual entries for all the
3954 callers that you changed. Just write in the entry for the function
3955 being called, ``All callers changed''---like this:
3956
3957 @example
3958 * keyboard.c (Fcommand_execute): New arg SPECIAL.
3959 All callers changed.
3960 @end example
3961
3962 When you change just comments or doc strings, it is enough to write an
3963 entry for the file, without mentioning the functions. Just ``Doc
3964 fixes'' is enough for the change log.
3965
3966 When you make changes in many files that follow mechanically from one
3967 underlying change, it is enough to describe the underlying change.
3968 Here's an example of a change that affects all of the files in the
3969 repository:
3970
3971 @example
3972 2019-01-07 Paul Eggert <eggert@@cs.ucla.edu>
3973
3974 Update copyright year to 2019
3975
3976 Run 'TZ=UTC0 admin/update-copyright $(git ls-files)'.
3977 @end example
3978
3979 Test suite files are part of the software, so we recommend treating
3980 them as code for change-log purposes.
3981
3982 There's no technical need to make change log entries for non-software
3983 files (manuals, help files, media files, etc.). This is because they
3984 are not susceptible to bugs that are hard to understand. To correct
3985 an error, you need not know the history of the erroneous passage; it
3986 is enough to compare what the file says with the actual facts.
3987
3988 However, you should keep change logs for non-software files when the
3989 project gets copyright assignments from its contributors, so as to
3990 make the records of authorship more accurate. For that reason, we
3991 recommend to keep change logs for Texinfo sources of your project's
3992 manuals.
3993
3994 @node Conditional Changes
3995 @subsection Conditional Changes
3996 @cindex conditional changes, and change logs
3997 @cindex change logs, conditional changes
3998
3999 Source files can often contain code that is conditional to build-time
4000 or static conditions. For example, C programs can contain
4001 compile-time @code{#if} conditionals; programs implemented in
4002 interpreted languages can contain module imports of function
4003 definitions that are only performed for certain versions of the
4004 interpreter; and Automake @file{Makefile.am} files can contain
4005 variable definitions or target declarations that are only to be
4006 considered if a configure-time Automake conditional is true.
4007
4008 Many changes are conditional as well: sometimes you add a new variable,
4009 or function, or even a new program or library, which is entirely
4010 dependent on a build-time condition. It is useful to indicate
4011 in the change log the conditions for which a change applies.
4012
4013 Our convention for indicating conditional changes is to use
4014 @emph{square brackets around the name of the condition}.
4015
4016 Conditional changes can happen in numerous scenarios and with many
4017 variations, so here are some examples to help clarify. This first
4018 example describes changes in C, Perl, and Python files which are
4019 conditional but do not have an associated function or entity name:
4020
4021 @example
4022 * xterm.c [SOLARIS2]: Include <string.h>.
4023 * FilePath.pm [$^O eq 'VMS']: Import the VMS::Feature module.
4024 * framework.py [sys.version_info < (2, 6)]: Make "with" statement
4025 available by importing it from __future__,
4026 to support also python 2.5.
4027 @end example
4028
4029 Our other examples will for simplicity be limited to C, as the minor
4030 changes necessary to adapt them to other languages should be
4031 self-evident.
4032
4033 Next, here is an entry describing a new definition which is entirely
4034 conditional: the C macro @code{FRAME_WINDOW_P} is defined (and used)
4035 only when the macro @code{HAVE_X_WINDOWS} is defined:
4036
4037 @example
4038 * frame.h [HAVE_X_WINDOWS] (FRAME_WINDOW_P): Macro defined.
4039 @end example
4040
4041 Next, an entry for a change within the function @code{init_display},
4042 whose definition as a whole is unconditional, but the changes
4043 themselves are contained in a @samp{#ifdef HAVE_LIBNCURSES}
4044 conditional:
4045
4046 @example
4047 * dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent.
4048 @end example
4049
4050 Finally, here is an entry for a change that takes effect only when
4051 a certain macro is @emph{not} defined:
4052
4053 @example
4054 * host.c (gethostname) [!HAVE_SOCKETS]: Replace with winsock version.
4055 @end example
4056
4057
4058 @node Indicating the Part Changed
4059 @subsection Indicating the Part Changed
4060
4061 Indicate the part of a function which changed by using angle brackets
4062 enclosing an indication of what the changed part does. Here is an entry
4063 for a change in the part of the function @code{sh-while-getopts} that
4064 deals with @code{sh} commands:
4065
4066 @example
4067 * progmodes/sh-script.el (sh-while-getopts) <sh>: Handle case that
4068 user-specified option string is empty.
4069 @end example
4070
4071
4072 @node Man Pages
4073 @section Man Pages
4074 @cindex man pages
4075
4076 In the GNU project, man pages are secondary. It is not necessary or
4077 expected for every GNU program to have a man page, but some of them do.
4078 It's your choice whether to include a man page in your program.
4079
4080 When you make this decision, consider that supporting a man page
4081 requires continual effort each time the program is changed. The time
4082 you spend on the man page is time taken away from more useful work.
4083
4084 For a simple program which changes little, updating the man page may be
4085 a small job. Then there is little reason not to include a man page, if
4086 you have one.
4087
4088 For a large program that changes a great deal, updating a man page may
4089 be a substantial burden. If a user offers to donate a man page, you may
4090 find this gift costly to accept. It may be better to refuse the man
4091 page unless the same person agrees to take full responsibility for
4092 maintaining it---so that you can wash your hands of it entirely. If
4093 this volunteer later ceases to do the job, then don't feel obliged to
4094 pick it up yourself; it may be better to withdraw the man page from the
4095 distribution until someone else agrees to update it.
4096
4097 When a program changes only a little, you may feel that the
4098 discrepancies are small enough that the man page remains useful without
4099 updating. If so, put a prominent note near the beginning of the man
4100 page stating that you don't maintain it and that the Texinfo manual
4101 is more authoritative. The note should say how to access the Texinfo
4102 documentation.
4103
4104 Be sure that man pages include a copyright statement and free license.
4105 The simple all-permissive license is appropriate for simple man pages
4106 (@pxref{License Notices for Other Files,,,maintain,Information for GNU
4107 Maintainers}).
4108
4109 For long man pages, with enough explanation and documentation that
4110 they can be considered true manuals, use the GFDL (@pxref{License for
4111 Manuals}).
4112
4113 Finally, the GNU help2man program
4114 (@uref{https://www.gnu.org/software/help2man/}) is one way to automate
4115 generation of a man page, in this case from @option{--help} output.
4116 This is sufficient in many cases.
4117
4118 @node Reading other Manuals
4119 @section Reading other Manuals
4120
4121 There may be nonfree books or documentation files that describe the
4122 program you are documenting.
4123
4124 It is ok to use these documents for reference, just as the author of a
4125 new algebra textbook can read other books on algebra. A large portion
4126 of any non-fiction book consists of facts, in this case facts about how
4127 a certain program works, and these facts are necessarily the same for
4128 everyone who writes about the subject. But be careful not to copy your
4129 outline structure, wording, tables or examples from preexisting nonfree
4130 documentation. Copying from free documentation may be ok; please check
4131 with the FSF about the individual case.
4132
4133 @node Managing Releases
4134 @chapter The Release Process
4135 @cindex releasing
4136
4137 Making a release is more than just bundling up your source files in a
4138 tar file and putting it up for FTP@. You should set up your software so
4139 that it can be configured to run on a variety of systems. Your Makefile
4140 should conform to the GNU standards described below, and your directory
4141 layout should also conform to the standards discussed below. Doing so
4142 makes it easy to include your package into the larger framework of
4143 all GNU software.
4144
4145 @menu
4146 * Configuration:: How configuration of GNU packages should work.
4147 * Makefile Conventions:: Makefile conventions.
4148 * Releases:: Making releases
4149 @end menu
4150
4151 @node Configuration
4152 @section How Configuration Should Work
4153 @cindex program configuration
4154
4155 @pindex configure
4156 Each GNU distribution should come with a shell script named
4157 @code{configure}. This script is given arguments which describe the
4158 kind of machine and system you want to compile the program for.
4159 The @code{configure} script must record the configuration options so
4160 that they affect compilation.
4161
4162 The description here is the specification of the interface for the
4163 @code{configure} script in GNU packages. Many packages implement it
4164 using GNU Autoconf (@pxref{Top,, Introduction, autoconf, Autoconf})
4165 and/or GNU Automake (@pxref{Top,, Introduction, automake, Automake}),
4166 but you do not have to use these tools. You can implement it any way
4167 you like; for instance, by making @code{configure} be a wrapper around
4168 a completely different configuration system.
4169
4170 Another way for the @code{configure} script to operate is to make a
4171 link from a standard name such as @file{config.h} to the proper
4172 configuration file for the chosen system. If you use this technique,
4173 the distribution should @emph{not} contain a file named
4174 @file{config.h}. This is so that people won't be able to build the
4175 program without configuring it first.
4176
4177 Another thing that @code{configure} can do is to edit the Makefile. If
4178 you do this, the distribution should @emph{not} contain a file named
4179 @file{Makefile}. Instead, it should include a file @file{Makefile.in} which
4180 contains the input used for editing. Once again, this is so that people
4181 won't be able to build the program without configuring it first.
4182
4183 If @code{configure} does write the @file{Makefile}, then @file{Makefile}
4184 should have a target named @file{Makefile} which causes @code{configure}
4185 to be rerun, setting up the same configuration that was set up last
4186 time. The files that @code{configure} reads should be listed as
4187 dependencies of @file{Makefile}.
4188
4189 All the files which are output from the @code{configure} script should
4190 have comments at the beginning stating that they were generated
4191 automatically using @code{configure}. This is so that users won't think
4192 of trying to edit them by hand.
4193
4194 The @code{configure} script should write a file named @file{config.status}
4195 which describes which configuration options were specified when the
4196 program was last configured. This file should be a shell script which,
4197 if run, will recreate the same configuration.
4198
4199 The @code{configure} script should accept an option of the form
4200 @samp{--srcdir=@var{dirname}} to specify the directory where sources are found
4201 (if it is not the current directory). This makes it possible to build
4202 the program in a separate directory, so that the actual source directory
4203 is not modified.
4204
4205 If the user does not specify @samp{--srcdir}, then @code{configure} should
4206 check both @file{.} and @file{..} to see if it can find the sources. If
4207 it finds the sources in one of these places, it should use them from
4208 there. Otherwise, it should report that it cannot find the sources, and
4209 should exit with nonzero status.
4210
4211 Usually the easy way to support @samp{--srcdir} is by editing a
4212 definition of @code{VPATH} into the Makefile. Some rules may need to
4213 refer explicitly to the specified source directory. To make this
4214 possible, @code{configure} can add to the Makefile a variable named
4215 @code{srcdir} whose value is precisely the specified directory.
4216
4217 In addition, the @samp{configure} script should take options
4218 corresponding to most of the standard directory variables
4219 (@pxref{Directory Variables}). Here is the list:
4220
4221 @example
4222 --prefix --exec-prefix --bindir --sbindir --libexecdir --sysconfdir
4223 --sharedstatedir --localstatedir --runstatedir
4224 --libdir --includedir --oldincludedir
4225 --datarootdir --datadir --infodir --localedir --mandir --docdir
4226 --htmldir --pdfdir --psdir
4227 @end example
4228
4229 The @code{configure} script should also take an argument which specifies the
4230 type of system to build the program for. This argument should look like
4231 this:
4232
4233 @example
4234 @var{cpu}-@var{company}-@var{system}
4235 @end example
4236
4237 For example, an Athlon-based GNU/Linux system might be
4238 @samp{i686-pc-linux-gnu}.
4239
4240 The @code{configure} script needs to be able to decode all plausible
4241 alternatives for how to describe a machine. Thus,
4242 @samp{athlon-pc-gnu/linux} would be a valid alias. There is a shell
4243 script called
4244 @uref{https://git.savannah.gnu.org/cgit/config.git/plain/config.sub,
4245 @file{config.sub}} that you can use as a subroutine to validate system
4246 types and canonicalize aliases.
4247
4248 The @code{configure} script should also take the option
4249 @option{--build=@var{buildtype}}, which should be equivalent to a
4250 plain @var{buildtype} argument. For example, @samp{configure
4251 --build=i686-pc-linux-gnu} is equivalent to @samp{configure
4252 i686-pc-linux-gnu}. When the build type is not specified by an option
4253 or argument, the @code{configure} script should normally guess it using
4254 the shell script
4255 @uref{https://git.savannah.gnu.org/cgit/config.git/plain/config.guess,
4256 @file{config.guess}}.
4257
4258 @cindex optional features, configure-time
4259 Other options are permitted to specify in more detail the software
4260 or hardware present on the machine, to include or exclude optional parts
4261 of the package, or to adjust the name of some tools or arguments to them:
4262
4263 @table @samp
4264 @item --enable-@var{feature}@r{[}=@var{parameter}@r{]}
4265 Configure the package to build and install an optional user-level
4266 facility called @var{feature}. This allows users to choose which
4267 optional features to include. Giving an optional @var{parameter} of
4268 @samp{no} should omit @var{feature}, if it is built by default.
4269
4270 No @samp{--enable} option should @strong{ever} cause one feature to
4271 replace another. No @samp{--enable} option should ever substitute one
4272 useful behavior for another useful behavior. The only proper use for
4273 @samp{--enable} is for questions of whether to build part of the program
4274 or exclude it.
4275
4276 @item --with-@var{package}
4277 @c @r{[}=@var{parameter}@r{]}
4278 The package @var{package} will be installed, so configure this package
4279 to work with @var{package}.
4280
4281 @c Giving an optional @var{parameter} of
4282 @c @samp{no} should omit @var{package}, if it is used by default.
4283
4284 Possible values of @var{package} include
4285 @samp{gnu-as} (or @samp{gas}), @samp{gnu-ld}, @samp{gnu-libc},
4286 @samp{gdb},
4287 @samp{x},
4288 and
4289 @samp{x-toolkit}.
4290
4291 Do not use a @samp{--with} option to specify the file name to use to
4292 find certain files. That is outside the scope of what @samp{--with}
4293 options are for.
4294
4295 @item @var{variable}=@var{value}
4296 Set the value of the variable @var{variable} to @var{value}. This is
4297 used to override the default values of commands or arguments in the
4298 build process. For example, the user could issue @samp{configure
4299 CFLAGS=-g CXXFLAGS=-g} to build with debugging information and without
4300 the default optimization.
4301
4302 Specifying variables as arguments to @code{configure}, like this:
4303 @example
4304 ./configure CC=gcc
4305 @end example
4306 is preferable to setting them in environment variables:
4307 @example
4308 CC=gcc ./configure
4309 @end example
4310 as it helps to recreate the same configuration later with
4311 @file{config.status}. However, both methods should be supported.
4312 @end table
4313
4314 All @code{configure} scripts should accept all of the ``detail''
4315 options and the variable settings, whether or not they make any
4316 difference to the particular package at hand. In particular, they
4317 should accept any option that starts with @samp{--with-} or
4318 @samp{--enable-}. This is so users will be able to configure an
4319 entire GNU source tree at once with a single set of options.
4320
4321 You will note that the categories @samp{--with-} and @samp{--enable-}
4322 are narrow: they @strong{do not} provide a place for any sort of option
4323 you might think of. That is deliberate. We want to limit the possible
4324 configuration options in GNU software. We do not want GNU programs to
4325 have idiosyncratic configuration options.
4326
4327 Packages that perform part of the compilation process may support
4328 cross-compilation. In such a case, the host and target machines for the
4329 program may be different.
4330
4331 The @code{configure} script should normally treat the specified type of
4332 system as both the host and the target, thus producing a program which
4333 works for the same type of machine that it runs on.
4334
4335 To compile a program to run on a host type that differs from the build
4336 type, use the configure option @option{--host=@var{hosttype}}, where
4337 @var{hosttype} uses the same syntax as @var{buildtype}. The host type
4338 normally defaults to the build type.
4339
4340 To configure a cross-compiler, cross-assembler, or what have you, you
4341 should specify a target different from the host, using the configure
4342 option @samp{--target=@var{targettype}}. The syntax for
4343 @var{targettype} is the same as for the host type. So the command would
4344 look like this:
4345
4346 @example
4347 ./configure --host=@var{hosttype} --target=@var{targettype}
4348 @end example
4349
4350 The target type normally defaults to the host type.
4351 Programs for which cross-operation is not meaningful need not accept the
4352 @samp{--target} option, because configuring an entire operating system for
4353 cross-operation is not a meaningful operation.
4354
4355 Some programs have ways of configuring themselves automatically. If
4356 your program is set up to do this, your @code{configure} script can simply
4357 ignore most of its arguments.
4358
4359 @comment The makefile standards are in a separate file that is also
4360 @comment included by make.texinfo. Done by [email protected] on 1/6/93.
4361 @comment For this document, turn chapters into sections, etc.
4362 @lowersections
4363 @include make-stds.texi
4364 @raisesections
4365
4366 @node Releases
4367 @section Making Releases
4368 @cindex packaging
4369
4370 @cindex version numbers, for releases
4371 You should identify each release with a pair of version numbers, a
4372 major version and a minor. We have no objection to using more than
4373 two numbers, but it is very unlikely that you really need them.
4374
4375 Package the distribution of @code{Foo version 69.96} up in a gzipped tar
4376 file with the name @file{foo-69.96.tar.gz}. It should unpack into a
4377 subdirectory named @file{foo-69.96}.
4378
4379 Building and installing the program should never modify any of the files
4380 contained in the distribution. This means that all the files that form
4381 part of the program in any way must be classified into @dfn{source
4382 files} and @dfn{non-source files}. Source files are written by humans
4383 and never changed automatically; non-source files are produced from
4384 source files by programs under the control of the Makefile.
4385
4386 @cindex @file{README} file
4387 The distribution should contain a file named @file{README} with a
4388 general overview of the package:
4389
4390 @itemize
4391 @item the name of the package;
4392
4393 @item the version number of the package, or refer to where in the
4394 package the version can be found;
4395
4396 @item a general description of what the package does;
4397
4398 @item a reference to the file @file{INSTALL}, which
4399 should in turn contain an explanation of the installation procedure;
4400
4401 @item a brief explanation of any unusual top-level directories or
4402 files, or other hints for readers to find their way around the source;
4403
4404 @item a reference to the file which contains the copying conditions.
4405 The GNU GPL, if used, should be in a file called @file{COPYING}. If
4406 the GNU LGPL is used, it should be in a file called
4407 @file{COPYING.LESSER}.
4408 @end itemize
4409
4410 Naturally, all the source files must be in the distribution. It is
4411 okay to include non-source files in the distribution along with the
4412 source files they are generated from, provided they are up-to-date
4413 with the source they are made from, and machine-independent, so that
4414 normal building of the distribution will never modify them. We
4415 commonly include non-source files produced by Autoconf, Automake,
4416 Bison, @code{flex}, @TeX{}, and @code{makeinfo}; this helps avoid
4417 unnecessary dependencies between our distributions, so that users can
4418 install whichever versions of whichever packages they like. Do not
4419 induce new dependencies on other software lightly.
4420
4421 Non-source files that might actually be modified by building and
4422 installing the program should @strong{never} be included in the
4423 distribution. So if you do distribute non-source files, always make
4424 sure they are up to date when you make a new distribution.
4425
4426 Make sure that all the files in the distribution are world-readable, and
4427 that directories are world-readable and world-searchable (octal mode 755).
4428 We used to recommend that all directories in the distribution also be
4429 world-writable (octal mode 777), because ancient versions of @code{tar}
4430 would otherwise not cope when extracting the archive as an unprivileged
4431 user. That can easily lead to security issues when creating the archive,
4432 however, so now we recommend against that.
4433
4434 Don't include any symbolic links in the distribution itself. If the tar
4435 file contains symbolic links, then people cannot even unpack it on
4436 systems that don't support symbolic links. Also, don't use multiple
4437 names for one file in different directories, because certain file
4438 systems cannot handle this and that prevents unpacking the
4439 distribution.
4440
4441 Try to make sure that all the file names will be unique on MS-DOS@. A
4442 name on MS-DOS consists of up to 8 characters, optionally followed by a
4443 period and up to three characters. MS-DOS will truncate extra
4444 characters both before and after the period. Thus,
4445 @file{foobarhacker.c} and @file{foobarhacker.o} are not ambiguous; they
4446 are truncated to @file{foobarha.c} and @file{foobarha.o}, which are
4447 distinct.
4448
4449 @cindex @file{texinfo.tex}, in a distribution
4450 Include in your distribution a copy of the @file{texinfo.tex} you used
4451 to test print any @file{*.texinfo} or @file{*.texi} files.
4452
4453 Likewise, if your program uses small GNU software packages like regex,
4454 getopt, obstack, or termcap, include them in the distribution file.
4455 Leaving them out would make the distribution file a little smaller at
4456 the expense of possible inconvenience to a user who doesn't know what
4457 other files to get.
4458
4459 @node References
4460 @chapter References to Nonfree Software and Documentation
4461 @cindex references to nonfree material
4462
4463 A GNU program should not recommend, promote, or grant legitimacy to
4464 the use of any nonfree program. Proprietary software is a social and
4465 ethical problem, and our aim is to put an end to that problem. We
4466 can't stop some people from writing proprietary programs, or stop
4467 other people from using them, but we can and should refuse to
4468 advertise them to new potential customers, or to give the public the
4469 impression that their existence is legitimate.
4470
4471 The GNU definition of free software is found on the GNU web site at
4472 @url{https://www.gnu.org/@/philosophy/@/free-sw.html}, and the definition
4473 of free documentation is found at
4474 @url{https://www.gnu.org/@/philosophy/@/free-doc.html}. The terms ``free''
4475 and ``nonfree'', used in this document, refer to those definitions.
4476
4477 A list of important licenses and whether they qualify as free is in
4478 @url{https://www.gnu.org/@/licenses/@/license-list.html}. If it is not
4479 clear whether a license qualifies as free, please ask the GNU Project
4480 by writing to @email{licensing@@gnu.org}. We will answer, and if the
4481 license is an important one, we will add it to the list.
4482
4483 When a nonfree program or system is well known, you can mention it in
4484 passing---that is harmless, since users who might want to use it
4485 probably already know about it. For instance, it is fine to explain
4486 how to build your package on top of some widely used nonfree
4487 operating system, or how to use it together with some widely used
4488 nonfree program, after first explaining how to use it on the GNU
4489 system.
4490
4491 However, you should give only the necessary information to help those
4492 who already use the nonfree program to use your program with
4493 it---don't give, or refer to, any further information about the
4494 proprietary program, and don't imply that the proprietary program
4495 enhances your program, or that its existence is in any way a good
4496 thing. The goal should be that people already using the proprietary
4497 program will get the advice they need about how to use your free
4498 program with it, while people who don't already use the proprietary
4499 program will not see anything likely to lead them to take an interest
4500 in it.
4501
4502 You shouldn't recommend any nonfree add-ons for the nonfree program,
4503 but it is ok to mention free add-ons that help it to work with your
4504 program, and how to install the free add-ons even if that requires
4505 running some nonfree program.
4506
4507 If a nonfree program or system is obscure in your program's domain,
4508 your program should not mention or support it at all, since doing so
4509 would tend to popularize the nonfree program more than it popularizes
4510 your program. (You cannot hope to find many additional users for your
4511 program among the users of Foobar, if the existence of Foobar is not
4512 generally known among people who might want to use your program.)
4513
4514 Sometimes a program is free software in itself but depends on a
4515 nonfree platform in order to run. For instance, it used to be the
4516 case that many Java programs depended on some nonfree Java libraries.
4517 (See @uref{https://www.gnu.org/philosophy/java-trap.html}.)
4518 To recommend or promote such a program is to promote the other
4519 programs it needs; therefore, judge mentions of the former as if they
4520 were mentions of the latter. For this reason, we were careful about
4521 listing Java programs in the Free Software Directory: we wanted to
4522 avoid promoting the nonfree Java libraries.
4523
4524 Java no longer has this problem, but the general principle will remain
4525 the same: don't recommend, promote or legitimize programs that depend
4526 on nonfree software to run.
4527
4528 Some free programs strongly encourage the use of nonfree software. A
4529 typical example is @command{mplayer}. It is free software in itself,
4530 and the free code can handle some kinds of files. However,
4531 @command{mplayer} recommends use of nonfree codecs for other kinds of
4532 files, and users that install @command{mplayer} are very likely to
4533 install those codecs along with it. To recommend @command{mplayer}
4534 is, in effect, to promote use of the nonfree codecs.
4535
4536 Thus, you should not recommend programs that strongly encourage the
4537 use of nonfree software. This is why we do not list
4538 @command{mplayer} in the Free Software Directory.
4539
4540 A GNU package should not refer the user to any nonfree documentation
4541 for free software. Free documentation that can be included in free
4542 operating systems is essential for completing the GNU system, or any
4543 free operating system, so encouraging it is a priority; to recommend
4544 use of documentation that we are not allowed to include undermines the
4545 impetus for the community to produce documentation that we can
4546 include. So GNU packages should never recommend nonfree
4547 documentation.
4548
4549 By contrast, it is ok to refer to journal articles and textbooks in
4550 the comments of a program for explanation of how it functions, even
4551 though they are nonfree. This is because we don't include such
4552 things in the GNU system even if they are free---they are outside the
4553 scope of what a software distribution needs to include.
4554
4555 Referring to a web site that describes or recommends a nonfree
4556 program is promoting that program, so please do not make links to (or
4557 mention by name) web sites that contain such material. This policy is
4558 relevant particularly for the web pages for a GNU package.
4559
4560 What about chains of links? Following links from nearly any web site
4561 can lead eventually to promotion of nonfree software; this is
4562 inherent in the nature of the web. Here's how we treat that.
4563
4564 You should not refer to AT&T's web site if that recommends AT&T's
4565 nonfree software packages; you should not refer to a page @var{p}
4566 that links to AT&T's site presenting it as a place to get some
4567 nonfree program, because that part of the page @var{p} itself
4568 recommends and legitimizes the nonfree program.
4569
4570 However, if @var{p} contains a link to AT&T's web site for some other
4571 purpose (such as long-distance telephone service), that is no reason
4572 you should not link to @var{p}.
4573
4574 A web page recommends a program in an implicit but particularly strong
4575 way if it requires users to run that program in order to use the page.
4576 Many pages contain JavaScript code which they recommend in this way.
4577 This JavaScript code may be free or nonfree, but nonfree is the usual
4578 case.
4579
4580 If the purpose for which you would refer to the page cannot be carried
4581 out without running nonfree JavaScript code, then you should not refer
4582 to it. Thus, if the purpose of referring to the page is for people to
4583 view a video, or subscribing to a mailing list, and the viewing or
4584 subscribing fail to work if the user's browser blocks the nonfree
4585 JavaScript code, then don't refer to that page.
4586
4587 The extreme case is that of web sites which depend on nonfree
4588 JavaScript code even to @emph{see} the contents of the pages. Any
4589 site hosted on @indicateurl{wix.com} has this problem, and so do some
4590 other sites. Referring people to such pages to read their contents
4591 is, in effect, urging them to run those nonfree programs---so please
4592 don't refer to those pages. (Such pages also break the Web, so they
4593 deserve condemnation for two reasons.)
4594
4595 Instead, please quote excerpts from the page to make your point,
4596 or find another place to refer to that information.
4597
4598 @node GNU Free Documentation License
4599 @appendix GNU Free Documentation License
4600
4601 @cindex FDL, GNU Free Documentation License
4602 @include fdl.texi
4603
4604 @node Index
4605 @unnumbered Index
4606 @printindex cp
4607
4608 @bye
4609
4610 Local variables:
4611 eval: (add-hook 'before-save-hook 'time-stamp)
4612 time-stamp-start: "@set lastupdate "
4613 time-stamp-end: "$"
4614 time-stamp-format: "%:b %:d, %:y"
4615 compile-command: "cd work.s && make"
4616 End: