home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / standards.info < prev    next >
Encoding:
GNU Info File  |  1993-06-14  |  65.0 KB  |  1,617 lines

  1. This is Info file standards.info, produced by Makeinfo-1.55 from the
  2. input file standards.texi.
  3.  
  4.    Copyright (C) 1992, 1993 Free Software Foundation Permission is
  5. granted to make and distribute verbatim copies of this manual provided
  6. the copyright notice and this permission notice are preserved on all
  7. copies.
  8.  
  9.    Permission is granted to copy and distribute modified versions of
  10. this manual under the conditions for verbatim copying, provided that
  11. the entire resulting derived work is distributed under the terms of a
  12. permission notice identical to this one.
  13.  
  14.    Permission is granted to copy and distribute translations of this
  15. manual into another language, under the above conditions for modified
  16. versions, except that this permission notice may be stated in a
  17. translation approved by the Free Software Foundation.
  18.  
  19. 
  20. File: standards.info,  Node: Top,  Next: Reading Non-Free Code,  Prev: (dir),  Up: (dir)
  21.  
  22. Version
  23. *******
  24.  
  25.    Last updated 03 Feb 1993.
  26.  
  27. * Menu:
  28.  
  29. * Reading Non-Free Code::    Referring to Proprietary Programs
  30. * Contributions::        Accepting Contributions
  31. * Change Logs::            Recording Changes
  32. * Compatibility::        Compatibility with Other Implementations
  33. * Makefile Conventions::    Makefile Conventions
  34. * Configuration::        How Configuration Should Work
  35. * Source Language::        Using Languages Other Than C
  36. * Formatting::            Formatting Your Source Code
  37. * Comments::            Commenting Your Work
  38. * Syntactic Conventions::    Clean Use of C Constructs
  39. * Names::            Naming Variables and Functions
  40. * Using Extensions::        Using Non-standard Features
  41. * Semantics::            Program Behaviour for All Programs
  42. * Errors::            Formatting Error Messages
  43. * Libraries::            Library Behaviour
  44. * Portability::            Portability As It Applies to GNU
  45. * User Interfaces::        Standards for Command Line Interfaces
  46. * Documentation::        Documenting Programs
  47. * Releases::            Making Releases
  48.  
  49. 
  50. File: standards.info,  Node: Reading Non-Free Code,  Next: Contributions,  Prev: Top,  Up: Top
  51.  
  52. Referring to Proprietary Programs
  53. *********************************
  54.  
  55.    Don't in any circumstances refer to Unix source code for or during
  56. your work on GNU!  (Or to any other proprietary programs.)
  57.  
  58.    If you have a vague recollection of the internals of a Unix program,
  59. this does not absolutely mean you can't write an imitation of it, but
  60. do try to organize the imitation internally along different lines,
  61. because this is likely to make the details of the Unix version
  62. irrelevant and dissimilar to your results.
  63.  
  64.    For example, Unix utilities were generally optimized to minimize
  65. memory use; if you go for speed instead, your program will be very
  66. different.  You could keep the entire input file in core and scan it
  67. there instead of using stdio.  Use a smarter algorithm discovered more
  68. recently than the Unix program.  Eliminate use of temporary files.  Do
  69. it in one pass instead of two (we did this in the assembler).
  70.  
  71.    Or, on the contrary, emphasize simplicity instead of speed.  For some
  72. applications, the speed of today's computers makes simpler algorithms
  73. adequate.
  74.  
  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.  
  81.    Or turn some parts of the program into independently usable
  82. libraries.  Or use a simple garbage collector instead of tracking
  83. precisely when to free memory, or use a new GNU facility such as
  84. obstacks.
  85.  
  86. 
  87. File: standards.info,  Node: Contributions,  Next: Change Logs,  Prev: Reading Non-Free Code,  Up: Top
  88.  
  89. Accepting Contributions
  90. ***********************
  91.  
  92.    If someone else sends you a piece of code to add to the program you
  93. are working on, we need legal papers to use it--the same sort of legal
  94. papers we will need to get from you.  *Each* significant contributor to
  95. a program must sign some sort of legal papers in order for us to have
  96. clear title to the program.  The main author alone is not enough.
  97.  
  98.    So, before adding in any contributions from other people, tell us so
  99. we can arrange to get the papers.  Then wait until we tell you that we
  100. have received the signed papers, before you actually use the
  101. contribution.
  102.  
  103.    This applies both before you release the program and afterward.  If
  104. you receive diffs to fix a bug, and they make significant change, we
  105. need legal papers for it.
  106.  
  107.    You don't need papers for changes of a few lines here or there, since
  108. they are not significant for copyright purposes.  Also, you don't need
  109. papers if all you get from the suggestion is some ideas, not actual code
  110. which you use.  For example, if you write a different solution to the
  111. problem, you don't need to get papers.
  112.  
  113.    I know this is frustrating; it's frustrating for us as well.  But if
  114. you don't wait, you are going out on a limb--for example, what if the
  115. contributor's employer won't sign a disclaimer?  You might have to take
  116. that code out again!
  117.  
  118.    The very worst thing is if you forget to tell us about the other
  119. contributor.  We could be very embarrassed in court some day as a
  120. result.
  121.  
  122. 
  123. File: standards.info,  Node: Change Logs,  Next: Compatibility,  Prev: Contributions,  Up: Top
  124.  
  125. Change Logs
  126. ***********
  127.  
  128.    Keep a change log for each directory, describing the changes made to
  129. source files in that directory.  The purpose of this is so that people
  130. investigating bugs in the future will know about the changes that might
  131. have introduced the bug.  Often a new bug can be found by looking at
  132. what was recently changed.  More importantly, change logs can help
  133. eliminate conceptual inconsistencies between different parts of a
  134. program; they can give you a history of how the conflicting concepts
  135. arose.
  136.  
  137.    Use the Emacs command `M-x add-change' to start a new entry in the
  138. change log.  An entry should have an asterisk, the name of the changed
  139. file, and then in parentheses the name of the changed functions,
  140. variables or whatever, followed by a colon.  Then describe the changes
  141. you made to that function or variable.
  142.  
  143.    Separate unrelated entries with blank lines.  When two entries
  144. represent parts of the same change, so that they work together, then
  145. don't put blank lines between them.  Then you can omit the file name
  146. and the asterisk when successive entries are in the same file.
  147.  
  148.    Here are some examples:
  149.  
  150.      * register.el (insert-register): Return nil.
  151.      (jump-to-register): Likewise.
  152.      
  153.      * sort.el (sort-subr): Return nil.
  154.      
  155.      * tex-mode.el (tex-bibtex-file, tex-file, tex-region):
  156.      Restart the tex shell if process is gone or stopped.
  157.      (tex-shell-running): New function.
  158.      
  159.      * expr.c (store_one_arg): Round size up for move_block_to_reg.
  160.      (expand_call): Round up when emitting USE insns.
  161.      * stmt.c (assign_parms): Round size up for move_block_from_reg.
  162.  
  163.    There's no need to describe here the full purpose of the changes or
  164. how they work together.  It is better to put this explanation in
  165. comments in the code.  That's why just "New function" is enough; there
  166. is a comment with the function in the source to explain what it does.
  167.  
  168.    However, sometimes it is useful to write one line to describe the
  169. overall purpose of a large batch of changes.
  170.  
  171.    You can think of the change log as a conceptual "undo list" which
  172. explains how earlier versions were different from the current version.
  173. People can see the current version; they don't need the change log to
  174. tell them what is in it.  What they want from a change log is a clear
  175. explanation of how the earlier version differed.
  176.  
  177.    When you change the calling sequence of a function in a simple
  178. fashion, and you change all the callers of the function, there is no
  179. need to make individual entries for all the callers.  Just write in the
  180. entry for the function being called, "All callers changed."
  181.  
  182.    When you change just comments or doc strings, it is enough to write
  183. an entry for the file, without mentioning the functions.  Write just,
  184. "Doc fix."  There's no need to keep a change log for documentation
  185. files.  This is because documentation is not susceptible to bugs that
  186. are hard to fix.  Documentation does not consist of parts that must
  187. interact in a precisely engineered fashion; to correct an error, you
  188. need not know the history of the erroneous passage.
  189.  
  190. 
  191. File: standards.info,  Node: Compatibility,  Next: Makefile Conventions,  Prev: Change Logs,  Up: Top
  192.  
  193. Compatibility with Other Implementations
  194. ****************************************
  195.  
  196.    With certain exceptions, utility programs and libraries for GNU
  197. should be upward compatible with those in Berkeley Unix, and upward
  198. compatible with ANSI C if ANSI C specifies their behavior, and upward
  199. compatible with POSIX if POSIX specifies their behavior.
  200.  
  201.    When these standards conflict, it is useful to offer compatibility
  202. modes for each of them.
  203.  
  204.    ANSI C and POSIX prohibit many kinds of extensions.  Feel free to
  205. make the extensions anyway, and include a `--ansi' or `--compatible'
  206. option to turn them off.  However, if the extension has a significant
  207. chance of breaking any real programs or scripts, then it is not really
  208. upward compatible.  Try to redesign its interface.
  209.  
  210.    When a feature is used only by users (not by programs or command
  211. files), and it is done poorly in Unix, feel free to replace it
  212. completely with something totally different and better.  (For example,
  213. vi is replaced with Emacs.)  But it is nice to offer a compatible
  214. feature as well.  (There is a free vi clone, so we offer it.)
  215.  
  216.    Additional useful features not in Berkeley Unix are welcome.
  217. Additional programs with no counterpart in Unix may be useful, but our
  218. first priority is usually to duplicate what Unix already has.
  219.  
  220. 
  221. File: standards.info,  Node: Makefile Conventions,  Next: Configuration,  Prev: Compatibility,  Up: Top
  222.  
  223. Makefile Conventions
  224. ********************
  225.  
  226.    This chapter describes conventions for writing the Makefiles for GNU
  227. programs.
  228.  
  229. * Menu:
  230.  
  231. * Makefile Basics::
  232. * Utilities in Makefiles::
  233. * Standard Targets::
  234. * Command Variables::
  235. * Directory Variables::
  236.  
  237. 
  238. File: standards.info,  Node: Makefile Basics,  Next: Utilities in Makefiles,  Up: Makefile Conventions
  239.  
  240. General Conventions for Makefiles
  241. =================================
  242.  
  243.    Every Makefile should contain this line:
  244.  
  245.      SHELL = /bin/sh
  246.  
  247. to avoid trouble on systems where the `SHELL' variable might be
  248. inherited from the environment.  (This is never a problem with GNU
  249. `make'.)
  250.  
  251.    Don't assume that `.' is in the path for command execution.  When
  252. you need to run programs that are a part of your package during the
  253. make, please make sure that it uses `./' if the program is built as
  254. part of the make or `$(srcdir)/' if the file is an unchanging part of
  255. the source code.  Without one of these prefixes, the current search
  256. path is used.
  257.  
  258.    The distinction between `./' and `$(srcdir)/' is important when
  259. using the `--srcdir' option to `configure'.  A rule of the form:
  260.  
  261.      foo.1 : foo.man sedscript
  262.              sed -e sedscript foo.man > foo.1
  263.  
  264. will fail when the current directory is not the source directory,
  265. because `foo.man' and `sedscript' are not in the current directory.
  266.  
  267.    When using GNU `make', relying on `VPATH' to find the source file
  268. will work in the case where there is a single dependency file, since
  269. the `make' automatic variable `$<' will represent the source file
  270. wherever it is.  (Many versions of `make' set `$<' only in implicit
  271. rules.)  A makefile target like
  272.  
  273.      foo.o : bar.c
  274.              $(CC) -I. -I$(srcdir) $(CFLAGS) -c bar.c -o foo.o
  275.  
  276. should instead be written as
  277.  
  278.      foo.o : bar.c
  279.              $(CC) $(CFLAGS) $< -o $@
  280.  
  281. in order to allow `VPATH' to work correctly.  When the target has
  282. multiple dependencies, using an explicit `$(srcdir)' is the easiest way
  283. to make the rule work well.  For example, the target above for `foo.1'
  284. is best written as:
  285.  
  286.      foo.1 : foo.man sedscript
  287.              sed -s $(srcdir)/sedscript $(srcdir)/foo.man > foo.1
  288.  
  289. 
  290. File: standards.info,  Node: Utilities in Makefiles,  Next: Standard Targets,  Prev: Makefile Basics,  Up: Makefile Conventions
  291.  
  292. Utilities in Makefiles
  293. ======================
  294.  
  295.    Write the Makefile commands (and any shell scripts, such as
  296. `configure') to run in `sh', not in `csh'.  Don't use any special
  297. features of `ksh' or `bash'.
  298.  
  299.    The `configure' script and the Makefile rules for building and
  300. installation should not use any utilities directly except these:
  301.  
  302.      cat cmp cp echo egrep expr grep
  303.      ln mkdir mv pwd rm rmdir sed test touch
  304.  
  305.    Stick to the generally supported options for these programs.  For
  306. example, don't use `mkdir -p', convenient as it may be, because most
  307. systems don't support it.
  308.  
  309.    The Makefile rules for building and installation can also use
  310. compilers and related programs, but should do so via `make' variables
  311. so that the user can substitute alternatives.  Here are some of the
  312. programs we mean:
  313.  
  314.      ar bison cc flex install ld lex
  315.      make makeinfo ranlib texi2dvi yacc
  316.  
  317.    When you use `ranlib', you should test whether it exists, and run it
  318. only if it exists, so that the distribution will work on systems that
  319. don't have `ranlib'.
  320.  
  321.    If you use symbolic links, you should implement a fallback for
  322. systems that don't have symbolic links.
  323.  
  324.    It is ok to use other utilities in Makefile portions (or scripts)
  325. intended only for particular systems where you know those utilities to
  326. exist.
  327.  
  328. 
  329. File: standards.info,  Node: Standard Targets,  Next: Command Variables,  Prev: Utilities in Makefiles,  Up: Makefile Conventions
  330.  
  331. Standard Targets for Users
  332. ==========================
  333.  
  334.    All GNU programs should have the following targets in their
  335. Makefiles:
  336.  
  337. `all'
  338.      Compile the entire program.  This should be the default target.
  339.      This target need not rebuild any documentation files; info files
  340.      should normally be included in the distribution, and DVI files
  341.      should be made only when explicitly asked for.
  342.  
  343. `install'
  344.      Compile the program and copy the executables, libraries, and so on
  345.      to the file names where they should reside for actual use.  If
  346.      there is a simple test to verify that a program is properly
  347.      installed then run that test.
  348.  
  349.      Use `-' before any command for installing a man page, so that
  350.      `make' will ignore any errors.  This is in case there are systems
  351.      that don't have the Unix man page documentation system installed.
  352.  
  353.      In the future, when we have a standard way of installing info
  354.      files, `install' targets will be the proper place to do so.
  355.  
  356. `uninstall'
  357.      Delete all the installed files that the `install' target would
  358.      create (but not the noninstalled files such as `make all' would
  359.      create).
  360.  
  361. `clean'
  362.      Delete all files from the current directory that are normally
  363.      created by building the program.  Don't delete the files that
  364.      record the configuration.  Also preserve files that could be made
  365.      by building, but normally aren't because the distribution comes
  366.      with them.
  367.  
  368.      Delete `.dvi' files here if they are not part of the distribution.
  369.  
  370. `distclean'
  371.      Delete all files from the current directory that are created by
  372.      configuring or building the program.  If you have unpacked the
  373.      source and built the program without creating any other files,
  374.      `make distclean' should leave only the files that were in the
  375.      distribution.
  376.  
  377. `mostlyclean'
  378.      Like `clean', but may refrain from deleting a few files that people
  379.      normally don't want to recompile.  For example, the `mostlyclean'
  380.      target for GCC does not delete `libgcc.a', because recompiling it
  381.      is rarely necessary and takes a lot of time.
  382.  
  383. `realclean'
  384.      Delete everything from the current directory that can be
  385.      reconstructed with this Makefile.  This typically includes
  386.      everything deleted by distclean, plus more: C source files
  387.      produced by Bison, tags tables, info files, and so on.
  388.  
  389.      One exception, however: `make realclean' should not delete
  390.      `configure' even if `configure' can be remade using a rule in the
  391.      Makefile.  More generally, `make realclean' should not delete
  392.      anything that needs to exist in order to run `configure' and then
  393.      begin to build the program.
  394.  
  395. `TAGS'
  396.      Update a tags table for this program.
  397.  
  398. `info'
  399.      Generate any info files needed.  The best way to write the rules
  400.      is as follows:
  401.  
  402.           info:  foo.info
  403.           
  404.           foo.info: $(srcdir)/foo.texi $(srcdir)/chap1.texi $(srcdir)/chap2.texi
  405.                   $(MAKEINFO) $(srcdir)/foo.texi
  406.  
  407.      You must define the variable `MAKEINFO' in the Makefile.  It
  408.      should run the Makeinfo program, which is part of the Texinfo2
  409.      distribution.
  410.  
  411. `dvi'
  412.      Generate DVI files for all TeXinfo documentation.  For example:
  413.  
  414.           dvi: foo.dvi
  415.           
  416.           foo.dvi: $(srcdir)/foo.texi $(srcdir)/chap1.texi $(srcdir)/chap2.texi
  417.                   $(TEXI2DVI) $(srcdir)/foo.texi
  418.  
  419.      You must define the variable `TEXI2DVI' in the Makefile.  It should
  420.      run the program `texi2dvi', which is part of the Texinfo2
  421.      distribution.  Alternatively, write just the dependencies, and
  422.      allow GNU Make to provide the command.
  423.  
  424. `dist'
  425.      Create a distribution tar file for this program.  The tar file
  426.      should be set up so that the file names in the tar file start with
  427.      a subdirectory name which is the name of the package it is a
  428.      distribution for.  This name can include the version number.
  429.  
  430.      For example, the distribution tar file of GCC version 1.40 unpacks
  431.      into a subdirectory named `gcc-1.40'.
  432.  
  433.      The easiest way to do this is to create a subdirectory
  434.      appropriately named, use `ln' or `cp' to install the proper files
  435.      in it, and then `tar' that subdirectory.
  436.  
  437.      The `dist' target should explicitly depend on all non-source files
  438.      that are in the distribution, to make sure they are up to date in
  439.      the distribution.  *Note Making Releases: (standards)Releases.
  440.  
  441. `check'
  442.      Perform self-tests (if any).  The user must build the program
  443.      before running the tests, but need not install the program; you
  444.      should write the self-tests so that they work when the program is
  445.      built but not installed.
  446.  
  447.    The following target is suggested as a conventional name, for
  448. programs in which it is useful.
  449.  
  450. `installcheck'
  451.      Perform installation tests (if any).  The user must build and
  452.      install the program before running the tests.  You should not
  453.      assume that `$(bindir)' is in the search path.
  454.  
  455. `installdirs'
  456.      It's useful to add a target named `installdirs' to create the
  457.      directories where files are installed, and their parent
  458.      directories.  You can use a rule like this:
  459.  
  460.           # Make sure all installation directories, e.g. $(bindir) actually exist by
  461.           # making them if necessary.
  462.           installdirs:
  463.                   for file in $(bindir) $(datadir) $(libdir) $(infodir) $(mandir) ; do \
  464.                      oIFS="$${IFS}"; IFS='/'; set - $${file}; IFS="$${oIFS}"; \
  465.                      pathcomp=''; test ".$${1}" = "." && shift; \
  466.                      while test $$# -ne 0 ; do \
  467.                        pathcomp="$${pathcomp}/$${1}"; shift; \
  468.                        if test ! -d "$${pathcomp}"; then \
  469.                           echo "making directory $$pathcomp" 1>&2 ; \
  470.                           mkdir "$${pathcomp}"; \
  471.                        fi; \
  472.                      done; \
  473.                   done
  474.  
  475. 
  476. File: standards.info,  Node: Command Variables,  Next: Directory Variables,  Prev: Standard Targets,  Up: Makefile Conventions
  477.  
  478. Variables for Specifying Commands
  479. =================================
  480.  
  481.    Makefiles should provide variables for overriding certain commands,
  482. options, and so on.
  483.  
  484.    In particular, you should run most utility programs via variables.
  485. Thus, if you use Bison, have a variable named `BISON' whose default
  486. value is set with `BISON = bison', and refer to it with `$(BISON)'
  487. whenever you need to use Bison.
  488.  
  489.    File management utilities such as `ln', `rm', `mv', and so on, need
  490. not be referred to through variables in this way, since users don't
  491. need to replace them with other programs.
  492.  
  493.    Each program-name variable should come with an options variable that
  494. is used to supply options to the program.  Append `FLAGS' to the
  495. program-name variable name to get the options variable name--for
  496. example, `BISONFLAGS'.  (The name `CFLAGS' is an exception to this
  497. rule, but we keep it because it is standard.)  Use `CPPFLAGS' in any
  498. compilation command that runs the preprocessor, and use `LDFLAGS' in
  499. any compilation command that does linking as well as in any direct use
  500. of `ld'.
  501.  
  502.    If there are C compiler options that *must* be used for proper
  503. compilation of certain files, do not include them in `CFLAGS'.  Users
  504. expect to be able to specify `CFLAGS' freely themselves.  Instead,
  505. arrange to pass the necessary options to the C compiler independently
  506. of `CFLAGS', by writing them explicitly in the compilation commands or
  507. by defining an implicit rule, like this:
  508.  
  509.      CFLAGS = -g
  510.      ALL_CFLAGS = -I. $(CFLAGS)
  511.      .c.o:
  512.              $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) $<
  513.  
  514.    Do include the `-g' option in `CFLAGS', because that is not
  515. *required* for proper compilation.  You can consider it a default that
  516. is only recommended.  If the package is set up so that it is compiled
  517. with GCC by default, then you might as well include `-O' in the default
  518. value of `CFLAGS' as well.
  519.  
  520.    Put `CFLAGS' last in the compilation command, after other variables
  521. containing compiler options, so the user can use `CFLAGS' to override
  522. the others.
  523.  
  524.    Every Makefile should define the variable `INSTALL', which is the
  525. basic command for installing a file into the system.
  526.  
  527.    Every Makefile should also define variables `INSTALL_PROGRAM' and
  528. `INSTALL_DATA'.  (The default for each of these should be
  529. `$(INSTALL)'.)  Then it should use those variables as the commands for
  530. actual installation, for executables and nonexecutables respectively.
  531. Use these variables as follows:
  532.  
  533.      $(INSTALL_PROGRAM) foo $(bindir)/foo
  534.      $(INSTALL_DATA) libfoo.a $(libdir)/libfoo.a
  535.  
  536. Always use a file name, not a directory name, as the second argument of
  537. the installation commands.  Use a separate command for each file to be
  538. installed.
  539.  
  540. 
  541. File: standards.info,  Node: Directory Variables,  Prev: Command Variables,  Up: Makefile Conventions
  542.  
  543. Variables for Installation Directories
  544. ======================================
  545.  
  546.    Installation directories should always be named by variables, so it
  547. is easy to install in a nonstandard place.  The standard names for these
  548. variables are:
  549.  
  550. `prefix'
  551.      A prefix used in constructing the default values of the variables
  552.      listed below.  The default value of `prefix' should be `/usr/local'
  553.      (at least for now).
  554.  
  555. `exec_prefix'
  556.      A prefix used in constructing the default values of the some of the
  557.      variables listed below.  The default value of `exec_prefix' should
  558.      be `$(prefix)'.
  559.  
  560.      Generally, `$(exec_prefix)' is used for directories that contain
  561.      machine-specific files (such as executables and subroutine
  562.      libraries), while `$(prefix)' is used directly for other
  563.      directories.
  564.  
  565. `bindir'
  566.      The directory for installing executable programs that users can
  567.      run.  This should normally be `/usr/local/bin', but write it as
  568.      `$(exec_prefix)/bin'.
  569.  
  570. `libdir'
  571.      The directory for installing executable files to be run by the
  572.      program rather than by users.  Object files and libraries of
  573.      object code should also go in this directory.  The idea is that
  574.      this directory is used for files that pertain to a specific
  575.      machine architecture, but need not be in the path for commands.
  576.      The value of `libdir' should normally be `/usr/local/lib', but
  577.      write it as `$(exec_prefix)/lib'.
  578.  
  579. `datadir'
  580.      The directory for installing read-only data files which the
  581.      programs refer to while they run.  This directory is used for
  582.      files which are independent of the type of machine being used.
  583.      This should normally be `/usr/local/lib', but write it as
  584.      `$(prefix)/lib'.
  585.  
  586. `statedir'
  587.      The directory for installing data files which the programs modify
  588.      while they run.  These files should be independent of the type of
  589.      machine being used, and it should be possible to share them among
  590.      machines at a network installation.  This should normally be
  591.      `/usr/local/lib', but write it as `$(prefix)/lib'.
  592.  
  593. `includedir'
  594.      The directory for installing header files to be included by user
  595.      programs with the C `#include' preprocessor directive.  This
  596.      should normally be `/usr/local/include', but write it as
  597.      `$(prefix)/include'.
  598.  
  599.      Most compilers other than GCC do not look for header files in
  600.      `/usr/local/include'.  So installing the header files this way is
  601.      only useful with GCC.  Sometimes this is not a problem because some
  602.      libraries are only really intended to work with GCC.  But some
  603.      libraries are intended to work with other compilers.  They should
  604.      install their header files in two places, one specified by
  605.      `includedir' and one specified by `oldincludedir'.
  606.  
  607. `oldincludedir'
  608.      The directory for installing `#include' header files for use with
  609.      compilers other than GCC.  This should normally be `/usr/include'.
  610.  
  611.      The Makefile commands should check whether the value of
  612.      `oldincludedir' is empty.  If it is, they should not try to use
  613.      it; they should cancel the second installation of the header files.
  614.  
  615.      A package should not replace an existing header in this directory
  616.      unless the header came from the same package.  Thus, if your Foo
  617.      package provides a header file `foo.h', then it should install the
  618.      header file in the `oldincludedir' directory if either (1) there
  619.      is no `foo.h' there or (2) the `foo.h' that exists came from the
  620.      Foo package.
  621.  
  622.      The way to tell whether `foo.h' came from the Foo package is to put
  623.      a magic string in the file--part of a comment--and grep for that
  624.      string.
  625.  
  626. `mandir'
  627.      The directory for installing the man pages (if any) for this
  628.      package.  It should include the suffix for the proper section of
  629.      the manual--usually `1' for a utility.
  630.  
  631. `man1dir'
  632.      The directory for installing section 1 man pages.
  633.  
  634. `man2dir'
  635.      The directory for installing section 2 man pages.
  636.  
  637. `...'
  638.      Use these names instead of `mandir' if the package needs to
  639.      install man pages in more than one section of the manual.
  640.  
  641.      *Don't make the primary documentation for any GNU software be a
  642.      man page.  Write a manual in Texinfo instead.  Man pages are just
  643.      for the sake of people running GNU software on Unix, which is a
  644.      secondary application only.*
  645.  
  646. `manext'
  647.      The file name extension for the installed man page.  This should
  648.      contain a period followed by the appropriate digit.
  649.  
  650. `infodir'
  651.      The directory for installing the info files for this package.  By
  652.      default, it should be `/usr/local/info', but it should be written
  653.      as `$(prefix)/info'.
  654.  
  655. `srcdir'
  656.      The directory for the sources being compiled.  The value of this
  657.      variable is normally inserted by the `configure' shell script.
  658.  
  659.    For example:
  660.  
  661.      # Common prefix for installation directories.
  662.      # NOTE: This directory must exist when you start the install.
  663.      prefix = /usr/local
  664.      exec_prefix = $(prefix)
  665.      # Where to put the executable for the command `gcc'.
  666.      bindir = $(exec_prefix)/bin
  667.      # Where to put the directories used by the compiler.
  668.      libdir = $(exec_prefix)/lib
  669.      # Where to put the Info files.
  670.      infodir = $(prefix)/info
  671.  
  672.    If your program installs a large number of files into one of the
  673. standard user-specified directories, it might be useful to group them
  674. into a subdirectory particular to that program.  If you do this, you
  675. should write the `install' rule to create these subdirectories.
  676.  
  677.    Do not expect the user to include the subdirectory name in the value
  678. of any of the variables listed above.  The idea of having a uniform set
  679. of variable names for installation directories is to enable the user to
  680. specify the exact same values for several different GNU packages.  In
  681. order for this to be useful, all the packages must be designed so that
  682. they will work sensibly when the user does so.
  683.  
  684. 
  685. File: standards.info,  Node: Configuration,  Next: Source Language,  Prev: Makefile Conventions,  Up: Top
  686.  
  687. How Configuration Should Work
  688. *****************************
  689.  
  690.    Each GNU distribution should come with a shell script named
  691. `configure'.  This script is given arguments which describe the kind of
  692. machine and system you want to compile the program for.
  693.  
  694.    The `configure' script must record the configuration options so that
  695. they affect compilation.
  696.  
  697.    One way to do this is to make a link from a standard name such as
  698. `config.h' to the proper configuration file for the chosen system.  If
  699. you use this technique, the distribution should *not* contain a file
  700. named `config.h'.  This is so that people won't be able to build the
  701. program without configuring it first.
  702.  
  703.    Another thing that `configure' can do is to edit the Makefile.  If
  704. you do this, the distribution should *not* contain a file named
  705. `Makefile'.  Instead, include a file `Makefile.in' which contains the
  706. input used for editing.  Once again, this is so that people won't be
  707. able to build the program without configuring it first.
  708.  
  709.    If `configure' does write the `Makefile', then `Makefile' should
  710. have a target named `Makefile' which causes `configure' to be rerun,
  711. setting up the same configuration that was set up last time.  The files
  712. that `configure' reads should be listed as dependencies of `Makefile'.
  713.  
  714.    All the files which are output from the `configure' script should
  715. have comments at the beginning explaining that they were generated
  716. automatically using `configure'.  This is so that users won't think of
  717. trying to edit them by hand.
  718.  
  719.    The `configure' script should write a file named `config.status'
  720. which describes which configuration options were specified when the
  721. program was last configured.  This file should be a shell script which,
  722. if run, will recreate the same configuration.
  723.  
  724.    The `configure' script should accept an option of the form
  725. `--srcdir=DIRNAME' to specify the directory where sources are found (if
  726. it is not the current directory).  This makes it possible to build the
  727. program in a separate directory, so that the actual source directory is
  728. not modified.
  729.  
  730.    If the user does not specify `--srcdir', then `configure' should
  731. check both `.' and `..' to see if it can find the sources.  If it finds
  732. the sources in one of these places, it should use them from there.
  733. Otherwise, it should report that it cannot find the sources, and should
  734. exit with nonzero status.
  735.  
  736.    Usually the easy way to support `--srcdir' is by editing a
  737. definition of `VPATH' into the Makefile.  Some rules may need to refer
  738. explicitly to the specified source directory.  To make this possible,
  739. `configure' can add to the Makefile a variable named `srcdir' whose
  740. value is precisely the specified directory.
  741.  
  742.    The `configure' script should also take an argument which specifies
  743. the type of system to build the program for.  This argument should look
  744. like this:
  745.  
  746.      CPU-COMPANY-SYSTEM
  747.  
  748.    For example, a Sun 3 might be `m68k-sun-sunos4.1'.
  749.  
  750.    The `configure' script needs to be able to decode all plausible
  751. alternatives for how to describe a machine.  Thus, `sun3-sunos4.1'
  752. would be a valid alias.  So would `sun3-bsd4.2', since SunOS is
  753. basically BSD and no other BSD system is used on a Sun.  For many
  754. programs, `vax-dec-ultrix' would be an alias for `vax-dec-bsd', simply
  755. because the differences between Ultrix and BSD are rarely noticeable,
  756. but a few programs might need to distinguish them.
  757.  
  758.    There is a shell script called `config.sub' that you can use as a
  759. subroutine to validate system types and canonicalize aliases.
  760.  
  761.    Other options are permitted to specify in more detail the software
  762. or hardware are present on the machine:
  763.  
  764. `--with-PACKAGE'
  765.      The package PACKAGE will be installed, so configure this package
  766.      to work with PACKAGE.
  767.  
  768.      Possible values of PACKAGE include `x', `gnu-as' (or `gas'),
  769.      `gnu-ld', `gnu-libc', and `gdb'.
  770.  
  771. `--nfp'
  772.      The target machine has no floating point processor.
  773.  
  774. `--gas'
  775.      The target machine assembler is GAS, the GNU assembler.  This is
  776.      obsolete; use `--with-gnu-as' instead.
  777.  
  778. `--x'
  779.      The target machine has the X Window System installed.  This is
  780.      obsolete; use `--with-x' instead.
  781.  
  782.    All `configure' scripts should accept all of these "detail" options,
  783. whether or not they make any difference to the particular package at
  784. hand.  In particular, they should accept any option that starts with
  785. `--with-'.  This is so users will be able to configure an entire GNU
  786. source tree at once with a single set of options.
  787.  
  788.    Packages that perform part of compilation may support
  789. cross-compilation.  In such a case, the host and target machines for
  790. the program may be different.  The `configure' script should normally
  791. treat the specified type of system as both the host and the target,
  792. thus producing a program which works for the same type of machine that
  793. it runs on.
  794.  
  795.    The way to build a cross-compiler, cross-assembler, or what have
  796. you, is to specify the option `--host=HOSTTYPE' when running
  797. `configure'.  This specifies the host system without changing the type
  798. of target system.  The syntax for HOSTTYPE is the same as described
  799. above.
  800.  
  801.    Programs for which cross-operation is not meaningful need not accept
  802. the `--host' option, because configuring an entire operating system for
  803. cross-operation is not a meaningful thing.
  804.  
  805.    Some programs have ways of configuring themselves automatically.  If
  806. your program is set up to do this, your `configure' script can simply
  807. ignore most of its arguments.
  808.  
  809. 
  810. File: standards.info,  Node: Source Language,  Next: Formatting,  Prev: Configuration,  Up: Top
  811.  
  812. Using Languages Other Than C
  813. ****************************
  814.  
  815.    Using a language other than C is like using a non-standard feature:
  816. it will cause trouble for users.  Even if GCC supports the other
  817. language, users may find it inconvenient to have to install the
  818. compiler for that other language in order to build your program.  So
  819. please write in C.
  820.  
  821.    There are three exceptions for this rule:
  822.  
  823.    * It is okay to use a special language if the same program contains
  824.      an interpreter for that language.
  825.  
  826.      Thus, it is not a problem that GNU Emacs contains code written in
  827.      Emacs Lisp, because it comes with a Lisp interpreter.
  828.  
  829.    * It is okay to use another language in a tool specifically intended
  830.      for use with that language.
  831.  
  832.      This is okay because the only people who want to build the tool
  833.      will be those who have installed the other language anyway.
  834.  
  835.    * If an application is not of extremely widespread interest, then
  836.      perhaps it's not important if the application is inconvenient to
  837.      install.
  838.  
  839. 
  840. File: standards.info,  Node: Formatting,  Next: Comments,  Prev: Source Language,  Up: Top
  841.  
  842. Formatting Your Source Code
  843. ***************************
  844.  
  845.    It is important to put the open-brace that starts the body of a C
  846. function in column zero, and avoid putting any other open-brace or
  847. open-parenthesis or open-bracket in column zero.  Several tools look
  848. for open-braces in column zero to find the beginnings of C functions.
  849. These tools will not work on code not formatted that way.
  850.  
  851.    It is also important for function definitions to start the name of
  852. the function in column zero.  This helps people to search for function
  853. definitions, and may also help certain tools recognize them.  Thus, the
  854. proper format is this:
  855.  
  856.      static char *
  857.      concat (s1, s2)        /* Name starts in column zero here */
  858.           char *s1, *s2;
  859.      {                     /* Open brace in column zero here */
  860.        ...
  861.      }
  862.  
  863. or, if you want to use ANSI C, format the definition like this:
  864.  
  865.      static char *
  866.      concat (char *s1, char *s2)
  867.      {
  868.        ...
  869.      }
  870.  
  871.    In ANSI C, if the arguments don't fit nicely on one line, split it
  872. like this:
  873.  
  874.      int
  875.      lots_of_args (int an_integer, long a_long, short a_short,
  876.                    double a_double, float a_float)
  877.      ...
  878.  
  879.    For the body of the function, we prefer code formatted like this:
  880.  
  881.      if (x < foo (y, z))
  882.        haha = bar[4] + 5;
  883.      else
  884.        {
  885.          while (z)
  886.            {
  887.              haha += foo (z, z);
  888.              z--;
  889.            }
  890.          return ++x + bar ();
  891.        }
  892.  
  893.    We find it easier to read a program when it has spaces before the
  894. open-parentheses and after the commas.  Especially after the commas.
  895.  
  896.    When you split an expression into multiple lines, split it before an
  897. operator, not after one.  Here is the right way:
  898.  
  899.      if (foo_this_is_long && bar > win (x, y, z)
  900.          && remaining_condition)
  901.  
  902.    Try to avoid having two operators of different precedence at the same
  903. level of indentation.  For example, don't write this:
  904.  
  905.      mode = (inmode[j] == VOIDmode
  906.              || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
  907.              ? outmode[j] : inmode[j]);
  908.  
  909.    Instead, use extra parentheses so that the indentation shows the
  910. nesting:
  911.  
  912.      mode = ((inmode[j] == VOIDmode
  913.               || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
  914.              ? outmode[j] : inmode[j]);
  915.  
  916.    Insert extra parentheses so that Emacs will indent the code properly.
  917. For example, the following indentation looks nice if you do it by hand,
  918. but Emacs would mess it up:
  919.  
  920.      v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
  921.          + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
  922.  
  923.    But adding a set of parentheses solves the problem:
  924.  
  925.      v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
  926.           + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
  927.  
  928.    Format do-while statements like this:
  929.  
  930.      do
  931.        {
  932.          a = foo (a);
  933.        }
  934.      while (a > 0);
  935.  
  936.    Please use formfeed characters (control-L) to divide the program into
  937. pages at logical places (but not within a function).  It does not matter
  938. just how long the pages are, since they do not have to fit on a printed
  939. page.  The formfeeds should appear alone on lines by themselves.
  940.  
  941. 
  942. File: standards.info,  Node: Comments,  Next: Syntactic Conventions,  Prev: Formatting,  Up: Top
  943.  
  944. Commenting Your Work
  945. ********************
  946.  
  947.    Every program should start with a comment saying briefly what it is
  948. for.  Example: `fmt - filter for simple filling of text'.
  949.  
  950.    Please put a comment on each function saying what the function does,
  951. what sorts of arguments it gets, and what the possible values of
  952. arguments mean and are used for.  It is not necessary to duplicate in
  953. words the meaning of the C argument declarations, if a C type is being
  954. used in its customary fashion.  If there is anything nonstandard about
  955. its use (such as an argument of type `char *' which is really the
  956. address of the second character of a string, not the first), or any
  957. possible values that would not work the way one would expect (such as,
  958. that strings containing newlines are not guaranteed to work), be sure
  959. to say so.
  960.  
  961.    Also explain the significance of the return value, if there is one.
  962.  
  963.    Please put two spaces after the end of a sentence in your comments,
  964. so that the Emacs sentence commands will work.  Also, please write
  965. complete sentences and capitalize the first word.  If a lower-case
  966. identifer comes at the beginning of a sentence, don't capitalize it!
  967. Changing the spelling makes it a different identifier.  If you don't
  968. like starting a sentence with a lower case letter, write the sentence
  969. differently (e.g. "The identifier lower-case is ...").
  970.  
  971.    The comment on a function is much clearer if you use the argument
  972. names to speak about the argument values.  The variable name itself
  973. should be lower case, but write it in upper case when you are speaking
  974. about the value rather than the variable itself.  Thus, "the inode
  975. number NODE_NUM" rather than "an inode".
  976.  
  977.    There is usually no purpose in restating the name of the function in
  978. the comment before it, because the reader can see that for himself.
  979. There might be an exception when the comment is so long that the
  980. function itself would be off the bottom of the screen.
  981.  
  982.    There should be a comment on each static variable as well, like this:
  983.  
  984.      /* Nonzero means truncate lines in the display;
  985.         zero means continue them.  */
  986.      
  987.      int truncate_lines;
  988.  
  989.    Every `#endif' should have a comment, except in the case of short
  990. conditionals (just a few lines) that are not nested.  The comment should
  991. state the condition of the conditional that is ending, *including its
  992. sense*.  `#else' should have a comment describing the condition *and
  993. sense* of the code that follows.  For example:
  994.  
  995.      #ifdef foo
  996.        ...
  997.      #else /* not foo */
  998.        ...
  999.      #endif /* not foo */
  1000.  
  1001. but, by contrast, write the comments this way for a `#ifndef':
  1002.  
  1003.      #ifndef foo
  1004.        ...
  1005.      #else /* foo */
  1006.        ...
  1007.      #endif /* foo */
  1008.  
  1009. 
  1010. File: standards.info,  Node: Syntactic Conventions,  Next: Names,  Prev: Comments,  Up: Top
  1011.  
  1012. Clean Use of C Constructs
  1013. *************************
  1014.  
  1015.    Please explicitly declare all arguments to functions.  Don't omit
  1016. them just because they are ints.
  1017.  
  1018.    Declarations of external functions and functions to appear later in
  1019. the source file should all go in one place near the beginning of the
  1020. file (somewhere before the first function definition in the file), or
  1021. else should go in a header file.  Don't put extern declarations inside
  1022. functions.
  1023.  
  1024.    It used to be common practice to use the same local variables (with
  1025. names like `tem') over and over for different values within one
  1026. function.  Instead of doing this, it is better declare a separate local
  1027. variable for each distinct purpose, and give it a name which is
  1028. meaningful.  This not only makes programs easier to understand, it also
  1029. facilitates optimization by good compilers.  You can also move the
  1030. declaration of each local variable into the smallest scope that includes
  1031. all its uses.  This makes the program even cleaner.
  1032.  
  1033.    Don't use local variables or parameters that shadow global
  1034. identifiers.
  1035.  
  1036.    Don't declare multiple variables in one declaration that spans lines.
  1037. Start a new declaration on each line, instead.  For example, instead of
  1038. this:
  1039.  
  1040.      int    foo,
  1041.             bar;
  1042.  
  1043. write either this:
  1044.  
  1045.      int foo, bar;
  1046.  
  1047. or this:
  1048.  
  1049.      int foo;
  1050.      int bar;
  1051.  
  1052. (If they are global variables, each should have a comment preceding it
  1053. anyway.)
  1054.  
  1055.    When you have an if-else statement nested in another if statement,
  1056. always put braces around the if-else.  Thus, never write like this:
  1057.  
  1058.      if (foo)
  1059.        if (bar)
  1060.          win ();
  1061.        else
  1062.          lose ();
  1063.  
  1064. always like this:
  1065.  
  1066.      if (foo)
  1067.        {
  1068.          if (bar)
  1069.            win ();
  1070.          else
  1071.            lose ();
  1072.        }
  1073.  
  1074.    If you have an if statement nested inside of an else statement,
  1075. either write `else if' on one line, like this,
  1076.  
  1077.      if (foo)
  1078.        ...
  1079.      else if (bar)
  1080.        ...
  1081.  
  1082. with its then-part indented like the preceding then-part, or write the
  1083. nested if within braces like this:
  1084.  
  1085.      if (foo)
  1086.        ...
  1087.      else
  1088.        {
  1089.          if (bar)
  1090.            ...
  1091.        }
  1092.  
  1093.    Don't declare both a structure tag and variables or typedefs in the
  1094. same declaration.  Instead, declare the structure tag separately and
  1095. then use it to declare the variables or typedefs.
  1096.  
  1097.    Try to avoid assignments inside if-conditions.  For example, don't
  1098. write this:
  1099.  
  1100.      if ((foo = (char *) malloc (sizeof *foo)) == 0)
  1101.        fatal ("virtual memory exhausted");
  1102.  
  1103. instead, write this:
  1104.  
  1105.      foo = (char *) malloc (sizeof *foo);
  1106.      if (foo == 0)
  1107.        fatal ("virtual memory exhausted");
  1108.  
  1109.    Don't make the program ugly to placate lint.  Please don't insert any
  1110. casts to void.  Zero without a cast is perfectly fine as a null pointer
  1111. constant.
  1112.  
  1113. 
  1114. File: standards.info,  Node: Names,  Next: Using Extensions,  Prev: Syntactic Conventions,  Up: Top
  1115.  
  1116. Naming Variables and Functions
  1117. ******************************
  1118.  
  1119.    Please use underscores to separate words in a name, so that the Emacs
  1120. word commands can be useful within them.  Stick to lower case; reserve
  1121. upper case for macros and enum constants, and for name-prefixes that
  1122. follow a uniform convention.
  1123.  
  1124.    For example, you should use names like `ignore_space_change_flag';
  1125. don't use names like `iCantReadThis'.
  1126.  
  1127.    Variables that indicate whether command-line options have been
  1128. specified should be named after the meaning of the option, not after
  1129. the option-letter.  A comment should state both the exact meaning of
  1130. the option and its letter.  For example,
  1131.  
  1132.      /* Ignore changes in horizontal whitespace (-b).  */
  1133.      int ignore_space_change_flag;
  1134.  
  1135.    When you want to define names with constant integer values, use
  1136. `enum' rather than `#define'.  GDB knows about enumeration constants.
  1137.  
  1138.    Use file names of 14 characters or less, to avoid creating gratuitous
  1139. problems on System V.
  1140.  
  1141. 
  1142. File: standards.info,  Node: Using Extensions,  Next: Semantics,  Prev: Names,  Up: Top
  1143.  
  1144. Using Non-standard Features
  1145. ***************************
  1146.  
  1147.    Many GNU facilities that already exist support a number of convenient
  1148. extensions over the comparable Unix facilities.  Whether to use these
  1149. extensions in implementing your program is a difficult question.
  1150.  
  1151.    On the one hand, using the extensions can make a cleaner program.
  1152. On the other hand, people will not be able to build the program unless
  1153. the other GNU tools are available.  This might cause the program to
  1154. work on fewer kinds of machines.
  1155.  
  1156.    With some extensions, it might be easy to provide both alternatives.
  1157. For example, you can define functions with a "keyword" `INLINE' and
  1158. define that as a macro to expand into either `inline' or nothing,
  1159. depending on the compiler.
  1160.  
  1161.    In general, perhaps it is best not to use the extensions if you can
  1162. straightforwardly do without them, but to use the extensions if they
  1163. are a big improvement.
  1164.  
  1165.    An exception to this rule are the large, established programs (such
  1166. as Emacs) which run on a great variety of systems.  Such programs would
  1167. be broken by use of GNU extensions.
  1168.  
  1169.    Another exception is for programs that are used as part of
  1170. compilation: anything that must be compiled with other compilers in
  1171. order to bootstrap the GNU compilation facilities.  If these require
  1172. the GNU compiler, then no one can compile them without having them
  1173. installed already.  That would be no good.
  1174.  
  1175.    Since most computer systems do not yet implement ANSI C, using the
  1176. ANSI C features is effectively using a GNU extension, so the same
  1177. considerations apply.  (Except for ANSI features that we discourage,
  1178. such as trigraphs--don't ever use them.)
  1179.  
  1180. 
  1181. File: standards.info,  Node: Semantics,  Next: Errors,  Prev: Using Extensions,  Up: Top
  1182.  
  1183. Program Behaviour for All Programs
  1184. **********************************
  1185.  
  1186.    Avoid arbitrary limits on the length or number of *any* data
  1187. structure, including filenames, lines, files, and symbols, by allocating
  1188. all data structures dynamically.  In most Unix utilities, "long lines
  1189. are silently truncated".  This is not acceptable in a GNU utility.
  1190.  
  1191.    Utilities reading files should not drop NUL characters, or any other
  1192. nonprinting characters *including those with codes above 0177*.  The
  1193. only sensible exceptions would be utilities specifically intended for
  1194. interface to certain types of printers that can't handle those
  1195. characters.
  1196.  
  1197.    Check every system call for an error return, unless you know you
  1198. wish to ignore errors.  Include the system error text (from `perror' or
  1199. equivalent) in *every* error message resulting from a failing system
  1200. call, as well as the name of the file if any and the name of the
  1201. utility.  Just "cannot open foo.c" or "stat failed" is not sufficient.
  1202.  
  1203.    Check every call to `malloc' or `realloc' to see if it returned
  1204. zero.  Check `realloc' even if you are making the block smaller; in a
  1205. system that rounds block sizes to a power of 2, `realloc' may get a
  1206. different block if you ask for less space.
  1207.  
  1208.    In Unix, `realloc' can destroy the storage block if it returns zero.
  1209. GNU `realloc' does not have this bug: if it fails, the original block
  1210. is unchanged.  Feel free to assume the bug is fixed.  If you wish to
  1211. run your program on Unix, and wish to avoid lossage in this case, you
  1212. can use the GNU `malloc'.
  1213.  
  1214.    You must expect `free' to alter the contents of the block that was
  1215. freed.  Anything you want to fetch from the block, you must fetch before
  1216. calling `free'.
  1217.  
  1218.    Use `getopt_long' to decode arguments, unless the argument syntax
  1219. makes this unreasonable.
  1220.  
  1221.    When static storage is to be written in during program execution, use
  1222. explicit C code to initialize it.  Reserve C initialized declarations
  1223. for data that will not be changed.
  1224.  
  1225.    Try to avoid low-level interfaces to obscure Unix data structures
  1226. (such as file directories, utmp, or the layout of kernel memory), since
  1227. these are less likely to work compatibly.  If you need to find all the
  1228. files in a directory, use `readdir' or some other high-level interface.
  1229. These will be supported compatibly by GNU.
  1230.  
  1231.    By default, the GNU system will provide the signal handling
  1232. functions of BSD and of POSIX.  So GNU software should be written to use
  1233. these.
  1234.  
  1235.    In error checks that detect "impossible" conditions, just abort.
  1236. There is usually no point in printing any message.  These checks
  1237. indicate the existence of bugs.  Whoever wants to fix the bugs will have
  1238. to read the source code and run a debugger.  So explain the problem with
  1239. comments in the source.  The relevant data will be in variables, which
  1240. are easy to examine with the debugger, so there is no point moving them
  1241. elsewhere.
  1242.  
  1243. 
  1244. File: standards.info,  Node: Errors,  Next: Libraries,  Prev: Semantics,  Up: Top
  1245.  
  1246. Formatting Error Messages
  1247. *************************
  1248.  
  1249.    Error messages from compilers should look like this:
  1250.  
  1251.      SOURCE-FILE-NAME:LINENO: MESSAGE
  1252.  
  1253.    Error messages from other noninteractive programs should look like
  1254. this:
  1255.  
  1256.      PROGRAM:SOURCE-FILE-NAME:LINENO: MESSAGE
  1257.  
  1258. when there is an appropriate source file, or like this:
  1259.  
  1260.      PROGRAM: MESSAGE
  1261.  
  1262. when there is no relevant source file.
  1263.  
  1264.    In an interactive program (one that is reading commands from a
  1265. terminal), it is better not to include the program name in an error
  1266. message.  The place to indicate which program is running is in the
  1267. prompt or with the screen layout.  (When the same program runs with
  1268. input from a source other than a terminal, it is not interactive and
  1269. would do best to print error messages using the noninteractive style.)
  1270.  
  1271.    The string MESSAGE should not begin with a capital letter when it
  1272. follows a program name and/or filename.  Also, it should not end with a
  1273. period.
  1274.  
  1275.    Error messages from interactive programs, and other messages such as
  1276. usage messages, should start with a capital letter.  But they should not
  1277. end with a period.
  1278.  
  1279. 
  1280. File: standards.info,  Node: Libraries,  Next: Portability,  Prev: Errors,  Up: Top
  1281.  
  1282. Library Behaviour
  1283. *****************
  1284.  
  1285.    Try to make library functions reentrant.  If they need to do dynamic
  1286. storage allocation, at least try to avoid any nonreentrancy aside from
  1287. that of `malloc' itself.
  1288.  
  1289.    Here are certain name conventions for libraries, to avoid name
  1290. conflicts.
  1291.  
  1292.    Choose a name prefix for the library, more than two characters long.
  1293. All external function and variable names should start with this prefix.
  1294. In addition, there should only be one of these in any given library
  1295. member.  This usually means putting each one in a separate source file.
  1296.  
  1297.    An exception can be made when two external symbols are always used
  1298. together, so that no reasonable program could use one without the
  1299. other; then they can both go in the same file.
  1300.  
  1301.    External symbols that are not documented entry points for the user
  1302. should have names beginning with `_'.  They should also contain the
  1303. chosen name prefix for the library, to prevent collisions with other
  1304. libraries.  These can go in the same files with user entry points if
  1305. you like.
  1306.  
  1307.    Static functions and variables can be used as you like and need not
  1308. fit any naming convention.
  1309.  
  1310. 
  1311. File: standards.info,  Node: Portability,  Next: User Interfaces,  Prev: Libraries,  Up: Top
  1312.  
  1313. Portability As It Applies to GNU
  1314. ********************************
  1315.  
  1316.    Much of what is called "portability" in the Unix world refers to
  1317. porting to different Unix versions.  This is a secondary consideration
  1318. for GNU software, because its primary purpose is to run on top of one
  1319. and only one kernel, the GNU kernel, compiled with one and only one C
  1320. compiler, the GNU C compiler.  The amount and kinds of variation among
  1321. GNU systems on different cpu's will be like the variation among Berkeley
  1322. 4.3 systems on different cpu's.
  1323.  
  1324.    All users today run GNU software on non-GNU systems.  So supporting a
  1325. variety of non-GNU systems is desirable; simply not paramount.  The
  1326. easiest way to achieve portability to a reasonable range of systems is
  1327. to use Autoconf.  It's unlikely that your program needs to know more
  1328. information about the host machine than Autoconf can provide, simply
  1329. because most of the programs that need such knowledge have already been
  1330. written.
  1331.  
  1332.    It is difficult to be sure exactly what facilities the GNU kernel
  1333. will provide, since it isn't finished yet.  Therefore, assume you can
  1334. use anything in 4.3; just avoid using the format of semi-internal data
  1335. bases (e.g., directories) when there is a higher-level alternative
  1336. (readdir).
  1337.  
  1338.    You can freely assume any reasonably standard facilities in the C
  1339. language, libraries or kernel, because we will find it necessary to
  1340. support these facilities in the full GNU system, whether or not we have
  1341. already done so.  The fact that there may exist kernels or C compilers
  1342. that lack these facilities is irrelevant as long as the GNU kernel and
  1343. C compiler support them.
  1344.  
  1345.    It remains necessary to worry about differences among cpu types, such
  1346. as the difference in byte ordering and alignment restrictions.  It's
  1347. unlikely that 16-bit machines will ever be supported by GNU, so there
  1348. is no point in spending any time to consider the possibility that an
  1349. int will be less than 32 bits.
  1350.  
  1351.    You can assume that all pointers have the same format, regardless of
  1352. the type they point to, and that this is really an integer.  There are
  1353. some weird machines where this isn't true, but they aren't important;
  1354. don't waste time catering to them.  Besides, eventually we will put
  1355. function prototypes into all GNU programs, and that will probably make
  1356. your program work even on weird machines.
  1357.  
  1358.    Since some important machines (including the 68000) are big-endian,
  1359. it is important not to assume that the address of an int object is also
  1360. the address of its least-significant byte.  Thus, don't make the
  1361. following mistake:
  1362.  
  1363.      int c;
  1364.      ...
  1365.      while ((c = getchar()) != EOF)
  1366.              write(file_descriptor, &c, 1);
  1367.  
  1368.    You can assume that it is reasonable to use a meg of memory.  Don't
  1369. strain to reduce memory usage unless it can get to that level.  If your
  1370. program creates complicated data structures, just make them in core and
  1371. give a fatal error if malloc returns zero.
  1372.  
  1373.    If a program works by lines and could be applied to arbitrary
  1374. user-supplied input files, it should keep only a line in memory, because
  1375. this is not very hard and users will want to be able to operate on input
  1376. files that are bigger than will fit in core all at once.
  1377.  
  1378. 
  1379. File: standards.info,  Node: User Interfaces,  Next: Documentation,  Prev: Portability,  Up: Top
  1380.  
  1381. Standards for Command Line Interfaces
  1382. *************************************
  1383.  
  1384.    Please don't make the behavior of a utility depend on the name used
  1385. to invoke it.  It is useful sometimes to make a link to a utility with
  1386. a different name, and that should not change what it does.
  1387.  
  1388.    Instead, use a run time option or a compilation switch or both to
  1389. select among the alternate behaviors.
  1390.  
  1391.    Likewise, please don't make the behavior of the program depend on the
  1392. type of output device it is used with.  Device independence is an
  1393. important principle of the system's design; do not compromise it merely
  1394. to save someone from typing an option now and then.
  1395.  
  1396.    If you think one behavior is most useful when the output is to a
  1397. terminal, and another is most useful when the output is a file or a
  1398. pipe, then it is usually best to make the default behavior the one that
  1399. is useful with output to a terminal, and have an option for the other
  1400. behavior.
  1401.  
  1402.    Compatibility requires certain programs to depend on the type of
  1403. output device.  It would be disastrous if `ls' or `sh' did not do so in
  1404. the way all users expect.  In some of these cases, we supplement the
  1405. program with a preferred alternate version that does not depend on the
  1406. output device type.  For example, we provide a `dir' program much like
  1407. `ls' except that its default output format is always multi-column
  1408. format.
  1409.  
  1410.    It is a good idea to follow the POSIX guidelines for the
  1411. command-line options of a program.  The easiest way to do this is to use
  1412. `getopt' to parse them.  Note that the GNU version of `getopt' will
  1413. normally permit options anywhere among the arguments unless the special
  1414. argument `--' is used.  This is not what POSIX specifies; it is a GNU
  1415. extension.
  1416.  
  1417.    Please define long-named options that are equivalent to the
  1418. single-letter Unix-style options.  We hope to make GNU more user
  1419. friendly this way.  This is easy to do with the GNU function
  1420. `getopt_long'.
  1421.  
  1422.    One of the advantages of long-named options is that they can be
  1423. consistent from program to program.  For example, users should be able
  1424. to expect the "verbose" option of any GNU program which has one, to be
  1425. spelled precisely `--verbose'.  To achieve this uniformity, look at the
  1426. table of common long-option names when you choose the option names for
  1427. your program.  The table is in the file `longopts.table'.
  1428.  
  1429.    If you use names not already in the table, please send
  1430. `gnu@prep.ai.mit.edu' a list of them, with their meanings, so we can
  1431. update the table.
  1432.  
  1433.    It is usually a good idea for file names given as ordinary arguments
  1434. to be input files only; any output files would be specified using
  1435. options (preferably `-o').  Even if you allow an output file name as an
  1436. ordinary argument for compatibility, try to provide a suitable option
  1437. as well.  This will lead to more consistency among GNU utilities, so
  1438. that there are fewer idiosyncracies for users to remember.
  1439.  
  1440.    Programs should support an option `--version' which prints the
  1441. program's version number on standard output and exits successfully, and
  1442. an option `--help' which prints option usage information on standard
  1443. output and exits successfully.  These options should inhibit the normal
  1444. function of the command; they should do nothing except print the
  1445. requested information.
  1446.  
  1447. 
  1448. File: standards.info,  Node: Documentation,  Next: Releases,  Prev: User Interfaces,  Up: Top
  1449.  
  1450. Documenting Programs
  1451. ********************
  1452.  
  1453.    Please use Texinfo for documenting GNU programs.  See the Texinfo
  1454. manual, either the hardcopy or the version in the GNU Emacs Info
  1455. subsystem (`C-h i').  See existing GNU Texinfo files (e.g. those under
  1456. the `man/' directory in the GNU Emacs Distribution) for examples.
  1457.  
  1458.    The title page of the manual should state the version of the program
  1459. which the manual applies to.  The Top node of the manual should also
  1460. contain this information.  If the manual is changing more frequently
  1461. than or independent of the program, also state a version number for the
  1462. manual in both of these places.
  1463.  
  1464.    The manual should document all command-line arguments and all
  1465. commands.  It should give examples of their use.  But don't organize
  1466. the manual as a list of features.  Instead, organize it by the concepts
  1467. a user will have before reaching that point in the manual.  Address the
  1468. goals that a user will have in mind, and explain how to accomplish
  1469. them.  Don't use Unix man pages as a model for how to write GNU
  1470. documentation; they are a bad example to follow.
  1471.  
  1472.    The manual should have a node named `PROGRAM Invocation', `PROGRAM
  1473. Invoke' or `Invoking PROGRAM', where PROGRAM stands for the name of the
  1474. program being described, as you would type it in the shell to run the
  1475. program.  This node (together with its subnodes if any) should describe
  1476. the program's command line arguments and how to run it (the sort of
  1477. information people would look in a man page for).  Start with an
  1478. `@example' containing a template for all the options and arguments that
  1479. the program uses.
  1480.  
  1481.    Alternatively, put a menu item in some menu whose item name fits one
  1482. of the above patterns.  This identifies the node which that item points
  1483. to as the node for this purpose, regardless of the node's actual name.
  1484.  
  1485.    There will be automatic features for specifying a program name and
  1486. quickly reading just this part of its manual.
  1487.  
  1488.    If one manual describes several programs, it should have such a node
  1489. for each program described.
  1490.  
  1491.    In addition to its manual, the package should have a file named
  1492. `NEWS' which contains a list of user-visible changes worth mentioning.
  1493. In each new release, add items to the front of the file and identify
  1494. the version they pertain to.  Don't discard old items; leave them in
  1495. the file after the newer items.  This way, a user upgrading from any
  1496. previous version can see what is new.
  1497.  
  1498.    If the `NEWS' file gets very long, move some of the older items into
  1499. a file named `ONEWS' and put a note at the end referring the user to
  1500. that file.
  1501.  
  1502.    It is ok to supply a man page for the program as well as a Texinfo
  1503. manual if you wish to.  But keep in mind that supporting a man page
  1504. requires continual effort, each time the program is changed.  Any time
  1505. you spend on the man page is time taken away from more useful things you
  1506. could contribute.
  1507.  
  1508.    Thus, even if a user volunteers to donate a man page, you may find
  1509. this gift costly to accept.  Unless you have time on your hands, it may
  1510. be better to refuse the man page unless the same volunteer agrees to
  1511. take full responsibility for maintaining it--so that you can wash your
  1512. hands of it entirely.  If the volunteer ceases to do the job, then
  1513. don't feel obliged to pick it up yourself; it may be better to withdraw
  1514. the man page until another volunteer offers to carry on with it.
  1515.  
  1516.    Alternatively, if you expect the discrepancies to be small enough
  1517. that the man page remains useful, put a prominent note near the
  1518. beginning of the man page explaining that you don't maintain it and
  1519. that the Texinfo manual is more authoritative, and describing how to
  1520. access the Texinfo documentation.
  1521.  
  1522. 
  1523. File: standards.info,  Node: Releases,  Prev: Documentation,  Up: Top
  1524.  
  1525. Making Releases
  1526. ***************
  1527.  
  1528.    Package the distribution of Foo version 69.96 in a tar file named
  1529. `foo-69.96.tar'.  It should unpack into a subdirectory named
  1530. `foo-69.96'.
  1531.  
  1532.    Building and installing the program should never modify any of the
  1533. files contained in the distribution.  This means that all the files
  1534. that form part of the program in any way must be classified into "source
  1535. files" and "non-source files".  Source files are written by humans and
  1536. never changed automatically; non-source files are produced from source
  1537. files by programs under the control of the Makefile.
  1538.  
  1539.    Naturally, all the source files must be in the distribution.  It is
  1540. okay to include non-source files in the distribution, provided they are
  1541. up-to-date and machine-independent, so that building the distribution
  1542. normally will never modify them.  We commonly included non-source files
  1543. produced by Bison, Lex, TeX, and Makeinfo; this helps avoid unnecessary
  1544. dependencies between our distributions, so that users can install
  1545. whichever packages they want to install.
  1546.  
  1547.    Non-source files that might actually be modified by building and
  1548. installing the program should *never* be included in the distribution.
  1549. So if you do distribute non-source files, always make sure they are up
  1550. to date when you make a new distribution.
  1551.  
  1552.    Make sure that the directory into which the distribution unpacks (as
  1553. well as any subdirectories) are all world-writable (octal mode 777).
  1554. This is so that old versions of `tar' which preserve the ownership and
  1555. permissions of the files from the tar archive will be able to extract
  1556. all the files even if the user is unprivileged.
  1557.  
  1558.    Make sure that no file name in the distribution is more than 14
  1559. characters long.  Likewise, no file created by building the program
  1560. should have a name longer than 14 characters.  The reason for this is
  1561. that some systems adhere to a foolish interpretation of the POSIX
  1562. standard, and refuse to open a longer name, rather than truncating as
  1563. they did in the past.
  1564.  
  1565.    Don't include any symbolic links in the distribution itself.  If the
  1566. tar file contains symbolic links, then people cannot even unpack it on
  1567. systems that don't support symbolic links.  Also, don't use multiple
  1568. names for one file in different directories, because certain file
  1569. systems cannot handle this and that prevents unpacking the distribution.
  1570.  
  1571.    Try to make sure that all the file names will be unique on MS-DOG.  A
  1572. name on MS-DOG consists of up to 8 characters, optionally followed by a
  1573. period and up to three characters.  MS-DOG will truncate extra
  1574. characters both before and after the period.  Thus, `foobarhacker.c'
  1575. and `foobarhacker.o' are not ambiguous; they are truncated to
  1576. `foobarha.c' and `foobarha.o', which are distinct.
  1577.  
  1578.    Include in your distribution a copy of the `texinfo.tex' you used to
  1579. test print any `*.texinfo' files.
  1580.  
  1581.    Likewise, if your program uses small GNU software packages like
  1582. regex, getopt, obstack, or termcap, include them in the distribution
  1583. file.  Leaving them out would make the distribution file a little
  1584. smaller at the expense of possible inconvenience to a user who doesn't
  1585. know what other files to get.
  1586.  
  1587.  
  1588. 
  1589. Tag Table:
  1590. Node: Top821
  1591. Node: Reading Non-Free Code1845
  1592. Node: Contributions3571
  1593. Node: Change Logs5169
  1594. Node: Compatibility8351
  1595. Node: Makefile Conventions9757
  1596. Node: Makefile Basics10114
  1597. Node: Utilities in Makefiles12005
  1598. Node: Standard Targets13441
  1599. Node: Command Variables19492
  1600. Node: Directory Variables22318
  1601. Node: Configuration28391
  1602. Node: Source Language33958
  1603. Node: Formatting35088
  1604. Node: Comments38378
  1605. Node: Syntactic Conventions41169
  1606. Node: Names44031
  1607. Node: Using Extensions45123
  1608. Node: Semantics46857
  1609. Node: Errors49825
  1610. Node: Libraries51028
  1611. Node: Portability52254
  1612. Node: User Interfaces55537
  1613. Node: Documentation58897
  1614. Node: Releases62655
  1615. 
  1616. End Tag Table
  1617.