home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / autoconf-2.10-bin.lha / info / standards.info (.txt) < prev   
GNU Info File  |  1996-10-12  |  107KB  |  2,442 lines

  1. This is Info file standards.info, produced by Makeinfo-1.64 from the
  2. input file /ade-src/fsf/autoconf/standards.texi.
  3. START-INFO-DIR-ENTRY
  4. * Standards: (standards).        GNU coding standards.
  5. END-INFO-DIR-ENTRY
  6.    GNU Coding Standards Copyright (C) 1992, 1993, 1994, 1995, 1996 Free
  7. Software Foundation, Inc.
  8.    Permission is granted to make and distribute verbatim copies of this
  9. manual provided the copyright notice and this permission notice are
  10. preserved on all copies.
  11.    Permission is granted to copy and distribute modified versions of
  12. this manual under the conditions for verbatim copying, provided that
  13. the entire resulting derived work is distributed under the terms of a
  14. permission notice identical to this one.
  15.    Permission is granted to copy and distribute translations of this
  16. manual into another language, under the above conditions for modified
  17. versions, except that this permission notice may be stated in a
  18. translation approved by the Free Software Foundation.
  19. File: standards.info,  Node: Top,  Next: Preface,  Prev: (dir),  Up: (dir)
  20. Version
  21. *******
  22.    Last updated 27 February 1996.
  23. * Menu:
  24. * Preface::            About the GNU Coding Standards
  25. * Intellectual Property::       Keeping Free Software Free
  26. * Design Advice::               General Program Design
  27. * Program Behavior::            Program Behavior for All Programs
  28. * Writing C::                   Making The Best Use of C
  29. * Documentation::        Documenting Programs
  30. * Managing Releases::           The Release Process
  31. File: standards.info,  Node: Preface,  Next: Intellectual Property,  Prev: Top,  Up: Top
  32. About the GNU Coding Standards
  33. ******************************
  34.    The GNU Coding Standards were written by Richard Stallman and other
  35. GNU Project volunteers.  Their purpose is to make the GNU system clean,
  36. consistent, and easy to install.  This document can also be read as a
  37. guide to writing portable, robust and reliable programs.  It focuses on
  38. programs written in C, but many of the rules and principles are useful
  39. even if you write in another programming language.  The rules often
  40. state reasons for writing in a certain way.
  41.    Corrections or suggestions regarding this document should be sent to
  42. `gnu@prep.ai.mit.edu'.  If you make a suggestion, please include a
  43. suggested new wording for it; our time is limited.  We prefer a context
  44. diff to the `standards.texi' or `make-stds.texi' files, but if you
  45. don't have those files, please mail your suggestion anyway.
  46.    This release of the GNU Coding Standards was last updated 27
  47. February 1996.
  48. File: standards.info,  Node: Intellectual Property,  Next: Design Advice,  Prev: Preface,  Up: Top
  49. Keeping Free Software Free
  50. **************************
  51.    This node discusses how you can make sure that GNU software remains
  52. unencumbered.
  53. * Menu:
  54. * Reading Non-Free Code::    Referring to Proprietary Programs
  55. * Contributions::        Accepting Contributions
  56. File: standards.info,  Node: Reading Non-Free Code,  Next: Contributions,  Up: Intellectual Property
  57. Referring to Proprietary Programs
  58. =================================
  59.    Don't in any circumstances refer to Unix source code for or during
  60. your work on GNU!  (Or to any other proprietary programs.)
  61.    If you have a vague recollection of the internals of a Unix program,
  62. this does not absolutely mean you can't write an imitation of it, but
  63. do try to organize the imitation internally along different lines,
  64. because this is likely to make the details of the Unix version
  65. irrelevant and dissimilar to your results.
  66.    For example, Unix utilities were generally optimized to minimize
  67. memory use; if you go for speed instead, your program will be very
  68. different.  You could keep the entire input file in core and scan it
  69. there instead of using stdio.  Use a smarter algorithm discovered more
  70. recently than the Unix program.  Eliminate use of temporary files.  Do
  71. it in one pass instead of two (we did this in the assembler).
  72.    Or, on the contrary, emphasize simplicity instead of speed.  For some
  73. applications, the speed of today's computers makes simpler algorithms
  74. adequate.
  75.    Or go for generality.  For example, Unix programs often have static
  76. tables or fixed-size strings, which make for arbitrary limits; use
  77. dynamic allocation instead.  Make sure your program handles NULs and
  78. other funny characters in the input files.  Add a programming language
  79. for extensibility and write part of the program in that language.
  80.    Or turn some parts of the program into independently usable
  81. libraries.  Or use a simple garbage collector instead of tracking
  82. precisely when to free memory, or use a new GNU facility such as
  83. obstacks.
  84. File: standards.info,  Node: Contributions,  Prev: Reading Non-Free Code,  Up: Intellectual Property
  85. Accepting Contributions
  86. =======================
  87.    If someone else sends you a piece of code to add to the program you
  88. are working on, we need legal papers to use it--the same sort of legal
  89. papers we will need to get from you.  *Each* significant contributor to
  90. a program must sign some sort of legal papers in order for us to have
  91. clear title to the program.  The main author alone is not enough.
  92.    So, before adding in any contributions from other people, tell us so
  93. we can arrange to get the papers.  Then wait until we tell you that we
  94. have received the signed papers, before you actually use the
  95. contribution.
  96.    This applies both before you release the program and afterward.  If
  97. you receive diffs to fix a bug, and they make significant changes, we
  98. need legal papers for it.
  99.    You don't need papers for changes of a few lines here or there, since
  100. they are not significant for copyright purposes.  Also, you don't need
  101. papers if all you get from the suggestion is some ideas, not actual code
  102. which you use.  For example, if you write a different solution to the
  103. problem, you don't need to get papers.
  104.    We know this is frustrating; it's frustrating for us as well.  But if
  105. you don't wait, you are going out on a limb--for example, what if the
  106. contributor's employer won't sign a disclaimer?  You might have to take
  107. that code out again!
  108.    The very worst thing is if you forget to tell us about the other
  109. contributor.  We could be very embarrassed in court some day as a
  110. result.
  111. File: standards.info,  Node: Design Advice,  Next: Program Behavior,  Prev: Intellectual Property,  Up: Top
  112. General Program Design
  113. **********************
  114.    This node discusses some of the issues you should take into account
  115. when designing your program.
  116. * Menu:
  117. * Compatibility::        Compatibility with other implementations
  118. * Using Extensions::        Using non-standard features
  119. * ANSI C::                      Using ANSI C features
  120. * Source Language::        Using languages other than C
  121. File: standards.info,  Node: Compatibility,  Next: Using Extensions,  Up: Design Advice
  122. Compatibility with Other Implementations
  123. ========================================
  124.    With occasional exceptions, utility programs and libraries for GNU
  125. should be upward compatible with those in Berkeley Unix, and upward
  126. compatible with ANSI C if ANSI C specifies their behavior, and upward
  127. compatible with POSIX if POSIX specifies their behavior.
  128.    When these standards conflict, it is useful to offer compatibility
  129. modes for each of them.
  130.    ANSI C and POSIX prohibit many kinds of extensions.  Feel free to
  131. make the extensions anyway, and include a `--ansi', `--posix', or
  132. `--compatible' option to turn them off.  However, if the extension has
  133. a significant chance of breaking any real programs or scripts, then it
  134. is not really upward compatible.  Try to redesign its interface.
  135.    Many GNU programs suppress extensions that conflict with POSIX if the
  136. environment variable `POSIXLY_CORRECT' is defined (even if it is
  137. defined with a null value).  Please make your program recognize this
  138. variable if appropriate.
  139.    When a feature is used only by users (not by programs or command
  140. files), and it is done poorly in Unix, feel free to replace it
  141. completely with something totally different and better.  (For example,
  142. `vi' is replaced with Emacs.)  But it is nice to offer a compatible
  143. feature as well.  (There is a free `vi' clone, so we offer it.)
  144.    Additional useful features not in Berkeley Unix are welcome.
  145. Additional programs with no counterpart in Unix may be useful, but our
  146. first priority is usually to duplicate what Unix already has.
  147. File: standards.info,  Node: Using Extensions,  Next: ANSI C,  Prev: Compatibility,  Up: Design Advice
  148. Using Non-standard Features
  149. ===========================
  150.    Many GNU facilities that already exist support a number of convenient
  151. extensions over the comparable Unix facilities.  Whether to use these
  152. extensions in implementing your program is a difficult question.
  153.    On the one hand, using the extensions can make a cleaner program.
  154. On the other hand, people will not be able to build the program unless
  155. the other GNU tools are available.  This might cause the program to
  156. work on fewer kinds of machines.
  157.    With some extensions, it might be easy to provide both alternatives.
  158. For example, you can define functions with a "keyword" `INLINE' and
  159. define that as a macro to expand into either `inline' or nothing,
  160. depending on the compiler.
  161.    In general, perhaps it is best not to use the extensions if you can
  162. straightforwardly do without them, but to use the extensions if they
  163. are a big improvement.
  164.    An exception to this rule are the large, established programs (such
  165. as Emacs) which run on a great variety of systems.  Such programs would
  166. be broken by use of GNU extensions.
  167.    Another exception is for programs that are used as part of
  168. compilation: anything that must be compiled with other compilers in
  169. order to bootstrap the GNU compilation facilities.  If these require
  170. the GNU compiler, then no one can compile them without having them
  171. installed already.  That would be no good.
  172. File: standards.info,  Node: ANSI C,  Next: Source Language,  Prev: Using Extensions,  Up: Design Advice
  173. ANSI C and pre-ANSI C
  174. =====================
  175.    Do not ever use the "trigraph" feature of ANSI C.
  176.    ANSI C is widespread enough now that it is ok to write new programs
  177. that use ANSI C features (and therefore will not work in non-ANSI
  178. compilers).  And if a program is already written in ANSI C, there's no
  179. need to convert it to support non-ANSI compilers.
  180.    However, it is easy to support non-ANSI compilers in most programs,
  181. so you might still consider doing so when you write a program.  Instead
  182. of writing function definitions in ANSI prototype form,
  183.      int
  184.      foo (int x, int y)
  185.      ...
  186. write the definition in pre-ANSI style like this,
  187.      int
  188.      foo (x, y)
  189.           int x, y;
  190.      ...
  191. and use a separate declaration to specify the argument prototype:
  192.      int foo (int, int);
  193.    You need such a declaration anyway, in a header file, to get the
  194. benefit of ANSI C prototypes in all the files where the function is
  195. called.  And once you have it, you lose nothing by writing the function
  196. definition in the pre-ANSI style.
  197.    If you don't know non-ANSI C, there's no need to learn it; just
  198. write in ANSI C.
  199. File: standards.info,  Node: Source Language,  Prev: ANSI C,  Up: Design Advice
  200. Using Languages Other Than C
  201. ============================
  202.    Using a language other than C is like using a non-standard feature:
  203. it will cause trouble for users.  Even if GCC supports the other
  204. language, users may find it inconvenient to have to install the
  205. compiler for that other language in order to build your program.  So
  206. please write in C.
  207.    There are three exceptions for this rule:
  208.    * It is okay to use a special language if the same program contains
  209.      an interpreter for that language.
  210.      For example, if your program links with GUILE, it is ok to write
  211.      part of the program in Scheme or another language supported by
  212.      GUILE.
  213.    * It is okay to use another language in a tool specifically intended
  214.      for use with that language.
  215.      This is okay because the only people who want to build the tool
  216.      will be those who have installed the other language anyway.
  217.    * If an application is not of extremely widespread interest, then
  218.      perhaps it's not important if the application is inconvenient to
  219.      install.
  220. File: standards.info,  Node: Program Behavior,  Next: Writing C,  Prev: Design Advice,  Up: Top
  221. Program Behavior for All Programs
  222. *********************************
  223.    This node describes how to write robust software. It also describes
  224. general standards for error messages, the command line interface, and
  225. how libraries should behave.
  226. * Menu:
  227. * Semantics::            Writing robust programs
  228. * Libraries::            Library behavior
  229. * Errors::            Formatting error messages
  230. * User Interfaces::        Standards for command line interfaces
  231. * Memory Usage::                When and how to care about memory needs
  232. File: standards.info,  Node: Semantics,  Next: Libraries,  Up: Program Behavior
  233. Writing Robust Programs
  234. =======================
  235.    Avoid arbitrary limits on the length or number of *any* data
  236. structure, including file names, lines, files, and symbols, by
  237. allocating all data structures dynamically.  In most Unix utilities,
  238. "long lines are silently truncated".  This is not acceptable in a GNU
  239. utility.
  240.    Utilities reading files should not drop NUL characters, or any other
  241. nonprinting characters *including those with codes above 0177*.  The
  242. only sensible exceptions would be utilities specifically intended for
  243. interface to certain types of printers that can't handle those
  244. characters.
  245.    Check every system call for an error return, unless you know you
  246. wish to ignore errors.  Include the system error text (from `perror' or
  247. equivalent) in *every* error message resulting from a failing system
  248. call, as well as the name of the file if any and the name of the
  249. utility.  Just "cannot open foo.c" or "stat failed" is not sufficient.
  250.    Check every call to `malloc' or `realloc' to see if it returned
  251. zero.  Check `realloc' even if you are making the block smaller; in a
  252. system that rounds block sizes to a power of 2, `realloc' may get a
  253. different block if you ask for less space.
  254.    In Unix, `realloc' can destroy the storage block if it returns zero.
  255. GNU `realloc' does not have this bug: if it fails, the original block
  256. is unchanged.  Feel free to assume the bug is fixed.  If you wish to
  257. run your program on Unix, and wish to avoid lossage in this case, you
  258. can use the GNU `malloc'.
  259.    You must expect `free' to alter the contents of the block that was
  260. freed.  Anything you want to fetch from the block, you must fetch before
  261. calling `free'.
  262.    If `malloc' fails in a noninteractive program, make that a fatal
  263. error.  In an interactive program (one that reads commands from the
  264. user), it is better to abort the command and return to the command
  265. reader loop.  This allows the user to kill other processes to free up
  266. virtual memory, and then try the command again.
  267.    Use `getopt_long' to decode arguments, unless the argument syntax
  268. makes this unreasonable.
  269.    When static storage is to be written in during program execution, use
  270. explicit C code to initialize it.  Reserve C initialized declarations
  271. for data that will not be changed.
  272.    Try to avoid low-level interfaces to obscure Unix data structures
  273. (such as file directories, utmp, or the layout of kernel memory), since
  274. these are less likely to work compatibly.  If you need to find all the
  275. files in a directory, use `readdir' or some other high-level interface.
  276. These will be supported compatibly by GNU.
  277.    By default, the GNU system will provide the signal handling
  278. functions of BSD and of POSIX.  So GNU software should be written to use
  279. these.
  280.    In error checks that detect "impossible" conditions, just abort.
  281. There is usually no point in printing any message.  These checks
  282. indicate the existence of bugs.  Whoever wants to fix the bugs will have
  283. to read the source code and run a debugger.  So explain the problem with
  284. comments in the source.  The relevant data will be in variables, which
  285. are easy to examine with the debugger, so there is no point moving them
  286. elsewhere.
  287.    Do not use a count of errors as the exit status for a program.
  288. *That does not work*, because exit status values are limited to 8 bits
  289. (0 through 255).  A single run of the program might have 256 errors; if
  290. you try to return 256 as the exit status, the parent process will see 0
  291. as the status, and it will appear that the program succeeded.
  292.    If you make temporary files, check the `TMPDIR' environment
  293. variable; if that variable is defined, use the specified directory
  294. instead of `/tmp'.
  295. File: standards.info,  Node: Libraries,  Next: Errors,  Prev: Semantics,  Up: Program Behavior
  296. Library Behavior
  297. ================
  298.    Try to make library functions reentrant.  If they need to do dynamic
  299. storage allocation, at least try to avoid any nonreentrancy aside from
  300. that of `malloc' itself.
  301.    Here are certain name conventions for libraries, to avoid name
  302. conflicts.
  303.    Choose a name prefix for the library, more than two characters long.
  304. All external function and variable names should start with this prefix.
  305. In addition, there should only be one of these in any given library
  306. member.  This usually means putting each one in a separate source file.
  307.    An exception can be made when two external symbols are always used
  308. together, so that no reasonable program could use one without the
  309. other; then they can both go in the same file.
  310.    External symbols that are not documented entry points for the user
  311. should have names beginning with `_'.  They should also contain the
  312. chosen name prefix for the library, to prevent collisions with other
  313. libraries.  These can go in the same files with user entry points if
  314. you like.
  315.    Static functions and variables can be used as you like and need not
  316. fit any naming convention.
  317. File: standards.info,  Node: Errors,  Next: User Interfaces,  Prev: Libraries,  Up: Program Behavior
  318. Formatting Error Messages
  319. =========================
  320.    Error messages from compilers should look like this:
  321.      SOURCE-FILE-NAME:LINENO: MESSAGE
  322.    Error messages from other noninteractive programs should look like
  323. this:
  324.      PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
  325. when there is an appropriate source file, or like this:
  326.      PROGRAM: MESSAGE
  327. when there is no relevant source file.
  328.    In an interactive program (one that is reading commands from a
  329. terminal), it is better not to include the program name in an error
  330. message.  The place to indicate which program is running is in the
  331. prompt or with the screen layout.  (When the same program runs with
  332. input from a source other than a terminal, it is not interactive and
  333. would do best to print error messages using the noninteractive style.)
  334.    The string MESSAGE should not begin with a capital letter when it
  335. follows a program name and/or file name.  Also, it should not end with
  336. a period.
  337.    Error messages from interactive programs, and other messages such as
  338. usage messages, should start with a capital letter.  But they should not
  339. end with a period.
  340. File: standards.info,  Node: User Interfaces,  Next: Memory Usage,  Prev: Errors,  Up: Program Behavior
  341. Standards for Command Line Interfaces
  342. =====================================
  343.    Please don't make the behavior of a utility depend on the name used
  344. to invoke it.  It is useful sometimes to make a link to a utility with
  345. a different name, and that should not change what it does.
  346.    Instead, use a run time option or a compilation switch or both to
  347. select among the alternate behaviors.
  348.    Likewise, please don't make the behavior of the program depend on the
  349. type of output device it is used with.  Device independence is an
  350. important principle of the system's design; do not compromise it merely
  351. to save someone from typing an option now and then.
  352.    If you think one behavior is most useful when the output is to a
  353. terminal, and another is most useful when the output is a file or a
  354. pipe, then it is usually best to make the default behavior the one that
  355. is useful with output to a terminal, and have an option for the other
  356. behavior.
  357.    Compatibility requires certain programs to depend on the type of
  358. output device.  It would be disastrous if `ls' or `sh' did not do so in
  359. the way all users expect.  In some of these cases, we supplement the
  360. program with a preferred alternate version that does not depend on the
  361. output device type.  For example, we provide a `dir' program much like
  362. `ls' except that its default output format is always multi-column
  363. format.
  364.    It is a good idea to follow the POSIX guidelines for the
  365. command-line options of a program.  The easiest way to do this is to use
  366. `getopt' to parse them.  Note that the GNU version of `getopt' will
  367. normally permit options anywhere among the arguments unless the special
  368. argument `--' is used.  This is not what POSIX specifies; it is a GNU
  369. extension.
  370.    Please define long-named options that are equivalent to the
  371. single-letter Unix-style options.  We hope to make GNU more user
  372. friendly this way.  This is easy to do with the GNU function
  373. `getopt_long'.
  374.    One of the advantages of long-named options is that they can be
  375. consistent from program to program.  For example, users should be able
  376. to expect the "verbose" option of any GNU program which has one, to be
  377. spelled precisely `--verbose'.  To achieve this uniformity, look at the
  378. table of common long-option names when you choose the option names for
  379. your program.  The table appears below.
  380.    If you use names not already in the table, please send
  381. `gnu@prep.ai.mit.edu' a list of them, with their meanings, so we can
  382. update the table.
  383.    It is usually a good idea for file names given as ordinary arguments
  384. to be input files only; any output files would be specified using
  385. options (preferably `-o').  Even if you allow an output file name as an
  386. ordinary argument for compatibility, try to provide a suitable option
  387. as well.  This will lead to more consistency among GNU utilities, so
  388. that there are fewer idiosyncracies for users to remember.
  389.    Programs should support an option `--version' which prints the
  390. program's version number on standard output and exits successfully, and
  391. an option `--help' which prints option usage information on standard
  392. output and exits successfully.  These options should inhibit the normal
  393. function of the command; they should do nothing except print the
  394. requested information.
  395.    Here is the table of long options used by GNU programs.
  396. `after-date'
  397.      `-N' in `tar'.
  398. `all'
  399.      `-a' in `du', `ls', `nm', `stty', `uname', and `unexpand'.
  400. `all-text'
  401.      `-a' in `diff'.
  402. `almost-all'
  403.      `-A' in `ls'.
  404. `append'
  405.      `-a' in `etags', `tee', `time'; `-r' in `tar'.
  406. `archive'
  407.      `-a' in `cp'.
  408. `archive-name'
  409.      `-n' in `shar'.
  410. `arglength'
  411.      `-l' in `m4'.
  412. `ascii'
  413.      `-a' in `diff'.
  414. `assign'
  415.      `-v' in `gawk'.
  416. `assume-new'
  417.      `-W' in Make.
  418. `assume-old'
  419.      `-o' in Make.
  420. `auto-check'
  421.      `-a' in `recode'.
  422. `auto-pager'
  423.      `-a' in `wdiff'.
  424. `auto-reference'
  425.      `-A' in `ptx'.
  426. `avoid-wraps'
  427.      `-n' in `wdiff'.
  428. `backward-search'
  429.      `-B' in `ctags'.
  430. `basename'
  431.      `-f' in `shar'.
  432. `batch'
  433.      Used in GDB.
  434. `baud'
  435.      Used in GDB.
  436. `before'
  437.      `-b' in `tac'.
  438. `binary'
  439.      `-b' in `cpio' and `diff'.
  440. `bits-per-code'
  441.      `-b' in `shar'.
  442. `block-size'
  443.      Used in `cpio' and `tar'.
  444. `blocks'
  445.      `-b' in `head' and `tail'.
  446. `break-file'
  447.      `-b' in `ptx'.
  448. `brief'
  449.      Used in various programs to make output shorter.
  450. `bytes'
  451.      `-c' in `head', `split', and `tail'.
  452. `c++'
  453.      `-C' in `etags'.
  454. `catenate'
  455.      `-A' in `tar'.
  456.      Used in various programs to specify the directory to use.
  457. `changes'
  458.      `-c' in `chgrp' and `chown'.
  459. `classify'
  460.      `-F' in `ls'.
  461. `colons'
  462.      `-c' in `recode'.
  463. `command'
  464.      `-c' in `su'; `-x' in GDB.
  465. `compare'
  466.      `-d' in `tar'.
  467. `compat'
  468.      Used in `gawk'.
  469. `compress'
  470.      `-Z' in `tar' and `shar'.
  471. `concatenate'
  472.      `-A' in `tar'.
  473. `confirmation'
  474.      `-w' in `tar'.
  475. `context'
  476.      Used in `diff'.
  477. `copyleft'
  478.      `-W copyleft' in `gawk'.
  479. `copyright'
  480.      `-C' in `ptx', `recode', and `wdiff'; `-W copyright' in `gawk'.
  481. `core'
  482.      Used in GDB.
  483. `count'
  484.      `-q' in `who'.
  485. `count-links'
  486.      `-l' in `du'.
  487. `create'
  488.      Used in `tar' and `cpio'.
  489. `cut-mark'
  490.      `-c' in `shar'.
  491. `cxref'
  492.      `-x' in `ctags'.
  493. `date'
  494.      `-d' in `touch'.
  495. `debug'
  496.      `-d' in Make and `m4'; `-t' in Bison.
  497. `define'
  498.      `-D' in `m4'.
  499. `defines'
  500.      `-d' in Bison and `ctags'.
  501. `delete'
  502.      `-D' in `tar'.
  503. `dereference'
  504.      `-L' in `chgrp', `chown', `cpio', `du', `ls', and `tar'.
  505. `dereference-args'
  506.      `-D' in `du'.
  507. `diacritics'
  508.      `-d' in `recode'.
  509. `dictionary-order'
  510.      `-d' in `look'.
  511. `diff'
  512.      `-d' in `tar'.
  513. `digits'
  514.      `-n' in `csplit'.
  515. `directory'
  516.      Specify the directory to use, in various programs.  In `ls', it
  517.      means to show directories themselves rather than their contents.
  518.      In `rm' and `ln', it means to not treat links to directories
  519.      specially.
  520. `discard-all'
  521.      `-x' in `strip'.
  522. `discard-locals'
  523.      `-X' in `strip'.
  524. `dry-run'
  525.      `-n' in Make.
  526.      `-e' in `diff'.
  527. `elide-empty-files'
  528.      `-z' in `csplit'.
  529. `end-delete'
  530.      `-x' in `wdiff'.
  531. `end-insert'
  532.      `-z' in `wdiff'.
  533. `entire-new-file'
  534.      `-N' in `diff'.
  535. `environment-overrides'
  536.      `-e' in Make.
  537. `eof'
  538.      `-e' in `xargs'.
  539. `epoch'
  540.      Used in GDB.
  541. `error-limit'
  542.      Used in `makeinfo'.
  543. `error-output'
  544.      `-o' in `m4'.
  545. `escape'
  546.      `-b' in `ls'.
  547. `exclude-from'
  548.      `-X' in `tar'.
  549. `exec'
  550.      Used in GDB.
  551. `exit'
  552.      `-x' in `xargs'.
  553. `exit-0'
  554.      `-e' in `unshar'.
  555. `expand-tabs'
  556.      `-t' in `diff'.
  557. `expression'
  558.      `-e' in `sed'.
  559. `extern-only'
  560.      `-g' in `nm'.
  561. `extract'
  562.      `-i' in `cpio'; `-x' in `tar'.
  563. `faces'
  564.      `-f' in `finger'.
  565. `fast'
  566.      `-f' in `su'.
  567. `fatal-warnings'
  568.      `-E' in `m4'.
  569. `file'
  570.      `-f' in `info', `gawk', Make, `mt', and `tar'; `-n' in `sed'; `-r'
  571.      in `touch'.
  572. `field-separator'
  573.      `-F' in `gawk'.
  574. `file-prefix'
  575.      `-b' in Bison.
  576. `file-type'
  577.      `-F' in `ls'.
  578. `files-from'
  579.      `-T' in `tar'.
  580. `fill-column'
  581.      Used in `makeinfo'.
  582. `flag-truncation'
  583.      `-F' in `ptx'.
  584. `fixed-output-files'
  585.      `-y' in Bison.
  586. `follow'
  587.      `-f' in `tail'.
  588. `footnote-style'
  589.      Used in `makeinfo'.
  590. `force'
  591.      `-f' in `cp', `ln', `mv', and `rm'.
  592. `force-prefix'
  593.      `-F' in `shar'.
  594. `format'
  595.      Used in `ls', `time', and `ptx'.
  596. `freeze-state'
  597.      `-F' in `m4'.
  598. `fullname'
  599.      Used in GDB.
  600. `gap-size'
  601.      `-g' in `ptx'.
  602. `get'
  603.      `-x' in `tar'.
  604. `graphic'
  605.      `-i' in `ul'.
  606. `graphics'
  607.      `-g' in `recode'.
  608. `group'
  609.      `-g' in `install'.
  610. `gzip'
  611.      `-z' in `tar' and `shar'.
  612. `hashsize'
  613.      `-H' in `m4'.
  614. `header'
  615.      `-h' in `objdump' and `recode'
  616. `heading'
  617.      `-H' in `who'.
  618. `help'
  619.      Used to ask for brief usage information.
  620. `here-delimiter'
  621.      `-d' in `shar'.
  622. `hide-control-chars'
  623.      `-q' in `ls'.
  624. `idle'
  625.      `-u' in `who'.
  626. `ifdef'
  627.      `-D' in `diff'.
  628. `ignore'
  629.      `-I' in `ls'; `-x' in `recode'.
  630. `ignore-all-space'
  631.      `-w' in `diff'.
  632. `ignore-backups'
  633.      `-B' in `ls'.
  634. `ignore-blank-lines'
  635.      `-B' in `diff'.
  636. `ignore-case'
  637.      `-f' in `look' and `ptx'; `-i' in `diff' and `wdiff'.
  638. `ignore-errors'
  639.      `-i' in Make.
  640. `ignore-file'
  641.      `-i' in `ptx'.
  642. `ignore-indentation'
  643.      `-I' in `etags'.
  644. `ignore-init-file'
  645.      `-f' in Oleo.
  646. `ignore-interrupts'
  647.      `-i' in `tee'.
  648. `ignore-matching-lines'
  649.      `-I' in `diff'.
  650. `ignore-space-change'
  651.      `-b' in `diff'.
  652. `ignore-zeros'
  653.      `-i' in `tar'.
  654. `include'
  655.      `-i' in `etags'; `-I' in `m4'.
  656. `include-dir'
  657.      `-I' in Make.
  658. `incremental'
  659.      `-G' in `tar'.
  660. `info'
  661.      `-i', `-l', and `-m' in Finger.
  662. `initial'
  663.      `-i' in `expand'.
  664. `initial-tab'
  665.      `-T' in `diff'.
  666. `inode'
  667.      `-i' in `ls'.
  668. `interactive'
  669.      `-i' in `cp', `ln', `mv', `rm'; `-e' in `m4'; `-p' in `xargs';
  670.      `-w' in `tar'.
  671. `intermix-type'
  672.      `-p' in `shar'.
  673. `jobs'
  674.      `-j' in Make.
  675. `just-print'
  676.      `-n' in Make.
  677. `keep-going'
  678.      `-k' in Make.
  679. `keep-files'
  680.      `-k' in `csplit'.
  681. `kilobytes'
  682.      `-k' in `du' and `ls'.
  683. `language'
  684.      `-l' in `etags'.
  685. `less-mode'
  686.      `-l' in `wdiff'.
  687. `level-for-gzip'
  688.      `-g' in `shar'.
  689. `line-bytes'
  690.      `-C' in `split'.
  691. `lines'
  692.      Used in `split', `head', and `tail'.
  693. `link'
  694.      `-l' in `cpio'.
  695. `lint'
  696. `lint-old'
  697.      Used in `gawk'.
  698. `list'
  699.      `-t' in `cpio'; `-l' in `recode'.
  700. `list'
  701.      `-t' in `tar'.
  702. `literal'
  703.      `-N' in `ls'.
  704. `load-average'
  705.      `-l' in Make.
  706. `login'
  707.      Used in `su'.
  708. `machine'
  709.      No listing of which programs already use this; someone should
  710.      check to see if any actually do and tell `gnu@prep.ai.mit.edu'.
  711. `macro-name'
  712.      `-M' in `ptx'.
  713. `mail'
  714.      `-m' in `hello' and `uname'.
  715. `make-directories'
  716.      `-d' in `cpio'.
  717. `makefile'
  718.      `-f' in Make.
  719. `mapped'
  720.      Used in GDB.
  721. `max-args'
  722.      `-n' in `xargs'.
  723. `max-chars'
  724.      `-n' in `xargs'.
  725. `max-lines'
  726.      `-l' in `xargs'.
  727. `max-load'
  728.      `-l' in Make.
  729. `max-procs'
  730.      `-P' in `xargs'.
  731. `mesg'
  732.      `-T' in `who'.
  733. `message'
  734.      `-T' in `who'.
  735. `minimal'
  736.      `-d' in `diff'.
  737. `mixed-uuencode'
  738.      `-M' in `shar'.
  739. `mode'
  740.      `-m' in `install', `mkdir', and `mkfifo'.
  741. `modification-time'
  742.      `-m' in `tar'.
  743. `multi-volume'
  744.      `-M' in `tar'.
  745. `name-prefix'
  746.      `-a' in Bison.
  747. `nesting-limit'
  748.      `-L' in `m4'.
  749. `net-headers'
  750.      `-a' in `shar'.
  751. `new-file'
  752.      `-W' in Make.
  753. `no-builtin-rules'
  754.      `-r' in Make.
  755. `no-character-count'
  756.      `-w' in `shar'.
  757. `no-check-existing'
  758.      `-x' in `shar'.
  759. `no-common'
  760.      `-3' in `wdiff'.
  761. `no-create'
  762.      `-c' in `touch'.
  763. `no-defines'
  764.      `-D' in `etags'.
  765. `no-deleted'
  766.      `-1' in `wdiff'.
  767. `no-dereference'
  768.      `-d' in `cp'.
  769. `no-inserted'
  770.      `-2' in `wdiff'.
  771. `no-keep-going'
  772.      `-S' in Make.
  773. `no-lines'
  774.      `-l' in Bison.
  775. `no-piping'
  776.      `-P' in `shar'.
  777. `no-prof'
  778.      `-e' in `gprof'.
  779. `no-regex'
  780.      `-R' in `etags'.
  781. `no-sort'
  782.      `-p' in `nm'.
  783. `no-split'
  784.      Used in `makeinfo'.
  785. `no-static'
  786.      `-a' in `gprof'.
  787. `no-time'
  788.      `-E' in `gprof'.
  789. `no-timestamp'
  790.      `-m' in `shar'.
  791. `no-validate'
  792.      Used in `makeinfo'.
  793. `no-warn'
  794.      Used in various programs to inhibit warnings.
  795. `node'
  796.      `-n' in `info'.
  797. `nodename'
  798.      `-n' in `uname'.
  799. `nonmatching'
  800.      `-f' in `cpio'.
  801. `nstuff'
  802.      `-n' in `objdump'.
  803. `null'
  804.      `-0' in `xargs'.
  805. `number'
  806.      `-n' in `cat'.
  807. `number-nonblank'
  808.      `-b' in `cat'.
  809. `numeric-sort'
  810.      `-n' in `nm'.
  811. `numeric-uid-gid'
  812.      `-n' in `cpio' and `ls'.
  813.      Used in GDB.
  814. `old-archive'
  815.      `-o' in `tar'.
  816. `old-file'
  817.      `-o' in Make.
  818. `one-file-system'
  819.      `-l' in `tar', `cp', and `du'.
  820. `only-file'
  821.      `-o' in `ptx'.
  822. `only-prof'
  823.      `-f' in `gprof'.
  824. `only-time'
  825.      `-F' in `gprof'.
  826. `output'
  827.      In various programs, specify the output file name.
  828. `output-prefix'
  829.      `-o' in `shar'.
  830. `override'
  831.      `-o' in `rm'.
  832. `overwrite'
  833.      `-c' in `unshar'.
  834. `owner'
  835.      `-o' in `install'.
  836. `paginate'
  837.      `-l' in `diff'.
  838. `paragraph-indent'
  839.      Used in `makeinfo'.
  840. `parents'
  841.      `-p' in `mkdir' and `rmdir'.
  842. `pass-all'
  843.      `-p' in `ul'.
  844. `pass-through'
  845.      `-p' in `cpio'.
  846. `port'
  847.      `-P' in `finger'.
  848. `portability'
  849.      `-c' in `cpio' and `tar'.
  850. `posix'
  851.      Used in `gawk'.
  852. `prefix-builtins'
  853.      `-P' in `m4'.
  854. `prefix'
  855.      `-f' in `csplit'.
  856. `preserve'
  857.      Used in `tar' and `cp'.
  858. `preserve-environment'
  859.      `-p' in `su'.
  860. `preserve-modification-time'
  861.      `-m' in `cpio'.
  862. `preserve-order'
  863.      `-s' in `tar'.
  864. `preserve-permissions'
  865.      `-p' in `tar'.
  866. `print'
  867.      `-l' in `diff'.
  868. `print-chars'
  869.      `-L' in `cmp'.
  870. `print-data-base'
  871.      `-p' in Make.
  872. `print-directory'
  873.      `-w' in Make.
  874. `print-file-name'
  875.      `-o' in `nm'.
  876. `print-symdefs'
  877.      `-s' in `nm'.
  878. `printer'
  879.      `-p' in `wdiff'.
  880. `prompt'
  881.      `-p' in `ed'.
  882. `query-user'
  883.      `-X' in `shar'.
  884. `question'
  885.      `-q' in Make.
  886. `quiet'
  887.      Used in many programs to inhibit the usual output.  *Note:* every
  888.      program accepting `--quiet' should accept `--silent' as a synonym.
  889. `quiet-unshar'
  890.      `-Q' in `shar'
  891. `quote-name'
  892.      `-Q' in `ls'.
  893. `rcs'
  894.      `-n' in `diff'.
  895. `re-interval'
  896.      Used in `gawk'.
  897. `read-full-blocks'
  898.      `-B' in `tar'.
  899. `readnow'
  900.      Used in GDB.
  901. `recon'
  902.      `-n' in Make.
  903. `record-number'
  904.      `-R' in `tar'.
  905. `recursive'
  906.      Used in `chgrp', `chown', `cp', `ls', `diff', and `rm'.
  907. `reference-limit'
  908.      Used in `makeinfo'.
  909. `references'
  910.      `-r' in `ptx'.
  911. `regex'
  912.      `-r' in `tac' and `etags'.
  913. `release'
  914.      `-r' in `uname'.
  915. `reload-state'
  916.      `-R' in `m4'.
  917. `relocation'
  918.      `-r' in `objdump'.
  919. `rename'
  920.      `-r' in `cpio'.
  921. `replace'
  922.      `-i' in `xargs'.
  923. `report-identical-files'
  924.      `-s' in `diff'.
  925. `reset-access-time'
  926.      `-a' in `cpio'.
  927. `reverse'
  928.      `-r' in `ls' and `nm'.
  929. `reversed-ed'
  930.      `-f' in `diff'.
  931. `right-side-defs'
  932.      `-R' in `ptx'.
  933. `same-order'
  934.      `-s' in `tar'.
  935. `same-permissions'
  936.      `-p' in `tar'.
  937. `save'
  938.      `-g' in `stty'.
  939.      Used in GDB.
  940. `sentence-regexp'
  941.      `-S' in `ptx'.
  942. `separate-dirs'
  943.      `-S' in `du'.
  944. `separator'
  945.      `-s' in `tac'.
  946. `sequence'
  947.      Used by `recode' to chose files or pipes for sequencing passes.
  948. `shell'
  949.      `-s' in `su'.
  950. `show-all'
  951.      `-A' in `cat'.
  952. `show-c-function'
  953.      `-p' in `diff'.
  954. `show-ends'
  955.      `-E' in `cat'.
  956. `show-function-line'
  957.      `-F' in `diff'.
  958. `show-tabs'
  959.      `-T' in `cat'.
  960. `silent'
  961.      Used in many programs to inhibit the usual output.  *Note:* every
  962.      program accepting `--silent' should accept `--quiet' as a synonym.
  963. `size'
  964.      `-s' in `ls'.
  965. `sort'
  966.      Used in `ls'.
  967. `source'
  968.      `-W source' in `gawk'.
  969. `sparse'
  970.      `-S' in `tar'.
  971. `speed-large-files'
  972.      `-H' in `diff'.
  973. `split-at'
  974.      `-E' in `unshar'.
  975. `split-size-limit'
  976.      `-L' in `shar'.
  977. `squeeze-blank'
  978.      `-s' in `cat'.
  979. `start-delete'
  980.      `-w' in `wdiff'.
  981. `start-insert'
  982.      `-y' in `wdiff'.
  983. `starting-file'
  984.      Used in `tar' and `diff' to specify which file within a directory
  985.      to start processing with.
  986. `statistics'
  987.      `-s' in `wdiff'.
  988. `stdin-file-list'
  989.      `-S' in `shar'.
  990. `stop'
  991.      `-S' in Make.
  992. `strict'
  993.      `-s' in `recode'.
  994. `strip'
  995.      `-s' in `install'.
  996. `strip-all'
  997.      `-s' in `strip'.
  998. `strip-debug'
  999.      `-S' in `strip'.
  1000. `submitter'
  1001.      `-s' in `shar'.
  1002. `suffix'
  1003.      `-S' in `cp', `ln', `mv'.
  1004. `suffix-format'
  1005.      `-b' in `csplit'.
  1006. `sum'
  1007.      `-s' in `gprof'.
  1008. `summarize'
  1009.      `-s' in `du'.
  1010. `symbolic'
  1011.      `-s' in `ln'.
  1012. `symbols'
  1013.      Used in GDB and `objdump'.
  1014. `synclines'
  1015.      `-s' in `m4'.
  1016. `sysname'
  1017.      `-s' in `uname'.
  1018. `tabs'
  1019.      `-t' in `expand' and `unexpand'.
  1020. `tabsize'
  1021.      `-T' in `ls'.
  1022. `terminal'
  1023.      `-T' in `tput' and `ul'.  `-t' in `wdiff'.
  1024. `text'
  1025.      `-a' in `diff'.
  1026. `text-files'
  1027.      `-T' in `shar'.
  1028. `time'
  1029.      Used in `ls' and `touch'.
  1030. `to-stdout'
  1031.      `-O' in `tar'.
  1032. `total'
  1033.      `-c' in `du'.
  1034. `touch'
  1035.      `-t' in Make, `ranlib', and `recode'.
  1036. `trace'
  1037.      `-t' in `m4'.
  1038. `traditional'
  1039.      `-t' in `hello'; `-W traditional' in `gawk'; `-G' in `ed', `m4',
  1040.      and `ptx'.
  1041. `tty'
  1042.      Used in GDB.
  1043. `typedefs'
  1044.      `-t' in `ctags'.
  1045. `typedefs-and-c++'
  1046.      `-T' in `ctags'.
  1047. `typeset-mode'
  1048.      `-t' in `ptx'.
  1049. `uncompress'
  1050.      `-z' in `tar'.
  1051. `unconditional'
  1052.      `-u' in `cpio'.
  1053. `undefine'
  1054.      `-U' in `m4'.
  1055. `undefined-only'
  1056.      `-u' in `nm'.
  1057. `update'
  1058.      `-u' in `cp', `ctags', `mv', `tar'.
  1059. `usage'
  1060.      Used in `gawk'; same as `--help'.
  1061. `uuencode'
  1062.      `-B' in `shar'.
  1063. `vanilla-operation'
  1064.      `-V' in `shar'.
  1065. `verbose'
  1066.      Print more information about progress.  Many programs support this.
  1067. `verify'
  1068.      `-W' in `tar'.
  1069. `version'
  1070.      Print the version number.
  1071. `version-control'
  1072.      `-V' in `cp', `ln', `mv'.
  1073. `vgrind'
  1074.      `-v' in `ctags'.
  1075. `volume'
  1076.      `-V' in `tar'.
  1077. `what-if'
  1078.      `-W' in Make.
  1079. `whole-size-limit'
  1080.      `-l' in `shar'.
  1081. `width'
  1082.      `-w' in `ls' and `ptx'.
  1083. `word-regexp'
  1084.      `-W' in `ptx'.
  1085. `writable'
  1086.      `-T' in `who'.
  1087. `zeros'
  1088.      `-z' in `gprof'.
  1089. File: standards.info,  Node: Memory Usage,  Prev: User Interfaces,  Up: Program Behavior
  1090. Memory Usage
  1091. ============
  1092.    If it typically uses just a few meg of memory, don't bother making
  1093. any effort to reduce memory usage.  For example, if it is impractical
  1094. for other reasons to operate on files more than a few meg long, it is
  1095. reasonable to read entire input files into core to operate on them.
  1096.    However, for programs such as `cat' or `tail', that can usefully
  1097. operate on very large files, it is important to avoid using a technique
  1098. that would artificially limit the size of files it can handle.  If a
  1099. program works by lines and could be applied to arbitrary user-supplied
  1100. input files, it should keep only a line in memory, because this is not
  1101. very hard and users will want to be able to operate on input files that
  1102. are bigger than will fit in core all at once.
  1103.    If your program creates complicated data structures, just make them
  1104. in core and give a fatal error if `malloc' returns zero.
  1105. File: standards.info,  Node: Writing C,  Next: Documentation,  Prev: Program Behavior,  Up: Top
  1106. Making The Best Use of C
  1107. ************************
  1108.    This node provides advice on how best to use the C language when
  1109. writing GNU software.
  1110. * Menu:
  1111. * Formatting::            Formatting Your Source Code
  1112. * Comments::            Commenting Your Work
  1113. * Syntactic Conventions::    Clean Use of C Constructs
  1114. * Names::            Naming Variables and Functions
  1115. * System Portability::        Portability between different operating systems
  1116. * CPU Portability::             Supporting the range of CPU types
  1117. * System Functions::            Portability and "standard" library functions
  1118. File: standards.info,  Node: Formatting,  Next: Comments,  Up: Writing C
  1119. Formatting Your Source Code
  1120. ===========================
  1121.    It is important to put the open-brace that starts the body of a C
  1122. function in column zero, and avoid putting any other open-brace or
  1123. open-parenthesis or open-bracket in column zero.  Several tools look
  1124. for open-braces in column zero to find the beginnings of C functions.
  1125. These tools will not work on code not formatted that way.
  1126.    It is also important for function definitions to start the name of
  1127. the function in column zero.  This helps people to search for function
  1128. definitions, and may also help certain tools recognize them.  Thus, the
  1129. proper format is this:
  1130.      static char *
  1131.      concat (s1, s2)        /* Name starts in column zero here */
  1132.           char *s1, *s2;
  1133.      {                     /* Open brace in column zero here */
  1134.        ...
  1135.      }
  1136. or, if you want to use ANSI C, format the definition like this:
  1137.      static char *
  1138.      concat (char *s1, char *s2)
  1139.      {
  1140.        ...
  1141.      }
  1142.    In ANSI C, if the arguments don't fit nicely on one line, split it
  1143. like this:
  1144.      int
  1145.      lots_of_args (int an_integer, long a_long, short a_short,
  1146.                    double a_double, float a_float)
  1147.      ...
  1148.    For the body of the function, we prefer code formatted like this:
  1149.      if (x < foo (y, z))
  1150.        haha = bar[4] + 5;
  1151.      else
  1152.        {
  1153.          while (z)
  1154.            {
  1155.              haha += foo (z, z);
  1156.              z--;
  1157.            }
  1158.          return ++x + bar ();
  1159.        }
  1160.    We find it easier to read a program when it has spaces before the
  1161. open-parentheses and after the commas.  Especially after the commas.
  1162.    When you split an expression into multiple lines, split it before an
  1163. operator, not after one.  Here is the right way:
  1164.      if (foo_this_is_long && bar > win (x, y, z)
  1165.          && remaining_condition)
  1166.    Try to avoid having two operators of different precedence at the same
  1167. level of indentation.  For example, don't write this:
  1168.      mode = (inmode[j] == VOIDmode
  1169.              || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
  1170.              ? outmode[j] : inmode[j]);
  1171.    Instead, use extra parentheses so that the indentation shows the
  1172. nesting:
  1173.      mode = ((inmode[j] == VOIDmode
  1174.               || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
  1175.              ? outmode[j] : inmode[j]);
  1176.    Insert extra parentheses so that Emacs will indent the code properly.
  1177. For example, the following indentation looks nice if you do it by hand,
  1178. but Emacs would mess it up:
  1179.      v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
  1180.          + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
  1181.    But adding a set of parentheses solves the problem:
  1182.      v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
  1183.           + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
  1184.    Format do-while statements like this:
  1185.      do
  1186.        {
  1187.          a = foo (a);
  1188.        }
  1189.      while (a > 0);
  1190.    Please use formfeed characters (control-L) to divide the program into
  1191. pages at logical places (but not within a function).  It does not matter
  1192. just how long the pages are, since they do not have to fit on a printed
  1193. page.  The formfeeds should appear alone on lines by themselves.
  1194. File: standards.info,  Node: Comments,  Next: Syntactic Conventions,  Prev: Formatting,  Up: Writing C
  1195. Commenting Your Work
  1196. ====================
  1197.    Every program should start with a comment saying briefly what it is
  1198. for.  Example: `fmt - filter for simple filling of text'.
  1199.    Please put a comment on each function saying what the function does,
  1200. what sorts of arguments it gets, and what the possible values of
  1201. arguments mean and are used for.  It is not necessary to duplicate in
  1202. words the meaning of the C argument declarations, if a C type is being
  1203. used in its customary fashion.  If there is anything nonstandard about
  1204. its use (such as an argument of type `char *' which is really the
  1205. address of the second character of a string, not the first), or any
  1206. possible values that would not work the way one would expect (such as,
  1207. that strings containing newlines are not guaranteed to work), be sure
  1208. to say so.
  1209.    Also explain the significance of the return value, if there is one.
  1210.    Please put two spaces after the end of a sentence in your comments,
  1211. so that the Emacs sentence commands will work.  Also, please write
  1212. complete sentences and capitalize the first word.  If a lower-case
  1213. identifier comes at the beginning of a sentence, don't capitalize it!
  1214. Changing the spelling makes it a different identifier.  If you don't
  1215. like starting a sentence with a lower case letter, write the sentence
  1216. differently (e.g., "The identifier lower-case is ...").
  1217.    The comment on a function is much clearer if you use the argument
  1218. names to speak about the argument values.  The variable name itself
  1219. should be lower case, but write it in upper case when you are speaking
  1220. about the value rather than the variable itself.  Thus, "the inode
  1221. number NODE_NUM" rather than "an inode".
  1222.    There is usually no purpose in restating the name of the function in
  1223. the comment before it, because the reader can see that for himself.
  1224. There might be an exception when the comment is so long that the
  1225. function itself would be off the bottom of the screen.
  1226.    There should be a comment on each static variable as well, like this:
  1227.      /* Nonzero means truncate lines in the display;
  1228.         zero means continue them.  */
  1229.      int truncate_lines;
  1230.    Every `#endif' should have a comment, except in the case of short
  1231. conditionals (just a few lines) that are not nested.  The comment should
  1232. state the condition of the conditional that is ending, *including its
  1233. sense*.  `#else' should have a comment describing the condition *and
  1234. sense* of the code that follows.  For example:
  1235.      #ifdef foo
  1236.        ...
  1237.      #else /* not foo */
  1238.        ...
  1239.      #endif /* not foo */
  1240. but, by contrast, write the comments this way for a `#ifndef':
  1241.      #ifndef foo
  1242.        ...
  1243.      #else /* foo */
  1244.        ...
  1245.      #endif /* foo */
  1246. File: standards.info,  Node: Syntactic Conventions,  Next: Names,  Prev: Comments,  Up: Writing C
  1247. Clean Use of C Constructs
  1248. =========================
  1249.    Please explicitly declare all arguments to functions.  Don't omit
  1250. them just because they are `int's.
  1251.    Declarations of external functions and functions to appear later in
  1252. the source file should all go in one place near the beginning of the
  1253. file (somewhere before the first function definition in the file), or
  1254. else should go in a header file.  Don't put `extern' declarations inside
  1255. functions.
  1256.    It used to be common practice to use the same local variables (with
  1257. names like `tem') over and over for different values within one
  1258. function.  Instead of doing this, it is better declare a separate local
  1259. variable for each distinct purpose, and give it a name which is
  1260. meaningful.  This not only makes programs easier to understand, it also
  1261. facilitates optimization by good compilers.  You can also move the
  1262. declaration of each local variable into the smallest scope that includes
  1263. all its uses.  This makes the program even cleaner.
  1264.    Don't use local variables or parameters that shadow global
  1265. identifiers.
  1266.    Don't declare multiple variables in one declaration that spans lines.
  1267. Start a new declaration on each line, instead.  For example, instead of
  1268. this:
  1269.      int    foo,
  1270.             bar;
  1271. write either this:
  1272.      int foo, bar;
  1273. or this:
  1274.      int foo;
  1275.      int bar;
  1276. (If they are global variables, each should have a comment preceding it
  1277. anyway.)
  1278.    When you have an `if'-`else' statement nested in another `if'
  1279. statement, always put braces around the `if'-`else'.  Thus, never write
  1280. like this:
  1281.      if (foo)
  1282.        if (bar)
  1283.          win ();
  1284.        else
  1285.          lose ();
  1286. always like this:
  1287.      if (foo)
  1288.        {
  1289.          if (bar)
  1290.            win ();
  1291.          else
  1292.            lose ();
  1293.        }
  1294.    If you have an `if' statement nested inside of an `else' statement,
  1295. either write `else if' on one line, like this,
  1296.      if (foo)
  1297.        ...
  1298.      else if (bar)
  1299.        ...
  1300. with its `then'-part indented like the preceding `then'-part, or write
  1301. the nested `if' within braces like this:
  1302.      if (foo)
  1303.        ...
  1304.      else
  1305.        {
  1306.          if (bar)
  1307.            ...
  1308.        }
  1309.    Don't declare both a structure tag and variables or typedefs in the
  1310. same declaration.  Instead, declare the structure tag separately and
  1311. then use it to declare the variables or typedefs.
  1312.    Try to avoid assignments inside `if'-conditions.  For example, don't
  1313. write this:
  1314.      if ((foo = (char *) malloc (sizeof *foo)) == 0)
  1315.        fatal ("virtual memory exhausted");
  1316. instead, write this:
  1317.      foo = (char *) malloc (sizeof *foo);
  1318.      if (foo == 0)
  1319.        fatal ("virtual memory exhausted");
  1320.    Don't make the program ugly to placate `lint'.  Please don't insert
  1321. any casts to `void'.  Zero without a cast is perfectly fine as a null
  1322. pointer constant.
  1323. File: standards.info,  Node: Names,  Next: System Portability,  Prev: Syntactic Conventions,  Up: Writing C
  1324. Naming Variables and Functions
  1325. ==============================
  1326.    Please use underscores to separate words in a name, so that the Emacs
  1327. word commands can be useful within them.  Stick to lower case; reserve
  1328. upper case for macros and `enum' constants, and for name-prefixes that
  1329. follow a uniform convention.
  1330.    For example, you should use names like `ignore_space_change_flag';
  1331. don't use names like `iCantReadThis'.
  1332.    Variables that indicate whether command-line options have been
  1333. specified should be named after the meaning of the option, not after
  1334. the option-letter.  A comment should state both the exact meaning of
  1335. the option and its letter.  For example,
  1336.      /* Ignore changes in horizontal whitespace (-b).  */
  1337.      int ignore_space_change_flag;
  1338.    When you want to define names with constant integer values, use
  1339. `enum' rather than `#define'.  GDB knows about enumeration constants.
  1340.    Use file names of 14 characters or less, to avoid creating gratuitous
  1341. problems on older System V systems.  You can use the program `doschk'
  1342. to test for this.  `doschk' also tests for potential name conflicts if
  1343. the files were loaded onto an MS-DOS file system--something you may or
  1344. may not care about.
  1345. File: standards.info,  Node: System Portability,  Next: CPU Portability,  Prev: Names,  Up: Writing C
  1346. Portability between System Types
  1347. ================================
  1348.    In the Unix world, "portability" refers to porting to different Unix
  1349. versions.  For a GNU program, this kind of portability is desirable, but
  1350. not paramount.
  1351.    The primary purpose of GNU software is to run on top of the GNU
  1352. kernel, compiled with the GNU C compiler, on various types of CPU.  The
  1353. amount and kinds of variation among GNU systems on different CPUs will
  1354. be comparable to the variation among Linux-based GNU systems or among
  1355. BSD systems today.  So the kinds of portability that are absolutely
  1356. necessary are quite limited.
  1357.    But many users do run GNU software on non-GNU Unix or Unix-like
  1358. systems.  So supporting a variety of Unix-like systems is desirable,
  1359. although not paramount.
  1360.    The easiest way to achieve portability to most Unix-like systems is
  1361. to use Autoconf.  It's unlikely that your program needs to know more
  1362. information about the host platform than Autoconf can provide, simply
  1363. because most of the programs that need such knowledge have already been
  1364. written.
  1365.    Avoid using the format of semi-internal data bases (e.g.,
  1366. directories) when there is a higher-level alternative (`readdir').
  1367.    As for systems that are not like Unix, such as MSDOS, Windows, the
  1368. Macintosh, VMS, and MVS, supporting them is usually so much work that it
  1369. is better if you don't.
  1370.    The planned GNU kernel is not finished yet, but you can tell which
  1371. facilities it will provide by looking at the GNU C Library Manual.  The
  1372. GNU kernel is based on Mach, so the features of Mach will also be
  1373. available.  However, if you use Mach features, you'll probably have
  1374. trouble debugging your program today.
  1375. File: standards.info,  Node: CPU Portability,  Next: System Functions,  Prev: System Portability,  Up: Writing C
  1376. Portability between CPUs
  1377. ========================
  1378.    Even GNU systems will differ because of differences among CPU
  1379. types--for example, difference in byte ordering and alignment
  1380. requirements.  It is absolutely essential to handle these differences.
  1381. However, don't make any effort to cater to the possibility that an
  1382. `int' will be less than 32 bits.  We don't support 16-bit machines in
  1383.    Don't assume that the address of an `int' object is also the address
  1384. of its least-significant byte.  This is false on big-endian machines.
  1385. Thus, don't make the following mistake:
  1386.      int c;
  1387.      ...
  1388.      while ((c = getchar()) != EOF)
  1389.        write(file_descriptor, &c, 1);
  1390.    When calling functions, you need not worry about the difference
  1391. between pointers of various types, or between pointers an integers.  On
  1392. most machines, there's no difference anyway.  As for the few machines
  1393. where there is a difference, all of them support ANSI C, so you can use
  1394. prototypes (conditionalized to be active only in ANSI C) to make the
  1395. code work on those systems.
  1396.    In certain cases, it is ok to pass integer and pointer arguments
  1397. indiscriminately to the same function, and use no prototype on any
  1398. system.  For example, many GNU programs have error-reporting functions
  1399. that pass their arguments along to `printf' and friends:
  1400.      error (s, a1, a2, a3)
  1401.           char *s;
  1402.           int a1, a2, a3;
  1403.      {
  1404.        fprintf (stderr, "error: ");
  1405.        fprintf (stderr, s, a1, a2, a3);
  1406.      }
  1407. In practice, this works on all machines, and it is much simpler than any
  1408. "correct" alternative.
  1409.    However, avoid casting pointers to integers unless you really need
  1410. to.  These assumptions really reduce portability, and in most programs
  1411. they are easy to avoid.  In the cases where casting pointers to
  1412. integers is essential--such as, a Lisp interpreter which stores type
  1413. information as well as an address in one word--it is ok to do so, but
  1414. you'll have to make explicit provisions to handle different word sizes.
  1415. File: standards.info,  Node: System Functions,  Prev: CPU Portability,  Up: Writing C
  1416. Calling System Functions
  1417. ========================
  1418.    C implementations differ substantially.  ANSI C reduces but does not
  1419. eliminate the incompatibilities; meanwhile, many users wish to compile
  1420. GNU software with pre-ANSI compilers.  This chapter gives
  1421. recommendations for how to use the more or less standard C library
  1422. functions to avoid unnecessary loss of portability.
  1423.    * Don't use the value of `sprintf'.  It returns the number of
  1424.      characters written on some systems, but not on all systems.
  1425.    * Don't declare system functions explicitly.
  1426.      Almost any declaration for a system function is wrong on some
  1427.      system.  To minimize conflicts, leave it to the system header
  1428.      files to declare system functions.  If the headers don't declare a
  1429.      function, let it remain undeclared.
  1430.      While it may seem unclean to use a function without declaring it,
  1431.      in practice this works fine for most system library functions on
  1432.      the systems where this really happens; thus, the disadvantage is
  1433.      only theoretical.  By contrast, actual declarations have
  1434.      frequently caused actual conflicts.
  1435.    * If you must declare a system function, don't specify the argument
  1436.      types.  Use an old-style declaration, not an ANSI prototype.  The
  1437.      more you specify about the function, the more likely a conflict.
  1438.    * In particular, don't unconditionally declare `malloc' or `realloc'.
  1439.      Most GNU programs use those functions just once, in functions
  1440.      conventionally named `xmalloc' and `xrealloc'.  These functions
  1441.      call `malloc' and `realloc', respectively, and check the results.
  1442.      Because `xmalloc' and `xrealloc' are defined in your program, you
  1443.      can declare them in other files without any risk of type conflict.
  1444.      On most systems, `int' is the same length as a pointer; thus, the
  1445.      calls to `malloc' and `realloc' work fine.  For the few
  1446.      exceptional systems (mostly 64-bit machines), you can use
  1447.      *conditionalized* declarations of `malloc' and `realloc'--or put
  1448.      these declarations in configuration files specific to those
  1449.      systems.
  1450.    * The string functions require special treatment.  Some Unix systems
  1451.      have a header file `string.h'; others have `strings.h'.  Neither
  1452.      file name is portable.  There are two things you can do: use
  1453.      Autoconf to figure out which file to include, or don't include
  1454.      either file.
  1455.    * If you don't include either strings file, you can't get
  1456.      declarations for the string functions from the header file in the
  1457.      usual way.
  1458.      That causes less of a problem than you might think.  The newer ANSI
  1459.      string functions should be avoided anyway because many systems
  1460.      still don't support them.  The string functions you can use are
  1461.      these:
  1462.           strcpy   strncpy   strcat   strncat
  1463.           strlen   strcmp    strncmp
  1464.           strchr   strrchr
  1465.      The copy and concatenate functions work fine without a declaration
  1466.      as long as you don't use their values.  Using their values without
  1467.      a declaration fails on systems where the width of a pointer
  1468.      differs from the width of `int', and perhaps in other cases.  It
  1469.      is trivial to avoid using their values, so do that.
  1470.      The compare functions and `strlen' work fine without a declaration
  1471.      on most systems, possibly all the ones that GNU software runs on.
  1472.      You may find it necessary to declare them *conditionally* on a few
  1473.      systems.
  1474.      The search functions must be declared to return `char *'.  Luckily,
  1475.      there is no variation in the data type they return.  But there is
  1476.      variation in their names.  Some systems give these functions the
  1477.      names `index' and `rindex'; other systems use the names `strchr'
  1478.      and `strrchr'.  Some systems support both pairs of names, but
  1479.      neither pair works on all systems.
  1480.      You should pick a single pair of names and use it throughout your
  1481.      program.  (Nowadays, it is better to choose `strchr' and `strrchr'
  1482.      for new programs, since those are the standard ANSI names.)
  1483.      Declare both of those names as functions returning `char *'.  On
  1484.      systems which don't support those names, define them as macros in
  1485.      terms of the other pair.  For example, here is what to put at the
  1486.      beginning of your file (or in a header) if you want to use the
  1487.      names `strchr' and `strrchr' throughout:
  1488.           #ifndef HAVE_STRCHR
  1489.           #define strchr index
  1490.           #endif
  1491.           #ifndef HAVE_STRRCHR
  1492.           #define strrchr rindex
  1493.           #endif
  1494.           
  1495.           char *strchr ();
  1496.           char *strrchr ();
  1497.    Here we assume that `HAVE_STRCHR' and `HAVE_STRRCHR' are macros
  1498. defined in systems where the corresponding functions exist.  One way to
  1499. get them properly defined is to use Autoconf.
  1500. File: standards.info,  Node: Documentation,  Next: Managing Releases,  Prev: Writing C,  Up: Top
  1501. Documenting Programs
  1502. ********************
  1503. * Menu:
  1504. * GNU Manuals::                 Writing proper manuals.
  1505. * Manual Structure Details::    Specific structure conventions.
  1506. * NEWS File::                   NEWS files supplement manuals.
  1507. * Change Logs::            Recording Changes
  1508. * Man Pages::                   Man pages are secondary.
  1509. * Reading other Manuals::       How far you can go in learning
  1510.                                 from other manuals.
  1511. File: standards.info,  Node: GNU Manuals,  Next: Manual Structure Details,  Up: Documentation
  1512. GNU Manuals
  1513. ===========
  1514.    The preferred way to document part of the GNU system is to write a
  1515. manual in the Texinfo formatting language.  See the Texinfo manual,
  1516. either the hardcopy, or the on-line version available through `info' or
  1517. the Emacs Info subsystem (`C-h i').
  1518.    The manual should document all of the program's command-line options
  1519. and all of its commands.  It should give examples of their use.  But
  1520. don't organize the manual as a list of features.  Instead, organize it
  1521. logically, by subtopics.  Address the goals that a user will have in
  1522. mind, and explain how to accomplish them.
  1523.    In general, a GNU manual should serve both as tutorial and reference.
  1524. It should be set up for convenient access to each topic through Info,
  1525. and for reading straight through (appendixes aside).  A GNU manual
  1526. should give a good introduction to a beginner reading through from the
  1527. start, and should also provide all the details that hackers want.
  1528.    That is not as hard as it first sounds.  Arrange each chapter as a
  1529. logical breakdown of its topic, but order the sections, and write their
  1530. text, so that reading the chapter straight through makes sense.  Do
  1531. likewise when structuring the book into chapters, and when structuring a
  1532. section into paragraphs.  The watchword is, *at each point, address the
  1533. most fundamental and important issue raised by the preceding text.*
  1534.    If necessary, add extra chapters at the beginning of the manual which
  1535. are purely tutorial and cover the basics of the subject.  These provide
  1536. the framework for a beginner to understand the rest of the manual.  The
  1537. Bison manual provides a good example of how to do this.
  1538.    Don't use Unix man pages as a model for how to write GNU
  1539. documentation; they are a bad example to follow.
  1540.    Please do not use the term "pathname" that is used in Unix
  1541. documentation; use "file name" (two words) instead.  We use the term
  1542. "path" only for search paths, which are lists of file names.
  1543. File: standards.info,  Node: Manual Structure Details,  Next: NEWS File,  Prev: GNU Manuals,  Up: Documentation
  1544. Manual Structure Details
  1545. ========================
  1546.    The title page of the manual should state the version of the program
  1547. to which the manual applies.  The Top node of the manual should also
  1548. contain this information.  If the manual is changing more frequently
  1549. than or independent of the program, also state a version number for the
  1550. manual in both of these places.
  1551.    The manual should have a node named `PROGRAM Invocation' or
  1552. `Invoking PROGRAM', where PROGRAM stands for the name of the program
  1553. being described, as you would type it in the shell to run the program.
  1554. This node (together with its subnodes, if any) should describe the
  1555. program's command line arguments and how to run it (the sort of
  1556. information people would look in a man page for).  Start with an
  1557. `@example' containing a template for all the options and arguments that
  1558. the program uses.
  1559.    Alternatively, put a menu item in some menu whose item name fits one
  1560. of the above patterns.  This identifies the node which that item points
  1561. to as the node for this purpose, regardless of the node's actual name.
  1562.    There will be automatic features for specifying a program name and
  1563. quickly reading just this part of its manual.
  1564.    If one manual describes several programs, it should have such a node
  1565. for each program described.
  1566. File: standards.info,  Node: NEWS File,  Next: Change Logs,  Prev: Manual Structure Details,  Up: Documentation
  1567. The NEWS File
  1568. =============
  1569.    In addition to its manual, the package should have a file named
  1570. `NEWS' which contains a list of user-visible changes worth mentioning.
  1571. In each new release, add items to the front of the file and identify
  1572. the version they pertain to.  Don't discard old items; leave them in
  1573. the file after the newer items.  This way, a user upgrading from any
  1574. previous version can see what is new.
  1575.    If the `NEWS' file gets very long, move some of the older items into
  1576. a file named `ONEWS' and put a note at the end referring the user to
  1577. that file.
  1578. File: standards.info,  Node: Change Logs,  Next: Man Pages,  Prev: NEWS File,  Up: Documentation
  1579. Change Logs
  1580. ===========
  1581.    Keep a change log for each directory, describing the changes made to
  1582. source files in that directory.  The purpose of this is so that people
  1583. investigating bugs in the future will know about the changes that might
  1584. have introduced the bug.  Often a new bug can be found by looking at
  1585. what was recently changed.  More importantly, change logs can help
  1586. eliminate conceptual inconsistencies between different parts of a
  1587. program; they can give you a history of how the conflicting concepts
  1588. arose.
  1589.    Use the Emacs command `M-x add-change-log-entry' to start a new
  1590. entry in the change log.  An entry should have an asterisk, the name of
  1591. the changed file, and then in parentheses the name of the changed
  1592. functions, variables or whatever, followed by a colon.  Then describe
  1593. the changes you made to that function or variable.
  1594.    Separate unrelated entries with blank lines.  When two entries
  1595. represent parts of the same change, so that they work together, then
  1596. don't put blank lines between them.  Then you can omit the file name
  1597. and the asterisk when successive entries are in the same file.
  1598.    Here are some examples:
  1599.      * register.el (insert-register): Return nil.
  1600.      (jump-to-register): Likewise.
  1601.      
  1602.      * sort.el (sort-subr): Return nil.
  1603.      
  1604.      * tex-mode.el (tex-bibtex-file, tex-file, tex-region):
  1605.      Restart the tex shell if process is gone or stopped.
  1606.      (tex-shell-running): New function.
  1607.      
  1608.      * expr.c (store_one_arg): Round size up for move_block_to_reg.
  1609.      (expand_call): Round up when emitting USE insns.
  1610.      * stmt.c (assign_parms): Round size up for move_block_from_reg.
  1611.    It's important to name the changed function or variable in full.
  1612. Don't abbreviate function or variable names, and don't combine them.
  1613. Subsequent maintainers will often search for a function name to find
  1614. all the change log entries that pertain to it; if you abbreviate the
  1615. name, they won't find it when they search.  For example, some people
  1616. are tempted to abbreviate groups of function names by writing `*
  1617. register.el ({insert,jump-to}-register)'; this is not a good idea,
  1618. since searching for `jump-to-register' or `insert-register' would not
  1619. find the entry.
  1620.    There's no need to describe the full purpose of the changes or how
  1621. they work together.  It is better to put such explanations in comments
  1622. in the code.  That's why just "New function" is enough; there is a
  1623. comment with the function in the source to explain what it does.
  1624.    However, sometimes it is useful to write one line to describe the
  1625. overall purpose of a large batch of changes.
  1626.    You can think of the change log as a conceptual "undo list" which
  1627. explains how earlier versions were different from the current version.
  1628. People can see the current version; they don't need the change log to
  1629. tell them what is in it.  What they want from a change log is a clear
  1630. explanation of how the earlier version differed.
  1631.    When you change the calling sequence of a function in a simple
  1632. fashion, and you change all the callers of the function, there is no
  1633. need to make individual entries for all the callers.  Just write in the
  1634. entry for the function being called, "All callers changed."
  1635.    When you change just comments or doc strings, it is enough to write
  1636. an entry for the file, without mentioning the functions.  Write just,
  1637. "Doc fix."  There's no need to keep a change log for documentation
  1638. files.  This is because documentation is not susceptible to bugs that
  1639. are hard to fix.  Documentation does not consist of parts that must
  1640. interact in a precisely engineered fashion; to correct an error, you
  1641. need not know the history of the erroneous passage.
  1642. File: standards.info,  Node: Man Pages,  Next: Reading other Manuals,  Prev: Change Logs,  Up: Documentation
  1643. Man Pages
  1644. =========
  1645.    In the GNU project, man pages are secondary.  It is not necessary or
  1646. expected for every GNU program to have a man page, but some of them do.
  1647. It's your choice whether to include a man page in your program.
  1648.    When you make this decision, consider that supporting a man page
  1649. requires continual effort each time the program is changed.  The time
  1650. you spend on the man page is time taken away from more useful work.
  1651.    For a simple program which changes little, updating the man page may
  1652. be a small job.  Then there is little reason not to include a man page,
  1653. if you have one.
  1654.    For a large program that changes a great deal, updating a man page
  1655. may be a substantial burden.  If a user offers to donate a man page,
  1656. you may find this gift costly to accept.  It may be better to refuse
  1657. the man page unless the same person agrees to take full responsibility
  1658. for maintaining it--so that you can wash your hands of it entirely.  If
  1659. this volunteer later ceases to do the job, then don't feel obliged to
  1660. pick it up yourself; it may be better to withdraw the man page from the
  1661. distribution until someone else agrees to update it.
  1662.    When a program changes only a little, you may feel that the
  1663. discrepancies are small enough that the man page remains useful without
  1664. updating.  If so, put a prominent note near the beginning of the man
  1665. page explaining that you don't maintain it and that the Texinfo manual
  1666. is more authoritative.  The note should say how to access the Texinfo
  1667. documentation.
  1668. File: standards.info,  Node: Reading other Manuals,  Prev: Man Pages,  Up: Documentation
  1669. Reading other Manuals
  1670. =====================
  1671.    There may be non-free books or documentation files that describe the
  1672. program you are documenting.
  1673.    It is ok to use these documents for reference, just as the author of
  1674. a new algebra textbook can read other books on algebra.  A large portion
  1675. of any non-fiction book consists of facts, in this case facts about how
  1676. a certain program works, and these facts are necessarily the same for
  1677. everyone who writes about the subject.  But be careful not to copy your
  1678. outline structure, wording, tables or examples from preexisting non-free
  1679. documentation.  Copying from free documentation may be ok; please check
  1680. with the FSF about the individual case.
  1681. File: standards.info,  Node: Managing Releases,  Prev: Documentation,  Up: Top
  1682. The Release Process
  1683. *******************
  1684.    Making a release is more than just bundling up your source files in a
  1685. tar file and putting it up for FTP.  You should set up your software so
  1686. that it can be configured to run on a variety of systems.  Your Makefile
  1687. should conform to the GNU standards described below, and your directory
  1688. layout should also conform to the standards discussed below.  Doing so
  1689. makes it easy to include your package into the larger framework of all
  1690. GNU software.
  1691. * Menu:
  1692. * Configuration::        How Configuration Should Work
  1693. * Makefile Conventions::    Makefile Conventions
  1694. * Releases::            Making Releases
  1695. File: standards.info,  Node: Configuration,  Next: Makefile Conventions,  Up: Managing Releases
  1696. How Configuration Should Work
  1697. =============================
  1698.    Each GNU distribution should come with a shell script named
  1699. `configure'.  This script is given arguments which describe the kind of
  1700. machine and system you want to compile the program for.
  1701.    The `configure' script must record the configuration options so that
  1702. they affect compilation.
  1703.    One way to do this is to make a link from a standard name such as
  1704. `config.h' to the proper configuration file for the chosen system.  If
  1705. you use this technique, the distribution should *not* contain a file
  1706. named `config.h'.  This is so that people won't be able to build the
  1707. program without configuring it first.
  1708.    Another thing that `configure' can do is to edit the Makefile.  If
  1709. you do this, the distribution should *not* contain a file named
  1710. `Makefile'.  Instead, it should include a file `Makefile.in' which
  1711. contains the input used for editing.  Once again, this is so that people
  1712. won't be able to build the program without configuring it first.
  1713.    If `configure' does write the `Makefile', then `Makefile' should
  1714. have a target named `Makefile' which causes `configure' to be rerun,
  1715. setting up the same configuration that was set up last time.  The files
  1716. that `configure' reads should be listed as dependencies of `Makefile'.
  1717.    All the files which are output from the `configure' script should
  1718. have comments at the beginning explaining that they were generated
  1719. automatically using `configure'.  This is so that users won't think of
  1720. trying to edit them by hand.
  1721.    The `configure' script should write a file named `config.status'
  1722. which describes which configuration options were specified when the
  1723. program was last configured.  This file should be a shell script which,
  1724. if run, will recreate the same configuration.
  1725.    The `configure' script should accept an option of the form
  1726. `--srcdir=DIRNAME' to specify the directory where sources are found (if
  1727. it is not the current directory).  This makes it possible to build the
  1728. program in a separate directory, so that the actual source directory is
  1729. not modified.
  1730.    If the user does not specify `--srcdir', then `configure' should
  1731. check both `.' and `..' to see if it can find the sources.  If it finds
  1732. the sources in one of these places, it should use them from there.
  1733. Otherwise, it should report that it cannot find the sources, and should
  1734. exit with nonzero status.
  1735.    Usually the easy way to support `--srcdir' is by editing a
  1736. definition of `VPATH' into the Makefile.  Some rules may need to refer
  1737. explicitly to the specified source directory.  To make this possible,
  1738. `configure' can add to the Makefile a variable named `srcdir' whose
  1739. value is precisely the specified directory.
  1740.    The `configure' script should also take an argument which specifies
  1741. the type of system to build the program for.  This argument should look
  1742. like this:
  1743.      CPU-COMPANY-SYSTEM
  1744.    For example, a Sun 3 might be `m68k-sun-sunos4.1'.
  1745.    The `configure' script needs to be able to decode all plausible
  1746. alternatives for how to describe a machine.  Thus, `sun3-sunos4.1'
  1747. would be a valid alias.  For many programs, `vax-dec-ultrix' would be
  1748. an alias for `vax-dec-bsd', simply because the differences between
  1749. Ultrix and BSD are rarely noticeable, but a few programs might need to
  1750. distinguish them.
  1751.    There is a shell script called `config.sub' that you can use as a
  1752. subroutine to validate system types and canonicalize aliases.
  1753.    Other options are permitted to specify in more detail the software
  1754. or hardware present on the machine, and include or exclude optional
  1755. parts of the package:
  1756. `--enable-FEATURE[=PARAMETER]'
  1757.      Configure the package to build and install an optional user-level
  1758.      facility called FEATURE.  This allows users to choose which
  1759.      optional features to include.  Giving an optional PARAMETER of
  1760.      `no' should omit FEATURE, if it is built by default.
  1761.      No `--enable' option should *ever* cause one feature to replace
  1762.      another.  No `--enable' option should ever substitute one useful
  1763.      behavior for another useful behavior.  The only proper use for
  1764.      `--enable' is for questions of whether to build part of the program
  1765.      or exclude it.
  1766. `--with-PACKAGE'
  1767.      The package PACKAGE will be installed, so configure this package
  1768.      to work with PACKAGE.
  1769.      Possible values of PACKAGE include `x', `x-toolkit', `gnu-as' (or
  1770.      `gas'), `gnu-ld', `gnu-libc', and `gdb'.
  1771.      Do not use a `--with' option to specify the file name to use to
  1772.      find certain files.  That is outside the scope of what `--with'
  1773.      options are for.
  1774. `--nfp'
  1775.      The target machine has no floating point processor.
  1776. `--gas'
  1777.      The target machine assembler is GAS, the GNU assembler.  This is
  1778.      obsolete; users should use `--with-gnu-as' instead.
  1779. `--x'
  1780.      The target machine has the X Window System installed.  This is
  1781.      obsolete; users should use `--with-x' instead.
  1782.    All `configure' scripts should accept all of these "detail" options,
  1783. whether or not they make any difference to the particular package at
  1784. hand.  In particular, they should accept any option that starts with
  1785. `--with-' or `--enable-'.  This is so users will be able to configure
  1786. an entire GNU source tree at once with a single set of options.
  1787.    You will note that the categories `--with-' and `--enable-' are
  1788. narrow: they *do not* provide a place for any sort of option you might
  1789. think of.  That is deliberate.  We want to limit the possible
  1790. configuration options in GNU software.  We do not want GNU programs to
  1791. have idiosyncratic configuration options.
  1792.    Packages that perform part of the compilation process may support
  1793. cross-compilation.  In such a case, the host and target machines for
  1794. the program may be different.  The `configure' script should normally
  1795. treat the specified type of system as both the host and the target,
  1796. thus producing a program which works for the same type of machine that
  1797. it runs on.
  1798.    The way to build a cross-compiler, cross-assembler, or what have
  1799. you, is to specify the option `--host=HOSTTYPE' when running
  1800. `configure'.  This specifies the host system without changing the type
  1801. of target system.  The syntax for HOSTTYPE is the same as described
  1802. above.
  1803.    Bootstrapping a cross-compiler requires compiling it on a machine
  1804. other than the host it will run on.  Compilation packages accept a
  1805. configuration option `--build=HOSTTYPE' for specifying the
  1806. configuration on which you will compile them, in case that is different
  1807. from the host.
  1808.    Programs for which cross-operation is not meaningful need not accept
  1809. the `--host' option, because configuring an entire operating system for
  1810. cross-operation is not a meaningful thing.
  1811.    Some programs have ways of configuring themselves automatically.  If
  1812. your program is set up to do this, your `configure' script can simply
  1813. ignore most of its arguments.
  1814. File: standards.info,  Node: Makefile Conventions,  Next: Releases,  Prev: Configuration,  Up: Managing Releases
  1815. Makefile Conventions
  1816. ====================
  1817.    This node describes conventions for writing the Makefiles for GNU
  1818. programs.
  1819. * Menu:
  1820. * Makefile Basics::        General Conventions for Makefiles
  1821. * Utilities in Makefiles::    Utilities in Makefiles
  1822. * Command Variables::        Variables for Specifying Commands
  1823. * Directory Variables::        Variables for Installation Directories
  1824. * Standard Targets::        Standard Targets for Users
  1825. File: standards.info,  Node: Makefile Basics,  Next: Utilities in Makefiles,  Up: Makefile Conventions
  1826. General Conventions for Makefiles
  1827. ---------------------------------
  1828.    Every Makefile should contain this line:
  1829.      SHELL = /bin/sh
  1830. to avoid trouble on systems where the `SHELL' variable might be
  1831. inherited from the environment.  (This is never a problem with GNU
  1832. `make'.)
  1833.    Different `make' programs have incompatible suffix lists and
  1834. implicit rules, and this sometimes creates confusion or misbehavior.  So
  1835. it is a good idea to set the suffix list explicitly using only the
  1836. suffixes you need in the particular Makefile, like this:
  1837.      .SUFFIXES:
  1838.      .SUFFIXES: .c .o
  1839. The first line clears out the suffix list, the second introduces all
  1840. suffixes which may be subject to implicit rules in this Makefile.
  1841.    Don't assume that `.' is in the path for command execution.  When
  1842. you need to run programs that are a part of your package during the
  1843. make, please make sure that it uses `./' if the program is built as
  1844. part of the make or `$(srcdir)/' if the file is an unchanging part of
  1845. the source code.  Without one of these prefixes, the current search
  1846. path is used.
  1847.    The distinction between `./' and `$(srcdir)/' is important when
  1848. using the `--srcdir' option to `configure'.  A rule of the form:
  1849.      foo.1 : foo.man sedscript
  1850.              sed -e sedscript foo.man > foo.1
  1851. will fail when the current directory is not the source directory,
  1852. because `foo.man' and `sedscript' are not in the current directory.
  1853.    When using GNU `make', relying on `VPATH' to find the source file
  1854. will work in the case where there is a single dependency file, since
  1855. the `make' automatic variable `$<' will represent the source file
  1856. wherever it is.  (Many versions of `make' set `$<' only in implicit
  1857. rules.)  A Makefile target like
  1858.      foo.o : bar.c
  1859.              $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
  1860. should instead be written as
  1861.      foo.o : bar.c
  1862.              $(CC) -I. -I$(srcdir) $(CFLAGS) -c $< -o $@
  1863. in order to allow `VPATH' to work correctly.  When the target has
  1864. multiple dependencies, using an explicit `$(srcdir)' is the easiest way
  1865. to make the rule work well.  For example, the target above for `foo.1'
  1866. is best written as:
  1867.      foo.1 : foo.man sedscript
  1868.              sed -e $(srcdir)/sedscript $(srcdir)/foo.man > $@
  1869.    Try to make the build and installation targets, at least (and all
  1870. their subtargets) work correctly with a parallel `make'.
  1871. File: standards.info,  Node: Utilities in Makefiles,  Next: Command Variables,  Prev: Makefile Basics,  Up: Makefile Conventions
  1872. Utilities in Makefiles
  1873. ----------------------
  1874.    Write the Makefile commands (and any shell scripts, such as
  1875. `configure') to run in `sh', not in `csh'.  Don't use any special
  1876. features of `ksh' or `bash'.
  1877.    The `configure' script and the Makefile rules for building and
  1878. installation should not use any utilities directly except these:
  1879.      cat cmp cp echo egrep expr false grep
  1880.      ln mkdir mv pwd rm rmdir sed test touch true
  1881.    Stick to the generally supported options for these programs.  For
  1882. example, don't use `mkdir -p', convenient as it may be, because most
  1883. systems don't support it.
  1884.    It is a good idea to avoid creating symbolic links in makefiles,
  1885. since a few systems don't support them.
  1886.    The Makefile rules for building and installation can also use
  1887. compilers and related programs, but should do so via `make' variables
  1888. so that the user can substitute alternatives.  Here are some of the
  1889. programs we mean:
  1890.      ar bison cc flex install ld lex
  1891.      make makeinfo ranlib texi2dvi yacc
  1892.    Use the following `make' variables:
  1893.      $(AR) $(BISON) $(CC) $(FLEX) $(INSTALL) $(LD) $(LEX)
  1894.      $(MAKE) $(MAKEINFO) $(RANLIB) $(TEXI2DVI) $(YACC)
  1895.    When you use `ranlib', you should make sure nothing bad happens if
  1896. the system does not have `ranlib'.  Arrange to ignore an error from
  1897. that command, and print a message before the command to tell the user
  1898. that failure of the `ranlib' command does not mean a problem.  (The
  1899. Autoconf `AC_PROG_RANLIB' macro can help with this.)
  1900.    If you use symbolic links, you should implement a fallback for
  1901. systems that don't have symbolic links.
  1902.    It is ok to use other utilities in Makefile portions (or scripts)
  1903. intended only for particular systems where you know those utilities
  1904. exist.
  1905. File: standards.info,  Node: Command Variables,  Next: Directory Variables,  Prev: Utilities in Makefiles,  Up: Makefile Conventions
  1906. Variables for Specifying Commands
  1907. ---------------------------------
  1908.    Makefiles should provide variables for overriding certain commands,
  1909. options, and so on.
  1910.    In particular, you should run most utility programs via variables.
  1911. Thus, if you use Bison, have a variable named `BISON' whose default
  1912. value is set with `BISON = bison', and refer to it with `$(BISON)'
  1913. whenever you need to use Bison.
  1914.    File management utilities such as `ln', `rm', `mv', and so on, need
  1915. not be referred to through variables in this way, since users don't
  1916. need to replace them with other programs.
  1917.    Each program-name variable should come with an options variable that
  1918. is used to supply options to the program.  Append `FLAGS' to the
  1919. program-name variable name to get the options variable name--for
  1920. example, `BISONFLAGS'.  (The name `CFLAGS' is an exception to this
  1921. rule, but we keep it because it is standard.)  Use `CPPFLAGS' in any
  1922. compilation command that runs the preprocessor, and use `LDFLAGS' in
  1923. any compilation command that does linking as well as in any direct use
  1924. of `ld'.
  1925.    If there are C compiler options that *must* be used for proper
  1926. compilation of certain files, do not include them in `CFLAGS'.  Users
  1927. expect to be able to specify `CFLAGS' freely themselves.  Instead,
  1928. arrange to pass the necessary options to the C compiler independently
  1929. of `CFLAGS', by writing them explicitly in the compilation commands or
  1930. by defining an implicit rule, like this:
  1931.      CFLAGS = -g
  1932.      ALL_CFLAGS = -I. $(CFLAGS)
  1933.      .c.o:
  1934.              $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
  1935.    Do include the `-g' option in `CFLAGS', because that is not
  1936. *required* for proper compilation.  You can consider it a default that
  1937. is only recommended.  If the package is set up so that it is compiled
  1938. with GCC by default, then you might as well include `-O' in the default
  1939. value of `CFLAGS' as well.
  1940.    Put `CFLAGS' last in the compilation command, after other variables
  1941. containing compiler options, so the user can use `CFLAGS' to override
  1942. the others.
  1943.    Every Makefile should define the variable `INSTALL', which is the
  1944. basic command for installing a file into the system.
  1945.    Every Makefile should also define the variables `INSTALL_PROGRAM'
  1946. and `INSTALL_DATA'.  (The default for each of these should be
  1947. `$(INSTALL)'.)  Then it should use those variables as the commands for
  1948. actual installation, for executables and nonexecutables respectively.
  1949. Use these variables as follows:
  1950.      $(INSTALL_PROGRAM) foo $(bindir)/foo
  1951.      $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
  1952. Always use a file name, not a directory name, as the second argument of
  1953. the installation commands.  Use a separate command for each file to be
  1954. installed.
  1955. File: standards.info,  Node: Directory Variables,  Next: Standard Targets,  Prev: Command Variables,  Up: Makefile Conventions
  1956. Variables for Installation Directories
  1957. --------------------------------------
  1958.    Installation directories should always be named by variables, so it
  1959. is easy to install in a nonstandard place.  The standard names for these
  1960. variables are described below.  They are based on a standard filesystem
  1961. layout; variants of it are used in SVR4, 4.4BSD, Linux, Ultrix v4, and
  1962. other modern operating systems.
  1963.    These two variables set the root for the installation.  All the other
  1964. installation directories should be subdirectories of one of these two,
  1965. and nothing should be directly installed into these two directories.
  1966. `prefix'
  1967.      A prefix used in constructing the default values of the variables
  1968.      listed below.  The default value of `prefix' should be
  1969.      `/usr/local'.  When building the complete GNU system, the prefix
  1970.      will be empty and `/usr' will be a symbolic link to `/'.  (If you
  1971.      are using Autoconf, write it as `@prefix@'.)
  1972. `exec_prefix'
  1973.      A prefix used in constructing the default values of some of the
  1974.      variables listed below.  The default value of `exec_prefix' should
  1975.      be `$(prefix)'.  (If you are using Autoconf, write it as
  1976.      `@exec_prefix@'.)
  1977.      Generally, `$(exec_prefix)' is used for directories that contain
  1978.      machine-specific files (such as executables and subroutine
  1979.      libraries), while `$(prefix)' is used directly for other
  1980.      directories.
  1981.    Executable programs are installed in one of the following
  1982. directories.
  1983. `bindir'
  1984.      The directory for installing executable programs that users can
  1985.      run.  This should normally be `/usr/local/bin', but write it as
  1986.      `$(exec_prefix)/bin'.  (If you are using Autoconf, write it as
  1987.      `@bindir@'.)
  1988. `sbindir'
  1989.      The directory for installing executable programs that can be run
  1990.      from the shell, but are only generally useful to system
  1991.      administrators.  This should normally be `/usr/local/sbin', but
  1992.      write it as `$(exec_prefix)/sbin'.  (If you are using Autoconf,
  1993.      write it as `@sbindir@'.)
  1994. `libexecdir'
  1995.      The directory for installing executable programs to be run by other
  1996.      programs rather than by users.  This directory should normally be
  1997.      `/usr/local/libexec', but write it as `$(exec_prefix)/libexec'.
  1998.      (If you are using Autoconf, write it as `@libexecdir@'.)
  1999.    Data files used by the program during its execution are divided into
  2000. categories in two ways.
  2001.    * Some files are normally modified by programs; others are never
  2002.      normally modified (though users may edit some of these).
  2003.    * Some files are architecture-independent and can be shared by all
  2004.      machines at a site; some are architecture-dependent and can be
  2005.      shared only by machines of the same kind and operating system;
  2006.      others may never be shared between two machines.
  2007.    This makes for six different possibilities.  However, we want to
  2008. discourage the use of architecture-dependent files, aside from object
  2009. files and libraries.  It is much cleaner to make other data files
  2010. architecture-independent, and it is generally not hard.
  2011.    Therefore, here are the variables Makefiles should use to specify
  2012. directories:
  2013. `datadir'
  2014.      The directory for installing read-only architecture independent
  2015.      data files.  This should normally be `/usr/local/share', but write
  2016.      it as `$(prefix)/share'.  (If you are using Autoconf, write it as
  2017.      `@datadir@'.) As a special exception, see `$(infodir)' and
  2018.      `$(includedir)' below.
  2019. `sysconfdir'
  2020.      The directory for installing read-only data files that pertain to a
  2021.      single machine-that is to say, files for configuring a host.
  2022.      Mailer and network configuration files, `/etc/passwd', and so
  2023.      forth belong here.  All the files in this directory should be
  2024.      ordinary ASCII text files.  This directory should normally be
  2025.      `/usr/local/etc', but write it as `$(prefix)/etc'.  (If you are
  2026.      using Autoconf, write it as `@sysconfdir@'.)
  2027.      Do not install executables in this directory (they probably belong
  2028.      in `$(libexecdir)' or `$(sbindir)').  Also do not install files
  2029.      that are modified in the normal course of their use (programs
  2030.      whose purpose is to change the configuration of the system
  2031.      excluded).  Those probably belong in `$(localstatedir)'.
  2032. `sharedstatedir'
  2033.      The directory for installing architecture-independent data files
  2034.      which the programs modify while they run.  This should normally be
  2035.      `/usr/local/com', but write it as `$(prefix)/com'.  (If you are
  2036.      using Autoconf, write it as `@sharedstatedir@'.)
  2037. `localstatedir'
  2038.      The directory for installing data files which the programs modify
  2039.      while they run, and that pertain to one specific machine.  Users
  2040.      should never need to modify files in this directory to configure
  2041.      the package's operation; put such configuration information in
  2042.      separate files that go in `$(datadir)' or `$(sysconfdir)'.
  2043.      `$(localstatedir)' should normally be `/usr/local/var', but write
  2044.      it as `$(prefix)/var'.  (If you are using Autoconf, write it as
  2045.      `@localstatedir@'.)
  2046. `libdir'
  2047.      The directory for object files and libraries of object code.  Do
  2048.      not install executables here, they probably ought to go in
  2049.      `$(libexecdir)' instead.  The value of `libdir' should normally be
  2050.      `/usr/local/lib', but write it as `$(exec_prefix)/lib'.  (If you
  2051.      are using Autoconf, write it as `@libdir@'.)
  2052. `infodir'
  2053.      The directory for installing the Info files for this package.  By
  2054.      default, it should be `/usr/local/info', but it should be written
  2055.      as `$(prefix)/info'.  (If you are using Autoconf, write it as
  2056.      `@infodir@'.)
  2057. `includedir'
  2058.      The directory for installing header files to be included by user
  2059.      programs with the C `#include' preprocessor directive.  This
  2060.      should normally be `/usr/local/include', but write it as
  2061.      `$(prefix)/include'.  (If you are using Autoconf, write it as
  2062.      `@includedir@'.)
  2063.      Most compilers other than GCC do not look for header files in
  2064.      `/usr/local/include'.  So installing the header files this way is
  2065.      only useful with GCC.  Sometimes this is not a problem because some
  2066.      libraries are only really intended to work with GCC.  But some
  2067.      libraries are intended to work with other compilers.  They should
  2068.      install their header files in two places, one specified by
  2069.      `includedir' and one specified by `oldincludedir'.
  2070. `oldincludedir'
  2071.      The directory for installing `#include' header files for use with
  2072.      compilers other than GCC.  This should normally be `/usr/include'.
  2073.      (If you are using Autoconf, you can write it as `@oldincludedir@'.)
  2074.      The Makefile commands should check whether the value of
  2075.      `oldincludedir' is empty.  If it is, they should not try to use
  2076.      it; they should cancel the second installation of the header files.
  2077.      A package should not replace an existing header in this directory
  2078.      unless the header came from the same package.  Thus, if your Foo
  2079.      package provides a header file `foo.h', then it should install the
  2080.      header file in the `oldincludedir' directory if either (1) there
  2081.      is no `foo.h' there or (2) the `foo.h' that exists came from the
  2082.      Foo package.
  2083.      To tell whether `foo.h' came from the Foo package, put a magic
  2084.      string in the file--part of a comment--and `grep' for that string.
  2085.    Unix-style man pages are installed in one of the following:
  2086. `mandir'
  2087.      The top-level directory for installing the man pages (if any) for
  2088.      this package.  It will normally be `/usr/local/man', but you should
  2089.      write it as `$(prefix)/man'.  (If you are using Autoconf, write it
  2090.      as `@mandir@'.)
  2091. `man1dir'
  2092.      The directory for installing section 1 man pages.  Write it as
  2093.      `$(mandir)/man1'.
  2094. `man2dir'
  2095.      The directory for installing section 2 man pages.  Write it as
  2096.      `$(mandir)/man2'
  2097. `...'
  2098.      *Don't make the primary documentation for any GNU software be a
  2099.      man page.  Write a manual in Texinfo instead.  Man pages are just
  2100.      for the sake of people running GNU software on Unix, which is a
  2101.      secondary application only.*
  2102. `manext'
  2103.      The file name extension for the installed man page.  This should
  2104.      contain a period followed by the appropriate digit; it should
  2105.      normally be `.1'.
  2106. `man1ext'
  2107.      The file name extension for installed section 1 man pages.
  2108. `man2ext'
  2109.      The file name extension for installed section 2 man pages.
  2110. `...'
  2111.      Use these names instead of `manext' if the package needs to
  2112.      install man pages in more than one section of the manual.
  2113.    And finally, you should set the following variable:
  2114. `srcdir'
  2115.      The directory for the sources being compiled.  The value of this
  2116.      variable is normally inserted by the `configure' shell script.
  2117.      (If you are using Autconf, use `srcdir = @srcdir@'.)
  2118.    For example:
  2119.      # Common prefix for installation directories.
  2120.      # NOTE: This directory must exist when you start the install.
  2121.      prefix = /usr/local
  2122.      exec_prefix = $(prefix)
  2123.      # Where to put the executable for the command `gcc'.
  2124.      bindir = $(exec_prefix)/bin
  2125.      # Where to put the directories used by the compiler.
  2126.      libexecdir = $(exec_prefix)/libexec
  2127.      # Where to put the Info files.
  2128.      infodir = $(prefix)/info
  2129.    If your program installs a large number of files into one of the
  2130. standard user-specified directories, it might be useful to group them
  2131. into a subdirectory particular to that program.  If you do this, you
  2132. should write the `install' rule to create these subdirectories.
  2133.    Do not expect the user to include the subdirectory name in the value
  2134. of any of the variables listed above.  The idea of having a uniform set
  2135. of variable names for installation directories is to enable the user to
  2136. specify the exact same values for several different GNU packages.  In
  2137. order for this to be useful, all the packages must be designed so that
  2138. they will work sensibly when the user does so.
  2139. File: standards.info,  Node: Standard Targets,  Prev: Directory Variables,  Up: Makefile Conventions
  2140. Standard Targets for Users
  2141. --------------------------
  2142.    All GNU programs should have the following targets in their
  2143. Makefiles:
  2144. `all'
  2145.      Compile the entire program.  This should be the default target.
  2146.      This target need not rebuild any documentation files; Info files
  2147.      should normally be included in the distribution, and DVI files
  2148.      should be made only when explicitly asked for.
  2149.      By default, the Make rules should compile and link with `-g', so
  2150.      that executable programs have debugging symbols.  Users who don't
  2151.      mind being helpless can strip the executables later if they wish.
  2152. `install'
  2153.      Compile the program and copy the executables, libraries, and so on
  2154.      to the file names where they should reside for actual use.  If
  2155.      there is a simple test to verify that a program is properly
  2156.      installed, this target should run that test.
  2157.      Do not strip executables when installing them.  Devil-may-care
  2158.      users can use the `install-strip' target to do that.
  2159.      If possible, write the `install' target rule so that it does not
  2160.      modify anything in the directory where the program was built,
  2161.      provided `make all' has just been done.  This is convenient for
  2162.      building the program under one user name and installing it under
  2163.      another.
  2164.      The commands should create all the directories in which files are
  2165.      to be installed, if they don't already exist.  This includes the
  2166.      directories specified as the values of the variables `prefix' and
  2167.      `exec_prefix', as well as all subdirectories that are needed.  One
  2168.      way to do this is by means of an `installdirs' target as described
  2169.      below.
  2170.      Use `-' before any command for installing a man page, so that
  2171.      `make' will ignore any errors.  This is in case there are systems
  2172.      that don't have the Unix man page documentation system installed.
  2173.      The way to install Info files is to copy them into `$(infodir)'
  2174.      with `$(INSTALL_DATA)' (*note Command Variables::.), and then run
  2175.      the `install-info' program if it is present.  `install-info' is a
  2176.      program that edits the Info `dir' file to add or update the menu
  2177.      entry for the given Info file; it is part of the Texinfo package.
  2178.      Here is a sample rule to install an Info file:
  2179.           $(infodir)/foo.info: foo.info
  2180.           # There may be a newer info file in . than in srcdir.
  2181.                   -if test -f foo.info; then d=.; \
  2182.                    else d=$(srcdir); fi; \
  2183.                   $(INSTALL_DATA) $$d/foo.info $@; \
  2184.           # Run install-info only if it exists.
  2185.           # Use `if' instead of just prepending `-' to the
  2186.           # line so we notice real errors from install-info.
  2187.           # We use `$(SHELL) -c' because some shells do not
  2188.           # fail gracefully when there is an unknown command.
  2189.                   if $(SHELL) -c 'install-info --version' \
  2190.                      >/dev/null 2>&1; then \
  2191.                     install-info --dir-file=$(infodir)/dir \
  2192.                                  $(infodir)/foo.info; \
  2193.                   else true; fi
  2194. `uninstall'
  2195.      Delete all the installed files that the `install' target would
  2196.      create (but not the noninstalled files such as `make all' would
  2197.      create).
  2198.      This rule should not modify the directories where compilation is
  2199.      done, only the directories where files are installed.
  2200. `install-strip'
  2201.      Like `install', but strip the executable files while installing
  2202.      them.  The definition of this target can be very simple:
  2203.           install-strip:
  2204.                   $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \
  2205.                           install
  2206.      Normally we do not recommend stripping an executable unless you
  2207.      are sure the program has no bugs.  However, it can be reasonable
  2208.      to install a stripped executable for actual execution while saving
  2209.      the unstripped executable elsewhere in case there is a bug.
  2210. `clean'
  2211.      Delete all files from the current directory that are normally
  2212.      created by building the program.  Don't delete the files that
  2213.      record the configuration.  Also preserve files that could be made
  2214.      by building, but normally aren't because the distribution comes
  2215.      with them.
  2216.      Delete `.dvi' files here if they are not part of the distribution.
  2217. `distclean'
  2218.      Delete all files from the current directory that are created by
  2219.      configuring or building the program.  If you have unpacked the
  2220.      source and built the program without creating any other files,
  2221.      `make distclean' should leave only the files that were in the
  2222.      distribution.
  2223. `mostlyclean'
  2224.      Like `clean', but may refrain from deleting a few files that people
  2225.      normally don't want to recompile.  For example, the `mostlyclean'
  2226.      target for GCC does not delete `libgcc.a', because recompiling it
  2227.      is rarely necessary and takes a lot of time.
  2228. `maintainer-clean'
  2229.      Delete almost everything from the current directory that can be
  2230.      reconstructed with this Makefile.  This typically includes
  2231.      everything deleted by `distclean', plus more: C source files
  2232.      produced by Bison, tags tables, Info files, and so on.
  2233.      The reason we say "almost everything" is that running the command
  2234.      `make maintainer-clean' should not delete `configure' even if
  2235.      `configure' can be remade using a rule in the Makefile.  More
  2236.      generally, `make maintainer-clean' should not delete anything that
  2237.      needs to exist in order to run `configure' and then begin to build
  2238.      the program.  This is the only exception; `maintainer-clean' should
  2239.      delete everything else that can be rebuilt.
  2240.      The `maintainer-clean' target is intended to be used by a
  2241.      maintainer of the package, not by ordinary users.  You may need
  2242.      special tools to reconstruct some of the files that `make
  2243.      maintainer-clean' deletes.  Since these files are normally
  2244.      included in the distribution, we don't take care to make them easy
  2245.      to reconstruct.  If you find you need to unpack the full
  2246.      distribution again, don't blame us.
  2247.      To help make users aware of this, the commands for the special
  2248.      `maintainer-clean' target should start with these two:
  2249.           @echo 'This command is intended for maintainers to use; it'
  2250.           @echo 'deletes files that may need special tools to rebuild.'
  2251. `TAGS'
  2252.      Update a tags table for this program.
  2253. `info'
  2254.      Generate any Info files needed.  The best way to write the rules
  2255.      is as follows:
  2256.           info: foo.info
  2257.           
  2258.           foo.info: foo.texi chap1.texi chap2.texi
  2259.                   $(MAKEINFO) $(srcdir)/foo.texi
  2260.      You must define the variable `MAKEINFO' in the Makefile.  It should
  2261.      run the `makeinfo' program, which is part of the Texinfo
  2262.      distribution.
  2263. `dvi'
  2264.      Generate DVI files for all Texinfo documentation.  For example:
  2265.           dvi: foo.dvi
  2266.           
  2267.           foo.dvi: foo.texi chap1.texi chap2.texi
  2268.                   $(TEXI2DVI) $(srcdir)/foo.texi
  2269.      You must define the variable `TEXI2DVI' in the Makefile.  It should
  2270.      run the program `texi2dvi', which is part of the Texinfo
  2271.      distribution.(1)  Alternatively, write just the dependencies, and
  2272.      allow GNU `make' to provide the command.
  2273. `dist'
  2274.      Create a distribution tar file for this program.  The tar file
  2275.      should be set up so that the file names in the tar file start with
  2276.      a subdirectory name which is the name of the package it is a
  2277.      distribution for.  This name can include the version number.
  2278.      For example, the distribution tar file of GCC version 1.40 unpacks
  2279.      into a subdirectory named `gcc-1.40'.
  2280.      The easiest way to do this is to create a subdirectory
  2281.      appropriately named, use `ln' or `cp' to install the proper files
  2282.      in it, and then `tar' that subdirectory.
  2283.      Compress the tar file file with `gzip'.  For example, the actual
  2284.      distribution file for GCC version 1.40 is called `gcc-1.40.tar.gz'.
  2285.      The `dist' target should explicitly depend on all non-source files
  2286.      that are in the distribution, to make sure they are up to date in
  2287.      the distribution.  *Note Making Releases: Releases.
  2288. `check'
  2289.      Perform self-tests (if any).  The user must build the program
  2290.      before running the tests, but need not install the program; you
  2291.      should write the self-tests so that they work when the program is
  2292.      built but not installed.
  2293.    The following targets are suggested as conventional names, for
  2294. programs in which they are useful.
  2295. `installcheck'
  2296.      Perform installation tests (if any).  The user must build and
  2297.      install the program before running the tests.  You should not
  2298.      assume that `$(bindir)' is in the search path.
  2299. `installdirs'
  2300.      It's useful to add a target named `installdirs' to create the
  2301.      directories where files are installed, and their parent
  2302.      directories.  There is a script called `mkinstalldirs' which is
  2303.      convenient for this; you can find it in the Texinfo package.  You
  2304.      can use a rule like this:
  2305.           # Make sure all installation directories (e.g. $(bindir))
  2306.           # actually exist by making them if necessary.
  2307.           installdirs: mkinstalldirs
  2308.                   $(srcdir)/mkinstalldirs $(bindir) $(datadir) \
  2309.                                           $(libdir) $(infodir) \
  2310.                                           $(mandir)
  2311.      This rule should not modify the directories where compilation is
  2312.      done.  It should do nothing but create installation directories.
  2313.    ---------- Footnotes ----------
  2314.    (1)  `texi2dvi' uses TeX to do the real work of formatting. TeX is
  2315. not distributed with Texinfo.
  2316. File: standards.info,  Node: Releases,  Prev: Makefile Conventions,  Up: Managing Releases
  2317. Making Releases
  2318. ===============
  2319.    Package the distribution of Foo version 69.96 in a gzipped tar file
  2320. named `foo-69.96.tar.gz'.  It should unpack into a subdirectory named
  2321. `foo-69.96'.
  2322.    Building and installing the program should never modify any of the
  2323. files contained in the distribution.  This means that all the files
  2324. that form part of the program in any way must be classified into "source
  2325. files" and "non-source files".  Source files are written by humans and
  2326. never changed automatically; non-source files are produced from source
  2327. files by programs under the control of the Makefile.
  2328.    Naturally, all the source files must be in the distribution.  It is
  2329. okay to include non-source files in the distribution, provided they are
  2330. up-to-date and machine-independent, so that building the distribution
  2331. normally will never modify them.  We commonly include non-source files
  2332. produced by Bison, `lex', TeX, and `makeinfo'; this helps avoid
  2333. unnecessary dependencies between our distributions, so that users can
  2334. install whichever packages they want to install.
  2335.    Non-source files that might actually be modified by building and
  2336. installing the program should *never* be included in the distribution.
  2337. So if you do distribute non-source files, always make sure they are up
  2338. to date when you make a new distribution.
  2339.    Make sure that the directory into which the distribution unpacks (as
  2340. well as any subdirectories) are all world-writable (octal mode 777).
  2341. This is so that old versions of `tar' which preserve the ownership and
  2342. permissions of the files from the tar archive will be able to extract
  2343. all the files even if the user is unprivileged.
  2344.    Make sure that all the files in the distribution are world-readable.
  2345.    Make sure that no file name in the distribution is more than 14
  2346. characters long.  Likewise, no file created by building the program
  2347. should have a name longer than 14 characters.  The reason for this is
  2348. that some systems adhere to a foolish interpretation of the POSIX
  2349. standard, and refuse to open a longer name, rather than truncating as
  2350. they did in the past.
  2351.    Don't include any symbolic links in the distribution itself.  If the
  2352. tar file contains symbolic links, then people cannot even unpack it on
  2353. systems that don't support symbolic links.  Also, don't use multiple
  2354. names for one file in different directories, because certain file
  2355. systems cannot handle this and that prevents unpacking the distribution.
  2356.    Try to make sure that all the file names will be unique on MS-DOS.  A
  2357. name on MS-DOS consists of up to 8 characters, optionally followed by a
  2358. period and up to three characters.  MS-DOS will truncate extra
  2359. characters both before and after the period.  Thus, `foobarhacker.c'
  2360. and `foobarhacker.o' are not ambiguous; they are truncated to
  2361. `foobarha.c' and `foobarha.o', which are distinct.
  2362.    Include in your distribution a copy of the `texinfo.tex' you used to
  2363. test print any `*.texinfo' or `*.texi' files.
  2364.    Likewise, if your program uses small GNU software packages like
  2365. regex, getopt, obstack, or termcap, include them in the distribution
  2366. file.  Leaving them out would make the distribution file a little
  2367. smaller at the expense of possible inconvenience to a user who doesn't
  2368. know what other files to get.
  2369. Tag Table:
  2370. Node: Top
  2371. Node: Preface
  2372. Node: Intellectual Property
  2373. Node: Reading Non-Free Code
  2374. Node: Contributions
  2375. Node: Design Advice
  2376. Node: Compatibility
  2377. Node: Using Extensions
  2378. Node: ANSI C
  2379. Node: Source Language
  2380. 11096
  2381. Node: Program Behavior
  2382. 12230
  2383. Node: Semantics
  2384. 12822
  2385. Node: Libraries
  2386. 16576
  2387. Node: Errors
  2388. 17811
  2389. Node: User Interfaces
  2390. 19034
  2391. Node: Memory Usage
  2392. 36035
  2393. Node: Writing C
  2394. 37032
  2395. Node: Formatting
  2396. 37674
  2397. Node: Comments
  2398. 40946
  2399. Node: Syntactic Conventions
  2400. 43739
  2401. Node: Names
  2402. 46637
  2403. Node: System Portability
  2404. 47949
  2405. Node: CPU Portability
  2406. 49725
  2407. Node: System Functions
  2408. 51832
  2409. Node: Documentation
  2410. 56704
  2411. Node: GNU Manuals
  2412. 57248
  2413. Node: Manual Structure Details
  2414. 59290
  2415. Node: NEWS File
  2416. 60695
  2417. Node: Change Logs
  2418. 61376
  2419. Node: Man Pages
  2420. 65129
  2421. Node: Reading other Manuals
  2422. 66748
  2423. Node: Managing Releases
  2424. 67532
  2425. Node: Configuration
  2426. 68238
  2427. Node: Makefile Conventions
  2428. 75178
  2429. Node: Makefile Basics
  2430. 75702
  2431. Node: Utilities in Makefiles
  2432. 78173
  2433. Node: Command Variables
  2434. 80047
  2435. Node: Directory Variables
  2436. 82883
  2437. Node: Standard Targets
  2438. 92988
  2439. Node: Releases
  2440. 102736
  2441. End Tag Table
  2442.