1 | This is Info file standards.info, produced by Makeinfo version 1.67
|
---|
2 | from the input file /home/bje/autoconf-2.13/standards.texi.
|
---|
3 |
|
---|
4 | START-INFO-DIR-ENTRY
|
---|
5 | * Standards: (standards). GNU coding standards.
|
---|
6 | END-INFO-DIR-ENTRY
|
---|
7 |
|
---|
8 | GNU Coding Standards Copyright (C) 1992, 1993, 1994, 1995, 1996,
|
---|
9 | 1997, 1998 Free Software Foundation, Inc.
|
---|
10 |
|
---|
11 | Permission is granted to make and distribute verbatim copies of this
|
---|
12 | manual provided the copyright notice and this permission notice are
|
---|
13 | preserved on all copies.
|
---|
14 |
|
---|
15 | Permission is granted to copy and distribute modified versions of
|
---|
16 | this manual under the conditions for verbatim copying, provided that
|
---|
17 | the entire resulting derived work is distributed under the terms of a
|
---|
18 | permission notice identical to this one.
|
---|
19 |
|
---|
20 | Permission is granted to copy and distribute translations of this
|
---|
21 | manual into another language, under the above conditions for modified
|
---|
22 | versions, except that this permission notice may be stated in a
|
---|
23 | translation approved by the Free Software Foundation.
|
---|
24 |
|
---|
25 |
|
---|
26 | File: standards.info, Node: Top, Next: Preface, Prev: (dir), Up: (dir)
|
---|
27 |
|
---|
28 | Version
|
---|
29 | *******
|
---|
30 |
|
---|
31 | Last updated August 26, 1998.
|
---|
32 |
|
---|
33 | * Menu:
|
---|
34 |
|
---|
35 | * Preface:: About the GNU Coding Standards
|
---|
36 | * Intellectual Property:: Keeping Free Software Free
|
---|
37 | * Design Advice:: General Program Design
|
---|
38 | * Program Behavior:: Program Behavior for All Programs
|
---|
39 | * Writing C:: Making The Best Use of C
|
---|
40 | * Documentation:: Documenting Programs
|
---|
41 | * Managing Releases:: The Release Process
|
---|
42 |
|
---|
43 |
|
---|
44 | File: standards.info, Node: Preface, Next: Intellectual Property, Prev: Top, Up: Top
|
---|
45 |
|
---|
46 | About the GNU Coding Standards
|
---|
47 | ******************************
|
---|
48 |
|
---|
49 | The GNU Coding Standards were written by Richard Stallman and other
|
---|
50 | GNU Project volunteers. Their purpose is to make the GNU system clean,
|
---|
51 | consistent, and easy to install. This document can also be read as a
|
---|
52 | guide to writing portable, robust and reliable programs. It focuses on
|
---|
53 | programs written in C, but many of the rules and principles are useful
|
---|
54 | even if you write in another programming language. The rules often
|
---|
55 | state reasons for writing in a certain way.
|
---|
56 |
|
---|
57 | Corrections or suggestions for this document should be sent to
|
---|
58 | <gnu@gnu.org>. If you make a suggestion, please include a suggested
|
---|
59 | new wording for it; our time is limited. We prefer a context diff to
|
---|
60 | the `standards.texi' or `make-stds.texi' files, but if you don't have
|
---|
61 | those files, please mail your suggestion anyway.
|
---|
62 |
|
---|
63 | This release of the GNU Coding Standards was last updated August 26,
|
---|
64 | 1998.
|
---|
65 |
|
---|
66 |
|
---|
67 | File: standards.info, Node: Intellectual Property, Next: Design Advice, Prev: Preface, Up: Top
|
---|
68 |
|
---|
69 | Keeping Free Software Free
|
---|
70 | **************************
|
---|
71 |
|
---|
72 | This node discusses how you can make sure that GNU software remains
|
---|
73 | unencumbered.
|
---|
74 |
|
---|
75 | * Menu:
|
---|
76 |
|
---|
77 | * Reading Non-Free Code:: Referring to Proprietary Programs
|
---|
78 | * Contributions:: Accepting Contributions
|
---|
79 |
|
---|
80 |
|
---|
81 | File: standards.info, Node: Reading Non-Free Code, Next: Contributions, Up: Intellectual Property
|
---|
82 |
|
---|
83 | Referring to Proprietary Programs
|
---|
84 | =================================
|
---|
85 |
|
---|
86 | Don't in any circumstances refer to Unix source code for or during
|
---|
87 | your work on GNU! (Or to any other proprietary programs.)
|
---|
88 |
|
---|
89 | If you have a vague recollection of the internals of a Unix program,
|
---|
90 | this does not absolutely mean you can't write an imitation of it, but
|
---|
91 | do try to organize the imitation internally along different lines,
|
---|
92 | because this is likely to make the details of the Unix version
|
---|
93 | irrelevant and dissimilar to your results.
|
---|
94 |
|
---|
95 | For example, Unix utilities were generally optimized to minimize
|
---|
96 | memory use; if you go for speed instead, your program will be very
|
---|
97 | different. You could keep the entire input file in core and scan it
|
---|
98 | there instead of using stdio. Use a smarter algorithm discovered more
|
---|
99 | recently than the Unix program. Eliminate use of temporary files. Do
|
---|
100 | it in one pass instead of two (we did this in the assembler).
|
---|
101 |
|
---|
102 | Or, on the contrary, emphasize simplicity instead of speed. For some
|
---|
103 | applications, the speed of today's computers makes simpler algorithms
|
---|
104 | adequate.
|
---|
105 |
|
---|
106 | Or go for generality. For example, Unix programs often have static
|
---|
107 | tables or fixed-size strings, which make for arbitrary limits; use
|
---|
108 | dynamic allocation instead. Make sure your program handles NULs and
|
---|
109 | other funny characters in the input files. Add a programming language
|
---|
110 | for extensibility and write part of the program in that language.
|
---|
111 |
|
---|
112 | Or turn some parts of the program into independently usable
|
---|
113 | libraries. Or use a simple garbage collector instead of tracking
|
---|
114 | precisely when to free memory, or use a new GNU facility such as
|
---|
115 | obstacks.
|
---|
116 |
|
---|
117 |
|
---|
118 | File: standards.info, Node: Contributions, Prev: Reading Non-Free Code, Up: Intellectual Property
|
---|
119 |
|
---|
120 | Accepting Contributions
|
---|
121 | =======================
|
---|
122 |
|
---|
123 | If someone else sends you a piece of code to add to the program you
|
---|
124 | are working on, we need legal papers to use it--the same sort of legal
|
---|
125 | papers we will need to get from you. *Each* significant contributor to
|
---|
126 | a program must sign some sort of legal papers in order for us to have
|
---|
127 | clear title to the program. The main author alone is not enough.
|
---|
128 |
|
---|
129 | So, before adding in any contributions from other people, please tell
|
---|
130 | us, so we can arrange to get the papers. Then wait until we tell you
|
---|
131 | that we have received the signed papers, before you actually use the
|
---|
132 | contribution.
|
---|
133 |
|
---|
134 | This applies both before you release the program and afterward. If
|
---|
135 | you receive diffs to fix a bug, and they make significant changes, we
|
---|
136 | need legal papers for that change.
|
---|
137 |
|
---|
138 | This also applies to comments and documentation files. For copyright
|
---|
139 | law, comments and code are just text. Copyright applies to all kinds of
|
---|
140 | text, so we need legal papers for all kinds.
|
---|
141 |
|
---|
142 | You don't need papers for changes of a few lines here or there, since
|
---|
143 | they are not significant for copyright purposes. Also, you don't need
|
---|
144 | papers if all you get from the suggestion is some ideas, not actual code
|
---|
145 | which you use. For example, if you write a different solution to the
|
---|
146 | problem, you don't need to get papers.
|
---|
147 |
|
---|
148 | We know this is frustrating; it's frustrating for us as well. But if
|
---|
149 | you don't wait, you are going out on a limb--for example, what if the
|
---|
150 | contributor's employer won't sign a disclaimer? You might have to take
|
---|
151 | that code out again!
|
---|
152 |
|
---|
153 | The very worst thing is if you forget to tell us about the other
|
---|
154 | contributor. We could be very embarrassed in court some day as a
|
---|
155 | result.
|
---|
156 |
|
---|
157 | We have more detailed advice for maintainers of programs; if you have
|
---|
158 | reached the stage of actually maintaining a program for GNU (whether
|
---|
159 | released or not), please ask us for a copy.
|
---|
160 |
|
---|
161 |
|
---|
162 | File: standards.info, Node: Design Advice, Next: Program Behavior, Prev: Intellectual Property, Up: Top
|
---|
163 |
|
---|
164 | General Program Design
|
---|
165 | **********************
|
---|
166 |
|
---|
167 | This node discusses some of the issues you should take into account
|
---|
168 | when designing your program.
|
---|
169 |
|
---|
170 | * Menu:
|
---|
171 |
|
---|
172 | * Compatibility:: Compatibility with other implementations
|
---|
173 | * Using Extensions:: Using non-standard features
|
---|
174 | * ANSI C:: Using ANSI C features
|
---|
175 | * Source Language:: Using languages other than C
|
---|
176 |
|
---|
177 |
|
---|
178 | File: standards.info, Node: Compatibility, Next: Using Extensions, Up: Design Advice
|
---|
179 |
|
---|
180 | Compatibility with Other Implementations
|
---|
181 | ========================================
|
---|
182 |
|
---|
183 | With occasional exceptions, utility programs and libraries for GNU
|
---|
184 | should be upward compatible with those in Berkeley Unix, and upward
|
---|
185 | compatible with ANSI C if ANSI C specifies their behavior, and upward
|
---|
186 | compatible with POSIX if POSIX specifies their behavior.
|
---|
187 |
|
---|
188 | When these standards conflict, it is useful to offer compatibility
|
---|
189 | modes for each of them.
|
---|
190 |
|
---|
191 | ANSI C and POSIX prohibit many kinds of extensions. Feel free to
|
---|
192 | make the extensions anyway, and include a `--ansi', `--posix', or
|
---|
193 | `--compatible' option to turn them off. However, if the extension has
|
---|
194 | a significant chance of breaking any real programs or scripts, then it
|
---|
195 | is not really upward compatible. Try to redesign its interface.
|
---|
196 |
|
---|
197 | Many GNU programs suppress extensions that conflict with POSIX if the
|
---|
198 | environment variable `POSIXLY_CORRECT' is defined (even if it is
|
---|
199 | defined with a null value). Please make your program recognize this
|
---|
200 | variable if appropriate.
|
---|
201 |
|
---|
202 | When a feature is used only by users (not by programs or command
|
---|
203 | files), and it is done poorly in Unix, feel free to replace it
|
---|
204 | completely with something totally different and better. (For example,
|
---|
205 | `vi' is replaced with Emacs.) But it is nice to offer a compatible
|
---|
206 | feature as well. (There is a free `vi' clone, so we offer it.)
|
---|
207 |
|
---|
208 | Additional useful features not in Berkeley Unix are welcome.
|
---|
209 |
|
---|
210 |
|
---|
211 | File: standards.info, Node: Using Extensions, Next: ANSI C, Prev: Compatibility, Up: Design Advice
|
---|
212 |
|
---|
213 | Using Non-standard Features
|
---|
214 | ===========================
|
---|
215 |
|
---|
216 | Many GNU facilities that already exist support a number of convenient
|
---|
217 | extensions over the comparable Unix facilities. Whether to use these
|
---|
218 | extensions in implementing your program is a difficult question.
|
---|
219 |
|
---|
220 | On the one hand, using the extensions can make a cleaner program.
|
---|
221 | On the other hand, people will not be able to build the program unless
|
---|
222 | the other GNU tools are available. This might cause the program to
|
---|
223 | work on fewer kinds of machines.
|
---|
224 |
|
---|
225 | With some extensions, it might be easy to provide both alternatives.
|
---|
226 | For example, you can define functions with a "keyword" `INLINE' and
|
---|
227 | define that as a macro to expand into either `inline' or nothing,
|
---|
228 | depending on the compiler.
|
---|
229 |
|
---|
230 | In general, perhaps it is best not to use the extensions if you can
|
---|
231 | straightforwardly do without them, but to use the extensions if they
|
---|
232 | are a big improvement.
|
---|
233 |
|
---|
234 | An exception to this rule are the large, established programs (such
|
---|
235 | as Emacs) which run on a great variety of systems. Such programs would
|
---|
236 | be broken by use of GNU extensions.
|
---|
237 |
|
---|
238 | Another exception is for programs that are used as part of
|
---|
239 | compilation: anything that must be compiled with other compilers in
|
---|
240 | order to bootstrap the GNU compilation facilities. If these require
|
---|
241 | the GNU compiler, then no one can compile them without having them
|
---|
242 | installed already. That would be no good.
|
---|
243 |
|
---|
244 |
|
---|
245 | File: standards.info, Node: ANSI C, Next: Source Language, Prev: Using Extensions, Up: Design Advice
|
---|
246 |
|
---|
247 | ANSI C and pre-ANSI C
|
---|
248 | =====================
|
---|
249 |
|
---|
250 | Do not ever use the "trigraph" feature of ANSI C.
|
---|
251 |
|
---|
252 | ANSI C is widespread enough now that it is ok to write new programs
|
---|
253 | that use ANSI C features (and therefore will not work in non-ANSI
|
---|
254 | compilers). And if a program is already written in ANSI C, there's no
|
---|
255 | need to convert it to support non-ANSI compilers.
|
---|
256 |
|
---|
257 | However, it is easy to support non-ANSI compilers in most programs,
|
---|
258 | so you might still consider doing so when you write a program. Instead
|
---|
259 | of writing function definitions in ANSI prototype form,
|
---|
260 |
|
---|
261 | int
|
---|
262 | foo (int x, int y)
|
---|
263 | ...
|
---|
264 |
|
---|
265 | write the definition in pre-ANSI style like this,
|
---|
266 |
|
---|
267 | int
|
---|
268 | foo (x, y)
|
---|
269 | int x, y;
|
---|
270 | ...
|
---|
271 |
|
---|
272 | and use a separate declaration to specify the argument prototype:
|
---|
273 |
|
---|
274 | int foo (int, int);
|
---|
275 |
|
---|
276 | You need such a declaration anyway, in a header file, to get the
|
---|
277 | benefit of ANSI C prototypes in all the files where the function is
|
---|
278 | called. And once you have it, you lose nothing by writing the function
|
---|
279 | definition in the pre-ANSI style.
|
---|
280 |
|
---|
281 | If you don't know non-ANSI C, there's no need to learn it; just
|
---|
282 | write in ANSI C.
|
---|
283 |
|
---|
284 |
|
---|
285 | File: standards.info, Node: Source Language, Prev: ANSI C, Up: Design Advice
|
---|
286 |
|
---|
287 | Using Languages Other Than C
|
---|
288 | ============================
|
---|
289 |
|
---|
290 | Using a language other than C is like using a non-standard feature:
|
---|
291 | it will cause trouble for users. Even if GCC supports the other
|
---|
292 | language, users may find it inconvenient to have to install the
|
---|
293 | compiler for that other language in order to build your program. For
|
---|
294 | example, if you write your program in C++, people will have to install
|
---|
295 | the C++ compiler in order to compile your program. Thus, it is better
|
---|
296 | if you write in C.
|
---|
297 |
|
---|
298 | But there are three situations when there is no disadvantage in using
|
---|
299 | some other language:
|
---|
300 |
|
---|
301 | * It is okay to use another language if your program contains an
|
---|
302 | interpreter for that language.
|
---|
303 |
|
---|
304 | For example, if your program links with GUILE, it is ok to write
|
---|
305 | part of the program in Scheme or another language supported by
|
---|
306 | GUILE.
|
---|
307 |
|
---|
308 | * It is okay to use another language in a tool specifically intended
|
---|
309 | for use with that language.
|
---|
310 |
|
---|
311 | This is okay because the only people who want to build the tool
|
---|
312 | will be those who have installed the other language anyway.
|
---|
313 |
|
---|
314 | * If an application is of interest to a narrow community, then
|
---|
315 | perhaps it's not important if the application is inconvenient to
|
---|
316 | install.
|
---|
317 |
|
---|
318 | C has one other advantage over C++ and other compiled languages: more
|
---|
319 | people know C, so more people will find it easy to read and modify the
|
---|
320 | program if it is written in C.
|
---|
321 |
|
---|
322 |
|
---|
323 | File: standards.info, Node: Program Behavior, Next: Writing C, Prev: Design Advice, Up: Top
|
---|
324 |
|
---|
325 | Program Behavior for All Programs
|
---|
326 | *********************************
|
---|
327 |
|
---|
328 | This node describes how to write robust software. It also describes
|
---|
329 | general standards for error messages, the command line interface, and
|
---|
330 | how libraries should behave.
|
---|
331 |
|
---|
332 | * Menu:
|
---|
333 |
|
---|
334 | * Semantics:: Writing robust programs
|
---|
335 | * Libraries:: Library behavior
|
---|
336 | * Errors:: Formatting error messages
|
---|
337 | * User Interfaces:: Standards for command line interfaces
|
---|
338 | * Option Table:: Table of long options.
|
---|
339 | * Memory Usage:: When and how to care about memory needs
|
---|
340 |
|
---|
341 |
|
---|
342 | File: standards.info, Node: Semantics, Next: Libraries, Up: Program Behavior
|
---|
343 |
|
---|
344 | Writing Robust Programs
|
---|
345 | =======================
|
---|
346 |
|
---|
347 | Avoid arbitrary limits on the length or number of *any* data
|
---|
348 | structure, including file names, lines, files, and symbols, by
|
---|
349 | allocating all data structures dynamically. In most Unix utilities,
|
---|
350 | "long lines are silently truncated". This is not acceptable in a GNU
|
---|
351 | utility.
|
---|
352 |
|
---|
353 | Utilities reading files should not drop NUL characters, or any other
|
---|
354 | nonprinting characters *including those with codes above 0177*. The
|
---|
355 | only sensible exceptions would be utilities specifically intended for
|
---|
356 | interface to certain types of printers that can't handle those
|
---|
357 | characters.
|
---|
358 |
|
---|
359 | Check every system call for an error return, unless you know you
|
---|
360 | wish to ignore errors. Include the system error text (from `perror' or
|
---|
361 | equivalent) in *every* error message resulting from a failing system
|
---|
362 | call, as well as the name of the file if any and the name of the
|
---|
363 | utility. Just "cannot open foo.c" or "stat failed" is not sufficient.
|
---|
364 |
|
---|
365 | Check every call to `malloc' or `realloc' to see if it returned
|
---|
366 | zero. Check `realloc' even if you are making the block smaller; in a
|
---|
367 | system that rounds block sizes to a power of 2, `realloc' may get a
|
---|
368 | different block if you ask for less space.
|
---|
369 |
|
---|
370 | In Unix, `realloc' can destroy the storage block if it returns zero.
|
---|
371 | GNU `realloc' does not have this bug: if it fails, the original block
|
---|
372 | is unchanged. Feel free to assume the bug is fixed. If you wish to
|
---|
373 | run your program on Unix, and wish to avoid lossage in this case, you
|
---|
374 | can use the GNU `malloc'.
|
---|
375 |
|
---|
376 | You must expect `free' to alter the contents of the block that was
|
---|
377 | freed. Anything you want to fetch from the block, you must fetch before
|
---|
378 | calling `free'.
|
---|
379 |
|
---|
380 | If `malloc' fails in a noninteractive program, make that a fatal
|
---|
381 | error. In an interactive program (one that reads commands from the
|
---|
382 | user), it is better to abort the command and return to the command
|
---|
383 | reader loop. This allows the user to kill other processes to free up
|
---|
384 | virtual memory, and then try the command again.
|
---|
385 |
|
---|
386 | Use `getopt_long' to decode arguments, unless the argument syntax
|
---|
387 | makes this unreasonable.
|
---|
388 |
|
---|
389 | When static storage is to be written in during program execution, use
|
---|
390 | explicit C code to initialize it. Reserve C initialized declarations
|
---|
391 | for data that will not be changed.
|
---|
392 |
|
---|
393 | Try to avoid low-level interfaces to obscure Unix data structures
|
---|
394 | (such as file directories, utmp, or the layout of kernel memory), since
|
---|
395 | these are less likely to work compatibly. If you need to find all the
|
---|
396 | files in a directory, use `readdir' or some other high-level interface.
|
---|
397 | These will be supported compatibly by GNU.
|
---|
398 |
|
---|
399 | The preferred signal handling facilities are the BSD variant of
|
---|
400 | `signal', and the POSIX `sigaction' function; the alternative USG
|
---|
401 | `signal' interface is an inferior design.
|
---|
402 |
|
---|
403 | Nowadays, using the POSIX signal functions may be the easiest way to
|
---|
404 | make a program portable. If you use `signal', then on GNU/Linux
|
---|
405 | systems running GNU libc version 1, you should include `bsd/signal.h'
|
---|
406 | instead of `signal.h', so as to get BSD behavior. It is up to you
|
---|
407 | whether to support systems where `signal' has only the USG behavior, or
|
---|
408 | give up on them.
|
---|
409 |
|
---|
410 | In error checks that detect "impossible" conditions, just abort.
|
---|
411 | There is usually no point in printing any message. These checks
|
---|
412 | indicate the existence of bugs. Whoever wants to fix the bugs will have
|
---|
413 | to read the source code and run a debugger. So explain the problem with
|
---|
414 | comments in the source. The relevant data will be in variables, which
|
---|
415 | are easy to examine with the debugger, so there is no point moving them
|
---|
416 | elsewhere.
|
---|
417 |
|
---|
418 | Do not use a count of errors as the exit status for a program.
|
---|
419 | *That does not work*, because exit status values are limited to 8 bits
|
---|
420 | (0 through 255). A single run of the program might have 256 errors; if
|
---|
421 | you try to return 256 as the exit status, the parent process will see 0
|
---|
422 | as the status, and it will appear that the program succeeded.
|
---|
423 |
|
---|
424 | If you make temporary files, check the `TMPDIR' environment
|
---|
425 | variable; if that variable is defined, use the specified directory
|
---|
426 | instead of `/tmp'.
|
---|
427 |
|
---|
428 |
|
---|
429 | File: standards.info, Node: Libraries, Next: Errors, Prev: Semantics, Up: Program Behavior
|
---|
430 |
|
---|
431 | Library Behavior
|
---|
432 | ================
|
---|
433 |
|
---|
434 | Try to make library functions reentrant. If they need to do dynamic
|
---|
435 | storage allocation, at least try to avoid any nonreentrancy aside from
|
---|
436 | that of `malloc' itself.
|
---|
437 |
|
---|
438 | Here are certain name conventions for libraries, to avoid name
|
---|
439 | conflicts.
|
---|
440 |
|
---|
441 | Choose a name prefix for the library, more than two characters long.
|
---|
442 | All external function and variable names should start with this prefix.
|
---|
443 | In addition, there should only be one of these in any given library
|
---|
444 | member. This usually means putting each one in a separate source file.
|
---|
445 |
|
---|
446 | An exception can be made when two external symbols are always used
|
---|
447 | together, so that no reasonable program could use one without the
|
---|
448 | other; then they can both go in the same file.
|
---|
449 |
|
---|
450 | External symbols that are not documented entry points for the user
|
---|
451 | should have names beginning with `_'. They should also contain the
|
---|
452 | chosen name prefix for the library, to prevent collisions with other
|
---|
453 | libraries. These can go in the same files with user entry points if
|
---|
454 | you like.
|
---|
455 |
|
---|
456 | Static functions and variables can be used as you like and need not
|
---|
457 | fit any naming convention.
|
---|
458 |
|
---|
459 |
|
---|
460 | File: standards.info, Node: Errors, Next: User Interfaces, Prev: Libraries, Up: Program Behavior
|
---|
461 |
|
---|
462 | Formatting Error Messages
|
---|
463 | =========================
|
---|
464 |
|
---|
465 | Error messages from compilers should look like this:
|
---|
466 |
|
---|
467 | SOURCE-FILE-NAME:LINENO: MESSAGE
|
---|
468 |
|
---|
469 | Error messages from other noninteractive programs should look like
|
---|
470 | this:
|
---|
471 |
|
---|
472 | PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
|
---|
473 |
|
---|
474 | when there is an appropriate source file, or like this:
|
---|
475 |
|
---|
476 | PROGRAM: MESSAGE
|
---|
477 |
|
---|
478 | when there is no relevant source file.
|
---|
479 |
|
---|
480 | In an interactive program (one that is reading commands from a
|
---|
481 | terminal), it is better not to include the program name in an error
|
---|
482 | message. The place to indicate which program is running is in the
|
---|
483 | prompt or with the screen layout. (When the same program runs with
|
---|
484 | input from a source other than a terminal, it is not interactive and
|
---|
485 | would do best to print error messages using the noninteractive style.)
|
---|
486 |
|
---|
487 | The string MESSAGE should not begin with a capital letter when it
|
---|
488 | follows a program name and/or file name. Also, it should not end with
|
---|
489 | a period.
|
---|
490 |
|
---|
491 | Error messages from interactive programs, and other messages such as
|
---|
492 | usage messages, should start with a capital letter. But they should not
|
---|
493 | end with a period.
|
---|
494 |
|
---|
495 |
|
---|
496 | File: standards.info, Node: User Interfaces, Next: Option Table, Prev: Errors, Up: Program Behavior
|
---|
497 |
|
---|
498 | Standards for Command Line Interfaces
|
---|
499 | =====================================
|
---|
500 |
|
---|
501 | Please don't make the behavior of a utility depend on the name used
|
---|
502 | to invoke it. It is useful sometimes to make a link to a utility with
|
---|
503 | a different name, and that should not change what it does.
|
---|
504 |
|
---|
505 | Instead, use a run time option or a compilation switch or both to
|
---|
506 | select among the alternate behaviors.
|
---|
507 |
|
---|
508 | Likewise, please don't make the behavior of the program depend on the
|
---|
509 | type of output device it is used with. Device independence is an
|
---|
510 | important principle of the system's design; do not compromise it merely
|
---|
511 | to save someone from typing an option now and then. (Variation in error
|
---|
512 | message syntax when using a terminal is ok, because that is a side issue
|
---|
513 | that people do not depend on.)
|
---|
514 |
|
---|
515 | If you think one behavior is most useful when the output is to a
|
---|
516 | terminal, and another is most useful when the output is a file or a
|
---|
517 | pipe, then it is usually best to make the default behavior the one that
|
---|
518 | is useful with output to a terminal, and have an option for the other
|
---|
519 | behavior.
|
---|
520 |
|
---|
521 | Compatibility requires certain programs to depend on the type of
|
---|
522 | output device. It would be disastrous if `ls' or `sh' did not do so in
|
---|
523 | the way all users expect. In some of these cases, we supplement the
|
---|
524 | program with a preferred alternate version that does not depend on the
|
---|
525 | output device type. For example, we provide a `dir' program much like
|
---|
526 | `ls' except that its default output format is always multi-column
|
---|
527 | format.
|
---|
528 |
|
---|
529 | It is a good idea to follow the POSIX guidelines for the
|
---|
530 | command-line options of a program. The easiest way to do this is to use
|
---|
531 | `getopt' to parse them. Note that the GNU version of `getopt' will
|
---|
532 | normally permit options anywhere among the arguments unless the special
|
---|
533 | argument `--' is used. This is not what POSIX specifies; it is a GNU
|
---|
534 | extension.
|
---|
535 |
|
---|
536 | Please define long-named options that are equivalent to the
|
---|
537 | single-letter Unix-style options. We hope to make GNU more user
|
---|
538 | friendly this way. This is easy to do with the GNU function
|
---|
539 | `getopt_long'.
|
---|
540 |
|
---|
541 | One of the advantages of long-named options is that they can be
|
---|
542 | consistent from program to program. For example, users should be able
|
---|
543 | to expect the "verbose" option of any GNU program which has one, to be
|
---|
544 | spelled precisely `--verbose'. To achieve this uniformity, look at the
|
---|
545 | table of common long-option names when you choose the option names for
|
---|
546 | your program (*note Option Table::.).
|
---|
547 |
|
---|
548 | It is usually a good idea for file names given as ordinary arguments
|
---|
549 | to be input files only; any output files would be specified using
|
---|
550 | options (preferably `-o' or `--output'). Even if you allow an output
|
---|
551 | file name as an ordinary argument for compatibility, try to provide an
|
---|
552 | option as another way to specify it. This will lead to more consistency
|
---|
553 | among GNU utilities, and fewer idiosyncracies for users to remember.
|
---|
554 |
|
---|
555 | All programs should support two standard options: `--version' and
|
---|
556 | `--help'.
|
---|
557 |
|
---|
558 | `--version'
|
---|
559 | This option should direct the program to information about its
|
---|
560 | name, version, origin and legal status, all on standard output,
|
---|
561 | and then exit successfully. Other options and arguments should be
|
---|
562 | ignored once this is seen, and the program should not perform its
|
---|
563 | normal function.
|
---|
564 |
|
---|
565 | The first line is meant to be easy for a program to parse; the
|
---|
566 | version number proper starts after the last space. In addition,
|
---|
567 | it contains the canonical name for this program, in this format:
|
---|
568 |
|
---|
569 | GNU Emacs 19.30
|
---|
570 |
|
---|
571 | The program's name should be a constant string; *don't* compute it
|
---|
572 | from `argv[0]'. The idea is to state the standard or canonical
|
---|
573 | name for the program, not its file name. There are other ways to
|
---|
574 | find out the precise file name where a command is found in `PATH'.
|
---|
575 |
|
---|
576 | If the program is a subsidiary part of a larger package, mention
|
---|
577 | the package name in parentheses, like this:
|
---|
578 |
|
---|
579 | emacsserver (GNU Emacs) 19.30
|
---|
580 |
|
---|
581 | If the package has a version number which is different from this
|
---|
582 | program's version number, you can mention the package version
|
---|
583 | number just before the close-parenthesis.
|
---|
584 |
|
---|
585 | If you *need* to mention the version numbers of libraries which
|
---|
586 | are distributed separately from the package which contains this
|
---|
587 | program, you can do so by printing an additional line of version
|
---|
588 | info for each library you want to mention. Use the same format
|
---|
589 | for these lines as for the first line.
|
---|
590 |
|
---|
591 | Please do not mention all of the libraries that the program uses
|
---|
592 | "just for completeness"--that would produce a lot of unhelpful
|
---|
593 | clutter. Please mention library version numbers only if you find
|
---|
594 | in practice that they are very important to you in debugging.
|
---|
595 |
|
---|
596 | The following line, after the version number line or lines, should
|
---|
597 | be a copyright notice. If more than one copyright notice is
|
---|
598 | called for, put each on a separate line.
|
---|
599 |
|
---|
600 | Next should follow a brief statement that the program is free
|
---|
601 | software, and that users are free to copy and change it on certain
|
---|
602 | conditions. If the program is covered by the GNU GPL, say so
|
---|
603 | here. Also mention that there is no warranty, to the extent
|
---|
604 | permitted by law.
|
---|
605 |
|
---|
606 | It is ok to finish the output with a list of the major authors of
|
---|
607 | the program, as a way of giving credit.
|
---|
608 |
|
---|
609 | Here's an example of output that follows these rules:
|
---|
610 |
|
---|
611 | GNU Emacs 19.34.5
|
---|
612 | Copyright (C) 1996 Free Software Foundation, Inc.
|
---|
613 | GNU Emacs comes with NO WARRANTY,
|
---|
614 | to the extent permitted by law.
|
---|
615 | You may redistribute copies of GNU Emacs
|
---|
616 | under the terms of the GNU General Public License.
|
---|
617 | For more information about these matters,
|
---|
618 | see the files named COPYING.
|
---|
619 |
|
---|
620 | You should adapt this to your program, of course, filling in the
|
---|
621 | proper year, copyright holder, name of program, and the references
|
---|
622 | to distribution terms, and changing the rest of the wording as
|
---|
623 | necessary.
|
---|
624 |
|
---|
625 | This copyright notice only needs to mention the most recent year in
|
---|
626 | which changes were made--there's no need to list the years for
|
---|
627 | previous versions' changes. You don't have to mention the name of
|
---|
628 | the program in these notices, if that is inconvenient, since it
|
---|
629 | appeared in the first line.
|
---|
630 |
|
---|
631 | `--help'
|
---|
632 | This option should output brief documentation for how to invoke the
|
---|
633 | program, on standard output, then exit successfully. Other
|
---|
634 | options and arguments should be ignored once this is seen, and the
|
---|
635 | program should not perform its normal function.
|
---|
636 |
|
---|
637 | Near the end of the `--help' option's output there should be a line
|
---|
638 | that says where to mail bug reports. It should have this format:
|
---|
639 |
|
---|
640 | Report bugs to MAILING-ADDRESS.
|
---|
641 |
|
---|
642 |
|
---|
643 | File: standards.info, Node: Option Table, Next: Memory Usage, Prev: User Interfaces, Up: Program Behavior
|
---|
644 |
|
---|
645 | Table of Long Options
|
---|
646 | =====================
|
---|
647 |
|
---|
648 | Here is a table of long options used by GNU programs. It is surely
|
---|
649 | incomplete, but we aim to list all the options that a new program might
|
---|
650 | want to be compatible with. If you use names not already in the table,
|
---|
651 | please send <gnu@gnu.org> a list of them, with their meanings, so we
|
---|
652 | can update the table.
|
---|
653 |
|
---|
654 | `after-date'
|
---|
655 | `-N' in `tar'.
|
---|
656 |
|
---|
657 | `all'
|
---|
658 | `-a' in `du', `ls', `nm', `stty', `uname', and `unexpand'.
|
---|
659 |
|
---|
660 | `all-text'
|
---|
661 | `-a' in `diff'.
|
---|
662 |
|
---|
663 | `almost-all'
|
---|
664 | `-A' in `ls'.
|
---|
665 |
|
---|
666 | `append'
|
---|
667 | `-a' in `etags', `tee', `time'; `-r' in `tar'.
|
---|
668 |
|
---|
669 | `archive'
|
---|
670 | `-a' in `cp'.
|
---|
671 |
|
---|
672 | `archive-name'
|
---|
673 | `-n' in `shar'.
|
---|
674 |
|
---|
675 | `arglength'
|
---|
676 | `-l' in `m4'.
|
---|
677 |
|
---|
678 | `ascii'
|
---|
679 | `-a' in `diff'.
|
---|
680 |
|
---|
681 | `assign'
|
---|
682 | `-v' in `gawk'.
|
---|
683 |
|
---|
684 | `assume-new'
|
---|
685 | `-W' in Make.
|
---|
686 |
|
---|
687 | `assume-old'
|
---|
688 | `-o' in Make.
|
---|
689 |
|
---|
690 | `auto-check'
|
---|
691 | `-a' in `recode'.
|
---|
692 |
|
---|
693 | `auto-pager'
|
---|
694 | `-a' in `wdiff'.
|
---|
695 |
|
---|
696 | `auto-reference'
|
---|
697 | `-A' in `ptx'.
|
---|
698 |
|
---|
699 | `avoid-wraps'
|
---|
700 | `-n' in `wdiff'.
|
---|
701 |
|
---|
702 | `background'
|
---|
703 | For server programs, run in the background.
|
---|
704 |
|
---|
705 | `backward-search'
|
---|
706 | `-B' in `ctags'.
|
---|
707 |
|
---|
708 | `basename'
|
---|
709 | `-f' in `shar'.
|
---|
710 |
|
---|
711 | `batch'
|
---|
712 | Used in GDB.
|
---|
713 |
|
---|
714 | `baud'
|
---|
715 | Used in GDB.
|
---|
716 |
|
---|
717 | `before'
|
---|
718 | `-b' in `tac'.
|
---|
719 |
|
---|
720 | `binary'
|
---|
721 | `-b' in `cpio' and `diff'.
|
---|
722 |
|
---|
723 | `bits-per-code'
|
---|
724 | `-b' in `shar'.
|
---|
725 |
|
---|
726 | `block-size'
|
---|
727 | Used in `cpio' and `tar'.
|
---|
728 |
|
---|
729 | `blocks'
|
---|
730 | `-b' in `head' and `tail'.
|
---|
731 |
|
---|
732 | `break-file'
|
---|
733 | `-b' in `ptx'.
|
---|
734 |
|
---|
735 | `brief'
|
---|
736 | Used in various programs to make output shorter.
|
---|
737 |
|
---|
738 | `bytes'
|
---|
739 | `-c' in `head', `split', and `tail'.
|
---|
740 |
|
---|
741 | `c++'
|
---|
742 | `-C' in `etags'.
|
---|
743 |
|
---|
744 | `catenate'
|
---|
745 | `-A' in `tar'.
|
---|
746 |
|
---|
747 | `cd'
|
---|
748 | Used in various programs to specify the directory to use.
|
---|
749 |
|
---|
750 | `changes'
|
---|
751 | `-c' in `chgrp' and `chown'.
|
---|
752 |
|
---|
753 | `classify'
|
---|
754 | `-F' in `ls'.
|
---|
755 |
|
---|
756 | `colons'
|
---|
757 | `-c' in `recode'.
|
---|
758 |
|
---|
759 | `command'
|
---|
760 | `-c' in `su'; `-x' in GDB.
|
---|
761 |
|
---|
762 | `compare'
|
---|
763 | `-d' in `tar'.
|
---|
764 |
|
---|
765 | `compat'
|
---|
766 | Used in `gawk'.
|
---|
767 |
|
---|
768 | `compress'
|
---|
769 | `-Z' in `tar' and `shar'.
|
---|
770 |
|
---|
771 | `concatenate'
|
---|
772 | `-A' in `tar'.
|
---|
773 |
|
---|
774 | `confirmation'
|
---|
775 | `-w' in `tar'.
|
---|
776 |
|
---|
777 | `context'
|
---|
778 | Used in `diff'.
|
---|
779 |
|
---|
780 | `copyleft'
|
---|
781 | `-W copyleft' in `gawk'.
|
---|
782 |
|
---|
783 | `copyright'
|
---|
784 | `-C' in `ptx', `recode', and `wdiff'; `-W copyright' in `gawk'.
|
---|
785 |
|
---|
786 | `core'
|
---|
787 | Used in GDB.
|
---|
788 |
|
---|
789 | `count'
|
---|
790 | `-q' in `who'.
|
---|
791 |
|
---|
792 | `count-links'
|
---|
793 | `-l' in `du'.
|
---|
794 |
|
---|
795 | `create'
|
---|
796 | Used in `tar' and `cpio'.
|
---|
797 |
|
---|
798 | `cut-mark'
|
---|
799 | `-c' in `shar'.
|
---|
800 |
|
---|
801 | `cxref'
|
---|
802 | `-x' in `ctags'.
|
---|
803 |
|
---|
804 | `date'
|
---|
805 | `-d' in `touch'.
|
---|
806 |
|
---|
807 | `debug'
|
---|
808 | `-d' in Make and `m4'; `-t' in Bison.
|
---|
809 |
|
---|
810 | `define'
|
---|
811 | `-D' in `m4'.
|
---|
812 |
|
---|
813 | `defines'
|
---|
814 | `-d' in Bison and `ctags'.
|
---|
815 |
|
---|
816 | `delete'
|
---|
817 | `-D' in `tar'.
|
---|
818 |
|
---|
819 | `dereference'
|
---|
820 | `-L' in `chgrp', `chown', `cpio', `du', `ls', and `tar'.
|
---|
821 |
|
---|
822 | `dereference-args'
|
---|
823 | `-D' in `du'.
|
---|
824 |
|
---|
825 | `diacritics'
|
---|
826 | `-d' in `recode'.
|
---|
827 |
|
---|
828 | `dictionary-order'
|
---|
829 | `-d' in `look'.
|
---|
830 |
|
---|
831 | `diff'
|
---|
832 | `-d' in `tar'.
|
---|
833 |
|
---|
834 | `digits'
|
---|
835 | `-n' in `csplit'.
|
---|
836 |
|
---|
837 | `directory'
|
---|
838 | Specify the directory to use, in various programs. In `ls', it
|
---|
839 | means to show directories themselves rather than their contents.
|
---|
840 | In `rm' and `ln', it means to not treat links to directories
|
---|
841 | specially.
|
---|
842 |
|
---|
843 | `discard-all'
|
---|
844 | `-x' in `strip'.
|
---|
845 |
|
---|
846 | `discard-locals'
|
---|
847 | `-X' in `strip'.
|
---|
848 |
|
---|
849 | `dry-run'
|
---|
850 | `-n' in Make.
|
---|
851 |
|
---|
852 | `ed'
|
---|
853 | `-e' in `diff'.
|
---|
854 |
|
---|
855 | `elide-empty-files'
|
---|
856 | `-z' in `csplit'.
|
---|
857 |
|
---|
858 | `end-delete'
|
---|
859 | `-x' in `wdiff'.
|
---|
860 |
|
---|
861 | `end-insert'
|
---|
862 | `-z' in `wdiff'.
|
---|
863 |
|
---|
864 | `entire-new-file'
|
---|
865 | `-N' in `diff'.
|
---|
866 |
|
---|
867 | `environment-overrides'
|
---|
868 | `-e' in Make.
|
---|
869 |
|
---|
870 | `eof'
|
---|
871 | `-e' in `xargs'.
|
---|
872 |
|
---|
873 | `epoch'
|
---|
874 | Used in GDB.
|
---|
875 |
|
---|
876 | `error-limit'
|
---|
877 | Used in `makeinfo'.
|
---|
878 |
|
---|
879 | `error-output'
|
---|
880 | `-o' in `m4'.
|
---|
881 |
|
---|
882 | `escape'
|
---|
883 | `-b' in `ls'.
|
---|
884 |
|
---|
885 | `exclude-from'
|
---|
886 | `-X' in `tar'.
|
---|
887 |
|
---|
888 | `exec'
|
---|
889 | Used in GDB.
|
---|
890 |
|
---|
891 | `exit'
|
---|
892 | `-x' in `xargs'.
|
---|
893 |
|
---|
894 | `exit-0'
|
---|
895 | `-e' in `unshar'.
|
---|
896 |
|
---|
897 | `expand-tabs'
|
---|
898 | `-t' in `diff'.
|
---|
899 |
|
---|
900 | `expression'
|
---|
901 | `-e' in `sed'.
|
---|
902 |
|
---|
903 | `extern-only'
|
---|
904 | `-g' in `nm'.
|
---|
905 |
|
---|
906 | `extract'
|
---|
907 | `-i' in `cpio'; `-x' in `tar'.
|
---|
908 |
|
---|
909 | `faces'
|
---|
910 | `-f' in `finger'.
|
---|
911 |
|
---|
912 | `fast'
|
---|
913 | `-f' in `su'.
|
---|
914 |
|
---|
915 | `fatal-warnings'
|
---|
916 | `-E' in `m4'.
|
---|
917 |
|
---|
918 | `file'
|
---|
919 | `-f' in `info', `gawk', Make, `mt', and `tar'; `-n' in `sed'; `-r'
|
---|
920 | in `touch'.
|
---|
921 |
|
---|
922 | `field-separator'
|
---|
923 | `-F' in `gawk'.
|
---|
924 |
|
---|
925 | `file-prefix'
|
---|
926 | `-b' in Bison.
|
---|
927 |
|
---|
928 | `file-type'
|
---|
929 | `-F' in `ls'.
|
---|
930 |
|
---|
931 | `files-from'
|
---|
932 | `-T' in `tar'.
|
---|
933 |
|
---|
934 | `fill-column'
|
---|
935 | Used in `makeinfo'.
|
---|
936 |
|
---|
937 | `flag-truncation'
|
---|
938 | `-F' in `ptx'.
|
---|
939 |
|
---|
940 | `fixed-output-files'
|
---|
941 | `-y' in Bison.
|
---|
942 |
|
---|
943 | `follow'
|
---|
944 | `-f' in `tail'.
|
---|
945 |
|
---|
946 | `footnote-style'
|
---|
947 | Used in `makeinfo'.
|
---|
948 |
|
---|
949 | `force'
|
---|
950 | `-f' in `cp', `ln', `mv', and `rm'.
|
---|
951 |
|
---|
952 | `force-prefix'
|
---|
953 | `-F' in `shar'.
|
---|
954 |
|
---|
955 | `foreground'
|
---|
956 | For server programs, run in the foreground; in other words, don't
|
---|
957 | do anything special to run the server in the background.
|
---|
958 |
|
---|
959 | `format'
|
---|
960 | Used in `ls', `time', and `ptx'.
|
---|
961 |
|
---|
962 | `freeze-state'
|
---|
963 | `-F' in `m4'.
|
---|
964 |
|
---|
965 | `fullname'
|
---|
966 | Used in GDB.
|
---|
967 |
|
---|
968 | `gap-size'
|
---|
969 | `-g' in `ptx'.
|
---|
970 |
|
---|
971 | `get'
|
---|
972 | `-x' in `tar'.
|
---|
973 |
|
---|
974 | `graphic'
|
---|
975 | `-i' in `ul'.
|
---|
976 |
|
---|
977 | `graphics'
|
---|
978 | `-g' in `recode'.
|
---|
979 |
|
---|
980 | `group'
|
---|
981 | `-g' in `install'.
|
---|
982 |
|
---|
983 | `gzip'
|
---|
984 | `-z' in `tar' and `shar'.
|
---|
985 |
|
---|
986 | `hashsize'
|
---|
987 | `-H' in `m4'.
|
---|
988 |
|
---|
989 | `header'
|
---|
990 | `-h' in `objdump' and `recode'
|
---|
991 |
|
---|
992 | `heading'
|
---|
993 | `-H' in `who'.
|
---|
994 |
|
---|
995 | `help'
|
---|
996 | Used to ask for brief usage information.
|
---|
997 |
|
---|
998 | `here-delimiter'
|
---|
999 | `-d' in `shar'.
|
---|
1000 |
|
---|
1001 | `hide-control-chars'
|
---|
1002 | `-q' in `ls'.
|
---|
1003 |
|
---|
1004 | `idle'
|
---|
1005 | `-u' in `who'.
|
---|
1006 |
|
---|
1007 | `ifdef'
|
---|
1008 | `-D' in `diff'.
|
---|
1009 |
|
---|
1010 | `ignore'
|
---|
1011 | `-I' in `ls'; `-x' in `recode'.
|
---|
1012 |
|
---|
1013 | `ignore-all-space'
|
---|
1014 | `-w' in `diff'.
|
---|
1015 |
|
---|
1016 | `ignore-backups'
|
---|
1017 | `-B' in `ls'.
|
---|
1018 |
|
---|
1019 | `ignore-blank-lines'
|
---|
1020 | `-B' in `diff'.
|
---|
1021 |
|
---|
1022 | `ignore-case'
|
---|
1023 | `-f' in `look' and `ptx'; `-i' in `diff' and `wdiff'.
|
---|
1024 |
|
---|
1025 | `ignore-errors'
|
---|
1026 | `-i' in Make.
|
---|
1027 |
|
---|
1028 | `ignore-file'
|
---|
1029 | `-i' in `ptx'.
|
---|
1030 |
|
---|
1031 | `ignore-indentation'
|
---|
1032 | `-I' in `etags'.
|
---|
1033 |
|
---|
1034 | `ignore-init-file'
|
---|
1035 | `-f' in Oleo.
|
---|
1036 |
|
---|
1037 | `ignore-interrupts'
|
---|
1038 | `-i' in `tee'.
|
---|
1039 |
|
---|
1040 | `ignore-matching-lines'
|
---|
1041 | `-I' in `diff'.
|
---|
1042 |
|
---|
1043 | `ignore-space-change'
|
---|
1044 | `-b' in `diff'.
|
---|
1045 |
|
---|
1046 | `ignore-zeros'
|
---|
1047 | `-i' in `tar'.
|
---|
1048 |
|
---|
1049 | `include'
|
---|
1050 | `-i' in `etags'; `-I' in `m4'.
|
---|
1051 |
|
---|
1052 | `include-dir'
|
---|
1053 | `-I' in Make.
|
---|
1054 |
|
---|
1055 | `incremental'
|
---|
1056 | `-G' in `tar'.
|
---|
1057 |
|
---|
1058 | `info'
|
---|
1059 | `-i', `-l', and `-m' in Finger.
|
---|
1060 |
|
---|
1061 | `initial'
|
---|
1062 | `-i' in `expand'.
|
---|
1063 |
|
---|
1064 | `initial-tab'
|
---|
1065 | `-T' in `diff'.
|
---|
1066 |
|
---|
1067 | `inode'
|
---|
1068 | `-i' in `ls'.
|
---|
1069 |
|
---|
1070 | `interactive'
|
---|
1071 | `-i' in `cp', `ln', `mv', `rm'; `-e' in `m4'; `-p' in `xargs';
|
---|
1072 | `-w' in `tar'.
|
---|
1073 |
|
---|
1074 | `intermix-type'
|
---|
1075 | `-p' in `shar'.
|
---|
1076 |
|
---|
1077 | `jobs'
|
---|
1078 | `-j' in Make.
|
---|
1079 |
|
---|
1080 | `just-print'
|
---|
1081 | `-n' in Make.
|
---|
1082 |
|
---|
1083 | `keep-going'
|
---|
1084 | `-k' in Make.
|
---|
1085 |
|
---|
1086 | `keep-files'
|
---|
1087 | `-k' in `csplit'.
|
---|
1088 |
|
---|
1089 | `kilobytes'
|
---|
1090 | `-k' in `du' and `ls'.
|
---|
1091 |
|
---|
1092 | `language'
|
---|
1093 | `-l' in `etags'.
|
---|
1094 |
|
---|
1095 | `less-mode'
|
---|
1096 | `-l' in `wdiff'.
|
---|
1097 |
|
---|
1098 | `level-for-gzip'
|
---|
1099 | `-g' in `shar'.
|
---|
1100 |
|
---|
1101 | `line-bytes'
|
---|
1102 | `-C' in `split'.
|
---|
1103 |
|
---|
1104 | `lines'
|
---|
1105 | Used in `split', `head', and `tail'.
|
---|
1106 |
|
---|
1107 | `link'
|
---|
1108 | `-l' in `cpio'.
|
---|
1109 |
|
---|
1110 | `lint'
|
---|
1111 | `lint-old'
|
---|
1112 | Used in `gawk'.
|
---|
1113 |
|
---|
1114 | `list'
|
---|
1115 | `-t' in `cpio'; `-l' in `recode'.
|
---|
1116 |
|
---|
1117 | `list'
|
---|
1118 | `-t' in `tar'.
|
---|
1119 |
|
---|
1120 | `literal'
|
---|
1121 | `-N' in `ls'.
|
---|
1122 |
|
---|
1123 | `load-average'
|
---|
1124 | `-l' in Make.
|
---|
1125 |
|
---|
1126 | `login'
|
---|
1127 | Used in `su'.
|
---|
1128 |
|
---|
1129 | `machine'
|
---|
1130 | No listing of which programs already use this; someone should
|
---|
1131 | check to see if any actually do, and tell <gnu@gnu.org>.
|
---|
1132 |
|
---|
1133 | `macro-name'
|
---|
1134 | `-M' in `ptx'.
|
---|
1135 |
|
---|
1136 | `mail'
|
---|
1137 | `-m' in `hello' and `uname'.
|
---|
1138 |
|
---|
1139 | `make-directories'
|
---|
1140 | `-d' in `cpio'.
|
---|
1141 |
|
---|
1142 | `makefile'
|
---|
1143 | `-f' in Make.
|
---|
1144 |
|
---|
1145 | `mapped'
|
---|
1146 | Used in GDB.
|
---|
1147 |
|
---|
1148 | `max-args'
|
---|
1149 | `-n' in `xargs'.
|
---|
1150 |
|
---|
1151 | `max-chars'
|
---|
1152 | `-n' in `xargs'.
|
---|
1153 |
|
---|
1154 | `max-lines'
|
---|
1155 | `-l' in `xargs'.
|
---|
1156 |
|
---|
1157 | `max-load'
|
---|
1158 | `-l' in Make.
|
---|
1159 |
|
---|
1160 | `max-procs'
|
---|
1161 | `-P' in `xargs'.
|
---|
1162 |
|
---|
1163 | `mesg'
|
---|
1164 | `-T' in `who'.
|
---|
1165 |
|
---|
1166 | `message'
|
---|
1167 | `-T' in `who'.
|
---|
1168 |
|
---|
1169 | `minimal'
|
---|
1170 | `-d' in `diff'.
|
---|
1171 |
|
---|
1172 | `mixed-uuencode'
|
---|
1173 | `-M' in `shar'.
|
---|
1174 |
|
---|
1175 | `mode'
|
---|
1176 | `-m' in `install', `mkdir', and `mkfifo'.
|
---|
1177 |
|
---|
1178 | `modification-time'
|
---|
1179 | `-m' in `tar'.
|
---|
1180 |
|
---|
1181 | `multi-volume'
|
---|
1182 | `-M' in `tar'.
|
---|
1183 |
|
---|
1184 | `name-prefix'
|
---|
1185 | `-a' in Bison.
|
---|
1186 |
|
---|
1187 | `nesting-limit'
|
---|
1188 | `-L' in `m4'.
|
---|
1189 |
|
---|
1190 | `net-headers'
|
---|
1191 | `-a' in `shar'.
|
---|
1192 |
|
---|
1193 | `new-file'
|
---|
1194 | `-W' in Make.
|
---|
1195 |
|
---|
1196 | `no-builtin-rules'
|
---|
1197 | `-r' in Make.
|
---|
1198 |
|
---|
1199 | `no-character-count'
|
---|
1200 | `-w' in `shar'.
|
---|
1201 |
|
---|
1202 | `no-check-existing'
|
---|
1203 | `-x' in `shar'.
|
---|
1204 |
|
---|
1205 | `no-common'
|
---|
1206 | `-3' in `wdiff'.
|
---|
1207 |
|
---|
1208 | `no-create'
|
---|
1209 | `-c' in `touch'.
|
---|
1210 |
|
---|
1211 | `no-defines'
|
---|
1212 | `-D' in `etags'.
|
---|
1213 |
|
---|
1214 | `no-deleted'
|
---|
1215 | `-1' in `wdiff'.
|
---|
1216 |
|
---|
1217 | `no-dereference'
|
---|
1218 | `-d' in `cp'.
|
---|
1219 |
|
---|
1220 | `no-inserted'
|
---|
1221 | `-2' in `wdiff'.
|
---|
1222 |
|
---|
1223 | `no-keep-going'
|
---|
1224 | `-S' in Make.
|
---|
1225 |
|
---|
1226 | `no-lines'
|
---|
1227 | `-l' in Bison.
|
---|
1228 |
|
---|
1229 | `no-piping'
|
---|
1230 | `-P' in `shar'.
|
---|
1231 |
|
---|
1232 | `no-prof'
|
---|
1233 | `-e' in `gprof'.
|
---|
1234 |
|
---|
1235 | `no-regex'
|
---|
1236 | `-R' in `etags'.
|
---|
1237 |
|
---|
1238 | `no-sort'
|
---|
1239 | `-p' in `nm'.
|
---|
1240 |
|
---|
1241 | `no-split'
|
---|
1242 | Used in `makeinfo'.
|
---|
1243 |
|
---|
1244 | `no-static'
|
---|
1245 | `-a' in `gprof'.
|
---|
1246 |
|
---|
1247 | `no-time'
|
---|
1248 | `-E' in `gprof'.
|
---|
1249 |
|
---|
1250 | `no-timestamp'
|
---|
1251 | `-m' in `shar'.
|
---|
1252 |
|
---|
1253 | `no-validate'
|
---|
1254 | Used in `makeinfo'.
|
---|
1255 |
|
---|
1256 | `no-wait'
|
---|
1257 | Used in `emacsclient'.
|
---|
1258 |
|
---|
1259 | `no-warn'
|
---|
1260 | Used in various programs to inhibit warnings.
|
---|
1261 |
|
---|
1262 | `node'
|
---|
1263 | `-n' in `info'.
|
---|
1264 |
|
---|
1265 | `nodename'
|
---|
1266 | `-n' in `uname'.
|
---|
1267 |
|
---|
1268 | `nonmatching'
|
---|
1269 | `-f' in `cpio'.
|
---|
1270 |
|
---|
1271 | `nstuff'
|
---|
1272 | `-n' in `objdump'.
|
---|
1273 |
|
---|
1274 | `null'
|
---|
1275 | `-0' in `xargs'.
|
---|
1276 |
|
---|
1277 | `number'
|
---|
1278 | `-n' in `cat'.
|
---|
1279 |
|
---|
1280 | `number-nonblank'
|
---|
1281 | `-b' in `cat'.
|
---|
1282 |
|
---|
1283 | `numeric-sort'
|
---|
1284 | `-n' in `nm'.
|
---|
1285 |
|
---|
1286 | `numeric-uid-gid'
|
---|
1287 | `-n' in `cpio' and `ls'.
|
---|
1288 |
|
---|
1289 | `nx'
|
---|
1290 | Used in GDB.
|
---|
1291 |
|
---|
1292 | `old-archive'
|
---|
1293 | `-o' in `tar'.
|
---|
1294 |
|
---|
1295 | `old-file'
|
---|
1296 | `-o' in Make.
|
---|
1297 |
|
---|
1298 | `one-file-system'
|
---|
1299 | `-l' in `tar', `cp', and `du'.
|
---|
1300 |
|
---|
1301 | `only-file'
|
---|
1302 | `-o' in `ptx'.
|
---|
1303 |
|
---|
1304 | `only-prof'
|
---|
1305 | `-f' in `gprof'.
|
---|
1306 |
|
---|
1307 | `only-time'
|
---|
1308 | `-F' in `gprof'.
|
---|
1309 |
|
---|
1310 | `output'
|
---|
1311 | In various programs, specify the output file name.
|
---|
1312 |
|
---|
1313 | `output-prefix'
|
---|
1314 | `-o' in `shar'.
|
---|
1315 |
|
---|
1316 | `override'
|
---|
1317 | `-o' in `rm'.
|
---|
1318 |
|
---|
1319 | `overwrite'
|
---|
1320 | `-c' in `unshar'.
|
---|
1321 |
|
---|
1322 | `owner'
|
---|
1323 | `-o' in `install'.
|
---|
1324 |
|
---|
1325 | `paginate'
|
---|
1326 | `-l' in `diff'.
|
---|
1327 |
|
---|
1328 | `paragraph-indent'
|
---|
1329 | Used in `makeinfo'.
|
---|
1330 |
|
---|
1331 | `parents'
|
---|
1332 | `-p' in `mkdir' and `rmdir'.
|
---|
1333 |
|
---|
1334 | `pass-all'
|
---|
1335 | `-p' in `ul'.
|
---|
1336 |
|
---|
1337 | `pass-through'
|
---|
1338 | `-p' in `cpio'.
|
---|
1339 |
|
---|
1340 | `port'
|
---|
1341 | `-P' in `finger'.
|
---|
1342 |
|
---|
1343 | `portability'
|
---|
1344 | `-c' in `cpio' and `tar'.
|
---|
1345 |
|
---|
1346 | `posix'
|
---|
1347 | Used in `gawk'.
|
---|
1348 |
|
---|
1349 | `prefix-builtins'
|
---|
1350 | `-P' in `m4'.
|
---|
1351 |
|
---|
1352 | `prefix'
|
---|
1353 | `-f' in `csplit'.
|
---|
1354 |
|
---|
1355 | `preserve'
|
---|
1356 | Used in `tar' and `cp'.
|
---|
1357 |
|
---|
1358 | `preserve-environment'
|
---|
1359 | `-p' in `su'.
|
---|
1360 |
|
---|
1361 | `preserve-modification-time'
|
---|
1362 | `-m' in `cpio'.
|
---|
1363 |
|
---|
1364 | `preserve-order'
|
---|
1365 | `-s' in `tar'.
|
---|
1366 |
|
---|
1367 | `preserve-permissions'
|
---|
1368 | `-p' in `tar'.
|
---|
1369 |
|
---|
1370 | `print'
|
---|
1371 | `-l' in `diff'.
|
---|
1372 |
|
---|
1373 | `print-chars'
|
---|
1374 | `-L' in `cmp'.
|
---|
1375 |
|
---|
1376 | `print-data-base'
|
---|
1377 | `-p' in Make.
|
---|
1378 |
|
---|
1379 | `print-directory'
|
---|
1380 | `-w' in Make.
|
---|
1381 |
|
---|
1382 | `print-file-name'
|
---|
1383 | `-o' in `nm'.
|
---|
1384 |
|
---|
1385 | `print-symdefs'
|
---|
1386 | `-s' in `nm'.
|
---|
1387 |
|
---|
1388 | `printer'
|
---|
1389 | `-p' in `wdiff'.
|
---|
1390 |
|
---|
1391 | `prompt'
|
---|
1392 | `-p' in `ed'.
|
---|
1393 |
|
---|
1394 | `query-user'
|
---|
1395 | `-X' in `shar'.
|
---|
1396 |
|
---|
1397 | `question'
|
---|
1398 | `-q' in Make.
|
---|
1399 |
|
---|
1400 | `quiet'
|
---|
1401 | Used in many programs to inhibit the usual output. *Note:* every
|
---|
1402 | program accepting `--quiet' should accept `--silent' as a synonym.
|
---|
1403 |
|
---|
1404 | `quiet-unshar'
|
---|
1405 | `-Q' in `shar'
|
---|
1406 |
|
---|
1407 | `quote-name'
|
---|
1408 | `-Q' in `ls'.
|
---|
1409 |
|
---|
1410 | `rcs'
|
---|
1411 | `-n' in `diff'.
|
---|
1412 |
|
---|
1413 | `re-interval'
|
---|
1414 | Used in `gawk'.
|
---|
1415 |
|
---|
1416 | `read-full-blocks'
|
---|
1417 | `-B' in `tar'.
|
---|
1418 |
|
---|
1419 | `readnow'
|
---|
1420 | Used in GDB.
|
---|
1421 |
|
---|
1422 | `recon'
|
---|
1423 | `-n' in Make.
|
---|
1424 |
|
---|
1425 | `record-number'
|
---|
1426 | `-R' in `tar'.
|
---|
1427 |
|
---|
1428 | `recursive'
|
---|
1429 | Used in `chgrp', `chown', `cp', `ls', `diff', and `rm'.
|
---|
1430 |
|
---|
1431 | `reference-limit'
|
---|
1432 | Used in `makeinfo'.
|
---|
1433 |
|
---|
1434 | `references'
|
---|
1435 | `-r' in `ptx'.
|
---|
1436 |
|
---|
1437 | `regex'
|
---|
1438 | `-r' in `tac' and `etags'.
|
---|
1439 |
|
---|
1440 | `release'
|
---|
1441 | `-r' in `uname'.
|
---|
1442 |
|
---|
1443 | `reload-state'
|
---|
1444 | `-R' in `m4'.
|
---|
1445 |
|
---|
1446 | `relocation'
|
---|
1447 | `-r' in `objdump'.
|
---|
1448 |
|
---|
1449 | `rename'
|
---|
1450 | `-r' in `cpio'.
|
---|
1451 |
|
---|
1452 | `replace'
|
---|
1453 | `-i' in `xargs'.
|
---|
1454 |
|
---|
1455 | `report-identical-files'
|
---|
1456 | `-s' in `diff'.
|
---|
1457 |
|
---|
1458 | `reset-access-time'
|
---|
1459 | `-a' in `cpio'.
|
---|
1460 |
|
---|
1461 | `reverse'
|
---|
1462 | `-r' in `ls' and `nm'.
|
---|
1463 |
|
---|
1464 | `reversed-ed'
|
---|
1465 | `-f' in `diff'.
|
---|
1466 |
|
---|
1467 | `right-side-defs'
|
---|
1468 | `-R' in `ptx'.
|
---|
1469 |
|
---|
1470 | `same-order'
|
---|
1471 | `-s' in `tar'.
|
---|
1472 |
|
---|
1473 | `same-permissions'
|
---|
1474 | `-p' in `tar'.
|
---|
1475 |
|
---|
1476 | `save'
|
---|
1477 | `-g' in `stty'.
|
---|
1478 |
|
---|
1479 | `se'
|
---|
1480 | Used in GDB.
|
---|
1481 |
|
---|
1482 | `sentence-regexp'
|
---|
1483 | `-S' in `ptx'.
|
---|
1484 |
|
---|
1485 | `separate-dirs'
|
---|
1486 | `-S' in `du'.
|
---|
1487 |
|
---|
1488 | `separator'
|
---|
1489 | `-s' in `tac'.
|
---|
1490 |
|
---|
1491 | `sequence'
|
---|
1492 | Used by `recode' to chose files or pipes for sequencing passes.
|
---|
1493 |
|
---|
1494 | `shell'
|
---|
1495 | `-s' in `su'.
|
---|
1496 |
|
---|
1497 | `show-all'
|
---|
1498 | `-A' in `cat'.
|
---|
1499 |
|
---|
1500 | `show-c-function'
|
---|
1501 | `-p' in `diff'.
|
---|
1502 |
|
---|
1503 | `show-ends'
|
---|
1504 | `-E' in `cat'.
|
---|
1505 |
|
---|
1506 | `show-function-line'
|
---|
1507 | `-F' in `diff'.
|
---|
1508 |
|
---|
1509 | `show-tabs'
|
---|
1510 | `-T' in `cat'.
|
---|
1511 |
|
---|
1512 | `silent'
|
---|
1513 | Used in many programs to inhibit the usual output. *Note:* every
|
---|
1514 | program accepting `--silent' should accept `--quiet' as a synonym.
|
---|
1515 |
|
---|
1516 | `size'
|
---|
1517 | `-s' in `ls'.
|
---|
1518 |
|
---|
1519 | `socket'
|
---|
1520 | Specify a file descriptor for a network server to use for its
|
---|
1521 | socket, instead of opening and binding a new socket. This
|
---|
1522 | provides a way to run, in a nonpriveledged process, a server that
|
---|
1523 | normally needs a reserved port number.
|
---|
1524 |
|
---|
1525 | `sort'
|
---|
1526 | Used in `ls'.
|
---|
1527 |
|
---|
1528 | `source'
|
---|
1529 | `-W source' in `gawk'.
|
---|
1530 |
|
---|
1531 | `sparse'
|
---|
1532 | `-S' in `tar'.
|
---|
1533 |
|
---|
1534 | `speed-large-files'
|
---|
1535 | `-H' in `diff'.
|
---|
1536 |
|
---|
1537 | `split-at'
|
---|
1538 | `-E' in `unshar'.
|
---|
1539 |
|
---|
1540 | `split-size-limit'
|
---|
1541 | `-L' in `shar'.
|
---|
1542 |
|
---|
1543 | `squeeze-blank'
|
---|
1544 | `-s' in `cat'.
|
---|
1545 |
|
---|
1546 | `start-delete'
|
---|
1547 | `-w' in `wdiff'.
|
---|
1548 |
|
---|
1549 | `start-insert'
|
---|
1550 | `-y' in `wdiff'.
|
---|
1551 |
|
---|
1552 | `starting-file'
|
---|
1553 | Used in `tar' and `diff' to specify which file within a directory
|
---|
1554 | to start processing with.
|
---|
1555 |
|
---|
1556 | `statistics'
|
---|
1557 | `-s' in `wdiff'.
|
---|
1558 |
|
---|
1559 | `stdin-file-list'
|
---|
1560 | `-S' in `shar'.
|
---|
1561 |
|
---|
1562 | `stop'
|
---|
1563 | `-S' in Make.
|
---|
1564 |
|
---|
1565 | `strict'
|
---|
1566 | `-s' in `recode'.
|
---|
1567 |
|
---|
1568 | `strip'
|
---|
1569 | `-s' in `install'.
|
---|
1570 |
|
---|
1571 | `strip-all'
|
---|
1572 | `-s' in `strip'.
|
---|
1573 |
|
---|
1574 | `strip-debug'
|
---|
1575 | `-S' in `strip'.
|
---|
1576 |
|
---|
1577 | `submitter'
|
---|
1578 | `-s' in `shar'.
|
---|
1579 |
|
---|
1580 | `suffix'
|
---|
1581 | `-S' in `cp', `ln', `mv'.
|
---|
1582 |
|
---|
1583 | `suffix-format'
|
---|
1584 | `-b' in `csplit'.
|
---|
1585 |
|
---|
1586 | `sum'
|
---|
1587 | `-s' in `gprof'.
|
---|
1588 |
|
---|
1589 | `summarize'
|
---|
1590 | `-s' in `du'.
|
---|
1591 |
|
---|
1592 | `symbolic'
|
---|
1593 | `-s' in `ln'.
|
---|
1594 |
|
---|
1595 | `symbols'
|
---|
1596 | Used in GDB and `objdump'.
|
---|
1597 |
|
---|
1598 | `synclines'
|
---|
1599 | `-s' in `m4'.
|
---|
1600 |
|
---|
1601 | `sysname'
|
---|
1602 | `-s' in `uname'.
|
---|
1603 |
|
---|
1604 | `tabs'
|
---|
1605 | `-t' in `expand' and `unexpand'.
|
---|
1606 |
|
---|
1607 | `tabsize'
|
---|
1608 | `-T' in `ls'.
|
---|
1609 |
|
---|
1610 | `terminal'
|
---|
1611 | `-T' in `tput' and `ul'. `-t' in `wdiff'.
|
---|
1612 |
|
---|
1613 | `text'
|
---|
1614 | `-a' in `diff'.
|
---|
1615 |
|
---|
1616 | `text-files'
|
---|
1617 | `-T' in `shar'.
|
---|
1618 |
|
---|
1619 | `time'
|
---|
1620 | Used in `ls' and `touch'.
|
---|
1621 |
|
---|
1622 | `to-stdout'
|
---|
1623 | `-O' in `tar'.
|
---|
1624 |
|
---|
1625 | `total'
|
---|
1626 | `-c' in `du'.
|
---|
1627 |
|
---|
1628 | `touch'
|
---|
1629 | `-t' in Make, `ranlib', and `recode'.
|
---|
1630 |
|
---|
1631 | `trace'
|
---|
1632 | `-t' in `m4'.
|
---|
1633 |
|
---|
1634 | `traditional'
|
---|
1635 | `-t' in `hello'; `-W traditional' in `gawk'; `-G' in `ed', `m4',
|
---|
1636 | and `ptx'.
|
---|
1637 |
|
---|
1638 | `tty'
|
---|
1639 | Used in GDB.
|
---|
1640 |
|
---|
1641 | `typedefs'
|
---|
1642 | `-t' in `ctags'.
|
---|
1643 |
|
---|
1644 | `typedefs-and-c++'
|
---|
1645 | `-T' in `ctags'.
|
---|
1646 |
|
---|
1647 | `typeset-mode'
|
---|
1648 | `-t' in `ptx'.
|
---|
1649 |
|
---|
1650 | `uncompress'
|
---|
1651 | `-z' in `tar'.
|
---|
1652 |
|
---|
1653 | `unconditional'
|
---|
1654 | `-u' in `cpio'.
|
---|
1655 |
|
---|
1656 | `undefine'
|
---|
1657 | `-U' in `m4'.
|
---|
1658 |
|
---|
1659 | `undefined-only'
|
---|
1660 | `-u' in `nm'.
|
---|
1661 |
|
---|
1662 | `update'
|
---|
1663 | `-u' in `cp', `ctags', `mv', `tar'.
|
---|
1664 |
|
---|
1665 | `usage'
|
---|
1666 | Used in `gawk'; same as `--help'.
|
---|
1667 |
|
---|
1668 | `uuencode'
|
---|
1669 | `-B' in `shar'.
|
---|
1670 |
|
---|
1671 | `vanilla-operation'
|
---|
1672 | `-V' in `shar'.
|
---|
1673 |
|
---|
1674 | `verbose'
|
---|
1675 | Print more information about progress. Many programs support this.
|
---|
1676 |
|
---|
1677 | `verify'
|
---|
1678 | `-W' in `tar'.
|
---|
1679 |
|
---|
1680 | `version'
|
---|
1681 | Print the version number.
|
---|
1682 |
|
---|
1683 | `version-control'
|
---|
1684 | `-V' in `cp', `ln', `mv'.
|
---|
1685 |
|
---|
1686 | `vgrind'
|
---|
1687 | `-v' in `ctags'.
|
---|
1688 |
|
---|
1689 | `volume'
|
---|
1690 | `-V' in `tar'.
|
---|
1691 |
|
---|
1692 | `what-if'
|
---|
1693 | `-W' in Make.
|
---|
1694 |
|
---|
1695 | `whole-size-limit'
|
---|
1696 | `-l' in `shar'.
|
---|
1697 |
|
---|
1698 | `width'
|
---|
1699 | `-w' in `ls' and `ptx'.
|
---|
1700 |
|
---|
1701 | `word-regexp'
|
---|
1702 | `-W' in `ptx'.
|
---|
1703 |
|
---|
1704 | `writable'
|
---|
1705 | `-T' in `who'.
|
---|
1706 |
|
---|
1707 | `zeros'
|
---|
1708 | `-z' in `gprof'.
|
---|
1709 |
|
---|
1710 |
|
---|
1711 | File: standards.info, Node: Memory Usage, Prev: Option Table, Up: Program Behavior
|
---|
1712 |
|
---|
1713 | Memory Usage
|
---|
1714 | ============
|
---|
1715 |
|
---|
1716 | If it typically uses just a few meg of memory, don't bother making
|
---|
1717 | any effort to reduce memory usage. For example, if it is impractical
|
---|
1718 | for other reasons to operate on files more than a few meg long, it is
|
---|
1719 | reasonable to read entire input files into core to operate on them.
|
---|
1720 |
|
---|
1721 | However, for programs such as `cat' or `tail', that can usefully
|
---|
1722 | operate on very large files, it is important to avoid using a technique
|
---|
1723 | that would artificially limit the size of files it can handle. If a
|
---|
1724 | program works by lines and could be applied to arbitrary user-supplied
|
---|
1725 | input files, it should keep only a line in memory, because this is not
|
---|
1726 | very hard and users will want to be able to operate on input files that
|
---|
1727 | are bigger than will fit in core all at once.
|
---|
1728 |
|
---|
1729 | If your program creates complicated data structures, just make them
|
---|
1730 | in core and give a fatal error if `malloc' returns zero.
|
---|
1731 |
|
---|
1732 |
|
---|
1733 | File: standards.info, Node: Writing C, Next: Documentation, Prev: Program Behavior, Up: Top
|
---|
1734 |
|
---|
1735 | Making The Best Use of C
|
---|
1736 | ************************
|
---|
1737 |
|
---|
1738 | This node provides advice on how best to use the C language when
|
---|
1739 | writing GNU software.
|
---|
1740 |
|
---|
1741 | * Menu:
|
---|
1742 |
|
---|
1743 | * Formatting:: Formatting Your Source Code
|
---|
1744 | * Comments:: Commenting Your Work
|
---|
1745 | * Syntactic Conventions:: Clean Use of C Constructs
|
---|
1746 | * Names:: Naming Variables and Functions
|
---|
1747 | * System Portability:: Portability between different operating systems
|
---|
1748 | * CPU Portability:: Supporting the range of CPU types
|
---|
1749 | * System Functions:: Portability and "standard" library functions
|
---|
1750 | * Internationalization:: Techniques for internationalization
|
---|
1751 | * Mmap:: How you can safely use `mmap'.
|
---|
1752 |
|
---|
1753 |
|
---|
1754 | File: standards.info, Node: Formatting, Next: Comments, Up: Writing C
|
---|
1755 |
|
---|
1756 | Formatting Your Source Code
|
---|
1757 | ===========================
|
---|
1758 |
|
---|
1759 | It is important to put the open-brace that starts the body of a C
|
---|
1760 | function in column zero, and avoid putting any other open-brace or
|
---|
1761 | open-parenthesis or open-bracket in column zero. Several tools look
|
---|
1762 | for open-braces in column zero to find the beginnings of C functions.
|
---|
1763 | These tools will not work on code not formatted that way.
|
---|
1764 |
|
---|
1765 | It is also important for function definitions to start the name of
|
---|
1766 | the function in column zero. This helps people to search for function
|
---|
1767 | definitions, and may also help certain tools recognize them. Thus, the
|
---|
1768 | proper format is this:
|
---|
1769 |
|
---|
1770 | static char *
|
---|
1771 | concat (s1, s2) /* Name starts in column zero here */
|
---|
1772 | char *s1, *s2;
|
---|
1773 | { /* Open brace in column zero here */
|
---|
1774 | ...
|
---|
1775 | }
|
---|
1776 |
|
---|
1777 | or, if you want to use ANSI C, format the definition like this:
|
---|
1778 |
|
---|
1779 | static char *
|
---|
1780 | concat (char *s1, char *s2)
|
---|
1781 | {
|
---|
1782 | ...
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 | In ANSI C, if the arguments don't fit nicely on one line, split it
|
---|
1786 | like this:
|
---|
1787 |
|
---|
1788 | int
|
---|
1789 | lots_of_args (int an_integer, long a_long, short a_short,
|
---|
1790 | double a_double, float a_float)
|
---|
1791 | ...
|
---|
1792 |
|
---|
1793 | For the body of the function, we prefer code formatted like this:
|
---|
1794 |
|
---|
1795 | if (x < foo (y, z))
|
---|
1796 | haha = bar[4] + 5;
|
---|
1797 | else
|
---|
1798 | {
|
---|
1799 | while (z)
|
---|
1800 | {
|
---|
1801 | haha += foo (z, z);
|
---|
1802 | z--;
|
---|
1803 | }
|
---|
1804 | return ++x + bar ();
|
---|
1805 | }
|
---|
1806 |
|
---|
1807 | We find it easier to read a program when it has spaces before the
|
---|
1808 | open-parentheses and after the commas. Especially after the commas.
|
---|
1809 |
|
---|
1810 | When you split an expression into multiple lines, split it before an
|
---|
1811 | operator, not after one. Here is the right way:
|
---|
1812 |
|
---|
1813 | if (foo_this_is_long && bar > win (x, y, z)
|
---|
1814 | && remaining_condition)
|
---|
1815 |
|
---|
1816 | Try to avoid having two operators of different precedence at the same
|
---|
1817 | level of indentation. For example, don't write this:
|
---|
1818 |
|
---|
1819 | mode = (inmode[j] == VOIDmode
|
---|
1820 | || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
|
---|
1821 | ? outmode[j] : inmode[j]);
|
---|
1822 |
|
---|
1823 | Instead, use extra parentheses so that the indentation shows the
|
---|
1824 | nesting:
|
---|
1825 |
|
---|
1826 | mode = ((inmode[j] == VOIDmode
|
---|
1827 | || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
|
---|
1828 | ? outmode[j] : inmode[j]);
|
---|
1829 |
|
---|
1830 | Insert extra parentheses so that Emacs will indent the code properly.
|
---|
1831 | For example, the following indentation looks nice if you do it by hand,
|
---|
1832 | but Emacs would mess it up:
|
---|
1833 |
|
---|
1834 | v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
|
---|
1835 | + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
|
---|
1836 |
|
---|
1837 | But adding a set of parentheses solves the problem:
|
---|
1838 |
|
---|
1839 | v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
|
---|
1840 | + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
|
---|
1841 |
|
---|
1842 | Format do-while statements like this:
|
---|
1843 |
|
---|
1844 | do
|
---|
1845 | {
|
---|
1846 | a = foo (a);
|
---|
1847 | }
|
---|
1848 | while (a > 0);
|
---|
1849 |
|
---|
1850 | Please use formfeed characters (control-L) to divide the program into
|
---|
1851 | pages at logical places (but not within a function). It does not matter
|
---|
1852 | just how long the pages are, since they do not have to fit on a printed
|
---|
1853 | page. The formfeeds should appear alone on lines by themselves.
|
---|
1854 |
|
---|
1855 |
|
---|
1856 | File: standards.info, Node: Comments, Next: Syntactic Conventions, Prev: Formatting, Up: Writing C
|
---|
1857 |
|
---|
1858 | Commenting Your Work
|
---|
1859 | ====================
|
---|
1860 |
|
---|
1861 | Every program should start with a comment saying briefly what it is
|
---|
1862 | for. Example: `fmt - filter for simple filling of text'.
|
---|
1863 |
|
---|
1864 | Please write the comments in a GNU program in English, because
|
---|
1865 | English is the one language that nearly all programmers in all
|
---|
1866 | countries can read. If you do not write English well, please write
|
---|
1867 | comments in English as well as you can, then ask other people to help
|
---|
1868 | rewrite them. If you can't write comments in English, please find
|
---|
1869 | someone to work with you and translate your comments into English.
|
---|
1870 |
|
---|
1871 | Please put a comment on each function saying what the function does,
|
---|
1872 | what sorts of arguments it gets, and what the possible values of
|
---|
1873 | arguments mean and are used for. It is not necessary to duplicate in
|
---|
1874 | words the meaning of the C argument declarations, if a C type is being
|
---|
1875 | used in its customary fashion. If there is anything nonstandard about
|
---|
1876 | its use (such as an argument of type `char *' which is really the
|
---|
1877 | address of the second character of a string, not the first), or any
|
---|
1878 | possible values that would not work the way one would expect (such as,
|
---|
1879 | that strings containing newlines are not guaranteed to work), be sure
|
---|
1880 | to say so.
|
---|
1881 |
|
---|
1882 | Also explain the significance of the return value, if there is one.
|
---|
1883 |
|
---|
1884 | Please put two spaces after the end of a sentence in your comments,
|
---|
1885 | so that the Emacs sentence commands will work. Also, please write
|
---|
1886 | complete sentences and capitalize the first word. If a lower-case
|
---|
1887 | identifier comes at the beginning of a sentence, don't capitalize it!
|
---|
1888 | Changing the spelling makes it a different identifier. If you don't
|
---|
1889 | like starting a sentence with a lower case letter, write the sentence
|
---|
1890 | differently (e.g., "The identifier lower-case is ...").
|
---|
1891 |
|
---|
1892 | The comment on a function is much clearer if you use the argument
|
---|
1893 | names to speak about the argument values. The variable name itself
|
---|
1894 | should be lower case, but write it in upper case when you are speaking
|
---|
1895 | about the value rather than the variable itself. Thus, "the inode
|
---|
1896 | number NODE_NUM" rather than "an inode".
|
---|
1897 |
|
---|
1898 | There is usually no purpose in restating the name of the function in
|
---|
1899 | the comment before it, because the reader can see that for himself.
|
---|
1900 | There might be an exception when the comment is so long that the
|
---|
1901 | function itself would be off the bottom of the screen.
|
---|
1902 |
|
---|
1903 | There should be a comment on each static variable as well, like this:
|
---|
1904 |
|
---|
1905 | /* Nonzero means truncate lines in the display;
|
---|
1906 | zero means continue them. */
|
---|
1907 | int truncate_lines;
|
---|
1908 |
|
---|
1909 | Every `#endif' should have a comment, except in the case of short
|
---|
1910 | conditionals (just a few lines) that are not nested. The comment should
|
---|
1911 | state the condition of the conditional that is ending, *including its
|
---|
1912 | sense*. `#else' should have a comment describing the condition *and
|
---|
1913 | sense* of the code that follows. For example:
|
---|
1914 |
|
---|
1915 | #ifdef foo
|
---|
1916 | ...
|
---|
1917 | #else /* not foo */
|
---|
1918 | ...
|
---|
1919 | #endif /* not foo */
|
---|
1920 | #ifdef foo
|
---|
1921 | ...
|
---|
1922 | #endif /* foo */
|
---|
1923 |
|
---|
1924 | but, by contrast, write the comments this way for a `#ifndef':
|
---|
1925 |
|
---|
1926 | #ifndef foo
|
---|
1927 | ...
|
---|
1928 | #else /* foo */
|
---|
1929 | ...
|
---|
1930 | #endif /* foo */
|
---|
1931 | #ifndef foo
|
---|
1932 | ...
|
---|
1933 | #endif /* not foo */
|
---|
1934 |
|
---|
1935 |
|
---|
1936 | File: standards.info, Node: Syntactic Conventions, Next: Names, Prev: Comments, Up: Writing C
|
---|
1937 |
|
---|
1938 | Clean Use of C Constructs
|
---|
1939 | =========================
|
---|
1940 |
|
---|
1941 | Please explicitly declare all arguments to functions. Don't omit
|
---|
1942 | them just because they are `int's.
|
---|
1943 |
|
---|
1944 | Declarations of external functions and functions to appear later in
|
---|
1945 | the source file should all go in one place near the beginning of the
|
---|
1946 | file (somewhere before the first function definition in the file), or
|
---|
1947 | else should go in a header file. Don't put `extern' declarations inside
|
---|
1948 | functions.
|
---|
1949 |
|
---|
1950 | It used to be common practice to use the same local variables (with
|
---|
1951 | names like `tem') over and over for different values within one
|
---|
1952 | function. Instead of doing this, it is better declare a separate local
|
---|
1953 | variable for each distinct purpose, and give it a name which is
|
---|
1954 | meaningful. This not only makes programs easier to understand, it also
|
---|
1955 | facilitates optimization by good compilers. You can also move the
|
---|
1956 | declaration of each local variable into the smallest scope that includes
|
---|
1957 | all its uses. This makes the program even cleaner.
|
---|
1958 |
|
---|
1959 | Don't use local variables or parameters that shadow global
|
---|
1960 | identifiers.
|
---|
1961 |
|
---|
1962 | Don't declare multiple variables in one declaration that spans lines.
|
---|
1963 | Start a new declaration on each line, instead. For example, instead of
|
---|
1964 | this:
|
---|
1965 |
|
---|
1966 | int foo,
|
---|
1967 | bar;
|
---|
1968 |
|
---|
1969 | write either this:
|
---|
1970 |
|
---|
1971 | int foo, bar;
|
---|
1972 |
|
---|
1973 | or this:
|
---|
1974 |
|
---|
1975 | int foo;
|
---|
1976 | int bar;
|
---|
1977 |
|
---|
1978 | (If they are global variables, each should have a comment preceding it
|
---|
1979 | anyway.)
|
---|
1980 |
|
---|
1981 | When you have an `if'-`else' statement nested in another `if'
|
---|
1982 | statement, always put braces around the `if'-`else'. Thus, never write
|
---|
1983 | like this:
|
---|
1984 |
|
---|
1985 | if (foo)
|
---|
1986 | if (bar)
|
---|
1987 | win ();
|
---|
1988 | else
|
---|
1989 | lose ();
|
---|
1990 |
|
---|
1991 | always like this:
|
---|
1992 |
|
---|
1993 | if (foo)
|
---|
1994 | {
|
---|
1995 | if (bar)
|
---|
1996 | win ();
|
---|
1997 | else
|
---|
1998 | lose ();
|
---|
1999 | }
|
---|
2000 |
|
---|
2001 | If you have an `if' statement nested inside of an `else' statement,
|
---|
2002 | either write `else if' on one line, like this,
|
---|
2003 |
|
---|
2004 | if (foo)
|
---|
2005 | ...
|
---|
2006 | else if (bar)
|
---|
2007 | ...
|
---|
2008 |
|
---|
2009 | with its `then'-part indented like the preceding `then'-part, or write
|
---|
2010 | the nested `if' within braces like this:
|
---|
2011 |
|
---|
2012 | if (foo)
|
---|
2013 | ...
|
---|
2014 | else
|
---|
2015 | {
|
---|
2016 | if (bar)
|
---|
2017 | ...
|
---|
2018 | }
|
---|
2019 |
|
---|
2020 | Don't declare both a structure tag and variables or typedefs in the
|
---|
2021 | same declaration. Instead, declare the structure tag separately and
|
---|
2022 | then use it to declare the variables or typedefs.
|
---|
2023 |
|
---|
2024 | Try to avoid assignments inside `if'-conditions. For example, don't
|
---|
2025 | write this:
|
---|
2026 |
|
---|
2027 | if ((foo = (char *) malloc (sizeof *foo)) == 0)
|
---|
2028 | fatal ("virtual memory exhausted");
|
---|
2029 |
|
---|
2030 | instead, write this:
|
---|
2031 |
|
---|
2032 | foo = (char *) malloc (sizeof *foo);
|
---|
2033 | if (foo == 0)
|
---|
2034 | fatal ("virtual memory exhausted");
|
---|
2035 |
|
---|
2036 | Don't make the program ugly to placate `lint'. Please don't insert
|
---|
2037 | any casts to `void'. Zero without a cast is perfectly fine as a null
|
---|
2038 | pointer constant, except when calling a varargs function.
|
---|
2039 |
|
---|
2040 |
|
---|
2041 | File: standards.info, Node: Names, Next: System Portability, Prev: Syntactic Conventions, Up: Writing C
|
---|
2042 |
|
---|
2043 | Naming Variables and Functions
|
---|
2044 | ==============================
|
---|
2045 |
|
---|
2046 | The names of global variables and functions in a program serve as
|
---|
2047 | comments of a sort. So don't choose terse names--instead, look for
|
---|
2048 | names that give useful information about the meaning of the variable or
|
---|
2049 | function. In a GNU program, names should be English, like other
|
---|
2050 | comments.
|
---|
2051 |
|
---|
2052 | Local variable names can be shorter, because they are used only
|
---|
2053 | within one context, where (presumably) comments explain their purpose.
|
---|
2054 |
|
---|
2055 | Please use underscores to separate words in a name, so that the Emacs
|
---|
2056 | word commands can be useful within them. Stick to lower case; reserve
|
---|
2057 | upper case for macros and `enum' constants, and for name-prefixes that
|
---|
2058 | follow a uniform convention.
|
---|
2059 |
|
---|
2060 | For example, you should use names like `ignore_space_change_flag';
|
---|
2061 | don't use names like `iCantReadThis'.
|
---|
2062 |
|
---|
2063 | Variables that indicate whether command-line options have been
|
---|
2064 | specified should be named after the meaning of the option, not after
|
---|
2065 | the option-letter. A comment should state both the exact meaning of
|
---|
2066 | the option and its letter. For example,
|
---|
2067 |
|
---|
2068 | /* Ignore changes in horizontal whitespace (-b). */
|
---|
2069 | int ignore_space_change_flag;
|
---|
2070 |
|
---|
2071 | When you want to define names with constant integer values, use
|
---|
2072 | `enum' rather than `#define'. GDB knows about enumeration constants.
|
---|
2073 |
|
---|
2074 | Use file names of 14 characters or less, to avoid creating gratuitous
|
---|
2075 | problems on older System V systems. You can use the program `doschk'
|
---|
2076 | to test for this. `doschk' also tests for potential name conflicts if
|
---|
2077 | the files were loaded onto an MS-DOS file system--something you may or
|
---|
2078 | may not care about.
|
---|
2079 |
|
---|
2080 |
|
---|
2081 | File: standards.info, Node: System Portability, Next: CPU Portability, Prev: Names, Up: Writing C
|
---|
2082 |
|
---|
2083 | Portability between System Types
|
---|
2084 | ================================
|
---|
2085 |
|
---|
2086 | In the Unix world, "portability" refers to porting to different Unix
|
---|
2087 | versions. For a GNU program, this kind of portability is desirable, but
|
---|
2088 | not paramount.
|
---|
2089 |
|
---|
2090 | The primary purpose of GNU software is to run on top of the GNU
|
---|
2091 | kernel, compiled with the GNU C compiler, on various types of CPU. The
|
---|
2092 | amount and kinds of variation among GNU systems on different CPUs will
|
---|
2093 | be comparable to the variation among Linux-based GNU systems or among
|
---|
2094 | BSD systems today. So the kinds of portability that are absolutely
|
---|
2095 | necessary are quite limited.
|
---|
2096 |
|
---|
2097 | But many users do run GNU software on non-GNU Unix or Unix-like
|
---|
2098 | systems. So supporting a variety of Unix-like systems is desirable,
|
---|
2099 | although not paramount.
|
---|
2100 |
|
---|
2101 | The easiest way to achieve portability to most Unix-like systems is
|
---|
2102 | to use Autoconf. It's unlikely that your program needs to know more
|
---|
2103 | information about the host platform than Autoconf can provide, simply
|
---|
2104 | because most of the programs that need such knowledge have already been
|
---|
2105 | written.
|
---|
2106 |
|
---|
2107 | Avoid using the format of semi-internal data bases (e.g.,
|
---|
2108 | directories) when there is a higher-level alternative (`readdir').
|
---|
2109 |
|
---|
2110 | As for systems that are not like Unix, such as MSDOS, Windows, the
|
---|
2111 | Macintosh, VMS, and MVS, supporting them is usually so much work that it
|
---|
2112 | is better if you don't.
|
---|
2113 |
|
---|
2114 | The planned GNU kernel is not finished yet, but you can tell which
|
---|
2115 | facilities it will provide by looking at the GNU C Library Manual. The
|
---|
2116 | GNU kernel is based on Mach, so the features of Mach will also be
|
---|
2117 | available. However, if you use Mach features, you'll probably have
|
---|
2118 | trouble debugging your program today.
|
---|
2119 |
|
---|
2120 |
|
---|
2121 | File: standards.info, Node: CPU Portability, Next: System Functions, Prev: System Portability, Up: Writing C
|
---|
2122 |
|
---|
2123 | Portability between CPUs
|
---|
2124 | ========================
|
---|
2125 |
|
---|
2126 | Even GNU systems will differ because of differences among CPU
|
---|
2127 | types--for example, difference in byte ordering and alignment
|
---|
2128 | requirements. It is absolutely essential to handle these differences.
|
---|
2129 | However, don't make any effort to cater to the possibility that an
|
---|
2130 | `int' will be less than 32 bits. We don't support 16-bit machines in
|
---|
2131 | GNU.
|
---|
2132 |
|
---|
2133 | Don't assume that the address of an `int' object is also the address
|
---|
2134 | of its least-significant byte. This is false on big-endian machines.
|
---|
2135 | Thus, don't make the following mistake:
|
---|
2136 |
|
---|
2137 | int c;
|
---|
2138 | ...
|
---|
2139 | while ((c = getchar()) != EOF)
|
---|
2140 | write(file_descriptor, &c, 1);
|
---|
2141 |
|
---|
2142 | When calling functions, you need not worry about the difference
|
---|
2143 | between pointers of various types, or between pointers and integers.
|
---|
2144 | On most machines, there's no difference anyway. As for the few
|
---|
2145 | machines where there is a difference, all of them support ANSI C, so
|
---|
2146 | you can use prototypes (conditionalized to be active only in ANSI C) to
|
---|
2147 | make the code work on those systems.
|
---|
2148 |
|
---|
2149 | In certain cases, it is ok to pass integer and pointer arguments
|
---|
2150 | indiscriminately to the same function, and use no prototype on any
|
---|
2151 | system. For example, many GNU programs have error-reporting functions
|
---|
2152 | that pass their arguments along to `printf' and friends:
|
---|
2153 |
|
---|
2154 | error (s, a1, a2, a3)
|
---|
2155 | char *s;
|
---|
2156 | int a1, a2, a3;
|
---|
2157 | {
|
---|
2158 | fprintf (stderr, "error: ");
|
---|
2159 | fprintf (stderr, s, a1, a2, a3);
|
---|
2160 | }
|
---|
2161 |
|
---|
2162 | In practice, this works on all machines, and it is much simpler than any
|
---|
2163 | "correct" alternative. Be sure *not* to use a prototype for such
|
---|
2164 | functions.
|
---|
2165 |
|
---|
2166 | However, avoid casting pointers to integers unless you really need
|
---|
2167 | to. These assumptions really reduce portability, and in most programs
|
---|
2168 | they are easy to avoid. In the cases where casting pointers to
|
---|
2169 | integers is essential--such as, a Lisp interpreter which stores type
|
---|
2170 | information as well as an address in one word--it is ok to do so, but
|
---|
2171 | you'll have to make explicit provisions to handle different word sizes.
|
---|
2172 |
|
---|
2173 |
|
---|
2174 | File: standards.info, Node: System Functions, Next: Internationalization, Prev: CPU Portability, Up: Writing C
|
---|
2175 |
|
---|
2176 | Calling System Functions
|
---|
2177 | ========================
|
---|
2178 |
|
---|
2179 | C implementations differ substantially. ANSI C reduces but does not
|
---|
2180 | eliminate the incompatibilities; meanwhile, many users wish to compile
|
---|
2181 | GNU software with pre-ANSI compilers. This chapter gives
|
---|
2182 | recommendations for how to use the more or less standard C library
|
---|
2183 | functions to avoid unnecessary loss of portability.
|
---|
2184 |
|
---|
2185 | * Don't use the value of `sprintf'. It returns the number of
|
---|
2186 | characters written on some systems, but not on all systems.
|
---|
2187 |
|
---|
2188 | * `main' should be declared to return type `int'. It should
|
---|
2189 | terminate either by calling `exit' or by returning the integer
|
---|
2190 | status code; make sure it cannot ever return an undefined value.
|
---|
2191 |
|
---|
2192 | * Don't declare system functions explicitly.
|
---|
2193 |
|
---|
2194 | Almost any declaration for a system function is wrong on some
|
---|
2195 | system. To minimize conflicts, leave it to the system header
|
---|
2196 | files to declare system functions. If the headers don't declare a
|
---|
2197 | function, let it remain undeclared.
|
---|
2198 |
|
---|
2199 | While it may seem unclean to use a function without declaring it,
|
---|
2200 | in practice this works fine for most system library functions on
|
---|
2201 | the systems where this really happens; thus, the disadvantage is
|
---|
2202 | only theoretical. By contrast, actual declarations have
|
---|
2203 | frequently caused actual conflicts.
|
---|
2204 |
|
---|
2205 | * If you must declare a system function, don't specify the argument
|
---|
2206 | types. Use an old-style declaration, not an ANSI prototype. The
|
---|
2207 | more you specify about the function, the more likely a conflict.
|
---|
2208 |
|
---|
2209 | * In particular, don't unconditionally declare `malloc' or `realloc'.
|
---|
2210 |
|
---|
2211 | Most GNU programs use those functions just once, in functions
|
---|
2212 | conventionally named `xmalloc' and `xrealloc'. These functions
|
---|
2213 | call `malloc' and `realloc', respectively, and check the results.
|
---|
2214 |
|
---|
2215 | Because `xmalloc' and `xrealloc' are defined in your program, you
|
---|
2216 | can declare them in other files without any risk of type conflict.
|
---|
2217 |
|
---|
2218 | On most systems, `int' is the same length as a pointer; thus, the
|
---|
2219 | calls to `malloc' and `realloc' work fine. For the few
|
---|
2220 | exceptional systems (mostly 64-bit machines), you can use
|
---|
2221 | *conditionalized* declarations of `malloc' and `realloc'--or put
|
---|
2222 | these declarations in configuration files specific to those
|
---|
2223 | systems.
|
---|
2224 |
|
---|
2225 | * The string functions require special treatment. Some Unix systems
|
---|
2226 | have a header file `string.h'; others have `strings.h'. Neither
|
---|
2227 | file name is portable. There are two things you can do: use
|
---|
2228 | Autoconf to figure out which file to include, or don't include
|
---|
2229 | either file.
|
---|
2230 |
|
---|
2231 | * If you don't include either strings file, you can't get
|
---|
2232 | declarations for the string functions from the header file in the
|
---|
2233 | usual way.
|
---|
2234 |
|
---|
2235 | That causes less of a problem than you might think. The newer ANSI
|
---|
2236 | string functions should be avoided anyway because many systems
|
---|
2237 | still don't support them. The string functions you can use are
|
---|
2238 | these:
|
---|
2239 |
|
---|
2240 | strcpy strncpy strcat strncat
|
---|
2241 | strlen strcmp strncmp
|
---|
2242 | strchr strrchr
|
---|
2243 |
|
---|
2244 | The copy and concatenate functions work fine without a declaration
|
---|
2245 | as long as you don't use their values. Using their values without
|
---|
2246 | a declaration fails on systems where the width of a pointer
|
---|
2247 | differs from the width of `int', and perhaps in other cases. It
|
---|
2248 | is trivial to avoid using their values, so do that.
|
---|
2249 |
|
---|
2250 | The compare functions and `strlen' work fine without a declaration
|
---|
2251 | on most systems, possibly all the ones that GNU software runs on.
|
---|
2252 | You may find it necessary to declare them *conditionally* on a few
|
---|
2253 | systems.
|
---|
2254 |
|
---|
2255 | The search functions must be declared to return `char *'. Luckily,
|
---|
2256 | there is no variation in the data type they return. But there is
|
---|
2257 | variation in their names. Some systems give these functions the
|
---|
2258 | names `index' and `rindex'; other systems use the names `strchr'
|
---|
2259 | and `strrchr'. Some systems support both pairs of names, but
|
---|
2260 | neither pair works on all systems.
|
---|
2261 |
|
---|
2262 | You should pick a single pair of names and use it throughout your
|
---|
2263 | program. (Nowadays, it is better to choose `strchr' and `strrchr'
|
---|
2264 | for new programs, since those are the standard ANSI names.)
|
---|
2265 | Declare both of those names as functions returning `char *'. On
|
---|
2266 | systems which don't support those names, define them as macros in
|
---|
2267 | terms of the other pair. For example, here is what to put at the
|
---|
2268 | beginning of your file (or in a header) if you want to use the
|
---|
2269 | names `strchr' and `strrchr' throughout:
|
---|
2270 |
|
---|
2271 | #ifndef HAVE_STRCHR
|
---|
2272 | #define strchr index
|
---|
2273 | #endif
|
---|
2274 | #ifndef HAVE_STRRCHR
|
---|
2275 | #define strrchr rindex
|
---|
2276 | #endif
|
---|
2277 |
|
---|
2278 | char *strchr ();
|
---|
2279 | char *strrchr ();
|
---|
2280 |
|
---|
2281 | Here we assume that `HAVE_STRCHR' and `HAVE_STRRCHR' are macros
|
---|
2282 | defined in systems where the corresponding functions exist. One way to
|
---|
2283 | get them properly defined is to use Autoconf.
|
---|
2284 |
|
---|
2285 |
|
---|
2286 | File: standards.info, Node: Internationalization, Next: Mmap, Prev: System Functions, Up: Writing C
|
---|
2287 |
|
---|
2288 | Internationalization
|
---|
2289 | ====================
|
---|
2290 |
|
---|
2291 | GNU has a library called GNU gettext that makes it easy to translate
|
---|
2292 | the messages in a program into various languages. You should use this
|
---|
2293 | library in every program. Use English for the messages as they appear
|
---|
2294 | in the program, and let gettext provide the way to translate them into
|
---|
2295 | other languages.
|
---|
2296 |
|
---|
2297 | Using GNU gettext involves putting a call to the `gettext' macro
|
---|
2298 | around each string that might need translation--like this:
|
---|
2299 |
|
---|
2300 | printf (gettext ("Processing file `%s'..."));
|
---|
2301 |
|
---|
2302 | This permits GNU gettext to replace the string `"Processing file
|
---|
2303 | `%s'..."' with a translated version.
|
---|
2304 |
|
---|
2305 | Once a program uses gettext, please make a point of writing calls to
|
---|
2306 | `gettext' when you add new strings that call for translation.
|
---|
2307 |
|
---|
2308 | Using GNU gettext in a package involves specifying a "text domain
|
---|
2309 | name" for the package. The text domain name is used to separate the
|
---|
2310 | translations for this package from the translations for other packages.
|
---|
2311 | Normally, the text domain name should be the same as the name of the
|
---|
2312 | package--for example, `fileutils' for the GNU file utilities.
|
---|
2313 |
|
---|
2314 | To enable gettext to work well, avoid writing code that makes
|
---|
2315 | assumptions about the structure of words or sentences. When you want
|
---|
2316 | the precise text of a sentence to vary depending on the data, use two or
|
---|
2317 | more alternative string constants each containing a complete sentences,
|
---|
2318 | rather than inserting conditionalized words or phrases into a single
|
---|
2319 | sentence framework.
|
---|
2320 |
|
---|
2321 | Here is an example of what not to do:
|
---|
2322 |
|
---|
2323 | printf ("%d file%s processed", nfiles,
|
---|
2324 | nfiles != 1 ? "s" : "");
|
---|
2325 |
|
---|
2326 | The problem with that example is that it assumes that plurals are made
|
---|
2327 | by adding `s'. If you apply gettext to the format string, like this,
|
---|
2328 |
|
---|
2329 | printf (gettext ("%d file%s processed"), nfiles,
|
---|
2330 | nfiles != 1 ? "s" : "");
|
---|
2331 |
|
---|
2332 | the message can use different words, but it will still be forced to use
|
---|
2333 | `s' for the plural. Here is a better way:
|
---|
2334 |
|
---|
2335 | printf ((nfiles != 1 ? "%d files processed"
|
---|
2336 | : "%d file processed"),
|
---|
2337 | nfiles);
|
---|
2338 |
|
---|
2339 | This way, you can apply gettext to each of the two strings
|
---|
2340 | independently:
|
---|
2341 |
|
---|
2342 | printf ((nfiles != 1 ? gettext ("%d files processed")
|
---|
2343 | : gettext ("%d file processed")),
|
---|
2344 | nfiles);
|
---|
2345 |
|
---|
2346 | This can be any method of forming the plural of the word for "file", and
|
---|
2347 | also handles languages that require agreement in the word for
|
---|
2348 | "processed".
|
---|
2349 |
|
---|
2350 | A similar problem appears at the level of sentence structure with
|
---|
2351 | this code:
|
---|
2352 |
|
---|
2353 | printf ("# Implicit rule search has%s been done.\n",
|
---|
2354 | f->tried_implicit ? "" : " not");
|
---|
2355 |
|
---|
2356 | Adding `gettext' calls to this code cannot give correct results for all
|
---|
2357 | languages, because negation in some languages requires adding words at
|
---|
2358 | more than one place in the sentence. By contrast, adding `gettext'
|
---|
2359 | calls does the job straightfowardly if the code starts out like this:
|
---|
2360 |
|
---|
2361 | printf (f->tried_implicit
|
---|
2362 | ? "# Implicit rule search has been done.\n",
|
---|
2363 | : "# Implicit rule search has not been done.\n");
|
---|
2364 |
|
---|
2365 |
|
---|
2366 | File: standards.info, Node: Mmap, Prev: Internationalization, Up: Writing C
|
---|
2367 |
|
---|
2368 | Mmap
|
---|
2369 | ====
|
---|
2370 |
|
---|
2371 | Don't assume that `mmap' either works on all files or fails for all
|
---|
2372 | files. It may work on some files and fail on others.
|
---|
2373 |
|
---|
2374 | The proper way to use `mmap' is to try it on the specific file for
|
---|
2375 | which you want to use it--and if `mmap' doesn't work, fall back on
|
---|
2376 | doing the job in another way using `read' and `write'.
|
---|
2377 |
|
---|
2378 | The reason this precaution is needed is that the GNU kernel (the
|
---|
2379 | HURD) provides a user-extensible file system, in which there can be many
|
---|
2380 | different kinds of "ordinary files." Many of them support `mmap', but
|
---|
2381 | some do not. It is important to make programs handle all these kinds
|
---|
2382 | of files.
|
---|
2383 |
|
---|
2384 |
|
---|
2385 | File: standards.info, Node: Documentation, Next: Managing Releases, Prev: Writing C, Up: Top
|
---|
2386 |
|
---|
2387 | Documenting Programs
|
---|
2388 | ********************
|
---|
2389 |
|
---|
2390 | * Menu:
|
---|
2391 |
|
---|
2392 | * GNU Manuals:: Writing proper manuals.
|
---|
2393 | * Manual Structure Details:: Specific structure conventions.
|
---|
2394 | * NEWS File:: NEWS files supplement manuals.
|
---|
2395 | * Change Logs:: Recording Changes
|
---|
2396 | * Man Pages:: Man pages are secondary.
|
---|
2397 | * Reading other Manuals:: How far you can go in learning
|
---|
2398 | from other manuals.
|
---|
2399 |
|
---|
2400 |
|
---|
2401 | File: standards.info, Node: GNU Manuals, Next: Manual Structure Details, Up: Documentation
|
---|
2402 |
|
---|
2403 | GNU Manuals
|
---|
2404 | ===========
|
---|
2405 |
|
---|
2406 | The preferred way to document part of the GNU system is to write a
|
---|
2407 | manual in the Texinfo formatting language. See the Texinfo manual,
|
---|
2408 | either the hardcopy, or the on-line version available through `info' or
|
---|
2409 | the Emacs Info subsystem (`C-h i').
|
---|
2410 |
|
---|
2411 | Programmers often find it most natural to structure the documentation
|
---|
2412 | following the structure of the implementation, which they know. But
|
---|
2413 | this structure is not necessarily good for explaining how to use the
|
---|
2414 | program; it may be irrelevant and confusing for a user.
|
---|
2415 |
|
---|
2416 | At every level, from the sentences in a paragraph to the grouping of
|
---|
2417 | topics into separate manuals, the right way to structure documentation
|
---|
2418 | is according to the concepts and questions that a user will have in mind
|
---|
2419 | when reading it. Sometimes this structure of ideas matches the
|
---|
2420 | structure of the implementation of the software being documented--but
|
---|
2421 | often they are different. Often the most important part of learning to
|
---|
2422 | write good documentation is learning to notice when you are structuring
|
---|
2423 | the documentation like the implementation, and think about better
|
---|
2424 | alternatives.
|
---|
2425 |
|
---|
2426 | For example, each program in the GNU system probably ought to be
|
---|
2427 | documented in one manual; but this does not mean each program should
|
---|
2428 | have its own manual. That would be following the structure of the
|
---|
2429 | implementation, rather than the structure that helps the user
|
---|
2430 | understand.
|
---|
2431 |
|
---|
2432 | Instead, each manual should cover a coherent *topic*. For example,
|
---|
2433 | instead of a manual for `diff' and a manual for `diff3', we have one
|
---|
2434 | manual for "comparison of files" which covers both of those programs,
|
---|
2435 | as well as `cmp'. By documenting these programs together, we can make
|
---|
2436 | the whole subject clearer.
|
---|
2437 |
|
---|
2438 | The manual which discusses a program should document all of the
|
---|
2439 | program's command-line options and all of its commands. It should give
|
---|
2440 | examples of their use. But don't organize the manual as a list of
|
---|
2441 | features. Instead, organize it logically, by subtopics. Address the
|
---|
2442 | questions that a user will ask when thinking about the job that the
|
---|
2443 | program does.
|
---|
2444 |
|
---|
2445 | In general, a GNU manual should serve both as tutorial and reference.
|
---|
2446 | It should be set up for convenient access to each topic through Info,
|
---|
2447 | and for reading straight through (appendixes aside). A GNU manual
|
---|
2448 | should give a good introduction to a beginner reading through from the
|
---|
2449 | start, and should also provide all the details that hackers want.
|
---|
2450 |
|
---|
2451 | That is not as hard as it first sounds. Arrange each chapter as a
|
---|
2452 | logical breakdown of its topic, but order the sections, and write their
|
---|
2453 | text, so that reading the chapter straight through makes sense. Do
|
---|
2454 | likewise when structuring the book into chapters, and when structuring a
|
---|
2455 | section into paragraphs. The watchword is, *at each point, address the
|
---|
2456 | most fundamental and important issue raised by the preceding text.*
|
---|
2457 |
|
---|
2458 | If necessary, add extra chapters at the beginning of the manual which
|
---|
2459 | are purely tutorial and cover the basics of the subject. These provide
|
---|
2460 | the framework for a beginner to understand the rest of the manual. The
|
---|
2461 | Bison manual provides a good example of how to do this.
|
---|
2462 |
|
---|
2463 | Don't use Unix man pages as a model for how to write GNU
|
---|
2464 | documentation; most of them are terse, badly structured, and give
|
---|
2465 | inadequate explanation of the underlying concepts. (There are, of
|
---|
2466 | course exceptions.) Also Unix man pages use a particular format which
|
---|
2467 | is different from what we use in GNU manuals.
|
---|
2468 |
|
---|
2469 | Please do not use the term "pathname" that is used in Unix
|
---|
2470 | documentation; use "file name" (two words) instead. We use the term
|
---|
2471 | "path" only for search paths, which are lists of file names.
|
---|
2472 |
|
---|
2473 | Please do not use the term "illegal" to refer to erroneous input to a
|
---|
2474 | computer program. Please use "invalid" for this, and reserve the term
|
---|
2475 | "illegal" for violations of law.
|
---|
2476 |
|
---|
2477 |
|
---|
2478 | File: standards.info, Node: Manual Structure Details, Next: NEWS File, Prev: GNU Manuals, Up: Documentation
|
---|
2479 |
|
---|
2480 | Manual Structure Details
|
---|
2481 | ========================
|
---|
2482 |
|
---|
2483 | The title page of the manual should state the version of the
|
---|
2484 | programs or packages documented in the manual. The Top node of the
|
---|
2485 | manual should also contain this information. If the manual is changing
|
---|
2486 | more frequently than or independent of the program, also state a version
|
---|
2487 | number for the manual in both of these places.
|
---|
2488 |
|
---|
2489 | Each program documented in the manual should should have a node named
|
---|
2490 | `PROGRAM Invocation' or `Invoking PROGRAM'. This node (together with
|
---|
2491 | its subnodes, if any) should describe the program's command line
|
---|
2492 | arguments and how to run it (the sort of information people would look
|
---|
2493 | in a man page for). Start with an `@example' containing a template for
|
---|
2494 | all the options and arguments that the program uses.
|
---|
2495 |
|
---|
2496 | Alternatively, put a menu item in some menu whose item name fits one
|
---|
2497 | of the above patterns. This identifies the node which that item points
|
---|
2498 | to as the node for this purpose, regardless of the node's actual name.
|
---|
2499 |
|
---|
2500 | There will be automatic features for specifying a program name and
|
---|
2501 | quickly reading just this part of its manual.
|
---|
2502 |
|
---|
2503 | If one manual describes several programs, it should have such a node
|
---|
2504 | for each program described.
|
---|
2505 |
|
---|
2506 |
|
---|
2507 | File: standards.info, Node: NEWS File, Next: Change Logs, Prev: Manual Structure Details, Up: Documentation
|
---|
2508 |
|
---|
2509 | The NEWS File
|
---|
2510 | =============
|
---|
2511 |
|
---|
2512 | In addition to its manual, the package should have a file named
|
---|
2513 | `NEWS' which contains a list of user-visible changes worth mentioning.
|
---|
2514 | In each new release, add items to the front of the file and identify
|
---|
2515 | the version they pertain to. Don't discard old items; leave them in
|
---|
2516 | the file after the newer items. This way, a user upgrading from any
|
---|
2517 | previous version can see what is new.
|
---|
2518 |
|
---|
2519 | If the `NEWS' file gets very long, move some of the older items into
|
---|
2520 | a file named `ONEWS' and put a note at the end referring the user to
|
---|
2521 | that file.
|
---|
2522 |
|
---|
2523 |
|
---|
2524 | File: standards.info, Node: Change Logs, Next: Man Pages, Prev: NEWS File, Up: Documentation
|
---|
2525 |
|
---|
2526 | Change Logs
|
---|
2527 | ===========
|
---|
2528 |
|
---|
2529 | Keep a change log to describe all the changes made to program source
|
---|
2530 | files. The purpose of this is so that people investigating bugs in the
|
---|
2531 | future will know about the changes that might have introduced the bug.
|
---|
2532 | Often a new bug can be found by looking at what was recently changed.
|
---|
2533 | More importantly, change logs can help you eliminate conceptual
|
---|
2534 | inconsistencies between different parts of a program, by giving you a
|
---|
2535 | history of how the conflicting concepts arose and who they came from.
|
---|
2536 |
|
---|
2537 | * Menu:
|
---|
2538 |
|
---|
2539 | * Change Log Concepts::
|
---|
2540 | * Style of Change Logs::
|
---|
2541 | * Simple Changes::
|
---|
2542 | * Conditional Changes::
|
---|
2543 |
|
---|
2544 |
|
---|
2545 | File: standards.info, Node: Change Log Concepts, Next: Style of Change Logs, Up: Change Logs
|
---|
2546 |
|
---|
2547 | Change Log Concepts
|
---|
2548 | -------------------
|
---|
2549 |
|
---|
2550 | You can think of the change log as a conceptual "undo list" which
|
---|
2551 | explains how earlier versions were different from the current version.
|
---|
2552 | People can see the current version; they don't need the change log to
|
---|
2553 | tell them what is in it. What they want from a change log is a clear
|
---|
2554 | explanation of how the earlier version differed.
|
---|
2555 |
|
---|
2556 | The change log file is normally called `ChangeLog' and covers an
|
---|
2557 | entire directory. Each directory can have its own change log, or a
|
---|
2558 | directory can use the change log of its parent directory-it's up to you.
|
---|
2559 |
|
---|
2560 | Another alternative is to record change log information with a
|
---|
2561 | version control system such as RCS or CVS. This can be converted
|
---|
2562 | automatically to a `ChangeLog' file.
|
---|
2563 |
|
---|
2564 | There's no need to describe the full purpose of the changes or how
|
---|
2565 | they work together. If you think that a change calls for explanation,
|
---|
2566 | you're probably right. Please do explain it--but please put the
|
---|
2567 | explanation in comments in the code, where people will see it whenever
|
---|
2568 | they see the code. For example, "New function" is enough for the
|
---|
2569 | change log when you add a function, because there should be a comment
|
---|
2570 | before the function definition to explain what it does.
|
---|
2571 |
|
---|
2572 | However, sometimes it is useful to write one line to describe the
|
---|
2573 | overall purpose of a batch of changes.
|
---|
2574 |
|
---|
2575 | The easiest way to add an entry to `ChangeLog' is with the Emacs
|
---|
2576 | command `M-x add-change-log-entry'. An entry should have an asterisk,
|
---|
2577 | the name of the changed file, and then in parentheses the name of the
|
---|
2578 | changed functions, variables or whatever, followed by a colon. Then
|
---|
2579 | describe the changes you made to that function or variable.
|
---|
2580 |
|
---|
2581 |
|
---|
2582 | File: standards.info, Node: Style of Change Logs, Next: Simple Changes, Prev: Change Log Concepts, Up: Change Logs
|
---|
2583 |
|
---|
2584 | Style of Change Logs
|
---|
2585 | --------------------
|
---|
2586 |
|
---|
2587 | Here are some examples of change log entries:
|
---|
2588 |
|
---|
2589 | * register.el (insert-register): Return nil.
|
---|
2590 | (jump-to-register): Likewise.
|
---|
2591 |
|
---|
2592 | * sort.el (sort-subr): Return nil.
|
---|
2593 |
|
---|
2594 | * tex-mode.el (tex-bibtex-file, tex-file, tex-region):
|
---|
2595 | Restart the tex shell if process is gone or stopped.
|
---|
2596 | (tex-shell-running): New function.
|
---|
2597 |
|
---|
2598 | * expr.c (store_one_arg): Round size up for move_block_to_reg.
|
---|
2599 | (expand_call): Round up when emitting USE insns.
|
---|
2600 | * stmt.c (assign_parms): Round size up for move_block_from_reg.
|
---|
2601 |
|
---|
2602 | It's important to name the changed function or variable in full.
|
---|
2603 | Don't abbreviate function or variable names, and don't combine them.
|
---|
2604 | Subsequent maintainers will often search for a function name to find all
|
---|
2605 | the change log entries that pertain to it; if you abbreviate the name,
|
---|
2606 | they won't find it when they search.
|
---|
2607 |
|
---|
2608 | For example, some people are tempted to abbreviate groups of function
|
---|
2609 | names by writing `* register.el ({insert,jump-to}-register)'; this is
|
---|
2610 | not a good idea, since searching for `jump-to-register' or
|
---|
2611 | `insert-register' would not find that entry.
|
---|
2612 |
|
---|
2613 | Separate unrelated change log entries with blank lines. When two
|
---|
2614 | entries represent parts of the same change, so that they work together,
|
---|
2615 | then don't put blank lines between them. Then you can omit the file
|
---|
2616 | name and the asterisk when successive entries are in the same file.
|
---|
2617 |
|
---|
2618 |
|
---|
2619 | File: standards.info, Node: Simple Changes, Next: Conditional Changes, Prev: Style of Change Logs, Up: Change Logs
|
---|
2620 |
|
---|
2621 | Simple Changes
|
---|
2622 | --------------
|
---|
2623 |
|
---|
2624 | Certain simple kinds of changes don't need much detail in the change
|
---|
2625 | log.
|
---|
2626 |
|
---|
2627 | When you change the calling sequence of a function in a simple
|
---|
2628 | fashion, and you change all the callers of the function, there is no
|
---|
2629 | need to make individual entries for all the callers that you changed.
|
---|
2630 | Just write in the entry for the function being called, "All callers
|
---|
2631 | changed."
|
---|
2632 |
|
---|
2633 | * keyboard.c (Fcommand_execute): New arg SPECIAL.
|
---|
2634 | All callers changed.
|
---|
2635 |
|
---|
2636 | When you change just comments or doc strings, it is enough to write
|
---|
2637 | an entry for the file, without mentioning the functions. Just "Doc
|
---|
2638 | fixes" is enough for the change log.
|
---|
2639 |
|
---|
2640 | There's no need to make change log entries for documentation files.
|
---|
2641 | This is because documentation is not susceptible to bugs that are hard
|
---|
2642 | to fix. Documentation does not consist of parts that must interact in a
|
---|
2643 | precisely engineered fashion. To correct an error, you need not know
|
---|
2644 | the history of the erroneous passage; it is enough to compare what the
|
---|
2645 | documentation says with the way the program actually works.
|
---|
2646 |
|
---|
2647 |
|
---|
2648 | File: standards.info, Node: Conditional Changes, Prev: Simple Changes, Up: Change Logs
|
---|
2649 |
|
---|
2650 | Conditional Changes
|
---|
2651 | -------------------
|
---|
2652 |
|
---|
2653 | C programs often contain compile-time `#if' conditionals. Many
|
---|
2654 | changes are conditional; sometimes you add a new definition which is
|
---|
2655 | entirely contained in a conditional. It is very useful to indicate in
|
---|
2656 | the change log the conditions for which the change applies.
|
---|
2657 |
|
---|
2658 | Our convention for indicating conditional changes is to use square
|
---|
2659 | brackets around the name of the condition.
|
---|
2660 |
|
---|
2661 | Here is a simple example, describing a change which is conditional
|
---|
2662 | but does not have a function or entity name associated with it:
|
---|
2663 |
|
---|
2664 | * xterm.c [SOLARIS2]: Include string.h.
|
---|
2665 |
|
---|
2666 | Here is an entry describing a new definition which is entirely
|
---|
2667 | conditional. This new definition for the macro `FRAME_WINDOW_P' is
|
---|
2668 | used only when `HAVE_X_WINDOWS' is defined:
|
---|
2669 |
|
---|
2670 | * frame.h [HAVE_X_WINDOWS] (FRAME_WINDOW_P): Macro defined.
|
---|
2671 |
|
---|
2672 | Here is an entry for a change within the function `init_display',
|
---|
2673 | whose definition as a whole is unconditional, but the changes themselves
|
---|
2674 | are contained in a `#ifdef HAVE_LIBNCURSES' conditional:
|
---|
2675 |
|
---|
2676 | * dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent.
|
---|
2677 |
|
---|
2678 | Here is an entry for a change that takes affect only when a certain
|
---|
2679 | macro is *not* defined:
|
---|
2680 |
|
---|
2681 | (gethostname) [!HAVE_SOCKETS]: Replace with winsock version.
|
---|
2682 |
|
---|
2683 |
|
---|
2684 | File: standards.info, Node: Man Pages, Next: Reading other Manuals, Prev: Change Logs, Up: Documentation
|
---|
2685 |
|
---|
2686 | Man Pages
|
---|
2687 | =========
|
---|
2688 |
|
---|
2689 | In the GNU project, man pages are secondary. It is not necessary or
|
---|
2690 | expected for every GNU program to have a man page, but some of them do.
|
---|
2691 | It's your choice whether to include a man page in your program.
|
---|
2692 |
|
---|
2693 | When you make this decision, consider that supporting a man page
|
---|
2694 | requires continual effort each time the program is changed. The time
|
---|
2695 | you spend on the man page is time taken away from more useful work.
|
---|
2696 |
|
---|
2697 | For a simple program which changes little, updating the man page may
|
---|
2698 | be a small job. Then there is little reason not to include a man page,
|
---|
2699 | if you have one.
|
---|
2700 |
|
---|
2701 | For a large program that changes a great deal, updating a man page
|
---|
2702 | may be a substantial burden. If a user offers to donate a man page,
|
---|
2703 | you may find this gift costly to accept. It may be better to refuse
|
---|
2704 | the man page unless the same person agrees to take full responsibility
|
---|
2705 | for maintaining it--so that you can wash your hands of it entirely. If
|
---|
2706 | this volunteer later ceases to do the job, then don't feel obliged to
|
---|
2707 | pick it up yourself; it may be better to withdraw the man page from the
|
---|
2708 | distribution until someone else agrees to update it.
|
---|
2709 |
|
---|
2710 | When a program changes only a little, you may feel that the
|
---|
2711 | discrepancies are small enough that the man page remains useful without
|
---|
2712 | updating. If so, put a prominent note near the beginning of the man
|
---|
2713 | page explaining that you don't maintain it and that the Texinfo manual
|
---|
2714 | is more authoritative. The note should say how to access the Texinfo
|
---|
2715 | documentation.
|
---|
2716 |
|
---|
2717 |
|
---|
2718 | File: standards.info, Node: Reading other Manuals, Prev: Man Pages, Up: Documentation
|
---|
2719 |
|
---|
2720 | Reading other Manuals
|
---|
2721 | =====================
|
---|
2722 |
|
---|
2723 | There may be non-free books or documentation files that describe the
|
---|
2724 | program you are documenting.
|
---|
2725 |
|
---|
2726 | It is ok to use these documents for reference, just as the author of
|
---|
2727 | a new algebra textbook can read other books on algebra. A large portion
|
---|
2728 | of any non-fiction book consists of facts, in this case facts about how
|
---|
2729 | a certain program works, and these facts are necessarily the same for
|
---|
2730 | everyone who writes about the subject. But be careful not to copy your
|
---|
2731 | outline structure, wording, tables or examples from preexisting non-free
|
---|
2732 | documentation. Copying from free documentation may be ok; please check
|
---|
2733 | with the FSF about the individual case.
|
---|
2734 |
|
---|
2735 |
|
---|
2736 | File: standards.info, Node: Managing Releases, Prev: Documentation, Up: Top
|
---|
2737 |
|
---|
2738 | The Release Process
|
---|
2739 | *******************
|
---|
2740 |
|
---|
2741 | Making a release is more than just bundling up your source files in a
|
---|
2742 | tar file and putting it up for FTP. You should set up your software so
|
---|
2743 | that it can be configured to run on a variety of systems. Your Makefile
|
---|
2744 | should conform to the GNU standards described below, and your directory
|
---|
2745 | layout should also conform to the standards discussed below. Doing so
|
---|
2746 | makes it easy to include your package into the larger framework of all
|
---|
2747 | GNU software.
|
---|
2748 |
|
---|
2749 | * Menu:
|
---|
2750 |
|
---|
2751 | * Configuration:: How Configuration Should Work
|
---|
2752 | * Makefile Conventions:: Makefile Conventions
|
---|
2753 | * Releases:: Making Releases
|
---|
2754 |
|
---|
2755 |
|
---|
2756 | File: standards.info, Node: Configuration, Next: Makefile Conventions, Up: Managing Releases
|
---|
2757 |
|
---|
2758 | How Configuration Should Work
|
---|
2759 | =============================
|
---|
2760 |
|
---|
2761 | Each GNU distribution should come with a shell script named
|
---|
2762 | `configure'. This script is given arguments which describe the kind of
|
---|
2763 | machine and system you want to compile the program for.
|
---|
2764 |
|
---|
2765 | The `configure' script must record the configuration options so that
|
---|
2766 | they affect compilation.
|
---|
2767 |
|
---|
2768 | One way to do this is to make a link from a standard name such as
|
---|
2769 | `config.h' to the proper configuration file for the chosen system. If
|
---|
2770 | you use this technique, the distribution should *not* contain a file
|
---|
2771 | named `config.h'. This is so that people won't be able to build the
|
---|
2772 | program without configuring it first.
|
---|
2773 |
|
---|
2774 | Another thing that `configure' can do is to edit the Makefile. If
|
---|
2775 | you do this, the distribution should *not* contain a file named
|
---|
2776 | `Makefile'. Instead, it should include a file `Makefile.in' which
|
---|
2777 | contains the input used for editing. Once again, this is so that people
|
---|
2778 | won't be able to build the program without configuring it first.
|
---|
2779 |
|
---|
2780 | If `configure' does write the `Makefile', then `Makefile' should
|
---|
2781 | have a target named `Makefile' which causes `configure' to be rerun,
|
---|
2782 | setting up the same configuration that was set up last time. The files
|
---|
2783 | that `configure' reads should be listed as dependencies of `Makefile'.
|
---|
2784 |
|
---|
2785 | All the files which are output from the `configure' script should
|
---|
2786 | have comments at the beginning explaining that they were generated
|
---|
2787 | automatically using `configure'. This is so that users won't think of
|
---|
2788 | trying to edit them by hand.
|
---|
2789 |
|
---|
2790 | The `configure' script should write a file named `config.status'
|
---|
2791 | which describes which configuration options were specified when the
|
---|
2792 | program was last configured. This file should be a shell script which,
|
---|
2793 | if run, will recreate the same configuration.
|
---|
2794 |
|
---|
2795 | The `configure' script should accept an option of the form
|
---|
2796 | `--srcdir=DIRNAME' to specify the directory where sources are found (if
|
---|
2797 | it is not the current directory). This makes it possible to build the
|
---|
2798 | program in a separate directory, so that the actual source directory is
|
---|
2799 | not modified.
|
---|
2800 |
|
---|
2801 | If the user does not specify `--srcdir', then `configure' should
|
---|
2802 | check both `.' and `..' to see if it can find the sources. If it finds
|
---|
2803 | the sources in one of these places, it should use them from there.
|
---|
2804 | Otherwise, it should report that it cannot find the sources, and should
|
---|
2805 | exit with nonzero status.
|
---|
2806 |
|
---|
2807 | Usually the easy way to support `--srcdir' is by editing a
|
---|
2808 | definition of `VPATH' into the Makefile. Some rules may need to refer
|
---|
2809 | explicitly to the specified source directory. To make this possible,
|
---|
2810 | `configure' can add to the Makefile a variable named `srcdir' whose
|
---|
2811 | value is precisely the specified directory.
|
---|
2812 |
|
---|
2813 | The `configure' script should also take an argument which specifies
|
---|
2814 | the type of system to build the program for. This argument should look
|
---|
2815 | like this:
|
---|
2816 |
|
---|
2817 | CPU-COMPANY-SYSTEM
|
---|
2818 |
|
---|
2819 | For example, a Sun 3 might be `m68k-sun-sunos4.1'.
|
---|
2820 |
|
---|
2821 | The `configure' script needs to be able to decode all plausible
|
---|
2822 | alternatives for how to describe a machine. Thus, `sun3-sunos4.1'
|
---|
2823 | would be a valid alias. For many programs, `vax-dec-ultrix' would be
|
---|
2824 | an alias for `vax-dec-bsd', simply because the differences between
|
---|
2825 | Ultrix and BSD are rarely noticeable, but a few programs might need to
|
---|
2826 | distinguish them.
|
---|
2827 |
|
---|
2828 | There is a shell script called `config.sub' that you can use as a
|
---|
2829 | subroutine to validate system types and canonicalize aliases.
|
---|
2830 |
|
---|
2831 | Other options are permitted to specify in more detail the software
|
---|
2832 | or hardware present on the machine, and include or exclude optional
|
---|
2833 | parts of the package:
|
---|
2834 |
|
---|
2835 | `--enable-FEATURE[=PARAMETER]'
|
---|
2836 | Configure the package to build and install an optional user-level
|
---|
2837 | facility called FEATURE. This allows users to choose which
|
---|
2838 | optional features to include. Giving an optional PARAMETER of
|
---|
2839 | `no' should omit FEATURE, if it is built by default.
|
---|
2840 |
|
---|
2841 | No `--enable' option should *ever* cause one feature to replace
|
---|
2842 | another. No `--enable' option should ever substitute one useful
|
---|
2843 | behavior for another useful behavior. The only proper use for
|
---|
2844 | `--enable' is for questions of whether to build part of the program
|
---|
2845 | or exclude it.
|
---|
2846 |
|
---|
2847 | `--with-PACKAGE'
|
---|
2848 | The package PACKAGE will be installed, so configure this package
|
---|
2849 | to work with PACKAGE.
|
---|
2850 |
|
---|
2851 | Possible values of PACKAGE include `gnu-as' (or `gas'), `gnu-ld',
|
---|
2852 | `gnu-libc', `gdb', `x', and `x-toolkit'.
|
---|
2853 |
|
---|
2854 | Do not use a `--with' option to specify the file name to use to
|
---|
2855 | find certain files. That is outside the scope of what `--with'
|
---|
2856 | options are for.
|
---|
2857 |
|
---|
2858 | `--nfp'
|
---|
2859 | The target machine has no floating point processor.
|
---|
2860 |
|
---|
2861 | `--gas'
|
---|
2862 | The target machine assembler is GAS, the GNU assembler. This is
|
---|
2863 | obsolete; users should use `--with-gnu-as' instead.
|
---|
2864 |
|
---|
2865 | `--x'
|
---|
2866 | The target machine has the X Window System installed. This is
|
---|
2867 | obsolete; users should use `--with-x' instead.
|
---|
2868 |
|
---|
2869 | All `configure' scripts should accept all of these "detail" options,
|
---|
2870 | whether or not they make any difference to the particular package at
|
---|
2871 | hand. In particular, they should accept any option that starts with
|
---|
2872 | `--with-' or `--enable-'. This is so users will be able to configure
|
---|
2873 | an entire GNU source tree at once with a single set of options.
|
---|
2874 |
|
---|
2875 | You will note that the categories `--with-' and `--enable-' are
|
---|
2876 | narrow: they *do not* provide a place for any sort of option you might
|
---|
2877 | think of. That is deliberate. We want to limit the possible
|
---|
2878 | configuration options in GNU software. We do not want GNU programs to
|
---|
2879 | have idiosyncratic configuration options.
|
---|
2880 |
|
---|
2881 | Packages that perform part of the compilation process may support
|
---|
2882 | cross-compilation. In such a case, the host and target machines for
|
---|
2883 | the program may be different. The `configure' script should normally
|
---|
2884 | treat the specified type of system as both the host and the target,
|
---|
2885 | thus producing a program which works for the same type of machine that
|
---|
2886 | it runs on.
|
---|
2887 |
|
---|
2888 | The way to build a cross-compiler, cross-assembler, or what have
|
---|
2889 | you, is to specify the option `--host=HOSTTYPE' when running
|
---|
2890 | `configure'. This specifies the host system without changing the type
|
---|
2891 | of target system. The syntax for HOSTTYPE is the same as described
|
---|
2892 | above.
|
---|
2893 |
|
---|
2894 | Bootstrapping a cross-compiler requires compiling it on a machine
|
---|
2895 | other than the host it will run on. Compilation packages accept a
|
---|
2896 | configuration option `--build=HOSTTYPE' for specifying the
|
---|
2897 | configuration on which you will compile them, in case that is different
|
---|
2898 | from the host.
|
---|
2899 |
|
---|
2900 | Programs for which cross-operation is not meaningful need not accept
|
---|
2901 | the `--host' option, because configuring an entire operating system for
|
---|
2902 | cross-operation is not a meaningful thing.
|
---|
2903 |
|
---|
2904 | Some programs have ways of configuring themselves automatically. If
|
---|
2905 | your program is set up to do this, your `configure' script can simply
|
---|
2906 | ignore most of its arguments.
|
---|
2907 |
|
---|
2908 |
|
---|
2909 | File: standards.info, Node: Makefile Conventions, Next: Releases, Prev: Configuration, Up: Managing Releases
|
---|
2910 |
|
---|
2911 | Makefile Conventions
|
---|
2912 | ====================
|
---|
2913 |
|
---|
2914 | This node describes conventions for writing the Makefiles for GNU
|
---|
2915 | programs.
|
---|
2916 |
|
---|
2917 | * Menu:
|
---|
2918 |
|
---|
2919 | * Makefile Basics:: General Conventions for Makefiles
|
---|
2920 | * Utilities in Makefiles:: Utilities in Makefiles
|
---|
2921 | * Command Variables:: Variables for Specifying Commands
|
---|
2922 | * Directory Variables:: Variables for Installation Directories
|
---|
2923 | * Standard Targets:: Standard Targets for Users
|
---|
2924 | * Install Command Categories:: Three categories of commands in the `install'
|
---|
2925 | rule: normal, pre-install and post-install.
|
---|
2926 |
|
---|
2927 |
|
---|
2928 | File: standards.info, Node: Makefile Basics, Next: Utilities in Makefiles, Up: Makefile Conventions
|
---|
2929 |
|
---|
2930 | General Conventions for Makefiles
|
---|
2931 | ---------------------------------
|
---|
2932 |
|
---|
2933 | Every Makefile should contain this line:
|
---|
2934 |
|
---|
2935 | SHELL = /bin/sh
|
---|
2936 |
|
---|
2937 | to avoid trouble on systems where the `SHELL' variable might be
|
---|
2938 | inherited from the environment. (This is never a problem with GNU
|
---|
2939 | `make'.)
|
---|
2940 |
|
---|
2941 | Different `make' programs have incompatible suffix lists and
|
---|
2942 | implicit rules, and this sometimes creates confusion or misbehavior. So
|
---|
2943 | it is a good idea to set the suffix list explicitly using only the
|
---|
2944 | suffixes you need in the particular Makefile, like this:
|
---|
2945 |
|
---|
2946 | .SUFFIXES:
|
---|
2947 | .SUFFIXES: .c .o
|
---|
2948 |
|
---|
2949 | The first line clears out the suffix list, the second introduces all
|
---|
2950 | suffixes which may be subject to implicit rules in this Makefile.
|
---|
2951 |
|
---|
2952 | Don't assume that `.' is in the path for command execution. When
|
---|
2953 | you need to run programs that are a part of your package during the
|
---|
2954 | make, please make sure that it uses `./' if the program is built as
|
---|
2955 | part of the make or `$(srcdir)/' if the file is an unchanging part of
|
---|
2956 | the source code. Without one of these prefixes, the current search
|
---|
2957 | path is used.
|
---|
2958 |
|
---|
2959 | The distinction between `./' (the "build directory") and
|
---|
2960 | `$(srcdir)/' (the "source directory") is important because users can
|
---|
2961 | build in a separate directory using the `--srcdir' option to
|
---|
2962 | `configure'. A rule of the form:
|
---|
2963 |
|
---|
2964 | foo.1 : foo.man sedscript
|
---|
2965 | sed -e sedscript foo.man > foo.1
|
---|
2966 |
|
---|
2967 | will fail when the build directory is not the source directory, because
|
---|
2968 | `foo.man' and `sedscript' are in the the source directory.
|
---|
2969 |
|
---|
2970 | When using GNU `make', relying on `VPATH' to find the source file
|
---|
2971 | will work in the case where there is a single dependency file, since
|
---|
2972 | the `make' automatic variable `$<' will represent the source file
|
---|
2973 | wherever it is. (Many versions of `make' set `$<' only in implicit
|
---|
2974 | rules.) A Makefile target like
|
---|
2975 |
|
---|
2976 | foo.o : bar.c
|
---|
2977 | $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
|
---|
2978 |
|
---|
2979 | should instead be written as
|
---|
2980 |
|
---|
2981 | foo.o : bar.c
|
---|
2982 | $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@
|
---|
2983 |
|
---|
2984 | in order to allow `VPATH' to work correctly. When the target has
|
---|
2985 | multiple dependencies, using an explicit `$(srcdir)' is the easiest way
|
---|
2986 | to make the rule work well. For example, the target above for `foo.1'
|
---|
2987 | is best written as:
|
---|
2988 |
|
---|
2989 | foo.1 : foo.man sedscript
|
---|
2990 | sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@
|
---|
2991 |
|
---|
2992 | GNU distributions usually contain some files which are not source
|
---|
2993 | files--for example, Info files, and the output from Autoconf, Automake,
|
---|
2994 | Bison or Flex. Since these files normally appear in the source
|
---|
2995 | directory, they should always appear in the source directory, not in the
|
---|
2996 | build directory. So Makefile rules to update them should put the
|
---|
2997 | updated files in the source directory.
|
---|
2998 |
|
---|
2999 | However, if a file does not appear in the distribution, then the
|
---|
3000 | Makefile should not put it in the source directory, because building a
|
---|
3001 | program in ordinary circumstances should not modify the source directory
|
---|
3002 | in any way.
|
---|
3003 |
|
---|
3004 | Try to make the build and installation targets, at least (and all
|
---|
3005 | their subtargets) work correctly with a parallel `make'.
|
---|
3006 |
|
---|
3007 |
|
---|
3008 | File: standards.info, Node: Utilities in Makefiles, Next: Command Variables, Prev: Makefile Basics, Up: Makefile Conventions
|
---|
3009 |
|
---|
3010 | Utilities in Makefiles
|
---|
3011 | ----------------------
|
---|
3012 |
|
---|
3013 | Write the Makefile commands (and any shell scripts, such as
|
---|
3014 | `configure') to run in `sh', not in `csh'. Don't use any special
|
---|
3015 | features of `ksh' or `bash'.
|
---|
3016 |
|
---|
3017 | The `configure' script and the Makefile rules for building and
|
---|
3018 | installation should not use any utilities directly except these:
|
---|
3019 |
|
---|
3020 | cat cmp cp diff echo egrep expr false grep install-info
|
---|
3021 | ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
|
---|
3022 |
|
---|
3023 | The compression program `gzip' can be used in the `dist' rule.
|
---|
3024 |
|
---|
3025 | Stick to the generally supported options for these programs. For
|
---|
3026 | example, don't use `mkdir -p', convenient as it may be, because most
|
---|
3027 | systems don't support it.
|
---|
3028 |
|
---|
3029 | It is a good idea to avoid creating symbolic links in makefiles,
|
---|
3030 | since a few systems don't support them.
|
---|
3031 |
|
---|
3032 | The Makefile rules for building and installation can also use
|
---|
3033 | compilers and related programs, but should do so via `make' variables
|
---|
3034 | so that the user can substitute alternatives. Here are some of the
|
---|
3035 | programs we mean:
|
---|
3036 |
|
---|
3037 | ar bison cc flex install ld ldconfig lex
|
---|
3038 | make makeinfo ranlib texi2dvi yacc
|
---|
3039 |
|
---|
3040 | Use the following `make' variables to run those programs:
|
---|
3041 |
|
---|
3042 | $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LDCONFIG) $(LEX)
|
---|
3043 | $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
|
---|
3044 |
|
---|
3045 | When you use `ranlib' or `ldconfig', you should make sure nothing
|
---|
3046 | bad happens if the system does not have the program in question.
|
---|
3047 | Arrange to ignore an error from that command, and print a message before
|
---|
3048 | the command to tell the user that failure of this command does not mean
|
---|
3049 | a problem. (The Autoconf `AC_PROG_RANLIB' macro can help with this.)
|
---|
3050 |
|
---|
3051 | If you use symbolic links, you should implement a fallback for
|
---|
3052 | systems that don't have symbolic links.
|
---|
3053 |
|
---|
3054 | Additional utilities that can be used via Make variables are:
|
---|
3055 |
|
---|
3056 | chgrp chmod chown mknod
|
---|
3057 |
|
---|
3058 | It is ok to use other utilities in Makefile portions (or scripts)
|
---|
3059 | intended only for particular systems where you know those utilities
|
---|
3060 | exist.
|
---|
3061 |
|
---|
3062 |
|
---|
3063 | File: standards.info, Node: Command Variables, Next: Directory Variables, Prev: Utilities in Makefiles, Up: Makefile Conventions
|
---|
3064 |
|
---|
3065 | Variables for Specifying Commands
|
---|
3066 | ---------------------------------
|
---|
3067 |
|
---|
3068 | Makefiles should provide variables for overriding certain commands,
|
---|
3069 | options, and so on.
|
---|
3070 |
|
---|
3071 | In particular, you should run most utility programs via variables.
|
---|
3072 | Thus, if you use Bison, have a variable named `BISON' whose default
|
---|
3073 | value is set with `BISON = bison', and refer to it with `$(BISON)'
|
---|
3074 | whenever you need to use Bison.
|
---|
3075 |
|
---|
3076 | File management utilities such as `ln', `rm', `mv', and so on, need
|
---|
3077 | not be referred to through variables in this way, since users don't
|
---|
3078 | need to replace them with other programs.
|
---|
3079 |
|
---|
3080 | Each program-name variable should come with an options variable that
|
---|
3081 | is used to supply options to the program. Append `FLAGS' to the
|
---|
3082 | program-name variable name to get the options variable name--for
|
---|
3083 | example, `BISONFLAGS'. (The names `CFLAGS' for the C compiler,
|
---|
3084 | `YFLAGS' for yacc, and `LFLAGS' for lex, are exceptions to this rule,
|
---|
3085 | but we keep them because they are standard.) Use `CPPFLAGS' in any
|
---|
3086 | compilation command that runs the preprocessor, and use `LDFLAGS' in
|
---|
3087 | any compilation command that does linking as well as in any direct use
|
---|
3088 | of `ld'.
|
---|
3089 |
|
---|
3090 | If there are C compiler options that *must* be used for proper
|
---|
3091 | compilation of certain files, do not include them in `CFLAGS'. Users
|
---|
3092 | expect to be able to specify `CFLAGS' freely themselves. Instead,
|
---|
3093 | arrange to pass the necessary options to the C compiler independently
|
---|
3094 | of `CFLAGS', by writing them explicitly in the compilation commands or
|
---|
3095 | by defining an implicit rule, like this:
|
---|
3096 |
|
---|
3097 | CFLAGS = -g
|
---|
3098 | ALL_CFLAGS = -I. $(CFLAGS)
|
---|
3099 | .c.o:
|
---|
3100 | $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
|
---|
3101 |
|
---|
3102 | Do include the `-g' option in `CFLAGS', because that is not
|
---|
3103 | *required* for proper compilation. You can consider it a default that
|
---|
3104 | is only recommended. If the package is set up so that it is compiled
|
---|
3105 | with GCC by default, then you might as well include `-O' in the default
|
---|
3106 | value of `CFLAGS' as well.
|
---|
3107 |
|
---|
3108 | Put `CFLAGS' last in the compilation command, after other variables
|
---|
3109 | containing compiler options, so the user can use `CFLAGS' to override
|
---|
3110 | the others.
|
---|
3111 |
|
---|
3112 | `CFLAGS' should be used in every invocation of the C compiler, both
|
---|
3113 | those which do compilation and those which do linking.
|
---|
3114 |
|
---|
3115 | Every Makefile should define the variable `INSTALL', which is the
|
---|
3116 | basic command for installing a file into the system.
|
---|
3117 |
|
---|
3118 | Every Makefile should also define the variables `INSTALL_PROGRAM'
|
---|
3119 | and `INSTALL_DATA'. (The default for each of these should be
|
---|
3120 | `$(INSTALL)'.) Then it should use those variables as the commands for
|
---|
3121 | actual installation, for executables and nonexecutables respectively.
|
---|
3122 | Use these variables as follows:
|
---|
3123 |
|
---|
3124 | $(INSTALL_PROGRAM) foo $(bindir)/foo
|
---|
3125 | $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
|
---|
3126 |
|
---|
3127 | Always use a file name, not a directory name, as the second argument of
|
---|
3128 | the installation commands. Use a separate command for each file to be
|
---|
3129 | installed.
|
---|
3130 |
|
---|
3131 |
|
---|
3132 | File: standards.info, Node: Directory Variables, Next: Standard Targets, Prev: Command Variables, Up: Makefile Conventions
|
---|
3133 |
|
---|
3134 | Variables for Installation Directories
|
---|
3135 | --------------------------------------
|
---|
3136 |
|
---|
3137 | Installation directories should always be named by variables, so it
|
---|
3138 | is easy to install in a nonstandard place. The standard names for these
|
---|
3139 | variables are described below. They are based on a standard filesystem
|
---|
3140 | layout; variants of it are used in SVR4, 4.4BSD, Linux, Ultrix v4, and
|
---|
3141 | other modern operating systems.
|
---|
3142 |
|
---|
3143 | These two variables set the root for the installation. All the other
|
---|
3144 | installation directories should be subdirectories of one of these two,
|
---|
3145 | and nothing should be directly installed into these two directories.
|
---|
3146 |
|
---|
3147 | `prefix'
|
---|
3148 | A prefix used in constructing the default values of the variables
|
---|
3149 | listed below. The default value of `prefix' should be
|
---|
3150 | `/usr/local'. When building the complete GNU system, the prefix
|
---|
3151 | will be empty and `/usr' will be a symbolic link to `/'. (If you
|
---|
3152 | are using Autoconf, write it as `@prefix@'.)
|
---|
3153 |
|
---|
3154 | `exec_prefix'
|
---|
3155 | A prefix used in constructing the default values of some of the
|
---|
3156 | variables listed below. The default value of `exec_prefix' should
|
---|
3157 | be `$(prefix)'. (If you are using Autoconf, write it as
|
---|
3158 | `@exec_prefix@'.)
|
---|
3159 |
|
---|
3160 | Generally, `$(exec_prefix)' is used for directories that contain
|
---|
3161 | machine-specific files (such as executables and subroutine
|
---|
3162 | libraries), while `$(prefix)' is used directly for other
|
---|
3163 | directories.
|
---|
3164 |
|
---|
3165 | Executable programs are installed in one of the following
|
---|
3166 | directories.
|
---|
3167 |
|
---|
3168 | `bindir'
|
---|
3169 | The directory for installing executable programs that users can
|
---|
3170 | run. This should normally be `/usr/local/bin', but write it as
|
---|
3171 | `$(exec_prefix)/bin'. (If you are using Autoconf, write it as
|
---|
3172 | `@bindir@'.)
|
---|
3173 |
|
---|
3174 | `sbindir'
|
---|
3175 | The directory for installing executable programs that can be run
|
---|
3176 | from the shell, but are only generally useful to system
|
---|
3177 | administrators. This should normally be `/usr/local/sbin', but
|
---|
3178 | write it as `$(exec_prefix)/sbin'. (If you are using Autoconf,
|
---|
3179 | write it as `@sbindir@'.)
|
---|
3180 |
|
---|
3181 | `libexecdir'
|
---|
3182 | The directory for installing executable programs to be run by other
|
---|
3183 | programs rather than by users. This directory should normally be
|
---|
3184 | `/usr/local/libexec', but write it as `$(exec_prefix)/libexec'.
|
---|
3185 | (If you are using Autoconf, write it as `@libexecdir@'.)
|
---|
3186 |
|
---|
3187 | Data files used by the program during its execution are divided into
|
---|
3188 | categories in two ways.
|
---|
3189 |
|
---|
3190 | * Some files are normally modified by programs; others are never
|
---|
3191 | normally modified (though users may edit some of these).
|
---|
3192 |
|
---|
3193 | * Some files are architecture-independent and can be shared by all
|
---|
3194 | machines at a site; some are architecture-dependent and can be
|
---|
3195 | shared only by machines of the same kind and operating system;
|
---|
3196 | others may never be shared between two machines.
|
---|
3197 |
|
---|
3198 | This makes for six different possibilities. However, we want to
|
---|
3199 | discourage the use of architecture-dependent files, aside from object
|
---|
3200 | files and libraries. It is much cleaner to make other data files
|
---|
3201 | architecture-independent, and it is generally not hard.
|
---|
3202 |
|
---|
3203 | Therefore, here are the variables Makefiles should use to specify
|
---|
3204 | directories:
|
---|
3205 |
|
---|
3206 | `datadir'
|
---|
3207 | The directory for installing read-only architecture independent
|
---|
3208 | data files. This should normally be `/usr/local/share', but write
|
---|
3209 | it as `$(prefix)/share'. (If you are using Autoconf, write it as
|
---|
3210 | `@datadir@'.) As a special exception, see `$(infodir)' and
|
---|
3211 | `$(includedir)' below.
|
---|
3212 |
|
---|
3213 | `sysconfdir'
|
---|
3214 | The directory for installing read-only data files that pertain to a
|
---|
3215 | single machine-that is to say, files for configuring a host.
|
---|
3216 | Mailer and network configuration files, `/etc/passwd', and so
|
---|
3217 | forth belong here. All the files in this directory should be
|
---|
3218 | ordinary ASCII text files. This directory should normally be
|
---|
3219 | `/usr/local/etc', but write it as `$(prefix)/etc'. (If you are
|
---|
3220 | using Autoconf, write it as `@sysconfdir@'.)
|
---|
3221 |
|
---|
3222 | Do not install executables here in this directory (they probably
|
---|
3223 | belong in `$(libexecdir)' or `$(sbindir)'). Also do not install
|
---|
3224 | files that are modified in the normal course of their use (programs
|
---|
3225 | whose purpose is to change the configuration of the system
|
---|
3226 | excluded). Those probably belong in `$(localstatedir)'.
|
---|
3227 |
|
---|
3228 | `sharedstatedir'
|
---|
3229 | The directory for installing architecture-independent data files
|
---|
3230 | which the programs modify while they run. This should normally be
|
---|
3231 | `/usr/local/com', but write it as `$(prefix)/com'. (If you are
|
---|
3232 | using Autoconf, write it as `@sharedstatedir@'.)
|
---|
3233 |
|
---|
3234 | `localstatedir'
|
---|
3235 | The directory for installing data files which the programs modify
|
---|
3236 | while they run, and that pertain to one specific machine. Users
|
---|
3237 | should never need to modify files in this directory to configure
|
---|
3238 | the package's operation; put such configuration information in
|
---|
3239 | separate files that go in `$(datadir)' or `$(sysconfdir)'.
|
---|
3240 | `$(localstatedir)' should normally be `/usr/local/var', but write
|
---|
3241 | it as `$(prefix)/var'. (If you are using Autoconf, write it as
|
---|
3242 | `@localstatedir@'.)
|
---|
3243 |
|
---|
3244 | `libdir'
|
---|
3245 | The directory for object files and libraries of object code. Do
|
---|
3246 | not install executables here, they probably ought to go in
|
---|
3247 | `$(libexecdir)' instead. The value of `libdir' should normally be
|
---|
3248 | `/usr/local/lib', but write it as `$(exec_prefix)/lib'. (If you
|
---|
3249 | are using Autoconf, write it as `@libdir@'.)
|
---|
3250 |
|
---|
3251 | `infodir'
|
---|
3252 | The directory for installing the Info files for this package. By
|
---|
3253 | default, it should be `/usr/local/info', but it should be written
|
---|
3254 | as `$(prefix)/info'. (If you are using Autoconf, write it as
|
---|
3255 | `@infodir@'.)
|
---|
3256 |
|
---|
3257 | `lispdir'
|
---|
3258 | The directory for installing any Emacs Lisp files in this package.
|
---|
3259 | By default, it should be `/usr/local/share/emacs/site-lisp', but
|
---|
3260 | it should be written as `$(prefix)/share/emacs/site-lisp'.
|
---|
3261 |
|
---|
3262 | If you are using Autoconf, write the default as `@lispdir@'. In
|
---|
3263 | order to make `@lispdir@' work, you need the following lines in
|
---|
3264 | your `configure.in' file:
|
---|
3265 |
|
---|
3266 | lispdir='${datadir}/emacs/site-lisp'
|
---|
3267 | AC_SUBST(lispdir)
|
---|
3268 |
|
---|
3269 | `includedir'
|
---|
3270 | The directory for installing header files to be included by user
|
---|
3271 | programs with the C `#include' preprocessor directive. This
|
---|
3272 | should normally be `/usr/local/include', but write it as
|
---|
3273 | `$(prefix)/include'. (If you are using Autoconf, write it as
|
---|
3274 | `@includedir@'.)
|
---|
3275 |
|
---|
3276 | Most compilers other than GCC do not look for header files in
|
---|
3277 | directory `/usr/local/include'. So installing the header files
|
---|
3278 | this way is only useful with GCC. Sometimes this is not a problem
|
---|
3279 | because some libraries are only really intended to work with GCC.
|
---|
3280 | But some libraries are intended to work with other compilers.
|
---|
3281 | They should install their header files in two places, one
|
---|
3282 | specified by `includedir' and one specified by `oldincludedir'.
|
---|
3283 |
|
---|
3284 | `oldincludedir'
|
---|
3285 | The directory for installing `#include' header files for use with
|
---|
3286 | compilers other than GCC. This should normally be `/usr/include'.
|
---|
3287 | (If you are using Autoconf, you can write it as `@oldincludedir@'.)
|
---|
3288 |
|
---|
3289 | The Makefile commands should check whether the value of
|
---|
3290 | `oldincludedir' is empty. If it is, they should not try to use
|
---|
3291 | it; they should cancel the second installation of the header files.
|
---|
3292 |
|
---|
3293 | A package should not replace an existing header in this directory
|
---|
3294 | unless the header came from the same package. Thus, if your Foo
|
---|
3295 | package provides a header file `foo.h', then it should install the
|
---|
3296 | header file in the `oldincludedir' directory if either (1) there
|
---|
3297 | is no `foo.h' there or (2) the `foo.h' that exists came from the
|
---|
3298 | Foo package.
|
---|
3299 |
|
---|
3300 | To tell whether `foo.h' came from the Foo package, put a magic
|
---|
3301 | string in the file--part of a comment--and `grep' for that string.
|
---|
3302 |
|
---|
3303 | Unix-style man pages are installed in one of the following:
|
---|
3304 |
|
---|
3305 | `mandir'
|
---|
3306 | The top-level directory for installing the man pages (if any) for
|
---|
3307 | this package. It will normally be `/usr/local/man', but you should
|
---|
3308 | write it as `$(prefix)/man'. (If you are using Autoconf, write it
|
---|
3309 | as `@mandir@'.)
|
---|
3310 |
|
---|
3311 | `man1dir'
|
---|
3312 | The directory for installing section 1 man pages. Write it as
|
---|
3313 | `$(mandir)/man1'.
|
---|
3314 |
|
---|
3315 | `man2dir'
|
---|
3316 | The directory for installing section 2 man pages. Write it as
|
---|
3317 | `$(mandir)/man2'
|
---|
3318 |
|
---|
3319 | `...'
|
---|
3320 | *Don't make the primary documentation for any GNU software be a
|
---|
3321 | man page. Write a manual in Texinfo instead. Man pages are just
|
---|
3322 | for the sake of people running GNU software on Unix, which is a
|
---|
3323 | secondary application only.*
|
---|
3324 |
|
---|
3325 | `manext'
|
---|
3326 | The file name extension for the installed man page. This should
|
---|
3327 | contain a period followed by the appropriate digit; it should
|
---|
3328 | normally be `.1'.
|
---|
3329 |
|
---|
3330 | `man1ext'
|
---|
3331 | The file name extension for installed section 1 man pages.
|
---|
3332 |
|
---|
3333 | `man2ext'
|
---|
3334 | The file name extension for installed section 2 man pages.
|
---|
3335 |
|
---|
3336 | `...'
|
---|
3337 | Use these names instead of `manext' if the package needs to
|
---|
3338 | install man pages in more than one section of the manual.
|
---|
3339 |
|
---|
3340 | And finally, you should set the following variable:
|
---|
3341 |
|
---|
3342 | `srcdir'
|
---|
3343 | The directory for the sources being compiled. The value of this
|
---|
3344 | variable is normally inserted by the `configure' shell script.
|
---|
3345 | (If you are using Autconf, use `srcdir = @srcdir@'.)
|
---|
3346 |
|
---|
3347 | For example:
|
---|
3348 |
|
---|
3349 | # Common prefix for installation directories.
|
---|
3350 | # NOTE: This directory must exist when you start the install.
|
---|
3351 | prefix = /usr/local
|
---|
3352 | exec_prefix = $(prefix)
|
---|
3353 | # Where to put the executable for the command `gcc'.
|
---|
3354 | bindir = $(exec_prefix)/bin
|
---|
3355 | # Where to put the directories used by the compiler.
|
---|
3356 | libexecdir = $(exec_prefix)/libexec
|
---|
3357 | # Where to put the Info files.
|
---|
3358 | infodir = $(prefix)/info
|
---|
3359 |
|
---|
3360 | If your program installs a large number of files into one of the
|
---|
3361 | standard user-specified directories, it might be useful to group them
|
---|
3362 | into a subdirectory particular to that program. If you do this, you
|
---|
3363 | should write the `install' rule to create these subdirectories.
|
---|
3364 |
|
---|
3365 | Do not expect the user to include the subdirectory name in the value
|
---|
3366 | of any of the variables listed above. The idea of having a uniform set
|
---|
3367 | of variable names for installation directories is to enable the user to
|
---|
3368 | specify the exact same values for several different GNU packages. In
|
---|
3369 | order for this to be useful, all the packages must be designed so that
|
---|
3370 | they will work sensibly when the user does so.
|
---|
3371 |
|
---|
3372 |
|
---|
3373 | File: standards.info, Node: Standard Targets, Next: Install Command Categories, Prev: Directory Variables, Up: Makefile Conventions
|
---|
3374 |
|
---|
3375 | Standard Targets for Users
|
---|
3376 | --------------------------
|
---|
3377 |
|
---|
3378 | All GNU programs should have the following targets in their
|
---|
3379 | Makefiles:
|
---|
3380 |
|
---|
3381 | `all'
|
---|
3382 | Compile the entire program. This should be the default target.
|
---|
3383 | This target need not rebuild any documentation files; Info files
|
---|
3384 | should normally be included in the distribution, and DVI files
|
---|
3385 | should be made only when explicitly asked for.
|
---|
3386 |
|
---|
3387 | By default, the Make rules should compile and link with `-g', so
|
---|
3388 | that executable programs have debugging symbols. Users who don't
|
---|
3389 | mind being helpless can strip the executables later if they wish.
|
---|
3390 |
|
---|
3391 | `install'
|
---|
3392 | Compile the program and copy the executables, libraries, and so on
|
---|
3393 | to the file names where they should reside for actual use. If
|
---|
3394 | there is a simple test to verify that a program is properly
|
---|
3395 | installed, this target should run that test.
|
---|
3396 |
|
---|
3397 | Do not strip executables when installing them. Devil-may-care
|
---|
3398 | users can use the `install-strip' target to do that.
|
---|
3399 |
|
---|
3400 | If possible, write the `install' target rule so that it does not
|
---|
3401 | modify anything in the directory where the program was built,
|
---|
3402 | provided `make all' has just been done. This is convenient for
|
---|
3403 | building the program under one user name and installing it under
|
---|
3404 | another.
|
---|
3405 |
|
---|
3406 | The commands should create all the directories in which files are
|
---|
3407 | to be installed, if they don't already exist. This includes the
|
---|
3408 | directories specified as the values of the variables `prefix' and
|
---|
3409 | `exec_prefix', as well as all subdirectories that are needed. One
|
---|
3410 | way to do this is by means of an `installdirs' target as described
|
---|
3411 | below.
|
---|
3412 |
|
---|
3413 | Use `-' before any command for installing a man page, so that
|
---|
3414 | `make' will ignore any errors. This is in case there are systems
|
---|
3415 | that don't have the Unix man page documentation system installed.
|
---|
3416 |
|
---|
3417 | The way to install Info files is to copy them into `$(infodir)'
|
---|
3418 | with `$(INSTALL_DATA)' (*note Command Variables::.), and then run
|
---|
3419 | the `install-info' program if it is present. `install-info' is a
|
---|
3420 | program that edits the Info `dir' file to add or update the menu
|
---|
3421 | entry for the given Info file; it is part of the Texinfo package.
|
---|
3422 | Here is a sample rule to install an Info file:
|
---|
3423 |
|
---|
3424 | $(infodir)/foo.info: foo.info
|
---|
3425 | $(POST_INSTALL)
|
---|
3426 | # There may be a newer info file in . than in srcdir.
|
---|
3427 | -if test -f foo.info; then d=.; \
|
---|
3428 | else d=$(srcdir); fi; \
|
---|
3429 | $(INSTALL_DATA) $$d/foo.info $@; \
|
---|
3430 | # Run install-info only if it exists.
|
---|
3431 | # Use `if' instead of just prepending `-' to the
|
---|
3432 | # line so we notice real errors from install-info.
|
---|
3433 | # We use `$(SHELL) -c' because some shells do not
|
---|
3434 | # fail gracefully when there is an unknown command.
|
---|
3435 | if $(SHELL) -c 'install-info --version' \
|
---|
3436 | >/dev/null 2>&1; then \
|
---|
3437 | install-info --dir-file=$(infodir)/dir \
|
---|
3438 | $(infodir)/foo.info; \
|
---|
3439 | else true; fi
|
---|
3440 |
|
---|
3441 | When writing the `install' target, you must classify all the
|
---|
3442 | commands into three categories: normal ones, "pre-installation"
|
---|
3443 | commands and "post-installation" commands. *Note Install Command
|
---|
3444 | Categories::.
|
---|
3445 |
|
---|
3446 | `uninstall'
|
---|
3447 | Delete all the installed files--the copies that the `install'
|
---|
3448 | target creates.
|
---|
3449 |
|
---|
3450 | This rule should not modify the directories where compilation is
|
---|
3451 | done, only the directories where files are installed.
|
---|
3452 |
|
---|
3453 | The uninstallation commands are divided into three categories,
|
---|
3454 | just like the installation commands. *Note Install Command
|
---|
3455 | Categories::.
|
---|
3456 |
|
---|
3457 | `install-strip'
|
---|
3458 | Like `install', but strip the executable files while installing
|
---|
3459 | them. In many cases, the definition of this target can be very
|
---|
3460 | simple:
|
---|
3461 |
|
---|
3462 | install-strip:
|
---|
3463 | $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
|
---|
3464 | install
|
---|
3465 |
|
---|
3466 | Normally we do not recommend stripping an executable unless you
|
---|
3467 | are sure the program has no bugs. However, it can be reasonable
|
---|
3468 | to install a stripped executable for actual execution while saving
|
---|
3469 | the unstripped executable elsewhere in case there is a bug.
|
---|
3470 |
|
---|
3471 | `clean'
|
---|
3472 | Delete all files from the current directory that are normally
|
---|
3473 | created by building the program. Don't delete the files that
|
---|
3474 | record the configuration. Also preserve files that could be made
|
---|
3475 | by building, but normally aren't because the distribution comes
|
---|
3476 | with them.
|
---|
3477 |
|
---|
3478 | Delete `.dvi' files here if they are not part of the distribution.
|
---|
3479 |
|
---|
3480 | `distclean'
|
---|
3481 | Delete all files from the current directory that are created by
|
---|
3482 | configuring or building the program. If you have unpacked the
|
---|
3483 | source and built the program without creating any other files,
|
---|
3484 | `make distclean' should leave only the files that were in the
|
---|
3485 | distribution.
|
---|
3486 |
|
---|
3487 | `mostlyclean'
|
---|
3488 | Like `clean', but may refrain from deleting a few files that people
|
---|
3489 | normally don't want to recompile. For example, the `mostlyclean'
|
---|
3490 | target for GCC does not delete `libgcc.a', because recompiling it
|
---|
3491 | is rarely necessary and takes a lot of time.
|
---|
3492 |
|
---|
3493 | `maintainer-clean'
|
---|
3494 | Delete almost everything from the current directory that can be
|
---|
3495 | reconstructed with this Makefile. This typically includes
|
---|
3496 | everything deleted by `distclean', plus more: C source files
|
---|
3497 | produced by Bison, tags tables, Info files, and so on.
|
---|
3498 |
|
---|
3499 | The reason we say "almost everything" is that running the command
|
---|
3500 | `make maintainer-clean' should not delete `configure' even if
|
---|
3501 | `configure' can be remade using a rule in the Makefile. More
|
---|
3502 | generally, `make maintainer-clean' should not delete anything that
|
---|
3503 | needs to exist in order to run `configure' and then begin to build
|
---|
3504 | the program. This is the only exception; `maintainer-clean' should
|
---|
3505 | delete everything else that can be rebuilt.
|
---|
3506 |
|
---|
3507 | The `maintainer-clean' target is intended to be used by a
|
---|
3508 | maintainer of the package, not by ordinary users. You may need
|
---|
3509 | special tools to reconstruct some of the files that `make
|
---|
3510 | maintainer-clean' deletes. Since these files are normally
|
---|
3511 | included in the distribution, we don't take care to make them easy
|
---|
3512 | to reconstruct. If you find you need to unpack the full
|
---|
3513 | distribution again, don't blame us.
|
---|
3514 |
|
---|
3515 | To help make users aware of this, the commands for the special
|
---|
3516 | `maintainer-clean' target should start with these two:
|
---|
3517 |
|
---|
3518 | @echo 'This command is intended for maintainers to use; it'
|
---|
3519 | @echo 'deletes files that may need special tools to rebuild.'
|
---|
3520 |
|
---|
3521 | `TAGS'
|
---|
3522 | Update a tags table for this program.
|
---|
3523 |
|
---|
3524 | `info'
|
---|
3525 | Generate any Info files needed. The best way to write the rules
|
---|
3526 | is as follows:
|
---|
3527 |
|
---|
3528 | info: foo.info
|
---|
3529 |
|
---|
3530 | foo.info: foo.texi chap1.texi chap2.texi
|
---|
3531 | $(MAKEINFO) $(srcdir)/foo.texi
|
---|
3532 |
|
---|
3533 | You must define the variable `MAKEINFO' in the Makefile. It should
|
---|
3534 | run the `makeinfo' program, which is part of the Texinfo
|
---|
3535 | distribution.
|
---|
3536 |
|
---|
3537 | Normally a GNU distribution comes with Info files, and that means
|
---|
3538 | the Info files are present in the source directory. Therefore,
|
---|
3539 | the Make rule for an info file should update it in the source
|
---|
3540 | directory. When users build the package, ordinarily Make will not
|
---|
3541 | update the Info files because they will already be up to date.
|
---|
3542 |
|
---|
3543 | `dvi'
|
---|
3544 | Generate DVI files for all Texinfo documentation. For example:
|
---|
3545 |
|
---|
3546 | dvi: foo.dvi
|
---|
3547 |
|
---|
3548 | foo.dvi: foo.texi chap1.texi chap2.texi
|
---|
3549 | $(TEXI2DVI) $(srcdir)/foo.texi
|
---|
3550 |
|
---|
3551 | You must define the variable `TEXI2DVI' in the Makefile. It should
|
---|
3552 | run the program `texi2dvi', which is part of the Texinfo
|
---|
3553 | distribution.(1) Alternatively, write just the dependencies, and
|
---|
3554 | allow GNU `make' to provide the command.
|
---|
3555 |
|
---|
3556 | `dist'
|
---|
3557 | Create a distribution tar file for this program. The tar file
|
---|
3558 | should be set up so that the file names in the tar file start with
|
---|
3559 | a subdirectory name which is the name of the package it is a
|
---|
3560 | distribution for. This name can include the version number.
|
---|
3561 |
|
---|
3562 | For example, the distribution tar file of GCC version 1.40 unpacks
|
---|
3563 | into a subdirectory named `gcc-1.40'.
|
---|
3564 |
|
---|
3565 | The easiest way to do this is to create a subdirectory
|
---|
3566 | appropriately named, use `ln' or `cp' to install the proper files
|
---|
3567 | in it, and then `tar' that subdirectory.
|
---|
3568 |
|
---|
3569 | Compress the tar file file with `gzip'. For example, the actual
|
---|
3570 | distribution file for GCC version 1.40 is called `gcc-1.40.tar.gz'.
|
---|
3571 |
|
---|
3572 | The `dist' target should explicitly depend on all non-source files
|
---|
3573 | that are in the distribution, to make sure they are up to date in
|
---|
3574 | the distribution. *Note Making Releases: Releases.
|
---|
3575 |
|
---|
3576 | `check'
|
---|
3577 | Perform self-tests (if any). The user must build the program
|
---|
3578 | before running the tests, but need not install the program; you
|
---|
3579 | should write the self-tests so that they work when the program is
|
---|
3580 | built but not installed.
|
---|
3581 |
|
---|
3582 | The following targets are suggested as conventional names, for
|
---|
3583 | programs in which they are useful.
|
---|
3584 |
|
---|
3585 | `installcheck'
|
---|
3586 | Perform installation tests (if any). The user must build and
|
---|
3587 | install the program before running the tests. You should not
|
---|
3588 | assume that `$(bindir)' is in the search path.
|
---|
3589 |
|
---|
3590 | `installdirs'
|
---|
3591 | It's useful to add a target named `installdirs' to create the
|
---|
3592 | directories where files are installed, and their parent
|
---|
3593 | directories. There is a script called `mkinstalldirs' which is
|
---|
3594 | convenient for this; you can find it in the Texinfo package. You
|
---|
3595 | can use a rule like this:
|
---|
3596 |
|
---|
3597 | # Make sure all installation directories (e.g. $(bindir))
|
---|
3598 | # actually exist by making them if necessary.
|
---|
3599 | installdirs: mkinstalldirs
|
---|
3600 | $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
|
---|
3601 | $(libdir) $(infodir) \
|
---|
3602 | $(mandir)
|
---|
3603 |
|
---|
3604 | This rule should not modify the directories where compilation is
|
---|
3605 | done. It should do nothing but create installation directories.
|
---|
3606 |
|
---|
3607 | ---------- Footnotes ----------
|
---|
3608 |
|
---|
3609 | (1) `texi2dvi' uses TeX to do the real work of formatting. TeX is
|
---|
3610 | not distributed with Texinfo.
|
---|
3611 |
|
---|
3612 |
|
---|
3613 | File: standards.info, Node: Install Command Categories, Prev: Standard Targets, Up: Makefile Conventions
|
---|
3614 |
|
---|
3615 | Install Command Categories
|
---|
3616 | --------------------------
|
---|
3617 |
|
---|
3618 | When writing the `install' target, you must classify all the
|
---|
3619 | commands into three categories: normal ones, "pre-installation"
|
---|
3620 | commands and "post-installation" commands.
|
---|
3621 |
|
---|
3622 | Normal commands move files into their proper places, and set their
|
---|
3623 | modes. They may not alter any files except the ones that come entirely
|
---|
3624 | from the package they belong to.
|
---|
3625 |
|
---|
3626 | Pre-installation and post-installation commands may alter other
|
---|
3627 | files; in particular, they can edit global configuration files or data
|
---|
3628 | bases.
|
---|
3629 |
|
---|
3630 | Pre-installation commands are typically executed before the normal
|
---|
3631 | commands, and post-installation commands are typically run after the
|
---|
3632 | normal commands.
|
---|
3633 |
|
---|
3634 | The most common use for a post-installation command is to run
|
---|
3635 | `install-info'. This cannot be done with a normal command, since it
|
---|
3636 | alters a file (the Info directory) which does not come entirely and
|
---|
3637 | solely from the package being installed. It is a post-installation
|
---|
3638 | command because it needs to be done after the normal command which
|
---|
3639 | installs the package's Info files.
|
---|
3640 |
|
---|
3641 | Most programs don't need any pre-installation commands, but we have
|
---|
3642 | the feature just in case it is needed.
|
---|
3643 |
|
---|
3644 | To classify the commands in the `install' rule into these three
|
---|
3645 | categories, insert "category lines" among them. A category line
|
---|
3646 | specifies the category for the commands that follow.
|
---|
3647 |
|
---|
3648 | A category line consists of a tab and a reference to a special Make
|
---|
3649 | variable, plus an optional comment at the end. There are three
|
---|
3650 | variables you can use, one for each category; the variable name
|
---|
3651 | specifies the category. Category lines are no-ops in ordinary execution
|
---|
3652 | because these three Make variables are normally undefined (and you
|
---|
3653 | *should not* define them in the makefile).
|
---|
3654 |
|
---|
3655 | Here are the three possible category lines, each with a comment that
|
---|
3656 | explains what it means:
|
---|
3657 |
|
---|
3658 | $(PRE_INSTALL) # Pre-install commands follow.
|
---|
3659 | $(POST_INSTALL) # Post-install commands follow.
|
---|
3660 | $(NORMAL_INSTALL) # Normal commands follow.
|
---|
3661 |
|
---|
3662 | If you don't use a category line at the beginning of the `install'
|
---|
3663 | rule, all the commands are classified as normal until the first category
|
---|
3664 | line. If you don't use any category lines, all the commands are
|
---|
3665 | classified as normal.
|
---|
3666 |
|
---|
3667 | These are the category lines for `uninstall':
|
---|
3668 |
|
---|
3669 | $(PRE_UNINSTALL) # Pre-uninstall commands follow.
|
---|
3670 | $(POST_UNINSTALL) # Post-uninstall commands follow.
|
---|
3671 | $(NORMAL_UNINSTALL) # Normal commands follow.
|
---|
3672 |
|
---|
3673 | Typically, a pre-uninstall command would be used for deleting entries
|
---|
3674 | from the Info directory.
|
---|
3675 |
|
---|
3676 | If the `install' or `uninstall' target has any dependencies which
|
---|
3677 | act as subroutines of installation, then you should start *each*
|
---|
3678 | dependency's commands with a category line, and start the main target's
|
---|
3679 | commands with a category line also. This way, you can ensure that each
|
---|
3680 | command is placed in the right category regardless of which of the
|
---|
3681 | dependencies actually run.
|
---|
3682 |
|
---|
3683 | Pre-installation and post-installation commands should not run any
|
---|
3684 | programs except for these:
|
---|
3685 |
|
---|
3686 | [ basename bash cat chgrp chmod chown cmp cp dd diff echo
|
---|
3687 | egrep expand expr false fgrep find getopt grep gunzip gzip
|
---|
3688 | hostname install install-info kill ldconfig ln ls md5sum
|
---|
3689 | mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
|
---|
3690 | test touch true uname xargs yes
|
---|
3691 |
|
---|
3692 | The reason for distinguishing the commands in this way is for the
|
---|
3693 | sake of making binary packages. Typically a binary package contains
|
---|
3694 | all the executables and other files that need to be installed, and has
|
---|
3695 | its own method of installing them--so it does not need to run the normal
|
---|
3696 | installation commands. But installing the binary package does need to
|
---|
3697 | execute the pre-installation and post-installation commands.
|
---|
3698 |
|
---|
3699 | Programs to build binary packages work by extracting the
|
---|
3700 | pre-installation and post-installation commands. Here is one way of
|
---|
3701 | extracting the pre-installation commands:
|
---|
3702 |
|
---|
3703 | make -n install -o all \
|
---|
3704 | PRE_INSTALL=pre-install \
|
---|
3705 | POST_INSTALL=post-install \
|
---|
3706 | NORMAL_INSTALL=normal-install \
|
---|
3707 | | gawk -f pre-install.awk
|
---|
3708 |
|
---|
3709 | where the file `pre-install.awk' could contain this:
|
---|
3710 |
|
---|
3711 | $0 ~ /^\t[ \t]*(normal_install|post_install)[ \t]*$/ {on = 0}
|
---|
3712 | on {print $0}
|
---|
3713 | $0 ~ /^\t[ \t]*pre_install[ \t]*$/ {on = 1}
|
---|
3714 |
|
---|
3715 | The resulting file of pre-installation commands is executed as a
|
---|
3716 | shell script as part of installing the binary package.
|
---|
3717 |
|
---|
3718 |
|
---|
3719 | File: standards.info, Node: Releases, Prev: Makefile Conventions, Up: Managing Releases
|
---|
3720 |
|
---|
3721 | Making Releases
|
---|
3722 | ===============
|
---|
3723 |
|
---|
3724 | Package the distribution of `Foo version 69.96' up in a gzipped tar
|
---|
3725 | file with the name `foo-69.96.tar.gz'. It should unpack into a
|
---|
3726 | subdirectory named `foo-69.96'.
|
---|
3727 |
|
---|
3728 | Building and installing the program should never modify any of the
|
---|
3729 | files contained in the distribution. This means that all the files
|
---|
3730 | that form part of the program in any way must be classified into "source
|
---|
3731 | files" and "non-source files". Source files are written by humans and
|
---|
3732 | never changed automatically; non-source files are produced from source
|
---|
3733 | files by programs under the control of the Makefile.
|
---|
3734 |
|
---|
3735 | Naturally, all the source files must be in the distribution. It is
|
---|
3736 | okay to include non-source files in the distribution, provided they are
|
---|
3737 | up-to-date and machine-independent, so that building the distribution
|
---|
3738 | normally will never modify them. We commonly include non-source files
|
---|
3739 | produced by Bison, `lex', TeX, and `makeinfo'; this helps avoid
|
---|
3740 | unnecessary dependencies between our distributions, so that users can
|
---|
3741 | install whichever packages they want to install.
|
---|
3742 |
|
---|
3743 | Non-source files that might actually be modified by building and
|
---|
3744 | installing the program should *never* be included in the distribution.
|
---|
3745 | So if you do distribute non-source files, always make sure they are up
|
---|
3746 | to date when you make a new distribution.
|
---|
3747 |
|
---|
3748 | Make sure that the directory into which the distribution unpacks (as
|
---|
3749 | well as any subdirectories) are all world-writable (octal mode 777).
|
---|
3750 | This is so that old versions of `tar' which preserve the ownership and
|
---|
3751 | permissions of the files from the tar archive will be able to extract
|
---|
3752 | all the files even if the user is unprivileged.
|
---|
3753 |
|
---|
3754 | Make sure that all the files in the distribution are world-readable.
|
---|
3755 |
|
---|
3756 | Make sure that no file name in the distribution is more than 14
|
---|
3757 | characters long. Likewise, no file created by building the program
|
---|
3758 | should have a name longer than 14 characters. The reason for this is
|
---|
3759 | that some systems adhere to a foolish interpretation of the POSIX
|
---|
3760 | standard, and refuse to open a longer name, rather than truncating as
|
---|
3761 | they did in the past.
|
---|
3762 |
|
---|
3763 | Don't include any symbolic links in the distribution itself. If the
|
---|
3764 | tar file contains symbolic links, then people cannot even unpack it on
|
---|
3765 | systems that don't support symbolic links. Also, don't use multiple
|
---|
3766 | names for one file in different directories, because certain file
|
---|
3767 | systems cannot handle this and that prevents unpacking the distribution.
|
---|
3768 |
|
---|
3769 | Try to make sure that all the file names will be unique on MS-DOS. A
|
---|
3770 | name on MS-DOS consists of up to 8 characters, optionally followed by a
|
---|
3771 | period and up to three characters. MS-DOS will truncate extra
|
---|
3772 | characters both before and after the period. Thus, `foobarhacker.c'
|
---|
3773 | and `foobarhacker.o' are not ambiguous; they are truncated to
|
---|
3774 | `foobarha.c' and `foobarha.o', which are distinct.
|
---|
3775 |
|
---|
3776 | Include in your distribution a copy of the `texinfo.tex' you used to
|
---|
3777 | test print any `*.texinfo' or `*.texi' files.
|
---|
3778 |
|
---|
3779 | Likewise, if your program uses small GNU software packages like
|
---|
3780 | regex, getopt, obstack, or termcap, include them in the distribution
|
---|
3781 | file. Leaving them out would make the distribution file a little
|
---|
3782 | smaller at the expense of possible inconvenience to a user who doesn't
|
---|
3783 | know what other files to get.
|
---|
3784 |
|
---|
3785 |
|
---|
3786 |
|
---|
3787 | Tag Table:
|
---|
3788 | Node: Top1010
|
---|
3789 | Node: Preface1554
|
---|
3790 | Node: Intellectual Property2582
|
---|
3791 | Node: Reading Non-Free Code2957
|
---|
3792 | Node: Contributions4689
|
---|
3793 | Node: Design Advice6683
|
---|
3794 | Node: Compatibility7200
|
---|
3795 | Node: Using Extensions8711
|
---|
3796 | Node: ANSI C10213
|
---|
3797 | Node: Source Language11449
|
---|
3798 | Node: Program Behavior12942
|
---|
3799 | Node: Semantics13651
|
---|
3800 | Node: Libraries17801
|
---|
3801 | Node: Errors19036
|
---|
3802 | Node: User Interfaces20259
|
---|
3803 | Node: Option Table27131
|
---|
3804 | Node: Memory Usage41686
|
---|
3805 | Node: Writing C42680
|
---|
3806 | Node: Formatting43519
|
---|
3807 | Node: Comments46791
|
---|
3808 | Node: Syntactic Conventions50089
|
---|
3809 | Node: Names53027
|
---|
3810 | Node: System Portability54763
|
---|
3811 | Node: CPU Portability56539
|
---|
3812 | Node: System Functions58700
|
---|
3813 | Node: Internationalization63804
|
---|
3814 | Node: Mmap66952
|
---|
3815 | Node: Documentation67657
|
---|
3816 | Node: GNU Manuals68215
|
---|
3817 | Node: Manual Structure Details72102
|
---|
3818 | Node: NEWS File73432
|
---|
3819 | Node: Change Logs74113
|
---|
3820 | Node: Change Log Concepts74830
|
---|
3821 | Node: Style of Change Logs76598
|
---|
3822 | Node: Simple Changes78152
|
---|
3823 | Node: Conditional Changes79343
|
---|
3824 | Node: Man Pages80720
|
---|
3825 | Node: Reading other Manuals82339
|
---|
3826 | Node: Managing Releases83123
|
---|
3827 | Node: Configuration83859
|
---|
3828 | Node: Makefile Conventions90799
|
---|
3829 | Node: Makefile Basics91479
|
---|
3830 | Node: Utilities in Makefiles94648
|
---|
3831 | Node: Command Variables96784
|
---|
3832 | Node: Directory Variables99812
|
---|
3833 | Node: Standard Targets110394
|
---|
3834 | Node: Install Command Categories120895
|
---|
3835 | Node: Releases125468
|
---|
3836 |
|
---|
3837 | End Tag Table
|
---|