Changeset 609 for branches/GNU/src/binutils/etc
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- Location:
- branches/GNU/src/binutils/etc
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/etc/Makefile.in
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 2 2 # Makefile.in for etc 3 3 # 4 5 DESTDIR = 4 6 5 7 prefix = @prefix@ … … 52 54 all: 53 55 54 install: 56 # We want install to imply install-info as per GNU standards. 57 install: install-info 55 58 56 59 uninstall: … … 68 71 69 72 install-info: info 70 $(SHELL) $(srcdir)/../mkinstalldirs $( infodir)73 $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(infodir) 71 74 if test ! -f standards.info; then cd $(srcdir); fi; \ 72 75 if test -f standards.info; then \ 73 76 for i in standards.info*; do \ 74 $(INSTALL_DATA) $$i $( infodir)/$$i; \77 $(INSTALL_DATA) $$i $(DESTDIR)$(infodir)/$$i; \ 75 78 done; \ 76 79 fi … … 78 81 if test -f configure.info; then \ 79 82 for i in configure.info*; do \ 80 $(INSTALL_DATA) $$i $( infodir)/$$i; \83 $(INSTALL_DATA) $$i $(DESTDIR)$(infodir)/$$i; \ 81 84 done; \ 82 85 fi -
Property cvs2svn:cvs-rev
changed from
-
branches/GNU/src/binutils/etc/configure.info
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 This is configure.info, produced by makeinfo version 4. 0from1 This is configure.info, produced by makeinfo version 4.3 from 2 2 ./configure.texi. 3 3 -
Property cvs2svn:cvs-rev
changed from
-
branches/GNU/src/binutils/etc/configure.info-1
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 This is configure.info, produced by makeinfo version 4. 0from1 This is configure.info, produced by makeinfo version 4.3 from 2 2 ./configure.texi. 3 3 -
Property cvs2svn:cvs-rev
changed from
-
branches/GNU/src/binutils/etc/configure.info-2
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 This is configure.info, produced by makeinfo version 4. 0from1 This is configure.info, produced by makeinfo version 4.3 from 2 2 ./configure.texi. 3 3 -
Property cvs2svn:cvs-rev
changed from
-
branches/GNU/src/binutils/etc/configure.info-3
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 This is configure.info, produced by makeinfo version 4. 0from1 This is configure.info, produced by makeinfo version 4.3 from 2 2 ./configure.texi. 3 3 -
Property cvs2svn:cvs-rev
changed from
-
branches/GNU/src/binutils/etc/make-stds.texi
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 8 8 @cindex conventions for makefiles 9 9 @cindex standards for makefiles 10 11 @c Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2001 Free 12 @c Software Foundation, Inc. 13 14 @c Permission is granted to copy, distribute and/or modify this document 15 @c under the terms of the GNU Free Documentation License, Version 1.1 16 @c or any later version published by the Free Software Foundation; 17 @c with no Invariant Sections, with no 18 @c Front-Cover Texts, and with no Back-Cover Texts. 19 @c A copy of the license is included in the section entitled ``GNU 20 @c Free Documentation License''. 10 21 11 22 This … … 22 33 @end iftex 23 34 describes conventions for writing the Makefiles for GNU programs. 35 Using Automake will help you write a Makefile that follows these 36 conventions. 24 37 25 38 @menu 26 * Makefile Basics:: 27 * Utilities in Makefiles:: 28 * Command Variables:: 29 * Directory Variables:: 30 * Standard Targets:: 39 * Makefile Basics:: General Conventions for Makefiles 40 * Utilities in Makefiles:: Utilities in Makefiles 41 * Command Variables:: Variables for Specifying Commands 42 * Directory Variables:: Variables for Installation Directories 43 * Standard Targets:: Standard Targets for Users 31 44 * Install Command Categories:: Three categories of commands in the `install' 32 45 rule: normal, pre-install and post-install. … … 80 93 @noindent 81 94 will fail when the build directory is not the source directory, because 82 @file{foo.man} and @file{sedscript} are in the thesource directory.95 @file{foo.man} and @file{sedscript} are in the source directory. 83 96 84 97 When using GNU @code{make}, relying on @samp{VPATH} to find the source … … 139 152 @c dd find 140 153 @c gunzip gzip md5sum 141 @c mkfifo mknod tee uname 154 @c mkfifo mknod tee uname 142 155 143 156 @example … … 248 261 249 262 Every Makefile should also define the variables @code{INSTALL_PROGRAM} 250 and @code{INSTALL_DATA}. (The default for each of these should be 251 @code{$(INSTALL)}.) Then it should use those variables as the commands 252 for actual installation, for executables and nonexecutables 263 and @code{INSTALL_DATA}. (The default for @code{INSTALL_PROGRAM} should 264 be @code{$(INSTALL)}; the default for @code{INSTALL_DATA} should be 265 @code{$@{INSTALL@} -m 644}.) Then it should use those variables as the 266 commands for actual installation, for executables and nonexecutables 253 267 respectively. Use these variables as follows: 254 268 … … 281 295 easy to install in a nonstandard place. The standard names for these 282 296 variables are described below. They are based on a standard filesystem 283 layout; variants of it are used in SVR4, 4.4BSD, Linux, Ultrix v4, and284 other modern operating systems.297 layout; variants of it are used in SVR4, 4.4BSD, GNU/Linux, Ultrix v4, 298 and other modern operating systems. 285 299 286 300 These two variables set the root for the installation. All the other … … 288 302 and nothing should be directly installed into these two directories. 289 303 290 @table @ samp304 @table @code 291 305 @item prefix 306 @vindex prefix 292 307 A prefix used in constructing the default values of the variables listed 293 308 below. The default value of @code{prefix} should be @file{/usr/local}. … … 296 311 (If you are using Autoconf, write it as @samp{@@prefix@@}.) 297 312 298 Running @samp{make install} with a different value of @code{prefix} 299 from the one used to build the program should @var{not} recompile300 theprogram.313 Running @samp{make install} with a different value of @code{prefix} from 314 the one used to build the program should @emph{not} recompile the 315 program. 301 316 302 317 @item exec_prefix 318 @vindex exec_prefix 303 319 A prefix used in constructing the default values of some of the 304 320 variables listed below. The default value of @code{exec_prefix} should … … 311 327 312 328 Running @samp{make install} with a different value of @code{exec_prefix} 313 from the one used to build the program should @ var{not} recompile the329 from the one used to build the program should @emph{not} recompile the 314 330 program. 315 331 @end table … … 317 333 Executable programs are installed in one of the following directories. 318 334 319 @table @ samp335 @table @code 320 336 @item bindir 337 @vindex bindir 321 338 The directory for installing executable programs that users can run. 322 339 This should normally be @file{/usr/local/bin}, but write it as … … 325 342 326 343 @item sbindir 344 @vindex sbindir 327 345 The directory for installing executable programs that can be run from 328 346 the shell, but are only generally useful to system administrators. This … … 332 350 333 351 @item libexecdir 352 @vindex libexecdir 334 353 @comment This paragraph adjusted to avoid overfull hbox --roland 5jul94 335 354 The directory for installing executable programs to be run by other … … 624 643 @item install-strip 625 644 Like @code{install}, but strip the executable files while installing 626 them. In many cases, the definition of this target can be very simple: 645 them. In simple cases, this target can use the @code{install} target in 646 a simple way: 627 647 628 648 @smallexample … … 631 651 install 632 652 @end smallexample 653 654 But if the package installs scripts as well as real executables, the 655 @code{install-strip} target can't just refer to the @code{install} 656 target; it has to strip the executables but not the scripts. 657 658 @code{install-strip} should not strip the executables in the build 659 directory which are being copied for installation. It should only strip 660 the copies that are installed. 633 661 634 662 Normally we do not recommend stripping an executable unless you are sure … … 746 774 then @code{tar} that subdirectory. 747 775 748 Compress the tar file filewith @code{gzip}. For example, the actual776 Compress the tar file with @code{gzip}. For example, the actual 749 777 distribution file for GCC version 1.40 is called @file{gcc-1.40.tar.gz}. 750 778 … … 794 822 @end smallexample 795 823 824 @noindent 825 or, if you wish to support @env{DESTDIR}, 826 827 @smallexample 828 # Make sure all installation directories (e.g. $(bindir)) 829 # actually exist by making them if necessary. 830 installdirs: mkinstalldirs 831 $(srcdir)/mkinstalldirs \ 832 $(DESTDIR)$(bindir) $(DESTDIR)$(datadir) \ 833 $(DESTDIR)$(libdir) $(DESTDIR)$(infodir) \ 834 $(DESTDIR)$(mandir) 835 @end smallexample 836 796 837 This rule should not modify the directories where compilation is done. 797 838 It should do nothing but create installation directories. -
Property cvs2svn:cvs-rev
changed from
-
branches/GNU/src/binutils/etc/standards.info
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 This is standards.info, produced by makeinfo version 4. 0from1 This is standards.info, produced by makeinfo version 4.3 from 2 2 ./standards.texi. 3 3 … … 7 7 8 8 GNU Coding Standards Copyright (C) 1992, 1993, 1994, 1995, 1996, 9 1997, 1998 Free Software Foundation, Inc. 10 11 Permission is granted to make and distribute verbatim copies of this 12 manual provided the copyright notice and this permission notice are 13 preserved on all copies. 14 15 Permission is granted to copy and distribute modified versions of 16 this manual under the conditions for verbatim copying, provided that 17 the entire resulting derived work is distributed under the terms of a 18 permission notice identical to this one. 19 20 Permission is granted to copy and distribute translations of this 21 manual into another language, under the above conditions for modified 22 versions, except that this permission notice may be stated in a 23 translation approved by the Free Software Foundation. 9 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. 10 11 Permission is granted to copy, distribute and/or modify this document 12 under the terms of the GNU Free Documentation License, Version 1.1 or 13 any later version published by the Free Software Foundation; with no 14 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover 15 Texts. A copy of the license is included in the section entitled "GNU 16 Free Documentation License". 24 17 25 18 … … 29 22 ******* 30 23 31 Last updated March 13, 1998.24 Last updated February 14, 2002. 32 25 33 26 * Menu: 34 27 35 28 * Preface:: About the GNU Coding Standards 36 * Intellectual Property::Keeping Free Software Free29 * Legal Issues:: Keeping Free Software Free 37 30 * Design Advice:: General Program Design 38 31 * Program Behavior:: Program Behavior for All Programs … … 40 33 * Documentation:: Documenting Programs 41 34 * Managing Releases:: The Release Process 42 43 44 File: standards.info, Node: Preface, Next: Intellectual Property, Prev: Top, Up: Top 35 * References:: References to Non-Free Software or Documentation 36 * Copying This Manual:: How to Make Copies of This Manual 37 * Index:: 38 39 40 File: standards.info, Node: Preface, Next: Legal Issues, Prev: Top, Up: Top 45 41 46 42 About the GNU Coding Standards … … 55 51 state reasons for writing in a certain way. 56 52 53 This release of the GNU Coding Standards was last updated February 54 14, 2002. 55 56 If you did not obtain this file directly from the GNU project and 57 recently, please check for a newer version. You can ftp the GNU Coding 58 Standards from any GNU FTP host in the directory `/pub/gnu/standards/'. 59 The GNU Coding Standards are available there in several different 60 formats: `standards.text', `standards.info', and `standards.dvi', as 61 well as the Texinfo "source" which is divided in two files: 62 `standards.texi' and `make-stds.texi'. The GNU Coding Standards are 63 also available on the GNU World Wide Web server: 64 `http://www.gnu.org/prep/standards_toc.html'. 65 57 66 Corrections or suggestions for this document should be sent to 58 <gnu@gnu.org>. If you make a suggestion, please include a suggested 59 new wording for it; our time is limited. We prefer a context diff to 60 the `standards.texi' or `make-stds.texi' files, but if you don't have 61 those files, please mail your suggestion anyway. 62 63 This release of the GNU Coding Standards was last updated March 13, 64 1998. 65 66 67 File: standards.info, Node: Intellectual Property, Next: Design Advice, Prev: Preface, Up: Top 67 <bug-standards@gnu.org>. If you make a suggestion, please include a 68 suggested new wording for it; our time is limited. We prefer a context 69 diff to the `standards.texi' or `make-stds.texi' files, but if you 70 don't have those files, please mail your suggestion anyway. 71 72 These standards cover the minimum of what is important when writing a 73 GNU package. Likely, the needs for additional standards will come up. 74 Sometimes, you might suggest that such standards be added to this 75 document. If you think your standards would be generally useful, please 76 do suggest them. 77 78 You should also set standards for your package on many questions not 79 addressed or not firmly specified here. The most important point is to 80 be self-consistent--try to stick to the conventions you pick, and try 81 to document them as much as possible. That way, your program will be 82 more maintainable by others. 83 84 85 File: standards.info, Node: Legal Issues, Next: Design Advice, Prev: Preface, Up: Top 68 86 69 87 Keeping Free Software Free 70 88 ************************** 71 89 72 This node discusses how you can make sure that GNU software remains73 unencumbered.90 This node discusses how you can make sure that GNU software avoids 91 legal difficulties, and other related issues. 74 92 75 93 * Menu: … … 77 95 * Reading Non-Free Code:: Referring to Proprietary Programs 78 96 * Contributions:: Accepting Contributions 79 80 81 File: standards.info, Node: Reading Non-Free Code, Next: Contributions, Up: Intellectual Property 97 * Trademarks:: How We Deal with Trademark Issues 98 99 100 File: standards.info, Node: Reading Non-Free Code, Next: Contributions, Up: Legal Issues 82 101 83 102 Referring to Proprietary Programs … … 116 135 117 136 118 File: standards.info, Node: Contributions, Prev: Reading Non-Free Code, Up: Intellectual Property137 File: standards.info, Node: Contributions, Next: Trademarks, Prev: Reading Non-Free Code, Up: Legal Issues 119 138 120 139 Accepting Contributions 121 140 ======================= 122 141 123 If someone else sends you a piece of code to add to the program you 124 are working on, we need legal papers to use it--the same sort of legal 125 papers we will need to get from you. _Each_ significant contributor to 126 a program must sign some sort of legal papers in order for us to have 127 clear title to the program. The main author alone is not enough. 142 If the program you are working on is copyrighted by the Free Software 143 Foundation, then when someone else sends you a piece of code to add to 144 the program, we need legal papers to use it--just as we asked you to 145 sign papers initially. _Each_ person who makes a nontrivial 146 contribution to a program must sign some sort of legal papers in order 147 for us to have clear title to the program; the main author alone is not 148 enough. 128 149 129 150 So, before adding in any contributions from other people, please tell … … 140 161 text, so we need legal papers for all kinds. 141 162 163 We know it is frustrating to ask for legal papers; it's frustrating 164 for us as well. But if you don't wait, you are going out on a limb--for 165 example, what if the contributor's employer won't sign a disclaimer? 166 You might have to take that code out again! 167 142 168 You don't need papers for changes of a few lines here or there, since 143 169 they are not significant for copyright purposes. Also, you don't need 144 170 papers if all you get from the suggestion is some ideas, not actual code 145 which you use. For example, if you write a different solution to the 146 problem, you don't need to get papers. 147 148 We know this is frustrating; it's frustrating for us as well. But if 149 you don't wait, you are going out on a limb--for example, what if the 150 contributor's employer won't sign a disclaimer? You might have to take 151 that code out again! 171 which you use. For example, if someone send you one implementation, but 172 you write a different implementation of the same idea, you don't need to 173 get papers. 152 174 153 175 The very worst thing is if you forget to tell us about the other … … 160 182 161 183 162 File: standards.info, Node: Design Advice, Next: Program Behavior, Prev: Intellectual Property, Up: Top 184 File: standards.info, Node: Trademarks, Prev: Contributions, Up: Legal Issues 185 186 Trademarks 187 ========== 188 189 Please do not include any trademark acknowledgements in GNU software 190 packages or documentation. 191 192 Trademark acknowledgements are the statements that such-and-such is a 193 trademark of so-and-so. The GNU Project has no objection to the basic 194 idea of trademarks, but these acknowledgements feel like kowtowing, so 195 we don't use them. There is no legal requirement for them. 196 197 What is legally required, as regards other people's trademarks, is to 198 avoid using them in ways which a reader might read as naming or labeling 199 our own programs or activities. For example, since "Objective C" is 200 (or at least was) a trademark, we made sure to say that we provide a 201 "compiler for the Objective C language" rather than an "Objective C 202 compiler". The latter is meant to be short for the former, but it does 203 not explicitly state the relationship, so it could be misinterpreted as 204 using "Objective C" as a label for the compiler rather than for the 205 language. 206 207 208 File: standards.info, Node: Design Advice, Next: Program Behavior, Prev: Legal Issues, Up: Top 163 209 164 210 General Program Design … … 170 216 * Menu: 171 217 218 * Source Language:: Which languges to use. 172 219 * Compatibility:: Compatibility with other implementations 173 220 * Using Extensions:: Using non-standard features 174 * ANSI C:: Using ANSI C features 175 * Source Language:: Using languages other than C 176 177 178 File: standards.info, Node: Compatibility, Next: Using Extensions, Up: Design Advice 221 * Standard C:: Using Standard C features 222 * Conditional Compilation:: Compiling Code Only If A Conditional is True 223 224 225 File: standards.info, Node: Source Language, Next: Compatibility, Up: Design Advice 226 227 Which Languages to Use 228 ====================== 229 230 When you want to use a language that gets compiled and runs at high 231 speed, the best language to use is C. Using another language is like 232 using a non-standard feature: it will cause trouble for users. Even if 233 GCC supports the other language, users may find it inconvenient to have 234 to install the compiler for that other language in order to build your 235 program. For example, if you write your program in C++, people will 236 have to install the GNU C++ compiler in order to compile your program. 237 238 C has one other advantage over C++ and other compiled languages: more 239 people know C, so more people will find it easy to read and modify the 240 program if it is written in C. 241 242 So in general it is much better to use C, rather than the comparable 243 alternatives. 244 245 But there are two exceptions to that conclusion: 246 247 * It is no problem to use another language to write a tool 248 specifically intended for use with that language. That is because 249 the only people who want to build the tool will be those who have 250 installed the other language anyway. 251 252 * If an application is of interest only to a narrow part of the 253 community, then the question of which language it is written in 254 has less effect on other people, so you may as well please 255 yourself. 256 257 Many programs are designed to be extensible: they include an 258 interpreter for a language that is higher level than C. Often much of 259 the program is written in that language, too. The Emacs editor 260 pioneered this technique. 261 262 The standard extensibility interpreter for GNU software is GUILE, 263 which implements the language Scheme (an especially clean and simple 264 dialect of Lisp). `http://www.gnu.org/software/guile/'. We don't 265 reject programs written in other "scripting languages" such as Perl and 266 Python, but using GUILE is very important for the overall consistency of 267 the GNU system. 268 269 270 File: standards.info, Node: Compatibility, Next: Using Extensions, Prev: Source Language, Up: Design Advice 179 271 180 272 Compatibility with Other Implementations … … 183 275 With occasional exceptions, utility programs and libraries for GNU 184 276 should be upward compatible with those in Berkeley Unix, and upward 185 compatible with ANSI C if ANSI C specifies their behavior, and upward186 compatible with POSIX if POSIX specifies their behavior.277 compatible with Standard C if Standard C specifies their behavior, and 278 upward compatible with POSIX if POSIX specifies their behavior. 187 279 188 280 When these standards conflict, it is useful to offer compatibility 189 281 modes for each of them. 190 282 191 ANSI C and POSIX prohibit many kinds of extensions. Feel free to192 make the extensions anyway, and include a `--ansi', `--posix', or283 Standard C and POSIX prohibit many kinds of extensions. Feel free 284 to make the extensions anyway, and include a `--ansi', `--posix', or 193 285 `--compatible' option to turn them off. However, if the extension has 194 286 a significant chance of breaking any real programs or scripts, then it 195 is not really upward compatible. Try to redesign its interface. 287 is not really upward compatible. So you should try to redesign its 288 interface to make it upward compatible. 196 289 197 290 Many GNU programs suppress extensions that conflict with POSIX if the … … 206 299 feature as well. (There is a free `vi' clone, so we offer it.) 207 300 208 Additional useful features not in Berkeley Unix are welcome. 209 210 211 File: standards.info, Node: Using Extensions, Next: ANSI C, Prev: Compatibility, Up: Design Advice 301 Additional useful features are welcome regardless of whether there 302 is any precedent for them. 303 304 305 File: standards.info, Node: Using Extensions, Next: Standard C, Prev: Compatibility, Up: Design Advice 212 306 213 307 Using Non-standard Features … … 233 327 234 328 An exception to this rule are the large, established programs (such 235 as Emacs) which run on a great variety of systems. Such programs would 236 be broken by use of GNU extensions. 329 as Emacs) which run on a great variety of systems. Using GNU 330 extensions in such programs would make many users unhappy, so we don't 331 do that. 237 332 238 333 Another exception is for programs that are used as part of … … 240 335 order to bootstrap the GNU compilation facilities. If these require 241 336 the GNU compiler, then no one can compile them without having them 242 installed already. That would be no good. 243 244 245 File: standards.info, Node: ANSI C, Next: Source Language, Prev: Using Extensions, Up: Design Advice 246 247 ANSI C and pre-ANSI C 248 ===================== 249 250 Do not ever use the "trigraph" feature of ANSI C. 251 252 ANSI C is widespread enough now that it is ok to write new programs 253 that use ANSI C features (and therefore will not work in non-ANSI 254 compilers). And if a program is already written in ANSI C, there's no 255 need to convert it to support non-ANSI compilers. 256 257 However, it is easy to support non-ANSI compilers in most programs, 258 so you might still consider doing so when you write a program. Instead 259 of writing function definitions in ANSI prototype form, 337 installed already. That would be extremely troublesome in certain 338 cases. 339 340 341 File: standards.info, Node: Standard C, Next: Conditional Compilation, Prev: Using Extensions, Up: Design Advice 342 343 Standard C and Pre-Standard C 344 ============================= 345 346 1989 Standard C is widespread enough now that it is ok to use its 347 features in new programs. There is one exception: do not ever use the 348 "trigraph" feature of Standard C. 349 350 1999 Standard C is not widespread yet, so please do not require its 351 features in programs. It is ok to use its features if they are present. 352 353 However, it is easy to support pre-standard compilers in most 354 programs, so if you know how to do that, feel free. If a program you 355 are maintaining has such support, you should try to keep it working. 356 357 To support pre-standard C, instead of writing function definitions in 358 standard prototype form, 260 359 261 360 int … … 263 362 ... 264 363 265 write the definition in pre- ANSIstyle like this,364 write the definition in pre-standard style like this, 266 365 267 366 int … … 275 374 276 375 You need such a declaration anyway, in a header file, to get the 277 benefit of ANSI C prototypes in all the files where the function is 278 called. And once you have it, you lose nothing by writing the function 279 definition in the pre-ANSI style. 280 281 If you don't know non-ANSI C, there's no need to learn it; just 282 write in ANSI C. 283 284 285 File: standards.info, Node: Source Language, Prev: ANSI C, Up: Design Advice 286 287 Using Languages Other Than C 288 ============================ 289 290 Using a language other than C is like using a non-standard feature: 291 it will cause trouble for users. Even if GCC supports the other 292 language, users may find it inconvenient to have to install the 293 compiler for that other language in order to build your program. For 294 example, if you write your program in C++, people will have to install 295 the C++ compiler in order to compile your program. Thus, it is better 296 if you write in C. 297 298 But there are three situations when there is no disadvantage in using 299 some other language: 300 301 * It is okay to use another language if your program contains an 302 interpreter for that language. 303 304 For example, if your program links with GUILE, it is ok to write 305 part of the program in Scheme or another language supported by 306 GUILE. 307 308 * It is okay to use another language in a tool specifically intended 309 for use with that language. 310 311 This is okay because the only people who want to build the tool 312 will be those who have installed the other language anyway. 313 314 * If an application is of interest to a narrow community, then 315 perhaps it's not important if the application is inconvenient to 316 install. 317 318 C has one other advantage over C++ and other compiled languages: more 319 people know C, so more people will find it easy to read and modify the 320 program if it is written in C. 376 benefit of prototypes in all the files where the function is called. 377 And once you have the declaration, you normally lose nothing by writing 378 the function definition in the pre-standard style. 379 380 This technique does not work for integer types narrower than `int'. 381 If you think of an argument as being of a type narrower than `int', 382 declare it as `int' instead. 383 384 There are a few special cases where this technique is hard to use. 385 For example, if a function argument needs to hold the system type 386 `dev_t', you run into trouble, because `dev_t' is shorter than `int' on 387 some machines; but you cannot use `int' instead, because `dev_t' is 388 wider than `int' on some machines. There is no type you can safely use 389 on all machines in a non-standard definition. The only way to support 390 non-standard C and pass such an argument is to check the width of 391 `dev_t' using Autoconf and choose the argument type accordingly. This 392 may not be worth the trouble. 393 394 In order to support pre-standard compilers that do not recognize 395 prototypes, you may want to use a preprocessor macro like this: 396 397 /* Declare the prototype for a general external function. */ 398 #if defined (__STDC__) || defined (WINDOWSNT) 399 #define P_(proto) proto 400 #else 401 #define P_(proto) () 402 #endif 403 404 405 File: standards.info, Node: Conditional Compilation, Prev: Standard C, Up: Design Advice 406 407 Conditional Compilation 408 ======================= 409 410 When supporting configuration options already known when building 411 your program we prefer using `if (... )' over conditional compilation, 412 as in the former case the compiler is able to perform more extensive 413 checking of all possible code paths. 414 415 For example, please write 416 417 if (HAS_FOO) 418 ... 419 else 420 ... 421 422 instead of: 423 424 #ifdef HAS_FOO 425 ... 426 #else 427 ... 428 #endif 429 430 A modern compiler such as GCC will generate exactly the same code in 431 both cases, and we have been using similar techniques with good success 432 in several projects. 433 434 While this is not a silver bullet solving all portability problems, 435 following this policy would have saved the GCC project alone many person 436 hours if not days per year. 437 438 In the case of function-like macros like `REVERSIBLE_CC_MODE' in GCC 439 which cannot be simply used in `if( ...)' statements, there is an easy 440 workaround. Simply introduce another macro `HAS_REVERSIBLE_CC_MODE' as 441 in the following example: 442 443 #ifdef REVERSIBLE_CC_MODE 444 #define HAS_REVERSIBLE_CC_MODE 1 445 #else 446 #define HAS_REVERSIBLE_CC_MODE 0 447 #endif 321 448 322 449 … … 326 453 ********************************* 327 454 328 This node describes how to write robust software. It also describes329 general standards for error messages, the command line interface, and 330 how libraries should behave.455 This node describes conventions for writing robust software. It 456 also describes general standards for error messages, the command line 457 interface, and how libraries should behave. 331 458 332 459 * Menu: … … 335 462 * Libraries:: Library behavior 336 463 * Errors:: Formatting error messages 337 * User Interfaces:: Standards for command line interfaces 338 * Option Table:: Table of long options. 464 * User Interfaces:: Standards about interfaces generally 465 * Graphical Interfaces:: Standards for graphical interfaces 466 * Command-Line Interfaces:: Standards for command line interfaces 467 * Option Table:: Table of long options 339 468 * Memory Usage:: When and how to care about memory needs 469 * File Usage:: Which files to use, and where 340 470 341 471 … … 354 484 nonprinting characters _including those with codes above 0177_. The 355 485 only sensible exceptions would be utilities specifically intended for 356 interface to certain types of printers that can't handle those 357 characters. 486 interface to certain types of terminals or printers that can't handle 487 those characters. Whenever possible, try to make programs work 488 properly with sequences of bytes that represent multibyte characters, 489 using encodings such as UTF-8 and others. 358 490 359 491 Check every system call for an error return, unless you know you … … 395 527 these are less likely to work compatibly. If you need to find all the 396 528 files in a directory, use `readdir' or some other high-level interface. 397 These will be supported compatibly by GNU. 398 399 By default, the GNU system will provide the signal handling 400 functions of BSD and of POSIX. So GNU software should be written to use 401 these. 529 These are supported compatibly by GNU. 530 531 The preferred signal handling facilities are the BSD variant of 532 `signal', and the POSIX `sigaction' function; the alternative USG 533 `signal' interface is an inferior design. 534 535 Nowadays, using the POSIX signal functions may be the easiest way to 536 make a program portable. If you use `signal', then on GNU/Linux 537 systems running GNU libc version 1, you should include `bsd/signal.h' 538 instead of `signal.h', so as to get BSD behavior. It is up to you 539 whether to support systems where `signal' has only the USG behavior, or 540 give up on them. 402 541 403 542 In error checks that detect "impossible" conditions, just abort. … … 419 558 instead of `/tmp'. 420 559 560 In addition, be aware that there is a possible security problem when 561 creating temporary files in world-writable directories. In C, you can 562 avoid this problem by creating temporary files in this manner: 563 564 fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600); 565 566 or by using the `mkstemps' function from libiberty. 567 568 In bash, use `set -C' to avoid this problem. 569 421 570 422 571 File: standards.info, Node: Libraries, Next: Errors, Prev: Semantics, Up: Program Behavior … … 442 591 443 592 External symbols that are not documented entry points for the user 444 should have names beginning with `_'. The y should also contain the445 chosen name prefix for the library, to prevent collisions with other 446 libraries. These can go in the same files with user entry points if 447 you like.593 should have names beginning with `_'. The `_' should be followed by 594 the chosen name prefix for the library, to prevent collisions with 595 other libraries. These can go in the same files with user entry points 596 if you like. 448 597 449 598 Static functions and variables can be used as you like and need not … … 460 609 SOURCE-FILE-NAME:LINENO: MESSAGE 461 610 611 If you want to mention the column number, use this format: 612 613 SOURCE-FILE-NAME:LINENO:COLUMN: MESSAGE 614 615 Line numbers should start from 1 at the beginning of the file, and 616 column numbers should start from 1 at the beginning of the line. (Both 617 of these conventions are chosen for compatibility.) Calculate column 618 numbers assuming that space and all ASCII printing characters have 619 equal width, and assuming tab stops every 8 columns. 620 462 621 Error messages from other noninteractive programs should look like 463 622 this: … … 470 629 471 630 when there is no relevant source file. 631 632 If you want to mention the column number, use this format: 633 634 PROGRAM:SOURCE-FILE-NAME:LINENO:COLUMN: MESSAGE 472 635 473 636 In an interactive program (one that is reading commands from a … … 487 650 488 651 489 File: standards.info, Node: User Interfaces, Next: Option Table, Prev: Errors, Up: Program Behavior490 491 Standards for Command Line Interfaces492 ================================== ===652 File: standards.info, Node: User Interfaces, Next: Graphical Interfaces, Prev: Errors, Up: Program Behavior 653 654 Standards for Interfaces Generally 655 ================================== 493 656 494 657 Please don't make the behavior of a utility depend on the name used … … 502 665 type of output device it is used with. Device independence is an 503 666 important principle of the system's design; do not compromise it merely 504 to save someone from typing an option now and then. 667 to save someone from typing an option now and then. (Variation in error 668 message syntax when using a terminal is ok, because that is a side issue 669 that people do not depend on.) 505 670 506 671 If you think one behavior is most useful when the output is to a … … 518 683 format. 519 684 685 686 File: standards.info, Node: Graphical Interfaces, Next: Command-Line Interfaces, Prev: User Interfaces, Up: Program Behavior 687 688 Standards for Graphical Interfaces 689 ================================== 690 691 When you write a program that provides a graphical user interface, 692 please make it work with X Windows and the GTK toolkit unless the 693 functionality specifically requires some alternative (for example, 694 "displaying jpeg images while in console mode"). 695 696 In addition, please provide a command-line interface to control the 697 functionality. (In many cases, the graphical user interface can be a 698 separate program which invokes the command-line program.) This is so 699 that the same jobs can be done from scripts. 700 701 Please also consider providing a CORBA interface (for use from 702 GNOME), a library interface (for use from C), and perhaps a 703 keyboard-driven console interface (for use by users from console mode). 704 Once you are doing the work to provide the functionality and the 705 graphical interface, these won't be much extra work. 706 707 708 File: standards.info, Node: Command-Line Interfaces, Next: Option Table, Prev: Graphical Interfaces, Up: Program Behavior 709 710 Standards for Command Line Interfaces 711 ===================================== 712 520 713 It is a good idea to follow the POSIX guidelines for the 521 714 command-line options of a program. The easiest way to do this is to use … … 548 741 549 742 `--version' 550 This option should direct the program to information about its551 name, version, origin and legal status, all on standard output,552 and then exit successfully. Other options and arguments should be553 ignored once this is seen, and the program should not perform its554 normal function.743 This option should direct the program to print information about 744 its name, version, origin and legal status, all on standard 745 output, and then exit successfully. Other options and arguments 746 should be ignored once this is seen, and the program should not 747 perform its normal function. 555 748 556 749 The first line is meant to be easy for a program to parse; the … … 620 813 appeared in the first line. 621 814 815 Translations of the above lines must preserve the validity of the 816 copyright notices (*note Internationalization::). If the 817 translation's character set supports it, the `(C)' should be 818 replaced with the copyright symbol, as follows: 819 820 (the official copyright symbol, which is the letter C in a circle); 821 822 Write the word "Copyright" exactly like that, in English. Do not 823 translate it into another language. International treaties 824 recognize the English word "Copyright"; translations into other 825 languages do not have legal significance. 826 622 827 `--help' 623 828 This option should output brief documentation for how to invoke the … … 632 837 633 838 634 File: standards.info, Node: Option Table, Next: Memory Usage, Prev: UserInterfaces, Up: Program Behavior839 File: standards.info, Node: Option Table, Next: Memory Usage, Prev: Command-Line Interfaces, Up: Program Behavior 635 840 636 841 Table of Long Options … … 640 845 incomplete, but we aim to list all the options that a new program might 641 846 want to be compatible with. If you use names not already in the table, 642 please send < gnu@gnu.org> a list of them, with their meanings, so we643 can update the table.847 please send <bug-standards@gnu.org> a list of them, with their 848 meanings, so we can update the table. 644 849 645 850 `after-date' … … 691 896 `-n' in `wdiff'. 692 897 898 `background' 899 For server programs, run in the background. 900 693 901 `backward-search' 694 902 `-B' in `ctags'. … … 810 1018 `dereference-args' 811 1019 `-D' in `du'. 1020 1021 `device' 1022 Specify an I/O device (special file name). 812 1023 813 1024 `diacritics' … … 941 1152 `-F' in `shar'. 942 1153 1154 `foreground' 1155 For server programs, run in the foreground; in other words, don't 1156 do anything special to run the server in the background. 1157 943 1158 `format' 944 1159 Used in `ls', `time', and `ptx'. … … 986 1201 `-q' in `ls'. 987 1202 1203 `html' 1204 In `makeinfo', output HTML. 1205 988 1206 `idle' 989 1207 `-u' in `who'. … … 1042 1260 `info' 1043 1261 `-i', `-l', and `-m' in Finger. 1262 1263 `init-file' 1264 In some programs, specify the name of the file to read as the 1265 user's init file. 1044 1266 1045 1267 `initial' … … 1059 1281 `-p' in `shar'. 1060 1282 1283 `iso-8601' 1284 Used in `date' 1285 1061 1286 `jobs' 1062 1287 `-j' in Make. … … 1292 1517 `-F' in `gprof'. 1293 1518 1519 `options' 1520 `-o' in `getopt', `fdlist', `fdmount', `fdmountd', and `fdumount'. 1521 1294 1522 `output' 1295 1523 In various programs, specify the output file name. … … 1375 1603 `prompt' 1376 1604 `-p' in `ed'. 1605 1606 `proxy' 1607 Specify an HTTP proxy. 1377 1608 1378 1609 `query-user' … … 1501 1732 `-s' in `ls'. 1502 1733 1734 `socket' 1735 Specify a file descriptor for a network server to use for its 1736 socket, instead of opening and binding a new socket. This 1737 provides a way to run, in a nonpriveledged process, a server that 1738 normally needs a reserved port number. 1739 1503 1740 `sort' 1504 1741 Used in `ls'. … … 1598 1835 Used in `ls' and `touch'. 1599 1836 1837 `timeout' 1838 Specify how long to wait before giving up on some operation. 1839 1600 1840 `to-stdout' 1601 1841 `-O' in `tar'. … … 1687 1927 1688 1928 1689 File: standards.info, Node: Memory Usage, Prev: Option Table, Up: Program Behavior1929 File: standards.info, Node: Memory Usage, Next: File Usage, Prev: Option Table, Up: Program Behavior 1690 1930 1691 1931 Memory Usage 1692 1932 ============ 1693 1933 1694 If it typically uses just a few meg of memory, don't bother making 1695 any effort to reduce memory usage. For example, if it is impractical 1696 for other reasons to operate on files more than a few meg long, it is 1697 reasonable to read entire input files into core to operate on them. 1934 If a program typically uses just a few meg of memory, don't bother 1935 making any effort to reduce memory usage. For example, if it is 1936 impractical for other reasons to operate on files more than a few meg 1937 long, it is reasonable to read entire input files into core to operate 1938 on them. 1698 1939 1699 1940 However, for programs such as `cat' or `tail', that can usefully … … 1709 1950 1710 1951 1952 File: standards.info, Node: File Usage, Prev: Memory Usage, Up: Program Behavior 1953 1954 File Usage 1955 ========== 1956 1957 Programs should be prepared to operate when `/usr' and `/etc' are 1958 read-only file systems. Thus, if the program manages log files, lock 1959 files, backup files, score files, or any other files which are modified 1960 for internal purposes, these files should not be stored in `/usr' or 1961 `/etc'. 1962 1963 There are two exceptions. `/etc' is used to store system 1964 configuration information; it is reasonable for a program to modify 1965 files in `/etc' when its job is to update the system configuration. 1966 Also, if the user explicitly asks to modify one file in a directory, it 1967 is reasonable for the program to store other files in the same 1968 directory. 1969 1970 1711 1971 File: standards.info, Node: Writing C, Next: Documentation, Prev: Program Behavior, Up: Top 1712 1972 … … 1722 1982 * Comments:: Commenting Your Work 1723 1983 * Syntactic Conventions:: Clean Use of C Constructs 1724 * Names:: Naming Variables and Functions1984 * Names:: Naming Variables, Functions, and Files 1725 1985 * System Portability:: Portability between different operating systems 1726 1986 * CPU Portability:: Supporting the range of CPU types … … 1753 2013 } 1754 2014 1755 or, if you want to use ANSI C, format the definition like this: 2015 or, if you want to use Standard C syntax, format the definition like 2016 this: 1756 2017 1757 2018 static char * … … 1761 2022 } 1762 2023 1763 In ANSI C, if the arguments don't fit nicely on one line, splitit1764 like this:2024 In Standard C, if the arguments don't fit nicely on one line, split 2025 it like this: 1765 2026 1766 2027 int … … 1769 2030 ... 1770 2031 1771 For the body of the function, we prefer code formatted like this: 2032 The rest of this section gives our recommendations for other aspects 2033 of C formatting style, which is also the default style of the `indent' 2034 program in version 1.2 and newer. It corresponds to the options 2035 2036 -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2 2037 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob 2038 2039 We don't think of these recommendations as requirements, because it 2040 causes no problems for users if two different programs have different 2041 formatting styles. 2042 2043 But whatever style you use, please use it consistently, since a 2044 mixture of styles within one program tends to look ugly. If you are 2045 contributing changes to an existing program, please follow the style of 2046 that program. 2047 2048 For the body of the function, our recommended style looks like this: 1772 2049 1773 2050 if (x < foo (y, z)) … … 1808 2085 Insert extra parentheses so that Emacs will indent the code properly. 1809 2086 For example, the following indentation looks nice if you do it by hand, 1810 but Emacs would mess it up:1811 2087 1812 2088 v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000 1813 2089 + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000; 1814 2090 1815 But adding a set of parentheses solves the problem: 2091 but Emacs would alter it. Adding a set of parentheses produces 2092 something that looks equally nice, and which Emacs will preserve: 1816 2093 1817 2094 v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000 … … 1917 2194 ========================= 1918 2195 1919 Please explicitly declare all arguments to functions. Don't omit 1920 them just because they are `int's. 2196 Please explicitly declare the types of all objects. For example, you 2197 should explicitly declare all arguments to functions, and you should 2198 declare functions to return `int' rather than omitting the `int'. 2199 2200 Some programmers like to use the GCC `-Wall' option, and change the 2201 code whenever it issues a warning. If you want to do this, then do. 2202 Other programmers prefer not to use `-Wall', because it gives warnings 2203 for valid and legitimate code which they do not want to change. If you 2204 want to do this, then do. The compiler should be your servant, not 2205 your master. 1921 2206 1922 2207 Declarations of external functions and functions to appear later in … … 2019 2304 File: standards.info, Node: Names, Next: System Portability, Prev: Syntactic Conventions, Up: Writing C 2020 2305 2021 Naming Variables and Functions2022 ============================== 2306 Naming Variables, Functions, and Files 2307 ====================================== 2023 2308 2024 2309 The names of global variables and functions in a program serve as … … 2031 2316 within one context, where (presumably) comments explain their purpose. 2032 2317 2318 Try to limit your use of abbreviations in symbol names. It is ok to 2319 make a few abbreviations, explain what they mean, and then use them 2320 frequently, but don't use lots of obscure abbreviations. 2321 2033 2322 Please use underscores to separate words in a name, so that the Emacs 2034 2323 word commands can be useful within them. Stick to lower case; reserve … … 2050 2339 `enum' rather than `#define'. GDB knows about enumeration constants. 2051 2340 2052 Use file names of 14 characters or less, to avoid creating gratuitous 2053 problems on older System V systems. You can use the program `doschk' 2054 to test for this. `doschk' also tests for potential name conflicts if 2055 the files were loaded onto an MS-DOS file system--something you may or 2056 may not care about. 2341 You might want to make sure that none of the file names would 2342 conflict the files were loaded onto an MS-DOS file system which 2343 shortens the names. You can use the program `doschk' to test for this. 2344 2345 Some GNU programs were designed to limit themselves to file names of 2346 14 characters or less, to avoid file name conflicts if they are read 2347 into older System V systems. Please preserve this feature in the 2348 existing GNU programs that have it, but there is no need to do this in 2349 new GNU programs. `doschk' also reports file names longer than 14 2350 characters. 2057 2351 2058 2352 … … 2067 2361 2068 2362 The primary purpose of GNU software is to run on top of the GNU 2069 kernel, compiled with the GNU C compiler, on various types of CPU. The 2070 amount and kinds of variation among GNU systems on different CPUs will 2071 be comparable to the variation among Linux-based GNU systems or among 2072 BSD systems today. So the kinds of portability that are absolutely 2073 necessary are quite limited. 2074 2075 But many users do run GNU software on non-GNU Unix or Unix-like 2076 systems. So supporting a variety of Unix-like systems is desirable, 2077 although not paramount. 2363 kernel, compiled with the GNU C compiler, on various types of CPU. So 2364 the kinds of portability that are absolutely necessary are quite 2365 limited. But it is important to support Linux-based GNU systems, since 2366 they are the form of GNU that is popular. 2367 2368 Beyond that, it is good to support the other free operating systems 2369 (*BSD), and it is nice to support other Unix-like systems if you want 2370 to. Supporting a variety of Unix-like systems is desirable, although 2371 not paramount. It is usually not too hard, so you may as well do it. 2372 But you don't have to consider it an obligation, if it does turn out to 2373 be hard. 2078 2374 2079 2375 The easiest way to achieve portability to most Unix-like systems is … … 2087 2383 2088 2384 As for systems that are not like Unix, such as MSDOS, Windows, the 2089 Macintosh, VMS, and MVS, supporting them is usually so much work that it 2090 is better if you don't. 2091 2092 The planned GNU kernel is not finished yet, but you can tell which 2093 facilities it will provide by looking at the GNU C Library Manual. The 2094 GNU kernel is based on Mach, so the features of Mach will also be 2095 available. However, if you use Mach features, you'll probably have 2096 trouble debugging your program today. 2385 Macintosh, VMS, and MVS, supporting them is often a lot of work. When 2386 that is the case, it is better to spend your time adding features that 2387 will be useful on GNU and GNU/Linux, rather than on supporting other 2388 incompatible systems. 2389 2390 It is a good idea to define the "feature test macro" `_GNU_SOURCE' 2391 when compiling your C files. When you compile on GNU or GNU/Linux, 2392 this will enable the declarations of GNU library extension functions, 2393 and that will usually give you a compiler error message if you define 2394 the same function names in some other way in your program. (You don't 2395 have to actually _use_ these functions, if you prefer to make the 2396 program more portable to other systems.) 2397 2398 But whether or not you use these GNU extensions, you should avoid 2399 using their names for any other meanings. Doing so would make it hard 2400 to move your code into other GNU programs. 2097 2401 2098 2402 … … 2109 2413 GNU. 2110 2414 2415 Similarly, don't make any effort to cater to the possibility that 2416 `long' will be smaller than predefined types like `size_t'. For 2417 example, the following code is ok: 2418 2419 printf ("size = %lu\n", (unsigned long) sizeof array); 2420 printf ("diff = %ld\n", (long) (pointer2 - pointer1)); 2421 2422 1989 Standard C requires this to work, and we know of only one 2423 counterexample: 64-bit programs on Microsoft Windows IA-64. We will 2424 leave it to those who want to port GNU programs to that environment to 2425 figure out how to do it. 2426 2427 Predefined file-size types like `off_t' are an exception: they are 2428 longer than `long' on many platforms, so code like the above won't work 2429 with them. One way to print an `off_t' value portably is to print its 2430 digits yourself, one by one. 2431 2111 2432 Don't assume that the address of an `int' object is also the address 2112 2433 of its least-significant byte. This is false on big-endian machines. … … 2121 2442 between pointers of various types, or between pointers and integers. 2122 2443 On most machines, there's no difference anyway. As for the few 2123 machines where there is a difference, all of them support ANSI C, so2124 you can use prototypes (conditionalized to be active only in ANSI C) to 2125 make the code work on those systems.2444 machines where there is a difference, all of them support Standard C 2445 prototypes, so you can use prototypes (perhaps conditionalized to be 2446 active only in Standard C) to make the code work on those systems. 2126 2447 2127 2448 In certain cases, it is ok to pass integer and pointer arguments … … 2132 2453 error (s, a1, a2, a3) 2133 2454 char *s; 2134 int a1, a2,a3;2455 char *a1, *a2, *a3; 2135 2456 { 2136 2457 fprintf (stderr, "error: "); … … 2138 2459 } 2139 2460 2140 In practice, this works on all machines, and it is much simpler than any 2461 In practice, this works on all machines, since a pointer is generally 2462 the widest possible kind of argument; it is much simpler than any 2141 2463 "correct" alternative. Be sure _not_ to use a prototype for such 2142 2464 functions. 2143 2465 2144 However, avoid casting pointers to integers unless you really need 2145 to. These assumptions really reduce portability, and in most programs 2146 they are easy to avoid. In the cases where casting pointers to 2147 integers is essential--such as, a Lisp interpreter which stores type 2148 information as well as an address in one word--it is ok to do so, but 2149 you'll have to make explicit provisions to handle different word sizes. 2466 If you have decided to use Standard C, then you can instead define 2467 `error' using `stdarg.h', and pass the arguments along to `vfprintf'. 2468 2469 Avoid casting pointers to integers if you can. Such casts greatly 2470 reduce portability, and in most programs they are easy to avoid. In the 2471 cases where casting pointers to integers is essential--such as, a Lisp 2472 interpreter which stores type information as well as an address in one 2473 word--you'll have to make explicit provisions to handle different word 2474 sizes. You will also need to make provision for systems in which the 2475 normal range of addresses you can get from `malloc' starts far away 2476 from zero. 2150 2477 2151 2478 … … 2155 2482 ======================== 2156 2483 2157 C implementations differ substantially. ANSI C reduces but does not2158 eliminate the incompatibilities; meanwhile, many users wish to compile 2159 GNU software with pre-ANSI compilers. This chapter gives2160 recommendations for how to use the more or less standard C library 2161 functions to avoid unnecessary loss of portability.2162 2163 * Don't use the value of `sprintf'. It returns the number of2484 C implementations differ substantially. Standard C reduces but does 2485 not eliminate the incompatibilities; meanwhile, many GNU packages still 2486 support pre-standard compilers because this is not hard to do. This 2487 chapter gives recommendations for how to use the more-or-less standard C 2488 library functions to avoid unnecessary loss of portability. 2489 2490 * Don't use the return value of `sprintf'. It returns the number of 2164 2491 characters written on some systems, but not on all systems. 2492 2493 * Be aware that `vfprintf' is not always available. 2165 2494 2166 2495 * `main' should be declared to return type `int'. It should … … 2182 2511 2183 2512 * If you must declare a system function, don't specify the argument 2184 types. Use an old-style declaration, not an ANSI prototype. The 2185 more you specify about the function, the more likely a conflict. 2513 types. Use an old-style declaration, not a Standard C prototype. 2514 The more you specify about the function, the more likely a 2515 conflict. 2186 2516 2187 2517 * In particular, don't unconditionally declare `malloc' or `realloc'. … … 2211 2541 usual way. 2212 2542 2213 That causes less of a problem than you might think. The newer ANSI2214 st ring functions should be avoided anyway because many systems2215 s till don't support them. The string functions you can use are2216 these:2543 That causes less of a problem than you might think. The newer 2544 standard string functions should be avoided anyway because many 2545 systems still don't support them. The string functions you can 2546 use are these: 2217 2547 2218 2548 strcpy strncpy strcat strncat … … 2240 2570 You should pick a single pair of names and use it throughout your 2241 2571 program. (Nowadays, it is better to choose `strchr' and `strrchr' 2242 for new programs, since those are the standard ANSI names.)2243 Declare both of those names as functions returning `char *'. On2244 systems which don't support those names, define them as macros in2245 t erms of the other pair. For example, here is what to put at the2246 beginning of your file (or in a header) if you want to use the2247 names`strchr' and `strrchr' throughout:2572 for new programs, since those are the standard names.) Declare 2573 both of those names as functions returning `char *'. On systems 2574 which don't support those names, define them as macros in terms of 2575 the other pair. For example, here is what to put at the beginning 2576 of your file (or in a header) if you want to use the names 2577 `strchr' and `strrchr' throughout: 2248 2578 2249 2579 #ifndef HAVE_STRCHR … … 2366 2696 ******************** 2367 2697 2698 A GNU program should ideally come with full free documentation, 2699 adequate for both reference and tutorial purposes. If the package can 2700 be programmed or extended, the documentation should cover programming or 2701 extending it, as well as just using it. 2702 2368 2703 * Menu: 2369 2704 2370 2705 * GNU Manuals:: Writing proper manuals. 2706 * Doc Strings and Manuals:: Compiling doc strings doesn't make a manual. 2371 2707 * Manual Structure Details:: Specific structure conventions. 2708 * License for Manuals:: Writing the distribution terms for a manual. 2709 * Manual Credits:: Giving credit to documentation contributors. 2710 * Printed Manuals:: Mentioning the printed manual. 2372 2711 * NEWS File:: NEWS files supplement manuals. 2373 2712 * Change Logs:: Recording Changes … … 2377 2716 2378 2717 2379 File: standards.info, Node: GNU Manuals, Next: Manual Structure Details, Up: Documentation2718 File: standards.info, Node: GNU Manuals, Next: Doc Strings and Manuals, Up: Documentation 2380 2719 2381 2720 GNU Manuals 2382 2721 =========== 2383 2722 2384 The preferred way to document part of the GNU system is to write a 2385 manual in the Texinfo formatting language. See the Texinfo manual, 2386 either the hardcopy, or the on-line version available through `info' or 2387 the Emacs Info subsystem (`C-h i'). 2723 The preferred document format for the GNU system is the Texinfo 2724 formatting language. Every GNU package should (ideally) have 2725 documentation in Texinfo both for reference and for learners. Texinfo 2726 makes it possible to produce a good quality formatted book, using TeX, 2727 and to generate an Info file. It is also possible to generate HTML 2728 output from Texinfo source. See the Texinfo manual, either the 2729 hardcopy, or the on-line version available through `info' or the Emacs 2730 Info subsystem (`C-h i'). 2731 2732 Nowadays some other formats such as Docbook and Sgmltexi can be 2733 converted automatically into Texinfo. It is ok to produce the Texinfo 2734 documentation by conversion this way, as long as it gives good results. 2388 2735 2389 2736 Programmers often find it most natural to structure the documentation … … 2414 2761 the whole subject clearer. 2415 2762 2416 The manual which discusses a program should document all of the2417 program's command-line options and all of its commands. It should give 2418 examples of their use. But don't organize the manual as a list of2763 The manual which discusses a program should certainly document all of 2764 the program's command-line options and all of its commands. It should 2765 give examples of their use. But don't organize the manual as a list of 2419 2766 features. Instead, organize it logically, by subtopics. Address the 2420 2767 questions that a user will ask when thinking about the job that the … … 2425 2772 and for reading straight through (appendixes aside). A GNU manual 2426 2773 should give a good introduction to a beginner reading through from the 2427 start, and should also provide all the details that hackers want. 2774 start, and should also provide all the details that hackers want. The 2775 Bison manual is a good example of this--please take a look at it to see 2776 what we mean. 2428 2777 2429 2778 That is not as hard as it first sounds. Arrange each chapter as a … … 2439 2788 Bison manual provides a good example of how to do this. 2440 2789 2790 To serve as a reference, a manual should have an Index that list all 2791 the functions, variables, options, and important concepts that are part 2792 of the program. One combined Index should do for a short manual, but 2793 sometimes for a complex package it is better to use multiple indices. 2794 The Texinfo manual includes advice on preparing good index entries, see 2795 *Note Making Index Entries: (texinfo)Index Entries, and see *Note 2796 Defining the Entries of an Index: (texinfo)Indexing Commands. 2797 2441 2798 Don't use Unix man pages as a model for how to write GNU 2442 2799 documentation; most of them are terse, badly structured, and give 2443 2800 inadequate explanation of the underlying concepts. (There are, of 2444 course exceptions.) Also Unix man pages use a particular format which 2445 is different from what we use in GNU manuals. 2801 course, some exceptions.) Also, Unix man pages use a particular format 2802 which is different from what we use in GNU manuals. 2803 2804 Please include an email address in the manual for where to report 2805 bugs _in the manual_. 2446 2806 2447 2807 Please do not use the term "pathname" that is used in Unix 2448 2808 documentation; use "file name" (two words) instead. We use the term 2449 "path" only for search paths, which are lists of filenames.2809 "path" only for search paths, which are lists of directory names. 2450 2810 2451 2811 Please do not use the term "illegal" to refer to erroneous input to a 2452 2812 computer program. Please use "invalid" for this, and reserve the term 2453 "illegal" for violations of law. 2454 2455 2456 File: standards.info, Node: Manual Structure Details, Next: NEWS File, Prev: GNU Manuals, Up: Documentation 2813 "illegal" for activities punishable by law. 2814 2815 2816 File: standards.info, Node: Doc Strings and Manuals, Next: Manual Structure Details, Prev: GNU Manuals, Up: Documentation 2817 2818 Doc Strings and Manuals 2819 ======================= 2820 2821 Some programming systems, such as Emacs, provide a documentation 2822 string for each function, command or variable. You may be tempted to 2823 write a reference manual by compiling the documentation strings and 2824 writing a little additional text to go around them--but you must not do 2825 it. That approach is a fundamental mistake. The text of well-written 2826 documentation strings will be entirely wrong for a manual. 2827 2828 A documentation string needs to stand alone--when it appears on the 2829 screen, there will be no other text to introduce or explain it. 2830 Meanwhile, it can be rather informal in style. 2831 2832 The text describing a function or variable in a manual must not stand 2833 alone; it appears in the context of a section or subsection. Other text 2834 at the beginning of the section should explain some of the concepts, and 2835 should often make some general points that apply to several functions or 2836 variables. The previous descriptions of functions and variables in the 2837 section will also have given information about the topic. A description 2838 written to stand alone would repeat some of that information; this 2839 redundance looks bad. Meanwhile, the informality that is acceptable in 2840 a documentation string is totally unacceptable in a manual. 2841 2842 The only good way to use documentation strings in writing a good 2843 manual is to use them as a source of information for writing good text. 2844 2845 2846 File: standards.info, Node: Manual Structure Details, Next: License for Manuals, Prev: Doc Strings and Manuals, Up: Documentation 2457 2847 2458 2848 Manual Structure Details … … 2465 2855 number for the manual in both of these places. 2466 2856 2467 Each program documented in the manual should shouldhave a node named2857 Each program documented in the manual should have a node named 2468 2858 `PROGRAM Invocation' or `Invoking PROGRAM'. This node (together with 2469 2859 its subnodes, if any) should describe the program's command line … … 2476 2866 to as the node for this purpose, regardless of the node's actual name. 2477 2867 2478 There will be automatic features for specifying a program name and 2479 quickly reading just this part of its manual. 2868 The `--usage' feature of the Info reader looks for such a node or 2869 menu item in order to find the relevant text, so it is essential for 2870 every Texinfo file to have one. 2480 2871 2481 2872 If one manual describes several programs, it should have such a node 2482 for each program described. 2483 2484 2485 File: standards.info, Node: NEWS File, Next: Change Logs, Prev: Manual Structure Details, Up: Documentation 2873 for each program described in the manual. 2874 2875 2876 File: standards.info, Node: License for Manuals, Next: Manual Credits, Prev: Manual Structure Details, Up: Documentation 2877 2878 License for Manuals 2879 =================== 2880 2881 Please use the GNU Free Documentation License for all GNU manuals 2882 that are more than a few pages long. Likewise for a collection of short 2883 documents--you only need one copy of the GNU FDL for the whole 2884 collection. For a single short document, you can use a very permissive 2885 non-copyleft license, to avoid taking up space with a long license. 2886 2887 See `http://www.gnu.org/copyleft/fdl-howto.html' for more explanation 2888 of how to employ the GFDL. 2889 2890 Note that it is not obligatory to include a copy of the GNU GPL or 2891 GNU LGPL in a manual whose license is neither the GPL nor the LGPL. It 2892 can be a good idea to include the program's license in a large manual; 2893 in a short manual, whose size would be increased considerably by 2894 including the program's license, it is probably better not to include 2895 it. 2896 2897 2898 File: standards.info, Node: Manual Credits, Next: Printed Manuals, Prev: License for Manuals, Up: Documentation 2899 2900 Manual Credits 2901 ============== 2902 2903 Please credit the principal human writers of the manual as the 2904 authors, on the title page of the manual. If a company sponsored the 2905 work, thank the company in a suitable place in the manual, but do not 2906 cite the company as an author. 2907 2908 2909 File: standards.info, Node: Printed Manuals, Next: NEWS File, Prev: Manual Credits, Up: Documentation 2910 2911 Printed Manuals 2912 =============== 2913 2914 The FSF publishes some GNU manuals in printed form. To encourage 2915 sales of these manuals, the on-line versions of the manual should 2916 mention at the very start that the printed manual is available and 2917 should point at information for getting it--for instance, with a link 2918 to the page <http://www.gnu.org/order/order.html>. This should not be 2919 included in the printed manual, though, because there it is redundant. 2920 2921 It is also useful to explain in the on-line forms of the manual how 2922 the user can print out the manual from the sources. 2923 2924 2925 File: standards.info, Node: NEWS File, Next: Change Logs, Prev: Printed Manuals, Up: Documentation 2486 2926 2487 2927 The NEWS File … … 2519 2959 * Simple Changes:: 2520 2960 * Conditional Changes:: 2961 * Indicating the Part Changed:: 2521 2962 2522 2963 … … 2538 2979 Another alternative is to record change log information with a 2539 2980 version control system such as RCS or CVS. This can be converted 2540 automatically to a `ChangeLog' file. 2981 automatically to a `ChangeLog' file using `rcs2log'; in Emacs, the 2982 command `C-x v a' (`vc-update-change-log') does the job. 2541 2983 2542 2984 There's no need to describe the full purpose of the changes or how … … 2563 3005 -------------------- 2564 3006 2565 Here are some examples of change log entries: 2566 3007 Here are some simple examples of change log entries, starting with 3008 the header line that says who made the change and when, followed by 3009 descriptions of specific changes. (These examples are drawn from Emacs 3010 and GCC.) 3011 3012 1998-08-17 Richard Stallman <rms@gnu.org> 3013 2567 3014 * register.el (insert-register): Return nil. 2568 3015 (jump-to-register): Likewise. … … 2594 3041 name and the asterisk when successive entries are in the same file. 2595 3042 3043 Break long lists of function names by closing continued lines with 3044 `)', rather than `,', and opening the continuation with `(' as in this 3045 example: 3046 3047 * keyboard.c (menu_bar_items, tool_bar_items) 3048 (Fexecute_extended_command): Deal with `keymap' property. 3049 2596 3050 2597 3051 File: standards.info, Node: Simple Changes, Next: Conditional Changes, Prev: Style of Change Logs, Up: Change Logs … … 2604 3058 2605 3059 When you change the calling sequence of a function in a simple 2606 fashion, and you change all the callers of the function , there is no2607 need to make individual entries for all the callers that you changed. 2608 Just write in the entry for the function being called, "All callers 2609 changed." 3060 fashion, and you change all the callers of the function to use the new 3061 calling sequence, there is no need to make individual entries for all 3062 the callers that you changed. Just write in the entry for the function 3063 being called, "All callers changed"--like this: 2610 3064 2611 3065 * keyboard.c (Fcommand_execute): New arg SPECIAL. … … 2624 3078 2625 3079 2626 File: standards.info, Node: Conditional Changes, Prev: Simple Changes, Up: Change Logs3080 File: standards.info, Node: Conditional Changes, Next: Indicating the Part Changed, Prev: Simple Changes, Up: Change Logs 2627 3081 2628 3082 Conditional Changes … … 2658 3112 2659 3113 (gethostname) [!HAVE_SOCKETS]: Replace with winsock version. 3114 3115 3116 File: standards.info, Node: Indicating the Part Changed, Prev: Conditional Changes, Up: Change Logs 3117 3118 Indicating the Part Changed 3119 --------------------------- 3120 3121 Indicate the part of a function which changed by using angle brackets 3122 enclosing an indication of what the changed part does. Here is an entry 3123 for a change in the part of the function `sh-while-getopts' that deals 3124 with `sh' commands: 3125 3126 * progmodes/sh-script.el (sh-while-getopts) <sh>: Handle case that 3127 user-specified option string is empty. 2660 3128 2661 3129 … … 2712 3180 2713 3181 2714 File: standards.info, Node: Managing Releases, Prev: Documentation, Up: Top3182 File: standards.info, Node: Managing Releases, Next: References, Prev: Documentation, Up: Top 2715 3183 2716 3184 The Release Process … … 2728 3196 2729 3197 * Configuration:: How Configuration Should Work 2730 * Makefile Conventions:: 3198 * Makefile Conventions:: Makefile Conventions 2731 3199 * Releases:: Making Releases 2732 3200 … … 2834 3302 options are for. 2835 3303 2836 `--nfp'2837 The target machine has no floating point processor.2838 2839 `--gas'2840 The target machine assembler is GAS, the GNU assembler. This is2841 obsolete; users should use `--with-gnu-as' instead.2842 2843 `--x'2844 The target machine has the X Window System installed. This is2845 obsolete; users should use `--with-x' instead.2846 2847 3304 All `configure' scripts should accept all of these "detail" options, 2848 3305 whether or not they make any difference to the particular package at … … 2858 3315 2859 3316 Packages that perform part of the compilation process may support 2860 cross-compilation. In such a case, the host and target machines for 2861 the program may be different. The `configure' script should normally 2862 treat the specified type of system as both the host and the target, 2863 thus producing a program which works for the same type of machine that 2864 it runs on. 2865 2866 The way to build a cross-compiler, cross-assembler, or what have 2867 you, is to specify the option `--host=HOSTTYPE' when running 2868 `configure'. This specifies the host system without changing the type 2869 of target system. The syntax for HOSTTYPE is the same as described 2870 above. 3317 cross-compilation. In such a case, the host and target machines for the 3318 program may be different. 3319 3320 The `configure' script should normally treat the specified type of 3321 system as both the host and the target, thus producing a program which 3322 works for the same type of machine that it runs on. 3323 3324 To configure a cross-compiler, cross-assembler, or what have you, you 3325 should specify a target different from the host, using the configure 3326 option `--target=TARGETTYPE'. The syntax for TARGETTYPE is the same as 3327 for the host type. So the command would look like this: 3328 3329 ./configure HOSTTYPE --target=TARGETTYPE 3330 3331 Programs for which cross-operation is not meaningful need not accept 3332 the `--target' option, because configuring an entire operating system 3333 for cross-operation is not a meaningful operation. 2871 3334 2872 3335 Bootstrapping a cross-compiler requires compiling it on a machine 2873 3336 other than the host it will run on. Compilation packages accept a 2874 configuration option `--build=HOSTTYPE' for specifying the 2875 configuration on which you will compile them, in case that is different 2876 from the host. 2877 2878 Programs for which cross-operation is not meaningful need not accept 2879 the `--host' option, because configuring an entire operating system for 2880 cross-operation is not a meaningful thing. 3337 configuration option `--build=BUILDTYPE' for specifying the 3338 configuration on which you will compile them, but the configure script 3339 should normally guess the build machine type (using `config.guess'), so 3340 this option is probably not necessary. The host and target types 3341 normally default from the build type, so in bootstrapping a 3342 cross-compiler you must specify them both explicitly. 2881 3343 2882 3344 Some programs have ways of configuring themselves automatically. If … … 2891 3353 2892 3354 This node describes conventions for writing the Makefiles for GNU 2893 programs. 3355 programs. Using Automake will help you write a Makefile that follows 3356 these conventions. 2894 3357 2895 3358 * Menu: 2896 3359 2897 * Makefile Basics:: 2898 * Utilities in Makefiles:: 2899 * Command Variables:: 2900 * Directory Variables:: 2901 * Standard Targets:: 3360 * Makefile Basics:: General Conventions for Makefiles 3361 * Utilities in Makefiles:: Utilities in Makefiles 3362 * Command Variables:: Variables for Specifying Commands 3363 * Directory Variables:: Variables for Installation Directories 3364 * Standard Targets:: Standard Targets for Users 2902 3365 * Install Command Categories:: Three categories of commands in the `install' 2903 3366 rule: normal, pre-install and post-install. … … 2944 3407 2945 3408 will fail when the build directory is not the source directory, because 2946 `foo.man' and `sedscript' are in the thesource directory.3409 `foo.man' and `sedscript' are in the source directory. 2947 3410 2948 3411 When using GNU `make', relying on `VPATH' to find the source file … … 3095 3558 3096 3559 Every Makefile should also define the variables `INSTALL_PROGRAM' 3097 and `INSTALL_DATA'. (The default for each of these should be 3098 `$(INSTALL)'.) Then it should use those variables as the commands for 3099 actual installation, for executables and nonexecutables respectively. 3100 Use these variables as follows: 3560 and `INSTALL_DATA'. (The default for `INSTALL_PROGRAM' should be 3561 `$(INSTALL)'; the default for `INSTALL_DATA' should be `${INSTALL} -m 3562 644'.) Then it should use those variables as the commands for actual 3563 installation, for executables and nonexecutables respectively. Use 3564 these variables as follows: 3101 3565 3102 3566 $(INSTALL_PROGRAM) foo $(bindir)/foo … … 3126 3590 is easy to install in a nonstandard place. The standard names for these 3127 3591 variables are described below. They are based on a standard filesystem 3128 layout; variants of it are used in SVR4, 4.4BSD, Linux, Ultrix v4, and3129 other modern operating systems.3592 layout; variants of it are used in SVR4, 4.4BSD, GNU/Linux, Ultrix v4, 3593 and other modern operating systems. 3130 3594 3131 3595 These two variables set the root for the installation. All the other … … 3141 3605 3142 3606 Running `make install' with a different value of `prefix' from the 3143 one used to build the program should NOTrecompile the program.3607 one used to build the program should _not_ recompile the program. 3144 3608 3145 3609 `exec_prefix' … … 3155 3619 3156 3620 Running `make install' with a different value of `exec_prefix' 3157 from the one used to build the program should NOTrecompile the3621 from the one used to build the program should _not_ recompile the 3158 3622 program. 3159 3623 … … 3452 3916 `install-strip' 3453 3917 Like `install', but strip the executable files while installing 3454 them. In many cases, the definition of this target can be very3455 simple:3918 them. In simple cases, this target can use the `install' target in 3919 a simple way: 3456 3920 3457 3921 install-strip: 3458 3922 $(MAKE) INSTALL_PROGRAM='$(INSTALL_PROGRAM) -s' \ 3459 3923 install 3924 3925 But if the package installs scripts as well as real executables, 3926 the `install-strip' target can't just refer to the `install' 3927 target; it has to strip the executables but not the scripts. 3928 3929 `install-strip' should not strip the executables in the build 3930 directory which are being copied for installation. It should only 3931 strip the copies that are installed. 3460 3932 3461 3933 Normally we do not recommend stripping an executable unless you … … 3562 4034 in it, and then `tar' that subdirectory. 3563 4035 3564 Compress the tar file filewith `gzip'. For example, the actual4036 Compress the tar file with `gzip'. For example, the actual 3565 4037 distribution file for GCC version 1.40 is called `gcc-1.40.tar.gz'. 3566 4038 … … 3597 4069 $(mandir) 3598 4070 4071 or, if you wish to support `DESTDIR', 4072 4073 # Make sure all installation directories (e.g. $(bindir)) 4074 # actually exist by making them if necessary. 4075 installdirs: mkinstalldirs 4076 $(srcdir)/mkinstalldirs \ 4077 $(DESTDIR)$(bindir) $(DESTDIR)$(datadir) \ 4078 $(DESTDIR)$(libdir) $(DESTDIR)$(infodir) \ 4079 $(DESTDIR)$(mandir) 4080 3599 4081 This rule should not modify the directories where compilation is 3600 4082 done. It should do nothing but create installation directories. … … 3727 4209 never changed automatically; non-source files are produced from source 3728 4210 files by programs under the control of the Makefile. 4211 4212 The distribution should contain a file named `README' which gives 4213 the name of the package, and a general description of what it does. It 4214 is also good to explain the purpose of each of the first-level 4215 subdirectories in the package, if there are any. The `README' file 4216 should either state the version number of the package, or refer to where 4217 in the package it can be found. 4218 4219 The `README' file should refer to the file `INSTALL', which should 4220 contain an explanation of the installation procedure. 4221 4222 The `README' file should also refer to the file which contains the 4223 copying conditions. The GNU GPL, if used, should be in a file called 4224 `COPYING'. If the GNU LGPL is used, it should be in a file called 4225 `COPYING.LIB'. 3729 4226 3730 4227 Naturally, all the source files must be in the distribution. It is … … 3778 4275 know what other files to get. 3779 4276 4277 4278 File: standards.info, Node: References, Next: Copying This Manual, Prev: Managing Releases, Up: Top 4279 4280 References to Non-Free Software and Documentation 4281 ************************************************* 4282 4283 A GNU program should not recommend use of any non-free program. We 4284 can't stop some people from writing proprietary programs, or stop other 4285 people from using them, but we can and should avoid helping to 4286 advertise them to new potential customers. Proprietary software is a 4287 social and ethical problem, and the point of GNU is to solve that 4288 problem. 4289 4290 When a non-free program or system is well known, you can mention it 4291 in passing--that is harmless, since users who might want to use it 4292 probably already know about it. For instance, it is fine to explain 4293 how to build your package on top of some non-free operating system, or 4294 how to use it together with some widely used non-free program. 4295 4296 However, you should give only the necessary information to help those 4297 who already use the non-free program to use your program with it--don't 4298 give, or refer to, any further information about the proprietary 4299 program, and don't imply that the proprietary program enhances your 4300 program, or that its existence is in any way a good thing. The goal 4301 should be that people already using the proprietary program will get 4302 the advice they need about how to use your free program, while people 4303 who don't already use the proprietary program will not see anything to 4304 lead them to take an interest in it. 4305 4306 If a non-free program or system is obscure in your program's domain, 4307 your program should not mention or support it at all, since doing so 4308 would tend to popularize the non-free program more than it popularizes 4309 your program. (You cannot hope to find many additional users among the 4310 users of Foobar if the users of Foobar are few.) 4311 4312 A GNU package should not refer the user to any non-free documentation 4313 for free software. Free documentation that can be included in free 4314 operating systems is essential for completing the GNU system, so it is 4315 a major focus of the GNU Project; to recommend use of documentation 4316 that we are not allowed to use in GNU would undermine the efforts to 4317 get documentation that we can include. So GNU packages should never 4318 recommend non-free documentation. 4319 4320 4321 File: standards.info, Node: Copying This Manual, Next: Index, Prev: References, Up: Top 4322 4323 Copying This Manual 4324 ******************* 4325 4326 * Menu: 4327 4328 * GNU Free Documentation License:: License for copying this manual 4329 4330 4331 File: standards.info, Node: GNU Free Documentation License, Up: Copying This Manual 4332 4333 GNU Free Documentation License 4334 ****************************** 4335 4336 Version 1.1, March 2000 4337 Copyright (C) 2000 Free Software Foundation, Inc. 4338 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 4339 4340 Everyone is permitted to copy and distribute verbatim copies 4341 of this license document, but changing it is not allowed. 4342 4343 4344 0. PREAMBLE 4345 4346 The purpose of this License is to make a manual, textbook, or other 4347 written document "free" in the sense of freedom: to assure everyone 4348 the effective freedom to copy and redistribute it, with or without 4349 modifying it, either commercially or noncommercially. Secondarily, 4350 this License preserves for the author and publisher a way to get 4351 credit for their work, while not being considered responsible for 4352 modifications made by others. 4353 4354 This License is a kind of "copyleft", which means that derivative 4355 works of the document must themselves be free in the same sense. 4356 It complements the GNU General Public License, which is a copyleft 4357 license designed for free software. 4358 4359 We have designed this License in order to use it for manuals for 4360 free software, because free software needs free documentation: a 4361 free program should come with manuals providing the same freedoms 4362 that the software does. But this License is not limited to 4363 software manuals; it can be used for any textual work, regardless 4364 of subject matter or whether it is published as a printed book. 4365 We recommend this License principally for works whose purpose is 4366 instruction or reference. 4367 4368 4369 1. APPLICABILITY AND DEFINITIONS 4370 4371 This License applies to any manual or other work that contains a 4372 notice placed by the copyright holder saying it can be distributed 4373 under the terms of this License. The "Document", below, refers to 4374 any such manual or work. Any member of the public is a licensee, 4375 and is addressed as "you." 4376 4377 A "Modified Version" of the Document means any work containing the 4378 Document or a portion of it, either copied verbatim, or with 4379 modifications and/or translated into another language. 4380 4381 A "Secondary Section" is a named appendix or a front-matter 4382 section of the Document that deals exclusively with the 4383 relationship of the publishers or authors of the Document to the 4384 Document's overall subject (or to related matters) and contains 4385 nothing that could fall directly within that overall subject. 4386 (For example, if the Document is in part a textbook of 4387 mathematics, a Secondary Section may not explain any mathematics.) 4388 The relationship could be a matter of historical connection with 4389 the subject or with related matters, or of legal, commercial, 4390 philosophical, ethical or political position regarding them. 4391 4392 The "Invariant Sections" are certain Secondary Sections whose 4393 titles are designated, as being those of Invariant Sections, in 4394 the notice that says that the Document is released under this 4395 License. 4396 4397 The "Cover Texts" are certain short passages of text that are 4398 listed, as Front-Cover Texts or Back-Cover Texts, in the notice 4399 that says that the Document is released under this License. 4400 4401 A "Transparent" copy of the Document means a machine-readable copy, 4402 represented in a format whose specification is available to the 4403 general public, whose contents can be viewed and edited directly 4404 and straightforwardly with generic text editors or (for images 4405 composed of pixels) generic paint programs or (for drawings) some 4406 widely available drawing editor, and that is suitable for input to 4407 text formatters or for automatic translation to a variety of 4408 formats suitable for input to text formatters. A copy made in an 4409 otherwise Transparent file format whose markup has been designed 4410 to thwart or discourage subsequent modification by readers is not 4411 Transparent. A copy that is not "Transparent" is called "Opaque." 4412 4413 Examples of suitable formats for Transparent copies include plain 4414 ASCII without markup, Texinfo input format, LaTeX input format, 4415 SGML or XML using a publicly available DTD, and 4416 standard-conforming simple HTML designed for human modification. 4417 Opaque formats include PostScript, PDF, proprietary formats that 4418 can be read and edited only by proprietary word processors, SGML 4419 or XML for which the DTD and/or processing tools are not generally 4420 available, and the machine-generated HTML produced by some word 4421 processors for output purposes only. 4422 4423 The "Title Page" means, for a printed book, the title page itself, 4424 plus such following pages as are needed to hold, legibly, the 4425 material this License requires to appear in the title page. For 4426 works in formats which do not have any title page as such, "Title 4427 Page" means the text near the most prominent appearance of the 4428 work's title, preceding the beginning of the body of the text. 4429 4430 2. VERBATIM COPYING 4431 4432 You may copy and distribute the Document in any medium, either 4433 commercially or noncommercially, provided that this License, the 4434 copyright notices, and the license notice saying this License 4435 applies to the Document are reproduced in all copies, and that you 4436 add no other conditions whatsoever to those of this License. You 4437 may not use technical measures to obstruct or control the reading 4438 or further copying of the copies you make or distribute. However, 4439 you may accept compensation in exchange for copies. If you 4440 distribute a large enough number of copies you must also follow 4441 the conditions in section 3. 4442 4443 You may also lend copies, under the same conditions stated above, 4444 and you may publicly display copies. 4445 4446 3. COPYING IN QUANTITY 4447 4448 If you publish printed copies of the Document numbering more than 4449 100, and the Document's license notice requires Cover Texts, you 4450 must enclose the copies in covers that carry, clearly and legibly, 4451 all these Cover Texts: Front-Cover Texts on the front cover, and 4452 Back-Cover Texts on the back cover. Both covers must also clearly 4453 and legibly identify you as the publisher of these copies. The 4454 front cover must present the full title with all words of the 4455 title equally prominent and visible. You may add other material 4456 on the covers in addition. Copying with changes limited to the 4457 covers, as long as they preserve the title of the Document and 4458 satisfy these conditions, can be treated as verbatim copying in 4459 other respects. 4460 4461 If the required texts for either cover are too voluminous to fit 4462 legibly, you should put the first ones listed (as many as fit 4463 reasonably) on the actual cover, and continue the rest onto 4464 adjacent pages. 4465 4466 If you publish or distribute Opaque copies of the Document 4467 numbering more than 100, you must either include a 4468 machine-readable Transparent copy along with each Opaque copy, or 4469 state in or with each Opaque copy a publicly-accessible 4470 computer-network location containing a complete Transparent copy 4471 of the Document, free of added material, which the general 4472 network-using public has access to download anonymously at no 4473 charge using public-standard network protocols. If you use the 4474 latter option, you must take reasonably prudent steps, when you 4475 begin distribution of Opaque copies in quantity, to ensure that 4476 this Transparent copy will remain thus accessible at the stated 4477 location until at least one year after the last time you 4478 distribute an Opaque copy (directly or through your agents or 4479 retailers) of that edition to the public. 4480 4481 It is requested, but not required, that you contact the authors of 4482 the Document well before redistributing any large number of 4483 copies, to give them a chance to provide you with an updated 4484 version of the Document. 4485 4486 4. MODIFICATIONS 4487 4488 You may copy and distribute a Modified Version of the Document 4489 under the conditions of sections 2 and 3 above, provided that you 4490 release the Modified Version under precisely this License, with 4491 the Modified Version filling the role of the Document, thus 4492 licensing distribution and modification of the Modified Version to 4493 whoever possesses a copy of it. In addition, you must do these 4494 things in the Modified Version: 4495 4496 A. Use in the Title Page (and on the covers, if any) a title 4497 distinct from that of the Document, and from those of previous 4498 versions (which should, if there were any, be listed in the 4499 History section of the Document). You may use the same title 4500 as a previous version if the original publisher of that version 4501 gives permission. 4502 B. List on the Title Page, as authors, one or more persons or 4503 entities responsible for authorship of the modifications in the 4504 Modified Version, together with at least five of the principal 4505 authors of the Document (all of its principal authors, if it 4506 has less than five). 4507 C. State on the Title page the name of the publisher of the 4508 Modified Version, as the publisher. 4509 D. Preserve all the copyright notices of the Document. 4510 E. Add an appropriate copyright notice for your modifications 4511 adjacent to the other copyright notices. 4512 F. Include, immediately after the copyright notices, a license 4513 notice giving the public permission to use the Modified Version 4514 under the terms of this License, in the form shown in the 4515 Addendum below. 4516 G. Preserve in that license notice the full lists of Invariant 4517 Sections and required Cover Texts given in the Document's 4518 license notice. 4519 H. Include an unaltered copy of this License. 4520 I. Preserve the section entitled "History", and its title, and add 4521 to it an item stating at least the title, year, new authors, and 4522 publisher of the Modified Version as given on the Title Page. 4523 If there is no section entitled "History" in the Document, 4524 create one stating the title, year, authors, and publisher of 4525 the Document as given on its Title Page, then add an item 4526 describing the Modified Version as stated in the previous 4527 sentence. 4528 J. Preserve the network location, if any, given in the Document for 4529 public access to a Transparent copy of the Document, and 4530 likewise the network locations given in the Document for 4531 previous versions it was based on. These may be placed in the 4532 "History" section. You may omit a network location for a work 4533 that was published at least four years before the Document 4534 itself, or if the original publisher of the version it refers 4535 to gives permission. 4536 K. In any section entitled "Acknowledgements" or "Dedications", 4537 preserve the section's title, and preserve in the section all the 4538 substance and tone of each of the contributor acknowledgements 4539 and/or dedications given therein. 4540 L. Preserve all the Invariant Sections of the Document, 4541 unaltered in their text and in their titles. Section numbers 4542 or the equivalent are not considered part of the section titles. 4543 M. Delete any section entitled "Endorsements." Such a section 4544 may not be included in the Modified Version. 4545 N. Do not retitle any existing section as "Endorsements" or to 4546 conflict in title with any Invariant Section. 4547 4548 If the Modified Version includes new front-matter sections or 4549 appendices that qualify as Secondary Sections and contain no 4550 material copied from the Document, you may at your option 4551 designate some or all of these sections as invariant. To do this, 4552 add their titles to the list of Invariant Sections in the Modified 4553 Version's license notice. These titles must be distinct from any 4554 other section titles. 4555 4556 You may add a section entitled "Endorsements", provided it contains 4557 nothing but endorsements of your Modified Version by various 4558 parties-for example, statements of peer review or that the text has 4559 been approved by an organization as the authoritative definition 4560 of a standard. 4561 4562 You may add a passage of up to five words as a Front-Cover Text, 4563 and a passage of up to 25 words as a Back-Cover Text, to the end 4564 of the list of Cover Texts in the Modified Version. Only one 4565 passage of Front-Cover Text and one of Back-Cover Text may be 4566 added by (or through arrangements made by) any one entity. If the 4567 Document already includes a cover text for the same cover, 4568 previously added by you or by arrangement made by the same entity 4569 you are acting on behalf of, you may not add another; but you may 4570 replace the old one, on explicit permission from the previous 4571 publisher that added the old one. 4572 4573 The author(s) and publisher(s) of the Document do not by this 4574 License give permission to use their names for publicity for or to 4575 assert or imply endorsement of any Modified Version. 4576 4577 5. COMBINING DOCUMENTS 4578 4579 You may combine the Document with other documents released under 4580 this License, under the terms defined in section 4 above for 4581 modified versions, provided that you include in the combination 4582 all of the Invariant Sections of all of the original documents, 4583 unmodified, and list them all as Invariant Sections of your 4584 combined work in its license notice. 4585 4586 The combined work need only contain one copy of this License, and 4587 multiple identical Invariant Sections may be replaced with a single 4588 copy. If there are multiple Invariant Sections with the same name 4589 but different contents, make the title of each such section unique 4590 by adding at the end of it, in parentheses, the name of the 4591 original author or publisher of that section if known, or else a 4592 unique number. Make the same adjustment to the section titles in 4593 the list of Invariant Sections in the license notice of the 4594 combined work. 4595 4596 In the combination, you must combine any sections entitled 4597 "History" in the various original documents, forming one section 4598 entitled "History"; likewise combine any sections entitled 4599 "Acknowledgements", and any sections entitled "Dedications." You 4600 must delete all sections entitled "Endorsements." 4601 4602 6. COLLECTIONS OF DOCUMENTS 4603 4604 You may make a collection consisting of the Document and other 4605 documents released under this License, and replace the individual 4606 copies of this License in the various documents with a single copy 4607 that is included in the collection, provided that you follow the 4608 rules of this License for verbatim copying of each of the 4609 documents in all other respects. 4610 4611 You may extract a single document from such a collection, and 4612 distribute it individually under this License, provided you insert 4613 a copy of this License into the extracted document, and follow 4614 this License in all other respects regarding verbatim copying of 4615 that document. 4616 4617 7. AGGREGATION WITH INDEPENDENT WORKS 4618 4619 A compilation of the Document or its derivatives with other 4620 separate and independent documents or works, in or on a volume of 4621 a storage or distribution medium, does not as a whole count as a 4622 Modified Version of the Document, provided no compilation 4623 copyright is claimed for the compilation. Such a compilation is 4624 called an "aggregate", and this License does not apply to the 4625 other self-contained works thus compiled with the Document, on 4626 account of their being thus compiled, if they are not themselves 4627 derivative works of the Document. 4628 4629 If the Cover Text requirement of section 3 is applicable to these 4630 copies of the Document, then if the Document is less than one 4631 quarter of the entire aggregate, the Document's Cover Texts may be 4632 placed on covers that surround only the Document within the 4633 aggregate. Otherwise they must appear on covers around the whole 4634 aggregate. 4635 4636 8. TRANSLATION 4637 4638 Translation is considered a kind of modification, so you may 4639 distribute translations of the Document under the terms of section 4640 4. Replacing Invariant Sections with translations requires special 4641 permission from their copyright holders, but you may include 4642 translations of some or all Invariant Sections in addition to the 4643 original versions of these Invariant Sections. You may include a 4644 translation of this License provided that you also include the 4645 original English version of this License. In case of a 4646 disagreement between the translation and the original English 4647 version of this License, the original English version will prevail. 4648 4649 9. TERMINATION 4650 4651 You may not copy, modify, sublicense, or distribute the Document 4652 except as expressly provided for under this License. Any other 4653 attempt to copy, modify, sublicense or distribute the Document is 4654 void, and will automatically terminate your rights under this 4655 License. However, parties who have received copies, or rights, 4656 from you under this License will not have their licenses 4657 terminated so long as such parties remain in full compliance. 4658 4659 10. FUTURE REVISIONS OF THIS LICENSE 4660 4661 The Free Software Foundation may publish new, revised versions of 4662 the GNU Free Documentation License from time to time. Such new 4663 versions will be similar in spirit to the present version, but may 4664 differ in detail to address new problems or concerns. See 4665 http://www.gnu.org/copyleft/. 4666 4667 Each version of the License is given a distinguishing version 4668 number. If the Document specifies that a particular numbered 4669 version of this License "or any later version" applies to it, you 4670 have the option of following the terms and conditions either of 4671 that specified version or of any later version that has been 4672 published (not as a draft) by the Free Software Foundation. If 4673 the Document does not specify a version number of this License, 4674 you may choose any version ever published (not as a draft) by the 4675 Free Software Foundation. 4676 4677 4678 ADDENDUM: How to use this License for your documents 4679 ==================================================== 4680 4681 To use this License in a document you have written, include a copy of 4682 the License in the document and put the following copyright and license 4683 notices just after the title page: 4684 4685 Copyright (C) YEAR YOUR NAME. 4686 Permission is granted to copy, distribute and/or modify this document 4687 under the terms of the GNU Free Documentation License, Version 1.1 4688 or any later version published by the Free Software Foundation; 4689 with the Invariant Sections being LIST THEIR TITLES, with the 4690 Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. 4691 A copy of the license is included in the section entitled "GNU 4692 Free Documentation License." 4693 4694 If you have no Invariant Sections, write "with no Invariant Sections" 4695 instead of saying which ones are invariant. If you have no Front-Cover 4696 Texts, write "no Front-Cover Texts" instead of "Front-Cover Texts being 4697 LIST"; likewise for Back-Cover Texts. 4698 4699 If your document contains nontrivial examples of program code, we 4700 recommend releasing these examples in parallel under your choice of 4701 free software license, such as the GNU General Public License, to 4702 permit their use in free software. 4703 4704 4705 File: standards.info, Node: Index, Prev: Copying This Manual, Up: Top 4706 4707 Index 4708 ***** 4709 4710 * Menu: 4711 4712 * #endif, commenting: Comments. 4713 * --help option: Command-Line Interfaces. 4714 * --version option: Command-Line Interfaces. 4715 * -Wall compiler option: Syntactic Conventions. 4716 * accepting contributions: Contributions. 4717 * address for bug reports: Command-Line Interfaces. 4718 * ANSI C standard: Standard C. 4719 * arbitrary limits on data: Semantics. 4720 * autoconf: System Portability. 4721 * avoiding proprietary code: Reading Non-Free Code. 4722 * behavior, dependent on program's name: User Interfaces. 4723 * binary packages: Install Command Categories. 4724 * bindir: Directory Variables. 4725 * braces, in C source: Formatting. 4726 * bug reports: Command-Line Interfaces. 4727 * canonical name of a program: Command-Line Interfaces. 4728 * casting pointers to integers: CPU Portability. 4729 * change logs: Change Logs. 4730 * change logs, conditional changes: Conditional Changes. 4731 * change logs, style: Style of Change Logs. 4732 * command-line arguments, decoding: Semantics. 4733 * command-line interface: Command-Line Interfaces. 4734 * commenting: Comments. 4735 * compatibility with C and POSIX standards: Compatibility. 4736 * compiler warnings: Syntactic Conventions. 4737 * conditional changes, and change logs: Conditional Changes. 4738 * conditionals, comments for: Comments. 4739 * configure: Configuration. 4740 * control-L: Formatting. 4741 * conventions for makefiles: Makefile Conventions. 4742 * corba: Graphical Interfaces. 4743 * credits for manuals: Manual Credits. 4744 * data types, and portability: CPU Portability. 4745 * declaration for system functions: System Functions. 4746 * documentation: Documentation. 4747 * doschk: Names. 4748 * downloading this manual: Preface. 4749 * error messages: Semantics. 4750 * error messages, formatting: Errors. 4751 * exec_prefix: Directory Variables. 4752 * expressions, splitting: Formatting. 4753 * file usage: File Usage. 4754 * file-name limitations: Names. 4755 * formatting error messages: Errors. 4756 * formatting source code: Formatting. 4757 * formfeed: Formatting. 4758 * function argument, declaring: Syntactic Conventions. 4759 * function prototypes: Standard C. 4760 * getopt: Command-Line Interfaces. 4761 * gettext: Internationalization. 4762 * gnome: Graphical Interfaces. 4763 * graphical user interface: Graphical Interfaces. 4764 * gtk: Graphical Interfaces. 4765 * GUILE: Source Language. 4766 * implicit int: Syntactic Conventions. 4767 * impossible conditions: Semantics. 4768 * internationalization: Internationalization. 4769 * legal aspects: Legal Issues. 4770 * legal papers: Contributions. 4771 * libexecdir: Directory Variables. 4772 * libraries: Libraries. 4773 * library functions, and portability: System Functions. 4774 * license for manuals: License for Manuals. 4775 * lint: Syntactic Conventions. 4776 * long option names: Option Table. 4777 * long-named options: Command-Line Interfaces. 4778 * makefile, conventions for: Makefile Conventions. 4779 * malloc return value: Semantics. 4780 * man pages: Man Pages. 4781 * manual structure: Manual Structure Details. 4782 * memory allocation failure: Semantics. 4783 * memory usage: Memory Usage. 4784 * message text, and internationalization: Internationalization. 4785 * mmap: Mmap. 4786 * multiple variables in a line: Syntactic Conventions. 4787 * names of variables, functions, and files: Names. 4788 * NEWS file: NEWS File. 4789 * non-POSIX systems, and portability: System Portability. 4790 * non-standard extensions: Using Extensions. 4791 * NUL characters: Semantics. 4792 * open brace: Formatting. 4793 * optional features, configure-time: Configuration. 4794 * options for compatibility: Compatibility. 4795 * output device and program's behavior: User Interfaces. 4796 * packaging: Releases. 4797 * portability, and data types: CPU Portability. 4798 * portability, and library functions: System Functions. 4799 * portability, between system types: System Portability. 4800 * POSIX compatibility: Compatibility. 4801 * POSIXLY_CORRECT, environment variable: Compatibility. 4802 * post-installation commands: Install Command Categories. 4803 * pre-installation commands: Install Command Categories. 4804 * prefix: Directory Variables. 4805 * program configuration: Configuration. 4806 * program design: Design Advice. 4807 * program name and its behavior: User Interfaces. 4808 * program's canonical name: Command-Line Interfaces. 4809 * programming languges: Source Language. 4810 * proprietary programs: Reading Non-Free Code. 4811 * README file: Releases. 4812 * references to non-free material: References. 4813 * releasing: Managing Releases. 4814 * sbindir: Directory Variables. 4815 * signal handling: Semantics. 4816 * spaces before open-paren: Formatting. 4817 * standard command-line options: Command-Line Interfaces. 4818 * standards for makefiles: Makefile Conventions. 4819 * string library functions: System Functions. 4820 * syntactic conventions: Syntactic Conventions. 4821 * table of long options: Option Table. 4822 * temporary files: Semantics. 4823 * temporary variables: Syntactic Conventions. 4824 * texinfo.tex, in a distribution: Releases. 4825 * TMPDIR environment variable: Semantics. 4826 * trademarks: Trademarks. 4827 * where to obtain standards.texi: Preface. 4828 3780 4829 3781 4830 3782 4831 Tag Table: 3783 Node: Top962 3784 Node: Preface1505 3785 Node: Intellectual Property2532 3786 Node: Reading Non-Free Code2907 3787 Node: Contributions4639 3788 Node: Design Advice6633 3789 Node: Compatibility7150 3790 Node: Using Extensions8661 3791 Node: ANSI C10163 3792 Node: Source Language11399 3793 Node: Program Behavior12892 3794 Node: Semantics13601 3795 Node: Libraries17355 3796 Node: Errors18590 3797 Node: User Interfaces19813 3798 Node: Option Table26559 3799 Node: Memory Usage40648 3800 Node: Writing C41642 3801 Node: Formatting42483 3802 Node: Comments45755 3803 Node: Syntactic Conventions49053 3804 Node: Names51991 3805 Node: System Portability53727 3806 Node: CPU Portability55503 3807 Node: System Functions57664 3808 Node: Internationalization62768 3809 Node: Mmap65916 3810 Node: Documentation66621 3811 Node: GNU Manuals67179 3812 Node: Manual Structure Details71066 3813 Node: NEWS File72396 3814 Node: Change Logs73077 3815 Node: Change Log Concepts73794 3816 Node: Style of Change Logs75562 3817 Node: Simple Changes77116 3818 Node: Conditional Changes78307 3819 Node: Man Pages79684 3820 Node: Reading other Manuals81303 3821 Node: Managing Releases82087 3822 Node: Configuration82823 3823 Node: Makefile Conventions89763 3824 Node: Makefile Basics90443 3825 Node: Utilities in Makefiles93612 3826 Node: Command Variables95748 3827 Node: Directory Variables99249 3828 Node: Standard Targets110126 3829 Ref: Standard Targets-Footnote-1120565 3830 Node: Install Command Categories120665 3831 Node: Releases125238 4832 Node: Top689 4833 Node: Preface1392 4834 Node: Legal Issues3611 4835 Node: Reading Non-Free Code4074 4836 Node: Contributions5797 4837 Node: Trademarks7946 4838 Node: Design Advice9004 4839 Node: Source Language9587 4840 Node: Compatibility11594 4841 Node: Using Extensions13217 4842 Node: Standard C14788 4843 Node: Conditional Compilation17186 4844 Node: Program Behavior18480 4845 Node: Semantics19398 4846 Node: Libraries24086 4847 Node: Errors25326 4848 Node: User Interfaces27102 4849 Node: Graphical Interfaces28702 4850 Node: Command-Line Interfaces29732 4851 Node: Option Table35798 4852 Node: Memory Usage50802 4853 Node: File Usage51822 4854 Node: Writing C52565 4855 Node: Formatting53414 4856 Node: Comments57472 4857 Node: Syntactic Conventions60770 4858 Node: Names64177 4859 Node: System Portability66381 4860 Node: CPU Portability68761 4861 Node: System Functions72012 4862 Node: Internationalization77214 4863 Node: Mmap80362 4864 Node: Documentation81067 4865 Node: GNU Manuals82171 4866 Node: Doc Strings and Manuals87223 4867 Node: Manual Structure Details88771 4868 Node: License for Manuals90184 4869 Node: Manual Credits91153 4870 Node: Printed Manuals91541 4871 Node: NEWS File92222 4872 Node: Change Logs92894 4873 Node: Change Log Concepts93643 4874 Node: Style of Change Logs95498 4875 Node: Simple Changes97544 4876 Node: Conditional Changes98779 4877 Node: Indicating the Part Changed100192 4878 Node: Man Pages100710 4879 Node: Reading other Manuals102329 4880 Node: Managing Releases103113 4881 Node: Configuration103875 4882 Node: Makefile Conventions110775 4883 Node: Makefile Basics111576 4884 Node: Utilities in Makefiles114741 4885 Node: Command Variables116877 4886 Node: Directory Variables120445 4887 Node: Standard Targets131330 4888 Ref: Standard Targets-Footnote-1142581 4889 Node: Install Command Categories142681 4890 Node: Releases147254 4891 Node: References151337 4892 Node: Copying This Manual153621 4893 Node: GNU Free Documentation License153835 4894 Node: Index173521 3832 4895 3833 4896 End Tag Table -
Property cvs2svn:cvs-rev
changed from
-
branches/GNU/src/binutils/etc/standards.texi
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 4 4 @settitle GNU Coding Standards 5 5 @c This date is automagically updated when you save this file: 6 @set lastupdate March 13, 19986 @set lastupdate February 14, 2002 7 7 @c %**end of header 8 8 … … 17 17 @c @setchapternewpage odd 18 18 @setchapternewpage off 19 20 @c Put everything in one index (arbitrarily chosen to be the concept index). 21 @syncodeindex fn cp 22 @syncodeindex ky cp 23 @syncodeindex pg cp 24 @syncodeindex vr cp 19 25 20 26 @c This is used by a cross ref in make-stds.texi … … 29 35 @ifinfo 30 36 GNU Coding Standards 31 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. 32 33 Permission is granted to make and distribute verbatim copies of 34 this manual provided the copyright notice and this permission notice 35 are preserved on all copies. 36 37 @ignore 38 Permission is granted to process this file through TeX and print the 39 results, provided the printed document carries copying permission 40 notice identical to this one except for the removal of this paragraph 41 (this paragraph not being relevant to the printed manual). 42 @end ignore 43 44 Permission is granted to copy and distribute modified versions of this 45 manual under the conditions for verbatim copying, provided that the entire 46 resulting derived work is distributed under the terms of a permission 47 notice identical to this one. 48 49 Permission is granted to copy and distribute translations of this manual 50 into another language, under the above conditions for modified versions, 51 except that this permission notice may be stated in a translation approved 52 by the Free Software Foundation. 37 Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. 38 39 Permission is granted to copy, distribute and/or modify this document 40 under the terms of the GNU Free Documentation License, Version 1.1 41 or any later version published by the Free Software Foundation; 42 with no Invariant Sections, with no 43 Front-Cover Texts, and with no Back-Cover Texts. 44 A copy of the license is included in the section entitled ``GNU 45 Free Documentation License''. 53 46 @end ifinfo 54 47 55 48 @titlepage 56 49 @title GNU Coding Standards 57 @author Richard Stallman 50 @author Richard Stallman, et al. 58 51 @author last updated @value{lastupdate} 59 52 @page 60 53 61 54 @vskip 0pt plus 1filll 62 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1997, 1998 Free Software Foundation, Inc. 63 64 Permission is granted to make and distribute verbatim copies of 65 this manual provided the copyright notice and this permission notice 66 are preserved on all copies. 67 68 Permission is granted to copy and distribute modified versions of this 69 manual under the conditions for verbatim copying, provided that the entire 70 resulting derived work is distributed under the terms of a permission 71 notice identical to this one. 72 73 Permission is granted to copy and distribute translations of this manual 74 into another language, under the above conditions for modified versions, 75 except that this permission notice may be stated in a translation approved 76 by the Free Software Foundation. 55 Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. 56 57 Permission is granted to copy, distribute and/or modify this document 58 under the terms of the GNU Free Documentation License, Version 1.1 59 or any later version published by the Free Software Foundation; 60 with no Invariant Sections, with no 61 Front-Cover Texts, and with no Back-Cover Texts. 62 A copy of the license is included in the section entitled ``GNU 63 Free Documentation License''. 77 64 @end titlepage 78 65 … … 86 73 @menu 87 74 * Preface:: About the GNU Coding Standards 88 * Intellectual Property::Keeping Free Software Free75 * Legal Issues:: Keeping Free Software Free 89 76 * Design Advice:: General Program Design 90 77 * Program Behavior:: Program Behavior for All Programs … … 92 79 * Documentation:: Documenting Programs 93 80 * Managing Releases:: The Release Process 81 * References:: References to Non-Free Software or Documentation 82 * Copying This Manual:: How to Make Copies of This Manual 83 * Index:: 84 94 85 @end menu 95 86 … … 105 96 state reasons for writing in a certain way. 106 97 98 This release of the GNU Coding Standards was last updated 99 @value{lastupdate}. 100 101 @cindex where to obtain @code{standards.texi} 102 @cindex downloading this manual 103 If you did not obtain this file directly from the GNU project and 104 recently, please check for a newer version. You can ftp the GNU 105 Coding Standards from any GNU FTP host in the directory 106 @file{/pub/gnu/standards/}. The GNU Coding Standards are available 107 there in several different formats: @file{standards.text}, 108 @file{standards.info}, and @file{standards.dvi}, as well as the 109 Texinfo ``source'' which is divided in two files: 110 @file{standards.texi} and @file{make-stds.texi}. The GNU Coding 111 Standards are also available on the GNU World Wide Web server: 112 @uref{http://www.gnu.org/prep/standards_toc.html}. 113 107 114 Corrections or suggestions for this document should be sent to 108 @email{ gnu@@gnu.org}. If you make a suggestion, please include a115 @email{bug-standards@@gnu.org}. If you make a suggestion, please include a 109 116 suggested new wording for it; our time is limited. We prefer a context 110 117 diff to the @file{standards.texi} or @file{make-stds.texi} files, but if 111 118 you don't have those files, please mail your suggestion anyway. 112 119 113 This release of the GNU Coding Standards was last updated 114 @value{lastupdate}. 115 116 @node Intellectual Property 120 These standards cover the minimum of what is important when writing a 121 GNU package. Likely, the needs for additional standards will come up. 122 Sometimes, you might suggest that such standards be added to this 123 document. If you think your standards would be generally useful, please 124 do suggest them. 125 126 You should also set standards for your package on many questions not 127 addressed or not firmly specified here. The most important point is to 128 be self-consistent---try to stick to the conventions you pick, and try 129 to document them as much as possible. That way, your program will be 130 more maintainable by others. 131 132 @node Legal Issues 117 133 @chapter Keeping Free Software Free 134 @cindex legal aspects 118 135 119 136 This @value{CHAPTER} discusses how you can make sure that GNU software 120 remains unencumbered.137 avoids legal difficulties, and other related issues. 121 138 122 139 @menu 123 140 * Reading Non-Free Code:: Referring to Proprietary Programs 124 141 * Contributions:: Accepting Contributions 142 * Trademarks:: How We Deal with Trademark Issues 125 143 @end menu 126 144 127 145 @node Reading Non-Free Code 128 146 @section Referring to Proprietary Programs 147 @cindex proprietary programs 148 @cindex avoiding proprietary code 129 149 130 150 Don't in any circumstances refer to Unix source code for or during … … 158 178 to free memory, or use a new GNU facility such as obstacks. 159 179 160 161 180 @node Contributions 162 181 @section Accepting Contributions 163 164 If someone else sends you a piece of code to add to the program you are 165 working on, we need legal papers to use it---the same sort of legal 166 papers we will need to get from you. @emph{Each} significant 167 contributor to a program must sign some sort of legal papers in order 168 for us to have clear title to the program. The main author alone is not 182 @cindex legal papers 183 @cindex accepting contributions 184 185 If the program you are working on is copyrighted by the Free Software 186 Foundation, then when someone else sends you a piece of code to add to 187 the program, we need legal papers to use it---just as we asked you to 188 sign papers initially. @emph{Each} person who makes a nontrivial 189 contribution to a program must sign some sort of legal papers in order 190 for us to have clear title to the program; the main author alone is not 169 191 enough. 170 192 … … 182 204 text, so we need legal papers for all kinds. 183 205 206 We know it is frustrating to ask for legal papers; it's frustrating for 207 us as well. But if you don't wait, you are going out on a limb---for 208 example, what if the contributor's employer won't sign a disclaimer? 209 You might have to take that code out again! 210 184 211 You don't need papers for changes of a few lines here or there, since 185 212 they are not significant for copyright purposes. Also, you don't need 186 213 papers if all you get from the suggestion is some ideas, not actual code 187 which you use. For example, if you write a different solution to the 188 problem, you don't need to get papers. 189 190 We know this is frustrating; it's frustrating for us as well. But if 191 you don't wait, you are going out on a limb---for example, what if the 192 contributor's employer won't sign a disclaimer? You might have to take 193 that code out again! 214 which you use. For example, if someone send you one implementation, but 215 you write a different implementation of the same idea, you don't need to 216 get papers. 194 217 195 218 The very worst thing is if you forget to tell us about the other … … 201 224 released or not), please ask us for a copy. 202 225 226 @node Trademarks 227 @section Trademarks 228 @cindex trademarks 229 230 Please do not include any trademark acknowledgements in GNU software 231 packages or documentation. 232 233 Trademark acknowledgements are the statements that such-and-such is a 234 trademark of so-and-so. The GNU Project has no objection to the basic 235 idea of trademarks, but these acknowledgements feel like kowtowing, so 236 we don't use them. There is no legal requirement for them. 237 238 What is legally required, as regards other people's trademarks, is to 239 avoid using them in ways which a reader might read as naming or labeling 240 our own programs or activities. For example, since ``Objective C'' is 241 (or at least was) a trademark, we made sure to say that we provide a 242 ``compiler for the Objective C language'' rather than an ``Objective C 243 compiler''. The latter is meant to be short for the former, but it does 244 not explicitly state the relationship, so it could be misinterpreted as 245 using ``Objective C'' as a label for the compiler rather than for the 246 language. 247 203 248 @node Design Advice 204 249 @chapter General Program Design 250 @cindex program design 205 251 206 252 This @value{CHAPTER} discusses some of the issues you should take into 207 253 account when designing your program. 208 254 255 @c Standard or ANSI C 256 @c 257 @c In 1989 the American National Standards Institute (ANSI) standardized 258 @c C as standard X3.159-1989. In December of that year the 259 @c International Standards Organization ISO adopted the ANSI C standard 260 @c making minor changes. In 1990 ANSI then re-adopted ISO standard 261 @c C. This version of C is known as either ANSI C or Standard C. 262 263 @c A major revision of the C Standard appeared in 1999. 264 209 265 @menu 266 * Source Language:: Which languges to use. 210 267 * Compatibility:: Compatibility with other implementations 211 268 * Using Extensions:: Using non-standard features 212 * ANSI C:: Using ANSIC features213 * Source Language:: Using languages other than C269 * Standard C:: Using Standard C features 270 * Conditional Compilation:: Compiling Code Only If A Conditional is True 214 271 @end menu 272 273 @node Source Language 274 @section Which Languages to Use 275 @cindex programming languges 276 277 When you want to use a language that gets compiled and runs at high 278 speed, the best language to use is C. Using another language is like 279 using a non-standard feature: it will cause trouble for users. Even if 280 GCC supports the other language, users may find it inconvenient to have 281 to install the compiler for that other language in order to build your 282 program. For example, if you write your program in C++, people will 283 have to install the GNU C++ compiler in order to compile your program. 284 285 C has one other advantage over C++ and other compiled languages: more 286 people know C, so more people will find it easy to read and modify the 287 program if it is written in C. 288 289 So in general it is much better to use C, rather than the 290 comparable alternatives. 291 292 But there are two exceptions to that conclusion: 293 294 @itemize @bullet 295 @item 296 It is no problem to use another language to write a tool specifically 297 intended for use with that language. That is because the only people 298 who want to build the tool will be those who have installed the other 299 language anyway. 300 301 @item 302 If an application is of interest only to a narrow part of the community, 303 then the question of which language it is written in has less effect on 304 other people, so you may as well please yourself. 305 @end itemize 306 307 Many programs are designed to be extensible: they include an interpreter 308 for a language that is higher level than C. Often much of the program 309 is written in that language, too. The Emacs editor pioneered this 310 technique. 311 312 @cindex GUILE 313 The standard extensibility interpreter for GNU software is GUILE, which 314 implements the language Scheme (an especially clean and simple dialect 315 of Lisp). @uref{http://www.gnu.org/software/guile/}. We don't reject 316 programs written in other ``scripting languages'' such as Perl and 317 Python, but using GUILE is very important for the overall consistency of 318 the GNU system. 215 319 216 320 @node Compatibility 217 321 @section Compatibility with Other Implementations 322 @cindex compatibility with C and @sc{posix} standards 323 @cindex @sc{posix} compatibility 218 324 219 325 With occasional exceptions, utility programs and libraries for GNU 220 326 should be upward compatible with those in Berkeley Unix, and upward 221 compatible with @sc{ansi} C if @sc{ansi} C specifies their behavior, and222 upward compatible with @sc{POSIX} if @sc{POSIX} specifies their 223 behavior.327 compatible with Standard C if Standard C specifies their 328 behavior, and upward compatible with @sc{posix} if @sc{posix} specifies 329 their behavior. 224 330 225 331 When these standards conflict, it is useful to offer compatibility 226 332 modes for each of them. 227 333 228 @sc{ansi} C and @sc{POSIX} prohibit many kinds of extensions. Feel free 229 to make the extensions anyway, and include a @samp{--ansi}, 334 @cindex options for compatibility 335 Standard C and @sc{posix} prohibit many kinds of extensions. Feel 336 free to make the extensions anyway, and include a @samp{--ansi}, 230 337 @samp{--posix}, or @samp{--compatible} option to turn them off. 231 338 However, if the extension has a significant chance of breaking any real 232 programs or scripts, then it is not really upward compatible. Try to 233 redesign its interface. 234 235 Many GNU programs suppress extensions that conflict with POSIX if the 339 programs or scripts, then it is not really upward compatible. So you 340 should try to redesign its interface to make it upward compatible. 341 342 @cindex @code{POSIXLY_CORRECT}, environment variable 343 Many GNU programs suppress extensions that conflict with @sc{posix} if the 236 344 environment variable @code{POSIXLY_CORRECT} is defined (even if it is 237 345 defined with a null value). Please make your program recognize this … … 244 352 feature as well. (There is a free @code{vi} clone, so we offer it.) 245 353 246 Additional useful features not in Berkeley Unix are welcome. 354 Additional useful features are welcome regardless of whether 355 there is any precedent for them. 247 356 248 357 @node Using Extensions 249 358 @section Using Non-standard Features 359 @cindex non-standard extensions 250 360 251 361 Many GNU facilities that already exist support a number of convenient … … 268 378 269 379 An exception to this rule are the large, established programs (such as 270 Emacs) which run on a great variety of systems. Such programs would 271 be broken by use of GNU extensions. 272 273 Another exception is for programs that are used as part of 274 compilation: anything that must be compiled with other compilers in 275 order to bootstrap the GNU compilation facilities. If these require 276 the GNU compiler, then no one can compile them without having them 277 installed already. That would be no good. 278 279 @node ANSI C 280 @section @sc{ansi} C and pre-@sc{ansi} C 281 282 Do not ever use the ``trigraph'' feature of @sc{ansi} C. 283 284 @sc{ansi} C is widespread enough now that it is ok to write new programs 285 that use @sc{ansi} C features (and therefore will not work in 286 non-@sc{ansi} compilers). And if a program is already written in 287 @sc{ansi} C, there's no need to convert it to support non-@sc{ansi} 288 compilers. 289 290 However, it is easy to support non-@sc{ansi} compilers in most programs, 291 so you might still consider doing so when you write a program. Instead 292 of writing function definitions in @sc{ansi} prototype form, 380 Emacs) which run on a great variety of systems. Using GNU extensions in 381 such programs would make many users unhappy, so we don't do that. 382 383 Another exception is for programs that are used as part of compilation: 384 anything that must be compiled with other compilers in order to 385 bootstrap the GNU compilation facilities. If these require the GNU 386 compiler, then no one can compile them without having them installed 387 already. That would be extremely troublesome in certain cases. 388 389 @node Standard C 390 @section Standard C and Pre-Standard C 391 @cindex @sc{ansi} C standard 392 393 1989 Standard C is widespread enough now that it is ok to use its 394 features in new programs. There is one exception: do not ever use the 395 ``trigraph'' feature of Standard C. 396 397 1999 Standard C is not widespread yet, so please do not require its 398 features in programs. It is ok to use its features if they are present. 399 400 However, it is easy to support pre-standard compilers in most programs, 401 so if you know how to do that, feel free. If a program you are 402 maintaining has such support, you should try to keep it working. 403 404 @cindex function prototypes 405 To support pre-standard C, instead of writing function definitions in 406 standard prototype form, 293 407 294 408 @example … … 299 413 300 414 @noindent 301 write the definition in pre- @sc{ansi}style like this,415 write the definition in pre-standard style like this, 302 416 303 417 @example … … 316 430 317 431 You need such a declaration anyway, in a header file, to get the benefit 318 of @sc{ansi} C prototypes in all the files where the function is called. 319 And once you have it, you lose nothing by writing the function 320 definition in the pre-@sc{ansi} style. 321 322 If you don't know non-@sc{ansi} C, there's no need to learn it; just 323 write in @sc{ansi} C. 324 325 @node Source Language 326 @section Using Languages Other Than C 327 328 Using a language other than C is like using a non-standard feature: it 329 will cause trouble for users. Even if GCC supports the other language, 330 users may find it inconvenient to have to install the compiler for that 331 other language in order to build your program. For example, if you 332 write your program in C++, people will have to install the C++ compiler 333 in order to compile your program. Thus, it is better if you write in C. 334 335 But there are three situations when there is no disadvantage in using 336 some other language: 337 338 @itemize @bullet 339 @item 340 It is okay to use another language if your program contains an 341 interpreter for that language. 342 343 For example, if your program links with GUILE, it is ok to write part of 344 the program in Scheme or another language supported by GUILE. 345 346 @item 347 It is okay to use another language in a tool specifically intended for 348 use with that language. 349 350 This is okay because the only people who want to build the tool will be 351 those who have installed the other language anyway. 352 353 @item 354 If an application is of interest to a narrow community, then perhaps 355 it's not important if the application is inconvenient to install. 356 @end itemize 357 358 C has one other advantage over C++ and other compiled languages: more 359 people know C, so more people will find it easy to read and modify the 360 program if it is written in C. 432 of prototypes in all the files where the function is called. And once 433 you have the declaration, you normally lose nothing by writing the 434 function definition in the pre-standard style. 435 436 This technique does not work for integer types narrower than @code{int}. 437 If you think of an argument as being of a type narrower than @code{int}, 438 declare it as @code{int} instead. 439 440 There are a few special cases where this technique is hard to use. For 441 example, if a function argument needs to hold the system type 442 @code{dev_t}, you run into trouble, because @code{dev_t} is shorter than 443 @code{int} on some machines; but you cannot use @code{int} instead, 444 because @code{dev_t} is wider than @code{int} on some machines. There 445 is no type you can safely use on all machines in a non-standard 446 definition. The only way to support non-standard C and pass such an 447 argument is to check the width of @code{dev_t} using Autoconf and choose 448 the argument type accordingly. This may not be worth the trouble. 449 450 In order to support pre-standard compilers that do not recognize 451 prototypes, you may want to use a preprocessor macro like this: 452 453 @example 454 /* Declare the prototype for a general external function. */ 455 #if defined (__STDC__) || defined (WINDOWSNT) 456 #define P_(proto) proto 457 #else 458 #define P_(proto) () 459 #endif 460 @end example 461 462 @node Conditional Compilation 463 @section Conditional Compilation 464 465 When supporting configuration options already known when building your 466 program we prefer using @code{if (... )} over conditional compilation, 467 as in the former case the compiler is able to perform more extensive 468 checking of all possible code paths. 469 470 For example, please write 471 472 @smallexample 473 if (HAS_FOO) 474 ... 475 else 476 ... 477 @end smallexample 478 479 instead of: 480 481 @smallexample 482 #ifdef HAS_FOO 483 ... 484 #else 485 ... 486 #endif 487 @end smallexample 488 489 A modern compiler such as GCC will generate exactly the same code in 490 both cases, and we have been using similar techniques with good success 491 in several projects. 492 493 While this is not a silver bullet solving all portability problems, 494 following this policy would have saved the GCC project alone many person 495 hours if not days per year. 496 497 In the case of function-like macros like @code{REVERSIBLE_CC_MODE} in 498 GCC which cannot be simply used in @code{if( ...)} statements, there is 499 an easy workaround. Simply introduce another macro 500 @code{HAS_REVERSIBLE_CC_MODE} as in the following example: 501 502 @smallexample 503 #ifdef REVERSIBLE_CC_MODE 504 #define HAS_REVERSIBLE_CC_MODE 1 505 #else 506 #define HAS_REVERSIBLE_CC_MODE 0 507 #endif 508 @end smallexample 361 509 362 510 @node Program Behavior 363 511 @chapter Program Behavior for All Programs 364 512 365 This @value{CHAPTER} describes how to write robust software. It also366 describes general standards for error messages, the command line interface, 367 and how libraries should behave.513 This @value{CHAPTER} describes conventions for writing robust 514 software. It also describes general standards for error messages, the 515 command line interface, and how libraries should behave. 368 516 369 517 @menu … … 371 519 * Libraries:: Library behavior 372 520 * Errors:: Formatting error messages 373 * User Interfaces:: Standards for command line interfaces 374 * Option Table:: Table of long options. 521 * User Interfaces:: Standards about interfaces generally 522 * Graphical Interfaces:: Standards for graphical interfaces 523 * Command-Line Interfaces:: Standards for command line interfaces 524 * Option Table:: Table of long options 375 525 * Memory Usage:: When and how to care about memory needs 526 * File Usage:: Which files to use, and where 376 527 @end menu 377 528 … … 379 530 @section Writing Robust Programs 380 531 532 @cindex arbitrary limits on data 381 533 Avoid arbitrary limits on the length or number of @emph{any} data 382 534 structure, including file names, lines, files, and symbols, by allocating … … 384 536 are silently truncated''. This is not acceptable in a GNU utility. 385 537 538 @cindex @code{NUL} characters 386 539 Utilities reading files should not drop NUL characters, or any other 387 nonprinting characters @emph{including those with codes above 0177}. The 388 only sensible exceptions would be utilities specifically intended for 389 interface to certain types of printers that can't handle those characters. 390 540 nonprinting characters @emph{including those with codes above 0177}. 541 The only sensible exceptions would be utilities specifically intended 542 for interface to certain types of terminals or printers 543 that can't handle those characters. 544 Whenever possible, try to make programs work properly with 545 sequences of bytes that represent multibyte characters, using encodings 546 such as UTF-8 and others. 547 548 @cindex error messages 391 549 Check every system call for an error return, unless you know you wish to 392 550 ignore errors. Include the system error text (from @code{perror} or … … 396 554 sufficient. 397 555 556 @cindex @code{malloc} return value 557 @cindex memory allocation failure 398 558 Check every call to @code{malloc} or @code{realloc} to see if it 399 559 returned zero. Check @code{realloc} even if you are making the block … … 417 577 virtual memory, and then try the command again. 418 578 579 @cindex command-line arguments, decoding 419 580 Use @code{getopt_long} to decode arguments, unless the argument syntax 420 581 makes this unreasonable. … … 429 590 are less likely to work compatibly. If you need to find all the files 430 591 in a directory, use @code{readdir} or some other high-level interface. 431 These will be supported compatibly by GNU. 432 433 By default, the GNU system will provide the signal handling functions of 434 @sc{BSD} and of @sc{POSIX}. So GNU software should be written to use 435 these. 436 592 These are supported compatibly by GNU. 593 594 @cindex signal handling 595 The preferred signal handling facilities are the BSD variant of 596 @code{signal}, and the @sc{posix} @code{sigaction} function; the 597 alternative USG @code{signal} interface is an inferior design. 598 599 Nowadays, using the @sc{posix} signal functions may be the easiest way 600 to make a program portable. If you use @code{signal}, then on GNU/Linux 601 systems running GNU libc version 1, you should include 602 @file{bsd/signal.h} instead of @file{signal.h}, so as to get BSD 603 behavior. It is up to you whether to support systems where 604 @code{signal} has only the USG behavior, or give up on them. 605 606 @cindex impossible conditions 437 607 In error checks that detect ``impossible'' conditions, just abort. 438 608 There is usually no point in printing any message. These checks … … 449 619 will see 0 as the status, and it will appear that the program succeeded. 450 620 621 @cindex temporary files 622 @cindex @code{TMPDIR} environment variable 451 623 If you make temporary files, check the @code{TMPDIR} environment 452 624 variable; if that variable is defined, use the specified directory 453 625 instead of @file{/tmp}. 454 626 627 In addition, be aware that there is a possible security problem when 628 creating temporary files in world-writable directories. In C, you can 629 avoid this problem by creating temporary files in this manner: 630 631 @example 632 fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, 0600); 633 @end example 634 635 @noindent 636 or by using the @code{mkstemps} function from libiberty. 637 638 In bash, use @code{set -C} to avoid this problem. 639 455 640 @node Libraries 456 641 @section Library Behavior 642 @cindex libraries 457 643 458 644 Try to make library functions reentrant. If they need to do dynamic … … 474 660 475 661 External symbols that are not documented entry points for the user 476 should have names beginning with @samp{_}. The y should also contain477 the chosen name prefix for the library, to prevent collisions with 478 other libraries. These can go in the same files with user entry 479 points if you like.662 should have names beginning with @samp{_}. The @samp{_} should be 663 followed by the chosen name prefix for the library, to prevent 664 collisions with other libraries. These can go in the same files with 665 user entry points if you like. 480 666 481 667 Static functions and variables can be used as you like and need not … … 484 670 @node Errors 485 671 @section Formatting Error Messages 672 @cindex formatting error messages 673 @cindex error messages, formatting 486 674 487 675 Error messages from compilers should look like this: … … 490 678 @var{source-file-name}:@var{lineno}: @var{message} 491 679 @end example 680 681 @noindent 682 If you want to mention the column number, use this format: 683 684 @example 685 @var{source-file-name}:@var{lineno}:@var{column}: @var{message} 686 @end example 687 688 @noindent 689 Line numbers should start from 1 at the beginning of the file, and 690 column numbers should start from 1 at the beginning of the line. (Both 691 of these conventions are chosen for compatibility.) Calculate column 692 numbers assuming that space and all ASCII printing characters have 693 equal width, and assuming tab stops every 8 columns. 492 694 493 695 Error messages from other noninteractive programs should look like this: … … 506 708 @noindent 507 709 when there is no relevant source file. 710 711 If you want to mention the column number, use this format: 712 713 @example 714 @var{program}:@var{source-file-name}:@var{lineno}:@var{column}: @var{message} 715 @end example 508 716 509 717 In an interactive program (one that is reading commands from a … … 523 731 524 732 @node User Interfaces 525 @section Standards for Command Line Interfaces 526 733 @section Standards for Interfaces Generally 734 735 @cindex program name and its behavior 736 @cindex behavior, dependent on program's name 527 737 Please don't make the behavior of a utility depend on the name used 528 738 to invoke it. It is useful sometimes to make a link to a utility … … 532 742 to select among the alternate behaviors. 533 743 744 @cindex output device and program's behavior 534 745 Likewise, please don't make the behavior of the program depend on the 535 746 type of output device it is used with. Device independence is an 536 important principle of the system's design; do not compromise it 537 merely to save someone from typing an option now and then. 747 important principle of the system's design; do not compromise it merely 748 to save someone from typing an option now and then. (Variation in error 749 message syntax when using a terminal is ok, because that is a side issue 750 that people do not depend on.) 538 751 539 752 If you think one behavior is most useful when the output is to a … … 551 764 multi-column format. 552 765 553 It is a good idea to follow the @sc{POSIX} guidelines for the 766 @node Graphical Interfaces 767 @section Standards for Graphical Interfaces 768 @cindex graphical user interface 769 770 @cindex gtk 771 When you write a program that provides a graphical user interface, 772 please make it work with X Windows and the GTK toolkit unless the 773 functionality specifically requires some alternative (for example, 774 ``displaying jpeg images while in console mode''). 775 776 In addition, please provide a command-line interface to control the 777 functionality. (In many cases, the graphical user interface can be a 778 separate program which invokes the command-line program.) This is 779 so that the same jobs can be done from scripts. 780 781 @cindex corba 782 @cindex gnome 783 Please also consider providing a CORBA interface (for use from GNOME), a 784 library interface (for use from C), and perhaps a keyboard-driven 785 console interface (for use by users from console mode). Once you are 786 doing the work to provide the functionality and the graphical interface, 787 these won't be much extra work. 788 789 @node Command-Line Interfaces 790 @section Standards for Command Line Interfaces 791 @cindex command-line interface 792 793 @findex getopt 794 It is a good idea to follow the @sc{posix} guidelines for the 554 795 command-line options of a program. The easiest way to do this is to use 555 796 @code{getopt} to parse them. Note that the GNU version of @code{getopt} 556 797 will normally permit options anywhere among the arguments unless the 557 special argument @samp{--} is used. This is not what @sc{ POSIX}798 special argument @samp{--} is used. This is not what @sc{posix} 558 799 specifies; it is a GNU extension. 559 800 801 @cindex long-named options 560 802 Please define long-named options that are equivalent to the 561 803 single-letter Unix-style options. We hope to make GNU more user … … 577 819 among GNU utilities, and fewer idiosyncracies for users to remember. 578 820 821 @cindex standard command-line options 579 822 All programs should support two standard options: @samp{--version} 580 823 and @samp{--help}. 581 824 582 825 @table @code 826 @cindex @samp{--version} option 583 827 @item --version 584 This option should direct the program to information about its name,828 This option should direct the program to print information about its name, 585 829 version, origin and legal status, all on standard output, and then exit 586 830 successfully. Other options and arguments should be ignored once this 587 831 is seen, and the program should not perform its normal function. 588 832 833 @cindex canonical name of a program 834 @cindex program's canonical name 589 835 The first line is meant to be easy for a program to parse; the version 590 836 number proper starts after the last space. In addition, it contains … … 659 905 line. 660 906 907 Translations of the above lines must preserve the validity of the 908 copyright notices (@pxref{Internationalization}). If the translation's 909 character set supports it, the @samp{(C)} should be replaced with the 910 copyright symbol, as follows: 911 912 @ifinfo 913 (the official copyright symbol, which is the letter C in a circle); 914 @end ifinfo 915 @ifnotinfo 916 @copyright{} 917 @end ifnotinfo 918 919 Write the word ``Copyright'' exactly like that, in English. Do not 920 translate it into another language. International treaties recognize 921 the English word ``Copyright''; translations into other languages do not 922 have legal significance. 923 924 925 @cindex @samp{--help} option 661 926 @item --help 662 927 This option should output brief documentation for how to invoke the … … 665 930 not perform its normal function. 666 931 932 @cindex address for bug reports 933 @cindex bug reports 667 934 Near the end of the @samp{--help} option's output there should be a line 668 935 that says where to mail bug reports. It should have this format: … … 675 942 @node Option Table 676 943 @section Table of Long Options 944 @cindex long option names 945 @cindex table of long options 677 946 678 947 Here is a table of long options used by GNU programs. It is surely 679 948 incomplete, but we aim to list all the options that a new program might 680 949 want to be compatible with. If you use names not already in the table, 681 please send @email{ gnu@@gnu.org} a list of them, with their950 please send @email{bug-standards@@gnu.org} a list of them, with their 682 951 meanings, so we can update the table. 683 952 … … 739 1008 @samp{-n} in @code{wdiff}. 740 1009 1010 @item background 1011 For server programs, run in the background. 1012 741 1013 @item backward-search 742 1014 @samp{-B} in @code{ctags}. … … 862 1134 @item dereference-args 863 1135 @samp{-D} in @code{du}. 1136 1137 @item device 1138 Specify an I/O device (special file name). 864 1139 865 1140 @item diacritics … … 995 1270 @samp{-F} in @code{shar}. 996 1271 1272 @item foreground 1273 For server programs, run in the foreground; 1274 in other words, don't do anything special to run the server 1275 in the background. 1276 997 1277 @item format 998 1278 Used in @code{ls}, @code{time}, and @code{ptx}. … … 1039 1319 @item hide-control-chars 1040 1320 @samp{-q} in @code{ls}. 1321 1322 @item html 1323 In @code{makeinfo}, output HTML. 1041 1324 1042 1325 @item idle … … 1099 1382 @item info 1100 1383 @samp{-i}, @samp{-l}, and @samp{-m} in Finger. 1384 1385 @item init-file 1386 In some programs, specify the name of the file to read as the user's 1387 init file. 1101 1388 1102 1389 @item initial … … 1118 1405 @samp{-p} in @code{shar}. 1119 1406 1407 @item iso-8601 1408 Used in @code{date} 1409 1120 1410 @item jobs 1121 1411 @samp{-j} in Make. … … 1353 1643 @samp{-F} in @code{gprof}. 1354 1644 1645 @item options 1646 @samp{-o} in @code{getopt}, @code{fdlist}, @code{fdmount}, 1647 @code{fdmountd}, and @code{fdumount}. 1648 1355 1649 @item output 1356 1650 In various programs, specify the output file name. … … 1436 1730 @item prompt 1437 1731 @samp{-p} in @code{ed}. 1732 1733 @item proxy 1734 Specify an HTTP proxy. 1438 1735 1439 1736 @item query-user … … 1565 1862 @samp{-s} in @code{ls}. 1566 1863 1864 @item socket 1865 Specify a file descriptor for a network server to use for its socket, 1866 instead of opening and binding a new socket. This provides a way to 1867 run, in a nonpriveledged process, a server that normally needs a 1868 reserved port number. 1869 1567 1870 @item sort 1568 1871 Used in @code{ls}. … … 1662 1965 @item time 1663 1966 Used in @code{ls} and @code{touch}. 1967 1968 @item timeout 1969 Specify how long to wait before giving up on some operation. 1664 1970 1665 1971 @item to-stdout … … 1755 2061 @node Memory Usage 1756 2062 @section Memory Usage 1757 1758 If it typically uses just a few meg of memory, don't bother making any 2063 @cindex memory usage 2064 2065 If a program typically uses just a few meg of memory, don't bother making any 1759 2066 effort to reduce memory usage. For example, if it is impractical for 1760 2067 other reasons to operate on files more than a few meg long, it is … … 1772 2079 core and give a fatal error if @code{malloc} returns zero. 1773 2080 2081 @node File Usage 2082 @section File Usage 2083 @cindex file usage 2084 2085 Programs should be prepared to operate when @file{/usr} and @file{/etc} 2086 are read-only file systems. Thus, if the program manages log files, 2087 lock files, backup files, score files, or any other files which are 2088 modified for internal purposes, these files should not be stored in 2089 @file{/usr} or @file{/etc}. 2090 2091 There are two exceptions. @file{/etc} is used to store system 2092 configuration information; it is reasonable for a program to modify 2093 files in @file{/etc} when its job is to update the system configuration. 2094 Also, if the user explicitly asks to modify one file in a directory, it 2095 is reasonable for the program to store other files in the same 2096 directory. 2097 1774 2098 @node Writing C 1775 2099 @chapter Making The Best Use of C … … 1782 2106 * Comments:: Commenting Your Work 1783 2107 * Syntactic Conventions:: Clean Use of C Constructs 1784 * Names:: Naming Variables and Functions2108 * Names:: Naming Variables, Functions, and Files 1785 2109 * System Portability:: Portability between different operating systems 1786 2110 * CPU Portability:: Supporting the range of CPU types … … 1792 2116 @node Formatting 1793 2117 @section Formatting Your Source Code 1794 2118 @cindex formatting source code 2119 2120 @cindex open brace 2121 @cindex braces, in C source 1795 2122 It is important to put the open-brace that starts the body of a C 1796 2123 function in column zero, and avoid putting any other open-brace or … … 1814 2141 1815 2142 @noindent 1816 or, if you want to use @sc{ansi} C, format the definition like this: 2143 or, if you want to use Standard C syntax, format the definition like 2144 this: 1817 2145 1818 2146 @example … … 1824 2152 @end example 1825 2153 1826 In @sc{ansi}C, if the arguments don't fit nicely on one line,2154 In Standard C, if the arguments don't fit nicely on one line, 1827 2155 split it like this: 1828 2156 … … 1834 2162 @end example 1835 2163 1836 For the body of the function, we prefer code formatted like this: 2164 The rest of this section gives our recommendations for other aspects of 2165 C formatting style, which is also the default style of the @code{indent} 2166 program in version 1.2 and newer. It corresponds to the options 2167 2168 @smallexample 2169 -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2 2170 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob 2171 @end smallexample 2172 2173 We don't think of these recommendations as requirements, because it 2174 causes no problems for users if two different programs have different 2175 formatting styles. 2176 2177 But whatever style you use, please use it consistently, since a mixture 2178 of styles within one program tends to look ugly. If you are 2179 contributing changes to an existing program, please follow the style of 2180 that program. 2181 2182 For the body of the function, our recommended style looks like this: 1837 2183 1838 2184 @example … … 1850 2196 @end example 1851 2197 2198 @cindex spaces before open-paren 1852 2199 We find it easier to read a program when it has spaces before the 1853 2200 open-parentheses and after the commas. Especially after the commas. … … 1856 2203 before an operator, not after one. Here is the right way: 1857 2204 2205 @cindex expressions, splitting 1858 2206 @example 1859 2207 if (foo_this_is_long && bar > win (x, y, z) … … 1880 2228 Insert extra parentheses so that Emacs will indent the code properly. 1881 2229 For example, the following indentation looks nice if you do it by hand, 1882 but Emacs would mess it up:1883 2230 1884 2231 @example … … 1887 2234 @end example 1888 2235 1889 But adding a set of parentheses solves the problem: 2236 @noindent 2237 but Emacs would alter it. Adding a set of parentheses produces 2238 something that looks equally nice, and which Emacs will preserve: 1890 2239 1891 2240 @example … … 1904 2253 @end example 1905 2254 2255 @cindex formfeed 2256 @cindex control-L 1906 2257 Please use formfeed characters (control-L) to divide the program into 1907 2258 pages at logical places (but not within a function). It does not matter … … 1909 2260 page. The formfeeds should appear alone on lines by themselves. 1910 2261 1911 1912 2262 @node Comments 1913 2263 @section Commenting Your Work 2264 @cindex commenting 1914 2265 1915 2266 Every program should start with a comment saying briefly what it is for. … … 1963 2314 @end example 1964 2315 2316 @cindex conditionals, comments for 2317 @cindex @code{#endif}, commenting 1965 2318 Every @samp{#endif} should have a comment, except in the case of short 1966 2319 conditionals (just a few lines) that are not nested. The comment should … … 2004 2357 @node Syntactic Conventions 2005 2358 @section Clean Use of C Constructs 2006 2007 Please explicitly declare all arguments to functions. 2008 Don't omit them just because they are @code{int}s. 2359 @cindex syntactic conventions 2360 2361 @cindex implicit @code{int} 2362 @cindex function argument, declaring 2363 Please explicitly declare the types of all objects. For example, you 2364 should explicitly declare all arguments to functions, and you should 2365 declare functions to return @code{int} rather than omitting the 2366 @code{int}. 2367 2368 @cindex compiler warnings 2369 @cindex @samp{-Wall} compiler option 2370 Some programmers like to use the GCC @samp{-Wall} option, and change the 2371 code whenever it issues a warning. If you want to do this, then do. 2372 Other programmers prefer not to use @samp{-Wall}, because it gives 2373 warnings for valid and legitimate code which they do not want to change. 2374 If you want to do this, then do. The compiler should be your servant, 2375 not your master. 2009 2376 2010 2377 Declarations of external functions and functions to appear later in the … … 2014 2381 functions. 2015 2382 2383 @cindex temporary variables 2016 2384 It used to be common practice to use the same local variables (with 2017 2385 names like @code{tem}) over and over for different values within one … … 2025 2393 Don't use local variables or parameters that shadow global identifiers. 2026 2394 2395 @cindex multiple variables in a line 2027 2396 Don't declare multiple variables in one declaration that spans lines. 2028 2397 Start a new declaration on each line, instead. For example, instead … … 2125 2494 @end example 2126 2495 2496 @pindex lint 2127 2497 Don't make the program ugly to placate @code{lint}. Please don't insert any 2128 2498 casts to @code{void}. Zero without a cast is perfectly fine as a null 2129 2499 pointer constant, except when calling a varargs function. 2130 2500 2131 @node Names 2132 @section Naming Variables and Functions 2133 2501 @node Names 2502 @section Naming Variables, Functions, and Files 2503 2504 @cindex names of variables, functions, and files 2134 2505 The names of global variables and functions in a program serve as 2135 2506 comments of a sort. So don't choose terse names---instead, look for … … 2141 2512 one context, where (presumably) comments explain their purpose. 2142 2513 2514 Try to limit your use of abbreviations in symbol names. It is ok to 2515 make a few abbreviations, explain what they mean, and then use them 2516 frequently, but don't use lots of obscure abbreviations. 2517 2143 2518 Please use underscores to separate words in a name, so that the Emacs 2144 2519 word commands can be useful within them. Stick to lower case; reserve … … 2165 2540 constants. 2166 2541 2167 Use file names of 14 characters or less, to avoid creating gratuitous 2168 problems on older System V systems. You can use the program 2169 @code{doschk} to test for this. @code{doschk} also tests for potential 2170 name conflicts if the files were loaded onto an MS-DOS file 2171 system---something you may or may not care about. 2542 @cindex file-name limitations 2543 @pindex doschk 2544 You might want to make sure that none of the file names would conflict 2545 the files were loaded onto an MS-DOS file system which shortens the 2546 names. You can use the program @code{doschk} to test for this. 2547 2548 Some GNU programs were designed to limit themselves to file names of 14 2549 characters or less, to avoid file name conflicts if they are read into 2550 older System V systems. Please preserve this feature in the existing 2551 GNU programs that have it, but there is no need to do this in new GNU 2552 programs. @code{doschk} also reports file names longer than 14 2553 characters. 2172 2554 2173 2555 @node System Portability 2174 2556 @section Portability between System Types 2557 @cindex portability, between system types 2175 2558 2176 2559 In the Unix world, ``portability'' refers to porting to different Unix … … 2179 2562 2180 2563 The primary purpose of GNU software is to run on top of the GNU kernel, 2181 compiled with the GNU C compiler, on various types of @sc{cpu}. The 2182 amount and kinds of variation among GNU systems on different @sc{cpu}s 2183 will be comparable to the variation among Linux-based GNU systems or 2184 among BSD systems today. So the kinds of portability that are absolutely 2185 necessary are quite limited. 2186 2187 But many users do run GNU software on non-GNU Unix or Unix-like systems. 2188 So supporting a variety of Unix-like systems is desirable, although not 2189 paramount. 2190 2564 compiled with the GNU C compiler, on various types of @sc{cpu}. So the 2565 kinds of portability that are absolutely necessary are quite limited. 2566 But it is important to support Linux-based GNU systems, since they 2567 are the form of GNU that is popular. 2568 2569 Beyond that, it is good to support the other free operating systems 2570 (*BSD), and it is nice to support other Unix-like systems if you want 2571 to. Supporting a variety of Unix-like systems is desirable, although 2572 not paramount. It is usually not too hard, so you may as well do it. 2573 But you don't have to consider it an obligation, if it does turn out to 2574 be hard. 2575 2576 @pindex autoconf 2191 2577 The easiest way to achieve portability to most Unix-like systems is to 2192 2578 use Autoconf. It's unlikely that your program needs to know more … … 2198 2584 when there is a higher-level alternative (@code{readdir}). 2199 2585 2586 @cindex non-@sc{posix} systems, and portability 2200 2587 As for systems that are not like Unix, such as MSDOS, Windows, the 2201 Macintosh, VMS, and MVS, supporting them is usually so much work that it 2202 is better if you don't. 2203 2204 The planned GNU kernel is not finished yet, but you can tell which 2205 facilities it will provide by looking at the GNU C Library Manual. The 2206 GNU kernel is based on Mach, so the features of Mach will also be 2207 available. However, if you use Mach features, you'll probably have 2208 trouble debugging your program today. 2588 Macintosh, VMS, and MVS, supporting them is often a lot of work. When 2589 that is the case, it is better to spend your time adding features that 2590 will be useful on GNU and GNU/Linux, rather than on supporting other 2591 incompatible systems. 2592 2593 It is a good idea to define the ``feature test macro'' 2594 @code{_GNU_SOURCE} when compiling your C files. When you compile on GNU 2595 or GNU/Linux, this will enable the declarations of GNU library extension 2596 functions, and that will usually give you a compiler error message if 2597 you define the same function names in some other way in your program. 2598 (You don't have to actually @emph{use} these functions, if you prefer 2599 to make the program more portable to other systems.) 2600 2601 But whether or not you use these GNU extensions, you should avoid 2602 using their names for any other meanings. Doing so would make it hard 2603 to move your code into other GNU programs. 2209 2604 2210 2605 @node CPU Portability 2211 2606 @section Portability between @sc{cpu}s 2212 2607 2608 @cindex data types, and portability 2609 @cindex portability, and data types 2213 2610 Even GNU systems will differ because of differences among @sc{cpu} 2214 2611 types---for example, difference in byte ordering and alignment … … 2218 2615 in GNU. 2219 2616 2617 Similarly, don't make any effort to cater to the possibility that 2618 @code{long} will be smaller than predefined types like @code{size_t}. 2619 For example, the following code is ok: 2620 2621 @example 2622 printf ("size = %lu\n", (unsigned long) sizeof array); 2623 printf ("diff = %ld\n", (long) (pointer2 - pointer1)); 2624 @end example 2625 2626 1989 Standard C requires this to work, and we know of only one 2627 counterexample: 64-bit programs on Microsoft Windows IA-64. We will 2628 leave it to those who want to port GNU programs to that environment 2629 to figure out how to do it. 2630 2631 Predefined file-size types like @code{off_t} are an exception: they are 2632 longer than @code{long} on many platforms, so code like the above won't 2633 work with them. One way to print an @code{off_t} value portably is to 2634 print its digits yourself, one by one. 2635 2220 2636 Don't assume that the address of an @code{int} object is also the 2221 2637 address of its least-significant byte. This is false on big-endian … … 2232 2648 pointers of various types, or between pointers and integers. On most 2233 2649 machines, there's no difference anyway. As for the few machines where 2234 there is a difference, all of them support @sc{ansi} C, so you can use2235 prototypes (conditionalized to be active only in @sc{ansi} C) to make 2236 t he code work on those systems.2650 there is a difference, all of them support Standard C prototypes, so you can 2651 use prototypes (perhaps conditionalized to be active only in Standard C) 2652 to make the code work on those systems. 2237 2653 2238 2654 In certain cases, it is ok to pass integer and pointer arguments … … 2244 2660 error (s, a1, a2, a3) 2245 2661 char *s; 2246 int a1, a2,a3;2662 char *a1, *a2, *a3; 2247 2663 @{ 2248 2664 fprintf (stderr, "error: "); … … 2252 2668 2253 2669 @noindent 2254 In practice, this works on all machines, and it is much simpler than any 2255 ``correct'' alternative. Be sure @emph{not} to use a prototype 2256 for such functions. 2257 2258 However, avoid casting pointers to integers unless you really need to. 2259 These assumptions really reduce portability, and in most programs they 2260 are easy to avoid. In the cases where casting pointers to integers is 2261 essential---such as, a Lisp interpreter which stores type information as 2262 well as an address in one word---it is ok to do so, but you'll have to 2263 make explicit provisions to handle different word sizes. 2670 In practice, this works on all machines, since a pointer is generally 2671 the widest possible kind of argument; it is much simpler than any 2672 ``correct'' alternative. Be sure @emph{not} to use a prototype for such 2673 functions. 2674 2675 If you have decided to use Standard C, then you can instead define 2676 @code{error} using @file{stdarg.h}, and pass the arguments along to 2677 @code{vfprintf}. 2678 2679 @cindex casting pointers to integers 2680 Avoid casting pointers to integers if you can. Such casts greatly 2681 reduce portability, and in most programs they are easy to avoid. In the 2682 cases where casting pointers to integers is essential---such as, a Lisp 2683 interpreter which stores type information as well as an address in one 2684 word---you'll have to make explicit provisions to handle different word 2685 sizes. You will also need to make provision for systems in which the 2686 normal range of addresses you can get from @code{malloc} starts far away 2687 from zero. 2264 2688 2265 2689 @node System Functions 2266 2690 @section Calling System Functions 2267 2268 C implementations differ substantially. @sc{ansi} C reduces but does not 2269 eliminate the incompatibilities; meanwhile, many users wish to compile 2270 GNU software with pre-@sc{ansi} compilers. This chapter gives 2271 recommendations for how to use the more or less standard C library 2272 functions to avoid unnecessary loss of portability. 2691 @cindex library functions, and portability 2692 @cindex portability, and library functions 2693 2694 C implementations differ substantially. Standard C reduces but does 2695 not eliminate the incompatibilities; meanwhile, many GNU packages still 2696 support pre-standard compilers because this is not hard to do. This 2697 chapter gives recommendations for how to use the more-or-less standard C 2698 library functions to avoid unnecessary loss of portability. 2273 2699 2274 2700 @itemize @bullet 2275 2701 @item 2276 Don't use the value of @code{sprintf}. It returns the number of2702 Don't use the return value of @code{sprintf}. It returns the number of 2277 2703 characters written on some systems, but not on all systems. 2704 2705 @item 2706 Be aware that @code{vfprintf} is not always available. 2278 2707 2279 2708 @item … … 2282 2711 status code; make sure it cannot ever return an undefined value. 2283 2712 2713 @cindex declaration for system functions 2284 2714 @item 2285 2715 Don't declare system functions explicitly. … … 2298 2728 @item 2299 2729 If you must declare a system function, don't specify the argument types. 2300 Use an old-style declaration, not a n @sc{ansi}prototype. The more you2730 Use an old-style declaration, not a Standard C prototype. The more you 2301 2731 specify about the function, the more likely a conflict. 2302 2732 … … 2320 2750 specific to those systems. 2321 2751 2752 @cindex string library functions 2322 2753 @item 2323 2754 The string functions require special treatment. Some Unix systems have … … 2330 2761 the string functions from the header file in the usual way. 2331 2762 2332 That causes less of a problem than you might think. The newer @sc{ansi}2763 That causes less of a problem than you might think. The newer standard 2333 2764 string functions should be avoided anyway because many systems still 2334 2765 don't support them. The string functions you can use are these: … … 2360 2791 You should pick a single pair of names and use it throughout your 2361 2792 program. (Nowadays, it is better to choose @code{strchr} and 2362 @code{strrchr} for new programs, since those are the standard @sc{ansi}2793 @code{strrchr} for new programs, since those are the standard 2363 2794 names.) Declare both of those names as functions returning @code{char 2364 2795 *}. On systems which don't support those names, define them as macros … … 2386 2817 @node Internationalization 2387 2818 @section Internationalization 2388 2819 @cindex internationalization 2820 2821 @pindex gettext 2389 2822 GNU has a library called GNU gettext that makes it easy to translate the 2390 2823 messages in a program into various languages. You should use this … … 2413 2846 package---for example, @samp{fileutils} for the GNU file utilities. 2414 2847 2848 @cindex message text, and internationalization 2415 2849 To enable gettext to work well, avoid writing code that makes 2416 2850 assumptions about the structure of words or sentences. When you want … … 2484 2918 @node Mmap 2485 2919 @section Mmap 2920 @findex mmap 2486 2921 2487 2922 Don't assume that @code{mmap} either works on all files or fails … … 2500 2935 @node Documentation 2501 2936 @chapter Documenting Programs 2937 @cindex documentation 2938 2939 A GNU program should ideally come with full free documentation, adequate 2940 for both reference and tutorial purposes. If the package can be 2941 programmed or extended, the documentation should cover programming or 2942 extending it, as well as just using it. 2502 2943 2503 2944 @menu 2504 2945 * GNU Manuals:: Writing proper manuals. 2946 * Doc Strings and Manuals:: Compiling doc strings doesn't make a manual. 2505 2947 * Manual Structure Details:: Specific structure conventions. 2948 * License for Manuals:: Writing the distribution terms for a manual. 2949 * Manual Credits:: Giving credit to documentation contributors. 2950 * Printed Manuals:: Mentioning the printed manual. 2506 2951 * NEWS File:: NEWS files supplement manuals. 2507 2952 * Change Logs:: Recording Changes … … 2514 2959 @section GNU Manuals 2515 2960 2516 The preferred way to document part of the GNU system is to write a 2517 manual in the Texinfo formatting language. See the Texinfo manual, 2518 either the hardcopy, or the on-line version available through 2519 @code{info} or the Emacs Info subsystem (@kbd{C-h i}). 2961 The preferred document format for the GNU system is the Texinfo 2962 formatting language. Every GNU package should (ideally) have 2963 documentation in Texinfo both for reference and for learners. Texinfo 2964 makes it possible to produce a good quality formatted book, using 2965 @TeX{}, and to generate an Info file. It is also possible to generate 2966 HTML output from Texinfo source. See the Texinfo manual, either the 2967 hardcopy, or the on-line version available through @code{info} or the 2968 Emacs Info subsystem (@kbd{C-h i}). 2969 2970 Nowadays some other formats such as Docbook and Sgmltexi can be 2971 converted automatically into Texinfo. It is ok to produce the Texinfo 2972 documentation by conversion this way, as long as it gives good results. 2520 2973 2521 2974 Programmers often find it most natural to structure the documentation … … 2546 2999 together, we can make the whole subject clearer. 2547 3000 2548 The manual which discusses a program should document all of the2549 program's command-line options and all of its commands. It should give 2550 examples of their use. But don't organize the manual as a list of3001 The manual which discusses a program should certainly document all of 3002 the program's command-line options and all of its commands. It should 3003 give examples of their use. But don't organize the manual as a list of 2551 3004 features. Instead, organize it logically, by subtopics. Address the 2552 3005 questions that a user will ask when thinking about the job that the … … 2558 3011 should give a good introduction to a beginner reading through from the 2559 3012 start, and should also provide all the details that hackers want. 3013 The Bison manual is a good example of this---please take a look at it 3014 to see what we mean. 2560 3015 2561 3016 That is not as hard as it first sounds. Arrange each chapter as a … … 2571 3026 Bison manual provides a good example of how to do this. 2572 3027 3028 To serve as a reference, a manual should have an Index that list all the 3029 functions, variables, options, and important concepts that are part of 3030 the program. One combined Index should do for a short manual, but 3031 sometimes for a complex package it is better to use multiple indices. 3032 The Texinfo manual includes advice on preparing good index entries, see 3033 @ref{Index Entries, , Making Index Entries, texinfo, The GNU Texinfo 3034 Manual}, and see @ref{Indexing Commands, , Defining the Entries of an 3035 Index, texinfo, The GNU Texinfo manual}. 3036 2573 3037 Don't use Unix man pages as a model for how to write GNU documentation; 2574 3038 most of them are terse, badly structured, and give inadequate 2575 explanation of the underlying concepts. (There are, of course 2576 exceptions.) Also Unix man pages use a particular format which is3039 explanation of the underlying concepts. (There are, of course, some 3040 exceptions.) Also, Unix man pages use a particular format which is 2577 3041 different from what we use in GNU manuals. 3042 3043 Please include an email address in the manual for where to report 3044 bugs @emph{in the manual}. 2578 3045 2579 3046 Please do not use the term ``pathname'' that is used in Unix 2580 3047 documentation; use ``file name'' (two words) instead. We use the term 2581 ``path'' only for search paths, which are lists of filenames.3048 ``path'' only for search paths, which are lists of directory names. 2582 3049 2583 3050 Please do not use the term ``illegal'' to refer to erroneous input to a 2584 3051 computer program. Please use ``invalid'' for this, and reserve the term 2585 ``illegal'' for violations of law. 3052 ``illegal'' for activities punishable by law. 3053 3054 @node Doc Strings and Manuals 3055 @section Doc Strings and Manuals 3056 3057 Some programming systems, such as Emacs, provide a documentation string 3058 for each function, command or variable. You may be tempted to write a 3059 reference manual by compiling the documentation strings and writing a 3060 little additional text to go around them---but you must not do it. That 3061 approach is a fundamental mistake. The text of well-written 3062 documentation strings will be entirely wrong for a manual. 3063 3064 A documentation string needs to stand alone---when it appears on the 3065 screen, there will be no other text to introduce or explain it. 3066 Meanwhile, it can be rather informal in style. 3067 3068 The text describing a function or variable in a manual must not stand 3069 alone; it appears in the context of a section or subsection. Other text 3070 at the beginning of the section should explain some of the concepts, and 3071 should often make some general points that apply to several functions or 3072 variables. The previous descriptions of functions and variables in the 3073 section will also have given information about the topic. A description 3074 written to stand alone would repeat some of that information; this 3075 redundance looks bad. Meanwhile, the informality that is acceptable in 3076 a documentation string is totally unacceptable in a manual. 3077 3078 The only good way to use documentation strings in writing a good manual 3079 is to use them as a source of information for writing good text. 2586 3080 2587 3081 @node Manual Structure Details 2588 3082 @section Manual Structure Details 3083 @cindex manual structure 2589 3084 2590 3085 The title page of the manual should state the version of the programs or … … 2594 3089 number for the manual in both of these places. 2595 3090 2596 Each program documented in the manual should shouldhave a node named3091 Each program documented in the manual should have a node named 2597 3092 @samp{@var{program} Invocation} or @samp{Invoking @var{program}}. This 2598 3093 node (together with its subnodes, if any) should describe the program's … … 2606 3101 as the node for this purpose, regardless of the node's actual name. 2607 3102 2608 There will be automatic features for specifying a program name and 2609 quickly reading just this part of its manual. 3103 The @samp{--usage} feature of the Info reader looks for such a node 3104 or menu item in order to find the relevant text, so it is essential 3105 for every Texinfo file to have one. 2610 3106 2611 3107 If one manual describes several programs, it should have such a node for 2612 each program described. 3108 each program described in the manual. 3109 3110 @node License for Manuals 3111 @section License for Manuals 3112 @cindex license for manuals 3113 3114 Please use the GNU Free Documentation License for all GNU manuals that 3115 are more than a few pages long. Likewise for a collection of short 3116 documents---you only need one copy of the GNU FDL for the whole 3117 collection. For a single short document, you can use a very permissive 3118 non-copyleft license, to avoid taking up space with a long license. 3119 3120 See @uref{http://www.gnu.org/copyleft/fdl-howto.html} for more explanation 3121 of how to employ the GFDL. 3122 3123 Note that it is not obligatory to include a copy of the GNU GPL or GNU 3124 LGPL in a manual whose license is neither the GPL nor the LGPL. It can 3125 be a good idea to include the program's license in a large manual; in a 3126 short manual, whose size would be increased considerably by including 3127 the program's license, it is probably better not to include it. 3128 3129 @node Manual Credits 3130 @section Manual Credits 3131 @cindex credits for manuals 3132 3133 Please credit the principal human writers of the manual as the authors, 3134 on the title page of the manual. If a company sponsored the work, thank 3135 the company in a suitable place in the manual, but do not cite the 3136 company as an author. 3137 3138 @node Printed Manuals 3139 @section Printed Manuals 3140 3141 The FSF publishes some GNU manuals in printed form. To encourage sales 3142 of these manuals, the on-line versions of the manual should mention at 3143 the very start that the printed manual is available and should point at 3144 information for getting it---for instance, with a link to the page 3145 @url{http://www.gnu.org/order/order.html}. This should not be included 3146 in the printed manual, though, because there it is redundant. 3147 3148 It is also useful to explain in the on-line forms of the manual how the 3149 user can print out the manual from the sources. 2613 3150 2614 3151 @node NEWS File 2615 3152 @section The NEWS File 3153 @cindex @file{NEWS} file 2616 3154 2617 3155 In addition to its manual, the package should have a file named … … 2628 3166 @node Change Logs 2629 3167 @section Change Logs 3168 @cindex change logs 2630 3169 2631 3170 Keep a change log to describe all the changes made to program source … … 2642 3181 * Simple Changes:: 2643 3182 * Conditional Changes:: 3183 * Indicating the Part Changed:: 2644 3184 @end menu 2645 3185 … … 2660 3200 Another alternative is to record change log information with a version 2661 3201 control system such as RCS or CVS. This can be converted automatically 2662 to a @file{ChangeLog} file. 3202 to a @file{ChangeLog} file using @code{rcs2log}; in Emacs, the command 3203 @kbd{C-x v a} (@code{vc-update-change-log}) does the job. 2663 3204 2664 3205 There's no need to describe the full purpose of the changes or how they … … 2681 3222 @node Style of Change Logs 2682 3223 @subsection Style of Change Logs 2683 2684 Here are some examples of change log entries: 2685 2686 @example 3224 @cindex change logs, style 3225 3226 Here are some simple examples of change log entries, starting with the 3227 header line that says who made the change and when, followed by 3228 descriptions of specific changes. (These examples are drawn from Emacs 3229 and GCC.) 3230 3231 @example 3232 1998-08-17 Richard Stallman <rms@@gnu.org> 3233 2687 3234 * register.el (insert-register): Return nil. 2688 3235 (jump-to-register): Likewise. … … 2715 3262 name and the asterisk when successive entries are in the same file. 2716 3263 3264 Break long lists of function names by closing continued lines with 3265 @samp{)}, rather than @samp{,}, and opening the continuation with 3266 @samp{(} as in this example: 3267 3268 @example 3269 * keyboard.c (menu_bar_items, tool_bar_items) 3270 (Fexecute_extended_command): Deal with `keymap' property. 3271 @end example 3272 2717 3273 @node Simple Changes 2718 3274 @subsection Simple Changes … … 2722 3278 2723 3279 When you change the calling sequence of a function in a simple fashion, 2724 and you change all the callers of the function, there is no need to make 2725 individual entries for all the callers that you changed. Just write in 2726 the entry for the function being called, ``All callers changed.'' 3280 and you change all the callers of the function to use the new calling 3281 sequence, there is no need to make individual entries for all the 3282 callers that you changed. Just write in the entry for the function 3283 being called, ``All callers changed''---like this: 2727 3284 2728 3285 @example … … 2744 3301 @node Conditional Changes 2745 3302 @subsection Conditional Changes 3303 @cindex conditional changes, and change logs 3304 @cindex change logs, conditional changes 2746 3305 2747 3306 C programs often contain compile-time @code{#if} conditionals. Many … … 2783 3342 @end example 2784 3343 3344 @node Indicating the Part Changed 3345 @subsection Indicating the Part Changed 3346 3347 Indicate the part of a function which changed by using angle brackets 3348 enclosing an indication of what the changed part does. Here is an entry 3349 for a change in the part of the function @code{sh-while-getopts} that 3350 deals with @code{sh} commands: 3351 3352 @example 3353 * progmodes/sh-script.el (sh-while-getopts) <sh>: Handle case that 3354 user-specified option string is empty. 3355 @end example 3356 3357 2785 3358 @node Man Pages 2786 3359 @section Man Pages 3360 @cindex man pages 2787 3361 2788 3362 In the GNU project, man pages are secondary. It is not necessary or … … 2831 3405 @node Managing Releases 2832 3406 @chapter The Release Process 3407 @cindex releasing 2833 3408 2834 3409 Making a release is more than just bundling up your source files in a … … 2842 3417 @menu 2843 3418 * Configuration:: How Configuration Should Work 2844 * Makefile Conventions:: 3419 * Makefile Conventions:: Makefile Conventions 2845 3420 * Releases:: Making Releases 2846 3421 @end menu … … 2848 3423 @node Configuration 2849 3424 @section How Configuration Should Work 2850 3425 @cindex program configuration 3426 3427 @pindex configure 2851 3428 Each GNU distribution should come with a shell script named 2852 3429 @code{configure}. This script is given arguments which describe the … … 2916 3493 would be a valid alias. For many programs, @samp{vax-dec-ultrix} would 2917 3494 be an alias for @samp{vax-dec-bsd}, simply because the differences 2918 between Ultrix and @sc{ BSD} are rarely noticeable, but a few programs3495 between Ultrix and @sc{bsd} are rarely noticeable, but a few programs 2919 3496 might need to distinguish them. 2920 3497 @c Real 4.4BSD now runs on some Suns. … … 2923 3500 as a subroutine to validate system types and canonicalize aliases. 2924 3501 3502 @cindex optional features, configure-time 2925 3503 Other options are permitted to specify in more detail the software 2926 3504 or hardware present on the machine, and include or exclude optional … … 2948 3526 @c @samp{no} should omit @var{package}, if it is used by default. 2949 3527 2950 Possible values of @var{package} include 3528 Possible values of @var{package} include 2951 3529 @samp{gnu-as} (or @samp{gas}), @samp{gnu-ld}, @samp{gnu-libc}, 2952 3530 @samp{gdb}, 2953 @samp{x}, 3531 @samp{x}, 2954 3532 and 2955 3533 @samp{x-toolkit}. … … 2958 3536 find certain files. That is outside the scope of what @samp{--with} 2959 3537 options are for. 2960 2961 @item --nfp2962 The target machine has no floating point processor.2963 2964 @item --gas2965 The target machine assembler is GAS, the GNU assembler.2966 This is obsolete; users should use @samp{--with-gnu-as} instead.2967 2968 @item --x2969 The target machine has the X Window System installed.2970 This is obsolete; users should use @samp{--with-x} instead.2971 3538 @end table 2972 3539 … … 2984 3551 have idiosyncratic configuration options. 2985 3552 2986 Packages that perform part of the compilation process may support cross-compilation. 2987 In such a case, the host and target machines for the program may be 2988 different. The @code{configure} script should normally treat the 2989 specified type of system as both the host and the target, thus producing 2990 a program which works for the same type of machine that it runs on. 2991 2992 The way to build a cross-compiler, cross-assembler, or what have you, is 2993 to specify the option @samp{--host=@var{hosttype}} when running 2994 @code{configure}. This specifies the host system without changing the 2995 type of target system. The syntax for @var{hosttype} is the same as 2996 described above. 3553 Packages that perform part of the compilation process may support 3554 cross-compilation. In such a case, the host and target machines for the 3555 program may be different. 3556 3557 The @code{configure} script should normally treat the specified type of 3558 system as both the host and the target, thus producing a program which 3559 works for the same type of machine that it runs on. 3560 3561 To configure a cross-compiler, cross-assembler, or what have you, you 3562 should specify a target different from the host, using the configure 3563 option @samp{--target=@var{targettype}}. The syntax for 3564 @var{targettype} is the same as for the host type. So the command would 3565 look like this: 3566 3567 @example 3568 ./configure @var{hosttype} --target=@var{targettype} 3569 @end example 3570 3571 Programs for which cross-operation is not meaningful need not accept the 3572 @samp{--target} option, because configuring an entire operating system for 3573 cross-operation is not a meaningful operation. 2997 3574 2998 3575 Bootstrapping a cross-compiler requires compiling it on a machine other 2999 3576 than the host it will run on. Compilation packages accept a 3000 configuration option @samp{--build=@var{hosttype}} for specifying the 3001 configuration on which you will compile them, in case that is different 3002 from the host. 3003 3004 Programs for which cross-operation is not meaningful need not accept the 3005 @samp{--host} option, because configuring an entire operating system for 3006 cross-operation is not a meaningful thing. 3577 configuration option @samp{--build=@var{buildtype}} for specifying the 3578 configuration on which you will compile them, but the configure script 3579 should normally guess the build machine type (using 3580 @file{config.guess}), so this option is probably not necessary. The 3581 host and target types normally default from the build type, so in 3582 bootstrapping a cross-compiler you must specify them both explicitly. 3007 3583 3008 3584 Some programs have ways of configuring themselves automatically. If … … 3019 3595 @node Releases 3020 3596 @section Making Releases 3597 @cindex packaging 3021 3598 3022 3599 Package the distribution of @code{Foo version 69.96} up in a gzipped tar … … 3030 3607 and never changed automatically; non-source files are produced from 3031 3608 source files by programs under the control of the Makefile. 3609 3610 @cindex @file{README} file 3611 The distribution should contain a file named @file{README} which gives 3612 the name of the package, and a general description of what it does. It 3613 is also good to explain the purpose of each of the first-level 3614 subdirectories in the package, if there are any. The @file{README} file 3615 should either state the version number of the package, or refer to where 3616 in the package it can be found. 3617 3618 The @file{README} file should refer to the file @file{INSTALL}, which 3619 should contain an explanation of the installation procedure. 3620 3621 The @file{README} file should also refer to the file which contains the 3622 copying conditions. The GNU GPL, if used, should be in a file called 3623 @file{COPYING}. If the GNU LGPL is used, it should be in a file called 3624 @file{COPYING.LIB}. 3032 3625 3033 3626 Naturally, all the source files must be in the distribution. It is okay … … 3055 3648 characters long. Likewise, no file created by building the program 3056 3649 should have a name longer than 14 characters. The reason for this is 3057 that some systems adhere to a foolish interpretation of the POSIX3650 that some systems adhere to a foolish interpretation of the @sc{posix} 3058 3651 standard, and refuse to open a longer name, rather than truncating as 3059 3652 they did in the past. … … 3074 3667 distinct. 3075 3668 3669 @cindex @file{texinfo.tex}, in a distribution 3076 3670 Include in your distribution a copy of the @file{texinfo.tex} you used 3077 3671 to test print any @file{*.texinfo} or @file{*.texi} files. … … 3083 3677 other files to get. 3084 3678 3679 @node References 3680 @chapter References to Non-Free Software and Documentation 3681 @cindex references to non-free material 3682 3683 A GNU program should not recommend use of any non-free program. We 3684 can't stop some people from writing proprietary programs, or stop 3685 other people from using them, but we can and should avoid helping to 3686 advertise them to new potential customers. Proprietary software is a 3687 social and ethical problem, and the point of GNU is to solve that 3688 problem. 3689 3690 When a non-free program or system is well known, you can mention it in 3691 passing---that is harmless, since users who might want to use it 3692 probably already know about it. For instance, it is fine to explain 3693 how to build your package on top of some non-free operating system, or 3694 how to use it together with some widely used non-free program. 3695 3696 However, you should give only the necessary information to help those 3697 who already use the non-free program to use your program with 3698 it---don't give, or refer to, any further information about the 3699 proprietary program, and don't imply that the proprietary program 3700 enhances your program, or that its existence is in any way a good 3701 thing. The goal should be that people already using the proprietary 3702 program will get the advice they need about how to use your free 3703 program, while people who don't already use the proprietary program 3704 will not see anything to lead them to take an interest in it. 3705 3706 If a non-free program or system is obscure in your program's domain, 3707 your program should not mention or support it at all, since doing so 3708 would tend to popularize the non-free program more than it popularizes 3709 your program. (You cannot hope to find many additional users among 3710 the users of Foobar if the users of Foobar are few.) 3711 3712 A GNU package should not refer the user to any non-free documentation 3713 for free software. Free documentation that can be included in free 3714 operating systems is essential for completing the GNU system, so it is 3715 a major focus of the GNU Project; to recommend use of documentation 3716 that we are not allowed to use in GNU would undermine the efforts to 3717 get documentation that we can include. So GNU packages should never 3718 recommend non-free documentation. 3719 3720 @node Copying This Manual 3721 @appendix Copying This Manual 3722 3723 @menu 3724 * GNU Free Documentation License:: License for copying this manual 3725 @end menu 3726 3727 @include fdl.texi 3728 3729 @node Index 3730 @unnumbered Index 3731 @printindex cp 3732 3085 3733 @contents 3086 3734 3087 3735 @bye 3088 Local variables: 3089 update-date-leading-regexp: "@c This date is automagically updated when you save this file:\n@set lastupdate " 3090 update-date-trailing-regexp: "" 3091 eval: (load "/gd/gnuorg/update-date.el") 3092 eval: (add-hook 'write-file-hooks 'update-date) 3093 End: 3736 @c Local variables: 3737 @c eval: (add-hook 'write-file-hooks 'time-stamp) 3738 @c time-stamp-start: "@set lastupdate " 3739 @c time-stamp-end: "$" 3740 @c time-stamp-format: "%:b %:d, %:y" 3741 @c compile-command: "make just-standards" 3742 @c End: -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.