standards.texi 141 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256
  1. \input texinfo @c -*-texinfo-*-
  2. @c %**start of header
  3. @setfilename standards.info
  4. @settitle GNU Coding Standards
  5. @c This date is automagically updated when you save this file:
  6. @set lastupdate April 7, 2012
  7. @c %**end of header
  8. @dircategory GNU organization
  9. @direntry
  10. * Standards: (standards). GNU coding standards.
  11. @end direntry
  12. @c @setchapternewpage odd
  13. @setchapternewpage off
  14. @c Put everything in one index (arbitrarily chosen to be the concept index).
  15. @syncodeindex fn cp
  16. @syncodeindex ky cp
  17. @syncodeindex pg cp
  18. @syncodeindex vr cp
  19. @c This is used by a cross ref in make-stds.texi
  20. @set CODESTD 1
  21. @copying
  22. The GNU coding standards, last updated @value{lastupdate}.
  23. Copyright @copyright{} 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
  24. 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
  25. 2011, 2012 Free Software Foundation, Inc.
  26. Permission is granted to copy, distribute and/or modify this document
  27. under the terms of the GNU Free Documentation License, Version 1.3 or
  28. any later version published by the Free Software Foundation; with no
  29. Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
  30. Texts. A copy of the license is included in the section entitled
  31. ``GNU Free Documentation License''.
  32. @end copying
  33. @titlepage
  34. @title GNU Coding Standards
  35. @author Richard Stallman, et al.
  36. @author last updated @value{lastupdate}
  37. @page
  38. @vskip 0pt plus 1filll
  39. @insertcopying
  40. @end titlepage
  41. @contents
  42. @ifnottex
  43. @node Top
  44. @top GNU Coding Standards
  45. @insertcopying
  46. @end ifnottex
  47. @menu
  48. * Preface:: About the GNU Coding Standards.
  49. * Legal Issues:: Keeping free software free.
  50. * Design Advice:: General program design.
  51. * Program Behavior:: Program behavior for all programs
  52. * Writing C:: Making the best use of C.
  53. * Documentation:: Documenting programs.
  54. * Managing Releases:: The release process.
  55. * References:: Mentioning non-free software or documentation.
  56. * GNU Free Documentation License:: Copying and sharing this manual.
  57. * Index::
  58. @end menu
  59. @node Preface
  60. @chapter About the GNU Coding Standards
  61. The GNU Coding Standards were written by Richard Stallman and other GNU
  62. Project volunteers. Their purpose is to make the GNU system clean,
  63. consistent, and easy to install. This document can also be read as a
  64. guide to writing portable, robust and reliable programs. It focuses on
  65. programs written in C, but many of the rules and principles are useful
  66. even if you write in another programming language. The rules often
  67. state reasons for writing in a certain way.
  68. @cindex where to obtain @code{standards.texi}
  69. @cindex downloading this manual
  70. If you did not obtain this file directly from the GNU project and
  71. recently, please check for a newer version. You can get the GNU
  72. Coding Standards from the GNU web server in many
  73. different formats, including the Texinfo source, PDF, HTML, DVI, plain
  74. text, and more, at: @uref{http://www.gnu.org/prep/standards/}.
  75. If you are maintaining an official GNU package, in addition to this
  76. document, please read and follow the GNU maintainer information
  77. (@pxref{Top, , Contents, maintain, Information for Maintainers of GNU
  78. Software}).
  79. @cindex @code{gnustandards-commit@@gnu.org} mailing list
  80. If you want to receive diffs for every change to these GNU documents,
  81. join the mailing list @code{gnustandards-commit@@gnu.org}, via the web
  82. interface at
  83. @url{http://lists.gnu.org/mailman/listinfo/gnustandards-commit}.
  84. Archives are also available there.
  85. @cindex @code{bug-standards@@gnu.org} email address
  86. @cindex Savannah repository for gnustandards
  87. @cindex gnustandards project repository
  88. Please send corrections or suggestions for this document to
  89. @email{bug-standards@@gnu.org}. If you make a suggestion, please
  90. include a suggested new wording for it, to help us consider the
  91. suggestion efficiently. We prefer a context diff to the Texinfo
  92. source, but if that's difficult for you, you can make a context diff
  93. for some other version of this document, or propose it in any way that
  94. makes it clear. The source repository for this document can be found
  95. at @url{http://savannah.gnu.org/projects/gnustandards}.
  96. These standards cover the minimum of what is important when writing a
  97. GNU package. Likely, the need for additional standards will come up.
  98. Sometimes, you might suggest that such standards be added to this
  99. document. If you think your standards would be generally useful, please
  100. do suggest them.
  101. You should also set standards for your package on many questions not
  102. addressed or not firmly specified here. The most important point is to
  103. be self-consistent---try to stick to the conventions you pick, and try
  104. to document them as much as possible. That way, your program will be
  105. more maintainable by others.
  106. The GNU Hello program serves as an example of how to follow the GNU
  107. coding standards for a trivial program.
  108. @uref{http://www.gnu.org/software/hello/hello.html}.
  109. This release of the GNU Coding Standards was last updated
  110. @value{lastupdate}.
  111. @node Legal Issues
  112. @chapter Keeping Free Software Free
  113. @cindex legal aspects
  114. This chapter discusses how you can make sure that GNU software
  115. avoids legal difficulties, and other related issues.
  116. @menu
  117. * Reading Non-Free Code:: Referring to proprietary programs.
  118. * Contributions:: Accepting contributions.
  119. * Trademarks:: How we deal with trademark issues.
  120. @end menu
  121. @node Reading Non-Free Code
  122. @section Referring to Proprietary Programs
  123. @cindex proprietary programs
  124. @cindex avoiding proprietary code
  125. Don't in any circumstances refer to Unix source code for or during
  126. your work on GNU! (Or to any other proprietary programs.)
  127. If you have a vague recollection of the internals of a Unix program,
  128. this does not absolutely mean you can't write an imitation of it, but
  129. do try to organize the imitation internally along different lines,
  130. because this is likely to make the details of the Unix version
  131. irrelevant and dissimilar to your results.
  132. For example, Unix utilities were generally optimized to minimize
  133. memory use; if you go for speed instead, your program will be very
  134. different. You could keep the entire input file in memory and scan it
  135. there instead of using stdio. Use a smarter algorithm discovered more
  136. recently than the Unix program. Eliminate use of temporary files. Do
  137. it in one pass instead of two (we did this in the assembler).
  138. Or, on the contrary, emphasize simplicity instead of speed. For some
  139. applications, the speed of today's computers makes simpler algorithms
  140. adequate.
  141. Or go for generality. For example, Unix programs often have static
  142. tables or fixed-size strings, which make for arbitrary limits; use
  143. dynamic allocation instead. Make sure your program handles NULs and
  144. other funny characters in the input files. Add a programming language
  145. for extensibility and write part of the program in that language.
  146. Or turn some parts of the program into independently usable libraries.
  147. Or use a simple garbage collector instead of tracking precisely when
  148. to free memory, or use a new GNU facility such as obstacks.
  149. @node Contributions
  150. @section Accepting Contributions
  151. @cindex legal papers
  152. @cindex accepting contributions
  153. If the program you are working on is copyrighted by the Free Software
  154. Foundation, then when someone else sends you a piece of code to add to
  155. the program, we need legal papers to use it---just as we asked you to
  156. sign papers initially. @emph{Each} person who makes a nontrivial
  157. contribution to a program must sign some sort of legal papers in order
  158. for us to have clear title to the program; the main author alone is not
  159. enough.
  160. So, before adding in any contributions from other people, please tell
  161. us, so we can arrange to get the papers. Then wait until we tell you
  162. that we have received the signed papers, before you actually use the
  163. contribution.
  164. This applies both before you release the program and afterward. If
  165. you receive diffs to fix a bug, and they make significant changes, we
  166. need legal papers for that change.
  167. This also applies to comments and documentation files. For copyright
  168. law, comments and code are just text. Copyright applies to all kinds of
  169. text, so we need legal papers for all kinds.
  170. We know it is frustrating to ask for legal papers; it's frustrating for
  171. us as well. But if you don't wait, you are going out on a limb---for
  172. example, what if the contributor's employer won't sign a disclaimer?
  173. You might have to take that code out again!
  174. You don't need papers for changes of a few lines here or there, since
  175. they are not significant for copyright purposes. Also, you don't need
  176. papers if all you get from the suggestion is some ideas, not actual code
  177. which you use. For example, if someone sent you one implementation, but
  178. you write a different implementation of the same idea, you don't need to
  179. get papers.
  180. The very worst thing is if you forget to tell us about the other
  181. contributor. We could be very embarrassed in court some day as a
  182. result.
  183. We have more detailed advice for maintainers of GNU packages. If you
  184. have reached the stage of maintaining a GNU program (whether released
  185. or not), please take a look: @pxref{Legal Matters,,, maintain,
  186. Information for GNU Maintainers}.
  187. @node Trademarks
  188. @section Trademarks
  189. @cindex trademarks
  190. Please do not include any trademark acknowledgements in GNU software
  191. packages or documentation.
  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,
  195. and there is no legal requirement for them, so we don't use them.
  196. What is legally required, as regards other people's trademarks, is to
  197. avoid using them in ways which a reader might reasonably understand as
  198. naming or labeling our own programs or activities. For example, since
  199. ``Objective C'' is (or at least was) a trademark, we made sure to say
  200. that we provide a ``compiler for the Objective C language'' rather
  201. than an ``Objective C compiler''. The latter would have been meant as
  202. a shorter way of saying the former, but it does not explicitly state
  203. the relationship, so it could be misinterpreted as using ``Objective
  204. C'' as a label for the compiler rather than for the language.
  205. Please don't use ``win'' as an abbreviation for Microsoft Windows in
  206. GNU software or documentation. In hacker terminology, calling
  207. something a ``win'' is a form of praise. If you wish to praise
  208. Microsoft Windows when speaking on your own, by all means do so, but
  209. not in GNU software. Usually we write the name ``Windows'' in full,
  210. but when brevity is very important (as in file names and sometimes
  211. symbol names), we abbreviate it to ``w''. For instance, the files and
  212. functions in Emacs that deal with Windows start with @samp{w32}.
  213. @node Design Advice
  214. @chapter General Program Design
  215. @cindex program design
  216. This chapter discusses some of the issues you should take into
  217. account when designing your program.
  218. @c Standard or ANSI C
  219. @c
  220. @c In 1989 the American National Standards Institute (ANSI) standardized
  221. @c C as standard X3.159-1989. In December of that year the
  222. @c International Standards Organization ISO adopted the ANSI C standard
  223. @c making minor changes. In 1990 ANSI then re-adopted ISO standard
  224. @c C. This version of C is known as either ANSI C or Standard C.
  225. @c A major revision of the C Standard appeared in 1999.
  226. @menu
  227. * Source Language:: Which languages to use.
  228. * Compatibility:: Compatibility with other implementations.
  229. * Using Extensions:: Using non-standard features.
  230. * Standard C:: Using standard C features.
  231. * Conditional Compilation:: Compiling code only if a conditional is true.
  232. @end menu
  233. @node Source Language
  234. @section Which Languages to Use
  235. @cindex programming languages
  236. When you want to use a language that gets compiled and runs at high
  237. speed, the best language to use is C. Using another language is like
  238. using a non-standard feature: it will cause trouble for users. Even if
  239. GCC supports the other language, users may find it inconvenient to have
  240. to install the compiler for that other language in order to build your
  241. program. For example, if you write your program in C++, people will
  242. have to install the GNU C++ compiler in order to compile your program.
  243. C has one other advantage over C++ and other compiled languages: more
  244. people know C, so more people will find it easy to read and modify the
  245. program if it is written in C.
  246. So in general it is much better to use C, rather than the
  247. comparable alternatives.
  248. But there are two exceptions to that conclusion:
  249. @itemize @bullet
  250. @item
  251. It is no problem to use another language to write a tool specifically
  252. intended for use with that language. That is because the only people
  253. who want to build the tool will be those who have installed the other
  254. language anyway.
  255. @item
  256. If an application is of interest only to a narrow part of the community,
  257. then the question of which language it is written in has less effect on
  258. other people, so you may as well please yourself.
  259. @end itemize
  260. Many programs are designed to be extensible: they include an interpreter
  261. for a language that is higher level than C. Often much of the program
  262. is written in that language, too. The Emacs editor pioneered this
  263. technique.
  264. @cindex Guile
  265. @cindex GNOME and Guile
  266. The standard extensibility interpreter for GNU software is Guile
  267. (@uref{http://www.gnu.org/@/software/@/guile/}), which implements the
  268. language Scheme (an especially clean and simple dialect of Lisp).
  269. Guile also includes bindings for GTK+/GNOME, making it practical to
  270. write modern GUI functionality within Guile. We don't reject programs
  271. written in other ``scripting languages'' such as Perl and Python, but
  272. using Guile is very important for the overall consistency of the GNU
  273. system.
  274. @node Compatibility
  275. @section Compatibility with Other Implementations
  276. @cindex compatibility with C and @sc{posix} standards
  277. @cindex @sc{posix} compatibility
  278. With occasional exceptions, utility programs and libraries for GNU
  279. should be upward compatible with those in Berkeley Unix, and upward
  280. compatible with Standard C if Standard C specifies their
  281. behavior, and upward compatible with @sc{posix} if @sc{posix} specifies
  282. their behavior.
  283. When these standards conflict, it is useful to offer compatibility
  284. modes for each of them.
  285. @cindex options for compatibility
  286. Standard C and @sc{posix} prohibit many kinds of extensions. Feel
  287. free to make the extensions anyway, and include a @samp{--ansi},
  288. @samp{--posix}, or @samp{--compatible} option to turn them off.
  289. However, if the extension has a significant chance of breaking any real
  290. programs or scripts, then it is not really upward compatible. So you
  291. should try to redesign its interface to make it upward compatible.
  292. @cindex @code{POSIXLY_CORRECT}, environment variable
  293. Many GNU programs suppress extensions that conflict with @sc{posix} if the
  294. environment variable @code{POSIXLY_CORRECT} is defined (even if it is
  295. defined with a null value). Please make your program recognize this
  296. variable if appropriate.
  297. When a feature is used only by users (not by programs or command
  298. files), and it is done poorly in Unix, feel free to replace it
  299. completely with something totally different and better. (For example,
  300. @code{vi} is replaced with Emacs.) But it is nice to offer a compatible
  301. feature as well. (There is a free @code{vi} clone, so we offer it.)
  302. Additional useful features are welcome regardless of whether
  303. there is any precedent for them.
  304. @node Using Extensions
  305. @section Using Non-standard Features
  306. @cindex non-standard extensions
  307. Many GNU facilities that already exist support a number of convenient
  308. extensions over the comparable Unix facilities. Whether to use these
  309. extensions in implementing your program is a difficult question.
  310. On the one hand, using the extensions can make a cleaner program.
  311. On the other hand, people will not be able to build the program
  312. unless the other GNU tools are available. This might cause the
  313. program to work on fewer kinds of machines.
  314. With some extensions, it might be easy to provide both alternatives.
  315. For example, you can define functions with a ``keyword'' @code{INLINE}
  316. and define that as a macro to expand into either @code{inline} or
  317. nothing, depending on the compiler.
  318. In general, perhaps it is best not to use the extensions if you can
  319. straightforwardly do without them, but to use the extensions if they
  320. are a big improvement.
  321. An exception to this rule are the large, established programs (such as
  322. Emacs) which run on a great variety of systems. Using GNU extensions in
  323. such programs would make many users unhappy, so we don't do that.
  324. Another exception is for programs that are used as part of compilation:
  325. anything that must be compiled with other compilers in order to
  326. bootstrap the GNU compilation facilities. If these require the GNU
  327. compiler, then no one can compile them without having them installed
  328. already. That would be extremely troublesome in certain cases.
  329. @node Standard C
  330. @section Standard C and Pre-Standard C
  331. @cindex @sc{ansi} C standard
  332. 1989 Standard C is widespread enough now that it is ok to use its
  333. features in new programs. There is one exception: do not ever use the
  334. ``trigraph'' feature of Standard C.
  335. 1999 Standard C is not widespread yet, so please do not require its
  336. features in programs. It is ok to use its features if they are present.
  337. However, it is easy to support pre-standard compilers in most programs,
  338. so if you know how to do that, feel free. If a program you are
  339. maintaining has such support, you should try to keep it working.
  340. @cindex function prototypes
  341. To support pre-standard C, instead of writing function definitions in
  342. standard prototype form,
  343. @example
  344. int
  345. foo (int x, int y)
  346. @dots{}
  347. @end example
  348. @noindent
  349. write the definition in pre-standard style like this,
  350. @example
  351. int
  352. foo (x, y)
  353. int x, y;
  354. @dots{}
  355. @end example
  356. @noindent
  357. and use a separate declaration to specify the argument prototype:
  358. @example
  359. int foo (int, int);
  360. @end example
  361. You need such a declaration anyway, in a header file, to get the benefit
  362. of prototypes in all the files where the function is called. And once
  363. you have the declaration, you normally lose nothing by writing the
  364. function definition in the pre-standard style.
  365. This technique does not work for integer types narrower than @code{int}.
  366. If you think of an argument as being of a type narrower than @code{int},
  367. declare it as @code{int} instead.
  368. There are a few special cases where this technique is hard to use. For
  369. example, if a function argument needs to hold the system type
  370. @code{dev_t}, you run into trouble, because @code{dev_t} is shorter than
  371. @code{int} on some machines; but you cannot use @code{int} instead,
  372. because @code{dev_t} is wider than @code{int} on some machines. There
  373. is no type you can safely use on all machines in a non-standard
  374. definition. The only way to support non-standard C and pass such an
  375. argument is to check the width of @code{dev_t} using Autoconf and choose
  376. the argument type accordingly. This may not be worth the trouble.
  377. In order to support pre-standard compilers that do not recognize
  378. prototypes, you may want to use a preprocessor macro like this:
  379. @example
  380. /* Declare the prototype for a general external function. */
  381. #if defined (__STDC__) || defined (WINDOWSNT)
  382. #define P_(proto) proto
  383. #else
  384. #define P_(proto) ()
  385. #endif
  386. @end example
  387. @node Conditional Compilation
  388. @section Conditional Compilation
  389. When supporting configuration options already known when building your
  390. program we prefer using @code{if (... )} over conditional compilation,
  391. as in the former case the compiler is able to perform more extensive
  392. checking of all possible code paths.
  393. For example, please write
  394. @smallexample
  395. if (HAS_FOO)
  396. ...
  397. else
  398. ...
  399. @end smallexample
  400. @noindent
  401. instead of:
  402. @smallexample
  403. #ifdef HAS_FOO
  404. ...
  405. #else
  406. ...
  407. #endif
  408. @end smallexample
  409. A modern compiler such as GCC will generate exactly the same code in
  410. both cases, and we have been using similar techniques with good success
  411. in several projects. Of course, the former method assumes that
  412. @code{HAS_FOO} is defined as either 0 or 1.
  413. While this is not a silver bullet solving all portability problems,
  414. and is not always appropriate, following this policy would have saved
  415. GCC developers many hours, or even days, per year.
  416. In the case of function-like macros like @code{REVERSIBLE_CC_MODE} in
  417. GCC which cannot be simply used in @code{if (...)} statements, there is
  418. an easy workaround. Simply introduce another macro
  419. @code{HAS_REVERSIBLE_CC_MODE} as in the following example:
  420. @smallexample
  421. #ifdef REVERSIBLE_CC_MODE
  422. #define HAS_REVERSIBLE_CC_MODE 1
  423. #else
  424. #define HAS_REVERSIBLE_CC_MODE 0
  425. #endif
  426. @end smallexample
  427. @node Program Behavior
  428. @chapter Program Behavior for All Programs
  429. This chapter describes conventions for writing robust
  430. software. It also describes general standards for error messages, the
  431. command line interface, and how libraries should behave.
  432. @menu
  433. * Non-GNU Standards:: We consider standards such as POSIX;
  434. we don't "obey" them.
  435. * Semantics:: Writing robust programs.
  436. * Libraries:: Library behavior.
  437. * Errors:: Formatting error messages.
  438. * User Interfaces:: Standards about interfaces generally.
  439. * Graphical Interfaces:: Standards for graphical interfaces.
  440. * Command-Line Interfaces:: Standards for command line interfaces.
  441. * Dynamic Plug-In Interfaces:: Standards for dynamic plug-in interfaces.
  442. * Option Table:: Table of long options.
  443. * OID Allocations:: Table of OID slots for GNU.
  444. * Memory Usage:: When and how to care about memory needs.
  445. * File Usage:: Which files to use, and where.
  446. @end menu
  447. @node Non-GNU Standards
  448. @section Non-GNU Standards
  449. The GNU Project regards standards published by other organizations as
  450. suggestions, not orders. We consider those standards, but we do not
  451. ``obey'' them. In developing a GNU program, you should implement
  452. an outside standard's specifications when that makes the GNU system
  453. better overall in an objective sense. When it doesn't, you shouldn't.
  454. In most cases, following published standards is convenient for
  455. users---it means that their programs or scripts will work more
  456. portably. For instance, GCC implements nearly all the features of
  457. Standard C as specified by that standard. C program developers would
  458. be unhappy if it did not. And GNU utilities mostly follow
  459. specifications of POSIX.2; shell script writers and users would be
  460. unhappy if our programs were incompatible.
  461. But we do not follow either of these specifications rigidly, and there
  462. are specific points on which we decided not to follow them, so as to
  463. make the GNU system better for users.
  464. For instance, Standard C says that nearly all extensions to C are
  465. prohibited. How silly! GCC implements many extensions, some of which
  466. were later adopted as part of the standard. If you want these
  467. constructs to give an error message as ``required'' by the standard,
  468. you must specify @samp{--pedantic}, which was implemented only so that
  469. we can say ``GCC is a 100% implementation of the standard'', not
  470. because there is any reason to actually use it.
  471. POSIX.2 specifies that @samp{df} and @samp{du} must output sizes by
  472. default in units of 512 bytes. What users want is units of 1k, so
  473. that is what we do by default. If you want the ridiculous behavior
  474. ``required'' by POSIX, you must set the environment variable
  475. @samp{POSIXLY_CORRECT} (which was originally going to be named
  476. @samp{POSIX_ME_HARDER}).
  477. GNU utilities also depart from the letter of the POSIX.2 specification
  478. when they support long-named command-line options, and intermixing
  479. options with ordinary arguments. This minor incompatibility with
  480. POSIX is never a problem in practice, and it is very useful.
  481. In particular, don't reject a new feature, or remove an old one,
  482. merely because a standard says it is ``forbidden'' or ``deprecated''.
  483. @node Semantics
  484. @section Writing Robust Programs
  485. @cindex arbitrary limits on data
  486. Avoid arbitrary limits on the length or number of @emph{any} data
  487. structure, including file names, lines, files, and symbols, by allocating
  488. all data structures dynamically. In most Unix utilities, ``long lines
  489. are silently truncated''. This is not acceptable in a GNU utility.
  490. @cindex @code{NUL} characters
  491. @findex libiconv
  492. Utilities reading files should not drop NUL characters, or any other
  493. nonprinting characters @emph{including those with codes above 0177}.
  494. The only sensible exceptions would be utilities specifically intended
  495. for interface to certain types of terminals or printers that can't
  496. handle those characters. Whenever possible, try to make programs work
  497. properly with sequences of bytes that represent multibyte characters;
  498. UTF-8 is the most important.
  499. @cindex error messages
  500. Check every system call for an error return, unless you know you wish
  501. to ignore errors. Include the system error text (from @code{perror},
  502. @code{strerror}, or equivalent) in @emph{every} error message
  503. resulting from a failing system call, as well as the name of the file
  504. if any and the name of the utility. Just ``cannot open foo.c'' or
  505. ``stat failed'' is not sufficient.
  506. @cindex @code{malloc} return value
  507. @cindex memory allocation failure
  508. Check every call to @code{malloc} or @code{realloc} to see if it
  509. returned zero. Check @code{realloc} even if you are making the block
  510. smaller; in a system that rounds block sizes to a power of 2,
  511. @code{realloc} may get a different block if you ask for less space.
  512. In Unix, @code{realloc} can destroy the storage block if it returns
  513. zero. GNU @code{realloc} does not have this bug: if it fails, the
  514. original block is unchanged. Feel free to assume the bug is fixed. If
  515. you wish to run your program on Unix, and wish to avoid lossage in this
  516. case, you can use the GNU @code{malloc}.
  517. You must expect @code{free} to alter the contents of the block that was
  518. freed. Anything you want to fetch from the block, you must fetch before
  519. calling @code{free}.
  520. If @code{malloc} fails in a noninteractive program, make that a fatal
  521. error. In an interactive program (one that reads commands from the
  522. user), it is better to abort the command and return to the command
  523. reader loop. This allows the user to kill other processes to free up
  524. virtual memory, and then try the command again.
  525. @cindex command-line arguments, decoding
  526. Use @code{getopt_long} to decode arguments, unless the argument syntax
  527. makes this unreasonable.
  528. When static storage is to be written in during program execution, use
  529. explicit C code to initialize it. Reserve C initialized declarations
  530. for data that will not be changed.
  531. @c ADR: why?
  532. Try to avoid low-level interfaces to obscure Unix data structures (such
  533. as file directories, utmp, or the layout of kernel memory), since these
  534. are less likely to work compatibly. If you need to find all the files
  535. in a directory, use @code{readdir} or some other high-level interface.
  536. These are supported compatibly by GNU.
  537. @cindex signal handling
  538. The preferred signal handling facilities are the BSD variant of
  539. @code{signal}, and the @sc{posix} @code{sigaction} function; the
  540. alternative USG @code{signal} interface is an inferior design.
  541. Nowadays, using the @sc{posix} signal functions may be the easiest way
  542. to make a program portable. If you use @code{signal}, then on GNU/Linux
  543. systems running GNU libc version 1, you should include
  544. @file{bsd/signal.h} instead of @file{signal.h}, so as to get BSD
  545. behavior. It is up to you whether to support systems where
  546. @code{signal} has only the USG behavior, or give up on them.
  547. @cindex impossible conditions
  548. In error checks that detect ``impossible'' conditions, just abort.
  549. There is usually no point in printing any message. These checks
  550. indicate the existence of bugs. Whoever wants to fix the bugs will have
  551. to read the source code and run a debugger. So explain the problem with
  552. comments in the source. The relevant data will be in variables, which
  553. are easy to examine with the debugger, so there is no point moving them
  554. elsewhere.
  555. Do not use a count of errors as the exit status for a program.
  556. @emph{That does not work}, because exit status values are limited to 8
  557. bits (0 through 255). A single run of the program might have 256
  558. errors; if you try to return 256 as the exit status, the parent process
  559. will see 0 as the status, and it will appear that the program succeeded.
  560. @cindex temporary files
  561. @cindex @code{TMPDIR} environment variable
  562. If you make temporary files, check the @code{TMPDIR} environment
  563. variable; if that variable is defined, use the specified directory
  564. instead of @file{/tmp}.
  565. In addition, be aware that there is a possible security problem when
  566. creating temporary files in world-writable directories. In C, you can
  567. avoid this problem by creating temporary files in this manner:
  568. @example
  569. fd = open (filename, O_WRONLY | O_CREAT | O_EXCL, 0600);
  570. @end example
  571. @noindent
  572. or by using the @code{mkstemps} function from Gnulib
  573. (@pxref{mkstemps,,, gnulib, Gnulib}).
  574. In bash, use @code{set -C} (long name @code{noclobber}) to avoid this
  575. problem. In addition, the @code{mktemp} utility is a more general
  576. solution for creating temporary files from shell scripts
  577. (@pxref{mktemp invocation,,, coreutils, GNU Coreutils}).
  578. @node Libraries
  579. @section Library Behavior
  580. @cindex libraries
  581. Try to make library functions reentrant. If they need to do dynamic
  582. storage allocation, at least try to avoid any nonreentrancy aside from
  583. that of @code{malloc} itself.
  584. Here are certain name conventions for libraries, to avoid name
  585. conflicts.
  586. Choose a name prefix for the library, more than two characters long.
  587. All external function and variable names should start with this
  588. prefix. In addition, there should only be one of these in any given
  589. library member. This usually means putting each one in a separate
  590. source file.
  591. An exception can be made when two external symbols are always used
  592. together, so that no reasonable program could use one without the
  593. other; then they can both go in the same file.
  594. External symbols that are not documented entry points for the user
  595. should have names beginning with @samp{_}. The @samp{_} should be
  596. followed by the chosen name prefix for the library, to prevent
  597. collisions with other libraries. These can go in the same files with
  598. user entry points if you like.
  599. Static functions and variables can be used as you like and need not
  600. fit any naming convention.
  601. @node Errors
  602. @section Formatting Error Messages
  603. @cindex formatting error messages
  604. @cindex error messages, formatting
  605. Error messages from compilers should look like this:
  606. @example
  607. @var{sourcefile}:@var{lineno}: @var{message}
  608. @end example
  609. @noindent
  610. If you want to mention the column number, use one of these formats:
  611. @example
  612. @var{sourcefile}:@var{lineno}:@var{column}: @var{message}
  613. @var{sourcefile}:@var{lineno}.@var{column}: @var{message}
  614. @end example
  615. @noindent
  616. Line numbers should start from 1 at the beginning of the file, and
  617. column numbers should start from 1 at the beginning of the line.
  618. (Both of these conventions are chosen for compatibility.) Calculate
  619. column numbers assuming that space and all ASCII printing characters
  620. have equal width, and assuming tab stops every 8 columns. For
  621. non-ASCII characters, Unicode character widths should be used when in
  622. a UTF-8 locale; GNU libc and GNU gnulib provide suitable
  623. @code{wcwidth} functions.
  624. The error message can also give both the starting and ending positions
  625. of the erroneous text. There are several formats so that you can
  626. avoid redundant information such as a duplicate line number.
  627. Here are the possible formats:
  628. @example
  629. @var{sourcefile}:@var{line1}.@var{column1}-@var{line2}.@var{column2}: @var{message}
  630. @var{sourcefile}:@var{line1}.@var{column1}-@var{column2}: @var{message}
  631. @var{sourcefile}:@var{line1}-@var{line2}: @var{message}
  632. @end example
  633. @noindent
  634. When an error is spread over several files, you can use this format:
  635. @example
  636. @var{file1}:@var{line1}.@var{column1}-@var{file2}:@var{line2}.@var{column2}: @var{message}
  637. @end example
  638. Error messages from other noninteractive programs should look like this:
  639. @example
  640. @var{program}:@var{sourcefile}:@var{lineno}: @var{message}
  641. @end example
  642. @noindent
  643. when there is an appropriate source file, or like this:
  644. @example
  645. @var{program}: @var{message}
  646. @end example
  647. @noindent
  648. when there is no relevant source file.
  649. If you want to mention the column number, use this format:
  650. @example
  651. @var{program}:@var{sourcefile}:@var{lineno}:@var{column}: @var{message}
  652. @end example
  653. In an interactive program (one that is reading commands from a
  654. terminal), it is better not to include the program name in an error
  655. message. The place to indicate which program is running is in the
  656. prompt or with the screen layout. (When the same program runs with
  657. input from a source other than a terminal, it is not interactive and
  658. would do best to print error messages using the noninteractive style.)
  659. The string @var{message} should not begin with a capital letter when
  660. it follows a program name and/or file name, because that isn't the
  661. beginning of a sentence. (The sentence conceptually starts at the
  662. beginning of the line.) Also, it should not end with a period.
  663. Error messages from interactive programs, and other messages such as
  664. usage messages, should start with a capital letter. But they should not
  665. end with a period.
  666. @node User Interfaces
  667. @section Standards for Interfaces Generally
  668. @cindex program name and its behavior
  669. @cindex behavior, dependent on program's name
  670. Please don't make the behavior of a utility depend on the name used
  671. to invoke it. It is useful sometimes to make a link to a utility
  672. with a different name, and that should not change what it does.
  673. Instead, use a run time option or a compilation switch or both
  674. to select among the alternate behaviors.
  675. @cindex output device and program's behavior
  676. Likewise, please don't make the behavior of the program depend on the
  677. type of output device it is used with. Device independence is an
  678. important principle of the system's design; do not compromise it merely
  679. to save someone from typing an option now and then. (Variation in error
  680. message syntax when using a terminal is ok, because that is a side issue
  681. that people do not depend on.)
  682. If you think one behavior is most useful when the output is to a
  683. terminal, and another is most useful when the output is a file or a
  684. pipe, then it is usually best to make the default behavior the one that
  685. is useful with output to a terminal, and have an option for the other
  686. behavior.
  687. Compatibility requires certain programs to depend on the type of output
  688. device. It would be disastrous if @code{ls} or @code{sh} did not do so
  689. in the way all users expect. In some of these cases, we supplement the
  690. program with a preferred alternate version that does not depend on the
  691. output device type. For example, we provide a @code{dir} program much
  692. like @code{ls} except that its default output format is always
  693. multi-column format.
  694. @node Graphical Interfaces
  695. @section Standards for Graphical Interfaces
  696. @cindex graphical user interface
  697. @cindex interface styles
  698. @cindex user interface styles
  699. @cindex GTK+
  700. When you write a program that provides a graphical user interface,
  701. please make it work with the X Window System and the GTK+ toolkit
  702. unless the functionality specifically requires some alternative (for
  703. example, ``displaying jpeg images while in console mode'').
  704. In addition, please provide a command-line interface to control the
  705. functionality. (In many cases, the graphical user interface can be a
  706. separate program which invokes the command-line program.) This is
  707. so that the same jobs can be done from scripts.
  708. @cindex CORBA
  709. @cindex GNOME
  710. @cindex D-bus
  711. @cindex keyboard interface
  712. @cindex library interface
  713. Please also consider providing a D-bus interface for use from other
  714. running programs, such as within GNOME. (GNOME used to use CORBA
  715. for this, but that is being phased out.) In addition, consider
  716. providing a library interface (for use from C), and perhaps a
  717. keyboard-driven console interface (for use by users from console
  718. mode). Once you are doing the work to provide the functionality and
  719. the graphical interface, these won't be much extra work.
  720. @node Command-Line Interfaces
  721. @section Standards for Command Line Interfaces
  722. @cindex command-line interface
  723. @findex getopt
  724. It is a good idea to follow the @sc{posix} guidelines for the
  725. command-line options of a program. The easiest way to do this is to use
  726. @code{getopt} to parse them. Note that the GNU version of @code{getopt}
  727. will normally permit options anywhere among the arguments unless the
  728. special argument @samp{--} is used. This is not what @sc{posix}
  729. specifies; it is a GNU extension.
  730. @cindex long-named options
  731. Please define long-named options that are equivalent to the
  732. single-letter Unix-style options. We hope to make GNU more user
  733. friendly this way. This is easy to do with the GNU function
  734. @code{getopt_long}.
  735. One of the advantages of long-named options is that they can be
  736. consistent from program to program. For example, users should be able
  737. to expect the ``verbose'' option of any GNU program which has one, to be
  738. spelled precisely @samp{--verbose}. To achieve this uniformity, look at
  739. the table of common long-option names when you choose the option names
  740. for your program (@pxref{Option Table}).
  741. It is usually a good idea for file names given as ordinary arguments to
  742. be input files only; any output files would be specified using options
  743. (preferably @samp{-o} or @samp{--output}). Even if you allow an output
  744. file name as an ordinary argument for compatibility, try to provide an
  745. option as another way to specify it. This will lead to more consistency
  746. among GNU utilities, and fewer idiosyncrasies for users to remember.
  747. @cindex standard command-line options
  748. @cindex options, standard command-line
  749. @cindex CGI programs, standard options for
  750. @cindex PATH_INFO, specifying standard options as
  751. All programs should support two standard options: @samp{--version}
  752. and @samp{--help}. CGI programs should accept these as command-line
  753. options, and also if given as the @env{PATH_INFO}; for instance,
  754. visiting @url{http://example.org/p.cgi/--help} in a browser should
  755. output the same information as invoking @samp{p.cgi --help} from the
  756. command line.
  757. @menu
  758. * --version:: The standard output for --version.
  759. * --help:: The standard output for --help.
  760. @end menu
  761. @node --version
  762. @subsection @option{--version}
  763. @cindex @samp{--version} output
  764. The standard @code{--version} option should direct the program to
  765. print information about its name, version, origin and legal status,
  766. all on standard output, and then exit successfully. Other options and
  767. arguments should be ignored once this is seen, and the program should
  768. not perform its normal function.
  769. @cindex canonical name of a program
  770. @cindex program's canonical name
  771. The first line is meant to be easy for a program to parse; the version
  772. number proper starts after the last space. In addition, it contains
  773. the canonical name for this program, in this format:
  774. @example
  775. GNU Emacs 19.30
  776. @end example
  777. @noindent
  778. The program's name should be a constant string; @emph{don't} compute it
  779. from @code{argv[0]}. The idea is to state the standard or canonical
  780. name for the program, not its file name. There are other ways to find
  781. out the precise file name where a command is found in @code{PATH}.
  782. If the program is a subsidiary part of a larger package, mention the
  783. package name in parentheses, like this:
  784. @example
  785. emacsserver (GNU Emacs) 19.30
  786. @end example
  787. @noindent
  788. If the package has a version number which is different from this
  789. program's version number, you can mention the package version number
  790. just before the close-parenthesis.
  791. If you @emph{need} to mention the version numbers of libraries which
  792. are distributed separately from the package which contains this program,
  793. you can do so by printing an additional line of version info for each
  794. library you want to mention. Use the same format for these lines as for
  795. the first line.
  796. Please do not mention all of the libraries that the program uses ``just
  797. for completeness''---that would produce a lot of unhelpful clutter.
  798. Please mention library version numbers only if you find in practice that
  799. they are very important to you in debugging.
  800. The following line, after the version number line or lines, should be a
  801. copyright notice. If more than one copyright notice is called for, put
  802. each on a separate line.
  803. Next should follow a line stating the license, preferably using one of
  804. abbreviations below, and a brief statement that the program is free
  805. software, and that users are free to copy and change it. Also mention
  806. that there is no warranty, to the extent permitted by law. See
  807. recommended wording below.
  808. It is ok to finish the output with a list of the major authors of the
  809. program, as a way of giving credit.
  810. Here's an example of output that follows these rules:
  811. @smallexample
  812. GNU hello 2.3
  813. Copyright (C) 2007 Free Software Foundation, Inc.
  814. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
  815. This is free software: you are free to change and redistribute it.
  816. There is NO WARRANTY, to the extent permitted by law.
  817. @end smallexample
  818. You should adapt this to your program, of course, filling in the proper
  819. year, copyright holder, name of program, and the references to
  820. distribution terms, and changing the rest of the wording as necessary.
  821. This copyright notice only needs to mention the most recent year in
  822. which changes were made---there's no need to list the years for previous
  823. versions' changes. You don't have to mention the name of the program in
  824. these notices, if that is inconvenient, since it appeared in the first
  825. line. (The rules are different for copyright notices in source files;
  826. @pxref{Copyright Notices,,,maintain,Information for GNU Maintainers}.)
  827. Translations of the above lines must preserve the validity of the
  828. copyright notices (@pxref{Internationalization}). If the translation's
  829. character set supports it, the @samp{(C)} should be replaced with the
  830. copyright symbol, as follows:
  831. @ifinfo
  832. (the official copyright symbol, which is the letter C in a circle);
  833. @end ifinfo
  834. @ifnotinfo
  835. @copyright{}
  836. @end ifnotinfo
  837. Write the word ``Copyright'' exactly like that, in English. Do not
  838. translate it into another language. International treaties recognize
  839. the English word ``Copyright''; translations into other languages do not
  840. have legal significance.
  841. Finally, here is the table of our suggested license abbreviations.
  842. Any abbreviation can be followed by @samp{v@var{version}[+]}, meaning
  843. that particular version, or later versions with the @samp{+}, as shown
  844. above.
  845. In the case of exceptions for extra permissions with the GPL, we use
  846. @samp{/} for a separator; the version number can follow the license
  847. abbreviation as usual, as in the examples below.
  848. @table @asis
  849. @item GPL
  850. GNU General Public License, @url{http://www.gnu.org/@/licenses/@/gpl.html}.
  851. @item LGPL
  852. GNU Lesser General Public License, @url{http://www.gnu.org/@/licenses/@/lgpl.html}.
  853. @item GPL/Ada
  854. GNU GPL with the exception for Ada.
  855. @item Apache
  856. The Apache Software Foundation license,
  857. @url{http://www.apache.org/@/licenses}.
  858. @item Artistic
  859. The Artistic license used for Perl, @url{http://www.perlfoundation.org/@/legal}.
  860. @item Expat
  861. The Expat license, @url{http://www.jclark.com/@/xml/@/copying.txt}.
  862. @item MPL
  863. The Mozilla Public License, @url{http://www.mozilla.org/@/MPL/}.
  864. @item OBSD
  865. The original (4-clause) BSD license, incompatible with the GNU GPL
  866. @url{http://www.xfree86.org/@/3.3.6/@/COPYRIGHT2.html#6}.
  867. @item PHP
  868. The license used for PHP, @url{http://www.php.net/@/license/}.
  869. @item public domain
  870. The non-license that is being in the public domain,
  871. @url{http://www.gnu.org/@/licenses/@/license-list.html#PublicDomain}.
  872. @item Python
  873. The license for Python, @url{http://www.python.org/@/2.0.1/@/license.html}.
  874. @item RBSD
  875. The revised (3-clause) BSD, compatible with the GNU GPL,@*
  876. @url{http://www.xfree86.org/@/3.3.6/@/COPYRIGHT2.html#5}.
  877. @item X11
  878. The simple non-copyleft license used for most versions of the X Window
  879. System, @url{http://www.xfree86.org/@/3.3.6/@/COPYRIGHT2.html#3}.
  880. @item Zlib
  881. The license for Zlib, @url{http://www.gzip.org/@/zlib/@/zlib_license.html}.
  882. @end table
  883. More information about these licenses and many more are on the GNU
  884. licensing web pages,
  885. @url{http://www.gnu.org/@/licenses/@/license-list.html}.
  886. @node --help
  887. @subsection @option{--help}
  888. @cindex @samp{--help} output
  889. The standard @code{--help} option should output brief documentation
  890. for how to invoke the program, on standard output, then exit
  891. successfully. Other options and arguments should be ignored once this
  892. is seen, and the program should not perform its normal function.
  893. @cindex address for bug reports
  894. @cindex bug reports
  895. Near the end of the @samp{--help} option's output, please place lines
  896. giving the email address for bug reports, the package's home page
  897. (normally @indicateurl{http://www.gnu.org/software/@var{pkg}}, and the
  898. general page for help using GNU programs. The format should be like this:
  899. @example
  900. Report bugs to: @var{mailing-address}
  901. @var{pkg} home page: <http://www.gnu.org/software/@var{pkg}/>
  902. General help using GNU software: <http://www.gnu.org/gethelp/>
  903. @end example
  904. It is ok to mention other appropriate mailing lists and web pages.
  905. @node Dynamic Plug-In Interfaces
  906. @section Standards for Dynamic Plug-in Interfaces
  907. @cindex plug-ins
  908. @cindex dynamic plug-ins
  909. Another aspect of keeping free programs free is encouraging
  910. development of free plug-ins, and discouraging development of
  911. proprietary plug-ins. Many GNU programs will not have anything like
  912. plug-ins at all, but those that do should follow these
  913. practices.
  914. First, the general plug-in architecture design should closely tie the
  915. plug-in to the original code, such that the plug-in and the base
  916. program are parts of one extended program. For GCC, for example,
  917. plug-ins receive and modify GCC's internal data structures, and so
  918. clearly form an extended program with the base GCC.
  919. @vindex plugin_is_GPL_compatible
  920. Second, you should require plug-in developers to affirm that their
  921. plug-ins are released under an appropriate license. This should be
  922. enforced with a simple programmatic check. For GCC, again for
  923. example, a plug-in must define the global symbol
  924. @code{plugin_is_GPL_compatible}, thus asserting that the plug-in is
  925. released under a GPL-compatible license (@pxref{Plugins,, Plugins,
  926. gccint, GCC Internals}).
  927. By adding this check to your program you are not creating a new legal
  928. requirement. The GPL itself requires plug-ins to be free software,
  929. licensed compatibly. As long as you have followed the first rule above
  930. to keep plug-ins closely tied to your original program, the GPL and AGPL
  931. already require those plug-ins to be released under a compatible
  932. license. The symbol definition in the plug-in---or whatever equivalent
  933. works best in your program---makes it harder for anyone who might
  934. distribute proprietary plug-ins to legally defend themselves. If a case
  935. about this got to court, we can point to that symbol as evidence that
  936. the plug-in developer understood that the license had this requirement.
  937. @node Option Table
  938. @section Table of Long Options
  939. @cindex long option names
  940. @cindex table of long options
  941. Here is a table of long options used by GNU programs. It is surely
  942. incomplete, but we aim to list all the options that a new program might
  943. want to be compatible with. If you use names not already in the table,
  944. please send @email{bug-standards@@gnu.org} a list of them, with their
  945. meanings, so we can update the table.
  946. @c Please leave newlines between items in this table; it's much easier
  947. @c to update when it isn't completely squashed together and unreadable.
  948. @c When there is more than one short option for a long option name, put
  949. @c a semicolon between the lists of the programs that use them, not a
  950. @c period. --friedman
  951. @table @samp
  952. @item after-date
  953. @samp{-N} in @code{tar}.
  954. @item all
  955. @samp{-a} in @code{du}, @code{ls}, @code{nm}, @code{stty}, @code{uname},
  956. and @code{unexpand}.
  957. @item all-text
  958. @samp{-a} in @code{diff}.
  959. @item almost-all
  960. @samp{-A} in @code{ls}.
  961. @item append
  962. @samp{-a} in @code{etags}, @code{tee}, @code{time};
  963. @samp{-r} in @code{tar}.
  964. @item archive
  965. @samp{-a} in @code{cp}.
  966. @item archive-name
  967. @samp{-n} in @code{shar}.
  968. @item arglength
  969. @samp{-l} in @code{m4}.
  970. @item ascii
  971. @samp{-a} in @code{diff}.
  972. @item assign
  973. @samp{-v} in @code{gawk}.
  974. @item assume-new
  975. @samp{-W} in @code{make}.
  976. @item assume-old
  977. @samp{-o} in @code{make}.
  978. @item auto-check
  979. @samp{-a} in @code{recode}.
  980. @item auto-pager
  981. @samp{-a} in @code{wdiff}.
  982. @item auto-reference
  983. @samp{-A} in @code{ptx}.
  984. @item avoid-wraps
  985. @samp{-n} in @code{wdiff}.
  986. @item background
  987. For server programs, run in the background.
  988. @item backward-search
  989. @samp{-B} in @code{ctags}.
  990. @item basename
  991. @samp{-f} in @code{shar}.
  992. @item batch
  993. Used in GDB.
  994. @item baud
  995. Used in GDB.
  996. @item before
  997. @samp{-b} in @code{tac}.
  998. @item binary
  999. @samp{-b} in @code{cpio} and @code{diff}.
  1000. @item bits-per-code
  1001. @samp{-b} in @code{shar}.
  1002. @item block-size
  1003. Used in @code{cpio} and @code{tar}.
  1004. @item blocks
  1005. @samp{-b} in @code{head} and @code{tail}.
  1006. @item break-file
  1007. @samp{-b} in @code{ptx}.
  1008. @item brief
  1009. Used in various programs to make output shorter.
  1010. @item bytes
  1011. @samp{-c} in @code{head}, @code{split}, and @code{tail}.
  1012. @item c@t{++}
  1013. @samp{-C} in @code{etags}.
  1014. @item catenate
  1015. @samp{-A} in @code{tar}.
  1016. @item cd
  1017. Used in various programs to specify the directory to use.
  1018. @item changes
  1019. @samp{-c} in @code{chgrp} and @code{chown}.
  1020. @item classify
  1021. @samp{-F} in @code{ls}.
  1022. @item colons
  1023. @samp{-c} in @code{recode}.
  1024. @item command
  1025. @samp{-c} in @code{su};
  1026. @samp{-x} in GDB.
  1027. @item compare
  1028. @samp{-d} in @code{tar}.
  1029. @item compat
  1030. Used in @code{gawk}.
  1031. @item compress
  1032. @samp{-Z} in @code{tar} and @code{shar}.
  1033. @item concatenate
  1034. @samp{-A} in @code{tar}.
  1035. @item confirmation
  1036. @samp{-w} in @code{tar}.
  1037. @item context
  1038. Used in @code{diff}.
  1039. @item copyleft
  1040. @samp{-W copyleft} in @code{gawk}.
  1041. @item copyright
  1042. @samp{-C} in @code{ptx}, @code{recode}, and @code{wdiff};
  1043. @samp{-W copyright} in @code{gawk}.
  1044. @item core
  1045. Used in GDB.
  1046. @item count
  1047. @samp{-q} in @code{who}.
  1048. @item count-links
  1049. @samp{-l} in @code{du}.
  1050. @item create
  1051. Used in @code{tar} and @code{cpio}.
  1052. @item cut-mark
  1053. @samp{-c} in @code{shar}.
  1054. @item cxref
  1055. @samp{-x} in @code{ctags}.
  1056. @item date
  1057. @samp{-d} in @code{touch}.
  1058. @item debug
  1059. @samp{-d} in @code{make} and @code{m4};
  1060. @samp{-t} in Bison.
  1061. @item define
  1062. @samp{-D} in @code{m4}.
  1063. @item defines
  1064. @samp{-d} in Bison and @code{ctags}.
  1065. @item delete
  1066. @samp{-D} in @code{tar}.
  1067. @item dereference
  1068. @samp{-L} in @code{chgrp}, @code{chown}, @code{cpio}, @code{du},
  1069. @code{ls}, and @code{tar}.
  1070. @item dereference-args
  1071. @samp{-D} in @code{du}.
  1072. @item device
  1073. Specify an I/O device (special file name).
  1074. @item diacritics
  1075. @samp{-d} in @code{recode}.
  1076. @item dictionary-order
  1077. @samp{-d} in @code{look}.
  1078. @item diff
  1079. @samp{-d} in @code{tar}.
  1080. @item digits
  1081. @samp{-n} in @code{csplit}.
  1082. @item directory
  1083. Specify the directory to use, in various programs. In @code{ls}, it
  1084. means to show directories themselves rather than their contents. In
  1085. @code{rm} and @code{ln}, it means to not treat links to directories
  1086. specially.
  1087. @item discard-all
  1088. @samp{-x} in @code{strip}.
  1089. @item discard-locals
  1090. @samp{-X} in @code{strip}.
  1091. @item dry-run
  1092. @samp{-n} in @code{make}.
  1093. @item ed
  1094. @samp{-e} in @code{diff}.
  1095. @item elide-empty-files
  1096. @samp{-z} in @code{csplit}.
  1097. @item end-delete
  1098. @samp{-x} in @code{wdiff}.
  1099. @item end-insert
  1100. @samp{-z} in @code{wdiff}.
  1101. @item entire-new-file
  1102. @samp{-N} in @code{diff}.
  1103. @item environment-overrides
  1104. @samp{-e} in @code{make}.
  1105. @item eof
  1106. @samp{-e} in @code{xargs}.
  1107. @item epoch
  1108. Used in GDB.
  1109. @item error-limit
  1110. Used in @code{makeinfo}.
  1111. @item error-output
  1112. @samp{-o} in @code{m4}.
  1113. @item escape
  1114. @samp{-b} in @code{ls}.
  1115. @item exclude-from
  1116. @samp{-X} in @code{tar}.
  1117. @item exec
  1118. Used in GDB.
  1119. @item exit
  1120. @samp{-x} in @code{xargs}.
  1121. @item exit-0
  1122. @samp{-e} in @code{unshar}.
  1123. @item expand-tabs
  1124. @samp{-t} in @code{diff}.
  1125. @item expression
  1126. @samp{-e} in @code{sed}.
  1127. @item extern-only
  1128. @samp{-g} in @code{nm}.
  1129. @item extract
  1130. @samp{-i} in @code{cpio};
  1131. @samp{-x} in @code{tar}.
  1132. @item faces
  1133. @samp{-f} in @code{finger}.
  1134. @item fast
  1135. @samp{-f} in @code{su}.
  1136. @item fatal-warnings
  1137. @samp{-E} in @code{m4}.
  1138. @item file
  1139. @samp{-f} in @code{gawk}, @code{info}, @code{make}, @code{mt},
  1140. @code{sed}, and @code{tar}.
  1141. @item field-separator
  1142. @samp{-F} in @code{gawk}.
  1143. @item file-prefix
  1144. @samp{-b} in Bison.
  1145. @item file-type
  1146. @samp{-F} in @code{ls}.
  1147. @item files-from
  1148. @samp{-T} in @code{tar}.
  1149. @item fill-column
  1150. Used in @code{makeinfo}.
  1151. @item flag-truncation
  1152. @samp{-F} in @code{ptx}.
  1153. @item fixed-output-files
  1154. @samp{-y} in Bison.
  1155. @item follow
  1156. @samp{-f} in @code{tail}.
  1157. @item footnote-style
  1158. Used in @code{makeinfo}.
  1159. @item force
  1160. @samp{-f} in @code{cp}, @code{ln}, @code{mv}, and @code{rm}.
  1161. @item force-prefix
  1162. @samp{-F} in @code{shar}.
  1163. @item foreground
  1164. For server programs, run in the foreground;
  1165. in other words, don't do anything special to run the server
  1166. in the background.
  1167. @item format
  1168. Used in @code{ls}, @code{time}, and @code{ptx}.
  1169. @item freeze-state
  1170. @samp{-F} in @code{m4}.
  1171. @item fullname
  1172. Used in GDB.
  1173. @item gap-size
  1174. @samp{-g} in @code{ptx}.
  1175. @item get
  1176. @samp{-x} in @code{tar}.
  1177. @item graphic
  1178. @samp{-i} in @code{ul}.
  1179. @item graphics
  1180. @samp{-g} in @code{recode}.
  1181. @item group
  1182. @samp{-g} in @code{install}.
  1183. @item gzip
  1184. @samp{-z} in @code{tar} and @code{shar}.
  1185. @item hashsize
  1186. @samp{-H} in @code{m4}.
  1187. @item header
  1188. @samp{-h} in @code{objdump} and @code{recode}
  1189. @item heading
  1190. @samp{-H} in @code{who}.
  1191. @item help
  1192. Used to ask for brief usage information.
  1193. @item here-delimiter
  1194. @samp{-d} in @code{shar}.
  1195. @item hide-control-chars
  1196. @samp{-q} in @code{ls}.
  1197. @item html
  1198. In @code{makeinfo}, output HTML.
  1199. @item idle
  1200. @samp{-u} in @code{who}.
  1201. @item ifdef
  1202. @samp{-D} in @code{diff}.
  1203. @item ignore
  1204. @samp{-I} in @code{ls};
  1205. @samp{-x} in @code{recode}.
  1206. @item ignore-all-space
  1207. @samp{-w} in @code{diff}.
  1208. @item ignore-backups
  1209. @samp{-B} in @code{ls}.
  1210. @item ignore-blank-lines
  1211. @samp{-B} in @code{diff}.
  1212. @item ignore-case
  1213. @samp{-f} in @code{look} and @code{ptx};
  1214. @samp{-i} in @code{diff} and @code{wdiff}.
  1215. @item ignore-errors
  1216. @samp{-i} in @code{make}.
  1217. @item ignore-file
  1218. @samp{-i} in @code{ptx}.
  1219. @item ignore-indentation
  1220. @samp{-I} in @code{etags}.
  1221. @item ignore-init-file
  1222. @samp{-f} in Oleo.
  1223. @item ignore-interrupts
  1224. @samp{-i} in @code{tee}.
  1225. @item ignore-matching-lines
  1226. @samp{-I} in @code{diff}.
  1227. @item ignore-space-change
  1228. @samp{-b} in @code{diff}.
  1229. @item ignore-zeros
  1230. @samp{-i} in @code{tar}.
  1231. @item include
  1232. @samp{-i} in @code{etags};
  1233. @samp{-I} in @code{m4}.
  1234. @item include-dir
  1235. @samp{-I} in @code{make}.
  1236. @item incremental
  1237. @samp{-G} in @code{tar}.
  1238. @item info
  1239. @samp{-i}, @samp{-l}, and @samp{-m} in Finger.
  1240. @item init-file
  1241. In some programs, specify the name of the file to read as the user's
  1242. init file.
  1243. @item initial
  1244. @samp{-i} in @code{expand}.
  1245. @item initial-tab
  1246. @samp{-T} in @code{diff}.
  1247. @item inode
  1248. @samp{-i} in @code{ls}.
  1249. @item interactive
  1250. @samp{-i} in @code{cp}, @code{ln}, @code{mv}, @code{rm};
  1251. @samp{-e} in @code{m4};
  1252. @samp{-p} in @code{xargs};
  1253. @samp{-w} in @code{tar}.
  1254. @item intermix-type
  1255. @samp{-p} in @code{shar}.
  1256. @item iso-8601
  1257. Used in @code{date}
  1258. @item jobs
  1259. @samp{-j} in @code{make}.
  1260. @item just-print
  1261. @samp{-n} in @code{make}.
  1262. @item keep-going
  1263. @samp{-k} in @code{make}.
  1264. @item keep-files
  1265. @samp{-k} in @code{csplit}.
  1266. @item kilobytes
  1267. @samp{-k} in @code{du} and @code{ls}.
  1268. @item language
  1269. @samp{-l} in @code{etags}.
  1270. @item less-mode
  1271. @samp{-l} in @code{wdiff}.
  1272. @item level-for-gzip
  1273. @samp{-g} in @code{shar}.
  1274. @item line-bytes
  1275. @samp{-C} in @code{split}.
  1276. @item lines
  1277. Used in @code{split}, @code{head}, and @code{tail}.
  1278. @item link
  1279. @samp{-l} in @code{cpio}.
  1280. @item lint
  1281. @itemx lint-old
  1282. Used in @code{gawk}.
  1283. @item list
  1284. @samp{-t} in @code{cpio};
  1285. @samp{-l} in @code{recode}.
  1286. @item list
  1287. @samp{-t} in @code{tar}.
  1288. @item literal
  1289. @samp{-N} in @code{ls}.
  1290. @item load-average
  1291. @samp{-l} in @code{make}.
  1292. @item login
  1293. Used in @code{su}.
  1294. @item machine
  1295. Used in @code{uname}.
  1296. @item macro-name
  1297. @samp{-M} in @code{ptx}.
  1298. @item mail
  1299. @samp{-m} in @code{hello} and @code{uname}.
  1300. @item make-directories
  1301. @samp{-d} in @code{cpio}.
  1302. @item makefile
  1303. @samp{-f} in @code{make}.
  1304. @item mapped
  1305. Used in GDB.
  1306. @item max-args
  1307. @samp{-n} in @code{xargs}.
  1308. @item max-chars
  1309. @samp{-n} in @code{xargs}.
  1310. @item max-lines
  1311. @samp{-l} in @code{xargs}.
  1312. @item max-load
  1313. @samp{-l} in @code{make}.
  1314. @item max-procs
  1315. @samp{-P} in @code{xargs}.
  1316. @item mesg
  1317. @samp{-T} in @code{who}.
  1318. @item message
  1319. @samp{-T} in @code{who}.
  1320. @item minimal
  1321. @samp{-d} in @code{diff}.
  1322. @item mixed-uuencode
  1323. @samp{-M} in @code{shar}.
  1324. @item mode
  1325. @samp{-m} in @code{install}, @code{mkdir}, and @code{mkfifo}.
  1326. @item modification-time
  1327. @samp{-m} in @code{tar}.
  1328. @item multi-volume
  1329. @samp{-M} in @code{tar}.
  1330. @item name-prefix
  1331. @samp{-a} in Bison.
  1332. @item nesting-limit
  1333. @samp{-L} in @code{m4}.
  1334. @item net-headers
  1335. @samp{-a} in @code{shar}.
  1336. @item new-file
  1337. @samp{-W} in @code{make}.
  1338. @item no-builtin-rules
  1339. @samp{-r} in @code{make}.
  1340. @item no-character-count
  1341. @samp{-w} in @code{shar}.
  1342. @item no-check-existing
  1343. @samp{-x} in @code{shar}.
  1344. @item no-common
  1345. @samp{-3} in @code{wdiff}.
  1346. @item no-create
  1347. @samp{-c} in @code{touch}.
  1348. @item no-defines
  1349. @samp{-D} in @code{etags}.
  1350. @item no-deleted
  1351. @samp{-1} in @code{wdiff}.
  1352. @item no-dereference
  1353. @samp{-d} in @code{cp}.
  1354. @item no-inserted
  1355. @samp{-2} in @code{wdiff}.
  1356. @item no-keep-going
  1357. @samp{-S} in @code{make}.
  1358. @item no-lines
  1359. @samp{-l} in Bison.
  1360. @item no-piping
  1361. @samp{-P} in @code{shar}.
  1362. @item no-prof
  1363. @samp{-e} in @code{gprof}.
  1364. @item no-regex
  1365. @samp{-R} in @code{etags}.
  1366. @item no-sort
  1367. @samp{-p} in @code{nm}.
  1368. @item no-splash
  1369. Don't print a startup splash screen.
  1370. @item no-split
  1371. Used in @code{makeinfo}.
  1372. @item no-static
  1373. @samp{-a} in @code{gprof}.
  1374. @item no-time
  1375. @samp{-E} in @code{gprof}.
  1376. @item no-timestamp
  1377. @samp{-m} in @code{shar}.
  1378. @item no-validate
  1379. Used in @code{makeinfo}.
  1380. @item no-wait
  1381. Used in @code{emacsclient}.
  1382. @item no-warn
  1383. Used in various programs to inhibit warnings.
  1384. @item node
  1385. @samp{-n} in @code{info}.
  1386. @item nodename
  1387. @samp{-n} in @code{uname}.
  1388. @item nonmatching
  1389. @samp{-f} in @code{cpio}.
  1390. @item nstuff
  1391. @samp{-n} in @code{objdump}.
  1392. @item null
  1393. @samp{-0} in @code{xargs}.
  1394. @item number
  1395. @samp{-n} in @code{cat}.
  1396. @item number-nonblank
  1397. @samp{-b} in @code{cat}.
  1398. @item numeric-sort
  1399. @samp{-n} in @code{nm}.
  1400. @item numeric-uid-gid
  1401. @samp{-n} in @code{cpio} and @code{ls}.
  1402. @item nx
  1403. Used in GDB.
  1404. @item old-archive
  1405. @samp{-o} in @code{tar}.
  1406. @item old-file
  1407. @samp{-o} in @code{make}.
  1408. @item one-file-system
  1409. @samp{-l} in @code{tar}, @code{cp}, and @code{du}.
  1410. @item only-file
  1411. @samp{-o} in @code{ptx}.
  1412. @item only-prof
  1413. @samp{-f} in @code{gprof}.
  1414. @item only-time
  1415. @samp{-F} in @code{gprof}.
  1416. @item options
  1417. @samp{-o} in @code{getopt}, @code{fdlist}, @code{fdmount},
  1418. @code{fdmountd}, and @code{fdumount}.
  1419. @item output
  1420. In various programs, specify the output file name.
  1421. @item output-prefix
  1422. @samp{-o} in @code{shar}.
  1423. @item override
  1424. @samp{-o} in @code{rm}.
  1425. @item overwrite
  1426. @samp{-c} in @code{unshar}.
  1427. @item owner
  1428. @samp{-o} in @code{install}.
  1429. @item paginate
  1430. @samp{-l} in @code{diff}.
  1431. @item paragraph-indent
  1432. Used in @code{makeinfo}.
  1433. @item parents
  1434. @samp{-p} in @code{mkdir} and @code{rmdir}.
  1435. @item pass-all
  1436. @samp{-p} in @code{ul}.
  1437. @item pass-through
  1438. @samp{-p} in @code{cpio}.
  1439. @item port
  1440. @samp{-P} in @code{finger}.
  1441. @item portability
  1442. @samp{-c} in @code{cpio} and @code{tar}.
  1443. @item posix
  1444. Used in @code{gawk}.
  1445. @item prefix-builtins
  1446. @samp{-P} in @code{m4}.
  1447. @item prefix
  1448. @samp{-f} in @code{csplit}.
  1449. @item preserve
  1450. Used in @code{tar} and @code{cp}.
  1451. @item preserve-environment
  1452. @samp{-p} in @code{su}.
  1453. @item preserve-modification-time
  1454. @samp{-m} in @code{cpio}.
  1455. @item preserve-order
  1456. @samp{-s} in @code{tar}.
  1457. @item preserve-permissions
  1458. @samp{-p} in @code{tar}.
  1459. @item print
  1460. @samp{-l} in @code{diff}.
  1461. @item print-chars
  1462. @samp{-L} in @code{cmp}.
  1463. @item print-data-base
  1464. @samp{-p} in @code{make}.
  1465. @item print-directory
  1466. @samp{-w} in @code{make}.
  1467. @item print-file-name
  1468. @samp{-o} in @code{nm}.
  1469. @item print-symdefs
  1470. @samp{-s} in @code{nm}.
  1471. @item printer
  1472. @samp{-p} in @code{wdiff}.
  1473. @item prompt
  1474. @samp{-p} in @code{ed}.
  1475. @item proxy
  1476. Specify an HTTP proxy.
  1477. @item query-user
  1478. @samp{-X} in @code{shar}.
  1479. @item question
  1480. @samp{-q} in @code{make}.
  1481. @item quiet
  1482. Used in many programs to inhibit the usual output. Every
  1483. program accepting @samp{--quiet} should accept @samp{--silent} as a
  1484. synonym.
  1485. @item quiet-unshar
  1486. @samp{-Q} in @code{shar}
  1487. @item quote-name
  1488. @samp{-Q} in @code{ls}.
  1489. @item rcs
  1490. @samp{-n} in @code{diff}.
  1491. @item re-interval
  1492. Used in @code{gawk}.
  1493. @item read-full-blocks
  1494. @samp{-B} in @code{tar}.
  1495. @item readnow
  1496. Used in GDB.
  1497. @item recon
  1498. @samp{-n} in @code{make}.
  1499. @item record-number
  1500. @samp{-R} in @code{tar}.
  1501. @item recursive
  1502. Used in @code{chgrp}, @code{chown}, @code{cp}, @code{ls}, @code{diff},
  1503. and @code{rm}.
  1504. @item reference
  1505. @samp{-r} in @code{touch}.
  1506. @item references
  1507. @samp{-r} in @code{ptx}.
  1508. @item regex
  1509. @samp{-r} in @code{tac} and @code{etags}.
  1510. @item release
  1511. @samp{-r} in @code{uname}.
  1512. @item reload-state
  1513. @samp{-R} in @code{m4}.
  1514. @item relocation
  1515. @samp{-r} in @code{objdump}.
  1516. @item rename
  1517. @samp{-r} in @code{cpio}.
  1518. @item replace
  1519. @samp{-i} in @code{xargs}.
  1520. @item report-identical-files
  1521. @samp{-s} in @code{diff}.
  1522. @item reset-access-time
  1523. @samp{-a} in @code{cpio}.
  1524. @item reverse
  1525. @samp{-r} in @code{ls} and @code{nm}.
  1526. @item reversed-ed
  1527. @samp{-f} in @code{diff}.
  1528. @item right-side-defs
  1529. @samp{-R} in @code{ptx}.
  1530. @item same-order
  1531. @samp{-s} in @code{tar}.
  1532. @item same-permissions
  1533. @samp{-p} in @code{tar}.
  1534. @item save
  1535. @samp{-g} in @code{stty}.
  1536. @item se
  1537. Used in GDB.
  1538. @item sentence-regexp
  1539. @samp{-S} in @code{ptx}.
  1540. @item separate-dirs
  1541. @samp{-S} in @code{du}.
  1542. @item separator
  1543. @samp{-s} in @code{tac}.
  1544. @item sequence
  1545. Used by @code{recode} to chose files or pipes for sequencing passes.
  1546. @item shell
  1547. @samp{-s} in @code{su}.
  1548. @item show-all
  1549. @samp{-A} in @code{cat}.
  1550. @item show-c-function
  1551. @samp{-p} in @code{diff}.
  1552. @item show-ends
  1553. @samp{-E} in @code{cat}.
  1554. @item show-function-line
  1555. @samp{-F} in @code{diff}.
  1556. @item show-tabs
  1557. @samp{-T} in @code{cat}.
  1558. @item silent
  1559. Used in many programs to inhibit the usual output.
  1560. Every program accepting
  1561. @samp{--silent} should accept @samp{--quiet} as a synonym.
  1562. @item size
  1563. @samp{-s} in @code{ls}.
  1564. @item socket
  1565. Specify a file descriptor for a network server to use for its socket,
  1566. instead of opening and binding a new socket. This provides a way to
  1567. run, in a non-privileged process, a server that normally needs a
  1568. reserved port number.
  1569. @item sort
  1570. Used in @code{ls}.
  1571. @item source
  1572. @samp{-W source} in @code{gawk}.
  1573. @item sparse
  1574. @samp{-S} in @code{tar}.
  1575. @item speed-large-files
  1576. @samp{-H} in @code{diff}.
  1577. @item split-at
  1578. @samp{-E} in @code{unshar}.
  1579. @item split-size-limit
  1580. @samp{-L} in @code{shar}.
  1581. @item squeeze-blank
  1582. @samp{-s} in @code{cat}.
  1583. @item start-delete
  1584. @samp{-w} in @code{wdiff}.
  1585. @item start-insert
  1586. @samp{-y} in @code{wdiff}.
  1587. @item starting-file
  1588. Used in @code{tar} and @code{diff} to specify which file within
  1589. a directory to start processing with.
  1590. @item statistics
  1591. @samp{-s} in @code{wdiff}.
  1592. @item stdin-file-list
  1593. @samp{-S} in @code{shar}.
  1594. @item stop
  1595. @samp{-S} in @code{make}.
  1596. @item strict
  1597. @samp{-s} in @code{recode}.
  1598. @item strip
  1599. @samp{-s} in @code{install}.
  1600. @item strip-all
  1601. @samp{-s} in @code{strip}.
  1602. @item strip-debug
  1603. @samp{-S} in @code{strip}.
  1604. @item submitter
  1605. @samp{-s} in @code{shar}.
  1606. @item suffix
  1607. @samp{-S} in @code{cp}, @code{ln}, @code{mv}.
  1608. @item suffix-format
  1609. @samp{-b} in @code{csplit}.
  1610. @item sum
  1611. @samp{-s} in @code{gprof}.
  1612. @item summarize
  1613. @samp{-s} in @code{du}.
  1614. @item symbolic
  1615. @samp{-s} in @code{ln}.
  1616. @item symbols
  1617. Used in GDB and @code{objdump}.
  1618. @item synclines
  1619. @samp{-s} in @code{m4}.
  1620. @item sysname
  1621. @samp{-s} in @code{uname}.
  1622. @item tabs
  1623. @samp{-t} in @code{expand} and @code{unexpand}.
  1624. @item tabsize
  1625. @samp{-T} in @code{ls}.
  1626. @item terminal
  1627. @samp{-T} in @code{tput} and @code{ul}.
  1628. @samp{-t} in @code{wdiff}.
  1629. @item text
  1630. @samp{-a} in @code{diff}.
  1631. @item text-files
  1632. @samp{-T} in @code{shar}.
  1633. @item time
  1634. Used in @code{ls} and @code{touch}.
  1635. @item timeout
  1636. Specify how long to wait before giving up on some operation.
  1637. @item to-stdout
  1638. @samp{-O} in @code{tar}.
  1639. @item total
  1640. @samp{-c} in @code{du}.
  1641. @item touch
  1642. @samp{-t} in @code{make}, @code{ranlib}, and @code{recode}.
  1643. @item trace
  1644. @samp{-t} in @code{m4}.
  1645. @item traditional
  1646. @samp{-t} in @code{hello};
  1647. @samp{-W traditional} in @code{gawk};
  1648. @samp{-G} in @code{ed}, @code{m4}, and @code{ptx}.
  1649. @item tty
  1650. Used in GDB.
  1651. @item typedefs
  1652. @samp{-t} in @code{ctags}.
  1653. @item typedefs-and-c++
  1654. @samp{-T} in @code{ctags}.
  1655. @item typeset-mode
  1656. @samp{-t} in @code{ptx}.
  1657. @item uncompress
  1658. @samp{-z} in @code{tar}.
  1659. @item unconditional
  1660. @samp{-u} in @code{cpio}.
  1661. @item undefine
  1662. @samp{-U} in @code{m4}.
  1663. @item undefined-only
  1664. @samp{-u} in @code{nm}.
  1665. @item update
  1666. @samp{-u} in @code{cp}, @code{ctags}, @code{mv}, @code{tar}.
  1667. @item usage
  1668. Used in @code{gawk}; same as @samp{--help}.
  1669. @item uuencode
  1670. @samp{-B} in @code{shar}.
  1671. @item vanilla-operation
  1672. @samp{-V} in @code{shar}.
  1673. @item verbose
  1674. Print more information about progress. Many programs support this.
  1675. @item verify
  1676. @samp{-W} in @code{tar}.
  1677. @item version
  1678. Print the version number.
  1679. @item version-control
  1680. @samp{-V} in @code{cp}, @code{ln}, @code{mv}.
  1681. @item vgrind
  1682. @samp{-v} in @code{ctags}.
  1683. @item volume
  1684. @samp{-V} in @code{tar}.
  1685. @item what-if
  1686. @samp{-W} in @code{make}.
  1687. @item whole-size-limit
  1688. @samp{-l} in @code{shar}.
  1689. @item width
  1690. @samp{-w} in @code{ls} and @code{ptx}.
  1691. @item word-regexp
  1692. @samp{-W} in @code{ptx}.
  1693. @item writable
  1694. @samp{-T} in @code{who}.
  1695. @item zeros
  1696. @samp{-z} in @code{gprof}.
  1697. @end table
  1698. @node OID Allocations
  1699. @section OID Allocations
  1700. @cindex OID allocations for GNU
  1701. @cindex SNMP
  1702. @cindex LDAP
  1703. @cindex X.509
  1704. The OID (object identifier) 1.3.6.1.4.1.11591 has been assigned to the
  1705. GNU Project (thanks to Werner Koch). These are used for SNMP, LDAP,
  1706. X.509 certificates, and so on. The web site
  1707. @url{http://www.alvestrand.no/objectid} has a (voluntary) listing of
  1708. many OID assignments.
  1709. If you need a new slot for your GNU package, write
  1710. @email{maintainers@@gnu.org}. Here is a list of arcs currently
  1711. assigned:
  1712. @example
  1713. @include gnu-oids.texi
  1714. @end example
  1715. @node Memory Usage
  1716. @section Memory Usage
  1717. @cindex memory usage
  1718. If a program typically uses just a few meg of memory, don't bother making any
  1719. effort to reduce memory usage. For example, if it is impractical for
  1720. other reasons to operate on files more than a few meg long, it is
  1721. reasonable to read entire input files into memory to operate on them.
  1722. However, for programs such as @code{cat} or @code{tail}, that can
  1723. usefully operate on very large files, it is important to avoid using a
  1724. technique that would artificially limit the size of files it can handle.
  1725. If a program works by lines and could be applied to arbitrary
  1726. user-supplied input files, it should keep only a line in memory, because
  1727. this is not very hard and users will want to be able to operate on input
  1728. files that are bigger than will fit in memory all at once.
  1729. If your program creates complicated data structures, just make them in
  1730. memory and give a fatal error if @code{malloc} returns zero.
  1731. @pindex valgrind
  1732. @cindex memory leak
  1733. Memory analysis tools such as @command{valgrind} can be useful, but
  1734. don't complicate a program merely to avoid their false alarms. For
  1735. example, if memory is used until just before a process exits, don't
  1736. free it simply to silence such a tool.
  1737. @node File Usage
  1738. @section File Usage
  1739. @cindex file usage
  1740. Programs should be prepared to operate when @file{/usr} and @file{/etc}
  1741. are read-only file systems. Thus, if the program manages log files,
  1742. lock files, backup files, score files, or any other files which are
  1743. modified for internal purposes, these files should not be stored in
  1744. @file{/usr} or @file{/etc}.
  1745. There are two exceptions. @file{/etc} is used to store system
  1746. configuration information; it is reasonable for a program to modify
  1747. files in @file{/etc} when its job is to update the system configuration.
  1748. Also, if the user explicitly asks to modify one file in a directory, it
  1749. is reasonable for the program to store other files in the same
  1750. directory.
  1751. @node Writing C
  1752. @chapter Making The Best Use of C
  1753. This chapter provides advice on how best to use the C language
  1754. when writing GNU software.
  1755. @menu
  1756. * Formatting:: Formatting your source code.
  1757. * Comments:: Commenting your work.
  1758. * Syntactic Conventions:: Clean use of C constructs.
  1759. * Names:: Naming variables, functions, and files.
  1760. * System Portability:: Portability among different operating systems.
  1761. * CPU Portability:: Supporting the range of CPU types.
  1762. * System Functions:: Portability and ``standard'' library functions.
  1763. * Internationalization:: Techniques for internationalization.
  1764. * Character Set:: Use ASCII by default.
  1765. * Quote Characters:: Use "..." or '...' in the C locale.
  1766. * Mmap:: How you can safely use @code{mmap}.
  1767. @end menu
  1768. @node Formatting
  1769. @section Formatting Your Source Code
  1770. @cindex formatting source code
  1771. @cindex open brace
  1772. @cindex braces, in C source
  1773. @cindex function definitions, formatting
  1774. It is important to put the open-brace that starts the body of a C
  1775. function in column one, so that they will start a defun. Several
  1776. tools look for open-braces in column one to find the beginnings of C
  1777. functions. These tools will not work on code not formatted that way.
  1778. Avoid putting open-brace, open-parenthesis or open-bracket in column
  1779. one when they are inside a function, so that they won't start a defun.
  1780. The open-brace that starts a @code{struct} body can go in column one
  1781. if you find it useful to treat that definition as a defun.
  1782. It is also important for function definitions to start the name of the
  1783. function in column one. This helps people to search for function
  1784. definitions, and may also help certain tools recognize them. Thus,
  1785. using Standard C syntax, the format is this:
  1786. @example
  1787. static char *
  1788. concat (char *s1, char *s2)
  1789. @{
  1790. @dots{}
  1791. @}
  1792. @end example
  1793. @noindent
  1794. or, if you want to use traditional C syntax, format the definition like
  1795. this:
  1796. @example
  1797. static char *
  1798. concat (s1, s2) /* Name starts in column one here */
  1799. char *s1, *s2;
  1800. @{ /* Open brace in column one here */
  1801. @dots{}
  1802. @}
  1803. @end example
  1804. In Standard C, if the arguments don't fit nicely on one line,
  1805. split it like this:
  1806. @example
  1807. int
  1808. lots_of_args (int an_integer, long a_long, short a_short,
  1809. double a_double, float a_float)
  1810. @dots{}
  1811. @end example
  1812. @cindex @code{struct} types, formatting
  1813. @cindex @code{enum} types, formatting
  1814. For @code{struct} and @code{enum} types, likewise put the braces in
  1815. column one, unless the whole contents fits on one line:
  1816. @example
  1817. struct foo
  1818. @{
  1819. int a, b;
  1820. @}
  1821. @exdent @r{or}
  1822. struct foo @{ int a, b; @}
  1823. @end example
  1824. The rest of this section gives our recommendations for other aspects of
  1825. C formatting style, which is also the default style of the @code{indent}
  1826. program in version 1.2 and newer. It corresponds to the options
  1827. @smallexample
  1828. -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
  1829. -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -psl -nsc -nsob
  1830. @end smallexample
  1831. We don't think of these recommendations as requirements, because it
  1832. causes no problems for users if two different programs have different
  1833. formatting styles.
  1834. But whatever style you use, please use it consistently, since a mixture
  1835. of styles within one program tends to look ugly. If you are
  1836. contributing changes to an existing program, please follow the style of
  1837. that program.
  1838. For the body of the function, our recommended style looks like this:
  1839. @example
  1840. if (x < foo (y, z))
  1841. haha = bar[4] + 5;
  1842. else
  1843. @{
  1844. while (z)
  1845. @{
  1846. haha += foo (z, z);
  1847. z--;
  1848. @}
  1849. return ++x + bar ();
  1850. @}
  1851. @end example
  1852. @cindex spaces before open-paren
  1853. We find it easier to read a program when it has spaces before the
  1854. open-parentheses and after the commas. Especially after the commas.
  1855. When you split an expression into multiple lines, split it
  1856. before an operator, not after one. Here is the right way:
  1857. @cindex expressions, splitting
  1858. @example
  1859. if (foo_this_is_long && bar > win (x, y, z)
  1860. && remaining_condition)
  1861. @end example
  1862. Try to avoid having two operators of different precedence at the same
  1863. level of indentation. For example, don't write this:
  1864. @example
  1865. mode = (inmode[j] == VOIDmode
  1866. || GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])
  1867. ? outmode[j] : inmode[j]);
  1868. @end example
  1869. Instead, use extra parentheses so that the indentation shows the nesting:
  1870. @example
  1871. mode = ((inmode[j] == VOIDmode
  1872. || (GET_MODE_SIZE (outmode[j]) > GET_MODE_SIZE (inmode[j])))
  1873. ? outmode[j] : inmode[j]);
  1874. @end example
  1875. Insert extra parentheses so that Emacs will indent the code properly.
  1876. For example, the following indentation looks nice if you do it by hand,
  1877. @example
  1878. v = rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
  1879. + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000;
  1880. @end example
  1881. @noindent
  1882. but Emacs would alter it. Adding a set of parentheses produces
  1883. something that looks equally nice, and which Emacs will preserve:
  1884. @example
  1885. v = (rup->ru_utime.tv_sec*1000 + rup->ru_utime.tv_usec/1000
  1886. + rup->ru_stime.tv_sec*1000 + rup->ru_stime.tv_usec/1000);
  1887. @end example
  1888. Format do-while statements like this:
  1889. @example
  1890. do
  1891. @{
  1892. a = foo (a);
  1893. @}
  1894. while (a > 0);
  1895. @end example
  1896. @cindex formfeed
  1897. @cindex control-L
  1898. Please use formfeed characters (control-L) to divide the program into
  1899. pages at logical places (but not within a function). It does not matter
  1900. just how long the pages are, since they do not have to fit on a printed
  1901. page. The formfeeds should appear alone on lines by themselves.
  1902. @node Comments
  1903. @section Commenting Your Work
  1904. @cindex commenting
  1905. Every program should start with a comment saying briefly what it is for.
  1906. Example: @samp{fmt - filter for simple filling of text}. This comment
  1907. should be at the top of the source file containing the @samp{main}
  1908. function of the program.
  1909. Also, please write a brief comment at the start of each source file,
  1910. with the file name and a line or two about the overall purpose of the
  1911. file.
  1912. Please write the comments in a GNU program in English, because English
  1913. is the one language that nearly all programmers in all countries can
  1914. read. If you do not write English well, please write comments in
  1915. English as well as you can, then ask other people to help rewrite them.
  1916. If you can't write comments in English, please find someone to work with
  1917. you and translate your comments into English.
  1918. Please put a comment on each function saying what the function does,
  1919. what sorts of arguments it gets, and what the possible values of
  1920. arguments mean and are used for. It is not necessary to duplicate in
  1921. words the meaning of the C argument declarations, if a C type is being
  1922. used in its customary fashion. If there is anything nonstandard about
  1923. its use (such as an argument of type @code{char *} which is really the
  1924. address of the second character of a string, not the first), or any
  1925. possible values that would not work the way one would expect (such as,
  1926. that strings containing newlines are not guaranteed to work), be sure
  1927. to say so.
  1928. Also explain the significance of the return value, if there is one.
  1929. Please put two spaces after the end of a sentence in your comments, so
  1930. that the Emacs sentence commands will work. Also, please write
  1931. complete sentences and capitalize the first word. If a lower-case
  1932. identifier comes at the beginning of a sentence, don't capitalize it!
  1933. Changing the spelling makes it a different identifier. If you don't
  1934. like starting a sentence with a lower case letter, write the sentence
  1935. differently (e.g., ``The identifier lower-case is @dots{}'').
  1936. The comment on a function is much clearer if you use the argument
  1937. names to speak about the argument values. The variable name itself
  1938. should be lower case, but write it in upper case when you are speaking
  1939. about the value rather than the variable itself. Thus, ``the inode
  1940. number NODE_NUM'' rather than ``an inode''.
  1941. There is usually no purpose in restating the name of the function in
  1942. the comment before it, because readers can see that for themselves.
  1943. There might be an exception when the comment is so long that the function
  1944. itself would be off the bottom of the screen.
  1945. There should be a comment on each static variable as well, like this:
  1946. @example
  1947. /* Nonzero means truncate lines in the display;
  1948. zero means continue them. */
  1949. int truncate_lines;
  1950. @end example
  1951. @cindex conditionals, comments for
  1952. @cindex @code{#endif}, commenting
  1953. Every @samp{#endif} should have a comment, except in the case of short
  1954. conditionals (just a few lines) that are not nested. The comment should
  1955. state the condition of the conditional that is ending, @emph{including
  1956. its sense}. @samp{#else} should have a comment describing the condition
  1957. @emph{and sense} of the code that follows. For example:
  1958. @example
  1959. @group
  1960. #ifdef foo
  1961. @dots{}
  1962. #else /* not foo */
  1963. @dots{}
  1964. #endif /* not foo */
  1965. @end group
  1966. @group
  1967. #ifdef foo
  1968. @dots{}
  1969. #endif /* foo */
  1970. @end group
  1971. @end example
  1972. @noindent
  1973. but, by contrast, write the comments this way for a @samp{#ifndef}:
  1974. @example
  1975. @group
  1976. #ifndef foo
  1977. @dots{}
  1978. #else /* foo */
  1979. @dots{}
  1980. #endif /* foo */
  1981. @end group
  1982. @group
  1983. #ifndef foo
  1984. @dots{}
  1985. #endif /* not foo */
  1986. @end group
  1987. @end example
  1988. @node Syntactic Conventions
  1989. @section Clean Use of C Constructs
  1990. @cindex syntactic conventions
  1991. @cindex implicit @code{int}
  1992. @cindex function argument, declaring
  1993. Please explicitly declare the types of all objects. For example, you
  1994. should explicitly declare all arguments to functions, and you should
  1995. declare functions to return @code{int} rather than omitting the
  1996. @code{int}.
  1997. @cindex compiler warnings
  1998. @cindex @samp{-Wall} compiler option
  1999. Some programmers like to use the GCC @samp{-Wall} option, and change the
  2000. code whenever it issues a warning. If you want to do this, then do.
  2001. Other programmers prefer not to use @samp{-Wall}, because it gives
  2002. warnings for valid and legitimate code which they do not want to change.
  2003. If you want to do this, then do. The compiler should be your servant,
  2004. not your master.
  2005. @pindex clang
  2006. @pindex lint
  2007. Don't make the program ugly just to placate static analysis tools such
  2008. as @command{lint}, @command{clang}, and GCC with extra warnings
  2009. options such as @option{-Wconversion} and @option{-Wundef}. These
  2010. tools can help find bugs and unclear code, but they can also generate
  2011. so many false alarms that it hurts readability to silence them with
  2012. unnecessary casts, wrappers, and other complications. For example,
  2013. please don't insert casts to @code{void} or calls to do-nothing
  2014. functions merely to pacify a lint checker.
  2015. Declarations of external functions and functions to appear later in the
  2016. source file should all go in one place near the beginning of the file
  2017. (somewhere before the first function definition in the file), or else
  2018. should go in a header file. Don't put @code{extern} declarations inside
  2019. functions.
  2020. @cindex temporary variables
  2021. It used to be common practice to use the same local variables (with
  2022. names like @code{tem}) over and over for different values within one
  2023. function. Instead of doing this, it is better to declare a separate local
  2024. variable for each distinct purpose, and give it a name which is
  2025. meaningful. This not only makes programs easier to understand, it also
  2026. facilitates optimization by good compilers. You can also move the
  2027. declaration of each local variable into the smallest scope that includes
  2028. all its uses. This makes the program even cleaner.
  2029. Don't use local variables or parameters that shadow global identifiers.
  2030. GCC's @samp{-Wshadow} option can detect this problem.
  2031. @cindex multiple variables in a line
  2032. Don't declare multiple variables in one declaration that spans lines.
  2033. Start a new declaration on each line, instead. For example, instead
  2034. of this:
  2035. @example
  2036. @group
  2037. int foo,
  2038. bar;
  2039. @end group
  2040. @end example
  2041. @noindent
  2042. write either this:
  2043. @example
  2044. int foo, bar;
  2045. @end example
  2046. @noindent
  2047. or this:
  2048. @example
  2049. int foo;
  2050. int bar;
  2051. @end example
  2052. @noindent
  2053. (If they are global variables, each should have a comment preceding it
  2054. anyway.)
  2055. When you have an @code{if}-@code{else} statement nested in another
  2056. @code{if} statement, always put braces around the @code{if}-@code{else}.
  2057. Thus, never write like this:
  2058. @example
  2059. if (foo)
  2060. if (bar)
  2061. win ();
  2062. else
  2063. lose ();
  2064. @end example
  2065. @noindent
  2066. always like this:
  2067. @example
  2068. if (foo)
  2069. @{
  2070. if (bar)
  2071. win ();
  2072. else
  2073. lose ();
  2074. @}
  2075. @end example
  2076. If you have an @code{if} statement nested inside of an @code{else}
  2077. statement, either write @code{else if} on one line, like this,
  2078. @example
  2079. if (foo)
  2080. @dots{}
  2081. else if (bar)
  2082. @dots{}
  2083. @end example
  2084. @noindent
  2085. with its @code{then}-part indented like the preceding @code{then}-part,
  2086. or write the nested @code{if} within braces like this:
  2087. @example
  2088. if (foo)
  2089. @dots{}
  2090. else
  2091. @{
  2092. if (bar)
  2093. @dots{}
  2094. @}
  2095. @end example
  2096. Don't declare both a structure tag and variables or typedefs in the
  2097. same declaration. Instead, declare the structure tag separately
  2098. and then use it to declare the variables or typedefs.
  2099. Try to avoid assignments inside @code{if}-conditions (assignments
  2100. inside @code{while}-conditions are ok). For example, don't write
  2101. this:
  2102. @example
  2103. if ((foo = (char *) malloc (sizeof *foo)) == 0)
  2104. fatal ("virtual memory exhausted");
  2105. @end example
  2106. @noindent
  2107. instead, write this:
  2108. @example
  2109. foo = (char *) malloc (sizeof *foo);
  2110. if (foo == 0)
  2111. fatal ("virtual memory exhausted");
  2112. @end example
  2113. This example uses zero without a cast as a null pointer constant.
  2114. This is perfectly fine, except that a cast is needed when calling a
  2115. varargs function or when using @code{sizeof}.
  2116. @node Names
  2117. @section Naming Variables, Functions, and Files
  2118. @cindex names of variables, functions, and files
  2119. The names of global variables and functions in a program serve as
  2120. comments of a sort. So don't choose terse names---instead, look for
  2121. names that give useful information about the meaning of the variable or
  2122. function. In a GNU program, names should be English, like other
  2123. comments.
  2124. Local variable names can be shorter, because they are used only within
  2125. one context, where (presumably) comments explain their purpose.
  2126. Try to limit your use of abbreviations in symbol names. It is ok to
  2127. make a few abbreviations, explain what they mean, and then use them
  2128. frequently, but don't use lots of obscure abbreviations.
  2129. Please use underscores to separate words in a name, so that the Emacs
  2130. word commands can be useful within them. Stick to lower case; reserve
  2131. upper case for macros and @code{enum} constants, and for name-prefixes
  2132. that follow a uniform convention.
  2133. For example, you should use names like @code{ignore_space_change_flag};
  2134. don't use names like @code{iCantReadThis}.
  2135. Variables that indicate whether command-line options have been
  2136. specified should be named after the meaning of the option, not after
  2137. the option-letter. A comment should state both the exact meaning of
  2138. the option and its letter. For example,
  2139. @example
  2140. @group
  2141. /* Ignore changes in horizontal whitespace (-b). */
  2142. int ignore_space_change_flag;
  2143. @end group
  2144. @end example
  2145. When you want to define names with constant integer values, use
  2146. @code{enum} rather than @samp{#define}. GDB knows about enumeration
  2147. constants.
  2148. @cindex file-name limitations
  2149. @pindex doschk
  2150. You might want to make sure that none of the file names would conflict
  2151. if the files were loaded onto an MS-DOS file system which shortens the
  2152. names. You can use the program @code{doschk} to test for this.
  2153. Some GNU programs were designed to limit themselves to file names of 14
  2154. characters or less, to avoid file name conflicts if they are read into
  2155. older System V systems. Please preserve this feature in the existing
  2156. GNU programs that have it, but there is no need to do this in new GNU
  2157. programs. @code{doschk} also reports file names longer than 14
  2158. characters.
  2159. @node System Portability
  2160. @section Portability between System Types
  2161. @cindex portability, between system types
  2162. In the Unix world, ``portability'' refers to porting to different Unix
  2163. versions. For a GNU program, this kind of portability is desirable, but
  2164. not paramount.
  2165. The primary purpose of GNU software is to run on top of the GNU kernel,
  2166. compiled with the GNU C compiler, on various types of @sc{cpu}. So the
  2167. kinds of portability that are absolutely necessary are quite limited.
  2168. But it is important to support Linux-based GNU systems, since they
  2169. are the form of GNU that is popular.
  2170. Beyond that, it is good to support the other free operating systems
  2171. (*BSD), and it is nice to support other Unix-like systems if you want
  2172. to. Supporting a variety of Unix-like systems is desirable, although
  2173. not paramount. It is usually not too hard, so you may as well do it.
  2174. But you don't have to consider it an obligation, if it does turn out to
  2175. be hard.
  2176. @pindex autoconf
  2177. The easiest way to achieve portability to most Unix-like systems is to
  2178. use Autoconf. It's unlikely that your program needs to know more
  2179. information about the host platform than Autoconf can provide, simply
  2180. because most of the programs that need such knowledge have already been
  2181. written.
  2182. Avoid using the format of semi-internal data bases (e.g., directories)
  2183. when there is a higher-level alternative (@code{readdir}).
  2184. @cindex non-@sc{posix} systems, and portability
  2185. As for systems that are not like Unix, such as MSDOS, Windows, VMS, MVS,
  2186. and older Macintosh systems, supporting them is often a lot of work.
  2187. When that is the case, it is better to spend your time adding features
  2188. that will be useful on GNU and GNU/Linux, rather than on supporting
  2189. other incompatible systems.
  2190. If you do support Windows, please do not abbreviate it as ``win''. In
  2191. hacker terminology, calling something a ``win'' is a form of praise.
  2192. You're free to praise Microsoft Windows on your own if you want, but
  2193. please don't do this in GNU packages. Instead of abbreviating
  2194. ``Windows'' to ``win'', you can write it in full or abbreviate it to
  2195. ``woe'' or ``w''. In GNU Emacs, for instance, we use @samp{w32} in
  2196. file names of Windows-specific files, but the macro for Windows
  2197. conditionals is called @code{WINDOWSNT}.
  2198. It is a good idea to define the ``feature test macro''
  2199. @code{_GNU_SOURCE} when compiling your C files. When you compile on GNU
  2200. or GNU/Linux, this will enable the declarations of GNU library extension
  2201. functions, and that will usually give you a compiler error message if
  2202. you define the same function names in some other way in your program.
  2203. (You don't have to actually @emph{use} these functions, if you prefer
  2204. to make the program more portable to other systems.)
  2205. But whether or not you use these GNU extensions, you should avoid
  2206. using their names for any other meanings. Doing so would make it hard
  2207. to move your code into other GNU programs.
  2208. @node CPU Portability
  2209. @section Portability between @sc{cpu}s
  2210. @cindex data types, and portability
  2211. @cindex portability, and data types
  2212. Even GNU systems will differ because of differences among @sc{cpu}
  2213. types---for example, difference in byte ordering and alignment
  2214. requirements. It is absolutely essential to handle these differences.
  2215. However, don't make any effort to cater to the possibility that an
  2216. @code{int} will be less than 32 bits. We don't support 16-bit machines
  2217. in GNU.
  2218. Similarly, don't make any effort to cater to the possibility that
  2219. @code{long} will be smaller than predefined types like @code{size_t}.
  2220. For example, the following code is ok:
  2221. @example
  2222. printf ("size = %lu\n", (unsigned long) sizeof array);
  2223. printf ("diff = %ld\n", (long) (pointer2 - pointer1));
  2224. @end example
  2225. 1989 Standard C requires this to work, and we know of only one
  2226. counterexample: 64-bit programs on Microsoft Windows. We will leave
  2227. it to those who want to port GNU programs to that environment to
  2228. figure out how to do it.
  2229. Predefined file-size types like @code{off_t} are an exception: they are
  2230. longer than @code{long} on many platforms, so code like the above won't
  2231. work with them. One way to print an @code{off_t} value portably is to
  2232. print its digits yourself, one by one.
  2233. Don't assume that the address of an @code{int} object is also the
  2234. address of its least-significant byte. This is false on big-endian
  2235. machines. Thus, don't make the following mistake:
  2236. @example
  2237. int c;
  2238. @dots{}
  2239. while ((c = getchar ()) != EOF)
  2240. write (file_descriptor, &c, 1);
  2241. @end example
  2242. @noindent Instead, use @code{unsigned char} as follows. (The @code{unsigned}
  2243. is for portability to unusual systems where @code{char} is signed and
  2244. where there is integer overflow checking.)
  2245. @example
  2246. int c;
  2247. while ((c = getchar ()) != EOF)
  2248. @{
  2249. unsigned char u = c;
  2250. write (file_descriptor, &u, 1);
  2251. @}
  2252. @end example
  2253. @cindex casting pointers to integers
  2254. Avoid casting pointers to integers if you can. Such casts greatly
  2255. reduce portability, and in most programs they are easy to avoid. In the
  2256. cases where casting pointers to integers is essential---such as, a Lisp
  2257. interpreter which stores type information as well as an address in one
  2258. word---you'll have to make explicit provisions to handle different word
  2259. sizes. You will also need to make provision for systems in which the
  2260. normal range of addresses you can get from @code{malloc} starts far away
  2261. from zero.
  2262. @node System Functions
  2263. @section Calling System Functions
  2264. @cindex C library functions, and portability
  2265. @cindex POSIX functions, and portability
  2266. @cindex library functions, and portability
  2267. @cindex portability, and library functions
  2268. Historically, C implementations differed substantially, and many
  2269. systems lacked a full implementation of ANSI/ISO C89. Nowadays,
  2270. however, very few systems lack a C89 compiler and GNU C supports
  2271. almost all of C99. Similarly, most systems implement POSIX.1-1993
  2272. libraries and tools, and many have POSIX.1-2001.
  2273. Hence, there is little reason to support old C or non-POSIX systems,
  2274. and you may want to take advantage of C99 and POSIX-1.2001 to write
  2275. clearer, more portable, or faster code. You should use standard
  2276. interfaces where possible; but if GNU extensions make your program
  2277. more maintainable, powerful, or otherwise better, don't hesitate to
  2278. use them. In any case, don't make your own declaration of system
  2279. functions; that's a recipe for conflict.
  2280. Despite the standards, nearly every library function has some sort of
  2281. portability issue on some system or another. Here are some examples:
  2282. @table @code
  2283. @item open
  2284. Names with trailing @code{/}'s are mishandled on many platforms.
  2285. @item printf
  2286. @code{long double} may be unimplemented; floating values Infinity and
  2287. NaN are often mishandled; output for large precisions may be
  2288. incorrect.
  2289. @item readlink
  2290. May return @code{int} instead of @code{ssize_t}.
  2291. @item scanf
  2292. On Windows, @code{errno} is not set on failure.
  2293. @end table
  2294. @cindex Gnulib
  2295. @uref{http://www.gnu.org/software/gnulib/, Gnulib} is a big help in
  2296. this regard. Gnulib provides implementations of standard interfaces
  2297. on many of the systems that lack them, including portable
  2298. implementations of enhanced GNU interfaces, thereby making their use
  2299. portable, and of POSIX-1.2008 interfaces, some of which are missing
  2300. even on up-to-date GNU systems.
  2301. @findex xmalloc, in Gnulib
  2302. @findex error messages, in Gnulib
  2303. @findex data structures, in Gnulib
  2304. Gnulib also provides many useful non-standard interfaces; for example,
  2305. C implementations of standard data structures (hash tables, binary
  2306. trees), error-checking type-safe wrappers for memory allocation
  2307. functions (@code{xmalloc}, @code{xrealloc}), and output of error
  2308. messages.
  2309. Gnulib integrates with GNU Autoconf and Automake to remove much of the
  2310. burden of writing portable code from the programmer: Gnulib makes your
  2311. configure script automatically determine what features are missing and
  2312. use the Gnulib code to supply the missing pieces.
  2313. The Gnulib and Autoconf manuals have extensive sections on
  2314. portability: @ref{Top,, Introduction, gnulib, Gnulib} and
  2315. @pxref{Portable C and C++,,, autoconf, Autoconf}. Please consult them
  2316. for many more details.
  2317. @node Internationalization
  2318. @section Internationalization
  2319. @cindex internationalization
  2320. @pindex gettext
  2321. GNU has a library called GNU gettext that makes it easy to translate the
  2322. messages in a program into various languages. You should use this
  2323. library in every program. Use English for the messages as they appear
  2324. in the program, and let gettext provide the way to translate them into
  2325. other languages.
  2326. Using GNU gettext involves putting a call to the @code{gettext} macro
  2327. around each string that might need translation---like this:
  2328. @example
  2329. printf (gettext ("Processing file '%s'..."), file);
  2330. @end example
  2331. @noindent
  2332. This permits GNU gettext to replace the string @code{"Processing file
  2333. '%s'..."} with a translated version.
  2334. Once a program uses gettext, please make a point of writing calls to
  2335. @code{gettext} when you add new strings that call for translation.
  2336. Using GNU gettext in a package involves specifying a @dfn{text domain
  2337. name} for the package. The text domain name is used to separate the
  2338. translations for this package from the translations for other packages.
  2339. Normally, the text domain name should be the same as the name of the
  2340. package---for example, @samp{coreutils} for the GNU core utilities.
  2341. @cindex message text, and internationalization
  2342. To enable gettext to work well, avoid writing code that makes
  2343. assumptions about the structure of words or sentences. When you want
  2344. the precise text of a sentence to vary depending on the data, use two or
  2345. more alternative string constants each containing a complete sentences,
  2346. rather than inserting conditionalized words or phrases into a single
  2347. sentence framework.
  2348. Here is an example of what not to do:
  2349. @smallexample
  2350. printf ("%s is full", capacity > 5000000 ? "disk" : "floppy disk");
  2351. @end smallexample
  2352. If you apply gettext to all strings, like this,
  2353. @smallexample
  2354. printf (gettext ("%s is full"),
  2355. capacity > 5000000 ? gettext ("disk") : gettext ("floppy disk"));
  2356. @end smallexample
  2357. @noindent
  2358. the translator will hardly know that "disk" and "floppy disk" are meant to
  2359. be substituted in the other string. Worse, in some languages (like French)
  2360. the construction will not work: the translation of the word "full" depends
  2361. on the gender of the first part of the sentence; it happens to be not the
  2362. same for "disk" as for "floppy disk".
  2363. Complete sentences can be translated without problems:
  2364. @example
  2365. printf (capacity > 5000000 ? gettext ("disk is full")
  2366. : gettext ("floppy disk is full"));
  2367. @end example
  2368. A similar problem appears at the level of sentence structure with this
  2369. code:
  2370. @example
  2371. printf ("# Implicit rule search has%s been done.\n",
  2372. f->tried_implicit ? "" : " not");
  2373. @end example
  2374. @noindent
  2375. Adding @code{gettext} calls to this code cannot give correct results for
  2376. all languages, because negation in some languages requires adding words
  2377. at more than one place in the sentence. By contrast, adding
  2378. @code{gettext} calls does the job straightforwardly if the code starts
  2379. out like this:
  2380. @example
  2381. printf (f->tried_implicit
  2382. ? "# Implicit rule search has been done.\n",
  2383. : "# Implicit rule search has not been done.\n");
  2384. @end example
  2385. Another example is this one:
  2386. @example
  2387. printf ("%d file%s processed", nfiles,
  2388. nfiles != 1 ? "s" : "");
  2389. @end example
  2390. @noindent
  2391. The problem with this example is that it assumes that plurals are made
  2392. by adding `s'. If you apply gettext to the format string, like this,
  2393. @example
  2394. printf (gettext ("%d file%s processed"), nfiles,
  2395. nfiles != 1 ? "s" : "");
  2396. @end example
  2397. @noindent
  2398. the message can use different words, but it will still be forced to use
  2399. `s' for the plural. Here is a better way, with gettext being applied to
  2400. the two strings independently:
  2401. @example
  2402. printf ((nfiles != 1 ? gettext ("%d files processed")
  2403. : gettext ("%d file processed")),
  2404. nfiles);
  2405. @end example
  2406. @noindent
  2407. But this still doesn't work for languages like Polish, which has three
  2408. plural forms: one for nfiles == 1, one for nfiles == 2, 3, 4, 22, 23, 24, ...
  2409. and one for the rest. The GNU @code{ngettext} function solves this problem:
  2410. @example
  2411. printf (ngettext ("%d files processed", "%d file processed", nfiles),
  2412. nfiles);
  2413. @end example
  2414. @node Character Set
  2415. @section Character Set
  2416. @cindex character set
  2417. @cindex encodings
  2418. @cindex ASCII characters
  2419. @cindex non-ASCII characters
  2420. Sticking to the ASCII character set (plain text, 7-bit characters) is
  2421. preferred in GNU source code comments, text documents, and other
  2422. contexts, unless there is good reason to do something else because of
  2423. the application domain. For example, if source code deals with the
  2424. French Revolutionary calendar, it is OK if its literal strings contain
  2425. accented characters in month names like ``Flor@'eal''. Also, it is OK
  2426. (but not required) to use non-ASCII characters to represent proper
  2427. names of contributors in change logs (@pxref{Change Logs}).
  2428. If you need to use non-ASCII characters, you should normally stick
  2429. with one encoding, certainly within a single file. UTF-8 is likely to
  2430. be the best choice.
  2431. @node Quote Characters
  2432. @section Quote Characters
  2433. @cindex quote characters
  2434. @cindex locale-specific quote characters
  2435. @cindex left quote
  2436. @cindex right quote
  2437. @cindex opening quote
  2438. @cindex single quote
  2439. @cindex double quote
  2440. @cindex grave accent
  2441. @set txicodequoteundirected
  2442. @set txicodequotebacktick
  2443. In the C locale, the output of GNU programs should stick to plain
  2444. ASCII for quotation characters in messages to users: preferably 0x22
  2445. (@samp{"}) or 0x27 (@samp{'}) for both opening and closing quotes.
  2446. Although GNU programs traditionally used 0x60 (@samp{`}) for opening
  2447. and 0x27 (@samp{'}) for closing quotes, nowadays quotes @samp{`like
  2448. this'} are typically rendered asymmetrically, so quoting @samp{"like
  2449. this"} or @samp{'like this'} typically looks better.
  2450. It is ok, but not required, for GNU programs to generate
  2451. locale-specific quotes in non-C locales. For example:
  2452. @example
  2453. printf (gettext ("Processing file '%s'..."), file);
  2454. @end example
  2455. @noindent
  2456. Here, a French translation might cause @code{gettext} to return the
  2457. string @code{"Traitement de fichier
  2458. @guilsinglleft{}@tie{}%s@tie{}@guilsinglright{}..."}, yielding quotes
  2459. more appropriate for a French locale.
  2460. Sometimes a program may need to use opening and closing quotes
  2461. directly. By convention, @code{gettext} translates the string
  2462. @samp{"`"} to the opening quote and the string @samp{"'"} to the
  2463. closing quote, and a program can use these translations. Generally,
  2464. though, it is better to translate quote characters in the context of
  2465. longer strings.
  2466. If the output of your program is ever likely to be parsed by another
  2467. program, it is good to provide an option that makes this parsing
  2468. reliable. For example, you could escape special characters using
  2469. conventions from the C language or the Bourne shell. See for example
  2470. the option @option{--quoting-style} of GNU @code{ls}.
  2471. @clear txicodequoteundirected
  2472. @clear txicodequotebacktick
  2473. @node Mmap
  2474. @section Mmap
  2475. @findex mmap
  2476. Don't assume that @code{mmap} either works on all files or fails
  2477. for all files. It may work on some files and fail on others.
  2478. The proper way to use @code{mmap} is to try it on the specific file for
  2479. which you want to use it---and if @code{mmap} doesn't work, fall back on
  2480. doing the job in another way using @code{read} and @code{write}.
  2481. The reason this precaution is needed is that the GNU kernel (the HURD)
  2482. provides a user-extensible file system, in which there can be many
  2483. different kinds of ``ordinary files''. Many of them support
  2484. @code{mmap}, but some do not. It is important to make programs handle
  2485. all these kinds of files.
  2486. @node Documentation
  2487. @chapter Documenting Programs
  2488. @cindex documentation
  2489. A GNU program should ideally come with full free documentation, adequate
  2490. for both reference and tutorial purposes. If the package can be
  2491. programmed or extended, the documentation should cover programming or
  2492. extending it, as well as just using it.
  2493. @menu
  2494. * GNU Manuals:: Writing proper manuals.
  2495. * Doc Strings and Manuals:: Compiling doc strings doesn't make a manual.
  2496. * Manual Structure Details:: Specific structure conventions.
  2497. * License for Manuals:: Writing the distribution terms for a manual.
  2498. * Manual Credits:: Giving credit to documentation contributors.
  2499. * Printed Manuals:: Mentioning the printed manual.
  2500. * NEWS File:: NEWS files supplement manuals.
  2501. * Change Logs:: Recording changes.
  2502. * Man Pages:: Man pages are secondary.
  2503. * Reading other Manuals:: How far you can go in learning
  2504. from other manuals.
  2505. @end menu
  2506. @node GNU Manuals
  2507. @section GNU Manuals
  2508. The preferred document format for the GNU system is the Texinfo
  2509. formatting language. Every GNU package should (ideally) have
  2510. documentation in Texinfo both for reference and for learners. Texinfo
  2511. makes it possible to produce a good quality formatted book, using
  2512. @TeX{}, and to generate an Info file. It is also possible to generate
  2513. HTML output from Texinfo source. See the Texinfo manual, either the
  2514. hardcopy, or the on-line version available through @code{info} or the
  2515. Emacs Info subsystem (@kbd{C-h i}).
  2516. Nowadays some other formats such as Docbook and Sgmltexi can be
  2517. converted automatically into Texinfo. It is ok to produce the Texinfo
  2518. documentation by conversion this way, as long as it gives good results.
  2519. Make sure your manual is clear to a reader who knows nothing about the
  2520. topic and reads it straight through. This means covering basic topics
  2521. at the beginning, and advanced topics only later. This also means
  2522. defining every specialized term when it is first used.
  2523. Programmers tend to carry over the structure of the program as the
  2524. structure for its documentation. But this structure is not
  2525. necessarily good for explaining how to use the program; it may be
  2526. irrelevant and confusing for a user.
  2527. Instead, the right way to structure documentation is according to the
  2528. concepts and questions that a user will have in mind when reading it.
  2529. This principle applies at every level, from the lowest (ordering
  2530. sentences in a paragraph) to the highest (ordering of chapter topics
  2531. within the manual). Sometimes this structure of ideas matches the
  2532. structure of the implementation of the software being documented---but
  2533. often they are different. An important part of learning to write good
  2534. documentation is to learn to notice when you have unthinkingly
  2535. structured the documentation like the implementation, stop yourself,
  2536. and look for better alternatives.
  2537. For example, each program in the GNU system probably ought to be
  2538. documented in one manual; but this does not mean each program should
  2539. have its own manual. That would be following the structure of the
  2540. implementation, rather than the structure that helps the user
  2541. understand.
  2542. Instead, each manual should cover a coherent @emph{topic}. For example,
  2543. instead of a manual for @code{diff} and a manual for @code{diff3}, we
  2544. have one manual for ``comparison of files'' which covers both of those
  2545. programs, as well as @code{cmp}. By documenting these programs
  2546. together, we can make the whole subject clearer.
  2547. The manual which discusses a program should certainly document all of
  2548. the program's command-line options and all of its commands. It should
  2549. give examples of their use. But don't organize the manual as a list
  2550. of features. Instead, organize it logically, by subtopics. Address
  2551. the questions that a user will ask when thinking about the job that
  2552. the program does. Don't just tell the reader what each feature can
  2553. do---say what jobs it is good for, and show how to use it for those
  2554. jobs. Explain what is recommended usage, and what kinds of usage
  2555. users should avoid.
  2556. In general, a GNU manual should serve both as tutorial and reference.
  2557. It should be set up for convenient access to each topic through Info,
  2558. and for reading straight through (appendixes aside). A GNU manual
  2559. should give a good introduction to a beginner reading through from the
  2560. start, and should also provide all the details that hackers want.
  2561. The Bison manual is a good example of this---please take a look at it
  2562. to see what we mean.
  2563. That is not as hard as it first sounds. Arrange each chapter as a
  2564. logical breakdown of its topic, but order the sections, and write their
  2565. text, so that reading the chapter straight through makes sense. Do
  2566. likewise when structuring the book into chapters, and when structuring a
  2567. section into paragraphs. The watchword is, @emph{at each point, address
  2568. the most fundamental and important issue raised by the preceding text.}
  2569. If necessary, add extra chapters at the beginning of the manual which
  2570. are purely tutorial and cover the basics of the subject. These provide
  2571. the framework for a beginner to understand the rest of the manual. The
  2572. Bison manual provides a good example of how to do this.
  2573. To serve as a reference, a manual should have an Index that list all the
  2574. functions, variables, options, and important concepts that are part of
  2575. the program. One combined Index should do for a short manual, but
  2576. sometimes for a complex package it is better to use multiple indices.
  2577. The Texinfo manual includes advice on preparing good index entries, see
  2578. @ref{Index Entries, , Making Index Entries, texinfo, GNU Texinfo}, and
  2579. see @ref{Indexing Commands, , Defining the Entries of an
  2580. Index, texinfo, GNU Texinfo}.
  2581. Don't use Unix man pages as a model for how to write GNU documentation;
  2582. most of them are terse, badly structured, and give inadequate
  2583. explanation of the underlying concepts. (There are, of course, some
  2584. exceptions.) Also, Unix man pages use a particular format which is
  2585. different from what we use in GNU manuals.
  2586. Please include an email address in the manual for where to report
  2587. bugs @emph{in the text of the manual}.
  2588. Please do not use the term ``pathname'' that is used in Unix
  2589. documentation; use ``file name'' (two words) instead. We use the term
  2590. ``path'' only for search paths, which are lists of directory names.
  2591. Please do not use the term ``illegal'' to refer to erroneous input to
  2592. a computer program. Please use ``invalid'' for this, and reserve the
  2593. term ``illegal'' for activities prohibited by law.
  2594. Please do not write @samp{()} after a function name just to indicate
  2595. it is a function. @code{foo ()} is not a function, it is a function
  2596. call with no arguments.
  2597. @node Doc Strings and Manuals
  2598. @section Doc Strings and Manuals
  2599. Some programming systems, such as Emacs, provide a documentation string
  2600. for each function, command or variable. You may be tempted to write a
  2601. reference manual by compiling the documentation strings and writing a
  2602. little additional text to go around them---but you must not do it. That
  2603. approach is a fundamental mistake. The text of well-written
  2604. documentation strings will be entirely wrong for a manual.
  2605. A documentation string needs to stand alone---when it appears on the
  2606. screen, there will be no other text to introduce or explain it.
  2607. Meanwhile, it can be rather informal in style.
  2608. The text describing a function or variable in a manual must not stand
  2609. alone; it appears in the context of a section or subsection. Other text
  2610. at the beginning of the section should explain some of the concepts, and
  2611. should often make some general points that apply to several functions or
  2612. variables. The previous descriptions of functions and variables in the
  2613. section will also have given information about the topic. A description
  2614. written to stand alone would repeat some of that information; this
  2615. redundancy looks bad. Meanwhile, the informality that is acceptable in
  2616. a documentation string is totally unacceptable in a manual.
  2617. The only good way to use documentation strings in writing a good manual
  2618. is to use them as a source of information for writing good text.
  2619. @node Manual Structure Details
  2620. @section Manual Structure Details
  2621. @cindex manual structure
  2622. The title page of the manual should state the version of the programs or
  2623. packages documented in the manual. The Top node of the manual should
  2624. also contain this information. If the manual is changing more
  2625. frequently than or independent of the program, also state a version
  2626. number for the manual in both of these places.
  2627. Each program documented in the manual should have a node named
  2628. @samp{@var{program} Invocation} or @samp{Invoking @var{program}}. This
  2629. node (together with its subnodes, if any) should describe the program's
  2630. command line arguments and how to run it (the sort of information people
  2631. would look for in a man page). Start with an @samp{@@example}
  2632. containing a template for all the options and arguments that the program
  2633. uses.
  2634. Alternatively, put a menu item in some menu whose item name fits one of
  2635. the above patterns. This identifies the node which that item points to
  2636. as the node for this purpose, regardless of the node's actual name.
  2637. The @samp{--usage} feature of the Info reader looks for such a node
  2638. or menu item in order to find the relevant text, so it is essential
  2639. for every Texinfo file to have one.
  2640. If one manual describes several programs, it should have such a node for
  2641. each program described in the manual.
  2642. @node License for Manuals
  2643. @section License for Manuals
  2644. @cindex license for manuals
  2645. Please use the GNU Free Documentation License for all GNU manuals that
  2646. are more than a few pages long. Likewise for a collection of short
  2647. documents---you only need one copy of the GNU FDL for the whole
  2648. collection. For a single short document, you can use a very permissive
  2649. non-copyleft license, to avoid taking up space with a long license.
  2650. See @uref{http://www.gnu.org/copyleft/fdl-howto.html} for more explanation
  2651. of how to employ the GFDL.
  2652. Note that it is not obligatory to include a copy of the GNU GPL or GNU
  2653. LGPL in a manual whose license is neither the GPL nor the LGPL. It can
  2654. be a good idea to include the program's license in a large manual; in a
  2655. short manual, whose size would be increased considerably by including
  2656. the program's license, it is probably better not to include it.
  2657. @node Manual Credits
  2658. @section Manual Credits
  2659. @cindex credits for manuals
  2660. Please credit the principal human writers of the manual as the authors,
  2661. on the title page of the manual. If a company sponsored the work, thank
  2662. the company in a suitable place in the manual, but do not cite the
  2663. company as an author.
  2664. @node Printed Manuals
  2665. @section Printed Manuals
  2666. The FSF publishes some GNU manuals in printed form. To encourage sales
  2667. of these manuals, the on-line versions of the manual should mention at
  2668. the very start that the printed manual is available and should point at
  2669. information for getting it---for instance, with a link to the page
  2670. @url{http://www.gnu.org/order/order.html}. This should not be included
  2671. in the printed manual, though, because there it is redundant.
  2672. It is also useful to explain in the on-line forms of the manual how the
  2673. user can print out the manual from the sources.
  2674. @node NEWS File
  2675. @section The NEWS File
  2676. @cindex @file{NEWS} file
  2677. In addition to its manual, the package should have a file named
  2678. @file{NEWS} which contains a list of user-visible changes worth
  2679. mentioning. In each new release, add items to the front of the file and
  2680. identify the version they pertain to. Don't discard old items; leave
  2681. them in the file after the newer items. This way, a user upgrading from
  2682. any previous version can see what is new.
  2683. If the @file{NEWS} file gets very long, move some of the older items
  2684. into a file named @file{ONEWS} and put a note at the end referring the
  2685. user to that file.
  2686. @node Change Logs
  2687. @section Change Logs
  2688. @cindex change logs
  2689. Keep a change log to describe all the changes made to program source
  2690. files. The purpose of this is so that people investigating bugs in the
  2691. future will know about the changes that might have introduced the bug.
  2692. Often a new bug can be found by looking at what was recently changed.
  2693. More importantly, change logs can help you eliminate conceptual
  2694. inconsistencies between different parts of a program, by giving you a
  2695. history of how the conflicting concepts arose and who they came from.
  2696. @menu
  2697. * Change Log Concepts::
  2698. * Style of Change Logs::
  2699. * Simple Changes::
  2700. * Conditional Changes::
  2701. * Indicating the Part Changed::
  2702. @end menu
  2703. @node Change Log Concepts
  2704. @subsection Change Log Concepts
  2705. You can think of the change log as a conceptual ``undo list'' which
  2706. explains how earlier versions were different from the current version.
  2707. People can see the current version; they don't need the change log
  2708. to tell them what is in it. What they want from a change log is a
  2709. clear explanation of how the earlier version differed.
  2710. The change log file is normally called @file{ChangeLog} and covers an
  2711. entire directory. Each directory can have its own change log, or a
  2712. directory can use the change log of its parent directory---it's up to
  2713. you.
  2714. Another alternative is to record change log information with a version
  2715. control system such as RCS or CVS. This can be converted automatically
  2716. to a @file{ChangeLog} file using @code{rcs2log}; in Emacs, the command
  2717. @kbd{C-x v a} (@code{vc-update-change-log}) does the job.
  2718. There's no need to describe the full purpose of the changes or how
  2719. they work together. However, sometimes it is useful to write one line
  2720. to describe the overall purpose of a change or a batch of changes. If
  2721. you think that a change calls for explanation, you're probably right.
  2722. Please do explain it---but please put the full explanation in comments
  2723. in the code, where people will see it whenever they see the code. For
  2724. example, ``New function'' is enough for the change log when you add a
  2725. function, because there should be a comment before the function
  2726. definition to explain what it does.
  2727. In the past, we recommended not mentioning changes in non-software
  2728. files (manuals, help files, etc.) in change logs. However, we've been
  2729. advised that it is a good idea to include them, for the sake of
  2730. copyright records.
  2731. The easiest way to add an entry to @file{ChangeLog} is with the Emacs
  2732. command @kbd{M-x add-change-log-entry}. An entry should have an
  2733. asterisk, the name of the changed file, and then in parentheses the name
  2734. of the changed functions, variables or whatever, followed by a colon.
  2735. Then describe the changes you made to that function or variable.
  2736. @node Style of Change Logs
  2737. @subsection Style of Change Logs
  2738. @cindex change logs, style
  2739. Here are some simple examples of change log entries, starting with the
  2740. header line that says who made the change and when it was installed,
  2741. followed by descriptions of specific changes. (These examples are
  2742. drawn from Emacs and GCC.)
  2743. @example
  2744. 1998-08-17 Richard Stallman <rms@@gnu.org>
  2745. * register.el (insert-register): Return nil.
  2746. (jump-to-register): Likewise.
  2747. * sort.el (sort-subr): Return nil.
  2748. * tex-mode.el (tex-bibtex-file, tex-file, tex-region):
  2749. Restart the tex shell if process is gone or stopped.
  2750. (tex-shell-running): New function.
  2751. * expr.c (store_one_arg): Round size up for move_block_to_reg.
  2752. (expand_call): Round up when emitting USE insns.
  2753. * stmt.c (assign_parms): Round size up for move_block_from_reg.
  2754. @end example
  2755. It's important to name the changed function or variable in full. Don't
  2756. abbreviate function or variable names, and don't combine them.
  2757. Subsequent maintainers will often search for a function name to find all
  2758. the change log entries that pertain to it; if you abbreviate the name,
  2759. they won't find it when they search.
  2760. For example, some people are tempted to abbreviate groups of function
  2761. names by writing @samp{* register.el (@{insert,jump-to@}-register)};
  2762. this is not a good idea, since searching for @code{jump-to-register} or
  2763. @code{insert-register} would not find that entry.
  2764. Separate unrelated change log entries with blank lines. When two
  2765. entries represent parts of the same change, so that they work together,
  2766. then don't put blank lines between them. Then you can omit the file
  2767. name and the asterisk when successive entries are in the same file.
  2768. Break long lists of function names by closing continued lines with
  2769. @samp{)}, rather than @samp{,}, and opening the continuation with
  2770. @samp{(} as in this example:
  2771. @example
  2772. * keyboard.c (menu_bar_items, tool_bar_items)
  2773. (Fexecute_extended_command): Deal with 'keymap' property.
  2774. @end example
  2775. When you install someone else's changes, put the contributor's name in
  2776. the change log entry rather than in the text of the entry. In other
  2777. words, write this:
  2778. @example
  2779. 2002-07-14 John Doe <jdoe@@gnu.org>
  2780. * sewing.c: Make it sew.
  2781. @end example
  2782. @noindent
  2783. rather than this:
  2784. @example
  2785. 2002-07-14 Usual Maintainer <usual@@gnu.org>
  2786. * sewing.c: Make it sew. Patch by jdoe@@gnu.org.
  2787. @end example
  2788. As for the date, that should be the date you applied the change.
  2789. @node Simple Changes
  2790. @subsection Simple Changes
  2791. Certain simple kinds of changes don't need much detail in the change
  2792. log.
  2793. When you change the calling sequence of a function in a simple fashion,
  2794. and you change all the callers of the function to use the new calling
  2795. sequence, there is no need to make individual entries for all the
  2796. callers that you changed. Just write in the entry for the function
  2797. being called, ``All callers changed''---like this:
  2798. @example
  2799. * keyboard.c (Fcommand_execute): New arg SPECIAL.
  2800. All callers changed.
  2801. @end example
  2802. When you change just comments or doc strings, it is enough to write an
  2803. entry for the file, without mentioning the functions. Just ``Doc
  2804. fixes'' is enough for the change log.
  2805. There's no technical need to make change log entries for documentation
  2806. files. This is because documentation is not susceptible to bugs that
  2807. are hard to fix. Documentation does not consist of parts that must
  2808. interact in a precisely engineered fashion. To correct an error, you
  2809. need not know the history of the erroneous passage; it is enough to
  2810. compare what the documentation says with the way the program actually
  2811. works.
  2812. However, you should keep change logs for documentation files when the
  2813. project gets copyright assignments from its contributors, so as to
  2814. make the records of authorship more accurate.
  2815. @node Conditional Changes
  2816. @subsection Conditional Changes
  2817. @cindex conditional changes, and change logs
  2818. @cindex change logs, conditional changes
  2819. Source files can often contain code that is conditional to build-time
  2820. or static conditions. For example, C programs can contain
  2821. compile-time @code{#if} conditionals; programs implemented in
  2822. interpreted languages can contain module imports of function
  2823. definitions that are only performed for certain versions of the
  2824. interpreter; and Automake @file{Makefile.am} files can contain
  2825. variable definitions or target declarations that are only to be
  2826. considered if a configure-time Automake conditional is true.
  2827. Many changes are conditional as well: sometimes you add a new variable,
  2828. or function, or even a new program or library, which is entirely
  2829. dependent on a build-time condition. It is useful to indicate
  2830. in the change log the conditions for which a change applies.
  2831. Our convention for indicating conditional changes is to use
  2832. @emph{square brackets around the name of the condition}.
  2833. Conditional changes can happen in numerous scenarios and with many
  2834. variations, so here are some examples to help clarify. This first
  2835. example describes changes in C, Perl, and Python files which are
  2836. conditional but do not have an associated function or entity name:
  2837. @example
  2838. * xterm.c [SOLARIS2]: Include <string.h>.
  2839. * FilePath.pm [$^O eq 'VMS']: Import the VMS::Feature module.
  2840. * framework.py [sys.version_info < (2, 6)]: Make "with" statement
  2841. available by importing it from __future__,
  2842. to support also python 2.5.
  2843. @end example
  2844. Our other examples will for simplicity be limited to C, as the minor
  2845. changes necessary to adapt them to other languages should be
  2846. self-evident.
  2847. Next, here is an entry describing a new definition which is entirely
  2848. conditional: the C macro @code{FRAME_WINDOW_P} is defined (and used)
  2849. only when the macro @code{HAVE_X_WINDOWS} is defined:
  2850. @example
  2851. * frame.h [HAVE_X_WINDOWS] (FRAME_WINDOW_P): Macro defined.
  2852. @end example
  2853. Next, an entry for a change within the function @code{init_display},
  2854. whose definition as a whole is unconditional, but the changes
  2855. themselves are contained in a @samp{#ifdef HAVE_LIBNCURSES}
  2856. conditional:
  2857. @example
  2858. * dispnew.c (init_display) [HAVE_LIBNCURSES]: If X, call tgetent.
  2859. @end example
  2860. Finally, here is an entry for a change that takes effect only when
  2861. a certain macro is @emph{not} defined:
  2862. @example
  2863. (gethostname) [!HAVE_SOCKETS]: Replace with winsock version.
  2864. @end example
  2865. @node Indicating the Part Changed
  2866. @subsection Indicating the Part Changed
  2867. Indicate the part of a function which changed by using angle brackets
  2868. enclosing an indication of what the changed part does. Here is an entry
  2869. for a change in the part of the function @code{sh-while-getopts} that
  2870. deals with @code{sh} commands:
  2871. @example
  2872. * progmodes/sh-script.el (sh-while-getopts) <sh>: Handle case that
  2873. user-specified option string is empty.
  2874. @end example
  2875. @node Man Pages
  2876. @section Man Pages
  2877. @cindex man pages
  2878. In the GNU project, man pages are secondary. It is not necessary or
  2879. expected for every GNU program to have a man page, but some of them do.
  2880. It's your choice whether to include a man page in your program.
  2881. When you make this decision, consider that supporting a man page
  2882. requires continual effort each time the program is changed. The time
  2883. you spend on the man page is time taken away from more useful work.
  2884. For a simple program which changes little, updating the man page may be
  2885. a small job. Then there is little reason not to include a man page, if
  2886. you have one.
  2887. For a large program that changes a great deal, updating a man page may
  2888. be a substantial burden. If a user offers to donate a man page, you may
  2889. find this gift costly to accept. It may be better to refuse the man
  2890. page unless the same person agrees to take full responsibility for
  2891. maintaining it---so that you can wash your hands of it entirely. If
  2892. this volunteer later ceases to do the job, then don't feel obliged to
  2893. pick it up yourself; it may be better to withdraw the man page from the
  2894. distribution until someone else agrees to update it.
  2895. When a program changes only a little, you may feel that the
  2896. discrepancies are small enough that the man page remains useful without
  2897. updating. If so, put a prominent note near the beginning of the man
  2898. page explaining that you don't maintain it and that the Texinfo manual
  2899. is more authoritative. The note should say how to access the Texinfo
  2900. documentation.
  2901. Be sure that man pages include a copyright statement and free license.
  2902. The simple all-permissive license is appropriate for simple man pages
  2903. (@pxref{License Notices for Other Files,,,maintain,Information for GNU
  2904. Maintainers}).
  2905. For long man pages, with enough explanation and documentation that
  2906. they can be considered true manuals, use the GFDL (@pxref{License for
  2907. Manuals}).
  2908. Finally, the GNU help2man program
  2909. (@uref{http://www.gnu.org/software/help2man/}) is one way to automate
  2910. generation of a man page, in this case from @option{--help} output.
  2911. This is sufficient in many cases.
  2912. @node Reading other Manuals
  2913. @section Reading other Manuals
  2914. There may be non-free books or documentation files that describe the
  2915. program you are documenting.
  2916. It is ok to use these documents for reference, just as the author of a
  2917. new algebra textbook can read other books on algebra. A large portion
  2918. of any non-fiction book consists of facts, in this case facts about how
  2919. a certain program works, and these facts are necessarily the same for
  2920. everyone who writes about the subject. But be careful not to copy your
  2921. outline structure, wording, tables or examples from preexisting non-free
  2922. documentation. Copying from free documentation may be ok; please check
  2923. with the FSF about the individual case.
  2924. @node Managing Releases
  2925. @chapter The Release Process
  2926. @cindex releasing
  2927. Making a release is more than just bundling up your source files in a
  2928. tar file and putting it up for FTP. You should set up your software so
  2929. that it can be configured to run on a variety of systems. Your Makefile
  2930. should conform to the GNU standards described below, and your directory
  2931. layout should also conform to the standards discussed below. Doing so
  2932. makes it easy to include your package into the larger framework of
  2933. all GNU software.
  2934. @menu
  2935. * Configuration:: How configuration of GNU packages should work.
  2936. * Makefile Conventions:: Makefile conventions.
  2937. * Releases:: Making releases
  2938. @end menu
  2939. @node Configuration
  2940. @section How Configuration Should Work
  2941. @cindex program configuration
  2942. @pindex configure
  2943. Each GNU distribution should come with a shell script named
  2944. @code{configure}. This script is given arguments which describe the
  2945. kind of machine and system you want to compile the program for.
  2946. The @code{configure} script must record the configuration options so
  2947. that they affect compilation.
  2948. The description here is the specification of the interface for the
  2949. @code{configure} script in GNU packages. Many packages implement it
  2950. using GNU Autoconf (@pxref{Top,, Introduction, autoconf, Autoconf})
  2951. and/or GNU Automake (@pxref{Top,, Introduction, automake, Automake}),
  2952. but you do not have to use these tools. You can implement it any way
  2953. you like; for instance, by making @code{configure} be a wrapper around
  2954. a completely different configuration system.
  2955. Another way for the @code{configure} script to operate is to make a
  2956. link from a standard name such as @file{config.h} to the proper
  2957. configuration file for the chosen system. If you use this technique,
  2958. the distribution should @emph{not} contain a file named
  2959. @file{config.h}. This is so that people won't be able to build the
  2960. program without configuring it first.
  2961. Another thing that @code{configure} can do is to edit the Makefile. If
  2962. you do this, the distribution should @emph{not} contain a file named
  2963. @file{Makefile}. Instead, it should include a file @file{Makefile.in} which
  2964. contains the input used for editing. Once again, this is so that people
  2965. won't be able to build the program without configuring it first.
  2966. If @code{configure} does write the @file{Makefile}, then @file{Makefile}
  2967. should have a target named @file{Makefile} which causes @code{configure}
  2968. to be rerun, setting up the same configuration that was set up last
  2969. time. The files that @code{configure} reads should be listed as
  2970. dependencies of @file{Makefile}.
  2971. All the files which are output from the @code{configure} script should
  2972. have comments at the beginning explaining that they were generated
  2973. automatically using @code{configure}. This is so that users won't think
  2974. of trying to edit them by hand.
  2975. The @code{configure} script should write a file named @file{config.status}
  2976. which describes which configuration options were specified when the
  2977. program was last configured. This file should be a shell script which,
  2978. if run, will recreate the same configuration.
  2979. The @code{configure} script should accept an option of the form
  2980. @samp{--srcdir=@var{dirname}} to specify the directory where sources are found
  2981. (if it is not the current directory). This makes it possible to build
  2982. the program in a separate directory, so that the actual source directory
  2983. is not modified.
  2984. If the user does not specify @samp{--srcdir}, then @code{configure} should
  2985. check both @file{.} and @file{..} to see if it can find the sources. If
  2986. it finds the sources in one of these places, it should use them from
  2987. there. Otherwise, it should report that it cannot find the sources, and
  2988. should exit with nonzero status.
  2989. Usually the easy way to support @samp{--srcdir} is by editing a
  2990. definition of @code{VPATH} into the Makefile. Some rules may need to
  2991. refer explicitly to the specified source directory. To make this
  2992. possible, @code{configure} can add to the Makefile a variable named
  2993. @code{srcdir} whose value is precisely the specified directory.
  2994. In addition, the @samp{configure} script should take options
  2995. corresponding to most of the standard directory variables
  2996. (@pxref{Directory Variables}). Here is the list:
  2997. @example
  2998. --prefix --exec-prefix --bindir --sbindir --libexecdir --sysconfdir
  2999. --sharedstatedir --localstatedir --libdir --includedir --oldincludedir
  3000. --datarootdir --datadir --infodir --localedir --mandir --docdir
  3001. --htmldir --dvidir --pdfdir --psdir
  3002. @end example
  3003. The @code{configure} script should also take an argument which specifies the
  3004. type of system to build the program for. This argument should look like
  3005. this:
  3006. @example
  3007. @var{cpu}-@var{company}-@var{system}
  3008. @end example
  3009. For example, an Athlon-based GNU/Linux system might be
  3010. @samp{i686-pc-linux-gnu}.
  3011. The @code{configure} script needs to be able to decode all plausible
  3012. alternatives for how to describe a machine. Thus,
  3013. @samp{athlon-pc-gnu/linux} would be a valid alias. There is a shell
  3014. script called
  3015. @uref{http://git.savannah.gnu.org/@/gitweb/@/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD,
  3016. @file{config.sub}} that you can use as a subroutine to validate system
  3017. types and canonicalize aliases.
  3018. The @code{configure} script should also take the option
  3019. @option{--build=@var{buildtype}}, which should be equivalent to a
  3020. plain @var{buildtype} argument. For example, @samp{configure
  3021. --build=i686-pc-linux-gnu} is equivalent to @samp{configure
  3022. i686-pc-linux-gnu}. When the build type is not specified by an option
  3023. or argument, the @code{configure} script should normally guess it using
  3024. the shell script
  3025. @uref{http://git.savannah.gnu.org/@/gitweb/@/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD,
  3026. @file{config.guess}}.
  3027. @cindex optional features, configure-time
  3028. Other options are permitted to specify in more detail the software
  3029. or hardware present on the machine, to include or exclude optional parts
  3030. of the package, or to adjust the name of some tools or arguments to them:
  3031. @table @samp
  3032. @item --enable-@var{feature}@r{[}=@var{parameter}@r{]}
  3033. Configure the package to build and install an optional user-level
  3034. facility called @var{feature}. This allows users to choose which
  3035. optional features to include. Giving an optional @var{parameter} of
  3036. @samp{no} should omit @var{feature}, if it is built by default.
  3037. No @samp{--enable} option should @strong{ever} cause one feature to
  3038. replace another. No @samp{--enable} option should ever substitute one
  3039. useful behavior for another useful behavior. The only proper use for
  3040. @samp{--enable} is for questions of whether to build part of the program
  3041. or exclude it.
  3042. @item --with-@var{package}
  3043. @c @r{[}=@var{parameter}@r{]}
  3044. The package @var{package} will be installed, so configure this package
  3045. to work with @var{package}.
  3046. @c Giving an optional @var{parameter} of
  3047. @c @samp{no} should omit @var{package}, if it is used by default.
  3048. Possible values of @var{package} include
  3049. @samp{gnu-as} (or @samp{gas}), @samp{gnu-ld}, @samp{gnu-libc},
  3050. @samp{gdb},
  3051. @samp{x},
  3052. and
  3053. @samp{x-toolkit}.
  3054. Do not use a @samp{--with} option to specify the file name to use to
  3055. find certain files. That is outside the scope of what @samp{--with}
  3056. options are for.
  3057. @item @var{variable}=@var{value}
  3058. Set the value of the variable @var{variable} to @var{value}. This is
  3059. used to override the default values of commands or arguments in the
  3060. build process. For example, the user could issue @samp{configure
  3061. CFLAGS=-g CXXFLAGS=-g} to build with debugging information and without
  3062. the default optimization.
  3063. Specifying variables as arguments to @code{configure}, like this:
  3064. @example
  3065. ./configure CC=gcc
  3066. @end example
  3067. is preferable to setting them in environment variables:
  3068. @example
  3069. CC=gcc ./configure
  3070. @end example
  3071. as it helps to recreate the same configuration later with
  3072. @file{config.status}. However, both methods should be supported.
  3073. @end table
  3074. All @code{configure} scripts should accept all of the ``detail''
  3075. options and the variable settings, whether or not they make any
  3076. difference to the particular package at hand. In particular, they
  3077. should accept any option that starts with @samp{--with-} or
  3078. @samp{--enable-}. This is so users will be able to configure an
  3079. entire GNU source tree at once with a single set of options.
  3080. You will note that the categories @samp{--with-} and @samp{--enable-}
  3081. are narrow: they @strong{do not} provide a place for any sort of option
  3082. you might think of. That is deliberate. We want to limit the possible
  3083. configuration options in GNU software. We do not want GNU programs to
  3084. have idiosyncratic configuration options.
  3085. Packages that perform part of the compilation process may support
  3086. cross-compilation. In such a case, the host and target machines for the
  3087. program may be different.
  3088. The @code{configure} script should normally treat the specified type of
  3089. system as both the host and the target, thus producing a program which
  3090. works for the same type of machine that it runs on.
  3091. To compile a program to run on a host type that differs from the build
  3092. type, use the configure option @option{--host=@var{hosttype}}, where
  3093. @var{hosttype} uses the same syntax as @var{buildtype}. The host type
  3094. normally defaults to the build type.
  3095. To configure a cross-compiler, cross-assembler, or what have you, you
  3096. should specify a target different from the host, using the configure
  3097. option @samp{--target=@var{targettype}}. The syntax for
  3098. @var{targettype} is the same as for the host type. So the command would
  3099. look like this:
  3100. @example
  3101. ./configure --host=@var{hosttype} --target=@var{targettype}
  3102. @end example
  3103. The target type normally defaults to the host type.
  3104. Programs for which cross-operation is not meaningful need not accept the
  3105. @samp{--target} option, because configuring an entire operating system for
  3106. cross-operation is not a meaningful operation.
  3107. Some programs have ways of configuring themselves automatically. If
  3108. your program is set up to do this, your @code{configure} script can simply
  3109. ignore most of its arguments.
  3110. @comment The makefile standards are in a separate file that is also
  3111. @comment included by make.texinfo. Done by roland@gnu.ai.mit.edu on 1/6/93.
  3112. @comment For this document, turn chapters into sections, etc.
  3113. @lowersections
  3114. @include make-stds.texi
  3115. @raisesections
  3116. @node Releases
  3117. @section Making Releases
  3118. @cindex packaging
  3119. You should identify each release with a pair of version numbers, a
  3120. major version and a minor. We have no objection to using more than
  3121. two numbers, but it is very unlikely that you really need them.
  3122. Package the distribution of @code{Foo version 69.96} up in a gzipped tar
  3123. file with the name @file{foo-69.96.tar.gz}. It should unpack into a
  3124. subdirectory named @file{foo-69.96}.
  3125. Building and installing the program should never modify any of the files
  3126. contained in the distribution. This means that all the files that form
  3127. part of the program in any way must be classified into @dfn{source
  3128. files} and @dfn{non-source files}. Source files are written by humans
  3129. and never changed automatically; non-source files are produced from
  3130. source files by programs under the control of the Makefile.
  3131. @cindex @file{README} file
  3132. The distribution should contain a file named @file{README} which gives
  3133. the name of the package, and a general description of what it does. It
  3134. is also good to explain the purpose of each of the first-level
  3135. subdirectories in the package, if there are any. The @file{README} file
  3136. should either state the version number of the package, or refer to where
  3137. in the package it can be found.
  3138. The @file{README} file should refer to the file @file{INSTALL}, which
  3139. should contain an explanation of the installation procedure.
  3140. The @file{README} file should also refer to the file which contains the
  3141. copying conditions. The GNU GPL, if used, should be in a file called
  3142. @file{COPYING}. If the GNU LGPL is used, it should be in a file called
  3143. @file{COPYING.LESSER}.
  3144. Naturally, all the source files must be in the distribution. It is
  3145. okay to include non-source files in the distribution along with the
  3146. source files they are generated from, provided they are up-to-date
  3147. with the source they are made from, and machine-independent, so that
  3148. normal building of the distribution will never modify them. We
  3149. commonly include non-source files produced by Autoconf, Automake,
  3150. Bison, @code{lex}, @TeX{}, and @code{makeinfo}; this helps avoid
  3151. unnecessary dependencies between our distributions, so that users can
  3152. install whichever packages they want to install.
  3153. Non-source files that might actually be modified by building and
  3154. installing the program should @strong{never} be included in the
  3155. distribution. So if you do distribute non-source files, always make
  3156. sure they are up to date when you make a new distribution.
  3157. Make sure that all the files in the distribution are world-readable, and
  3158. that directories are world-readable and world-searchable (octal mode 755).
  3159. We used to recommend that all directories in the distribution also be
  3160. world-writable (octal mode 777), because ancient versions of @code{tar}
  3161. would otherwise not cope when extracting the archive as an unprivileged
  3162. user. That can easily lead to security issues when creating the archive,
  3163. however, so now we recommend against that.
  3164. Don't include any symbolic links in the distribution itself. If the tar
  3165. file contains symbolic links, then people cannot even unpack it on
  3166. systems that don't support symbolic links. Also, don't use multiple
  3167. names for one file in different directories, because certain file
  3168. systems cannot handle this and that prevents unpacking the
  3169. distribution.
  3170. Try to make sure that all the file names will be unique on MS-DOS. A
  3171. name on MS-DOS consists of up to 8 characters, optionally followed by a
  3172. period and up to three characters. MS-DOS will truncate extra
  3173. characters both before and after the period. Thus,
  3174. @file{foobarhacker.c} and @file{foobarhacker.o} are not ambiguous; they
  3175. are truncated to @file{foobarha.c} and @file{foobarha.o}, which are
  3176. distinct.
  3177. @cindex @file{texinfo.tex}, in a distribution
  3178. Include in your distribution a copy of the @file{texinfo.tex} you used
  3179. to test print any @file{*.texinfo} or @file{*.texi} files.
  3180. Likewise, if your program uses small GNU software packages like regex,
  3181. getopt, obstack, or termcap, include them in the distribution file.
  3182. Leaving them out would make the distribution file a little smaller at
  3183. the expense of possible inconvenience to a user who doesn't know what
  3184. other files to get.
  3185. @node References
  3186. @chapter References to Non-Free Software and Documentation
  3187. @cindex references to non-free material
  3188. A GNU program should not recommend, promote, or grant legitimacy to
  3189. the use of any non-free program. Proprietary software is a social and
  3190. ethical problem, and our aim is to put an end to that problem. We
  3191. can't stop some people from writing proprietary programs, or stop
  3192. other people from using them, but we can and should refuse to
  3193. advertise them to new potential customers, or to give the public the
  3194. idea that their existence is ethical.
  3195. The GNU definition of free software is found on the GNU web site at
  3196. @url{http://www.gnu.org/@/philosophy/@/free-sw.html}, and the definition
  3197. of free documentation is found at
  3198. @url{http://www.gnu.org/@/philosophy/@/free-doc.html}. The terms ``free''
  3199. and ``non-free'', used in this document, refer to those definitions.
  3200. A list of important licenses and whether they qualify as free is in
  3201. @url{http://www.gnu.org/@/licenses/@/license-list.html}. If it is not
  3202. clear whether a license qualifies as free, please ask the GNU Project
  3203. by writing to @email{licensing@@gnu.org}. We will answer, and if the
  3204. license is an important one, we will add it to the list.
  3205. When a non-free program or system is well known, you can mention it in
  3206. passing---that is harmless, since users who might want to use it
  3207. probably already know about it. For instance, it is fine to explain
  3208. how to build your package on top of some widely used non-free
  3209. operating system, or how to use it together with some widely used
  3210. non-free program.
  3211. However, you should give only the necessary information to help those
  3212. who already use the non-free program to use your program with
  3213. it---don't give, or refer to, any further information about the
  3214. proprietary program, and don't imply that the proprietary program
  3215. enhances your program, or that its existence is in any way a good
  3216. thing. The goal should be that people already using the proprietary
  3217. program will get the advice they need about how to use your free
  3218. program with it, while people who don't already use the proprietary
  3219. program will not see anything likely to lead them to take an interest
  3220. in it.
  3221. If a non-free program or system is obscure in your program's domain,
  3222. your program should not mention or support it at all, since doing so
  3223. would tend to popularize the non-free program more than it popularizes
  3224. your program. (You cannot hope to find many additional users for your
  3225. program among the users of Foobar, if the existence of Foobar is not
  3226. generally known among people who might want to use your program.)
  3227. Sometimes a program is free software in itself but depends on a
  3228. non-free platform in order to run. For instance, many Java programs
  3229. depend on some non-free Java libraries. To recommend or promote such
  3230. a program is to promote the other programs it needs. This is why we
  3231. are careful about listing Java programs in the Free Software
  3232. Directory: we don't want to promote the non-free Java libraries.
  3233. We hope this particular problem with Java will be gone by and by, as
  3234. we replace the remaining non-free standard Java libraries with free
  3235. software, but the general principle will remain the same: don't
  3236. recommend, promote or legitimize programs that depend on non-free
  3237. software to run.
  3238. Some free programs strongly encourage the use of non-free software. A
  3239. typical example is @command{mplayer}. It is free software in itself,
  3240. and the free code can handle some kinds of files. However,
  3241. @command{mplayer} recommends use of non-free codecs for other kinds of
  3242. files, and users that install @command{mplayer} are very likely to
  3243. install those codecs along with it. To recommend @command{mplayer}
  3244. is, in effect, to promote use of the non-free codecs.
  3245. Thus, you should not recommend programs that strongly encourage the
  3246. use of non-free software. This is why we do not list
  3247. @command{mplayer} in the Free Software Directory.
  3248. A GNU package should not refer the user to any non-free documentation
  3249. for free software. Free documentation that can be included in free
  3250. operating systems is essential for completing the GNU system, or any
  3251. free operating system, so encouraging it is a priority; to recommend
  3252. use of documentation that we are not allowed to include undermines the
  3253. impetus for the community to produce documentation that we can
  3254. include. So GNU packages should never recommend non-free
  3255. documentation.
  3256. By contrast, it is ok to refer to journal articles and textbooks in
  3257. the comments of a program for explanation of how it functions, even
  3258. though they are non-free. This is because we don't include such
  3259. things in the GNU system even if they are free---they are outside the
  3260. scope of what a software distribution needs to include.
  3261. Referring to a web site that describes or recommends a non-free
  3262. program is promoting that program, so please do not make links to (or
  3263. mention by name) web sites that contain such material. This policy is
  3264. relevant particularly for the web pages for a GNU package.
  3265. Following links from nearly any web site can lead eventually to
  3266. non-free software; this is inherent in the nature of the web. So it
  3267. makes no sense to criticize a site for having such links. As long as
  3268. the site does not itself recommend a non-free program, there is no
  3269. need to consider the question of the sites that it links to for other
  3270. reasons.
  3271. Thus, for example, you should not refer to AT&T's web site if that
  3272. recommends AT&T's non-free software packages; you should not refer to
  3273. a site that links to AT&T's site presenting it as a place to get some
  3274. non-free program, because that link recommends and legitimizes the
  3275. non-free program. However, that a site contains a link to AT&T's web
  3276. site for some other purpose (such as long-distance telephone service)
  3277. is not an objection against it.
  3278. @node GNU Free Documentation License
  3279. @appendix GNU Free Documentation License
  3280. @cindex FDL, GNU Free Documentation License
  3281. @include fdl.texi
  3282. @node Index
  3283. @unnumbered Index
  3284. @printindex cp
  3285. @bye
  3286. Local variables:
  3287. eval: (add-hook 'write-file-hooks 'time-stamp)
  3288. time-stamp-start: "@set lastupdate "
  3289. time-stamp-end: "$"
  3290. time-stamp-format: "%:b %:d, %:y"
  3291. compile-command: "cd work.s && make"
  3292. End: