| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667 | \input texinfo @c -*-texinfo-*-@comment ========================================================@comment %**start of header@setfilename autoconf.info@include version.texi@settitle Autoconf@setchapternewpage odd@ifnothtml@setcontentsaftertitlepage@end ifnothtml@finalout@c @ovar(ARG)@c ----------@c The ARG is an optional argument.  To be used for macro arguments in@c their documentation (@defmac).@macro ovar{varname}@r{[}@var{\varname\}@r{]}@c@end macro@c @dvar(ARG, DEFAULT)@c -------------------@c The ARG is an optional argument, defaulting to DEFAULT.  To be used@c for macro arguments in their documentation (@defmac).@macro dvar{varname, default}@r{[}@var{\varname\} = @samp{\default\}@r{]}@c@end macro@c Handling the indexes with Texinfo yields several different problems.@c@c Because we want to drop out the AC_ part of the macro names in the@c printed manual, but not in the other outputs, we need a layer above@c the usual @acindex{} etc.  That's why we first define indexes such as@c acx meant to become the macro @acindex.  First of all, using ``ac_''@c does not work with makeinfo, and using ``ac1'' doesn't work with TeX.@c So use something more regular ``acx''.  Then you finish with a printed@c index saying ``index is not existent''.  Of course: you ought to use@c two letters :(  So you use capitals.@c@c Second, when defining a macro in the TeX world, following spaces are@c eaten.  But then, since we embed @acxindex commands that use the end@c of line as an end marker, the whole things wrecks itself.  So make@c sure you do *force* an additional end of line, add a ``@c''.@c@c Finally, you might want to get rid of TeX expansion, using --expand@c with texi2dvi.  But then you wake up an old problem: we use macros@c in @defmac etc. where TeX does perform the expansion, but not makeinfo.@c Define an environment variable index, for variables users may set@c in their environment or on the configure command line.@defcodeindex ev@c Define an output variable index, for commonly AC_SUBST'ed variables.@defcodeindex ov@c Define a cache variable index, for variables matching *_cv_*.@defcodeindex CA@c Other shell variables not fitting the above categories should be@c listed in the predefined vrindex, which we merge in the concept index.@syncodeindex vr cp@c Define a CPP preprocessor macro index, for #define'd strings.@defcodeindex cv@c Define an Autoconf macro index that @defmac doesn't write to.@defcodeindex AC@c Define an Autotest macro index that @defmac doesn't write to.@defcodeindex AT@c Define an M4sugar macro index that @defmac doesn't write to.@defcodeindex MS@c Define an index for *foreign* programs: `mv' etc.  Used for the@c portability sections and so on.@defindex pr@c shortindexflag@c --------------@c Shall we factor AC_ out of the Autoconf macro index etc.?@iftex@set shortindexflag@end iftex@c @acindex{MACRO}@c ---------------@c Registering an AC_\MACRO\.@ifset shortindexflag@macro acindex{macro}@ACindex \macro\@c@end macro@end ifset@ifclear shortindexflag@macro acindex{macro}@ACindex AC_\macro\@end macro@end ifclear@c @ahindex{MACRO}@c ---------------@c Registering an AH_\MACRO\.@macro ahindex{macro}@ACindex AH_\macro\@c@end macro@c @asindex{MACRO}@c ---------------@c Registering an AS_\MACRO\.@ifset shortindexflag@macro asindex{macro}@MSindex \macro\@c@end macro@end ifset@ifclear shortindexflag@macro asindex{macro}@MSindex AS_\macro\@end macro@end ifclear@c @atindex{MACRO}@c ---------------@c Registering an AT_\MACRO\.@ifset shortindexflag@macro atindex{macro}@ATindex \macro\@c@end macro@end ifset@ifclear shortindexflag@macro atindex{macro}@ATindex AT_\macro\@end macro@end ifclear@c @auindex{MACRO}@c ---------------@c Registering an AU_\MACRO\.@macro auindex{macro}@ACindex AU_\macro\@c@end macro@c @hdrindex{MACRO}@c ----------------@c Indexing a header.@macro hdrindex{macro}@prindex @file{\macro\}@c@end macro@c @msindex{MACRO}@c ---------------@c Registering an m4_\MACRO\.@ifset shortindexflag@macro msindex{macro}@MSindex \macro\@c@end macro@end ifset@ifclear shortindexflag@macro msindex{macro}@MSindex m4_\macro\@end macro@end ifclear@c @caindex{VARIABLE}@c ------------------@c Registering an ac_cv_\VARIABLE\ cache variable.@ifset shortindexflag@macro caindex{macro}@CAindex \macro\@end macro@end ifset@ifclear shortindexflag@macro caindex{macro}@CAindex ac_cv_\macro\@end macro@end ifclear@c Define an index for functions: `alloca' etc.  Used for the@c portability sections and so on.  We can't use `fn' (aka `fnindex),@c since `@defmac' goes into it => we'd get all the macros too.@c   FIXME: Aaarg!  It seems there are too many indices for TeX :(@c@c   ! No room for a new @write .@c   l.112 @defcodeindex fu@c@c   so don't define yet another one :(  Just put some tags before each@c   @prindex which is actually a @funindex.@c@c   @defcodeindex fu@c@c@c   @c Put the programs and functions into their own index.@c   @syncodeindex fu pr@comment %**end of header@comment ========================================================@copyingThis manual (@value{UPDATED}) is for GNU Autoconf(version @value{VERSION}),a package for creating scripts to configure source code packages usingtemplates and an M4 macro package.Copyright @copyright{} 1992-1996, 1998-2012 Free Software Foundation,Inc.@quotationPermission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License,Version 1.3 or any later version published by the Free SoftwareFoundation; with no Invariant Sections, no Front-Cover texts, andno Back-Cover Texts.  A copy of the license is included in the sectionentitled ``GNU Free Documentation License.''@end quotation@end copying@dircategory Software development@direntry* Autoconf: (autoconf).         Create source code configuration scripts.@end direntry@dircategory Individual utilities@direntry* autoscan: (autoconf)autoscan Invocation.                                Semi-automatic @file{configure.ac} writing* ifnames: (autoconf)ifnames Invocation.        Listing conditionals in source.* autoconf-invocation: (autoconf)autoconf Invocation.                                How to create configuration scripts* autoreconf: (autoconf)autoreconf Invocation.                                Remaking multiple @command{configure} scripts* autoheader: (autoconf)autoheader Invocation.                                How to create configuration templates* autom4te: (autoconf)autom4te Invocation.                                The Autoconf executables backbone* configure: (autoconf)configure Invocation.    Configuring a package.* autoupdate: (autoconf)autoupdate Invocation.                                Automatic update of @file{configure.ac}* config.status: (autoconf)config.status Invocation. Recreating configurations.* testsuite: (autoconf)testsuite Invocation.    Running an Autotest test suite.@end direntry@titlepage@title Autoconf@subtitle Creating Automatic Configuration Scripts@subtitle for version @value{VERSION}, @value{UPDATED}@author David MacKenzie@author Ben Elliston@author Akim Demaille@page@vskip 0pt plus 1filll@insertcopying@end titlepage@contents@ifnottex@node Top@top Autoconf@insertcopying@end ifnottex@c The master menu, created with texinfo-master-menu, goes here.@menu* Introduction::                Autoconf's purpose, strengths, and weaknesses* The GNU Build System::        A set of tools for portable software packages* Making configure Scripts::    How to organize and produce Autoconf scripts* Setup::                       Initialization and output* Existing Tests::              Macros that check for particular features* Writing Tests::               How to write new feature checks* Results::                     What to do with results from feature checks* Programming in M4::           Layers on top of which Autoconf is written* Programming in M4sh::         Shell portability layer* Writing Autoconf Macros::     Adding new macros to Autoconf* Portable Shell::              Shell script portability pitfalls* Portable Make::               Makefile portability pitfalls* Portable C and C++::          C and C++ portability pitfalls* Manual Configuration::        Selecting features that can't be guessed* Site Configuration::          Local defaults for @command{configure}* Running configure Scripts::   How to use the Autoconf output* config.status Invocation::    Recreating a configuration* Obsolete Constructs::         Kept for backward compatibility* Using Autotest::              Creating portable test suites* FAQ::                         Frequent Autoconf Questions, with answers* History::                     History of Autoconf* GNU Free Documentation License::  License for copying this manual* Indices::                     Indices of symbols, concepts, etc.@detailmenu --- The Detailed Node Listing ---The GNU Build System* Automake::                    Escaping makefile hell* Gnulib::                      The GNU portability library* Libtool::                     Building libraries portably* Pointers::                    More info on the GNU build systemMaking @command{configure} Scripts* Writing Autoconf Input::      What to put in an Autoconf input file* autoscan Invocation::         Semi-automatic @file{configure.ac} writing* ifnames Invocation::          Listing the conditionals in source code* autoconf Invocation::         How to create configuration scripts* autoreconf Invocation::       Remaking multiple @command{configure} scriptsWriting @file{configure.ac}* Shell Script Compiler::       Autoconf as solution of a problem* Autoconf Language::           Programming in Autoconf* Autoconf Input Layout::       Standard organization of @file{configure.ac}Initialization and Output Files* Initializing configure::      Option processing etc.* Versioning::                  Dealing with Autoconf versions* Notices::                     Copyright, version numbers in @command{configure}* Input::                       Where Autoconf should find files* Output::                      Outputting results from the configuration* Configuration Actions::       Preparing the output based on results* Configuration Files::         Creating output files* Makefile Substitutions::      Using output variables in makefiles* Configuration Headers::       Creating a configuration header file* Configuration Commands::      Running arbitrary instantiation commands* Configuration Links::         Links depending on the configuration* Subdirectories::              Configuring independent packages together* Default Prefix::              Changing the default installation prefixSubstitutions in Makefiles* Preset Output Variables::     Output variables that are always set* Installation Directory Variables::  Other preset output variables* Changed Directory Variables::  Warnings about @file{datarootdir}* Build Directories::           Supporting multiple concurrent compiles* Automatic Remaking::          Makefile rules for configuringConfiguration Header Files* Header Templates::            Input for the configuration headers* autoheader Invocation::       How to create configuration templates* Autoheader Macros::           How to specify CPP templatesExisting Tests* Common Behavior::             Macros' standard schemes* Alternative Programs::        Selecting between alternative programs* Files::                       Checking for the existence of files* Libraries::                   Library archives that might be missing* Library Functions::           C library functions that might be missing* Header Files::                Header files that might be missing* Declarations::                Declarations that may be missing* Structures::                  Structures or members that might be missing* Types::                       Types that might be missing* Compilers and Preprocessors::  Checking for compiling programs* System Services::             Operating system services* Posix Variants::              Special kludges for specific Posix variants* Erlang Libraries::            Checking for the existence of Erlang librariesCommon Behavior* Standard Symbols::            Symbols defined by the macros* Default Includes::            Includes used by the generic macrosAlternative Programs* Particular Programs::         Special handling to find certain programs* Generic Programs::            How to find other programsLibrary Functions* Function Portability::        Pitfalls with usual functions* Particular Functions::        Special handling to find certain functions* Generic Functions::           How to find other functionsHeader Files* Header Portability::          Collected knowledge on common headers* Particular Headers::          Special handling to find certain headers* Generic Headers::             How to find other headersDeclarations* Particular Declarations::     Macros to check for certain declarations* Generic Declarations::        How to find other declarationsStructures* Particular Structures::       Macros to check for certain structure members* Generic Structures::          How to find other structure membersTypes* Particular Types::            Special handling to find certain types* Generic Types::               How to find other typesCompilers and Preprocessors* Specific Compiler Characteristics::  Some portability issues* Generic Compiler Characteristics::  Language independent tests and features* C Compiler::                  Checking its characteristics* C++ Compiler::                Likewise* Objective C Compiler::        Likewise* Objective C++ Compiler::      Likewise* Erlang Compiler and Interpreter::  Likewise* Fortran Compiler::            Likewise* Go Compiler::                 LikewiseWriting Tests* Language Choice::             Selecting which language to use for testing* Writing Test Programs::       Forging source files for compilers* Running the Preprocessor::    Detecting preprocessor symbols* Running the Compiler::        Detecting language or header features* Running the Linker::          Detecting library features* Runtime::                     Testing for runtime features* Systemology::                 A zoology of operating systems* Multiple Cases::              Tests for several possible valuesWriting Test Programs* Guidelines::                  General rules for writing test programs* Test Functions::              Avoiding pitfalls in test programs* Generating Sources::          Source program boilerplateResults of Tests* Defining Symbols::            Defining C preprocessor symbols* Setting Output Variables::    Replacing variables in output files* Special Chars in Variables::  Characters to beware of in variables* Caching Results::             Speeding up subsequent @command{configure} runs* Printing Messages::           Notifying @command{configure} usersCaching Results* Cache Variable Names::        Shell variables used in caches* Cache Files::                 Files @command{configure} uses for caching* Cache Checkpointing::         Loading and saving the cache fileProgramming in M4* M4 Quotation::                Protecting macros from unwanted expansion* Using autom4te::              The Autoconf executables backbone* Programming in M4sugar::      Convenient pure M4 macros* Debugging via autom4te::      Figuring out what M4 was doingM4 Quotation* Active Characters::           Characters that change the behavior of M4* One Macro Call::              Quotation and one macro call* Quoting and Parameters::      M4 vs. shell parameters* Quotation and Nested Macros::  Macros calling macros* Changequote is Evil::         Worse than INTERCAL: M4 + changequote* Quadrigraphs::                Another way to escape special characters* Balancing Parentheses::       Dealing with unbalanced parentheses* Quotation Rule Of Thumb::     One parenthesis, one quoteUsing @command{autom4te}* autom4te Invocation::         A GNU M4 wrapper* Customizing autom4te::        Customizing the Autoconf packageProgramming in M4sugar* Redefined M4 Macros::         M4 builtins changed in M4sugar* Diagnostic Macros::           Diagnostic messages from M4sugar* Diversion support::           Diversions in M4sugar* Conditional constructs::      Conditions in M4* Looping constructs::          Iteration in M4* Evaluation Macros::           More quotation and evaluation control* Text processing Macros::      String manipulation in M4* Number processing Macros::    Arithmetic computation in M4* Set manipulation Macros::     Set manipulation in M4* Forbidden Patterns::          Catching unexpanded macrosProgramming in M4sh* Common Shell Constructs::     Portability layer for common shell constructs* Polymorphic Variables::       Support for indirect variable names* Initialization Macros::       Macros to establish a sane shell environment* File Descriptor Macros::      File descriptor macros for input and outputWriting Autoconf Macros* Macro Definitions::           Basic format of an Autoconf macro* Macro Names::                 What to call your new macros* Reporting Messages::          Notifying @command{autoconf} users* Dependencies Between Macros::  What to do when macros depend on other macros* Obsoleting Macros::           Warning about old ways of doing things* Coding Style::                Writing Autoconf macros @`a la AutoconfDependencies Between Macros* Prerequisite Macros::         Ensuring required information* Suggested Ordering::          Warning about possible ordering problems* One-Shot Macros::             Ensuring a macro is called only oncePortable Shell Programming* Shellology::                  A zoology of shells* Invoking the Shell::          Invoking the shell as a command* Here-Documents::              Quirks and tricks* File Descriptors::            FDs and redirections* Signal Handling::             Shells, signals, and headaches* File System Conventions::     File names* Shell Pattern Matching::      Pattern matching* Shell Substitutions::         Variable and command expansions* Assignments::                 Varying side effects of assignments* Parentheses::                 Parentheses in shell scripts* Slashes::                     Slashes in shell scripts* Special Shell Variables::     Variables you should not change* Shell Functions::             What to look out for if you use them* Limitations of Builtins::     Portable use of not so portable /bin/sh* Limitations of Usual Tools::  Portable use of portable toolsPortable Make Programming* $< in Ordinary Make Rules::   $< in ordinary rules* Failure in Make Rules::       Failing portably in rules* Special Chars in Names::      Special Characters in Macro Names* Backslash-Newline-Empty::     Empty lines after backslash-newline* Backslash-Newline Comments::  Spanning comments across line boundaries* Long Lines in Makefiles::     Line length limitations* Macros and Submakes::         @code{make macro=value} and submakes* The Make Macro MAKEFLAGS::    @code{$(MAKEFLAGS)} portability issues* The Make Macro SHELL::        @code{$(SHELL)} portability issues* Parallel Make::               Parallel @command{make} quirks* Comments in Make Rules::      Other problems with Make comments* Newlines in Make Rules::      Using literal newlines in rules* Comments in Make Macros::     Other problems with Make comments in macros* Trailing whitespace in Make Macros::  Macro substitution problems* Command-line Macros and whitespace::  Whitespace trimming of values* obj/ and Make::               Don't name a subdirectory @file{obj}* make -k Status::              Exit status of @samp{make -k}* VPATH and Make::              @code{VPATH} woes* Single Suffix Rules::         Single suffix rules and separated dependencies* Timestamps and Make::         Subsecond timestamp resolution@code{VPATH} and Make* Variables listed in VPATH::   @code{VPATH} must be literal on ancient hosts* VPATH and Double-colon::      Problems with @samp{::} on ancient hosts* $< in Explicit Rules::        @code{$<} does not work in ordinary rules* Automatic Rule Rewriting::    @code{VPATH} goes wild on Solaris* Tru64 Directory Magic::       @command{mkdir} goes wild on Tru64* Make Target Lookup::          More details about @code{VPATH} lookupPortable C and C++ Programming* Varieties of Unportability::  How to make your programs unportable* Integer Overflow::            When integers get too large* Preprocessor Arithmetic::     @code{#if} expression problems* Null Pointers::               Properties of null pointers* Buffer Overruns::             Subscript errors and the like* Volatile Objects::            @code{volatile} and signals* Floating Point Portability::  Portable floating-point arithmetic* Exiting Portably::            Exiting and the exit statusInteger Overflow* Integer Overflow Basics::     Why integer overflow is a problem* Signed Overflow Examples::    Examples of code assuming wraparound* Optimization and Wraparound::  Optimizations that break uses of wraparound* Signed Overflow Advice::      Practical advice for signed overflow issues* Signed Integer Division::     @code{INT_MIN / -1} and @code{INT_MIN % -1}Manual Configuration* Specifying Target Triplets::  Specifying target triplets* Canonicalizing::              Getting the canonical system type* Using System Type::           What to do with the system typeSite Configuration* Help Formatting::             Customizing @samp{configure --help}* External Software::           Working with other optional software* Package Options::             Selecting optional features* Pretty Help Strings::         Formatting help string* Option Checking::             Controlling checking of @command{configure} options* Site Details::                Configuring site details* Transforming Names::          Changing program names when installing* Site Defaults::               Giving @command{configure} local defaultsTransforming Program Names When Installing* Transformation Options::      @command{configure} options to transform names* Transformation Examples::     Sample uses of transforming names* Transformation Rules::        Makefile uses of transforming namesRunning @command{configure} Scripts* Basic Installation::          Instructions for typical cases* Compilers and Options::       Selecting compilers and optimization* Multiple Architectures::      Compiling for multiple architectures at once* Installation Names::          Installing in different directories* Optional Features::           Selecting optional features* Particular Systems::          Particular systems* System Type::                 Specifying the system type* Sharing Defaults::            Setting site-wide defaults for @command{configure}* Defining Variables::          Specifying the compiler etc.* configure Invocation::        Changing how @command{configure} runsObsolete Constructs* Obsolete config.status Use::  Obsolete convention for @command{config.status}* acconfig Header::             Additional entries in @file{config.h.in}* autoupdate Invocation::       Automatic update of @file{configure.ac}* Obsolete Macros::             Backward compatibility macros* Autoconf 1::                  Tips for upgrading your files* Autoconf 2.13::               Some fresher tipsUpgrading From Version 1* Changed File Names::          Files you might rename* Changed Makefiles::           New things to put in @file{Makefile.in}* Changed Macros::              Macro calls you might replace* Changed Results::             Changes in how to check test results* Changed Macro Writing::       Better ways to write your own macrosUpgrading From Version 2.13* Changed Quotation::           Broken code which used to work* New Macros::                  Interaction with foreign macros* Hosts and Cross-Compilation::  Bugward compatibility kludges* AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token* AC_ACT_IFELSE vs AC_TRY_ACT::  A more generic scheme for testing sourcesGenerating Test Suites with Autotest* Using an Autotest Test Suite::  Autotest and the user* Writing Testsuites::          Autotest macros* testsuite Invocation::        Running @command{testsuite} scripts* Making testsuite Scripts::    Using autom4te to create @command{testsuite}Using an Autotest Test Suite* testsuite Scripts::           The concepts of Autotest* Autotest Logs::               Their contentsFrequent Autoconf Questions, with answers* Distributing::                Distributing @command{configure} scripts* Why GNU M4::                  Why not use the standard M4?* Bootstrapping::               Autoconf and GNU M4 require each other?* Why Not Imake::               Why GNU uses @command{configure} instead of Imake* Defining Directories::        Passing @code{datadir} to program* Autom4te Cache::              What is it?  Can I remove it?* Present But Cannot Be Compiled::  Compiler and Preprocessor Disagree* Expanded Before Required::    Expanded Before Required* Debugging::                   Debugging @command{configure} scriptsHistory of Autoconf* Genesis::                     Prehistory and naming of @command{configure}* Exodus::                      The plagues of M4 and Perl* Leviticus::                   The priestly code of portability arrives* Numbers::                     Growth and contributors* Deuteronomy::                 Approaching the promises of easy configurationIndices* Environment Variable Index::  Index of environment variables used* Output Variable Index::       Index of variables set in output files* Preprocessor Symbol Index::   Index of C preprocessor symbols defined* Cache Variable Index::        Index of documented cache variables* Autoconf Macro Index::        Index of Autoconf macros* M4 Macro Index::              Index of M4, M4sugar, and M4sh macros* Autotest Macro Index::        Index of Autotest macros* Program & Function Index::    Index of those with portability problems* Concept Index::               General index@end detailmenu@end menu@c ============================================================= Introduction.@node Introduction@chapter Introduction@cindex Introduction@flushrightA physicist, an engineer, and a computer scientist were discussing thenature of God.  ``Surely a Physicist,'' said the physicist, ``becauseearly in the Creation, God made Light; and you know, Maxwell'sequations, the dual nature of electromagnetic waves, the relativisticconsequences@enddots{}'' ``An Engineer!,'' said the engineer, ``becausebefore making Light, God split the Chaos into Land and Water; it takes ahell of an engineer to handle that big amount of mud, and orderlyseparation of solids from liquids@enddots{}'' The computer scientistshouted: ``And the Chaos, where do you think it was coming from, hmm?''---Anonymous@end flushright@c (via Franc,ois Pinard)Autoconf is a tool for producing shell scripts that automaticallyconfigure software source code packages to adapt to many kinds ofPosix-like systems.  The configuration scripts produced by Autoconfare independent of Autoconf when they are run, so their users do notneed to have Autoconf.The configuration scripts produced by Autoconf require no manual userintervention when run; they do not normally even need an argumentspecifying the system type.  Instead, they individually test for thepresence of each feature that the software package they are for might need.(Before each check, they print a one-line message stating what they arechecking for, so the user doesn't get too bored while waiting for thescript to finish.)  As a result, they deal well with systems that arehybrids or customized from the more common Posix variants.  There isno need to maintain files that list the features supported by eachrelease of each variant of Posix.For each software package that Autoconf is used with, it creates aconfiguration script from a template file that lists the system featuresthat the package needs or can use.  After the shell code to recognizeand respond to a system feature has been written, Autoconf allows it tobe shared by many software packages that can use (or need) that feature.If it later turns out that the shell code needs adjustment for somereason, it needs to be changed in only one place; all of theconfiguration scripts can be regenerated automatically to take advantageof the updated code.@c "Those who do not understand Unix are condemned to reinvent it, poorly."@c --Henry Spencer, 1987 (see http://en.wikipedia.org/wiki/Unix_philosophy)Those who do not understand Autoconf are condemned to reinvent it, poorly.The primary goal of Autoconf is making the @emph{user's} life easier;making the @emph{maintainer's} life easier is only a secondary goal.Put another way, the primary goal is not to make the generation of@file{configure} automatic for package maintainers (although patchesalong that front are welcome, since package maintainers form the userbase of Autoconf); rather, the goal is to make @file{configure}painless, portable, and predictable for the end user of each@dfn{autoconfiscated} package.  And to this degree, Autoconf is highlysuccessful at its goal --- most complaints to the Autoconf list areabout difficulties in writing Autoconf input, and not in the behavior ofthe resulting @file{configure}.  Even packages that don't use Autoconfwill generally provide a @file{configure} script, and the most commoncomplaint about these alternative home-grown scripts is that they failto meet one or more of the GNU Coding Standards (@pxref{Configuration, , ,standards, The GNU Coding Standards}) that usershave come to expect from Autoconf-generated @file{configure} scripts.The Metaconfig package is similar in purpose to Autoconf, but thescripts it produces require manual user intervention, which is quiteinconvenient when configuring large source trees.  Unlike Metaconfigscripts, Autoconf scripts can support cross-compiling, if some care istaken in writing them.Autoconf does not solve all problems related to making portablesoftware packages---for a more complete solution, it should be used inconcert with other GNU build tools like Automake andLibtool.  These other tools take on jobs like the creation of aportable, recursive makefile with all of the standard targets,linking of shared libraries, and so on.  @xref{The GNU Build System},for more information.Autoconf imposes some restrictions on the names of macros used with@code{#if} in C programs (@pxref{Preprocessor Symbol Index}).Autoconf requires GNU M4 version 1.4.6 or later in order togenerate the scripts.  It uses features that some versions of M4,including GNU M4 1.3, do not have.  Autoconf works betterwith GNU M4 version 1.4.14 or later, though this is notrequired.@xref{Autoconf 1}, for information about upgrading from version 1.@xref{History}, for the story of Autoconf's development.  @xref{FAQ},for answers to some common questions about Autoconf.See the @uref{http://@/www.gnu.org/@/software/@/autoconf/,Autoconf web page} for up-to-date information, details on the mailinglists, pointers to a list of known bugs, etc.Mail suggestions to @email{autoconf@@gnu.org, the Autoconf mailinglist}.  Past suggestions are@uref{http://@/lists.gnu.org/@/archive/@/html/@/autoconf/, archived}.Mail bug reports to @email{bug-autoconf@@gnu.org, theAutoconf Bugs mailing list}.  Past bug reports are@uref{http://@/lists.gnu.org/@/archive/@/html/@/bug-autoconf/, archived}.If possible, first check that your bug isnot already solved in current development versions, and that it has notbeen reported yet.  Be sure to include all the needed information and ashort @file{configure.ac} that demonstrates the problem.Autoconf's development tree is accessible via @command{git}; see the@uref{http://@/savannah.gnu.org/@/projects/@/autoconf/, AutoconfSummary} for details, or view@uref{http://@/git.sv.gnu.org/@/gitweb/@/?p=autoconf.git, the actualrepository}.  Anonymous CVS access is also available, see@file{README} for more details.  Patches relative to thecurrent @command{git} version can be sent for review to the@email{autoconf-patches@@gnu.org, Autoconf Patches mailing list}, withdiscussion on prior patches@uref{http://@/lists.gnu.org/@/archive/@/html/@/autoconf-@/patches/,archived}; and all commits are posted in the read-only@email{autoconf-commit@@gnu.org, Autoconf Commit mailing list}, which isalso @uref{http://@/lists.gnu.org/@/archive/@/html/@/autoconf-commit/,archived}.Because of its mission, the Autoconf package itselfincludes only a set of often-usedmacros that have already demonstrated their usefulness.  Nevertheless,if you wish to share your macros, or find existing ones, see the@uref{http://@/www.gnu.org/@/software/@/autoconf-archive/, Autoconf MacroArchive}, which is kindly run by @email{simons@@cryp.to,Peter Simons}.@c ================================================= The GNU Build System@node The GNU Build System@chapter The GNU Build System@cindex GNU build systemAutoconf solves an important problem---reliable discovery ofsystem-specific build and runtime information---but this is only onepiece of the puzzle for the development of portable software.  To thisend, the GNU project has developed a suite of integratedutilities to finish the job Autoconf started: the GNU buildsystem, whose most important components are Autoconf, Automake, andLibtool.  In this chapter, we introduce you to those tools, point youto sources of more information, and try to convince you to use theentire GNU build system for your software.@menu* Automake::                    Escaping makefile hell* Gnulib::                      The GNU portability library* Libtool::                     Building libraries portably* Pointers::                    More info on the GNU build system@end menu@node Automake@section AutomakeThe ubiquity of @command{make} means that a makefile is almost theonly viable way to distribute automatic build rules for software, butone quickly runs into its numerous limitations.  Its lack ofsupport for automatic dependency tracking, recursive builds insubdirectories, reliable timestamps (e.g., for network file systems), andso on, mean that developers must painfully (and often incorrectly)reinvent the wheel for each project.  Portability is non-trivial, thanksto the quirks of @command{make} on many systems.  On top of all this is themanual labor required to implement the many standard targets that usershave come to expect (@code{make install}, @code{make distclean},@code{make uninstall}, etc.).  Since you are, of course, using Autoconf,you also have to insert repetitive code in your @file{Makefile.in} torecognize @code{@@CC@@}, @code{@@CFLAGS@@}, and other substitutionsprovided by @command{configure}.  Into this mess steps @dfn{Automake}.@cindex AutomakeAutomake allows you to specify your build needs in a @file{Makefile.am}file with a vastly simpler and more powerful syntax than that of a plainmakefile, and then generates a portable @file{Makefile.in} foruse with Autoconf.  For example, the @file{Makefile.am} to build andinstall a simple ``Hello world'' program might look like:@examplebin_PROGRAMS = hellohello_SOURCES = hello.c@end example@noindentThe resulting @file{Makefile.in} (~400 lines) automatically supports allthe standard targets, the substitutions provided by Autoconf, automaticdependency tracking, @code{VPATH} building, and so on.  @command{make}builds the @code{hello} program, and @code{make install} installs itin @file{/usr/local/bin} (or whatever prefix was given to@command{configure}, if not @file{/usr/local}).The benefits of Automake increase for larger packages (especially oneswith subdirectories), but even for small programs the added convenienceand portability can be substantial.  And that's not all@enddots{}@node Gnulib@section GnulibGNU software has a well-deserved reputation for running onmany different types of systems.  While our primary goal is to writesoftware for the GNU system, many users and developers havebeen introduced to us through the systems that they were already using.@cindex GnulibGnulib is a central location for common GNU code, intended tobe shared among free software packages.  Its components are typicallyshared at the source level, rather than being a library that gets built,installed, and linked against.  The idea is to copy files from Gnulibinto your own source tree.  There is no distribution tarball; developersshould just grab source modules from the repository.  The source filesare available online, under various licenses, mostly GNUGPL or GNU LGPL.Gnulib modules typically contain C source code along with Autoconfmacros used to configure the source code.  For example, the Gnulib@code{stdbool} module implements a @file{stdbool.h} header that nearlyconforms to C99, even on old-fashioned hosts that lack @file{stdbool.h}.This module contains a source file for the replacement header, alongwith an Autoconf macro that arranges to use the replacement header onold-fashioned systems.@node Libtool@section LibtoolOften, one wants to build not only programs, but libraries, so thatother programs can benefit from the fruits of your labor.  Ideally, onewould like to produce @emph{shared} (dynamically linked) libraries,which can be used by multiple programs without duplication on disk or inmemory and can be updated independently of the linked programs.Producing shared libraries portably, however, is the stuff ofnightmares---each system has its own incompatible tools, compiler flags,and magic incantations.  Fortunately, GNU provides a solution:@dfn{Libtool}.@cindex LibtoolLibtool handles all the requirements of building shared libraries foryou, and at this time seems to be the @emph{only} way to do so with anyportability.  It also handles many other headaches, such as: theinteraction of Make rules with the variable suffixes ofshared libraries, linking reliably with shared libraries before they areinstalled by the superuser, and supplying a consistent versioning system(so that different versions of a library can be installed or upgradedwithout breaking binary compatibility).  Although Libtool, likeAutoconf, can be used without Automake, it is most simply utilized inconjunction with Automake---there, Libtool is used automaticallywhenever shared libraries are needed, and you need not know its syntax.@node Pointers@section PointersDevelopers who are used to the simplicity of @command{make} for smallprojects on a single system might be daunted at the prospect oflearning to use Automake and Autoconf.  As your software isdistributed to more and more users, however, you otherwisequickly find yourself putting lots of effort into reinventing theservices that the GNU build tools provide, and making thesame mistakes that they once made and overcame.  (Besides, sinceyou're already learning Autoconf, Automake is a piece of cake.)There are a number of places that you can go to for more information onthe GNU build tools.@itemize @minus@item WebThe project home pages for@uref{http://@/www@/.gnu@/.org/@/software/@/autoconf/, Autoconf},@uref{http://@/www@/.gnu@/.org/@/software/@/automake/, Automake},@uref{http://@/www@/.gnu@/.org/@/software/@/gnulib/, Gnulib}, and@uref{http://@/www@/.gnu@/.org/@/software/@/libtool/, Libtool}.@item Automake Manual@xref{Top, , Automake, automake, GNU Automake}, for moreinformation on Automake.@item BooksThe book @cite{GNU Autoconf, Automake andLibtool}@footnote{@cite{GNU Autoconf, Automake and Libtool},by G. V. Vaughan, B. Elliston, T. Tromey, and I. L. Taylor.  SAMS (originallyNew Riders), 2000, ISBN 1578701902.} describes the complete GNUbuild environment.  You can also find@uref{http://@/sources.redhat.com/@/autobook/, the entire book on-line}.@end itemize@c ================================================= Making configure Scripts.@node Making configure Scripts@chapter Making @command{configure} Scripts@cindex @file{aclocal.m4}@cindex @command{configure}The configuration scripts that Autoconf produces are by conventioncalled @command{configure}.  When run, @command{configure} creates severalfiles, replacing configuration parameters in them with appropriatevalues.  The files that @command{configure} creates are:@itemize @minus@itemone or more @file{Makefile} files, usually one in each subdirectory of thepackage (@pxref{Makefile Substitutions});@itemoptionally, a C header file, the name of which is configurable,containing @code{#define} directives (@pxref{Configuration Headers});@itema shell script called @file{config.status} that, when run, recreatesthe files listed above (@pxref{config.status Invocation});@iteman optional shell script normally called @file{config.cache}(created when using @samp{configure --config-cache}) thatsaves the results of running many of the tests (@pxref{Cache Files});@itema file called @file{config.log} containing any messages produced bycompilers, to help debugging if @command{configure} makes a mistake.@end itemize@cindex @file{configure.in}@cindex @file{configure.ac}To create a @command{configure} script with Autoconf, you need to write anAutoconf input file @file{configure.ac} (or @file{configure.in}) and run@command{autoconf} on it.  If you write your own feature tests tosupplement those that come with Autoconf, you might also write filescalled @file{aclocal.m4} and @file{acsite.m4}.  If you use a C headerfile to contain @code{#define} directives, you might also run@command{autoheader}, and you can distribute the generated file@file{config.h.in} with the package.Here is a diagram showing how the files that can be used inconfiguration are produced.  Programs that are executed are suffixed by@samp{*}.  Optional files are enclosed in square brackets (@samp{[]}).@command{autoconf} and @command{autoheader} also read the installed Autoconfmacro files (by reading @file{autoconf.m4}).@noindentFiles used in preparing a software package for distribution, when usingjust Autoconf:@exampleyour source files --> [autoscan*] --> [configure.scan] --> configure.ac@groupconfigure.ac --.               |   .------> autoconf* -----> configure[aclocal.m4] --+---+               |   `-----> [autoheader*] --> [config.h.in][acsite.m4] ---'@end groupMakefile.in@end example@noindentAdditionally, if you use Automake, the following additional productionscome into play:@example@group[acinclude.m4] --.                 |[local macros] --+--> aclocal* --> aclocal.m4                 |configure.ac ----'@end group@groupconfigure.ac --.               +--> automake* --> Makefile.inMakefile.am ---'@end group@end example@noindentFiles used in configuring a software package:@example@group                       .-------------> [config.cache]configure* ------------+-------------> config.log                       |[config.h.in] -.       v            .-> [config.h] -.               +--> config.status* -+               +--> make*Makefile.in ---'                    `-> Makefile ---'@end group@end example@menu* Writing Autoconf Input::      What to put in an Autoconf input file* autoscan Invocation::         Semi-automatic @file{configure.ac} writing* ifnames Invocation::          Listing the conditionals in source code* autoconf Invocation::         How to create configuration scripts* autoreconf Invocation::       Remaking multiple @command{configure} scripts@end menu@node Writing Autoconf Input@section Writing @file{configure.ac}To produce a @command{configure} script for a software package, create afile called @file{configure.ac} that contains invocations of theAutoconf macros that test the system features your package needs or canuse.  Autoconf macros already exist to check for many features; see@ref{Existing Tests}, for their descriptions.  For most other features,you can use Autoconf template macros to produce custom checks; see@ref{Writing Tests}, for information about them.  For especially trickyor specialized features, @file{configure.ac} might need to contain somehand-crafted shell commands; see @ref{Portable Shell, , Portable ShellProgramming}.  The @command{autoscan} program can give you a good startin writing @file{configure.ac} (@pxref{autoscan Invocation}, for moreinformation).Previous versions of Autoconf promoted the name @file{configure.in},which is somewhat ambiguous (the tool needed to process this file is notdescribed by its extension), and introduces a slight confusion with@file{config.h.in} and so on (for which @samp{.in} means ``to beprocessed by @command{configure}'').  Using @file{configure.ac} is nowpreferred.@menu* Shell Script Compiler::       Autoconf as solution of a problem* Autoconf Language::           Programming in Autoconf* Autoconf Input Layout::       Standard organization of @file{configure.ac}@end menu@node Shell Script Compiler@subsection A Shell Script CompilerJust as for any other computer language, in order to properly program@file{configure.ac} in Autoconf you must understand @emph{what} problemthe language tries to address and @emph{how} it does so.The problem Autoconf addresses is that the world is a mess.  After all,you are using Autoconf in order to have your package compile easily onall sorts of different systems, some of them being extremely hostile.Autoconf itself bears the price for these differences: @command{configure}must run on all those systems, and thus @command{configure} must limit itselfto their lowest common denominator of features.Naturally, you might then think of shell scripts; who needs@command{autoconf}?  A set of properly written shell functions is enough tomake it easy to write @command{configure} scripts by hand.  Sigh!Unfortunately, even in 2008, where shells without any function support arefar and few between, there are pitfalls to avoid when making use of them.Also, finding a Bourne shell that accepts shell functions is not trivial,even though there is almost always one on interesting porting targets.So, what is really needed is some kind of compiler, @command{autoconf},that takes an Autoconf program, @file{configure.ac}, and transforms itinto a portable shell script, @command{configure}.How does @command{autoconf} perform this task?There are two obvious possibilities: creating a brand new language orextending an existing one.  The former option is attractive: allsorts of optimizations could easily be implemented in the compiler andmany rigorous checks could be performed on the Autoconf program(e.g., rejecting any non-portable construct).  Alternatively, you canextend an existing language, such as the @code{sh} (Bourne shell)language.Autoconf does the latter: it is a layer on top of @code{sh}.  It wastherefore most convenient to implement @command{autoconf} as a macroexpander: a program that repeatedly performs @dfn{macro expansions} ontext input, replacing macro calls with macro bodies and producing a pure@code{sh} script in the end.  Instead of implementing a dedicatedAutoconf macro expander, it is natural to use an existinggeneral-purpose macro language, such as M4, and implement the extensionsas a set of M4 macros.@node Autoconf Language@subsection The Autoconf Language@cindex quotationThe Autoconf language differs from many other computerlanguages because it treats actual code the same as plain text.  Whereasin C, for instance, data and instructions have different syntacticstatus, in Autoconf their status is rigorously the same.  Therefore, weneed a means to distinguish literal strings from text to be expanded:quotation.When calling macros that take arguments, there must not be any whitespace between the macro name and the open parenthesis.@exampleAC_INIT ([oops], [1.0]) # incorrectAC_INIT([hello], [1.0]) # good@end exampleArguments shouldbe enclosed within the quote characters @samp{[} and @samp{]}, and beseparated by commas.  Any leading blanks or newlines in arguments are ignored,unless they are quoted.  You should always quote an argument thatmight contain a macro name, comma, parenthesis, or a leading blank ornewline.  This rule applies recursively for every macrocall, including macros called from other macros.  For more details onquoting rules, see @ref{Programming in M4}.For instance:@exampleAC_CHECK_HEADER([stdio.h],                [AC_DEFINE([HAVE_STDIO_H], [1],                   [Define to 1 if you have <stdio.h>.])],                [AC_MSG_ERROR([sorry, can't do anything for you])])@end example@noindentis quoted properly.  You may safely simplify its quotation to:@exampleAC_CHECK_HEADER([stdio.h],                [AC_DEFINE([HAVE_STDIO_H], 1,                   [Define to 1 if you have <stdio.h>.])],                [AC_MSG_ERROR([sorry, can't do anything for you])])@end example@noindentbecause @samp{1} cannot contain a macro call.  Here, the argument of@code{AC_MSG_ERROR} must be quoted; otherwise, its comma would beinterpreted as an argument separator.  Also, the second and third argumentsof @samp{AC_CHECK_HEADER} must be quoted, since they containmacro calls.  The three arguments @samp{HAVE_STDIO_H}, @samp{stdio.h},and @samp{Define to 1 if you have <stdio.h>.} do not need quoting, butif you unwisely defined a macro with a name like @samp{Define} or@samp{stdio} then they would need quoting.  Cautious Autoconf userswould keep the quotes, but many Autoconf users find such precautionsannoying, and would rewrite the example as follows:@exampleAC_CHECK_HEADER(stdio.h,                [AC_DEFINE(HAVE_STDIO_H, 1,                   [Define to 1 if you have <stdio.h>.])],                [AC_MSG_ERROR([sorry, can't do anything for you])])@end example@noindentThis is safe, so long as you adopt good naming conventions and do notdefine macros with names like @samp{HAVE_STDIO_H}, @samp{stdio}, or@samp{h}.  Though it is also safe here to omit the quotes around@samp{Define to 1 if you have <stdio.h>.} this is not recommended, asmessage strings are more likely to inadvertently contain commas.The following example is wrong and dangerous, as it is underquoted:@exampleAC_CHECK_HEADER(stdio.h,                AC_DEFINE(HAVE_STDIO_H, 1,                   Define to 1 if you have <stdio.h>.),                AC_MSG_ERROR([sorry, can't do anything for you]))@end exampleIn other cases, you may have to use text that also resembles a macrocall.  You must quote that text even when it is not passed as a macroargument.  For example, these two approaches in @file{configure.ac}(quoting just the potential problems, or quoting the entire line) willprotect your script in case autoconf ever adds a macro @code{AC_DC}:@exampleecho "Hard rock was here!  --[AC_DC]"[echo "Hard rock was here!  --AC_DC"]@end example@noindentwhich results in this text in @file{configure}:@exampleecho "Hard rock was here!  --AC_DC"echo "Hard rock was here!  --AC_DC"@end example@noindentWhen you use the same text in a macro argument, you must therefore havean extra quotation level (since one is stripped away by the macrosubstitution).  In general, then, it is a good idea to @emph{use doublequoting for all literal string arguments}, either around just theproblematic portions, or over the entire argument:@exampleAC_MSG_WARN([[AC_DC] stinks  --Iron Maiden])AC_MSG_WARN([[AC_DC stinks  --Iron Maiden]])@end exampleHowever, the above example triggers a warning about a possiblyunexpanded macro when running @command{autoconf}, because it collideswith the namespace of macros reserved for the Autoconf language.  To bereally safe, you can use additional escaping (either a quadrigraph, orcreative shell constructs) to silence that particular warning:@exampleecho "Hard rock was here!  --AC""_DC"AC_MSG_WARN([[AC@@&t@@_DC stinks  --Iron Maiden]])@end exampleYou are now able to understand one of the constructs of Autoconf thathas been continually misunderstood@enddots{}  The rule of thumb is that@emph{whenever you expect macro expansion, expect quote expansion};i.e., expect one level of quotes to be lost.  For instance:@exampleAC_COMPILE_IFELSE(AC_LANG_SOURCE([char b[10];]), [], [AC_MSG_ERROR([you lose])])@end example@noindentis incorrect: here, the first argument of @code{AC_LANG_SOURCE} is@samp{char b[10];} and is expanded once, which results in@samp{char b10;}; and the @code{AC_LANG_SOURCE} is also expanded priorto being passed to @code{AC_COMPILE_IFELSE}.  (There was an idiom commonin Autoconf's past toaddress this issue via the M4 @code{changequote} primitive, but do notuse it!)  Let's take a closer look: the author meant the first argumentto be understood as a literal, and therefore it must be quoted twice;likewise, the intermediate @code{AC_LANG_SOURCE} macro should be quotedonce so that it is only expanded after the rest of the body of@code{AC_COMPILE_IFELSE} is in place:@exampleAC_COMPILE_IFELSE([AC_LANG_SOURCE([[char b[10];]])], [],  [AC_MSG_ERROR([you lose])])@end example@noindentVoil@`a, you actually produce @samp{char b[10];} this time!On the other hand, descriptions (e.g., the last parameter of@code{AC_DEFINE} or @code{AS_HELP_STRING}) are not literals---theyare subject to line breaking, for example---and should not be double quoted.Even if these descriptions are short and are not actually broken, doublequoting them yields weird results.Some macros take optional arguments, which this documentation representsas @ovar{arg} (not to be confused with the quote characters).  You mayjust leave them empty, or use @samp{[]} to make the emptiness of theargument explicit, or you may simply omit the trailing commas.  Thethree lines below are equivalent:@exampleAC_CHECK_HEADERS([stdio.h], [], [], [])AC_CHECK_HEADERS([stdio.h],,,)AC_CHECK_HEADERS([stdio.h])@end exampleIt is best to put each macro call on its own line in@file{configure.ac}.  Most of the macros don't add extra newlines; theyrely on the newline after the macro call to terminate the commands.This approach makes the generated @command{configure} script a littleeasier to read by not inserting lots of blank lines.  It is generallysafe to set shell variables on the same line as a macro call, becausethe shell allows assignments without intervening newlines.You can include comments in @file{configure.ac} files by starting themwith the @samp{#}.  For example, it is helpful to begin@file{configure.ac} files with a line like this:@example# Process this file with autoconf to produce a configure script.@end example@node Autoconf Input Layout@subsection Standard @file{configure.ac} LayoutThe order in which @file{configure.ac} calls the Autoconf macros is notimportant, with a few exceptions.  Every @file{configure.ac} mustcontain a call to @code{AC_INIT} before the checks, and a call to@code{AC_OUTPUT} at the end (@pxref{Output}).  Additionally, some macrosrely on other macros having been called first, because they checkpreviously set values of some variables to decide what to do.  Thesemacros are noted in the individual descriptions (@pxref{ExistingTests}), and they also warn you when @command{configure} is created if theyare called out of order.To encourage consistency, here is a suggested order for calling theAutoconf macros.  Generally speaking, the things near the end of thislist are those that could depend on things earlier in it.  For example,library functions could be affected by types and libraries.@display@groupAutoconf requirements@code{AC_INIT(@var{package}, @var{version}, @var{bug-report-address})}information on the packagechecks for programschecks for librarieschecks for header fileschecks for typeschecks for structureschecks for compiler characteristicschecks for library functionschecks for system services@code{AC_CONFIG_FILES(@r{[}@var{file@dots{}}@r{]})}@code{AC_OUTPUT}@end group@end display@node autoscan Invocation@section Using @command{autoscan} to Create @file{configure.ac}@cindex @command{autoscan}The @command{autoscan} program can help you create and/or maintain a@file{configure.ac} file for a software package.  @command{autoscan}examines source files in the directory tree rooted at a directory givenas a command line argument, or the current directory if none is given.It searches the source files for common portability problems and createsa file @file{configure.scan} which is a preliminary @file{configure.ac}for that package, and checks a possibly existing @file{configure.ac} forcompleteness.When using @command{autoscan} to create a @file{configure.ac}, youshould manually examine @file{configure.scan} before renaming it to@file{configure.ac}; it probably needs some adjustments.Occasionally, @command{autoscan} outputs a macro in the wrong orderrelative to another macro, so that @command{autoconf} produces a warning;you need to move such macros manually.  Also, if you want the package touse a configuration header file, you must add a call to@code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers}).  You mightalso have to change or add some @code{#if} directives to your program inorder to make it work with Autoconf (@pxref{ifnames Invocation}, forinformation about a program that can help with that job).When using @command{autoscan} to maintain a @file{configure.ac}, simplyconsider adding its suggestions.  The file @file{autoscan.log}contains detailed information on why a macro is requested.@command{autoscan} uses several data files (installed along with Autoconf)to determine which macros to output when it finds particular symbols ina package's source files.  These data files all have the same format:each line consists of a symbol, one or more blanks, and the Autoconf macro tooutput if that symbol is encountered.  Lines starting with @samp{#} arecomments.@command{autoscan} accepts the following options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@item --verbose@itemx -vPrint the names of the files it examines and the potentially interestingsymbols it finds in them.  This output can be voluminous.@item --debug@itemx -dDon't remove temporary files.@item --include=@var{dir}@itemx -I @var{dir}Append @var{dir} to the include path.  Multiple invocations accumulate.@item --prepend-include=@var{dir}@itemx -B @var{dir}Prepend @var{dir} to the include path.  Multiple invocations accumulate.@end table@node ifnames Invocation@section Using @command{ifnames} to List Conditionals@cindex @command{ifnames}@command{ifnames} can help you write @file{configure.ac} for a softwarepackage.  It prints the identifiers that the package already uses in Cpreprocessor conditionals.  If a package has already been set up to havesome portability, @command{ifnames} can thus help you figure out what its@command{configure} needs to check for.  It may help fill in some gaps in a@file{configure.ac} generated by @command{autoscan} (@pxref{autoscanInvocation}).@command{ifnames} scans all of the C source files named on the command line(or the standard input, if none are given) and writes to the standardoutput a sorted list of all the identifiers that appear in those filesin @code{#if}, @code{#elif}, @code{#ifdef}, or @code{#ifndef}directives.  It prints each identifier on a line, followed by aspace-separated list of the files in which that identifier occurs.@noindent@command{ifnames} accepts the following options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@end table@node autoconf Invocation@section Using @command{autoconf} to Create @command{configure}@cindex @command{autoconf}To create @command{configure} from @file{configure.ac}, run the@command{autoconf} program with no arguments.  @command{autoconf} processes@file{configure.ac} with the M4 macro processor, using theAutoconf macros.  If you give @command{autoconf} an argument, it reads thatfile instead of @file{configure.ac} and writes the configuration scriptto the standard output instead of to @command{configure}.  If you give@command{autoconf} the argument @option{-}, it reads from the standardinput instead of @file{configure.ac} and writes the configuration scriptto the standard output.The Autoconf macros are defined in several files.  Some of the files aredistributed with Autoconf; @command{autoconf} reads them first.  Then itlooks for the optional file @file{acsite.m4} in the directory thatcontains the distributed Autoconf macro files, and for the optional file@file{aclocal.m4} in the current directory.  Those files can containyour site's or the package's own Autoconf macro definitions(@pxref{Writing Autoconf Macros}, for more information).  If a macro isdefined in more than one of the files that @command{autoconf} reads, thelast definition it reads overrides the earlier ones.@command{autoconf} accepts the following options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@item --verbose@itemx -vReport processing steps.@item --debug@itemx -dDon't remove the temporary files.@item --force@itemx -fRemake @file{configure} even if newer than its input files.@item --include=@var{dir}@itemx -I @var{dir}Append @var{dir} to the include path.  Multiple invocations accumulate.@item --prepend-include=@var{dir}@itemx -B @var{dir}Prepend @var{dir} to the include path.  Multiple invocations accumulate.@item --output=@var{file}@itemx -o @var{file}Save output (script or trace) to @var{file}.  The file @option{-} standsfor the standard output.@item --warnings=@var{category}@itemx -W @var{category}@evindex WARNINGSReport the warnings related to @var{category} (which can actually be acomma separated list).  @xref{Reporting Messages}, macro@code{AC_DIAGNOSE}, for a comprehensive list of categories.  Specialvalues include:@table @samp@item allreport all the warnings@item nonereport none@item errortreats warnings as errors@item no-@var{category}disable warnings falling into @var{category}@end tableWarnings about @samp{syntax} are enabled by default, and the environmentvariable @env{WARNINGS}, a comma separated list of categories, ishonored as well.  Passing @option{-W @var{category}} actually behaves as ifyou had passed @option{--warnings syntax,$WARNINGS,@var{category}}.  Todisable the defaults and @env{WARNINGS}, and thenenable warnings about obsolete constructs, use @option{-Wnone,obsolete}.@cindex Back trace@cindex Macro invocation stackBecause @command{autoconf} uses @command{autom4te} behind the scenes, itdisplays a back trace for errors, but not for warnings; if you wantthem, just pass @option{-W error}.  @xref{autom4te Invocation}, for someexamples.@item --trace=@var{macro}[:@var{format}]@itemx -t @var{macro}[:@var{format}]Do not create the @command{configure} script, but list the calls to@var{macro} according to the @var{format}.  Multiple @option{--trace}arguments can be used to list several macros.  Multiple @option{--trace}arguments for a single macro are not cumulative; instead, you shouldjust make @var{format} as long as needed.The @var{format} is a regular string, with newlines if desired, andseveral special escape codes.  It defaults to @samp{$f:$l:$n:$%}; see@ref{autom4te Invocation}, for details on the @var{format}.@item --initialization@itemx -iBy default, @option{--trace} does not trace the initialization of theAutoconf macros (typically the @code{AC_DEFUN} definitions).  Thisresults in a noticeable speedup, but can be disabled by this option.@end tableIt is often necessary to check the content of a @file{configure.ac}file, but parsing it yourself is extremely fragile and error-prone.  Itis suggested that you rely upon @option{--trace} to scan@file{configure.ac}.  For instance, to find the list of variables thatare substituted, use:@example@group$ @kbd{autoconf -t AC_SUBST}configure.ac:2:AC_SUBST:ECHO_Cconfigure.ac:2:AC_SUBST:ECHO_Nconfigure.ac:2:AC_SUBST:ECHO_T@i{More traces deleted}@end group@end example@noindentThe example below highlights the difference between @samp{$@@},@samp{$*}, and @samp{$%}.@example@group$ @kbd{cat configure.ac}AC_DEFINE(This, is, [an[example]])$ @kbd{autoconf -t 'AC_DEFINE:@@: $@@}*: $*%: $%'@@: [This],[is],[an[example]]*: This,is,an[example]%: This:is:an [example]@end group@end example@noindentThe @var{format} gives you a lot of freedom:@example@group$ @kbd{autoconf -t 'AC_SUBST:$$ac_subst@{"$1"@} = "$f:$l";'}$ac_subst@{"ECHO_C"@} = "configure.ac:2";$ac_subst@{"ECHO_N"@} = "configure.ac:2";$ac_subst@{"ECHO_T"@} = "configure.ac:2";@i{More traces deleted}@end group@end example@noindentA long @var{separator} can be used to improve the readability of complexstructures, and to ease their parsing (for instance when no singlecharacter is suitable as a separator):@example@group$ @kbd{autoconf -t 'AM_MISSING_PROG:$@{|:::::|@}*'}ACLOCAL|:::::|aclocal|:::::|$missing_dirAUTOCONF|:::::|autoconf|:::::|$missing_dirAUTOMAKE|:::::|automake|:::::|$missing_dir@i{More traces deleted}@end group@end example@node autoreconf Invocation@section Using @command{autoreconf} to Update @command{configure} Scripts@cindex @command{autoreconf}Installing the various components of the GNU Build System can betedious: running @command{autopoint} for Gettext, @command{automake} for@file{Makefile.in} etc.@: in each directory.  It may be needed eitherbecause some tools such as @command{automake} have been updated on yoursystem, or because some of the sources such as @file{configure.ac} havebeen updated, or finally, simply in order to install the GNU BuildSystem in a fresh tree.@command{autoreconf} runs @command{autoconf}, @command{autoheader},@command{aclocal}, @command{automake}, @command{libtoolize}, and@command{autopoint} (when appropriate) repeatedly to update theGNU Build System in the specified directories and theirsubdirectories (@pxref{Subdirectories}).  By default, it only remakesthose files that are older than their sources.  The environment variables@env{AUTOM4TE}, @env{AUTOCONF}, @env{AUTOHEADER}, @env{AUTOMAKE},@env{ACLOCAL}, @env{AUTOPOINT}, @env{LIBTOOLIZE}, @env{M4}, and @env{MAKE}may be used to override the invocation of the respective tools.If you install a new version of some tool, you can make@command{autoreconf} remake @emph{all} of the files by giving it the@option{--force} option.@xref{Automatic Remaking}, for Make rules to automaticallyrebuild @command{configure} scripts when their source files change.  Thatmethod handles the timestamps of configuration header templatesproperly, but does not pass @option{--autoconf-dir=@var{dir}} or@option{--localdir=@var{dir}}.@cindex Gettext@cindex @command{autopoint}Gettext supplies the @command{autopoint} command to add translationinfrastructure to a source package.  If you use @command{autopoint},your @file{configure.ac} should invoke both @code{AM_GNU_GETTEXT} and@code{AM_GNU_GETTEXT_VERSION(@var{gettext-version})}.  @xref{autopointInvocation, , Invoking the @code{autopoint} Program, gettext,GNU @code{gettext} utilities}, for further details.@noindent@command{autoreconf} accepts the following options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@item --verbose@itemx -vPrint the name of each directory @command{autoreconf} examines and thecommands it runs.  If given two or more times, pass @option{--verbose}to subordinate tools that support it.@item --debug@itemx -dDon't remove the temporary files.@item --force@itemx -fRemake even @file{configure} scripts and configuration headers that arenewer than their input files (@file{configure.ac} and, if present,@file{aclocal.m4}).@item --install@itemx -iInstall the missing auxiliary files in the package.  By default, filesare copied; this can be changed with @option{--symlink}.If deemed appropriate, this option triggers calls to@samp{automake --add-missing},@samp{libtoolize}, @samp{autopoint}, etc.@item --no-recursiveDo not rebuild files in subdirectories to configure (see @ref{Subdirectories},macro @code{AC_CONFIG_SUBDIRS}).@item --symlink@itemx -sWhen used with @option{--install}, install symbolic links to the missingauxiliary files instead of copying them.@item --make@itemx -mWhen the directories were configured, update the configuration byrunning @samp{./config.status --recheck && ./config.status}, and thenrun @samp{make}.@item --include=@var{dir}@itemx -I @var{dir}Append @var{dir} to the include path.  Multiple invocations accumulate.Passed on to @command{aclocal}, @command{autoconf} and@command{autoheader} internally.@item --prepend-include=@var{dir}@itemx -B @var{dir}Prepend @var{dir} to the include path.  Multiple invocations accumulate.Passed on to @command{autoconf} and @command{autoheader} internally.@item --warnings=@var{category}@itemx -W @var{category}@evindex WARNINGSReport the warnings related to @var{category} (which can actually be acomma separated list).@table @samp@item crossrelated to cross compilation issues.@item obsoletereport the uses of obsolete constructs.@item portabilityportability issues@item syntaxdubious syntactic constructs.@item allreport all the warnings@item nonereport none@item errortreats warnings as errors@item no-@var{category}disable warnings falling into @var{category}@end tableWarnings about @samp{syntax} are enabled by default, and the environmentvariable @env{WARNINGS}, a comma separated list of categories, ishonored as well.  Passing @option{-W @var{category}} actually behaves as ifyou had passed @option{--warnings syntax,$WARNINGS,@var{category}}.  Todisable the defaults and @env{WARNINGS}, and thenenable warnings about obsolete constructs, use @option{-Wnone,obsolete}.@end tableIf you want @command{autoreconf} to pass flags that are not listed hereon to @command{aclocal}, set @code{ACLOCAL_AMFLAGS} in your @file{Makefile.am}.Due to a limitation in the Autoconf implementation these flags currentlymust be set on a single line in @file{Makefile.am}, without anybackslash-newlines.@c ========================================= Initialization and Output Files.@node Setup@chapter Initialization and Output FilesAutoconf-generated @command{configure} scripts need some information abouthow to initialize, such as how to find the package's source files andabout the output files to produce.  The following sections describe theinitialization and the creation of output files.@menu* Initializing configure::      Option processing etc.* Versioning::                  Dealing with Autoconf versions* Notices::                     Copyright, version numbers in @command{configure}* Input::                       Where Autoconf should find files* Output::                      Outputting results from the configuration* Configuration Actions::       Preparing the output based on results* Configuration Files::         Creating output files* Makefile Substitutions::      Using output variables in makefiles* Configuration Headers::       Creating a configuration header file* Configuration Commands::      Running arbitrary instantiation commands* Configuration Links::         Links depending on the configuration* Subdirectories::              Configuring independent packages together* Default Prefix::              Changing the default installation prefix@end menu@node Initializing configure@section Initializing @command{configure}Every @command{configure} script must call @code{AC_INIT} before doinganything else that produces output.  Calls to silent macros, such as@code{AC_DEFUN}, may also occur prior to @code{AC_INIT}, although theseare generally used via @file{aclocal.m4}, since that is implicitlyincluded before the start of @file{configure.ac}.  The only otherrequired macro is @code{AC_OUTPUT} (@pxref{Output}).@anchor{AC_INIT}@defmac AC_INIT (@var{package}, @var{version}, @ovar{bug-report}, @  @ovar{tarname}, @ovar{url})@acindex{INIT}Process any command-line arguments and perform initializationand verification.Set the name of the @var{package} and its @var{version}.  These aretypically used in @option{--version} support, including that of@command{configure}.  The optional argument @var{bug-report} should bethe email to which users should send bug reports.  The package@var{tarname} differs from @var{package}: the latter designates the fullpackage name (e.g., @samp{GNU Autoconf}), while the former is meant fordistribution tar ball names (e.g., @samp{autoconf}).  It defaults to@var{package} with @samp{GNU } stripped, lower-cased, and all charactersother than alphanumerics and underscores are changed to @samp{-}.  Ifprovided, @var{url} should be the home page for the package.The arguments of @code{AC_INIT} must be static, i.e., there should notbe any shell computation, quotes, or newlines, but they can be computedby M4.  This is because the package information strings are expanded atM4 time into several contexts, and must give the same text at shell timewhether used in single-quoted strings, double-quoted strings, quotedhere-documents, or unquoted here-documents.  It is permissible to use@code{m4_esyscmd} or @code{m4_esyscmd_s} for computing a version stringthat changes with every commit to a version control system (in fact,Autoconf does just that, for all builds of the development tree madebetween releases).The following M4 macros (e.g., @code{AC_PACKAGE_NAME}), output variables(e.g., @code{PACKAGE_NAME}), and preprocessor symbols (e.g.,@code{PACKAGE_NAME}), are defined by @code{AC_INIT}:@table @asis@item @code{AC_PACKAGE_NAME}, @code{PACKAGE_NAME}@acindex{PACKAGE_NAME}@ovindex PACKAGE_NAME@cvindex PACKAGE_NAMEExactly @var{package}.@item @code{AC_PACKAGE_TARNAME}, @code{PACKAGE_TARNAME}@acindex{PACKAGE_TARNAME}@ovindex PACKAGE_TARNAME@cvindex PACKAGE_TARNAMEExactly @var{tarname}, possibly generated from @var{package}.@item @code{AC_PACKAGE_VERSION}, @code{PACKAGE_VERSION}@acindex{PACKAGE_VERSION}@ovindex PACKAGE_VERSION@cvindex PACKAGE_VERSIONExactly @var{version}.@item @code{AC_PACKAGE_STRING}, @code{PACKAGE_STRING}@acindex{PACKAGE_STRING}@ovindex PACKAGE_STRING@cvindex PACKAGE_STRINGExactly @samp{@var{package} @var{version}}.@item @code{AC_PACKAGE_BUGREPORT}, @code{PACKAGE_BUGREPORT}@acindex{PACKAGE_BUGREPORT}@ovindex PACKAGE_BUGREPORT@cvindex PACKAGE_BUGREPORTExactly @var{bug-report}, if one was provided.  Typically an emailaddress, or URL to a bug management web page.@item @code{AC_PACKAGE_URL}, @code{PACKAGE_URL}@acindex{PACKAGE_URL}@ovindex PACKAGE_URL@cvindex PACKAGE_URLExactly @var{url}, if one was provided.  If @var{url} was empty, but@var{package} begins with @samp{GNU }, then this defaults to@samp{http://@/www.gnu.org/@/software/@/@var{tarname}/}, otherwise, no URL isassumed.@end table@end defmacIf your @command{configure} script does its own option processing, itshould inspect @samp{$@@} or @samp{$*} immediately after calling@code{AC_INIT}, because other Autoconf macros liberally use the@command{set} command to process strings, and this has the side effectof updating @samp{$@@} and @samp{$*}.  However, we suggest that you usestandard macros like @code{AC_ARG_ENABLE} instead of attempting toimplement your own option processing.  @xref{Site Configuration}.@node Versioning@section Dealing with Autoconf versions@cindex Autoconf version@cindex version, AutoconfThe following optional macros can be used to help choose the minimumversion of Autoconf that can successfully compile a given@file{configure.ac}.@defmac AC_PREREQ (@var{version})@acindex{PREREQ}@cindex VersionEnsure that a recent enough version of Autoconf is being used.  If theversion of Autoconf being used to create @command{configure} isearlier than @var{version}, print an error message to the standarderror output and exit with failure (exit status is 63).  For example:@exampleAC_PREREQ([@value{VERSION}])@end exampleThis macro may be used before @code{AC_INIT}.@end defmac@defmac AC_AUTOCONF_VERSION@acindex{AUTOCONF_VERSION}This macro was introduced in Autoconf 2.62.  It identifies the versionof Autoconf that is currently parsing the input file, in a formatsuitable for @code{m4_version_compare} (@pxref{m4_version_compare}); inother words, for this release of Autoconf, its value is@samp{@value{VERSION}}.  One potential use of this macro is for writingconditional fallbacks based on when a feature was added to Autoconf,rather than using @code{AC_PREREQ} to require the newer version ofAutoconf.  However, remember that the Autoconf philosophy favors featurechecks over version checks.You should not expand this macro directly; use@samp{m4_defn([AC_AUTOCONF_VERSION])} instead.  This is because someusers mighthave a beta version of Autoconf installed, with arbitrary lettersincluded in its version string.  This means it is possible for theversion string to contain the name of a defined macro, such thatexpanding @code{AC_AUTOCONF_VERSION} would trigger the expansion of thatmacro during rescanning, and change the version string to be differentthan what you intended to check.@end defmac@node Notices@section Notices in @command{configure}@cindex Notices in @command{configure}The following macros manage version numbers for @command{configure}scripts.  Using them is optional.@defmac AC_COPYRIGHT (@var{copyright-notice})@acindex{COPYRIGHT}@cindex Copyright NoticeState that, in addition to the Free Software Foundation's copyright onthe Autoconf macros, parts of your @command{configure} are covered by the@var{copyright-notice}.The @var{copyright-notice} shows up in both the head of@command{configure} and in @samp{configure --version}.@end defmac@defmac AC_REVISION (@var{revision-info})@acindex{REVISION}@cindex RevisionCopy revision stamp @var{revision-info} into the @command{configure}script, with any dollar signs or double-quotes removed.  This macro letsyou put a revision stamp from @file{configure.ac} into @command{configure}without RCS or CVS changing it when you check in@command{configure}.  That way, you can determine easily which revision of@file{configure.ac} a particular @command{configure} corresponds to.For example, this line in @file{configure.ac}:@c The @w prevents RCS from changing the example in the manual.@exampleAC_REVISION([@w{$}Revision: 1.30 $])@end example@noindentproduces this in @command{configure}:@example#!/bin/sh# From configure.ac Revision: 1.30@end example@end defmac@node Input@section Finding @command{configure} Input@anchor{AC_CONFIG_SRCDIR}@defmac AC_CONFIG_SRCDIR (@var{unique-file-in-source-dir})@acindex{CONFIG_SRCDIR}@var{unique-file-in-source-dir} is some file that is in the package'ssource directory; @command{configure} checks for this file's existence tomake sure that the directory that it is told contains the source code infact does.  Occasionally people accidentally specify the wrong directorywith @option{--srcdir}; this is a safety check.  @xref{configureInvocation}, for more information.@end defmac@c FIXME: Remove definitively once --install explained.@c@c Small packages may store all their macros in @code{aclocal.m4}.  As the@c set of macros grows, or for maintenance reasons, a maintainer may prefer@c to split the macros in several files.  In this case, Autoconf must be@c told which files to load, and in which order.@c@c @defmac AC_INCLUDE (@var{file}@dots{})@c @acindex{INCLUDE}@c @c FIXME: There is no longer shell globbing.@c Read the macro definitions that appear in the listed files.  A list of@c space-separated file names or shell globbing patterns is expected.  The@c files are read in the order they're listed.@c@c Because the order of definition of macros is important (only the last@c definition of a macro is used), beware that it is @code{AC_INIT} that@c loads @file{acsite.m4} and @file{aclocal.m4}.  Note that@c @code{AC_INCLUDE}ing a file before @code{AC_INIT} or within@c @file{aclocal.m4} is different from doing so after @code{AC_INIT}: in@c the latter case, non-macro lines from included files may end up in the@c @file{configure} script, whereas in the former case, they'd be discarded@c just like any text that appear before @code{AC_INIT}.@c @end defmacPackages that do manual configuration or use the @command{install} programmight need to tell @command{configure} where to find some other shellscripts by calling @code{AC_CONFIG_AUX_DIR}, though the default placesit looks are correct for most cases.@defmac AC_CONFIG_AUX_DIR (@var{dir})@acindex{CONFIG_AUX_DIR}Use the auxiliary build tools (e.g., @file{install-sh},@file{config.sub}, @file{config.guess}, Cygnus @command{configure},Automake and Libtool scripts, etc.)@: that are in directory @var{dir}.These are auxiliary files used in configuration.  @var{dir} can beeither absolute or relative to @file{@var{srcdir}}.  The default is@file{@var{srcdir}} or @file{@var{srcdir}/..} or@file{@var{srcdir}/../..}, whichever is the first that contains@file{install-sh}.  The other files are not checked for, so that using@code{AC_PROG_INSTALL} does not automatically require distributing theother auxiliary files.  It checks for @file{install.sh} also, but thatname is obsolete because some @command{make} have a rule that creates@file{install} from it if there is no makefile.The auxiliary directory is commonly named @file{build-aux}.If you need portability to DOS variants, do not name theauxiliary directory @file{aux}.  @xref{File System Conventions}.@end defmac@defmac AC_REQUIRE_AUX_FILE (@var{file})@acindex{REQUIRE_AUX_FILE}Declares that @var{file} is expected in the directory defined above.  InAutoconf proper, this macro does nothing: its sole purpose is to betraced by third-party tools to produce a list of expected auxiliaryfiles.  For instance it is called by macros like @code{AC_PROG_INSTALL}(@pxref{Particular Programs}) or @code{AC_CANONICAL_BUILD}(@pxref{Canonicalizing}) to register the auxiliary files they need.@end defmacSimilarly, packages that use @command{aclocal} should declare wherelocal macros can be found using @code{AC_CONFIG_MACRO_DIR}.@defmac AC_CONFIG_MACRO_DIR (@var{dir})@acindex{CONFIG_MACRO_DIR}Specify @var{dir} as the location of additional local Autoconf macros.This macro is intended for use by future versions of commands like@command{autoreconf} that trace macro calls.  It should be calleddirectly from @file{configure.ac} so that tools that install macros for@command{aclocal} can find the macros' declarations.Note that if you use @command{aclocal} from Automake to generate@file{aclocal.m4}, you must also set @code{ACLOCAL_AMFLAGS = -I@var{dir}} in your top-level @file{Makefile.am}.  Due to a limitation inthe Autoconf implementation of @command{autoreconf}, these includedirectives currently must be set on a single line in @file{Makefile.am},without any backslash-newlines.@end defmac@node Output@section Outputting Files@cindex Outputting filesEvery Autoconf script, e.g., @file{configure.ac}, should finish bycalling @code{AC_OUTPUT}.  That is the macro that generates and runs@file{config.status}, which in turn creates the makefiles and anyother files resulting from configuration.  This is the only requiredmacro besides @code{AC_INIT} (@pxref{Input}).@anchor{AC_OUTPUT}@defmac AC_OUTPUT@acindex{OUTPUT}@cindex InstantiationGenerate @file{config.status} and launch it.  Call this macro once, atthe end of @file{configure.ac}.@file{config.status} performs all the configuration actions: all theoutput files (see @ref{Configuration Files}, macro@code{AC_CONFIG_FILES}), header files (see @ref{Configuration Headers},macro @code{AC_CONFIG_HEADERS}), commands (see @ref{ConfigurationCommands}, macro @code{AC_CONFIG_COMMANDS}), links (see@ref{Configuration Links}, macro @code{AC_CONFIG_LINKS}), subdirectoriesto configure (see @ref{Subdirectories}, macro @code{AC_CONFIG_SUBDIRS})are honored.The location of your @code{AC_OUTPUT} invocation is the exact pointwhere configuration actions are taken: any code afterwards isexecuted by @command{configure} once @command{config.status} was run.  Ifyou want to bind actions to @command{config.status} itself(independently of whether @command{configure} is being run), see@ref{Configuration Commands, , Running Arbitrary ConfigurationCommands}.@end defmacHistorically, the usage of @code{AC_OUTPUT} was somewhat different.@xref{Obsolete Macros}, for a description of the arguments that@code{AC_OUTPUT} used to support.If you run @command{make} in subdirectories, you should run it using the@command{make} variable @code{MAKE}.  Most versions of @command{make} set@code{MAKE} to the name of the @command{make} program plus any options itwas given.  (But many do not include in it the values of any variablesset on the command line, so those are not passed on automatically.)Some old versions of @command{make} do not set this variable.  Thefollowing macro allows you to use it even with those versions.@anchor{AC_PROG_MAKE_SET}@defmac AC_PROG_MAKE_SET@acindex{PROG_MAKE_SET}@ovindex SET_MAKEIf the Make command, @code{$MAKE} if set or else @samp{make}, predefines@code{$(MAKE)}, define output variable @code{SET_MAKE} to be empty.Otherwise, define @code{SET_MAKE} to a macro definition that sets@code{$(MAKE)}, such as @samp{MAKE=make}.  Calls @code{AC_SUBST} for@code{SET_MAKE}.@end defmacIf you use this macro, place a line like this in each @file{Makefile.in}that runs @command{MAKE} on other directories:@example@@SET_MAKE@@@end example@node Configuration Actions@section Performing Configuration Actions@cindex Configuration actions@file{configure} is designed so that it appears to do everything itself,but there is actually a hidden slave: @file{config.status}.@file{configure} is in charge of examining your system, but it is@file{config.status} that actually takes the proper actions based on theresults of @file{configure}.  The most typical task of@file{config.status} is to @emph{instantiate} files.@acindex{CONFIG_@var{ITEMS}}This section describes the common behavior of the four standardinstantiating macros: @code{AC_CONFIG_FILES}, @code{AC_CONFIG_HEADERS},@code{AC_CONFIG_COMMANDS} and @code{AC_CONFIG_LINKS}.  They allhave this prototype:@c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something@c awful.@exampleAC_CONFIG_@var{ITEMS}(@var{tag}@dots{}, @r{[}@var{commands}@r{]}, @r{[}@var{init-cmds}@r{]})@end example@noindentwhere the arguments are:@table @var@item tag@dots{}A blank-or-newline-separated list of tags, which are typically the names ofthe files to instantiate.You are encouraged to use literals as @var{tags}.  In particular, youshould avoid@example@dots{} && my_foos="$my_foos fooo"@dots{} && my_foos="$my_foos foooo"AC_CONFIG_@var{ITEMS}([$my_foos])@end example@noindentand use this instead:@example@dots{} && AC_CONFIG_@var{ITEMS}([fooo])@dots{} && AC_CONFIG_@var{ITEMS}([foooo])@end exampleThe macros @code{AC_CONFIG_FILES} and @code{AC_CONFIG_HEADERS} usespecial @var{tag} values: they may have the form @samp{@var{output}} or@samp{@var{output}:@var{inputs}}.  The file @var{output} is instantiatedfrom its templates, @var{inputs} (defaulting to @samp{@var{output}.in}).@samp{AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk])},for example, asks forthe creation of the file @file{Makefile} that contains the expansion of theoutput variables in the concatenation of @file{boiler/top.mk} and@file{boiler/bot.mk}.The special value @samp{-} might be used to denote the standard outputwhen used in @var{output}, or the standard input when used in the@var{inputs}.  You most probably don't need to use this in@file{configure.ac}, but it is convenient when using the command lineinterface of @file{./config.status}, see @ref{config.status Invocation},for more details.The @var{inputs} may be absolute or relative file names.  In the lattercase they are first looked for in the build tree, and then in the sourcetree.  Input files should be text files, and a line length below 2000bytes should be safe.@item commandsShell commands output literally into @file{config.status}, andassociated with a tag that the user can use to tell @file{config.status}which commands to run.  The commands are run each time a @var{tag}request is given to @file{config.status}, typically each time the file@file{@var{tag}} is created.The variables set during the execution of @command{configure} are@emph{not} available here: you first need to set them via the@var{init-cmds}.  Nonetheless the following variables are precomputed:@table @code@item srcdir@vrindex srcdirThe name of the top source directory, assuming that the workingdirectory is the top build directory.  Thisis what the @command{configure} option @option{--srcdir} sets.@item ac_top_srcdir@vrindex ac_top_srcdirThe name of the top source directory, assuming that the workingdirectory is the current build directory.@item ac_top_build_prefix@vrindex ac_top_build_prefixThe name of the top build directory, assuming that the workingdirectory is the current build directory.It can be empty, or else ends with a slash, so that you may concatenateit.@item ac_srcdir@vrindex ac_srcdirThe name of the corresponding source directory, assuming that theworking directory is the current build directory.@item tmp@vrindex tmpThe name of a temporary directory within the build tree, which youcan use if you need to create additional temporary files.  Thedirectory is cleaned up when @command{config.status} is done orinterrupted.  Please use package-specific file name prefixes toavoid clashing with files that @command{config.status} may useinternally.@end table@noindentThe @dfn{current} directory refers to the directory (orpseudo-directory) containing the input part of @var{tags}.  Forinstance, running@exampleAC_CONFIG_COMMANDS([deep/dir/out:in/in.in], [@dots{}], [@dots{}])@end example@noindent with @option{--srcdir=../package} produces the following values:@example# Argument of --srcdirsrcdir='../package'# Reversing deep/dirac_top_build_prefix='../../'# Concatenation of $ac_top_build_prefix and srcdirac_top_srcdir='../../../package'# Concatenation of $ac_top_srcdir and deep/dirac_srcdir='../../../package/deep/dir'@end example@noindentindependently of @samp{in/in.in}.@item init-cmdsShell commands output @emph{unquoted} near the beginning of@file{config.status}, and executed each time @file{config.status} runs(regardless of the tag).  Because they are unquoted, for example,@samp{$var} is output as the value of @code{var}.  @var{init-cmds}is typically used by @file{configure} to give @file{config.status} somevariables it needs to run the @var{commands}.You should be extremely cautious in your variable names: all the@var{init-cmds} share the same name space and may overwrite each otherin unpredictable ways.  Sorry@enddots{}@end tableAll these macros can be called multiple times, with different@var{tag} values, of course!@node Configuration Files@section Creating Configuration Files@cindex Creating configuration files@cindex Configuration file creationBe sure to read the previous section, @ref{Configuration Actions}.@anchor{AC_CONFIG_FILES}@defmac AC_CONFIG_FILES (@var{file}@dots{}, @ovar{cmds}, @ovar{init-cmds})@acindex{CONFIG_FILES}Make @code{AC_OUTPUT} create each @file{@var{file}} by copying an inputfile (by default @file{@var{file}.in}), substituting the output variablevalues.@c Before we used to have this feature, which was later rejected@c because it complicates the writing of makefiles:@c If the file would be unchanged, it is left untouched, to preserve@c timestamp.This macro is one of the instantiating macros; see @ref{ConfigurationActions}.  @xref{Makefile Substitutions}, for more information on usingoutput variables.  @xref{Setting Output Variables}, for more informationon creating them.  This macro creates the directory that the file is inif it doesn't exist.  Usually, makefiles are created this way,but other files, such as @file{.gdbinit}, can be specified as well.Typical calls to @code{AC_CONFIG_FILES} look like this:@exampleAC_CONFIG_FILES([Makefile src/Makefile man/Makefile X/Imakefile])AC_CONFIG_FILES([autoconf], [chmod +x autoconf])@end exampleYou can override an input file name by appending to @var{file} acolon-separated list of input files.  Examples:@exampleAC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk]                [lib/Makefile:boiler/lib.mk])@end example@noindentDoing this allows you to keep your file names acceptable toDOS variants, orto prepend and/or append boilerplate to the file.@end defmac@node Makefile Substitutions@section Substitutions in Makefiles@cindex Substitutions in makefiles@cindex Makefile substitutionsEach subdirectory in a distribution that contains something to becompiled or installed should come with a file @file{Makefile.in}, fromwhich @command{configure} creates a file @file{Makefile} in that directory.To create @file{Makefile}, @command{configure} performs a simple variablesubstitution, replacing occurrences of @samp{@@@var{variable}@@} in@file{Makefile.in} with the value that @command{configure} has determinedfor that variable.  Variables that are substituted into output files inthis way are called @dfn{output variables}.  They are ordinary shellvariables that are set in @command{configure}.  To make @command{configure}substitute a particular variable into the output files, the macro@code{AC_SUBST} must be called with that variable name as an argument.Any occurrences of @samp{@@@var{variable}@@} for other variables areleft unchanged.  @xref{Setting Output Variables}, for more informationon creating output variables with @code{AC_SUBST}.A software package that uses a @command{configure} script should bedistributed with a file @file{Makefile.in}, but no makefile; thatway, the user has to properly configure the package for the local systembefore compiling it.@xref{Makefile Conventions, , Makefile Conventions, standards, TheGNU Coding Standards}, for more information on what to put inmakefiles.@menu* Preset Output Variables::     Output variables that are always set* Installation Directory Variables::  Other preset output variables* Changed Directory Variables::  Warnings about @file{datarootdir}* Build Directories::           Supporting multiple concurrent compiles* Automatic Remaking::          Makefile rules for configuring@end menu@node Preset Output Variables@subsection Preset Output Variables@cindex Output variablesSome output variables are preset by the Autoconf macros.  Some of theAutoconf macros set additional output variables, which are mentioned inthe descriptions for those macros.  @xref{Output Variable Index}, for acomplete list of output variables.  @xref{Installation DirectoryVariables}, for the list of the preset ones related to installationdirectories.  Below are listed the other preset ones, many of which areprecious variables (@pxref{Setting Output Variables},@code{AC_ARG_VAR}).The preset variables which are available during @file{config.status}(@pxref{Configuration Actions}) may also be used during@command{configure} tests.  For example, it is permissible to reference@samp{$srcdir} when constructing a list of directories to pass viaoption @option{-I} during a compiler feature check.  When used in thismanner, coupled with the fact that @command{configure} is always runfrom the top build directory, it is sufficient to use just@samp{$srcdir} instead of @samp{$top_srcdir}.@c Just say no to ASCII sorting!  We're humans, not computers.@c These variables are listed as they would be in a dictionary:@c actor@c Actress@c actress@defvar CFLAGS@evindex CFLAGS@ovindex CFLAGSDebugging and optimization options for the C compiler.  If it is not setin the environment when @command{configure} runs, the default value is setwhen you call @code{AC_PROG_CC} (or empty if you don't).  @command{configure}uses this variable when compiling or linking programs to test for C features.If a compiler option affects only the behavior of the preprocessor(e.g., @option{-D@var{name}}), it should be put into @code{CPPFLAGS}instead.  If it affects only the linker (e.g., @option{-L@var{directory}}),it should be put into @code{LDFLAGS} instead.  If itaffects only the compiler proper, @code{CFLAGS} is the natural home forit.  If an option affects multiple phases of the compiler, though,matters get tricky.  One approach to put such options directly into@code{CC}, e.g., @code{CC='gcc -m64'}.  Another is to put them into both@code{CPPFLAGS} and @code{LDFLAGS}, but not into @code{CFLAGS}.However, remember that some @file{Makefile} variables are reserved bythe GNU Coding Standards for the use of the ``user''---the personbuilding the package.  For instance, @code{CFLAGS} is one such variable.Sometimes package developers are tempted to set user variables such as@code{CFLAGS} because it appears to make their job easier.  However, thepackage itself should never set a user variable, particularly not toinclude switches that are required for proper compilation of thepackage.  Since these variables are documented as being for the packagebuilder, that person rightfully expects to be able to override any ofthese variables at build time.  If the package developer needs to addswitches without interfering with the user, the proper way to do that isto introduce an additional variable.  Automake makes this easy byintroducing @code{AM_CFLAGS} (@pxref{Flag Variables Ordering, , ,automake, GNU Automake}), but the concept is the same even ifAutomake is not used.@end defvar@defvar configure_input@ovindex configure_inputA comment saying that the file was generated automatically by@command{configure} and giving the name of the input file.@code{AC_OUTPUT} adds a comment line containing this variable to the topof every makefile it creates.  For other files, you shouldreference this variable in a comment at the top of each input file.  Forexample, an input shell script should begin like this:@example#!/bin/sh# @@configure_input@@@end example@noindentThe presence of that line also reminds people editing the file that itneeds to be processed by @command{configure} in order to be used.@end defvar@defvar CPPFLAGS@evindex CPPFLAGS@ovindex CPPFLAGSPreprocessor options for the C, C++, Objective C, and Objective C++preprocessors and compilers.  Ifit is not set in the environment when @command{configure} runs, the defaultvalue is empty.  @command{configure} uses this variable when preprocessingor compiling programs to test for C, C++, Objective C, and Objective C++features.This variable's contents should contain options like @option{-I},@option{-D}, and @option{-U} that affect only the behavior of thepreprocessor.  Please see the explanation of @code{CFLAGS} for what youcan do if an option affects other phases of the compiler as well.Currently, @command{configure} always links as part of a singleinvocation of the compiler that also preprocesses and compiles, so ituses this variable also when linking programs.  However, it is unwise todepend on this behavior because the GNU Coding Standards donot require it and many packages do not use @code{CPPFLAGS} when linkingprograms.@xref{Special Chars in Variables}, for limitations that @code{CPPFLAGS}might run into.@end defvar@defvar CXXFLAGS@evindex CXXFLAGS@ovindex CXXFLAGSDebugging and optimization options for the C++ compiler.  It acts like@code{CFLAGS}, but for C++ instead of C.@end defvar@defvar DEFS@ovindex DEFS@option{-D} options to pass to the C compiler.  If @code{AC_CONFIG_HEADERS}is called, @command{configure} replaces @samp{@@DEFS@@} with@option{-DHAVE_CONFIG_H} instead (@pxref{Configuration Headers}).  Thisvariable is not defined while @command{configure} is performing its tests,only when creating the output files.  @xref{Setting Output Variables}, forhow to check the results of previous tests.@end defvar@defvar ECHO_C@defvarx ECHO_N@defvarx ECHO_T@ovindex ECHO_C@ovindex ECHO_N@ovindex ECHO_THow does one suppress the trailing newline from @command{echo} forquestion-answer message pairs?  These variables provide a way:@exampleecho $ECHO_N "And the winner is... $ECHO_C"sleep 100000000000echo "$@{ECHO_T@}dead."@end example@noindentSome old and uncommon @command{echo} implementations offer no means toachieve this, in which case @code{ECHO_T} is set to tab.  You might notwant to use it.@end defvar@defvar ERLCFLAGS@evindex ERLCFLAGS@ovindex ERLCFLAGSDebugging and optimization options for the Erlang compiler.  If it is not setin the environment when @command{configure} runs, the default value is empty.@command{configure} uses this variable when compilingprograms to test for Erlang features.@end defvar@defvar FCFLAGS@evindex FCFLAGS@ovindex FCFLAGSDebugging and optimization options for the Fortran compiler.  If itis not set in the environment when @command{configure} runs, the defaultvalue is set when you call @code{AC_PROG_FC} (or empty if you don't).@command{configure} uses this variable when compiling or linkingprograms to test for Fortran features.@end defvar@defvar FFLAGS@evindex FFLAGS@ovindex FFLAGSDebugging and optimization options for the Fortran 77 compiler.  If itis not set in the environment when @command{configure} runs, the defaultvalue is set when you call @code{AC_PROG_F77} (or empty if you don't).@command{configure} uses this variable when compiling or linkingprograms to test for Fortran 77 features.@end defvar@defvar LDFLAGS@evindex LDFLAGS@ovindex LDFLAGSOptions for the linker.  If it is not setin the environment when @command{configure} runs, the default value is empty.@command{configure} uses this variable when linking programs to test forC, C++, Objective C, Objective C++, Fortran, and Go features.This variable's contents should contain options like @option{-s} and@option{-L} that affect only the behavior of the linker.  Please see theexplanation of @code{CFLAGS} for what you can do if an option alsoaffects other phases of the compiler.Don't use this variable to pass library names(@option{-l}) to the linker; use @code{LIBS} instead.@end defvar@defvar LIBS@evindex LIBS@ovindex LIBS@option{-l} options to pass to the linker.  The default value is empty,but some Autoconf macros may prepend extra libraries to this variable ifthose libraries are found and provide necessary functions, see@ref{Libraries}.  @command{configure} uses this variable when linkingprograms to test for C, C++, Objective C, Objective C++, Fortran, and Gofeatures.@end defvar@defvar OBJCFLAGS@evindex OBJCFLAGS@ovindex OBJCFLAGSDebugging and optimization options for the Objective C compiler.  Itacts like @code{CFLAGS}, but for Objective C instead of C.@end defvar@defvar OBJCXXFLAGS@evindex OBJCXXFLAGS@ovindex OBJCXXFLAGSDebugging and optimization options for the Objective C++ compiler.  Itacts like @code{CXXFLAGS}, but for Objective C++ instead of C++.@end defvar@defvar GOFLAGS@evindex GOFLAGS@ovindex GOFLAGSDebugging and optimization options for the Go compiler.  It acts like@code{CFLAGS}, but for Go instead of C.@end defvar@defvar builddir@ovindex builddirRigorously equal to @samp{.}.  Added for symmetry only.@end defvar@defvar abs_builddir@ovindex abs_builddirAbsolute name of @code{builddir}.@end defvar@defvar top_builddir@ovindex top_builddirThe relative name of the top level of the current build tree.  In thetop-level directory, this is the same as @code{builddir}.@end defvar@defvar top_build_prefix@ovindex top_build_prefixThe relative name of the top level of the current build tree with finalslash if nonempty.  This is the same as @code{top_builddir}, except thatit contains zero or more runs of @code{../}, so it should not beappended with a slash for concatenation.  This helps for @command{make}implementations that otherwise do not treat @file{./file} and @file{file}as equal in the toplevel build directory.@end defvar@defvar abs_top_builddir@ovindex abs_top_builddirAbsolute name of @code{top_builddir}.@end defvar@defvar srcdir@ovindex srcdirThe name of the directory that contains the source code forthat makefile.@end defvar@defvar abs_srcdir@ovindex abs_srcdirAbsolute name of @code{srcdir}.@end defvar@defvar top_srcdir@ovindex top_srcdirThe name of the top-level source code directory for thepackage.  In the top-level directory, this is the same as @code{srcdir}.@end defvar@defvar abs_top_srcdir@ovindex abs_top_srcdirAbsolute name of @code{top_srcdir}.@end defvar@node Installation Directory Variables@subsection Installation Directory Variables@cindex Installation directories@cindex Directories, installationThe following variables specify the directories forpackage installation, see @ref{Directory Variables, , Variables forInstallation Directories, standards, The GNU CodingStandards}, for more information.  Each variable corresponds to anargument of @command{configure}; trailing slashes are stripped so thatexpressions such as @samp{$@{prefix@}/lib} expand with only one slashbetween directory names.  See the end of this section fordetails on when and how to use these variables.@defvar bindir@ovindex bindirThe directory for installing executables that users run.@end defvar@defvar datadir@ovindex datadirThe directory for installing idiosyncratic read-onlyarchitecture-independent data.@end defvar@defvar datarootdir@ovindex datarootdirThe root of the directory tree for read-only architecture-independentdata files.@end defvar@defvar docdir@ovindex docdirThe directory for installing documentation files (other than Info andman).@end defvar@defvar dvidir@ovindex dvidirThe directory for installing documentation files in DVI format.@end defvar@defvar exec_prefix@ovindex exec_prefixThe installation prefix for architecture-dependent files.  By defaultit's the same as @code{prefix}.  You should avoid installing anythingdirectly to @code{exec_prefix}.  However, the default value fordirectories containing architecture-dependent files should be relativeto @code{exec_prefix}.@end defvar@defvar htmldir@ovindex htmldirThe directory for installing HTML documentation.@end defvar@defvar includedir@ovindex includedirThe directory for installing C header files.@end defvar@defvar infodir@ovindex infodirThe directory for installing documentation in Info format.@end defvar@defvar libdir@ovindex libdirThe directory for installing object code libraries.@end defvar@defvar libexecdir@ovindex libexecdirThe directory for installing executables that other programs run.@end defvar@defvar localedir@ovindex localedirThe directory for installing locale-dependent butarchitecture-independent data, such as message catalogs.  This directoryusually has a subdirectory per locale.@end defvar@defvar localstatedir@ovindex localstatedirThe directory for installing modifiable single-machine data.@end defvar@defvar mandir@ovindex mandirThe top-level directory for installing documentation in man format.@end defvar@defvar oldincludedir@ovindex oldincludedirThe directory for installing C header files for non-GCC compilers.@end defvar@defvar pdfdir@ovindex pdfdirThe directory for installing PDF documentation.@end defvar@defvar prefix@ovindex prefixThe common installation prefix for all files.  If @code{exec_prefix}is defined to a different value, @code{prefix} is used only forarchitecture-independent files.@end defvar@defvar psdir@ovindex psdirThe directory for installing PostScript documentation.@end defvar@defvar sbindir@ovindex sbindirThe directory for installing executables that systemadministrators run.@end defvar@defvar sharedstatedir@ovindex sharedstatedirThe directory for installing modifiable architecture-independent data.@end defvar@defvar sysconfdir@ovindex sysconfdirThe directory for installing read-only single-machine data.@end defvarMost of these variables have values that rely on @code{prefix} or@code{exec_prefix}.  It is deliberate that the directory outputvariables keep them unexpanded: typically @samp{@@datarootdir@@} isreplaced by @samp{$@{prefix@}/share}, not @samp{/usr/local/share}, and@samp{@@datadir@@} is replaced by @samp{$@{datarootdir@}}.This behavior is mandated by the GNU Coding Standards, so that whenthe user runs:@table @samp@item makeshe can still specify a different prefix from the one specified to@command{configure}, in which case, if needed, the package should hardcode dependencies corresponding to the make-specified prefix.@item make installshe can specify a different installation location, in which case thepackage @emph{must} still depend on the location which was compiled in(i.e., never recompile when @samp{make install} is run).  This is anextremely important feature, as many people may decide to install allthe files of a package grouped together, and then install links fromthe final locations to there.@end tableIn order to support these features, it is essential that@code{datarootdir} remains defined as @samp{$@{prefix@}/share},so that its value can be expanded basedon the current value of @code{prefix}.A corollary is that you should not use these variables except inmakefiles.  For instance, instead of trying to evaluate @code{datadir}in @file{configure} and hard-coding it in makefiles usinge.g., @samp{AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])},you should add@option{-DDATADIR='$(datadir)'} to your makefile's definition of@code{CPPFLAGS} (@code{AM_CPPFLAGS} if you are also using Automake).Similarly, you should not rely on @code{AC_CONFIG_FILES} to replace@code{bindir} and friends in your shell scripts and other files; instead,let @command{make} manage their replacement.  For instance Autoconfships templates of its shell scripts ending with @samp{.in}, and uses amakefile snippet similar to the following to build scripts like@command{autoheader} and @command{autom4te}:@example@groupedit = sed \        -e 's|@@bindir[@@]|$(bindir)|g' \        -e 's|@@pkgdatadir[@@]|$(pkgdatadir)|g' \        -e 's|@@prefix[@@]|$(prefix)|g'@end group@groupautoheader autom4te: Makefile        rm -f $@@ $@@.tmp        srcdir=''; \          test -f ./$@@.in || srcdir=$(srcdir)/; \          $(edit) $$@{srcdir@}$@@.in >$@@.tmp@c $$ restore font-lock        chmod +x $@@.tmp        chmod a-w $@@.tmp        mv $@@.tmp $@@@end group@groupautoheader: $(srcdir)/autoheader.inautom4te: $(srcdir)/autom4te.in@end group@end exampleSome details are noteworthy:@table @asis@item @samp{@@bindir[@@]}The brackets prevent @command{configure} from replacing@samp{@@bindir@@} in the Sed expression itself.Brackets are preferable to a backslash here, sincePosix says @samp{\@@} is not portable.@item @samp{$(bindir)}Don't use @samp{@@bindir@@}!  Use the matching makefile variableinstead.@item @samp{$(pkgdatadir)}The example takes advantage of the variable @samp{$(pkgdatadir)}provided by Automake; it is equivalent to @samp{$(datadir)/$(PACKAGE)}.@item @samp{/}Don't use @samp{/} in the Sed expressions that replace file names sincemost likely thevariables you use, such as @samp{$(bindir)}, contain @samp{/}.Use a shell metacharacter instead, such as @samp{|}.@item special charactersFile names, file name components, and the value of @code{VPATH} shouldnot contain shell metacharacters or whitespace.  @xref{Special Chars in Variables}.@item dependency on @file{Makefile}Since @code{edit} uses values that depend on the configuration specificvalues (@code{prefix}, etc.)@: and not only on @code{VERSION} and so forth,the output depends on @file{Makefile}, not @file{configure.ac}.@item @samp{$@@}The main rule is generic, and uses @samp{$@@} extensively toavoid the need for multiple copies of the rule.@item Separated dependencies and single suffix rulesYou can't use them!  The above snippet cannot be (portably) rewrittenas:@exampleautoconf autoheader: Makefile@group.in:        rm -f $@@ $@@.tmp        $(edit) $< >$@@.tmp        chmod +x $@@.tmp        mv $@@.tmp $@@@end group@end example@xref{Single Suffix Rules}, for details.@item @samp{$(srcdir)}Be sure to specify the name of the source directory,otherwise the package won't support separated builds.@end tableFor the more specific installation of Erlang libraries, the following variablesare defined:@defvar ERLANG_INSTALL_LIB_DIR@ovindex ERLANG_INSTALL_LIB_DIR@acindex{ERLANG_SUBST_INSTALL_LIB_DIR}The common parent directory of Erlang library installation directories.This variable is set by calling the @code{AC_ERLANG_SUBST_INSTALL_LIB_DIR}macro in @file{configure.ac}.@end defvar@defvar ERLANG_INSTALL_LIB_DIR_@var{library}@ovindex ERLANG_INSTALL_LIB_DIR_@var{library}@acindex{ERLANG_SUBST_INSTALL_LIB_SUBDIR}The installation directory for Erlang library @var{library}.This variable is set by using the@samp{AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR}macro in @file{configure.ac}.@end defvar@xref{Erlang Libraries}, for details.@node Changed Directory Variables@subsection Changed Directory Variables@cindex @file{datarootdir}In Autoconf 2.60, the set of directory variables has changed, and thedefaults of some variables have been adjusted(@pxref{Installation Directory Variables}) to changes in theGNU Coding Standards.  Notably, @file{datadir}, @file{infodir}, and@file{mandir} are now expressed in terms of @file{datarootdir}.  If you areupgrading from an earlier Autoconf version, you may need to adjust your filesto ensure that the directory variables are substituted correctly(@pxref{Defining Directories}), and that a definition of @file{datarootdir} isin place.  For example, in a @file{Makefile.in}, adding@exampledatarootdir = @@datarootdir@@@end example@noindentis usually sufficient.  If you use Automake to create @file{Makefile.in},it will add this for you.To help with the transition, Autoconf warns about files that seem to use@code{datarootdir} without defining it.  In some cases, it then expandsthe value of @code{$datarootdir} in substitutions of the directoryvariables.  The following example shows such a warning:@example$ @kbd{cat configure.ac}AC_INITAC_CONFIG_FILES([Makefile])AC_OUTPUT$ @kbd{cat Makefile.in}prefix = @@prefix@@datadir = @@datadir@@$ @kbd{autoconf}$ @kbd{configure}configure: creating ./config.statusconfig.status: creating Makefileconfig.status: WARNING:               Makefile.in seems to ignore the --datarootdir setting$ @kbd{cat Makefile}prefix = /usr/localdatadir = $@{prefix@}/share@end exampleUsually one can easily change the file to accommodate both older and newerAutoconf releases:@example$ @kbd{cat Makefile.in}prefix = @@prefix@@datarootdir = @@datarootdir@@datadir = @@datadir@@$ @kbd{configure}configure: creating ./config.statusconfig.status: creating Makefile$ @kbd{cat Makefile}prefix = /usr/localdatarootdir = $@{prefix@}/sharedatadir = $@{datarootdir@}@end example@acindex{DATAROOTDIR_CHECKED}In some cases, however, the checks may not be able to detect that a suitableinitialization of @code{datarootdir} is in place, or they may fail to detectthat such an initialization is necessary in the output file.  If, afterauditing your package, there are still spurious @file{configure} warnings about@code{datarootdir}, you may add the line@exampleAC_DEFUN([AC_DATAROOTDIR_CHECKED])@end example@noindentto your @file{configure.ac} to disable the warnings.  This is an exceptionto the usual rule that you should not define a macro whose name begins with@code{AC_} (@pxref{Macro Names}).@node Build Directories@subsection Build Directories@cindex Build directories@cindex Directories, buildYou can support compiling a software package for several architecturessimultaneously from the same copy of the source code.  The object filesfor each architecture are kept in their own directory.To support doing this, @command{make} uses the @code{VPATH} variable tofind the files that are in the source directory.  GNU Makecan do this.  Most other recent @command{make} programs can do this aswell, though they may have difficulties and it is often simpler torecommend GNU @command{make} (@pxref{VPATH and Make}).  Older@command{make} programs do not support @code{VPATH}; when using them, thesource code must be in the same directory as the object files.If you are using GNU Automake, the remaining details in thissection are already covered for you, based on the contents of your@file{Makefile.am}.  But if you are using Autoconf in isolation, thensupporting @code{VPATH} requires the following in your@file{Makefile.in}:@examplesrcdir = @@srcdir@@VPATH = @@srcdir@@@end exampleDo not set @code{VPATH} to the value of another variable (@pxref{Variableslisted in VPATH}.@command{configure} substitutes the correct value for @code{srcdir} whenit produces @file{Makefile}.Do not use the @command{make} variable @code{$<}, which expands to thefile name of the file in the source directory (found with @code{VPATH}),except in implicit rules.  (An implicit rule is one such as @samp{.c.o},which tells how to create a @file{.o} file from a @file{.c} file.)  Someversions of @command{make} do not set @code{$<} in explicit rules; theyexpand it to an empty value.Instead, Make command lines should always refer to sourcefiles by prefixing them with @samp{$(srcdir)/}.  For example:@exampletime.info: time.texinfo        $(MAKEINFO) '$(srcdir)/time.texinfo'@end example@node Automatic Remaking@subsection Automatic Remaking@cindex Automatic remaking@cindex Remaking automaticallyYou can put rules like the following in the top-level @file{Makefile.in}for a package to automatically update the configuration information whenyou change the configuration files.  This example includes all of theoptional files, such as @file{aclocal.m4} and those related toconfiguration header files.  Omit from the @file{Makefile.in} rules forany of these files that your package does not use.The @samp{$(srcdir)/} prefix is included because of limitations in the@code{VPATH} mechanism.The @file{stamp-} files are necessary because the timestamps of@file{config.h.in} and @file{config.h} are not changed if remakingthem does not change their contents.  This feature avoids unnecessaryrecompilation.  You should include the file @file{stamp-h.in} in yourpackage's distribution, so that @command{make} considers@file{config.h.in} up to date.  Don't use @command{touch}(@pxref{touch, , Limitations of Usual Tools}); instead, use@command{echo} (using@command{date} would cause needless differences, hence CVSconflicts, etc.).@example@group$(srcdir)/configure: configure.ac aclocal.m4        cd '$(srcdir)' && autoconf# autoheader might not change config.h.in, so touch a stamp file.$(srcdir)/config.h.in: stamp-h.in$(srcdir)/stamp-h.in: configure.ac aclocal.m4        cd '$(srcdir)' && autoheader        echo timestamp > '$(srcdir)/stamp-h.in'config.h: stamp-hstamp-h: config.h.in config.status        ./config.statusMakefile: Makefile.in config.status        ./config.statusconfig.status: configure        ./config.status --recheck@end group@end example@noindent(Be careful if you copy these lines directly into your makefile, as youneed to convert the indented lines to start with the tab character.)In addition, you should use@exampleAC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])@end example@noindentso @file{config.status} ensures that @file{config.h} is considered up todate.  @xref{Output}, for more information about @code{AC_OUTPUT}.@xref{config.status Invocation}, for more examples of handlingconfiguration-related dependencies.@node Configuration Headers@section Configuration Header Files@cindex Configuration Header@cindex @file{config.h}When a package contains more than a few tests that define C preprocessorsymbols, the command lines to pass @option{-D} options to the compilercan get quite long.  This causes two problems.  One is that the@command{make} output is hard to visually scan for errors.  Moreseriously, the command lines can exceed the length limits of someoperating systems.  As an alternative to passing @option{-D} options tothe compiler, @command{configure} scripts can create a C header filecontaining @samp{#define} directives.  The @code{AC_CONFIG_HEADERS}macro selects this kind of output.  Though it can be called anywherebetween @code{AC_INIT} and @code{AC_OUTPUT}, it is customary to callit right after @code{AC_INIT}.The package should @samp{#include} the configuration header file beforeany other header files, to prevent inconsistencies in declarations (forexample, if it redefines @code{const}).To provide for VPATH builds, remember to pass the C compiler a @option{-I.}option (or @option{-I..}; whichever directory contains @file{config.h}).Even if you use @samp{#include "config.h"}, the preprocessor searches onlythe directory of the currently read file, i.e., the source directory, notthe build directory.With the appropriate @option{-I} option, you can use@samp{#include <config.h>}.  Actually, it's a good habit to use it,because in the rare case when the source directory contains another@file{config.h}, the build directory should be searched first.@defmac AC_CONFIG_HEADERS (@var{header} @dots{}, @ovar{cmds}, @ovar{init-cmds})@acindex{CONFIG_HEADERS}@cvindex HAVE_CONFIG_HThis macro is one of the instantiating macros; see @ref{ConfigurationActions}.  Make @code{AC_OUTPUT} create the file(s) in theblank-or-newline-separated list @var{header} containing C preprocessor@code{#define} statements, and replace @samp{@@DEFS@@} in generatedfiles with @option{-DHAVE_CONFIG_H} instead of the value of @code{DEFS}.The usual name for @var{header} is @file{config.h}.If @var{header} already exists and its contents are identical to what@code{AC_OUTPUT} would put in it, it is left alone.  Doing this allowsmaking some changes in the configuration without needlessly causingobject files that depend on the header file to be recompiled.Usually the input file is named @file{@var{header}.in}; however, you canoverride the input file name by appending to @var{header} acolon-separated list of input files.  For example, you might need to makethe input file name acceptable to DOS variants:@exampleAC_CONFIG_HEADERS([config.h:config.hin])@end example@end defmac@defmac AH_HEADER@ahindex{HEADER}This macro is defined as the name of the first declared config headerand undefined if no config headers have been declared up to this point.A third-party macro may, for example, require use of a config headerwithout invoking AC_CONFIG_HEADERS twice, like this:@exampleAC_CONFIG_COMMANDS_PRE(        [m4_ifndef([AH_HEADER], [AC_CONFIG_HEADERS([config.h])])])@end example@end defmac@xref{Configuration Actions}, for more details on @var{header}.@menu* Header Templates::            Input for the configuration headers* autoheader Invocation::       How to create configuration templates* Autoheader Macros::           How to specify CPP templates@end menu@node Header Templates@subsection Configuration Header Templates@cindex Configuration Header Template@cindex Header templates@cindex @file{config.h.in}Your distribution should contain a template file that looks as you wantthe final header file to look, including comments, with @code{#undef}statements which are used as hooks.  For example, suppose your@file{configure.ac} makes these calls:@exampleAC_CONFIG_HEADERS([conf.h])AC_CHECK_HEADERS([unistd.h])@end example@noindentThen you could have code like the following in @file{conf.h.in}.The @file{conf.h} created by @command{configure} defines @samp{HAVE_UNISTD_H}to 1, if and only if the system has @file{unistd.h}.@example@group/* Define as 1 if you have unistd.h.  */#undef HAVE_UNISTD_H@end group@end exampleThe format of the template file is stricter than what the C preprocessoris required to accept.  A directive line should contain only whitespace,@samp{#undef}, and @samp{HAVE_UNISTD_H}.  The use of @samp{#define}instead of @samp{#undef}, or of comments on the same line as@samp{#undef}, is strongly discouraged.  Each hook should only be listedonce.  Other preprocessor lines, such as @samp{#ifdef} or@samp{#include}, are copied verbatim from the template into thegenerated header.Since it is a tedious task to keep a template header up to date, you mayuse @command{autoheader} to generate it, see @ref{autoheader Invocation}.During the instantiation of the header, each @samp{#undef} line in thetemplate file for each symbol defined by @samp{AC_DEFINE} is changed to anappropriate @samp{#define}. If the corresponding @samp{AC_DEFINE} has notbeen executed during the @command{configure} run, the @samp{#undef} line iscommented out.  (This is important, e.g., for @samp{_POSIX_SOURCE}:on many systems, it can be implicitly defined by the compiler, andundefining it in the header would then break compilation of subsequentheaders.)Currently, @emph{all} remaining @samp{#undef} lines in the headertemplate are commented out, whether or not there was a corresponding@samp{AC_DEFINE} for the macro name; but this behavior is not guaranteedfor future releases of Autoconf.Generally speaking, since you should not use @samp{#define}, and youcannot guarantee whether a @samp{#undef} directive in the headertemplate will be converted to a @samp{#define} or commented out in thegenerated header file, the template file cannot be used for conditionaldefinition effects.  Consequently, if you need to use the construct@example@group#ifdef THIS# define THAT#endif@end group@end example@noindentyou must place it outside of the template.If you absolutely need to hook it to the config header itself, please putthe directives to a separate file, and @samp{#include} that file from theconfig header template.  If you are using @command{autoheader}, you wouldprobably use @samp{AH_BOTTOM} to append the @samp{#include} directive.@node autoheader Invocation@subsection Using @command{autoheader} to Create @file{config.h.in}@cindex @command{autoheader}The @command{autoheader} program can create a template file of C@samp{#define} statements for @command{configure} to use.It searches for the first invocation of @code{AC_CONFIG_HEADERS} in@file{configure} sources to determine the name of the template.(If the first call of @code{AC_CONFIG_HEADERS} specifies more than oneinput file name, @command{autoheader} uses the first one.)It is recommended that only one input file is used.  If you want to appenda boilerplate code, it is preferable to use@samp{AH_BOTTOM([#include <conf_post.h>])}.File @file{conf_post.h} is not processed during the configuration then,which make things clearer.  Analogically, @code{AH_TOP} can be used toprepend a boilerplate code.In order to do its job, @command{autoheader} needs you to document allof the symbols that you might use.  Typically this is done via an@code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED} call whose first argumentis a literal symbol and whose third argument describes the symbol(@pxref{Defining Symbols}).  Alternatively, you can use@code{AH_TEMPLATE} (@pxref{Autoheader Macros}), or you can supply asuitable input file for a subsequent configuration header file.Symbols defined by Autoconf's builtin tests are already documented properly;you need to document only those that youdefine yourself.You might wonder why @command{autoheader} is needed: after all, whywould @command{configure} need to ``patch'' a @file{config.h.in} toproduce a @file{config.h} instead of just creating @file{config.h} fromscratch?  Well, when everything rocks, the answer is just that we arewasting our time maintaining @command{autoheader}: generating@file{config.h} directly is all that is needed.  When things go wrong,however, you'll be thankful for the existence of @command{autoheader}.The fact that the symbols are documented is important in order to@emph{check} that @file{config.h} makes sense.  The fact that there is awell-defined list of symbols that should be defined (or not) isalso important for people who are porting packages to environments where@command{configure} cannot be run: they just have to @emph{fill in theblanks}.But let's come back to the point: the invocation of @command{autoheader}@dots{}If you give @command{autoheader} an argument, it uses that file insteadof @file{configure.ac} and writes the header file to the standard outputinstead of to @file{config.h.in}.  If you give @command{autoheader} anargument of @option{-}, it reads the standard input instead of@file{configure.ac} and writes the header file to the standard output.@command{autoheader} accepts the following options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@item --verbose@itemx -vReport processing steps.@item --debug@itemx -dDon't remove the temporary files.@item --force@itemx -fRemake the template file even if newer than its input files.@item --include=@var{dir}@itemx -I @var{dir}Append @var{dir} to the include path.  Multiple invocations accumulate.@item --prepend-include=@var{dir}@itemx -B @var{dir}Prepend @var{dir} to the include path.  Multiple invocations accumulate.@item --warnings=@var{category}@itemx -W @var{category}@evindex WARNINGSReport the warnings related to @var{category} (which can actually be acomma separated list).  Current categories include:@table @samp@item obsoletereport the uses of obsolete constructs@item allreport all the warnings@item nonereport none@item errortreats warnings as errors@item no-@var{category}disable warnings falling into @var{category}@end table@end table@node Autoheader Macros@subsection Autoheader Macros@cindex Autoheader macros@command{autoheader} scans @file{configure.ac} and figures out which Cpreprocessor symbols it might define.  It knows how to generatetemplates for symbols defined by @code{AC_CHECK_HEADERS},@code{AC_CHECK_FUNCS} etc., but if you @code{AC_DEFINE} any additionalsymbol, you must define a template for it.  If there are missingtemplates, @command{autoheader} fails with an error message.The template for a @var{symbol} is createdby @command{autoheader} fromthe @var{description} argument to an @code{AC_DEFINE};see @ref{Defining Symbols}.For special needs, you can use the following macros.@defmac AH_TEMPLATE (@var{key}, @var{description})@ahindex{TEMPLATE}Tell @command{autoheader} to generate a template for @var{key}.  This macrogenerates standard templates just like @code{AC_DEFINE} when a@var{description} is given.For example:@exampleAH_TEMPLATE([CRAY_STACKSEG_END],            [Define to one of _getb67, GETB67, getb67             for Cray-2 and Cray-YMP systems.  This             function is required for alloca.c support             on those systems.])@end example@noindentgenerates the following template, with the description properlyjustified.@example/* Define to one of _getb67, GETB67, getb67 for Cray-2 and   Cray-YMP systems.  This function is required for alloca.c   support on those systems.  */#undef CRAY_STACKSEG_END@end example@end defmac@defmac AH_VERBATIM (@var{key}, @var{template})@ahindex{VERBATIM}Tell @command{autoheader} to include the @var{template} as-is in the headertemplate file.  This @var{template} is associated with the @var{key},which is used to sort all the different templates and guarantee theiruniqueness.  It should be a symbol that can be defined via @code{AC_DEFINE}.@end defmac@defmac AH_TOP (@var{text})@ahindex{TOP}Include @var{text} at the top of the header template file.@end defmac@defmac AH_BOTTOM (@var{text})@ahindex{BOTTOM}Include @var{text} at the bottom of the header template file.@end defmacPlease note that @var{text} gets included ``verbatim'' to the template file,not to the resulting config header, so it can easily get mangled when thetemplate is processed.  There is rarely a need for something other than@exampleAH_BOTTOM([#include <custom.h>])@end example@node Configuration Commands@section Running Arbitrary Configuration Commands@cindex Configuration commands@cindex Commands for configurationYou can execute arbitrary commands before, during, and after@file{config.status} is run.  The three following macros accumulate thecommands to run when they are called multiple times.@code{AC_CONFIG_COMMANDS} replaces the obsolete macro@code{AC_OUTPUT_COMMANDS}; see @ref{Obsolete Macros}, for details.@anchor{AC_CONFIG_COMMANDS}@defmac AC_CONFIG_COMMANDS (@var{tag}@dots{}, @ovar{cmds}, @ovar{init-cmds})@acindex{CONFIG_COMMANDS}Specify additional shell commands to run at the end of@file{config.status}, and shell commands to initialize any variablesfrom @command{configure}.  Associate the commands with @var{tag}.Since typically the @var{cmds} create a file, @var{tag} shouldnaturally be the name of that file.  If needed, the directory hosting@var{tag} is created.  This macro is one of the instantiating macros;see @ref{Configuration Actions}.Here is an unrealistic example:@examplefubar=42AC_CONFIG_COMMANDS([fubar],                   [echo this is extra $fubar, and so on.],                   [fubar=$fubar])@end exampleHere is a better one:@exampleAC_CONFIG_COMMANDS([timestamp], [date >timestamp])@end example@end defmacThe following two macros look similar, but in fact they are not of the samebreed: they are executed directly by @file{configure}, so you cannot use@file{config.status} to rerun them.@c Yet it is good to leave them here.  The user sees them together and@c decides which best fits their needs.@defmac AC_CONFIG_COMMANDS_PRE (@var{cmds})@acindex{CONFIG_COMMANDS_PRE}Execute the @var{cmds} right before creating @file{config.status}.This macro presents the last opportunity to call @code{AC_SUBST},@code{AC_DEFINE}, or @code{AC_CONFIG_@var{ITEMS}} macros.@end defmac@defmac AC_CONFIG_COMMANDS_POST (@var{cmds})@acindex{CONFIG_COMMANDS_POST}Execute the @var{cmds} right after creating @file{config.status}.@end defmac@node Configuration Links@section Creating Configuration Links@cindex Configuration links@cindex Links for configurationYou may find it convenient to create links whose destinations depend uponresults of tests.  One can use @code{AC_CONFIG_COMMANDS} but thecreation of relative symbolic links can be delicate when the package isbuilt in a directory different from the source directory.@anchor{AC_CONFIG_LINKS}@defmac AC_CONFIG_LINKS (@var{dest}:@var{source}@dots{}, @ovar{cmds}, @  @ovar{init-cmds})@acindex{CONFIG_LINKS}@cindex LinksMake @code{AC_OUTPUT} link each of the existing files @var{source} tothe corresponding link name @var{dest}.  Makes a symbolic link ifpossible, otherwise a hard link if possible, otherwise a copy.  The@var{dest} and @var{source} names should be relative to the top levelsource or build directory.  This macro is one of the instantiatingmacros; see @ref{Configuration Actions}.For example, this call:@exampleAC_CONFIG_LINKS([host.h:config/$machine.h                object.h:config/$obj_format.h])@end example@noindentcreates in the current directory @file{host.h} as a link to@file{@var{srcdir}/config/$machine.h}, and @file{object.h} as alink to @file{@var{srcdir}/config/$obj_format.h}.The tempting value @samp{.} for @var{dest} is invalid: it makes itimpossible for @samp{config.status} to guess the links to establish.One can then run:@example./config.status host.h object.h@end example@noindentto create the links.@end defmac@node Subdirectories@section Configuring Other Packages in Subdirectories@cindex Configure subdirectories@cindex Subdirectory configureIn most situations, calling @code{AC_OUTPUT} is sufficient to producemakefiles in subdirectories.  However, @command{configure} scriptsthat control more than one independent package can use@code{AC_CONFIG_SUBDIRS} to run @command{configure} scripts for otherpackages in subdirectories.@defmac AC_CONFIG_SUBDIRS (@var{dir} @dots{})@acindex{CONFIG_SUBDIRS}@ovindex subdirsMake @code{AC_OUTPUT} run @command{configure} in each subdirectory@var{dir} in the given blank-or-newline-separated list.  Each @var{dir} shouldbe a literal, i.e., please do not use:@example@c If you change this example, adjust tests/torture.at:Non-literal AC_CONFIG_SUBDIRS.if test "x$package_foo_enabled" = xyes; then  my_subdirs="$my_subdirs foo"fiAC_CONFIG_SUBDIRS([$my_subdirs])@end example@noindentbecause this prevents @samp{./configure --help=recursive} fromdisplaying the options of the package @code{foo}.  Instead, you shouldwrite:@exampleif test "x$package_foo_enabled" = xyes; then  AC_CONFIG_SUBDIRS([foo])fi@end exampleIf a given @var{dir} is not found at @command{configure} run time, awarning is reported; if the subdirectory is optional, write:@exampleif test -d "$srcdir/foo"; then  AC_CONFIG_SUBDIRS([foo])fi@end example@c NB: Yes, below we mean configure.in, not configure.ac.If a given @var{dir} contains @command{configure.gnu}, it is run insteadof @command{configure}.  This is for packages that might use anon-Autoconf script @command{Configure}, which can't be called through awrapper @command{configure} since it would be the same file oncase-insensitive file systems.  Likewise, if a @var{dir} contains@file{configure.in} but no @command{configure}, the Cygnus@command{configure} script found by @code{AC_CONFIG_AUX_DIR} is used.The subdirectory @command{configure} scripts are given the same commandline options that were given to this @command{configure} script, with minorchanges if needed, which include:@itemize @minus@itemadjusting a relative name for the cache file;@itemadjusting a relative name for the source directory;@itempropagating the current value of @code{$prefix}, including if it wasdefaulted, and if the default values of the top level and of the subdirectory@file{configure} differ.@end itemizeThis macro also sets the output variable @code{subdirs} to the list ofdirectories @samp{@var{dir} @dots{}}.  Make rules can usethis variable to determine which subdirectories to recurse into.This macro may be called multiple times.@end defmac@node Default Prefix@section Default Prefix@cindex Install prefix@cindex Prefix for installBy default, @command{configure} sets the prefix for files it installs to@file{/usr/local}.  The user of @command{configure} can select a differentprefix using the @option{--prefix} and @option{--exec-prefix} options.There are two ways to change the default: when creating@command{configure}, and when running it.Some software packages might want to install in a directory other than@file{/usr/local} by default.  To accomplish that, use the@code{AC_PREFIX_DEFAULT} macro.@defmac AC_PREFIX_DEFAULT (@var{prefix})@acindex{PREFIX_DEFAULT}Set the default installation prefix to @var{prefix} instead of@file{/usr/local}.@end defmacIt may be convenient for users to have @command{configure} guess theinstallation prefix from the location of a related program that theyhave already installed.  If you wish to do that, you can call@code{AC_PREFIX_PROGRAM}.@anchor{AC_PREFIX_PROGRAM}@defmac AC_PREFIX_PROGRAM (@var{program})@acindex{PREFIX_PROGRAM}If the user did not specify an installation prefix (using the@option{--prefix} option), guess a value for it by looking for@var{program} in @env{PATH}, the way the shell does.  If @var{program}is found, set the prefix to the parent of the directory containing@var{program}, else default the prefix as described above(@file{/usr/local} or @code{AC_PREFIX_DEFAULT}).  For example, if@var{program} is @code{gcc} and the @env{PATH} contains@file{/usr/local/gnu/bin/gcc}, set the prefix to @file{/usr/local/gnu}.@end defmac@c ======================================================== Existing tests@node Existing Tests@chapter Existing TestsThese macros test for particular system features that packages mightneed or want to use.  If you need to test for a kind of feature thatnone of these macros check for, you can probably do it by callingprimitive test macros with appropriate arguments (@pxref{WritingTests}).These tests print messages telling the user which feature they'rechecking for, and what they find.  They cache their results for future@command{configure} runs (@pxref{Caching Results}).Some of these macros set output variables.  @xref{MakefileSubstitutions}, for how to get their values.  The phrase ``define@var{name}'' is used below as a shorthand to mean ``define the Cpreprocessor symbol @var{name} to the value 1''.  @xref{DefiningSymbols}, for how to get those symbol definitions into your program.@menu* Common Behavior::             Macros' standard schemes* Alternative Programs::        Selecting between alternative programs* Files::                       Checking for the existence of files* Libraries::                   Library archives that might be missing* Library Functions::           C library functions that might be missing* Header Files::                Header files that might be missing* Declarations::                Declarations that may be missing* Structures::                  Structures or members that might be missing* Types::                       Types that might be missing* Compilers and Preprocessors::  Checking for compiling programs* System Services::             Operating system services* Posix Variants::              Special kludges for specific Posix variants* Erlang Libraries::            Checking for the existence of Erlang libraries@end menu@node Common Behavior@section Common Behavior@cindex Common autoconf behaviorMuch effort has been expended to make Autoconf easy to learn.  The mostobvious way to reach this goal is simply to enforce standard interfacesand behaviors, avoiding exceptions as much as possible.  Because ofhistory and inertia, unfortunately, there are still too many exceptionsin Autoconf; nevertheless, this section describes some of the commonrules.@menu* Standard Symbols::            Symbols defined by the macros* Default Includes::            Includes used by the generic macros@end menu@node Standard Symbols@subsection Standard Symbols@cindex Standard symbolsAll the generic macros that @code{AC_DEFINE} a symbol as a result oftheir test transform their @var{argument} values to a standard alphabet.First, @var{argument} is converted to upper case and any asterisks(@samp{*}) are each converted to @samp{P}.  Any remaining charactersthat are not alphanumeric are converted to underscores.For instance,@exampleAC_CHECK_TYPES([struct $Expensive*])@end example@noindentdefines the symbol @samp{HAVE_STRUCT__EXPENSIVEP} if the checksucceeds.@node Default Includes@subsection Default Includes@cindex Default includes@cindex Includes, defaultSeveral tests depend upon a set of header files.  Since these headersare not universally available, tests actually have to provide a set ofprotected includes, such as:@example@group#ifdef TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# ifdef HAVE_SYS_TIME_H#  include <sys/time.h># else#  include <time.h># endif#endif@end group@end example@noindentUnless you know exactly what you are doing, you should avoid usingunconditional includes, and check the existence of the headers youinclude beforehand (@pxref{Header Files}).Most generic macros use the following macro to provide the default setof includes:@defmac AC_INCLUDES_DEFAULT (@ovar{include-directives})@acindex{INCLUDES_DEFAULT}Expand to @var{include-directives} if defined, otherwise to:@example@group#include <stdio.h>#ifdef HAVE_SYS_TYPES_H# include <sys/types.h>#endif#ifdef HAVE_SYS_STAT_H# include <sys/stat.h>#endif#ifdef STDC_HEADERS# include <stdlib.h># include <stddef.h>#else# ifdef HAVE_STDLIB_H#  include <stdlib.h># endif#endif#ifdef HAVE_STRING_H# if !defined STDC_HEADERS && defined HAVE_MEMORY_H#  include <memory.h># endif# include <string.h>#endif#ifdef HAVE_STRINGS_H# include <strings.h>#endif#ifdef HAVE_INTTYPES_H# include <inttypes.h>#endif#ifdef HAVE_STDINT_H# include <stdint.h>#endif#ifdef HAVE_UNISTD_H# include <unistd.h>#endif@end group@end exampleIf the default includes are used, then check for the presence of theseheaders and their compatibility, i.e., you don't need to run@code{AC_HEADER_STDC}, nor check for @file{stdlib.h} etc.These headers are checked for in the same order as they are included.For instance, on some systems @file{string.h} and @file{strings.h} bothexist, but conflict.  Then @code{HAVE_STRING_H} is defined, not@code{HAVE_STRINGS_H}.@end defmac@node Alternative Programs@section Alternative Programs@cindex Programs, checkingThese macros check for the presence or behavior of particular programs.They are used to choose between several alternative programs and todecide what to do once one has been chosen.  If there is no macrospecifically defined to check for a program you need, and you don't needto check for any special properties of it, then you can use one of thegeneral program-check macros.@menu* Particular Programs::         Special handling to find certain programs* Generic Programs::            How to find other programs@end menu@node Particular Programs@subsection Particular Program ChecksThese macros check for particular programs---whether they exist, andin some cases whether they support certain features.@defmac AC_PROG_AWK@acindex{PROG_AWK}@ovindex AWK@caindex prog_AWKCheck for @code{gawk}, @code{mawk}, @code{nawk}, and @code{awk}, in thatorder, and set output variable @code{AWK} to the first one that is found.It tries @code{gawk} first because that is reported to be thebest implementation.  The result can be overridden by setting thevariable @code{AWK} or the cache variable @code{ac_cv_prog_AWK}.Using this macro is sufficient to avoid the pitfalls of traditional@command{awk} (@pxref{awk, , Limitations of Usual Tools}).@end defmac@defmac AC_PROG_GREP@acindex{PROG_GREP}@ovindex GREP@caindex prog_GREPLook for the best available @code{grep} or @code{ggrep} that accepts thelongest input lines possible, and that supports multiple @option{-e} options.Set the output variable @code{GREP} to whatever is chosen.@xref{grep, , Limitations of Usual Tools}, for more information aboutportability problems with the @command{grep} command family.  The resultcan be overridden by setting the @code{GREP} variable and is cached in the@code{ac_cv_path_GREP} variable.@end defmac@defmac AC_PROG_EGREP@acindex{PROG_EGREP}@ovindex EGREP@caindex prog_EGREPCheck whether @code{$GREP -E} works, or else look for the best available@code{egrep} or @code{gegrep} that accepts the longest input lines possible.Set the output variable @code{EGREP} to whatever is chosen.  The resultcan be overridden by setting the @code{EGREP} variable and is cached in the@code{ac_cv_path_EGREP} variable.@end defmac@defmac AC_PROG_FGREP@acindex{PROG_FGREP}@ovindex FGREP@caindex prog_FGREPCheck whether @code{$GREP -F} works, or else look for the best available@code{fgrep} or @code{gfgrep} that accepts the longest input lines possible.Set the output variable @code{FGREP} to whatever is chosen.  The resultcan be overridden by setting the @code{FGREP} variable and is cached in the@code{ac_cv_path_FGREP} variable.@end defmac@defmac AC_PROG_INSTALL@acindex{PROG_INSTALL}@ovindex INSTALL@ovindex INSTALL_PROGRAM@ovindex INSTALL_DATA@ovindex INSTALL_SCRIPT@caindex path_installSet output variable @code{INSTALL} to the name of a BSD-compatible@command{install} program, if one is found in the current @env{PATH}.Otherwise, set @code{INSTALL} to @samp{@var{dir}/install-sh -c},checking the directories specified to @code{AC_CONFIG_AUX_DIR} (or itsdefault directories) to determine @var{dir} (@pxref{Output}).  Also setthe variables @code{INSTALL_PROGRAM} and @code{INSTALL_SCRIPT} to@samp{$@{INSTALL@}} and @code{INSTALL_DATA} to @samp{$@{INSTALL@} -m 644}.@samp{@@INSTALL@@} is special, as its value may vary for differentconfiguration files.This macro screens out various instances of @command{install} known not towork.  It prefers to find a C program rather than a shell script, forspeed.  Instead of @file{install-sh}, it can also use @file{install.sh},but that name is obsolete because some @command{make} programs have a rulethat creates @file{install} from it if there is no makefile.  Further, thismacro requires @command{install} to be able to install multiple files into atarget directory in a single invocation.Autoconf comes with a copy of @file{install-sh} that you can use.  Ifyou use @code{AC_PROG_INSTALL}, you must include either@file{install-sh} or @file{install.sh} in your distribution; otherwise@command{configure} produces an error message saying it can't findthem---even if the system you're on has a good @command{install} program.This check is a safety measure to prevent you from accidentally leavingthat file out, which would prevent your package from installing onsystems that don't have a BSD-compatible @command{install} program.If you need to use your own installation program because it has featuresnot found in standard @command{install} programs, there is no reason to use@code{AC_PROG_INSTALL}; just put the file name of your program into your@file{Makefile.in} files.The result of the test can be overridden by setting the variable@code{INSTALL} or the cache variable @code{ac_cv_path_install}.@end defmac@defmac AC_PROG_MKDIR_P@acindex{PROG_MKDIR_P}@ovindex MKDIR_P@caindex path_mkdirSet output variable @code{MKDIR_P} to a program that ensures that foreach argument, a directory named by this argument exists, creating itand its parent directories if needed, and without race conditions whentwo instances of the program attempt to make the same directory atnearly the same time.This macro uses the @samp{mkdir -p} command if possible.  Otherwise, itfalls back on invoking @command{install-sh} with the @option{-d} option,so your package shouldcontain @file{install-sh} as described under @code{AC_PROG_INSTALL}.An @file{install-sh} file that predates Autoconf 2.60 or Automake 1.10is vulnerable to race conditions, so if you want to support parallelinstalls fromdifferent packages into the same directory you need to make sure youhave an up-to-date @file{install-sh}.  In particular, be careful aboutusing @samp{autoreconf -if} if your Automake predates Automake 1.10.This macro is related to the @code{AS_MKDIR_P} macro (@pxref{Programmingin M4sh}), but it sets an output variable intended for use in otherfiles, whereas @code{AS_MKDIR_P} is intended for use in scripts like@command{configure}.  Also, @code{AS_MKDIR_P} does not accept options,but @code{MKDIR_P} supports the @option{-m} option, e.g., a makefilemight invoke @code{$(MKDIR_P) -m 0 dir} to create an inaccessibledirectory, and conversely a makefile should use @code{$(MKDIR_P) --$(FOO)} if @var{FOO} might yield a value that begins with @samp{-}.Finally, @code{AS_MKDIR_P} does not check for race conditionvulnerability, whereas @code{AC_PROG_MKDIR_P} does.@samp{@@MKDIR_P@@} is special, as its value may vary for differentconfiguration files.The result of the test can be overridden by setting the variable@code{MKDIR_P} or the cache variable @code{ac_cv_path_mkdir}.@end defmac@anchor{AC_PROG_LEX}@defmac AC_PROG_LEX@acindex{PROG_LEX}@ovindex LEX@ovindex LEXLIB@cvindex YYTEXT_POINTER@ovindex LEX_OUTPUT_ROOT@caindex prog_LEXIf @code{flex} is found, set output variable @code{LEX} to @samp{flex}and @code{LEXLIB} to @option{-lfl}, if that library is in a standardplace.  Otherwise set @code{LEX} to @samp{lex} and @code{LEXLIB} to@option{-ll}, if found.  If neither variant is available, set @code{LEX}to @samp{:}; for packages that ship the generated @file{file.yy.c}alongside the source @file{file.l}, this default allows users without alexer generator to still build the package even if the timestamp for@file{file.l} is inadvertently changed.Define @code{YYTEXT_POINTER} if @code{yytext} defaults to @samp{char *} insteadof to @samp{char []}.  Also set output variable @code{LEX_OUTPUT_ROOT} tothe base of the file name that the lexer generates; usually@file{lex.yy}, but sometimes something else.  These results varyaccording to whether @code{lex} or @code{flex} is being used.You are encouraged to use Flex in your sources, since it is both morepleasant to use than plain Lex and the C source it produces is portable.In order to ensure portability, however, you must either provide afunction @code{yywrap} or, if you don't use it (e.g., your scanner hasno @samp{#include}-like feature), simply include a @samp{%noyywrap}statement in the scanner's source.  Once this done, the scanner isportable (unless @emph{you} felt free to use nonportable constructs) anddoes not depend on any library.  In this case, and in this case only, itis suggested that you use this Autoconf snippet:@exampleAC_PROG_LEXif test "x$LEX" != xflex; then  LEX="$SHELL $missing_dir/missing flex"  AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])  AC_SUBST([LEXLIB], [''])fi@end exampleThe shell script @command{missing} can be found in the Automakedistribution.Remember that the user may have supplied an alternate location in@env{LEX}, so if Flex is required, it is better to check that the userprovided something sufficient by parsing the output of @samp{$LEX--version} than by simply relying on @code{test "x$LEX" = xflex}.To ensure backward compatibility, Automake's @code{AM_PROG_LEX} invokes(indirectly) this macro twice, which causes an annoying but benign``@code{AC_PROG_LEX} invoked multiple times'' warning.  Future versionsof Automake will fix this issue; meanwhile, just ignore this message.As part of running the test, this macro may delete any file in theconfiguration directory named @file{lex.yy.c} or @file{lexyy.c}.The result of this test can be influenced by setting the variable@code{LEX} or the cache variable @code{ac_cv_prog_LEX}.@end defmac@anchor{AC_PROG_LN_S}@defmac AC_PROG_LN_S@acindex{PROG_LN_S}@ovindex LN_SIf @samp{ln -s} works on the current file system (the operating systemand file system support symbolic links), set the output variable@code{LN_S} to @samp{ln -s}; otherwise, if @samp{ln} works, set@code{LN_S} to @samp{ln}, and otherwise set it to @samp{cp -pR}.If you make a link in a directory other than the current directory, itsmeaning depends on whether @samp{ln} or @samp{ln -s} is used.  To safelycreate links using @samp{$(LN_S)}, either find out which form is usedand adjust the arguments, or always invoke @code{ln} in the directorywhere the link is to be created.In other words, it does not work to do:@example$(LN_S) foo /x/bar@end exampleInstead, do:@example(cd /x && $(LN_S) foo bar)@end example@end defmac@defmac AC_PROG_RANLIB@acindex{PROG_RANLIB}@ovindex RANLIB@c @caindex prog_RANLIB@c @caindex prog_ac_ct_RANLIBSet output variable @code{RANLIB} to @samp{ranlib} if @code{ranlib}is found, and otherwise to @samp{:} (do nothing).@end defmac@defmac AC_PROG_SED@acindex{PROG_SED}@ovindex SED@caindex path_SEDSet output variable @code{SED} to a Sed implementation that conforms toPosix and does not have arbitrary length limits.  Report an error if noacceptable Sed is found.  @xref{sed, , Limitations of Usual Tools}, for moreinformation about portability problems with Sed.The result of this test can be overridden by setting the @code{SED} variableand is cached in the @code{ac_cv_path_SED} variable.@end defmac@defmac AC_PROG_YACC@acindex{PROG_YACC}@evindex YACC@evindex YFLAGS@ovindex YACC@caindex prog_YACCIf @code{bison} is found, set output variable @code{YACC} to @samp{bison-y}.  Otherwise, if @code{byacc} is found, set @code{YACC} to@samp{byacc}.  Otherwise set @code{YACC} to @samp{yacc}.The result of this test can be influenced by setting the variable@code{YACC} or the cache variable @code{ac_cv_prog_YACC}.@end defmac@node Generic Programs@subsection Generic Program and File ChecksThese macros are used to find programs not covered by the ``particular''test macros.  If you need to check the behavior of a program as well asfind out whether it is present, you have to write your own test for it(@pxref{Writing Tests}).  By default, these macros use the environmentvariable @env{PATH}.  If you need to check for a program that might notbe in the user's @env{PATH}, you can pass a modified path to useinstead, like this:@exampleAC_PATH_PROG([INETD], [inetd], [/usr/libexec/inetd],             [$PATH$PATH_SEPARATOR/usr/libexec$PATH_SEPARATOR]dnl[/usr/sbin$PATH_SEPARATOR/usr/etc$PATH_SEPARATOR/etc])@end exampleYou are strongly encouraged to declare the @var{variable} passed to@code{AC_CHECK_PROG} etc.@: as precious.  @xref{Setting Output Variables},@code{AC_ARG_VAR}, for more details.@anchor{AC_CHECK_PROG}@defmac AC_CHECK_PROG (@var{variable}, @var{prog-to-check-for}, @  @var{value-if-found}, @ovar{value-if-not-found}, @dvar{path, $PATH}, @  @ovar{reject})@acindex{CHECK_PROG}@caindex prog_@var{variable}Check whether program @var{prog-to-check-for} exists in @var{path}.  Ifit is found, set @var{variable} to @var{value-if-found}, otherwise to@var{value-if-not-found}, if given.  Always pass over @var{reject} (anabsolute file name) even if it is the first found in the search path; inthat case, set @var{variable} using the absolute file name of the@var{prog-to-check-for} found that is not @var{reject}.  If@var{variable} was already set, do nothing.  Calls @code{AC_SUBST} for@var{variable}.  The result of this test can be overridden by setting the@var{variable} variable or the cache variable@code{ac_cv_prog_@var{variable}}.@end defmac@anchor{AC_CHECK_PROGS}@defmac AC_CHECK_PROGS (@var{variable}, @var{progs-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{CHECK_PROGS}@caindex prog_@var{variable}Check for each program in the blank-separated list@var{progs-to-check-for} existing in the @var{path}.  If one is found, set@var{variable} to the name of that program.  Otherwise, continuechecking the next program in the list.  If none of the programs in thelist are found, set @var{variable} to @var{value-if-not-found}; if@var{value-if-not-found} is not specified, the value of @var{variable}is not changed.  Calls @code{AC_SUBST} for @var{variable}.  The result ofthis test can be overridden by setting the @var{variable} variable or thecache variable @code{ac_cv_prog_@var{variable}}.@end defmac@defmac AC_CHECK_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{CHECK_TARGET_TOOL}Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}with a prefix of the target type as determined by@code{AC_CANONICAL_TARGET}, followed by a dash (@pxref{Canonicalizing}).If the tool cannot be found with a prefix, and if the build and targettypes are equal, then it is also searched for without a prefix.As noted in @ref{Specifying Target Triplets}, thetarget is rarely specified, because most of the time it is the sameas the host: it is the type of system for which any compiler tool inthe package produces code.  What this macro looks for is,for example, @emph{a tool @r{(assembler, linker, etc.)}@: that thecompiler driver @r{(@command{gcc} for the GNU C Compiler)}uses to produce objects, archives or executables}.@end defmac@defmac AC_CHECK_TOOL (@var{variable}, @var{prog-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{CHECK_TOOL}@c @caindex prog_@var{VARIABLE}@c @caindex prog_ac_ct_@var{VARIABLE}Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}with a prefix of the host type as specified by @option{--host}, followed by adash.  For example, if the user runs@samp{configure --build=x86_64-gnu --host=i386-gnu}, then this call:@exampleAC_CHECK_TOOL([RANLIB], [ranlib], [:])@end example@noindentsets @code{RANLIB} to @file{i386-gnu-ranlib} if that program exists in@var{path}, or otherwise to @samp{ranlib} if that program exists in@var{path}, or to @samp{:} if neither program exists.When cross-compiling, this macro will issue a warning if no programprefixed with the host type could be found.For more information, see @ref{Specifying Target Triplets}.@end defmac@defmac AC_CHECK_TARGET_TOOLS (@var{variable}, @var{progs-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{CHECK_TARGET_TOOLS}Like @code{AC_CHECK_TARGET_TOOL}, each of the tools in the list@var{progs-to-check-for} are checked with a prefix of the target type asdetermined by @code{AC_CANONICAL_TARGET}, followed by a dash(@pxref{Canonicalizing}).  If none of the tools can be found with aprefix, and if the build and target types are equal, then the first onewithout a prefix is used.  If a tool is found, set @var{variable} tothe name of that program.  If none of the tools in the list are found,set @var{variable} to @var{value-if-not-found}; if @var{value-if-not-found}is not specified, the value of @var{variable} is not changed.  Calls@code{AC_SUBST} for @var{variable}.@end defmac@defmac AC_CHECK_TOOLS (@var{variable}, @var{progs-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{CHECK_TOOLS}Like @code{AC_CHECK_TOOL}, each of the tools in the list@var{progs-to-check-for} are checked with a prefix of the host type asdetermined by @code{AC_CANONICAL_HOST}, followed by a dash(@pxref{Canonicalizing}).  If none of the tools can be found with aprefix, then the first one without a prefix is used.  If a tool is found,set @var{variable} to the name of that program.  If none of the tools inthe list are found, set @var{variable} to @var{value-if-not-found}; if@var{value-if-not-found} is not specified, the value of @var{variable}is not changed.  Calls @code{AC_SUBST} for @var{variable}.When cross-compiling, this macro will issue a warning if no programprefixed with the host type could be found.For more information, see @ref{Specifying Target Triplets}.@end defmac@anchor{AC_PATH_PROG}@defmac AC_PATH_PROG (@var{variable}, @var{prog-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{PATH_PROG}@caindex path_@var{variable}Like @code{AC_CHECK_PROG}, but set @var{variable} to the absolutename of @var{prog-to-check-for} if found.  The result of this testcan be overridden by setting the @var{variable} variable.  A positiveresult of this test is cached in the @code{ac_cv_path_@var{variable}}variable.@end defmac@anchor{AC_PATH_PROGS}@defmac AC_PATH_PROGS (@var{variable}, @var{progs-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{PATH_PROGS}@caindex path_@var{variable}Like @code{AC_CHECK_PROGS}, but if any of @var{progs-to-check-for}are found, set @var{variable} to the absolute name of the programfound.  The result of this test can be overridden by setting the@var{variable} variable.  A positive result of this test is cached inthe @code{ac_cv_path_@var{variable}} variable.@end defmac@defmac AC_PATH_PROGS_FEATURE_CHECK (@var{variable}, @  @var{progs-to-check-for}, @var{feature-test}, @  @ovar{action-if-not-found}, @dvar{path, $PATH})@acindex{PATH_PROGS_FEATURE_CHECK}@caindex path_@var{variable}@vrindex ac_path_@var{variable}@vrindex ac_path_@var{variable}_foundThis macro was introduced in Autoconf 2.62.  If @var{variable} is notempty, then set the cache variable @code{ac_cv_path_@var{variable}} toits value.  Otherwise, check for each program in the blank-separatedlist @var{progs-to-check-for} existing in @var{path}.  For each programfound, execute @var{feature-test} with @code{ac_path_@var{variable}}set to the absolute name of the candidate program.  If no invocation of@var{feature-test} sets the shell variable@code{ac_cv_path_@var{variable}}, then @var{action-if-not-found} isexecuted.  @var{feature-test} will be run even when@code{ac_cv_path_@var{variable}} is set, to provide the ability tochoose a better candidate found later in @var{path}; to accept thecurrent setting and bypass all further checks, @var{feature-test} canexecute @code{ac_path_@var{variable}_found=:}.Note that this macro has some subtle differences from@code{AC_CHECK_PROGS}.  It is designed to be run inside@code{AC_CACHE_VAL}, therefore, it should have no side effects.  Inparticular, @var{variable} is not set to the final value of@code{ac_cv_path_@var{variable}}, nor is @code{AC_SUBST} automaticallyrun.  Also, on failure, any action can be performed, whereas@code{AC_CHECK_PROGS} only performs@code{@var{variable}=@var{value-if-not-found}}.Here is an example, similar to what Autoconf uses in its own configurescript.  It will search for an implementation of @command{m4} thatsupports the @code{indir} builtin, even if it goes by the name@command{gm4} or is not the first implementation on @env{PATH}.@exampleAC_CACHE_CHECK([for m4 that supports indir], [ac_cv_path_M4],  [AC_PATH_PROGS_FEATURE_CHECK([M4], [m4 gm4],    [[m4out=`echo 'changequote([,])indir([divnum])' | $ac_path_M4`      test "x$m4out" = x0 \      && ac_cv_path_M4=$ac_path_M4 ac_path_M4_found=:]],    [AC_MSG_ERROR([could not find m4 that supports indir])])])AC_SUBST([M4], [$ac_cv_path_M4])@end example@end defmac@defmac AC_PATH_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{PATH_TARGET_TOOL}Like @code{AC_CHECK_TARGET_TOOL}, but set @var{variable} to the absolutename of the program if it is found.@end defmac@defmac AC_PATH_TOOL (@var{variable}, @var{prog-to-check-for}, @  @ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{PATH_TOOL}Like @code{AC_CHECK_TOOL}, but set @var{variable} to the absolutename of the program if it is found.When cross-compiling, this macro will issue a warning if no programprefixed with the host type could be found.For more information, see @ref{Specifying Target Triplets}.@end defmac@node Files@section Files@cindex File, checkingYou might also need to check for the existence of files.  Before usingthese macros, ask yourself whether a runtime test might not be a bettersolution.  Be aware that, like most Autoconf macros, they test a featureof the host machine, and therefore, they die when cross-compiling.@defmac AC_CHECK_FILE (@var{file}, @ovar{action-if-found}, @  @ovar{action-if-not-found})@acindex{CHECK_FILE}@caindex file_@var{file}Check whether file @var{file} exists on the native system.  If it isfound, execute @var{action-if-found}, otherwise do@var{action-if-not-found}, if given.  The result of this test is cachedin the @code{ac_cv_file_@var{file}} variable, with characters notsuitable for a variable name mapped to underscores.@end defmac@defmac AC_CHECK_FILES (@var{files}, @ovar{action-if-found}, @  @ovar{action-if-not-found})@acindex{CHECK_FILES}@caindex file_@var{file}Executes @code{AC_CHECK_FILE} once for each file listed in @var{files}.Additionally, defines @samp{HAVE_@var{file}} (@pxref{Standard Symbols})for each file found.  The results of each test are cached in the@code{ac_cv_file_@var{file}} variable, with characters not suitable fora variable name mapped to underscores.@end defmac@node Libraries@section Library Files@cindex Library, checkingThe following macros check for the presence of certain C, C++, Fortran,or Go library archive files.@anchor{AC_CHECK_LIB}@defmac AC_CHECK_LIB (@var{library}, @var{function}, @  @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})@acindex{CHECK_LIB}@caindex lib_@var{library}_@var{function}Test whether the library @var{library} is available by trying to linka test program that calls function @var{function} with the library.@var{function} should be a function provided by the library.Use the basename of the library; e.g., to check for @option{-lmp}, use @samp{mp} asthe @var{library} argument.@var{action-if-found} is a list of shell commands to run if the linkwith the library succeeds; @var{action-if-not-found} is a list of shellcommands to run if the link fails.  If @var{action-if-found} is notspecified, the default action prepends @option{-l@var{library}} to@code{LIBS} and defines @samp{HAVE_LIB@var{library}} (in allcapitals).  This macro is intended to support building @code{LIBS} ina right-to-left (least-dependent to most-dependent) fashion such thatlibrary dependencies are satisfied as a natural side effect ofconsecutive tests.  Linkers are sensitive to library orderingso the order in which @code{LIBS} is generated is important to reliabledetection of libraries.If linking with @var{library} results in unresolved symbols that wouldbe resolved by linking with additional libraries, give those librariesas the @var{other-libraries} argument, separated by spaces:e.g., @option{-lXt -lX11}.  Otherwise, this macro may fail to detectthat @var{library} is present, because linking the test program canfail with unresolved symbols.  The @var{other-libraries} argumentshould be limited to cases where it is desirable to test for one libraryin the presence of another that is not already in @code{LIBS}.@code{AC_CHECK_LIB} requires some care in usage, and should be avoidedin some common cases.  Many standard functions like @code{gethostbyname}appear in the standard C library on some hosts, and in special librarieslike @code{nsl} on other hosts.  On some hosts the special librariescontain variant implementations that you may not want to use.  Thesedays it is normally better to use @code{AC_SEARCH_LIBS([gethostbyname],[nsl])} instead of @code{AC_CHECK_LIB([nsl], [gethostbyname])}.The result of this test is cached in the@code{ac_cv_lib_@var{library}_@var{function}} variable.@end defmac@anchor{AC_SEARCH_LIBS}@defmac AC_SEARCH_LIBS (@var{function}, @var{search-libs}, @  @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})@acindex{SEARCH_LIBS}@caindex search_@var{function}Search for a library defining @var{function} if it's not alreadyavailable.  This equates to calling@samp{AC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])])} first withno libraries, then for each library listed in @var{search-libs}.Prepend @option{-l@var{library}} to @code{LIBS} for the first library foundto contain @var{function}, and run @var{action-if-found}.  If thefunction is not found, run @var{action-if-not-found}.If linking with @var{library} results in unresolved symbols that wouldbe resolved by linking with additional libraries, give those librariesas the @var{other-libraries} argument, separated by spaces:e.g., @option{-lXt -lX11}.  Otherwise, this macro fails to detectthat @var{function} is present, because linking the test programalways fails with unresolved symbols.The result of this test is cached in the@code{ac_cv_search_@var{function}} variable as @samp{none required} if@var{function} is already available, as @samp{no} if no librarycontaining @var{function} was found, otherwise as the@option{-l@var{library}} option that needs to be prepended to @code{LIBS}.@end defmac@node Library Functions@section Library FunctionsThe following macros check for particular C library functions.If there is no macro specifically defined to check for a function you need,and you don't need to check for any special properties ofit, then you can use one of the general function-check macros.@menu* Function Portability::        Pitfalls with usual functions* Particular Functions::        Special handling to find certain functions* Generic Functions::           How to find other functions@end menu@node Function Portability@subsection Portability of C Functions@cindex Portability of C functions@cindex C function portabilityMost usual functions can either be missing, or be buggy, or be limitedon some architectures.  This section tries to make an inventory of theseportability issues.  By definition, this list always requiresadditions.  A much more complete list is maintained by the Gnulibproject (@pxref{Gnulib}), covering @ref{Function Substitutes, ,Current Posix Functions, gnulib, GNU gnulib}, @ref{Legacy FunctionSubstitutes, , Legacy Functions, gnulib, GNU gnulib}, and @ref{GlibcFunction Substitutes, , Glibc Functions, gnulib, GNU gnulib}.  Pleasehelp us keep the gnulib list as complete as possible.@table @asis@item @code{exit}@c @fuindex exit@prindex @code{exit}On ancient hosts, @code{exit} returned @code{int}.This is because @code{exit} predates @code{void}, and there was a longtradition of it returning @code{int}.On current hosts, the problem more likely is that @code{exit} is notdeclared, due to C++ problems of some sort or another.  For this reasonwe suggest that test programs not invoke @code{exit}, but return from@code{main} instead.@item @code{free}@c @fuindex free@prindex @code{free}The C standard says a call @code{free (NULL)} does nothing, butsome old systems don't support this (e.g., NextStep).@item @code{isinf}@itemx @code{isnan}@c @fuindex isinf@c @fuindex isnan@prindex @code{isinf}@prindex @code{isnan}The C99 standard says that @code{isinf} and @code{isnan} aremacros.  On some systems just macros are available(e.g., HP-UX and Solaris 10), onsome systems both macros and functions (e.g., glibc 2.3.2), and on somesystems only functions (e.g., IRIX 6 and Solaris 9).  In some casesthese functions are declared in nonstandard headers like@code{<sunmath.h>} and defined in non-default libraries like@option{-lm} or @option{-lsunmath}.The C99 @code{isinf} and @code{isnan} macros work correctly with@code{long double} arguments, but pre-C99 systems that use functionstypically assume @code{double} arguments.  On such a system,@code{isinf} incorrectly returns true for a finite @code{long double}argument that is outside the range of @code{double}.The best workaround for these issues is to use gnulib modules@code{isinf} and @code{isnan} (@pxref{Gnulib}).  But a lighter weightsolution involves code like the following.@smallexample#include <math.h>#ifndef isnan# define isnan(x) \    (sizeof (x) == sizeof (long double) ? isnan_ld (x) \     : sizeof (x) == sizeof (double) ? isnan_d (x) \     : isnan_f (x))static inline int isnan_f  (float       x) @{ return x != x; @}static inline int isnan_d  (double      x) @{ return x != x; @}static inline int isnan_ld (long double x) @{ return x != x; @}#endif#ifndef isinf# define isinf(x) \    (sizeof (x) == sizeof (long double) ? isinf_ld (x) \     : sizeof (x) == sizeof (double) ? isinf_d (x) \     : isinf_f (x))static inline int isinf_f  (float       x)@{ return !isnan (x) && isnan (x - x); @}static inline int isinf_d  (double      x)@{ return !isnan (x) && isnan (x - x); @}static inline int isinf_ld (long double x)@{ return !isnan (x) && isnan (x - x); @}#endif@end smallexampleUse @code{AC_C_INLINE} (@pxref{C Compiler}) so that this code works oncompilers that lack the @code{inline} keyword.  Some optimizingcompilers mishandle these definitions, but systems with that bugtypically have many other floating point corner-case compliance problemsanyway, so it's probably not worth worrying about.@item @code{malloc}@c @fuindex malloc@prindex @code{malloc}The C standard says a call @code{malloc (0)} is implementationdependent.  It can return either @code{NULL} or a new non-null pointer.The latter is more common (e.g., the GNU C Library) but is byno means universal.  @code{AC_FUNC_MALLOC}can be used to insist on non-@code{NULL} (@pxref{Particular Functions}).@item @code{putenv}@c @fuindex putenv@prindex @code{putenv}Posix prefers @code{setenv} to @code{putenv}; among other things,@code{putenv} is not required of all Posix implementations, but@code{setenv} is.Posix specifies that @code{putenv} puts the given string directly in@code{environ}, but some systems make a copy of it instead (e.g.,glibc 2.0, or BSD).  And when a copy is made, @code{unsetenv} mightnot free it, causing a memory leak (e.g., FreeBSD 4).On some systems @code{putenv ("FOO")} removes @samp{FOO} from theenvironment, but this is not standard usage and it dumps coreon some systems (e.g., AIX).On MinGW, a call @code{putenv ("FOO=")} removes @samp{FOO} from theenvironment, rather than inserting it with an empty value.@item @code{realloc}@c @fuindex realloc@prindex @code{realloc}The C standard says a call @code{realloc (NULL, size)} is equivalentto @code{malloc (size)}, but some old systems don't support this (e.g.,NextStep).@item @code{signal} handler@c @fuindex signal@prindex @code{signal}@prindex @code{sigaction}Normally @code{signal} takes a handler function with a return type of@code{void}, but some old systems required @code{int} instead.  Anyactual @code{int} value returned is not used; this is only adifference in the function prototype demanded.All systems we know of in current use return @code{void}.  The@code{int} was to support K&R C, where of course @code{void} is notavailable.  The obsolete macro @code{AC_TYPE_SIGNAL}(@pxref{AC_TYPE_SIGNAL}) can be used to establish the correct type inall cases.In most cases, it is more robust to use @code{sigaction} when it isavailable, rather than @code{signal}.@item @code{snprintf}@c @fuindex snprintf@prindex @code{snprintf}@c @fuindex vsnprintf@prindex @code{vsnprintf}The C99 standard says that if the output array isn't big enoughand if no other errors occur, @code{snprintf} and @code{vsnprintf}truncate the output and return the number of bytes that ought to havebeen produced.  Some older systems return the truncated length (e.g.,GNU C Library 2.0.x or IRIX 6.5), some a negative value(e.g., earlier GNU C Library versions), and some the bufferlength without truncation (e.g., 32-bit Solaris 7).  Also, some buggyolder systems ignore the length and overrun the buffer (e.g., 64-bitSolaris 7).@item @code{sprintf}@c @fuindex sprintf@prindex @code{sprintf}@c @fuindex vsprintf@prindex @code{vsprintf}The C standard says @code{sprintf} and @code{vsprintf} return thenumber of bytes written.  On some ancient systems (SunOS 4 forinstance) they return the buffer pointer instead, but these nolonger need to be worried about.@item @code{sscanf}@c @fuindex sscanf@prindex @code{sscanf}On various old systems, e.g., HP-UX 9, @code{sscanf} requiresthat itsinput string be writable (though it doesn't actually change it).  Thiscan be a problem when using @command{gcc} since it normally putsconstant strings in read-only memory (@pxref{Incompatibilities,Incompatibilities of GCC, , gcc, Using andPorting the GNU Compiler Collection}).  Apparently in some cases evenhaving format strings read-only can be a problem.@item @code{strerror_r}@c @fuindex strerror_r@prindex @code{strerror_r}Posix specifies that @code{strerror_r} returns an @code{int}, but manysystems (e.g., GNU C Library version 2.2.4) provide adifferent version returning a @code{char *}.  @code{AC_FUNC_STRERROR_R}can detect which is in use (@pxref{Particular Functions}).@item @code{strnlen}@c @fuindex strnlen@prindex @code{strnlen}AIX 4.3 provides a broken version which produces thefollowing results:@examplestrnlen ("foobar", 0) = 0strnlen ("foobar", 1) = 3strnlen ("foobar", 2) = 2strnlen ("foobar", 3) = 1strnlen ("foobar", 4) = 0strnlen ("foobar", 5) = 6strnlen ("foobar", 6) = 6strnlen ("foobar", 7) = 6strnlen ("foobar", 8) = 6strnlen ("foobar", 9) = 6@end example@item @code{sysconf}@c @fuindex sysconf@prindex @code{sysconf}@code{_SC_PAGESIZE} is standard, but some older systems (e.g., HP-UX9) have @code{_SC_PAGE_SIZE} instead.  This can be tested with@code{#ifdef}.@item @code{unlink}@c @fuindex unlink@prindex @code{unlink}The Posix spec says that @code{unlink} causes the given file to beremoved only after there are no more open file handles for it.  Somenon-Posix hosts have trouble with this requirement, though,and some DOS variants even corrupt the file system.@item @code{unsetenv}@c @fuindex unsetenv@prindex @code{unsetenv}On MinGW, @code{unsetenv} is not available, but a variable @samp{FOO}can be removed with a call @code{putenv ("FOO=")}, as described under@code{putenv} above.@item @code{va_copy}@c @fuindex va_copy@prindex @code{va_copy}The C99 standard provides @code{va_copy} for copying@code{va_list} variables.  It may be available in older environmentstoo, though possibly as @code{__va_copy} (e.g., @command{gcc} in strictpre-C99 mode).  These can be tested with @code{#ifdef}.  A fallback to@code{memcpy (&dst, &src, sizeof (va_list))} gives maximumportability.@item @code{va_list}@c @fuindex va_list@prindex @code{va_list}@code{va_list} is not necessarily just a pointer.  It can be a@code{struct} (e.g., @command{gcc} on Alpha), which means @code{NULL} isnot portable.  Or it can be an array (e.g., @command{gcc} in somePowerPC configurations), which means as a function parameter it can beeffectively call-by-reference and library routines might modify thevalue back in the caller (e.g., @code{vsnprintf} in the GNU C Library2.1).@item Signed @code{>>}Normally the C @code{>>} right shift of a signed type replicates thehigh bit, giving a so-called ``arithmetic'' shift.  But care should betaken since Standard C doesn't require that behavior.  On thosefew processors without a native arithmetic shift (for instance Crayvector systems) zero bits may be shifted in, the same as a shift of anunsigned type.@item Integer @code{/}C divides signed integers by truncating their quotient toward zero,yielding the same result as Fortran.  However, before C99 the standardallowed C implementations to take the floor or ceiling of the quotientin some cases.  Hardly any implementations took advantage of thisfreedom, though, and it's probably not worth worrying about this issuenowadays.@end table@node Particular Functions@subsection Particular Function Checks@cindex Function, checkingThese macros check for particular C functions---whether they exist, andin some cases how they respond when given certain arguments.@anchor{AC_FUNC_ALLOCA}@defmac AC_FUNC_ALLOCA@acindex{FUNC_ALLOCA}@cvindex C_ALLOCA@cvindex HAVE_ALLOCA_H@ovindex ALLOCA@c @fuindex alloca@prindex @code{alloca}@hdrindex{alloca.h}@c @caindex working_alloca_hCheck how to get @code{alloca}.  Tries to get a builtin version bychecking for @file{alloca.h} or the predefined C preprocessor macros@code{__GNUC__} and @code{_AIX}.  If this macro finds @file{alloca.h},it defines @code{HAVE_ALLOCA_H}.If those attempts fail, it looks for the function in the standard Clibrary.  If any of those methods succeed, it defines@code{HAVE_ALLOCA}.  Otherwise, it sets the output variable@code{ALLOCA} to @samp{$@{LIBOBJDIR@}alloca.o} and defines@code{C_ALLOCA} (so programs can periodically call @samp{alloca (0)} togarbage collect).  This variable is separate from @code{LIBOBJS} somultiple programs can share the value of @code{ALLOCA} without needingto create an actual library, in case only some of them use the code in@code{LIBOBJS}.  The @samp{$@{LIBOBJDIR@}} prefix serves the samepurpose as in @code{LIBOBJS} (@pxref{AC_LIBOBJ vs LIBOBJS}).This macro does not try to get @code{alloca} from the System V R3@file{libPW} or the System V R4 @file{libucb} because those librariescontain some incompatible functions that cause trouble.  Some versionsdo not even contain @code{alloca} or contain a buggy version.  If youstill want to use their @code{alloca}, use @code{ar} to extract@file{alloca.o} from them instead of compiling @file{alloca.c}.Source files that use @code{alloca} should start with a piece of codelike the following, to declare it properly.@example@group#ifdef STDC_HEADERS# include <stdlib.h># include <stddef.h>#else# ifdef HAVE_STDLIB_H#  include <stdlib.h># endif#endif#ifdef HAVE_ALLOCA_H# include <alloca.h>#elif !defined alloca# ifdef __GNUC__#  define alloca __builtin_alloca# elif defined _AIX#  define alloca __alloca# elif defined _MSC_VER#  include <malloc.h>#  define alloca _alloca# elif !defined HAVE_ALLOCA#  ifdef  __cplusplusextern "C"#  endifvoid *alloca (size_t);# endif#endif@end group@end example@end defmac@defmac AC_FUNC_CHOWN@acindex{FUNC_CHOWN}@cvindex HAVE_CHOWN@c @fuindex chown@prindex @code{chown}@caindex func_chown_worksIf the @code{chown} function is available and works (in particular, itshould accept @option{-1} for @code{uid} and @code{gid}), define@code{HAVE_CHOWN}.  The result of this macro is cached in the@code{ac_cv_func_chown_works} variable.@end defmac@anchor{AC_FUNC_CLOSEDIR_VOID}@defmac AC_FUNC_CLOSEDIR_VOID@acindex{FUNC_CLOSEDIR_VOID}@cvindex CLOSEDIR_VOID@c @fuindex closedir@prindex @code{closedir}@caindex func_closedir_voidIf the @code{closedir} function does not return a meaningful value,define @code{CLOSEDIR_VOID}.  Otherwise, callers ought to check itsreturn value for an error indicator.Currently this test is implemented by running a test program.  Whencross compiling the pessimistic assumption that @code{closedir} does notreturn a meaningful value is made.The result of this macro is cached in the @code{ac_cv_func_closedir_void}variable.This macro is obsolescent, as @code{closedir} returns a meaningful valueon current systems.  New programs need not use this macro.@end defmac@defmac AC_FUNC_ERROR_AT_LINE@acindex{FUNC_ERROR_AT_LINE}@c @fuindex error_at_line@prindex @code{error_at_line}@caindex lib_error_at_lineIf the @code{error_at_line} function is not found, require an@code{AC_LIBOBJ} replacement of @samp{error}.The result of this macro is cached in the @code{ac_cv_lib_error_at_line}variable.The @code{AC_FUNC_ERROR_AT_LINE} macro is obsolescent.  New programsshould use Gnulib's @code{error} module.  @xref{Gnulib}.@end defmac@defmac AC_FUNC_FNMATCH@acindex{FUNC_FNMATCH}@c @fuindex fnmatch@prindex @code{fnmatch}@caindex func_fnmatch_worksIf the @code{fnmatch} function conforms to Posix, define@code{HAVE_FNMATCH}.  Detect common implementation bugs, for example,the bugs in Solaris 2.4.Unlike the other specific@code{AC_FUNC} macros, @code{AC_FUNC_FNMATCH} does not replace abroken/missing @code{fnmatch}.  This is for historical reasons.See @code{AC_REPLACE_FNMATCH} below.The result of this macro is cached in the @code{ac_cv_func_fnmatch_works}variable.This macro is obsolescent.  New programs should use Gnulib's@code{fnmatch-posix} module.  @xref{Gnulib}.@end defmac@defmac AC_FUNC_FNMATCH_GNU@acindex{FUNC_FNMATCH_GNU}@c @fuindex fnmatch@prindex @code{fnmatch}@caindex func_fnmatch_gnuBehave like @code{AC_REPLACE_FNMATCH} (@emph{replace}) but also testwhether @code{fnmatch} supports GNU extensions.  Detect commonimplementation bugs, for example, the bugs in the GNU CLibrary 2.1.The result of this macro is cached in the @code{ac_cv_func_fnmatch_gnu}variable.This macro is obsolescent.  New programs should use Gnulib's@code{fnmatch-gnu} module.  @xref{Gnulib}.@end defmac@anchor{AC_FUNC_FORK}@defmac AC_FUNC_FORK@acindex{FUNC_FORK}@cvindex HAVE_VFORK_H@cvindex HAVE_WORKING_FORK@cvindex HAVE_WORKING_VFORK@cvindex vfork@c @fuindex fork@prindex @code{fork}@c @fuindex vfork@prindex @code{vfork}@hdrindex{vfork.h}@c @caindex func_fork@c @caindex func_fork_worksThis macro checks for the @code{fork} and @code{vfork} functions.  If aworking @code{fork} is found, define @code{HAVE_WORKING_FORK}.  This macrochecks whether @code{fork} is just a stub by trying to run it.If @file{vfork.h} is found, define @code{HAVE_VFORK_H}.  If a working@code{vfork} is found, define @code{HAVE_WORKING_VFORK}.  Otherwise,define @code{vfork} to be @code{fork} for backward compatibility withprevious versions of @command{autoconf}.  This macro checks for several knownerrors in implementations of @code{vfork} and considers the system to nothave a working @code{vfork} if it detects any of them.  It is not consideredto be an implementation error if a child's invocation of @code{signal}modifies the parent's signal handler, since child processes rarely changetheir signal handlers.Since this macro defines @code{vfork} only for backward compatibility withprevious versions of @command{autoconf} you're encouraged to define ityourself in new code:@example@group#ifndef HAVE_WORKING_VFORK# define vfork fork#endif@end group@end exampleThe results of this macro are cached in the @code{ac_cv_func_fork_works}and @code{ac_cv_func_vfork_works} variables.  In order to override thetest, you also need to set the @code{ac_cv_func_fork} and@code{ac_cv_func_vfork} variables.@end defmac@defmac AC_FUNC_FSEEKO@acindex{FUNC_FSEEKO}@cvindex _LARGEFILE_SOURCE@cvindex HAVE_FSEEKO@c @fuindex fseeko@prindex @code{fseeko}@c @fuindex ftello@prindex @code{ftello}@c @caindex sys_largefile_sourceIf the @code{fseeko} function is available, define @code{HAVE_FSEEKO}.Define @code{_LARGEFILE_SOURCE} if necessary to make the prototypevisible on some systems (e.g., glibc 2.2).  Otherwise linkage problemsmay occur when compiling with @code{AC_SYS_LARGEFILE} onlargefile-sensitive systems where @code{off_t} does not default to a64bit entity.  All systems with @code{fseeko} also supply @code{ftello}.@end defmac@defmac AC_FUNC_GETGROUPS@acindex{FUNC_GETGROUPS}@cvindex HAVE_GETGROUPS@ovindex GETGROUPS_LIBS@c @fuindex getgroups@prindex @code{getgroups}@caindex func_getgroups_worksIf the @code{getgroups} function is available and works (unlike onUltrix 4.3, where @samp{getgroups (0, 0)} always fails), define@code{HAVE_GETGROUPS}.  Set @code{GETGROUPS_LIBS} to any librariesneeded to get that function.  This macro runs @code{AC_TYPE_GETGROUPS}.@end defmac@anchor{AC_FUNC_GETLOADAVG}@defmac AC_FUNC_GETLOADAVG@acindex{FUNC_GETLOADAVG}@cvindex SVR4@cvindex DGUX@cvindex UMAX@cvindex UMAX4_3@cvindex HAVE_NLIST_H@cvindex NLIST_NAME_UNION@cvindex GETLOADAVG_PRIVILEGED@cvindex NEED_SETGID@cvindex C_GETLOADAVG@ovindex LIBOBJS@ovindex NEED_SETGID@ovindex KMEM_GROUP@ovindex GETLOADAVG_LIBS@c @fuindex getloadavg@prindex @code{getloadavg}Check how to get the system load averages.  To perform its testsproperly, this macro needs the file @file{getloadavg.c}; therefore, besure to set the @code{AC_LIBOBJ} replacement directory properly (see@ref{Generic Functions}, @code{AC_CONFIG_LIBOBJ_DIR}).If the system has the @code{getloadavg} function, define@code{HAVE_GETLOADAVG}, and set @code{GETLOADAVG_LIBS} to any librariesnecessary to get that function.  Also add @code{GETLOADAVG_LIBS} to@code{LIBS}.  Otherwise, require an @code{AC_LIBOBJ} replacement for@samp{getloadavg} with source code in @file{@var{dir}/getloadavg.c}, andpossibly define several other C preprocessor macros and outputvariables:@enumerate@itemDefine @code{C_GETLOADAVG}.@itemDefine @code{SVR4}, @code{DGUX}, @code{UMAX}, or @code{UMAX4_3} if onthose systems.@item@hdrindex{nlist.h}If @file{nlist.h} is found, define @code{HAVE_NLIST_H}.@itemIf @samp{struct nlist} has an @samp{n_un.n_name} member, define@code{HAVE_STRUCT_NLIST_N_UN_N_NAME}.  The obsolete symbol@code{NLIST_NAME_UNION} is still defined, but do not depend upon it.@itemPrograms may need to be installed set-group-ID (or set-user-ID) for@code{getloadavg} to work.  In this case, define@code{GETLOADAVG_PRIVILEGED}, set the output variable @code{NEED_SETGID}to @samp{true} (and otherwise to @samp{false}), and set@code{KMEM_GROUP} to the name of the group that should own the installedprogram.@end enumerateThe @code{AC_FUNC_GETLOADAVG} macro is obsolescent.  New programs shoulduse Gnulib's @code{getloadavg} module.  @xref{Gnulib}.@end defmac@anchor{AC_FUNC_GETMNTENT}@defmac AC_FUNC_GETMNTENT@acindex{FUNC_GETMNTENT}@cvindex HAVE_GETMNTENT@c @fuindex getmntent@prindex @code{getmntent}@caindex search_getmntentCheck for @code{getmntent} in the standard C library, and then in the@file{sun}, @file{seq}, and @file{gen} libraries, for UNICOS,IRIX 4, PTX, and UnixWare, respectively.  Then, if@code{getmntent} is available, define @code{HAVE_GETMNTENT} and set@code{ac_cv_func_getmntent} to @code{yes}.  Otherwise set@code{ac_cv_func_getmntent} to @code{no}.The result of this macro can be overridden by setting the cache variable@code{ac_cv_search_getmntent}.@end defmac@defmac AC_FUNC_GETPGRP@acindex{FUNC_GETPGRP}@cvindex GETPGRP_VOID@c @fuindex getpgid@c @fuindex getpgrp@prindex @code{getpgid}@prindex @code{getpgrp}@caindex func_getpgrp_voidDefine @code{GETPGRP_VOID} if it is an error to pass 0 to@code{getpgrp}; this is the Posix behavior.  On older BSDsystems, you must pass 0 to @code{getpgrp}, as it takes an argument andbehaves like Posix's @code{getpgid}.@example#ifdef GETPGRP_VOID  pid = getpgrp ();#else  pid = getpgrp (0);#endif@end exampleThis macro does not check whether@code{getpgrp} exists at all; if you need to work in that situation,first call @code{AC_CHECK_FUNC} for @code{getpgrp}.The result of this macro is cached in the @code{ac_cv_func_getpgrp_void}variable.This macro is obsolescent, as current systems have a @code{getpgrp}whose signature conforms to Posix.  New programs need not use this macro.@end defmac@defmac AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK@acindex{FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK}@cvindex LSTAT_FOLLOWS_SLASHED_SYMLINK@c @fuindex lstat@prindex @code{lstat}@caindex func_lstat_dereferences_slashed_symlinkIf @file{link} is a symbolic link, then @code{lstat} should treat@file{link/} the same as @file{link/.}.  However, many older@code{lstat} implementations incorrectly ignore trailing slashes.It is safe to assume that if @code{lstat} incorrectly ignorestrailing slashes, then other symbolic-link-aware functions like@code{unlink} also incorrectly ignore trailing slashes.If @code{lstat} behaves properly, define@code{LSTAT_FOLLOWS_SLASHED_SYMLINK}, otherwise require an@code{AC_LIBOBJ} replacement of @code{lstat}.The result of this macro is cached in the@code{ac_cv_func_lstat_dereferences_slashed_symlink} variable.The @code{AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK} macro is obsolescent.New programs should use Gnulib's @code{lstat} module.  @xref{Gnulib}.@end defmac@defmac AC_FUNC_MALLOC@acindex{FUNC_MALLOC}@cvindex HAVE_MALLOC@cvindex malloc@c @fuindex malloc@prindex @code{malloc}@caindex func_malloc_0_nonnullIf the @code{malloc} function is compatible with the GNU Clibrary @code{malloc} (i.e., @samp{malloc (0)} returns a validpointer), define @code{HAVE_MALLOC} to 1.  Otherwise define@code{HAVE_MALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for@samp{malloc}, and define @code{malloc} to @code{rpl_malloc} so that thenative @code{malloc} is not used in the main project.Typically, the replacement file @file{malloc.c} should look like (notethe @samp{#undef malloc}):@verbatim#include <config.h>#undef malloc#include <sys/types.h>void *malloc ();/* Allocate an N-byte block of memory from the heap.   If N is zero, allocate a 1-byte block.  */void *rpl_malloc (size_t n){  if (n == 0)    n = 1;  return malloc (n);}@end verbatimThe result of this macro is cached in the@code{ac_cv_func_malloc_0_nonnull} variable.@end defmac@defmac AC_FUNC_MBRTOWC@acindex{FUNC_MBRTOWC}@cvindex HAVE_MBRTOWC@c @fuindex mbrtowc@prindex @code{mbrtowc}@caindex func_mbrtowcDefine @code{HAVE_MBRTOWC} to 1 if the function @code{mbrtowc} and thetype @code{mbstate_t} are properly declared.The result of this macro is cached in the @code{ac_cv_func_mbrtowc}variable.@end defmac@defmac AC_FUNC_MEMCMP@acindex{FUNC_MEMCMP}@ovindex LIBOBJS@c @fuindex memcmp@prindex @code{memcmp}@caindex func_memcmp_workingIf the @code{memcmp} function is not available, or does not work on8-bit data (like the one on SunOS 4.1.3), or fails when comparing 16bytes or more and with at least one buffer not starting on a 4-byteboundary (such as the one on NeXT x86 OpenStep), require an@code{AC_LIBOBJ} replacement for @samp{memcmp}.The result of this macro is cached in the@code{ac_cv_func_memcmp_working} variable.This macro is obsolescent, as current systems have a working@code{memcmp}.  New programs need not use this macro.@end defmac@defmac AC_FUNC_MKTIME@acindex{FUNC_MKTIME}@ovindex LIBOBJS@c @fuindex mktime@prindex @code{mktime}@caindex func_working_mktimeIf the @code{mktime} function is not available, or does not workcorrectly, require an @code{AC_LIBOBJ} replacement for @samp{mktime}.For the purposes of this test, @code{mktime} should conform to thePosix standard and should be the inverse of@code{localtime}.The result of this macro is cached in the@code{ac_cv_func_working_mktime} variable.The @code{AC_FUNC_MKTIME} macro is obsolescent.  New programs shoulduse Gnulib's @code{mktime} module.  @xref{Gnulib}.@end defmac@anchor{AC_FUNC_MMAP}@defmac AC_FUNC_MMAP@acindex{FUNC_MMAP}@cvindex HAVE_MMAP@c @fuindex mmap@prindex @code{mmap}@caindex func_mmap_fixed_mappedIf the @code{mmap} function exists and works correctly, define@code{HAVE_MMAP}.  This checks only private fixed mapping of already-mappedmemory.The result of this macro is cached in the@code{ac_cv_func_mmap_fixed_mapped} variable.@end defmac@defmac AC_FUNC_OBSTACK@acindex{FUNC_OBSTACK}@cvindex HAVE_OBSTACK@cindex obstack@caindex func_obstackIf the obstacks are found, define @code{HAVE_OBSTACK}, else require an@code{AC_LIBOBJ} replacement for @samp{obstack}.The result of this macro is cached in the @code{ac_cv_func_obstack}variable.@end defmac@defmac AC_FUNC_REALLOC@acindex{FUNC_REALLOC}@cvindex HAVE_REALLOC@cvindex realloc@c @fuindex realloc@prindex @code{realloc}@caindex func_realloc_0_nonnullIf the @code{realloc} function is compatible with the GNU Clibrary @code{realloc} (i.e., @samp{realloc (NULL, 0)} returns avalid pointer), define @code{HAVE_REALLOC} to 1.  Otherwise define@code{HAVE_REALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for@samp{realloc}, and define @code{realloc} to @code{rpl_realloc} so thatthe native @code{realloc} is not used in the main project.  See@code{AC_FUNC_MALLOC} for details.The result of this macro is cached in the@code{ac_cv_func_realloc_0_nonnull} variable.@end defmac@defmac AC_FUNC_SELECT_ARGTYPES@acindex{FUNC_SELECT_ARGTYPES}@cvindex SELECT_TYPE_ARG1@cvindex SELECT_TYPE_ARG234@cvindex SELECT_TYPE_ARG5@c @fuindex select@prindex @code{select}@c @caindex func_select_argsDetermines the correct type to be passed for each of the@code{select} function's arguments, and defines those typesin @code{SELECT_TYPE_ARG1}, @code{SELECT_TYPE_ARG234}, and@code{SELECT_TYPE_ARG5} respectively.  @code{SELECT_TYPE_ARG1} defaultsto @samp{int}, @code{SELECT_TYPE_ARG234} defaults to @samp{int *},and @code{SELECT_TYPE_ARG5} defaults to @samp{struct timeval *}.This macro is obsolescent, as current systems have a @code{select} whosesignature conforms to Posix.  New programs need not use this macro.@end defmac@defmac AC_FUNC_SETPGRP@acindex{FUNC_SETPGRP}@cvindex SETPGRP_VOID@c @fuindex setpgrp@prindex @code{setpgrp}@caindex func_setpgrp_voidIf @code{setpgrp} takes no argument (the Posix version), define@code{SETPGRP_VOID}.  Otherwise, it is the BSD version, which takestwo process IDs as arguments.  This macro does not check whether@code{setpgrp} exists at all; if you need to work in that situation,first call @code{AC_CHECK_FUNC} for @code{setpgrp}.The result of this macro is cached in the @code{ac_cv_func_setpgrp_void}variable.This macro is obsolescent, as current systems have a @code{setpgrp}whose signature conforms to Posix.  New programs need not use this macro.@end defmac@defmac AC_FUNC_STAT@defmacx AC_FUNC_LSTAT@acindex{FUNC_STAT}@acindex{FUNC_LSTAT}@cvindex HAVE_STAT_EMPTY_STRING_BUG@cvindex HAVE_LSTAT_EMPTY_STRING_BUG@c @fuindex stat@prindex @code{stat}@c @fuindex lstat@prindex @code{lstat}@caindex func_stat_empty_string_bug@caindex func_lstat_empty_string_bugDetermine whether @code{stat} or @code{lstat} have the bug that itsucceeds when given the zero-length file name as argument.  The @code{stat}and @code{lstat} from SunOS 4.1.4 and the Hurd (as of 1998-11-01) dothis.If it does, then define @code{HAVE_STAT_EMPTY_STRING_BUG} (or@code{HAVE_LSTAT_EMPTY_STRING_BUG}) and ask for an @code{AC_LIBOBJ}replacement of it.The results of these macros are cached in the@code{ac_cv_func_stat_empty_string_bug} and the@code{ac_cv_func_lstat_empty_string_bug} variables, respectively.These macros are obsolescent, as no current systems have the bug.New programs need not use these macros.@end defmac@anchor{AC_FUNC_STRCOLL}@defmac AC_FUNC_STRCOLL@acindex{FUNC_STRCOLL}@cvindex HAVE_STRCOLL@c @fuindex strcoll@prindex @code{strcoll}@caindex func_strcoll_worksIf the @code{strcoll} function exists and works correctly, define@code{HAVE_STRCOLL}.  This does a bit more than@samp{AC_CHECK_FUNCS(strcoll)}, because some systems have incorrectdefinitions of @code{strcoll} that should not be used.The result of this macro is cached in the @code{ac_cv_func_strcoll_works}variable.@end defmac@defmac AC_FUNC_STRERROR_R@acindex{FUNC_STRERROR_R}@cvindex HAVE_STRERROR_R@cvindex HAVE_DECL_STRERROR_R@cvindex STRERROR_R_CHAR_P@c @fuindex strerror_r@caindex func_strerror_r_char_p@prindex @code{strerror_r}If @code{strerror_r} is available, define @code{HAVE_STRERROR_R}, and ifit is declared, define @code{HAVE_DECL_STRERROR_R}.  If it returns a@code{char *} message, define @code{STRERROR_R_CHAR_P}; otherwise itreturns an @code{int} error number.  The Thread-Safe Functions option ofPosix requires @code{strerror_r} to return @code{int}, butmany systems (including, for example, version 2.2.4 of the GNU CLibrary) return a @code{char *} value that is not necessarily equal tothe buffer argument.The result of this macro is cached in the@code{ac_cv_func_strerror_r_char_p} variable.@end defmac@anchor{AC_FUNC_STRFTIME}@defmac AC_FUNC_STRFTIME@acindex{FUNC_STRFTIME}@cvindex HAVE_STRFTIME@c @fuindex strftime@prindex @code{strftime}Check for @code{strftime} in the @file{intl} library, for SCO Unix.Then, if @code{strftime} is available, define @code{HAVE_STRFTIME}.This macro is obsolescent, as no current systems require the @file{intl}library for @code{strftime}.  New programs need not use this macro.@end defmac@defmac AC_FUNC_STRTOD@acindex{FUNC_STRTOD}@ovindex POW_LIB@c @fuindex strtod@prindex @code{strtod}@caindex func_strtod@caindex func_powIf the @code{strtod} function does not exist or doesn't work correctly,ask for an @code{AC_LIBOBJ} replacement of @samp{strtod}.  In this case,because @file{strtod.c} is likely to need @samp{pow}, set the outputvariable @code{POW_LIB} to the extra library needed.This macro caches its result in the @code{ac_cv_func_strtod} variableand depends upon the result in the @code{ac_cv_func_pow} variable.The @code{AC_FUNC_STRTOD} macro is obsolescent.  New programs shoulduse Gnulib's @code{strtod} module.  @xref{Gnulib}.@end defmac@defmac AC_FUNC_STRTOLD@acindex{FUNC_STRTOLD}@cvindex HAVE_STRTOLD@prindex @code{strtold}@caindex func_strtoldIf the @code{strtold} function exists and conforms to C99, define@code{HAVE_STRTOLD}.This macro caches its result in the @code{ac_cv_func_strtold} variable.@end defmac@defmac AC_FUNC_STRNLEN@acindex{FUNC_STRNLEN}@cvindex HAVE_STRNLEN@c @fuindex strnlen@prindex @code{strnlen}@caindex func_strnlen_workingIf the @code{strnlen} function is not available, or is buggy (like the onefrom AIX 4.3), require an @code{AC_LIBOBJ} replacement for it.This macro caches its result in the @code{ac_cv_func_strnlen_working}variable.@end defmac@anchor{AC_FUNC_UTIME_NULL}@defmac AC_FUNC_UTIME_NULL@acindex{FUNC_UTIME_NULL}@cvindex HAVE_UTIME_NULL@c @fuindex utime@prindex @code{utime}@caindex func_utime_nullIf @samp{utime (@var{file}, NULL)} sets @var{file}'s timestamp tothe present, define @code{HAVE_UTIME_NULL}.This macro caches its result in the @code{ac_cv_func_utime_null}variable.This macro is obsolescent, as all current systems have a @code{utime}that behaves this way.  New programs need not use this macro.@end defmac@anchor{AC_FUNC_VPRINTF}@defmac AC_FUNC_VPRINTF@acindex{FUNC_VPRINTF}@cvindex HAVE_VPRINTF@cvindex HAVE_DOPRNT@c @fuindex vprintf@prindex @code{vprintf}@c @fuindex vsprintf@prindex @code{vsprintf}If @code{vprintf} is found, define @code{HAVE_VPRINTF}.  Otherwise, if@code{_doprnt} is found, define @code{HAVE_DOPRNT}.  (If @code{vprintf}is available, you may assume that @code{vfprintf} and @code{vsprintf}are also available.)This macro is obsolescent, as all current systems have @code{vprintf}.New programs need not use this macro.@end defmac@defmac AC_REPLACE_FNMATCH@acindex{REPLACE_FNMATCH}@c @fuindex fnmatch@prindex @code{fnmatch}@hdrindex{fnmatch.h}@caindex func_fnmatch_worksIf the @code{fnmatch} function does not conform to Posix (see@code{AC_FUNC_FNMATCH}), ask for its @code{AC_LIBOBJ} replacement.The files @file{fnmatch.c}, @file{fnmatch_loop.c}, and @file{fnmatch_.h}in the @code{AC_LIBOBJ} replacement directory are assumed to contain acopy of the source code of GNU @code{fnmatch}.  If necessary,this source code is compiled as an @code{AC_LIBOBJ} replacement, and the@file{fnmatch_.h} file is linked to @file{fnmatch.h} so that it can beincluded in place of the system @code{<fnmatch.h>}.This macro caches its result in the @code{ac_cv_func_fnmatch_works}variable.This macro is obsolescent, as it assumes the use of particular sourcefiles.  New programs should use Gnulib's @code{fnmatch-posix} module,which provides this macro along with the source files.  @xref{Gnulib}.@end defmac@node Generic Functions@subsection Generic Function ChecksThese macros are used to find functions not covered by the ``particular''test macros.  If the functions might be in libraries other than thedefault C library, first call @code{AC_CHECK_LIB} for those libraries.If you need to check the behavior of a function as well as find outwhether it is present, you have to write your own test forit (@pxref{Writing Tests}).@anchor{AC_CHECK_FUNC}@defmac AC_CHECK_FUNC (@var{function}, @ovar{action-if-found}, @  @ovar{action-if-not-found})@acindex{CHECK_FUNC}@caindex func_@var{function}If C function @var{function} is available, run shell commands@var{action-if-found}, otherwise @var{action-if-not-found}.  If you justwant to define a symbol if the function is available, consider using@code{AC_CHECK_FUNCS} instead.  This macro checks for functions with Clinkage even when @code{AC_LANG(C++)} has been called, since C is morestandardized than C++.  (@pxref{Language Choice}, for more informationabout selecting the language for checks.)This macro caches its result in the @code{ac_cv_func_@var{function}}variable.@end defmac@anchor{AC_CHECK_FUNCS}@defmac AC_CHECK_FUNCS (@var{function}@dots{}, @ovar{action-if-found}, @  @ovar{action-if-not-found})@acindex{CHECK_FUNCS}@cvindex HAVE_@var{function}For each @var{function} enumerated in the blank-or-newline-separated argumentlist, define @code{HAVE_@var{function}} (in all capitals) if it is available.If @var{action-if-found} is given, it is additional shell code toexecute when one of the functions is found.  You can give it a value of@samp{break} to break out of the loop on the first match.  If@var{action-if-not-found} is given, it is executed when one of thefunctions is not found.Results are cached for each @var{function} as in @code{AC_CHECK_FUNC}.@end defmac@defmac AC_CHECK_FUNCS_ONCE (@var{function}@dots{})@acindex{CHECK_FUNCS_ONCE}@cvindex HAVE_@var{function}For each @var{function} enumerated in the blank-or-newline-separated argumentlist, define @code{HAVE_@var{function}} (in all capitals) if it is available.This is a once-only variant of @code{AC_CHECK_FUNCS}.  It generates thechecking code at most once, so that @command{configure} is smaller andfaster; but the checks cannot be conditionalized and are always done once,early during the @command{configure} run.@end defmac@sp 1Autoconf follows a philosophy that was formed over the years by thosewho have struggled for portability: isolate the portability issues inspecific files, and then program as if you were in a Posixenvironment.  Some functions may be missing or unfixable, and yourpackage must be ready to replace them.Suitable replacements for many such problem functions are available fromGnulib (@pxref{Gnulib}).@defmac AC_LIBOBJ (@var{function})@acindex{LIBOBJ}@ovindex LIBOBJSSpecify that @samp{@var{function}.c} must be included in the executablesto replace a missing or broken implementation of @var{function}.@vrindex ac_objextTechnically, it adds @samp{@var{function}.$ac_objext} to the outputvariable @code{LIBOBJS} if it is not already in, and calls@code{AC_LIBSOURCE} for @samp{@var{function}.c}.  You should notdirectly change @code{LIBOBJS}, since this is not traceable.@end defmac@defmac AC_LIBSOURCE (@var{file})@acindex{LIBSOURCE}Specify that @var{file} might be needed to compile the project.  If youneed to know what files might be needed by a @file{configure.ac}, youshould trace @code{AC_LIBSOURCE}.  @var{file} must be a literal.This macro is called automatically from @code{AC_LIBOBJ}, but you mustcall it explicitly if you pass a shell variable to @code{AC_LIBOBJ}.  Inthat case, since shell variables cannot be traced statically, you mustpass to @code{AC_LIBSOURCE} any possible files that the shell variablemight cause @code{AC_LIBOBJ} to need.  For example, if you want to passa variable @code{$foo_or_bar} to @code{AC_LIBOBJ} that holds either@code{"foo"} or @code{"bar"}, you should do:@exampleAC_LIBSOURCE([foo.c])AC_LIBSOURCE([bar.c])AC_LIBOBJ([$foo_or_bar])@end example@noindentThere is usually a way to avoid this, however, and you are encouraged tosimply call @code{AC_LIBOBJ} with literal arguments.Note that this macro replaces the obsolete @code{AC_LIBOBJ_DECL}, withslightly different semantics: the old macro took the function name,e.g., @code{foo}, as its argument rather than the file name.@end defmac@defmac AC_LIBSOURCES (@var{files})@acindex{LIBSOURCES}Like @code{AC_LIBSOURCE}, but accepts one or more @var{files} in acomma-separated M4 list.  Thus, the above example might be rewritten:@exampleAC_LIBSOURCES([foo.c, bar.c])AC_LIBOBJ([$foo_or_bar])@end example@end defmac@defmac AC_CONFIG_LIBOBJ_DIR (@var{directory})@acindex{CONFIG_LIBOBJ_DIR}Specify that @code{AC_LIBOBJ} replacement files are to be found in@var{directory}, a name relative to the top level of thesource tree.  The replacement directory defaults to @file{.}, the toplevel directory, and the most typical value is @file{lib}, correspondingto @samp{AC_CONFIG_LIBOBJ_DIR([lib])}.@command{configure} might need to know the replacement directory for thefollowing reasons: (i) some checks use the replacement files, (ii) somemacros bypass broken system headers by installing links to thereplacement headers (iii) when used in conjunction with Automake,within each makefile, @var{directory} is used as a relative pathfrom @code{$(top_srcdir)} to each object named in @code{LIBOBJS} and@code{LTLIBOBJS}, etc.@end defmac@sp 1It is common to merely check for the existence of a function, and askfor its @code{AC_LIBOBJ} replacement if missing.  The following macro isa convenient shorthand.@defmac AC_REPLACE_FUNCS (@var{function}@dots{})@acindex{REPLACE_FUNCS}@cvindex HAVE_@var{function}@ovindex LIBOBJSLike @code{AC_CHECK_FUNCS}, but uses @samp{AC_LIBOBJ(@var{function})} as@var{action-if-not-found}.  You can declare your replacement function byenclosing the prototype in @samp{#ifndef HAVE_@var{function}}.  If thesystem has the function, it probably declares it in a header file youshould be including, so you shouldn't redeclare it lest your declarationconflict.@end defmac@node Header Files@section Header Files@cindex Header, checkingThe following macros check for the presence of certain C header files.If there is no macro specifically defined to check for a header file you need,and you don't need to check for any special properties ofit, then you can use one of the general header-file check macros.@menu* Header Portability::          Collected knowledge on common headers* Particular Headers::          Special handling to find certain headers* Generic Headers::             How to find other headers@end menu@node Header Portability@subsection Portability of Headers@cindex Portability of headers@cindex Header portabilityThis section documents some collected knowledge about common headers,and the problems they cause.  By definition, this list always requiresadditions.  A much more complete list is maintained by the Gnulibproject (@pxref{Gnulib}), covering @ref{Header File Substitutes, ,Posix Headers, gnulib, GNU gnulib} and @ref{Glibc Header FileSubstitutes, , Glibc Headers, gnulib, GNU gnulib}.  Please help us keepthe gnulib list as complete as possible.@table @asis@item @file{limits.h}C99 says that @file{limits.h} defines @code{LLONG_MIN},@code{LLONG_MAX}, and @code{ULLONG_MAX}, but many almost-C99environments (e.g., default GCC 4.0.2 + glibc 2.4) do notdefine them.@item @file{inttypes.h} vs.@: @file{stdint.h}@hdrindex{inttypes.h}@hdrindex{stdint.h}The C99 standard says that @file{inttypes.h} includes@file{stdint.h}, so there's no need to include @file{stdint.h}separately in a standard environment.  Some implementations have@file{inttypes.h} but not @file{stdint.h} (e.g., Solaris 7), but we don'tknow of any implementation that has @file{stdint.h} but not@file{inttypes.h}.@item @file{linux/irda.h}@hdrindex{linux/irda.h}It requires @file{linux/types.h} and @file{sys/socket.h}.@item @file{linux/random.h}@hdrindex{linux/random.h}It requires @file{linux/types.h}.@item @file{net/if.h}@hdrindex{net/if.h}On Darwin, this file requires that @file{sys/socket.h} be includedbeforehand.  One should run:@exampleAC_CHECK_HEADERS([sys/socket.h])AC_CHECK_HEADERS([net/if.h], [], [],[#include <stdio.h>#ifdef STDC_HEADERS# include <stdlib.h># include <stddef.h>#else# ifdef HAVE_STDLIB_H#  include <stdlib.h># endif#endif#ifdef HAVE_SYS_SOCKET_H# include <sys/socket.h>#endif])@end example@item @file{netinet/if_ether.h}@hdrindex{netinet/if_ether.h}On Darwin, this file requires that @file{stdio.h} and@file{sys/socket.h} be included beforehand.  One should run:@exampleAC_CHECK_HEADERS([sys/socket.h])AC_CHECK_HEADERS([netinet/if_ether.h], [], [],[#include <stdio.h>#ifdef STDC_HEADERS# include <stdlib.h># include <stddef.h>#else# ifdef HAVE_STDLIB_H#  include <stdlib.h># endif#endif#ifdef HAVE_SYS_SOCKET_H# include <sys/socket.h>#endif])@end example@item @file{stdint.h}See above, item @file{inttypes.h} vs.@: @file{stdint.h}.@item @file{stdlib.h}@hdrindex{stdlib.h}On many systems (e.g., Darwin), @file{stdio.h} is a prerequisite.@item @file{sys/mount.h}@hdrindex{sys/mount.h}On FreeBSD 4.8 on ia32 and using gcc version 2.95.4,@file{sys/params.h} is a prerequisite.@item @file{sys/ptem.h}@hdrindex{sys/ptem.h}On Solaris 8, @file{sys/stream.h} is a prerequisite.@item @file{sys/socket.h}@hdrindex{sys/socket.h}On Darwin, @file{stdlib.h} is a prerequisite.@item @file{sys/ucred.h}@hdrindex{sys/ucred.h}On Tru64 5.1, @file{sys/types.h} is a prerequisite.@item @file{X11/extensions/scrnsaver.h}@hdrindex{X11/extensions/scrnsaver.h}Using XFree86, this header requires @file{X11/Xlib.h}, which is probablyso required that you might not even consider looking for it.@exampleAC_CHECK_HEADERS([X11/extensions/scrnsaver.h], [], [],[[#include <X11/Xlib.h>]])@end example@end table@node Particular Headers@subsection Particular Header ChecksThese macros check for particular system header files---whether theyexist, and in some cases whether they declare certain symbols.@defmac AC_CHECK_HEADER_STDBOOL@acindex{CHECK_HEADER_STDBOOL}@cvindex HAVE__BOOL@hdrindex{stdbool.h}@caindex header_stdbool_hCheck whether @file{stdbool.h} exists and conforms to C99, and cache theresult in the @code{ac_cv_header_stdbool_h} variable.  If the type@code{_Bool} is defined, define @code{HAVE__BOOL} to 1.This macro is intended for use by Gnulib (@pxref{Gnulib}) and otherpackages that supply a substitute @file{stdbool.h} on platforms lackinga conforming one.  The @code{AC_HEADER_STDBOOL} macro is better for codethat explicitly checks for @file{stdbool.h}.@end defmac@defmac AC_HEADER_ASSERT@acindex{HEADER_ASSERT}@cvindex NDEBUG@hdrindex{assert.h}Check whether to enable assertions in the style of @file{assert.h}.Assertions are enabled by default, but the user can override this byinvoking @command{configure} with the @option{--disable-assert} option.@end defmac@anchor{AC_HEADER_DIRENT}@defmac AC_HEADER_DIRENT@acindex{HEADER_DIRENT}@cvindex HAVE_DIRENT_H@cvindex HAVE_NDIR_H@cvindex HAVE_SYS_DIR_H@cvindex HAVE_SYS_NDIR_H@hdrindex{dirent.h}@hdrindex{sys/ndir.h}@hdrindex{sys/dir.h}@hdrindex{ndir.h}Check for the following header files.  For the first one that isfound and defines @samp{DIR}, define the listed C preprocessor macro:@multitable {@file{sys/ndir.h}} {@code{HAVE_SYS_NDIR_H}}@item @file{dirent.h}   @tab @code{HAVE_DIRENT_H}@item @file{sys/ndir.h} @tab @code{HAVE_SYS_NDIR_H}@item @file{sys/dir.h}  @tab @code{HAVE_SYS_DIR_H}@item @file{ndir.h}     @tab @code{HAVE_NDIR_H}@end multitableThe directory-library declarations in your source code should looksomething like the following:@example@group#include <sys/types.h>#ifdef HAVE_DIRENT_H# include <dirent.h># define NAMLEN(dirent) strlen ((dirent)->d_name)#else# define dirent direct# define NAMLEN(dirent) ((dirent)->d_namlen)# ifdef HAVE_SYS_NDIR_H#  include <sys/ndir.h># endif# ifdef HAVE_SYS_DIR_H#  include <sys/dir.h># endif# ifdef HAVE_NDIR_H#  include <ndir.h># endif#endif@end group@end exampleUsing the above declarations, the program would declare variables to beof type @code{struct dirent}, not @code{struct direct}, and would accessthe length of a directory entry name by passing a pointer to a@code{struct dirent} to the @code{NAMLEN} macro.This macro also checks for the SCO Xenix @file{dir} and @file{x} libraries.This macro is obsolescent, as all current systems with directorylibraries have @code{<dirent.h>}.  New programs need not use this macro.Also see @code{AC_STRUCT_DIRENT_D_INO} and@code{AC_STRUCT_DIRENT_D_TYPE} (@pxref{Particular Structures}).@end defmac@anchor{AC_HEADER_MAJOR}@defmac AC_HEADER_MAJOR@acindex{HEADER_MAJOR}@cvindex MAJOR_IN_MKDEV@cvindex MAJOR_IN_SYSMACROS@hdrindex{sys/mkdev.h}@hdrindex{sys/sysmacros.h}If @file{sys/types.h} does not define @code{major}, @code{minor}, and@code{makedev}, but @file{sys/mkdev.h} does, define@code{MAJOR_IN_MKDEV}; otherwise, if @file{sys/sysmacros.h} does, define@code{MAJOR_IN_SYSMACROS}.@end defmac@defmac AC_HEADER_RESOLV@acindex{HEADER_RESOLV}@cvindex HAVE_RESOLV_H@hdrindex{resolv.h}Checks for header @file{resolv.h}, checking for prerequisites first.To properly use @file{resolv.h}, your code should contain something likethe following:@verbatim#ifdef HAVE_SYS_TYPES_H#  include <sys/types.h>#endif#ifdef HAVE_NETINET_IN_H#  include <netinet/in.h>   /* inet_ functions / structs */#endif#ifdef HAVE_ARPA_NAMESER_H#  include <arpa/nameser.h> /* DNS HEADER struct */#endif#ifdef HAVE_NETDB_H#  include <netdb.h>#endif#include <resolv.h>@end verbatim@end defmac@anchor{AC_HEADER_STAT}@defmac AC_HEADER_STAT@acindex{HEADER_STAT}@cvindex STAT_MACROS_BROKEN@hdrindex{sys/stat.h}If the macros @code{S_ISDIR}, @code{S_ISREG}, etc.@: defined in@file{sys/stat.h} do not work properly (returning false positives),define @code{STAT_MACROS_BROKEN}.  This is the case on Tektronix UTekV,Amdahl UTS and Motorola System V/88.This macro is obsolescent, as no current systems have the bug.New programs need not use this macro.@end defmac@defmac AC_HEADER_STDBOOL@acindex{HEADER_STDBOOL}@cvindex HAVE_STDBOOL_H@cvindex HAVE__BOOL@hdrindex{stdbool.h}@caindex header_stdbool_hIf @file{stdbool.h} exists and conforms to C99, define@code{HAVE_STDBOOL_H} to 1; if the type @code{_Bool} is defined, define@code{HAVE__BOOL} to 1.  To fulfill the C99 requirements, yourprogram could contain the following code:@example@group#ifdef HAVE_STDBOOL_H# include <stdbool.h>#else# ifndef HAVE__BOOL#  ifdef __cplusplustypedef bool _Bool;#  else#   define _Bool signed char#  endif# endif# define bool _Bool# define false 0# define true 1# define __bool_true_false_are_defined 1#endif@end group@end exampleAlternatively you can use the @samp{stdbool} package of Gnulib(@pxref{Gnulib}).  It simplifies your code so that it can say just@code{#include <stdbool.h>}, and it adds support for less-commonplatforms.This macro caches its result in the @code{ac_cv_header_stdbool_h}variable.This macro differs from @code{AC_CHECK_HEADER_STDBOOL} only in that itdefines @code{HAVE_STDBOOL_H} whereas @code{AC_CHECK_HEADER_STDBOOL}does not.@end defmac@anchor{AC_HEADER_STDC}@defmac AC_HEADER_STDC@acindex{HEADER_STDC}@cvindex STDC_HEADERS@hdrindex{stdlib.h}@hdrindex{stdarg.h}@hdrindex{string.h}@hdrindex{float.h}@hdrindex{ctype.h}@caindex header_stdcDefine @code{STDC_HEADERS} if the system has C header filesconforming to ANSI C89 (ISO C90).Specifically, this macro checks for @file{stdlib.h}, @file{stdarg.h},@file{string.h}, and @file{float.h}; if the system has those, itprobably has the rest of the C89 header files.  This macro alsochecks whether @file{string.h} declares @code{memchr} (and thuspresumably the other @code{mem} functions), whether @file{stdlib.h}declare @code{free} (and thus presumably @code{malloc} and other relatedfunctions), and whether the @file{ctype.h} macros work on characterswith the high bit set, as the C standard requires.If you use this macro, your code can refer to @code{STDC_HEADERS} todetermine whether the system has conforming header files (and probably Clibrary functions).This macro caches its result in the @code{ac_cv_header_stdc} variable.This macro is obsolescent, as current systems have conforming headerfiles.  New programs need not use this macro.@hdrindex{string.h}@hdrindex{strings.h}Nowadays @file{string.h} is part of the C standard and declares functions like@code{strcpy}, and @file{strings.h} is standardized by Posix and declaresBSD functions like @code{bcopy}; buthistorically, string functions were a major sticking point in this area.If you still want to worry about portability to ancient systems withoutstandard headers, there is so much variationthat it is probably easier to declare the functions you use than tofigure out exactly what the system header files declare.  Some ancient systemscontained a mix of functions from the C standard and from BSD;some were mostly standard but lacked @samp{memmove}; some defined theBSD functions as macros in @file{string.h} or@file{strings.h}; some had only the BSD functions but@file{string.h}; some declared the memory functions in @file{memory.h},some in @file{string.h}; etc.  It is probably sufficient to check forone string function and one memory function; if the library had thestandard versions of those then it probably had most of the others.If you put the following in @file{configure.ac}:@example# This example is obsolescent.# Nowadays you can omit these macro calls.AC_HEADER_STDCAC_CHECK_FUNCS([strchr memcpy])@end example@noindentthen, in your code, you can use declarations like this:@example@group/* This example is obsolescent.   Nowadays you can just #include <string.h>.  */#ifdef STDC_HEADERS# include <string.h>#else# ifndef HAVE_STRCHR#  define strchr index#  define strrchr rindex# endifchar *strchr (), *strrchr ();# ifndef HAVE_MEMCPY#  define memcpy(d, s, n) bcopy ((s), (d), (n))#  define memmove(d, s, n) bcopy ((s), (d), (n))# endif#endif@end group@end example@noindentIf you use a function like @code{memchr}, @code{memset}, @code{strtok},or @code{strspn}, which have no BSD equivalent, then macros don'tsuffice to port to ancient hosts; you must provide an implementation ofeach function.  An easyway to incorporate your implementations only when needed (since the onesin system C libraries may be hand optimized) is to, taking @code{memchr}for example, put it in @file{memchr.c} and use@samp{AC_REPLACE_FUNCS([memchr])}.@end defmac@defmac AC_HEADER_SYS_WAIT@acindex{HEADER_SYS_WAIT}@cvindex HAVE_SYS_WAIT_H@hdrindex{sys/wait.h}@caindex header_sys_wait_hIf @file{sys/wait.h} exists and is compatible with Posix, define@code{HAVE_SYS_WAIT_H}.  Incompatibility can occur if @file{sys/wait.h}does not exist, or if it uses the old BSD @code{union wait} insteadof @code{int} to store a status value.  If @file{sys/wait.h} is notPosix compatible, then instead of including it, define thePosix macros with their usual interpretations.  Here is anexample:@example@group#include <sys/types.h>#ifdef HAVE_SYS_WAIT_H# include <sys/wait.h>#endif#ifndef WEXITSTATUS# define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)#endif#ifndef WIFEXITED# define WIFEXITED(stat_val) (((stat_val) & 255) == 0)#endif@end group@end example@noindentThis macro caches its result in the @code{ac_cv_header_sys_wait_h}variable.This macro is obsolescent, as current systems are compatible with Posix.New programs need not use this macro.@end defmac@cvindex _POSIX_VERSION@hdrindex{unistd.h}@code{_POSIX_VERSION} is defined when @file{unistd.h} is included onPosix systems.  If there is no @file{unistd.h}, it is definitelynot a Posix system.  However, some non-Posix systems dohave @file{unistd.h}.The way to check whether the system supports Posix is:@example@group#ifdef HAVE_UNISTD_H# include <sys/types.h># include <unistd.h>#endif#ifdef _POSIX_VERSION/* Code for Posix systems.  */#endif@end group@end example@anchor{AC_HEADER_TIME}@defmac AC_HEADER_TIME@acindex{HEADER_TIME}@cvindex TIME_WITH_SYS_TIME@hdrindex{time.h}@hdrindex{sys/time.h}@caindex header_timeIf a program may include both @file{time.h} and @file{sys/time.h},define @code{TIME_WITH_SYS_TIME}.  On some ancient systems,@file{sys/time.h} included @file{time.h}, but @file{time.h} was notprotected against multiple inclusion, so programs could not explicitlyinclude both files.  This macro is useful in programs that use, forexample, @code{struct timeval} as well as@code{struct tm}.  It is best used in conjunction with@code{HAVE_SYS_TIME_H}, which can be checked for using@code{AC_CHECK_HEADERS([sys/time.h])}.@example@group#ifdef TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# ifdef HAVE_SYS_TIME_H#  include <sys/time.h># else#  include <time.h># endif#endif@end group@end example@noindentThis macro caches its result in the @code{ac_cv_header_time} variable.This macro is obsolescent, as current systems can include both fileswhen they exist.  New programs need not use this macro.@end defmac@defmac AC_HEADER_TIOCGWINSZ@acindex{HEADER_TIOCGWINSZ}@cvindex GWINSZ_IN_SYS_IOCTL@hdrindex{sys/ioctl.h}@hdrindex{termios.h}@c FIXME: I need clarifications from Jim.If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, thendefine @code{GWINSZ_IN_SYS_IOCTL}.  Otherwise @code{TIOCGWINSZ} can befound in @file{<termios.h>}.Use:@example@group#ifdef HAVE_TERMIOS_H# include <termios.h>#endif#ifdef GWINSZ_IN_SYS_IOCTL# include <sys/ioctl.h>#endif@end group@end example@end defmac@node Generic Headers@subsection Generic Header ChecksThese macros are used to find system header files not covered by the``particular'' test macros.  If you need to check the contents of a headeras well as find out whether it is present, you have to write your owntest for it (@pxref{Writing Tests}).@anchor{AC_CHECK_HEADER}@defmac AC_CHECK_HEADER (@var{header-file}, @ovar{action-if-found}, @  @ovar{action-if-not-found}, @ovar{includes})@acindex{CHECK_HEADER}@caindex header_@var{header-file}If the system header file @var{header-file} is compilable, execute shellcommands @var{action-if-found}, otherwise execute@var{action-if-not-found}.  If you just want to define a symbol if theheader file is available, consider using @code{AC_CHECK_HEADERS}instead.@var{includes} is decoded to determine the appropriate includedirectives.  If omitted or empty, @file{configure} will check for both headerexistence (with the preprocessor) and usability (with the compiler),using @code{AC_INCLUDES_DEFAULT} for the compile test.  Ifthere is a discrepancy between the results, a warning is issued to theuser, and the compiler results are favored (@pxref{Present ButCannot Be Compiled}).  In general, favoring the compiler results meansthat a header will be treated as not found even though the file exists,because you did not provide enough prerequisites.Providing a non-empty @var{includes} argument allows the code to provideany prerequisites prior to including the header under test; it is commonto use the argument @code{AC_INCLUDES_DEFAULT} (@pxref{DefaultIncludes}).  With an explicit fourth argument, no preprocessor test isneeded.  As a special case, an @var{includes} of exactly @samp{-}triggers the older preprocessor check, which merely determines existenceof the file in the preprocessor search path; this should only be used asa last resort (it is safer to determine the actual prerequisites andperform a compiler check, or else use @code{AC_PREPROC_IFELSE} to makeit obvious that only a preprocessor check is desired).This macro caches its result in the @code{ac_cv_header_@var{header-file}}variable, with characters not suitable for a variable name mapped tounderscores.@end defmac@anchor{AC_CHECK_HEADERS}@defmac AC_CHECK_HEADERS (@var{header-file}@dots{}, @  @ovar{action-if-found}, @ovar{action-if-not-found}, @  @ovar{includes})@acindex{CHECK_HEADERS}@cvindex HAVE_@var{header}@caindex header_@var{header-file}For each given system header file @var{header-file} in theblank-separated argument list that exists, define@code{HAVE_@var{header-file}} (in all capitals).  If @var{action-if-found}is given, it is additional shell code to execute when one of the headerfiles is found.  You can give it a value of @samp{break} to break out ofthe loop on the first match.  If @var{action-if-not-found} is given, itis executed when one of the header files is not found.@var{includes} is interpreted as in @code{AC_CHECK_HEADER}, in order tochoose the set of preprocessor directives supplied before the headerunder test.This macro caches its result in the @code{ac_cv_header_@var{header-file}}variable, with characters not suitable for a variable name mapped tounderscores.@end defmacPrevious versions of Autoconf merely checked whether the header wasaccepted by the preprocessor.  This was changed because the old test wasinappropriate for typical uses.  Headers are typically used to compile,not merely to preprocess, and the old behavior sometimes acceptedheaders that clashed at compile-time (@pxref{Present But Cannot BeCompiled}).  If you need to check whether a header is preprocessable,you can use @code{AC_PREPROC_IFELSE} (@pxref{Running the Preprocessor}).Actually requiring a header to compile improves the robustness of thetest, but it also requiresthat you make sure that headers that must be included before the@var{header-file} be part of the @var{includes}, (@pxref{DefaultIncludes}).  If looking for @file{bar.h}, which requires that@file{foo.h} be included before if it exists, we suggest the followingscheme:@verbatimAC_CHECK_HEADERS([foo.h])AC_CHECK_HEADERS([bar.h], [], [],[#ifdef HAVE_FOO_H# include <foo.h>#endif])@end verbatimThe following variant generates smaller, faster @command{configure}files if you do not need the full power of @code{AC_CHECK_HEADERS}.@defmac AC_CHECK_HEADERS_ONCE (@var{header-file}@dots{})@acindex{CHECK_HEADERS_ONCE}@cvindex HAVE_@var{header}For each given system header file @var{header-file} in theblank-separated argument list that exists, define@code{HAVE_@var{header-file}} (in all capitals).This is a once-only variant of @code{AC_CHECK_HEADERS}.  It generates thechecking code at most once, so that @command{configure} is smaller andfaster; but the checks cannot be conditionalized and are always done once,early during the @command{configure} run.  Thus, this macro is only safefor checking headers that do not have prerequisites beyond what@code{AC_INCLUDES_DEFAULT} provides.@end defmac@node Declarations@section Declarations@cindex Declaration, checkingThe following macros check for the declaration of variables andfunctions.  If there is no macro specifically defined to check for asymbol you need, then you can use the general macros (@pxref{GenericDeclarations}) or, for more complex tests, you may use@code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).@menu* Particular Declarations::     Macros to check for certain declarations* Generic Declarations::        How to find other declarations@end menu@node Particular Declarations@subsection Particular Declaration ChecksThere are no specific macros for declarations.@node Generic Declarations@subsection Generic Declaration ChecksThese macros are used to find declarations not covered by the ``particular''test macros.@defmac AC_CHECK_DECL (@var{symbol}, @ovar{action-if-found}, @  @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})@acindex{CHECK_DECL}@caindex have_decl_@var{symbol}If @var{symbol} (a function, variable, or constant) is not declared in@var{includes} and a declaration is needed, run the shell commands@var{action-if-not-found}, otherwise @var{action-if-found}.@var{includes} is a series of include directives, defaulting to@code{AC_INCLUDES_DEFAULT} (@pxref{Default Includes}), which are usedprior to the declaration under test.This macro actually tests whether @var{symbol} is defined as a macro orcan be used as an r-value, not whether it is really declared, because itis much safer to avoid introducing extra declarations when they are notneeded.  In order to facilitate use of C++ and overloaded functiondeclarations, it is possible to specify function argument types inparentheses for types which can be zero-initialized:@exampleAC_CHECK_DECL([basename(char *)])@end exampleThis macro caches its result in the @code{ac_cv_have_decl_@var{symbol}}variable, with characters not suitable for a variable name mapped tounderscores.@end defmac@anchor{AC_CHECK_DECLS}@defmac AC_CHECK_DECLS (@var{symbols}, @ovar{action-if-found}, @  @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})@acindex{CHECK_DECLS}@cvindex HAVE_DECL_@var{symbol}@caindex have_decl_@var{symbol}For each of the @var{symbols} (@emph{comma}-separated list with optionalfunction argument types for C++ overloads), define@code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if@var{symbol} is declared, otherwise to @samp{0}.  If@var{action-if-not-found} is given, it is additional shell code toexecute when one of the function declarations is needed, otherwise@var{action-if-found} is executed.@var{includes} is a series of include directives, defaulting to@code{AC_INCLUDES_DEFAULT} (@pxref{Default Includes}), which are usedprior to the declarations under test.This macro uses an M4 list as first argument:@exampleAC_CHECK_DECLS([strdup])AC_CHECK_DECLS([strlen])AC_CHECK_DECLS([malloc, realloc, calloc, free])AC_CHECK_DECLS([j0], [], [], [[#include <math.h>]])AC_CHECK_DECLS([[basename(char *)], [dirname(char *)]])@end exampleUnlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is notdeclared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} insteadof leaving @code{HAVE_DECL_@var{symbol}} undeclared.  When you are@emph{sure} that the check was performed, use@code{HAVE_DECL_@var{symbol}} in @code{#if}:@example#if !HAVE_DECL_SYMBOLextern char *symbol;#endif@end example@noindentIf the test may have not been performed, however, because it is safer@emph{not} to declare a symbol than to use a declaration that conflictswith the system's one, you should use:@example#if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOCvoid *malloc (size_t *s);#endif@end example@noindentYou fall into the second category only in extreme situations: eitheryour files may be used without being configured, or they are used duringthe configuration.  In most cases the traditional approach is enough.This macro caches its results in @code{ac_cv_have_decl_@var{symbol}}variables, with characters not suitable for a variable name mapped tounderscores.@end defmac@defmac AC_CHECK_DECLS_ONCE (@var{symbols})@acindex{CHECK_DECLS_ONCE}@cvindex HAVE_DECL_@var{symbol}For each of the @var{symbols} (@emph{comma}-separated list), define@code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if@var{symbol} is declared in the default include files, otherwise to@samp{0}.  This is a once-only variant of @code{AC_CHECK_DECLS}.  Itgenerates the checking code at most once, so that @command{configure} issmaller and faster; but the checks cannot be conditionalized and arealways done once, early during the @command{configure} run.@end defmac@node Structures@section Structures@cindex Structure, checkingThe following macros check for the presence of certain members in Cstructures.  If there is no macro specifically defined to check for amember you need, then you can use the general structure-member macros(@pxref{Generic Structures}) or, for more complex tests, you may use@code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).@menu* Particular Structures::       Macros to check for certain structure members* Generic Structures::          How to find other structure members@end menu@node Particular Structures@subsection Particular Structure ChecksThe following macros check for certain structures or structure members.@defmac AC_STRUCT_DIRENT_D_INO@acindex{STRUCT_DIRENT_D_INO}@cvindex HAVE_STRUCT_DIRENT_D_INO@c @caindex header_dirent_dirent_h@c @caindex member_struct_dirent_d_inoPerform all the actions of @code{AC_HEADER_DIRENT} (@pxref{ParticularHeaders}).  Then, if @code{struct dirent} contains a @code{d_ino}member, define @code{HAVE_STRUCT_DIRENT_D_INO}.@code{HAVE_STRUCT_DIRENT_D_INO} indicates only the presence of@code{d_ino}, not whether its contents are always reliable.Traditionally, a zero @code{d_ino} indicated a deleted directory entry,though current systems hide this detail from the user and never returnzero @code{d_ino} values.Many current systems report an incorrect @code{d_ino} for a directoryentry that is a mount point.@end defmac@defmac AC_STRUCT_DIRENT_D_TYPE@acindex{STRUCT_DIRENT_D_TYPE}@cvindex HAVE_STRUCT_DIRENT_D_TYPE@c @caindex header_dirent_dirent_h@c @caindex member_struct_dirent_d_typePerform all the actions of @code{AC_HEADER_DIRENT} (@pxref{ParticularHeaders}).  Then, if @code{struct dirent} contains a @code{d_type}member, define @code{HAVE_STRUCT_DIRENT_D_TYPE}.@end defmac@anchor{AC_STRUCT_ST_BLOCKS}@defmac AC_STRUCT_ST_BLOCKS@acindex{STRUCT_ST_BLOCKS}@cvindex HAVE_STRUCT_STAT_ST_BLOCKS@cvindex HAVE_ST_BLOCKS@ovindex LIBOBJS@caindex member_struct_stat_st_blocksIf @code{struct stat} contains an @code{st_blocks} member, define@code{HAVE_STRUCT_STAT_ST_BLOCKS}.  Otherwise, require an@code{AC_LIBOBJ} replacement of @samp{fileblocks}.  The former name,@code{HAVE_ST_BLOCKS} is to be avoided, as its support will cease in thefuture.This macro caches its result in the @code{ac_cv_member_struct_stat_st_blocks}variable.@end defmac@defmac AC_STRUCT_TM@acindex{STRUCT_TM}@cvindex TM_IN_SYS_TIME@hdrindex{time.h}@hdrindex{sys/time.h}If @file{time.h} does not define @code{struct tm}, define@code{TM_IN_SYS_TIME}, which means that including @file{sys/time.h}had better define @code{struct tm}.This macro is obsolescent, as @file{time.h} defines @code{struct tm} incurrent systems.  New programs need not use this macro.@end defmac@anchor{AC_STRUCT_TIMEZONE}@defmac AC_STRUCT_TIMEZONE@acindex{STRUCT_TIMEZONE}@cvindex HAVE_DECL_TZNAME@cvindex HAVE_STRUCT_TM_TM_ZONE@cvindex HAVE_TM_ZONE@cvindex HAVE_TZNAME@c @caindex member_struct_tm_tm_zone@c @caindex struct_tmFigure out how to get the current timezone.  If @code{struct tm} has a@code{tm_zone} member, define @code{HAVE_STRUCT_TM_TM_ZONE} (and theobsoleted @code{HAVE_TM_ZONE}).  Otherwise, if the external array@code{tzname} is found, define @code{HAVE_TZNAME}; if it is declared,define @code{HAVE_DECL_TZNAME}.@end defmac@node Generic Structures@subsection Generic Structure ChecksThese macros are used to find structure members not covered by the``particular'' test macros.@defmac AC_CHECK_MEMBER (@var{aggregate}.@var{member}, @  @ovar{action-if-found}, @ovar{action-if-not-found}, @  @dvar{includes, AC_INCLUDES_DEFAULT})@acindex{CHECK_MEMBER}@caindex member_@var{aggregate}_@var{member}Check whether @var{member} is a member of the aggregate @var{aggregate}.If no @var{includes} are specified, the default includes are used(@pxref{Default Includes}).@exampleAC_CHECK_MEMBER([struct passwd.pw_gecos], [],                [AC_MSG_ERROR([we need `passwd.pw_gecos'])],                [[#include <pwd.h>]])@end exampleYou can use this macro for submembers:@exampleAC_CHECK_MEMBER(struct top.middle.bot)@end exampleThis macro caches its result in the@code{ac_cv_member_@var{aggregate}_@var{member}} variable, withcharacters not suitable for a variable name mapped to underscores.@end defmac@anchor{AC_CHECK_MEMBERS}@defmac AC_CHECK_MEMBERS (@var{members}, @ovar{action-if-found}, @  @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})@acindex{CHECK_MEMBERS}@cvindex HAVE_@var{aggregate}_@var{member}Check for the existence of each @samp{@var{aggregate}.@var{member}} of@var{members} using the previous macro.  When @var{member} belongs to@var{aggregate}, define @code{HAVE_@var{aggregate}_@var{member}} (in allcapitals, with spaces and dots replaced by underscores).  If@var{action-if-found} is given, it is executed for each of the foundmembers.  If @var{action-if-not-found} is given, it is executed for eachof the members that could not be found.@var{includes} is a series of include directives, defaulting to@code{AC_INCLUDES_DEFAULT} (@pxref{Default Includes}), which are usedprior to the members under test.This macro uses M4 lists:@exampleAC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize])@end example@end defmac@node Types@section Types@cindex Types@cindex C typesThe following macros check for C types, either builtin or typedefs.  Ifthere is no macro specifically defined to check for a type you need, andyou don't need to check for any special properties of it, then you canuse a general type-check macro.@menu* Particular Types::            Special handling to find certain types* Generic Types::               How to find other types@end menu@node Particular Types@subsection Particular Type Checks@hdrindex{sys/types.h}@hdrindex{stdlib.h}@hdrindex{stdint.h}@hdrindex{inttypes.h}These macros check for particular C types in @file{sys/types.h},@file{stdlib.h}, @file{stdint.h}, @file{inttypes.h} and others, if theyexist.The Gnulib @code{stdint} module is an alternate way to define many ofthese symbols; it is useful if you prefer your code to assume aC99-or-better environment.  @xref{Gnulib}.@anchor{AC_TYPE_GETGROUPS}@defmac AC_TYPE_GETGROUPS@acindex{TYPE_GETGROUPS}@cvindex GETGROUPS_T@caindex type_getgroupsDefine @code{GETGROUPS_T} to be whichever of @code{gid_t} or @code{int}is the base type of the array argument to @code{getgroups}.This macro caches the base type in the @code{ac_cv_type_getgroups}variable.@end defmac@defmac AC_TYPE_INT8_T@acindex{TYPE_INT8_T}@cvindex HAVE_INT8_T@cvindex int8_t@caindex c_int8_tIf @file{stdint.h} or @file{inttypes.h} does not define the type@code{int8_t}, define @code{int8_t} to a signedinteger type that is exactly 8 bits wide and that uses two's complementrepresentation, if such a type exists.If you are worried about porting to hosts that lack such a type, you canuse the results of this macro in C89-or-later code as follows:@example#if HAVE_STDINT_H# include <stdint.h>#endif#if defined INT8_MAX || defined int8_t @emph{code using int8_t}#else @emph{complicated alternative using >8-bit 'signed char'}#endif@end exampleThis macro caches the type in the @code{ac_cv_c_int8_t} variable.@end defmac@defmac AC_TYPE_INT16_T@acindex{TYPE_INT16_T}@cvindex HAVE_INT16_T@cvindex int16_t@caindex c_int16_tThis is like @code{AC_TYPE_INT8_T}, except for 16-bit integers.@end defmac@defmac AC_TYPE_INT32_T@acindex{TYPE_INT32_T}@cvindex HAVE_INT32_T@cvindex int32_t@caindex c_int32_tThis is like @code{AC_TYPE_INT8_T}, except for 32-bit integers.@end defmac@defmac AC_TYPE_INT64_T@acindex{TYPE_INT64_T}@cvindex HAVE_INT64_T@cvindex int64_t@caindex c_int64_tThis is like @code{AC_TYPE_INT8_T}, except for 64-bit integers.@end defmac@defmac AC_TYPE_INTMAX_T@acindex{TYPE_INTMAX_T}@cvindex HAVE_INTMAX_T@cvindex intmax_t@c @caindex type_intmax_tIf @file{stdint.h} or @file{inttypes.h} defines the type @code{intmax_t},define @code{HAVE_INTMAX_T}.  Otherwise, define @code{intmax_t} to thewidest signed integer type.@end defmac@defmac AC_TYPE_INTPTR_T@acindex{TYPE_INTPTR_T}@cvindex HAVE_INTPTR_T@cvindex intptr_t@c @caindex type_intptr_tIf @file{stdint.h} or @file{inttypes.h} defines the type @code{intptr_t},define @code{HAVE_INTPTR_T}.  Otherwise, define @code{intptr_t} to asigned integer type wide enough to hold a pointer, if such a typeexists.@end defmac@defmac AC_TYPE_LONG_DOUBLE@acindex{TYPE_LONG_DOUBLE}@cvindex HAVE_LONG_DOUBLE@caindex type_long_doubleIf the C compiler supports a working @code{long double} type, define@code{HAVE_LONG_DOUBLE}.  The @code{long double} type might have thesame range and precision as @code{double}.This macro caches its result in the @code{ac_cv_type_long_double}variable.This macro is obsolescent, as current C compilers support @code{longdouble}.  New programs need not use this macro.@end defmac@defmac AC_TYPE_LONG_DOUBLE_WIDER@acindex{TYPE_LONG_DOUBLE_WIDER}@cvindex HAVE_LONG_DOUBLE_WIDER@caindex type_long_double_widerIf the C compiler supports a working @code{long double} type with morerange or precision than the @code{double} type, define@code{HAVE_LONG_DOUBLE_WIDER}.This macro caches its result in the @code{ac_cv_type_long_double_wider}variable.@end defmac@defmac AC_TYPE_LONG_LONG_INT@acindex{TYPE_LONG_LONG_INT}@cvindex HAVE_LONG_LONG_INT@caindex type_long_long_intIf the C compiler supports a working @code{long long int} type, define@code{HAVE_LONG_LONG_INT}.  However, this test does not test@code{long long int} values in preprocessor @code{#if} expressions,because too many compilers mishandle such expressions.@xref{Preprocessor Arithmetic}.This macro caches its result in the @code{ac_cv_type_long_long_int}variable.@end defmac@defmac AC_TYPE_MBSTATE_T@acindex{TYPE_MBSTATE_T}@cvindex mbstate_t@hdrindex{wchar.h}@caindex type_mbstate_tDefine @code{HAVE_MBSTATE_T} if @code{<wchar.h>} declares the@code{mbstate_t} type.  Also, define @code{mbstate_t} to be a type if@code{<wchar.h>} does not declare it.This macro caches its result in the @code{ac_cv_type_mbstate_t}variable.@end defmac@anchor{AC_TYPE_MODE_T}@defmac AC_TYPE_MODE_T@acindex{TYPE_MODE_T}@cvindex mode_t@caindex type_mode_tDefine @code{mode_t} to a suitable type, if standard headers do notdefine it.This macro caches its result in the @code{ac_cv_type_mode_t} variable.@end defmac@anchor{AC_TYPE_OFF_T}@defmac AC_TYPE_OFF_T@acindex{TYPE_OFF_T}@cvindex off_t@caindex type_off_tDefine @code{off_t} to a suitable type, if standard headers do notdefine it.This macro caches its result in the @code{ac_cv_type_off_t} variable.@end defmac@anchor{AC_TYPE_PID_T}@defmac AC_TYPE_PID_T@acindex{TYPE_PID_T}@cvindex pid_t@caindex type_pid_tDefine @code{pid_t} to a suitable type, if standard headers do notdefine it.This macro caches its result in the @code{ac_cv_type_pid_t} variable.@end defmac@anchor{AC_TYPE_SIZE_T}@defmac AC_TYPE_SIZE_T@acindex{TYPE_SIZE_T}@cvindex size_t@caindex type_size_tDefine @code{size_t} to a suitable type, if standard headers do notdefine it.This macro caches its result in the @code{ac_cv_type_size_t} variable.@end defmac@defmac AC_TYPE_SSIZE_T@acindex{TYPE_SSIZE_T}@cvindex ssize_t@caindex type_ssize_tDefine @code{ssize_t} to a suitable type, if standard headers do notdefine it.This macro caches its result in the @code{ac_cv_type_ssize_t} variable.@end defmac@anchor{AC_TYPE_UID_T}@defmac AC_TYPE_UID_T@acindex{TYPE_UID_T}@cvindex uid_t@cvindex gid_t@caindex type_uid_tDefine @code{uid_t} and @code{gid_t} to suitable types, if standardheaders do not define them.This macro caches its result in the @code{ac_cv_type_uid_t} variable.@end defmac@defmac AC_TYPE_UINT8_T@acindex{TYPE_UINT8_T}@cvindex HAVE_UINT8_T@cvindex uint8_t@caindex c_uint8_tIf @file{stdint.h} or @file{inttypes.h} does not define the type@code{uint8_t}, define @code{uint8_t} to anunsigned integer type that is exactly 8 bits wide, if such a typeexists.This is like @code{AC_TYPE_INT8_T}, except for unsigned integers.@end defmac@defmac AC_TYPE_UINT16_T@acindex{TYPE_UINT16_T}@cvindex HAVE_UINT16_T@cvindex uint16_t@caindex c_uint16_tThis is like @code{AC_TYPE_UINT8_T}, except for 16-bit integers.@end defmac@defmac AC_TYPE_UINT32_T@acindex{TYPE_UINT32_T}@cvindex HAVE_UINT32_T@cvindex uint32_t@caindex c_uint32_tThis is like @code{AC_TYPE_UINT8_T}, except for 32-bit integers.@end defmac@defmac AC_TYPE_UINT64_T@acindex{TYPE_UINT64_T}@cvindex HAVE_UINT64_T@cvindex uint64_t@caindex c_uint64_tThis is like @code{AC_TYPE_UINT8_T}, except for 64-bit integers.@end defmac@defmac AC_TYPE_UINTMAX_T@acindex{TYPE_UINTMAX_T}@cvindex HAVE_UINTMAX_T@cvindex uintmax_t@c @caindex type_uintmax_tIf @file{stdint.h} or @file{inttypes.h} defines the type @code{uintmax_t},define @code{HAVE_UINTMAX_T}.  Otherwise, define @code{uintmax_t} to thewidest unsigned integer type.@end defmac@defmac AC_TYPE_UINTPTR_T@acindex{TYPE_UINTPTR_T}@cvindex HAVE_UINTPTR_T@cvindex uintptr_t@c @caindex type_uintptr_tIf @file{stdint.h} or @file{inttypes.h} defines the type @code{uintptr_t},define @code{HAVE_UINTPTR_T}.  Otherwise, define @code{uintptr_t} to anunsigned integer type wide enough to hold a pointer, if such a typeexists.@end defmac@defmac AC_TYPE_UNSIGNED_LONG_LONG_INT@acindex{TYPE_UNSIGNED_LONG_LONG_INT}@cvindex HAVE_UNSIGNED_LONG_LONG_INT@caindex type_unsigned_long_long_intIf the C compiler supports a working @code{unsigned long long int} type,define @code{HAVE_UNSIGNED_LONG_LONG_INT}.  However, this test does not test@code{unsigned long long int} values in preprocessor @code{#if} expressions,because too many compilers mishandle such expressions.@xref{Preprocessor Arithmetic}.This macro caches its result in the @code{ac_cv_type_unsigned_long_long_int}variable.@end defmac@node Generic Types@subsection Generic Type ChecksThese macros are used to check for types not covered by the ``particular''test macros.@defmac AC_CHECK_TYPE (@var{type}, @ovar{action-if-found}, @  @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})@acindex{CHECK_TYPE}@caindex type_@var{type}Check whether @var{type} is defined.  It may be a compiler builtin typeor defined by the @var{includes}.  @var{includes} is a series of includedirectives, defaulting to @code{AC_INCLUDES_DEFAULT} (@pxref{DefaultIncludes}), which are used prior to the type under test.In C, @var{type} must be a type-name, so that the expression @samp{sizeof(@var{type})} is valid (but @samp{sizeof ((@var{type}))} is not).  Thesame test is applied when compiling for C++, which means that in C++@var{type} should be a type-id and should not be an anonymous@samp{struct} or @samp{union}.This macro caches its result in the @code{ac_cv_type_@var{type}}variable, with @samp{*} mapped to @samp{p} and other characters notsuitable for a variable name mapped to underscores.@end defmac@defmac AC_CHECK_TYPES (@var{types}, @ovar{action-if-found}, @  @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})@acindex{CHECK_TYPES}@cvindex HAVE_@var{type}For each @var{type} of the @var{types} that is defined, define@code{HAVE_@var{type}} (in all capitals).  Each @var{type} must followthe rules of @code{AC_CHECK_TYPE}.  If no @var{includes} arespecified, the default includes are used (@pxref{Default Includes}).  If@var{action-if-found} is given, it is additional shell code to executewhen one of the types is found.  If @var{action-if-not-found} is given,it is executed when one of the types is not found.This macro uses M4 lists:@exampleAC_CHECK_TYPES([ptrdiff_t])AC_CHECK_TYPES([unsigned long long int, uintmax_t])AC_CHECK_TYPES([float_t], [], [], [[#include <math.h>]])@end example@end defmacAutoconf, up to 2.13, used to provide to another version of@code{AC_CHECK_TYPE}, broken by design.  In order to keep backwardcompatibility, a simple heuristic, quite safe but not totally, isimplemented.  In case of doubt, read the documentation of the former@code{AC_CHECK_TYPE}, see @ref{Obsolete Macros}.@node Compilers and Preprocessors@section Compilers and Preprocessors@cindex Compilers@cindex Preprocessors@ovindex EXEEXTAll the tests for compilers (@code{AC_PROG_CC}, @code{AC_PROG_CXX},@code{AC_PROG_F77}) define the output variable @code{EXEEXT} based onthe output of the compiler, typically to the empty string ifPosix and @samp{.exe} if a DOS variant.@ovindex OBJEXTThey also define the output variable @code{OBJEXT} based on theoutput of the compiler, after @file{.c} files have been excluded, typicallyto @samp{o} if Posix, @samp{obj} if a DOS variant.If the compiler being used does not produce executables, the tests fail.  Ifthe executables can't be run, and cross-compilation is not enabled, theyfail too.  @xref{Manual Configuration}, for more on support for crosscompiling.@menu* Specific Compiler Characteristics::  Some portability issues* Generic Compiler Characteristics::  Language independent tests and features* C Compiler::                  Checking its characteristics* C++ Compiler::                Likewise* Objective C Compiler::        Likewise* Objective C++ Compiler::      Likewise* Erlang Compiler and Interpreter::  Likewise* Fortran Compiler::            Likewise* Go Compiler::                 Likewise@end menu@node Specific Compiler Characteristics@subsection Specific Compiler CharacteristicsSome compilers exhibit different behaviors.@table @asis@item Static/Dynamic ExpressionsAutoconf relies on a trick to extract one bit of information from the Ccompiler: using negative array sizes.  For instance the followingexcerpt of a C source demonstrates how to test whether @samp{int} objects are 4bytes wide:@examplestatic int test_array[sizeof (int) == 4 ? 1 : -1];@end example@noindentTo our knowledge, there is a single compiler that does not support thistrick: the HP C compilers (the real ones, not only the``bundled'') on HP-UX 11.00.They incorrectly reject the above program with the diagnostic``Variable-length arrays cannot have static storage.''This bug comes from HP compilers' mishandling of @code{sizeof (int)},not from the @code{? 1 : -1}, andAutoconf works around this problem by casting @code{sizeof (int)} to@code{long int} before comparing it.@end table@node Generic Compiler Characteristics@subsection Generic Compiler Characteristics@anchor{AC_CHECK_SIZEOF}@defmac AC_CHECK_SIZEOF (@var{type-or-expr}, @ovar{unused}, @  @dvar{includes, AC_INCLUDES_DEFAULT})@acindex{CHECK_SIZEOF}@cvindex SIZEOF_@var{type-or-expr}@caindex sizeof_@var{type-or-expr}Define @code{SIZEOF_@var{type-or-expr}} (@pxref{Standard Symbols}) to bethe size in bytes of @var{type-or-expr}, which may be either a type oran expression returning a value that has a size.  If the expression@samp{sizeof (@var{type-or-expr})} is invalid, the result is 0.@var{includes} is a series of include directives, defaulting to@code{AC_INCLUDES_DEFAULT} (@pxref{Default Includes}), which are usedprior to the expression under test.This macro now works even when cross-compiling.  The @var{unused}argument was used when cross-compiling.For example, the call@example@c If you change this example, adjust tests/semantics.at:AC_CHECK_SIZEOF struct.AC_CHECK_SIZEOF([int *])@end example@noindentdefines @code{SIZEOF_INT_P} to be 8 on DEC Alpha AXP systems.This macro caches its result in the @code{ac_cv_sizeof_@var{type-or-expr}}variable, with @samp{*} mapped to @samp{p} and other characters notsuitable for a variable name mapped to underscores.@end defmac@defmac AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, AC_INCLUDES_DEFAULT})@acindex{CHECK_ALIGNOF}@cvindex ALIGNOF_@var{type}@caindex alignof_@var{type-or-expr}Define @code{ALIGNOF_@var{type}} (@pxref{Standard Symbols}) to be thealignment in bytes of @var{type}.  @samp{@var{type} y;} must be valid asa structure member declaration.  If @samp{type} is unknown, the resultis 0.  If no @var{includes} are specified, the default includes are used(@pxref{Default Includes}).This macro caches its result in the @code{ac_cv_alignof_@var{type-or-expr}}variable, with @samp{*} mapped to @samp{p} and other characters notsuitable for a variable name mapped to underscores.@end defmac@defmac AC_COMPUTE_INT (@var{var}, @var{expression}, @  @dvar{includes, AC_INCLUDES_DEFAULT}, @ovar{action-if-fails})@acindex{COMPUTE_INT}Store into the shell variable @var{var} the value of the integer@var{expression}.  Thevalue should fit in an initializer in a C variable of type @code{signedlong}.  To support cross compilation (in which case, the macro only works onhosts that use twos-complement arithmetic), it should be possible to evaluatethe expression at compile-time.  If no @var{includes} are specified, thedefault includes are used (@pxref{Default Includes}).Execute @var{action-if-fails} if the value cannot be determined correctly.@end defmac@defmac AC_LANG_WERROR@acindex{LANG_WERROR}Normally Autoconf ignores warnings generated by the compiler, linker, andpreprocessor.  If this macro is used, warnings count as fatalerrors for the current language.  This macro is useful when theresults of configuration are used where warnings are unacceptable; forinstance, if parts of a program are built with the GCC@option{-Werror}option.  If the whole program is built using @option{-Werror} it isoften simpler to put @option{-Werror} in the compiler flags (@code{CFLAGS},etc.).@end defmac@defmac AC_OPENMP@acindex{OPENMP}@cvindex _OPENMP@ovindex OPENMP_CFLAGS@ovindex OPENMP_CXXFLAGS@ovindex OPENMP_FFLAGS@ovindex OPENMP_FCFLAGS@caindex prog_c_openmp@caindex prog_cxx_openmp@caindex prog_f77_openmp@caindex prog_fc_openmp@uref{http://@/www.openmp.org/, OpenMP} specifies extensions of C, C++,and Fortran that simplify optimization of shared memory parallelism,which is a common problem on multicore CPUs.If the current language is C, the macro @code{AC_OPENMP} sets thevariable @code{OPENMP_CFLAGS} to the C compiler flags needed forsupporting OpenMP@.  @code{OPENMP_CFLAGS} is set to empty if thecompiler already supports OpenMP, if it has no way to activate OpenMPsupport, or if the user rejects OpenMP support by invoking@samp{configure} with the @samp{--disable-openmp} option.@code{OPENMP_CFLAGS} needs to be used when compiling programs, whenpreprocessing program source, and when linking programs.  Therefore youneed to add @code{$(OPENMP_CFLAGS)} to the @code{CFLAGS} of C programsthat use OpenMP@.  If you preprocess OpenMP-specific C code, you alsoneed to add @code{$(OPENMP_CFLAGS)} to @code{CPPFLAGS}.  The presence ofOpenMP support is revealed at compile time by the preprocessor macro@code{_OPENMP}.Linking a program with @code{OPENMP_CFLAGS} typically adds one moreshared library to the program's dependencies, so its use is recommendedonly on programs that actually require OpenMP.If the current language is C++, @code{AC_OPENMP} sets the variable@code{OPENMP_CXXFLAGS}, suitably for the C++ compiler.  The same remarkshold as for C.If the current language is Fortran 77 or Fortran, @code{AC_OPENMP} setsthe variable @code{OPENMP_FFLAGS} or @code{OPENMP_FCFLAGS},respectively.  Similar remarks as for C hold, except that@code{CPPFLAGS} is not used for Fortran, and no preprocessor macrosignals OpenMP support.For portability, it is best to avoid spaces between @samp{#} and@samp{pragma omp}.  That is, write @samp{#pragma omp}, not@samp{# pragma omp}.  The Sun WorkShop 6.2 C compiler chokes on thelatter.This macro caches its result in the @code{ac_cv_prog_c_openmp},@code{ac_cv_prog_cxx_openmp}, @code{ac_cv_prog_f77_openmp}, or@code{ac_cv_prog_fc_openmp} variable, depending on the current language.@end defmac@node C Compiler@subsection C Compiler CharacteristicsThe following macros provide ways to find and exercise a C Compiler.There are a few constructs that ought to be avoided, but do not deservebeing checked for, since they can easily be worked around.@table @asis@item Don't use lines containing solitary backslashesThey tickle a bug in the HP-UX C compiler (checked onHP-UX 10.20,11.00, and 11i).  When given the following source:@example#ifdef __STDC__/\* A comment with backslash-newlines in it.  %@{ %@} *\\/char str[] = "\\" A string with backslash-newlines in it %@{ %@} \\"";char apostrophe = '\\\'\';#endif@end example@noindentthe compiler incorrectly fails with the diagnostics ``Non-terminatingcomment at end of file'' and ``Missing @samp{#endif} at end of file.''Removing the lines with solitary backslashes solves the problem.@item Don't compile several files at once if output matters to youSome compilers, such as HP's, report names of files beingcompiled when given more than one file operand.  For instance:@example$ @kbd{cc a.c b.c}a.c:b.c:@end example@noindentThis can cause problems if you observe the output of the compiler todetect failures.  Invoking @samp{cc -c a.c && cc -c b.c && cc -o c a.ob.o} solves the issue.@item Don't rely on @code{#error} failingThe IRIX C compiler does not fail when #error is preprocessed; itsimply emits a diagnostic and continues, exiting successfully.  So,instead of an error directive like @code{#error "Unsupported word size"}it is more portable to use an invalid directive like @code{#Unsupportedword size} in Autoconf tests.  In ordinary source code, @code{#error} isOK, since installers with inadequate compilers like IRIX can simplyexamine these compilers' diagnostic output.@item Don't rely on correct @code{#line} supportOn Solaris, @command{c89} (at least Sun C 5.3 through 5.8)diagnoses @code{#line} directives whose linenumbers are greater than 32767.  Nothing in Posixmakes this invalid.  That is why Autoconf stopped issuing@code{#line} directives.@end table@defmac AC_PROG_CC (@ovar{compiler-search-list})@acindex{PROG_CC}@evindex CC@evindex CFLAGS@ovindex CC@ovindex CFLAGS@caindex prog_cc_c89Determine a C compiler to use.  If @code{CC} is not already set in theenvironment, check for @code{gcc} and @code{cc}, then for other Ccompilers.  Set output variable @code{CC} to the name of the compilerfound.This macro may, however, be invoked with an optional first argumentwhich, if specified, must be a blank-separated list of C compilers tosearch for.  This just gives the user an opportunity to specify analternative search list for the C compiler.  For example, if you didn'tlike the default order, then you could invoke @code{AC_PROG_CC} likethis:@exampleAC_PROG_CC([gcc cl cc])@end exampleIf the C compiler does not handle function prototypes correctly bydefault, try to add an option to output variable @code{CC} to make itso.  This macro tries various options that select standard-conformancemodes on various systems.After calling this macro you can check whether the C compiler has beenset to accept ANSI C89 (ISO C90); if not, the shellvariable@code{ac_cv_prog_cc_c89} is set to @samp{no}.  See also@code{AC_C_PROTOTYPES} below.If using the GNU C compiler, set shell variable @code{GCC} to@samp{yes}.  If output variable @code{CFLAGS} was not already set, setit to @option{-g -O2} for the GNU C compiler (@option{-O2} on systemswhere GCC does not accept @option{-g}), or @option{-g} forother compilers.  If your package does not like this default, then it isacceptable to insert the line @samp{: $@{CFLAGS=""@}} after @code{AC_INIT}and before @code{AC_PROG_CC} to select an empty default instead.Many Autoconf macros use a compiler, and thus call@samp{AC_REQUIRE([AC_PROG_CC])} to ensure that the compiler has beendetermined before the body of the outermost @code{AC_DEFUN} macro.Although @code{AC_PROG_CC} is safe to directly expand multiple times, itperforms certain checks (such as the proper value of @env{EXEEXT}) onlyon the first invocation.  Therefore, care must be used when invokingthis macro from within another macro rather than at the top level(@pxref{Expanded Before Required}).@end defmac@anchor{AC_PROG_CC_C_O}@defmac AC_PROG_CC_C_O@acindex{PROG_CC_C_O}@cvindex NO_MINUS_C_MINUS_O@caindex prog_cc_@var{compiler}_c_oIf the C compiler does not accept the @option{-c} and @option{-o} optionssimultaneously, define @code{NO_MINUS_C_MINUS_O}.  This macro actuallytests both the compiler found by @code{AC_PROG_CC}, and, if different,the first @code{cc} in the path.  The test fails if one fails.  Thismacro was created for GNU Make to choose the default C compilationrule.For the compiler @var{compiler}, this macro caches its result in the@code{ac_cv_prog_cc_@var{compiler}_c_o} variable.@end defmac@defmac AC_PROG_CPP@acindex{PROG_CPP}@evindex CPP@ovindex CPPSet output variable @code{CPP} to a command that runs theC preprocessor.  If @samp{$CC -E} doesn't work, @file{/lib/cpp} is used.It is only portable to run @code{CPP} on files with a @file{.c}extension.Some preprocessors don't indicate missing include files by the errorstatus.  For such preprocessors an internal variable is set that causesother macros to check the standard error from the preprocessor andconsider the test failed if any warnings have been reported.For most preprocessors, though, warnings do not cause include-filetests to fail unless @code{AC_PROG_CPP_WERROR} is also specified.@end defmac@defmac AC_PROG_CPP_WERROR@acindex{PROG_CPP_WERROR}@ovindex CPPThis acts like @code{AC_PROG_CPP}, except it treats warnings from thepreprocessor as errors even if the preprocessor exit status indicatessuccess.  This is useful for avoiding headers that generate mandatorywarnings, such as deprecation notices.@end defmacThe following macros check for C compiler or machine architecturefeatures.  To check for characteristics not listed here, use@code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or@code{AC_RUN_IFELSE} (@pxref{Runtime}).@defmac AC_PROG_CC_STDC@acindex{PROG_CC_STDC}@caindex prog_cc_stdcIf the C compiler cannot compile ISO Standard C (currentlyC99), try to add an option to output variable @code{CC} to make it work.If the compiler does not support C99, fall back to supportingANSI C89 (ISO C90).After calling this macro you can check whether the C compiler has beenset to accept Standard C; if not, the shell variable@code{ac_cv_prog_cc_stdc} is set to @samp{no}.@end defmac@defmac AC_PROG_CC_C89@acindex{PROG_CC_C89}@caindex prog_cc_c89If the C compiler is not in ANSI C89 (ISO C90) mode bydefault, try to add an option to output variable @code{CC} to make itso.  This macro tries various options that select ANSI C89 onsome system or another, preferring extended functionality modes overstrict conformance modes.  It considers the compiler to be inANSI C89 mode if it handles function prototypes correctly.After calling this macro you can check whether the C compiler has beenset to accept ANSI C89; if not, the shell variable@code{ac_cv_prog_cc_c89} is set to @samp{no}.This macro is called automatically by @code{AC_PROG_CC}.@end defmac@defmac AC_PROG_CC_C99@acindex{PROG_CC_C99}@caindex prog_cc_c99If the C compiler is not in C99 mode by default, try to add anoption to output variable @code{CC} to make it so.  This macro triesvarious options that select C99 on some system or another, preferringextended functionality modes over strict conformance modes.  Itconsiders the compiler to be in C99 mode if it handles @code{_Bool},@code{//} comments, flexible array members, @code{inline}, signed andunsigned @code{long long int}, mixed code and declarations, namedinitialization of structs,@code{restrict}, @code{va_copy}, varargs macros, variable declarationsin @code{for} loops, and variable length arrays.After calling this macro you can check whether the C compiler has beenset to accept C99; if not, the shell variable@code{ac_cv_prog_cc_c99} is set to @samp{no}.@end defmac@defmac AC_C_BACKSLASH_A@acindex{C_BACKSLASH_A}@cvindex HAVE_C_BACKSLASH_ADefine @samp{HAVE_C_BACKSLASH_A} to 1 if the C compiler understands@samp{\a}.This macro is obsolescent, as current C compilers understand @samp{\a}.New programs need not use this macro.@end defmac@anchor{AC_C_BIGENDIAN}@defmac AC_C_BIGENDIAN (@ovar{action-if-true}, @ovar{action-if-false}, @  @ovar{action-if-unknown}, @ovar{action-if-universal})@acindex{C_BIGENDIAN}@cvindex WORDS_BIGENDIAN@cindex EndiannessIf words are stored with the most significant byte first (like Motorolaand SPARC CPUs), execute @var{action-if-true}.  If words are stored withthe least significant byte first (like Intel and VAX CPUs), execute@var{action-if-false}.This macro runs a test-case if endianness cannot be determined from thesystem header files.  When cross-compiling, the test-case is not run butgrep'ed for some magic values.  @var{action-if-unknown} is executed ifthe latter case fails to determine the byte sex of the host system.In some cases a single run of a compiler can generate code for multiplearchitectures.  This can happen, for example, when generating Mac OS Xuniversal binary files, which work on both PowerPC and Intelarchitectures.  In this case, the different variants might be fordifferent architectures whose endiannesses differ.  If@command{configure} detects this, it executes @var{action-if-universal}instead of @var{action-if-unknown}.The default for @var{action-if-true} is to define@samp{WORDS_BIGENDIAN}.  The default for @var{action-if-false} is to donothing.  The default for @var{action-if-unknown} is toabort configure and tell the installer how to bypass this test.And finally, the default for @var{action-if-universal} is to ensure that@samp{WORDS_BIGENDIAN} is defined if and only if a universal build isdetected and the current code is big-endian; this default works only if@command{autoheader} is used (@pxref{autoheader Invocation}).If you use this macro without specifying @var{action-if-universal}, youshould also use @code{AC_CONFIG_HEADERS}; otherwise@samp{WORDS_BIGENDIAN} may be set incorrectly for Mac OS X universalbinary files.@end defmac@anchor{AC_C_CONST}@defmac AC_C_CONST@acindex{C_CONST}@cvindex const@caindex c_constIf the C compiler does not fully support the @code{const} keyword,define @code{const} to be empty.  Some C compilers that donot define @code{__STDC__} do support @code{const}; some compilers thatdefine @code{__STDC__} do not completely support @code{const}.  Programscan simply use @code{const} as if every C compiler supported it; forthose that don't, the makefile or configuration header filedefines it as empty.Occasionally installers use a C++ compiler to compile C code, typicallybecause they lack a C compiler.  This causes problems with @code{const},because C and C++ treat @code{const} differently.  For example:@exampleconst int foo;@end example@noindentis valid in C but not in C++.  These differences unfortunately cannot bepapered over by defining @code{const} to be empty.If @command{autoconf} detects this situation, it leaves @code{const} alone,as this generally yields better results in practice.  However, using aC++ compiler to compile C code is not recommended or supported, andinstallers who run into trouble in this area should get a C compilerlike GCC to compile their C code.This macro caches its result in the @code{ac_cv_c_const} variable.This macro is obsolescent, as current C compilers support @code{const}.New programs need not use this macro.@end defmac@defmac AC_C_RESTRICT@acindex{C_RESTRICT}@cvindex restrict@caindex c_restrictIf the C compiler recognizes a variant spelling for the @code{restrict}keyword (@code{__restrict}, @code{__restrict__}, or @code{_Restrict}),then define @code{restrict} to that; this is more likely to do the rightthing with compilers that support language variants where plain@code{restrict} is not a keyword.  Otherwise, if the C compilerrecognizes the @code{restrict} keyword, don't do anything.Otherwise, define @code{restrict} to be empty.Thus, programs may simply use @code{restrict} as if every C compilersupported it; for those that do not, the makefileor configuration header defines it away.Although support in C++ for the @code{restrict} keyword is notrequired, several C++ compilers do accept the keyword.This macro works for them, too.This macro caches @samp{no} in the @code{ac_cv_c_restrict} variableif @code{restrict} is not supported, and a supported spelling otherwise.@end defmac@defmac AC_C_VOLATILE@acindex{C_VOLATILE}@cvindex volatileIf the C compiler does not understand the keyword @code{volatile},define @code{volatile} to be empty.  Programs can simply use@code{volatile} as if every C compiler supported it; for those that donot, the makefile or configuration header defines it asempty.If the correctness of your program depends on the semantics of@code{volatile}, simply defining it to be empty does, in a sense, breakyour code.  However, given that the compiler does not support@code{volatile}, you are at its mercy anyway.  At least yourprogram compiles, when it wouldn't before.@xref{Volatile Objects}, for more about @code{volatile}.In general, the @code{volatile} keyword is a standard C feature, soyou might expect that @code{volatile} is available only when@code{__STDC__} is defined.  However, Ultrix 4.3's native compiler doessupport volatile, but does not define @code{__STDC__}.This macro is obsolescent, as current C compilers support @code{volatile}.New programs need not use this macro.@end defmac@anchor{AC_C_INLINE}@defmac AC_C_INLINE@acindex{C_INLINE}@cvindex inlineIf the C compiler supports the keyword @code{inline}, do nothing.Otherwise define @code{inline} to @code{__inline__} or @code{__inline}if it accepts one of those, otherwise define @code{inline} to be empty.@end defmac@anchor{AC_C_CHAR_UNSIGNED}@defmac AC_C_CHAR_UNSIGNED@acindex{C_CHAR_UNSIGNED}@cvindex __CHAR_UNSIGNED__If the C type @code{char} is unsigned, define @code{__CHAR_UNSIGNED__},unless the C compiler predefines it.These days, using this macro is not necessary.  The same information canbe determined by this portable alternative, thus avoiding the use ofpreprocessor macros in the namespace reserved for the implementation.@example#include <limits.h>#if CHAR_MIN == 0# define CHAR_UNSIGNED 1#endif@end example@end defmac@defmac AC_C_STRINGIZE@acindex{C_STRINGIZE}@cvindex HAVE_STRINGIZEIf the C preprocessor supports the stringizing operator, define@code{HAVE_STRINGIZE}.  The stringizing operator is @samp{#} and isfound in macros such as this:@example#define x(y) #y@end exampleThis macro is obsolescent, as current C compilers support thestringizing operator.  New programs need not use this macro.@end defmac@defmac AC_C_FLEXIBLE_ARRAY_MEMBER@acindex{C_FLEXIBLE_ARRAY_MEMBER}@cvindex FLEXIBLE_ARRAY_MEMBERIf the C compiler supports flexible array members, define@code{FLEXIBLE_ARRAY_MEMBER} to nothing; otherwise define it to 1.That way, a declaration like this:@examplestruct s  @{    size_t n_vals;    double val[FLEXIBLE_ARRAY_MEMBER];  @};@end example@noindentwill let applications use the ``struct hack'' even with compilers thatdo not support flexible array members.  To allocate and use such anobject, you can use code like this:@examplesize_t i;size_t n = compute_value_count ();struct s *p =   malloc (offsetof (struct s, val)           + n * sizeof (double));p->n_vals = n;for (i = 0; i < n; i++)  p->val[i] = compute_value (i);@end example@end defmac@defmac AC_C_VARARRAYS@acindex{C_VARARRAYS}@cvindex HAVE_C_VARARRAYSIf the C compiler supports variable-length arrays, define@code{HAVE_C_VARARRAYS}.  A variable-length array is an array of automaticstorage duration whose length is determined at run time, when the arrayis declared.@end defmac@defmac AC_C_TYPEOF@acindex{C_TYPEOF}@cvindex HAVE_TYPEOF@cvindex typeofIf the C compiler supports GCC's @code{typeof} syntax eitherdirectly orthrough a different spelling of the keyword (e.g., @code{__typeof__}),define @code{HAVE_TYPEOF}.  If the support is available only through adifferent spelling, define @code{typeof} to that spelling.@end defmac@defmac AC_C_PROTOTYPES@acindex{C_PROTOTYPES}@cvindex PROTOTYPES@cvindex __PROTOTYPES@cvindex PARAMSIf function prototypes are understood by the compiler (as determined by@code{AC_PROG_CC}), define @code{PROTOTYPES} and @code{__PROTOTYPES}.Defining @code{__PROTOTYPES} is for the benefit ofheader files that cannot use macros that infringe on user name space.This macro is obsolescent, as current C compilers support prototypes.New programs need not use this macro.@end defmac@anchor{AC_PROG_GCC_TRADITIONAL}@defmac AC_PROG_GCC_TRADITIONAL@acindex{PROG_GCC_TRADITIONAL}@ovindex CCAdd @option{-traditional} to output variable @code{CC} if using theGNU C compiler and @code{ioctl} does not work properly without@option{-traditional}.  That usually happens when the fixed header fileshave not been installed on an old system.This macro is obsolescent, since current versions of the GNU Ccompiler fix the header files automatically when installed.@end defmac@node C++ Compiler@subsection C++ Compiler Characteristics@defmac AC_PROG_CXX (@ovar{compiler-search-list})@acindex{PROG_CXX}@evindex CXX@evindex CXXFLAGS@ovindex CXX@ovindex CXXFLAGSDetermine a C++ compiler to use.  Check whether the environment variable@code{CXX} or @code{CCC} (in that order) is set; if so, then set outputvariable @code{CXX} to its value.Otherwise, if the macro is invoked without an argument, then search fora C++ compiler under the likely names (first @code{g++} and @code{c++}then other names).  If none of those checks succeed, then as a lastresort set @code{CXX} to @code{g++}.This macro may, however, be invoked with an optional first argumentwhich, if specified, must be a blank-separated list of C++ compilers tosearch for.  This just gives the user an opportunity to specify analternative search list for the C++ compiler.  For example, if youdidn't like the default order, then you could invoke @code{AC_PROG_CXX}like this:@exampleAC_PROG_CXX([gcc cl KCC CC cxx cc++ xlC aCC c++ g++])@end exampleIf using the GNU C++ compiler, set shell variable @code{GXX} to@samp{yes}.  If output variable @code{CXXFLAGS} was not already set, setit to @option{-g -O2} for the GNU C++ compiler (@option{-O2} onsystems where G++ does not accept @option{-g}), or @option{-g} for othercompilers.  If your package does not like this default, then it isacceptable to insert the line @samp{: $@{CXXFLAGS=""@}} after @code{AC_INIT}and before @code{AC_PROG_CXX} to select an empty default instead.@end defmac@defmac AC_PROG_CXXCPP@acindex{PROG_CXXCPP}@evindex CXXCPP@ovindex CXXCPPSet output variable @code{CXXCPP} to a command that runs the C++preprocessor.  If @samp{$CXX -E} doesn't work, @file{/lib/cpp} is used.It is portable to run @code{CXXCPP} only on files with a @file{.c},@file{.C}, @file{.cc}, or @file{.cpp} extension.Some preprocessors don't indicate missing include files by the errorstatus.  For such preprocessors an internal variable is set that causesother macros to check the standard error from the preprocessor andconsider the test failed if any warnings have been reported.  However,it is not known whether such broken preprocessors exist for C++.@end defmac@defmac AC_PROG_CXX_C_O@acindex{PROG_CXX_C_O}@cvindex CXX_NO_MINUS_C_MINUS_OTest whether the C++ compiler accepts the options @option{-c} and@option{-o} simultaneously, and define @code{CXX_NO_MINUS_C_MINUS_O},if it does not.@end defmac@node Objective C Compiler@subsection Objective C Compiler Characteristics@defmac AC_PROG_OBJC (@ovar{compiler-search-list})@acindex{PROG_OBJC}@evindex OBJC@evindex OBJCFLAGS@ovindex OBJC@ovindex OBJCFLAGSDetermine an Objective C compiler to use.  If @code{OBJC} is not alreadyset in the environment, check for Objective C compilers.  Set outputvariable @code{OBJC} to the name of the compiler found.This macro may, however, be invoked with an optional first argumentwhich, if specified, must be a blank-separated list of Objective C compilers tosearch for.  This just gives the user an opportunity to specify analternative search list for the Objective C compiler.  For example, if youdidn't like the default order, then you could invoke @code{AC_PROG_OBJC}like this:@exampleAC_PROG_OBJC([gcc objcc objc])@end exampleIf using the GNU Objective C compiler, set shell variable@code{GOBJC} to @samp{yes}.  If output variable @code{OBJCFLAGS} was notalready set, set it to @option{-g -O2} for the GNU Objective Ccompiler (@option{-O2} on systems where @command{gcc} does not accept@option{-g}), or @option{-g} for other compilers.@end defmac@defmac AC_PROG_OBJCPP@acindex{PROG_OBJCPP}@evindex OBJCPP@ovindex OBJCPPSet output variable @code{OBJCPP} to a command that runs the Objective Cpreprocessor.  If @samp{$OBJC -E} doesn't work, @file{/lib/cpp} is used.@end defmac@node Objective C++ Compiler@subsection Objective C++ Compiler Characteristics@defmac AC_PROG_OBJCXX (@ovar{compiler-search-list})@acindex{PROG_OBJCXX}@evindex OBJCXX@evindex OBJCXXFLAGS@ovindex OBJCXX@ovindex OBJCXXFLAGSDetermine an Objective C++ compiler to use.  If @code{OBJCXX} is not alreadyset in the environment, check for Objective C++ compilers.  Set outputvariable @code{OBJCXX} to the name of the compiler found.This macro may, however, be invoked with an optional first argumentwhich, if specified, must be a blank-separated list of Objective C++ compilersto search for.  This just gives the user an opportunity to specify analternative search list for the Objective C++ compiler.  For example, if youdidn't like the default order, then you could invoke @code{AC_PROG_OBJCXX}like this:@exampleAC_PROG_OBJCXX([gcc g++ objcc++ objcxx])@end exampleIf using the GNU Objective C++ compiler, set shell variable@code{GOBJCXX} to @samp{yes}.  If output variable @code{OBJCXXFLAGS} was notalready set, set it to @option{-g -O2} for the GNU Objective C++compiler (@option{-O2} on systems where @command{gcc} does not accept@option{-g}), or @option{-g} for other compilers.@end defmac@defmac AC_PROG_OBJCXXCPP@acindex{PROG_OBJCXXCPP}@evindex OBJCXXCPP@ovindex OBJCXXCPPSet output variable @code{OBJCXXCPP} to a command that runs the Objective C++preprocessor.  If @samp{$OBJCXX -E} doesn't work, @file{/lib/cpp} is used.@end defmac@node Erlang Compiler and Interpreter@subsection Erlang Compiler and Interpreter Characteristics@cindex ErlangAutoconf defines the following macros for determining paths to the essentialErlang/OTP programs:@defmac AC_ERLANG_PATH_ERLC (@ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{ERLANG_PATH_ERLC}@evindex ERLC@evindex ERLCFLAGS@ovindex ERLC@ovindex ERLCFLAGSDetermine an Erlang compiler to use.  If @code{ERLC} is not already set in theenvironment, check for @command{erlc}.  Set output variable @code{ERLC} to thecomplete path of the compiler command found.  In addition, if @code{ERLCFLAGS}is not set in the environment, set it to an empty value.The two optional arguments have the same meaning as the two last arguments ofmacro @code{AC_PATH_PROG} for looking for the @command{erlc} program.  Forexample, to look for @command{erlc} only in the @file{/usr/lib/erlang/bin}directory:@exampleAC_ERLANG_PATH_ERLC([not found], [/usr/lib/erlang/bin])@end example@end defmac@defmac AC_ERLANG_NEED_ERLC (@dvar{path, $PATH})@acindex{ERLANG_NEED_ERLC}A simplified variant of the @code{AC_ERLANG_PATH_ERLC} macro, that prints anerror message and exits the @command{configure} script if the @command{erlc}program is not found.@end defmac@defmac AC_ERLANG_PATH_ERL (@ovar{value-if-not-found}, @dvar{path, $PATH})@acindex{ERLANG_PATH_ERL}@evindex ERL@ovindex ERLDetermine an Erlang interpreter to use.  If @code{ERL} is not alreadyset in theenvironment, check for @command{erl}.  Set output variable @code{ERL} to thecomplete path of the interpreter command found.The two optional arguments have the same meaning as the two last arguments ofmacro @code{AC_PATH_PROG} for looking for the @command{erl} program.  Forexample, to look for @command{erl} only in the @file{/usr/lib/erlang/bin}directory:@exampleAC_ERLANG_PATH_ERL([not found], [/usr/lib/erlang/bin])@end example@end defmac@defmac AC_ERLANG_NEED_ERL (@dvar{path, $PATH})@acindex{ERLANG_NEED_ERL}A simplified variant of the @code{AC_ERLANG_PATH_ERL} macro, that prints anerror message and exits the @command{configure} script if the @command{erl}program is not found.@end defmac@node Fortran Compiler@subsection Fortran Compiler Characteristics@cindex Fortran@cindex F77The Autoconf Fortran support is divided into two categories: legacyFortran 77 macros (@code{F77}), and modern Fortran macros (@code{FC}).The former are intended for traditional Fortran 77 code, and have outputvariables like @code{F77}, @code{FFLAGS}, and @code{FLIBS}.  The latterare for newer programs that can (or must) compile under the newerFortran standards, and have output variables like @code{FC},@code{FCFLAGS}, and @code{FCLIBS}.Except for the macros @code{AC_FC_SRCEXT}, @code{AC_FC_FREEFORM},@code{AC_FC_FIXEDFORM}, and @code{AC_FC_LINE_LENGTH} (see below), the@code{FC} and @code{F77} macros behave almost identically, and so theyare documented together in this section.@defmac AC_PROG_F77 (@ovar{compiler-search-list})@acindex{PROG_F77}@evindex F77@evindex FFLAGS@ovindex F77@ovindex FFLAGS@caindex f77_compiler_gnu@caindex prog_f77_gDetermine a Fortran 77 compiler to use.  If @code{F77} is not alreadyset in the environment, then check for @code{g77} and @code{f77}, andthen some other names.  Set the output variable @code{F77} to the nameof the compiler found.This macro may, however, be invoked with an optional first argumentwhich, if specified, must be a blank-separated list of Fortran 77compilers to search for.  This just gives the user an opportunity tospecify an alternative search list for the Fortran 77 compiler.  Forexample, if you didn't like the default order, then you could invoke@code{AC_PROG_F77} like this:@exampleAC_PROG_F77([fl32 f77 fort77 xlf g77 f90 xlf90])@end exampleIf using @code{g77} (the GNU Fortran 77 compiler), thenset the shell variable @code{G77} to @samp{yes}.If the output variable @code{FFLAGS} was not already set in theenvironment, then set it to @option{-g -02} for @code{g77} (or @option{-O2}where @code{g77} does not accept @option{-g}).  Otherwise, set@code{FFLAGS} to @option{-g} for all other Fortran 77 compilers.The result of the GNU test is cached in the@code{ac_cv_f77_compiler_gnu} variable, acceptance of @option{-g} in the@code{ac_cv_prog_f77_g} variable.@end defmac@defmac AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect})@acindex{PROG_FC}@evindex FC@evindex FCFLAGS@ovindex FC@ovindex FCFLAGS@caindex fc_compiler_gnu@caindex prog_fc_gDetermine a Fortran compiler to use.  If @code{FC} is not already set inthe environment, then @code{dialect} is a hint to indicate what Fortrandialect to search for; the default is to search for the newest availabledialect.  Set the output variable @code{FC} to the name of the compilerfound.By default, newer dialects are preferred over older dialects, but if@code{dialect} is specified then older dialects are preferred startingwith the specified dialect.  @code{dialect} can currently be one ofFortran 77, Fortran 90, or Fortran 95.  However, this is only a hint ofwhich compiler @emph{name} to prefer (e.g., @code{f90} or @code{f95}),and no attempt is made to guarantee that a particular language standardis actually supported.  Thus, it is preferable that you avoid the@code{dialect} option, and use AC_PROG_FC only for code compatible withthe latest Fortran standard.This macro may, alternatively, be invoked with an optional first argumentwhich, if specified, must be a blank-separated list of Fortrancompilers to search for, just as in @code{AC_PROG_F77}.If using @code{gfortran} or @code{g77} (the GNU Fortran compilers), thenset the shell variable @code{GFC} to @samp{yes}.If the output variable @code{FCFLAGS} was not already set in theenvironment, then set it to @option{-g -02} for GNU @code{g77} (or@option{-O2} where @code{g77} does not accept @option{-g}).  Otherwise,set @code{FCFLAGS} to @option{-g} for all other Fortran compilers.The result of the GNU test is cached in the @code{ac_cv_fc_compiler_gnu}variable, acceptance of @option{-g} in the @code{ac_cv_prog_fc_g}variable.@end defmac@defmac AC_PROG_F77_C_O@defmacx AC_PROG_FC_C_O@acindex{PROG_F77_C_O}@acindex{PROG_FC_C_O}@cvindex F77_NO_MINUS_C_MINUS_O@cvindex FC_NO_MINUS_C_MINUS_O@caindex prog_f77_c_o@caindex prog_fc_c_oTest whether the Fortran compiler accepts the options @option{-c} and@option{-o} simultaneously, and define @code{F77_NO_MINUS_C_MINUS_O} or@code{FC_NO_MINUS_C_MINUS_O}, respectively, if it does not.The result of the test is cached in the @code{ac_cv_prog_f77_c_o} or@code{ac_cv_prog_fc_c_o} variable, respectively.@end defmacThe following macros check for Fortran compiler characteristics.To check for characteristics not listed here, use@code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or@code{AC_RUN_IFELSE} (@pxref{Runtime}), making sure to first set thecurrent language to Fortran 77 or Fortran via @code{AC_LANG([Fortran 77])}or @code{AC_LANG(Fortran)} (@pxref{Language Choice}).@defmac AC_F77_LIBRARY_LDFLAGS@defmacx AC_FC_LIBRARY_LDFLAGS@acindex{F77_LIBRARY_LDFLAGS}@ovindex FLIBS@acindex{FC_LIBRARY_LDFLAGS}@ovindex FCLIBS@caindex prog_f77_v@caindex prog_fc_v@caindex f77_libs@caindex fc_libsDetermine the linker flags (e.g., @option{-L} and @option{-l}) for the@dfn{Fortran intrinsic and runtime libraries} that are required tosuccessfully link a Fortran program or shared library.  The outputvariable @code{FLIBS} or @code{FCLIBS} is set to these flags (whichshould be included after @code{LIBS} when linking).This macro is intended to be used in those situations when it isnecessary to mix, e.g., C++ and Fortran source code in a singleprogram or shared library (@pxref{Mixing Fortran 77 With C and C++, , ,automake, GNU Automake}).For example, if object files from a C++ and Fortran compiler must belinked together, then the C++ compiler/linker must be used for linking(since special C++-ish things need to happen at link time like callingglobal constructors, instantiating templates, enabling exceptionsupport, etc.).However, the Fortran intrinsic and runtime libraries must be linked inas well, but the C++ compiler/linker doesn't know by default how to addthese Fortran 77 libraries.  Hence, this macro was created to determinethese Fortran libraries.The macros @code{AC_F77_DUMMY_MAIN} and @code{AC_FC_DUMMY_MAIN} or@code{AC_F77_MAIN} and @code{AC_FC_MAIN} are probably also necessary tolink C/C++ with Fortran; see below.  Further, it is highly recommendedthat you use @code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers})because the complex defines that the function wrapper macros createmay not work with C/C++ compiler drivers.These macros internally compute the flag needed to verbose linkingoutput and cache it in @code{ac_cv_prog_f77_v} or @code{ac_cv_prog_fc_v}variables, respectively.  The computed linker flags are cached in@code{ac_cv_f77_libs} or @code{ac_cv_fc_libs}, respectively.@end defmac@defmac AC_F77_DUMMY_MAIN (@ovar{action-if-found}, @dvar{action-if-not-found, @  AC_MSG_FAILURE})@defmacx AC_FC_DUMMY_MAIN (@ovar{action-if-found}, @dvar{action-if-not-found, @  AC_MSG_FAILURE})@acindex{F77_DUMMY_MAIN}@cvindex F77_DUMMY_MAIN@acindex{FC_DUMMY_MAIN}@cvindex FC_DUMMY_MAIN@caindex f77_dummy_main@caindex fc_dummy_mainWith many compilers, the Fortran libraries detected by@code{AC_F77_LIBRARY_LDFLAGS} or @code{AC_FC_LIBRARY_LDFLAGS} providetheir own @code{main} entry function that initializes things likeFortran I/O, and which then calls a user-provided entry function named(say) @code{MAIN__} to run the user's program.  The@code{AC_F77_DUMMY_MAIN} and @code{AC_FC_DUMMY_MAIN} or@code{AC_F77_MAIN} and @code{AC_FC_MAIN} macros figure out how to deal withthis interaction.When using Fortran for purely numerical functions (no I/O, etc.)@: oftenone prefers to provide one's own @code{main} and skip the Fortranlibrary initializations.  In this case, however, one may still need toprovide a dummy @code{MAIN__} routine in order to prevent linking errorson some systems.  @code{AC_F77_DUMMY_MAIN} or @code{AC_FC_DUMMY_MAIN}detects whether any such routine is @emph{required} for linking, andwhat its name is; the shell variable @code{F77_DUMMY_MAIN} or@code{FC_DUMMY_MAIN} holds this name, @code{unknown} when no solutionwas found, and @code{none} when no such dummy main is needed.By default, @var{action-if-found} defines @code{F77_DUMMY_MAIN} or@code{FC_DUMMY_MAIN} to the name of this routine (e.g., @code{MAIN__})@emph{if} it is required.  @var{action-if-not-found} defaults toexiting with an error.In order to link with Fortran routines, the user's C/C++ program shouldthen include the following code to define the dummy main if it isneeded:@example@c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.#ifdef F77_DUMMY_MAIN#  ifdef __cplusplus     extern "C"#  endif   int F77_DUMMY_MAIN () @{ return 1; @}#endif@end example(Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)Note that this macro is called automatically from @code{AC_F77_WRAPPERS}or @code{AC_FC_WRAPPERS}; there is generally no need to call itexplicitly unless one wants to change the default actions.The result of this macro is cached in the @code{ac_cv_f77_dummy_main} or@code{ac_cv_fc_dummy_main} variable, respectively.@end defmac@defmac AC_F77_MAIN@defmacx AC_FC_MAIN@acindex{F77_MAIN}@cvindex F77_MAIN@acindex{FC_MAIN}@cvindex FC_MAIN@caindex f77_main@caindex fc_mainAs discussed above, many Fortran libraries allow you to provide an entrypoint called (say) @code{MAIN__} instead of the usual @code{main}, whichis then called by a @code{main} function in the Fortran libraries thatinitializes things like Fortran I/O@.  The@code{AC_F77_MAIN} and @code{AC_FC_MAIN} macros detect whether it is@emph{possible} to utilize such an alternate main function, and defines@code{F77_MAIN} and @code{FC_MAIN} to the name of the function.  (If noalternate main function name is found, @code{F77_MAIN} and @code{FC_MAIN} aresimply defined to @code{main}.)Thus, when calling Fortran routines from C that perform things like I/O,one should use this macro and declare the "main" function like so:@example@c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.#ifdef __cplusplus  extern "C"#endifint F77_MAIN (int argc, char *argv[]);@end example(Again, replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)The result of this macro is cached in the @code{ac_cv_f77_main} or@code{ac_cv_fc_main} variable, respectively.@end defmac@defmac AC_F77_WRAPPERS@defmacx AC_FC_WRAPPERS@acindex{F77_WRAPPERS}@cvindex F77_FUNC@cvindex F77_FUNC_@acindex{FC_WRAPPERS}@cvindex FC_FUNC@cvindex FC_FUNC_@caindex f77_mangling@caindex fc_manglingDefines C macros @code{F77_FUNC (name, NAME)}, @code{FC_FUNC (name, NAME)},@code{F77_FUNC_(name, NAME)}, and @code{FC_FUNC_(name, NAME)} to properlymangle the names of C/C++ identifiers, and identifiers with underscores,respectively, so that they match the name-mangling scheme used by theFortran compiler.Fortran is case-insensitive, and in order to achieve this the Fortrancompiler converts all identifiers into a canonical case and format.  Tocall a Fortran subroutine from C or to write a C function that iscallable from Fortran, the C program must explicitly use identifiers inthe format expected by the Fortran compiler.  In order to do this, onesimply wraps all C identifiers in one of the macros provided by@code{AC_F77_WRAPPERS} or @code{AC_FC_WRAPPERS}.  For example, supposeyou have the following Fortran 77 subroutine:@example@c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.      subroutine foobar (x, y)      double precision x, y      y = 3.14159 * x      return      end@end exampleYou would then declare its prototype in C or C++ as:@example@c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.#define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)#ifdef __cplusplusextern "C"  /* prevent C++ name mangling */#endifvoid FOOBAR_F77 (double *x, double *y);@end exampleNote that we pass both the lowercase and uppercase versions of thefunction name to @code{F77_FUNC} so that it can select the right one.Note also that all parameters to Fortran 77 routines are passed aspointers (@pxref{Mixing Fortran 77 With C and C++, , , automake, GNUAutomake}).(Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)Although Autoconf tries to be intelligent about detecting thename-mangling scheme of the Fortran compiler, there may be Fortrancompilers that it doesn't support yet.  In this case, the above codegenerates a compile-time error, but some other behavior(e.g., disabling Fortran-related features) can be induced by checkingwhether @code{F77_FUNC} or @code{FC_FUNC} is defined.Now, to call that routine from a C program, we would do something like:@example@c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.@{    double x = 2.7183, y;    FOOBAR_F77 (&x, &y);@}@end exampleIf the Fortran identifier contains an underscore (e.g., @code{foo_bar}),you should use @code{F77_FUNC_} or @code{FC_FUNC_} instead of@code{F77_FUNC} or @code{FC_FUNC} (with the same arguments).  This isbecause some Fortran compilers mangle names differently if they containan underscore.The name mangling scheme is encoded in the @code{ac_cv_f77_mangling} or@code{ac_cv_fc_mangling} cache variable, respectively, and also used forthe @code{AC_F77_FUNC} and @code{AC_FC_FUNC} macros described below.@end defmac@defmac AC_F77_FUNC (@var{name}, @ovar{shellvar})@defmacx AC_FC_FUNC (@var{name}, @ovar{shellvar})@acindex{F77_FUNC}@acindex{FC_FUNC}Given an identifier @var{name}, set the shell variable @var{shellvar} tohold the mangled version @var{name} according to the rules of theFortran linker (see also @code{AC_F77_WRAPPERS} or@code{AC_FC_WRAPPERS}).  @var{shellvar} is optional; if it is notsupplied, the shell variable is simply @var{name}.  The purpose ofthis macro is to give the caller a way to access the name-manglinginformation other than through the C preprocessor as above, for example,to call Fortran routines from some language other than C/C++.@end defmac@defmac AC_FC_SRCEXT (@var{ext}, @ovar{action-if-success}, @  @dvar{action-if-failure, AC_MSG_FAILURE})@defmacx AC_FC_PP_SRCEXT (@var{ext}, @ovar{action-if-success}, @  @dvar{action-if-failure, AC_MSG_FAILURE})@acindex{FC_SRCEXT}@acindex{FC_PP_SRCEXT}@caindex fc_srcext_@var{ext}@caindex fc_pp_srcext_@var{ext}By default, the @code{FC} macros perform their tests using a @file{.f}extension for source-code files.  Some compilers, however, only enablenewer language features for appropriately named files, e.g., Fortran 90features only for @file{.f90} files, or preprocessing only with@file{.F} files or maybe other upper-case extensions.  On the otherhand, some other compilers expect all source files to end in @file{.f}and require special flags to support other file name extensions.  The@code{AC_FC_SRCEXT} and @code{AC_FC_PP_SRCEXT} macros deal with theseissues.The @code{AC_FC_SRCEXT} macro tries to get the @code{FC} compiler toaccept files ending with the extension @file{.@var{ext}} (i.e.,@var{ext} does @emph{not} contain the dot).  If any special compilerflags are needed for this, it stores them in the output variable@code{FCFLAGS_@var{ext}}.  This extension and these flags are then usedfor all subsequent @code{FC} tests (until @code{AC_FC_SRCEXT} or@code{AC_FC_PP_SRCEXT} is called another time).For example, you would use @code{AC_FC_SRCEXT(f90)} to employ the@file{.f90} extension in future tests, and it would set the@code{FCFLAGS_f90} output variable with any extra flags that are neededto compile such files.Similarly, the @code{AC_FC_PP_SRCEXT} macro tries to get the @code{FC}compiler to preprocess and compile files with the extension@file{.@var{ext}}.  When both @command{fpp} and @command{cpp} stylepreprocessing are provided, the former is preferred, as the latter maytreat continuation lines, @code{//} tokens, and white space differentlyfrom what some Fortran dialects expect.  Conversely, if you do not wantfiles to be preprocessed, use only lower-case characters in the filename extension.  Like with @code{AC_FC_SRCEXT(f90)}, any needed flagsare stored in the @code{FCFLAGS_@var{ext}} variable.The @code{FCFLAGS_@var{ext}} flags can @emph{not} be simply absorbedinto @code{FCFLAGS}, for two reasons based on the limitations of somecompilers.  First, only one @code{FCFLAGS_@var{ext}} can be used at atime, so files with different extensions must be compiled separately.Second, @code{FCFLAGS_@var{ext}} must appear @emph{immediately} beforethe source-code file name when compiling.  So, continuing the exampleabove, you might compile a @file{foo.f90} file in your makefile with thecommand:@examplefoo.o: foo.f90       $(FC) -c $(FCFLAGS) $(FCFLAGS_f90) '$(srcdir)/foo.f90'@end exampleIf @code{AC_FC_SRCEXT} or @code{AC_FC_PP_SRCEXT} succeeds in compilingfiles with the @var{ext} extension, it calls @var{action-if-success}(defaults to nothing).  If it fails, and cannot find a way to make the@code{FC} compiler accept such files, it calls @var{action-if-failure}(defaults to exiting with an error message).The @code{AC_FC_SRCEXT} and @code{AC_FC_PP_SRCEXT} macros cache theirresults in @code{ac_cv_fc_srcext_@var{ext}} and@code{ac_cv_fc_pp_srcext_@var{ext}} variables, respectively.@end defmac@defmac AC_FC_PP_DEFINE (@ovar{action-if-success}, @dvar{action-if-failure, @  AC_MSG_FAILURE})@acindex{FC_PP_DEFINE}@caindex fc_pp_defineFind a flag to specify defines for preprocessed Fortran.  Not allFortran compilers use @option{-D}.  Substitute @code{FC_DEFINE} withthe result and call @var{action-if-success} (defaults to nothing) ifsuccessful, and @var{action-if-failure} (defaults to failing with anerror message) if not.This macro calls @code{AC_FC_PP_SRCEXT([F])} in order to learn how topreprocess a @file{conftest.F} file, but restores a previously usedFortran source file extension afterwards again.The result of this test is cached in the @code{ac_cv_fc_pp_define}variable.@end defmac@defmac AC_FC_FREEFORM (@ovar{action-if-success}, @dvar{action-if-failure, @  AC_MSG_FAILURE})@acindex{FC_FREEFORM}@caindex fc_freeformTry to ensure that the Fortran compiler (@code{$FC}) allows free-formatsource code (as opposed to the older fixed-format style from Fortran77).  If necessary, it may add some additional flags to @code{FCFLAGS}.This macro is most important if you are using the default @file{.f}extension, since many compilers interpret this extension as indicatingfixed-format source unless an additional flag is supplied.  If youspecify a different extension with @code{AC_FC_SRCEXT}, such as@file{.f90}, then @code{AC_FC_FREEFORM} ordinarily succeeds withoutmodifying @code{FCFLAGS}.  For extensions which the compiler does notknow about, the flag set by the @code{AC_FC_SRCEXT} macro might letthe compiler assume Fortran 77 by default, however.If @code{AC_FC_FREEFORM} succeeds in compiling free-form source, itcalls @var{action-if-success} (defaults to nothing).  If it fails, itcalls @var{action-if-failure} (defaults to exiting with an errormessage).The result of this test, or @samp{none} or @samp{unknown}, is cached inthe @code{ac_cv_fc_freeform} variable.@end defmac@defmac AC_FC_FIXEDFORM (@ovar{action-if-success}, @dvar{action-if-failure, @  AC_MSG_FAILURE})@acindex{FC_FIXEDFORM}@caindex fc_fixedformTry to ensure that the Fortran compiler (@code{$FC}) allows the oldfixed-format source code (as opposed to free-format style).  Ifnecessary, it may add some additional flags to @code{FCFLAGS}.This macro is needed for some compilers alias names like @command{xlf95}which assume free-form source code by default, and in case you want touse fixed-form source with an extension like @file{.f90} which manycompilers interpret as free-form by default.  If you specify a differentextension with @code{AC_FC_SRCEXT}, such as @file{.f}, then@code{AC_FC_FIXEDFORM} ordinarily succeeds without modifying@code{FCFLAGS}.If @code{AC_FC_FIXEDFORM} succeeds in compiling fixed-form source, itcalls @var{action-if-success} (defaults to nothing).  If it fails, itcalls @var{action-if-failure} (defaults to exiting with an errormessage).The result of this test, or @samp{none} or @samp{unknown}, is cached inthe @code{ac_cv_fc_fixedform} variable.@end defmac@defmac AC_FC_LINE_LENGTH (@ovar{length}, @ovar{action-if-success}, @  @dvar{action-if-failure, AC_MSG_FAILURE})@acindex{FC_LINE_LENGTH}@caindex fc_line_lengthTry to ensure that the Fortran compiler (@code{$FC}) accepts long sourcecode lines.  The @var{length} argument may be given as 80, 132, orunlimited, and defaults to 132.  Note that line lengths above 254columns are not portable, and some compilers do not accept more than 132columns at least for fixed format source.  If necessary, it may add someadditional flags to @code{FCFLAGS}.If @code{AC_FC_LINE_LENGTH} succeeds in compiling fixed-form source, itcalls @var{action-if-success} (defaults to nothing).  If it fails, itcalls @var{action-if-failure} (defaults to exiting with an errormessage).The result of this test, or @samp{none} or @samp{unknown}, is cached inthe @code{ac_cv_fc_line_length} variable.@end defmac@defmac AC_FC_CHECK_BOUNDS (@ovar{action-if-success}, @  @dvar{action-if-failure, AC_MSG_FAILURE})@acindex{FC_CHECK_BOUNDS}@caindex fc_check_boundsThe @code{AC_FC_CHECK_BOUNDS} macro tries to enable array bounds checkingin the Fortran compiler.  If successful, the @var{action-if-success}is called and any needed flags are added to @code{FCFLAGS}.  Otherwise,@var{action-if-failure} is called, which defaults to failing with an errormessage.  The macro currently requires Fortran 90 or a newer dialect.The result of the macro is cached in the @code{ac_cv_fc_check_bounds}variable.@end defmac@defmac AC_F77_IMPLICIT_NONE (@ovar{action-if-success}, @  @dvar{action-if-failure, AC_MSG_FAILURE})@defmacx AC_FC_IMPLICIT_NONE (@ovar{action-if-success}, @  @dvar{action-if-failure, AC_MSG_FAILURE})@acindex{F77_IMPLICIT_NONE}@acindex{FC_IMPLICIT_NONE}@caindex f77_implicit_none@caindex fc_implicit_noneTry to disallow implicit declarations in the Fortran compiler.  Ifsuccessful, @var{action-if-success} is called and any needed flagsare added to @code{FFLAGS} or @code{FCFLAGS}, respectively.  Otherwise,@var{action-if-failure} is called, which defaults to failing with an errormessage.The result of these macros are cached in the@code{ac_cv_f77_implicit_none} and @code{ac_cv_fc_implicit_none}variables, respectively.@end defmac@defmac AC_FC_MODULE_EXTENSION@acindex{FC_MODULE_EXTENSION}@caindex fc_module_ext@ovindex FC_MODEXTFind the Fortran 90 module file name extension.  Most Fortran 90compilers store module information in files separate from the objectfiles.  The module files are usually named after the name of the modulerather than the source file name, with characters possibly turned toupper case, plus an extension, often @file{.mod}.Not all compilers use module files at all, or by default.  The CrayFortran compiler requires @option{-e m} in order to store and searchmodule information in @file{.mod} files rather than in object files.Likewise, the Fujitsu Fortran compilers uses the @option{-Am} option toindicate how module information is stored.The @code{AC_FC_MODULE_EXTENSION} macro computes the module extensionwithout the leading dot, and stores that in the @code{FC_MODEXT}variable.  If the compiler does not produce module files, or theextension cannot be determined, @code{FC_MODEXT} is empty.  Typically,the result of this macro may be used in cleanup @command{make} rules asfollows:@exampleclean-modules:        -test -z "$(FC_MODEXT)" || rm -f *.$(FC_MODEXT)@end exampleThe extension, or @samp{unknown}, is cached in the@code{ac_cv_fc_module_ext} variable.@end defmac@defmac AC_FC_MODULE_FLAG (@ovar{action-if-success}, @  @dvar{action-if-failure, AC_MSG_FAILURE})@acindex{FC_MODULE_FLAG}@caindex fc_module_flag@ovindex FC_MODINC@ovindex ac_emptyFind the compiler flag to include Fortran 90 module information fromanother directory, and store that in the @code{FC_MODINC} variable.Call @var{action-if-success} (defaults to nothing) if successful, andset @code{FC_MODINC} to empty and call @var{action-if-failure} (defaultsto exiting with an error message) if not.Most Fortran 90 compilers provide a way to specify module directories.Some have separate flags for the directory to write module files to,and directories to search them in, whereas others only allow writing tothe current directory or to the first directory specified in the includepath.  Further, with some compilers, the module search path and thepreprocessor search path can only be modified with the same flag.  Thus,for portability, write module files to the current directory only andlist that as first directory in the search path.There may be no whitespace between @code{FC_MODINC} and the followingdirectory name, but @code{FC_MODINC} may contain trailing white space.For example, if you use Automake and would like to search @file{../lib}for module files, you can use the following:@exampleAM_FCFLAGS = $(FC_MODINC). $(FC_MODINC)../lib@end exampleInside @command{configure} tests, you can use:@exampleif test -n "$FC_MODINC"; then  FCFLAGS="$FCFLAGS $FC_MODINC. $FC_MODINC../lib"fi@end exampleThe flag is cached in the @code{ac_cv_fc_module_flag} variable.The substituted value of @code{FC_MODINC} may refer to the@code{ac_empty} dummy placeholder empty variable, to avoid losingthe significant trailing whitespace in a @file{Makefile}.@end defmac@defmac AC_FC_MODULE_OUTPUT_FLAG (@ovar{action-if-success}, @  @dvar{action-if-failure, AC_MSG_FAILURE})@acindex{FC_MODULE_OUTPUT_FLAG}@caindex fc_module_output_flag@ovindex FC_MODOUTFind the compiler flag to write Fortran 90 module information toanother directory, and store that in the @code{FC_MODOUT} variable.Call @var{action-if-success} (defaults to nothing) if successful, andset @code{FC_MODOUT} to empty and call @var{action-if-failure} (defaultsto exiting with an error message) if not.Not all Fortran 90 compilers write module files, and of those that do,not all allow writing to a directory other than the current one, nordo all have separate flags for writing and reading; see the descriptionof @code{AC_FC_MODULE_FLAG} above.  If you need to be able to write toanother directory, for maximum portability use @code{FC_MODOUT} beforeany @code{FC_MODINC} and include both the current directory and the oneyou write to in the search path:@exampleAM_FCFLAGS = $(FC_MODOUT)../mod $(FC_MODINC)../mod $(FC_MODINC). @dots{}@end exampleThe flag is cached in the @code{ac_cv_fc_module_output_flag} variable.The substituted value of @code{FC_MODOUT} may refer to the@code{ac_empty} dummy placeholder empty variable, to avoid losingthe significant trailing whitespace in a @file{Makefile}.@end defmac@node Go Compiler@subsection Go Compiler Characteristics@cindex GoAutoconf provides basic support for the Go programming language whenusing the @code{gccgo} compiler (there is currently no support for the@code{6g} and @code{8g} compilers).@defmac AC_PROG_GO (@ovar{compiler-search-list})Find the Go compiler to use.  Check whether the environment variable@code{GOC} is set; if so, then set output variable @code{GOC} to itsvalue.Otherwise, if the macro is invoked without an argument, then search fora Go compiler named @code{gccgo}.  If it is not found, then as a lastresort set @code{GOC} to @code{gccgo}.This macro may be invoked with an optional first argument which, ifspecified, must be a blank-separated list of Go compilers to search for.If output variable @code{GOFLAGS} was not already set, set it to@option{-g -O2}.  If your package does not like this default,@code{GOFLAGS} may be set before @code{AC_PROG_GO}.@end defmac@node System Services@section System ServicesThe following macros check for operating system services or capabilities.@anchor{AC_PATH_X}@defmac AC_PATH_X@acindex{PATH_X}@evindex XMKMF@cindex X Window SystemTry to locate the X Window System include files and libraries.  If theuser gave the command line options @option{--x-includes=@var{dir}} and@option{--x-libraries=@var{dir}}, use those directories.If either or both were not given, get the missing values by running@code{xmkmf} (or an executable pointed to by the @code{XMKMF}environment variable) on a trivial @file{Imakefile} and examining themakefile that it produces.  Setting @code{XMKMF} to @samp{false}disables this method.If this method fails to find the X Window System, @command{configure}looks for the files in several directories where they often reside.If either method is successful, set the shell variables@code{x_includes} and @code{x_libraries} to their locations, unless theyare in directories the compiler searches by default.If both methods fail, or the user gave the command line option@option{--without-x}, set the shell variable @code{no_x} to @samp{yes};otherwise set it to the empty string.@end defmac@anchor{AC_PATH_XTRA}@defmac AC_PATH_XTRA@acindex{PATH_XTRA}@ovindex X_CFLAGS@ovindex X_LIBS@ovindex X_EXTRA_LIBS@ovindex X_PRE_LIBS@cvindex X_DISPLAY_MISSINGAn enhanced version of @code{AC_PATH_X}.  It adds the C compiler flagsthat X needs to output variable @code{X_CFLAGS}, and the X linker flagsto @code{X_LIBS}.  Define @code{X_DISPLAY_MISSING} if X is notavailable.This macro also checks for special libraries that some systems need inorder to compile X programs.  It adds any that the system needs tooutput variable @code{X_EXTRA_LIBS}.  And it checks for special X11R6libraries that need to be linked with before @option{-lX11}, and addsany found to the output variable @code{X_PRE_LIBS}.@c This is an incomplete kludge.  Make a real way to do it.@c If you need to check for other X functions or libraries yourself, then@c after calling this macro, add the contents of @code{X_EXTRA_LIBS} to@c @code{LIBS} temporarily, like this: (FIXME - add example)@end defmac@anchor{AC_SYS_INTERPRETER}@defmac AC_SYS_INTERPRETER@acindex{SYS_INTERPRETER}Check whether the system supports starting scripts with a line of theform @samp{#!/bin/sh} to select the interpreter to use for the script.After running this macro, shell code in @file{configure.ac} can checkthe shell variable @code{interpval}; it is set to @samp{yes}if the system supports @samp{#!}, @samp{no} if not.@end defmac@defmac AC_SYS_LARGEFILE@acindex{SYS_LARGEFILE}@cvindex _FILE_OFFSET_BITS@cvindex _LARGE_FILES@ovindex CC@cindex Large file support@cindex LFSArrange for 64-bit file offsets, known as@uref{http://@/www.unix-systems@/.org/@/version2/@/whatsnew/@/lfs20mar.html,large-file support}.  On some hosts, one must use special compileroptions to build programs that can access large files.  Append any suchoptions to the output variable @code{CC}.  Define@code{_FILE_OFFSET_BITS} and @code{_LARGE_FILES} if necessary.Large-file support can be disabled by configuring with the@option{--disable-largefile} option.If you use this macro, check that your program works even when@code{off_t} is wider than @code{long int}, since this is common whenlarge-file support is enabled.  For example, it is not correct to printan arbitrary @code{off_t} value @code{X} with @code{printf ("%ld",(long int) X)}.The LFS introduced the @code{fseeko} and @code{ftello} functions toreplace their C counterparts @code{fseek} and @code{ftell} that do notuse @code{off_t}.  Take care to use @code{AC_FUNC_FSEEKO} to make theirprototypes available when using them and large-file support isenabled.@end defmac@anchor{AC_SYS_LONG_FILE_NAMES}@defmac AC_SYS_LONG_FILE_NAMES@acindex{SYS_LONG_FILE_NAMES}@cvindex HAVE_LONG_FILE_NAMESIf the system supports file names longer than 14 characters, define@code{HAVE_LONG_FILE_NAMES}.@end defmac@defmac AC_SYS_POSIX_TERMIOS@acindex{SYS_POSIX_TERMIOS}@cindex Posix termios headers@cindex termios Posix headers@caindex sys_posix_termiosCheck to see if the Posix termios headers and functions are available on thesystem.  If so, set the shell variable @code{ac_cv_sys_posix_termios} to@samp{yes}.  If not, set the variable to @samp{no}.@end defmac@node Posix Variants@section Posix VariantsThe following macro makes it possible to use features of Posix that areextensions to C, as well as platform extensions not defined by Posix.@anchor{AC_USE_SYSTEM_EXTENSIONS}@defmac AC_USE_SYSTEM_EXTENSIONS@acindex{USE_SYSTEM_EXTENSIONS}@cvindex _ALL_SOURCE@cvindex _GNU_SOURCE@cvindex _MINIX@cvindex _POSIX_1_SOURCE@cvindex _POSIX_PTHREAD_SEMANTICS@cvindex _POSIX_SOURCE@cvindex _TANDEM_SOURCE@cvindex __EXTENSIONS__This macro was introduced in Autoconf 2.60.  If possible, enableextensions to C or Posix on hosts that normally disable the extensions,typically due to standards-conformance namespace issues.  This should becalled before any macros that run the C compiler.  The followingpreprocessor macros are defined where appropriate:@table @code@item _GNU_SOURCEEnable extensions on GNU/Linux.@item __EXTENSIONS__Enable general extensions on Solaris.@item _POSIX_PTHREAD_SEMANTICSEnable threading extensions on Solaris.@item _TANDEM_SOURCEEnable extensions for the HP NonStop platform.@item _ALL_SOURCEEnable extensions for AIX 3, and for Interix.@item _POSIX_SOURCEEnable Posix functions for Minix.@item _POSIX_1_SOURCEEnable additional Posix functions for Minix.@item _MINIXIdentify Minix platform.  This particular preprocessor macro isobsolescent, and may be removed in a future release of Autoconf.@end table@end defmac@node Erlang Libraries@section Erlang Libraries@cindex Erlang, Library, checkingThe following macros check for an installation of Erlang/OTP, and for thepresence of certain Erlang libraries.  All those macros require theconfiguration of an Erlang interpreter and an Erlang compiler(@pxref{Erlang Compiler and Interpreter}).@defmac AC_ERLANG_SUBST_ERTS_VER@acindex{ERLANG_SUBST_ERTS_VER}@ovindex ERLANG_ERTS_VERSet the output variable @code{ERLANG_ERTS_VER} to the version of theErlang runtime system (as returned by Erlang's@code{erlang:system_info(version)} function).  The result of this testis cached if caching is enabled when running @command{configure}.  The@code{ERLANG_ERTS_VER} variable is not intended to be used for testingfor features of specific ERTS versions, but to be used for substitutingthe ERTS version in Erlang/OTP release resource files (@code{.rel}files), as shown below.@end defmac@defmac AC_ERLANG_SUBST_ROOT_DIR@acindex{ERLANG_SUBST_ROOT_DIR}@ovindex ERLANG_ROOT_DIRSet the output variable @code{ERLANG_ROOT_DIR} to the path to the basedirectory in which Erlang/OTP is installed (as returned by Erlang's@code{code:root_dir/0} function).  The result of this test is cached ifcaching is enabled when running @command{configure}.@end defmac@defmac AC_ERLANG_SUBST_LIB_DIR@acindex{ERLANG_SUBST_LIB_DIR}@ovindex ERLANG_LIB_DIRSet the output variable @code{ERLANG_LIB_DIR} to the path of the librarydirectory of Erlang/OTP (as returned by Erlang's@code{code:lib_dir/0} function), which subdirectories each contain an installedErlang/OTP library.  The result of this test is cached if caching is enabledwhen running @command{configure}.@end defmac@defmac AC_ERLANG_CHECK_LIB (@var{library}, @ovar{action-if-found}, @  @ovar{action-if-not-found})@acindex{ERLANG_CHECK_LIB}@ovindex ERLANG_LIB_DIR_@var{library}@ovindex ERLANG_LIB_VER_@var{library}Test whether the Erlang/OTP library @var{library} is installed bycalling Erlang's @code{code:lib_dir/1} function.  The result of thistest is cached if caching is enabled when running @command{configure}.@var{action-if-found} is a list of shell commands to run if the libraryis installed; @var{action-if-not-found} is a list of shell commands torun if it is not.  Additionally, if the library is installed, the outputvariable @samp{ERLANG_LIB_DIR_@var{library}} is set to the path to thelibrary installation directory, and the output variable@samp{ERLANG_LIB_VER_@var{library}} is set to the version number that ispart of the subdirectory name, if it is in the standard form(@code{@var{library}-@var{version}}).  If the directory name does nothave a version part, @samp{ERLANG_LIB_VER_@var{library}} is set to theempty string.  If the library is not installed,@samp{ERLANG_LIB_DIR_@var{library}} and@samp{ERLANG_LIB_VER_@var{library}} are set to @code{"not found"}.  Forexample, to check if library @code{stdlib} is installed:@exampleAC_ERLANG_CHECK_LIB([stdlib],  [echo "stdlib version \"$ERLANG_LIB_VER_stdlib\""   echo "is installed in \"$ERLANG_LIB_DIR_stdlib\""],  [AC_MSG_ERROR([stdlib was not found!])])@end exampleThe @samp{ERLANG_LIB_VER_@var{library}} variables (set by@code{AC_ERLANG_CHECK_LIB}) and the @code{ERLANG_ERTS_VER} variable (setby @code{AC_ERLANG_SUBST_ERTS_VER}) are not intended to be used fortesting for features of specific versions of libraries or of the Erlangruntime system.  Those variables are intended to be substituted inErlang release resource files (@code{.rel} files).  For instance, togenerate a @file{example.rel} file for an application depending on the@code{stdlib} library, @file{configure.ac} could contain:@exampleAC_ERLANG_SUBST_ERTS_VERAC_ERLANG_CHECK_LIB([stdlib],  [],  [AC_MSG_ERROR([stdlib was not found!])])AC_CONFIG_FILES([example.rel])@end example@noindentThe @file{example.rel.in} file used to generate @file{example.rel}should contain:@example@{release,    @{"@@PACKAGE@@", "@@VERSION@@"@},    @{erts, "@@ERLANG_ERTS_VER@@"@},    [@{stdlib, "@@ERLANG_LIB_VER_stdlib@@"@},     @{@@PACKAGE@@, "@@VERSION@@"@}]@}.@end example@end defmacIn addition to the above macros, which test installed Erlang libraries, thefollowing macros determine the paths to the directories into which newly builtErlang libraries are to be installed:@defmac AC_ERLANG_SUBST_INSTALL_LIB_DIR@acindex{ERLANG_SUBST_INSTALL_LIB_DIR}@ovindex ERLANG_INSTALL_LIB_DIRSet the @code{ERLANG_INSTALL_LIB_DIR} output variable to the directory intowhich every built Erlang library should be installed in a separatesubdirectory.If this variable is not set in the environment when @command{configure} runs,its default value is @code{$@{libdir@}/erlang/lib}.@end defmac@defmac AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR (@var{library}, @var{version})@acindex{ERLANG_SUBST_INSTALL_LIB_SUBDIR}@ovindex ERLANG_INSTALL_LIB_DIR_@var{library}Set the @samp{ERLANG_INSTALL_LIB_DIR_@var{library}} output variable to thedirectory into which the built Erlang library @var{library} version@var{version} should be installed.  If this variable is not set in theenvironment when @command{configure} runs, its default value is@samp{$ERLANG_INSTALL_LIB_DIR/@var{library}-@var{version}}, the value of the@code{ERLANG_INSTALL_LIB_DIR} variable being set by the@code{AC_ERLANG_SUBST_INSTALL_LIB_DIR} macro.@end defmac@c ========================================================= Writing Tests@node Writing Tests@chapter Writing TestsIf the existing feature tests don't do something you need, you have towrite new ones.  These macros are the building blocks.  They provideways for other macros to check whether various kinds of features areavailable and report the results.This chapter contains some suggestions and some of the reasons why theexisting tests are written the way they are.  You can also learn a lotabout how to write Autoconf tests by looking at the existing ones.  Ifsomething goes wrong in one or more of the Autoconf tests, thisinformation can help you understand the assumptions behind them, whichmight help you figure out how to best solve the problem.These macros check the output of the compiler system of the currentlanguage (@pxref{Language Choice}).  They do not cache the results oftheir tests for future use (@pxref{Caching Results}), because they don'tknow enough about the information they are checking for to generate acache variable name.  They also do not print any messages, for the samereason.  The checks for particular kinds of features call these macrosand do cache their results and print messages about what they'rechecking for.When you write a feature test that could be applicable to more than onesoftware package, the best thing to do is encapsulate it in a new macro.@xref{Writing Autoconf Macros}, for how to do that.@menu* Language Choice::             Selecting which language to use for testing* Writing Test Programs::       Forging source files for compilers* Running the Preprocessor::    Detecting preprocessor symbols* Running the Compiler::        Detecting language or header features* Running the Linker::          Detecting library features* Runtime::                     Testing for runtime features* Systemology::                 A zoology of operating systems* Multiple Cases::              Tests for several possible values@end menu@node Language Choice@section Language Choice@cindex LanguageAutoconf-generated @command{configure} scripts check for the C compiler andits features by default.  Packages that use other programming languages(maybe more than one, e.g., C and C++) need to test features of thecompilers for the respective languages.  The following macros determinewhich programming language is used in the subsequent tests in@file{configure.ac}.@anchor{AC_LANG}@defmac AC_LANG (@var{language})@acindex{LANG}Do compilation tests using the compiler, preprocessor, and fileextensions for the specified @var{language}.Supported languages are:@table @samp@item CDo compilation tests using @code{CC} and @code{CPP} and use extension@file{.c} for test programs.  Use compilation flags: @code{CPPFLAGS} with@code{CPP}, and both @code{CPPFLAGS} and @code{CFLAGS} with @code{CC}.@item C++Do compilation tests using @code{CXX} and @code{CXXCPP} and useextension @file{.C} for test programs.  Use compilation flags:@code{CPPFLAGS} with @code{CXXCPP}, and both @code{CPPFLAGS} and@code{CXXFLAGS} with @code{CXX}.@item Fortran 77Do compilation tests using @code{F77} and use extension @file{.f} fortest programs.  Use compilation flags: @code{FFLAGS}.@item FortranDo compilation tests using @code{FC} and use extension @file{.f} (orwhatever has been set by @code{AC_FC_SRCEXT}) for test programs.  Usecompilation flags: @code{FCFLAGS}.@item Erlang@ovindex ERLC@ovindex ERL@ovindex ERLCFLAGSCompile and execute tests using @code{ERLC} and @code{ERL} and use extension@file{.erl} for test Erlang modules.  Use compilation flags: @code{ERLCFLAGS}.@item Objective CDo compilation tests using @code{OBJC} and @code{OBJCPP} and useextension @file{.m} for test programs.  Use compilation flags:@code{CPPFLAGS} with @code{OBJCPP}, and both @code{CPPFLAGS} and@code{OBJCFLAGS} with @code{OBJC}.@item Objective C++Do compilation tests using @code{OBJCXX} and @code{OBJCXXCPP} and useextension @file{.mm} for test programs.  Use compilation flags:@code{CPPFLAGS} with @code{OBJCXXCPP}, and both @code{CPPFLAGS} and@code{OBJCXXFLAGS} with @code{OBJCXX}.@item GoDo compilation tests using @code{GOC} and use extension @file{.go} fortest programs.  Use compilation flags @code{GOFLAGS}.@end table@end defmac@anchor{AC_LANG_PUSH}@defmac AC_LANG_PUSH (@var{language})@acindex{LANG_PUSH}Remember the current language (as set by @code{AC_LANG}) on a stack, andthen select the @var{language}.  Use this macro and @code{AC_LANG_POP}in macros that need to temporarily switch to a particular language.@end defmac@defmac AC_LANG_POP (@ovar{language})@acindex{LANG_POP}Select the language that is saved on the top of the stack, as set by@code{AC_LANG_PUSH}, and remove it from the stack.If given, @var{language} specifies the language we just @emph{quit}.  Itis a good idea to specify it when it's known (which should be thecase@dots{}), since Autoconf detects inconsistencies.@exampleAC_LANG_PUSH([Fortran 77])# Perform some tests on Fortran 77.# @dots{}AC_LANG_POP([Fortran 77])@end example@end defmac@defmac AC_LANG_ASSERT (@var{language})@acindex{LANG_ASSERT}Check statically that the current language is @var{language}.You should use this in your language specific macrosto avoid that they be called with an inappropriate language.This macro runs only at @command{autoconf} time, and incurs no cost at@command{configure} time.  Sadly enough and because Autoconf is a twolayer language @footnote{Because M4 is not aware of Sh code,especially conditionals, some optimizations that look nice staticallymay produce incorrect results at runtime.}, the macros@code{AC_LANG_PUSH} and @code{AC_LANG_POP} cannot be ``optimizing'',therefore as much as possible you ought to avoid using them to wrapyour code, rather, require from the user to run the macro with acorrect current language, and check it with @code{AC_LANG_ASSERT}.And anyway, that may help the user understand she is running a Fortranmacro while expecting a result about her Fortran 77 compiler@enddots{}@end defmac@defmac AC_REQUIRE_CPP@acindex{REQUIRE_CPP}Ensure that whichever preprocessor would currently be used for tests hasbeen found.  Calls @code{AC_REQUIRE} (@pxref{Prerequisite Macros}) with anargument of either @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP},depending on which language is current.@end defmac@node Writing Test Programs@section Writing Test ProgramsAutoconf tests follow a common scheme: feed some program with someinput, and most of the time, feed a compiler with some source file.This section is dedicated to these source samples.@menu* Guidelines::                  General rules for writing test programs* Test Functions::              Avoiding pitfalls in test programs* Generating Sources::          Source program boilerplate@end menu@node Guidelines@subsection Guidelines for Test ProgramsThe most important rule to follow when writing testing samples is:@center @emph{Look for realism.}This motto means that testing samples must be written with the samestrictness as real programs are written.  In particular, you shouldavoid ``shortcuts'' and simplifications.Don't just play with the preprocessor if you want to prepare acompilation.  For instance, using @command{cpp} to check whether a header isfunctional might let your @command{configure} accept a header whichcauses some @emph{compiler} error.  Do not hesitate to check a header withother headers included before, especially required headers.Make sure the symbols you use are properly defined, i.e., refrain fromsimply declaring a function yourself instead of including the properheader.Test programs should not write to standard output.  Theyshould exit with status 0 if the test succeeds, and with status 1otherwise, so that successcan be distinguished easily from a core dump or other failure;segmentation violations and other failures produce a nonzero exitstatus.  Unless you arrange for @code{exit} to be declared, testprograms should @code{return}, not @code{exit}, from @code{main},because on many systems @code{exit} is not declared by default.Test programs can use @code{#if} or @code{#ifdef} to check the values ofpreprocessor macros defined by tests that have already run.  Forexample, if you call @code{AC_HEADER_STDBOOL}, then later on in@file{configure.ac} you can have a test program that includes@file{stdbool.h} conditionally:@example@group#ifdef HAVE_STDBOOL_H# include <stdbool.h>#endif@end group@end exampleBoth @code{#if HAVE_STDBOOL_H} and @code{#ifdef HAVE_STDBOOL_H} willwork with any standard C compiler.  Some developers prefer @code{#if}because it is easier to read, while others prefer @code{#ifdef} becauseit avoids diagnostics with picky compilers like GCC with the@option{-Wundef} option.If a test program needs to use or create a data file, give it a namethat starts with @file{conftest}, such as @file{conftest.data}.  The@command{configure} script cleans up by running @samp{rm -f -r conftest*}after running test programs and if the script is interrupted.@node Test Functions@subsection Test FunctionsThese days it's safe to assume support for function prototypes(introduced in C89).Functions that test programs declare should also be conditionalized forC++, which requires @samp{extern "C"} prototypes.  Make sure to notinclude any header files containing clashing prototypes.@example#ifdef __cplusplusextern "C"#endifvoid *valloc (size_t);@end exampleIf a test program calls a function with invalid parameters (just to seewhether it exists), organize the program to ensure that it never invokesthat function.  You can do this by calling it in another function that isnever invoked.  You can't do it by putting it after a call to@code{exit}, because GCC version 2 knows that @code{exit}never returnsand optimizes out any code that follows it in the same block.If you include any header files, be sure to call the functionsrelevant to them with the correct number of arguments, even if they arejust 0, to avoid compilation errors due to prototypes.  GCCversion 2has internal prototypes for several functions that it automaticallyinlines; for example, @code{memcpy}.  To avoid errors when checking forthem, either pass them the correct number of arguments or redeclare themwith a different return type (such as @code{char}).@node Generating Sources@subsection Generating SourcesAutoconf provides a set of macros that can be used to generate testsource files.  They are written to be language generic, i.e., theyactually depend on the current language (@pxref{Language Choice}) to``format'' the output properly.@defmac AC_LANG_CONFTEST (@var{source})@acindex{LANG_CONFTEST}Save the @var{source} text in the current test source file:@file{conftest.@var{extension}} where the @var{extension} depends on thecurrent language.  As of Autoconf 2.63b, the source file also containsthe results of all of the @code{AC_DEFINE} performed so far.Note that the @var{source} is evaluated exactly once, like regularAutoconf macro arguments, and therefore (i) you may pass a macroinvocation, (ii) if not, be sure to double quote if needed.This macro issues a warning during @command{autoconf} processing if@var{source} does not include an expansion of the macro@code{AC_LANG_DEFINES_PROVIDED} (note that both @code{AC_LANG_SOURCE} and@code{AC_LANG_PROGRAM} call this macro, and thus avoid the warning).This macro is seldom called directly, but is used under the hood by morecommon macros such as @code{AC_COMPILE_IFELSE} and @code{AC_RUN_IFELSE}.@end defmac@defmac AC_LANG_DEFINES_PROVIDED@acindex{LANG_DEFINES_PROVIDED}This macro is called as a witness that the file@file{conftest.@var{extension}} appropriate for the current language iscomplete, including all previously determined results from@code{AC_DEFINE}.  This macro is seldom called directly, but exists ifyou have a compelling reason to write a conftest file without using@code{AC_LANG_SOURCE}, yet still want to avoid a syntax warning from@code{AC_LANG_CONFTEST}.@end defmac@defmac AC_LANG_SOURCE (@var{source})@acindex{LANG_SOURCE}Expands into the @var{source}, with the definition ofall the @code{AC_DEFINE} performed so far.  This macro includes anexpansion of @code{AC_LANG_DEFINES_PROVIDED}.In many cases, you may find it more convenient to use the wrapper@code{AC_LANG_PROGRAM}.@end defmacFor instance, executing (observe the double quotation!):@example@c If you change this example, adjust tests/compile.at:AC_LANG_SOURCE example.AC_INIT([Hello], [1.0], [bug-hello@@example.org], [],        [http://www.example.org/])AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],  [Greetings string.])AC_LANG([C])AC_LANG_CONFTEST(   [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])gcc -E -dD conftest.c@end example@noindenton a system with @command{gcc} installed, results in:@example@c If you change this example, adjust tests/compile.at:AC_LANG_SOURCE example.@dots{}# 1 "conftest.c"#define PACKAGE_NAME "Hello"#define PACKAGE_TARNAME "hello"#define PACKAGE_VERSION "1.0"#define PACKAGE_STRING "Hello 1.0"#define PACKAGE_BUGREPORT "bug-hello@@example.org"#define PACKAGE_URL "http://www.example.org/"#define HELLO_WORLD "Hello, World\n"const char hw[] = "Hello, World\n";@end exampleWhen the test language is Fortran, Erlang, or Go, the @code{AC_DEFINE}definitions are not automatically translated into constants in thesource code by this macro.@defmac AC_LANG_PROGRAM (@var{prologue}, @var{body})@acindex{LANG_PROGRAM}Expands into a source file which consists of the @var{prologue}, andthen @var{body} as body of the main function (e.g., @code{main} inC).  Since it uses @code{AC_LANG_SOURCE}, the features of the latter areavailable.@end defmacFor instance:@example@c If you change this example, adjust tests/compile.at:AC_LANG_PROGRAM example.AC_INIT([Hello], [1.0], [bug-hello@@example.org], [],        [http://www.example.org/])AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],  [Greetings string.])AC_LANG_CONFTEST([AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],                 [[fputs (hw, stdout);]])])gcc -E -dD conftest.c@end example@noindenton a system with @command{gcc} installed, results in:@example@c If you change this example, adjust tests/compile.at:AC_LANG_PROGRAM example.@dots{}# 1 "conftest.c"#define PACKAGE_NAME "Hello"#define PACKAGE_TARNAME "hello"#define PACKAGE_VERSION "1.0"#define PACKAGE_STRING "Hello 1.0"#define PACKAGE_BUGREPORT "bug-hello@@example.org"#define PACKAGE_URL "http://www.example.org/"#define HELLO_WORLD "Hello, World\n"const char hw[] = "Hello, World\n";intmain ()@{fputs (hw, stdout);  ;  return 0;@}@end exampleIn Erlang tests, the created source file is that of an Erlang module called@code{conftest} (@file{conftest.erl}).  This module defines and exportsat leastone @code{start/0} function, which is called to perform the test.  The@var{prologue} is optional code that is inserted between the module header andthe @code{start/0} function definition.  @var{body} is the body of the@code{start/0} function without the final period (@pxref{Runtime}, aboutconstraints on this function's behavior).For instance:@exampleAC_INIT([Hello], [1.0], [bug-hello@@example.org])AC_LANG(Erlang)AC_LANG_CONFTEST([AC_LANG_PROGRAM([[-define(HELLO_WORLD, "Hello, world!").]],                 [[io:format("~s~n", [?HELLO_WORLD])]])])cat conftest.erl@end example@noindentresults in:@example-module(conftest).-export([start/0]).-define(HELLO_WORLD, "Hello, world!").start() ->io:format("~s~n", [?HELLO_WORLD]).@end example@defmac AC_LANG_CALL (@var{prologue}, @var{function})@acindex{LANG_CALL}Expands into a source file which consists of the @var{prologue}, andthen a call to the @var{function} as body of the main function (e.g.,@code{main} in C).  Since it uses @code{AC_LANG_PROGRAM}, the featureof the latter are available.This function will probably be replaced in the future by a versionwhich would enable specifying the arguments.  The use of this macro isnot encouraged, as it violates strongly the typing system.This macro cannot be used for Erlang tests.@end defmac@defmac AC_LANG_FUNC_LINK_TRY (@var{function})@acindex{LANG_FUNC_LINK_TRY}Expands into a source file which uses the @var{function} in the body ofthe main function (e.g., @code{main} in C).  Since it uses@code{AC_LANG_PROGRAM}, the features of the latter are available.As @code{AC_LANG_CALL}, this macro is documented only for completeness.It is considered to be severely broken, and in the future will beremoved in favor of actual function calls (with properly typedarguments).This macro cannot be used for Erlang tests.@end defmac@node Running the Preprocessor@section Running the PreprocessorSometimes one might need to run the preprocessor on some source file.@emph{Usually it is a bad idea}, as you typically need to @emph{compile}your project, not merely run the preprocessor on it; therefore youcertainly want to run the compiler, not the preprocessor.  Resist thetemptation of following the easiest path.Nevertheless, if you need to run the preprocessor, then use@code{AC_PREPROC_IFELSE}.The macros described in this section cannot be used for tests in Erlang,Fortran, or Go, since those languages require no preprocessor.@anchor{AC_PREPROC_IFELSE}@defmac AC_PREPROC_IFELSE (@var{input}, @ovar{action-if-true}, @  @ovar{action-if-false})@acindex{PREPROC_IFELSE}Run the preprocessor of the current language (@pxref{Language Choice})on the @var{input}, run the shell commands @var{action-if-true} onsuccess, @var{action-if-false} otherwise.  The @var{input} can be madeby @code{AC_LANG_PROGRAM} and friends.This macro uses @code{CPPFLAGS}, but not @code{CFLAGS}, because@option{-g}, @option{-O}, etc.@: are not valid options to many Cpreprocessors.It is customary to report unexpected failures with@code{AC_MSG_FAILURE}.  If needed, @var{action-if-true} can further accessthe preprocessed output in the file @file{conftest.i}.@end defmacFor instance:@exampleAC_INIT([Hello], [1.0], [bug-hello@@example.org])AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],  [Greetings string.])AC_PREPROC_IFELSE(   [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],                    [[fputs (hw, stdout);]])],   [AC_MSG_RESULT([OK])],   [AC_MSG_FAILURE([unexpected preprocessor failure])])@end example@noindentresults in:@examplechecking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables...checking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking how to run the C preprocessor... gcc -EOK@end example@sp 1The macro @code{AC_TRY_CPP} (@pxref{Obsolete Macros}) used to play therole of @code{AC_PREPROC_IFELSE}, but double quotes its argument, makingit impossible to use it to elaborate sources.  You are encouraged toget rid of your old use of the macro @code{AC_TRY_CPP} in favor of@code{AC_PREPROC_IFELSE}, but, in the first place, are you sure you needto run the @emph{preprocessor} and not the compiler?@anchor{AC_EGREP_HEADER}@defmac AC_EGREP_HEADER (@var{pattern}, @var{header-file}, @  @var{action-if-found}, @ovar{action-if-not-found})@acindex{EGREP_HEADER}If the output of running the preprocessor on the system header file@var{header-file} matches the extended regular expression@var{pattern}, execute shell commands @var{action-if-found}, otherwiseexecute @var{action-if-not-found}.@end defmac@anchor{AC_EGREP_CPP}@defmac AC_EGREP_CPP (@var{pattern}, @var{program}, @  @ovar{action-if-found}, @ovar{action-if-not-found})@acindex{EGREP_CPP}@var{program} is the text of a C or C++ program, on which shellvariable, back quote, and backslash substitutions are performed.  If theoutput of running the preprocessor on @var{program} matches theextended regular expression @var{pattern}, execute shell commands@var{action-if-found}, otherwise execute @var{action-if-not-found}.@end defmac@node Running the Compiler@section Running the CompilerTo check for a syntax feature of the current language's (@pxref{LanguageChoice}) compiler, such as whether it recognizes a certain keyword, orsimply to try some library feature, use @code{AC_COMPILE_IFELSE} to tryto compile a small program that uses that feature.@defmac AC_COMPILE_IFELSE (@var{input}, @ovar{action-if-true}, @  @ovar{action-if-false})@acindex{COMPILE_IFELSE}Run the compiler and compilation flags of the current language(@pxref{Language Choice}) on the @var{input}, run the shell commands@var{action-if-true} on success, @var{action-if-false} otherwise.  The@var{input} can be made by @code{AC_LANG_PROGRAM} and friends.It is customary to report unexpected failures with@code{AC_MSG_FAILURE}.  This macro does not try to link; use@code{AC_LINK_IFELSE} if you need to do that (@pxref{Running theLinker}).  If needed, @var{action-if-true} can further access thejust-compiled object file @file{conftest.$OBJEXT}.This macro uses @code{AC_REQUIRE} for the compiler associated with thecurrent language, which means that if the compiler has not yet beendetermined, the compiler determination will be made prior to the body ofthe outermost @code{AC_DEFUN} macro that triggered this macro toexpand (@pxref{Expanded Before Required}).@end defmac@ovindex ERLFor tests in Erlang, the @var{input} must be the source code of a module named@code{conftest}.  @code{AC_COMPILE_IFELSE} generates a @file{conftest.beam}file that can be interpreted by the Erlang virtual machine (@code{ERL}).  It isrecommended to use @code{AC_LANG_PROGRAM} to specify the test program,to ensure that the Erlang module has the right name.@node Running the Linker@section Running the LinkerTo check for a library, a function, or a global variable, Autoconf@command{configure} scripts try to compile and link a small program thatuses it.  This is unlike Metaconfig, which by default uses @code{nm} or@code{ar} on the C library to try to figure out which functions areavailable.  Trying to link with the function is usually a more reliableapproach because it avoids dealing with the variations in the optionsand output formats of @code{nm} and @code{ar} and in the location of thestandard libraries.  It also allows configuring for cross-compilation orchecking a function's runtime behavior if needed.  On the other hand,it can be slower than scanning the libraries once, but accuracy is moreimportant than speed.@code{AC_LINK_IFELSE} is used to compile test programs to test forfunctions and global variables.  It is also used by @code{AC_CHECK_LIB}to check for libraries (@pxref{Libraries}), by adding the library beingchecked for to @code{LIBS} temporarily and trying to link a smallprogram.@anchor{AC_LINK_IFELSE}@defmac AC_LINK_IFELSE (@var{input}, @ovar{action-if-true}, @  @ovar{action-if-false})@acindex{LINK_IFELSE}Run the compiler (and compilation flags) and the linker of the currentlanguage (@pxref{Language Choice}) on the @var{input}, run the shellcommands @var{action-if-true} on success, @var{action-if-false}otherwise.  The @var{input} can be made by @code{AC_LANG_PROGRAM} andfriends.  If needed, @var{action-if-true} can further access thejust-linked program file @file{conftest$EXEEXT}.@code{LDFLAGS} and @code{LIBS} are used for linking, in addition to thecurrent compilation flags.It is customary to report unexpected failures with@code{AC_MSG_FAILURE}.  This macro does not try to execute the program;use @code{AC_RUN_IFELSE} if you need to do that (@pxref{Runtime}).@end defmacThe @code{AC_LINK_IFELSE} macro cannot be used for Erlang tests, since Erlangprograms are interpreted and do not require linking.@node Runtime@section Checking Runtime BehaviorSometimes you need to find out how a system performs at runtime, suchas whether a given function has a certain capability or bug.  If youcan, make such checks when your program runs instead of when it isconfigured.  You can check for things like the machine's endianness whenyour program initializes itself.If you really need to test for a runtime behavior while configuring,you can write a test program to determine the result, and compile andrun it using @code{AC_RUN_IFELSE}.  Avoid running test programs ifpossible, because this prevents people from configuring your package forcross-compiling.@anchor{AC_RUN_IFELSE}@defmac AC_RUN_IFELSE (@var{input}, @ovar{action-if-true}, @  @ovar{action-if-false}, @dvar{action-if-cross-compiling, AC_MSG_FAILURE})@acindex{RUN_IFELSE}Run the compiler (and compilation flags) and the linker of the currentlanguage (@pxref{Language Choice}) on the @var{input}, then execute theresulting program.  If the program returns an exitstatus of 0 when executed, run shell commands @var{action-if-true}.Otherwise, run shell commands @var{action-if-false}.The @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.@code{LDFLAGS} and @code{LIBS} are used for linking, in addition to thecompilation flags of the current language (@pxref{Language Choice}).Additionally, @var{action-if-true} can run @command{./conftest$EXEEXT}for further testing.In the @var{action-if-false} section, the failing exit status isavailable in the shell variable @samp{$?}.  This exit status might bethat of a failed compilation, or it might be that of a failed programexecution.If cross-compilation mode is enabled (this is the case if either thecompiler being used does not produce executables that run on the systemwhere @command{configure} is being run, or if the options @code{--build}and @code{--host} were both specified and their values are different),then the test program isnot run.  If the optional shell commands @var{action-if-cross-compiling}are given, those commands are run instead; typically these commandsprovide pessimistic defaults that allow cross-compilation to work evenif the guess was wrong.  If the fourth argument is empty or omitted, butcross-compilation is detected, then @command{configure} prints an errormessage and exits.  If you want your package to be useful in across-compilation scenario, you @emph{should} provide a non-empty@var{action-if-cross-compiling} clause, as well as wrap the@code{AC_RUN_IFELSE} compilation inside an @code{AC_CACHE_CHECK}(@pxref{Caching Results}) which allows the user to override thepessimistic default if needed.It is customary to report unexpected failures with@code{AC_MSG_FAILURE}.@end defmac@command{autoconf} prints a warning message when creating@command{configure} each time it encounters a call to@code{AC_RUN_IFELSE} with no @var{action-if-cross-compiling} argumentgiven.  If you are not concerned about users configuring your packagefor cross-compilation, you may ignore the warning.  A few of the macrosdistributed with Autoconf produce this warning message; but if this is aproblem for you, please report it as a bug, along with an appropriatepessimistic guess to use instead.To configure for cross-compiling you can also choose a value for thoseparameters based on the canonical system name (@pxref{ManualConfiguration}).  Alternatively, set up a test results cache file withthe correct values for the host system (@pxref{Caching Results}).@ovindex cross_compilingTo provide a default for calls of @code{AC_RUN_IFELSE} that are embeddedin other macros, including a few of the ones that come with Autoconf,you can test whether the shell variable @code{cross_compiling} is set to@samp{yes}, and then use an alternate method to get the results insteadof calling the macros.It is also permissible to temporarily assign to @code{cross_compiling}in order to force tests to behave as though they are in across-compilation environment, particularly since this provides a way totest your @var{action-if-cross-compiling} even when you are not using across-compiler.@example# We temporarily set cross-compile mode to force AC_COMPUTE_INT# to use the slow link-only methodsave_cross_compiling=$cross_compilingcross_compiling=yesAC_COMPUTE_INT([@dots{}])cross_compiling=$save_cross_compiling@end exampleA C or C++ runtime test should be portable.@xref{Portable C and C++}.Erlang tests must exit themselves the Erlang VM by calling the @code{halt/1}function: the given status code is used to determine the success of the test(status is @code{0}) or its failure (status is different than @code{0}), asexplained above.  It must be noted that data output through the standard output(e.g., using @code{io:format/2}) may be truncated when halting the VM.Therefore, if a test must output configuration information, it is recommendedto create and to output data into the temporary file named @file{conftest.out},using the functions of module @code{file}.  The @code{conftest.out} file isautomatically deleted by the @code{AC_RUN_IFELSE} macro.  For instance, asimplified implementation of Autoconf's @code{AC_ERLANG_SUBST_LIB_DIR}macro is:@exampleAC_INIT([LibdirTest], [1.0], [bug-libdirtest@@example.org])AC_ERLANG_NEED_ERLAC_LANG(Erlang)AC_RUN_IFELSE(  [AC_LANG_PROGRAM([], [dnl    file:write_file("conftest.out", code:lib_dir()),    halt(0)])],  [echo "code:lib_dir() returned: `cat conftest.out`"],  [AC_MSG_FAILURE([test Erlang program execution failed])])@end example@node Systemology@section Systemology@cindex SystemologyThis section aims at presenting some systems and pointers todocumentation.  It may help you addressing particular problems reportedby users.@uref{http://@/www.opengroup.org/@/susv3, Posix-conforming systems} arederived from the @uref{http://@/www.bell-labs.com/@/history/@/unix/, Unixoperating system}.The @uref{http://@/bhami.com/@/rosetta.html, Rosetta Stone for Unix}contains a table correlating the features of various Posix-conformingsystems.  @uref{http://@/www.levenez.com/@/unix/, Unix History} is asimplified diagram of how many Unix systems were derived from eachother.@uref{http://@/heirloom.sourceforge.net/, The Heirloom Project}provides some variants of traditional implementations of Unix utilities.@table @asis@item Darwin@cindex DarwinDarwin is also known as Mac OS X@.  Beware that the file system @emph{can} becase-preserving, but case insensitive.  This can cause nasty problems,since for instance the installation attempt for a package having an@file{INSTALL} file can result in @samp{make install} report thatnothing was to be done!That's all dependent on whether the file system is a UFS (casesensitive) or HFS+ (case preserving).  By default Apple wants you toinstall the OS on HFS+.  Unfortunately, there are some pieces ofsoftware which really need to be built on UFS@.  We may want to rebuildDarwin to have both UFS and HFS+ available (and put the /local/buildtree on the UFS).@item QNX 4.25@cindex QNX 4.25@c FIXME: Please, if you feel like writing something more precise,@c it'd be great.  In particular, I can't understand the difference with@c QNX Neutrino.QNX is a realtime operating system running on Intel architecturemeant to be scalable from the small embedded systems to the hundredprocessor super-computer.  It claims to be Posix certified.  Moreinformation is available on the@uref{http://@/www.qnx.com/, QNX home page}.@item Tru64@cindex Tru64@uref{http://@/h30097.www3.hp.com/@/docs/,Documentation of several versions of Tru64} is available in differentformats.@item Unix version 7@cindex Unix version 7@cindex V7Officially this was called the ``Seventh Edition'' of ``the UNIXtime-sharing system'' but we use the more-common name ``Unix version 7''.Documentation is available in the@uref{http://@/plan9.bell-labs.com/@/7thEdMan/, Unix Seventh Edition Manual}.Previous versions of Unix are called ``Unix version 6'', etc., butthey were not as widely used.@end table@node Multiple Cases@section Multiple CasesSome operations are accomplished in several possible ways, depending onthe OS variant.  Checking for them essentially requires a ``casestatement''.  Autoconf does not directly provide one; however, it iseasy to simulate by using a shell variable to keep track of whether away to perform the operation has been found yet.Here is an example that uses the shell variable @code{fstype} to keeptrack of whether the remaining cases need to be checked.  Note thatsince the value of @code{fstype} is under our control, we don't have touse the longer @samp{test "x$fstype" = xno}.@example@groupAC_MSG_CHECKING([how to get file system type])fstype=no# The order of these tests is important.AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statvfs.h>#include <sys/fstyp.h>]])],                  [AC_DEFINE([FSTYPE_STATVFS], [1],                     [Define if statvfs exists.])                   fstype=SVR4])if test $fstype = no; then  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>#include <sys/fstyp.h>]])],                  [AC_DEFINE([FSTYPE_USG_STATFS], [1],                     [Define if USG statfs.])                   fstype=SVR3])fiif test $fstype = no; then  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>#include <sys/vmount.h>]])]),                  [AC_DEFINE([FSTYPE_AIX_STATFS], [1],                     [Define if AIX statfs.])                   fstype=AIX])fi# (more cases omitted here)AC_MSG_RESULT([$fstype])@end group@end example@c ====================================================== Results of Tests.@node Results@chapter Results of TestsOnce @command{configure} has determined whether a feature exists, what canit do to record that information?  There are four sorts of things it cando: define a C preprocessor symbol, set a variable in the output files,save the result in a cache file for future @command{configure} runs, andprint a message letting the user know the result of the test.@menu* Defining Symbols::            Defining C preprocessor symbols* Setting Output Variables::    Replacing variables in output files* Special Chars in Variables::  Characters to beware of in variables* Caching Results::             Speeding up subsequent @command{configure} runs* Printing Messages::           Notifying @command{configure} users@end menu@node Defining Symbols@section Defining C Preprocessor SymbolsA common action to take in response to a feature test is to define a Cpreprocessor symbol indicating the results of the test.  That is done bycalling @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}.By default, @code{AC_OUTPUT} places the symbols defined by these macrosinto the output variable @code{DEFS}, which contains an option@option{-D@var{symbol}=@var{value}} for each symbol defined.  Unlike inAutoconf version 1, there is no variable @code{DEFS} defined while@command{configure} is running.  To check whether Autoconf macros havealready defined a certain C preprocessor symbol, test the value of theappropriate cache variable, as in this example:@exampleAC_CHECK_FUNC([vprintf], [AC_DEFINE([HAVE_VPRINTF], [1],                          [Define if vprintf exists.])])if test "x$ac_cv_func_vprintf" != xyes; then  AC_CHECK_FUNC([_doprnt], [AC_DEFINE([HAVE_DOPRNT], [1],                            [Define if _doprnt exists.])])fi@end exampleIf @code{AC_CONFIG_HEADERS} has been called, then instead of creating@code{DEFS}, @code{AC_OUTPUT} creates a header file by substituting thecorrect values into @code{#define} statements in a template file.@xref{Configuration Headers}, for more information about this kind ofoutput.@defmac AC_DEFINE (@var{variable}, @var{value}, @ovar{description})@defmacx AC_DEFINE (@var{variable})@cvindex @var{variable}@acindex{DEFINE}Define @var{variable} to @var{value} (verbatim), by defining a Cpreprocessor macro for @var{variable}.  @var{variable} should be a Cidentifier, optionally suffixed by a parenthesized argument list todefine a C preprocessor macro with arguments.  The macro argument list,if present, should be a comma-separated list of C identifiers, possiblyterminated by an ellipsis @samp{...} if C99 syntax is employed.@var{variable} should not contain comments, white space, trigraphs,backslash-newlines, universal character names, or non-ASCIIcharacters.@var{value} may contain backslash-escaped newlines, which will bepreserved if you use @code{AC_CONFIG_HEADERS} but flattened if passedvia @code{@@DEFS@@} (with no effect on the compilation, since thepreprocessor sees only one line in the first place).  @var{value} shouldnot contain raw newlines.  If you are not using@code{AC_CONFIG_HEADERS}, @var{value} should not contain any @samp{#}characters, as @command{make} tends to eat them.  To use a shellvariable, use @code{AC_DEFINE_UNQUOTED} instead.@var{description} is only useful if you are using@code{AC_CONFIG_HEADERS}.  In this case, @var{description} is put intothe generated @file{config.h.in} as the comment before the macro define.The following example defines the C preprocessor variable@code{EQUATION} to be the string constant @samp{"$a > $b"}:@exampleAC_DEFINE([EQUATION], ["$a > $b"],  [Equation string.])@end exampleIf neither @var{value} nor @var{description} are given, then@var{value} defaults to 1 instead of to the empty string.  This is forbackwards compatibility with older versions of Autoconf, but this usageis obsolescent and may be withdrawn in future versions of Autoconf.If the @var{variable} is a literal string, it is passed to@code{m4_pattern_allow} (@pxref{Forbidden Patterns}).If multiple @code{AC_DEFINE} statements are executed for the same@var{variable} name (not counting any parenthesized argument list),the last one wins.@end defmac@defmac AC_DEFINE_UNQUOTED (@var{variable}, @var{value}, @ovar{description})@defmacx AC_DEFINE_UNQUOTED (@var{variable})@acindex{DEFINE_UNQUOTED}@cvindex @var{variable}Like @code{AC_DEFINE}, but three shell expansions areperformed---once---on @var{variable} and @var{value}: variable expansion(@samp{$}), command substitution (@samp{`}), and backslash escaping(@samp{\}), as if in an unquoted here-document.  Single and double quotecharacters in the value have nospecial meaning.  Use this macro instead of @code{AC_DEFINE} when@var{variable} or @var{value} is a shell variable.  Examples:@exampleAC_DEFINE_UNQUOTED([config_machfile], ["$machfile"],  [Configuration machine file.])AC_DEFINE_UNQUOTED([GETGROUPS_T], [$ac_cv_type_getgroups],  [getgroups return type.])AC_DEFINE_UNQUOTED([$ac_tr_hdr], [1],  [Translated header name.])@end example@end defmacDue to a syntactical bizarreness of the Bourne shell, do not usesemicolons to separate @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}calls from other macro calls or shell code; that can cause syntax errorsin the resulting @command{configure} script.  Use either blanks ornewlines.  That is, do this:@exampleAC_CHECK_HEADER([elf.h],  [AC_DEFINE([SVR4], [1], [System V Release 4]) LIBS="-lelf $LIBS"])@end example@noindentor this:@exampleAC_CHECK_HEADER([elf.h],  [AC_DEFINE([SVR4], [1], [System V Release 4])   LIBS="-lelf $LIBS"])@end example@noindentinstead of this:@exampleAC_CHECK_HEADER([elf.h],  [AC_DEFINE([SVR4], [1], [System V Release 4]); LIBS="-lelf $LIBS"])@end example@node Setting Output Variables@section Setting Output Variables@cindex Output variablesAnother way to record the results of tests is to set @dfn{outputvariables}, which are shell variables whose values are substituted intofiles that @command{configure} outputs.  The two macros below create newoutput variables.  @xref{Preset Output Variables}, for a list of outputvariables that are always available.@defmac AC_SUBST (@var{variable}, @ovar{value})@acindex{SUBST}Create an output variable from a shell variable.  Make @code{AC_OUTPUT}substitute the variable @var{variable} into output files (typically oneor more makefiles).  This means that @code{AC_OUTPUT}replaces instances of @samp{@@@var{variable}@@} in input files with thevalue that the shell variable @var{variable} has when @code{AC_OUTPUT}is called.  The value can contain any non-@code{NUL} character, includingnewline.  If you are using Automake 1.11 or newer, for newlines in valuesyou might want to consider using @code{AM_SUBST_NOTMAKE} to prevent@command{automake} from adding a line @code{@var{variable} =@@@var{variable}@@} to the @file{Makefile.in} files (@pxref{Optional, ,Automake, automake, Other things Automake recognizes}).Variable occurrences should not overlap: e.g., an input file shouldnot contain @samp{@@@var{var1}@@@var{var2}@@} if @var{var1} and @var{var2}are variable names.The substituted value is not rescanned for more output variables;occurrences of @samp{@@@var{variable}@@} in the value are insertedliterally into the output file.  (The algorithm uses the special marker@code{|#_!!_#|} internally, so neither the substituted value nor theoutput file may contain @code{|#_!!_#|}.)If @var{value} is given, in addition assign it to @var{variable}.The string @var{variable} is passed to @code{m4_pattern_allow}(@pxref{Forbidden Patterns}).@end defmac@defmac AC_SUBST_FILE (@var{variable})@acindex{SUBST_FILE}Another way to create an output variable from a shell variable.  Make@code{AC_OUTPUT} insert (without substitutions) the contents of the filenamed by shell variable @var{variable} into output files.  This meansthat @code{AC_OUTPUT} replaces instances of@samp{@@@var{variable}@@} in output files (such as @file{Makefile.in})with the contents of the file that the shell variable @var{variable}names when @code{AC_OUTPUT} is called.  Set the variable to@file{/dev/null} for cases that do not have a file to insert.This substitution occurs only when the @samp{@@@var{variable}@@} is on aline by itself, optionally surrounded by spaces and tabs.  Thesubstitution replaces the whole line, including the spaces, tabs, andthe terminating newline.This macro is useful for inserting makefile fragments containingspecial dependencies or other @command{make} directives for particular hostor target types into makefiles.  For example, @file{configure.ac}could contain:@exampleAC_SUBST_FILE([host_frag])host_frag=$srcdir/conf/sun4.mh@end example@noindentand then a @file{Makefile.in} could contain:@example@@host_frag@@@end exampleThe string @var{variable} is passed to @code{m4_pattern_allow}(@pxref{Forbidden Patterns}).@end defmac@cindex Precious Variable@cindex Variable, PreciousRunning @command{configure} in varying environments can be extremelydangerous.  If for instance the user runs @samp{CC=bizarre-cc./configure}, then the cache, @file{config.h}, and many other outputfiles depend upon @command{bizarre-cc} being the C compiler.  Iffor some reason the user runs @command{./configure} again, or if it isrun via @samp{./config.status --recheck}, (@xref{Automatic Remaking},and @pxref{config.status Invocation}), then the configuration can beinconsistent, composed of results depending upon two differentcompilers.Environment variables that affect this situation, such as @samp{CC}above, are called @dfn{precious variables}, and can be declared as suchby @code{AC_ARG_VAR}.@defmac AC_ARG_VAR (@var{variable}, @var{description})@acindex{ARG_VAR}Declare @var{variable} is a precious variable, and include its@var{description} in the variable section of @samp{./configure --help}.Being precious means that@itemize @minus@item@var{variable} is substituted via @code{AC_SUBST}.@itemThe value of @var{variable} when @command{configure} was launched issaved in the cache, including if it was not specified on the commandline but via the environment.  Indeed, while @command{configure} cannotice the definition of @code{CC} in @samp{./configure CC=bizarre-cc},it is impossible to notice it in @samp{CC=bizarre-cc ./configure},which, unfortunately, is what most users do.We emphasize that it is the @emph{initial} value of @var{variable} whichis saved, not that found during the execution of @command{configure}.Indeed, specifying @samp{./configure FOO=foo} and letting@samp{./configure} guess that @code{FOO} is @code{foo} can be twodifferent things.@item@var{variable} is checked for consistency between two@command{configure} runs.  For instance:@example$ @kbd{./configure --silent --config-cache}$ @kbd{CC=cc ./configure --silent --config-cache}configure: error: `CC' was not set in the previous runconfigure: error: changes in the environment can compromise \the buildconfigure: error: run `make distclean' and/or \`rm config.cache' and start over@end example@noindentand similarly if the variable is unset, or if its content is changed.If the content has white space changes only, then the error is degradedto a warning only, but the old value is reused.@item@var{variable} is kept during automatic reconfiguration(@pxref{config.status Invocation}) as if it had been passed as a commandline argument, including when no cache is used:@example$ @kbd{CC=/usr/bin/cc ./configure var=raboof --silent}$ @kbd{./config.status --recheck}running CONFIG_SHELL=/bin/sh /bin/sh ./configure var=raboof \  CC=/usr/bin/cc  --no-create --no-recursion@end example@end itemize@end defmac@node Special Chars in Variables@section Special Characters in Output Variables@cindex Output variables, special characters inMany output variables are intended to be evaluated both by@command{make} and by the shell.  Some characters are expandeddifferently in these two contexts, so to avoid confusion thesevariables' values should not contain any of the following characters:@example" # $ & ' ( ) * ; < > ? [ \ ^ ` |@end exampleAlso, these variables' values should neither contain newlines, nor startwith @samp{~}, nor contain white space or @samp{:} immediately followedby @samp{~}.  The values can contain nonempty sequences of white spacecharacters like tabs and spaces, but each such sequence mightarbitrarily be replaced by a single space during substitution.These restrictions apply both to the values that @command{configure}computes, and to the values set directly by the user.  For example, thefollowing invocations of @command{configure} are problematic, since theyattempt to use special characters within @code{CPPFLAGS} and white spacewithin @code{$(srcdir)}:@exampleCPPFLAGS='-DOUCH="&\"#$*?"' '../My Source/ouch-1.0/configure''../My Source/ouch-1.0/configure' CPPFLAGS='-DOUCH="&\"#$*?"'@end example@node Caching Results@section Caching Results@cindex CacheTo avoid checking for the same features repeatedly in various@command{configure} scripts (or in repeated runs of one script),@command{configure} can optionally save the results of many checks in a@dfn{cache file} (@pxref{Cache Files}).  If a @command{configure} scriptruns with caching enabled and finds a cache file, it reads the resultsof previous runs from the cache and avoids rerunning those checks.  As aresult, @command{configure} can then run much faster than if it had toperform all of the checks every time.@defmac AC_CACHE_VAL (@var{cache-id}, @var{commands-to-set-it})@acindex{CACHE_VAL}Ensure that the results of the check identified by @var{cache-id} areavailable.  If the results of the check were in the cache file that wasread, and @command{configure} was not given the @option{--quiet} or@option{--silent} option, print a message saying that the result wascached; otherwise, run the shell commands @var{commands-to-set-it}.  Ifthe shell commands are run to determine the value, the value issaved in the cache file just before @command{configure} creates its outputfiles.  @xref{Cache Variable Names}, for how to choose the name of the@var{cache-id} variable.The @var{commands-to-set-it} @emph{must have no side effects} except forsetting the variable @var{cache-id}, see below.@end defmac@defmac AC_CACHE_CHECK (@var{message}, @var{cache-id}, @  @var{commands-to-set-it})@acindex{CACHE_CHECK}A wrapper for @code{AC_CACHE_VAL} that takes care of printing themessages.  This macro provides a convenient shorthand for the mostcommon way to use these macros.  It calls @code{AC_MSG_CHECKING} for@var{message}, then @code{AC_CACHE_VAL} with the @var{cache-id} and@var{commands} arguments, and @code{AC_MSG_RESULT} with @var{cache-id}.The @var{commands-to-set-it} @emph{must have no side effects} except forsetting the variable @var{cache-id}, see below.@end defmacIt is common to find buggy macros using @code{AC_CACHE_VAL} or@code{AC_CACHE_CHECK}, because people are tempted to call@code{AC_DEFINE} in the @var{commands-to-set-it}.  Instead, the code that@emph{follows} the call to @code{AC_CACHE_VAL} should call@code{AC_DEFINE}, by examining the value of the cache variable.  Forinstance, the following macro is broken:@example@c If you change this example, adjust tests/base.at:AC_CACHE_CHECK.@groupAC_DEFUN([AC_SHELL_TRUE],[AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],                [my_cv_shell_true_works=no                 (true) 2>/dev/null && my_cv_shell_true_works=yes                 if test "x$my_cv_shell_true_works" = xyes; then                   AC_DEFINE([TRUE_WORKS], [1],                             [Define if `true(1)' works properly.])                 fi])])@end group@end example@noindentThis fails if the cache is enabled: the second time this macro is run,@code{TRUE_WORKS} @emph{will not be defined}.  The proper implementationis:@example@c If you change this example, adjust tests/base.at:AC_CACHE_CHECK.@groupAC_DEFUN([AC_SHELL_TRUE],[AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],                [my_cv_shell_true_works=no                 (true) 2>/dev/null && my_cv_shell_true_works=yes]) if test "x$my_cv_shell_true_works" = xyes; then   AC_DEFINE([TRUE_WORKS], [1],             [Define if `true(1)' works properly.]) fi])@end group@end exampleAlso, @var{commands-to-set-it} should not print any messages, forexample with @code{AC_MSG_CHECKING}; do that before calling@code{AC_CACHE_VAL}, so the messages are printed regardless of whetherthe results of the check are retrieved from the cache or determined byrunning the shell commands.@menu* Cache Variable Names::        Shell variables used in caches* Cache Files::                 Files @command{configure} uses for caching* Cache Checkpointing::         Loading and saving the cache file@end menu@node Cache Variable Names@subsection Cache Variable Names@cindex Cache variableThe names of cache variables should have the following format:@example@var{package-prefix}_cv_@var{value-type}_@var{specific-value}_@ovar{additional-options}@end example@noindentfor example, @samp{ac_cv_header_stat_broken} or@samp{ac_cv_prog_gcc_traditional}.  The parts of the variable name are:@table @asis@item @var{package-prefix}An abbreviation for your package or organization; the same prefix youbegin local Autoconf macros with, except lowercase by convention.For cache values used by the distributed Autoconf macros, this value is@samp{ac}.@item @code{_cv_}Indicates that this shell variable is a cache value.  This string@emph{must} be present in the variable name, including the leadingunderscore.@item @var{value-type}A convention for classifying cache values, to produce a rational namingsystem.  The values used in Autoconf are listed in @ref{Macro Names}.@item @var{specific-value}Which member of the class of cache values this test applies to.For example, which function (@samp{alloca}), program (@samp{gcc}), oroutput variable (@samp{INSTALL}).@item @var{additional-options}Any particular behavior of the specific member that this test applies to.For example, @samp{broken} or @samp{set}.  This part of the name maybe omitted if it does not apply.@end tableThe values assigned to cache variables may not contain newlines.Usually, their values are Boolean (@samp{yes} or @samp{no}) or thenames of files or functions; so this is not an important restriction.@ref{Cache Variable Index} for an index of cache variables withdocumented semantics.@node Cache Files@subsection Cache FilesA cache file is a shell script that caches the results of configuretests run on one system so they can be shared between configure scriptsand configure runs.  It is not useful on other systems.  If its contentsare invalid for some reason, the user may delete or edit it, or overridedocumented cache variables on the @command{configure} command line.By default, @command{configure} uses no cache file,to avoid problems caused by accidentaluse of stale cache files.To enable caching, @command{configure} accepts @option{--config-cache} (or@option{-C}) to cache results in the file @file{config.cache}.Alternatively, @option{--cache-file=@var{file}} specifies that@var{file} be the cache file.  The cache file is created if it does notexist already.  When @command{configure} calls @command{configure} scripts insubdirectories, it uses the @option{--cache-file} argument so that theyshare the same cache.  @xref{Subdirectories}, for information onconfiguring subdirectories with the @code{AC_CONFIG_SUBDIRS} macro.@file{config.status} only pays attention to the cache file if it isgiven the @option{--recheck} option, which makes it rerun@command{configure}.It is wrong to try to distribute cache files for particular system types.There is too much room for error in doing that, and too muchadministrative overhead in maintaining them.  For any features thatcan't be guessed automatically, use the standard method of the canonicalsystem type and linking files (@pxref{Manual Configuration}).The site initialization script can specify a site-wide cache file touse, instead of the usual per-program cache.  In this case, the cachefile gradually accumulates information whenever someone runs a new@command{configure} script.  (Running @command{configure} merges the new cacheresults with the existing cache file.)  This may cause problems,however, if the system configuration (e.g., the installed libraries orcompilers) changes and the stale cache file is not deleted.If @command{configure} is interrupted at the right time when it updatesa cache file outside of the build directory where the @command{configure}script is run, it may leave behind a temporary file named after thecache file with digits following it.  You may safely delete such a file.@node Cache Checkpointing@subsection Cache CheckpointingIf your configure script, or a macro called from @file{configure.ac}, happensto abort the configure process, it may be useful to checkpoint the cachea few times at key points using @code{AC_CACHE_SAVE}.  Doing soreduces the amount of time it takes to rerun the configure script with(hopefully) the error that caused the previous abort corrected.@c FIXME: Do we really want to document this guy?@defmac AC_CACHE_LOAD@acindex{CACHE_LOAD}Loads values from existing cache file, or creates a new cache file if acache file is not found.  Called automatically from @code{AC_INIT}.@end defmac@defmac AC_CACHE_SAVE@acindex{CACHE_SAVE}Flushes all cached values to the cache file.  Called automatically from@code{AC_OUTPUT}, but it can be quite useful to call@code{AC_CACHE_SAVE} at key points in @file{configure.ac}.@end defmacFor instance:@example@r{ @dots{} AC_INIT, etc. @dots{}}@group# Checks for programs.AC_PROG_CCAC_PROG_AWK@r{ @dots{} more program checks @dots{}}AC_CACHE_SAVE@end group@group# Checks for libraries.AC_CHECK_LIB([nsl], [gethostbyname])AC_CHECK_LIB([socket], [connect])@r{ @dots{} more lib checks @dots{}}AC_CACHE_SAVE@end group@group# Might abort@dots{}AM_PATH_GTK([1.0.2], [], [AC_MSG_ERROR([GTK not in path])])AM_PATH_GTKMM([0.9.5], [], [AC_MSG_ERROR([GTK not in path])])@end group@r{ @dots{} AC_OUTPUT, etc. @dots{}}@end example@node Printing Messages@section Printing Messages@cindex Messages, from @command{configure}@command{configure} scripts need to give users running them several kindsof information.  The following macros print messages in ways appropriatefor each kind.  The arguments to all of them get enclosed in shelldouble quotes, so the shell performs variable and back-quotesubstitution on them.These macros are all wrappers around the @command{echo} shell command.They direct output to the appropriate file descriptor (@pxref{FileDescriptor Macros}).@command{configure} scripts should rarely need to run @command{echo} directlyto print messages for the user.  Using these macros makes it easy tochange how and when each kind of message is printed; such changes needonly be made to the macro definitions and all the callers changeautomatically.To diagnose static issues, i.e., when @command{autoconf} is run, see@ref{Diagnostic Macros}.@defmac AC_MSG_CHECKING (@var{feature-description})@acindex{MSG_CHECKING}Notify the user that @command{configure} is checking for a particularfeature.  This macro prints a message that starts with @samp{checking }and ends with @samp{...} and no newline.  It must be followed by a callto @code{AC_MSG_RESULT} to print the result of the check and thenewline.  The @var{feature-description} should be something like@samp{whether the Fortran compiler accepts C++ comments} or @samp{forc89}.This macro prints nothing if @command{configure} is run with the@option{--quiet} or @option{--silent} option.@end defmac@anchor{AC_MSG_RESULT}@defmac AC_MSG_RESULT (@var{result-description})@acindex{MSG_RESULT}Notify the user of the results of a check.  @var{result-description} isalmost always the value of the cache variable for the check, typically@samp{yes}, @samp{no}, or a file name.  This macro should follow a callto @code{AC_MSG_CHECKING}, and the @var{result-description} should bethe completion of the message printed by the call to@code{AC_MSG_CHECKING}.This macro prints nothing if @command{configure} is run with the@option{--quiet} or @option{--silent} option.@end defmac@anchor{AC_MSG_NOTICE}@defmac AC_MSG_NOTICE (@var{message})@acindex{MSG_NOTICE}Deliver the @var{message} to the user.  It is useful mainly to print ageneral description of the overall purpose of a group of feature checks,e.g.,@exampleAC_MSG_NOTICE([checking if stack overflow is detectable])@end exampleThis macro prints nothing if @command{configure} is run with the@option{--quiet} or @option{--silent} option.@end defmac@anchor{AC_MSG_ERROR}@defmac AC_MSG_ERROR (@var{error-description}, @dvar{exit-status, $?/1})@acindex{MSG_ERROR}Notify the user of an error that prevents @command{configure} fromcompleting.  This macro prints an error message to the standard erroroutput and exits @command{configure} with @var{exit-status} (@samp{$?}by default, except that @samp{0} is converted to @samp{1}).@var{error-description} should be something like @samp{invalid value$HOME for \$HOME}.The @var{error-description} should start with a lower-case letter, and``cannot'' is preferred to ``can't''.@end defmac@defmac AC_MSG_FAILURE (@var{error-description}, @ovar{exit-status})@acindex{MSG_FAILURE}This @code{AC_MSG_ERROR} wrapper notifies the user of an error thatprevents @command{configure} from completing @emph{and} that additionaldetails are provided in @file{config.log}.  This is typically used whenabnormal results are found during a compilation.@end defmac@anchor{AC_MSG_WARN}@defmac AC_MSG_WARN (@var{problem-description})@acindex{MSG_WARN}Notify the @command{configure} user of a possible problem.  This macroprints the message to the standard error output; @command{configure}continues running afterward, so macros that call @code{AC_MSG_WARN} shouldprovide a default (back-up) behavior for the situations they warn about.@var{problem-description} should be something like @samp{ln -s seems tomake hard links}.@end defmac@c ====================================================== Programming in M4.@node Programming in M4@chapter Programming in M4@cindex M4Autoconf is written on top of two layers: @dfn{M4sugar}, which providesconvenient macros for pure M4 programming, and @dfn{M4sh}, whichprovides macros dedicated to shell script generation.As of this version of Autoconf, these two layers still containexperimental macros, whose interface might change in the future.  As amatter of fact, @emph{anything that is not documented must not be used}.@menu* M4 Quotation::                Protecting macros from unwanted expansion* Using autom4te::              The Autoconf executables backbone* Programming in M4sugar::      Convenient pure M4 macros* Debugging via autom4te::      Figuring out what M4 was doing@end menu@node M4 Quotation@section M4 Quotation@cindex M4 quotation@cindex quotationThe most common problem with existing macros is an improper quotation.This section, which users of Autoconf can skip, but which macro writers@emph{must} read, first justifies the quotation scheme that was chosenfor Autoconf and then ends with a rule of thumb.  Understanding theformer helps one to follow the latter.@menu* Active Characters::           Characters that change the behavior of M4* One Macro Call::              Quotation and one macro call* Quoting and Parameters::      M4 vs. shell parameters* Quotation and Nested Macros::  Macros calling macros* Changequote is Evil::         Worse than INTERCAL: M4 + changequote* Quadrigraphs::                Another way to escape special characters* Balancing Parentheses::       Dealing with unbalanced parentheses* Quotation Rule Of Thumb::     One parenthesis, one quote@end menu@node Active Characters@subsection Active CharactersTo fully understand where proper quotation is important, you first needto know what the special characters are in Autoconf: @samp{#} introducesa comment inside which no macro expansion is performed, @samp{,}separates arguments, @samp{[} and @samp{]} are the quotesthemselves@footnote{By itself, M4 uses @samp{`} and @samp{'}; it is theM4sugar layer that sets up the preferred quotes of @samp{[} and @samp{]}.},@samp{(} and @samp{)} (which M4 tries to match by pairs), and finally@samp{$} inside a macro definition.In order to understand the delicate case of macro calls, we first haveto present some obvious failures.  Below they are ``obvious-ified'',but when you find them in real life, they are usually in disguise.Comments, introduced by a hash and running up to the newline, are opaquetokens to the top level: active characters are turned off, and there isno macro expansion:@example# define([def], ine)@result{}# define([def], ine)@end exampleEach time there can be a macro expansion, there is a quotationexpansion, i.e., one level of quotes is stripped:@exampleint tab[10];@result{}int tab10;[int tab[10];]@result{}int tab[10];@end exampleWithout this in mind, the reader might try hopelessly to use her macro@code{array}:@exampledefine([array], [int tab[10];])array@result{}int tab10;[array]@result{}array@end example@noindentHow can you correctly output the intended results@footnote{Using@code{defn}.}?@node One Macro Call@subsection One Macro CallLet's proceed on the interaction between active characters and macroswith this small macro, which just returns its first argument:@exampledefine([car], [$1])@end example@noindentThe two pairs of quotes above are not part of the arguments of@code{define}; rather, they are understood by the top level when ittries to find the arguments of @code{define}.  Therefore, assuming@code{car} is not already defined, it is equivalent to write:@exampledefine(car, $1)@end example@noindentBut, while it is acceptable for a @file{configure.ac} to avoid unnecessaryquotes, it is bad practice for Autoconf macros which must both be morerobust and also advocate perfect style.At the top level, there are only two possibilities: either youquote or you don't:@examplecar(foo, bar, baz)@result{}foo[car(foo, bar, baz)]@result{}car(foo, bar, baz)@end exampleLet's pay attention to the special characters:@examplecar(#)@error{}EOF in argument list@end exampleThe closing parenthesis is hidden in the comment; with a hypotheticalquoting, the top level understood it this way:@examplecar([#)]@end example@noindentProper quotation, of course, fixes the problem:@examplecar([#])@result{}#@end exampleHere are more examples:@examplecar(foo, bar)@result{}foocar([foo, bar])@result{}foo, barcar((foo, bar))@result{}(foo, bar)car([(foo], [bar)])@result{}(foodefine([a], [b])@result{}car(a)@result{}bcar([a])@result{}bcar([[a]])@result{}acar([[[a]]])@result{}[a]@end example@node Quoting and Parameters@subsection Quoting and ParametersWhen M4 encounters @samp{$} within a macro definition, followedimmediately by a character it recognizes (@samp{0}@dots{}@samp{9},@samp{#}, @samp{@@}, or @samp{*}), it will perform M4 parameterexpansion.  This happens regardless of how many layers of quotes theparameter expansion is nested within, or even if it occurs in text thatwill be rescanned as a comment.@exampledefine([none], [$1])@result{}define([one], [[$1]])@result{}define([two], [[[$1]]])@result{}define([comment], [# $1])@result{}define([active], [ACTIVE])@result{}none([active])@result{}ACTIVEone([active])@result{}activetwo([active])@result{}[active]comment([active])@result{}# active@end exampleOn the other hand, since autoconf generates shell code, you often wantto output shell variable expansion, rather than performing M4 parameterexpansion.  To do this, you must use M4 quoting to separate the @samp{$}from the next character in the definition of your macro.  If the macrodefinition occurs in single-quoted text, then insert another level ofquoting; if the usage is already inside a double-quoted string, thensplit it into concatenated strings.@exampledefine([single], [a single-quoted $[]1 definition])@result{}define([double], [[a double-quoted $][1 definition]])@result{}single@result{}a single-quoted $1 definitiondouble@result{}a double-quoted $1 definition@end examplePosix states that M4 implementations are free to provide implementationextensions when @samp{$@{} is encountered in a macro definition.Autoconf reserves the longer sequence @samp{$@{@{} for use with plannedextensions that will be available in the future GNU M4 2.0,but guarantees that all other instances of @samp{$@{} will be outputliterally.  Therefore, this idiom can also be used to output shell codeparameter references:@exampledefine([first], [$@{1@}])first@result{}$@{1@}@end examplePosix also states that @samp{$11} should expand to the first parameterconcatenated with a literal @samp{1}, although some versions ofGNU M4 expand the eleventh parameter instead.  Forportability, you should only use single-digit M4 parameter expansion.With this in mind, we can explore the cases where macros invokemacros@enddots{}@node Quotation and Nested Macros@subsection Quotation and Nested MacrosThe examples below use the following macros:@exampledefine([car], [$1])define([active], [ACT, IVE])define([array], [int tab[10]])@end exampleEach additional embedded macro call introduces other possibleinteresting quotations:@examplecar(active)@result{}ACTcar([active])@result{}ACT, IVEcar([[active]])@result{}active@end exampleIn the first case, the top level looks for the arguments of @code{car},and finds @samp{active}.  Because M4 evaluates its argumentsbefore applying the macro, @samp{active} is expanded, which results in:@examplecar(ACT, IVE)@result{}ACT@end example@noindentIn the second case, the top level gives @samp{active} as first and onlyargument of @code{car}, which results in:@exampleactive@result{}ACT, IVE@end example@noindenti.e., the argument is evaluated @emph{after} the macro that invokes it.In the third case, @code{car} receives @samp{[active]}, which results in:@example[active]@result{}active@end example@noindentexactly as we already saw above.The example above, applied to a more realistic example, gives:@examplecar(int tab[10];)@result{}int tab10;car([int tab[10];])@result{}int tab10;car([[int tab[10];]])@result{}int tab[10];@end example@noindentHuh?  The first case is easily understood, but why is the second wrong,and the third right?  To understand that, you must know that afterM4 expands a macro, the resulting text is immediately subjectedto macro expansion and quote removal.  This means that the quote removaloccurs twice---first before the argument is passed to the @code{car}macro, and second after the @code{car} macro expands to the firstargument.As the author of the Autoconf macro @code{car}, you then consider it tobe incorrect that your users have to double-quote the arguments of@code{car}, so you ``fix'' your macro.  Let's call it @code{qar} forquoted car:@exampledefine([qar], [[$1]])@end example@noindentand check that @code{qar} is properly fixed:@exampleqar([int tab[10];])@result{}int tab[10];@end example@noindentAhhh!  That's much better.But note what you've done: now that the result of @code{qar} is alwaysa literal string, the only time a user can use nested macros is if sherelies on an @emph{unquoted} macro call:@exampleqar(active)@result{}ACTqar([active])@result{}active@end example@noindentleaving no way for her to reproduce what she used to do with @code{car}:@examplecar([active])@result{}ACT, IVE@end example@noindentWorse yet: she wants to use a macro that produces a set of @code{cpp}macros:@exampledefine([my_includes], [#include <stdio.h>])car([my_includes])@result{}#include <stdio.h>qar(my_includes)@error{}EOF in argument list@end exampleThis macro, @code{qar}, because it double quotes its arguments, forcesits users to leave their macro calls unquoted, which is dangerous.Commas and other active symbols are interpreted by M4 beforethey are given to the macro, often not in the way the users expect.Also, because @code{qar} behaves differently from the other macros,it's an exception that should be avoided in Autoconf.@node Changequote is Evil@subsection @code{changequote} is Evil@cindex @code{changequote}The temptation is often high to bypass proper quotation, in particularwhen it's late at night.  Then, many experienced Autoconf hackersfinally surrender to the dark side of the force and use the ultimateweapon: @code{changequote}.The M4 builtin @code{changequote} belongs to a set of primitives thatallow one to adjust the syntax of the language to adjust it to one'sneeds.  For instance, by default M4 uses @samp{`} and @samp{'} asquotes, but in the context of shell programming (and actually of mostprogramming languages), that's about the worst choice one can make:because of strings and back-quoted expressions in shell code (such as@samp{'this'} and @samp{`that`}), and because of literal characters in usualprogramming languages (as in @samp{'0'}), there are many unbalanced@samp{`} and @samp{'}.  Proper M4 quotation then becomes a nightmare, ifnot impossible.  In order to make M4 useful in such a context, itsdesigners have equipped it with @code{changequote}, which makes itpossible to choose another pair of quotes.  M4sugar, M4sh, Autoconf, andAutotest all have chosen to use @samp{[} and @samp{]}.  Not especiallybecause they are unlikely characters, but @emph{because they arecharacters unlikely to be unbalanced}.There are other magic primitives, such as @code{changecom} to specifywhat syntactic forms are comments (it is common to see@samp{changecom(<!--, -->)} when M4 is used to produce HTML pages),@code{changeword} and @code{changesyntax} to change other syntacticdetails (such as the character to denote the @var{n}th argument, @samp{$} bydefault, the parentheses around arguments, etc.).These primitives are really meant to make M4 more useful for specificdomains: they should be considered like command line options:@option{--quotes}, @option{--comments}, @option{--words}, and@option{--syntax}.  Nevertheless, they are implemented as M4 builtins, asit makes M4 libraries self contained (no need for additional options).There lies the problem@enddots{}@sp 1The problem is that it is then tempting to use them in the middle of anM4 script, as opposed to its initialization.  This, if not carefullythought out, can lead to disastrous effects: @emph{you are changing thelanguage in the middle of the execution}.  Changing and restoring thesyntax is often not enough: if you happened to invoke macros in between,these macros are lost, as the current syntax is probably notthe one they were implemented with.@c FIXME: I've been looking for a short, real case example, but I@c lost them all :(@node Quadrigraphs@subsection Quadrigraphs@cindex quadrigraphs@cindex @samp{@@S|@@}@cindex @samp{@@&t@@}@c Info cannot handle `:' in index entries.@ifnotinfo@cindex @samp{@@<:@@}@cindex @samp{@@:>@@}@cindex @samp{@@%:@@}@cindex @samp{@@@{:@@}@cindex @samp{@@:@}@@}@end ifnotinfoWhen writing an Autoconf macro you may occasionally need to generatespecial characters that are difficult to express with the standardAutoconf quoting rules.  For example, you may need to output the regularexpression @samp{[^[]}, which matches any character other than @samp{[}.This expression contains unbalanced brackets so it cannot be put easilyinto an M4 macro.Additionally, there are a few m4sugar macros (such as @code{m4_split}and @code{m4_expand}) which internally use special markers in additionto the regular quoting characters.  If the arguments to these macroscontain the literal strings @samp{-=<@{(} or @samp{)@}>=-}, the macrosmight behave incorrectly.You can work around these problems by using one of the following@dfn{quadrigraphs}:@table @samp@item @@<:@@@samp{[}@item @@:>@@@samp{]}@item @@S|@@@samp{$}@item @@%:@@@samp{#}@item @@@{:@@@samp{(}@item @@:@}@@@samp{)}@item @@&t@@Expands to nothing.@end tableQuadrigraphs are replaced at a late stage of the translation process,after @command{m4} is run, so they do not get in the way of M4 quoting.For example, the string @samp{^@@<:@@}, independently of its quotation,appears as @samp{^[} in the output.The empty quadrigraph can be used:@itemize @minus@item to mark trailing spaces explicitlyTrailing spaces are smashed by @command{autom4te}.  This is a feature.@item to produce quadrigraphs and other strings reserved by m4sugarFor instance @samp{@@<@@&t@@:@@} produces @samp{@@<:@@}.  For a morecontrived example:@examplem4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnlm4_split([a )@}>=- b -=<@{( c])@result{}[a], [], [B], [], [c]m4_split([a )@}@@&t@@>=- b -=<@@&t@@@{( c])@result{}[a], [)@}>=-], [b], [-=<@{(], [c]@end example@item to escape @emph{occurrences} of forbidden patternsFor instance you might want to mention @code{AC_FOO} in a comment, whilestill being sure that @command{autom4te} still catches unexpanded@samp{AC_*}.  Then write @samp{AC@@&t@@_FOO}.@end itemizeThe name @samp{@@&t@@} was suggested by Paul Eggert:@quotationI should give some credit to the @samp{@@&t@@} pun.  The @samp{&} is myown invention, but the @samp{t} came from the source code of theALGOL68C compiler, written by Steve Bourne (of Bourne shell fame),and which used @samp{mt} to denote the empty string.  In C, it wouldhave looked like something like:@examplechar const mt[] = "";@end example@noindentbut of course the source code was written in Algol 68.I don't know where he got @samp{mt} from: it could have been his owninvention, and I suppose it could have been a common pun around theCambridge University computer lab at the time.@end quotation@node Balancing Parentheses@subsection Dealing with unbalanced parentheses@cindex balancing parentheses@cindex parentheses, balancing@cindex unbalanced parentheses, managingOne of the pitfalls of portable shell programming is that @command{case}statements require unbalanced parentheses (@pxref{case, , Limitations ofShell Builtins}).  With syntax highlightingeditors, the presence of unbalanced @samp{)} can interfere with editorsthat perform syntax highlighting of macro contents based on finding thematching @samp{(}.  Another concern is how much editing must be donewhen transferring code snippets between shell scripts and macrodefinitions.  But most importantly, the presence of unbalancedparentheses can introduce expansion bugs.For an example, here is an underquoted attempt to use the macro@code{my_case}, which happens to expand to a portable @command{case}statement:@exampleAC_DEFUN([my_case],[case $file_name in  *.c) echo "C source code";;esac])AS_IF(:, my_case)@end example@noindentIn the above example, the @code{AS_IF} call underquotes its arguments.As a result, the unbalanced @samp{)} generated by the prematureexpansion of @code{my_case} results in expanding @code{AS_IF} with atruncated parameter, and the expansion is syntactically invalid:@exampleif :; then  case $file_name in  *.cfi echo "C source code";;esac)@end exampleIf nothing else, this should emphasize the importance of the quotingarguments to macro calls.  On the other hand, there are severalvariations for defining @code{my_case} to be more robust, even when usedwithout proper quoting, each with some benefits and some drawbacks.@itemize @w{}@item Creative literal shell comment@exampleAC_DEFUN([my_case],[case $file_name in #(  *.c) echo "C source code";;esac])@end example@noindentThis version provides balanced parentheses to several editors, and canbe copied and pasted into a terminal as is.  Unfortunately, it is stillunbalanced as an Autoconf argument, since @samp{#(} is an M4 commentthat masks the normal properties of @samp{(}.@item Quadrigraph shell comment@exampleAC_DEFUN([my_case],[case $file_name in @@%:@@(  *.c) echo "C source code";;esac])@end example@noindentThis version provides balanced parentheses to even more editors, and canbe used as a balanced Autoconf argument.  Unfortunately, it requiressome editing before it can be copied and pasted into a terminal, and theuse of the quadrigraph @samp{@@%:@@} for @samp{#} reduces readability.@item Quoting just the parenthesis@exampleAC_DEFUN([my_case],[case $file_name in  *.c[)] echo "C source code";;esac])@end example@noindentThis version quotes the @samp{)}, so that it can be used as a balancedAutoconf argument.  As written, this is not balanced to an editor, butit can be coupled with @samp{[#(]} to meet that need, too.  However, itstill requires some edits before it can be copied and pasted into aterminal.@item Double-quoting the entire statement@exampleAC_DEFUN([my_case],[[case $file_name in #(  *.c) echo "C source code";;esac]])@end example@noindentSince the entire macro is double-quoted, there is no problem with usingthis as an Autoconf argument; and since the double-quoting is over theentire statement, this code can be easily copied and pasted into aterminal.  However, the double quoting prevents the expansion of anymacros inside the case statement, which may cause its own set ofproblems.@item Using @code{AS_CASE}@exampleAC_DEFUN([my_case],[AS_CASE([$file_name],  [*.c], [echo "C source code"])])@end example@noindentThis version avoids the balancing issue altogether, by relying on@code{AS_CASE} (@pxref{Common Shell Constructs}); it also allows for theexpansion of @code{AC_REQUIRE} to occur prior to the entire casestatement, rather than within a branch of the case statement that mightnot be taken.  However, the abstraction comes with a penalty that it isno longer a quick copy, paste, and edit to get back to shell code.@end itemize@node Quotation Rule Of Thumb@subsection Quotation Rule Of ThumbTo conclude, the quotation rule of thumb is:@center @emph{One pair of quotes per pair of parentheses.}Never over-quote, never under-quote, in particular in the definition ofmacros.  In the few places where the macros need to use brackets(usually in C program text or regular expressions), properly quote@emph{the arguments}!It is common to read Autoconf programs with snippets like:@exampleAC_TRY_LINK(changequote(<<, >>)dnl<<#include <time.h>#ifndef tzname /* For SGI.  */extern char *tzname[]; /* RS6000 and others reject char **tzname.  */#endif>>,changequote([, ])dnl[atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)@end example@noindentwhich is incredibly useless since @code{AC_TRY_LINK} is @emph{already}double quoting, so you just need:@exampleAC_TRY_LINK([#include <time.h>#ifndef tzname /* For SGI.  */extern char *tzname[]; /* RS6000 and others reject char **tzname.  */#endif],            [atoi (*tzname);],            [ac_cv_var_tzname=yes],            [ac_cv_var_tzname=no])@end example@noindentThe M4-fluent reader might note that these two examples are rigorouslyequivalent, since M4 swallows both the @samp{changequote(<<, >>)}and @samp{<<} @samp{>>} when it @dfn{collects} the arguments: thesequotes are not part of the arguments!Simplified, the example above is just doing this:@examplechangequote(<<, >>)dnl<<[]>>changequote([, ])dnl@end example@noindentinstead of simply:@example[[]]@end exampleWith macros that do not double quote their arguments (which is therule), double-quote the (risky) literals:@exampleAC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <time.h>#ifndef tzname /* For SGI.  */extern char *tzname[]; /* RS6000 and others reject char **tzname.  */#endif]],                                [atoi (*tzname);])],               [ac_cv_var_tzname=yes],               [ac_cv_var_tzname=no])@end examplePlease note that the macro @code{AC_TRY_LINK} is obsolete, so you reallyshould be using @code{AC_LINK_IFELSE} instead.@xref{Quadrigraphs}, for what to do if you run into a hopeless casewhere quoting does not suffice.When you create a @command{configure} script using newly written macros,examine it carefully to check whether you need to add more quotes inyour macros.  If one or more words have disappeared in the M4output, you need more quotes.  When in doubt, quote.However, it's also possible to put on too many layers of quotes.  Ifthis happens, the resulting @command{configure} script may containunexpanded macros.  The @command{autoconf} program checks for this problemby looking for the string @samp{AC_} in @file{configure}.  However, thisheuristic does not work in general: for example, it does not catchoverquoting in @code{AC_DEFINE} descriptions.@c ---------------------------------------- Using autom4te@node Using autom4te@section Using @command{autom4te}The Autoconf suite, including M4sugar, M4sh, and Autotest, in additionto Autoconf per se, heavily rely on M4.  All these different usesrevealed common needs factored into a layer over M4:@command{autom4te}@footnote{@cYet another great name from Lars J. Aas.@c}.@command{autom4te} is a preprocessor that is like @command{m4}.It supports M4 extensions designed for use in tools like Autoconf.@menu* autom4te Invocation::         A GNU M4 wrapper* Customizing autom4te::        Customizing the Autoconf package@end menu@node autom4te Invocation@subsection Invoking @command{autom4te}The command line arguments are modeled after M4's:@exampleautom4te @var{options} @var{files}@end example@noindent@evindex M4where the @var{files} are directly passed to @command{m4}.  By default,GNU M4 is found during configuration, but the environmentvariable@env{M4} can be set to tell @command{autom4te} where to look.  In additionto the regular expansion, it handles the replacement of the quadrigraphs(@pxref{Quadrigraphs}), and of @samp{__oline__}, the current line in theoutput.  It supports an extended syntax for the @var{files}:@table @file@item @var{file}.m4fThis file is an M4 frozen file.  Note that @emph{all the previous filesare ignored}.  See the option @option{--melt} for the rationale.@item @var{file}?If found in the library path, the @var{file} is included for expansion,otherwise it is ignored instead of triggering a failure.@end table@sp 1Of course, it supports the Autoconf common subset of options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@item --verbose@itemx -vReport processing steps.@item --debug@itemx -dDon't remove the temporary files and be even more verbose.@item --include=@var{dir}@itemx -I @var{dir}Also look for input files in @var{dir}.  Multiple invocationsaccumulate.@item --output=@var{file}@itemx -o @var{file}Save output (script or trace) to @var{file}.  The file @option{-} standsfor the standard output.@end table@sp 1As an extension of @command{m4}, it includes the following options:@table @option@item --warnings=@var{category}@itemx -W @var{category}@evindex WARNINGS@c FIXME: Point to the M4sugar macros, not Autoconf's.Report the warnings related to @var{category} (which can actually be acomma separated list).  @xref{Reporting Messages}, macro@code{AC_DIAGNOSE}, for a comprehensive list of categories.  Specialvalues include:@table @samp@item allreport all the warnings@item nonereport none@item errortreats warnings as errors@item no-@var{category}disable warnings falling into @var{category}@end tableWarnings about @samp{syntax} are enabled by default, and the environmentvariable @env{WARNINGS}, a comma separated list of categories, ishonored.  @samp{autom4te -W @var{category}} actuallybehaves as if you had run:@exampleautom4te --warnings=syntax,$WARNINGS,@var{category}@end example@noindentFor example, if you want to disable defaults and @env{WARNINGS}of @command{autom4te}, but enable the warnings about obsoleteconstructs, you would use @option{-W none,obsolete}.@cindex Back trace@cindex Macro invocation stack@command{autom4te} displays a back trace for errors, but not forwarnings; if you want them, just pass @option{-W error}.@item --melt@itemx -MDo not use frozen files.  Any argument @code{@var{file}.m4f} isreplaced by @code{@var{file}.m4}.  This helps tracing the macros whichare executed only when the files are frozen, typically@code{m4_define}.  For instance, running:@exampleautom4te --melt 1.m4 2.m4f 3.m4 4.m4f input.m4@end example@noindentis roughly equivalent to running:@examplem4 1.m4 2.m4 3.m4 4.m4 input.m4@end example@noindentwhile@exampleautom4te 1.m4 2.m4f 3.m4 4.m4f input.m4@end example@noindentis equivalent to:@examplem4 --reload-state=4.m4f input.m4@end example@item --freeze@itemx -FProduce a frozen state file.  @command{autom4te} freezing is stricterthan M4's: it must produce no warnings, and no output other than emptylines (a line with white space is @emph{not} empty) and comments(starting with @samp{#}).  Unlike @command{m4}'s similarly-named option,this option takes no argument:@exampleautom4te 1.m4 2.m4 3.m4 --freeze --output=3.m4f@end example@noindentcorresponds to@examplem4 1.m4 2.m4 3.m4 --freeze-state=3.m4f@end example@item --mode=@var{octal-mode}@itemx -m @var{octal-mode}Set the mode of the non-traces output to @var{octal-mode}; by default@samp{0666}.@end table@sp 1@cindex @file{autom4te.cache}As another additional feature over @command{m4}, @command{autom4te}caches its results.  GNU M4 is able to produce a regularoutput and traces at the same time.  Traces are heavily used in theGNU Build System: @command{autoheader} uses them to build@file{config.h.in}, @command{autoreconf} to determine whatGNU Build System components are used, @command{automake} to``parse'' @file{configure.ac} etc.  To avoid recomputation,traces are cached while performing regular expansion,and conversely.  This cache is (actually, the caches are) stored inthe directory @file{autom4te.cache}.  @emph{It can safely be removed}at any moment (especially if for some reason @command{autom4te}considers it trashed).@table @option@item --cache=@var{directory}@itemx -C @var{directory}Specify the name of the directory where the result should be cached.Passing an empty value disables caching.  Be sure to pass a relativefile name, as for the time being, global caches are not supported.@item --no-cacheDon't cache the results.@item --force@itemx -fIf a cache is used, consider it obsolete (but update it anyway).@end table@sp 1Because traces are so important to the GNU Build System,@command{autom4te} provides high level tracing features as compared toM4, and helps exploiting the cache:@table @option@item --trace=@var{macro}[:@var{format}]@itemx -t @var{macro}[:@var{format}]Trace the invocations of @var{macro} according to the @var{format}.Multiple @option{--trace} arguments can be used to list several macros.Multiple @option{--trace} arguments for a single macro are notcumulative; instead, you should just make @var{format} as long asneeded.The @var{format} is a regular string, with newlines if desired, andseveral special escape codes.  It defaults to @samp{$f:$l:$n:$%}.  It canuse the following special escapes:@table @samp@item $$@c $$ restore font-lockThe character @samp{$}.@item $fThe file name from which @var{macro} is called.@item $lThe line number from which @var{macro} is called.@item $dThe depth of the @var{macro} call.  This is an M4 technical detail thatyou probably don't want to know about.@item $nThe name of the @var{macro}.@item $@var{num}The @var{num}th argument of the call to @var{macro}.@item $@@@itemx $@var{sep}@@@itemx $@{@var{separator}@}@@All the arguments passed to @var{macro}, separated by the character@var{sep} or the string @var{separator} (@samp{,} by default).  Eachargument is quoted, i.e., enclosed in a pair of square brackets.@item $*@itemx $@var{sep}*@itemx $@{@var{separator}@}*As above, but the arguments are not quoted.@item $%@itemx $@var{sep}%@itemx $@{@var{separator}@}%As above, but the arguments are not quoted, all new line characters inthe arguments are smashed, and the default separator is @samp{:}.The escape @samp{$%} produces single-line trace outputs (unless you putnewlines in the @samp{separator}), while @samp{$@@} and @samp{$*} donot.@end table@xref{autoconf Invocation}, for examples of trace uses.@item --preselect=@var{macro}@itemx -p @var{macro}Cache the traces of @var{macro}, but do not enable traces.  This isespecially important to save CPU cycles in the future.  For instance,when invoked, @command{autoconf} preselects all the macros that@command{autoheader}, @command{automake}, @command{autoreconf}, etc.,trace, so that running @command{m4} is not needed to trace them: thecache suffices.  This results in a huge speed-up.@end table@sp 1@cindex Autom4te LibraryFinally, @command{autom4te} introduces the concept of @dfn{Autom4telibraries}.  They consists in a powerful yet extremely simple feature:sets of combined command line arguments:@table @option@item --language=@var{language}@itemx -l @var{language}Use the @var{language} Autom4te library.  Current languages include:@table @code@item M4sugarcreate M4sugar output.@item M4shcreate M4sh executable shell scripts.@item Autotestcreate Autotest executable test suites.@item Autoconf-without-aclocal-m4create Autoconf executable configure scripts withoutreading @file{aclocal.m4}.@item Autoconfcreate Autoconf executable configure scripts.  This language inheritsall the characteristics of @code{Autoconf-without-aclocal-m4} andadditionally reads @file{aclocal.m4}.@end table@item --prepend-include=@var{dir}@itemx -B @var{dir}Prepend directory @var{dir} to the search path.  This is used to includethe language-specific files before any third-party macros.@end table@cindex @file{autom4te.cfg}As an example, if Autoconf is installed in its default location,@file{/usr/local}, the command @samp{autom4te -l m4sugar foo.m4} isstrictly equivalent to the command:@exampleautom4te --prepend-include /usr/local/share/autoconf \  m4sugar/m4sugar.m4f --warnings syntax foo.m4@end example@noindentRecursive expansion applies here: the command @samp{autom4te -l m4sh foo.m4}is the same as @samp{autom4te --language M4sugar m4sugar/m4sh.m4ffoo.m4}, i.e.:@exampleautom4te --prepend-include /usr/local/share/autoconf \  m4sugar/m4sugar.m4f m4sugar/m4sh.m4f --mode 777 foo.m4@end example@noindentThe definition of the languages is stored in @file{autom4te.cfg}.@node Customizing autom4te@subsection Customizing @command{autom4te}One can customize @command{autom4te} via @file{~/.autom4te.cfg} (i.e.,as found in the user home directory), and @file{./.autom4te.cfg} (i.e.,as found in the directory from which @command{autom4te} is run).  Theorder is first reading @file{autom4te.cfg}, then @file{~/.autom4te.cfg},then @file{./.autom4te.cfg}, and finally the command line arguments.In these text files, comments are introduced with @code{#}, and emptylines are ignored.  Customization is performed on a per-language basis,wrapped in between a @samp{begin-language: "@var{language}"},@samp{end-language: "@var{language}"} pair.Customizing a language stands for appending options (@pxref{autom4teInvocation}) to the current definition of the language.  Options, andmore generally arguments, are introduced by @samp{args:@var{arguments}}.  You may use the traditional shell syntax to quote the@var{arguments}.As an example, to disable Autoconf caches (@file{autom4te.cache})globally, include the following lines in @file{~/.autom4te.cfg}:@verbatim## ------------------ #### User Preferences.  #### ------------------ ##begin-language: "Autoconf-without-aclocal-m4"args: --no-cacheend-language: "Autoconf-without-aclocal-m4"@end verbatim@node Programming in M4sugar@section Programming in M4sugar@cindex M4sugarM4 by itself provides only a small, but sufficient, set of all-purposemacros.  M4sugar introduces additional generic macros.  Its name wascoined by Lars J. Aas: ``Readability And Greater Understanding Stands 4M4sugar''.M4sugar reserves the macro namespace @samp{^_m4_} for internal use, andthe macro namespace @samp{^m4_} for M4sugar macros.  You should notdefine your own macros into these namespaces.@menu* Redefined M4 Macros::         M4 builtins changed in M4sugar* Diagnostic Macros::           Diagnostic messages from M4sugar* Diversion support::           Diversions in M4sugar* Conditional constructs::      Conditions in M4* Looping constructs::          Iteration in M4* Evaluation Macros::           More quotation and evaluation control* Text processing Macros::      String manipulation in M4* Number processing Macros::    Arithmetic computation in M4* Set manipulation Macros::     Set manipulation in M4* Forbidden Patterns::          Catching unexpanded macros@end menu@node Redefined M4 Macros@subsection Redefined M4 Macros@msindex{builtin}@msindex{changecom}@msindex{changequote}@msindex{debugfile}@msindex{debugmode}@msindex{decr}@msindex{define}@msindex{divnum}@msindex{errprint}@msindex{esyscmd}@msindex{eval}@msindex{format}@msindex{ifdef}@msindex{incr}@msindex{index}@msindex{indir}@msindex{len}@msindex{pushdef}@msindex{shift}@msindex{substr}@msindex{syscmd}@msindex{sysval}@msindex{traceoff}@msindex{traceon}@msindex{translit}With a few exceptions, all the M4 native macros are moved in the@samp{m4_} pseudo-namespace, e.g., M4sugar renames @code{define} as@code{m4_define} etc.The list of macros unchanged from M4, except for their name, is:@itemize @minus@item m4_builtin@item m4_changecom@item m4_changequote@item m4_debugfile@item m4_debugmode@item m4_decr@item m4_define@item m4_divnum@item m4_errprint@item m4_esyscmd@item m4_eval@item m4_format@item m4_ifdef@item m4_incr@item m4_index@item m4_indir@item m4_len@item m4_pushdef@item m4_shift@item m4_substr@item m4_syscmd@item m4_sysval@item m4_traceoff@item m4_traceon@item m4_translit@end itemizeSome M4 macros are redefined, and are slightly incompatible with theirnative equivalent.@defmac __file__@defmacx __line__@MSindex __file__@MSindex __line__All M4 macros starting with @samp{__} retain their original name: forexample, no @code{m4__file__} is defined.@end defmac@defmac __oline__@MSindex __oline__This is not technically a macro, but a feature of Autom4te.  Thesequence @code{__oline__} can be used similarly to the other m4sugarlocation macros, but rather than expanding to the location of the inputfile, it is translated to the line number where it appears in the outputfile after all other M4 expansions.@end defmac@defmac dnl@MSindex dnlThis macro kept its original name: no @code{m4_dnl} is defined.@end defmac@defmac m4_bpatsubst (@var{string}, @var{regexp}, @ovar{replacement})@msindex{bpatsubst}This macro corresponds to @code{patsubst}.  The name @code{m4_patsubst}is kept for future versions of M4sugar, once GNU M4 2.0 isreleased and supports extended regular expression syntax.@end defmac@defmac m4_bregexp (@var{string}, @var{regexp}, @ovar{replacement})@msindex{bregexp}This macro corresponds to @code{regexp}.  The name @code{m4_regexp}is kept for future versions of M4sugar, once GNU M4 2.0 isreleased and supports extended regular expression syntax.@end defmac@defmac m4_copy (@var{source}, @var{dest})@defmacx m4_copy_force (@var{source}, @var{dest})@defmacx m4_rename (@var{source}, @var{dest})@defmacx m4_rename_force (@var{source}, @var{dest})@msindex{copy}@msindex{copy_force}@msindex{rename}@msindex{rename_force}These macros aren't directly builtins, but are closely related to@code{m4_pushdef} and @code{m4_defn}.  @code{m4_copy} and@code{m4_rename} ensure that @var{dest} is undefined, while@code{m4_copy_force} and @code{m4_rename_force} overwrite any existingdefinition.  All four macros then proceed to copy the entire pushdefstack of definitions of @var{source} over to @var{dest}.  @code{m4_copy}and @code{m4_copy_force} preserve the source (including in the specialcase where @var{source} is undefined), while @code{m4_rename} and@code{m4_rename_force} undefine the original macro name (making it anerror to rename an undefined @var{source}).Note that attempting to invoke a renamed macro might not work, since themacro may have a dependence on helper macros accessed via composition of@samp{$0} but that were not also renamed; likewise, other macros mayhave a hard-coded dependence on @var{source} and could break if@var{source} has been deleted.  On the other hand, it is always safe torename a macro to temporarily move it out of the way, then rename itback later to restore original semantics.@end defmac@defmac m4_defn (@var{macro}@dots{})@msindex{defn}This macro fails if @var{macro} is not defined, even when using olderversions of M4 that did not warn.  See @code{m4_undefine}.Unfortunately, in order to support these older versions of M4, there aresome situations involving unbalanced quotes where concatenating multiplemacros together will work in newer M4 but not in m4sugar; usequadrigraphs to work around this.@end defmac@defmac m4_divert (@var{diversion})@msindex{divert}M4sugar relies heavily on diversions, so rather than behaving as aprimitive, @code{m4_divert} behaves like:@examplem4_divert_pop()m4_divert_push([@var{diversion}])@end example@noindent@xref{Diversion support}, for more details about the use of thediversion stack.  In particular, this implies that @var{diversion}should be a named diversion rather than a raw number.  But be aware thatit is seldom necessary to explicitly change the diversion stack, andthat when done incorrectly, it can lead to syntactically invalidscripts.@end defmac@defmac m4_dumpdef (@var{name}@dots{})@defmacx m4_dumpdefs (@var{name}@dots{})@msindex{dumpdef}@msindex{dumpdefs}@code{m4_dumpdef} is like the M4 builtin, except that this versionrequires at least one argument, output always goes to standard errorrather than the current debug file, no sorting is done on multiplearguments, and an error is issued if any@var{name} is undefined.  @code{m4_dumpdefs} is a convenience macro thatcalls @code{m4_dumpdef} for all of the@code{m4_pushdef} stack of definitions, starting with the current, andsilently does nothing if @var{name} is undefined.Unfortunately, due to a limitation in M4 1.4.x, any macro defined as abuiltin is output as the empty string.  This behavior is rectified byusing M4 1.6 or newer.  However, this behavior difference means that@code{m4_dumpdef} should only be used while developing m4sugar macros,and never in the final published form of a macro.@end defmac@defmac m4_esyscmd_s (@var{command})@msindex{esyscmd_s}Like @code{m4_esyscmd}, this macro expands to the result of running@var{command} in a shell.  The difference is that any trailing newlinesare removed, so that the output behaves more like shell commandsubstitution.@end defmac@defmac m4_exit (@var{exit-status})@msindex{exit}This macro corresponds to @code{m4exit}.@end defmac@defmac m4_if (@var{comment})@defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal}, @ovar{not-equal})@defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal-1}, @  @var{string-3}, @var{string-4}, @var{equal-2}, @dots{}, @ovar{not-equal})@msindex{if}This macro corresponds to @code{ifelse}.  @var{string-1} and@var{string-2} are compared literally, so usually one of the twoarguments is passed unquoted.  @xref{Conditional constructs}, for moreconditional idioms.@end defmac@defmac m4_include (@var{file})@defmacx m4_sinclude (@var{file})@msindex{include}@msindex{sinclude}Like the M4 builtins, but warn against multiple inclusions of @var{file}.@end defmac@defmac m4_mkstemp (@var{template})@defmacx m4_maketemp (@var{template})@msindex{maketemp}@msindex{mkstemp}Posix requires @code{maketemp} to replace the trailing @samp{X}characters in @var{template} with the process id, without regards to theexistence of a file by that name, but this a security hole.  When thiswas pointed out to the Posix folks, they agreed to invent a new macro@code{mkstemp} that always creates a uniquely named file, but not allversions of GNU M4 support the new macro.  In M4sugar,@code{m4_maketemp} and @code{m4_mkstemp} are synonyms for each other,and both have the secure semantics regardless of which macro theunderlying M4 provides.@end defmac@defmac m4_popdef (@var{macro}@dots{})@msindex{popdef}This macro fails if @var{macro} is not defined, even when using olderversions of M4 that did not warn.  See @code{m4_undefine}.@end defmac@defmac m4_undefine (@var{macro}@dots{})@msindex{undefine}This macro fails if @var{macro} is not defined, even when using olderversions of M4 that did not warn.  Use@examplem4_ifdef([@var{macro}], [m4_undefine([@var{macro}])])@end example@noindentif you are not sure whether @var{macro} is defined.@end defmac@defmac m4_undivert (@var{diversion}@dots{})@msindex{undivert}Unlike the M4 builtin, at least one @var{diversion} must be specified.Also, since the M4sugar diversion stack prefers nameddiversions, the use of @code{m4_undivert} to include files is risky.@xref{Diversion support}, for more details about the use of thediversion stack.  But be aware that it is seldom necessary to explicitlychange the diversion stack, and that when done incorrectly, it can leadto syntactically invalid scripts.@end defmac@defmac m4_wrap (@var{text})@defmacx m4_wrap_lifo (@var{text})@msindex{wrap}@msindex{wrap_lifo}These macros correspond to @code{m4wrap}.  Posix requires arguments ofmultiple wrap calls to be reprocessed at EOF in the same orderas the original calls (first-in, first-out).  GNU M4 versionsthrough 1.4.10, however, reprocess them in reverse order (last-in,first-out).  Both orders are useful, therefore, you can rely on@code{m4_wrap} to provide FIFO semantics and @code{m4_wrap_lifo} forLIFO semantics, regardless of the underlying GNU M4 version.Unlike the GNU M4 builtin, these macros only recognize oneargument, and avoid token pasting between consecutive invocations.  Onthe other hand, nested calls to @code{m4_wrap} from within wrapped textwork just as in the builtin.@end defmac@node Diagnostic Macros@subsection Diagnostic messages from M4sugar@cindex Messages, from @command{M4sugar}When macros statically diagnose abnormal situations, benign or fatal,they should report them using these macros.  For issuing dynamic issues,i.e., when @command{configure} is run, see @ref{Printing Messages}.@defmac m4_assert (@var{expression}, @dvar{exit-status, 1})@msindex{assert}Assert that the arithmetic @var{expression} evaluates to non-zero.Otherwise, issue a fatal error, and exit @command{autom4te} with@var{exit-status}.@end defmac@defmac m4_errprintn (@var{message})@msindex{errprintn}Similar to the builtin @code{m4_errprint}, except that a newline isguaranteed after @var{message}.@end defmac@anchor{m4_fatal}@defmac m4_fatal (@var{message})@msindex{fatal}Report a severe error @var{message} prefixed with the current location,and have @command{autom4te} die.@end defmac@defmac m4_location@msindex{location}Useful as a prefix in a message line.  Short for:@example__file__:__line__@end example@end defmac@anchor{m4_warn}@defmac m4_warn (@var{category}, @var{message})@msindex{warn}Report @var{message} as a warning (or as an error if requested by theuser) if warnings of the @var{category} are turned on.  If the messageis emitted, it is prefixed with the current location, and followed by acall trace of all macros defined via @code{AC_DEFUN} used to get to thecurrent expansion.  You are encouraged to use standard categories, whichcurrently include:@table @samp@item allmessages that don't fall into one of the following categories.  Use of anempty @var{category} is equivalent.@item crossrelated to cross compilation issues.@item obsoleteuse of an obsolete construct.@item syntaxdubious syntactic constructs, incorrectly ordered macro calls.@end table@end defmac@node Diversion support@subsection Diversion supportM4sugar makes heavy use of diversions under the hood, because it isoften the case thattext that must appear early in the output is not discovered until latein the input.  Additionally, some of the topological sorting algorithmsused in resolving macro dependencies use diversions.  However, mostmacros should not need to change diversions directly, but rather rely onhigher-level M4sugar macros to manage diversions transparently.  If youchange diversions improperly, you risk generating a syntacticallyinvalid script, because an incorrect diversion will violate assumptionsmade by many macros about whether prerequisite text has been previouslyoutput.  In short, if you manually change the diversion, you should notexpect any macros provided by the Autoconf package to work until youhave restored the diversion stack back to its original state.In the rare case that it is necessary to write a macro that explicitlyoutputs text to a different diversion, it is important to be aware of anM4 limitation regarding diversions: text only goes to a diversion if itis not part of argument collection.  Therefore, any macro that changesthe current diversion cannot be used as an unquoted argument to anothermacro, but must be expanded at the top level.  The macro@code{m4_expand} will diagnose any attempt to change diversions, sinceit is generally useful only as an argument to another macro.  Thefollowing example shows what happens when diversion manipulation isattempted within macro arguments:@examplem4_do([normal text]m4_divert_push([KILL])unwanted[]m4_divert_pop([KILL])[m4_divert_push([KILL])discarded[]m4_divert_pop([KILL])])dnl@result{}normal text@result{}unwanted@end example@noindentNotice that the unquoted text @code{unwanted} is output, even though itwas processed while the current diversion was @code{KILL}, because itwas collected as part of the argument to @code{m4_do}.  However, thetext @code{discarded} disappeared as desired, because the diversionchanges were single-quoted, and were not expanded until the top-levelrescan of the output of @code{m4_do}.To make diversion management easier, M4sugar uses the concept of nameddiversions.  Rather than using diversion numbers directly, it is nicerto associate a name with each diversion.  The diversion number associatedwith a particular diversion name is an implementation detail, and asyntax warning is issued if a diversion number is used instead of aname.  In general, you should not output textto a named diversion until after calling the appropriate initializationroutine for your language (@code{m4_init}, @code{AS_INIT},@code{AT_INIT}, @dots{}), although there are some exceptions documentedbelow.M4sugar defines two named diversions.@table @code@item KILLText written to this diversion is discarded.  This is the defaultdiversion once M4sugar is initialized.@item GROWThis diversion is used behind the scenes by topological sorting macros,such as @code{AC_REQUIRE}.@end tableM4sh adds several more named diversions.@table @code@item BINSHThis diversion is reserved for the @samp{#!} interpreter line.@item HEADER-REVISIONThis diversion holds text from @code{AC_REVISION}.@item HEADER-COMMENTThis diversion holds comments about the purpose of a file.@item HEADER-COPYRIGHTThis diversion is managed by @code{AC_COPYRIGHT}.@item M4SH-SANITIZEThis diversion contains M4sh sanitization code, used to ensure M4sh isexecuting in a reasonable shell environment.@item M4SH-INITThis diversion contains M4sh initialization code, initializing variablesthat are required by other M4sh macros.@item BODYThis diversion contains the body of the shell code, and is the defaultdiversion once M4sh is initialized.@end tableAutotest inherits diversions from M4sh, and changes the defaultdiversion from @code{BODY} back to @code{KILL}.  It also adds severalmore named diversions, with the following subset designed for developeruse.@table @code@item PREPARE_TESTSThis diversion contains initialization sequences which are executedafter @file{atconfig} and @file{atlocal}, and after all command linearguments have been parsed, but prior to running any tests.  It can beused to set up state that is required across all tests.  This diversionwill work even before @code{AT_INIT}.@end tableAutoconf inherits diversions from M4sh, and adds the following nameddiversions which developers can utilize.@table @code@item DEFAULTSThis diversion contains shell variable assignments to set defaults thatmust be in place before arguments are parsed.  This diversion is placedearly enough in @file{configure} that it is unsafe to expand anyautoconf macros into this diversion.@item HELP_ENABLEIf @code{AC_PRESERVE_HELP_ORDER} was used, then text placed in thisdiversion will be included as part of a quoted here-doc providing all ofthe @option{--help} output of @file{configure} related to optionscreated by @code{AC_ARG_WITH} and @code{AC_ARG_ENABLE}.@item INIT_PREPAREThis diversion occurs after all command line options have been parsed,but prior to the main body of the @file{configure} script.  Thisdiversion is the last chance to insert shell code such as variableassignments or shell function declarations that will used by theexpansion of other macros.@end tableFor now, the remaining named diversions of Autoconf, Autoheader, andAutotest are not documented.  In other words,intentionally outputting text into an undocumented diversion is subjectto breakage in a future release of Autoconf.@defmac m4_cleardivert (@var{diversion}@dots{})@msindex{cleardivert}Permanently discard any text that has been diverted into@var{diversion}.@end defmac@defmac m4_divert_once (@var{diversion}, @ovar{content})@msindex{divert_once}Similar to @code{m4_divert_text}, except that @var{content} is onlyoutput to @var{diversion} if this is the first time that@code{m4_divert_once} has been called with its particular arguments.@end defmac@defmac m4_divert_pop (@ovar{diversion})@msindex{divert_pop}If provided, check that the current diversion is indeed @var{diversion}.Then change to the diversion located earlier on the stack, giving anerror if an attempt is made to pop beyond the initial m4sugar diversionof @code{KILL}.@end defmac@defmac m4_divert_push (@var{diversion})@msindex{divert_push}Remember the former diversion on the diversion stack, and outputsubsequent text into @var{diversion}.  M4sugar maintains a diversionstack, and issues an error if there is not a matching pop for everypush.@end defmac@defmac m4_divert_text (@var{diversion}, @ovar{content})@msindex{divert_text}Output @var{content} and a newline into @var{diversion}, withoutaffecting the current diversion.  Shorthand for:@examplem4_divert_push([@var{diversion}])@var{content}m4_divert_pop([@var{diversion}])dnl@end exampleOne use of @code{m4_divert_text} is to develop two related macros, wheremacro @samp{MY_A} does the work, but adjusts what work is performedbased on whether the optional macro @samp{MY_B} has also been expanded.Of course, it is possible to use @code{AC_BEFORE} within @code{MY_A} torequire that @samp{MY_B} occurs first, if it occurs at all.  But thisimposes an ordering restriction on the user; it would be nicer if macros@samp{MY_A} and @samp{MY_B} can be invoked in either order.  The trickis to let @samp{MY_B} leave a breadcrumb in an early diversion, which@samp{MY_A} can then use to determine whether @samp{MY_B} has beenexpanded.@exampleAC_DEFUN([MY_A],[# various actionsif test -n "$b_was_used"; then  # extra actionfi])AC_DEFUN([MY_B],[AC_REQUIRE([MY_A])dnlm4_divert_text([INIT_PREPARE], [b_was_used=true])])@end example@end defmac@defmac m4_init@msindex{init}Initialize the M4sugar environment, setting up the default nameddiversion to be @code{KILL}.@end defmac@node Conditional constructs@subsection Conditional constructsThe following macros provide additional conditional constructs asconvenience wrappers around @code{m4_if}.@defmac m4_bmatch (@var{string}, @var{regex-1}, @var{value-1}, @  @ovar{regex-2}, @ovar{value-2}, @dots{}, @ovar{default})@msindex{bmatch}The string @var{string} is repeatedly compared against a series of@var{regex} arguments; if a match is found, the expansion is thecorresponding @var{value}, otherwise, the macro moves on to the next@var{regex}.  If no @var{regex} match, then the result is the optional@var{default}, or nothing.@end defmac@defmac m4_bpatsubsts (@var{string}, @var{regex-1}, @var{subst-1}, @  @ovar{regex-2}, @ovar{subst-2}, @dots{})@msindex{bpatsubsts}The string @var{string} is altered by @var{regex-1} and @var{subst-1},as if by:@examplem4_bpatsubst([[@var{string}]], [@var{regex}], [@var{subst}])@end example@noindentThe result of the substitution is then passed through the next set of@var{regex} and @var{subst}, and so forth.  An empty @var{subst} impliesdeletion of any matched portions in the current string.  Note that thismacro over-quotes @var{string}; this behavior is intentional, so thatthe result of each step of the recursion remains as a quoted string.However, it means that anchors (@samp{^} and @samp{$} in the @var{regex}will line up with the extra quotations, and not the characters of theoriginal string.  The overquoting is removed after the finalsubstitution.@end defmac@defmac m4_case (@var{string}, @var{value-1}, @var{if-value-1}, @  @ovar{value-2}, @ovar{if-value-2}, @dots{}, @ovar{default})@msindex{case}Test @var{string} against multiple @var{value} possibilities, resultingin the first @var{if-value} for a match, or in the optional@var{default}.  This is shorthand for:@examplem4_if([@var{string}], [@var{value-1}], [@var{if-value-1}],      [@var{string}], [@var{value-2}], [@var{if-value-2}], @dots{},      [@var{default}])@end example@end defmac@defmac m4_cond (@var{test-1}, @var{value-1}, @var{if-value-1}, @  @ovar{test-2}, @ovar{value-2}, @ovar{if-value-2}, @dots{}, @ovar{default})@msindex{cond}This macro was introduced in Autoconf 2.62.  Similar to @code{m4_if},except that each @var{test} is expanded only when it is encountered.This is useful for short-circuiting expensive tests; while @code{m4_if}requires all its strings to be expanded up front before doingcomparisons, @code{m4_cond} only expands a @var{test} when all earliertests have failed.For an example, these two sequences give the same result, but in thecase where @samp{$1} does not contain a backslash, the @code{m4_cond}version only expands @code{m4_index} once, instead of five times, forfaster computation if this is a common case for @samp{$1}.  Notice thatevery third argument is unquoted for @code{m4_if}, and quoted for@code{m4_cond}:@examplem4_if(m4_index([$1], [\]), [-1], [$2],      m4_eval(m4_index([$1], [\\]) >= 0), [1], [$2],      m4_eval(m4_index([$1], [\$]) >= 0), [1], [$2],      m4_eval(m4_index([$1], [\`]) >= 0), [1], [$3],      m4_eval(m4_index([$1], [\"]) >= 0), [1], [$3],      [$2])m4_cond([m4_index([$1], [\])], [-1], [$2],        [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2],        [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2],        [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3],        [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3],        [$2])@end example@end defmac@defmac m4_default (@var{expr-1}, @var{expr-2})@defmacx m4_default_quoted (@var{expr-1}, @var{expr-2})@defmacx m4_default_nblank (@var{expr-1}, @ovar{expr-2})@defmacx m4_default_nblank_quoted (@var{expr-1}, @ovar{expr-2})@msindex{default}@msindex{default_quoted}@msindex{default_nblank}@msindex{default_nblank_quoted}If @var{expr-1} contains text, use it.  Otherwise, select @var{expr-2}.@code{m4_default} expands the result, while @code{m4_default_quoted}does not.  Useful for providing a fixed default if the expression thatresults in @var{expr-1} would otherwise be empty.  The differencebetween @code{m4_default} and @code{m4_default_nblank} is whether anargument consisting of just blanks (space, tab, newline) issignificant.  When using the expanding versions, note that an argumentmay contain text but still expand to an empty string.@examplem4_define([active], [ACTIVE])dnlm4_define([empty], [])dnlm4_define([demo1], [m4_default([$1], [$2])])dnlm4_define([demo2], [m4_default_quoted([$1], [$2])])dnlm4_define([demo3], [m4_default_nblank([$1], [$2])])dnlm4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnldemo1([active], [default])@result{}ACTIVEdemo1([], [active])@result{}ACTIVEdemo1([empty], [text])@result{}-demo1([ ], [active])-@result{}- -demo2([active], [default])@result{}activedemo2([], [active])@result{}activedemo2([empty], [text])@result{}empty-demo2([ ], [active])-@result{}- -demo3([active], [default])@result{}ACTIVEdemo3([], [active])@result{}ACTIVEdemo3([empty], [text])@result{}-demo3([ ], [active])-@result{}-ACTIVE-demo4([active], [default])@result{}activedemo4([], [active])@result{}activedemo4([empty], [text])@result{}empty-demo4([ ], [active])-@result{}-active-@end example@end defmac@defmac m4_define_default (@var{macro}, @ovar{default-definition})@msindex{define_default}If @var{macro} does not already have a definition, then define it to@var{default-definition}.@end defmac@defmac m4_ifblank (@var{cond}, @ovar{if-blank}, @ovar{if-text})@defmacx m4_ifnblank (@var{cond}, @ovar{if-text}, @ovar{if-blank})@msindex{ifblank}@msindex{ifnblank}If @var{cond} is empty or consists only of blanks (space, tab, newline),then expand @var{if-blank}; otherwise, expand @var{if-text}.  Twovariants exist, in order to make it easier to select the correct logicalsense when using only two parameters.  Note that this is more efficientthan the equivalent behavior of:@examplem4_ifval(m4_normalize([@var{cond}]), @var{if-text}, @var{if-blank})@end example@end defmac@defmac m4_ifndef (@var{macro}, @var{if-not-defined}, @ovar{if-defined})@msindex{ifndef}This is shorthand for:@examplem4_ifdef([@var{macro}], [@var{if-defined}], [@var{if-not-defined}])@end example@end defmac@defmac m4_ifset (@var{macro}, @ovar{if-true}, @ovar{if-false})@msindex{ifset}If @var{macro} is undefined, or is defined as the empty string, expandto @var{if-false}.  Otherwise, expands to @var{if-true}.  Similar to:@examplem4_ifval(m4_defn([@var{macro}]), [@var{if-true}], [@var{if-false}])@end example@noindentexcept that it is not an error if @var{macro} is undefined.@end defmac@defmac m4_ifval (@var{cond}, @ovar{if-true}, @ovar{if-false})@msindex{ifval}Expands to @var{if-true} if @var{cond} is not empty, otherwise to@var{if-false}.  This is shorthand for:@examplem4_if([@var{cond}], [], [@var{if-false}], [@var{if-true}])@end example@end defmac@defmac m4_ifvaln (@var{cond}, @ovar{if-true}, @ovar{if-false})@msindex{ifvaln}Similar to @code{m4_ifval}, except guarantee that a newline is presentafter any non-empty expansion.  Often followed by @code{dnl}.@end defmac@defmac m4_n (@var{text})@msindex{n}Expand to @var{text}, and add a newline if @var{text} is not empty.Often followed by @code{dnl}.@end defmac@node Looping constructs@subsection Looping constructsThe following macros are useful in implementing recursive algorithms inM4, including loop operations.  An M4 list is formed by quoting a listof quoted elements; generally the lists are comma-separated, although@code{m4_foreach_w} is whitespace-separated.  For example, the list@samp{[[a], [b,c]]} contains two elements: @samp{[a]} and @samp{[b,c]}.It is common to see lists with unquoted elements when those elements arenot likely to be macro names, as in @samp{[fputc_unlocked,fgetc_unlocked]}.Although not generally recommended, it is possible for quoted lists tohave side effects; all side effects are expanded only once, and prior tovisiting any list element.  On the other hand, the fact that unquotedmacros are expanded exactly once means that macros without side effectscan be used to generate lists.  For example,@examplem4_foreach([i], [[1], [2], [3]m4_errprintn([hi])], [i])@error{}hi@result{}123m4_define([list], [[1], [2], [3]])@result{}m4_foreach([i], [list], [i])@result{}123@end example@defmac m4_argn (@var{n}, @ovar{arg}@dots{})@msindex{argn}Extracts argument @var{n} (larger than 0) from the remaining arguments.If there are too few arguments, the empty string is used.  For any@var{n} besides 1, this is more efficient than the similar@samp{m4_car(m4_shiftn([@var{n}], [], [@var{arg}@dots{}]))}.@end defmac@defmac m4_car (@var{arg}@dots{})@msindex{car}Expands to the quoted first @var{arg}.  Can be used with @code{m4_cdr}to recursively iteratethrough a list.  Generally, when using quoted lists of quoted elements,@code{m4_car} should be called without any extra quotes.@end defmac@defmac m4_cdr (@var{arg}@dots{})@msindex{cdr}Expands to a quoted list of all but the first @var{arg}, or the emptystring if there was only one argument.  Generally, when using quotedlists of quoted elements, @code{m4_cdr} should be called without anyextra quotes.For example, this is a simple implementation of @code{m4_map}; note howeach iteration checks for the end of recursion, then merely applies thefirst argument to the first element of the list, then repeats with therest of the list.  (The actual implementation in M4sugar is a bit moreinvolved, to gain some speed and share code with @code{m4_map_sep}, andalso to avoid expanding side effects in @samp{$2} twice).@examplem4_define([m4_map], [m4_ifval([$2],  [m4_apply([$1], m4_car($2))[]$0([$1], m4_cdr($2))])])dnlm4_map([ m4_eval], [[[1]], [[1+1]], [[10],[16]]])@result{} 1 2 a@end example@end defmac@defmac m4_for (@var{var}, @var{first}, @var{last}, @ovar{step}, @  @var{expression})@msindex{for}Loop over the numeric values between @var{first} and @var{last}including bounds by increments of @var{step}.  For each iteration,expand @var{expression} with the numeric value assigned to @var{var}.If @var{step} is omitted, it defaults to @samp{1} or @samp{-1} dependingon the order of the limits.  If given, @var{step} has to match thisorder.  The number of iterations is determined independently fromdefinition of @var{var}; iteration cannot be short-circuited orlengthened by modifying @var{var} from within @var{expression}.@end defmac@defmac m4_foreach (@var{var}, @var{list}, @var{expression})@msindex{foreach}Loop over the comma-separated M4 list @var{list}, assigning each valueto @var{var}, and expand @var{expression}.  The following exampleoutputs two lines:@examplem4_foreach([myvar], [[foo], [bar, baz]],           [echo myvar])dnl@result{}echo foo@result{}echo bar, baz@end exampleNote that for some forms of @var{expression}, it may be faster to use@code{m4_map_args}.@end defmac@anchor{m4_foreach_w}@defmac m4_foreach_w (@var{var}, @var{list}, @var{expression})@msindex{foreach_w}Loop over the white-space-separated list @var{list}, assigning each valueto @var{var}, and expand @var{expression}.  If @var{var} is onlyreferenced once in @var{expression}, it is more efficient to use@code{m4_map_args_w}.The deprecated macro @code{AC_FOREACH} is an alias of@code{m4_foreach_w}.@end defmac@defmac m4_map (@var{macro}, @var{list})@defmacx m4_mapall (@var{macro}, @var{list})@defmacx m4_map_sep (@var{macro}, @var{separator}, @var{list})@defmacx m4_mapall_sep (@var{macro}, @var{separator}, @var{list})@msindex{map}@msindex{mapall}@msindex{map_sep}@msindex{mapall_sep}Loop over the comma separated quoted list of argument descriptions in@var{list}, and invoke @var{macro} with the arguments.  An argumentdescription is in turn a comma-separated quoted list of quoted elements,suitable for @code{m4_apply}.  The macros @code{m4_map} and@code{m4_map_sep} ignore empty argument descriptions, while@code{m4_mapall} and @code{m4_mapall_sep} invoke @var{macro} with noarguments.  The macros @code{m4_map_sep} and @code{m4_mapall_sep}additionally expand @var{separator} between invocations of @var{macro}.Note that @var{separator} is expanded, unlike in @code{m4_join}.  Whenseparating output with commas, this means that the map result can beused as a series of arguments, by using a single-quoted comma as@var{separator}, or as a single string, by using a double-quoted comma.@examplem4_map([m4_count], [])@result{}m4_map([ m4_count], [[],                     [[1]],                     [[1], [2]]])@result{} 1 2m4_mapall([ m4_count], [[],                        [[1]],                        [[1], [2]]])@result{} 0 1 2m4_map_sep([m4_eval], [,], [[[1+2]],                            [[10], [16]]])@result{}3,am4_map_sep([m4_echo], [,], [[[a]], [[b]]])@result{}a,bm4_count(m4_map_sep([m4_echo], [,], [[[a]], [[b]]]))@result{}2m4_map_sep([m4_echo], [[,]], [[[a]], [[b]]])@result{}a,bm4_count(m4_map_sep([m4_echo], [[,]], [[[a]], [[b]]]))@result{}1@end example@end defmac@defmac m4_map_args (@var{macro}, @var{arg}@dots{})@msindex{map_args}Repeatedly invoke @var{macro} with each successive @var{arg} as its onlyargument.  In the following example, three solutions are presented withthe same expansion; the solution using @code{m4_map_args} is the mostefficient.@examplem4_define([active], [ACTIVE])dnlm4_foreach([var], [[plain], [active]], [ m4_echo(m4_defn([var]))])@result{} plain activem4_map([ m4_echo], [[[plain]], [[active]]])@result{} plain activem4_map_args([ m4_echo], [plain], [active])@result{} plain active@end exampleIn cases where it is useful to operate on additional parameters besidesthe list elements, the macro @code{m4_curry} can be used in @var{macro}to supply the argument currying necessary to generate the desiredargument list.  In the following example, @code{list_add_n} is moreefficient than @code{list_add_x}.  On the other hand, using@code{m4_map_args_sep} can be even more efficient.@examplem4_define([list], [[1], [2], [3]])dnlm4_define([add], [m4_eval(([$1]) + ([$2]))])dnldnl list_add_n(N, ARG...)dnl Output a list consisting of each ARG added to Nm4_define([list_add_n],[m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@@)))])dnllist_add_n([1], list)@result{}2,3,4list_add_n([2], list)@result{}3,4,5m4_define([list_add_x],[m4_shift(m4_foreach([var], m4_dquote(m4_shift($@@)),  [,add([$1],m4_defn([var]))]))])dnllist_add_x([1], list)@result{}2,3,4@end example@end defmac@defmac m4_map_args_pair (@var{macro}, @dvar{macro-end, macro}, @  @var{arg}@dots{})@msindex{map_args_pair}For every pair of arguments @var{arg}, invoke @var{macro} with twoarguments.  If there is an odd number of arguments, invoke@var{macro-end}, which defaults to @var{macro}, with the remainingargument.@examplem4_map_args_pair([, m4_reverse], [], [1], [2], [3])@result{}, 2, 1, 3m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])@result{}, 2, 1, [3]m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])@result{}, 2, 1, 4, 3@end example@end defmac@defmac m4_map_args_sep (@ovar{pre}, @ovar{post}, @ovar{sep}, @var{arg}@dots{})@msindex{map_args_sep}Expand the sequence @code{@var{pre}[@var{arg}]@var{post}} for eachargument, additionally expanding @var{sep} between arguments.  Onecommon use of this macro is constructing a macro call, where the openingand closing parentheses are split between @var{pre} and @var{post}; inparticular, @code{m4_map_args([@var{macro}], [@var{arg}])} is equivalentto @code{m4_map_args_sep([@var{macro}(], [)], [], [@var{arg}])}.  Thismacro provides the most efficient means for iterating over an arbitrarylist of arguments, particularly when repeatedly constructing a macrocall with more arguments than @var{arg}.@end defmac@defmac m4_map_args_w (@var{string}, @ovar{pre}, @ovar{post}, @ovar{sep})@msindex{map_args_w}Expand the sequence @code{@var{pre}[word]@var{post}} for each word inthe whitespace-separated @var{string}, additionally expanding @var{sep}between words.  This macro provides the most efficient means foriterating over a whitespace-separated string.  In particular,@code{m4_map_args_w([@var{string}], [@var{action}(], [)])} is moreefficient than @code{m4_foreach_w([var], [@var{string}],[@var{action}(m4_defn([var]))])}.@end defmac@defmac m4_shiftn (@var{count}, @dots{})@defmacx m4_shift2 (@dots{})@defmacx m4_shift3 (@dots{})@msindex{shift2}@msindex{shift3}@msindex{shiftn}@code{m4_shiftn} performs @var{count} iterations of @code{m4_shift},along with validation that enough arguments were passed in to match theshift count, and that the count is positive.  @code{m4_shift2} and@code{m4_shift3} are specializationsof @code{m4_shiftn}, introduced in Autoconf 2.62, and are more efficientfor two and three shifts, respectively.@end defmac@defmac m4_stack_foreach (@var{macro}, @var{action})@defmacx m4_stack_foreach_lifo (@var{macro}, @var{action})@msindex{stack_foreach}@msindex{stack_foreach_lifo}For each of the @code{m4_pushdef} definitions of @var{macro}, expand@var{action} with the single argument of a definition of @var{macro}.@code{m4_stack_foreach} starts with the oldest definition, while@code{m4_stack_foreach_lifo} starts with the current definition.@var{action} should not push or pop definitions of @var{macro}, nor isthere any guarantee that the current definition of @var{macro} matchesthe argument that was passed to @var{action}.  The macro @code{m4_curry}can be used if @var{action} needs more than one argument, although inthat case it is more efficient to use @var{m4_stack_foreach_sep}.Due to technical limitations, there are a few low-level m4sugarfunctions, such as @code{m4_pushdef}, that cannot be used as the@var{macro} argument.@examplem4_pushdef([a], [1])m4_pushdef([a], [2])dnlm4_stack_foreach([a], [ m4_incr])@result{} 2 3m4_stack_foreach_lifo([a], [ m4_curry([m4_substr], [abcd])])@result{} cd bcd@end example@end defmac@defmac m4_stack_foreach_sep (@var{macro}, @ovar{pre}, @ovar{post}, @ovar{sep})@defmacx m4_stack_foreach_sep_lifo (@var{macro}, @ovar{pre}, @ovar{post}, @  @ovar{sep})@msindex{stack_foreach_sep}@msindex{stack_foreach_sep_lifo}Expand the sequence @code{@var{pre}[definition]@var{post}} for each@code{m4_pushdef} definition of @var{macro}, additionally expanding@var{sep} between definitions.  @code{m4_stack_foreach_sep} visits theoldest definition first, while @code{m4_stack_foreach_sep_lifo} visitsthe current definition first.  This macro provides the most efficientmeans for iterating over a pushdef stack.  In particular,@code{m4_stack_foreach([@var{macro}], [@var{action}])} is short for@code{m4_stack_foreach_sep([@var{macro}], [@var{action}(], [)])}.@end defmac@node Evaluation Macros@subsection Evaluation MacrosThe following macros give some control over the order of the evaluationby adding or removing levels of quotes.@defmac m4_apply (@var{macro}, @var{list})@msindex{apply}Apply the elements of the quoted, comma-separated @var{list} as thearguments to @var{macro}.  If @var{list} is empty, invoke @var{macro}without arguments.  Note the difference between @code{m4_indir}, whichexpects its first argument to be a macro name but can use names that areotherwise invalid, and @code{m4_apply}, where @var{macro} can containother text, but must end in a valid macro name.@examplem4_apply([m4_count], [])@result{}0m4_apply([m4_count], [[]])@result{}1m4_apply([m4_count], [[1], [2]])@result{}2m4_apply([m4_join], [[|], [1], [2]])@result{}1|2@end example@end defmac@defmac m4_count (@var{arg}, @dots{})@msindex{count}This macro returns the decimal count of the number of arguments it waspassed.@end defmac@defmac m4_curry (@var{macro}, @var{arg}@dots{})@msindex{curry}This macro performs argument currying.  The expansion of this macro isanother macro name that expects exactly one argument; that argument isthen appended to the @var{arg} list, and then @var{macro} is expandedwith the resulting argument list.@examplem4_curry([m4_curry], [m4_reverse], [1])([2])([3])@result{}3, 2, 1@end exampleUnfortunately, due to a limitation in M4 1.4.x, it is not possible topass the definition of a builtin macro as the argument to the output of@code{m4_curry}; the empty string is used instead of the builtin token.This behavior is rectified by using M4 1.6 or newer.@end defmac@defmac m4_do (@var{arg}, @dots{})@msindex{do}This macro loops over its arguments and expands each @var{arg} insequence.  Its main use is for readability; it allows the use ofindentation and fewer @code{dnl} to result in the same expansion.  Thismacro guarantees that no expansion will be concatenated with subsequenttext; to achieve full concatenation, use @code{m4_unquote(m4_join([],@var{arg@dots{}}))}.@examplem4_define([ab],[1])m4_define([bc],[2])m4_define([abc],[3])dnlm4_do([a],[b])c@result{}abcm4_unquote(m4_join([],[a],[b]))c@result{}3m4_define([a],[A])m4_define([b],[B])m4_define([c],[C])dnlm4_define([AB],[4])m4_define([BC],[5])m4_define([ABC],[6])dnlm4_do([a],[b])c@result{}ABCm4_unquote(m4_join([],[a],[b]))c@result{}3@end example@end defmac@defmac m4_dquote (@var{arg}, @dots{})@msindex{dquote}Return the arguments as a quoted list of quoted arguments.Conveniently, if there is just one @var{arg}, this effectively adds alevel of quoting.@end defmac@defmac m4_dquote_elt (@var{arg}, @dots{})@msindex{dquote_elt}Return the arguments as a series of double-quoted arguments.  Whereas@code{m4_dquote} returns a single argument, @code{m4_dquote_elt} returnsas many arguments as it was passed.@end defmac@defmac m4_echo (@var{arg}, @dots{})@msindex{echo}Return the arguments, with the same level of quoting.  Other thandiscarding whitespace after unquoted commas, this macro is a no-op.@end defmac@defmac m4_expand (@var{arg})@msindex{expand}Return the expansion of @var{arg} as a quoted string.  Whereas@code{m4_quote} is designed to collect expanded text into a singleargument, @code{m4_expand} is designed to perform one level of expansionon quoted text.  One distinction is in the treatment of whitespacefollowing a comma in the original @var{arg}.  Any time multiplearguments are collected into one with @code{m4_quote}, the M4 argumentcollection rules discard the whitespace.  However, with @code{m4_expand},whitespace is preserved, even after the expansion of macros contained in@var{arg}.  Additionally, @code{m4_expand} is able to expand text thatwould involve an unterminated comment, whereas expanding that same textas the argument to @code{m4_quote} runs into difficulty in finding theend of the argument.  Since manipulating diversions during argumentcollection is inherently unsafe, @code{m4_expand} issues an error if@var{arg} attempts to change the current diversion (@pxref{Diversionsupport}).@examplem4_define([active], [ACT, IVE])dnlm4_define([active2], [[ACT, IVE]])dnlm4_quote(active, active)@result{}ACT,IVE,ACT,IVEm4_expand([active, active])@result{}ACT, IVE, ACT, IVEm4_quote(active2, active2)@result{}ACT, IVE,ACT, IVEm4_expand([active2, active2])@result{}ACT, IVE, ACT, IVEm4_expand([# m4_echo])@result{}# m4_echom4_quote(# m4_echo))@result{}# m4_echo)@result{}@end exampleNote that @code{m4_expand} cannot handle an @var{arg} that expands toliteral unbalanced quotes, but that quadrigraphs can be used whenunbalanced output is necessary.  Likewise, unbalanced parentheses shouldbe supplied with double quoting or a quadrigraph.@examplem4_define([pattern], [[!@@<:@@]])dnlm4_define([bar], [BAR])dnlm4_expand([case $foo in  m4_defn([pattern])@@:@}@@ bar ;;  *[)] blah ;;esac])@result{}case $foo in@result{}  [![]) BAR ;;@result{}  *) blah ;;@result{}esac@end example@end defmac@defmac m4_ignore (@dots{})@msindex{ignore}This macro was introduced in Autoconf 2.62.  Expands to nothing,ignoring all of its arguments.  By itself, this isn't very useful.However, it can be used to conditionally ignore an arbitrary number ofarguments, by deciding which macro name to apply to a list of arguments.@examplednl foo outputs a message only if [debug] is defined.m4_define([foo],[m4_ifdef([debug],[AC_MSG_NOTICE],[m4_ignore])([debug message])])@end exampleNote that for earlier versions of Autoconf, the macro @code{__gnu__} canserve the same purpose, although it is less readable.@end defmac@defmac m4_make_list (@var{arg}, @dots{})@msindex{make_list}This macro exists to aid debugging of M4sugar algorithms.  Its neteffect is similar to @code{m4_dquote}---it produces a quoted list ofquoted arguments, for each @var{arg}.  The difference is that thisversion uses a comma-newline separator instead of just comma, to improvereadability of the list; with the result that it is less efficient than@code{m4_dquote}.@examplem4_define([zero],[0])m4_define([one],[1])m4_define([two],[2])dnlm4_dquote(zero, [one], [[two]])@result{}[0],[one],[[two]]m4_make_list(zero, [one], [[two]])@result{}[0],@result{}[one],@result{}[[two]]m4_foreach([number], m4_dquote(zero, [one], [[two]]), [ number])@result{} 0 1 twom4_foreach([number], m4_make_list(zero, [one], [[two]]), [ number])@result{} 0 1 two@end example@end defmac@c m4_noquote is too dangerous to document - it invokes macros that@c probably rely on @samp{[]} nested quoting for proper operation.  The@c user should generally prefer m4_unquote instead.@defmac m4_quote (@var{arg}, @dots{})@msindex{quote}Return the arguments as a single entity, i.e., wrap them into a pair ofquotes.  This effectively collapses multiple arguments into one,although it loses whitespace after unquoted commas in the process.@end defmac@defmac m4_reverse (@var{arg}, @dots{})@msindex{reverse}Outputs each argument with the same level of quoting, but in reverseorder, and with space following each comma for readability.@examplem4_define([active], [ACT,IVE])@result{}m4_reverse(active, [active])@result{}active, IVE, ACT@end example@end defmac@defmac m4_unquote (@var{arg}, @dots{})@msindex{unquote}This macro was introduced in Autoconf 2.62.  Expand each argument,separated by commas.  For a single @var{arg}, this effectively removes alayer of quoting, and @code{m4_unquote([@var{arg}])} is more efficientthan the equivalent @code{m4_do([@var{arg}])}.  For multiple arguments,this results in an unquoted list of expansions.  This is commonly usedwith @code{m4_split}, in order to convert a single quoted list into aseries of quoted elements.@end defmacThe following example aims at emphasizing the difference between severalscenarios: not using these macros, using @code{m4_defn}, using@code{m4_quote}, using @code{m4_dquote}, and using @code{m4_expand}.@example$ @kbd{cat example.m4}dnl Overquote, so that quotes are visible.m4_define([show], [$[]1 = [$1], $[]@@ = [$@@]])m4_define([a], [A])m4_define([mkargs], [1, 2[,] 3])m4_define([arg1], [[$1]])m4_divert([0])dnlshow(a, b)show([a, b])show(m4_quote(a, b))show(m4_dquote(a, b))show(m4_expand([a, b]))arg1(mkargs)arg1([mkargs])arg1(m4_defn([mkargs]))arg1(m4_quote(mkargs))arg1(m4_dquote(mkargs))arg1(m4_expand([mkargs]))$ @kbd{autom4te -l m4sugar example.m4}$1 = A, $@@ = [A],[b]$1 = a, b, $@@ = [a, b]$1 = A,b, $@@ = [A,b]$1 = [A],[b], $@@ = [[A],[b]]$1 = A, b, $@@ = [A, b]1mkargs1, 2[,] 31,2, 3[1],[2, 3]1, 2, 3@end example@node Text processing Macros@subsection String manipulation in M4The following macros may be used to manipulate strings in M4.  Many ofthe macros in this section intentionally result in quoted strings asoutput, rather than subjecting the arguments to further expansions.  Asa result, if you are manipulating text that contains active M4characters, the arguments are passed with single quoting rather thandouble.@defmac m4_append (@var{macro-name}, @var{string}, @ovar{separator})@defmacx m4_append_uniq (@var{macro-name}, @var{string}, @ovar{separator} @  @ovar{if-uniq}, @ovar{if-duplicate})@msindex{append}@msindex{append_uniq}Redefine @var{macro-name} to its former contents with @var{separator}and @var{string} added at the end.  If @var{macro-name} was undefinedbefore (but not if it was defined but empty), then no @var{separator} isadded.  As of Autoconf 2.62, neither @var{string} nor @var{separator}are expanded during this macro; instead, they are expanded when@var{macro-name} is invoked.@code{m4_append} can be used to grow strings, and @code{m4_append_uniq}to grow strings without duplicating substrings.  Additionally,@code{m4_append_uniq} takes two optional parameters as of Autoconf 2.62;@var{if-uniq} is expanded if @var{string} was appended, and@var{if-duplicate} is expanded if @var{string} was already present.Also, @code{m4_append_uniq} warns if @var{separator} is not empty, butoccurs within @var{string}, since that can lead to duplicates.Note that @code{m4_append} can scale linearly in the length of the finalstring, depending on the quality of the underlying M4 implementation,while @code{m4_append_uniq} has an inherent quadratic scaling factor.If an algorithm can tolerate duplicates in the final string, use theformer for speed.  If duplicates must be avoided, consider using@code{m4_set_add} instead (@pxref{Set manipulation Macros}).@examplem4_define([active], [ACTIVE])dnlm4_append([sentence], [This is an])dnlm4_append([sentence], [ active ])dnlm4_append([sentence], [symbol.])dnlsentence@result{}This is an ACTIVE symbol.m4_undefine([active])dnl@result{}This is an active symbol.m4_append_uniq([list], [one], [, ], [new], [existing])@result{}newm4_append_uniq([list], [one], [, ], [new], [existing])@result{}existingm4_append_uniq([list], [two], [, ], [new], [existing])@result{}newm4_append_uniq([list], [three], [, ], [new], [existing])@result{}newm4_append_uniq([list], [two], [, ], [new], [existing])@result{}existinglist@result{}one, two, threem4_dquote(list)@result{}[one],[two],[three]m4_append([list2], [one], [[, ]])dnlm4_append_uniq([list2], [two], [[, ]])dnlm4_append([list2], [three], [[, ]])dnllist2@result{}one, two, threem4_dquote(list2)@result{}[one, two, three]@end example@end defmac@defmac m4_append_uniq_w (@var{macro-name}, @var{strings})@msindex{append_uniq_w}This macro was introduced in Autoconf 2.62.  It is similar to@code{m4_append_uniq}, but treats @var{strings} as a whitespaceseparated list of words to append, and only appends unique words.@var{macro-name} is updated with a single space between new words.@examplem4_append_uniq_w([numbers], [1 1 2])dnlm4_append_uniq_w([numbers], [ 2 3 ])dnlnumbers@result{}1 2 3@end example@end defmac@defmac m4_chomp (@var{string})@defmacx m4_chomp_all (@var{string})@msindex{chomp}@msindex{chomp_all}Output @var{string} in quotes, but without a trailing newline.  Themacro @code{m4_chomp} is slightly faster, and removes at most onenewline; the macro @code{m4_chomp_all} removes all consecutive trailingnewlines.  Unlike @code{m4_flatten}, embedded newlines are left intact,and backslash does not influence the result.@end defmac@defmac m4_combine (@ovar{separator}, @var{prefix-list}, @ovar{infix}, @  @var{suffix-1}, @ovar{suffix-2}, @dots{})@msindex{combine}This macro produces a quoted string containing the pairwise combinationof every element of the quoted, comma-separated @var{prefix-list}, andevery element from the @var{suffix} arguments.  Each pairwisecombination is joined with @var{infix} in the middle, and successivepairs are joined by @var{separator}.  No expansion occurs on any of thearguments.  No output occurs if either the @var{prefix} or @var{suffix}list is empty, but the lists can contain empty elements.@examplem4_define([a], [oops])dnlm4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])@result{}a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3m4_combine([, ], [[a], [b]], [-])@result{}m4_combine([, ], [[a], [b]], [-], [])@result{}a-, b-m4_combine([, ], [], [-], [1], [2])@result{}m4_combine([, ], [[]], [-], [1], [2])@result{}-1, -2@end example@end defmac@defmac m4_escape (@var{string})@msindex{escape}Convert all instances of @samp{[}, @samp{]}, @samp{#}, and @samp{$}within @var{string} into their respective quadrigraphs.  The result isstill a quoted string.@end defmac@defmac m4_flatten (@var{string})@msindex{flatten}Flatten @var{string} into a single line.  Delete all backslash-newlinepairs, and replace all remaining newlines with a space.  The result isstill a quoted string.@end defmac@defmac m4_join (@ovar{separator}, @var{args}@dots{})@defmacx m4_joinall (@ovar{separator}, @var{args}@dots{})@msindex{join}@msindex{joinall}Concatenate each @var{arg}, separated by @var{separator}.@code{joinall} uses every argument, while @code{join} omits emptyarguments so that there are no back-to-back separators in the output.The result is a quoted string.@examplem4_define([active], [ACTIVE])dnlm4_join([|], [one], [], [active], [two])@result{}one|active|twom4_joinall([|], [one], [], [active], [two])@result{}one||active|two@end exampleNote that if all you intend to do is join @var{args} with commas betweenthem, to form a quoted list suitable for @code{m4_foreach}, it is moreefficient to use @code{m4_dquote}.@end defmac@defmac m4_newline (@ovar{text})@msindex{newline}This macro was introduced in Autoconf 2.62, and expands to a newline,followed by any @var{text}.It is primarily useful for maintaining macro formatting, and ensuringthat M4 does not discard leading whitespace during argument collection.@end defmac@defmac m4_normalize (@var{string})@msindex{normalize}Remove leading and trailing spaces and tabs, sequences ofbackslash-then-newline, and replace multiple spaces, tabs, and newlineswith a single space.  This is a combination of @code{m4_flatten} and@code{m4_strip}.  To determine if @var{string} consists only of bytesthat would be removed by @code{m4_normalize}, you can use@code{m4_ifblank}.@end defmac@defmac m4_re_escape (@var{string})@msindex{re_escape}Backslash-escape all characters in @var{string} that are active inregexps.@end defmac@c We cannot use @dvar because the macro expansion mistreats backslashes.@defmac m4_split (@var{string}, @r{[}@var{regexp} = @samp{[\t ]+}@r{]})@msindex{split}Split @var{string} into an M4 list of elements quoted by @samp{[} and@samp{]}, while keeping white space at the beginning and at the end.If @var{regexp} is given, use it instead of @samp{[\t ]+} for splitting.If @var{string} is empty, the result is an empty list.@end defmac@defmac m4_strip (@var{string})@msindex{strip}Strip whitespace from @var{string}.  Sequences of spaces and tabs arereduced to a single space, then leading and trailing spaces are removed.The result is still a quoted string.  Note that this does not interferewith newlines; if you want newlines stripped as well, consider@code{m4_flatten}, or do it all at once with @code{m4_normalize}.  Toquickly test if @var{string} has only whitespace, use @code{m4_ifblank}.@end defmac@defmac m4_text_box (@var{message}, @dvar{frame, -})@msindex{text_box}Add a text box around @var{message}, using @var{frame} as the bordercharacter above and below the message.  The @var{frame} argument must bea single byte, and does not support quadrigraphs.The frame correctly accounts forthe subsequent expansion of @var{message}.  For example:@examplem4_define([macro], [abc])dnlm4_text_box([macro])@result{}## --- ##@result{}## abc ##@result{}## --- ##@end exampleThe @var{message} must contain balanced quotes and parentheses, althoughquadrigraphs can be used to work around this.@end defmac@defmac m4_text_wrap (@var{string}, @ovar{prefix}, @  @dvar{prefix1, @var{prefix}}, @dvar{width, 79})@msindex{text_wrap}Break @var{string} into a series of whitespace-separated words, thenoutput those words separated by spaces, and wrapping lines any time theoutput would exceed @var{width} columns.  If given, @var{prefix1} beginsthe first line, and @var{prefix} begins all wrapped lines.  If@var{prefix1} is longer than @var{prefix}, then the first line consistsof just @var{prefix1}.  If @var{prefix} is longer than @var{prefix1},padding is inserted so that the first word of @var{string} begins at thesame indentation as all wrapped lines.  Note that using literal tabcharacters in any of the arguments will interfere with the calculationof width.  No expansions occur on @var{prefix}, @var{prefix1}, or thewords of @var{string}, although quadrigraphs are recognized.For some examples:@examplem4_text_wrap([Short string */], [   ], [/* ], [20])@result{}/* Short string */m4_text_wrap([Much longer string */], [   ], [/* ], [20])@result{}/* Much longer@result{}   string */m4_text_wrap([Short doc.], [          ], [  --short ], [30])@result{}  --short Short doc.m4_text_wrap([Short doc.], [          ], [  --too-wide ], [30])@result{}  --too-wide@result{}          Short doc.m4_text_wrap([Super long documentation.], [     ],             [  --too-wide ], 30)@result{}  --too-wide@result{}     Super long@result{}     documentation.@end example@end defmac@defmac m4_tolower (@var{string})@defmacx m4_toupper (@var{string})@msindex{tolower}@msindex{toupper}Return @var{string} with letters converted to upper or lower case,respectively.@end defmac@node Number processing Macros@subsection Arithmetic computation in M4The following macros facilitate integer arithmetic operations.Where a parameter is documented as taking an arithmetic expression, youcan use anything that can be parsed by @code{m4_eval}.@defmac m4_cmp (@var{expr-1}, @var{expr-2})@msindex{cmp}Compare the arithmetic expressions @var{expr-1} and @var{expr-2}, andexpand to @samp{-1} if @var{expr-1} is smaller, @samp{0} if they areequal, and @samp{1} if @var{expr-1} is larger.@end defmac@defmac m4_list_cmp (@var{list-1}, @var{list-2})@msindex{list_cmp}Compare the two M4 lists consisting of comma-separated arithmeticexpressions, left to right.  Expand to @samp{-1} for the first elementpairing where the value from @var{list-1} is smaller, @samp{1} where thevalue from @var{list-2} is smaller, or @samp{0} if both lists have thesame values.  If one list is shorter than the other, the remainingelements of the longer list are compared against zero.@examplem4_list_cmp([1, 0],       [1])@result{}0m4_list_cmp([1, [1 * 0]], [1, 0])@result{}0m4_list_cmp([1, 2],       [1, 0])@result{}1m4_list_cmp([1, [1+1], 3],[1, 2])@result{}1m4_list_cmp([1, 2, -3],   [1, 2])@result{}-1m4_list_cmp([1, 0],       [1, 2])@result{}-1m4_list_cmp([1],          [1, 2])@result{}-1@end example@end defmac@defmac m4_max (@var{arg}, @dots{})@msindex{max}This macro was introduced in Autoconf 2.62.  Expand to the decimal valueof the maximum arithmetic expression among all the arguments.@end defmac@defmac m4_min (@var{arg}, @dots{})@msindex{min}This macro was introduced in Autoconf 2.62.  Expand to the decimal valueof the minimum arithmetic expression among all the arguments.@end defmac@defmac m4_sign (@var{expr})@msindex{sign}Expand to @samp{-1} if the arithmetic expression @var{expr} is negative,@samp{1} if it is positive, and @samp{0} if it is zero.@end defmac@anchor{m4_version_compare}@defmac m4_version_compare (@var{version-1}, @var{version-2})@msindex{version_compare}This macro was introduced in Autoconf 2.53, but had a number ofusability limitations that were not lifted until Autoconf 2.62.  Comparethe version strings @var{version-1} and @var{version-2}, and expand to@samp{-1} if @var{version-1} is smaller, @samp{0} if they are the same,or @samp{1} @var{version-2} is smaller.  Version strings must be a listof elements separated by @samp{.}, @samp{,} or @samp{-}, where eachelement is a number along with optional case-insensitive lettersdesignating beta releases.  The comparison stops at the leftmost elementthat contains a difference, although a 0 element compares equal to amissing element.It is permissible to include commit identifiers in @var{version}, suchas an abbreviated SHA1 of the commit, provided there is still amonotonically increasing prefix to allow for accurate version-basedcomparisons.  For example, this paragraph was written when thedevelopment snapshot of autoconf claimed to be at version@samp{2.61a-248-dc51}, or 248 commits after the 2.61a release, with anabbreviated commit identification of @samp{dc51}.@examplem4_version_compare([1.1], [2.0])@result{}-1m4_version_compare([2.0b], [2.0a])@result{}1m4_version_compare([1.1.1], [1.1.1a])@result{}-1m4_version_compare([1.2], [1.1.1a])@result{}1m4_version_compare([1.0], [1])@result{}0m4_version_compare([1.1pre], [1.1PRE])@result{}0m4_version_compare([1.1a], [1,10])@result{}-1m4_version_compare([2.61a], [2.61a-248-dc51])@result{}-1m4_version_compare([2.61b], [2.61a-248-dc51])@result{}1@end example@end defmac@defmac m4_version_prereq (@var{version}, @ovar{if-new-enough}, @  @dvar{if-old, m4_fatal})@msindex{version_prereq}Compares @var{version} against the version of Autoconf currentlyrunning.  If the running version is at @var{version} or newer, expand@var{if-new-enough}, but if @var{version} is larger than the versioncurrently executing, expand @var{if-old}, which defaults to printing anerror message and exiting m4sugar with status 63.  When given only oneargument, this behaves like @code{AC_PREREQ} (@pxref{Versioning}).Remember that the autoconf philosophy favors feature checks over versionchecks.@end defmac@node Set manipulation Macros@subsection Set manipulation in M4@cindex Set manipulation@cindex Data structure, set@cindex Unordered set manipulationSometimes, it is necessary to track a set of data, where the order doesnot matter and where there are no duplicates in the set.  The followingmacros facilitate set manipulations.  Each set is an opaque object,which can only be accessed via these basic operations.  The underlyingimplementation guarantees linear scaling for set creation, which is moreefficient than using the quadratic @code{m4_append_uniq}.  Both setnames and values can be arbitrary strings, except for unbalanced quotes.This implementation ties up memory for removed elements until the nextoperation that must traverse all the elements of a set; and althoughthat may slow down some operations until the memory for removed elementsis pruned, it still guarantees linear performance.@defmac m4_set_add (@var{set}, @var{value}, @ovar{if-uniq}, @ovar{if-dup})@msindex{set_add}Adds the string @var{value} as a member of set @var{set}.  Expand@var{if-uniq} if the element was added, or @var{if-dup} if it waspreviously in the set.  Operates in amortized constant time, so that setcreation scales linearly.@end defmac@defmac m4_set_add_all (@var{set}, @var{value}@dots{})@msindex{set_add_all}Adds each @var{value} to the set @var{set}.  This is slightly moreefficient than repeatedly invoking @code{m4_set_add}.@end defmac@defmac m4_set_contains (@var{set}, @var{value}, @ovar{if-present}, @ @ovar{if-absent})@msindex{set_contains}Expands @var{if-present} if the string @var{value} is a member of@var{set}, otherwise @var{if-absent}.@examplem4_set_contains([a], [1], [yes], [no])@result{}nom4_set_add([a], [1], [added], [dup])@result{}addedm4_set_add([a], [1], [added], [dup])@result{}dupm4_set_contains([a], [1], [yes], [no])@result{}yesm4_set_remove([a], [1], [removed], [missing])@result{}removedm4_set_contains([a], [1], [yes], [no])@result{}nom4_set_remove([a], [1], [removed], [missing])@result{}missing@end example@end defmac@defmac m4_set_contents (@var{set}, @ovar{sep})@defmacx m4_set_dump (@var{set}, @ovar{sep})@msindex{set_contents}@msindex{set_dump}Expands to a single string consisting of all the members of the set@var{set}, each separated by @var{sep}, which is not expanded.@code{m4_set_contents} leaves the elements in @var{set} but reclaims anymemory occupied by removed elements, while @code{m4_set_dump} is afaster one-shot action that also deletes the set.  No provision is madefor disambiguating members that contain a non-empty @var{sep} as asubstring; use @code{m4_set_empty} to distinguish between an empty setand the set containing only the empty string.  The order of the outputis unspecified; in the current implementation, part of the speed of@code{m4_set_dump} results from using a different output order than@code{m4_set_contents}.  These macros scale linearly in the size of theset before memory pruning, and @code{m4_set_contents([@var{set}],[@var{sep}])} is faster than@code{m4_joinall([@var{sep}]m4_set_listc([@var{set}]))}.@examplem4_set_add_all([a], [1], [2], [3])@result{}m4_set_contents([a], [-])@result{}1-2-3m4_joinall([-]m4_set_listc([a]))@result{}1-2-3m4_set_dump([a], [-])@result{}3-2-1m4_set_contents([a])@result{}m4_set_add([a], [])@result{}m4_set_contents([a], [-])@result{}@end example@end defmac@defmac m4_set_delete (@var{set})@msindex{set_delete}Delete all elements and memory associated with @var{set}.  This islinear in the set size, and faster than removing one element at a time.@end defmac@defmac m4_set_difference (@var{seta}, @var{setb})@defmacx m4_set_intersection (@var{seta}, @var{setb})@defmacx m4_set_union (@var{seta}, @var{setb})@msindex{set_difference}@msindex{set_intersection}@msindex{set_union}Compute the relation between @var{seta} and @var{setb}, and output theresult as a list of quoted arguments without duplicates and with aleading comma.  Set difference selects the elements in @var{seta} butnot @var{setb}, intersection selects only elements in both sets, andunion selects elements in either set.  These actions are linear in thesum of the set sizes.  The leading comma is necessary to distinguishbetween no elements and the empty string as the only element.@examplem4_set_add_all([a], [1], [2], [3])@result{}m4_set_add_all([b], [3], [], [4])@result{}m4_set_difference([a], [b])@result{},1,2m4_set_difference([b], [a])@result{},,4m4_set_intersection([a], [b])@result{},3m4_set_union([a], [b])@result{},1,2,3,,4@end example@end defmac@defmac m4_set_empty (@var{set}, @ovar{if-empty}, @ovar{if-elements})@msindex{set_empty}Expand @var{if-empty} if the set @var{set} has no elements, otherwiseexpand @var{if-elements}.  This macro operates in constant time.  Usingthis macro can help disambiguate output from @code{m4_set_contents} or@code{m4_set_list}.@end defmac@defmac m4_set_foreach (@var{set}, @var{variable}, @var{action})@msindex{set_foreach}For each element in the set @var{set}, expand @var{action} with themacro @var{variable} defined as the set element.  Behavior isunspecified if @var{action} recursively lists the contents of @var{set}(although listing other sets is acceptable), or if it modifies the setin any way other than removing the element currently contained in@var{variable}.  This macro is faster than the corresponding@code{m4_foreach([@var{variable}],m4_indir([m4_dquote]m4_set_listc([@var{set}])), [@var{action}])},although @code{m4_set_map} might be faster still.@examplem4_set_add_all([a]m4_for([i], [1], [5], [], [,i]))@result{}m4_set_contents([a])@result{}12345m4_set_foreach([a], [i],  [m4_if(m4_eval(i&1), [0], [m4_set_remove([a], i, [i])])])@result{}24m4_set_contents([a])@result{}135@end example@end defmac@defmac m4_set_list (@var{set})@defmacx m4_set_listc (@var{set})@msindex{set_list}@msindex{set_listc}Produce a list of arguments, where each argument is a quoted elementfrom the set @var{set}.  The variant @code{m4_set_listc} is unambiguous,by adding a leading comma if there are any set elements, whereas thevariant @code{m4_set_list} cannot distinguish between an empty set and aset containing only the empty string.  These can be directly used inmacros that take multiple arguments, such as @code{m4_join} or@code{m4_set_add_all}, or wrapped by @code{m4_dquote} for macros thattake a quoted list, such as @code{m4_map} or @code{m4_foreach}.  Anymemory occupied by removed elements is reclaimed during these macros.@examplem4_set_add_all([a], [1], [2], [3])@result{}m4_set_list([a])@result{}1,2,3m4_set_list([b])@result{}m4_set_listc([b])@result{}m4_count(m4_set_list([b]))@result{}1m4_set_empty([b], [0], [m4_count(m4_set_list([b]))])@result{}0m4_set_add([b], [])@result{}m4_set_list([b])@result{}m4_set_listc([b])@result{},m4_count(m4_set_list([b]))@result{}1m4_set_empty([b], [0], [m4_count(m4_set_list([b]))])@result{}1@end example@end defmac@defmac m4_set_map (@var{set}, @var{action})@msindex{set_map}For each element in the set @var{set}, expand @var{action} with a singleargument of the set element.  Behavior is unspecified if @var{action}recursively lists the contents of @var{set} (although listing other setsis acceptable), or if it modifies the set in any way other than removingthe element passed as an argument.  This macro is faster than eithercorresponding counterpart of@code{m4_map_args([@var{action}]m4_set_listc([@var{set}]))} or@code{m4_set_foreach([@var{set}], [var],[@var{action}(m4_defn([var]))])}.  It is possible to use @code{m4_curry}if more than one argument is needed for @var{action}, although it ismore efficient to use @code{m4_set_map_sep} in that case.@end defmac@defmac m4_set_map_sep (@var{set}, @ovar{pre}, @ovar{post}, @ovar{sep})@msindex{set_map_sep}For each element in the set @var{set}, expand@code{@var{pre}[element]@var{post}}, additionally expanding @var{sep}between elements.  Behavior is unspecified if the expansion recursivelylists the contents of @var{set} (although listing other setsis acceptable), or if it modifies the set in any way other than removingthe element visited by the expansion.  This macro provides the mostefficient means for non-destructively visiting the elements of a set; inparticular, @code{m4_set_map([@var{set}], [@var{action}])} is equivalentto @code{m4_set_map_sep([@var{set}], [@var{action}(], [)])}.@end defmac@defmac m4_set_remove (@var{set}, @var{value}, @ovar{if-present}, @ @ovar{if-absent})@msindex{set_remove}If @var{value} is an element in the set @var{set}, then remove it andexpand @var{if-present}.  Otherwise expand @var{if-absent}.  This macrooperates in constant time so that multiple removals will scale linearlyrather than quadratically; but when used outside of@code{m4_set_foreach} or @code{m4_set_map}, it leaves memory occupieduntil the set is latercompacted by @code{m4_set_contents} or @code{m4_set_list}.  Severalother set operations are then less efficient between the time of elementremoval and subsequent memory compaction, but still maintain theirguaranteed scaling performance.@end defmac@defmac m4_set_size (@var{set})@msindex{set_size}Expand to the size of the set @var{set}.  This implementation operatesin constant time, and is thus more efficient than@code{m4_eval(m4_count(m4_set_listc([set])) - 1)}.@end defmac@node Forbidden Patterns@subsection Forbidden Patterns@cindex Forbidden patterns@cindex Patterns, forbiddenM4sugar provides a means to define suspicious patterns, patternsdescribing tokens which should not be found in the output.  Forinstance, if an Autoconf @file{configure} script includes tokens such as@samp{AC_DEFINE}, or @samp{dnl}, then most probably something wentwrong (typically a macro was not evaluated because of overquotation).M4sugar forbids all the tokens matching @samp{^_?m4_} and @samp{^dnl$}.Additional layers, such as M4sh and Autoconf, add additional forbiddenpatterns to the list.@defmac m4_pattern_forbid (@var{pattern})@msindex{pattern_forbid}Declare that no token matching @var{pattern} must be found in the output.Comments are not checked; this can be a problem if, for instance, youhave some macro left unexpanded after an @samp{#include}.  No consensusis currently found in the Autoconf community, as some people consider itshould be valid to name macros in comments (which doesn't make sense tothe authors of this documentation: input, such as macros, should bedocumented by @samp{dnl} comments; reserving @samp{#}-comments todocument the output).@end defmacOf course, you might encounter exceptions to these generic rules, forinstance you might have to refer to @samp{$m4_flags}.@defmac m4_pattern_allow (@var{pattern})@msindex{pattern_allow}Any token matching @var{pattern} is allowed, including if it matches an@code{m4_pattern_forbid} pattern.@end defmac@node Debugging via autom4te@section Debugging via autom4te@cindex debugging tips@cindex autom4te debugging tips@cindex m4sugar debugging tipsAt times, it is desirable to see what was happening inside m4, to seewhy output was not matching expectations.  However, post-processing doneby @command{autom4te} means that directly using the m4 builtin@code{m4_traceon} is likely to interfere with operation.  Also, frequentdiversion changes and the concept of forbidden tokens make it difficultto use @code{m4_defn} to generate inline comments in the final output.There are a couple of tools to help with this.  One is the use of the@option{--trace} option provided by @command{autom4te} (as well as eachof the programs that wrap @command{autom4te}, such as@command{autoconf}), in order to inspect when a macro is called and withwhich arguments.  For example, when this paragraph was written, theautoconf version could be found by:@example$ @kbd{autoconf --trace=AC_INIT}configure.ac:23:AC_INIT:GNU Autoconf:2.63b.95-3963:bug-autoconf@@gnu.org$ @kbd{autoconf --trace='AC_INIT:version is $2'}version is 2.63b.95-3963@end exampleAnother trick is to print out the expansion of various m4 expressions tostandard error or to an independent file, with no further m4 expansion,and without interfering with diversion changes or the post-processingdone to standard output.  @code{m4_errprintn} shows a given expressionon standard error.  For example, if you want to see the expansion of anautoconf primitive or of one of your autoconf macros, you can do it likethis:@example$ @kbd{cat <<\EOF > configure.ac}AC_INITm4_errprintn([The definition of AC_DEFINE_UNQUOTED:])m4_errprintn(m4_defn([AC_DEFINE_UNQUOTED]))AC_OUTPUTEOF$ @kbd{autoconf}@error{}The definition of AC_DEFINE_UNQUOTED:@error{}_AC_DEFINE_Q([], $@@)@end example@node Programming in M4sh@chapter Programming in M4shM4sh, pronounced ``mash'', is aiming at producing portable Bourne shellscripts.  This name was coined by Lars J. Aas, who notes that,according to the Webster's Revised Unabridged Dictionary (1913):@quotationMash \Mash\, n.  [Akin to G. meisch, maisch, meische, maische, mash,wash, and prob.@: to AS. miscian to mix.  See ``Mix''.]@enumerate 1@itemA mass of mixed ingredients reduced to a soft pulpy state by beating orpressure@enddots{}@itemA mixture of meal or bran and water fed to animals.@itemA mess; trouble.  [Obs.] --Beau.@: & Fl.@end enumerate@end quotationM4sh reserves the M4 macro namespace @samp{^_AS_} for internal use, andthe namespace @samp{^AS_} for M4sh macros.  It also reserves the shelland environment variable namespace @samp{^as_}, and the here-documentdelimiter namespace @samp{^_AS[A-Z]} in the output file.  You should notdefine your own macros or output shell code that conflicts with thesenamespaces.@menu* Common Shell Constructs::     Portability layer for common shell constructs* Polymorphic Variables::       Support for indirect variable names* Initialization Macros::       Macros to establish a sane shell environment* File Descriptor Macros::      File descriptor macros for input and output@end menu@node Common Shell Constructs@section Common Shell ConstructsM4sh provides portable alternatives for some common shell constructsthat unfortunately are not portable in practice.@c Deprecated, to be replaced by a better API@ignore@defmac AS_BASENAME (@var{file-name})@asindex{BASENAME}Output the non-directory portion of @var{file-name}.  For example,if @code{$file} is @samp{/one/two/three}, the command@code{base=`AS_BASENAME(["$file"])`} sets @code{base} to @samp{three}.@end defmac@end ignore@defmac AS_BOX (@var{text}, @dvar{char, -})@asindex{BOX}Expand into shell code that will output @var{text} surrounded by a boxwith @var{char} in the top and bottom border.  @var{text} should notcontain a newline, but may contain shell expansions valid for unquotedhere-documents.  @var{char} defaults to @samp{-}, but can be anycharacter except @samp{/}, @samp{'}, @samp{"}, @samp{\},@samp{&}, or @samp{`}.  This is useful for outputting a comment box intolog files to separate distinct phases of script operation.@end defmac@defmac AS_CASE (@var{word}, @ovar{pattern1}, @ovar{if-matched1}, @  @dots{}, @ovar{default})@asindex{CASE}Expand into a shell @samp{case} statement, where @var{word} is matchedagainst one or more patterns.  @var{if-matched} is run if thecorresponding pattern matched @var{word}, else @var{default} is run.Avoids several portability issues (@pxref{case, , Limitations of ShellBuiltins}).@end defmac@c Deprecated, to be replaced by a better API@defmac AS_DIRNAME (@var{file-name})@asindex{DIRNAME}Output the directory portion of @var{file-name}.  For example,if @code{$file} is @samp{/one/two/three}, the command@code{dir=`AS_DIRNAME(["$file"])`} sets @code{dir} to @samp{/one/two}.This interface may be improved in the future to avoid forks and losingtrailing newlines.@end defmac@defmac AS_ECHO (@var{word})@asindex{ECHO}Emits @var{word} to the standard output, followed by a newline.  @var{word}must be a single shell word (typically a quoted string).  The bytes of@var{word} are output as-is, even if it starts with "-" or contains "\".Redirections can be placed outside the macro invocation.  This is muchmore portable than using @command{echo} (@pxref{echo, , Limitations ofShell Builtins}).@end defmac@defmac AS_ECHO_N (@var{word})@asindex{ECHO_N}Emits @var{word} to the standard output, without a following newline.@var{word} must be a single shell word (typically a quoted string) and,for portability, should not include more than one newline.  The bytes of@var{word} are output as-is, even if it starts with "-" or contains "\".Redirections can be placed outside the macro invocation.@end defmac@c We cannot use @dvar because the macro expansion mistreats backslashes.@defmac AS_ESCAPE (@var{string}, @r{[}@var{chars} = @samp{`\"$}@r{]})@asindex{ESCAPE}Expands to @var{string}, with any characters in @var{chars} escaped witha backslash (@samp{\}).  @var{chars} should be at most four bytes long,and only contain characters from the set @samp{`\"$}; however,characters may be safely listed more than once in @var{chars} for thesake of syntax highlighting editors.  The current implementation expands@var{string} after adding escapes; if @var{string} contains macro callsthat in turn expand to text needing shell quoting, you can use@code{AS_ESCAPE(m4_dquote(m4_expand([string])))}.The default for @var{chars} (@samp{\"$`}) is the set of charactersneeding escapes when @var{string} will be used literally within doublequotes.  One common variant is the set of characters to protect when@var{string} will be used literally within back-ticks or an unquotedhere-document (@samp{\$`}).  Another common variant is @samp{""}, which canbe used to form a double-quoted string containing the same expansionsthat would have occurred if @var{string} were expanded in an unquotedhere-document; however, when using this variant, care must be taken that@var{string} does not use double quotes within complex variableexpansions (such as @samp{$@{foo-`echo "hi"`@}}) that would be brokenwith improper escapes.This macro is often used with @code{AS_ECHO}.  For an example, observethe output generated by the shell code generated from this snippet:@examplefoo=barAS_ECHO(["AS_ESCAPE(["$foo" = ])AS_ESCAPE(["$foo"], [""])"])@result{}"$foo" = "bar"m4_define([macro], [a, [\b]])AS_ECHO(["AS_ESCAPE([[macro]])"])@result{}macroAS_ECHO(["AS_ESCAPE([macro])"])@result{}a, bAS_ECHO(["AS_ESCAPE(m4_dquote(m4_expand([macro])))"])@result{}a, \b@end example@comment Should we add AS_ESCAPE_SINGLE? If we do, we can optimize in@comment the case of @var{string} that does not contain '.To escape a string that will be placed within single quotes, use:@examplem4_bpatsubst([[@var{string}]], ['], ['\\''])@end example@end defmac@defmac AS_EXECUTABLE_P (@var{file})@asindex{EXECUTABLE_P}Emit code to probe whether @var{file} is a regular file with executablepermissions (and not a directory with search permissions).  The calleris responsible for quoting @var{file}.@end defmac@defmac AS_EXIT (@dvar{status, $?})@asindex{EXIT}Emit code to exit the shell with @var{status}, defaulting to @samp{$?}.This macroworks around shells that see the exit status of the command prior to@code{exit} inside a @samp{trap 0} handler (@pxref{trap, , Limitationsof Shell Builtins}).@end defmac@defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false})@asindex{IF}Run shell code @var{test1}.  If @var{test1} exits with a zero status thenrun shell code @var{run-if-true1}, else examine further tests.  If no testexits with a zero status, run shell code @var{run-if-false}, withsimplifications if either @var{run-if-true1} or @var{run-if-false}is empty.  For example,@exampleAS_IF([test "x$foo" = xyes], [HANDLE_FOO([yes])],      [test "x$foo" != xno], [HANDLE_FOO([maybe])],      [echo foo not specified])@end example@noindentensures any required macros of @code{HANDLE_FOO}are expanded before the first test.@end defmac@defmac AS_MKDIR_P (@var{file-name})@asindex{MKDIR_P}Make the directory @var{file-name}, including intervening directoriesas necessary.  This is equivalent to @samp{mkdir -p -- @var{file-name}},except that it is portable to older versions of @command{mkdir} thatlack support for the @option{-p} option or for the @option{--}delimiter (@pxref{mkdir, , Limitations of Usual Tools}).  Also,@code{AS_MKDIR_P}succeeds if @var{file-name} is a symbolic link to an existing directory,even though Posix is unclear whether @samp{mkdir -p} shouldsucceed in that case.  If creation of @var{file-name} fails, exit thescript.Also see the @code{AC_PROG_MKDIR_P} macro (@pxref{Particular Programs}).@end defmac@defmac AS_SET_STATUS (@var{status})@asindex{SET_STATUS}Emit shell code to set the value of @samp{$?} to @var{status}, asefficiently as possible.  However, this is not guaranteed to abort ashell running with @code{set -e} (@pxref{set, , Limitations of ShellBuiltins}).  This should also be used at the end of a complex shellfunction instead of @samp{return} (@pxref{Shell Functions}) to avoida DJGPP shell bug.@end defmac@defmac AS_TR_CPP (@var{expression})@asindex{TR_CPP}Transform @var{expression} into a valid right-hand side for a C @code{#define}.For example:@example# This outputs "#define HAVE_CHAR_P 1".# Notice the m4 quoting around #, to prevent an m4 commenttype="char *"echo "[#]define AS_TR_CPP([HAVE_$type]) 1"@end example@end defmac@defmac AS_TR_SH (@var{expression})@asindex{TR_SH}Transform @var{expression} into shell code that generates a valid shellvariable name.  The result is literal when possible at m4 time, but mustbe used with @code{eval} if @var{expression} causes shell indirections.For example:@example# This outputs "Have it!".header="sys/some file.h"eval AS_TR_SH([HAVE_$header])=yesif test "x$HAVE_sys_some_file_h" = xyes; then echo "Have it!"; fi@end example@end defmac@defmac AS_SET_CATFILE (@var{var}, @var{dir}, @var{file})@asindex{SET_CATFILE}Set the polymorphic shell variable @var{var} to @var{dir}/@var{file},but optimizing the common cases (@var{dir} or @var{file} is @samp{.},@var{file} is absolute, etc.).@end defmac@defmac AS_UNSET (@var{var})@asindex{UNSET}Unsets the shell variable @var{var}, working around bugs in oldershells (@pxref{unset, , Limitations of ShellBuiltins}).  @var{var} can be a literal or indirect variable name.@end defmac@defmac AS_VERSION_COMPARE (@var{version-1}, @var{version-2}, @  @ovar{action-if-less}, @ovar{action-if-equal}, @ovar{action-if-greater})@asindex{VERSION_COMPARE}Compare two strings @var{version-1} and @var{version-2}, possiblycontaining shell variables, as version strings, and expand@var{action-if-less}, @var{action-if-equal}, or @var{action-if-greater}depending upon the result.The algorithm to compare is similar to the one used by strverscmp inglibc (@pxref{String/Array Comparison, , String/Array Comparison, libc,The GNU C Library}).@end defmac@node Polymorphic Variables@section Support for indirect variable names@cindex variable name indirection@cindex polymorphic variable name@cindex indirection, variable nameOften, it is convenient to write a macro that will emit shell codeoperating on a shell variable.  The simplest case is when the variablename is known.  But a more powerful idiom is writing shell code that canwork through an indirection, where another variable or commandsubstitution produces the name of the variable to actually manipulate.M4sh supports the notion of polymorphic shell variables, making it easyto write a macro that can deal with either literal or indirect variablenames and output shell code appropriate for both use cases.  Behavior isundefined if expansion of an indirect variable does not result in aliteral variable name.@defmac AS_LITERAL_IF (@var{expression}, @ovar{if-literal}, @ovar{if-not}, @  @dvar{if-simple-ref, @var{if-not}})@defmacx AS_LITERAL_WORD_IF (@var{expression}, @ovar{if-literal}, @  @ovar{if-not}, @dvar{if-simple-ref, @var{if-not}})@asindex{LITERAL_IF}@asindex{LITERAL_WORD_IF}If the expansion of @var{expression} is definitely a shell literal,expand @var{if-literal}.  If the expansion of @var{expression} lookslike it might contain shell indirections (such as @code{$var} or@code{`expr`}), then @var{if-not} is expanded.  Sometimes, it ispossible to output optimized code if @var{expression} consists only ofshell variable expansions (such as @code{$@{var@}}), in which case@var{if-simple-ref} can be provided; but defaulting to @var{if-not}should always be safe.  @code{AS_LITERAL_WORD_IF} only expands@var{if-literal} if @var{expression} looks like a single shell word,containing no whitespace; while @code{AS_LITERAL_IF} allows whitespacein @var{expression}.In order to reduce the time spent recognizing whether an@var{expression} qualifies as a literal or a simple indirection, theimplementation is somewhat conservative: @var{expression} must be asingle shell word (possibly after stripping whitespace), consisting onlyof bytes that would have the same meaning whether unquoted or enclosedin double quotes (for example, @samp{a.b} results in @var{if-literal},even though it is not a valid shell variable name; while both @samp{'a'}and @samp{[$]} result in @var{if-not}, because they behave differentlythan @samp{"'a'"} and @samp{"[$]"}).  This macro can be used in contextsfor recognizing portable file names (such as in the implementation of@code{AC_LIBSOURCE}), or coupled with some transliterations for formingvalid variable names (such as in the implementation of @code{AS_TR_SH},which uses an additional @code{m4_translit} to convert @samp{.} to@samp{_}).This example shows how to read the contents of the shell variable@code{bar}, exercising all three arguments to @code{AS_LITERAL_IF}.  Itresults in a script that will output the line @samp{hello} three times.@exampleAC_DEFUN([MY_ACTION],[AS_LITERAL_IF([$1],  [echo "$$1"],@c $$  [AS_VAR_COPY([var], [$1])   echo "$var"],  [eval 'echo "$'"$1"\"])])foo=bar bar=helloMY_ACTION([bar])MY_ACTION([`echo bar`])MY_ACTION([$foo])@end example@end defmac@defmac AS_VAR_APPEND (@var{var}, @var{text})@asindex{VAR_APPEND}Emit shell code to append the shell expansion of @var{text} to the endof the current contents of the polymorphic shell variable @var{var},taking advantage of shells that provide the @samp{+=} extension for moreefficient scaling.For situations where the final contents of @var{var} are relativelyshort (less than 256 bytes), it is more efficient to use the simplercode sequence of @code{@var{var}=$@{@var{var}@}@var{text}} (or itspolymorphic equivalent of @code{AS_VAR_COPY([t], [@var{var}])} and@code{AS_VAR_SET([@var{var}], ["$t"@var{text}])}).  But in the casewhen the script will be repeatedly appending text into @code{var},issues of scaling start to become apparent.  A naive implementationrequires execution time linear to the length of the current contents of@var{var} as well as the length of @var{text} for a single append, foran overall quadratic scaling with multiple appends.  This macro takesadvantage of shells which provide the extension@code{@var{var}+=@var{text}}, which can provide amortized constant timefor a single append, for an overall linear scaling with multipleappends.  Note that unlike @code{AS_VAR_SET}, this macro requires that@var{text} be quoted properly to avoid field splitting and file nameexpansion.@end defmac@defmac AS_VAR_ARITH (@var{var}, @var{expression})@asindex{VAR_ARITH}Emit shell code to compute the arithmetic expansion of @var{expression},assigning the result as the contents of the polymorphic shell variable@var{var}.  The code takes advantage of shells that provide @samp{$(())}for fewer forks, but uses @command{expr} as a fallback.  Therefore, thesyntax for a valid @var{expression} is rather limited: all operatorsmust occur as separate shell arguments and with proper quoting, there isno portable equality operator, all variables containing numeric valuesmust be expanded prior to the computation, all numeric values must beprovided in decimal without leading zeroes, and the first shell argumentshould not be a negative number.  In the following example, this snippetwill print @samp{(2+3)*4 == 20}.@examplebar=3AS_VAR_ARITH([foo], [\( 2 + $bar \) \* 4])echo "(2+$bar)*4 == $foo"@end example@end defmac@defmac AS_VAR_COPY (@var{dest}, @var{source})@asindex{VAR_COPY}Emit shell code to assign the contents of the polymorphic shell variable@var{source} to the polymorphic shell variable @var{dest}.  For example,executing this M4sh snippet will output @samp{bar hi}:@examplefoo=bar bar=hiAS_VAR_COPY([a], [foo])AS_VAR_COPY([b], [$foo])echo "$a $b"@end exampleWhen it is necessary to access the contents of an indirect variableinside a shell double-quoted context, the recommended idiom is to firstcopy the contents into a temporary literal shell variable.@smallexamplefor header in stdint_h inttypes_h ; do  AS_VAR_COPY([var], [ac_cv_header_$header])  echo "$header detected: $var"done@end smallexample@end defmac@comment AS_VAR_GET is intentionally undocumented; it can't handle@comment trailing newlines uniformly, and forks too much.@defmac AS_VAR_IF (@var{var}, @ovar{word}, @ovar{if-equal}, @  @ovar{if-not-equal})@asindex{VAR_IF}Output a shell conditional statement.  If the contents of thepolymorphic shell variable @var{var} match the string @var{word},execute @var{if-equal}; otherwise execute @var{if-not-equal}.  @var{word}must be a single shell word (typically a quoted string).  Avoidsshell bugs if an interrupt signal arrives while a command substitutionin @var{var} is being expanded.@end defmac@defmac AS_VAR_PUSHDEF (@var{m4-name}, @var{value})@defmacx AS_VAR_POPDEF (@var{m4-name})@asindex{VAR_PUSHDEF}@asindex{VAR_POPDEF}@cindex composing variable names@cindex variable names, composingA common M4sh idiom involves composing shell variable names from an m4argument (for example, writing a macro that uses a cache variable).@var{value} can be an arbitrary string, which will be transliteratedinto a valid shell name by @code{AS_TR_SH}.  In order to access thecomposed variable name based on @var{value}, it is easier to declare atemporary m4 macro @var{m4-name} with @code{AS_VAR_PUSHDEF}, then usethat macro as the argument to subsequent @code{AS_VAR} macros as apolymorphic variable name, and finally free the temporary macro with@code{AS_VAR_POPDEF}.  These macros are often followed with @code{dnl},to avoid excess newlines in the output.Here is an involved example, that shows the power of writing macros thatcan handle composed shell variable names:@examplem4_define([MY_CHECK_HEADER],[AS_VAR_PUSHDEF([my_Header], [ac_cv_header_$1])dnlAS_VAR_IF([my_Header], [yes], [echo "header $1 detected"])dnlAS_VAR_POPDEF([my_Header])dnl])MY_CHECK_HEADER([stdint.h])for header in inttypes.h stdlib.h ; do  MY_CHECK_HEADER([$header])done@end example@noindentIn the above example, @code{MY_CHECK_HEADER} can operate on polymorphicvariable names.  In the first invocation, the m4 argument is@code{stdint.h}, which transliterates into a literal @code{stdint_h}.As a result, the temporary macro @code{my_Header} expands to the literalshell name @samp{ac_cv_header_stdint_h}.  In the second invocation, them4 argument to @code{MY_CHECK_HEADER} is @code{$header}, and thetemporary macro @code{my_Header} expands to the indirect shell name@samp{$as_my_Header}.  During the shell execution of the for loop, when@samp{$header} contains @samp{inttypes.h}, then @samp{$as_my_Header}contains @samp{ac_cv_header_inttypes_h}.  If this script is then run on aplatform where all three headers have been previously detected, theoutput of the script will include:@smallexampleheader stdint.h detectedheader inttypes.h detectedheader stdlib.h detected@end smallexample@end defmac@defmac AS_VAR_SET (@var{var}, @ovar{value})@asindex{VAR_SET}Emit shell code to assign the contents of the polymorphic shell variable@var{var} to the shell expansion of @var{value}.  @var{value} is notsubject to field splitting or file name expansion, so if commandsubstitution is used, it may be done with @samp{`""`} rather than usingan intermediate variable (@pxref{Shell Substitutions}).  However,@var{value} does undergo rescanning for additional macro names; behavioris unspecified if late expansion results in any shell meta-characters.@end defmac@defmac AS_VAR_SET_IF (@var{var}, @ovar{if-set}, @ovar{if-undef})@asindex{VAR_SET_IF}Emit a shell conditional statement, which executes @var{if-set} if thepolymorphic shell variable @code{var} is set to any value, and@var{if-undef} otherwise.@end defmac@defmac AS_VAR_TEST_SET (@var{var})@asindex{VAR_TEST_SET}Emit a shell statement that results in a successful exit status only ifthe polymorphic shell variable @code{var} is set.@end defmac@node Initialization Macros@section Initialization Macros@defmac AS_BOURNE_COMPATIBLE@asindex{BOURNE_COMPATIBLE}Set up the shell to be more compatible with the Bourne shell asstandardized by Posix, if possible.  This may involve settingenvironment variables, or setting options, or similarimplementation-specific actions.  This macro is deprecated, since@code{AS_INIT} already invokes it.@end defmac@defmac AS_INIT@asindex{INIT}@evindex LC_ALL@evindex SHELLInitialize the M4sh environment.  This macro calls @code{m4_init}, thenoutputs the @code{#! /bin/sh} line, a notice about where the output wasgenerated from, and code to sanitize the environment for the rest of thescript.  Among other initializations, this sets @env{SHELL} to the shellchosen to run the script (@pxref{CONFIG_SHELL}), and @env{LC_ALL} toensure the C locale.  Finally, it changes the current diversion to@code{BODY}.  @code{AS_INIT} is called automatically by @code{AC_INIT}and @code{AT_INIT}, so shell code in @file{configure},@file{config.status}, and @file{testsuite} all benefit from a sanitizedshell environment.@end defmac@defmac AS_INIT_GENERATED (@var{file}, @ovar{comment})@asindex{INIT_GENERATED}Emit shell code to start the creation of a subsidiary shell script in@var{file}, including changing @var{file} to be executable.  This macropopulates the child script with information learned from the parent(thus, the emitted code is equivalent in effect, but more efficient,than the code output by @code{AS_INIT}, @code{AS_BOURNE_COMPATIBLE}, and@code{AS_SHELL_SANITIZE}).  If present, @var{comment} is output near thebeginning of the child, prior to the shell initialization code, and issubject to parameter expansion, command substitution, and backslashquote removal.  Theparent script should check the exit status after this macro, in case@var{file} could not be properly created (for example, if the disk wasfull).  If successfully created, the parent script can then proceed toappend additional M4sh constructs into the child script.Note that the child script starts life without a log file open, so ifthe parent script uses logging (@pxref{AS_MESSAGE_LOG_FD}), youmust temporarily disable any attempts to use the log file until afteremitting code to open a log within the child.  On the other hand, if theparent script has @code{AS_MESSAGE_FD} redirected somewhere besides@samp{1}, then the child script already has code that copies stdout tothat descriptor.  Currently, the suggestedidiom for writing a M4sh shell script from within another script is:@exampleAS_INIT_GENERATED([@var{file}], [[# My child script.]]) || @{ AS_ECHO(["Failed to create child script"]); AS_EXIT; @}m4_pushdef([AS_MESSAGE_LOG_FD])dnlcat >> "@var{file}" <<\__EOF__# Code to initialize AS_MESSAGE_LOG_FDm4_popdef([AS_MESSAGE_LOG_FD])dnl# Additional code__EOF__@end exampleThis, however, may change in the future as the M4sh interface isstabilized further.Also, be aware that use of @env{LINENO} within the child script mayreport line numbers relative to their location in the parent script,even when using @code{AS_LINENO_PREPARE}, if the parent script wasunable to locate a shell with working @env{LINENO} support.@end defmac@defmac AS_LINENO_PREPARE@asindex{LINENO_PREPARE}@evindex LINENOFind a shell that supports the special variable @env{LINENO}, whichcontains the number of the currently executing line.  This macro isautomatically invoked by @code{AC_INIT} in configure scripts.@end defmac@defmac AS_ME_PREPARE@asindex{ME_PREPARE}Set up variable @env{as_me} to be the basename of the currently executingscript.  This macro is automatically invoked by @code{AC_INIT} inconfigure scripts.@end defmac@defmac AS_TMPDIR (@var{prefix}, @dvar{dir, $@{TMPDIR:=/tmp@}})@asindex{TMPDIR}@evindex TMPDIR@ovindex tmpCreate, as safely as possible, a temporary sub-directory within@var{dir} with a name starting with @var{prefix}.  @var{prefix} shouldbe 2-4 characters, to make it slightly easier to identify the owner ofthe directory.  If @var{dir} is omitted, then the value of @env{TMPDIR}will be used (defaulting to @samp{/tmp}).  On success, the name of thenewly created directory is stored in the shell variable @code{tmp}.  Onerror, the script is aborted.Typically, this macro is coupled with some exit traps to delete the createddirectory and its contents on exit or interrupt.  However, there is aslight window between when the directory is created and when the name isactually known to the shell, so an interrupt at the right moment mightleave the temporary directory behind.  Hence it is important to use a@var{prefix} that makes it easier to determine if a leftover temporarydirectory from an interrupted script is safe to delete.The use of the output variable @samp{$tmp} rather than something in the@samp{as_} namespace is historical; it has the unfortunate consequencethat reusing this otherwise common name for any other purpose insideyour script has the potential to break any cleanup traps designed toremove the temporary directory.@end defmac@defmac AS_SHELL_SANITIZE@asindex{SHELL_SANITIZE}Initialize the shell suitably for @command{configure} scripts.  This hasthe effect of @code{AS_BOURNE_COMPATIBLE}, and sets some otherenvironment variables for predictable results from configuration tests.For example, it sets @env{LC_ALL} to change to the default C locale.@xref{Special Shell Variables}.  This macro is deprecated, since@code{AS_INIT} already invokes it.@end defmac@node File Descriptor Macros@section File Descriptor Macros@cindex input@cindex standard input@cindex file descriptors@cindex descriptors@cindex low-level output@cindex output, low-levelThe following macros define file descriptors used to output messages(or input values) from @file{configure} scripts.For example:@exampleecho "$wombats found" >&AS_MESSAGE_LOG_FDecho 'Enter desired kangaroo count:' >&AS_MESSAGE_FDread kangaroos <&AS_ORIGINAL_STDIN_FD`@end example@noindentHowever doing so is seldom needed, because Autoconf provides higherlevel macros as described below.@defmac AS_MESSAGE_FD@asindex{MESSAGE_FD}The file descriptor for @samp{checking for...}  messages and results.By default, @code{AS_INIT} sets this to @samp{1} for standalone M4shclients.  However, @code{AC_INIT} shuffles things around to another filedescriptor, in order to allow the @option{-q} option of@command{configure} to choose whether messages should go to the script'sstandard output or be discarded.If you want to display some messages, consider using one of the printingmacros (@pxref{Printing Messages}) instead.  Copies of messages outputvia these macros are also recorded in @file{config.log}.@end defmac@anchor{AS_MESSAGE_LOG_FD}@defmac AS_MESSAGE_LOG_FD@asindex{MESSAGE_LOG_FD}This must either be empty, or expand to a file descriptor for logmessages.  By default, @code{AS_INIT} sets this macro to the emptystring for standalone M4sh clients, thus disabling logging.  However,@code{AC_INIT} shuffles things around so that both @command{configure}and @command{config.status} use @file{config.log} for log messages.Macros that run tools, like @code{AC_COMPILE_IFELSE} (@pxref{Running theCompiler}), redirect all output to this descriptor.  You may want to doso if you develop such a low-level macro.@end defmac@defmac AS_ORIGINAL_STDIN_FD@asindex{ORIGINAL_STDIN_FD}This must expand to a file descriptor for the original standard input.By default, @code{AS_INIT} sets this macro to @samp{0} for standaloneM4sh clients.  However, @code{AC_INIT} shuffles things around forsafety.When @command{configure} runs, it may accidentally execute aninteractive command that has the same name as the non-interactive meantto be used or checked.  If the standard input was the terminal, suchinteractive programs would cause @command{configure} to stop, pendingsome user input.  Therefore @command{configure} redirects its standardinput from @file{/dev/null} during its initialization.  This is notnormally a problem, since @command{configure} normally does not needuser input.In the extreme case where your @file{configure} script really needs toobtain some values from the original standard input, you can read themexplicitly from @code{AS_ORIGINAL_STDIN_FD}.@end defmac@c =================================================== Writing Autoconf Macros.@node Writing Autoconf Macros@chapter Writing Autoconf MacrosWhen you write a feature test that could be applicable to more than onesoftware package, the best thing to do is encapsulate it in a new macro.Here are some instructions and guidelines for writing Autoconf macros.@menu* Macro Definitions::           Basic format of an Autoconf macro* Macro Names::                 What to call your new macros* Reporting Messages::          Notifying @command{autoconf} users* Dependencies Between Macros::  What to do when macros depend on other macros* Obsoleting Macros::           Warning about old ways of doing things* Coding Style::                Writing Autoconf macros @`a la Autoconf@end menu@node Macro Definitions@section Macro Definitions@defmac AC_DEFUN (@var{name}, @ovar{body})@acindex{DEFUN}Autoconf macros are defined using the @code{AC_DEFUN} macro, which issimilar to the M4 builtin @code{m4_define} macro; this creates a macronamed @var{name} and with @var{body} as its expansion.  In addition todefining a macro, @code{AC_DEFUN} adds to it some code that is used toconstrain the order in which macros are called, while avoiding redundantoutput (@pxref{Prerequisite Macros}).@end defmacAn Autoconf macro definition looks like this:@exampleAC_DEFUN(@var{macro-name}, @var{macro-body})@end exampleYou can refer to any arguments passed to the macro as @samp{$1},@samp{$2}, etc.  @xref{Definitions, , How to define new macros, m4.info,GNU M4}, for more complete information on writing M4 macros.Most macros fall in one of two general categories.  The first categoryincludes macros which take arguments, in order to generate outputparameterized by those arguments.  Macros in this category are designedto be directly expanded, often multiple times, and should not be used asthe argument to @code{AC_REQUIRE}.  The other category includes macroswhich are shorthand for a fixed block of text, and therefore do not takearguments.  For this category of macros, directly expanding the macromultiple times results in redundant output, so it is more common to usethe macro as the argument to @code{AC_REQUIRE}, or to declare the macrowith @code{AC_DEFUN_ONCE} (@pxref{One-Shot Macros}).Be sure to properly quote both the @var{macro-body} @emph{and} the@var{macro-name} to avoid any problems if the macro happens to havebeen previously defined.Each macro should have a header comment that gives its prototype, and abrief description.  When arguments have default values, display them inthe prototype.  For example:@example# AC_MSG_ERROR(ERROR, [EXIT-STATUS = 1])# --------------------------------------m4_define([AC_MSG_ERROR],  [@{ AS_MESSAGE([error: $1], [2])     exit m4_default([$2], [1]); @}])@end exampleComments about the macro should be left in the header comment.  Mostother comments make their way into @file{configure}, so just keepusing @samp{#} to introduce comments.@cindex @code{dnl}If you have some special comments about pure M4 code, commentsthat make no sense in @file{configure} and in the header comment, thenuse the builtin @code{dnl}: it causes M4 to discard the textthrough the next newline.Keep in mind that @code{dnl} is rarely needed to introduce comments;@code{dnl} is more useful to get rid of the newlines following macrosthat produce no output, such as @code{AC_REQUIRE}.Public third-party macros need to use @code{AC_DEFUN}, and not@code{m4_define}, in order to be found by @command{aclocal}(@pxref{Extending aclocal,,, automake, GNU Automake}).Additionally, if it is ever determined that a macro should be madeobsolete, it is easy to convert from @code{AC_DEFUN} to @code{AU_DEFUN}in order to have @command{autoupdate} assist the user in choosing abetter alternative, but there is no corresponding way to make@code{m4_define} issue an upgrade notice (@pxref{AU_DEFUN}).There is another subtle, but important, difference between using@code{m4_define} and @code{AC_DEFUN}: only the former is unaffected by@code{AC_REQUIRE}.  When writing a file, it is always safe to replace ablock of text with a @code{m4_define} macro that will expand to the sametext.  But replacing a block of text with an @code{AC_DEFUN} macro withthe same content does not necessarily give the same results, because itchanges the location where any embedded but unsatisfied@code{AC_REQUIRE} invocations within the block will be expanded.  For anexample of this, see @ref{Expanded Before Required}.@node Macro Names@section Macro NamesAll of the public Autoconf macros have all-uppercase names in thenamespace @samp{^AC_} to prevent them from accidentally conflicting withother text; Autoconf also reserves the namespace @samp{^_AC_} forinternal macros.  All shell variables that they use for internalpurposes have mostly-lowercase names starting with @samp{ac_}.  Autoconfalso uses here-document delimiters in the namespace @samp{^_AC[A-Z]}.  During@command{configure}, files produced by Autoconf make heavy use of thefile system namespace @samp{^conf}.Since Autoconf is built on top of M4sugar (@pxref{Programming inM4sugar}) and M4sh (@pxref{Programming in M4sh}), you must also be awareof those namespaces (@samp{^_?\(m4\|AS\)_}).  And since@file{configure.ac} is also designed to be scanned by Autoheader,Autoscan, Autoupdate, and Automake, you should be aware of the@samp{^_?A[HNUM]_} namespaces.  In general, you @emph{should not use}the namespace of a package that does not own the macro or shell code youare writing.To ensure that your macros don't conflict with present or futureAutoconf macros, you should prefix your own macro names and any shellvariables they use with some other sequence.  Possibilities include yourinitials, or an abbreviation for the name of your organization orsoftware package.  Historically, people have not always followed therule of using a namespace appropriate for their package, and this hasmade it difficult for determining the origin of a macro (and where toreport bugs about that macro), as well as difficult for the truenamespace owner to add new macros without interference from pre-existinguses of third-party macros.  Perhaps the best example of this confusionis the @code{AM_GNU_GETTEXT} macro, which belongs, not to Automake, butto Gettext.Most of the Autoconf macros' names follow a structured naming conventionthat indicates the kind of feature check by the name.  The macro namesconsist of several words, separated by underscores, going from mostgeneral to most specific.  The names of their cache variables use thesame convention (@pxref{Cache Variable Names}, for more information onthem).The first word of the name after the namespace initials (such as@samp{AC_}) usually tells the categoryof the feature being tested.  Here are the categories used in Autoconf forspecific test macros, the kind of macro that you are more likely towrite.  They are also used for cache variables, in all-lowercase.  Usethem where applicable; where they're not, invent your own categories.@table @code@item CC language builtin features.@item DECLDeclarations of C variables in header files.@item FUNCFunctions in libraries.@item GROUPPosix group owners of files.@item HEADERHeader files.@item LIBC libraries.@item PROGThe base names of programs.@item MEMBERMembers of aggregates.@item SYSOperating system features.@item TYPEC builtin or declared types.@item VARC variables in libraries.@end tableAfter the category comes the name of the particular feature beingtested.  Any further words in the macro name indicate particular aspectsof the feature.  For example, @code{AC_PROG_CC_STDC} checks whether theC compiler supports ISO Standard C.An internal macro should have a name that starts with an underscore;Autoconf internals should therefore start with @samp{_AC_}.Additionally, a macro that is an internal subroutine of another macroshould have a name that starts with an underscore and the name of thatother macro, followed by one or more words saying what the internalmacro does.  For example, @code{AC_PATH_X} has internal macros@code{_AC_PATH_X_XMKMF} and @code{_AC_PATH_X_DIRECT}.@node Reporting Messages@section Reporting Messages@cindex Messages, from @command{autoconf}When macros statically diagnose abnormal situations, benign or fatal, itis possible to make @command{autoconf} detect the problem, and refuse tocreate @file{configure} in the case of an error.  The macros in thissection are considered obsolescent, and new code should use M4sugarmacros for this purpose, see @ref{Diagnostic Macros}.On the other hand, it is possible to want to detect errors when@command{configure} is run, which are dependent on the environment ofthe user rather than the maintainer.  For dynamic diagnostics, see@ref{Printing Messages}.@defmac AC_DIAGNOSE (@var{category}, @var{message})@acindex{DIAGNOSE}Report @var{message} as a warning (or as an error if requested by theuser) if warnings of the @var{category} are turned on.  This macro isobsolescent; you are encouraged to use:@examplem4_warn([@var{category}], [@var{message}])@end example@noindentinstead.  @xref{m4_warn}, for more details, including valid@var{category} names.@end defmac@defmac AC_WARNING (@var{message})@acindex{WARNING}Report @var{message} as a syntax warning.  This macro is obsolescent;you are encouraged to use:@examplem4_warn([syntax], [@var{message}])@end example@noindentinstead.  @xref{m4_warn}, for more details, as well as betterfiner-grained categories of warnings (not all problems have to do withsyntax).@end defmac@defmac AC_FATAL (@var{message})@acindex{FATAL}Report a severe error @var{message}, and have @command{autoconf} die.This macro is obsolescent; you are encouraged to use:@examplem4_fatal([@var{message}])@end example@noindentinstead.  @xref{m4_fatal}, for more details.@end defmacWhen the user runs @samp{autoconf -W error}, warnings from@code{m4_warn} (including those issued through @code{AC_DIAGNOSE} and@code{AC_WARNING}) are reported as errors, see @ref{autoconf Invocation}.@node Dependencies Between Macros@section Dependencies Between Macros@cindex Dependencies between macrosSome Autoconf macros depend on other macros having been called first inorder to work correctly.  Autoconf provides a way to ensure that certainmacros are called if needed and a way to warn the user if macros arecalled in an order that might cause incorrect operation.@menu* Prerequisite Macros::         Ensuring required information* Suggested Ordering::          Warning about possible ordering problems* One-Shot Macros::             Ensuring a macro is called only once@end menu@node Prerequisite Macros@subsection Prerequisite Macros@cindex Prerequisite macros@cindex Macros, prerequisitesA macro that you write might need to use values that have previouslybeen computed by other macros.  For example, @code{AC_DECL_YYTEXT}examines the output of @code{flex} or @code{lex}, so it depends on@code{AC_PROG_LEX} having been called first to set the shell variable@code{LEX}.Rather than forcing the user of the macros to keep track of thedependencies between them, you can use the @code{AC_REQUIRE} macro to doit automatically.  @code{AC_REQUIRE} can ensure that a macro is onlycalled if it is needed, and only called once.@defmac AC_REQUIRE (@var{macro-name})@acindex{REQUIRE}If the M4 macro @var{macro-name} has not already been called, call it(without any arguments).  Make sure to quote @var{macro-name} withsquare brackets.  @var{macro-name} must have been defined using@code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicatethat it has been called.@code{AC_REQUIRE} must be used inside a macro defined by @code{AC_DEFUN}; itmust not be called from the top level.  Also, it does not make sense torequire a macro that takes parameters.@end defmac@code{AC_REQUIRE} is often misunderstood.  It really implementsdependencies between macros in the sense that if one macro depends uponanother, the latter is expanded @emph{before} the body of theformer.  To be more precise, the required macro is expanded beforethe outermost defined macro in the current expansion stack.In particular, @samp{AC_REQUIRE([FOO])} is not replaced with the body of@code{FOO}.  For instance, this definition of macros:@example@groupAC_DEFUN([TRAVOLTA],[test "$body_temperature_in_celsius" -gt "38" &&  dance_floor=occupied])AC_DEFUN([NEWTON_JOHN],[test "x$hair_style" = xcurly &&  dance_floor=occupied])@end group@groupAC_DEFUN([RESERVE_DANCE_FLOOR],[if date | grep '^Sat.*pm' >/dev/null 2>&1; then  AC_REQUIRE([TRAVOLTA])  AC_REQUIRE([NEWTON_JOHN])fi])@end group@end example@noindentwith this @file{configure.ac}@exampleAC_INIT([Dance Manager], [1.0], [bug-dance@@example.org])RESERVE_DANCE_FLOORif test "x$dance_floor" = xoccupied; then  AC_MSG_ERROR([cannot pick up here, let's move])fi@end example@noindentdoes not leave you with a better chance to meet a kindred soul atother times than Saturday night since it expands into:@example@grouptest "$body_temperature_in_Celsius" -gt "38" &&  dance_floor=occupiedtest "x$hair_style" = xcurly &&  dance_floor=occupiedfiif date | grep '^Sat.*pm' >/dev/null 2>&1; thenfi@end group@end exampleThis behavior was chosen on purpose: (i) it prevents messages inrequired macros from interrupting the messages in the requiring macros;(ii) it avoids bad surprises when shell conditionals are used, as in:@example@groupif @dots{}; then  AC_REQUIRE([SOME_CHECK])fi@dots{}SOME_CHECK@end group@end exampleHowever, this implementation can lead to another class of problems.Consider the case where an outer macro first expands, then indirectlyrequires, an inner macro:@exampleAC_DEFUN([TESTA], [[echo in Aif test -n "$SEEN_A" ; then echo duplicate ; fiSEEN_A=:]])AC_DEFUN([TESTB], [AC_REQUIRE([TESTA])[echo in Bif test -z "$SEEN_A" ; then echo bug ; fi]])AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])AC_DEFUN([OUTER], [[echo in OUTER]TESTATESTC])OUTER@end example@noindentPrior to Autoconf 2.64, the implementation of @code{AC_REQUIRE}recognized that @code{TESTB} needed to be hoisted prior to the expansionof @code{OUTER}, but because @code{TESTA} had already been directlyexpanded, it failed to hoist @code{TESTA}.  Therefore, the expansion of@code{TESTB} occurs prior to its prerequisites, leading to the followingoutput:@examplein Bbugin OUTERin Ain C@end example@noindentNewer Autoconf is smart enough to recognize this situation, and hoists@code{TESTA} even though it has already been expanded, but issues asyntax warning in the process.  This is because the hoisted expansion of@code{TESTA} defeats the purpose of using @code{AC_REQUIRE} to avoidredundant code, and causes its own set of problems if the hoisted macrois not idempotent:@examplein Ain Bin OUTERin Aduplicatein C@end exampleThe bug is not in Autoconf, but in the macro definitions.  If you everpass a particular macro name to @code{AC_REQUIRE}, then you are implyingthat the macro only needs to be expanded once.  But to enforce this,either the macro must be declared with @code{AC_DEFUN_ONCE} (althoughthis only helps in Autoconf 2.64 or newer), or alluses of that macro should be through @code{AC_REQUIRE}; directlyexpanding the macro defeats the point of using @code{AC_REQUIRE} toeliminate redundant expansion.  In the example, this rule of thumb wasviolated because @code{TESTB} requires @code{TESTA} while @code{OUTER}directly expands it.  One way of fixing the bug is to factor@code{TESTA} into two macros, the portion designed for direct andrepeated use (here, named @code{TESTA}), and the portion designed forone-shot output and used only inside @code{AC_REQUIRE} (here, named@code{TESTA_PREREQ}).  Then, by fixing all clients to use the correctcalling convention according to their needs:@exampleAC_DEFUN([TESTA], [AC_REQUIRE([TESTA_PREREQ])[echo in A]])AC_DEFUN([TESTA_PREREQ], [[echo in A_PREREQif test -n "$SEEN_A" ; then echo duplicate ; fiSEEN_A=:]])AC_DEFUN([TESTB], [AC_REQUIRE([TESTA_PREREQ])[echo in Bif test -z "$SEEN_A" ; then echo bug ; fi]])AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])AC_DEFUN([OUTER], [[echo in OUTER]TESTATESTC])OUTER@end example@noindentthe resulting output will then obey all dependency rules and avoid anysyntax warnings, whether the script is built with old or new Autoconfversions:@examplein A_PREREQin Bin OUTERin Ain C@end exampleThe helper macros @code{AS_IF} and @code{AS_CASE} may be used toenforce expansion of required macros outside of shell conditionalconstructs.  You are furthermore encouraged, although not required, toput all @code{AC_REQUIRE} callsat the beginning of a macro.  You can use @code{dnl} to avoid the emptylines they leave.@node Suggested Ordering@subsection Suggested Ordering@cindex Macros, ordering@cindex Ordering macrosSome macros should be run before another macro if both are called, butneither @emph{requires} that the other be called.  For example, a macrothat changes the behavior of the C compiler should be called before anymacros that run the C compiler.  Many of these dependencies are noted inthe documentation.Autoconf provides the @code{AC_BEFORE} macro to warn users when macroswith this kind of dependency appear out of order in a@file{configure.ac} file.  The warning occurs when creating@command{configure} from @file{configure.ac}, not when running@command{configure}.For example, @code{AC_PROG_CPP} checks whether the C compilercan run the C preprocessor when given the @option{-E} option.  It shouldtherefore be called after any macros that change which C compiler isbeing used, such as @code{AC_PROG_CC}.  So @code{AC_PROG_CC} contains:@exampleAC_BEFORE([$0], [AC_PROG_CPP])dnl@end example@noindentThis warns the user if a call to @code{AC_PROG_CPP} has already occurredwhen @code{AC_PROG_CC} is called.@defmac AC_BEFORE (@var{this-macro-name}, @var{called-macro-name})@acindex{BEFORE}Make M4 print a warning message to the standard error output if@var{called-macro-name} has already been called.  @var{this-macro-name}should be the name of the macro that is calling @code{AC_BEFORE}.  Themacro @var{called-macro-name} must have been defined using@code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicatethat it has been called.@end defmac@node One-Shot Macros@subsection One-Shot Macros@cindex One-shot macros@cindex Macros, called onceSome macros should be called only once, either because calling themmultiple time is unsafe, or because it is bad style.  For instanceAutoconf ensures that @code{AC_CANONICAL_BUILD} and cousins(@pxref{Canonicalizing}) are evaluated only once, because it makes nosense to run these expensive checks more than once.  Such one-shotmacros can be defined using @code{AC_DEFUN_ONCE}.@defmac AC_DEFUN_ONCE (@var{macro-name}, @var{macro-body})@acindex{DEFUN_ONCE}Declare macro @var{macro-name} like @code{AC_DEFUN} would (@pxref{MacroDefinitions}), but add additional logic that guarantees that only thefirst use of the macro (whether by direct expansion or@code{AC_REQUIRE}) causes an expansion of @var{macro-body}; theexpansion will occur before the start of any enclosing macro defined by@code{AC_DEFUN}.  Subsequent expansions are silently ignored.Generally, it does not make sense for @var{macro-body} to use parameterssuch as @code{$1}.@end defmacPrior to Autoconf 2.64, a macro defined by @code{AC_DEFUN_ONCE} wouldemit a warning if it was directly expanded a second time, so forportability, it is better to use @code{AC_REQUIRE} than directinvocation of @var{macro-name} inside a macro defined by @code{AC_DEFUN}(@pxref{Prerequisite Macros}).@node Obsoleting Macros@section Obsoleting Macros@cindex Obsoleting macros@cindex Macros, obsoletingConfiguration and portability technology has evolved over the years.Often better ways of solving a particular problem are developed, orad-hoc approaches are systematized.  This process has occurred in manyparts of Autoconf.  One result is that some of the macros are nowconsidered @dfn{obsolete}; they still work, but are no longer consideredthe best thing to do, hence they should be replaced with more modernmacros.  Ideally, @command{autoupdate} should replace the old macro callswith their modern implementation.Autoconf provides a simple means to obsolete a macro.@anchor{AU_DEFUN}@defmac AU_DEFUN (@var{old-macro}, @var{implementation}, @ovar{message})@auindex{DEFUN}Define @var{old-macro} as @var{implementation}.  The only differencewith @code{AC_DEFUN} is that the user is warned that@var{old-macro} is now obsolete.If she then uses @command{autoupdate}, the call to @var{old-macro} isreplaced by the modern @var{implementation}.  @var{message} shouldinclude information on what to do after running @command{autoupdate};@command{autoupdate} prints it as a warning, and includes itin the updated @file{configure.ac} file.The details of this macro are hairy: if @command{autoconf} encounters an@code{AU_DEFUN}ed macro, all macros inside its second argument are expandedas usual.  However, when @command{autoupdate} is run, only M4 and M4sugarmacros are expanded here, while all other macros are disabled andappear literally in the updated @file{configure.ac}.@end defmac@defmac AU_ALIAS (@var{old-name}, @var{new-name})@auindex{ALIAS}Used if the @var{old-name} is to be replaced by a call to @var{new-macro}with the same parameters.  This happens for example if the macro was renamed.@end defmac@node Coding Style@section Coding Style@cindex Coding styleThe Autoconf macros follow a strict coding style.  You are encouraged tofollow this style, especially if you intend to distribute your macro,either by contributing it to Autoconf itself or the@uref{http://@/www.gnu.org/@/software/@/autoconf-archive/, Autoconf MacroArchive}, or by other means.The first requirement is to pay great attention to the quotation.  Formore details, see @ref{Autoconf Language}, and @ref{M4 Quotation}.Do not try to invent new interfaces.  It is likely that there is a macroin Autoconf that resembles the macro you are defining: try to stick tothis existing interface (order of arguments, default values, etc.).  We@emph{are} conscious that some of these interfaces are not perfect;nevertheless, when harmless, homogeneity should be preferred overcreativity.Be careful about clashes both between M4 symbols and between shellvariables.If you stick to the suggested M4 naming scheme (@pxref{Macro Names}),you are unlikely to generate conflicts.  Nevertheless, when you need toset a special value, @emph{avoid using a regular macro name}; rather,use an ``impossible'' name.  For instance, up to version 2.13, the macro@code{AC_SUBST} used to remember what @var{symbol} macros were already definedby setting @code{AC_SUBST_@var{symbol}}, which is a regular macro name.But since there is a macro named @code{AC_SUBST_FILE}, it was justimpossible to @samp{AC_SUBST(FILE)}!  In this case,@code{AC_SUBST(@var{symbol})} or @code{_AC_SUBST(@var{symbol})} shouldhave been used (yes, with the parentheses).@c or better yet, high-level macros such as @code{m4_expand_once}No Autoconf macro should ever enter the user-variable name space; i.e.,except for the variables that are the actual result of running themacro, all shell variables should start with @code{ac_}.  Inaddition, small macros or any macro that is likely to be embedded inother macros should be careful not to use obvious names.@cindex @code{dnl}Do not use @code{dnl} to introduce comments: most of the comments youare likely to write are either header comments which are not outputanyway, or comments that should make their way into @file{configure}.There are exceptional cases where you do want to comment special M4constructs, in which case @code{dnl} is right, but keep in mind that itis unlikely.M4 ignores the leading blanks and newlines before each argument.Use this feature toindent in such a way that arguments are (more or less) aligned with theopening parenthesis of the macro being called.  For instance, instead of@exampleAC_CACHE_CHECK(for EMX OS/2 environment,ac_cv_emxos2,[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __EMX__;])],[ac_cv_emxos2=yes], [ac_cv_emxos2=no])])@end example@noindentwrite@exampleAC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],                   [ac_cv_emxos2=yes],                   [ac_cv_emxos2=no])])@end example@noindentor even@exampleAC_CACHE_CHECK([for EMX OS/2 environment],               [ac_cv_emxos2],               [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],                                                   [return __EMX__;])],                                  [ac_cv_emxos2=yes],                                  [ac_cv_emxos2=no])])@end exampleWhen using @code{AC_RUN_IFELSE} or any macro that cannot work whencross-compiling, provide a pessimistic value (typically @samp{no}).Feel free to use various tricks to prevent auxiliary tools, such assyntax-highlighting editors, from behaving improperly.  For instance,instead of:@examplem4_bpatsubst([$1], [$"])@end example@noindentuse@examplem4_bpatsubst([$1], [$""])@end example@noindentso that Emacsen do not open an endless ``string'' at the first quote.For the same reasons, avoid:@exampletest $[#] != 0@end example@noindentand use:@exampletest $[@@%:@@] != 0@end example@noindentOtherwise, the closing bracket would be hidden inside a @samp{#}-comment,breaking the bracket-matching highlighting from Emacsen.  Note thepreferred style to escape from M4: @samp{$[1]}, @samp{$[@@]}, etc.  Donot escape when it is unnecessary.  Common examples of useless quotationare @samp{[$]$1} (write @samp{$$1}), @samp{[$]var} (use @samp{$var}),etc.  If you add portability issues to the picture, you'll prefer@samp{$@{1+"$[@@]"@}} to @samp{"[$]@@"}, and you'll prefer do somethingbetter than hacking Autoconf @code{:-)}.When using @command{sed}, don't use @option{-e} except for indentingpurposes.  With the @code{s} and @code{y} commands, the preferredseparator is @samp{/} unless @samp{/} itself might appear in the patternor replacement, in which case you should use @samp{|}, or optionally@samp{,} if you know the pattern and replacement cannot contain a filename.  If none of these characters will do, choose a printable characterthat cannot appear in the pattern or replacement.  Characters from theset @samp{"#$&'()*;<=>?`|~} are good choices if the pattern orreplacement might contain a file name, since they have special meaningto the shell and are less likely to occur in file names.@xref{Macro Definitions}, for details on how to define a macro.  If amacro doesn't use @code{AC_REQUIRE}, is expected to never be the objectof an @code{AC_REQUIRE} directive, and macros required by other macrosinside arguments do not need to be expanded before this macro, thenuse @code{m4_define}.  In case of doubt, use @code{AC_DEFUN}.Also take into account that public third-party macros need to use@code{AC_DEFUN} in order to be found by @command{aclocal}(@pxref{Extending aclocal,,, automake, GNU Automake}).All the @code{AC_REQUIRE} statements should be at the beginning of themacro, and each statement should be followed by @code{dnl}.You should not rely on the number of arguments: instead of checkingwhether an argument is missing, test that it is not empty.  It providesboth a simpler and a more predictable interface to the user, and savesroom for further arguments.Unless the macro is short, try to leave the closing @samp{])} at thebeginning of a line, followed by a comment that repeats the name of themacro being defined.  This introduces an additional newline in@command{configure}; normally, that is not a problem, but if you want toremove it you can use @samp{[]dnl} on the last line.  You can similarlyuse @samp{[]dnl} after a macro call to remove its newline.  @samp{[]dnl}is recommended instead of @samp{dnl} to ensure that M4 does notinterpret the @samp{dnl} as being attached to the preceding text ormacro output.  For example, instead of:@exampleAC_DEFUN([AC_PATH_X],[AC_MSG_CHECKING([for X])AC_REQUIRE_CPP()@r{# @dots{}omitted@dots{}}  AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])fi])@end example@noindentyou would write:@exampleAC_DEFUN([AC_PATH_X],[AC_REQUIRE_CPP()[]dnlAC_MSG_CHECKING([for X])@r{# @dots{}omitted@dots{}}  AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])fi[]dnl])# AC_PATH_X@end exampleIf the macro is long, try to split it into logical chunks.  Typically,macros that check for a bug in a function and prepare its@code{AC_LIBOBJ} replacement should have an auxiliary macro to performthis setup.  Do not hesitate to introduce auxiliary macros to factoryour code.In order to highlight the recommended coding style, here is a macrowritten the old way:@examplednl Check for EMX on OS/2.dnl _AC_EMXOS2AC_DEFUN(_AC_EMXOS2,[AC_CACHE_CHECK(for EMX OS/2 environment, ac_cv_emxos2,[AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return __EMX__;)],ac_cv_emxos2=yes, ac_cv_emxos2=no)])test "x$ac_cv_emxos2" = xyes && EMXOS2=yes])@end example@noindentand the new way:@example# _AC_EMXOS2# ----------# Check for EMX on OS/2.m4_define([_AC_EMXOS2],[AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],                   [ac_cv_emxos2=yes],                   [ac_cv_emxos2=no])])test "x$ac_cv_emxos2" = xyes && EMXOS2=yes[]dnl])# _AC_EMXOS2@end example@c ============================================= Portable Shell Programming@node Portable Shell@chapter Portable Shell Programming@cindex Portable shell programmingWhen writing your own checks, there are some shell-script programmingtechniques you should avoid in order to make your code portable.  TheBourne shell and upward-compatible shells like the Korn shell and Bashhave evolved over the years, and many features added to the originalSystem7 shell are now supported on all interesting porting targets.However, the following discussion between Russ Allbery and Robert Lipeis worth reading:@noindentRuss Allbery:@quotationThe GNU assumption that @command{/bin/sh} is the one and only shellleads to a permanent deadlock.  Vendors don't want to break users'existing shell scripts, and there are some corner cases in the Bourneshell that are not completely compatible with a Posix shell.  Thus,vendors who have taken this route will @emph{never} (OK@dots{}``never saynever'') replace the Bourne shell (as @command{/bin/sh}) with aPosix shell.@end quotation@noindentRobert Lipe:@quotationThis is exactly the problem.  While most (at least most System V's) dohave a Bourne shell that accepts shell functions most vendor@command{/bin/sh} programs are not the Posix shell.So while most modern systems do have a shell @emph{somewhere} that meets thePosix standard, the challenge is to find it.@end quotationFor this reason, part of the job of M4sh (@pxref{Programming in M4sh})is to find such a shell.  But to prevent trouble, if you're not usingM4sh you should not take advantage of features that were added after Unixversion 7, circa 1977 (@pxref{Systemology}); you should not use aliases,negated character classes, or even @command{unset}.  @code{#} comments,while not in Unix version 7, were retrofitted in the original Bourneshell and can be assumed to be part of the least common denominator.On the other hand, if you're using M4sh you can assume that the shellhas the features that were added in SVR2 (circa 1984), including shellfunctions,@command{return}, @command{unset}, and I/O redirection for builtins.  Formore information, refer to @uref{http://@/www.in-ulm.de/@/~mascheck/@/bourne/}.However, some pitfalls have to be avoided for portable use of theseconstructs; these will be documented in the rest of this chapter.See in particular @ref{Shell Functions} and @ref{Limitations ofBuiltins, , Limitations of Shell Builtins}.Some ancient systems have quitesmall limits on the length of the @samp{#!} line; for instance, 32bytes (not including the newline) on SunOS 4.However, these ancient systems are no longer of practical concern.The set of external programs you should run in a @command{configure} scriptis fairly small.  @xref{Utilities in Makefiles, , Utilities inMakefiles, standards, The GNU Coding Standards}, for the list.  Thisrestriction allows users to start out with a fairly small set ofprograms and build the rest, avoiding too many interdependencies betweenpackages.Some of these external utilities have a portable subset of features; see@ref{Limitations of Usual Tools}.There are other sources of documentation about shells.  Thespecification for the Posix@uref{http://@/www.opengroup.org/@/susv3/@/utilities/@/xcu_chap02@/.html, ShellCommand Language}, though more generous than the restrictive shellsubset described above, is fairly portable nowadays.  Also please see@uref{http://@/www.faqs.org/@/faqs/@/unix-faq/@/shell/, the Shell FAQs}.@menu* Shellology::                  A zoology of shells* Invoking the Shell::          Invoking the shell as a command* Here-Documents::              Quirks and tricks* File Descriptors::            FDs and redirections* Signal Handling::             Shells, signals, and headaches* File System Conventions::     File names* Shell Pattern Matching::      Pattern matching* Shell Substitutions::         Variable and command expansions* Assignments::                 Varying side effects of assignments* Parentheses::                 Parentheses in shell scripts* Slashes::                     Slashes in shell scripts* Special Shell Variables::     Variables you should not change* Shell Functions::             What to look out for if you use them* Limitations of Builtins::     Portable use of not so portable /bin/sh* Limitations of Usual Tools::  Portable use of portable tools@end menu@node Shellology@section Shellology@cindex ShellologyThere are several families of shells, most prominently the Bourne familyand the C shell family which are deeply incompatible.  If you want towrite portable shell scripts, avoid members of the C shell family.  The@uref{http://@/www.faqs.org/@/faqs/@/unix-faq/@/shell/@/shell-differences/, theShell difference FAQ} includes a small history of Posix shells, and acomparison between several of them.Below we describe some of the members of the Bourne shell family.@table @asis@item Ash@cindex AshAsh is often used on GNU/Linux and BSDsystems as a light-weight Bourne-compatible shell.  Ash 0.2 has somebugs that are fixed in the 0.3.x series, but portable shell scriptsshould work around them, since version 0.2 is still shipped with manyGNU/Linux distributions.To be compatible with Ash 0.2:@itemize @minus@itemdon't use @samp{$?} after expanding empty or unset variables,or at the start of an @command{eval}:@examplefoo=false$fooecho "Do not use it: $?"falseeval 'echo "Do not use it: $?"'@end example@itemdon't use command substitution within variable expansion:@examplecat $@{FOO=`bar`@}@end example@itembeware that single builtin substitutions are not performed by asubshell, hence their effect applies to the current shell!  @xref{ShellSubstitutions}, item ``Command Substitution''.@end itemize@item Bash@cindex BashTo detect whether you are running Bash, test whether@code{BASH_VERSION} is set.  To requirePosix compatibility, run @samp{set -o posix}.  @xref{Bash POSIXMode, , Bash Posix Mode, bash, The GNU Bash ReferenceManual}, for details.@item Bash 2.05 and later@cindex Bash 2.05 and laterVersions 2.05 and later of Bash use a different format for theoutput of the @command{set} builtin, designed to make evaluating itsoutput easier.  However, this output is not compatible with earlierversions of Bash (or with many other shells, probably).  So ifyou use Bash 2.05 or higher to execute @command{configure},you'll need to use Bash 2.05 for all other build tasks as well.@item Ksh@cindex Ksh@cindex Korn shell@prindex @samp{ksh}@prindex @samp{ksh88}@prindex @samp{ksh93}The Korn shell is compatible with the Bourne family and it mostlyconforms to Posix.  It has two major variants commonlycalled @samp{ksh88} and @samp{ksh93}, named after the years of initialrelease.  It is usually called @command{ksh}, but is called @command{sh}on some hosts if you set your path appropriately.Solaris systems have three variants:@prindex @command{/usr/bin/ksh} on Solaris@command{/usr/bin/ksh} is @samp{ksh88}; it isstandard on Solaris 2.0 and later.@prindex @command{/usr/xpg4/bin/sh} on Solaris@command{/usr/xpg4/bin/sh} is a Posix-compliant variant of@samp{ksh88}; it is standard on Solaris 9 and later.@prindex @command{/usr/dt/bin/dtksh} on Solaris@command{/usr/dt/bin/dtksh} is @samp{ksh93}.Variants that are not standard may be parts of optionalpackages.  There is no extra charge for these packages, but they arenot part of a minimal OS install and therefore some installations maynot have it.Starting with Tru64 Version 4.0, the Korn shell @command{/usr/bin/ksh}is also available as @command{/usr/bin/posix/sh}.  If the environmentvariable @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations ofthe standard shell conform to Posix.@item Pdksh@prindex @samp{pdksh}A public-domain clone of the Korn shell called @command{pdksh} is widelyavailable: it has most of the @samp{ksh88} features along with a few ofits own.  It usually sets @code{KSH_VERSION}, except if invoked as@command{/bin/sh} on OpenBSD, and similarly to Bash you can requirePosix compatibility by running @samp{set -o posix}.  Unfortunately, with@command{pdksh} 5.2.14 (the latest stable version as of January 2007)Posix mode is buggy and causes @command{pdksh} to depart from Posix inat least one respect, see @ref{Shell Substitutions}.@item Zsh@cindex ZshTo detect whether you are running @command{zsh}, test whether@code{ZSH_VERSION} is set.  By default @command{zsh} is @emph{not}compatible with the Bourne shell: you must execute @samp{emulate sh},and for @command{zsh} versions before 3.1.6-dev-18 you must alsoset @code{NULLCMD} to @samp{:}.  @xref{Compatibility, , Compatibility,zsh, The Z Shell Manual}, for details.The default Mac OS X @command{sh} was originally Zsh; it was changed toBash in Mac OS X 10.2.@end table@node Invoking the Shell@section Invoking the Shell@cindex invoking the shell@cindex shell invocationThe Korn shell (up to at least version M-12/28/93d) has a bug wheninvoked on a file whose name does not contain a slash.  It firstsearches for the file's name in @env{PATH}, and if found it executesthat rather than the original file.  For example, assuming there is abinary executable @file{/usr/bin/script} in your @env{PATH}, the lastcommand in the following example fails because the Korn shell finds@file{/usr/bin/script} and refuses to execute it as a shell script:@example$ @kbd{touch xxyzzyz script}$ @kbd{ksh xxyzzyz}$ @kbd{ksh ./script}$ @kbd{ksh script}ksh: script: cannot execute@end exampleBash 2.03 has a bug when invoked with the @option{-c} option: if theoption-argument ends in backslash-newline, Bash incorrectly reports asyntax error.  The problem does not occur if a character follows thebackslash:@example$ @kbd{$ bash -c 'echo foo \}> @kbd{'}bash: -c: line 2: syntax error: unexpected end of file$ @kbd{bash -c 'echo foo \}> @kbd{ '}foo@end example@noindent@xref{Backslash-Newline-Empty}, for how this can cause problems in makefiles.@node Here-Documents@section Here-Documents@cindex Here-documents@cindex Shell here-documentsDon't rely on @samp{\} being preserved just because it has no specialmeaning together with the next symbol.  In the native @command{sh}on OpenBSD 2.7 @samp{\"} expands to @samp{"} in here-documents withunquoted delimiter.  As a general rule, if @samp{\\} expands to @samp{\}use @samp{\\} to get @samp{\}.With OpenBSD 2.7's @command{sh}@example@group$ @kbd{cat <<EOF> \" \\> EOF}" \@end group@end example@noindentand with Bash:@example@groupbash-2.04$ @kbd{cat <<EOF> \" \\> EOF}\" \@end group@end exampleUsing command substitutions in a here-document that is fed to a shellfunction is not portable.  For example, with Solaris 10 @command{/bin/sh}:@example$ @kbd{kitty () @{ cat; @}}$ @kbd{kitty <<EOF> `echo ok`> EOF}/tmp/sh199886: cannot open$ @kbd{echo $?}1@end exampleSome shells mishandle large here-documents: for example,Solaris 10 @command{dtksh} and the UnixWare 7.1.1 Posix shell, which arederived from Korn shell version M-12/28/93d, mishandle braced variableexpansion that crosses a 1024- or 4096-byte buffer boundarywithin a here-document.  Only the part of the variable name after the boundaryis used.  For example, @code{$@{variable@}} could be replaced by the expansionof @code{$@{ble@}}.  If the end of the variable name is aligned with the blockboundary, the shell reports an error, as if you used @code{$@{@}}.Instead of @code{$@{variable-default@}}, the shell may expand@code{$@{riable-default@}}, or even @code{$@{fault@}}.  This bug can oftenbe worked around by omitting the braces: @code{$variable}.  The bug wasfixed in@samp{ksh93g} (1998-04-30) but as of 2006 many operating systems werestill shipping older versions with the bug.Empty here-documents are not portable either; with the following code,@command{zsh} up to at least version 4.3.10 creates a file with a singlenewline, whereas other shells create an empty file:@examplecat >file <<EOFEOF@end exampleMany shells (including the Bourne shell) implement here-documentsinefficiently.  In particular, some shells can be extremely inefficient whena single statement contains many here-documents.  For instance if your@file{configure.ac} includes something like:@example@groupif <cross_compiling>; then  assume this and thatelse  check this  check that  check something else  @dots{}  on and on forever  @dots{}fi@end group@end exampleA shell parses the whole @code{if}/@code{fi} construct, creatingtemporary files for each here-document in it.  Some shells create linksfor such here-documents on every @code{fork}, so that the clean-up codethey had installed correctly removes them.  It is creating the linksthat can take the shell forever.Moving the tests out of the @code{if}/@code{fi}, or creating multiple@code{if}/@code{fi} constructs, would improve the performancesignificantly.  Anyway, this kind of construct is not exactly thetypical use of Autoconf.  In fact, it's even not recommended, because M4macros can't look into shell conditionals, so we may fail to expand amacro when it was expanded before in a conditional path, and thecondition turned out to be false at runtime, and we end up notexecuting the macro at all.Be careful with the use of @samp{<<-} to unindent here-documents.  Thebehavior is only portable for stripping leading @key{TAB}s, and thingscan silently break if an overzealous editor converts to using leadingspaces (not all shells are nice enough to warn about unterminatedhere-documents).@example$ @kbd{printf 'cat <<-x\n\t1\n\t 2\n\tx\n' | bash && echo done}1 2done$ @kbd{printf 'cat <<-x\n 1\n  2\n x\n' | bash-3.2 && echo done} 1  2 xdone@end example@node File Descriptors@section File Descriptors@cindex Descriptors@cindex File descriptors@cindex Shell file descriptorsMost shells, if not all (including Bash, Zsh, Ash), output traces onstderr, even for subshells.  This might result in undesirable contentif you meant to capture the standard-error output of the inner command:@example$ @kbd{ash -x -c '(eval "echo foo >&2") 2>stderr'}$ @kbd{cat stderr}+ eval echo foo >&2+ echo foofoo$ @kbd{bash -x -c '(eval "echo foo >&2") 2>stderr'}$ @kbd{cat stderr}+ eval 'echo foo >&2'++ echo foofoo$ @kbd{zsh -x -c '(eval "echo foo >&2") 2>stderr'}@i{# Traces on startup files deleted here.}$ @kbd{cat stderr}+zsh:1> eval echo foo >&2+zsh:1> echo foofoo@end example@noindentOne workaround is to grep out uninteresting lines, hoping not to removegood ones.If you intend to redirect both standard error and standard output,redirect standard output first.  This works better with HP-UX,since its shell mishandles tracing if standard error is redirectedfirst:@example$ @kbd{sh -x -c ': 2>err >out'}+ :+ 2> err $ @kbd{cat err}1> out@end exampleDon't try to redirect the standard error of a command substitution.  Itmust be done @emph{inside} the command substitution.  When running@samp{: `cd /zorglub` 2>/dev/null} expect the error message toescape, while @samp{: `cd /zorglub 2>/dev/null`} works properly.On the other hand, some shells, such as Solaris or FreeBSD@command{/bin/sh}, warn about missing programs before performingredirections.  Therefore, to silently check whether a program exists, itis necessary to perform redirections on a subshell or brace group:@example$ @kbd{/bin/sh -c 'nosuch 2>/dev/null'}nosuch: not found$ @kbd{/bin/sh -c '(nosuch) 2>/dev/null'}$ @kbd{/bin/sh -c '@{ nosuch; @} 2>/dev/null'}$ @kbd{bash -c 'nosuch 2>/dev/null'}@end exampleFreeBSD 6.2 sh may mix the trace output lines from the statements in ashell pipeline.It is worth noting that Zsh (but not Ash nor Bash) makes it possiblein assignments though: @samp{foo=`cd /zorglub` 2>/dev/null}.Some shells, like @command{ash}, don't recognize bi-directionalredirection (@samp{<>}).  And even on shells that recognize it, it isnot portable to use on fifos: Posix does not require read-write supportfor named pipes, and Cygwin does not support it:@example$ @kbd{mkfifo fifo}$ @kbd{exec 5<>fifo}$ @kbd{echo hi >&5}bash: echo: write error: Communication error on send@end example@noindentFurthermore, versions of @command{dash} before 0.5.6 mistakenly truncateregular files when using @samp{<>}:@example$ @kbd{echo a > file}$ @kbd{bash -c ': 1<>file'; cat file}a$ @kbd{dash -c ': 1<>file'; cat file}$ rm a@end exampleWhen catering to old systems, don't redirect the same file descriptorseveral times, as you are doomed to failure under Ultrix.@exampleULTRIX V4.4 (Rev. 69) System #31: Thu Aug 10 19:42:23 GMT 1995UWS V4.4 (Rev. 11)$ @kbd{eval 'echo matter >fullness' >void}illegal io$ @kbd{eval '(echo matter >fullness)' >void}illegal io$ @kbd{(eval '(echo matter >fullness)') >void}Ambiguous output redirect.@end example@noindentIn each case the expected result is of course @file{fullness} containing@samp{matter} and @file{void} being empty.  However, this bug isprobably not of practical concern to modern platforms.Solaris 10 @command{sh} will try to optimize away a @command{:} command(even if it is redirected) in a loop after the first iteration, or in ashell function after the first call:@example$ @kbd{for i in 1 2 3 ; do : >x$i; done}$ @kbd{ls x*}x1$ @kbd{f () @{ : >$1; @}; f y1; f y2; f y3;}$ @kbd{ls y*}y1@end example@noindentAs a workaround, @command{echo} or @command{eval} can be used.Don't rely on file descriptors 0, 1, and 2 remaining closed in asubsidiary program.  If any of these descriptors is closed, theoperating system may open an unspecified file for the descriptor in thenew process image.  Posix 2008 says this may be done only if thesubsidiary program is set-user-ID or set-group-ID, but HP-UX 11.23 doesit even for ordinary programs, and the next version of Posix will allowHP-UX behavior.If you want a file descriptor above 2 to be inherited into a childprocess, then you must use redirections specific to that command or acontaining subshell or command group, rather than relying on@command{exec} in the shell. In @command{ksh} as well as HP-UX@command{sh}, file descriptors above 2 which are opened using@samp{exec @var{n}>file} are closed by a subsequent @samp{exec} (such asthat involved in the fork-and-exec which runs a program or script):@example$ @kbd{echo 'echo hello >&5' >k}$ @kbd{/bin/sh -c 'exec 5>t; ksh ./k; exec 5>&-; cat t}hello$ @kbd{bash -c 'exec 5>t; ksh ./k; exec 5>&-; cat t}hello$ @kbd{ksh -c 'exec 5>t; ksh ./k; exec 5>&-; cat t}./k[1]: 5: cannot open [Bad file number]$ @kbd{ksh -c '(ksh ./k) 5>t; cat t'}hello$ @kbd{ksh -c '@{ ksh ./k; @} 5>t; cat t'}hello$ @kbd{ksh -c '5>t ksh ./k; cat t}hello@end exampleDon't rely on duplicating a closed file descriptor to cause anerror.  With Solaris @command{/bin/sh}, failed duplication is silentlyignored, which can cause unintended leaks to the original filedescriptor.  In this example, observe the leak to standard output:@example$ @kbd{bash -c 'echo hi >&3' 3>&-; echo $?}bash: 3: Bad file descriptor1$ @kbd{/bin/sh -c 'echo hi >&3' 3>&-; echo $?}hi0@end exampleFortunately, an attempt to close an already closed file descriptor willportably succeed.  Likewise, it is safe to use either style of@samp{@var{n}<&-} or @samp{@var{n}>&-} for closing a file descriptor,even if it doesn't match the read/write mode that the file descriptorwas opened with.DOS variants cannot rename or remove open files, such as in@samp{mv foo bar >foo} or @samp{rm foo >foo}, even though this isperfectly portable among Posix hosts.A few ancient systems reserved some file descriptors.  By convention,file descriptor 3 was opened to @file{/dev/tty} when you logged intoEighth Edition (1985) through Tenth Edition Unix (1989).  Filedescriptor 4 had a special use on the Stardent/Kubota Titan (circa1990), though we don't now remember what it was.  Both these systems areobsolete, so it's now safe to treat file descriptors 3 and 4 like anyother file descriptors.On the other hand, you can't portably use multi-digit file descriptors.Solaris @command{ksh} doesn't understand any file descriptor larger than@samp{9}:@example$ @kbd{bash -c 'exec 10>&-'; echo $?}0$ @kbd{ksh -c 'exec 9>&-'; echo $?}0$ @kbd{ksh -c 'exec 10>&-'; echo $?}ksh[1]: exec: 10: not found127@end example@c <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>@node Signal Handling@section Signal Handling@cindex Signal handling in the shell@cindex Signals, shells andPortable handling of signals within the shell is another major source ofheadaches.  This is worsened by the fact that various different, mutuallyincompatible approaches are possible in this area, each with itsdistinctive merits and demerits.  A detailed description of these possibleapproaches, as well as of their pros and cons, can be found in@uref{http://www.cons.org/cracauer/sigint.html, this article}.Solaris 10 @command{/bin/sh} automatically traps most signals by default;@c See: <http://dbaspot.com/shell/396118-bourne-shell-exit-code-term.html>the shell still exits with error upon termination by one of those signals,but in such a case the exit status might be somewhat unexpected (even ifallowed by POSIX, strictly speaking):@example$ @kbd{bash -c 'kill -1 $$'; echo $?} # Will exit 128 + (signal number).Hangup129$ @kbd{/bin/ksh -c 'kill -15 $$'; echo $?} # Likewise.Terminated143$ @kbd{for sig in 1 2 3 15; do}> @kbd{  echo $sig:}> @kbd{  /bin/sh -c "kill -$s \$\$"; echo $?}> @kbd{done}signal 1:Hangup129signal 2:208signal 3:208signal 15:208@end exampleThis gets even worse if one is using the POSIX `wait' interface to getdetails about the shell process terminations: it will result in the shellhaving exited normally, rather than by receiving a signal.@example$ @kbd{cat > foo.c <<'END'}#include <stdio.h>    /* for printf */#include <stdlib.h>   /* for system */#include <sys/wait.h> /* for WIF* macros */int main(void)@{  int status = system ("kill -15 $$");  printf ("Terminated by signal: %s\n",          WIFSIGNALED (status) ? "yes" : "no");  printf ("Exited normally: %s\n",          WIFEXITED (status) ? "yes" : "no");  return 0;@}END@c $$ font-lock$ @kbd{cc -o foo foo.c}$ @kbd{./a.out} # On GNU/LinuxTerminated by signal: noExited normally: yes$ @kbd{./a.out} # On Solaris 10Terminated by signal: yesExited normally: no@end exampleVarious shells seem to handle @code{SIGQUIT} specially: they ignore it evenif it is not blocked, and even if the shell is not running interactively(in fact, even if the shell has no attached tty); among these shellsare at least Bash (from version 2 onwards), Zsh 4.3.12, Solaris 10@code{/bin/ksh} and @code{/usr/xpg4/bin/sh}, and AT&T @code{ksh93} (2011).Still, @code{SIGQUIT} seems to be trappable quite portably within allthese shells.  OTOH, some other shells doesn't special-case the handlingof @code{SIGQUIT}; among these shells are at least @code{pdksh} 5.2.14,Solaris 10 and NetBSD 5.1 @code{/bin/sh}, and the Almquist Shell 0.5.5.1.@c See: <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html>Some shells (especially Korn shells and derivatives) might try topropagate to themselves a signal that has killed a child process; this isnot a bug, but a conscious design choice (although its overall value mightbe debatable).  The exact details of how this is attained vary from shellto shell.  For example, upon running @code{perl -e 'kill 2, $$'}, afterthe perl process has been interrupted AT&T @code{ksh93} (2011) willproceed to send itself a @code{SIGINT}, while Solaris 10 @code{/bin/ksh}and @code{/usr/xpg4/bin/sh} will proceed to exit with status 130 (i.e.,128 + 2). In any case, if there is an active trap associated with@code{SIGINT}, those shells will correctly execute it.@c See: <http://www.austingroupbugs.net/view.php?id=51>Some Korn shells, when a child process die due receiving a signal withsignal number @var{n}, can leave in @samp{$?} an exit status of256+@var{n} instead of the more common 128+@var{n}.  Observe thedifference between AT&T @code{ksh93} (2011) and @code{bash} 4.1.5 onDebian:@example$ @kbd{/bin/ksh -c 'sh -c "kill -1 \$\$"; echo $?'}/bin/ksh: line 1: 7837: Hangup257$ @kbd{/bin/bash -c 'sh -c "kill -1 \$\$"; echo $?'}/bin/bash: line 1:  7861 Hangup        (sh -c "kill -1 \$\$")129@end example@noindentThis @command{ksh} behavior is allowed by POSIX, if implemented withdue care; see this @uref{http://www.austingroupbugs.net/view.php?id=51,Austin Group discussion} for more background.  However, if it is notimplemented with proper care, such a behavior might cause problemsin some corner cases.  To see why, assume we have a ``wrapper'' scriptlike this:@example#!/bin/sh# Ignore some signals in the shell only, not in its child processes.trap : 1 2 13 15wrapped_command "$@@"ret=$?other_commandexit $ret@end example@noindentIf @command{wrapped_command} is interrupted by a @code{SIGHUP} (whichhas signal number 1), @code{ret} will be set to 257.  Unless the@command{exit} shell builtin is smart enough to understand that sucha value can only have originated from a signal, and adjust the finalwait status of the shell appropriately, the value 257 will just gettruncated to 1 by the closing @code{exit} call, so that a caller ofthe script will have no way to determine that termination by a signalwas involved.  Observe the different behavior of AT&T @code{ksh93}(2011) and @code{bash} 4.1.5 on Debian:@example$ @kbd{cat foo.sh}#!/bin/shsh -c 'kill -1 $$'ret=$?echo $retexit $ret$ @kbd{/bin/ksh foo.sh; echo $?}foo.sh: line 2: 12479: Hangup2571$ @kbd{/bin/bash foo.sh; echo $?}foo.sh: line 2: 12487 Hangup        (sh -c 'kill -1 $$')129129@end example@node File System Conventions@section File System Conventions@cindex File system conventionsAutoconf uses shell-script processing extensively, so the file namesthat it processes should not contain characters that are special to theshell.  Special characters include space, tab, newline, NUL, andthe following:@example" # $ & ' ( ) * ; < = > ? [ \ ` |@end exampleAlso, file names should not begin with @samp{~} or @samp{-}, and shouldcontain neither @samp{-} immediately after @samp{/} nor @samp{~}immediately after @samp{:}.  On Posix-like platforms, directory namesshould not contain @samp{:}, as this runs afoul of @samp{:} used as thepath separator.These restrictions apply not only to the files that you distribute, butalso to the absolute file names of your source, build, and destinationdirectories.On some Posix-like platforms, @samp{!} and @samp{^} are special too, sothey should be avoided.Posix lets implementations treat leading @file{//} specially, butrequires leading @file{///} and beyond to be equivalent to @file{/}.Most Unix variants treat @file{//} like @file{/}.  However, some treat@file{//} as a ``super-root'' that can provide access to files that arenot otherwise reachable from @file{/}.  The super-root tradition beganwith Apollo Domain/OS, which died out long ago, but unfortunately Cygwinhas revived it.While @command{autoconf} and friends are usually run on some Posixvariety, they can be used on other systems, most notably DOSvariants.  This impacts several assumptions regarding file names.@noindentFor example, the following code:@examplecase $foo_dir in  /*) # Absolute     ;;  *)     foo_dir=$dots$foo_dir ;;esac@end example@noindentfails to properly detect absolute file names on those systems, becausethey can use a drivespec, and usually use a backslash as directoryseparator.  If you want to be portable to DOS variants (at theprice of rejecting valid but oddball Posix file names like @file{a:\b}),you can check for absolute file names like this:@cindex absolute file names, detect@examplecase $foo_dir in  [\\/]* | ?:[\\/]* ) # Absolute     ;;  *)     foo_dir=$dots$foo_dir ;;esac@end example@noindentMake sure you quote the brackets if appropriate and keep the backslash asfirst character (@pxref{case, , Limitations of Shell Builtins}).Also, because the colon is used as part of a drivespec, these systems don'tuse it as path separator.  When creating or accessing paths, you can use the@code{PATH_SEPARATOR} output variable instead.  @command{configure} sets thisto the appropriate value for the build system (@samp{:} or @samp{;}) when itstarts up.File names need extra care as well.  While DOS variantsthat are Posixy enough to run @command{autoconf} (such as DJGPP)are usually able to handle long file names properly, there are stilllimitations that can seriously break packages.  Several of these issuescan be easily detected by the@uref{ftp://@/ftp.gnu.org/@/gnu/@/non-gnu/@/doschk/@/doschk-1.1.tar.gz, doschk}package.A short overview follows; problems are marked with SFN/LFN toindicate where they apply: SFN means the issues are only relevant toplain DOS, not to DOS under Microsoft Windowsvariants, while LFN identifies problems that exist even underMicrosoft Windows variants.@table @asis@item No multiple dots (SFN)DOS cannot handle multiple dots in file names.  This is an especiallyimportant thing to remember when building a portable configure script,as @command{autoconf} uses a .in suffix for template files.This is perfectly OK on Posix variants:@exampleAC_CONFIG_HEADERS([config.h])AC_CONFIG_FILES([source.c foo.bar])AC_OUTPUT@end example@noindentbut it causes problems on DOS, as it requires @samp{config.h.in},@samp{source.c.in} and @samp{foo.bar.in}.  To make your package more portableto DOS-based environments, you should use this instead:@exampleAC_CONFIG_HEADERS([config.h:config.hin])AC_CONFIG_FILES([source.c:source.cin foo.bar:foobar.in])AC_OUTPUT@end example@item No leading dot (SFN)DOS cannot handle file names that start with a dot.  This is usuallynot important for @command{autoconf}.@item Case insensitivity (LFN)DOS is case insensitive, so you cannot, for example, have both afile called @samp{INSTALL} and a directory called @samp{install}.  Thisalso affects @command{make}; if there's a file called @samp{INSTALL} inthe directory, @samp{make install} does nothing (unless the@samp{install} target is marked as PHONY).@item The 8+3 limit (SFN)Because the DOS file system only stores the first 8 characters ofthe file name and the first 3 of the extension, those must be unique.That means that @file{foobar-part1.c}, @file{foobar-part2.c} and@file{foobar-prettybird.c} all resolve to the same file name(@file{FOOBAR-P.C}).  The same goes for @file{foo.bar} and@file{foo.bartender}.The 8+3 limit is not usually a problem under Microsoft Windows, as ituses numerictails in the short version of file names to make them unique.  However, aregistry setting can turn this behavior off.  While this makes itpossible to share file trees containing long file names between SFNand LFN environments, it also means the above problem applies thereas well.@item Invalid characters (LFN)Some characters are invalid in DOS file names, and should thereforebe avoided.  In a LFN environment, these are @samp{/}, @samp{\},@samp{?}, @samp{*}, @samp{:}, @samp{<}, @samp{>}, @samp{|} and @samp{"}.In a SFN environment, other characters are also invalid.  Theseinclude @samp{+}, @samp{,}, @samp{[} and @samp{]}.@item Invalid names (LFN)Some DOS file names are reserved, and cause problems if youtry to use files with those names.  These names include @file{CON},@file{AUX}, @file{COM1}, @file{COM2}, @file{COM3}, @file{COM4},@file{LPT1}, @file{LPT2}, @file{LPT3}, @file{NUL}, and @file{PRN}.File names are case insensitive, so even names like@file{aux/config.guess} are disallowed.@end table@node Shell Pattern Matching@section Shell Pattern Matching@cindex Shell pattern matchingNowadays portable patterns can use negated character classes like@samp{[!-aeiou]}.  The older syntax @samp{[^-aeiou]} is supported bysome shells but not others; hence portable scripts should never use@samp{^} as the first character of a bracket pattern.Outside the C locale, patterns like @samp{[a-z]} are problematic sincethey may match characters that are not lower-case letters.@node Shell Substitutions@section Shell Substitutions@cindex Shell substitutionsContrary to a persistent urban legend, the Bourne shell does notsystematically split variables and back-quoted expressions, in particularon the right-hand side of assignments and in the argument of @code{case}.For instance, the following code:@examplecase "$given_srcdir" in.)  top_srcdir="`echo "$dots" | sed 's|/$||'`" ;;*)  top_srcdir="$dots$given_srcdir" ;;esac@end example@noindentis more readable when written as:@examplecase $given_srcdir in.)  top_srcdir=`echo "$dots" | sed 's|/$||'` ;;*)  top_srcdir=$dots$given_srcdir ;;esac@end example@noindentand in fact it is even @emph{more} portable: in the first case of thefirst attempt, the computation of @code{top_srcdir} is not portable,since not all shells properly understand @code{"`@dots{}"@dots{}"@dots{}`"},for example Solaris 10 ksh:@example$ @kbd{foo="`echo " bar" | sed 's, ,,'`"}ksh: : cannot executeksh: bar | sed 's, ,,': cannot execute@end example@noindentPosix does not specify behavior for this sequence.  On the other hand,behavior for @code{"`@dots{}\"@dots{}\"@dots{}`"} is specified by Posix,but in practice, not all shells understand it the same way: pdksh 5.2.14prints spurious quotes when in Posix mode:@example$ @kbd{echo "`echo \"hello\"`"}hello$ @kbd{set -o posix}$ @kbd{echo "`echo \"hello\"`"}"hello"@end example@noindentThere is just no portable way to use double-quoted strings insidedouble-quoted back-quoted expressions (pfew!).Bash 4.1 has a bug where quoted empty strings adjacent to unquotedparameter expansions are elided during word splitting.  Meanwhile, zshdoes not perform word splitting except when in Bourne compatibilitymode.  In the example below, the correct behavior is to have fivearguments to the function, and exactly two spaces on either side of themiddle @samp{-}, since word splitting collapses multiple spaces in@samp{$f} but leaves empty arguments intact.@example$ @kbd{bash -c 'n() @{ echo "$#$@@"; @}; f="  -  "; n - ""$f"" -'}3- - -$ @kbd{ksh -c 'n() @{ echo "$#$@@"; @}; f="  -  "; n - ""$f"" -'}5-  -  -$ @kbd{zsh -c 'n() @{ echo "$#$@@"; @}; f="  -  "; n - ""$f"" -'}3-   -   -$ @kbd{zsh -c 'emulate sh;}> @kbd{n() @{ echo "$#$@@"; @}; f="  -  "; n - ""$f"" -'}5-  -  -@end example@noindentYou can work around this by doing manual word splitting, such as using@samp{"$str" $list} rather than @samp{"$str"$list}.There are also portability pitfalls with particular expansions:@table @code@item $@@@cindex @code{"$@@"}One of the most famous shell-portability issues is related to@samp{"$@@"}.  When there are no positional arguments, Posix saysthat @samp{"$@@"} is supposed to be equivalent to nothing, but theoriginal Unix version 7 Bourne shell treated it as equivalent to@samp{""} instead, and this behavior survives in later implementationslike Digital Unix 5.0.The traditional way to work around this portability problem is to use@samp{$@{1+"$@@"@}}.  Unfortunately this method does not work withZsh (3.x and 4.x), which is used on Mac OS X@.  When emulatingthe Bourne shell, Zsh performs word splitting on @samp{$@{1+"$@@"@}}:@examplezsh $ @kbd{emulate sh}zsh $ @kbd{for i in "$@@"; do echo $i; done}Hello World!zsh $ @kbd{for i in $@{1+"$@@"@}; do echo $i; done}HelloWorld!@end example@noindentZsh handles plain @samp{"$@@"} properly, but we can't use plain@samp{"$@@"} because of the portability problems mentioned above.One workaround relies on Zsh's ``global aliases'' to convert@samp{$@{1+"$@@"@}} into @samp{"$@@"} by itself:@exampletest "$@{ZSH_VERSION+set@}" = set && alias -g '$@{1+"$@@"@}'='"$@@"'@end exampleZsh only recognizes this alias when a shell word matches it exactly;@samp{"foo"$@{1+"$@@"@}} remains subject to word splitting.  Since thiscase always yields at least one shell word, use plain @samp{"$@@"}.A more conservative workaround is to avoid @samp{"$@@"} if it ispossible that there may be no positional arguments.  For example,instead of:@examplecat conftest.c "$@@"@end exampleyou can use this instead:@examplecase $# in0) cat conftest.c;;*) cat conftest.c "$@@";;esac@end exampleAutoconf macros often use the @command{set} command to update@samp{$@@}, so if you are writing shell code intended for@command{configure} you should not assume that the value of @samp{$@@}persists for any length of time.@item $@{10@}@cindex positional parametersThe 10th, 11th, @dots{} positional parameters can be accessed only aftera @code{shift}.  The 7th Edition shell reported an error if given@code{$@{10@}}, andSolaris 10 @command{/bin/sh} still acts that way:@example$ @kbd{set 1 2 3 4 5 6 7 8 9 10}$ @kbd{echo $@{10@}}bad substitution@end exampleConversely, not all shells obey the Posix rule that when braces areomitted, multiple digits beyond a @samp{$} imply the single-digitpositional parameter expansion concatenated with the remaining literaldigits.  To work around the issue, you must use braces.@example$ @kbd{bash -c 'set a b c d e f g h i j; echo $10 $@{1@}0'}a0 a0$ @kbd{dash -c 'set a b c d e f g h i j; echo $10 $@{1@}0'}j a0@end example@item $@{@var{var}:-@var{value}@}@c Info cannot handle `:' in index entries.@ifnotinfo@cindex @code{$@{@var{var}:-@var{value}@}}@end ifnotinfo@cindex @code{$@{@var{var}-@var{value}@}}Old BSD shells, including the Ultrix @code{sh}, don't accept thecolon for any shell substitution, and complain and die.Similarly for $@{@var{var}:=@var{value}@}, $@{@var{var}:?@var{value}@}, etc.However, all shells that support functions allow the use of colon inshell substitution, and since m4sh requires functions, you can portablyuse null variable substitution patterns in configure scripts.@item $@{@var{var}+@var{value}@}@cindex @code{$@{@var{var}+@var{value}@}}When using @samp{$@{@var{var}-@var{value}@}} or@samp{$@{@var{var}-@var{value}@}} for providing alternate substitutions,@var{value} must either be a single shell word, quoted, or in thecontext of an unquoted here-document.  Solaris@command{/bin/sh} complains otherwise.@example$ @kbd{/bin/sh -c 'echo $@{a-b c@}'}/bin/sh: bad substitution$ @kbd{/bin/sh -c 'echo $@{a-'\''b c'\''@}'}b c$ @kbd{/bin/sh -c 'echo "$@{a-b c@}"'}b c$ @kbd{/bin/sh -c 'cat <<EOF$@{a-b c@}EOF}b c@end exampleAccording to Posix, if an expansion occurs inside double quotes, thenthe use of unquoted double quotes within @var{value} is unspecified, andany single quotes become literal characters; in that case, escaping mustbe done with backslash.  Likewise, the use of unquoted here-documents isa case where double quotes have unspecified results:@example$ @kbd{/bin/sh -c 'echo "$@{a-"b  c"@}"'}/bin/sh: bad substitution$ @kbd{ksh -c 'echo "$@{a-"b  c"@}"'}b c$ @kbd{bash -c 'echo "$@{a-"b  c"@}"'}b  c$ @kbd{/bin/sh -c 'a=; echo $@{a+'\''b  c'\''@}'}b  c$ @kbd{/bin/sh -c 'a=; echo "$@{a+'\''b  c'\''@}"'}'b  c'$ @kbd{/bin/sh -c 'a=; echo "$@{a+\"b  c\"@}"'}"b  c"$ @kbd{/bin/sh -c 'a=; echo "$@{a+b  c@}"'}b  c$ @kbd{/bin/sh -c 'cat <<EOF$@{a-"b  c"@}EOF'}"b  c"$ @kbd{/bin/sh -c 'cat <<EOF$@{a-'b  c'@}EOF'}'b  c'$ @kbd{bash -c 'cat <<EOF$@{a-"b  c"@}EOF'}b  c$ @kbd{bash -c 'cat <<EOF$@{a-'b  c'@}EOF'}'b  c'@end examplePerhaps the easiest way to work around quoting issues in a mannerportable to all shells is to place the results in a temporary variable,then use @samp{$t} as the @var{value}, rather than trying to inlinethe expression needing quoting.@example$ @kbd{/bin/sh -c 't="b  c\"'\''@}\\"; echo "$@{a-$t@}"'}b  c"'@}\$ @kbd{ksh -c 't="b  c\"'\''@}\\"; echo "$@{a-$t@}"'}b  c"'@}\$ @kbd{bash -c 't="b  c\"'\''@}\\"; echo "$@{a-$t@}"'}b  c"'@}\@end example@item $@{@var{var}=@var{value}@}@cindex @code{$@{@var{var}=@var{value}@}}When using @samp{$@{@var{var}=@var{value}@}} to assign a default valueto @var{var}, remember that even though the assignment to @var{var} doesnot undergo file name expansion, the result of the variable expansiondoes unless the expansion occurred within double quotes.  In particular,when using @command{:} followed by unquoted variable expansion for theside effect of setting a default value, if the final value of@samp{$var} contains any globbing characters (either from @var{value} orfrom prior contents), the shell has to spend time performing file nameexpansion and field splitting even though those results will not beused.  Therefore, it is a good idea to consider double quotes when performingdefault initialization; while remembering how this impacts any quotingcharacters appearing in @var{value}.@example$ @kbd{time bash -c ': "$@{a=/usr/bin/*@}"; echo "$a"'}/usr/bin/*real	0m0.005suser	0m0.002ssys	0m0.003s$ @kbd{time bash -c ': $@{a=/usr/bin/*@}; echo "$a"'}/usr/bin/*real	0m0.039suser	0m0.026ssys	0m0.009s$ @kbd{time bash -c 'a=/usr/bin/*; : $@{a=noglob@}; echo "$a"'}/usr/bin/*real	0m0.031suser	0m0.020ssys	0m0.010s$ @kbd{time bash -c 'a=/usr/bin/*; : "$@{a=noglob@}"; echo "$a"'}/usr/bin/*real	0m0.006suser	0m0.002ssys	0m0.003s@end exampleAs with @samp{+} and @samp{-}, you must use quotes when using @samp{=}if the @var{value} contains more than one shell word; either singlequotes for just the @var{value}, or double quotes around the entireexpansion:@example$ @kbd{: $@{var1='Some words'@}}$ @kbd{: "$@{var2=like this@}"}$ @kbd{echo $var1 $var2}Some words like this@end example@noindentotherwise some shells, such as Solaris @command{/bin/sh} or on DigitalUnix V 5.0, die because of a ``bad substitution''.  Meanwhile, Posixrequires that with @samp{=}, quote removal happens prior to theassignment, and the expansion be the final contents of @var{var} withoutquoting (and thus subject to field splitting), in contrast to thebehavior with @samp{-} passing the quoting through to the finalexpansion.  However, @command{bash} 4.1 does not obey this rule.@example$ @kbd{ksh -c 'echo $@{var-a\ \ b@}'}a  b$ @kbd{ksh -c 'echo $@{var=a\ \ b@}'}a b$ @kbd{bash -c 'echo $@{var=a\ \ b@}'}a  b@end exampleFinally, Posix states that when mixing @samp{$@{a=b@}} with regularcommands, it is unspecified whether the assignments affect the parentshell environment.  It is best to perform assignments independently fromcommands, to avoid the problems demonstrated in this example:@example$ @kbd{bash -c 'x= y=$@{x:=b@} sh -c "echo +\$x+\$y+";echo -$x-'}+b+b+-b-$ @kbd{/bin/sh -c 'x= y=$@{x:=b@} sh -c "echo +\$x+\$y+";echo -$x-'}++b+--$ @kbd{ksh -c 'x= y=$@{x:=b@} sh -c "echo +\$x+\$y+";echo -$x-'}+b+b+--@end example@item $@{@var{var}=@var{value}@}@cindex @code{$@{@var{var}=@var{literal}@}}Solaris @command{/bin/sh} has a frightening bug in its handling ofliteral assignments.  Imagine you need set a variable to a string containing@samp{@}}.  This @samp{@}} character confuses Solaris @command{/bin/sh}when the affected variable was already set.  This bug can be exercisedby running:@example$ @kbd{unset foo}$ @kbd{foo=$@{foo='@}'@}}$ @kbd{echo $foo}@}$ @kbd{foo=$@{foo='@}'   # no error; this hints to what the bug is}$ @kbd{echo $foo}@}$ @kbd{foo=$@{foo='@}'@}}$ @kbd{echo $foo}@}@} ^ ugh!@end exampleIt seems that @samp{@}} is interpreted as matching @samp{$@{}, eventhough it is enclosed in single quotes.  The problem doesn't happenusing double quotes, or when using a temporary variable holding theproblematic string.@item $@{@var{var}=@var{expanded-value}@}@cindex @code{$@{@var{var}=@var{expanded-value}@}}On Ultrix,running@exampledefault="yu,yaa": $@{var="$default"@}@end example@noindentsets @var{var} to @samp{M-yM-uM-,M-yM-aM-a}, i.e., the 8th bit ofeach char is set.  You don't observe the phenomenon using a simple@samp{echo $var} since apparently the shell resets the 8th bit when itexpands $var.  Here are two means to make this shell confess its sins:@example$ @kbd{cat -v <<EOF$varEOF}@end example@noindentand@example$ @kbd{set | grep '^var=' | cat -v}@end exampleOne classic incarnation of this bug is:@exampledefault="a b c": $@{list="$default"@}for c in $list; do  echo $cdone@end example@noindentYou'll get @samp{a b c} on a single line.  Why?  Because there are nospaces in @samp{$list}: there are @samp{M- }, i.e., spaces with the 8thbit set, hence no IFS splitting is performed!!!One piece of good news is that Ultrix works fine with @samp{:$@{list=$default@}}; i.e., if you @emph{don't} quote.  The bad news isthen that QNX 4.25 then sets @var{list} to the @emph{last} item of@var{default}!The portable way out consists in using a double assignment, to switchthe 8th bit twice on Ultrix:@examplelist=$@{list="$default"@}@end example@noindent@dots{}but beware of the @samp{@}} bug from Solaris (see above).  For safety,use:@exampletest "$@{var+set@}" = set || var=@var{@{value@}}@end example@item $@{#@var{var}@}@itemx $@{@var{var}%@var{word}@}@itemx $@{@var{var}%%@var{word}@}@itemx $@{@var{var}#@var{word}@}@itemx $@{@var{var}##@var{word}@}@cindex @code{$@{#@var{var}@}}@cindex @code{$@{@var{var}%@var{word}@}}@cindex @code{$@{@var{var}%%@var{word}@}}@cindex @code{$@{@var{var}#@var{word}@}}@cindex @code{$@{@var{var}##@var{word}@}}Posix requires support for these usages, but they do not work with manytraditional shells, e.g., Solaris 10 @command{/bin/sh}.Also, @command{pdksh} 5.2.14 mishandles some @var{word} forms.  Forexample if @samp{$1} is @samp{a/b} and @samp{$2} is @samp{a}, then@samp{$@{1#$2@}} should yield @samp{/b}, but with @command{pdksh} ityields the empty string.@item `@var{commands}`@cindex @code{`@var{commands}`}@cindex Command SubstitutionPosix requires shells to trim all trailing newlines from commandoutput before substituting it, so assignments like@samp{dir=`echo "$file" | tr a A`} do not work as expected if@samp{$file} ends in a newline.While in general it makes no sense, do not substitute a single builtinwith side effects, because Ash 0.2, trying to optimize, does not fork asubshell to perform the command.For instance, if you wanted to check that @command{cd} is silent, do notuse @samp{test -z "`cd /`"} because the following can happen:@example$ @kbd{pwd}/tmp$ @kbd{test -z "`cd /`" && pwd}/@end example@noindentThe result of @samp{foo=`exit 1`} is left as an exercise to the reader.The MSYS shell leaves a stray byte in the expansion of a double-quotedcommand substitution of a native program, if the end of the substitutionis not aligned with the end of the double quote.  This may be workedaround by inserting another pair of quotes:@example$ @kbd{echo "`printf 'foo\r\n'` bar" > broken}$ @kbd{echo "`printf 'foo\r\n'`"" bar" | cmp - broken}- broken differ: char 4, line 1@end exampleUpon interrupt or SIGTERM, some shells may abort a command substitution,replace it with a null string, and wrongly evaluate the enclosingcommand before entering the trap or ending the script.  This can lead tospurious errors:@example$ @kbd{sh -c 'if test `sleep 5; echo hi` = hi; then echo yes; fi'}$ @kbd{^C}sh: test: hi: unexpected operator/operand@end example@noindentYou can avoid this by assigning the command substitution to a temporaryvariable:@example$ @kbd{sh -c 'res=`sleep 5; echo hi`         if test "x$res" = xhi; then echo yes; fi'}$ @kbd{^C}@end example@item $(@var{commands})@cindex @code{$(@var{commands})}This construct is meant to replace @samp{`@var{commands}`},and it has most of the problems listed under @code{`@var{commands}`}.This construct can benested while this is impossible to do portably with back quotes.Unfortunately it is not yet universally supported.  Most notably, even recentreleases of Solaris don't support it:@example$ @kbd{showrev -c /bin/sh | grep version}Command version: SunOS 5.10 Generic 121005-03 Oct 2006$ @kbd{echo $(echo blah)}syntax error: `(' unexpected@end example@noindentnor does IRIX 6.5's Bourne shell:@example$ @kbd{uname -a}IRIX firebird-image 6.5 07151432 IP22$ @kbd{echo $(echo blah)}$(echo blah)@end exampleIf you do use @samp{$(@var{commands})}, make sure that the commandsdo not start with a parenthesis, as that would cause confusion witha different notation @samp{$((@var{expression}))} that in modernshells is an arithmetic expression not a command.  To avoid theconfusion, insert a space between the two opening parentheses.Avoid @var{commands} that contain unbalanced parentheses inhere-documents, comments, or case statement patterns, as many shellsmishandle them.  For example, Bash 3.1, @samp{ksh88}, @command{pdksh}5.2.14, and Zsh 4.2.6 all mishandle the following valid command:@exampleecho $(case x in x) echo hello;; esac)@end example@item $((@var{expression}))@cindex @code{$((@var{expression}))}Arithmetic expansion is not portable as some shells (mostnotably Solaris 10 @command{/bin/sh}) don't support it.Among shells that do support @samp{$(( ))}, not all of them obey thePosix rule that octal and hexadecimal constants must be recognized:@example$ @kbd{bash -c 'echo $(( 010 + 0x10 ))'}24$ @kbd{zsh -c 'echo $(( 010 + 0x10 ))'}26$ @kbd{zsh -c 'emulate sh; echo $(( 010 + 0x10 ))'}24$ @kbd{pdksh -c 'echo $(( 010 + 0x10 ))'}pdksh:  010 + 0x10 : bad number `0x10'$ @kbd{pdksh -c 'echo $(( 010 ))'}10@end exampleWhen it is available, using arithmetic expansion provides a noticeablespeedup in script execution; but testing for support requires@command{eval} to avoid syntax errors.  The following construct is usedby @code{AS_VAR_ARITH} to provide arithmetic computation when allarguments are provided in decimal and without a leading zero, and alloperators are properly quoted and appear as distinct arguments:@exampleif ( eval 'test $(( 1 + 1 )) = 2' ) 2>/dev/null; then  eval 'func_arith ()  @{    func_arith_result=$(( $* ))  @}'else  func_arith ()  @{    func_arith_result=`expr "$@@"`  @}fifunc_arith 1 + 1foo=$func_arith_result@end example@item ^@cindex @code{^} quotingAlways quote @samp{^}, otherwise traditional shells such as@command{/bin/sh} on Solaris 10 treat this like @samp{|}.@end table@node Assignments@section Assignments@cindex Shell assignmentsWhen setting several variables in a row, be aware that the order of theevaluation is undefined.  For instance @samp{foo=1 foo=2; echo $foo}gives @samp{1} with Solaris @command{/bin/sh}, but @samp{2} with Bash.You must use@samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}.Don't rely on the following to find @file{subdir/program}:@examplePATH=subdir$PATH_SEPARATOR$PATH program@end example@noindentas this does not work with Zsh 3.0.6.  Use something like thisinstead:@example(PATH=subdir$PATH_SEPARATOR$PATH; export PATH; exec program)@end exampleDon't rely on the exit status of an assignment: Ash 0.2 does not changethe status and propagates that of the last statement:@example$ @kbd{false || foo=bar; echo $?}1$ @kbd{false || foo=`:`; echo $?}0@end example@noindentand to make things even worse, QNX 4.25 just sets the exit statusto 0 in any case:@example$ @kbd{foo=`exit 1`; echo $?}0@end exampleTo assign default values, follow this algorithm:@enumerate@itemIf the default value is a literal and does not contain any closingbrace, use:@example: "$@{var='my literal'@}"@end example@itemIf the default value contains no closing brace, has to be expanded, andthe variable being initialized is not intended to be IFS-split(i.e., it's not a list), then use:@example: $@{var="$default"@}@end example@itemIf the default value contains no closing brace, has to be expanded, andthe variable being initialized is intended to be IFS-split (i.e., it's a list),then use:@examplevar=$@{var="$default"@}@end example@itemIf the default value contains a closing brace, then use:@exampletest "$@{var+set@}" = set || var="has a '@}'"@end example@end enumerateIn most cases @samp{var=$@{var="$default"@}} is fine, but in case ofdoubt, just use the last form.  @xref{Shell Substitutions}, items@samp{$@{@var{var}:-@var{value}@}} and @samp{$@{@var{var}=@var{value}@}}for the rationale.@node Parentheses@section Parentheses in Shell Scripts@cindex Shell parenthesesBeware of two opening parentheses in a row, as many shellimplementations treat them specially, and Posix says that a portablescript cannot use @samp{((} outside the @samp{$((} form used for shellarithmetic.  In traditional shells, @samp{((cat))} behaves like@samp{(cat)}; but many shells, includingBash and the Korn shell, treat @samp{((cat))} as an arithmeticexpression equivalent to @samp{let "cat"}, and may or may not report anerror when they detect that @samp{cat} is not a number.  As anotherexample, @samp{pdksh} 5.2.14 does not treat the following codeas a traditional shell would:@exampleif ((true) || false); then  echo okfi@end example@noindentTo work around this problem, insert a space between the two openingparentheses.  There is a similar problem and workaround with@samp{$((}; see @ref{Shell Substitutions}.@node Slashes@section Slashes in Shell Scripts@cindex Shell slashesUnpatched Tru64 5.1 @command{sh} omits the last slash of command-linearguments that contain two trailing slashes:@example$ @kbd{echo / // /// //// .// //.}/ / // /// ./ //.$ @kbd{x=//}$ @kbd{eval "echo \$x"}/$ @kbd{set -x}$ @kbd{echo abc | tr -t ab //}+ echo abc+ tr -t ab //bc@end exampleUnpatched Tru64 4.0 @command{sh} adds a slash after @samp{"$var"} if thevariable is empty and the second double-quote is followed by a word thatbegins and ends with slash:@example$ @kbd{sh -xc 'p=; echo "$p"/ouch/'}p=+ echo //ouch///ouch/@end exampleHowever, our understanding is that patches are available, so perhapsit's not worth worrying about working around these horrendous bugs.@node Special Shell Variables@section Special Shell Variables@cindex Shell variables@cindex Special shell variablesSome shell variables should not be used, since they can have a deepinfluence on the behavior of the shell.  In order to recover a sanebehavior from the shell, some variables should be unset; M4sh takescare of this and provides fallback values, whenever needed, to caterfor a very old @file{/bin/sh} that does not support @command{unset}.(@pxref{Portable Shell, , Portable Shell Programming}).As a general rule, shell variable names containing a lower-case letterare safe; you can define and use these variables without worrying abouttheir effect on the underlying system, and without worrying aboutwhether the shell changes them unexpectedly.  (The exception is theshell variable @code{status}, as described below.)Here is a list of names that are known to cause trouble.  This list isnot exhaustive, but you should be safe if you avoid the name@code{status} and names containing only upper-case letters andunderscores.@c Alphabetical order, case insensitive, `A' before `a'.@table @code@item ?Not all shells correctly reset @samp{$?} after conditionals (@pxref{if,, Limitations of Shell Builtins}).  Not all shells manage @samp{$?}correctly in shell functions (@pxref{Shell Functions}) or in traps(@pxref{trap, , Limitations of Shell Builtins}).  Not all shells reset@samp{$?} to zero after an empty command.@example$ @kbd{bash -c 'false; $empty; echo $?'}0$ @kbd{zsh -c 'false; $empty; echo $?'}1@end example@item _@evindex _Many shells reserve @samp{$_} for various purposes, e.g., the name ofthe last command executed.@item BIN_SH@evindex BIN_SHIn Tru64, if @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations ofthe standard shell conform to Posix.@item CDPATH@evindex CDPATHWhen this variable is set it specifies a list of directories to searchwhen invoking @code{cd} with a relative file name that did not startwith @samp{./} or @samp{../}.  Posix1003.1-2001 says that if a nonempty directory name from @env{CDPATH}is used successfully, @code{cd} prints the resulting absolutefile name.  Unfortunately this output can break idioms like@samp{abs=`cd src && pwd`} because @code{abs} receives the name twice.Also, many shells do not conform to this part of Posix; forexample, @command{zsh} prints the result only if a directory nameother than @file{.} was chosen from @env{CDPATH}.In practice the shells that have this problem also support@command{unset}, so you can work around the problem as follows:@example(unset CDPATH) >/dev/null 2>&1 && unset CDPATH@end exampleYou can also avoid output by ensuring that your directory name isabsolute or anchored at @samp{./}, as in @samp{abs=`cd ./src && pwd`}.Configure scripts use M4sh, which automatically unsets @env{CDPATH} ifpossible, so you need not worry about this problem in those scripts.@item CLICOLOR_FORCE@evindex CLICOLOR_FORCEWhen this variable is set, some implementations of tools like@command{ls} attempt to add color to their output via terminal escapesequences, even when the output is not directed to a terminal, and canthus cause spurious failures in scripts.  Configure scripts use M4sh,which automatically unsets this variable.@item DUALCASE@evindex DUALCASEIn the MKS shell, case statements and file name generation arecase-insensitive unless @env{DUALCASE} is nonzero.Autoconf-generated scripts export this variable when they start up.@item ENV@itemx MAIL@itemx MAILPATH@itemx PS1@itemx PS2@itemx PS4@evindex ENV@evindex MAIL@evindex MAILPATH@evindex PS1@evindex PS2@evindex PS4These variables should not matter for shell scripts, since they aresupposed to affect only interactive shells.  However, at least oneshell (the pre-3.0 UWIN Korn shell) gets confused aboutwhether it is interactive, which means that (for example) a @env{PS1}with a side effect can unexpectedly modify @samp{$?}.  To work aroundthis bug, M4sh scripts (including @file{configure} scripts) do somethinglike this:@example(unset ENV) >/dev/null 2>&1 && unset ENV MAIL MAILPATHPS1='$ 'PS2='> 'PS4='+ '@end example@noindent(actually, there is some complication due to bugs in @command{unset};@pxref{unset, , Limitations of Shell Builtins}).@item FPATH@evindex FPATHThe Korn shell uses @env{FPATH} to find shell functions, so avoid@env{FPATH} in portable scripts.  @env{FPATH} is consulted after@env{PATH}, but you still need to be wary of tests that use @env{PATH}to find whether a command exists, since they might report the wrongresult if @env{FPATH} is also set.@item GREP_OPTIONS@evindex GREP_OPTIONSWhen this variable is set, some implementations of @command{grep} honorthese options, even if the options include direction to enable coloredoutput via terminal escape sequences, and the result can cause spuriousfailures when the output is not directed to a terminal.  Configurescripts use M4sh, which automatically unsets this variable.@item IFS@evindex IFSLong ago, shell scripts inherited @env{IFS} from the environment,but this caused many problems so modern shells ignore any environmentsettings for @env{IFS}.Don't set the first character of @env{IFS} to backslash.  Indeed,Bourne shells use the first character (backslash) when joining thecomponents in @samp{"$@@"} and some shells then reinterpret (!)@: thebackslash escapes, so you can end up with backspace and other strangecharacters.The proper value for @env{IFS} (in regular code, not when performingsplits) is @samp{@key{SPC}@key{TAB}@key{RET}}.  The first character isespecially important, as it is used to join the arguments in @samp{$*};however, note that traditional shells, but also bash-2.04, fail to adhereto this and join with a space anyway.M4sh guarantees that @env{IFS} will have the default value at thebeginning of a script, and many macros within autoconf rely on thissetting.  It is okay to use blocks of shell code that temporarily changethe value of @env{IFS} in order to split on another character, butremember to restore it before expanding further macros.Unsetting @code{IFS} instead of resetting it to the default sequenceis not suggested, since code that tries to save and restore thevariable's value will incorrectly reset it to an empty value, thusdisabling field splitting:@exampleunset IFS# default separators used for field splittingsave_IFS=$IFSIFS=:# ...IFS=$save_IFS# no field splitting performed@end example@item LANG@itemx LC_ALL@itemx LC_COLLATE@itemx LC_CTYPE@itemx LC_MESSAGES@itemx LC_MONETARY@itemx LC_NUMERIC@itemx LC_TIME@evindex LANG@evindex LC_ALL@evindex LC_COLLATE@evindex LC_CTYPE@evindex LC_MESSAGES@evindex LC_MONETARY@evindex LC_NUMERIC@evindex LC_TIMEYou should set all these variables to @samp{C} because so muchconfiguration code assumes the C locale and Posix requires that localeenvironment variables be set to @samp{C} if the C locale is desired;@file{configure} scripts and M4sh do that for you.Export these variables after setting them.@c  However, some older, nonstandard@c  systems (notably SCO) break if locale environment variables@c  are set to @samp{C}, so when running on these systems@c  Autoconf-generated scripts unset the variables instead.@item LANGUAGE@evindex LANGUAGE@env{LANGUAGE} is not specified by Posix, but it is a GNUextension that overrides @env{LC_ALL} in some cases, so you (or M4sh)should set it too.@item LC_ADDRESS@itemx LC_IDENTIFICATION@itemx LC_MEASUREMENT@itemx LC_NAME@itemx LC_PAPER@itemx LC_TELEPHONE@evindex LC_ADDRESS@evindex LC_IDENTIFICATION@evindex LC_MEASUREMENT@evindex LC_NAME@evindex LC_PAPER@evindex LC_TELEPHONEThese locale environment variables are GNU extensions.  Theyare treated like their Posix brethren (@env{LC_COLLATE},etc.)@: as described above.@item LINENO@evindex LINENOMost modern shells provide the current line number in @code{LINENO}.Its value is the line number of the beginning of the current command.M4sh, and hence Autoconf, attempts to execute @command{configure} witha shell that supports @code{LINENO}.  If no such shell is available, itattempts to implement @code{LINENO} with a Sed prepass that replaces eachinstance of the string @code{$LINENO} (not followed by an alphanumericcharacter) with the line's number.  In M4sh scripts you should execute@code{AS_LINENO_PREPARE} so that these workarounds are included inyour script; configure scripts do this automatically in @code{AC_INIT}.You should not rely on @code{LINENO} within @command{eval} or shellfunctions, as the behavior differs in practice.  The presence of aquoted newline within simple commands can alter which line number isused as the starting point for @code{$LINENO} substitutions within thatcommand.  Also, the possibility of the Sed prepass means that you shouldnot rely on @code{$LINENO} when quoted, when in here-documents, or whenline continuations are used.  Subshells should be OK, though.  In thefollowing example, lines 1, 9, and 14 are portable, but the otherinstances of @code{$LINENO} do not have deterministic values:@example@group$ @kbd{cat lineno}echo 1. $LINENOecho "2. $LINENO3. $LINENO"cat <<EOF5. $LINENO6. $LINENO7. \$LINENOEOF( echo 9. $LINENO )eval 'echo 10. $LINENO'eval 'echo 11. $LINENOecho 12. $LINENO'echo 13. '$LINENO'echo 14. $LINENO '15.' $LINENOf () @{ echo $1 $LINENO;echo $1 $LINENO @}f 18.echo 19. \$LINENO@end group@group$ @kbd{bash-3.2 ./lineno}1. 12. 33. 35. 46. 47. $LINENO9. 910. 1011. 1212. 1313. $LINENO14. 1415. 1418. 1618. 1719. 19@end group@group$ @kbd{zsh-4.3.4 ./lineno}1. 12. 23. 25. 46. 47. $LINENO9. 910. 111. 112. 213. $LINENO14. 1415. 1418. 018. 119. 19@end group@group$ @kbd{pdksh-5.2.14 ./lineno}1. 12. 23. 25. 46. 47. $LINENO9. 910. 011. 012. 013. $LINENO14. 1415. 1418. 1618. 1719. 19@end group@group$ @kbd{sed '=' <lineno |}> @kbd{  sed '}> @kbd{    N}> @kbd{    s,$,-,}> @kbd{    t loop}> @kbd{    :loop}> @kbd{    s,^\([0-9]*\)\(.*\)[$]LINENO\([^a-zA-Z0-9_]\),\1\2\1\3,}> @kbd{    t loop}> @kbd{    s,-$,,}> @kbd{    s,^[0-9]*\n,,}> @kbd{  ' |}> @kbd{  sh}1. 12. 23. 35. 56. 67. \79. 910. 1011. 1112. 1213. 1314. 1415. 1518. 1618. 1719. 20@end group@end exampleIn particular, note that @file{config.status} (and any other subsidiaryscript created by @code{AS_INIT_GENERATED}) might report line numbersrelative to the parent script as a result of the potential Sed pass.@item NULLCMD@evindex NULLCMDWhen executing the command @samp{>foo}, @command{zsh} executes@samp{$NULLCMD >foo} unless it is operating in Bourne shellcompatibility mode and the @command{zsh} version is newerthan 3.1.6-dev-18.  If you are using an older @command{zsh}and forget to set @env{NULLCMD},your script might be suspended waiting for data on its standard input.@item options@evindex optionsFor @command{zsh} 4.3.10, @env{options} is treated as an associativearray even after @code{emulate sh}, so it should not be used.@item PATH_SEPARATOR@evindex PATH_SEPARATOROn DJGPP systems, the @env{PATH_SEPARATOR} environmentvariable can be set to either @samp{:} or @samp{;} to control the pathseparator Bash uses to set up certain environment variables (such as@env{PATH}).  You can set this variable to @samp{;} if you want@command{configure} to use @samp{;} as a separator; this might be usefulif you plan to use non-Posix shells to execute files.  @xref{File SystemConventions}, for more information about @code{PATH_SEPARATOR}.@item POSIXLY_CORRECT@evindex POSIXLY_CORRECTIn the GNU environment, exporting @env{POSIXLY_CORRECT} with any value(even empty) causes programs to try harder to conform to Posix.Autoconf does not directly manipulate this variable, but @command{bash}ties the shell variable @env{POSIXLY_CORRECT} to whether the script isrunning in Posix mode.  Therefore, take care when exporting or unsettingthis variable, so as not to change whether @command{bash} is in Posixmode.@example$ @kbd{bash --posix -c 'set -o | grep posix}> @kbd{unset POSIXLY_CORRECT}> @kbd{set -o | grep posix'}posix           onposix           off@end example@item PWD@evindex PWDPosix 1003.1-2001 requires that @command{cd} and@command{pwd} must update the @env{PWD} environment variable to pointto the logical name of the current directory, but traditional shellsdo not support this.  This can cause confusion if one shell instancemaintains @env{PWD} but a subsidiary and different shell does not knowabout @env{PWD} and executes @command{cd}; in this case @env{PWD}points to the wrong directory.  Use @samp{`pwd`} rather than@samp{$PWD}.@item RANDOM@evindex RANDOMMany shells provide @code{RANDOM}, a variable that returns a differentinteger each time it is used.  Most of the time, its value does notchange when it is not used, but on IRIX 6.5 the value changes allthe time.  This can be observed by using @command{set}.  It is commonpractice to use @code{$RANDOM} as part of a file name, but codeshouldn't rely on @code{$RANDOM} expanding to a nonempty string.@item status@evindex statusThis variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6),hence read-only.  Do not use it.@end table@node Shell Functions@section Shell Functions@cindex Shell FunctionsNowadays, it is difficult to find a shell that does not supportshell functions at all.  However, some differences should be expected.When declaring a shell function, you must include whitespace between the@samp{)} after the function name and the start of the compoundexpression, to avoid upsetting @command{ksh}.  While it is possible touse any compound command, most scripts use @samp{@{@dots{}@}}.@example$ @kbd{/bin/sh -c 'a()@{ echo hi;@}; a'}hi$ @kbd{ksh -c 'a()@{ echo hi;@}; a'}ksh: syntax error at line 1: `@}' unexpected$ @kbd{ksh -c 'a() @{ echo hi;@}; a'}hi@end exampleInside a shell function, you should not rely on the error status of asubshell if the last command of that subshell was @code{exit} or@code{trap}, as this triggers bugs in zsh 4.x; while Autoconf tries tofind a shell that does not exhibit the bug, zsh might be the only shellpresent on the user's machine.Likewise, the state of @samp{$?} is not reliable when entering a shellfunction.  This has the effect that using a function as the firstcommand in a @command{trap} handler can cause problems.@example$ @kbd{bash -c 'foo() @{ echo $?; @}; trap foo 0; (exit 2); exit 2'; echo $?}22$ @kbd{ash -c 'foo() @{ echo $?; @}; trap foo 0; (exit 2); exit 2'; echo $?}02@end exampleDJGPP bash 2.04 has a bug in that @command{return} from ashell function which also used a command substitution causes asegmentation fault.  To work around the issue, you can use@command{return} from a subshell, or @samp{AS_SET_STATUS} as last commandin the execution flow of the function (@pxref{Common Shell Constructs}).Not all shells treat shell functions as simple commands impacted by@samp{set -e}, for example with Solaris 10 @command{/bin/sh}:@example$ @kbd{bash -c 'f() @{ return 1; @}; set -e; f; echo oops'}$ @kbd{/bin/sh -c 'f() @{ return 1; @}; set -e; f; echo oops'}oops@end exampleShell variables and functions may share the same namespace, for examplewith Solaris 10 @command{/bin/sh}:@example$ @kbd{f () @{ :; @}; f=; f}f: not found@end example@noindentFor this reason, Autoconf (actually M4sh, @pxref{Programming in M4sh})uses the prefix @samp{as_fn_} for its functions.Handling of positional parameters and shell options varies among shells.For example, Korn shells reset and restore trace output (@samp{set -x})and other options upon function entry and exit.  Inside a function,IRIX sh sets @samp{$0} to the function name.It is not portable to pass temporary environment variables to shellfunctions.  Solaris @command{/bin/sh} does not see the variable.Meanwhile, not all shells follow the Posix rule that the assignment mustaffect the current environment in the same manner as special built-ins.@example$ @kbd{/bin/sh -c 'func() @{ echo $a;@}; a=1 func; echo $a'}@result{}@result{}$ @kbd{ash -c 'func() @{ echo $a;@}; a=1 func; echo $a'}@result{}1@result{}$ @kbd{bash -c 'set -o posix; func() @{ echo $a;@}; a=1 func; echo $a'}@result{}1@result{}1@end exampleSome ancient Bourne shell variants with function support did not reset@samp{$@var{i}, @var{i} >= 0}, upon function exit, so effectively thearguments of the script were lost after the first function invocation.It is probably not worth worrying about these shells any more.With AIX sh, a @command{trap} on 0 installed in a shell functiontriggers at function exit rather than at script exit.  @xref{trap, ,Limitations of Shell Builtins}.@node Limitations of Builtins@section Limitations of Shell Builtins@cindex Shell builtins@cindex Limitations of shell builtinsNo, no, we are serious: some shells do have limitations!  :)You should always keep in mind that any builtin or command may supportoptions, and therefore differ in behavior with argumentsstarting with a dash.  For instance, even the innocent @samp{echo "$word"}can give unexpected results when @code{word} starts with a dash.  It isoften possible to avoid this problem using @samp{echo "x$word"}, takingthe @samp{x} into account later in the pipe.  Many of these limitationscan be worked around using M4sh (@pxref{Programming in M4sh}).@c This table includes things like `@command{test} (files)', so we can't@c use @table @command.@table @asis@item @command{.}@c --------------@prindex @command{.}Use @command{.} only with regular files (use @samp{test -f}).  Bash2.03, for instance, chokes on @samp{. /dev/null}.  Remember that@command{.} uses @env{PATH} if its argument contains no slashes.  Also,some shells, including bash 3.2, implicitly append the current directoryto this @env{PATH} search, even though Posix forbids it.  So if you wantto use @command{.} on a file @file{foo} in the current directory, youmust use @samp{. ./foo}.Not all shells gracefully handle syntax errors within a sourced file.On one extreme, some non-interactive shells abort the entire script.  Onthe other, @command{zsh} 4.3.10 has a bug where it fails to react to thesyntax error.@example$ @kbd{echo 'fi' > syntax}$ @kbd{bash -c '. ./syntax; echo $?'}./syntax: line 1: syntax error near unexpected token `fi'./syntax: line 1: `fi'1$ @kbd{ash -c '. ./syntax; echo $?'}./syntax: 1: Syntax error: "fi" unexpected$ @kbd{zsh -c '. ./syntax; echo $?'}./syntax:1: parse error near `fi'0@end example@item @command{!}@c --------------@prindex @command{!}The Unix version 7 shell did not supportnegating the exit status of commands with @command{!}, and this featureis still absent from some shells (e.g., Solaris @command{/bin/sh}).Other shells, such as FreeBSD @command{/bin/sh} or @command{ash}, havebugs when using @command{!}:@example$ @kbd{sh -c '! : | :'; echo $?}1$ @kbd{ash -c '! : | :'; echo $?}0$ @kbd{sh -c '! @{ :; @}'; echo $?}1$ @kbd{ash -c '! @{ :; @}'; echo $?}@{: not foundSyntax error: "@}" unexpected2@end exampleShell code like this:@exampleif ! cmp file1 file2 >/dev/null 2>&1; then  echo files differ or troublefi@end exampleis therefore not portable in practice.  Typically it is easy to rewritesuch code, e.g.:@examplecmp file1 file2 >/dev/null 2>&1 ||  echo files differ or trouble@end exampleMore generally, one can always rewrite @samp{! @var{command}} as:@exampleif @var{command}; then (exit 1); else :; fi@end example@item @command{@{...@}}@c --------------------@prindex @command{@{...@}}Bash 3.2 (and earlier versions) sometimes does not properly set@samp{$?} when failing to write redirected output of a compound command.This problem is most commonly observed with @samp{@{@dots{}@}}; it doesnot occur with @samp{(@dots{})}.  For example:@example$ @kbd{bash -c '@{ echo foo; @} >/bad; echo $?'}bash: line 1: /bad: Permission denied0$ @kbd{bash -c 'while :; do echo; done >/bad; echo $?'}bash: line 1: /bad: Permission denied0@end exampleTo work around the bug, prepend @samp{:;}:@example$ @kbd{bash -c ':;@{ echo foo; @} >/bad; echo $?'}bash: line 1: /bad: Permission denied1@end examplePosix requires a syntax error if a brace list has no contents.  However,not all shells obey this rule; and on shells where empty lists arepermitted, the effect on @samp{$?} is inconsistent.  To avoid problems,ensure that a brace list is never empty.@example$ @kbd{bash -c 'false; @{ @}; echo $?' || echo $?}bash: line 1: syntax error near unexpected token `@}'bash: line 1: `false; @{ @}; echo $?'2$ @kbd{zsh -c 'false; @{ @}; echo $?' || echo $?}1$ @kbd{pdksh -c 'false; @{ @}; echo $?' || echo $?}0@end example@item @command{break}@c ------------------@prindex @command{break}The use of @samp{break 2} etc.@: is safe.@anchor{case}@item @command{case}@c -----------------@prindex @command{case}You don't need to quote the argument; no splitting is performed.You don't need the final @samp{;;}, but you should use it.Posix requires support for @code{case} patterns with openingparentheses like this:@examplecase $file_name in  (*.c) echo "C source code";;esac@end example@noindentbut the @code{(} in this example is not portable to many Bourneshell implementations, which is a pity for those of us using tools thatrely on balanced parentheses.  For instance, with Solaris@command{/bin/sh}:@example$ @kbd{case foo in (foo) echo foo;; esac}@error{}syntax error: `(' unexpected@end example@noindentThe leading @samp{(} can be omitted safely.  Unfortunately, there arecontexts where unbalanced parentheses cause other problems, such as whenusing a syntax-highlighting editor that searches for the balancingcounterpart, or more importantly, when using a case statement as anunderquoted argument to an Autoconf macro.  @xref{BalancingParentheses}, for tradeoffs involved in various styles of dealing withunbalanced @samp{)}.Zsh handles pattern fragments derived from parameter expansions orcommand substitutions as though quoted:@example$ pat=\?; case aa in ?$pat) echo match;; esac$ pat=\?; case a? in ?$pat) echo match;; esacmatch@end example@noindentBecause of a bug in its @code{fnmatch}, Bash fails to properlyhandle backslashes in character classes:@examplebash-2.02$ @kbd{case /tmp in [/\\]*) echo OK;; esac}bash-2.02$@end example@noindentThis is extremely unfortunate, since you are likely to use this code tohandle Posix or MS-DOS absolute file names.  To work around thisbug, always put the backslash first:@examplebash-2.02$ @kbd{case '\TMP' in [\\/]*) echo OK;; esac}OKbash-2.02$ @kbd{case /tmp in [\\/]*) echo OK;; esac}OK@end exampleMany Bourne shells cannot handle closing brackets in character classescorrectly.Some shells also have problems with backslash escaping in case you do not wantto match the backslash: both a backslash and the escaped character match thispattern.  To work around this, specify the character class in a variable, sothat quote removal does not apply afterwards, and the special characters don'thave to be backslash-escaped:@example$ @kbd{case '\' in [\<]) echo OK;; esac}OK$ @kbd{scanset='[<]'; case '\' in $scanset) echo OK;; esac}$@end exampleEven with this, Solaris @command{ksh} matches a backslash if the setcontains anyof the characters @samp{|}, @samp{&}, @samp{(}, or @samp{)}.Conversely, Tru64 @command{ksh} (circa 2003) erroneously always matchesa closing parenthesis if not specified in a character class:@example$ @kbd{case foo in *\)*) echo fail ;; esac}fail$ @kbd{case foo in *')'*) echo fail ;; esac}fail@end exampleSome shells, such as Ash 0.3.8, are confused by an empty@code{case}/@code{esac}:@exampleash-0.3.8 $ @kbd{case foo in esac;}@error{}Syntax error: ";" unexpected (expecting ")")@end examplePosix requires @command{case} to give an exit status of 0 if no casesmatch.  However, @command{/bin/sh} in Solaris 10 does not obey thisrule.  Meanwhile, it is unclear whether a case that matches, butcontains no statements, must also change the exit status to 0.  The M4shmacro @code{AS_CASE} works around these inconsistencies.@example$ @kbd{bash -c 'case `false` in ?) ;; esac; echo $?'}0$ @kbd{/bin/sh -c 'case `false` in ?) ;; esac; echo $?'}255@end example@item @command{cd}@c ---------------@prindex @command{cd}Posix 1003.1-2001 requires that @command{cd} must supportthe @option{-L} (``logical'') and @option{-P} (``physical'') options,with @option{-L} being the default.  However, traditional shells donot support these options, and their @command{cd} command has the@option{-P} behavior.Portable scripts should assume neither option is supported, and shouldassume neither behavior is the default.  This can be a bit tricky,since the Posix default behavior means that, for example,@samp{ls ..} and @samp{cd ..} may refer to different directories ifthe current logical directory is a symbolic link.  It is safe to use@code{cd @var{dir}} if @var{dir} contains no @file{..} components.Also, Autoconf-generated scripts check for this problem when computingvariables like @code{ac_top_srcdir} (@pxref{Configuration Actions}),so it is safe to @command{cd} to these variables.Posix states that behavior is undefined if @command{cd} is given anexplicit empty argument.  Some shells do nothing, some change to thefirst entry in @env{CDPATH}, some change to @env{HOME}, and some exitthe shell rather than returning an error.  Unfortunately, this meansthat if @samp{$var} is empty, then @samp{cd "$var"} is less predictablethan @samp{cd $var} (at least the latter is well-behaved in all shellsat changing to @env{HOME}, although this is probably not what you wantedin a script).  You should check that a directory name was suppliedbefore trying to change locations.@xref{Special Shell Variables}, for portability problems involving@command{cd} and the @env{CDPATH} environment variable.Also please see the discussion of the @command{pwd} command.@anchor{echo}@item @command{echo}@c -----------------@prindex @command{echo}The simple @command{echo} is probably the most surprising source ofportability troubles.  It is not possible to use @samp{echo} portablyunless both options and escape sequences are omitted.  Don't expect anyoption.Do not use backslashes in the arguments, as there is no consensus ontheir handling.  For @samp{echo '\n' | wc -l}, the @command{sh} ofSolaris outputs 2, but Bash and Zsh (in @command{sh} emulation mode) output 1.The problem is truly @command{echo}: all the shellsunderstand @samp{'\n'} as the string composed of a backslash and an@samp{n}.  Within a command substitution, @samp{echo 'string\c'} willmess up the internal state of ksh88 on AIX 6.1 so that it will printthe first character @samp{s} only, followed by a newline, and thenentirely drop the output of the next echo in a command substitution.Because of these problems, do not pass a string containing arbitrarycharacters to @command{echo}.  For example, @samp{echo "$foo"} is safeonly if you know that @var{foo}'s value cannot contain backslashes andcannot start with @samp{-}.If this may not be true, @command{printf} is in general safer andeasier to use than @command{echo} and @command{echo -n}.  Thus, scriptswhere portability is not a major concern should use @command{printf'%s\n'} whenever @command{echo} could fail, and similarly use@command{printf %s} instead of @command{echo -n}. For portable shellscripts, instead, it is suggested to use a here-document like this:@examplecat <<EOF$fooEOF@end exampleAlternatively, M4sh provides @code{AS_ECHO} and @code{AS_ECHO_N} macroswhich choose between various portable implementations: @samp{echo}or @samp{print} where they work, @command{printf} if it is available,or else other creative tricks in order to work around the above problems.@item @command{eval}@c -----------------@prindex @command{eval}The @command{eval} command is useful in limited circumstances, e.g.,using commands like @samp{eval table_$key=\$value} and @samp{evalvalue=table_$key} to simulate a hash table when the key is known to bealphanumeric.You should also be wary of common bugs in @command{eval} implementations.In some shell implementations (e.g., older @command{ash}, OpenBSD 3.8@command{sh}, @command{pdksh} v5.2.14 99/07/13.2, and @command{zsh}4.2.5), the arguments of @samp{eval} are evaluated in a context where@samp{$?} is 0, so they exhibit behavior like this:@example$ @kbd{false; eval 'echo $?'}0@end exampleThe correct behavior here is to output a nonzero value,but portable scripts should not rely on this.You should not rely on @code{LINENO} within @command{eval}.@xref{Special Shell Variables}.Note that, even though these bugs are easily avoided,@command{eval} is tricky to use on arbitrary arguments.It is obviously unwise to use @samp{eval $cmd} if the string value of@samp{cmd} was derived from an untrustworthy source.  But even if thestring value is valid, @samp{eval $cmd} might not work as intended,since it causes field splitting and file name expansion to occur twice,once for the @command{eval} and once for the command itself.  It istherefore safer to use @samp{eval "$cmd"}.  For example, if @var{cmd}has the value @samp{cat test?.c}, @samp{eval $cmd} might expand to theequivalent of @samp{cat test;.c} if there happens to be a file named@file{test;.c} in the current directory; and this in turnmistakenly attempts to invoke @command{cat} on the file @file{test} andthen execute the command @command{.c}.  To avoid this problem, use@samp{eval "$cmd"} rather than @samp{eval $cmd}.However, suppose that you want to output the text of the evaluatedcommand just before executing it.  Assuming the previous example,@samp{echo "Executing: $cmd"} outputs @samp{Executing: cat test?.c}, butthis output doesn't show the user that @samp{test;.c} is the actual nameof the copied file.  Conversely, @samp{eval "echo Executing: $cmd"}works on this example, but it fails with @samp{cmd='cat foo >bar'},since it mistakenly replaces the contents of @file{bar} by thestring @samp{cat foo}.  No simple, general, and portable solution tothis problem is known.@item @command{exec}@c -----------------@prindex @command{exec}Posix describes several categories of shell built-ins.  Specialbuilt-ins (such as @command{exit}) must impact the environment of thecurrent shell, and need not be available through @command{exec}.  Allother built-ins are regular, and must not propagate variable assignmentsto the environment of the current shell.  However, the group of regularbuilt-ins is further distinguished by commands that do not require a@env{PATH} search (such as @command{cd}), in contrast to built-ins thatare offered as a more efficient version of something that must still befound in a @env{PATH} search (such as @command{echo}).  Posix is notclear on whether @command{exec} must work with the list of 17 utilitiesthat are invoked without a @env{PATH} search, and many platforms lack anexecutable for some of those built-ins:@example$ @kbd{sh -c 'exec cd /tmp'}sh: line 0: exec: cd: not found@end exampleAll other built-ins that provide utilities specified by Posix must havea counterpart executable that exists on @env{PATH}, although Posixallows @command{exec} to use the built-in instead of the executable.For example, contrast @command{bash} 3.2 and @command{pdksh} 5.2.14:@example$ @kbd{bash -c 'pwd --version' | head -n1}bash: line 0: pwd: --: invalid optionpwd: usage: pwd [-LP]$ @kbd{bash -c 'exec pwd --version' | head -n1}pwd (GNU coreutils) 6.10$ @kbd{pdksh -c 'exec pwd --version' | head -n1}pdksh: pwd: --: unknown option@end exampleWhen it is desired to avoid a regular shell built-in, the workaround isto use some other forwarding command, such as @command{env} or@command{nice}, that will ensure a path search:@example$ @kbd{pdksh -c 'exec true --version' | head -n1}$ @kbd{pdksh -c 'nice true --version' | head -n1}true (GNU coreutils) 6.10$ @kbd{pdksh -c 'env true --version' | head -n1}true (GNU coreutils) 6.10@end example@item @command{exit}@c -----------------@prindex @command{exit}The default value of @command{exit} is supposed to be @code{$?};unfortunately, some shells, such as the DJGPP port of Bash 2.04, justperform @samp{exit 0}.@examplebash-2.04$ @kbd{foo=`exit 1` || echo fail}failbash-2.04$ @kbd{foo=`(exit 1)` || echo fail}failbash-2.04$ @kbd{foo=`(exit 1); exit` || echo fail}bash-2.04$@end exampleUsing @samp{exit $?} restores the expected behavior.Some shell scripts, such as those generated by @command{autoconf}, use atrap to clean up before exiting.  If the last shell command exited withnonzero status, the trap also exits with nonzero status so that theinvoker can tell that an error occurred.Unfortunately, in some shells, such as Solaris @command{/bin/sh}, an exittrap ignores the @code{exit} command's argument.  In these shells, a trapcannot determine whether it was invoked by plain @code{exit} or by@code{exit 1}.  Instead of calling @code{exit} directly, use the@code{AC_MSG_ERROR} macro that has a workaround for this problem.@anchor{export}@item @command{export}@c -------------------@prindex @command{export}The builtin @command{export} dubs a shell variable @dfn{environmentvariable}.  Each update of exported variables corresponds to an updateof the environment variables.  Conversely, each environment variablereceived by the shell when it is launched should be imported as a shellvariable marked as exported.Alas, many shells, such as Solaris @command{/bin/sh},IRIX 6.3, IRIX 5.2,AIX 4.1.5, and Digital Unix 4.0, forget to@command{export} the environment variables they receive.  As a result,two variables coexist: the environment variable and the shellvariable.  The following code demonstrates this failure:@example#!/bin/shecho $FOOFOO=barecho $FOOexec /bin/sh $0@end example@noindentwhen run with @samp{FOO=foo} in the environment, these shells printalternately @samp{foo} and @samp{bar}, although they should print only@samp{foo} and then a sequence of @samp{bar}s.Therefore you should @command{export} again each environment variablethat you update; the export can occur before or after the assignment.Posix is not clear on whether the @command{export} of an undefinedvariable causes the variable to be defined with the value of an emptystring, or merely marks any future definition of a variable by that namefor export.  Various shells behave differently in this regard:@example$ @kbd{sh -c 'export foo; env | grep foo'}$ @kbd{ash -c 'export foo; env | grep foo'}foo=@end examplePosix requires @command{export} to honor assignments made as arguments,but older shells do not support this, including @command{/bin/sh} inSolaris 10.  Portable scripts should separate assignments and exportsinto different statements.@example$ @kbd{bash -c 'export foo=bar; echo $foo'}bar$ @kbd{/bin/sh -c 'export foo=bar; echo $foo'}/bin/sh: foo=bar: is not an identifier$ @kbd{/bin/sh -c 'export foo; foo=bar; echo $foo'}bar@end example@item @command{false}@c ------------------@prindex @command{false}Don't expect @command{false} to exit with status 1: in nativeSolaris @file{/bin/false} exits with status 255.@item @command{for}@c ----------------@prindex @command{for}To loop over positional arguments, use:@examplefor argdo  echo "$arg"done@end example@noindentYou may @emph{not} leave the @code{do} on the same line as @code{for},since some shells improperly grok:@examplefor arg; do  echo "$arg"done@end exampleIf you want to explicitly refer to the positional arguments, given the@samp{$@@} bug (@pxref{Shell Substitutions}), use:@examplefor arg in $@{1+"$@@"@}; do  echo "$arg"done@end example@noindentBut keep in mind that Zsh, even in Bourne shell emulation mode, performsword splitting on @samp{$@{1+"$@@"@}}; see @ref{Shell Substitutions},item @samp{$@@}, for more.In Solaris @command{/bin/sh}, when the list of arguments of a@command{for} loop starts with @emph{unquoted} tokens looking likevariable assignments, the loop is not executed on those tokens:@example$ @kbd{/bin/sh -c 'for v in a=b c=d x e=f; do echo $v; done'}xe=f@end example@noindentThankfully, quoting the assignment-like tokens, or starting the listwith other tokens (including unquoted variable expansion that results inan assignment-like result), avoids the problem, so it is easy to workaround:@example$ @kbd{/bin/sh -c 'for v in "a=b"; do echo $v; done'}a=b$ @kbd{/bin/sh -c 'x=a=b; for v in $x c=d; do echo $v; done'}a=bc=d@end example@anchor{if}@item @command{if}@c ---------------@prindex @command{if}Using @samp{!} is not portable.  Instead of:@exampleif ! cmp -s file file.new; then  mv file.new filefi@end example@noindentuse:@exampleif cmp -s file file.new; then :; else  mv file.new filefi@end example@noindentOr, especially if the @dfn{else} branch is short, you can use @code{||}.In M4sh, the @code{AS_IF} macro provides an easy way to write these kindsof conditionals:@exampleAS_IF([cmp -s file file.new], [], [mv file.new file])@end exampleThis is especially useful in other M4 macros, where the @dfn{then} and@dfn{else} branches might be macro arguments.Some very old shells did not reset the exit status from an @command{if}with no @command{else}:@example$ @kbd{if (exit 42); then true; fi; echo $?}42@end example@noindentwhereas a proper shell should have printed @samp{0}.  But this is nolonger a portability problem; any shell that supports functions gets itcorrect.  However, it explains why some makefiles have lengthyconstructs:@exampleif test -f "$file"; then  install "$file" "$dest"else  :fi@end example@item @command{printf}@c ------------------@prindex @command{printf}A format string starting with a @samp{-} can cause problems.Bash interprets it as an option andgives an error.  And @samp{--} to mark the end of options is not goodin the NetBSD Almquist shell (e.g., 0.4.6) which takes thatliterally as the format string.  Putting the @samp{-} in a @samp{%c}or @samp{%s} is probably easiest:@exampleprintf %s -foo@end exampleBash 2.03 mishandles an escape sequence that happens to evaluate to @samp{%}:@example$ @kbd{printf '\045'}bash: printf: `%': missing format character@end exampleLarge outputs may cause trouble.  On Solaris 2.5.1 through 10, forexample, @file{/usr/bin/printf} is buggy, so when using@command{/bin/sh} the command @samp{printf %010000x 123} normally dumpscore.Since @command{printf} is not always a shell builtin, there is apotential speed penalty for using @code{printf '%s\n'} as a replacementfor an @command{echo} that does not interpret @samp{\} or leading@samp{-}. With Solaris @command{ksh}, it is possible to use @code{print-r --} for this role instead.@xref{echo, , Limitations of Shell Builtins} for a discussion ofportable alternatives to both @command{printf} and @command{echo}.@item @command{pwd}@c ----------------@prindex @command{pwd}With modern shells, plain @command{pwd} outputs a ``logical''directory name, some of whose components may be symbolic links.  Thesedirectory names are in contrast to ``physical'' directory names, whosecomponents are all directories.Posix 1003.1-2001 requires that @command{pwd} must supportthe @option{-L} (``logical'') and @option{-P} (``physical'') options,with @option{-L} being the default.  However, traditional shells donot support these options, and their @command{pwd} command has the@option{-P} behavior.Portable scripts should assume neither option is supported, and shouldassume neither behavior is the default.  Also, on many hosts@samp{/bin/pwd} is equivalent to @samp{pwd -P}, but Posixdoes not require this behavior and portable scripts should not rely onit.Typically it's best to use plain @command{pwd}.  On modern hosts thisoutputs logical directory names, which have the following advantages:@itemize @bullet@itemLogical names are what the user specified.@itemPhysical names may not be portable from one installationhost to another due to network file system gymnastics.@itemOn modern hosts @samp{pwd -P} may fail due to lack of permissions tosome parent directory, but plain @command{pwd} cannot fail for thisreason.@end itemizeAlso please see the discussion of the @command{cd} command.@item @command{read}@c -----------------@prindex @command{read}No options are portable, not even support @option{-r} (Solaris@command{/bin/sh} for example).  Tru64/OSF 5.1 @command{sh} treats@command{read} as a special built-in, so it may exit if input isredirected from a non-existent or unreadable file.@anchor{set}@item @command{set}@c ----------------@prindex @command{set}With the FreeBSD 6.0 shell, the @command{set} command (withoutany options) does not sort its output.The @command{set} builtin faces the usual problem with argumentsstarting with adash.  Modern shells such as Bash or Zsh understand @option{--} to specifythe end of the options (any argument after @option{--} is a parameter,even @samp{-x} for instance), but many traditional shells (e.g., Solaris10 @command{/bin/sh}) simply stop optionprocessing as soon as a non-option argument is found.  Therefore, use@samp{dummy} or simply @samp{x} to end the option processing, and use@command{shift} to pop it out:@exampleset x $my_list; shift@end exampleAvoid @samp{set -}, e.g., @samp{set - $my_list}.  Posix nolonger requires support for this command, and in traditional shells@samp{set - $my_list} resets the @option{-v} and @option{-x} options, whichmakes scripts harder to debug.Some nonstandard shells do not recognize more than one option(e.g., @samp{set -e -x} assigns @samp{-x} to the command line).  It isbetter to combine them:@exampleset -ex@end example@cindex @command{set -e}The option @option{-e} has historically been underspecified, with enoughambiguities to cause numerous differences across various shellimplementations; see for example@uref{http://www.in-ulm.de/@/~mascheck/@/various/@/set-e/, this overview},or @uref{http://www.austingroupbugs.net/@/view.php?id=52, this link},documenting a change to Posix 2008 to match @command{ksh88} behavior.Note that mixing @code{set -e} and shell functions is asking for surprises:@exampleset -edoit()@{  rm file  echo one@}doit || echo two@end example@noindentAccording to the recommendation, @samp{one} should always be outputregardless of whether the @command{rm} failed, because it occurs withinthe body of the shell function @samp{doit} invoked on the left side of@samp{||}, where the effects of @samp{set -e} are not enforced.Likewise, @samp{two} should never be printed, since the failure of@command{rm} does not abort the function, such that the status of@samp{doit} is 0.The BSD shell has had several problems with the @option{-e}option.  Older versions of the BSDshell (circa 1990) mishandled @samp{&&}, @samp{||}, @samp{if}, and@samp{case} when @option{-e} was in effect, causing the shell to exitunexpectedly in some cases.  This was particularly a problem withmakefiles, and led to circumlocutions like @samp{sh -c 'test -f file ||touch file'}, where the seemingly-unnecessary @samp{sh -c '@dots{}'}wrapper works around the bug (@pxref{Failure in Make Rules}).Even relatively-recent versions of the BSD shell (e.g., OpenBSD 3.4)wrongly exit with @option{-e} if the last command within a compoundstatement fails and is guarded by an @samp{&&} only.  For example:@example#! /bin/shset -efoo=''test -n "$foo" && exit 1echo oneif :; then  test -n "$foo" && exit 1  echo two  test -n "$foo" && exit 1fiecho three@end example@noindentdoes not print @samp{three}.  One workaround is to change the lastinstance of @samp{test -n "$foo" && exit 1} to be @samp{if test -n"$foo"; then exit 1; fi} instead.  Another possibility is to warn BSDusers not to use @samp{sh -e}.When @samp{set -e} is in effect, a failed command substitution inSolaris @command{/bin/sh} cannot be ignored, even with @samp{||}.@example$ @kbd{/bin/sh -c 'set -e; foo=`false` || echo foo; echo bar'}$ @kbd{bash -c 'set -e; foo=`false` || echo foo; echo bar'}foobar@end example@noindentMoreover, a command substitution, successful or not, causes this shell toexit from a failing outer command even in presence of an @samp{&&} list:@example$ @kbd{bash -c 'set -e; false `true` && echo notreached; echo ok'}ok$ @kbd{sh -c 'set -e; false `true` && echo notreached; echo ok'}$@end examplePortable scripts should not use @samp{set -e} if @command{trap} is usedto install an exit handler.  This is because Tru64/OSF 5.1 @command{sh}sometimes enters the trap handler with the exit status of the commandprior to the one that triggered the errexit handler:@example$ @kbd{sh -ec 'trap '\''echo $?'\'' 0; false'}0$ @kbd{sh -c 'set -e; trap '\''echo $?'\'' 0; false'}1@end example@noindentThus, when writing a script in M4sh, rather than trying to rely on@samp{set -e}, it is better to append @samp{|| AS_EXIT} to anystatement where it is desirable to abort on failure.@cindex @command{set -b}@cindex @command{set -m}Job control is not provided by all shells, so the use of @samp{set -m}or @samp{set -b} must be done with care.  When using @command{zsh} innative mode, asynchronous notification (@samp{set -b}) is enabled bydefault, and using @samp{emulate sh} to switch to Posix mode does notclear this setting (although asynchronous notification has no impactunless job monitoring is also enabled).  Also, @command{zsh} 4.3.10 andearlier have a bug where job control can be manipulated in interactiveshells, but not in subshells or scripts.  Furthermore, some shells, like@command{pdksh}, fail to treat subshells as interactive, even though theparent shell was.@example$ @kbd{echo $ZSH_VERSION}4.3.10$ @kbd{set -m; echo $?}0$ @kbd{zsh -c 'set -m; echo $?'}set: can't change option: -m$ @kbd{(set -m); echo $?}set: can't change option: -m1$ @kbd{pdksh -ci 'echo $-; (echo $-)'}cimc@end example@cindex @command{set -n}Use of @command{set -n} (typically via @command{sh -n script}) tovalidate a script is not foolproof.  Modern @command{ksh93} tries to behelpful by informing you about better syntax, but switching the scriptto use the suggested syntax in order to silence the warnings wouldrender the script no longer portable to older shells:@example$ @kbd{ksh -nc '``'}ksh: warning: line 1: `...` obsolete, use $(...)0@end exampleFurthermore, on ancient hosts, such as SunOS 4, @command{sh -n} could gointo an infinite loop; even with that bug fixed, Solaris 8@command{/bin/sh} takes extremely long to parse large scripts.  Autoconfitself uses @command{sh -n} within its testsuite to check that correctscripts were generated, but only after first probing for other shellfeatures (such as @code{test -n "$@{BASH_VERSION+set@}"}) that indicatea reasonably fast and working implementation.@item @command{shift}@c ------------------@prindex @command{shift}Not only is @command{shift}ing a bad idea when there is nothing left toshift, but in addition it is not portable: the shell of MIPSRISC/OS 4.52 refuses to do it.Don't use @samp{shift 2} etc.; while it in the SVR1 shell (1983),it is also absent in many pre-Posix shells.@item @command{source}@c -------------------@prindex @command{source}This command is not portable, as Posix does not require it; use@command{.} instead.@item @command{test}@c -----------------@prindex @command{test}The @code{test} program is the way to perform many file and stringtests.  It is often invoked by the alternate name @samp{[}, but usingthat name in Autoconf code is asking for trouble since it is an M4 quotecharacter.The @option{-a}, @option{-o}, @samp{(}, and @samp{)} operands are notpresent in all implementations, and have been marked obsolete by Posix2008.  This is because there are inherent ambiguities in using them.For example, @samp{test "$1" -a "$2"} looks like a binary operator tocheck whether two strings are both non-empty, but if @samp{$1} is theliteral @samp{!}, then some implementations of @command{test} treat itas a negation of the unary operator @option{-a}.Thus, portable uses of @command{test} should never have more than fourarguments, and scripts should use shell constructs like @samp{&&} and@samp{||} instead.  If you combine @samp{&&} and @samp{||} in the samestatement, keep in mind that they have equal precedence, so it is oftenbetter to parenthesize even when this is redundant.  For example:@smallexample# Not portable:test "X$a" = "X$b" -a \  '(' "X$c" != "X$d" -o "X$e" = "X$f" ')'# Portable:test "X$a" = "X$b" &&  @{ test "X$c" != "X$d" || test "X$e" = "X$f"; @}@end smallexample@command{test} does not process options like most other commands do; forexample, it does not recognize the @option{--} argument as marking theend of options.It is safe to use @samp{!} as a @command{test} operator.  For example,@samp{if test ! -d foo; @dots{}} is portable even though @samp{if ! test-d foo; @dots{}} is not.@item @command{test} (files)@c -------------------------To enable @command{configure} scripts to support cross-compilation, theyshouldn't do anything that tests features of the build system instead ofthe host system.  But occasionally you may find it necessary to checkwhether some arbitrary file exists.  To do so, use @samp{test -f},@samp{test -r}, or @samp{test -x}.  Do not use @samp{test -e}, becauseSolaris 10 @command{/bin/sh}lacks it.  To test for symbolic links on systems that have them, use@samp{test -h} rather than @samp{test -L}; either form conforms toPosix 1003.1-2001, but older shells like Solaris 8@code{/bin/sh} support only @option{-h}.For historical reasons, Posix reluctantly allows implementations of@samp{test -x} that will succeed for the root user, even if no executepermissions are present.  Furthermore, shells do not all agree onwhether Access Control Lists should affect @samp{test -r}, @samp{test-w}, and @samp{test -x}; some shells base test results strictly on thecurrent user id compared to file owner and mode, as if by@code{stat(2)}; while other shells base test results on whether thecurrent user has the given right, even if that right is only granted byan ACL, as if by @code{faccessat(2)}.  Furthermore, there is a classictime of check to time of use race between any use of @command{test}followed by operating on the just-checked file.  Therefore, it is a goodidea to write scripts that actually attempt an operation, and areprepared for the resulting failure if permission is denied, rather thantrying to avoid an operation based solely on whether @command{test}guessed that it might not be permitted.@item @command{test} (strings)@c ---------------------------Posix says that @samp{test "@var{string}"} succeeds if @var{string} isnot null, but this usage is not portable to traditional platforms likeSolaris 10 @command{/bin/sh}, which mishandle strings like @samp{!} and@samp{-n}.Posix also says that @samp{test ! "@var{string}"},@samp{test -n "@var{string}"} and@samp{test -z "@var{string}"} work with any string, but manyshells (such as Solaris, AIX 3.2, UNICOS 10.0.0.6,Digital Unix 4, etc.)@: get confused if@var{string} looks like an operator:@example$ @kbd{test -n =}test: argument expected$ @kbd{test ! -n}test: argument expected$ @kbd{test -z ")"; echo $?}0@end exampleSimilarly, Posix says that both @samp{test "@var{string1}" = "@var{string2"}}and @samp{test "@var{string1}" != "@var{string2"}} work for any pairs ofstrings, but in practice this is not true for troublesome strings thatlook like operators or parentheses, or that begin with @samp{-}.It is best to protect such strings with a leading @samp{X}, e.g.,@samp{test "X@var{string}" != X} rather than @samp{test -n"@var{string}"} or @samp{test ! "@var{string}"}.It is common to find variations of the following idiom:@exampletest -n "`echo $ac_feature | sed 's/[-a-zA-Z0-9_]//g'`" &&  @var{action}@end example@noindentto take an action when a token matches a given pattern.  Such constructsshould be avoided by using:@examplecase $ac_feature in  *[!-a-zA-Z0-9_]*) @var{action};;esac@end exampleIf the pattern is a complicated regular expression that cannot beexpressed as a shell pattern, use something like this instead:@exampleexpr "X$ac_feature" : 'X.*[^-a-zA-Z0-9_]' >/dev/null &&  @var{action}@end example@samp{expr "X@var{foo}" : "X@var{bar}"} is more robust than @samp{echo"X@var{foo}" | grep "^X@var{bar}"}, because it avoids problems when@samp{@var{foo}} contains backslashes.@anchor{trap}@item @command{trap}@c -----------------@prindex @command{trap}It is safe to trap at least the signals 1, 2, 13, and 15.  You can alsotrap 0, i.e., have the @command{trap} run when the script ends (either via anexplicit @command{exit}, or the end of the script).  The trap for 0 should beinstalled outside of a shell function, or AIX 5.3 @command{/bin/sh}will invoke the trap at the end of this function.Posix says that @samp{trap - 1 2 13 15} resets the traps for thespecified signals to their default values, but many common shells (e.g.,Solaris @command{/bin/sh}) misinterpret this and attempt to execute a``command'' named @command{-} when the specified conditions arise.Posix 2008 also added a requirement to support @samp{trap 1 2 13 15} toreset traps, as this is supported by a larger set of shells, but thereare still shells like @command{dash} that mistakenly try to execute@command{1} instead of resetting the traps.  Therefore, there is noportable workaround, except for @samp{trap - 0}, for which@samp{trap '' 0} is a portable substitute.Although Posix is not absolutely clear on this point, it is widelyadmitted that when entering the trap @samp{$?} should be set to the exitstatus of the last command run before the trap.  The ambiguity can besummarized as: ``when the trap is launched by an @command{exit}, what isthe @emph{last} command run: that before @command{exit}, or@command{exit} itself?''Bash considers @command{exit} to be the last command, while Zsh andSolaris @command{/bin/sh} consider that when the trap is run it is@emph{still} in the @command{exit}, hence it is the previous exit statusthat the trap receives:@example$ @kbd{cat trap.sh}trap 'echo $?' 0(exit 42); exit 0$ @kbd{zsh trap.sh}42$ @kbd{bash trap.sh}0@end exampleThe portable solution is then simple: when you want to @samp{exit 42},run @samp{(exit 42); exit 42}, the first @command{exit} being used toset the exit status to 42 for Zsh, and the second to trigger the trapand pass 42 as exit status for Bash.  In M4sh, this is covered by using@code{AS_EXIT}.The shell in FreeBSD 4.0 has the following bug: @samp{$?} isreset to 0 by empty lines if the code is inside @command{trap}.@example$ @kbd{trap 'false}echo $?' 0$ @kbd{exit}0@end example@noindentFortunately, this bug only affects @command{trap}.Several shells fail to execute an exit trap that is defined inside asubshell, when the last command of that subshell is not a builtin.  Aworkaround is to use @samp{exit $?} as the shell builtin.@example$ @kbd{bash -c '(trap "echo hi" 0; /bin/true)'}hi$ @kbd{/bin/sh -c '(trap "echo hi" 0; /bin/true)'}$ @kbd{/bin/sh -c '(trap "echo hi" 0; /bin/true; exit $?)'}hi@end example@noindentLikewise, older implementations of @command{bash} failed to preserve@samp{$?} across an exit trap consisting of a single cleanup command.@example$ @kbd{bash -c 'trap "/bin/true" 0; exit 2'; echo $?}2$ @kbd{bash-2.05b -c 'trap "/bin/true" 0; exit 2'; echo $?}0$ @kbd{bash-2.05b -c 'trap ":; /bin/true" 0; exit 2'; echo $?}2@end example@item @command{true}@c -----------------@prindex @command{true}@c Info cannot handle `:' in index entries.@c @prindex @command{:}Don't worry: as far as we know @command{true} is portable.Nevertheless, it's not always a builtin (e.g., Bash 1.x), and theportable shell community tends to prefer using @command{:}.  This has afunny side effect: when asked whether @command{false} is more portablethan @command{true} Alexandre Oliva answered:@quotationIn a sense, yes, because if it doesn't exist, the shell will produce anexit status of failure, which is correct for @command{false}, but notfor @command{true}.@end quotationRemember that even though @samp{:} ignores its arguments, it still takestime to compute those arguments.  It is a good idea to use double quotesaround any arguments to @samp{:} to avoid time spent in field splittingand file name expansion.@anchor{unset}@item @command{unset}@c ------------------@prindex @command{unset}In some nonconforming shells (e.g., Solaris 10 @command{/bin/ksh} and@command{/usr/xpg4/bin/sh}, NetBSD 5.99.43 sh, or Bash 2.05a),@code{unset FOO} fails when @code{FOO} is not set.  This can interferewith @code{set -e} operation.  You can use@smallexampleFOO=; unset FOO@end smallexample@noindentif you are not sure that @code{FOO} is set.A few ancient shells lack @command{unset} entirely.  For some variablessuch as @code{PS1}, you can use a neutralizing value instead:@smallexamplePS1='$ '@end smallexampleUsually, shells that do not support @command{unset} need less effort tomake the environment sane, so for example is not a problem if you cannotunset @command{CDPATH} on those shells.  However, Bash 2.01 mishandles@code{unset MAIL} and @code{unset MAILPATH} in some cases and dumps core.So, you should do something like@smallexample( (unset MAIL) || exit 1) >/dev/null 2>&1 && unset MAIL || :@end smallexample@noindent@xref{Special Shell Variables}, for some neutralizing values.  Also, see@ref{export, , Limitations of Builtins}, forthe case of environment variables.@item @command{wait}@c -----------------@prindex @command{wait}The exit status of @command{wait} is not always reliable.@end table@node Limitations of Usual Tools@section Limitations of Usual Tools@cindex Limitations of usual toolsThe small set of tools you can expect to find on any machine can stillinclude some limitations you should be aware of.@comment Between this list and the list of builtins above, we should@comment mention all the tools in GNU Coding Standards ``Utilities in@comment Makefiles''.@c This table includes things like `@command{expr} (|)', so we can't@c use @table @command.@table @asis@anchor{awk}@item @command{awk}@c ----------------@prindex @command{awk}Don't leave white space before the opening parenthesis in a user function call.Posix does not allow this and GNU Awk rejects it:@example$ @kbd{gawk 'function die () @{ print "Aaaaarg!"  @}        BEGIN @{ die () @}'}gawk: cmd. line:2:         BEGIN @{ die () @}gawk: cmd. line:2:                      ^ parse error$ @kbd{gawk 'function die () @{ print "Aaaaarg!"  @}        BEGIN @{ die() @}'}Aaaaarg!@end examplePosix says that if a program contains only @samp{BEGIN} actions, andcontains no instances of @code{getline}, then the program merelyexecutes the actions without reading input.  However, traditional Awkimplementations (such as Solaris 10 @command{awk}) read and discardinput in this case.  Portable scripts can redirect input from@file{/dev/null} to work around the problem.  For example:@exampleawk 'BEGIN @{print "hello world"@}' </dev/null@end examplePosix says that in an @samp{END} action, @samp{$NF} (and presumably,@samp{$1}) retain their value from the last record read, if nointervening @samp{getline} occurred.  However, some implementations(such as Solaris 10 @samp{/usr/bin/awk}, @samp{nawk}, or Darwin@samp{awk}) reset these variables.  A workaround is to use anintermediate variable prior to the @samp{END} block.  For example:@example$ @kbd{cat end.awk}@{ tmp = $1 @}END @{ print "a", $1, $NF, "b", tmp @}$ @kbd{echo 1 | awk -f end.awk}a   b 1$ @kbd{echo 1 | gawk -f end.awk}a 1 1 b 1@end exampleIf you want your program to be deterministic, don't depend on @code{for}on arrays:@example$ @kbd{cat for.awk}END @{  arr["foo"] = 1  arr["bar"] = 1  for (i in arr)    print i@}$ @kbd{gawk -f for.awk </dev/null}foobar$ @kbd{nawk -f for.awk </dev/null}barfoo@end exampleSome Awk implementations, such as HP-UX 11.0's native one,mishandle anchors:@example$ @kbd{echo xfoo | $AWK '/foo|^bar/ @{ print @}'}$ @kbd{echo bar | $AWK '/foo|^bar/ @{ print @}'}bar$ @kbd{echo xfoo | $AWK '/^bar|foo/ @{ print @}'}xfoo$ @kbd{echo bar | $AWK '/^bar|foo/ @{ print @}'}bar@end example@noindentEither do not depend on such patterns (i.e., use @samp{/^(.*foo|bar)/},or use a simple test to reject such implementations.On @samp{ia64-hp-hpux11.23}, Awk mishandles @code{printf} conversionsafter @code{%u}:@example$ @kbd{awk 'BEGIN @{ printf "%u %d\n", 0, -1 @}'}0 0@end exampleAIX version 5.2 has an arbitrary limit of 399 on thelength of regular expressions and literal strings in an Awk program.Traditional Awk implementations derived from Unix version 7, such asSolaris @command{/bin/awk}, have many limitations and do notconform to Posix.  Nowadays @code{AC_PROG_AWK} (@pxref{ParticularPrograms}) finds you an Awk that doesn't have these problems, but iffor some reason you prefer not to use @code{AC_PROG_AWK} you may need toaddress them.  For more detailed descriptions, see @ref{LanguageHistory, , @command{awk} language history, gawk, GNU Awk User's Guide}.Traditional Awk does not support multidimensional arrays or user-definedfunctions.Traditional Awk does not support the @option{-v} option.  You can useassignments after the program instead, e.g., @code{$AWK '@{print v$1@}' v=x}; however, don't forget that such assignments are notevaluated until they are encountered (e.g., after any @code{BEGIN}action).Traditional Awk does not support the keywords @code{delete} or @code{do}.Traditional Awk does not support the expressions@code{@var{a}?@var{b}:@var{c}}, @code{!@var{a}}, @code{@var{a}^@var{b}},or @code{@var{a}^=@var{b}}.Traditional Awk does not support the predefined @code{CONVFMT} or@code{ENVIRON} variables.Traditional Awk supports only the predefined functions @code{exp}, @code{index},@code{int}, @code{length}, @code{log}, @code{split}, @code{sprintf},@code{sqrt}, and @code{substr}.Traditional Awk @code{getline} is not at all compatible with Posix;avoid it.Traditional Awk has @code{for (i in a) @dots{}} but no other uses of the@code{in} keyword.  For example, it lacks @code{if (i in a) @dots{}}.In code portable to both traditional and modern Awk, @code{FS} must be astring containing just one ordinary character, and similarly for thefield-separator argument to @code{split}.Traditional Awk has a limit of 99 fields in a record.  Since some Awkimplementations, like Tru64's, split the input even if you don't referto any field in the script, to circumvent this problem, set @samp{FS}to an unusual character and use @code{split}.Traditional Awk has a limit of at most 99 bytes in a number formatted by@code{OFMT}; for example, @code{OFMT="%.300e"; print 0.1;} typicallydumps core.The original version of Awk had a limit of at most 99 bytes per@code{split} field, 99 bytes per @code{substr} substring, and 99 bytesper run of non-special characters in a @code{printf} format, but thesebugs have been fixed on all practical hosts that we know of.HP-UX 11.00 and IRIX 6.5 Awk require that input files have a line lengthof at most 3070 bytes.@item @command{basename}@c ---------------------@prindex @command{basename}Not all hosts have a working @command{basename}.You can use @command{expr} instead.@c AS_BASENAME is to be replaced by a better API.@ignoreNot all hosts have a working @command{basename}, and you should insteaduse @code{AS_BASENAME} (@pxref{Programming in M4sh}), followed by@command{expr} if you need to strip a suffix.  For example:@examplea=`basename "$aname"`       # This is not portable.a=`AS_BASENAME(["$aname"])` # This is more portable.# This is not portable.c=`basename "$cname" .c`# This is more portable.c=`AS_BASENAME(["$cname"])`case $c in?*.c) c=`expr "X$c" : 'X\(.*\)\.c'`;;esac@end example@end ignore@item @command{cat}@c ----------------@prindex @command{cat}Don't rely on any option.@item @command{cc}@c ---------------@prindex @command{cc}The command @samp{cc -c foo.c} traditionally produces an object filenamed @file{foo.o}.  Most compilers allow @option{-c} to be combinedwith @option{-o} to specify a different object file name, butPosix does not require this combination and a few compilerslack support for it.  @xref{C Compiler}, for how GNU Maketests for this feature with @code{AC_PROG_CC_C_O}.When a compilation such as @samp{cc -o foo foo.c} fails, some compilers(such as CDS on Reliant Unix) leave a @file{foo.o}.HP-UX @command{cc} doesn't accept @file{.S} files to preprocess andassemble.  @samp{cc -c foo.S} appears to succeed, but in fact doesnothing.The default executable, produced by @samp{cc foo.c}, can be@itemize@item @file{a.out} --- usual Posix convention.@item @file{b.out} --- i960 compilers (including @command{gcc}).@item @file{a.exe} --- DJGPP port of @command{gcc}.@item @file{a_out.exe} --- GNV @command{cc} wrapper for DEC C on OpenVMS.@item @file{foo.exe} --- various MS-DOS compilers.@end itemizeThe C compiler's traditional name is @command{cc}, but other names like@command{gcc} are common.  Posix 1003.1-2001 specifies thename @command{c99}, but older Posix editions specified@command{c89} and anyway these standard names are rarely used inpractice.  Typically the C compiler is invoked from makefiles that use@samp{$(CC)}, so the value of the @samp{CC} make variable selects thecompiler name.@item @command{chgrp}@itemx @command{chown}@c -------------------@prindex @command{chgrp}@prindex @command{chown}It is not portable to change a file's group to a group that the ownerdoes not belong to.@item @command{chmod}@c ------------------@prindex @command{chmod}Avoid usages like @samp{chmod -w file}; use @samp{chmod a-w file}instead, for two reasons.  First, plain @option{-w} does not necessarilymake the file unwritable, since it does not affect mode bits thatcorrespond to bits in the file mode creation mask.  Second,Posix says that the @option{-w} might be interpreted as animplementation-specific option, not as a mode; Posix suggestsusing @samp{chmod -- -w file} to avoid this confusion, but unfortunately@samp{--} does not work on some older hosts.@item @command{cmp}@c ----------------@prindex @command{cmp}@command{cmp} performs a raw data comparison of two files, while@command{diff} compares two text files.  Therefore, if you might compareDOS files, even if only checking whether two files are different, use@command{diff} to avoid spurious differences due to differences ofnewline encoding.@item @command{cp}@c ---------------@prindex @command{cp}Avoid the @option{-r} option, since Posix 1003.1-2004 marks it asobsolescent and its behavior on special files is implementation-defined.Use @option{-R} instead.  On GNU hosts the two optionsare equivalent, but on Solaris hosts (for example) @code{cp -r}reads from pipes instead of replicating them.  AIX 5.3 @code{cp -R} maycorrupt its own memory with some directory hierarchies and error out ordump core:@example@kbd{mkdir -p 12345678/12345678/12345678/12345678}@kbd{touch 12345678/12345678/x}@kbd{cp -R 12345678 t}cp: 0653-440 12345678/12345678/: name too long.@end exampleSome @command{cp} implementations (e.g., BSD/OS 4.2) do not allowtrailing slashes at the end of nonexistent destination directories.  Toavoid this problem, omit the trailing slashes.  For example, use@samp{cp -R source /tmp/newdir} rather than @samp{cp -R source/tmp/newdir/} if @file{/tmp/newdir} does not exist.@c This is thanks to Ian.The ancient SunOS 4 @command{cp} does not support @option{-f}, althoughits @command{mv} does.@cindex timestamp resolutionTraditionally, file timestamps had 1-second resolution, and @samp{cp-p} copied the timestamps exactly.  However, many modern file systemshave timestamps with 1-nanosecond resolution.  Unfortunately, some older@samp{cp -p} implementations truncate timestamps when copying files,which can cause the destination file to appear to be older than thesource.  The exact amount of truncation depends on the resolution ofthe system calls that @command{cp} uses.  Traditionally this was@code{utime}, which has 1-second resolution.  Less-ancient @command{cp}implementations such as GNU Core Utilities 5.0.91 (2003) use@code{utimes}, which has 1-microsecond resolution.  Modernimplementations such as GNU Core Utilities 6.12 (2008) can set timestamps tothe full nanosecond resolution, using the modern system calls@code{futimens} and @code{utimensat} when they are available.  As of2011, though, many platforms do not yet fully support these new systemcalls.Bob Proulx notes that @samp{cp -p} always @emph{tries} to copyownerships.  But whether it actually does copy ownerships or not is asystem dependent policy decision implemented by the kernel.  If thekernel allows it then it happens.  If the kernel does not allow it thenit does not happen.  It is not something @command{cp} itself has controlover.In Unix System V any user can chown files to any other user, and SystemV also has a non-sticky @file{/tmp}.  That probably derives from theheritage of System V in a business environment without hostile users.BSD changed thisto be a more secure model where only root can @command{chown} files anda sticky @file{/tmp} is used.  That undoubtedly derives from the heritageof BSD in a campus environment.GNU/Linux and Solaris by default follow BSD, butcan be configured to allow a System V style @command{chown}.  On theother hand, HP-UX follows System V, but canbe configured to use the modern security model and disallow@command{chown}.  Since it is an administrator-configurable parameteryou can't use the name of the kernel as an indicator of the behavior.@item @command{date}@c -----------------@prindex @command{date}Some versions of @command{date} do not recognize special @samp{%} directives,and unfortunately, instead of complaining, they just pass them through,and exit with success:@example$ @kbd{uname -a}OSF1 medusa.sis.pasteur.fr V5.1 732 alpha$ @kbd{date "+%s"}%s@end example@item @command{diff}@c -----------------@prindex @command{diff}Option @option{-u} is nonportable.Some implementations, such as Tru64's, fail when comparing to@file{/dev/null}.  Use an empty file instead.@item @command{dirname}@c --------------------@prindex @command{dirname}Not all hosts have a working @command{dirname}, and you should insteaduse @code{AS_DIRNAME} (@pxref{Programming in M4sh}).  For example:@exampledir=`dirname "$file"`       # This is not portable.dir=`AS_DIRNAME(["$file"])` # This is more portable.@end example@item @command{egrep}@c ------------------@prindex @command{egrep}Posix 1003.1-2001 no longer requires @command{egrep},but many hosts do not yet support the Posixreplacement @code{grep -E}.  Also, some traditional implementations donot work on long input lines.  To work around these problems, invoke@code{AC_PROG_EGREP} and then use @code{$EGREP}.Portable extended regular expressions should use @samp{\} only to escapecharacters in the string @samp{$()*+.?[\^@{|}.  For example, @samp{\@}}is not portable, even though it typically matches @samp{@}}.The empty alternative is not portable.  Use @samp{?} instead.  Forinstance with Digital Unix v5.0:@example> printf "foo\n|foo\n" | $EGREP '^(|foo|bar)$'|foo> printf "bar\nbar|\n" | $EGREP '^(foo|bar|)$'bar|> printf "foo\nfoo|\n|bar\nbar\n" | $EGREP '^(foo||bar)$'foo|bar@end example@command{$EGREP} also suffers the limitations of @command{grep}(@pxref{grep, , Limitations of Usual Tools}).@item @command{expr}@c -----------------@prindex @command{expr}Not all implementations obey the Posix rule that @samp{--} separatesoptions from arguments; likewise, not all implementations provide theextension to Posix that the first argument can be treated as part of avalid expression rather than an invalid option if it begins with@samp{-}.  When performing arithmetic, use @samp{expr 0 + $var} if@samp{$var} might be a negative number, to keep @command{expr} frominterpreting it as an option.No @command{expr} keyword starts with @samp{X}, so use @samp{exprX"@var{word}" : 'X@var{regex}'} to keep @command{expr} frommisinterpreting @var{word}.Don't use @code{length}, @code{substr}, @code{match} and @code{index}.@item @command{expr} (@samp{|})@prindex @command{expr} (@samp{|})You can use @samp{|}.  Although Posix does require that @samp{expr''} return the empty string, it does not specify the result when you@samp{|} together the empty string (or zero) with the empty string.  Forexample:@exampleexpr '' \| ''@end examplePosix 1003.2-1992 returns the empty stringfor this case, but traditional Unix returns @samp{0} (Solaris isone such example).  In Posix 1003.1-2001, the specification waschanged to match traditional Unix's behavior (which isbizarre, but it's too late to fix this).  Please note that the sameproblem does arise when the empty string results from a computation,as in:@exampleexpr bar : foo \| foo : bar@end example@noindentAvoid this portability problem by avoiding the empty string.@item @command{expr} (@samp{:})@c ----------------------------@prindex @command{expr}Portable @command{expr} regular expressions should use @samp{\} toescape only characters in the string @samp{$()*.0123456789[\^n@{@}}.For example, alternation, @samp{\|}, is common but Posix does notrequire its support, so it should be avoided in portable scripts.Similarly, @samp{\+} and @samp{\?} should be avoided.Portable @command{expr} regular expressions should not begin with@samp{^}.  Patterns are automatically anchored so leading @samp{^} isnot needed anyway.On the other hand, the behavior of the @samp{$} anchor is not portableon multi-line strings.  Posix is ambiguous whether the anchor applies toeach line, as was done in older versions of the GNU Core Utilities, orwhether it applies only to the end of the overall string, as inCoreutils 6.0 and most other implementations.@example$ @kbd{baz='foo}> @kbd{bar'}$ @kbd{expr "X$baz" : 'X\(foo\)$'}$ @kbd{expr-5.97 "X$baz" : 'X\(foo\)$'}foo@end exampleThe Posix standard is ambiguous as to whether@samp{expr 'a' : '\(b\)'} outputs @samp{0} or the empty string.In practice, it outputs the empty string on most platforms, but portablescripts should not assume this.  For instance, the QNX 4.25 native@command{expr} returns @samp{0}.One might think that a way to get a uniform behavior would be to usethe empty string as a default value:@exampleexpr a : '\(b\)' \| ''@end example@noindentUnfortunately this behaves exactly as the original expression; see the@command{expr} (@samp{|}) entry for more information.Some ancient @command{expr} implementations (e.g., SunOS 4 @command{expr} andSolaris 8 @command{/usr/ucb/expr}) have a silly length limit that causes@command{expr} to fail if the matched substring is longer than 120bytes.  In this case, you might want to fall back on @samp{echo|sed} if@command{expr} fails.  Nowadays this is of practical importance only forthe rare installer who mistakenly puts @file{/usr/ucb} before@file{/usr/bin} in @env{PATH}.On Mac OS X 10.4, @command{expr} mishandles the pattern @samp{[^-]} insome cases.  For example, the command@exampleexpr Xpowerpc-apple-darwin8.1.0 : 'X[^-]*-[^-]*-\(.*\)'@end example@noindentoutputs @samp{apple-darwin8.1.0} rather than the correct @samp{darwin8.1.0}.This particular case can be worked around by substituting @samp{[^--]}for @samp{[^-]}.Don't leave, there is some more!The QNX 4.25 @command{expr}, in addition of preferring @samp{0} tothe empty string, has a funny behavior in its exit status: it's always 1when parentheses are used!@example$ @kbd{val=`expr 'a' : 'a'`; echo "$?: $val"}0: 1$ @kbd{val=`expr 'a' : 'b'`; echo "$?: $val"}1: 0$ @kbd{val=`expr 'a' : '\(a\)'`; echo "?: $val"}1: a$ @kbd{val=`expr 'a' : '\(b\)'`; echo "?: $val"}1: 0@end example@noindentIn practice this can be a big problem if you are ready to catch failuresof @command{expr} programs with some other method (such as using@command{sed}), since you may get twice the result.  For instance@example$ @kbd{expr 'a' : '\(a\)' || echo 'a' | sed 's/^\(a\)$/\1/'}@end example@noindentoutputs @samp{a} on most hosts, but @samp{aa} on QNX 4.25.  Asimple workaround consists of testing @command{expr} and using a variableset to @command{expr} or to @command{false} according to the result.Tru64 @command{expr} incorrectly treats the result as a number, if itcan be interpreted that way:@example$ @kbd{expr 00001 : '.*\(...\)'}1@end exampleOn HP-UX 11, @command{expr} only supports a singlesub-expression.@example$ @kbd{expr 'Xfoo' : 'X\(f\(oo\)*\)$'}expr: More than one '\(' was used.@end example@item @command{fgrep}@c ------------------@prindex @command{fgrep}Posix 1003.1-2001 no longer requires @command{fgrep},but many hosts do not yet support the Posixreplacement @code{grep -F}.  Also, some traditional implementations donot work on long input lines.  To work around these problems, invoke@code{AC_PROG_FGREP} and then use @code{$FGREP}.Tru64/OSF 5.1 @command{fgrep} does not match an empty pattern.@item @command{find}@c -----------------@prindex @command{find}The option @option{-maxdepth} seems to be GNU specific.Tru64 v5.1, NetBSD 1.5 and Solaris @command{find}commands do not understand it.The replacement of @samp{@{@}} is guaranteed only if the argument isexactly @emph{@{@}}, not if it's only a part of an argument.  Forinstance on DU, and HP-UX 10.20 and HP-UX 11:@example$ @kbd{touch foo}$ @kbd{find . -name foo -exec echo "@{@}-@{@}" \;}@{@}-@{@}@end example@noindentwhile GNU @command{find} reports @samp{./foo-./foo}.@anchor{grep}@item @command{grep}@c -----------------@prindex @command{grep}Portable scripts can rely on the @command{grep} options @option{-c},@option{-l}, @option{-n}, and @option{-v}, but should avoid otheroptions.  For example, don't use @option{-w}, as Posix does not requireit and Irix 6.5.16m's @command{grep} does not support it.  Also,portable scripts should not combine @option{-c} with @option{-l},as Posix does not allow this.Some of the options required by Posix are not portable in practice.Don't use @samp{grep -q} to suppress output, because many @command{grep}implementations (e.g., Solaris) do not support @option{-q}.Don't use @samp{grep -s} to suppress output either, because Posixsays @option{-s} does not suppress output, only some error messages;also, the @option{-s} option of traditional @command{grep} behavedlike @option{-q} does in most modern implementations.  Instead,redirect the standard output and standard error (in case the filedoesn't exist) of @code{grep} to @file{/dev/null}.  Check the exitstatus of @code{grep} to determine whether it found a match.The QNX4 implementation fails to count lines with @code{grep -c '$'},but works with @code{grep -c '^'}.  Other alternatives for countinglines are to use @code{sed -n '$='} or @code{wc -l}.Some traditional @command{grep} implementations do not work on longinput lines.  On AIX the default @code{grep} silently truncates longlines on the input before matching.Also, many implementations do not support multiple regexpswith @option{-e}: they either reject @option{-e} entirely (e.g., Solaris)or honor only the last pattern (e.g., IRIX 6.5 and NeXT).  Towork around these problems, invoke @code{AC_PROG_GREP} and then use@code{$GREP}.Another possible workaround for the multiple @option{-e} problem is toseparate the patterns by newlines, for example:@examplegrep 'foobar' in.txt@end example@noindentexcept that this fails with traditional @command{grep}implementations and with OpenBSD 3.8 @command{grep}.Traditional @command{grep} implementations (e.g., Solaris) do notsupport the @option{-E} or @option{-F} options.  To work around theseproblems, invoke @code{AC_PROG_EGREP} and then use @code{$EGREP}, andsimilarly for @code{AC_PROG_FGREP} and @code{$FGREP}.  Even if you arewilling to require support for Posix @command{grep}, your script shouldnot use both @option{-E} and @option{-F}, since Posix does not allowthis combination.Portable @command{grep} regular expressions should use @samp{\} only toescape characters in the string @samp{$()*.0123456789[\^@{@}}.  For example,alternation, @samp{\|}, is common but Posix does not require itssupport in basic regular expressions, so it should be avoided inportable scripts.  Solaris and HP-UX @command{grep} do not support it.Similarly, the following escape sequences should also be avoided:@samp{\<}, @samp{\>}, @samp{\+}, @samp{\?}, @samp{\`}, @samp{\'},@samp{\B}, @samp{\b}, @samp{\S}, @samp{\s}, @samp{\W}, and @samp{\w}.Posix does not specify the behavior of @command{grep} on binary files.An example where this matters is using BSD @command{grep} tosearch text that includes embedded ANSI escape sequences forcolored output to terminals (@samp{\033[m} is the sequence to restorenormal output); the behavior depends on whether input is seekable:@example$ @kbd{printf 'esc\033[mape\n' > sample}$ @kbd{grep . sample}Binary file sample matches$ @kbd{cat sample | grep .}escape@end example@item @command{join}@c -----------------@prindex @command{join}Solaris 8 @command{join} has bugs when the second operand is standardinput, and when standard input is a pipe.  For example, the followingshell script causes Solaris 8 @command{join} to loop forever:@examplecat >file <<'EOF'1 x2 yEOFcat file | join file -@end exampleUse @samp{join - file} instead.On NetBSD, @command{join -a 1 file1 file2} mistakenly behaves like@command{join -a 1 -a 2 1 file1 file2}, resulting in a usage warning;the workaround is to use @command{join -a1 file1 file2} instead.@item @command{ln}@c ---------------@prindex @command{ln}@cindex Symbolic linksDon't rely on @command{ln} having a @option{-f} option.  Symbolic linksare not available on old systems; use @samp{$(LN_S)} as a portable substitute.For versions of the DJGPP before 2.04,@command{ln} emulates symbolic linksto executables by generating a stub that in turn calls the realprogram.  This feature also works with nonexistent files like in thePosix spec.  So @samp{ln -s file link} generates @file{link.exe},which attempts to call @file{file.exe} if run.  But this feature onlyworks for executables, so @samp{cp -p} is used instead for thesesystems.  DJGPP versions 2.04 and later have full supportfor symbolic links.@item @command{ls}@c ---------------@prindex @command{ls}@cindex Listing directoriesThe portable options are @option{-acdilrtu}.  Current practice is for@option{-l} to output both owner and group, even though ancient versionsof @command{ls} omitted the group.On ancient hosts, @samp{ls foo} sent the diagnostic @samp{foo not found}to standard output if @file{foo} did not exist.  Hence a shell commandlike @samp{sources=`ls *.c 2>/dev/null`} did not always work, since itwas equivalent to @samp{sources='*.c not found'} in the absence of@samp{.c} files.  This is no longer a practical problem, since current@command{ls} implementations send diagnostics to standard error.The behavior of @command{ls} on a directory that is being concurrentlymodified is not always predictable, because of a data race where cachedinformation returned by @code{readdir} does not match the currentdirectory state.  In fact, MacOS 10.5 has an intermittent bug where@code{readdir}, and thus @command{ls}, sometimes lists a file more thanonce if other files were added or removed from the directory immediatelyprior to the @command{ls} call.  Since @command{ls} already sorts itsoutput, the duplicate entries can be avoided by piping the resultsthrough @code{uniq}.@anchor{mkdir}@item @command{mkdir}@c ------------------@prindex @command{mkdir}@cindex Making directoriesNo @command{mkdir} option is portable to older systems.  Instead of@samp{mkdir -p @var{file-name}}, you should use@code{AS_MKDIR_P(@var{file-name})} (@pxref{Programming in M4sh})or @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs}).Combining the @option{-m} and @option{-p} options, as in @samp{mkdir -mgo-w -p @var{dir}}, often leads to trouble.  FreeBSD@command{mkdir} incorrectly attempts to change the permissions of@var{dir} even if it already exists.  HP-UX 11.23 andIRIX 6.5 @command{mkdir} often assign the wrong permissions toany newly-created parents of @var{dir}.Posix does not clearly specify whether @samp{mkdir -p foo}should succeed when @file{foo} is a symbolic link to an already-existingdirectory.  The GNU Core Utilities 5.1.0 @command{mkdir}succeeds, but Solaris @command{mkdir} fails.Traditional @code{mkdir -p} implementations suffer from race conditions.For example, if you invoke @code{mkdir -p a/b} and @code{mkdir -p a/c}at the same time, both processes might detect that @file{a} is missing,one might create @file{a}, then the other might try to create @file{a}and fail with a @code{File exists} diagnostic.  The GNU CoreUtilities (@samp{fileutils} version 4.1), FreeBSD 5.0,NetBSD 2.0.2, and OpenBSD 2.4 are known to berace-free when two processes invoke @code{mkdir -p} simultaneously, butearlier versions are vulnerable.  Solaris @command{mkdir} is stillvulnerable as of Solaris 10, and other traditional Unix systems areprobably vulnerable too.  This possible race is harmful in parallelbuilds when several Make rules call @code{mkdir -p} toconstruct directories.  You may use@code{install-sh -d} as a safe replacement, provided this script isrecent enough; the copy shipped with Autoconf 2.60 and Automake 1.10 isOK, but copies from older versions are vulnerable.@item @command{mkfifo}@itemx @command{mknod}@c -------------------@prindex @command{mkfifo}@prindex @command{mknod}The GNU Coding Standards state that @command{mknod} is safe to use onplatforms where it has been tested to exist; but it is generally portableonly for creating named FIFOs, since device numbers areplatform-specific.  Autotest uses @command{mkfifo} to implement paralleltestsuites.  Posix states that behavior is unspecified when opening anamed FIFO for both reading and writing; on at least Cygwin, thisresults in failure on any attempt to read or write to that filedescriptor.@item @command{mktemp}@c -------------------@prindex @command{mktemp}@cindex Creating temporary filesShell scripts can use temporary files safely with @command{mktemp}, butit does not exist on all systems.  A portable way to create a safetemporary file name is to create a temporary directory with mode 700 anduse a file inside this directory.  Both methods prevent attackers fromgaining control, though @command{mktemp} is far less likely to failgratuitously under attack.Here is sample code to create a new temporary directory @samp{$dir} safely:@example# Create a temporary directory $dir in $TMPDIR (default /tmp).# Use mktemp if possible; otherwise fall back on mkdir,# with $RANDOM to make collisions less likely.: "$@{TMPDIR:=/tmp@}"@{  dir=`    (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null  ` &&  test -d "$dir"@} || @{  dir=$TMPDIR/foo$$-$RANDOM@c $$ restore font-lock  (umask 077 && mkdir "$dir")@} || exit $?@end example@item @command{mv}@c ---------------@prindex @command{mv}@cindex Moving open filesThe only portable options are @option{-f} and @option{-i}.Moving individual files between file systems is portable (it was in Unixversion 6),but it is not always atomic: when doing @samp{mv new existing}, there'sa critical section where neither the old nor the new version of@file{existing} actually exists.On some systems moving files from @file{/tmp} can sometimes causeundesirable (but perfectly valid) warnings, even if you created thesefiles.  This is because @file{/tmp} belongs to a group that ordinaryusers are not members of, and files created in @file{/tmp} inheritthe group of @file{/tmp}.  When the file is copied, @command{mv} issuesa diagnostic without failing:@smallexample$ @kbd{touch /tmp/foo}$ @kbd{mv /tmp/foo .}@error{}mv: ./foo: set owner/group (was: 100/0): Operation not permitted$ @kbd{echo $?}0$ @kbd{ls foo}foo@end smallexample@noindentThis annoying behavior conforms to Posix, unfortunately.Moving directories across mount points is not portable, use @command{cp}and @command{rm}.DOS variants cannot rename or remove open files, and do notsupport commands like @samp{mv foo bar >foo}, even though this isperfectly portable among Posix hosts.@item @command{od}@c ---------------@prindex @command{od}In Mac OS X 10.3, @command{od} does not support thestandard Posix options @option{-A}, @option{-j}, @option{-N}, or@option{-t}, or the XSI option @option{-s}.  The onlysupported Posix option is @option{-v}, and the only supportedXSI options are those in @option{-bcdox}.  The BSD@command{hexdump} program can be used instead.This problem no longer exists in Mac OS X 10.4.3.@item @command{rm}@c ---------------@prindex @command{rm}The @option{-f} and @option{-r} options are portable.It is not portable to invoke @command{rm} without options or operands.On the other hand, Posix now requires @command{rm -f} to silentlysucceed when there are no operands (useful for constructs like@command{rm -rf $filelist} without first checking if @samp{$filelist}was empty).  But this was not always portable; at least NetBSD@command{rm} built before 2008 would fail with a diagnostic.A file might not be removed even if its parent directory is writableand searchable.  Many Posix hosts cannot remove a mount point, a namedstream, a working directory, or a last link to a file that is beingexecuted.DOS variants cannot rename or remove open files, and do notsupport commands like @samp{rm foo >foo}, even though this isperfectly portable among Posix hosts.@item @command{rmdir}@c ------------------@prindex @command{rmdir}Just as with @command{rm}, some platforms refuse to remove a workingdirectory.@anchor{sed}@item @command{sed}@c ----------------@prindex @command{sed}Patterns should not include the separator (unless escaped), even as partof a character class.  In conformance with Posix, the Cray@command{sed} rejects @samp{s/[^/]*$//}: use @samp{s%[^/]*$%%}.Even when escaped, patterns should not include separators that are alsoused as @command{sed} metacharacters.  For example, GNU sed 4.0.9 rejects@samp{s,x\@{1\,\@},,}, while sed 4.1 strips the backslash before the commabefore evaluating the basic regular expression.Avoid empty patterns within parentheses (i.e., @samp{\(\)}).  Posix doesnot require support for empty patterns, and Unicos 9 @command{sed} rejectsthem.Unicos 9 @command{sed} loops endlessly on patterns like @samp{.*\n.*}.Sed scripts should not use branch labels longer than 7 characters andshould not contain comments; AIX 5.3 @command{sed} rejects indented comments.HP-UX sed has a limit of 99 commands (not counting @samp{:} commands) and48 labels, which cannot be circumvented by using more than one scriptfile.  It can execute up to 19 reads with the @samp{r} command per cycle.Solaris @command{/usr/ucb/sed} rejects usages that exceed a limit ofabout 6000 bytes for the internal representation of commands.Avoid redundant @samp{;}, as some @command{sed} implementations, such asNetBSD 1.4.2's, incorrectly try to interpret the second@samp{;} as a command:@example$ @kbd{echo a | sed 's/x/x/;;s/x/x/'}sed: 1: "s/x/x/;;s/x/x/": invalid command code ;@end exampleSome @command{sed} implementations have a buffer limited to 4000 bytes,and this limits the size of input lines, output lines, and internalbuffers that can be processed portably.  Likewise,not all @command{sed} implementations can handle embedded @code{NUL} ora missing trailing newline.Remember that ranges within a bracket expression of a regular expressionare only well-defined in the @samp{C} (or @samp{POSIX}) locale.Meanwhile, support for character classes like @samp{[[:upper:]]} is notyet universal, so if you cannot guarantee the setting of @env{LC_ALL},it is better to spell out a range @samp{[ABCDEFGHIJKLMNOPQRSTUVWXYZ]}than to rely on @samp{[A-Z]}.Additionally, Posix states that regular expressions are onlywell-defined on characters.  Unfortunately, there exist platforms suchas MacOS X 10.5 where not all 8-bit byte values are valid characters,even though that platform has a single-byte @samp{C} locale.  And Posixallows the existence of a multi-byte @samp{C} locale, although that doesnot yet appear to be a common implementation.  At any rate, it meansthat not all bytes will be matched by the regular expression @samp{.}:@example$ @kbd{printf '\200\n' | LC_ALL=C sed -n /./p | wc -l}0$ @kbd{printf '\200\n' | LC_ALL=en_US.ISO8859-1 sed -n /./p | wc -l}1@end examplePortable @command{sed} regular expressions should use @samp{\} only to escapecharacters in the string @samp{$()*.0123456789[\^n@{@}}.  For example,alternation, @samp{\|}, is common but Posix does not require itssupport, so it should be avoided in portable scripts.  Solaris@command{sed} does not support alternation; e.g., @samp{sed '/a\|b/d'}deletes only lines that contain the literal string @samp{a|b}.Similarly, @samp{\+} and @samp{\?} should be avoided.Anchors (@samp{^} and @samp{$}) inside groups are not portable.Nested parentheses in patterns (e.g., @samp{\(\(a*\)b*)\)}) arequite portable to current hosts, but was not supported by some ancient@command{sed} implementations like SVR3.Some @command{sed} implementations, e.g., Solaris, restrict the specialrole of the asterisk @samp{*} to one-character regular expressions andback-references, and the special role of interval expressions@samp{\@{@var{m}\@}}, @samp{\@{@var{m},\@}}, or @samp{\@{@var{m},@var{n}\@}}to one-character regular expressions.  This may lead to unexpected behavior:@example$ @kbd{echo '1*23*4' | /usr/bin/sed 's/\(.\)*/x/g'}x2x4$ @kbd{echo '1*23*4' | /usr/xpg4/bin/sed 's/\(.\)*/x/g'}x@end exampleThe @option{-e} option is mostly portable.However, its argumentcannot start with @samp{a}, @samp{c}, or @samp{i},as this runs afoul of a Tru64 5.1 bug.Also, its argument cannot be empty, as this fails on AIX 5.3.Some people prefer to use @samp{-e}:@examplesed -e '@var{command-1}' \    -e '@var{command-2}'@end example@noindentas opposed to the equivalent:@examplesed '  @var{command-1}  @var{command-2}'@end example@noindentThe following usage is sometimes equivalent:@examplesed '@var{command-1};@var{command-2}'@end examplebut Posix says that this use of a semicolon has undefined effect if@var{command-1}'s verb is @samp{@{}, @samp{a}, @samp{b}, @samp{c},@samp{i}, @samp{r}, @samp{t}, @samp{w}, @samp{:}, or @samp{#}, so youshould use semicolon only with simple scripts that do not use theseverbs.Posix up to the 2008 revision requires the argument of the @option{-e}option to be a syntactically complete script.  GNU @command{sed} allowsto pass multiple script fragments, each as argument of a separate@option{-e} option, that are then combined, with newlines between thefragments, and a future Posix revision may allow this as well.  Thisapproach is not portable with script fragments ending in backslash; forexample, the @command{sed} programs on Solaris 10, HP-UX 11, and AIXdon't allow splitting in this case:@example$ @kbd{echo a | sed -n -e 'i\}@kbd{0'}0$ @kbd{echo a | sed -n -e 'i\' -e 0}Unrecognized command: 0@end example@noindentIn practice, however, this technique of joining fragmentsthrough @option{-e} works for multiple @command{sed} functions within@samp{@{} and @samp{@}}, even if that is not specified by Posix:@example@c The quote around the closing brace silences interactive zsh.$ @kbd{echo a | sed -n -e '/a/@{' -e s/a/b/ -e p -e '@}'}b@end exampleCommands inside @{ @} brackets are further restricted.  Posix 2008 says thatthey cannot be preceded by addresses, @samp{!}, or @samp{;}, and thateach command must be followed immediately by a newline, without anyintervening blanks or semicolons.  The closing bracket must be alone ona line, other than white space preceding or following it.  However, afuture version of Posix may standardize the use of addresses within brackets.Contrary to yet another urban legend, you may portably use @samp{&} inthe replacement part of the @code{s} command to mean ``what wasmatched''.  All descendants of Unix version 7 @command{sed}(at least; wedon't have first hand experience with older @command{sed} implementations) havesupported it.Posix requires that you must not have any white space between@samp{!} and the following command.  It is OK to have blanks betweenthe address and the @samp{!}.  For instance, on Solaris:@example$ @kbd{echo "foo" | sed -n '/bar/ ! p'}@error{}Unrecognized command: /bar/ ! p$ @kbd{echo "foo" | sed -n '/bar/! p'}@error{}Unrecognized command: /bar/! p$ @kbd{echo "foo" | sed -n '/bar/ !p'}foo@end examplePosix also says that you should not combine @samp{!} and @samp{;}.  Ifyou use @samp{!}, it is best to put it on a command that is delimited bynewlines rather than @samp{;}.Also note that Posix requires that the @samp{b}, @samp{t}, @samp{r}, and@samp{w} commands be followed by exactly one space before their argument.On the other hand, no white space is allowed between @samp{:} and thesubsequent label name.If a sed script is specified on the command line and ends in an@samp{a}, @samp{c}, or @samp{i} command, the last line of inserted textshould be followed by a newline.  Otherwise some @command{sed}implementations (e.g., OpenBSD 3.9) do not append a newline to theinserted text.Many @command{sed} implementations (e.g., MacOS X 10.4,OpenBSD 3.9, Solaris 10@command{/usr/ucb/sed}) strip leading white space from the text of@samp{a}, @samp{c}, and @samp{i} commands.  Prepend a backslash towork around this incompatibility with Posix:@example$ @kbd{echo flushleft | sed 'a\}> @kbd{   indented}> @kbd{'}flushleftindented$ @kbd{echo foo | sed 'a\}> @kbd{\   indented}> @kbd{'}flushleft   indented@end examplePosix requires that with an empty regular expression, the last non-emptyregular expression from either an address specification or substitutioncommand is applied.  However, busybox 1.6.1 complains when using asubstitution command with a replacement containing a back-reference toan empty regular expression; the workaround is repeating the regularexpression.@example$ @kbd{echo abc | busybox sed '/a\(b\)c/ s//\1/'}sed: No previous regexp.$ @kbd{echo abc | busybox sed '/a\(b\)c/ s/a\(b\)c/\1/'}b@end example@item @command{sed} (@samp{t})@c ---------------------------@prindex @command{sed} (@samp{t})Some old systems have @command{sed} that ``forget'' to reset their@samp{t} flag when starting a new cycle.  For instance on MIPSRISC/OS, and on IRIX 5.3, if you run the following @command{sed}script (the line numbers are not actual part of the texts):@examples/keep me/kept/g  # at end             # bs/.*/deleted/g    # c:end              # d@end example@noindenton@exampledelete me         # 1delete me         # 2keep me           # 3delete me         # 4@end example@noindentyou get@exampledeleteddelete mekeptdeleted@end example@noindentinstead of@exampledeleteddeletedkeptdeleted@end exampleWhy?  When processing line 1, (c) matches, therefore sets the @samp{t}flag, and the output is produced.  When processingline 2, the @samp{t} flag is still set (this is the bug).  Command (a)fails to match, but @command{sed} is not supposed to clear the @samp{t}flag when a substitution fails.  Command (b) sees that the flag is set,therefore it clears it, and jumps to (d), hence you get @samp{delete me}instead of @samp{deleted}.  When processing line (3), @samp{t} is clear,(a) matches, so the flag is set, hence (b) clears the flags and jumps.Finally, since the flag is clear, line 4 is processed properly.There are two things one should remember about @samp{t} in @command{sed}.Firstly, always remember that @samp{t} jumps if @emph{some} substitutionsucceeded, not only the immediately preceding substitution.  Therefore,always use a fake @samp{t clear} followed by a @samp{:clear} on the nextline, to reset the @samp{t} flag where needed.Secondly, you cannot rely on @command{sed} to clear the flag at each newcycle.One portable implementation of the script above is:@examplet clear:clears/keep me/kept/gt ends/.*/deleted/g:end@end example@item @command{sleep}@c ------------------@prindex @command{sleep}Using @command{sleep} is generally portable.  However, remember thatadding a @command{sleep} to work around timestamp issues, with a minimumgranularity of one second, doesn't scale well for parallel builds onmodern machines with sub-second process completion.@item @command{sort}@c -----------------@prindex @command{sort}Remember that sort order is influenced by the current locale.  Inside@file{configure}, the C locale is in effect, but in Makefile snippets,you may need to specify @code{LC_ALL=C sort}.@item @command{tar}@c ----------------@prindex @command{tar}There are multiple file formats for @command{tar}; if you use Automake,the macro @code{AM_INIT_AUTOMAKE} has some options controlling whichlevel of portability to use.@anchor{touch}@item @command{touch}@c ------------------@prindex @command{touch}@cindex timestamp resolutionIf you specify the desired timestamp (e.g., with the @option{-r}option), older @command{touch} implementations use the @code{utime} or@code{utimes} system call, which can result in the same kind oftimestamp truncation problems that @samp{cp -p} has.On ancient BSD systems, @command{touch} or any command thatresults in an empty file does not update the timestamps, so use acommand like @command{echo} as a workaround.Also,GNU @command{touch} 3.16r (and presumably all before that)fails to work on SunOS 4.1.3 when the empty file is on anNFS-mounted 4.2 volume.However, these problems are no longer of practical concern.@item @command{tr}@c ---------------@prindex @command{tr}@cindex carriage return, deleting@cindex newline, deleting@cindex deleting carriage returnNot all versions of @command{tr} handle all backslash character escapes.For example, Solaris 10 @command{/usr/ucb/tr} falls over, even thoughSolaris contains more modern @command{tr} in other locations.Using octal escapes is more portable for carriage returns, since@samp{\015} is the same for both ASCII and EBCDIC, and since use ofliteral carriage returns in scripts causes a number of other problems.But for other characters, like newline, using octal escapes ties theoperation to ASCII, so it is better to use literal characters.@example$ @kbd{@{ echo moon; echo light; @} | /usr/ucb/tr -d '\n' ; echo}moolight$ @kbd{@{ echo moon; echo light; @} | /usr/bin/tr -d '\n' ; echo}moonlight$ @kbd{@{ echo moon; echo light; @} | /usr/ucb/tr -d '\012' ; echo}moonlight$ @kbd{nl='}@kbd{'; @{ echo moon; echo light; @} | /usr/ucb/tr -d "$nl" ; echo}moonlight@end exampleNot all versions of @command{tr} recognize direct ranges of characters: atleast Solaris @command{/usr/bin/tr} still fails to do so.  But you canuse @command{/usr/xpg4/bin/tr} instead, or add brackets (which in Posixtransliterate to themselves).@example$ @kbd{echo "Hazy Fantazy" | LC_ALL=C /usr/bin/tr a-z A-Z}HAZy FAntAZy$ @kbd{echo "Hazy Fantazy" | LC_ALL=C /usr/bin/tr '[a-z]' '[A-Z]'}HAZY FANTAZY$ @kbd{echo "Hazy Fantazy" | LC_ALL=C /usr/xpg4/bin/tr a-z A-Z}HAZY FANTAZY@end exampleWhen providing two arguments, be sure the second string is at least aslong as the first.@example$ @kbd{echo abc | /usr/xpg4/bin/tr bc d}adc$ @kbd{echo abc | coreutils/tr bc d}add@end examplePosix requires @command{tr} to operate on binary files.  But at leastSolaris @command{/usr/ucb/tr} and @command{/usr/bin/tr} silently discard@code{NUL} in the input prior to doing any translation.  When using@command{tr} to process a binary file that may contain @code{NUL} bytes,it is necessary to use @command{/usr/xpg4/bin/tr} instead, or@command{/usr/xpg6/bin/tr} if that is available.@example$ @kbd{printf 'a\0b' | /usr/ucb/tr x x | od -An -tx1} 61 62$ @kbd{printf 'a\0b' | /usr/bin/tr x x | od -An -tx1} 61 62$ @kbd{printf 'a\0b' | /usr/xpg4/bin/tr x x | od -An -tx1} 61 00 62@end exampleSolaris @command{/usr/ucb/tr} additionally fails to handle @samp{\0} as theoctal escape for @code{NUL}.@example$ @kbd{printf 'abc' | /usr/ucb/tr 'bc' '\0d' | od -An -tx1} 61 62 63$ @kbd{printf 'abc' | /usr/bin/tr 'bc' '\0d' | od -An -tx1} 61 00 64$ @kbd{printf 'abc' | /usr/xpg4/bin/tr 'bc' '\0d' | od -An -tx1} 61 00 64@end example@end table@node Portable Make@chapter Portable Make Programming@prindex @command{make}@cindex Limitations of @command{make}Writing portable makefiles is an art.  Since a makefile's commands areexecuted by the shell, you must consider the shell portability issuesalready mentioned.  However, other issues are specific to @command{make}itself.@menu* $< in Ordinary Make Rules::   $< in ordinary rules* Failure in Make Rules::       Failing portably in rules* Special Chars in Names::      Special Characters in Macro Names* Backslash-Newline-Empty::     Empty lines after backslash-newline* Backslash-Newline Comments::  Spanning comments across line boundaries* Long Lines in Makefiles::     Line length limitations* Macros and Submakes::         @code{make macro=value} and submakes* The Make Macro MAKEFLAGS::    @code{$(MAKEFLAGS)} portability issues* The Make Macro SHELL::        @code{$(SHELL)} portability issues* Parallel Make::               Parallel @command{make} quirks* Comments in Make Rules::      Other problems with Make comments* Newlines in Make Rules::      Using literal newlines in rules* Comments in Make Macros::     Other problems with Make comments in macros* Trailing whitespace in Make Macros::  Macro substitution problems* Command-line Macros and whitespace::  Whitespace trimming of values* obj/ and Make::               Don't name a subdirectory @file{obj}* make -k Status::              Exit status of @samp{make -k}* VPATH and Make::              @code{VPATH} woes* Single Suffix Rules::         Single suffix rules and separated dependencies* Timestamps and Make::         Subsecond timestamp resolution@end menu@node $< in Ordinary Make Rules@section @code{$<} in Ordinary Make RulesPosix says that the @samp{$<} construct in makefiles can beused only in inference rules and in the @samp{.DEFAULT} rule; itsmeaning in ordinary rules is unspecified.  Solaris @command{make}for instance replaces it with the empty string.  OpenBSD (3.0 andlater) @command{make} diagnoses these uses and errors out.@node Failure in Make Rules@section Failure in Make RulesPosix 2008 requires that @command{make} must invoke each command withthe equivalent of a @samp{sh -e -c} subshell, which causes thesubshell to exit immediately if a subsidiary simple-command fails,although not all @command{make} implementations have historicallyfollowed this rule.  Forexample, the command @samp{touch T; rm -f U} may attempt toremove @file{U} even if the @command{touch} fails, although this is notpermitted with Posix make.  One way to work around failures in simplecommands is to reword them so that they always succeed, e.g., @samp{touchT || :; rm -f U}.However, even this approach can run into common bugs in BSDimplementations of the @option{-e} option of @command{sh} and@command{set} (@pxref{set, , Limitations of Shell Builtins}), so if youare worriedabout porting to buggy BSD shells it may be simpler to migratecomplicated @command{make} actions into separate scripts.@node Special Chars in Names@section Special Characters in Make Macro NamesPosix limits macro names to nonempty strings containing onlyASCII letters and digits, @samp{.}, and @samp{_}.  Many@command{make} implementations allow a wider variety of characters, butportable makefiles should avoid them.  It is portable to start a namewith a special character, e.g., @samp{$(.FOO)}.Some ancient @command{make} implementations don't support leadingunderscores in macro names.  An example is NEWS-OS 4.2R.@example$ @kbd{cat Makefile}_am_include = #_am_quote =all:; @@echo this is test$ @kbd{make}Make: Must be a separator on rules line 2.  Stop.$ @kbd{cat Makefile2}am_include = #am_quote =all:; @@echo this is test$ @kbd{make -f Makefile2}this is test@end example@noindentHowever, this problem is no longer of practical concern.@node Backslash-Newline-Empty@section Backslash-Newline Before Empty LinesA bug in Bash 2.03 can cause problems if a Make rule contains abackslash-newline followed by line that expands to nothing.For example, on Solaris 8:@exampleSHELL = /bin/bashEMPTY =foo:	touch foo \	$(EMPTY)@end example@noindentexecutes@example/bin/bash -c 'touch foo \'@end example@noindentwhich fails with a syntax error, due to the Bash bug.  To avoid thisproblem, avoid nullable macros in the last line of a multiline command.@c  This has been seen on ia64 hpux 11.20, and on one hppa hpux 10.20,@c  but another hppa hpux 10.20 didn't have it.  Bob Proulx@c  <bob@proulx.com> thinks it was in hpux 8.0 too.On some versions of HP-UX, @command{make} reads multiple newlinesfollowing a backslash, continuing to the next non-empty line.  Forexample,@exampleFOO = one \BAR = twotest:        : FOO is "$(FOO)"        : BAR is "$(BAR)"@end example@noindentshows @code{FOO} equal to @code{one BAR = two}.  Other implementationssensibly let a backslash continue only to the immediately followingline.@node Backslash-Newline Comments@section Backslash-Newline in Make CommentsAccording to Posix, Make comments start with @code{#}and continue until an unescaped newline is reached.@example$ @kbd{cat Makefile}# A = foo \      bar \      bazall:        @@echo ok$ @kbd{make}   # GNU makeok@end example@noindentHowever this is not always the case.  Some implementationsdiscard everything from @code{#} through the end of the line, ignoring anytrailing backslash.@example$ @kbd{pmake}  # BSD make"Makefile", line 3: Need an operatorFatal errors encountered -- cannot continue@end example@noindentTherefore, if you want to comment out a multi-line definition, prefix eachline with @code{#}, not only the first.@example# A = foo \#     bar \#     baz@end example@node Long Lines in Makefiles@section Long Lines in MakefilesTru64 5.1's @command{make} has been reported to crash when given amakefile with lines longer than around 20 kB.  Earlier versions arereported to exit with @code{Line too long} diagnostics.@node Macros and Submakes@section @code{make macro=value} and SubmakesA command-line variable definition such as @code{foo=bar} overrides anydefinition of @code{foo} in a makefile.  Some @command{make}implementations (such as GNU @command{make}) propagate thisoverride to subsidiary invocations of @command{make}.  Some otherimplementations do not pass the substitution along to submakes.@example$ @kbd{cat Makefile}foo = fooone:        @@echo $(foo)        $(MAKE) twotwo:        @@echo $(foo)$ @kbd{make foo=bar}            # GNU make 3.79.1barmake twomake[1]: Entering directory `/home/adl'barmake[1]: Leaving directory `/home/adl'$ @kbd{pmake foo=bar}           # BSD makebarpmake twofoo@end exampleYou have a few possibilities if you do want the @code{foo=bar} overrideto propagate to submakes.  One is to use the @option{-e}option, which causes all environment variables to have precedence overthe makefile macro definitions, and declare foo as an environmentvariable:@example$ @kbd{env foo=bar make -e}@end exampleThe @option{-e} option is propagated to submakes automatically,and since the environment is inherited between @command{make}invocations, the @code{foo} macro is overridden insubmakes as expected.This syntax (@code{foo=bar make -e}) is portable only when usedoutside of a makefile, for instance from a script or from thecommand line.  When run inside a @command{make} rule, GNU@command{make} 3.80 and prior versions forget to propagate the@option{-e} option to submakes.Moreover, using @option{-e} could have unexpected side effects if yourenvironment contains some other macros usually defined by themakefile.  (See also the note about @code{make -e} and @code{SHELL}below.)If you can foresee all macros that a user might want to override, thenyou can propagate them to submakes manually, from your makefile:@examplefoo = fooone:        @@echo $(foo)        $(MAKE) foo=$(foo) twotwo:        @@echo $(foo)@end exampleAnother way to propagate a variable to submakes in a portable way is toexpand an extra variable in every invocation of @samp{$(MAKE)} withinyour makefile:@examplefoo = fooone:        @@echo $(foo)        $(MAKE) $(SUBMAKEFLAGS) twotwo:        @@echo $(foo)@end exampleUsers must be aware that this technique is in use to take advantage ofit, e.g.@: with @code{make foo=bar SUBMAKEFLAGS='foo=bar'}, but itallows any macro to be overridden.  Makefiles generated by@command{automake} use this technique, expanding @code{$(AM_MAKEFLAGS)}on the command lines of submakes (@pxref{Subdirectories, , Automake,automake, GNU Automake}).@node The Make Macro MAKEFLAGS@section The Make Macro MAKEFLAGS@cindex @code{MAKEFLAGS} and @command{make}@cindex @command{make} and @code{MAKEFLAGS}Posix requires @command{make} to use @code{MAKEFLAGS} to affect thecurrent and recursive invocations of make, but allows implementationsseveral formats for the variable.  It is tricky to parse@code{$MAKEFLAGS} to determine whether @option{-s} for silent executionor @option{-k} for continued execution are in effect.  For example, youcannot assume that the first space-separated word in @code{$MAKEFLAGS}contains single-letter options, since in the Cygwin version ofGNU @command{make} it is either @option{--unix} or@option{--win32} with the second word containing single-letter options.@example$ @kbd{cat Makefile}all:        @@echo MAKEFLAGS = $(MAKEFLAGS)$ @kbd{make}MAKEFLAGS = --unix$ @kbd{make -k}MAKEFLAGS = --unix -k@end example@node The Make Macro SHELL@section The Make Macro @code{SHELL}@cindex @code{SHELL} and @command{make}@cindex @command{make} and @code{SHELL}Posix-compliant @command{make} internally uses the @code{$(SHELL)}macro to spawn shell processes and execute Make rules.  Thisis a builtin macro supplied by @command{make}, but it can be modifiedby a makefile or by a command-line argument.Not all @command{make} implementations define this @code{SHELL} macro.Tru64@command{make} is an example; this implementation always uses@code{/bin/sh}.  So it's a good idea to always define @code{SHELL} inyour makefiles.  If you use Autoconf, do@exampleSHELL = @@SHELL@@@end example@noindentIf you use Automake, this is done for you.Do not force @code{SHELL = /bin/sh} because that is not correcteverywhere.  Remember, @file{/bin/sh} is not Posix compliant on manysystems, such as FreeBSD 4, NetBSD 3, AIX 3, Solaris 10, or Tru64.Additionally, DJGPP lacks @code{/bin/sh}, and when itsGNU @command{make} port sees such a setting it enters aspecial emulation mode where features like pipes and redirections areemulated on top of DOS's @command{command.com}.  Unfortunately thisemulation is incomplete; for instance it does not handle commandsubstitutions.  Using @code{@@SHELL@@} means that your makefile willbenefit from the same improved shell, such as @command{bash} or@command{ksh}, that was discovered during @command{configure}, so thatyou aren't fighting two different sets of shell bugs between the twocontexts.Posix-compliant @command{make} should never acquire the value of$(SHELL) from the environment, even when @code{make -e} is used(otherwise, think about what would happen to your rules if@code{SHELL=/bin/tcsh}).However not all @command{make} implementations have this exception.For instance it's not surprising that Tru64 @command{make} doesn'tprotect @code{SHELL}, since it doesn't use it.@example$ @kbd{cat Makefile}SHELL = /bin/shFOO = fooall:        @@echo $(SHELL)        @@echo $(FOO)$ @kbd{env SHELL=/bin/tcsh FOO=bar make -e}   # Tru64 Make/bin/tcshbar$ @kbd{env SHELL=/bin/tcsh FOO=bar gmake -e}  # GNU make/bin/shbar@end exampleConversely, @command{make} is not supposed to export any changes to themacro @code{SHELL} to child processes.  Again, many implementationsbreak this rule:@example$ @kbd{cat Makefile}all:        @@echo $(SHELL)        @@printenv SHELL$ @kbd{env SHELL=sh make -e SHELL=/bin/ksh}   # BSD Make, GNU make 3.80/bin/ksh/bin/ksh$ @kbd{env SHELL=sh gmake -e SHELL=/bin/ksh}  # GNU make 3.81/bin/kshsh@end example@node Parallel Make@section Parallel Make@cindex Parallel @command{make}Support for parallel execution in @command{make} implementation varies.Generally, using GNU make is your best bet.When NetBSD or FreeBSD @command{make} are run in parallel mode, they willreuse the same shell for multiple commands within one recipe.  This canhave various unexpected consequences.  For example, changes of directoriesor variables persist between recipes, so that:@exampleall:        @@var=value; cd /; pwd; echo $$var; echo $$$$        @@pwd; echo $$var; echo $$$$@end example@noindentmay output the following with @code{make -j1}, at least on NetBSD up to5.1 and FreeBSD up to 8.2:@example/value32235/value32235@end example@noindentwhile without @option{-j1}, or with @option{-B}, the output looks lesssurprising:@example/value32238/tmp32239@end example@noindentAnother consequence is that, if one command in a recipe uses @code{exit 0}to indicate a successful exit, the shell will be gone and the remainingcommands of this recipe will not be executed.The BSD @command{make} implementations, when run in parallel mode,will also pass the @command{Makefile} recipes to the shell throughits standard input, thus making it unusable from the recipes:@example$ @kbd{cat Makefile}read:        @@read line; echo LINE: $$line@c $$ @c restore font-lock$ @kbd{echo foo | make read}LINE: foo$ @kbd{echo foo | make -j1 read} # NetBSD 5.1 and FreeBSD 8.2LINE:@end example@noindentMoreover, when FreeBSD @command{make} (up at least to 8.2) is run inparallel mode, it implements the @code{@@} and @code{-} ``recipemodifiers'' by dynamically modifying the active shell flags.  Thisbehavior has the effects of potentially clobbering the exit statusof recipes silenced with the @code{@@} modifier if they also unsetthe @option{errexit} shell flag, and of mangling the output inunexpected ways:@example$ @kbd{cat Makefile}a:        @@echo $$-; set +e; falseb:        -echo $$-; false; echo set -$ @kbd{make a; echo status: $?}ehBc*** Error code 1status: 1$ @kbd{make -j1 a; echo status: $?}ehBstatus: 0$ @kbd{make b}echo $-; echo set -hBcset -$ @kbd{make -j1 b}echo $-; echo hvB@end example@noindentYou can avoid all these issues by using the @option{-B} option to enablecompatibility semantics.  However, that will effectively also disableall parallelism as that will cause prerequisites to be updated in theorder they are listed in a rule.Some make implementations (among them, FreeBSD @command{make}, NetBSD@command{make}, and Solaris @command{dmake}), when invoked with a@option{-j@var{N}} option, connect the standard output and standarderror of all their child processes to pipes or temporary regularfiles.  This can lead to subtly different semantics in the behaviorof the spawned processes.  For example, even if the @command{make}standard output is connected to a tty, the recipe command will not be:@example$ @kbd{cat Makefile}all:        @@test -t 1 && echo "Is a tty" || echo "Is not a tty"$ @kbd{make -j 2} # FreeBSD 8.2 makeIs not a tty$ @kbd{make -j 2} # NetBSD 5.1 make--- all ---Is not a tty$ @kbd{dmake -j 2} # Solaris 10 dmake@var{hostname} --> 1 job@var{hostname} --> Job outputIs not a tty@end example@noindentOn the other hand:@example$ @kbd{make -j 2} # GNU make, Heirloom makeIs a tty@end example@noindentThe above examples also show additional status output produced in parallelmode for targets being updated by Solaris @command{dmake} and NetBSD@command{make} (but @emph{not} by FreeBSD @command{make}).Furthermore, parallel runs of those @command{make} implementations willroute standard error from commands that they spawn into their ownstandard output, and may remove leading whitespace from output lines.@node Comments in Make Rules@section Comments in Make Rules@cindex Comments in @file{Makefile} rules@cindex @file{Makefile} rules and commentsNever put comments in a rule.Some @command{make} treat anything starting with a tab as a command forthe current rule, even if the tab is immediately followed by a @code{#}.The @command{make} from Tru64 Unix V5.1 is one of them.  The followingmakefile runs @code{# foo} through the shell.@exampleall:        # foo@end exampleAs a workaround, you can use the @command{:} no-op command with a stringargument that gets ignored:@exampleall:        : "foo"@end exampleConversely, if you want to use the @samp{#} character in some command,you can only do so by expanding it inside a rule (@pxref{Comments inMake Macros}).  So for example, if @samp{COMMENT_CHAR} is substituted by@command{config.status} as @samp{#}, then the following substitutes@samp{@@COMMENT_CHAR@@} in a generated header:@examplefoo.h: foo.h.in        sed -e 's|@@''COMMENT_CHAR''@@|@@COMMENT_CHAR@@|g' \            $(srcdir)/foo.h.in > $@@@end exampleThe funny shell quoting avoids a substitution at @command{config.status}run time of the left-hand side of the @command{sed} @samp{s} command.@node Newlines in Make Rules@section Newlines in Make Rules@cindex Newlines in @file{Makefile} rules@cindex @file{Makefile} rules and newlinesIn shell scripts, newlines can be used inside string literals.  But inthe shell statements of @file{Makefile} rules, this is not possible:A newline not preceded by a backslash is a separator between shellstatements.  Whereas a newline that is preceded by a backslash becomespart of the shell statement according to POSIX, but gets replaced,together with the backslash that precedes it, by a space in GNU@command{make} 3.80 and older.  So, how can a newline be used in a stringliteral?The trick is to set up a shell variable that contains a newline:@examplenlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"@end exampleFor example, in order to create a multiline @samp{sed} expression thatinserts a blank line after every line of a file, this code can be used:@examplenlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \sed -e "s/\$$/\\$$@{nl@}/" < input > output@end example@node Comments in Make Macros@section Comments in Make Macros@cindex Comments in @file{Makefile} macros@cindex @file{Makefile} macros and commentsAvoid putting comments in macro values as far as possible.  Posixspecifies that the text starting from the @samp{#} sign until the end ofthe line is to be ignored, which has the unfortunate effect ofdisallowing them even within quotes.  Thus, the following might lead toa syntax error at compile time:@exampleCPPFLAGS = "-DCOMMENT_CHAR='#'"@end example@noindentas @samp{CPPFLAGS} may be expanded to @samp{"-DCOMMENT_CHAR='}.Most @command{make} implementations disregard this and treat single anddouble quotes specially here.  Also, GNU @command{make} lets you put@samp{#} into a macro value by escaping it with a backslash, i.e.,@samp{\#}.  However, neither of these usages are portable.@xref{Comments in Make Rules}, for a portable alternative.Even without quoting involved, comments can have surprising effects,because the whitespace before them is part of the variable value:@examplefoo = bar # trailing commentprint: ; @@echo "$(foo)."@end example@noindentprints @samp{bar .}, which is usually not intended, and can expose@command{make} bugs as described below.@node Trailing whitespace in Make Macros@section Trailing whitespace in Make Macros@cindex whitespace in @file{Makefile} macros@cindex @file{Makefile} macros and whitespaceGNU @command{make} 3.80 mistreats trailing whitespace in macrosubstitutions and appends another spurious suffix:@exampleempty =foo = bar $(empty)print: ; @@echo $(foo:=.test)@end example@noindentprints @samp{bar.test .test}.BSD and Solaris @command{make} implementations do not honor trailingwhitespace in macro definitions as Posix requires:@examplefoo = bar # Note the space after "bar".print: ; @@echo $(foo)t@end example@noindentprints @samp{bart} instead of @samp{bar t}.  To work around this, youcan use a helper macro as in the previous example.@node Command-line Macros and whitespace@section Command-line Macros and whitespace@cindex whitespace in command-line macros@cindex command-line, macros set on@cindex environment, macros set fromSome @command{make} implementations may strip trailing whitespace offof macros set on the command line in addition to leading whitespace.Further, some may strip leading whitespace off of macros set fromenvironment variables:@example$ @kbd{echo 'print: ; @@echo "x$(foo)x$(bar)x"' |  foo=' f f ' make -f - bar=' b b '}x f f xb b x  # AIX, BSD, GNU makexf f xb b x   # HP-UX, IRIX, Tru64/OSF makex f f xb bx   # Solaris make@end example@node obj/ and Make@section The @file{obj/} Subdirectory and Make@cindex @file{obj/}, subdirectory@cindex BSD @command{make} and @file{obj/}Never name one of your subdirectories @file{obj/} if you don't likesurprises.If an @file{obj/} directory exists, BSD @command{make} enters itbefore reading the makefile.  Hence the makefile in thecurrent directory is not read.@example$ @kbd{cat Makefile}all:        echo Hello$ @kbd{cat obj/Makefile}all:        echo World$ @kbd{make}      # GNU makeecho HelloHello$ @kbd{pmake}     # BSD makeecho WorldWorld@end example@node make -k Status@section Exit Status of @code{make -k}@cindex @code{make -k}Do not rely on the exit status of @code{make -k}.  Some implementationsreflect whether they encountered an error in their exit status; otherimplementations always succeed.@example$ @kbd{cat Makefile}all:        false$ @kbd{make -k; echo exit status: $?}    # GNU makefalsemake: *** [all] Error 1exit status: 2$ @kbd{pmake -k; echo exit status: $?}   # BSD makefalse*** Error code 1 (continuing)exit status: 0@end example@node VPATH and Make@section @code{VPATH} and Make@cindex @code{VPATH}Posix does not specify the semantics of @code{VPATH}.  Typically,@command{make} supports @code{VPATH}, but its implementation is notconsistent.Autoconf and Automake support makefiles whose usages of @code{VPATH} areportable to recent-enough popular implementations of @command{make}, butto keep the resulting makefiles portable, a package's makefileprototypes must take the following issues into account.  These issuesare complicated and are often poorly understood, and installers who use@code{VPATH} should expect to find many bugs in this area.  If you use@code{VPATH}, the simplest way to avoid these portability bugs is tostick with GNU @command{make}, since it is the mostcommonly-used @command{make} among Autoconf users.Here are some known issues with some @code{VPATH}implementations.@menu* Variables listed in VPATH::   @code{VPATH} must be literal on ancient hosts* VPATH and Double-colon::      Problems with @samp{::} on ancient hosts* $< in Explicit Rules::        @code{$<} does not work in ordinary rules* Automatic Rule Rewriting::    @code{VPATH} goes wild on Solaris* Tru64 Directory Magic::       @command{mkdir} goes wild on Tru64* Make Target Lookup::          More details about @code{VPATH} lookup@end menu@node Variables listed in VPATH@subsection Variables listed in @code{VPATH}@cindex @code{VPATH} and variables@cindex variables and @code{VPATH}Do not set @code{VPATH} to the value of another variable, for example@samp{VPATH = $(srcdir)}, because some ancient versions of@command{make} do not do variable substitutions on the value of@code{VPATH}.  For example, use this@examplesrcdir = @@srcdir@@VPATH = @@srcdir@@@end example@noindentrather than @samp{VPATH = $(srcdir)}.  Note that with GNUAutomake, there is no need to set this yourself.@node VPATH and Double-colon@subsection @code{VPATH} and Double-colon Rules@cindex @code{VPATH} and double-colon rules@cindex double-colon rules and @code{VPATH}With ancient versions of Sun @command{make},any assignment to @code{VPATH} causes @command{make} to execute onlythe first set of double-colon rules.However, this problem is no longer of practical concern.@node $< in Explicit Rules@subsection @code{$<} Not Supported in Explicit Rules@cindex explicit rules, @code{$<}, and @code{VPATH}@cindex @code{$<}, explicit rules, and @code{VPATH}@cindex @code{VPATH}, explicit rules, and @code{$<}Using @code{$<} in explicit rules is not portable.The prerequisite file must be named explicitly in the rule.  If you wantto find the prerequisite via a @code{VPATH} search, you have to code thewhole thing manually.  @xref{Build Directories}.@node Automatic Rule Rewriting@subsection Automatic Rule Rewriting@cindex @code{VPATH} and automatic rule rewriting@cindex automatic rule rewriting and @code{VPATH}Some @command{make} implementations, such as Solaris and Tru64,search for prerequisites in @code{VPATH} andthen rewrite each occurrence as a plain word in the rule.For instance:@example# This isn't portable to GNU make.VPATH = ../pkg/srcf.c: if.c        cp if.c f.c@end example@noindentexecutes @code{cp ../pkg/src/if.c f.c} if @file{if.c} isfound in @file{../pkg/src}.However, this rule leads to real problems in practice.  For example, ifthe source directory contains an ordinary file named @file{test} that isused in a dependency, Solaris @command{make} rewrites commands like@samp{if test -r foo; @dots{}} to @samp{if ../pkg/src/test -r foo;@dots{}}, which is typically undesirable.  In fact, @command{make} iscompletely unaware of shell syntax used in the rules, so the VPATHrewrite can potentially apply to @emph{any} whitespace-separated wordin a rule, including shell variables, functions, and keywords.@example$ @kbd{mkdir build}$ @kbd{cd build}$ @kbd{cat > Makefile <<'END'}VPATH = ..all: arg func for echo        func () @{ for arg in "$$@@"; do echo $$arg; done; @}; \        func "hello world"END$ @kbd{touch ../arg ../func ../for ../echo}$ @kbd{make}../func () @{ ../for ../arg in "$@@"; do ../echo $arg; done; @}; \../func "hello world"sh: syntax error at line 1: `do' unexpected*** Error code 2@end example@noindentTo avoid this problem, portable makefiles should never mention a sourcefile or dependency whose name is that of a shell keyword like @file{for}or @file{until}, a shell command like @command{cat} or @command{gcc} or@command{test}, or a shell function or variable used in the corresponding@command{Makefile} recipe.Because of these problems GNU @command{make} and many other @command{make}implementations do not rewrite commands, so portable makefiles shouldsearch @code{VPATH} manually.  It is tempting to write this:@smallexample# This isn't portable to Solaris make.VPATH = ../pkg/srcf.c: if.c        cp `test -f if.c || echo $(VPATH)/`if.c f.c@end smallexample@noindentHowever, the ``prerequisite rewriting'' still applies here.  So if@file{if.c} is in @file{../pkg/src}, Solaris and Tru64 @command{make}execute@smallexamplecp `test -f ../pkg/src/if.c || echo ../pkg/src/`if.c f.c@end smallexample@noindentwhich reduces to@examplecp if.c f.c@end example@noindentand thus fails.  Oops.A simple workaround, and good practice anyway, is to use @samp{$?} and@samp{$@@} when possible:@smallexampleVPATH = ../pkg/srcf.c: if.c        cp $? $@@@end smallexample@noindentbut this does not generalize well to commands with multipleprerequisites.  A more general workaround is to rewrite the rule so thatthe prerequisite @file{if.c} never appears as a plain word.  Forexample, these three rules would be safe, assuming @file{if.c} is in@file{../pkg/src} and the other files are in the working directory:@smallexampleVPATH = ../pkg/srcf.c: if.c f1.c        cat `test -f ./if.c || echo $(VPATH)/`if.c f1.c >$@@g.c: if.c g1.c        cat `test -f 'if.c' || echo $(VPATH)/`if.c g1.c >$@@h.c: if.c h1.c        cat `test -f "if.c" || echo $(VPATH)/`if.c h1.c >$@@@end smallexampleThings get worse when your prerequisites are in a macro.@exampleVPATH = ../pkg/srcHEADERS = f.h g.h h.hinstall-HEADERS: $(HEADERS)        for i in $(HEADERS); do \          $(INSTALL) -m 644 \            `test -f $$i || echo $(VPATH)/`$$i \            $(DESTDIR)$(includedir)/$$i; \@c $$ restore font-lock        done@end exampleThe above @code{install-HEADERS} rule is not Solaris-proof because @code{fori in $(HEADERS);} is expanded to @code{for i in f.h g.h h.h;}where @code{f.h} and @code{g.h} are plain words and are hencesubject to @code{VPATH} adjustments.If the three files are in @file{../pkg/src}, the rule is run as:@examplefor i in ../pkg/src/f.h ../pkg/src/g.h h.h; do \  install -m 644 \     `test -f $i || echo ../pkg/src/`$i \     /usr/local/include/$i; \done@end examplewhere the two first @command{install} calls fail.  For instance,consider the @code{f.h} installation:@exampleinstall -m 644 \  `test -f ../pkg/src/f.h || \    echo ../pkg/src/ \  `../pkg/src/f.h \  /usr/local/include/../pkg/src/f.h;@end example@noindentIt reduces to:@exampleinstall -m 644 \  ../pkg/src/f.h \  /usr/local/include/../pkg/src/f.h;@end exampleNote that the manual @code{VPATH} search did not cause any problems here;however this command installs @file{f.h} in an incorrect directory.Trying to quote @code{$(HEADERS)} in some way, as we did for@code{foo.c} a few makefiles ago, does not help:@exampleinstall-HEADERS: $(HEADERS)        headers='$(HEADERS)'; \        for i in $$headers; do \          $(INSTALL) -m 644 \            `test -f $$i || echo $(VPATH)/`$$i \            $(DESTDIR)$(includedir)/$$i; \        done@end exampleNow, @code{headers='$(HEADERS)'} macro-expands to:@exampleheaders='f.h g.h h.h'@end example@noindentbut @code{g.h} is still a plain word.  (As an aside, the idiom@code{headers='$(HEADERS)'; for i in $$headers;} is a goodidea if @code{$(HEADERS)} can be empty, because some shells diagnose asyntax error on @code{for i in;}.)One workaround is to strip this unwanted @file{../pkg/src/} prefix manually:@exampleVPATH = ../pkg/srcHEADERS = f.h g.h h.hinstall-HEADERS: $(HEADERS)        headers='$(HEADERS)'; \        for i in $$headers; do \          i=`expr "$$i" : '$(VPATH)/\(.*\)'`;          $(INSTALL) -m 644 \            `test -f $$i || echo $(VPATH)/`$$i \            $(DESTDIR)$(includedir)/$$i; \@c $$ restore font-lock        done@end exampleAutomake does something similar.  However the above hack works only ifthe files listed in @code{HEADERS} are in the current directory or asubdirectory; they should not be in an enclosing directory.  If we had@code{HEADERS = ../f.h}, the above fragment would fail in a VPATHbuild with Tru64 @command{make}.  The reason is that not only doesTru64 @command{make} rewrite dependencies, but it also simplifiesthem.  Hence @code{../f.h} becomes @code{../pkg/f.h} instead of@code{../pkg/src/../f.h}.  This obviously defeats any attempt to stripa leading @file{../pkg/src/} component.The following example makes the behavior of Tru64 @command{make}more apparent.@example$ @kbd{cat Makefile}VPATH = suball: ../foo        echo ../foo$ @kbd{ls}Makefile foo$ @kbd{make}echo foofoo@end example@noindentDependency @file{../foo} was found in @file{sub/../foo}, but Tru64@command{make} simplified it as @file{foo}.  (Note that the @file{sub/}directory does not even exist, this just means that the simplificationoccurred before the file was checked for.)For the record here is how SunOS 4 @command{make} behaves on thisexample.@smallexample$ @kbd{make}make: Fatal error: Don't know how to make target `../foo'$ @kbd{mkdir sub}$ @kbd{make}echo sub/../foosub/../foo@end smallexample@node Tru64 Directory Magic@subsection Tru64 @command{make} Creates Prerequisite Directories Magically@cindex @code{VPATH} and prerequisite directories@cindex prerequisite directories and @code{VPATH}When a prerequisite is a subdirectory of @code{VPATH}, Tru64@command{make} creates it in the current directory.@example$ @kbd{mkdir -p foo/bar build}$ @kbd{cd build}$ @kbd{cat >Makefile <<ENDVPATH = ..all: foo/barEND}$ @kbd{make}mkdir foomkdir foo/bar@end exampleThis can yield unexpected results if a rule uses a manual @code{VPATH}search as presented before.@exampleVPATH = ..all : foo/bar        command `test -d foo/bar || echo ../`foo/bar@end exampleThe above @command{command} is run on the empty @file{foo/bar}directory that was created in the current directory.@node Make Target Lookup@subsection Make Target Lookup@cindex @code{VPATH}, resolving target pathnamesGNU @command{make} uses a complex algorithm to decide when itshould use files found via a @code{VPATH} search.  @xref{SearchAlgorithm, , How Directory Searches are Performed, make, The GNU MakeManual}.If a target needs to be rebuilt, GNU @command{make} discards thefile name found during the @code{VPATH} search for this target, andbuilds the file locally using the file name given in the makefile.If a target does not need to be rebuilt, GNU @command{make} uses thefile name found during the @code{VPATH} search.Other @command{make} implementations, like NetBSD @command{make}, areeasier to describe: the file name found during the @code{VPATH} searchis used whether the target needs to be rebuilt or not.  Thereforenew files are created locally, but existing files are updated at their@code{VPATH} location.OpenBSD and FreeBSD @command{make}, however,never perform a@code{VPATH} search for a dependency that has an explicit rule.This is extremely annoying.When attempting a @code{VPATH} build for an autoconfiscated package(e.g., @code{mkdir build && cd build && ../configure}), this meansGNU@command{make} builds everything locally in the @file{build}directory, while BSD @command{make} builds new files locally andupdates existing files in the source directory.@example$ @kbd{cat Makefile}VPATH = ..all: foo.x bar.xfoo.x bar.x: newer.x        @@echo Building $@@$ @kbd{touch ../bar.x}$ @kbd{touch ../newer.x}$ @kbd{make}        # GNU makeBuilding foo.xBuilding bar.x$ @kbd{pmake}       # NetBSD makeBuilding foo.xBuilding ../bar.x$ @kbd{fmake}       # FreeBSD make, OpenBSD makeBuilding foo.xBuilding bar.x$ @kbd{tmake}       # Tru64 makeBuilding foo.xBuilding bar.x$ @kbd{touch ../bar.x}$ @kbd{make}        # GNU makeBuilding foo.x$ @kbd{pmake}       # NetBSD makeBuilding foo.x$ @kbd{fmake}       # FreeBSD make, OpenBSD makeBuilding foo.xBuilding bar.x$ @kbd{tmake}       # Tru64 makeBuilding foo.xBuilding bar.x@end exampleNote how NetBSD @command{make} updates @file{../bar.x} in itsVPATH location, and how FreeBSD, OpenBSD, and Tru64@command{make} alwaysupdate @file{bar.x}, even when @file{../bar.x} is up to date.Another point worth mentioning is that once GNU @command{make} hasdecided to ignore a @code{VPATH} file name (e.g., it ignored@file{../bar.x} in the above example) it continues to ignore it whenthe target occurs as a prerequisite of another rule.The following example shows that GNU @command{make} does not look up@file{bar.x} in @code{VPATH} before performing the @code{.x.y} rule,because it ignored the @code{VPATH} result of @file{bar.x} while runningthe @code{bar.x: newer.x} rule.@example$ @kbd{cat Makefile}VPATH = ..all: bar.ybar.x: newer.x        @@echo Building $@@.SUFFIXES: .x .y.x.y:        cp $< $@@$ @kbd{touch ../bar.x}$ @kbd{touch ../newer.x}$ @kbd{make}        # GNU makeBuilding bar.xcp bar.x bar.ycp: cannot stat `bar.x': No such file or directorymake: *** [bar.y] Error 1$ @kbd{pmake}       # NetBSD makeBuilding ../bar.xcp ../bar.x bar.y$ @kbd{rm bar.y}$ @kbd{fmake}       # FreeBSD make, OpenBSD makeecho Building bar.xcp bar.x bar.ycp: cannot stat `bar.x': No such file or directory*** Error code 1$ @kbd{tmake}       # Tru64 makeBuilding bar.xcp: bar.x: No such file or directory*** Exit 1@end exampleNote that if you drop away the command from the @code{bar.x: newer.x}rule, GNU @command{make} magically starts to work: itknows that @code{bar.x} hasn't been updated, therefore it doesn'tdiscard the result from @code{VPATH} (@file{../bar.x}) in succeedinguses.  Tru64 also works, but FreeBSD and OpenBSDstill don't.@example$ @kbd{cat Makefile}VPATH = ..all: bar.ybar.x: newer.x.SUFFIXES: .x .y.x.y:        cp $< $@@$ @kbd{touch ../bar.x}$ @kbd{touch ../newer.x}$ @kbd{make}        # GNU makecp ../bar.x bar.y$ @kbd{rm bar.y}$ @kbd{pmake}       # NetBSD makecp ../bar.x bar.y$ @kbd{rm bar.y}$ @kbd{fmake}       # FreeBSD make, OpenBSD makecp bar.x bar.ycp: cannot stat `bar.x': No such file or directory*** Error code 1$ @kbd{tmake}       # Tru64 makecp ../bar.x bar.y@end exampleIt seems the sole solution that would please every @command{make}implementation is to never rely on @code{VPATH} searches for targets.In other words, @code{VPATH} should be reserved to unbuilt sources.@node Single Suffix Rules@section Single Suffix Rules and Separated Dependencies@cindex Single Suffix Inference Rule@cindex Rule, Single Suffix InferenceA @dfn{Single Suffix Rule} is basically a usual suffix (inference) rule(@samp{.from.to:}), but which @emph{destination} suffix is empty(@samp{.from:}).@cindex Separated Dependencies@dfn{Separated dependencies} simply refers to listing the prerequisiteof a target, without defining a rule.  Usually one can list on the onehand side, the rules, and on the other hand side, the dependencies.Solaris @command{make} does not support separated dependencies fortargets defined by single suffix rules:@example$ @kbd{cat Makefile}.SUFFIXES: .infoo: foo.in.in:        cp $< $@@$ @kbd{touch foo.in}$ @kbd{make}$ @kbd{ls}Makefile  foo.in@end example@noindentwhile GNU Make does:@example$ @kbd{gmake}cp foo.in foo$ @kbd{ls}Makefile  foo       foo.in@end exampleNote it works without the @samp{foo: foo.in} dependency.@example$ @kbd{cat Makefile}.SUFFIXES: .in.in:        cp $< $@@$ @kbd{make foo}cp foo.in foo@end example@noindentand it works with double suffix inference rules:@example$ @kbd{cat Makefile}foo.out: foo.in.SUFFIXES: .in .out.in.out:        cp $< $@@$ @kbd{make}cp foo.in foo.out@end exampleAs a result, in such a case, you have to write target rules.@node Timestamps and Make@section Timestamp Resolution and Make@cindex timestamp resolutionTraditionally, file timestamps had 1-second resolution, and@command{make} used those timestamps to determine whether one file wasnewer than the other.  However, many modern file systems havetimestamps with 1-nanosecond resolution.  Some @command{make}implementations look at the entire timestamp; others ignore thefractional part, which can lead to incorrect results.  Normally thisis not a problem, but in some extreme cases you may need to use trickslike @samp{sleep 1} to work around timestamp truncation bugs.Commands like @samp{cp -p} and @samp{touch -r} typically do not copyfile timestamps to their full resolutions (@pxref{touch, , Limitations of UsualTools}).  Hence you should be wary of rules like this:@exampledest: src        cp -p src dest@end exampleas @file{dest} often appears to be older than @file{src} after thetimestamp is truncated, and this can cause @command{make} to doneedless rework the next time it is invoked.  To work around thisproblem, you can use a timestamp file, e.g.:@exampledest-stamp: src        cp -p src dest        date >dest-stamp@end exampleApart from timestamp resolution, there are also differences in handlingequal timestamps.  HP-UX @command{make} updates targets if it has thesame time stamp as one of its prerequisites, in violation of Posix rules.This can cause spurious rebuilds for repeated runs of @command{make}.This in turn can cause @command{make} to fail if it tries to rebuildgenerated files in a possibly read-only source tree with tools notpresent on the end-user machine.  Use GNU @command{make} instead.@c ======================================== Portable C and C++ Programming@node Portable C and C++@chapter Portable C and C++ Programming@cindex Portable C and C++ programmingC and C++ programs often use low-level features of the underlyingsystem, and therefore are often more difficult to make portable to otherplatforms.Several standards have been developed to help make your programs moreportable.  If you write programs with these standards in mind, you canhave greater confidence that your programs work on a wide varietyof systems.@ifhtml@uref{http://@/gcc.gnu.org/@/onlinedocs/@/gcc/@/Standards.html, LanguageStandards Supported by GCC}@end ifhtml@ifnothtml@xref{Standards, , Language Standards Supported byGCC, gcc, Using the GNU Compiler Collection(GCC)},@end ifnothtmlfor a list of C-related standards.  Many programs also assume the@uref{http://@/www.opengroup.org/@/susv3, Posix standard}.Some old code is written to be portable to K&R C, which predates any Cstandard.  K&R C compilers are no longer of practical interest, though,and the rest of section assumes at least C89, the first C standard.Program portability is a huge topic, and this section can only brieflyintroduce common pitfalls.  @xref{System Portability, , Portabilitybetween System Types, standards, The GNU Coding Standards}, formore information.@menu* Varieties of Unportability::  How to make your programs unportable* Integer Overflow::            When integers get too large* Preprocessor Arithmetic::     @code{#if} expression problems* Null Pointers::               Properties of null pointers* Buffer Overruns::             Subscript errors and the like* Volatile Objects::            @code{volatile} and signals* Floating Point Portability::  Portable floating-point arithmetic* Exiting Portably::            Exiting and the exit status@end menu@node Varieties of Unportability@section Varieties of Unportability@cindex portabilityAutoconf tests and ordinary programs often need to test what is allowedon a system, and therefore they may need to deliberately exceed theboundaries of what the standards allow, if only to see whether anoptional feature is present.  When you write such a program, you shouldkeep in mind the difference between constraints, unspecified behavior,and undefined behavior.In C, a @dfn{constraint} is a rule that the compiler must enforce.  Anexample constraint is that C programs must not declare a bit-field withnegative width.  Tests can therefore reliably assume that programs withnegative-width bit-fields are rejected by a compiler that conformsto the standard.@dfn{Unspecified behavior} is valid behavior, where the standard allowsmultiple possibilities.  For example, the order of evaluation offunction arguments is unspecified.  Some unspecified behavior is@dfn{implementation-defined}, i.e., documented by the implementation,but since Autoconf tests cannot read the documentation they cannotdistinguish between implementation-defined and other unspecifiedbehavior.  It is common for Autoconf tests to probe implementations todetermine otherwise-unspecified behavior.@dfn{Undefined behavior} is invalid behavior, where the standard allowsthe implementation to do anything it pleases.  For example,dereferencing a null pointer leads to undefined behavior.  If possible,test programs should avoid undefined behavior, since a program withundefined behavior might succeed on a test that should fail.The above rules apply to programs that are intended to conform to thestandard.  However, strictly-conforming programs are quite rare, sincethe standards are so limiting.  A major goal of Autoconf is to supportprograms that use implementation features not described by the standard,and it is fairly common for test programs to violate the above rules, ifthe programs work well enough in practice.@node Integer Overflow@section Integer Overflow@cindex integer overflow@cindex overflow, signed integer@cindex signed integer overflow@cindex wraparound arithmeticIn practice many portable C programs assume that signed integer overflow wrapsaround reliably using two's complement arithmetic.  Yet the C standardsays that program behavior is undefined on overflow, and in a few casesC programs do not work on some modern implementations because theiroverflows do not wrap around as their authors expected.  Conversely, insigned integer remainder, the C standard requires overflowbehavior that is commonly not implemented.@menu* Integer Overflow Basics::     Why integer overflow is a problem* Signed Overflow Examples::    Examples of code assuming wraparound* Optimization and Wraparound::  Optimizations that break uses of wraparound* Signed Overflow Advice::      Practical advice for signed overflow issues* Signed Integer Division::     @code{INT_MIN / -1} and @code{INT_MIN % -1}@end menu@node Integer Overflow Basics@subsection Basics of Integer Overflow@cindex integer overflow@cindex overflow, signed integer@cindex signed integer overflow@cindex wraparound arithmeticIn languages like C, unsigned integer overflow reliably wraps around;e.g., @code{UINT_MAX + 1} yields zero.This is guaranteed by the C standard and isportable in practice, unless you specify aggressive,nonstandard optimization optionssuitable only for special applications.In contrast, the C standard says that signed integer overflow leads toundefined behavior where a program can do anything, including dumpingcore or overrunning a buffer.  The misbehavior can even precede theoverflow.  Such an overflow can occur during addition, subtraction,multiplication, division, and left shift.Despite this requirement of the standard, many C programs and Autoconftests assume that signed integer overflow silently wraps around modulo apower of two, using two's complement arithmetic, so long as you cast theresulting value to a signed integer type or store it into a signedinteger variable.  If you use conservative optimization flags, suchprograms are generally portable to the vast majority of modernplatforms, with a few exceptions discussed later.For historical reasons the C standard also allows implementations withones' complement or signed magnitude arithmetic, but it is safe toassume two's complement nowadays.Also, overflow can occur when converting an out-of-range value to asigned integer type.  Here a standard implementation must define whathappens, but this might include raising an exception.  In practice allknown implementations support silent wraparound in this case, so you neednot worry about other possibilities.@node Signed Overflow Examples@subsection Examples of Code Assuming Wraparound Overflow@cindex integer overflow@cindex overflow, signed integer@cindex signed integer overflow@cindex wraparound arithmeticThere has long been a tension between what the C standard requires forsigned integer overflow, and what C programs commonly assume.  Thestandard allows aggressive optimizations based on assumptions thatoverflow never occurs, but many practical C programs rely on overflowwrapping around.  These programs do not conform to the standard, butthey commonly work in practice because compiler writers areunderstandably reluctant to implement optimizations that would breakmany programs, unless perhaps a user specifies aggressive optimization.The C Standard says that if a program has signed integer overflow itsbehavior is undefined, and the undefined behavior can even precede theoverflow.  To take an extreme example:@c Inspired by Robert Dewar's example in@c <http://gcc.gnu.org/ml/gcc/2007-01/msg00038.html> (2007-01-01).@exampleif (password == expected_password)  allow_superuser_privileges ();else if (counter++ == INT_MAX)  abort ();else  printf ("%d password mismatches\n", counter);@end example@noindentIf the @code{int} variable @code{counter} equals @code{INT_MAX},@code{counter++} must overflow and the behavior is undefined, so the Cstandard allows the compiler to optimize away the test against@code{INT_MAX} and the @code{abort} call.Worse, if an earlier bug in the program lets the compiler deduce that@code{counter == INT_MAX} or that @code{counter} previously overflowed,the C standard allows the compiler to optimize away the password testand generate code that allows superuser privileges unconditionally.Despite this requirement by the standard, it has long been common for Ccode to assume wraparound arithmetic after signed overflow, and allknown practical C implementations support some C idioms that assumewraparound signed arithmetic, even if the idioms do not conformstrictly to the standard.  If your code looks like the followingexamples it will almost surely work with real-world compilers.Here is an example derived from the 7th Edition Unix implementation of@code{atoi} (1979-01-10):@examplechar *p;int f, n;@dots{}while (*p >= '0' && *p <= '9')  n = n * 10 + *p++ - '0';return (f ? -n : n);@end example@noindentEven if the input string is in range, on most modern machines this hassigned overflow when computing the most negative integer (the @code{-n}overflows) or a value near an extreme integer (the first @code{+}overflows).Here is another example, derived from the 7th Edition implementation of@code{rand} (1979-01-10).  Here the programmer expects bothmultiplication and addition to wrap on overflow:@examplestatic long int randx = 1;@dots{}randx = randx * 1103515245 + 12345;return (randx >> 16) & 077777;@end exampleIn the following example, derived from the GNU C Library 2.5implementation of @code{mktime} (2006-09-09), the code assumeswraparound arithmetic in @code{+} to detect signed overflow:@exampletime_t t, t1, t2;int sec_requested, sec_adjustment;@dots{}t1 = t + sec_requested;t2 = t1 + sec_adjustment;if (((t1 < t) != (sec_requested < 0))    | ((t2 < t1) != (sec_adjustment < 0)))  return -1;@end exampleIf your code looks like these examples, it is probably safe even thoughit does not strictly conform to the C standard.  This might lead one tobelieve that one can generally assume wraparound on overflow, but thatis not always true, as can be seen in the next section.@node Optimization and Wraparound@subsection Optimizations That Break Wraparound Arithmetic@cindex loop inductionCompilers sometimes generate code that is incompatible with wraparoundinteger arithmetic.  A simple example is an algebraic simplification: acompiler might translate @code{(i * 2000) / 1000} to @code{i * 2}because it assumes that @code{i * 2000} does not overflow.  Thetranslation is not equivalent to the original when overflow occurs:e.g., in the typical case of 32-bit signed two's complement wraparound@code{int}, if @code{i} has type @code{int} and value @code{1073742},the original expression returns @minus{}2147483 but the optimizedversion returns the mathematically correct value 2147484.More subtly, loop induction optimizations often exploit the undefinedbehavior of signed overflow.  Consider the following contrived function@code{sumc}:@exampleintsumc (int lo, int hi)@{  int sum = 0;  int i;  for (i = lo; i <= hi; i++)    sum ^= i * 53;  return sum;@}@end example@noindentTo avoid multiplying by 53 each time through the loop, an optimizingcompiler might internally transform @code{sumc} to the equivalent of thefollowing:@exampleinttransformed_sumc (int lo, int hi)@{  int sum = 0;  int hic = hi * 53;  int ic;  for (ic = lo * 53; ic <= hic; ic += 53)    sum ^= ic;  return sum;@}@end example@noindentThis transformation is allowed by the C standard, but it is invalid forwraparound arithmetic when @code{INT_MAX / 53 < hi}, because then theoverflow in computing expressions like @code{hi * 53} can cause theexpression @code{i <= hi} to yield a different value from thetransformed expression @code{ic <= hic}.For this reason, compilers that use loop induction and similartechniques often do not support reliable wraparound arithmetic when aloop induction variable like @code{ic} is involved.  Since loopinduction variables are generated by the compiler, and are not visiblein the source code, it is not always trivial to say whether the problemaffects your code.Hardly any code actually depends on wraparound arithmetic in cases likethese, so in practice these loop induction optimizations are almostalways useful.  However, edge cases in this area can cause problems.For example:@exampleint j;for (j = 1; 0 < j; j *= 2)  test (j);@end example@noindentHere, the loop attempts to iterate through all powers of 2 that@code{int} can represent, but the C standard allows a compiler tooptimize away the comparison and generate an infinite loop,under the argument that behavior is undefined on overflow.  As of thiswriting this optimization is not done by any production version ofGCC with @option{-O2}, but it might be performed by othercompilers, or by more aggressive GCC optimization options,and the GCC developers have not decided whether it willcontinue to work with GCC and @option{-O2}.@node Signed Overflow Advice@subsection Practical Advice for Signed Overflow Issues@cindex integer overflow@cindex overflow, signed integer@cindex signed integer overflow@cindex wraparound arithmeticIdeally the safest approach is to avoid signed integer overflowentirely.  For example, instead of multiplying two signed integers, youcan convert them to unsigned integers, multiply the unsigned values,then test whether the result is in signed range.Rewriting code in this way will be inconvenient, though, particularly ifthe signed values might be negative.  Also, it may hurtperformance.  Using unsigned arithmetic to check for overflow isparticularly painful to do portably and efficiently when dealing with aninteger type like @code{uid_t} whose width and signedness vary fromplatform to platform.Furthermore, many C applications pervasively assume wraparound behaviorand typically it is not easy to find and remove all these assumptions.Hence it is often useful to maintain nonstandard code that assumeswraparound on overflow, instead of rewriting the code.  The rest of thissection attempts to give practical advice for this situation.If your code wants to detect signed integer overflow in @code{sum = a +b}, it is generally safe to use an expression like @code{(sum < a) != (b< 0)}.If your code uses a signed loop index, make sure that the index cannotoverflow, along with all signed expressions derived from the index.Here is a contrived example of problematic code with two instances ofoverflow.@examplefor (i = INT_MAX - 10; i <= INT_MAX; i++)  if (i + 1 < 0)    @{      report_overflow ();      break;    @}@end example@noindentBecause of the two overflows, a compiler might optimize away ortransform the two comparisons in a way that is incompatible with thewraparound assumption.If your code uses an expression like @code{(i * 2000) / 1000} and youactually want the multiplication to wrap around on overflow, useunsigned arithmeticto do it, e.g., @code{((int) (i * 2000u)) / 1000}.If your code assumes wraparound behavior and you want to insulate itagainst any GCC optimizations that would fail to support thatbehavior, you should use GCC's @option{-fwrapv} option, whichcauses signed overflow to wrap around reliably (except for division andremainder, as discussed in the next section).If you need to port to platforms where signed integer overflow does notreliably wrap around (e.g., due to hardware overflow checking, or tohighly aggressive optimizations), you should consider debugging withGCC's @option{-ftrapv} option, which causes signed overflow toraise an exception.@node Signed Integer Division@subsection Signed Integer Division and Integer Overflow@cindex division, integerOverflow in signedinteger division is not always harmless: for example, on CPUs of thei386 family, dividing @code{INT_MIN} by @code{-1} yields a SIGFPE signalwhich by default terminates the program.  Worse, taking the remainderof these two values typically yields the same signal on these CPUs,even though the C standard requires @code{INT_MIN % -1} to yield zerobecause the expression does not overflow.@node Preprocessor Arithmetic@section Preprocessor Arithmetic@cindex preprocessor arithmeticIn C99, preprocessor arithmetic, used for @code{#if} expressions, mustbe evaluated as if all signed values are of type @code{intmax_t} and allunsigned values of type @code{uintmax_t}.  Many compilers are buggy inthis area, though.  For example, as of 2007, Sun C mishandles @code{#ifLLONG_MIN < 0} on a platform with 32-bit @code{long int} and 64-bit@code{long long int}.  Also, some older preprocessors mishandleconstants ending in @code{LL}.  To work around these problems, you cancompute the value of expressions like @code{LONG_MAX < LLONG_MAX} at@code{configure}-time rather than at @code{#if}-time.@node Null Pointers@section Properties of Null Pointers@cindex null pointersMost modern hosts reliably fail when you attempt to dereference a nullpointer.On almost all modern hosts, null pointers use an all-bits-zero internalrepresentation, so you can reliably use @code{memset} with 0 to set allthe pointers in an array to null values.If @code{p} is a null pointer to an object type, the C expression@code{p + 0} always evaluates to @code{p} on modern hosts, even thoughthe standard says that it has undefined behavior.@node Buffer Overruns@section Buffer Overruns and Subscript Errors@cindex buffer overrunsBuffer overruns and subscript errors are the most common dangerouserrors in C programs.  They result in undefined behavior because storingoutside an array typically modifies storage that is used by some otherobject, and most modern systems lack runtime checks to catch theseerrors.  Programs should not rely on buffer overruns being caught.There is one exception to the usual rule that a portable program cannotaddress outside an array.  In C, it is valid to compute the address justpast an object, e.g., @code{&a[N]} where @code{a} has @code{N} elements,so long as you do not dereference the resulting pointer.  But it is notvalid to compute the address just before an object, e.g., @code{&a[-1]};nor is it valid to compute two past the end, e.g., @code{&a[N+1]}.  Onmost platforms @code{&a[-1] < &a[0] && &a[N] < &a[N+1]}, but this is notreliable in general, and it is usually easy enough to avoid thepotential portability problem, e.g., by allocating an extra unused arrayelement at the start or end.@uref{http://@/valgrind.org/, Valgrind} can catch many overruns.GCCusers might also consider using the @option{-fmudflap} option to catchoverruns.Buffer overruns are usually caused by off-by-one errors, but there aremore subtle ways to get them.Using @code{int} values to index into an array or compute array sizescauses problems on typical 64-bit hosts where an array index mightbe @math{2^{31}} or larger.  Index values of type @code{size_t} avoid thisproblem, but cannot be negative.  Index values of type @code{ptrdiff_t}are signed, and are wide enough in practice.If you add or multiply two numbers to calculate an array size, e.g.,@code{malloc (x * sizeof y + z)}, havoc ensues if the addition ormultiplication overflows.Many implementations of the @code{alloca} function silently misbehaveand can generate buffer overflows if given sizes that are too large.The size limits are implementation dependent, but are at least 4000bytes on all platforms that we know about.The standard functions @code{asctime}, @code{asctime_r}, @code{ctime},@code{ctime_r}, and @code{gets} are prone to buffer overflows, andportable code should not use them unless the inputs are known to bewithin certain limits.  The time-related functions can overflow theirbuffers if given timestamps out of range (e.g., a year less than -999or greater than 9999).  Time-related buffer overflows cannot happen withrecent-enough versions of the GNU C library, but are possiblewith otherimplementations.  The @code{gets} function is the worst, since it almostinvariably overflows its buffer when presented with an input line largerthan the buffer.@node Volatile Objects@section Volatile Objects@cindex volatile objectsThe keyword @code{volatile} is often misunderstood in portable code.Its use inhibits some memory-access optimizations, but programmers oftenwish that it had a different meaning than it actually does.@code{volatile} was designed for code that accesses special objects likememory-mapped device registers whose contents spontaneously change.Such code is inherently low-level, and it is difficult to specifyportably what @code{volatile} means in these cases.  The C standardsays, ``What constitutes an access to an object that hasvolatile-qualified type is implementation-defined,'' so in theory eachimplementation is supposed to fill in the gap by documenting what@code{volatile} means for that implementation.  In practice, though,this documentation is usually absent or incomplete.One area of confusion is the distinction between objects defined withvolatile types, and volatile lvalues.  From the C standard's point ofview, an object defined with a volatile type has externally visiblebehavior.  You can think of such objects as having little oscilloscopeprobes attached to them, so that the user can observe some properties ofaccesses to them, just as the user can observe data written to outputfiles.  However, the standard does not make it clear whether users canobserve accesses by volatile lvalues to ordinary objects.  For example:@example/* Declare and access a volatile object.   Accesses to X are "visible" to users.  */static int volatile x;x = 1;/* Access two ordinary objects via a volatile lvalue.   It's not clear whether accesses to *P are "visible".  */int y;int *z = malloc (sizeof (int));int volatile *p;p = &y;*p = 1;p = z;*p = 1;@end exampleProgrammers often wish that @code{volatile} meant ``Perform the memoryaccess here and now, without merging several memory accesses, withoutchanging the memory word size, and without reordering.''  But the Cstandard does not require this.  For objects defined with a volatiletype, accesses must be done before the next sequence point; butotherwise merging, reordering, and word-size change is allowed.  Worse,it is not clear from the standard whether volatile lvalues provide moreguarantees in general than nonvolatile lvalues, if the underlyingobjects are ordinary.Even when accessing objects defined with a volatile type,the C standard allows onlyextremely limited signal handlers: the behavior is undefined if a signalhandler reads any nonlocal object, or writes to any nonlocal objectwhose type is not @code{sig_atomic_t volatile}, or calls any standardlibrary function other than @code{abort}, @code{signal}, and (if C99)@code{_Exit}.  Hence C compilers need not worry about a signal handlerdisturbing ordinary computation, unless the computation accesses a@code{sig_atomic_t volatile} lvalue that is not a local variable.(There is an obscure exception for accesses via a pointer to a volatilecharacter, since it may point into part of a @code{sig_atomic_tvolatile} object.)  Posixadds to the list of library functions callable from a portable signalhandler, but otherwise is like the C standard in this area.Some C implementations allow memory-access optimizations within eachtranslation unit, such that actual behavior agrees with the behaviorrequired by the standard only when calling a function in some othertranslation unit, and a signal handler acts like it was called from adifferent translation unit.  The C standard hints that in theseimplementations, objects referred to by signal handlers ``would requireexplicit specification of @code{volatile} storage, as well as otherimplementation-defined restrictions.''  But unfortunately even for thisspecial case these other restrictions are often not documented well.@xref{Volatiles, , When is a Volatile Object Accessed?, gcc, Using theGNU Compiler Collection (GCC)}, for somerestrictions imposed by GCC.  @xref{Defining Handlers, ,Defining Signal Handlers, libc, The GNU C Library}, for somerestrictions imposed by the GNU C library.  Restrictionsdiffer on other platforms.If possible, it is best to use a signal handler that fits within thelimits imposed by the C and Posix standards.If this is not practical, you can try the following rules of thumb.  Asignal handler should access only volatile lvalues, preferably lvaluesthat refer to objects defined with a volatile type, and should notassume that the accessed objects have an internally consistent stateif they are larger than a machine word.  Furthermore, installersshould employ compilers and compiler options that are commonly usedfor building operating system kernels, because kernels often need morefrom @code{volatile} than the C Standard requires, and installers whocompile an application in a similar environment can sometimes benefitfrom the extra constraints imposed by kernels on compilers.Admittedly we are handwaving somewhat here, as there are fewguarantees in this area; the rules of thumb may help to fix some bugsbut there is a good chance that they will not fix them all.For @code{volatile}, C++ has the same problems that C does.Multithreaded applications have even more problems with @code{volatile},but they are beyond the scope of this section.The bottom line is that using @code{volatile} typically hurtsperformance but should not hurt correctness.  In some cases its usedoes help correctness, but these cases are often so poorly understoodthat all too often adding @code{volatile} to a data structure merelyalleviates some symptoms of a bug while not fixing the bug in general.@node Floating Point Portability@section Floating Point Portability@cindex floating pointAlmost all modern systems use IEEE-754 floating point, and it is safe toassume IEEE-754 in most portable code these days.  For more information,please see David Goldberg's classic paper@uref{http://@/www.validlab.com/@/goldberg/@/paper.pdf, What Every ComputerScientist Should Know About Floating-Point Arithmetic}.@node Exiting Portably@section Exiting Portably@cindex exiting portablyA C or C++ program can exit with status @var{N} by returning@var{N} from the @code{main} function.  Portable programs are supposedto exit either with status 0 or @code{EXIT_SUCCESS} to succeed, or withstatus @code{EXIT_FAILURE} to fail, but in practice it is portable tofail by exiting with status 1, and test programs that assume Posix canfail by exiting with status values from 1 through 255.  Programs onSunOS 2.0 (1985) through 3.5.2 (1988) incorrectly exited with zerostatus when @code{main} returned nonzero, but ancient systems like theseare no longer of practical concern.A program can also exit with status @var{N} by passing @var{N} to the@code{exit} function, and a program can fail by calling the @code{abort}function.  If a program is specialized to just some platforms, it can failby calling functions specific to those platforms, e.g., @code{_exit}(Posix) and @code{_Exit} (C99).  However, like other functions, an exitfunction should be declared, typically by including a header.  Forexample, if a C program calls @code{exit}, it should include @file{stdlib.h}either directly or via the default includes (@pxref{Default Includes}).A program can fail due to undefined behavior such as dereferencing a nullpointer, but this is not recommended as undefined behavior allows animplementation to do whatever it pleases and this includes exitingsuccessfully.@c ================================================== Manual Configuration@node Manual Configuration@chapter Manual ConfigurationA few kinds of features can't be guessed automatically by running testprograms.  For example, the details of the object-file format, orspecial options that need to be passed to the compiler or linker.  Youcan check for such features using ad-hoc means, such as having@command{configure} check the output of the @code{uname} program, orlooking for libraries that are unique to particular systems.  However,Autoconf provides a uniform method for handling unguessable features.@menu* Specifying Target Triplets::  Specifying target triplets* Canonicalizing::              Getting the canonical system type* Using System Type::           What to do with the system type@end menu@node Specifying Target Triplets@section Specifying target triplets@cindex System type@cindex Target triplet@c This node used to be named Specifying Names.  The @anchor allows old@c links to still work.@anchor{Specifying Names}Autoconf-generated@command{configure} scripts can make decisions based on a canonical namefor the system type, or @dfn{target triplet}, which has the form:@samp{@var{cpu}-@var{vendor}-@var{os}}, where @var{os} can be@samp{@var{system}} or @samp{@var{kernel}-@var{system}}@command{configure} can usually guess the canonical name for the type ofsystem it's running on.  To do so it runs a script called@command{config.guess}, which infers the name using the @code{uname}command or symbols predefined by the C preprocessor.Alternately, the user can specify the system type with command linearguments to @command{configure} (@pxref{System Type}.  Doing so isnecessary whencross-compiling.  In the most complex case of cross-compiling, threesystem types are involved.  The options to specify them are:@table @option@item --build=@var{build-type}the type of system on which the package is being configured andcompiled.  It defaults to the result of running @command{config.guess}.Specifying a @var{build-type} that differs from @var{host-type} enablescross-compilation mode.@item --host=@var{host-type}the type of system on which the package runs.  By default it is thesame as the build machine.  Specifying a @var{host-type} that differsfrom @var{build-type}, when @var{build-type} was also explicitlyspecified, enables cross-compilation mode.@item --target=@var{target-type}the type of system for which any compiler tools in the packageproduce code (rarely needed).  By default, it is the same as host.@end tableIf you mean to override the result of @command{config.guess}, use@option{--build}, not @option{--host}, since the latter enablescross-compilation.  For historical reasons,whenever you specify @option{--host},be sure to specify @option{--build} too; this will be fixed in thefuture.  So, to enter cross-compilation mode, use a command like this@example./configure --build=i686-pc-linux-gnu --host=m68k-coff@end example@noindentNote that if you do not specify @option{--host}, @command{configure}fails if it can't run the code generated by the specified compiler.  Forexample, configuring as follows fails:@example./configure CC=m68k-coff-gcc@end exampleWhen cross-compiling, @command{configure} will warn about any tools(compilers, linkers, assemblers) whose name is not prefixed with thehost type.  This is an aid to users performing cross-compilation.Continuing the example above, if a cross-compiler named @command{cc} isused with a native @command{pkg-config}, then libraries found by@command{pkg-config} will likely cause subtle build failures; but usingthe names @command{m68k-coff-cc} and @command{m68k-coff-pkg-config}avoids any confusion.  Avoiding the warning is as simple as creating thecorrect symlinks naming the cross tools.@cindex @command{config.sub}@command{configure} recognizes short aliases for many system types; forexample, @samp{decstation} can be used instead of@samp{mips-dec-ultrix4.2}.  @command{configure} runs a script called@command{config.sub} to canonicalize system type aliases.This section deliberately omits the description of the obsoleteinterface; see @ref{Hosts and Cross-Compilation}.@node Canonicalizing@section Getting the Canonical System Type@cindex System type@cindex Canonical system typeThe following macros make the system type available to @command{configure}scripts.@ovindex build_alias@ovindex host_alias@ovindex target_aliasThe variables @samp{build_alias}, @samp{host_alias}, and@samp{target_alias} are always exactly the arguments of @option{--build},@option{--host}, and @option{--target}; in particular, they are left emptyif the user did not use them, even if the corresponding@code{AC_CANONICAL} macro was run.  Any configure script may use thesevariables anywhere.  These are the variables that should be used when ininteraction with the user.If you need to recognize some special environments based on their systemtype, run the following macros to get canonical system names.  Thesevariables are not set before the macro call.If you use these macros, you must distribute @command{config.guess} and@command{config.sub} along with your source code.  @xref{Output}, forinformation about the @code{AC_CONFIG_AUX_DIR} macro which you can useto control in which directory @command{configure} looks for those scripts.@defmac AC_CANONICAL_BUILD@acindex{CANONICAL_BUILD}@ovindex build@ovindex build_cpu@ovindex build_vendor@ovindex build_osCompute the canonical build-system type variable, @code{build}, and itsthree individual parts @code{build_cpu}, @code{build_vendor}, and@code{build_os}.If @option{--build} was specified, then @code{build} is thecanonicalization of @code{build_alias} by @command{config.sub},otherwise it is determined by the shell script @command{config.guess}.@end defmac@defmac AC_CANONICAL_HOST@acindex{CANONICAL_HOST}@ovindex host@ovindex host_cpu@ovindex host_vendor@ovindex host_osCompute the canonical host-system type variable, @code{host}, and itsthree individual parts @code{host_cpu}, @code{host_vendor}, and@code{host_os}.If @option{--host} was specified, then @code{host} is thecanonicalization of @code{host_alias} by @command{config.sub},otherwise it defaults to @code{build}.@end defmac@defmac AC_CANONICAL_TARGET@acindex{CANONICAL_TARGET}@ovindex target@ovindex target_cpu@ovindex target_vendor@ovindex target_osCompute the canonical target-system type variable, @code{target}, and itsthree individual parts @code{target_cpu}, @code{target_vendor}, and@code{target_os}.If @option{--target} was specified, then @code{target} is thecanonicalization of @code{target_alias} by @command{config.sub},otherwise it defaults to @code{host}.@end defmacNote that there can be artifacts due to the backward compatibilitycode.  @xref{Hosts and Cross-Compilation}, for more.@node Using System Type@section Using the System TypeIn @file{configure.ac} the system type is generally used by one or more@code{case} statements to select system-specifics.  Shell wildcards canbe used to match a group of system types.For example, an extra assembler code object file could be chosen, givingaccess to a CPU cycle counter register.  @code{$(CYCLE_OBJ)} in thefollowing would be used in a makefile to add the object to aprogram or library.@exampleAS_CASE([$host],  [alpha*-*-*], [CYCLE_OBJ=rpcc.o],  [i?86-*-*],   [CYCLE_OBJ=rdtsc.o],  [CYCLE_OBJ=""])AC_SUBST([CYCLE_OBJ])@end example@code{AC_CONFIG_LINKS} (@pxref{Configuration Links}) is another good wayto select variant source files, for example optimized code for someCPUs.  The configured CPU type doesn't always indicate exact CPU types,so some runtime capability checks may be necessary too.@examplecase $host in  alpha*-*-*)   AC_CONFIG_LINKS([dither.c:alpha/dither.c]) ;;  powerpc*-*-*) AC_CONFIG_LINKS([dither.c:powerpc/dither.c]) ;;  *-*-*)        AC_CONFIG_LINKS([dither.c:generic/dither.c]) ;;esac@end exampleThe host system type can also be used to find cross-compilation toolswith @code{AC_CHECK_TOOL} (@pxref{Generic Programs}).The above examples all show @samp{$host}, since this is where the codeis going to run.  Only rarely is it necessary to test @samp{$build}(which is where the build is being done).Whenever you're tempted to use @samp{$host} it's worth consideringwhether some sort of probe would be better.  New system types come alongperiodically or previously missing features are added.  Well-writtenprobes can adapt themselves to such things, but hard-coded lists ofnames can't.  Here are some guidelines,@itemize @bullet@itemAvailability of libraries and library functions should always be checkedby probing.@itemVariant behavior of system calls is best identified with runtime testsif possible, but bug workarounds or obscure difficulties might have tobe driven from @samp{$host}.@itemAssembler code is inevitably highly CPU-specific and is best selectedaccording to @samp{$host_cpu}.@itemAssembler variations like underscore prefix on globals or ELF versusCOFF type directives are however best determined by probing, perhapseven examining the compiler output.@end itemize@samp{$target} is for use by a package creating a compiler or similar.For ordinary packages it's meaningless and should not be used.  Itindicates what the created compiler should generate code for, if it cancross-compile.  @samp{$target} generally selects various hard-coded CPUand system conventions, since usually the compiler or tools underconstruction themselves determine how the target works.@c ===================================================== Site Configuration.@node Site Configuration@chapter Site Configuration@command{configure} scripts support several kinds of local configurationdecisions.  There are ways for users to specify where external softwarepackages are, include or exclude optional features, install programsunder modified names, and set default values for @command{configure}options.@menu* Help Formatting::             Customizing @samp{configure --help}* External Software::           Working with other optional software* Package Options::             Selecting optional features* Pretty Help Strings::         Formatting help string* Option Checking::             Controlling checking of @command{configure} options* Site Details::                Configuring site details* Transforming Names::          Changing program names when installing* Site Defaults::               Giving @command{configure} local defaults@end menu@node Help Formatting@section Controlling Help OutputUsers consult @samp{configure --help} to learn of configurationdecisions specific to your package.  By default, @command{configure}breaks this output into sections for each type of option; within eachsection, help strings appear in the order @file{configure.ac} definesthem:@exampleOptional Features:  @dots{}  --enable-bar            include barOptional Packages:  @dots{}  --with-foo              use foo@end example@defmac AC_PRESERVE_HELP_ORDER@acindex{PRESERVE_HELP_ORDER}Request an alternate @option{--help} format, in which options of alltypes appear together, in the order defined.  Call this macro before any@code{AC_ARG_ENABLE} or @code{AC_ARG_WITH}.@exampleOptional Features and Packages:  @dots{}  --enable-bar            include bar  --with-foo              use foo@end example@end defmac@node External Software@section Working With External Software@cindex External softwareSome packages require, or can optionally use, other software packagesthat are already installed.  The user can give @command{configure}command line options to specify which such external software to use.The options have one of these forms:@c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something@c awful.@example--with-@var{package}@r{[}=@var{arg}@r{]}--without-@var{package}@end exampleFor example, @option{--with-gnu-ld} means work with the GNU linkerinstead of some other linker.  @option{--with-x} means work with The XWindow System.The user can give an argument by following the package name with@samp{=} and the argument.  Giving an argument of @samp{no} is forpackages that are used by default; it says to @emph{not} use thepackage.  An argument that is neither @samp{yes} nor @samp{no} couldinclude a name or number of a version of the other package, to specifymore precisely which other package this program is supposed to workwith.  If no argument is given, it defaults to @samp{yes}.@option{--without-@var{package}} is equivalent to@option{--with-@var{package}=no}.Normally @command{configure} scripts complain about@option{--with-@var{package}} options that they do not support.@xref{Option Checking}, for details, and for how to override thedefaults.For each external software package that may be used, @file{configure.ac}should call @code{AC_ARG_WITH} to detect whether the @command{configure}user asked to use it.  Whether each package is used or not by default,and which arguments are valid, is up to you.@anchor{AC_ARG_WITH}@defmac AC_ARG_WITH (@var{package}, @var{help-string}, @  @ovar{action-if-given}, @ovar{action-if-not-given})@acindex{ARG_WITH}If the user gave @command{configure} the option @option{--with-@var{package}}or @option{--without-@var{package}}, run shell commands@var{action-if-given}.  If neither option was given, run shell commands@var{action-if-not-given}.  The name @var{package} indicates anothersoftware package that this program should work with.  It should consistonly of alphanumeric characters, dashes, plus signs, and dots.The option's argument is available to the shell commands@var{action-if-given} in the shell variable @code{withval}, which isactually just the value of the shell variable named@code{with_@var{package}}, with any non-alphanumeric characters in@var{package} changed into @samp{_}.  You may use that variable instead,if you wish.The argument @var{help-string} is a description of the option thatlooks like this:@example  --with-readline         support fancy command line editing@end example@noindent@var{help-string} may be more than one line long, if more detail isneeded.  Just make sure the columns line up in @samp{configure--help}.  Avoid tabs in the help string.  The easiest way to provide theproper leading whitespace is to format your @var{help-string} with the macro@code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).The following example shows how to use the @code{AC_ARG_WITH} macro ina common situation.  You want to let the user decide whether to enablesupport for an external library (e.g., the readline library); if the userspecified neither @option{--with-readline} nor @option{--without-readline},you want to enable support for readline only if the library is availableon the system.@c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.@exampleAC_ARG_WITH([readline],  [AS_HELP_STRING([--with-readline],    [support fancy command line editing @@<:@@default=check@@:>@@])],  [],  [with_readline=check])LIBREADLINE=AS_IF([test "x$with_readline" != xno],  [AC_CHECK_LIB([readline], [main],    [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])     AC_DEFINE([HAVE_LIBREADLINE], [1],               [Define if you have libreadline])    ],    [if test "x$with_readline" != xcheck; then       AC_MSG_FAILURE(         [--with-readline was given, but test for readline failed])     fi    ], -lncurses)])@end exampleThe next example shows how to use @code{AC_ARG_WITH} to give the user thepossibility to enable support for the readline library, in case it is stillexperimental and not well tested, and is therefore disabled by default.@c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.@exampleAC_ARG_WITH([readline],  [AS_HELP_STRING([--with-readline],    [enable experimental support for readline])],  [],  [with_readline=no])LIBREADLINE=AS_IF([test "x$with_readline" != xno],  [AC_CHECK_LIB([readline], [main],    [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])     AC_DEFINE([HAVE_LIBREADLINE], [1],               [Define if you have libreadline])    ],    [AC_MSG_FAILURE(       [--with-readline was given, but test for readline failed])],    [-lncurses])])@end exampleThe last example shows how to use @code{AC_ARG_WITH} to give the user thepossibility to disable support for the readline library, given that it isan important feature and that it should be enabled by default.@c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.@exampleAC_ARG_WITH([readline],  [AS_HELP_STRING([--without-readline],    [disable support for readline])],  [],  [with_readline=yes])LIBREADLINE=AS_IF([test "x$with_readline" != xno],  [AC_CHECK_LIB([readline], [main],    [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])     AC_DEFINE([HAVE_LIBREADLINE], [1],               [Define if you have libreadline])    ],    [AC_MSG_FAILURE(       [readline test failed (--without-readline to disable)])],    [-lncurses])])@end exampleThese three examples can be easily adapted to the case where@code{AC_ARG_ENABLE} should be preferred to @code{AC_ARG_WITH} (see@ref{Package Options}).@end defmac@node Package Options@section Choosing Package Options@cindex Package options@cindex Options, packageIf a software package has optional compile-time features, the user cangive @command{configure} command line options to specify whether tocompile them.  The options have one of these forms:@c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something@c awful.@example--enable-@var{feature}@r{[}=@var{arg}@r{]}--disable-@var{feature}@end exampleThese options allow users to choose which optional features to build andinstall.  @option{--enable-@var{feature}} options should never make afeature behave differently or cause one feature to replace another.They should only cause parts of the program to be built rather than leftout.The user can give an argument by following the feature name with@samp{=} and the argument.  Giving an argument of @samp{no} requeststhat the feature @emph{not} be made available.  A feature with anargument looks like @option{--enable-debug=stabs}.  If no argument isgiven, it defaults to @samp{yes}.  @option{--disable-@var{feature}} isequivalent to @option{--enable-@var{feature}=no}.Normally @command{configure} scripts complain about@option{--enable-@var{package}} options that they do not support.@xref{Option Checking}, for details, and for how to override thedefaults.For each optional feature, @file{configure.ac} should call@code{AC_ARG_ENABLE} to detect whether the @command{configure} user askedto include it.  Whether each feature is included or not by default, andwhich arguments are valid, is up to you.@anchor{AC_ARG_ENABLE}@defmac AC_ARG_ENABLE (@var{feature}, @var{help-string}, @  @ovar{action-if-given}, @ovar{action-if-not-given})@acindex{ARG_ENABLE}If the user gave @command{configure} the option@option{--enable-@var{feature}} or @option{--disable-@var{feature}}, runshell commands @var{action-if-given}.  If neither option was given, runshell commands @var{action-if-not-given}.  The name @var{feature}indicates an optional user-level facility.  It should consist only ofalphanumeric characters, dashes, plus signs, and dots.The option's argument is available to the shell commands@var{action-if-given} in the shell variable @code{enableval}, which isactually just the value of the shell variable named@code{enable_@var{feature}}, with any non-alphanumeric characters in@var{feature} changed into @samp{_}.  You may use that variable instead,if you wish.  The @var{help-string} argument is like that of@code{AC_ARG_WITH} (@pxref{External Software}).You should format your @var{help-string} with the macro@code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).See the examples suggested with the definition of @code{AC_ARG_WITH}(@pxref{External Software}) to get an idea of possible applications of@code{AC_ARG_ENABLE}.@end defmac@node Pretty Help Strings@section Making Your Help Strings Look Pretty@cindex Help stringsProperly formatting the @samp{help strings} which are used in@code{AC_ARG_WITH} (@pxref{External Software}) and @code{AC_ARG_ENABLE}(@pxref{Package Options}) can be challenging.  Specifically, you wantyour own @samp{help strings} to line up in the appropriate columns of@samp{configure --help} just like the standard Autoconf @samp{helpstrings} do.  This is the purpose of the @code{AS_HELP_STRING} macro.@anchor{AS_HELP_STRING}@defmac AS_HELP_STRING (@var{left-hand-side}, @var{right-hand-side} @  @dvar{indent-column, 26}, @dvar{wrap-column, 79})@asindex{HELP_STRING}Expands into a help string that looks pretty when the user executes@samp{configure --help}.  It is typically used in @code{AC_ARG_WITH}(@pxref{External Software}) or @code{AC_ARG_ENABLE} (@pxref{PackageOptions}).  The following example makes this clearer.@exampleAC_ARG_WITH([foo],  [AS_HELP_STRING([--with-foo],     [use foo (default is no)])],  [use_foo=$withval],  [use_foo=no])@end exampleThen the last few lines of @samp{configure --help} appear likethis:@example--enable and --with options recognized:  --with-foo              use foo (default is no)@end exampleMacro expansion is performed on the first argument.  However, the secondargument of @code{AS_HELP_STRING} is treated as a whitespace separatedlist of text to be reformatted, and is not subject to macro expansion.Since it is not expanded, it should not be double quoted.@xref{Autoconf Language}, for a more detailed explanation.The @code{AS_HELP_STRING} macro is particularly helpful when the@var{left-hand-side} and/or @var{right-hand-side} are composed of macroarguments, as shown in the following example.  Be aware that@var{left-hand-side} may not expand to unbalanced quotes,although quadrigraphs can be used.@exampleAC_DEFUN([MY_ARG_WITH],  [AC_ARG_WITH(m4_translit([[$1]], [_], [-]),     [AS_HELP_STRING([--with-m4_translit([$1], [_], [-])],                     [use $1 (default is $2)])],     [use_[]$1=$withval],     [use_[]$1=$2])])MY_ARG_WITH([a_b], [no])@end example@noindentHere, the last few lines of @samp{configure --help} will include:@example--enable and --with options recognized:  --with-a-b              use a_b (default is no)@end exampleThe parameters @var{indent-column} and @var{wrap-column} were introducedin Autoconf 2.62.  Generally, they should not be specified; they existfor fine-tuning of the wrapping.@exampleAS_HELP_STRING([--option], [description of option])@result{}  --option                description of optionAS_HELP_STRING([--option], [description of option], [15], [30])@result{}  --option     description of@result{}               option@end example@end defmac@node Option Checking@section Controlling Checking of @command{configure} Options@cindex Options, PackageThe @command{configure} script checks its command-line options against alist of known options, like @option{--help} or @option{--config-cache}.An unknown option ordinarily indicates a mistake by the user and@command{configure} halts with an error.  However, by default unknown@option{--with-@var{package}} and @option{--enable-@var{feature}}options elicit only a warning, to support configuring entire sourcetrees.Source trees often contain multiple packages with a top-level@command{configure} script that uses the @code{AC_CONFIG_SUBDIRS} macro(@pxref{Subdirectories}).  Because the packages generally supportdifferent @option{--with-@var{package}} and@option{--enable-@var{feature}} options, the GNU CodingStandards say they must accept unrecognized options without halting.Even a warning message is undesirable here, so @code{AC_CONFIG_SUBDIRS}automatically disables the warnings.This default behavior may be modified in two ways.  First, the installercan invoke @code{configure --disable-option-checking} to disablethese warnings, or invoke @code{configure --enable-option-checking=fatal}options to turn them into fatal errors, respectively.  Second, themaintainer can use @code{AC_DISABLE_OPTION_CHECKING}.@defmac AC_DISABLE_OPTION_CHECKING@acindex{DISABLE_OPTION_CHECKING}By default, disable warnings related to any unrecognized@option{--with-@var{package}} or @option{--enable-@var{feature}}options.  This is implied by @code{AC_CONFIG_SUBDIRS}.The installer can override this behavior by passing@option{--enable-option-checking} (enable warnings) or@option{--enable-option-checking=fatal} (enable errors) to@command{configure}.@end defmac@node Site Details@section Configuring Site Details@cindex Site detailsSome software packages require complex site-specific information.  Someexamples are host names to use for certain services, company names, andemail addresses to contact.  Since some configuration scripts generatedby Metaconfig ask for such information interactively, people sometimeswonder how to get that information in Autoconf-generated configurationscripts, which aren't interactive.Such site configuration information should be put in a file that isedited @emph{only by users}, not by programs.  The location of the filecan either be based on the @code{prefix} variable, or be a standardlocation such as the user's home directory.  It could even be specifiedby an environment variable.  The programs should examine that file atruntime, rather than at compile time.  Runtime configuration is moreconvenient for users and makes the configuration process simpler thangetting the information while configuring.  @xref{Directory Variables, ,Variables for Installation Directories, standards, The GNU CodingStandards}, for more information on where to put data files.@node Transforming Names@section Transforming Program Names When Installing@cindex Transforming program names@cindex Program names, transformingAutoconf supports changing the names of programs when installing them.In order to use these transformations, @file{configure.ac} must call themacro @code{AC_ARG_PROGRAM}.@defmac AC_ARG_PROGRAM@acindex{ARG_PROGRAM}@ovindex program_transform_namePlace in output variable @code{program_transform_name} a sequence of@code{sed} commands for changing the names of installed programs.If any of the options described below are given to @command{configure},program names are transformed accordingly.  Otherwise, if@code{AC_CANONICAL_TARGET} has been called and a @option{--target} valueis given, the target type followed by a dash is used as a prefix.Otherwise, no program name transformation is done.@end defmac@menu* Transformation Options::      @command{configure} options to transform names* Transformation Examples::     Sample uses of transforming names* Transformation Rules::        Makefile uses of transforming names@end menu@node Transformation Options@subsection Transformation OptionsYou can specify name transformations by giving @command{configure} thesecommand line options:@table @option@item --program-prefix=@var{prefix}prepend @var{prefix} to the names;@item --program-suffix=@var{suffix}append @var{suffix} to the names;@item --program-transform-name=@var{expression}perform @code{sed} substitution @var{expression} on the names.@end table@node Transformation Examples@subsection Transformation ExamplesThese transformations are useful with programs that can be part of across-compilation development environment.  For example, across-assembler running on a Sun 4 configured with@option{--target=i960-vxworks} is normally installed as@file{i960-vxworks-as}, rather than @file{as}, which could be confusedwith a native Sun 4 assembler.You can force a program name to begin with @file{g}, if you don't wantGNU programs installed on your system to shadow other programs withthe same name.  For example, if you configure GNU @code{diff} with@option{--program-prefix=g}, then when you run @samp{make install} it isinstalled as @file{/usr/local/bin/gdiff}.As a more sophisticated example, you could use@example--program-transform-name='s/^/g/; s/^gg/g/; s/^gless/less/'@end example@noindentto prepend @samp{g} to most of the program names in a source tree,excepting those like @code{gdb} that already have one and those like@code{less} and @code{lesskey} that aren't GNU programs.  (That isassuming that you have a source tree containing those programs that isset up to use this feature.)One way to install multiple versions of some programs simultaneously isto append a version number to the name of one or both.  For example, ifyou want to keep Autoconf version 1 around for awhile, you can configureAutoconf version 2 using @option{--program-suffix=2} to install theprograms as @file{/usr/local/bin/autoconf2},@file{/usr/local/bin/autoheader2}, etc.  Nevertheless, pay attentionthat only the binaries are renamed, therefore you'd have problems withthe library files which might overlap.@node Transformation Rules@subsection Transformation RulesHere is how to use the variable @code{program_transform_name} in a@file{Makefile.in}:@examplePROGRAMS = cp ls rmtransform = @@program_transform_name@@install:        for p in $(PROGRAMS); do \          $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p | \                                              sed '$(transform)'`; \        doneuninstall:        for p in $(PROGRAMS); do \          rm -f $(DESTDIR)$(bindir)/`echo $$p | sed '$(transform)'`; \@c $$ restore font-lock        done@end exampleIt is guaranteed that @code{program_transform_name} is never empty, andthat there are no useless separators.  Therefore you may safely embed@code{program_transform_name} within a sed program using @samp{;}:@exampletransform = @@program_transform_name@@transform_exe = s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/@end exampleWhether to do the transformations on documentation files (Texinfo or@code{man}) is a tricky question; there seems to be no perfect answer,due to the several reasons for name transforming.  Documentation is notusually particular to a specific architecture, and Texinfo files do notconflict with system documentation.  But they might conflict withearlier versions of the same files, and @code{man} pages sometimes doconflict with system documentation.  As a compromise, it is probablybest to do name transformations on @code{man} pages but not on Texinfomanuals.@node Site Defaults@section Setting Site Defaults@cindex Site defaults@cindex config.siteAutoconf-generated @command{configure} scripts allow your site to providedefault values for some configuration values.  You do this by creatingsite- and system-wide initialization files.@evindex CONFIG_SITEIf the environment variable @code{CONFIG_SITE} is set, @command{configure}uses its value as the name of a shell script to read; it is recommendedthat this be an absolute file name.  Otherwise, itreads the shell script @file{@var{prefix}/share/config.site} if it exists,then @file{@var{prefix}/etc/config.site} if it exists.  Thus,settings in machine-specific files override those in machine-independentones in case of conflict.Site files can be arbitrary shell scripts, but only certain kinds ofcode are really appropriate to be in them.  Because @command{configure}reads any cache file after it has read any site files, a site file candefine a default cache file to be shared between all Autoconf-generated@command{configure} scripts run on that system (@pxref{Cache Files}).  Ifyou set a default cache file in a site file, it is a good idea to alsoset the output variable @code{CC} in that site file, because the cachefile is only valid for a particular compiler, but many systems haveseveral available.You can examine or override the value set by a command line option to@command{configure} in a site file; options set shell variables that havethe same names as the options, with any dashes turned into underscores.The exceptions are that @option{--without-} and @option{--disable-} optionsare like giving the corresponding @option{--with-} or @option{--enable-}option and the value @samp{no}.  Thus, @option{--cache-file=localcache}sets the variable @code{cache_file} to the value @samp{localcache};@option{--enable-warnings=no} or @option{--disable-warnings} sets the variable@code{enable_warnings} to the value @samp{no}; @option{--prefix=/usr} sets thevariable @code{prefix} to the value @samp{/usr}; etc.Site files are also good places to set default values for other outputvariables, such as @code{CFLAGS}, if you need to give them non-defaultvalues: anything you would normally do, repetitively, on the commandline.  If you use non-default values for @var{prefix} or@var{exec_prefix} (wherever you locate the site file), you can set themin the site file if you specify it with the @code{CONFIG_SITE}environment variable.You can set some cache values in the site file itself.  Doing this isuseful if you are cross-compiling, where it is impossible to check featuresthat require running a test program.  You could ``prime the cache'' bysetting those values correctly for that system in@file{@var{prefix}/etc/config.site}.  To find out the names of the cachevariables you need to set, see the documentation of the respectiveAutoconf macro.  If the variables or their semantics are undocumented,you may need to look for shell variables with @samp{_cv_} in their namesin the affected @command{configure} scripts, or in the Autoconf M4source code for those macros; but in that case, their name or semanticsmay change in a future Autoconf version.The cache file is careful to not override any variables set in the sitefiles.  Similarly, you should not override command-line options in thesite files.  Your code should check that variables such as @code{prefix}and @code{cache_file} have their default values (as set near the top of@command{configure}) before changing them.Here is a sample file @file{/usr/share/local/@/gnu/share/@/config.site}.  Thecommand @samp{configure --prefix=/usr/share/local/gnu} would read thisfile (if @code{CONFIG_SITE} is not set to a different file).@example# /usr/share/local/gnu/share/config.site for configure## Change some defaults.test "$prefix" = NONE && prefix=/usr/share/local/gnutest "$exec_prefix" = NONE && exec_prefix=/usr/local/gnutest "$sharedstatedir" = '$@{prefix@}/com' && sharedstatedir=/vartest "$localstatedir" = '$@{prefix@}/var' && localstatedir=/var# Give Autoconf 2.x generated configure scripts a shared default# cache file for feature test results, architecture-specific.if test "$cache_file" = /dev/null; then  cache_file="$prefix/var/config.cache"  # A cache file is only valid for one C compiler.  CC=gccfi@end example@c Leave this use of ``File system'' rendered as one word, but@c slightly obfuscated so as not to trigger the syntax-check prohibition.@cindex File@/system Hierarchy Standard@cindex FHSAnother use of @file{config.site} is for priming the directory variables@c ``File system'', but slightly obfuscated, as above.in a manner consistent with the File@/system Hierarchy Standard(FHS).  Once the following file is installed at@file{/usr/share/config.site}, a user can execute simply@code{./configure --prefix=/usr} to get all the directories chosen inthe locations recommended by FHS.@example# /usr/share/config.site for FHS defaults when installing below /usr,# and the respective settings were not changed on the command line.if test "$prefix" = /usr; then  test "$sysconfdir" = '$@{prefix@}/etc' && sysconfdir=/etc  test "$sharedstatedir" = '$@{prefix@}/com' && sharedstatedir=/var  test "$localstatedir" = '$@{prefix@}/var' && localstatedir=/varfi@end example@cindex @file{lib64}@cindex 64-bit librariesLikewise, on platforms where 64-bit libraries are built by default, theninstalled in @file{/usr/local/@/lib64} instead of @file{/usr/local/@/lib},it is appropriate to install @file{/usr/local/@/share/config.site}:@example# /usr/local/share/config.site for platforms that prefer# the directory /usr/local/lib64 over /usr/local/lib.test "$libdir" = '$@{exec_prefix@}/lib' && libdir='$@{exec_prefix@}/lib64'@end example@c ============================================== Running configure Scripts.@node Running configure Scripts@chapter Running @command{configure} Scripts@cindex @command{configure}Below are instructions on how to configure a package that uses a@command{configure} script, suitable for inclusion as an @file{INSTALL}file in the package.  A plain-text version of @file{INSTALL} which youmay use comes with Autoconf.@menu* Basic Installation::          Instructions for typical cases* Compilers and Options::       Selecting compilers and optimization* Multiple Architectures::      Compiling for multiple architectures at once* Installation Names::          Installing in different directories* Optional Features::           Selecting optional features* Particular Systems::          Particular systems* System Type::                 Specifying the system type* Sharing Defaults::            Setting site-wide defaults for @command{configure}* Defining Variables::          Specifying the compiler etc.* configure Invocation::        Changing how @command{configure} runs@end menu@set autoconf@include install.texi@c ============================================== config.status Invocation@node config.status Invocation@chapter config.status Invocation@cindex @command{config.status}The @command{configure} script creates a file named @file{config.status},which actually configures, @dfn{instantiates}, the template files.  Italso records the configuration options that were specified when thepackage was last configured in case reconfiguring is needed.Synopsis:@example./config.status @ovar{option}@dots{} @ovar{tag}@dots{}@end exampleIt configures each @var{tag}; if none are specified, all the templatesare instantiated.  A @var{tag} refers to a file or other tag associatedwith a configuration action, as specified by an @code{AC_CONFIG_@var{ITEMS}}macro (@pxref{Configuration Actions}).  The files must be specifiedwithout their dependencies, as in@example./config.status foobar@end example@noindentnot@example./config.status foobar:foo.in:bar.in@end exampleThe supported options are:@table @option@item --help@itemx -hPrint a summary of the command line options, the list of the templatefiles, and exit.@item --version@itemx -VPrint the version number of Autoconf and the configuration settings,and exit.@item --configPrint the configuration settings in reusable way, quoted for the shell,and exit.  For example, for a debugging build that otherwise reuses theconfiguration from a different build directory @var{build-dir} of apackage in @var{src-dir}, you could use the following:@exampleargs=`@var{build-dir}/config.status --config`eval @var{src-dir}/configure "$args" CFLAGS=-g --srcdir=@var{src-dir}@end example@noindentNote that it may be necessary to override a @option{--srcdir} settingthat was saved in the configuration, if the arguments are used in adifferent build directory.@item --silent@itemx --quiet@itemx -qDo not print progress messages.@item --debug@itemx -dDon't remove the temporary files.@item --file=@var{file}[:@var{template}]Require that @var{file} be instantiated as if@samp{AC_CONFIG_FILES(@var{file}:@var{template})} was used.  Both@var{file} and @var{template} may be @samp{-} in which case the standardoutput and/or standard input, respectively, is used.  If a@var{template} file name is relative, it is first looked for in the buildtree, and then in the source tree.  @xref{Configuration Actions}, formore details.This option and the following ones provide one way for separatelydistributed packages to share the values computed by @command{configure}.Doing so can be useful if some of the packages need a superset of thefeatures that one of them, perhaps a common library, does.  Theseoptions allow a @file{config.status} file to create files other than theones that its @file{configure.ac} specifies, so it can be used for adifferent package, or for extracting a subset of values.  For example,@exampleecho '@@CC@@' | ./config.status --file=-@end example@noindentprovides the value of @code{@@CC@@} on standard output.@item --header=@var{file}[:@var{template}]Same as @option{--file} above, but with @samp{AC_CONFIG_HEADERS}.@item --recheckAsk @file{config.status} to update itself and exit (no instantiation).This option is useful if you change @command{configure}, so that theresults of some tests might be different from the previous run.  The@option{--recheck} option reruns @command{configure} with the same argumentsyou used before, plus the @option{--no-create} option, which prevents@command{configure} from running @file{config.status} and creating@file{Makefile} and other files, and the @option{--no-recursion} option,which prevents @command{configure} from running other @command{configure}scripts in subdirectories.  (This is so other Make rules canrun @file{config.status} when it changes; @pxref{Automatic Remaking},for an example).@end table@file{config.status} checks several optional environment variables thatcan alter its behavior:@anchor{CONFIG_SHELL}@defvar CONFIG_SHELL@evindex CONFIG_SHELLThe shell with which to run @command{configure}.  It must beBourne-compatible, and the absolute name of the shell should be passed.The default is a shell that supports @code{LINENO} if available, and@file{/bin/sh} otherwise.@end defvar@defvar CONFIG_STATUS@evindex CONFIG_STATUSThe file name to use for the shell script that records theconfiguration.  The default is @file{./config.status}.  This variable isuseful when one package uses parts of another and the @command{configure}scripts shouldn't be merged because they are maintained separately.@end defvarYou can use @file{./config.status} in your makefiles.  For example, inthe dependencies given above (@pxref{Automatic Remaking}),@file{config.status} is run twice when @file{configure.ac} has changed.If that bothers you, you can make each run only regenerate the files forthat rule:@example@groupconfig.h: stamp-hstamp-h: config.h.in config.status        ./config.status config.h        echo > stamp-hMakefile: Makefile.in config.status        ./config.status Makefile@end group@end exampleThe calling convention of @file{config.status} has changed; see@ref{Obsolete config.status Use}, for details.@c =================================================== Obsolete Constructs@node Obsolete Constructs@chapter Obsolete Constructs@cindex Obsolete constructsAutoconf changes, and throughout the years some constructs have beenobsoleted.  Most of the changes involve the macros, but in some casesthe tools themselves, or even some concepts, are now consideredobsolete.You may completely skip this chapter if you are new to Autoconf.  Itsintention is mainly to help maintainers updating their packages byunderstanding how to move to more modern constructs.@menu* Obsolete config.status Use::  Obsolete convention for @command{config.status}* acconfig Header::             Additional entries in @file{config.h.in}* autoupdate Invocation::       Automatic update of @file{configure.ac}* Obsolete Macros::             Backward compatibility macros* Autoconf 1::                  Tips for upgrading your files* Autoconf 2.13::               Some fresher tips@end menu@node Obsolete config.status Use@section Obsolete @file{config.status} Invocation@file{config.status} now supports arguments to specify the files toinstantiate; see @ref{config.status Invocation}, for more details.Before, environment variables had to be used.@defvar CONFIG_COMMANDS@evindex CONFIG_COMMANDSThe tags of the commands to execute.  The default is the arguments givento @code{AC_OUTPUT} and @code{AC_CONFIG_COMMANDS} in@file{configure.ac}.@end defvar@defvar CONFIG_FILES@evindex CONFIG_FILESThe files in which to perform @samp{@@@var{variable}@@} substitutions.The default is the arguments given to @code{AC_OUTPUT} and@code{AC_CONFIG_FILES} in @file{configure.ac}.@end defvar@defvar CONFIG_HEADERS@evindex CONFIG_HEADERSThe files in which to substitute C @code{#define} statements.  Thedefault is the arguments given to @code{AC_CONFIG_HEADERS}; if thatmacro was not called, @file{config.status} ignores this variable.@end defvar@defvar CONFIG_LINKS@evindex CONFIG_LINKSThe symbolic links to establish.  The default is the arguments given to@code{AC_CONFIG_LINKS}; if that macro was not called,@file{config.status} ignores this variable.@end defvarIn @ref{config.status Invocation}, using this old interface, the examplewould be:@example@groupconfig.h: stamp-hstamp-h: config.h.in config.status        CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_FILES= \          CONFIG_HEADERS=config.h ./config.status        echo > stamp-hMakefile: Makefile.in config.status        CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_HEADERS= \          CONFIG_FILES=Makefile ./config.status@end group@end example@noindent(If @file{configure.ac} does not call @code{AC_CONFIG_HEADERS}, there isno need to set @code{CONFIG_HEADERS} in the @command{make} rules.  Equallyfor @code{CONFIG_COMMANDS}, etc.)@node acconfig Header@section @file{acconfig.h}@cindex @file{acconfig.h}@cindex @file{config.h.top}@cindex @file{config.h.bot}In order to produce @file{config.h.in}, @command{autoheader} needs tobuild or to find templates for each symbol.  Modern releases of Autoconfuse @code{AH_VERBATIM} and @code{AH_TEMPLATE} (@pxref{AutoheaderMacros}), but in older releases a file, @file{acconfig.h}, contained thelist of needed templates.  @command{autoheader} copied comments and@code{#define} and @code{#undef} statements from @file{acconfig.h} inthe current directory, if present.  This file used to be mandatory ifyou @code{AC_DEFINE} any additional symbols.Modern releases of Autoconf also provide @code{AH_TOP} and@code{AH_BOTTOM} if you need to prepend/append some information to@file{config.h.in}.  Ancient versions of Autoconf had a similar feature:if @file{./acconfig.h} contains the string @samp{@@TOP@@},@command{autoheader} copies the lines before the line containing@samp{@@TOP@@} into the top of the file that it generates.  Similarly,if @file{./acconfig.h} contains the string @samp{@@BOTTOM@@},@command{autoheader} copies the lines after that line to the end of thefile it generates.  Either or both of those strings may be omitted.  Aneven older alternate way to produce the same effect in ancient versionsof Autoconf is to create the files @file{@var{file}.top} (typically@file{config.h.top}) and/or @file{@var{file}.bot} in the currentdirectory.  If they exist, @command{autoheader} copies them to thebeginning and end, respectively, of its output.In former versions of Autoconf, the files used in preparing a softwarepackage for distribution were:@example@groupconfigure.ac --.   .------> autoconf* -----> configure               +---+[aclocal.m4] --+   `---.[acsite.m4] ---'       |                       +--> [autoheader*] -> [config.h.in][acconfig.h] ----.     |                 +-----'[config.h.top] --+[config.h.bot] --'@end group@end exampleUsing only the @code{AH_} macros, @file{configure.ac} should beself-contained, and should not depend upon @file{acconfig.h} etc.@node autoupdate Invocation@section Using @command{autoupdate} to Modernize @file{configure.ac}@cindex @command{autoupdate}The @command{autoupdate} program updates a @file{configure.ac} file thatcalls Autoconf macros by their old names to use the current macro names.In version 2 of Autoconf, most of the macros were renamed to use a moreuniform and descriptive naming scheme.  @xref{Macro Names}, for adescription of the new scheme.  Although the old names still work(@pxref{Obsolete Macros}, for a list of the old macros and the correspondingnew names), you can make your @file{configure.ac} files more readableand make it easier to use the current Autoconf documentation if youupdate them to use the new macro names.@evindex SIMPLE_BACKUP_SUFFIXIf given no arguments, @command{autoupdate} updates @file{configure.ac},backing up the original version with the suffix @file{~} (or the valueof the environment variable @code{SIMPLE_BACKUP_SUFFIX}, if that isset).  If you give @command{autoupdate} an argument, it reads that fileinstead of @file{configure.ac} and writes the updated file to thestandard output.@noindent@command{autoupdate} accepts the following options:@table @option@item --help@itemx -hPrint a summary of the command line options and exit.@item --version@itemx -VPrint the version number of Autoconf and exit.@item --verbose@itemx -vReport processing steps.@item --debug@itemx -dDon't remove the temporary files.@item --force@itemx -fForce the update even if the file has not changed.  Disregard the cache.@item --include=@var{dir}@itemx -I @var{dir}Also look for input files in @var{dir}.  Multiple invocations accumulate.Directories are browsed from last to first.@item --prepend-include=@var{dir}@itemx -B @var{dir}Prepend directory @var{dir} to the search path.  This is used to includethe language-specific files before any third-party macros.@end table@node Obsolete Macros@section Obsolete MacrosSeveral macros are obsoleted in Autoconf, for various reasons (typicallythey failed to quote properly, couldn't be extended for more recentissues, etc.).  They are still supported, but deprecated: their useshould be avoided.During the jump from Autoconf version 1 to version 2, most of themacros were renamed to use a more uniform and descriptive naming scheme,but their signature did not change.  @xref{Macro Names}, for adescription of the new naming scheme.  Below, if there is just the mappingfrom old names to new names for these macros, the reader is invited torefer to the definition of the new macro for the signature and thedescription.@defmac AC_AIX@acindex{AIX}@cvindex _ALL_SOURCEThis macro is a platform-specific subset of@code{AC_USE_SYSTEM_EXTENSIONS} (@pxref{AC_USE_SYSTEM_EXTENSIONS}).@end defmac@defmac AC_ALLOCA@acindex{ALLOCA}Replaced by @code{AC_FUNC_ALLOCA} (@pxref{AC_FUNC_ALLOCA}).@end defmac@defmac AC_ARG_ARRAY@acindex{ARG_ARRAY}Removed because of limited usefulness.@end defmac@defmac AC_C_CROSS@acindex{C_CROSS}This macro is obsolete; it does nothing.@end defmac@defmac AC_C_LONG_DOUBLE@acindex{C_LONG_DOUBLE}@cvindex HAVE_LONG_DOUBLEIf the C compiler supports a working @code{long double} type with morerange or precision than the @code{double} type, define@code{HAVE_LONG_DOUBLE}.You should use @code{AC_TYPE_LONG_DOUBLE} or@code{AC_TYPE_LONG_DOUBLE_WIDER} instead.  @xref{Particular Types}.@end defmac@defmac AC_CANONICAL_SYSTEM@acindex{CANONICAL_SYSTEM}Determine the system type and set output variables to the names of thecanonical system types.  @xref{Canonicalizing}, for details about thevariables this macro sets.The user is encouraged to use either @code{AC_CANONICAL_BUILD}, or@code{AC_CANONICAL_HOST}, or @code{AC_CANONICAL_TARGET}, depending onthe needs.  Using @code{AC_CANONICAL_TARGET} is enough to run the twoother macros (@pxref{Canonicalizing}).@end defmac@defmac AC_CHAR_UNSIGNED@acindex{CHAR_UNSIGNED}Replaced by @code{AC_C_CHAR_UNSIGNED} (@pxref{AC_C_CHAR_UNSIGNED}).@end defmac@defmac AC_CHECK_TYPE (@var{type}, @var{default})@acindex{CHECK_TYPE}Autoconf, up to 2.13, used to provide this version of@code{AC_CHECK_TYPE}, deprecated because of its flaws.  First, althoughit is a member of the @code{CHECK} clan, it doesmore than just checking.  Secondly, missing types are definedusing @code{#define}, not @code{typedef}, and this can lead toproblems in the case of pointer types.This use of @code{AC_CHECK_TYPE} is obsolete and discouraged; see@ref{Generic Types}, for the description of the current macro.If the type @var{type} is not defined, define it to be the C (or C++)builtin type @var{default}, e.g., @samp{short int} or @samp{unsigned int}.This macro is equivalent to:@exampleAC_CHECK_TYPE([@var{type}], [],  [AC_DEFINE_UNQUOTED([@var{type}], [@var{default}],     [Define to `@var{default}'      if <sys/types.h> does not define.])])@end exampleIn order to keep backward compatibility, the two versions of@code{AC_CHECK_TYPE} are implemented, selected using these heuristics:@enumerate@itemIf there are three or four arguments, the modern version is used.@itemIf the second argument appears to be a C or C++ type, then theobsolete version is used.  This happens if the argument is a C or C++@emph{builtin} type or a C identifier ending in @samp{_t}, optionallyfollowed by one of @samp{[(* } and then by a string of zero or morecharacters taken from the set @samp{[]()* _a-zA-Z0-9}.@itemIf the second argument is spelled with the alphabet of valid C and C++types, the user is warned and the modern version is used.@itemOtherwise, the modern version is used.@end enumerate@noindentYou are encouraged either to use a valid builtin type, or to use theequivalent modern code (see above), or better yet, to use@code{AC_CHECK_TYPES} together with@example#ifndef HAVE_LOFF_Ttypedef loff_t off_t;#endif@end example@end defmac@c end of AC_CHECK_TYPE@defmac AC_CHECKING (@var{feature-description})@acindex{CHECKING}Same as@exampleAC_MSG_NOTICE([checking @var{feature-description}@dots{}]@end example@noindent@xref{AC_MSG_NOTICE}.@end defmac@defmac AC_COMPILE_CHECK (@var{echo-text}, @var{includes}, @  @var{function-body}, @var{action-if-true}, @ovar{action-if-false})@acindex{COMPILE_CHECK}This is an obsolete version of @code{AC_TRY_COMPILE} itself replaced by@code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}), with theaddition that it prints @samp{checking for @var{echo-text}} to thestandard output first, if @var{echo-text} is non-empty.  Use@code{AC_MSG_CHECKING} and @code{AC_MSG_RESULT} instead to printmessages (@pxref{Printing Messages}).@end defmac@defmac AC_CONST@acindex{CONST}Replaced by @code{AC_C_CONST} (@pxref{AC_C_CONST}).@end defmac@defmac AC_CROSS_CHECK@acindex{CROSS_CHECK}Same as @code{AC_C_CROSS}, which is obsolete too, and does nothing@code{:-)}.@end defmac@defmac AC_CYGWIN@acindex{CYGWIN}@evindex CYGWINCheck for the Cygwin environment in which case the shell variable@code{CYGWIN} is set to @samp{yes}.  Don't use this macro, the dignifiedmeans to check the nature of the host is using @code{AC_CANONICAL_HOST}(@pxref{Canonicalizing}).  As a matter of fact this macro is defined as:@exampleAC_REQUIRE([AC_CANONICAL_HOST])[]dnlcase $host_os in  *cygwin* ) CYGWIN=yes;;         * ) CYGWIN=no;;esac@end exampleBeware that the variable @env{CYGWIN} has a special meaning whenrunning Cygwin, and should not be changed.  That's yet another reasonnot to use this macro.@end defmac@defmac AC_DECL_SYS_SIGLIST@acindex{DECL_SYS_SIGLIST}@cvindex SYS_SIGLIST_DECLAREDSame as:@exampleAC_CHECK_DECLS([sys_siglist], [], [],[#include <signal.h>/* NetBSD declares sys_siglist in unistd.h.  */#ifdef HAVE_UNISTD_H# include <unistd.h>#endif])@end example@noindent@xref{AC_CHECK_DECLS}.@end defmac@defmac AC_DECL_YYTEXT@acindex{DECL_YYTEXT}Does nothing, now integrated in @code{AC_PROG_LEX} (@pxref{AC_PROG_LEX}).@end defmac@defmac AC_DIR_HEADER@acindex{DIR_HEADER}@cvindex DIRENT@cvindex SYSNDIR@cvindex SYSDIR@cvindex NDIRLike calling @code{AC_FUNC_CLOSEDIR_VOID}(@pxref{AC_FUNC_CLOSEDIR_VOID}) and @code{AC_HEADER_DIRENT}(@pxref{AC_HEADER_DIRENT}),but defines a different set of C preprocessor macros to indicate whichheader file is found:@multitable {@file{sys/ndir.h}} {Old Symbol} {@code{HAVE_SYS_NDIR_H}}@item Header            @tab Old Symbol     @tab New Symbol@item @file{dirent.h}   @tab @code{DIRENT}  @tab @code{HAVE_DIRENT_H}@item @file{sys/ndir.h} @tab @code{SYSNDIR} @tab @code{HAVE_SYS_NDIR_H}@item @file{sys/dir.h}  @tab @code{SYSDIR}  @tab @code{HAVE_SYS_DIR_H}@item @file{ndir.h}     @tab @code{NDIR}    @tab @code{HAVE_NDIR_H}@end multitable@end defmac@defmac AC_DYNIX_SEQ@acindex{DYNIX_SEQ}If on DYNIX/ptx, add @option{-lseq} to output variable@code{LIBS}.  This macro used to be defined as@exampleAC_CHECK_LIB([seq], [getmntent], [LIBS="-lseq $LIBS"])@end example@noindentnow it is just @code{AC_FUNC_GETMNTENT} (@pxref{AC_FUNC_GETMNTENT}).@end defmac@defmac AC_EXEEXT@acindex{EXEEXT}@ovindex EXEEXTDefined the output variable @code{EXEEXT} based on the output of thecompiler, which is now done automatically.  Typically set to emptystring if Posix and @samp{.exe} if a DOS variant.@end defmac@defmac AC_EMXOS2@acindex{EMXOS2}Similar to @code{AC_CYGWIN} but checks for the EMX environment on OS/2and sets @code{EMXOS2}.  Don't use this macro, the dignified means tocheck the nature of the host is using @code{AC_CANONICAL_HOST}(@pxref{Canonicalizing}).@end defmac@defmac AC_ENABLE (@var{feature}, @var{action-if-given}, @  @ovar{action-if-not-given})@acindex{ENABLE}This is an obsolete version of @code{AC_ARG_ENABLE} that does notsupport providing a help string (@pxref{AC_ARG_ENABLE}).@end defmac@defmac AC_ERROR@acindex{ERROR}Replaced by @code{AC_MSG_ERROR} (@pxref{AC_MSG_ERROR}).@end defmac@defmac AC_FIND_X@acindex{FIND_X}Replaced by @code{AC_PATH_X} (@pxref{AC_PATH_X}).@end defmac@defmac AC_FIND_XTRA@acindex{FIND_XTRA}Replaced by @code{AC_PATH_XTRA} (@pxref{AC_PATH_XTRA}).@end defmac@defmac AC_FOREACH@acindex{FOREACH}Replaced by @code{m4_foreach_w} (@pxref{m4_foreach_w}).@end defmac@defmac AC_FUNC_CHECK@acindex{FUNC_CHECK}Replaced by @code{AC_CHECK_FUNC} (@pxref{AC_CHECK_FUNC}).@end defmac@anchor{AC_FUNC_SETVBUF_REVERSED}@defmac AC_FUNC_SETVBUF_REVERSED@acindex{FUNC_SETVBUF_REVERSED}@cvindex SETVBUF_REVERSED@c @fuindex setvbuf@prindex @code{setvbuf}Do nothing.  Formerly, this macro checked whether @code{setvbuf} takesthe buffering type as its second argument and the buffer pointer as thethird, instead of the other way around, and defined@code{SETVBUF_REVERSED}.  However, the last systems to have the problemwere those based on SVR2, which became obsolete in 1987, and the macrois no longer needed.@end defmac@defmac AC_FUNC_WAIT3@acindex{FUNC_WAIT3}@cvindex HAVE_WAIT3@c @fuindex wait3@prindex @code{wait3}If @code{wait3} is found and fills in the contents of its third argument(a @samp{struct rusage *}), which HP-UX does not do, define@code{HAVE_WAIT3}.These days portable programs should use @code{waitpid}, not@code{wait3}, as @code{wait3} has been removed from Posix.@end defmac@defmac AC_GCC_TRADITIONAL@acindex{GCC_TRADITIONAL}Replaced by @code{AC_PROG_GCC_TRADITIONAL} (@pxref{AC_PROG_GCC_TRADITIONAL}).@end defmac@defmac AC_GETGROUPS_T@acindex{GETGROUPS_T}Replaced by @code{AC_TYPE_GETGROUPS} (@pxref{AC_TYPE_GETGROUPS}).@end defmac@defmac AC_GETLOADAVG@acindex{GETLOADAVG}Replaced by @code{AC_FUNC_GETLOADAVG} (@pxref{AC_FUNC_GETLOADAVG}).@end defmac@defmac AC_GNU_SOURCE@acindex{GNU_SOURCE}@cvindex _GNU_SOURCEThis macro is a platform-specific subset of@code{AC_USE_SYSTEM_EXTENSIONS} (@pxref{AC_USE_SYSTEM_EXTENSIONS}).@end defmac@defmac AC_HAVE_FUNCS@acindex{HAVE_FUNCS}Replaced by @code{AC_CHECK_FUNCS} (@pxref{AC_CHECK_FUNCS}).@end defmac@defmac AC_HAVE_HEADERS@acindex{HAVE_HEADERS}Replaced by @code{AC_CHECK_HEADERS} (@pxref{AC_CHECK_HEADERS}).@end defmac@defmac AC_HAVE_LIBRARY (@var{library}, @ovar{action-if-found}, @  @ovar{action-if-not-found}, @ovar{other-libraries})@acindex{HAVE_LIBRARY}This macro is equivalent to calling @code{AC_CHECK_LIB} with a@var{function} argument of @code{main}.  In addition, @var{library} canbe written as any of @samp{foo}, @option{-lfoo}, or @samp{libfoo.a}.  Inall of those cases, the compiler is passed @option{-lfoo}.  However,@var{library} cannot be a shell variable; it must be a literal name.@xref{AC_CHECK_LIB}.@end defmac@defmac AC_HAVE_POUNDBANG@acindex{HAVE_POUNDBANG}Replaced by @code{AC_SYS_INTERPRETER} (@pxref{AC_SYS_INTERPRETER}).@end defmac@defmac AC_HEADER_CHECK@acindex{HEADER_CHECK}Replaced by @code{AC_CHECK_HEADER} (@pxref{AC_CHECK_HEADER}).@end defmac@defmac AC_HEADER_EGREP@acindex{HEADER_EGREP}Replaced by @code{AC_EGREP_HEADER} (@pxref{AC_EGREP_HEADER}).@end defmac@defmac AC_HELP_STRING@acindex{HELP_STRING}Replaced by @code{AS_HELP_STRING} (@pxref{AS_HELP_STRING}).@end defmac@defmac AC_INIT (@var{unique-file-in-source-dir})@acindex{INIT}Formerly @code{AC_INIT} used to have a single argument, and wasequivalent to:@exampleAC_INITAC_CONFIG_SRCDIR(@var{unique-file-in-source-dir})@end exampleSee @ref{AC_INIT} and @ref{AC_CONFIG_SRCDIR}.@end defmac@defmac AC_INLINE@acindex{INLINE}Replaced by @code{AC_C_INLINE} (@pxref{AC_C_INLINE}).@end defmac@defmac AC_INT_16_BITS@acindex{INT_16_BITS}@cvindex INT_16_BITSIf the C type @code{int} is 16 bits wide, define @code{INT_16_BITS}.Use @samp{AC_CHECK_SIZEOF(int)} instead (@pxref{AC_CHECK_SIZEOF}).@end defmac@defmac AC_IRIX_SUN@acindex{IRIX_SUN}If on IRIX (Silicon Graphics Unix), add @option{-lsun} to output@code{LIBS}.  If you were using it to get @code{getmntent}, use@code{AC_FUNC_GETMNTENT} instead.  If you used it for the NIS versionsof the password and group functions, use @samp{AC_CHECK_LIB(sun,getpwnam)}.  Up to Autoconf 2.13, it used to be@exampleAC_CHECK_LIB([sun], [getmntent], [LIBS="-lsun $LIBS"])@end example@noindentnow it is defined as@exampleAC_FUNC_GETMNTENTAC_CHECK_LIB([sun], [getpwnam])@end example@noindentSee @ref{AC_FUNC_GETMNTENT} and @ref{AC_CHECK_LIB}.@end defmac@defmac AC_ISC_POSIX@acindex{ISC_POSIX}@ovindex LIBSThis macro adds @option{-lcposix} to output variable @code{LIBS} ifnecessary for Posix facilities.  Sun dropped support for the obsoleteINTERACTIVE Systems Corporation Unix on 2006-07-23.  New programsneed not use this macro.  It is implemented as@code{AC_SEARCH_LIBS([strerror], [cposix])} (@pxref{AC_SEARCH_LIBS}).@end defmac@defmac AC_LANG_C@acindex{LANG_C}Same as @samp{AC_LANG([C])} (@pxref{AC_LANG}).@end defmac@defmac AC_LANG_CPLUSPLUS@acindex{LANG_CPLUSPLUS}Same as @samp{AC_LANG([C++])} (@pxref{AC_LANG}).@end defmac@defmac AC_LANG_FORTRAN77@acindex{LANG_FORTRAN77}Same as @samp{AC_LANG([Fortran 77])} (@pxref{AC_LANG}).@end defmac@defmac AC_LANG_RESTORE@acindex{LANG_RESTORE}Select the @var{language} that is saved on the top of the stack, as setby @code{AC_LANG_SAVE}, remove it from the stack, and call@code{AC_LANG(@var{language})}.  @xref{Language Choice}, for thepreferred way to change languages.@end defmac@defmac AC_LANG_SAVE@acindex{LANG_SAVE}Remember the current language (as set by @code{AC_LANG}) on a stack.The current language does not change.  @code{AC_LANG_PUSH} is preferred(@pxref{AC_LANG_PUSH}).@end defmac@defmac AC_LINK_FILES (@var{source}@dots{}, @var{dest}@dots{})@acindex{LINK_FILES}This is an obsolete version of @code{AC_CONFIG_LINKS}(@pxref{AC_CONFIG_LINKS}.  An updated version of:@exampleAC_LINK_FILES(config/$machine.h config/$obj_format.h,              host.h            object.h)@end example@noindentis:@exampleAC_CONFIG_LINKS([host.h:config/$machine.h                object.h:config/$obj_format.h])@end example@end defmac@defmac AC_LN_S@acindex{LN_S}Replaced by @code{AC_PROG_LN_S} (@pxref{AC_PROG_LN_S}).@end defmac@defmac AC_LONG_64_BITS@acindex{LONG_64_BITS}@cvindex LONG_64_BITSDefine @code{LONG_64_BITS} if the C type @code{long int} is 64 bits wide.Use the generic macro @samp{AC_CHECK_SIZEOF([long int])} instead(@pxref{AC_CHECK_SIZEOF}).@end defmac@defmac AC_LONG_DOUBLE@acindex{LONG_DOUBLE}If the C compiler supports a working @code{long double} type with morerange or precision than the @code{double} type, define@code{HAVE_LONG_DOUBLE}.You should use @code{AC_TYPE_LONG_DOUBLE} or@code{AC_TYPE_LONG_DOUBLE_WIDER} instead.  @xref{Particular Types}.@end defmac@defmac AC_LONG_FILE_NAMES@acindex{LONG_FILE_NAMES}Replaced by@exampleAC_SYS_LONG_FILE_NAMES@end example@noindent@xref{AC_SYS_LONG_FILE_NAMES}.@end defmac@defmac AC_MAJOR_HEADER@acindex{MAJOR_HEADER}Replaced by @code{AC_HEADER_MAJOR} (@pxref{AC_HEADER_MAJOR}).@end defmac@defmac AC_MEMORY_H@acindex{MEMORY_H}@cvindex NEED_MEMORY_HUsed to define @code{NEED_MEMORY_H} if the @code{mem} functions weredefined in @file{memory.h}.  Today it is equivalent to@samp{AC_CHECK_HEADERS([memory.h])} (@pxref{AC_CHECK_HEADERS}).  Adjustyour code to depend upon@code{HAVE_MEMORY_H}, not @code{NEED_MEMORY_H}; see @ref{StandardSymbols}.@end defmac@defmac AC_MINGW32@acindex{MINGW32}Similar to @code{AC_CYGWIN} but checks for the MinGW compilerenvironment and sets @code{MINGW32}.  Don't use this macro, thedignified means to check the nature of the host is using@code{AC_CANONICAL_HOST} (@pxref{Canonicalizing}).@end defmac@defmac AC_MINIX@acindex{MINIX}@cvindex _MINIX@cvindex _POSIX_SOURCE@cvindex _POSIX_1_SOURCEThis macro is a platform-specific subset of@code{AC_USE_SYSTEM_EXTENSIONS} (@pxref{AC_USE_SYSTEM_EXTENSIONS}).@end defmac@defmac AC_MINUS_C_MINUS_O@acindex{MINUS_C_MINUS_O}Replaced by @code{AC_PROG_CC_C_O} (@pxref{AC_PROG_CC_C_O}).@end defmac@defmac AC_MMAP@acindex{MMAP}Replaced by @code{AC_FUNC_MMAP} (@pxref{AC_FUNC_MMAP}).@end defmac@defmac AC_MODE_T@acindex{MODE_T}Replaced by @code{AC_TYPE_MODE_T} (@pxref{AC_TYPE_MODE_T}).@end defmac@defmac AC_OBJEXT@acindex{OBJEXT}@ovindex OBJEXTDefined the output variable @code{OBJEXT} based on the output of thecompiler, after .c files have been excluded.  Typically set to @samp{o}if Posix, @samp{obj} if a DOS variant.Now the compiler checking macros handlethis automatically.@end defmac@defmac AC_OBSOLETE (@var{this-macro-name}, @ovar{suggestion})@acindex{OBSOLETE}Make M4 print a message to the standard error output warning that@var{this-macro-name} is obsolete, and giving the file and line numberwhere it was called.  @var{this-macro-name} should be the name of themacro that is calling @code{AC_OBSOLETE}.  If @var{suggestion} is given,it is printed at the end of the warning message; for example, it can bea suggestion for what to use instead of @var{this-macro-name}.For instance@exampleAC_OBSOLETE([$0], [; use AC_CHECK_HEADERS(unistd.h) instead])dnl@end example@noindentYou are encouraged to use @code{AU_DEFUN} instead, since it gives betterservices to the user (@pxref{AU_DEFUN}).@end defmac@defmac AC_OFF_T@acindex{OFF_T}Replaced by @code{AC_TYPE_OFF_T} (@pxref{AC_TYPE_OFF_T}).@end defmac@defmac AC_OUTPUT (@ovar{file}@dots{}, @ovar{extra-cmds}, @ovar{init-cmds})@acindex{OUTPUT}The use of @code{AC_OUTPUT} with arguments is deprecated.  This obsoletedinterface is equivalent to:@example@groupAC_CONFIG_FILES(@var{file}@dots{})AC_CONFIG_COMMANDS([default],                   @var{extra-cmds}, @var{init-cmds})AC_OUTPUT@end group@end example@noindentSee @ref{AC_CONFIG_FILES}, @ref{AC_CONFIG_COMMANDS}, and @ref{AC_OUTPUT}.@end defmac@defmac AC_OUTPUT_COMMANDS (@var{extra-cmds}, @ovar{init-cmds})@acindex{OUTPUT_COMMANDS}Specify additional shell commands to run at the end of@file{config.status}, and shell commands to initialize any variablesfrom @command{configure}.  This macro may be called multiple times.  It isobsolete, replaced by @code{AC_CONFIG_COMMANDS} (@pxref{AC_CONFIG_COMMANDS}).Here is an unrealistic example:@examplefubar=27AC_OUTPUT_COMMANDS([echo this is extra $fubar, and so on.],                   [fubar=$fubar])AC_OUTPUT_COMMANDS([echo this is another, extra, bit],                   [echo init bit])@end exampleAside from the fact that @code{AC_CONFIG_COMMANDS} requires anadditional key, an important difference is that@code{AC_OUTPUT_COMMANDS} is quoting its arguments twice, unlike@code{AC_CONFIG_COMMANDS}.  This means that @code{AC_CONFIG_COMMANDS}can safely be given macro calls as arguments:@exampleAC_CONFIG_COMMANDS(foo, [my_FOO()])@end example@noindentConversely, where one level of quoting was enough for literal stringswith @code{AC_OUTPUT_COMMANDS}, you need two with@code{AC_CONFIG_COMMANDS}.  The following lines are equivalent:@example@groupAC_OUTPUT_COMMANDS([echo "Square brackets: []"])AC_CONFIG_COMMANDS([default], [[echo "Square brackets: []"]])@end group@end example@end defmac@defmac AC_PID_T@acindex{PID_T}Replaced by @code{AC_TYPE_PID_T} (@pxref{AC_TYPE_PID_T}).@end defmac@defmac AC_PREFIX@acindex{PREFIX}Replaced by @code{AC_PREFIX_PROGRAM} (@pxref{AC_PREFIX_PROGRAM}).@end defmac@defmac AC_PROGRAMS_CHECK@acindex{PROGRAMS_CHECK}Replaced by @code{AC_CHECK_PROGS} (@pxref{AC_CHECK_PROGS}).@end defmac@defmac AC_PROGRAMS_PATH@acindex{PROGRAMS_PATH}Replaced by @code{AC_PATH_PROGS} (@pxref{AC_PATH_PROGS}).@end defmac@defmac AC_PROGRAM_CHECK@acindex{PROGRAM_CHECK}Replaced by @code{AC_CHECK_PROG} (@pxref{AC_CHECK_PROG}).@end defmac@defmac AC_PROGRAM_EGREP@acindex{PROGRAM_EGREP}Replaced by @code{AC_EGREP_CPP} (@pxref{AC_EGREP_CPP}).@end defmac@defmac AC_PROGRAM_PATH@acindex{PROGRAM_PATH}Replaced by @code{AC_PATH_PROG} (@pxref{AC_PATH_PROG}).@end defmac@defmac AC_REMOTE_TAPE@acindex{REMOTE_TAPE}Removed because of limited usefulness.@end defmac@defmac AC_RESTARTABLE_SYSCALLS@acindex{RESTARTABLE_SYSCALLS}This macro was renamed @code{AC_SYS_RESTARTABLE_SYSCALLS}.  However,these days portable programs should use @code{sigaction} with@code{SA_RESTART} if they want restartable system calls.  They shouldnot rely on @code{HAVE_RESTARTABLE_SYSCALLS}, since nowadays whether asystem call is restartable is a dynamic issue, not a configuration-timeissue.@end defmac@defmac AC_RETSIGTYPE@acindex{RETSIGTYPE}Replaced by @code{AC_TYPE_SIGNAL} (@pxref{AC_TYPE_SIGNAL}), which itselfis obsolete when assuming C89 or better.@end defmac@defmac AC_RSH@acindex{RSH}Removed because of limited usefulness.@end defmac@defmac AC_SCO_INTL@acindex{SCO_INTL}@ovindex LIBSIf on SCO Unix, add @option{-lintl} to output variable @code{LIBS}.  Thismacro used to do this:@exampleAC_CHECK_LIB([intl], [strftime], [LIBS="-lintl $LIBS"])@end example@noindentNow it just calls @code{AC_FUNC_STRFTIME} instead (@pxref{AC_FUNC_STRFTIME}).@end defmac@defmac AC_SETVBUF_REVERSED@acindex{SETVBUF_REVERSED}Replaced by@exampleAC_FUNC_SETVBUF_REVERSED@end example@noindent@xref{AC_FUNC_SETVBUF_REVERSED}.@end defmac@defmac AC_SET_MAKE@acindex{SET_MAKE}Replaced by @code{AC_PROG_MAKE_SET} (@pxref{AC_PROG_MAKE_SET}).@end defmac@defmac AC_SIZEOF_TYPE@acindex{SIZEOF_TYPE}Replaced by @code{AC_CHECK_SIZEOF} (@pxref{AC_CHECK_SIZEOF}).@end defmac@defmac AC_SIZE_T@acindex{SIZE_T}Replaced by @code{AC_TYPE_SIZE_T} (@pxref{AC_TYPE_SIZE_T}).@end defmac@defmac AC_STAT_MACROS_BROKEN@acindex{STAT_MACROS_BROKEN}Replaced by @code{AC_HEADER_STAT} (@pxref{AC_HEADER_STAT}).@end defmac@defmac AC_STDC_HEADERS@acindex{STDC_HEADERS}Replaced by @code{AC_HEADER_STDC} (@pxref{AC_HEADER_STDC}).@end defmac@defmac AC_STRCOLL@acindex{STRCOLL}Replaced by @code{AC_FUNC_STRCOLL} (@pxref{AC_FUNC_STRCOLL}).@end defmac@defmac AC_STRUCT_ST_BLKSIZE@acindex{STRUCT_ST_BLKSIZE}@cvindex HAVE_STRUCT_STAT_ST_BLKSIZE@cvindex HAVE_ST_BLKSIZEIf @code{struct stat} contains an @code{st_blksize} member, define@code{HAVE_STRUCT_STAT_ST_BLKSIZE}.  The former name,@code{HAVE_ST_BLKSIZE} is to be avoided, as its support will cease inthe future.  This macro is obsoleted, and should be replaced by@exampleAC_CHECK_MEMBERS([struct stat.st_blksize])@end example@noindent@xref{AC_CHECK_MEMBERS}.@end defmac@defmac AC_STRUCT_ST_RDEV@acindex{STRUCT_ST_RDEV}@cvindex HAVE_ST_RDEV@cvindex HAVE_STRUCT_STAT_ST_RDEVIf @code{struct stat} contains an @code{st_rdev} member, define@code{HAVE_STRUCT_STAT_ST_RDEV}.  The former name for this macro,@code{HAVE_ST_RDEV}, is to be avoided as it will cease to be supportedin the future.  Actually, even the new macro is obsolete and should bereplaced by:@exampleAC_CHECK_MEMBERS([struct stat.st_rdev])@end example@noindent@xref{AC_CHECK_MEMBERS}.@end defmac@defmac AC_ST_BLKSIZE@acindex{ST_BLKSIZE}Replaced by @code{AC_CHECK_MEMBERS} (@pxref{AC_CHECK_MEMBERS}).@end defmac@defmac AC_ST_BLOCKS@acindex{ST_BLOCKS}Replaced by @code{AC_STRUCT_ST_BLOCKS} (@pxref{AC_STRUCT_ST_BLOCKS}).@end defmac@defmac AC_ST_RDEV@acindex{ST_RDEV}Replaced by @code{AC_CHECK_MEMBERS} (@pxref{AC_CHECK_MEMBERS}).@end defmac@defmac AC_SYS_RESTARTABLE_SYSCALLS@acindex{SYS_RESTARTABLE_SYSCALLS}@cvindex HAVE_RESTARTABLE_SYSCALLSIf the system automatically restarts a system call that is interruptedby a signal, define @code{HAVE_RESTARTABLE_SYSCALLS}.  This macro doesnot check whether system calls are restarted in general---it checks whether asignal handler installed with @code{signal} (but not @code{sigaction})causes system calls to be restarted.  It does not check whether system callscan be restarted when interrupted by signals that have no handler.These days portable programs should use @code{sigaction} with@code{SA_RESTART} if they want restartable system calls.  They shouldnot rely on @code{HAVE_RESTARTABLE_SYSCALLS}, since nowadays whether asystem call is restartable is a dynamic issue, not a configuration-timeissue.@end defmac@defmac AC_SYS_SIGLIST_DECLARED@acindex{SYS_SIGLIST_DECLARED}This macro was renamed @code{AC_DECL_SYS_SIGLIST}.  However, even thatname is obsolete, as the same functionality is now achieved via@code{AC_CHECK_DECLS} (@pxref{AC_CHECK_DECLS}).@end defmac@defmac AC_TEST_CPP@acindex{TEST_CPP}This macro was renamed @code{AC_TRY_CPP}, which in turn was replaced by@code{AC_PREPROC_IFELSE} (@pxref{AC_PREPROC_IFELSE}).@end defmac@defmac AC_TEST_PROGRAM@acindex{TEST_PROGRAM}This macro was renamed @code{AC_TRY_RUN}, which in turn was replaced by@code{AC_RUN_IFELSE} (@pxref{AC_RUN_IFELSE}).@end defmac@defmac AC_TIMEZONE@acindex{TIMEZONE}Replaced by @code{AC_STRUCT_TIMEZONE} (@pxref{AC_STRUCT_TIMEZONE}).@end defmac@defmac AC_TIME_WITH_SYS_TIME@acindex{TIME_WITH_SYS_TIME}Replaced by @code{AC_HEADER_TIME} (@pxref{AC_HEADER_TIME}).@end defmac@defmac AC_TRY_COMPILE (@var{includes}, @var{function-body}, @  @ovar{action-if-true}, @ovar{action-if-false})@acindex{TRY_COMPILE}Same as:@exampleAC_COMPILE_IFELSE(  [AC_LANG_PROGRAM([[@var{includes}]],     [[@var{function-body}]])],  [@var{action-if-true}],  [@var{action-if-false}])@end example@noindent@xref{Running the Compiler}.This macro double quotes both @var{includes} and @var{function-body}.For C and C++, @var{includes} is any @code{#include} statements neededby the code in @var{function-body} (@var{includes} is ignored ifthe currently selected language is Fortran or Fortran 77).  The compilerand compilation flags are determined by the current language(@pxref{Language Choice}).@end defmac@defmac AC_TRY_CPP (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})@acindex{TRY_CPP}Same as:@exampleAC_PREPROC_IFELSE(  [AC_LANG_SOURCE([[@var{input}]])],  [@var{action-if-true}],  [@var{action-if-false}])@end example@noindent@xref{Running the Preprocessor}.This macro double quotes the @var{input}.@end defmac@defmac AC_TRY_LINK (@var{includes}, @var{function-body}, @  @ovar{action-if-true}, @ovar{action-if-false})@acindex{TRY_LINK}Same as:@exampleAC_LINK_IFELSE(  [AC_LANG_PROGRAM([[@var{includes}]],     [[@var{function-body}]])],  [@var{action-if-true}],  [@var{action-if-false}])@end example@noindent@xref{Running the Compiler}.This macro double quotes both @var{includes} and @var{function-body}.Depending on the current language (@pxref{Language Choice}), create atest program to see whether a function whose body consists of@var{function-body} can be compiled and linked.  If the file compilesand links successfully, run shell commands @var{action-if-found},otherwise run @var{action-if-not-found}.This macro double quotes both @var{includes} and @var{function-body}.For C and C++, @var{includes} is any @code{#include} statements neededby the code in @var{function-body} (@var{includes} is ignored ifthe currently selected language is Fortran or Fortran 77).  The compilerand compilation flags are determined by the current language(@pxref{Language Choice}), and in addition @code{LDFLAGS} and@code{LIBS} are used for linking.@end defmac@defmac AC_TRY_LINK_FUNC (@var{function}, @ovar{action-if-found}, @  @ovar{action-if-not-found})@acindex{TRY_LINK_FUNC}This macro is equivalent to@exampleAC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])],  [@var{action-if-found}], [@var{action-if-not-found}])@end example@noindent@xref{AC_LINK_IFELSE}.@end defmac@defmac AC_TRY_RUN (@var{program}, @ovar{action-if-true}, @  @ovar{action-if-false}, @dvar{action-if-cross-compiling, AC_MSG_FAILURE})@acindex{TRY_RUN}Same as:@exampleAC_RUN_IFELSE(  [AC_LANG_SOURCE([[@var{program}]])],  [@var{action-if-true}],  [@var{action-if-false}],  [@var{action-if-cross-compiling}])@end example@noindent@xref{Runtime}.@end defmac@anchor{AC_TYPE_SIGNAL}@defmac AC_TYPE_SIGNAL@acindex{TYPE_SIGNAL}@cvindex RETSIGTYPE@hdrindex{signal.h}If @file{signal.h} declares @code{signal} as returning a pointer to afunction returning @code{void}, define @code{RETSIGTYPE} to be@code{void}; otherwise, define it to be @code{int}.  These days, it isportable to assume C89, and that signal handlers return @code{void},without needing to use this macro or @code{RETSIGTYPE}.When targeting older K&R C, it is possible to define signal handlers asreturning type @code{RETSIGTYPE}, and omit a return statement:@example@groupRETSIGTYPEhup_handler ()@{@dots{}@}@end group@end example@end defmac@defmac AC_UID_T@acindex{UID_T}Replaced by @code{AC_TYPE_UID_T} (@pxref{AC_TYPE_UID_T}).@end defmac@defmac AC_UNISTD_H@acindex{UNISTD_H}Same as @samp{AC_CHECK_HEADERS([unistd.h])} (@pxref{AC_CHECK_HEADERS}).@end defmac@defmac AC_USG@acindex{USG}@cvindex USGDefine @code{USG} if the BSD string functions are defined in@file{strings.h}.  You should no longer depend upon @code{USG}, but on@code{HAVE_STRING_H}; see @ref{Standard Symbols}.@end defmac@defmac AC_UTIME_NULL@acindex{UTIME_NULL}Replaced by @code{AC_FUNC_UTIME_NULL} (@pxref{AC_FUNC_UTIME_NULL}).@end defmac@defmac AC_VALIDATE_CACHED_SYSTEM_TUPLE (@ovar{cmd})@acindex{VALIDATE_CACHED_SYSTEM_TUPLE}If the cache file is inconsistent with the current host, target andbuild system types, it used to execute @var{cmd} or print a defaulterror message.  This is now handled by default.@end defmac@defmac AC_VERBOSE (@var{result-description})@acindex{VERBOSE}Replaced by @code{AC_MSG_RESULT} (@pxref{AC_MSG_RESULT}).@end defmac@defmac AC_VFORK@acindex{VFORK}Replaced by @code{AC_FUNC_FORK} (@pxref{AC_FUNC_FORK}).@end defmac@defmac AC_VPRINTF@acindex{VPRINTF}Replaced by @code{AC_FUNC_VPRINTF} (@pxref{AC_FUNC_VPRINTF}).@end defmac@defmac AC_WAIT3@acindex{WAIT3}This macro was renamed @code{AC_FUNC_WAIT3}.  However, these daysportable programs should use @code{waitpid}, not @code{wait3}, as@code{wait3} has been removed from Posix.@end defmac@defmac AC_WARN@acindex{WARN}Replaced by @code{AC_MSG_WARN} (@pxref{AC_MSG_WARN}).@end defmac@defmac AC_WITH (@var{package}, @var{action-if-given}, @  @ovar{action-if-not-given})@acindex{WITH}This is an obsolete version of @code{AC_ARG_WITH} that does notsupport providing a help string (@pxref{AC_ARG_WITH}).@end defmac@defmac AC_WORDS_BIGENDIAN@acindex{WORDS_BIGENDIAN}Replaced by @code{AC_C_BIGENDIAN} (@pxref{AC_C_BIGENDIAN}).@end defmac@defmac AC_XENIX_DIR@acindex{XENIX_DIR}@ovindex LIBSThis macro used to add @option{-lx} to output variable @code{LIBS} if onXenix.  Also, if @file{dirent.h} is being checked for, added@option{-ldir} to @code{LIBS}.  Now it is merely an alias of@code{AC_HEADER_DIRENT} instead, plus some code to detect whetherrunning XENIX on which you should not depend:@exampleAC_MSG_CHECKING([for Xenix])AC_EGREP_CPP([yes],[#if defined M_XENIX && !defined M_UNIX  yes#endif],             [AC_MSG_RESULT([yes]); XENIX=yes],             [AC_MSG_RESULT([no]); XENIX=])@end example@noindentDon't use this macro, the dignified means to check the nature of thehost is using @code{AC_CANONICAL_HOST} (@pxref{Canonicalizing}).@end defmac@defmac AC_YYTEXT_POINTER@acindex{YYTEXT_POINTER}This macro was renamed @code{AC_DECL_YYTEXT}, which in turn wasintegrated into @code{AC_PROG_LEX} (@pxref{AC_PROG_LEX}).@end defmac@node Autoconf 1@section Upgrading From Version 1@cindex Upgrading autoconf@cindex Autoconf upgradingAutoconf version 2 is mostly backward compatible with version 1.However, it introduces better ways to do some things, and doesn'tsupport some of the ugly things in version 1.  So, depending on howsophisticated your @file{configure.ac} files are, you might have to dosome manual work in order to upgrade to version 2.  This chapter pointsout some problems to watch for when upgrading.  Also, perhaps your@command{configure} scripts could benefit from some of the new features inversion 2; the changes are summarized in the file @file{NEWS} in theAutoconf distribution.@menu* Changed File Names::          Files you might rename* Changed Makefiles::           New things to put in @file{Makefile.in}* Changed Macros::              Macro calls you might replace* Changed Results::             Changes in how to check test results* Changed Macro Writing::       Better ways to write your own macros@end menu@node Changed File Names@subsection Changed File NamesIf you have an @file{aclocal.m4} installed with Autoconf (as opposed toin a particular package's source directory), you must rename it to@file{acsite.m4}.  @xref{autoconf Invocation}.If you distribute @file{install.sh} with your package, rename it to@file{install-sh} so @command{make} builtin rules don't inadvertentlycreate a file called @file{install} from it.  @code{AC_PROG_INSTALL}looks for the script under both names, but it is best to use the new name.If you were using @file{config.h.top}, @file{config.h.bot}, or@file{acconfig.h}, you still can, but you have less clutter if youuse the @code{AH_} macros.  @xref{Autoheader Macros}.@node Changed Makefiles@subsection Changed MakefilesAdd @samp{@@CFLAGS@@}, @samp{@@CPPFLAGS@@}, and @samp{@@LDFLAGS@@} inyour @file{Makefile.in} files, so they can take advantage of the valuesof those variables in the environment when @command{configure} is run.Doing this isn't necessary, but it's a convenience for users.Also add @samp{@@configure_input@@} in a comment to each input file for@code{AC_OUTPUT}, so that the output files contain a comment sayingthey were produced by @command{configure}.  Automatically selecting theright comment syntax for all the kinds of files that people call@code{AC_OUTPUT} on became too much work.Add @file{config.log} and @file{config.cache} to the list of files youremove in @code{distclean} targets.If you have the following in @file{Makefile.in}:@exampleprefix = /usr/localexec_prefix = $(prefix)@end example@noindentyou must change it to:@exampleprefix = @@prefix@@exec_prefix = @@exec_prefix@@@end example@noindentThe old behavior of replacing those variables without @samp{@@}characters around them has been removed.@node Changed Macros@subsection Changed MacrosMany of the macros were renamed in Autoconf version 2.  You can stilluse the old names, but the new ones are clearer, and it's easier to findthe documentation for them.  @xref{Obsolete Macros}, for a table showing thenew names for the old macros.  Use the @command{autoupdate} program toconvert your @file{configure.ac} to using the new macro names.@xref{autoupdate Invocation}.Some macros have been superseded by similar ones that do the job better,but are not call-compatible.  If you get warnings about calling obsoletemacros while running @command{autoconf}, you may safely ignore them, butyour @command{configure} script generally works better if you followthe advice that is printed about what to replace the obsolete macros with.  Inparticular, the mechanism for reporting the results of tests haschanged.  If you were using @command{echo} or @code{AC_VERBOSE} (perhapsvia @code{AC_COMPILE_CHECK}), your @command{configure} script's outputlooks better if you switch to @code{AC_MSG_CHECKING} and@code{AC_MSG_RESULT}.  @xref{Printing Messages}.  Those macros work bestin conjunction with cache variables.  @xref{Caching Results}.@node Changed Results@subsection Changed ResultsIf you were checking the results of previous tests by examining theshell variable @code{DEFS}, you need to switch to checking the values ofthe cache variables for those tests.  @code{DEFS} no longer exists while@command{configure} is running; it is only created when generating outputfiles.  This difference from version 1 is because properly quoting thecontents of that variable turned out to be too cumbersome andinefficient to do every time @code{AC_DEFINE} is called.  @xref{CacheVariable Names}.For example, here is a @file{configure.ac} fragment written for Autoconfversion 1:@exampleAC_HAVE_FUNCS(syslog)case "$DEFS" in*-DHAVE_SYSLOG*) ;;*) # syslog is not in the default libraries.  See if it's in some other.  saved_LIBS="$LIBS"  for lib in bsd socket inet; do    AC_CHECKING(for syslog in -l$lib)    LIBS="-l$lib $saved_LIBS"    AC_HAVE_FUNCS(syslog)    case "$DEFS" in    *-DHAVE_SYSLOG*) break ;;    *) ;;    esac    LIBS="$saved_LIBS"  done ;;esac@end exampleHere is a way to write it for version 2:@exampleAC_CHECK_FUNCS([syslog])if test "x$ac_cv_func_syslog" = xno; then  # syslog is not in the default libraries.  See if it's in some other.  for lib in bsd socket inet; do    AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG])      LIBS="-l$lib $LIBS"; break])  donefi@end exampleIf you were working around bugs in @code{AC_DEFINE_UNQUOTED} by addingbackslashes before quotes, you need to remove them.  It now workspredictably, and does not treat quotes (except back quotes) specially.@xref{Setting Output Variables}.All of the Boolean shell variables set by Autoconf macros now use@samp{yes} for the true value.  Most of them use @samp{no} for false,though for backward compatibility some use the empty string instead.  Ifyou were relying on a shell variable being set to something like 1 or@samp{t} for true, you need to change your tests.@node Changed Macro Writing@subsection Changed Macro WritingWhen defining your own macros, you should now use @code{AC_DEFUN}instead of @code{define}.  @code{AC_DEFUN} automatically calls@code{AC_PROVIDE} and ensures that macros called via @code{AC_REQUIRE}do not interrupt other macros, to prevent nested @samp{checking@dots{}}messages on the screen.  There's no actual harm in continuing to use theolder way, but it's less convenient and attractive.  @xref{MacroDefinitions}.You probably looked at the macros that came with Autoconf as a guide forhow to do things.  It would be a good idea to take a look at the newversions of them, as the style is somewhat improved and they takeadvantage of some new features.If you were doing tricky things with undocumented Autoconf internals(macros, variables, diversions), check whether you need to changeanything to account for changes that have been made.  Perhaps you caneven use an officially supported technique in version 2 instead ofkludging.  Or perhaps not.To speed up your locally written feature tests, add caching to them.See whether any of your tests are of general enough usefulness toencapsulate them into macros that you can share.@node Autoconf 2.13@section Upgrading From Version 2.13@cindex Upgrading autoconf@cindex Autoconf upgradingThe introduction of the previous section (@pxref{Autoconf 1}) perfectlysuits this section@enddots{}@quotationAutoconf version 2.50 is mostly backward compatible with version 2.13.However, it introduces better ways to do some things, and doesn'tsupport some of the ugly things in version 2.13.  So, depending on howsophisticated your @file{configure.ac} files are, you might have to dosome manual work in order to upgrade to version 2.50.  This chapterpoints out some problems to watch for when upgrading.  Also, perhapsyour @command{configure} scripts could benefit from some of the newfeatures in version 2.50; the changes are summarized in the file@file{NEWS} in the Autoconf distribution.@end quotation@menu* Changed Quotation::           Broken code which used to work* New Macros::                  Interaction with foreign macros* Hosts and Cross-Compilation::  Bugward compatibility kludges* AC_LIBOBJ vs LIBOBJS::        LIBOBJS is a forbidden token* AC_ACT_IFELSE vs AC_TRY_ACT::  A more generic scheme for testing sources@end menu@node Changed Quotation@subsection Changed QuotationThe most important changes are invisible to you: the implementation ofmost macros have completely changed.  This allowed more factorization ofthe code, better error messages, a higher uniformity of the user'sinterface etc.  Unfortunately, as a side effect, some construct whichused to (miraculously) work might break starting with Autoconf 2.50.The most common culprit is bad quotation.For instance, in the following example, the message is not properlyquoted:@exampleAC_INITAC_CHECK_HEADERS(foo.h, ,  AC_MSG_ERROR(cannot find foo.h, bailing out))AC_OUTPUT@end example@noindentAutoconf 2.13 simply ignores it:@example$ @kbd{autoconf-2.13; ./configure --silent}creating cache ./config.cacheconfigure: error: cannot find foo.h$@end example@noindentwhile Autoconf 2.50 produces a broken @file{configure}:@example$ @kbd{autoconf-2.50; ./configure --silent}configure: error: cannot find foo.h./configure: exit: bad non-numeric arg `bailing'./configure: exit: bad non-numeric arg `bailing'$@end exampleThe message needs to be quoted, and the @code{AC_MSG_ERROR} invocationtoo!@exampleAC_INIT([Example], [1.0], [bug-example@@example.org])AC_CHECK_HEADERS([foo.h], [],  [AC_MSG_ERROR([cannot find foo.h, bailing out])])AC_OUTPUT@end exampleMany many (and many more) Autoconf macros were lacking proper quotation,including no less than@dots{} @code{AC_DEFUN} itself!@example$ @kbd{cat configure.in}AC_DEFUN([AC_PROG_INSTALL],[# My own much better version])AC_INITAC_PROG_INSTALLAC_OUTPUT$ @kbd{autoconf-2.13}autoconf: Undefined macros:***BUG in Autoconf--please report*** AC_FD_MSG***BUG in Autoconf--please report*** AC_EPIconfigure.in:1:AC_DEFUN([AC_PROG_INSTALL],configure.in:5:AC_PROG_INSTALL$ @kbd{autoconf-2.50}$@end example@node New Macros@subsection New Macros@cindex undefined macro@cindex @code{_m4_divert_diversion}While Autoconf was relatively dormant in the late 1990s, Automakeprovided Autoconf-like macros for a while.  Starting with Autoconf 2.50in 2001, Autoconf providedversions of these macros, integrated in the @code{AC_} namespace,instead of @code{AM_}.  But in order to ease the upgrading via@command{autoupdate}, bindings to such @code{AM_} macros are provided.Unfortunately older versions of Automake (e.g., Automake 1.4)did not quote the names of these macros.Therefore, when @command{m4} finds something like@samp{AC_DEFUN(AM_TYPE_PTRDIFF_T, @dots{})} in @file{aclocal.m4},@code{AM_TYPE_PTRDIFF_T} isexpanded, replaced with its Autoconf definition.Fortunately Autoconf catches pre-@code{AC_INIT} expansions, andcomplains, in its own words:@example$ @kbd{cat configure.ac}AC_INIT([Example], [1.0], [bug-example@@example.org])AM_TYPE_PTRDIFF_T$ @kbd{aclocal-1.4}$ @kbd{autoconf}aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversionaclocal.m4:17: the top levelautom4te: m4 failed with exit status: 1$@end exampleModern versions of Automake no longer define most of thesemacros, and properly quote the names of the remaining macros.If you must use an old Automake, do not depend upon macros from Automakeas it is simply not its jobto provide macros (but the one it requires itself):@example$ @kbd{cat configure.ac}AC_INIT([Example], [1.0], [bug-example@@example.org])AM_TYPE_PTRDIFF_T$ @kbd{rm aclocal.m4}$ @kbd{autoupdate}autoupdate: `configure.ac' is updated$ @kbd{cat configure.ac}AC_INIT([Example], [1.0], [bug-example@@example.org])AC_CHECK_TYPES([ptrdiff_t])$ @kbd{aclocal-1.4}$ @kbd{autoconf}$@end example@node Hosts and Cross-Compilation@subsection Hosts and Cross-Compilation@cindex Cross compilationBased on the experience of compiler writers, and after long publicdebates, many aspects of the cross-compilation chain have changed:@itemize @minus@itemthe relationship between the build, host, and target architecture types,@itemthe command line interface for specifying them to @command{configure},@itemthe variables defined in @command{configure},@itemthe enabling of cross-compilation mode.@end itemize@sp 1The relationship between build, host, and target have been cleaned up:the chain of default is now simply: target defaults to host, host tobuild, and build to the result of @command{config.guess}.  Nevertheless,in order to ease the transition from 2.13 to 2.50, the followingtransition scheme is implemented.  @emph{Do not rely on it}, as it willbe completely disabled in a couple of releases (we cannot keep it, as itproves to cause more problems than it cures).They all default to the result of running @command{config.guess}, unlessyou specify either @option{--build} or @option{--host}.  In this case,the default becomes the system type you specified.  If you specify both,and they're different, @command{configure} enters cross compilationmode, so it doesn't run any tests that require execution.Hint: if you mean to override the result of @command{config.guess},prefer @option{--build} over @option{--host}.@sp 1For backward compatibility, @command{configure} accepts a systemtype as an option by itself.  Such an option overrides thedefaults for build, host, and target system types.  The followingconfigure statement configures a cross toolchain that runs onNetBSD/alpha but generates code for GNU Hurd/sparc,which is also the build platform.@example./configure --host=alpha-netbsd sparc-gnu@end example@sp 1In Autoconf 2.13 and before, the variables @code{build}, @code{host},and @code{target} had a different semantics before and after theinvocation of @code{AC_CANONICAL_BUILD} etc.  Now, the argument of@option{--build} is strictly copied into @code{build_alias}, and is leftempty otherwise.  After the @code{AC_CANONICAL_BUILD}, @code{build} isset to the canonicalized build type.  To ease the transition, before,its contents is the same as that of @code{build_alias}.  Do @emph{not}rely on this broken feature.For consistency with the backward compatibility scheme exposed above,when @option{--host} is specified but @option{--build} isn't, the buildsystem is assumed to be the same as @option{--host}, and@samp{build_alias} is set to that value.  Eventually, thishistorically incorrect behavior will go away.@sp 1The former scheme to enable cross-compilation proved to cause more harmthan good, in particular, it used to be triggered too easily, leavingregular end users puzzled in front of cryptic error messages.@command{configure} could even enter cross-compilation mode onlybecause the compiler was not functional.  This is mainly because@command{configure} used to try to detect cross-compilation, instead ofwaiting for an explicit flag from the user.Now, @command{configure} enters cross-compilation mode if and only if@option{--host} is passed.That's the short documentation.  To ease the transition between 2.13 andits successors, a more complicated scheme is implemented.  @emph{Do notrely on the following}, as it will be removed in the near future.If you specify @option{--host}, but not @option{--build}, when@command{configure} performs the first compiler test it tries to runan executable produced by the compiler.  If the execution fails, itenters cross-compilation mode.  This is fragile.  Moreover, by the timethe compiler test is performed, it may be too late to modify thebuild-system type: other tests may have already been performed.Therefore, whenever you specify @option{--host}, be sure to specify@option{--build} too.@example./configure --build=i686-pc-linux-gnu --host=m68k-coff@end example@noindententers cross-compilation mode.  The former interface, whichconsisted in setting the compiler to a cross-compiler without informing@command{configure} is obsolete.  For instance, @command{configure}fails if it can't run the code generated by the specified compiler if youconfigure as follows:@example./configure CC=m68k-coff-gcc@end example@node AC_LIBOBJ vs LIBOBJS@subsection @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}Up to Autoconf 2.13, the replacement of functions was triggered via thevariable @code{LIBOBJS}.  Since Autoconf 2.50, the macro@code{AC_LIBOBJ} should be used instead (@pxref{Generic Functions}).Starting at Autoconf 2.53, the use of @code{LIBOBJS} is an error.This change is mandated by the unification of the GNU Build Systemcomponents.  In particular, the various fragile techniques used to parsea @file{configure.ac} are all replaced with the use of traces.  As aconsequence, any action must be traceable, which obsoletes criticalvariable assignments.  Fortunately, @code{LIBOBJS} was the only problem,and it can even be handled gracefully (read, ``without your having tochange something'').There were two typical uses of @code{LIBOBJS}: asking for a replacementfunction, and adjusting @code{LIBOBJS} for Automake and/or Libtool.@sp 1As for function replacement, the fix is immediate: use@code{AC_LIBOBJ}.  For instance:@exampleLIBOBJS="$LIBOBJS fnmatch.o"LIBOBJS="$LIBOBJS malloc.$ac_objext"@end example@noindentshould be replaced with:@exampleAC_LIBOBJ([fnmatch])AC_LIBOBJ([malloc])@end example@sp 1@ovindex LIBOBJDIRWhen used with Automake 1.10 or newer, a suitable value for@code{LIBOBJDIR} is set so that the @code{LIBOBJS} and @code{LTLIBOBJS}can be referenced from any @file{Makefile.am}.  Even without Automake,arranging for @code{LIBOBJDIR} to be set correctly enablesreferencing @code{LIBOBJS} and @code{LTLIBOBJS} in another directory.The @code{LIBOBJDIR} feature is experimental.@node AC_ACT_IFELSE vs AC_TRY_ACT@subsection @code{AC_@var{ACT}_IFELSE} vs.@: @code{AC_TRY_@var{ACT}}@c the anchor keeps the old node name, to try to avoid breaking links@anchor{AC_FOO_IFELSE vs AC_TRY_FOO}@acindex{@var{ACT}_IFELSE}@acindex{TRY_@var{ACT}}Since Autoconf 2.50, internal codes uses @code{AC_PREPROC_IFELSE},@code{AC_COMPILE_IFELSE}, @code{AC_LINK_IFELSE}, and@code{AC_RUN_IFELSE} on one hand and @code{AC_LANG_SOURCE},and @code{AC_LANG_PROGRAM} on the other hand instead of the deprecated@code{AC_TRY_CPP}, @code{AC_TRY_COMPILE}, @code{AC_TRY_LINK}, and@code{AC_TRY_RUN}.  The motivations where:@itemize @minus@itema more consistent interface: @code{AC_TRY_COMPILE} etc.@: were doublequoting their arguments;@itemthe combinatoric explosion is solved by decomposing on the one hand thegeneration of sources, and on the other hand executing the program;@itemthis scheme helps supporting more languages than plain C and C++.@end itemizeIn addition to the change of syntax, the philosophy has changed too:while emphasis was put on speed at the expense of accuracy, today'sAutoconf promotes accuracy of the testing framework at, ahem@dots{}, theexpense of speed.As a perfect example of what is @emph{not} to be done, here is how tofind out whether a header file contains a particular declaration, suchas a typedef, a structure, a structure member, or a function.  Use@code{AC_EGREP_HEADER} instead of running @code{grep} directly on theheader file; on some systems the symbol might be defined in anotherheader file that the file you are checking includes.As a (bad) example, here is how you should not check for C preprocessorsymbols, either defined by header files or predefined by the Cpreprocessor: using @code{AC_EGREP_CPP}:@example@groupAC_EGREP_CPP(yes,[#ifdef _AIX  yes#endif], is_aix=yes, is_aix=no)@end group@end exampleThe above example, properly written would (i) use@code{AC_LANG_PROGRAM}, and (ii) run the compiler:@example@groupAC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#ifndef _AIX error: This isn't AIX!#endif]])],                   [is_aix=yes],                   [is_aix=no])@end group@end example@c ============================= Generating Test Suites with Autotest@node Using Autotest@chapter Generating Test Suites with Autotest@cindex Autotest@display@strong{N.B.: This section describes a feature which is stillstabilizing.  Although we believe that Autotest is useful as-is, thisdocumentation describes an interface which might change in the future:do not depend upon Autotest without subscribing to the Autoconf mailinglists.}@end displayIt is paradoxical that portable projects depend on nonportable toolsto run their test suite.  Autoconf by itself is the paragon of thisproblem: although it aims at perfectly portability, up to 2.13 itstest suite was using DejaGNU, a rich and complex testingframework, but which is far from being standard on Posix systems.Worse yet, it was likely to be missing on the most fragile platforms,the very platforms that are most likely to torture Autoconf andexhibit deficiencies.To circumvent this problem, many package maintainers have developed theirown testing framework, based on simple shell scripts whose sole outputsare exit status values describing whether the test succeeded.  Most ofthese tests share common patterns, and this can result in lots ofduplicated code and tedious maintenance.Following exactly the same reasoning that yielded to the inception ofAutoconf, Autotest provides a test suite generation framework, based onM4 macros building a portable shell script.  The suite itself isequipped with automatic logging and tracing facilities which greatlydiminish the interaction with bug reporters, and simple timing reports.Autoconf itself has been using Autotest for years, and we do attest thatit has considerably improved the strength of the test suite and thequality of bug reports.  Other projects are known to use some generationof Autotest, such as Bison, Free Recode, Free Wdiff, GNU Tar, each ofthem with different needs, and this usage has validated Autotest as a generaltesting framework.Nonetheless, compared to DejaGNU, Autotest is inadequate forinteractive tool testing, which is probably its main limitation.@menu* Using an Autotest Test Suite::  Autotest and the user* Writing Testsuites::          Autotest macros* testsuite Invocation::        Running @command{testsuite} scripts* Making testsuite Scripts::    Using autom4te to create @command{testsuite}@end menu@node Using an Autotest Test Suite@section Using an Autotest Test Suite@menu* testsuite Scripts::           The concepts of Autotest* Autotest Logs::               Their contents@end menu@node testsuite Scripts@subsection @command{testsuite} Scripts@cindex @command{testsuite}Generating testing or validation suites using Autotest is rather easy.The whole validation suite is held in a file to be processed through@command{autom4te}, itself using GNU M4 under the hood, toproduce a stand-alone Bourne shell script which then gets distributed.Neither @command{autom4te} nor GNU M4 are needed atthe installer's end.@cindex test groupEach test of the validation suite should be part of some test group.  A@dfn{test group} is a sequence of interwoven tests that ought to beexecuted together, usually because one test in the group creates datafiles that a later test in the same group needs to read.  Complex testgroups make later debugging more tedious.  It is much better tokeep only a few tests per test group.  Ideally there is only one testper test group.For all but the simplest packages, some file such as @file{testsuite.at}does not fully hold all test sources, as these are often easier tomaintain in separate files.  Each of these separate files holds a singletest group, or a sequence of test groups all addressing some commonfunctionality in the package.  In such cases, @file{testsuite.at}merely initializes the validation suite, and sometimes does elementaryhealth checking, before listing include statements for all other testfiles.  The special file @file{package.m4}, containing theidentification of the package, is automatically included if found.A convenient alternative consists in moving all the global issues(local Autotest macros, elementary health checking, and @code{AT_INIT}invocation) into the file @code{local.at}, and making@file{testsuite.at} be a simple list of @code{m4_include}s of sub testsuites.  In such case, generating the whole test suite or pieces of itis only a matter of choosing the @command{autom4te} command linearguments.The validation scripts that Autotest produces are by convention called@command{testsuite}.  When run, @command{testsuite} executes each testgroup in turn, producing only one summary line per test to say if thatparticular test succeeded or failed.  At end of all tests, summarizingcounters get printed.  One debugging directory is left for each testgroup which failed, if any: such directories are named@file{testsuite.dir/@var{nn}}, where @var{nn} is the sequence number ofthe test group, and they include:@itemize @bullet@item a debugging script named @file{run} which reruns the test in@dfn{debug mode} (@pxref{testsuite Invocation}).  The automatic generationof debugging scripts has the purpose of easing the chase for bugs.@item all the files created with @code{AT_DATA}@item all the Erlang source code files created with @code{AT_CHECK_EUNIT}@item a log of the run, named @file{testsuite.log}@end itemizeIn the ideal situation, none of the tests fail, and consequently nodebugging directory is left behind for validation.It often happens in practice that individual tests in the validationsuite need to get information coming out of the configuration process.Some of this information, common for all validation suites, is providedthrough the file @file{atconfig}, automatically created by@code{AC_CONFIG_TESTDIR}.  For configuration information which yourtesting environment specifically needs, you might prepare an optionalfile named @file{atlocal.in}, instantiated by @code{AC_CONFIG_FILES}.The configuration process produces @file{atconfig} and @file{atlocal}out of these two input files, and these two produced files areautomatically read by the @file{testsuite} script.Here is a diagram showing the relationship between files.@noindentFiles used in preparing a software package for distribution:@example                [package.m4] -->.                                 \subfile-1.at ->.  [local.at] ---->+    ...         \                  \subfile-i.at ---->-- testsuite.at -->-- autom4te* -->testsuite    ...         /subfile-n.at ->'@end example@noindentFiles used in configuring a software package:@example                                     .--> atconfig                                    /[atlocal.in] -->  config.status* --<                                    \                                     `--> [atlocal]@end example@noindentFiles created during test suite execution:@exampleatconfig -->.                    .--> testsuite.log             \                  /              >-- testsuite* --<             /                  \[atlocal] ->'                    `--> [testsuite.dir]@end example@node Autotest Logs@subsection Autotest LogsWhen run, the test suite creates a log file named after itself, e.g., atest suite named @command{testsuite} creates @file{testsuite.log}.  Itcontains a lot of information, usually more than maintainers actuallyneed, but therefore most of the time it contains all that is needed:@table @asis@item command line argumentsA bad but unfortunately widespread habit consists ofsetting environment variables before the command, such as in@samp{CC=my-home-grown-cc ./testsuite}.  The test suite does notknow this change, hence (i) it cannot report it to you, and (ii)it cannot preserve the value of @code{CC} for subsequent runs.Autoconf faced exactly the same problem, and solved it by askingusers to pass the variable definitions as command line arguments.Autotest requires this rule, too, but has no means to enforce it; the logthen contains a trace of the variables that were changed by the user.@item @file{ChangeLog} excerptsThe topmost lines of all the @file{ChangeLog} files found in the sourcehierarchy.  This is especially useful when bugs are reported againstdevelopment versions of the package, since the version string does notprovide sufficient information to know the exact state of the sourcesthe user compiled.  Of course, this relies on the use of a@file{ChangeLog}.@item build machineRunning a test suite in a cross-compile environment is not an easy task,since it would mean having the test suite run on a machine @var{build},while running programs on a machine @var{host}.  It is much simpler torun both the test suite and the programs on @var{host}, but then, fromthe point of view of the test suite, there remains a single environment,@var{host} = @var{build}.  The log contains relevant information on thestate of the @var{build} machine, including some important environmentvariables.@c FIXME: How about having an M4sh macro to say `hey, log the value@c of `@dots{}'?  This would help both Autoconf and Autotest.@item tested programsThe absolute file name and answers to @option{--version} of the testedprograms (see @ref{Writing Testsuites}, @code{AT_TESTED}).@item configuration logThe contents of @file{config.log}, as created by @command{configure},are appended.  It contains the configuration flags and a detailed reporton the configuration itself.@end table@node Writing Testsuites@section Writing @file{testsuite.at}The @file{testsuite.at} is a Bourne shell script making use of specialAutotest M4 macros.  It often contains a call to @code{AT_INIT} nearits beginning followed by one call to @code{m4_include} per source filefor tests.  Each such included file, or the remainder of@file{testsuite.at} if include files are not used, contain a sequence oftest groups.  Each test group begins with a call to @code{AT_SETUP},then an arbitrary number of shell commands or calls to @code{AT_CHECK},and then completes with a call to @code{AT_CLEANUP}.  Multiple testgroups can be categorized by a call to @code{AT_BANNER}.All of the public Autotest macros have all-uppercase names in thenamespace @samp{^AT_} to prevent them from accidentally conflicting withother text; Autoconf also reserves the namespace @samp{^_AT_} forinternal macros.  All shell variables used in the testsuite for internalpurposes have mostly-lowercase names starting with @samp{at_}.  Autotestalso uses here-document delimiters in the namespace @samp{^_AT[A-Z]}, andmakes use of the file system namespace @samp{^at-}.Since Autoconf is built on top of M4sugar (@pxref{Programming inM4sugar}) and M4sh (@pxref{Programming in M4sh}), you must also be awareof those namespaces (@samp{^_?\(m4\|AS\)_}).  In general, you@emph{should not use} the namespace of a package that does not own themacro or shell code you are writing.@defmac AT_INIT (@ovar{name})@atindex{INIT}@c FIXME: Not clear, plus duplication of the information.Initialize Autotest.  Giving a @var{name} to the test suite isencouraged if your package includes several test suites.  Before thismacro is called, @code{AT_PACKAGE_STRING} and@code{AT_PACKAGE_BUGREPORT} must be defined, which are used to displayinformation about the testsuite to the user.  Typically, these macrosare provided by a file @file{package.m4} built by @command{make}(@pxref{Making testsuite Scripts}), in order to inherit the packagename, version, and bug reporting address from @file{configure.ac}.@end defmac@defmac AT_COPYRIGHT (@var{copyright-notice})@atindex{COPYRIGHT}@cindex Copyright NoticeState that, in addition to the Free Software Foundation's copyright onthe Autotest macros, parts of your test suite are covered by@var{copyright-notice}.The @var{copyright-notice} shows up in both the head of@command{testsuite} and in @samp{testsuite --version}.@end defmac@defmac AT_ARG_OPTION (@var{options}, @var{help-text}, @  @ovar{action-if-given}, @ovar{action-if-not-given})@atindex{ARG_OPTION}@vrindex at_arg_@var{option}Accept options from the space-separated list @var{options}, a list thathas leading dashes removed from the options.  Long options will beprefixed with @samp{--}, single-character options with @samp{-}.  Thefirst word in this list is the primary @var{option}, any others areassumed to be short-hand aliases.  The variable associated with itis @code{at_arg_@var{option}}, with any dashes in @var{option} replacedwith underscores.If the user passes @option{--@var{option}} to the @command{testsuite},the variable will be set to @samp{:}.  If the user does not pass theoption, or passes @option{--no-@var{option}}, then the variable will beset to @samp{false}.@vrindex at_optarg@vrindex at_optarg_@var{option}@var{action-if-given} is run each time the option is encountered; here,the variable @code{at_optarg} will be set to @samp{:} or @samp{false} asappropriate.  @code{at_optarg} is actually just a copy of@code{at_arg_@var{option}}.@var{action-if-not-given} will be run once after option parsing iscomplete and if no option from @var{options} was used.@var{help-text} is added to the end of the list of options shown in@command{testsuite --help} (@pxref{AS_HELP_STRING}).It is recommended that you use a package-specific prefix to @var{options}names in order to avoid clashes with future Autotest built-in options.@end defmac@defmac AT_ARG_OPTION_ARG (@var{options}, @var{help-text}, @  @ovar{action-if-given}, @ovar{action-if-not-given})@atindex{ARG_OPTION_ARG}@vrindex at_arg_@var{option}Accept options with arguments from the space-separated list@var{options}, a list that has leading dashes removed from the options.Long options will be prefixed with @samp{--}, single-character optionswith @samp{-}.  The first word in this list is the primary @var{option},any others are assumed to be short-hand aliases.  The variable associatedwith it is @code{at_arg_@var{option}}, with any dashes in @var{option}replaced with underscores.If the user passes @option{--@var{option}=@var{arg}} or@option{--@var{option} @var{arg}} to the @command{testsuite}, thevariable will be set to @samp{@var{arg}}.@vrindex at_optarg@var{action-if-given} is run each time the option is encountered; here,the variable @code{at_optarg} will be set to @samp{@var{arg}}.@code{at_optarg} is actually just a copy of @code{at_arg_@var{option}}.@var{action-if-not-given} will be run once after option parsing iscomplete and if no option from @var{options} was used.@var{help-text} is added to the end of the list of options shown in@command{testsuite --help} (@pxref{AS_HELP_STRING}).It is recommended that you use a package-specific prefix to @var{options}names in order to avoid clashes with future Autotest built-in options.@end defmac@defmac AT_COLOR_TESTS@atindex{COLOR_TESTS}Enable colored test results by default when the output is connected toa terminal.@end defmac@defmac AT_TESTED (@var{executables})@atindex{TESTED}Log the file name and answer to @option{--version} of each program inspace-separated list @var{executables}.  Several invocations registernew executables, in other words, don't fear registering one programseveral times.Autotest test suites rely on @env{PATH} to find the tested program.This avoids the need to generate absolute names of the various tools, andmakes it possible to test installed programs.  Therefore, knowing whichprograms are being exercised is crucial to understanding problems inthe test suite itself, or its occasional misuses.  It is a good idea toalso subscribe foreign programs you depend upon, to avoid incompatiblediagnostics.@end defmac@sp 1@defmac AT_BANNER (@var{test-category-name})@atindex{BANNER}This macro identifies the start of a category of related test groups.When the resulting @file{testsuite} is invoked with more than one testgroup to run, its output will include a banner containing@var{test-category-name} prior to any tests run from that category.  Thebanner should be no more than about 40 or 50 characters.  A blank bannerindicates uncategorized tests; an empty line will be inserted aftertests from an earlier category, effectively ending that category.@end defmac@defmac AT_SETUP (@var{test-group-name})@atindex{SETUP}This macro starts a group of related tests, all to be executed in thesame subshell.  It accepts a single argument, which holds a few words(no more than about 30 or 40 characters) quickly describing the purposeof the test group being started.  @var{test-group-name} must not expandto unbalanced quotes, although quadrigraphs can be used.@end defmac@defmac AT_KEYWORDS (@var{keywords})@atindex{KEYWORDS}Associate the space-separated list of @var{keywords} to the enclosingtest group.  This makes it possible to run ``slices'' of the test suite.For instance, if some of your test groups exercise some @samp{foo}feature, then using @samp{AT_KEYWORDS(foo)} lets you run@samp{./testsuite -k foo} to run exclusively these test groups.  The@var{test-group-name} of the test group is automatically recorded to@code{AT_KEYWORDS}.Several invocations within a test group accumulate new keywords.  Inother words, don't fear registering the same keyword several times in atest group.@end defmac@defmac AT_CAPTURE_FILE (@var{file})@atindex{CAPTURE_FILE}If the current test group fails, log the contents of @var{file}.Several identical calls within one test group have no additional effect.@end defmac@defmac AT_FAIL_IF (@var{shell-condition})@atindex{FAIL_IF}Make the test group fail and skip the rest of its execution, if@var{shell-condition} is true.  @var{shell-condition} is a shell expressionsuch as a @code{test} command.  Tests before @command{AT_FAIL_IF}will be executed and may still cause the test group to be skipped.You can instantiate this macro many times from within the same test group.You should use this macro only for very simple failure conditions.  If the@var{shell-condition} could emit any kind of output you should insteaduse @command{AT_CHECK} like@exampleAT_CHECK([if @var{shell-condition}; then exit 99; fi])@end example@noindentso that such output is properly recorded in the @file{testsuite.log}file.@end defmac@defmac AT_SKIP_IF (@var{shell-condition})@atindex{SKIP_IF}Determine whether the test should be skipped because it requiresfeatures that are unsupported on the machine under test.@var{shell-condition} is a shell expression such as a @code{test}command.  Tests before @command{AT_SKIP_IF} will be executedand may still cause the test group to fail.  You can instantiate thismacro many times from within the same test group.You should use this macro only for very simple skip conditions.  If the@var{shell-condition} could emit any kind of output you should insteaduse @command{AT_CHECK} like@exampleAT_CHECK([if @var{shell-condition}; then exit 77; fi])@end example@noindentso that such output is properly recorded in the @file{testsuite.log}file.@end defmac@defmac AT_XFAIL_IF (@var{shell-condition})@atindex{XFAIL_IF}Determine whether the test is expected to fail because it is a knownbug (for unsupported features, you should skip the test).@var{shell-condition} is a shell expression such as a @code{test}command; you can instantiate this macro many times from within thesame test group, and one of the conditions is enough to turnthe test into an expected failure.@end defmac@defmac AT_CLEANUP@atindex{CLEANUP}End the current test group.@end defmac@sp 1@defmac AT_DATA (@var{file}, @var{contents})@atindex{DATA}Initialize an input data @var{file} with given @var{contents}.  Ofcourse, the @var{contents} have to be properly quoted between squarebrackets to protect against included commas or spurious M4expansion.  @var{contents} must be empty or end with a newline.@var{file} mustbe a single shell word that expands into a single file name.@end defmac@defmac AT_CHECK (@var{commands}, @dvar{status, 0}, @ovar{stdout}, @  @ovar{stderr}, @ovar{run-if-fail}, @ovar{run-if-pass})@defmacx AT_CHECK_UNQUOTED (@var{commands}, @dvar{status, 0}, @ovar{stdout}, @  @ovar{stderr}, @ovar{run-if-fail}, @ovar{run-if-pass})@atindex{CHECK}@atindex{CHECK_UNQUOTED}@vrindex at_statusExecute a test by performing given shell @var{commands} in a subshell.@var{commands} is output as-is, so shell expansions are honored.  Thesecommands should normally exit with @var{status}, while producing expected@var{stdout} and @var{stderr} contents.  If @var{commands} exit withunexpected status 77, then the rest of the test group is skipped.  If@var{commands} exit with unexpected status 99, then the test group isimmediately failed.  Otherwise, if this test fails, run shell commands@var{run-if-fail} or, if this test passes, run shell commands@var{run-if-pass}, both inside the current shell execution environment.At the beginning of @var{run-if-fail} and @var{run-if-pass}, the status of@var{commands} is available in the @code{at_status} shell variable.This macro must be invoked in between @code{AT_SETUP} and @code{AT_CLEANUP}.If @var{status} is the literal @samp{ignore}, then the correspondingexit status is not checked, except for the special cases of 77 (skip)and 99 (hard failure).  The existence of hard failures allows one tomark a test as an expected failure with @code{AT_XFAIL_IF} because afeature has not yet been implemented, but to still distinguish betweengracefully handling the missing feature and dumping core.  A hardfailure also inhibits post-test actions in @var{run-if-fail}.If the value of the @var{stdout} or @var{stderr} parameter is one of theliterals in the following table, then the test treats the outputaccording to the rules of that literal.  Otherwise, the value of theparameter is treated as text that must exactly match the output given by@var{commands} on standard output and standard error (including an emptyparameter for no output); any differences are captured in the testsuitelog and the test is failed (unless an unexpected exit status of 77skipped the test instead).  The difference between @code{AT_CHECK} and@code{AT_CHECK_UNQUOTED} is that only the latter performs shell variableexpansion (@samp{$}), command substitution (@samp{`}), and backslashescaping (@samp{\}) on comparison text given in the @var{stdout} and@var{stderr} arguments; if the text includes a trailing newline, thiswould be the same as if it were specified via an unquotedhere-document.  (However, there is no difference in the interpretationof @var{commands}).@table @samp@item ignoreThe content of the output is ignored, but still captured in the testgroup log (if the testsuite is run with option @option{-v}, the testgroup log is displayed as the test is run; if the test group laterfails, the test group log is also copied into the overall testsuitelog).  This action is valid for both @var{stdout} and @var{stderr}.@item ignore-nologThe content of the output is ignored, and nothing is captured in the logfiles.  If @var{commands} are likely to produce binary output (includinglong lines) or large amounts of output, then logging the output can makeit harder to locate details related to subsequent tests within thegroup, and could potentially corrupt terminal display of a user running@command{testsuite -v}.@item stdoutFor the @var{stdout} parameter, capture the content of standard outputto both the file @file{stdout} and the test group log.  Subsequentcommands in the test group can then post-process the file.  This actionis often used when it is desired to use @command{grep} to look for asubstring in the output, or when the output must be post-processed tonormalize error messages into a common form.@item stderrLike @samp{stdout}, except that it only works for the @var{stderr}parameter, and the standard error capture file will be named@file{stderr}.@item stdout-nolog@itemx stderr-nologLike @samp{stdout} or @samp{stderr}, except that the captured output isnot duplicated into the test group log.  This action is particularlyuseful for an intermediate check that produces large amounts of data,which will be followed by another check that filters down to therelevant data, as it makes it easier to locate details in the log.@item expoutFor the @var{stdout} parameter, compare standard output contents withthe previously created file @file{expout}, and list any differences inthe testsuite log.@item experrLike @samp{expout}, except that it only works for the @var{stderr}parameter, and the standard error contents are compared with@file{experr}.@end table@end defmac@defmac AT_CHECK_EUNIT (@var{module}, @var{test-spec}, @ovar{erlflags}, @  @ovar{run-if-fail}, @ovar{run-if-pass})@atindex{CHECK_EUNIT}Initialize and execute an Erlang module named @var{module} that performstests following the @var{test-spec} EUnit test specification.@var{test-spec} must be a valid EUnit test specification, as defined inthe @uref{http://@/erlang.org/@/doc/@/apps/@/eunit/@/index.html, EUnitReference Manual}.  @var{erlflags} are optional command-line optionspassed to the Erlang interpreter to execute the test Erlang module.Typically, @var{erlflags} defines at least the paths to directoriescontaining the compiled Erlang modules under test, as @samp{-pa path1path2 ...}.For example, the unit tests associated with Erlang module @samp{testme},which compiled code is in subdirectory @file{src}, can be performedwith:@exampleAT_CHECK_EUNIT([testme_testsuite], [@{module, testme@}],               [-pa "$@{abs_top_builddir@}/src"])@end exampleThis macro must be invoked in between @code{AT_SETUP} and @code{AT_CLEANUP}.Variables @code{ERL}, @code{ERLC}, and (optionally) @code{ERLCFLAGS}must be defined as the path of the Erlang interpreter, the path of theErlang compiler, and the command-line flags to pass to the compiler,respectively.  Those variables should be configured in@file{configure.ac} using the @command{AC_ERLANG_PATH_ERL} and@command{AC_ERLANG_PATH_ERLC} macros, and the configured values of thosevariables are automatically defined in the testsuite.  If @code{ERL} or@code{ERLC} is not defined, the test group is skipped.If the EUnit library cannot be found, i.e. if module @code{eunit} cannotbe loaded, the test group is skipped.  Otherwise, if @var{test-spec} isan invalid EUnit test specification, the test group fails.  Otherwise,if the EUnit test passes, shell commands @var{run-if-pass} are executedor, if the EUnit test fails, shell commands @var{run-if-fail} areexecuted and the test group fails.Only the generated test Erlang module is automatically compiled andexecuted.  If @var{test-spec} involves testing other Erlang modules,e.g. module @samp{testme} in the example above, those modules must bealready compiled.If the testsuite is run in verbose mode, with option @option{--verbose},EUnit is also run in verbose mode to output more details aboutindividual unit tests.@end defmac@node testsuite Invocation@section Running @command{testsuite} Scripts@cindex @command{testsuite}Autotest test suites support the following options:@table @option@item --help@itemx -hDisplay the list of options and exit successfully.@item --version@itemx -VDisplay the version of the test suite and exit successfully.@item --directory=@var{dir}@itemx -C @var{dir}Change the current directory to @var{dir} before creating any files.Useful for running the testsuite in a subdirectory from a top-levelMakefile.@item --jobs@r{[}=@var{n}@r{]}@itemx -j@ovar{n}Run @var{n} tests in parallel, if possible.  If @var{n} is not given,run all given tests in parallel.  Note that there should be no spacebefore the argument to @option{-j}, as @option{-j @var{number}} denotesthe separate arguments @option{-j} and @option{@var{number}}, see below.In parallel mode, the standard input device of the testsuite script isnot available to commands inside a test group.  Furthermore, bannerlines are not printed, and the summary line for each test group isoutput after the test group completes.  Summary lines may appearunordered.  If verbose and trace output are enabled (see below), theymay appear intermixed from concurrently running tests.Parallel mode requires the @command{mkfifo} command to work, and will besilently disabled otherwise.@item --clean@itemx -cRemove all the files the test suite might have created and exit.  Meantfor @code{clean} Make targets.@item --list@itemx -lList all the tests (or only the selection), including their possiblekeywords.@end table@sp 1By default all tests are performed (or described with @option{--list})silently in the default environment, but the environment, set of tests,and verbosity level can be tuned:@table @samp@item @var{variable}=@var{value}Set the environment @var{variable} to @var{value}.  Use this ratherthan @samp{FOO=foo ./testsuite} as debugging scripts would then run in adifferent environment.@cindex @code{AUTOTEST_PATH}The variable @code{AUTOTEST_PATH} specifies the testing path to prependto @env{PATH}.  Relative directory names (not starting with@samp{/}) are considered to be relative to the top level of thepackage being built.  All directories are made absolute, firststarting from the top level @emph{build} tree, then from the@emph{source} tree.  For instance @samp{./testsuiteAUTOTEST_PATH=tests:bin} for a @file{/src/foo-1.0} source package builtin @file{/tmp/foo} results in @samp{/tmp/foo/tests:/tmp/foo/bin} andthen @samp{/src/foo-1.0/tests:/src/foo-1.0/bin} being prepended to@env{PATH}.@item @var{number}@itemx @var{number}-@var{number}@itemx @var{number}-@itemx -@var{number}Add the corresponding test groups, with obvious semantics, to theselection.@item --keywords=@var{keywords}@itemx -k @var{keywords}Add to the selection the test groups with title or keywords (argumentsto @code{AT_SETUP} or @code{AT_KEYWORDS}) that match @emph{all} keywordsof the comma separated list @var{keywords}, case-insensitively.  Use@samp{!} immediately before the keyword to invert the selection for thiskeyword.  By default, the keywords match whole words; enclose them in@samp{.*} to also match parts of words.For example, running@example@kbd{./testsuite -k 'autoupdate,.*FUNC.*'}@end example@noindentselects all tests tagged @samp{autoupdate} @emph{and} with tagscontaining @samp{FUNC} (as in @samp{AC_CHECK_FUNC}, @samp{AC_FUNC_ALLOCA},etc.), while@example@kbd{./testsuite -k '!autoupdate' -k '.*FUNC.*'}@end example@noindentselects all tests not tagged @samp{autoupdate} @emph{or} with tagscontaining @samp{FUNC}.@item --errexit@itemx -eIf any test fails, immediately abort testing.  This implies@option{--debug}: post test group clean up, and top-level loggingare inhibited.  This option is meant for the full testsuite, it is not really useful for generated debugging scripts.If the testsuite is run in parallel mode using @option{--jobs},then concurrently running tests will finish before exiting.@item --verbose@itemx -vForce more verbosity in the detailed output of what is being done.  Thisis the default for debugging scripts.@item --color@itemx --color@r{[}=never@r{|}auto@r{|}always@r{]}Enable colored test results.  Without an argument, or with @samp{always},test results will be colored.  With @samp{never}, color mode is turnedoff.  Otherwise, if either the macro @code{AT_COLOR_TESTS} is used bythe testsuite author, or the argument @samp{auto} is given, then testresults are colored if standard output is connected to a terminal.@item --debug@itemx -dDo not remove the files after a test group was performed---but they arestill removed @emph{before}, therefore using this option is sane whenrunning several test groups.  Create debugging scripts.  Do notoverwrite the top-levellog (in order to preserve a supposedly existing full log file).  This isthe default for debugging scripts, but it can also be useful to debugthe testsuite itself.@item --recheckAdd to the selection all test groups that failed or passed unexpectedlyduring the last non-debugging test run.@item --trace@itemx -xTrigger shell tracing of the test groups.@end tableBesides these options accepted by every Autotest testsuite, thetestsuite author might have added package-specific optionsvia the @code{AT_ARG_OPTION} and @code{AT_ARG_OPTION_ARG} macros(@pxref{Writing Testsuites}); refer to @command{testsuite --help} andthe package documentation for details.@node Making testsuite Scripts@section Making @command{testsuite} ScriptsFor putting Autotest into movement, you need some configuration andmakefile machinery.  We recommend, at least if your package uses deep orshallow hierarchies, that you use @file{tests/} as the name of thedirectory holding all your tests and their makefile.  Here is acheck list of things to do.@itemize @minus@item@cindex @file{package.m4}@atindex{PACKAGE_STRING}@atindex{PACKAGE_BUGREPORT}@atindex{PACKAGE_NAME}@atindex{PACKAGE_TARNAME}@atindex{PACKAGE_VERSION}@atindex{PACKAGE_URL}Make sure to create the file @file{package.m4}, which defines theidentity of the package.  It must define @code{AT_PACKAGE_STRING}, thefull signature of the package, and @code{AT_PACKAGE_BUGREPORT}, theaddress to which bug reports should be sent.  For sake of completeness,we suggest that you also define @code{AT_PACKAGE_NAME},@code{AT_PACKAGE_TARNAME}, @code{AT_PACKAGE_VERSION}, and@code{AT_PACKAGE_URL}.@xref{Initializing configure}, for a description of these variables.Be sure to distribute @file{package.m4} and to put it into the sourcehierarchy: the test suite ought to be shipped!  See below for an example@file{Makefile} excerpt.@itemInvoke @code{AC_CONFIG_TESTDIR}.@defmac AC_CONFIG_TESTDIR (@var{directory}, @dvar{test-path, directory})@acindex{CONFIG_TESTDIR}An Autotest test suite is to be configured in @var{directory}.  Thismacro causes @file{@var{directory}/atconfig} to be created by@command{config.status} and sets the default @code{AUTOTEST_PATH} to@var{test-path} (@pxref{testsuite Invocation}).@end defmac@itemStill within @file{configure.ac}, as appropriate, ensure that some@code{AC_CONFIG_FILES} command includes substitution for@file{tests/atlocal}.@itemThe appropriate @file{Makefile} should be modified so the validation inyour package is triggered by @samp{make check}.  An example is providedbelow.@end itemizeWith Automake, here is a minimal example for inclusion in@file{tests/Makefile.am}, in order to link @samp{make check} with avalidation suite.@example# The `:;' works around a Bash 3.2 bug when the output is not writable.$(srcdir)/package.m4: $(top_srcdir)/configure.ac        :;@{ \          echo '# Signature of the current package.' && \          echo 'm4_define([AT_PACKAGE_NAME],' && \          echo '  [$(PACKAGE_NAME)])' && \          echo 'm4_define([AT_PACKAGE_TARNAME],' && \          echo '  [$(PACKAGE_TARNAME)])' && \          echo 'm4_define([AT_PACKAGE_VERSION],' && \          echo '  [$(PACKAGE_VERSION)])' && \          echo 'm4_define([AT_PACKAGE_STRING],' && \          echo '  [$(PACKAGE_STRING)])' && \          echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \          echo '  [$(PACKAGE_BUGREPORT)])'; \          echo 'm4_define([AT_PACKAGE_URL],' && \          echo '  [$(PACKAGE_URL)])'; \        @} >'$(srcdir)/package.m4'EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) atlocal.inTESTSUITE = $(srcdir)/testsuitecheck-local: atconfig atlocal $(TESTSUITE)        $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)installcheck-local: atconfig atlocal $(TESTSUITE)        $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \          $(TESTSUITEFLAGS)clean-local:        test ! -f '$(TESTSUITE)' || \         $(SHELL) '$(TESTSUITE)' --cleanAUTOM4TE = $(SHELL) $(srcdir)/build-aux/missing --run autom4teAUTOTEST = $(AUTOM4TE) --language=autotest$(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4        $(AUTOTEST) -I '$(srcdir)' -o $@@.tmp $@@.at        mv $@@.tmp $@@@end exampleNote that the built testsuite is distributed; this is necessary becauseusers might not have Autoconf installed, and thus would not be able torebuild it.  Likewise, the use of @file{missing} provides the user witha nicer error message if they modify a source file to the testsuite, andaccidentally trigger the rebuild rules.You might want to list explicitly the dependencies, i.e., the list ofthe files @file{testsuite.at} includes.If you don't use Automake, you should include the above example in@file{tests/@/Makefile.in}, along with additional lines inspired fromthe following:@examplesubdir = testsPACKAGE_NAME = @@PACKAGE_NAME@@PACKAGE_TARNAME = @@PACKAGE_TARNAME@@PACKAGE_VERSION = @@PACKAGE_VERSION@@PACKAGE_STRING = @@PACKAGE_STRING@@PACKAGE_BUGREPORT = @@PACKAGE_BUGREPORT@@PACKAGE_URL = @@PACKAGE_URL@@atconfig: $(top_builddir)/config.status        cd $(top_builddir) && \           $(SHELL) ./config.status $(subdir)/$@@atlocal: $(srcdir)/atlocal.in $(top_builddir)/config.status        cd $(top_builddir) && \           $(SHELL) ./config.status $(subdir)/$@@@end example@noindentand manage to have @code{$(EXTRA_DIST)} distributed.  You will also wantto distribute the file @file{build-aux/@/missing} from the Automakeproject; a copy of this file resides in the Autoconf source tree.With all this in place, and if you have not initialized @samp{TESTSUITEFLAGS}within your makefile, you can fine-tune test suite execution with thisvariable, for example:@examplemake check TESTSUITEFLAGS='-v -d -x 75 -k AC_PROG_CC CFLAGS=-g'@end example@c =============================== Frequent Autoconf Questions, with answers@node FAQ@chapter Frequent Autoconf Questions, with answersSeveral questions about Autoconf come up occasionally.  Here some of themare addressed.@menu* Distributing::                Distributing @command{configure} scripts* Why GNU M4::                  Why not use the standard M4?* Bootstrapping::               Autoconf and GNU M4 require each other?* Why Not Imake::               Why GNU uses @command{configure} instead of Imake* Defining Directories::        Passing @code{datadir} to program* Autom4te Cache::              What is it?  Can I remove it?* Present But Cannot Be Compiled::  Compiler and Preprocessor Disagree* Expanded Before Required::    Expanded Before Required* Debugging::                   Debugging @command{configure} scripts@end menu@node Distributing@section Distributing @command{configure} Scripts@cindex License@displayWhat are the restrictions on distributing @command{configure}scripts that Autoconf generates?  How does that affect myprograms that use them?@end displayThere are no restrictions on how the configuration scripts that Autoconfproduces may be distributed or used.  In Autoconf version 1, they werecovered by the GNU General Public License.  We still encouragesoftware authors to distribute their work under terms like those of theGPL, but doing so is not required to use Autoconf.Of the other files that might be used with @command{configure},@file{config.h.in} is under whatever copyright you use for your@file{configure.ac}.  @file{config.sub} and @file{config.guess} have anexception to the GPL when they are used with an Autoconf-generated@command{configure} script, which permits you to distribute them under thesame terms as the rest of your package.  @file{install-sh} is from the XConsortium and is not copyrighted.@node Why GNU M4@section Why Require GNU M4?@displayWhy does Autoconf require GNU M4?@end displayMany M4 implementations have hard-coded limitations on the size andnumber of macros that Autoconf exceeds.  They also lack severalbuiltin macros that it would be difficult to get along without in asophisticated application like Autoconf, including:@examplem4_builtinm4_indirm4_bpatsubst__file____line__@end exampleAutoconf requires version 1.4.6 or later of GNU M4.Since only software maintainers need to use Autoconf, and since GNUM4 is simple to configure and install, it seems reasonable to requireGNU M4 to be installed also.  Many maintainers of GNU andother free software already have most of the GNU utilitiesinstalled, since they prefer them.@node Bootstrapping@section How Can I Bootstrap?@cindex Bootstrap@displayIf Autoconf requires GNU M4 and GNU M4 has an Autoconf@command{configure} script, how do I bootstrap?  It seems like a chickenand egg problem!@end displayThis is a misunderstanding.  Although GNU M4 does come with a@command{configure} script produced by Autoconf, Autoconf is not requiredin order to run the script and install GNU M4.  Autoconf is onlyrequired if you want to change the M4 @command{configure} script, which fewpeople have to do (mainly its maintainer).@node Why Not Imake@section Why Not Imake?@cindex Imake@displayWhy not use Imake instead of @command{configure} scripts?@end displaySeveral people have written addressing this question, soadaptations of their explanations are included here.The following answer is based on one written by Richard Pixley:@quotationAutoconf generated scripts frequently work on machines that it hasnever been set up to handle before.  That is, it does a good job ofinferring a configuration for a new system.  Imake cannot do this.Imake uses a common database of host specific data.  For X11, this makessense because the distribution is made as a collection of tools, by onecentral authority who has control over the database.GNU tools are not released this way.  Each GNU tool has amaintainer; these maintainers are scattered across the world.  Using acommon database would be a maintenance nightmare.  Autoconf may appearto be this kind of database, but in fact it is not.  Instead of listinghost dependencies, it lists program requirements.If you view the GNU suite as a collection of native tools, then theproblems are similar.  But the GNU development tools can beconfigured as cross tools in almost any host+target permutation.  All ofthese configurations can be installed concurrently.  They can even beconfigured to share host independent files across hosts.  Imake doesn'taddress these issues.Imake templates are a form of standardization.  The GNU codingstandards address the same issues without necessarily imposing the samerestrictions.@end quotationHere is some further explanation, written by Per Bothner:@quotationOne of the advantages of Imake is that it is easy to generate largemakefiles using the @samp{#include} and macro mechanisms of @command{cpp}.However, @code{cpp} is not programmable: it has limited conditionalfacilities, and no looping.  And @code{cpp} cannot inspect itsenvironment.All of these problems are solved by using @code{sh} instead of@code{cpp}.  The shell is fully programmable, has macro substitution,can execute (or source) other shell scripts, and can inspect itsenvironment.@end quotationPaul Eggert elaborates more:@quotationWith Autoconf, installers need not assume that Imake itself is alreadyinstalled and working well.  This may not seem like much of an advantageto people who are accustomed to Imake.  But on many hosts Imake is notinstalled or the default installation is not working well, and requiringImake to install a package hinders the acceptance of that package onthose hosts.  For example, the Imake template and configuration filesmight not be installed properly on a host, or the Imake build proceduremight wrongly assume that all source files are in one big directorytree, or the Imake configuration might assume one compiler whereas thepackage or the installer needs to use another, or there might be aversion mismatch between the Imake expected by the package and the Imakesupported by the host.  These problems are much rarer with Autoconf,where each package comes with its own independent configurationprocessor.Also, Imake often suffers from unexpected interactions between@command{make} and the installer's C preprocessor.  The fundamental problemhere is that the C preprocessor was designed to preprocess C programs,not makefiles.  This is much less of a problem with Autoconf,which uses the general-purpose preprocessor M4, and where thepackage's author (rather than the installer) does the preprocessing in astandard way.@end quotationFinally, Mark Eichin notes:@quotationImake isn't all that extensible, either.  In order to add new features toImake, you need to provide your own project template, and duplicate mostof the features of the existing one.  This means that for a sophisticatedproject, using the vendor-provided Imake templates fails to provide anyleverage---since they don't cover anything that your own project needs(unless it is an X11 program).On the other side, though:The one advantage that Imake has over @command{configure}:@file{Imakefile} files tend to be much shorter (likewise, less redundant)than @file{Makefile.in} files.  There is a fix to this, however---at leastfor the Kerberos V5 tree, we've modified things to call in common@file{post.in} and @file{pre.in} makefile fragments for theentire tree.  This means that a lot of common things don't have to beduplicated, even though they normally are in @command{configure} setups.@end quotation@node Defining Directories@section How Do I @code{#define} Installation Directories?@displayMy program needs library files, installed in @code{datadir} andsimilar.  If I use@exampleAC_DEFINE_UNQUOTED([DATADIR], [$datadir],  [Define to the read-only architecture-independent   data directory.])@end example@noindentI get@example#define DATADIR "$@{prefix@}/share"@end example@end displayAs already explained, this behavior is on purpose, mandated by theGNU Coding Standards, see @ref{Installation DirectoryVariables}.  There are several means to achieve a similar goal:@itemize @minus@itemDo not use @code{AC_DEFINE} but use your makefile to pass theactual value of @code{datadir} via compilation flags.@xref{Installation Directory Variables}, for the details.@itemThis solution can be simplified when compiling a program: you may eitherextend the @code{CPPFLAGS}:@exampleCPPFLAGS = -DDATADIR='"$(datadir)"' @@CPPFLAGS@@@end example@noindentIf you are using Automake, you should use @code{AM_CPPFLAGS} instead:@exampleAM_CPPFLAGS = -DDATADIR='"$(datadir)"'@end example@noindentAlternatively, create a dedicated header file:@exampleDISTCLEANFILES = myprog-paths.hmyprog-paths.h: Makefile        echo '#define DATADIR "$(datadir)"' >$@@@end example@noindentThe gnulib module @samp{configmake} provides such a header with all thestandard directory variables defined, @pxref{configmake,,, gnulib, GNUGnulib}.@itemUse @code{AC_DEFINE} but have @command{configure} compute the literalvalue of @code{datadir} and others.  Many people have wrapped macros toautomate this task; for an example, see the macro @code{AC_DEFINE_DIR} fromthe @uref{http://@/www.gnu.org/@/software/@/autoconf-archive/, Autoconf MacroArchive}.This solution does not conform to the GNU Coding Standards.@itemNote that all the previous solutions hard wire the absolute name ofthese directories in the executables, which is not a good property.  Youmay try to compute the names relative to @code{prefix}, and try tofind @code{prefix} at runtime, this way your package is relocatable.@end itemize@node Autom4te Cache@section What is @file{autom4te.cache}?@displayWhat is this directory @file{autom4te.cache}?  Can I safely remove it?@end displayIn the GNU Build System, @file{configure.ac} plays a centralrole and is read by many tools: @command{autoconf} to create@file{configure}, @command{autoheader} to create @file{config.h.in},@command{automake} to create @file{Makefile.in}, @command{autoscan} tocheck the completeness of @file{configure.ac}, @command{autoreconf} tocheck the GNU Build System components that are used.  To``read @file{configure.ac}'' actually means to compile it with M4,which can be a long process for complex @file{configure.ac}.This is why all these tools, instead of running directly M4, invoke@command{autom4te} (@pxref{autom4te Invocation}) which, while answering toa specific demand, stores additional information in@file{autom4te.cache} for future runs.  For instance, if you run@command{autoconf}, behind the scenes, @command{autom4te} alsostores information for the other tools, so that when you invoke@command{autoheader} or @command{automake} etc., reprocessing@file{configure.ac} is not needed.  The speed up is frequently 30%,and is increasing with the size of @file{configure.ac}.But it is and remains being simply a cache: you can safely remove it.@sp 1@displayCan I permanently get rid of it?@end displayThe creation of this cache can be disabled from@file{~/.autom4te.cfg}, see @ref{Customizing autom4te}, for moredetails.  You should be aware that disabling the cache slows down theAutoconf test suite by 40%.  The more GNU Build Systemcomponents are used, the more the cache is useful; for instancerunning @samp{autoreconf -f} on the Core Utilities is twice slower withoutthe cache @emph{although @option{--force} implies that the cache isnot fully exploited}, and eight times slower than without@option{--force}.@node Present But Cannot Be Compiled@section Header Present But Cannot Be CompiledThe most important guideline to bear in mind when checking forfeatures is to mimic as much as possible the intended use.Unfortunately, old versions of @code{AC_CHECK_HEADER} and@code{AC_CHECK_HEADERS} failed to follow this idea, and calledthe preprocessor, instead of the compiler, to check for headers.  As aresult, incompatibilities between headers went unnoticed duringconfiguration, and maintainers finally had to deal with this issueelsewhere.The transition began with Autoconf 2.56.  As of Autoconf 2.64 bothchecks are performed, and @command{configure} complains loudly if thecompiler and the preprocessor do not agree.  However, only the compilerresult is considered.Consider the following example:@smallexample$ @kbd{cat number.h}typedef int number;$ @kbd{cat pi.h}const number pi = 3;$ @kbd{cat configure.ac}AC_INIT([Example], [1.0], [bug-example@@example.org])AC_CHECK_HEADERS([pi.h])$ @kbd{autoconf -Wall}$ @kbd{./configure}checking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables...checking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ISO C89... none neededchecking how to run the C preprocessor... gcc -Echecking for grep that handles long lines and -e... grepchecking for egrep... grep -Echecking for ANSI C header files... yeschecking for sys/types.h... yeschecking for sys/stat.h... yeschecking for stdlib.h... yeschecking for string.h... yeschecking for memory.h... yeschecking for strings.h... yeschecking for inttypes.h... yeschecking for stdint.h... yeschecking for unistd.h... yeschecking pi.h usability... nochecking pi.h presence... yesconfigure: WARNING: pi.h: present but cannot be compiledconfigure: WARNING: pi.h:     check for missing prerequisite headers?configure: WARNING: pi.h: see the Autoconf documentationconfigure: WARNING: pi.h:     section "Present But Cannot Be Compiled"configure: WARNING: pi.h: proceeding with the compiler's resultconfigure: WARNING:     ## -------------------------------------- ##configure: WARNING:     ## Report this to bug-example@@example.org ##configure: WARNING:     ## -------------------------------------- ##checking for pi.h... yes@end smallexample@noindentThe proper way the handle this case is using the fourth argument(@pxref{Generic Headers}):@example$ @kbd{cat configure.ac}AC_INIT([Example], [1.0], [bug-example@@example.org])AC_CHECK_HEADERS([number.h pi.h], [], [],[[#ifdef HAVE_NUMBER_H# include <number.h>#endif]])$ @kbd{autoconf -Wall}$ @kbd{./configure}checking for gcc... gccchecking for C compiler default output... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... nochecking for suffix of executables...checking for suffix of object files... ochecking whether we are using the GNU C compiler... yeschecking whether gcc accepts -g... yeschecking for gcc option to accept ANSI C... none neededchecking for number.h... yeschecking for pi.h... yes@end exampleSee @ref{Particular Headers}, for a list of headers with theirprerequisites.@node Expanded Before Required@section Expanded Before Required@cindex expanded before requiredOlder versions of Autoconf silently built files with incorrect orderingbetween dependent macros if an outer macro first expanded, then laterindirectly required, an inner macro.  Starting with Autoconf 2.64, thissituation no longer generates out-of-order code, but results induplicate output and a syntax warning:@example$ @kbd{cat configure.ac}@result{}AC_DEFUN([TESTA], [[echo in A@result{}if test -n "$SEEN_A" ; then echo duplicate ; fi@result{}SEEN_A=:]])@result{}AC_DEFUN([TESTB], [AC_REQUIRE([TESTA])[echo in B@result{}if test -z "$SEEN_A" ; then echo bug ; fi]])@result{}AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])@result{}AC_DEFUN([OUTER], [[echo in OUTER]@result{}TESTA@result{}TESTC])@result{}AC_INIT@result{}OUTER@result{}AC_OUTPUT$ @kbd{autoconf}@result{}configure.ac:11: warning: AC_REQUIRE:@result{} `TESTA' was expanded before it was required@result{}configure.ac:4: TESTB is expanded from...@result{}configure.ac:6: TESTC is expanded from...@result{}configure.ac:7: OUTER is expanded from...@result{}configure.ac:11: the top level@end example@noindentTo avoid this warning, decide what purpose the macro in question serves.If it only needs to be expanded once (for example, if it providesinitialization text used by later macros), then the simplest fix is tochange the macro to be declared with @code{AC_DEFUN_ONCE}(@pxref{One-Shot Macros}), although this only works in Autoconf 2.64 andnewer.  A more portable fix is to change allinstances of direct calls to instead go through @code{AC_REQUIRE}(@pxref{Prerequisite Macros}).  If, instead, the macro is parameterizedby arguments or by the current definition of other macros in the m4environment, then the macro should always be directly expanded insteadof required.For another case study, consider this example trimmed down from anactual package.  Originally, the package contained shell code andmultiple macro invocations at the top level of @file{configure.ac}:@exampleAC_DEFUN([FOO], [AC_COMPILE_IFELSE([@dots{}])])foobar=AC_PROG_CCFOO@end example@noindentbut that was getting complex, so the author wanted to offload some ofthe text into a new macro in another file included via@file{aclocal.m4}.  The na@"ive approach merely wraps the text in a newmacro:@exampleAC_DEFUN([FOO], [AC_COMPILE_IFELSE([@dots{}])])AC_DEFUN([BAR], [foobar=AC_PROG_CCFOO])BAR@end example@noindentWith older versions of Autoconf, the setting of @samp{foobar=} occursbefore the single compiler check, as the author intended.  But withAutoconf 2.64, this issues the ``expanded before it was required''warning for @code{AC_PROG_CC}, and outputs two copies of the compilercheck, one before @samp{foobar=}, and one after.  To understand why thisis happening, remember that the use of @code{AC_COMPILE_IFELSE} includesa call to @code{AC_REQUIRE([AC_PROG_CC])} under the hood.  According tothe documented semantics of @code{AC_REQUIRE}, this means that@code{AC_PROG_CC} @emph{must} occur before the body of the outermost@code{AC_DEFUN}, which in this case is @code{BAR}, thus preceding theuse of @samp{foobar=}.  The older versions of Autoconf were broken withregards to the rules of @code{AC_REQUIRE}, which explains why the codechanged from one over to two copies of @code{AC_PROG_CC} when upgradingautoconf.  In other words, the author was unknowingly relying on a bugexploit to get the desired results, and that exploit broke once the bugwas fixed.So, what recourse does the author have, to restore their intendedsemantics of setting @samp{foobar=} prior to a single compiler check,regardless of whether Autoconf 2.63 or 2.64 is used?  One idea is toremember that only @code{AC_DEFUN} is impacted by @code{AC_REQUIRE};there is always the possibility of using the lower-level@code{m4_define}:@exampleAC_DEFUN([FOO], [AC_COMPILE_IFELSE([@dots{}])])m4_define([BAR], [foobar=AC_PROG_CCFOO])BAR@end example@noindentThis works great if everything is in the same file.  However, it doesnot help in the case where the author wants to have @command{aclocal}find the definition of @code{BAR} from its own file, since@command{aclocal} requires the use of @code{AC_DEFUN}.  In this case, abetter fix is to recognize that if @code{BAR} also uses@code{AC_REQUIRE}, then there will no longer be direct expansion priorto a subsequent require.  Then, by creating yet another helper macro,the author can once again guarantee a single invocation of@code{AC_PROG_CC}, which will still occur after @code{foobar=}.  Theauthor can also use @code{AC_BEFORE} to make sure no other macroappearing before @code{BAR} has triggered an unwanted expansion of@code{AC_PROG_CC}.@exampleAC_DEFUN([FOO], [AC_COMPILE_IFELSE([@dots{}])])AC_DEFUN([BEFORE_CC], [foobar=])AC_DEFUN([BAR], [AC_BEFORE([$0], [AC_PROG_CC])dnlAC_REQUIRE([BEFORE_CC])dnlAC_REQUIRE([AC_PROG_CC])dnlFOO])BAR@end example@node Debugging@section Debugging @command{configure} scriptsWhile in general, @command{configure} scripts generated by Autoconfstrive to be fairly portable to various systems, compilers, shells, andother tools, it may still be necessary to debug a failing test, brokenscript or makefile, or fix or override an incomplete, faulty, or erroneoustest, especially during macro development.  Failures can occur at all levels,in M4 syntax or semantics, shell script issues, or due to bugs in thetest or the tools invoked by @command{configure}.  Together with therather arcane error message that @command{m4} and @command{make} mayproduce when their input contains syntax errors, this can make debuggingrather painful.Nevertheless, here is a list of hints and strategies that may help:@itemize@itemWhen @command{autoconf} fails, common causes for error include:@itemize@itemmismatched or unbalanced parentheses or braces (@pxref{BalancingParentheses}),@item under- or overquoted macro arguments (@pxref{AutoconfLanguage}, @pxref{Quoting and Parameters}, @pxref{Quotation and NestedMacros}),@item spaces between macro name and opening parenthesis (@pxref{AutoconfLanguage}).@end itemizeTypically, it helps to go back to the last working version of the inputand compare the differences for each of these errors.  Anotherpossibility is to sprinkle pairs of @code{m4_traceon} and@code{m4_traceoff} judiciously in the code, either without a parameteror listing some macro names and watch @command{m4} expand its inputverbosely (@pxref{Debugging via autom4te}).@itemSometimes @command{autoconf} succeeds but the generated@command{configure} script has invalid shell syntax.  You can detect thiscase by running @samp{bash -n configure} or @samp{sh -n configure}.If this command fails, the same tips apply, as if @command{autoconf} hadfailed.@itemDebugging @command{configure} script execution may be done by sprinklingpairs of @code{set -x} and @code{set +x} into the shell script beforeand after the region that contains a bug.  Running the whole script with@samp{@var{shell} -vx ./configure 2>&1 | tee @var{log-file}} with a decent@var{shell} may work, but produces lots of output.  Here, it can help tosearch for markers like @samp{checking for} a particular test in the@var{log-file}.@itemAlternatively, you might use a shell with debugging capabilities like@uref{http://bashdb.sourceforge.net/, bashdb}.@itemWhen @command{configure} tests produce invalid results for your system,it may be necessary to override them:@itemize@itemFor programs, tools or libraries variables, preprocessor, compiler, orlinker flags, it is often sufficient to override them at @command{make}run time with some care (@pxref{Macros and Submakes}).  Since thisnormally won't cause @command{configure} to be run again with thesechanged settings, it may fail if the changed variable would have causeddifferent test results from @command{configure}, so this may work onlyfor simple differences.@itemMost tests which produce their result in a substituted variable allow tooverride the test by setting the variable on the @command{configure}command line (@pxref{Compilers and Options}, @pxref{Defining Variables},@pxref{Particular Systems}).@itemMany tests store their result in a cache variable (@pxref{CachingResults}).  This lets you override them either on the@command{configure} command line as above, or through a primed cache orsite file (@pxref{Cache Files}, @pxref{Site Defaults}).  The name of acache variable is documented with a test macro or may be inferred from@ref{Cache Variable Names}; the precise semantics of undocumentedvariables are often internal details, subject to change.@end itemize@itemAlternatively, @command{configure} may produce invalid results becauseof uncaught programming errors, in your package or in an upstreamlibrary package.  For example, when @code{AC_CHECK_LIB} fails to find alibrary with a specified function, always check @file{config.log}.  Thiswill reveal the exact error that produced the failing result: thelibrary linked by @code{AC_CHECK_LIB} probably has a fatal bug.@end itemizeConversely, as macro author, you can make it easier for users of yourmacro:@itemize@itemby minimizing dependencies between tests and between test results as faras possible,@itemby using @command{make} variables to factorize and allowoverride of settings at @command{make} run time,@itemby honoring the GNU Coding Standards and not overriding flagsreserved for the user except temporarily during @command{configure}tests,@itemby not requiring users of your macro to use the cache variables.Instead, expose the result of the test via @var{run-if-true} and@var{run-if-false} parameters.  If the result is not a boolean,then provide it through documented shell variables.@end itemize@c ===================================================== History of Autoconf.@node History@chapter History of Autoconf@cindex History of autoconf@emph{This chapter was written by the original author, David MacKenzie.}You may be wondering, Why was Autoconf originally written?  How did itget into its present form?  (Why does it look like gorilla spit?)  Ifyou're not wondering, then this chapter contains no information usefulto you, and you might as well skip it.  If you @emph{are} wondering,then let there be light@enddots{}@menu* Genesis::                     Prehistory and naming of @command{configure}* Exodus::                      The plagues of M4 and Perl* Leviticus::                   The priestly code of portability arrives* Numbers::                     Growth and contributors* Deuteronomy::                 Approaching the promises of easy configuration@end menu@node Genesis@section GenesisIn June 1991 I was maintaining many of the GNU utilities for theFree Software Foundation.  As they were ported to more platforms andmore programs were added, the number of @option{-D} options that usershad to select in the makefile (around 20) became burdensome.Especially for me---I had to test each new release on a bunch ofdifferent systems.  So I wrote a little shell script to guess some ofthe correct settings for the fileutils package, and released it as partof fileutils 2.0.  That @command{configure} script worked well enough thatthe next month I adapted it (by hand) to create similar @command{configure}scripts for several other GNU utilities packages.  Brian Berlineralso adapted one of my scripts for his CVS revision control system.Later that summer, I learned that Richard Stallman and Richard Pixleywere developing similar scripts to use in the GNU compiler tools;so I adapted my @command{configure} scripts to support their evolvinginterface: using the file name @file{Makefile.in} as the templates;adding @samp{+srcdir}, the first option (of many); and creating@file{config.status} files.@node Exodus@section ExodusAs I got feedback from users, I incorporated many improvements, usingEmacs to search and replace, cut and paste, similar changes in each ofthe scripts.  As I adapted more GNU utilities packages to use@command{configure} scripts, updating them all by hand became impractical.Rich Murphey, the maintainer of the GNU graphics utilities, sent memail saying that the @command{configure} scripts were great, and asking ifI had a tool for generating them that I could send him.  No, I thought,but I should!  So I started to work out how to generate them.  And thejourney from the slavery of hand-written @command{configure} scripts to theabundance and ease of Autoconf began.Cygnus @command{configure}, which was being developed at around that time,is table driven; it is meant to deal mainly with a discrete number ofsystem types with a small number of mainly unguessable features (such asdetails of the object file format).  The automatic configuration systemthat Brian Fox had developed for Bash takes a similar approach.  Forgeneral use, it seems to me a hopeless cause to try to maintain anup-to-date database of which features each variant of each operatingsystem has.  It's easier and more reliable to check for most features onthe fly---especially on hybrid systems that people have hacked onlocally or that have patches from vendors installed.I considered using an architecture similar to that of Cygnus@command{configure}, where there is a single @command{configure} script thatreads pieces of @file{configure.in} when run.  But I didn't want to haveto distribute all of the feature tests with every package, so I settledon having a different @command{configure} made from each@file{configure.in} by a preprocessor.  That approach also offered morecontrol and flexibility.I looked briefly into using the Metaconfig package, by Larry Wall,Harlan Stenn, and Raphael Manfredi, but I decided not to for severalreasons.  The @command{Configure} scripts it produces are interactive,which I find quite inconvenient; I didn't like the ways it checked forsome features (such as library functions); I didn't know that it wasstill being maintained, and the @command{Configure} scripts I hadseen didn't work on many modern systems (such as System V R4 and NeXT);it wasn't flexible in what it could do in response to a feature'spresence or absence; I found it confusing to learn; and it was too bigand complex for my needs (I didn't realize then how much Autoconf wouldeventually have to grow).I considered using Perl to generate my style of @command{configure}scripts, but decided that M4 was better suited to the job of simpletextual substitutions: it gets in the way less, because output isimplicit.  Plus, everyone already has it.  (Initially I didn't rely onthe GNU extensions to M4.)  Also, some of my friends at theUniversity of Maryland had recently been putting M4 front ends onseveral programs, including @code{tvtwm}, and I was interested in tryingout a new language.@node Leviticus@section LeviticusSince my @command{configure} scripts determine the system's capabilitiesautomatically, with no interactive user intervention, I decided to callthe program that generates them Autoconfig.  But with a version numbertacked on, that name would be too long for old Unix file systems,so I shortened it to Autoconf.In the fall of 1991 I called together a group of fellow questers afterthe Holy Grail of portability (er, that is, alpha testers) to give mefeedback as I encapsulated pieces of my handwritten scripts in M4 macrosand continued to add features and improve the techniques used in thechecks.  Prominent among the testers were Fran@,{c}ois Pinard, who came upwith the idea of making an Autoconf shell script to run M4and check for unresolved macro calls; Richard Pixley, who suggestedrunning the compiler instead of searching the file system to findinclude files and symbols, for more accurate results; Karl Berry, whogot Autoconf to configure @TeX{} and added the macro index to thedocumentation; and Ian Lance Taylor, who added support for creating a Cheader file as an alternative to putting @option{-D} options in amakefile, so he could use Autoconf for his UUCP package.The alpha testers cheerfully adjusted their files again and again as thenames and calling conventions of the Autoconf macros changed fromrelease to release.  They all contributed many specific checks, greatideas, and bug fixes.@node Numbers@section NumbersIn July 1992, after months of alpha testing, I released Autoconf 1.0,and converted many GNU packages to use it.  I was surprised by howpositive the reaction to it was.  More people started using it than Icould keep track of, including people working on software that wasn'tpart of the GNU Project (such as TCL, FSP, and Kerberos V5).Autoconf continued to improve rapidly, as many people using the@command{configure} scripts reported problems they encountered.Autoconf turned out to be a good torture test for M4 implementations.Unix M4 started to dump core because of the length of themacros that Autoconf defined, and several bugs showed up in GNUM4 as well.  Eventually, we realized that we needed to use somefeatures that only GNU M4 has.  4.3BSD M4, inparticular, has an impoverished set of builtin macros; the System Vversion is better, but still doesn't provide everything we need.More development occurred as people put Autoconf under more stresses(and to uses I hadn't anticipated).  Karl Berry added checks for X11.david zuhn contributed C++ support.  Fran@,{c}ois Pinard made it diagnoseinvalid arguments.  Jim Blandy bravely coerced it into configuringGNU Emacs, laying the groundwork for several later improvements.Roland McGrath got it to configure the GNU C Library, wrote the@command{autoheader} script to automate the creation of C header filetemplates, and added a @option{--verbose} option to @command{configure}.Noah Friedman added the @option{--autoconf-dir} option and@code{AC_MACRODIR} environment variable.  (He also coined the term@dfn{autoconfiscate} to mean ``adapt a software package to useAutoconf''.)  Roland and Noah improved the quoting protection in@code{AC_DEFINE} and fixed many bugs, especially when I got sick ofdealing with portability problems from February through June, 1993.@node Deuteronomy@section DeuteronomyA long wish list for major features had accumulated, and the effect ofseveral years of patching by various people had left some residualcruft.  In April 1994, while working for Cygnus Support, I began a majorrevision of Autoconf.  I added most of the features of the Cygnus@command{configure} that Autoconf had lacked, largely by adapting therelevant parts of Cygnus @command{configure} with the help of david zuhnand Ken Raeburn.  These features include support for using@file{config.sub}, @file{config.guess}, @option{--host}, and@option{--target}; making links to files; and running @command{configure}scripts in subdirectories.  Adding these features enabled Ken to convertGNU @code{as}, and Rob Savoye to convert DejaGNU, to usingAutoconf.I added more features in response to other peoples' requests.  Manypeople had asked for @command{configure} scripts to share the results ofthe checks between runs, because (particularly when configuring a largesource tree, like Cygnus does) they were frustratingly slow.  MikeHaertel suggested adding site-specific initialization scripts.  Peopledistributing software that had to unpack on MS-DOS asked for a way tooverride the @file{.in} extension on the file names, which produced filenames like @file{config.h.in} containing two dots.  Jim Avera did anextensive examination of the problems with quoting in @code{AC_DEFINE}and @code{AC_SUBST}; his insights led to significant improvements.Richard Stallman asked that compiler output be sent to @file{config.log}instead of @file{/dev/null}, to help people debug the Emacs@command{configure} script.I made some other changes because of my dissatisfaction with the qualityof the program.  I made the messages showing results of the checks lessambiguous, always printing a result.  I regularized the names of themacros and cleaned up coding style inconsistencies.  I added someauxiliary utilities that I had developed to help convert source codepackages to use Autoconf.  With the help of Fran@,{c}ois Pinard, I madethe macros not interrupt each others' messages.  (That feature revealedsome performance bottlenecks in GNU M4, which he hastilycorrected!)  I reorganized the documentation around problems people wantto solve.  And I began a test suite, because experience had shown thatAutoconf has a pronounced tendency to regress when we change it.Again, several alpha testers gave invaluable feedback, especiallyFran@,{c}ois Pinard, Jim Meyering, Karl Berry, Rob Savoye, Ken Raeburn,and Mark Eichin.Finally, version 2.0 was ready.  And there was much rejoicing.  (And Ihave free time again.  I think.  Yeah, right.)@c ========================================================== Appendices@node GNU Free Documentation License@appendix GNU Free Documentation License@include fdl.texi@node Indices@appendix Indices@menu* Environment Variable Index::  Index of environment variables used* Output Variable Index::       Index of variables set in output files* Preprocessor Symbol Index::   Index of C preprocessor symbols defined* Cache Variable Index::        Index of documented cache variables* Autoconf Macro Index::        Index of Autoconf macros* M4 Macro Index::              Index of M4, M4sugar, and M4sh macros* Autotest Macro Index::        Index of Autotest macros* Program & Function Index::    Index of those with portability problems* Concept Index::               General index@end menu@node Environment Variable Index@appendixsec Environment Variable IndexThis is an alphabetical list of the environment variables that mightinfluence Autoconf checks.@printindex ev@node Output Variable Index@appendixsec Output Variable IndexThis is an alphabetical list of the variables that Autoconf cansubstitute into files that it creates, typically one or moremakefiles.  @xref{Setting Output Variables}, for more informationon how this is done.@printindex ov@node Preprocessor Symbol Index@appendixsec Preprocessor Symbol IndexThis is an alphabetical list of the C preprocessor symbols that theAutoconf macros define.  To work with Autoconf, C source code needs touse these names in @code{#if} or @code{#ifdef} directives.@printindex cv@node Cache Variable Index@appendixsec Cache Variable IndexThis is an alphabetical list of documented cache variables usedby macros defined in Autoconf.  Autoconf macros may use additional cachevariables internally.@ifset shortindexflagTo make the list easier to use, the variables are listed without theirpreceding @samp{ac_cv_}.@end ifset@printindex CA@node Autoconf Macro Index@appendixsec Autoconf Macro IndexThis is an alphabetical list of the Autoconf macros.@ifset shortindexflagTo make the list easier to use, the macros are listed without theirpreceding @samp{AC_}.@end ifset@printindex AC@node M4 Macro Index@appendixsec M4 Macro IndexThis is an alphabetical list of the M4, M4sugar, and M4sh macros.@ifset shortindexflagTo make the list easier to use, the macros are listed without theirpreceding @samp{m4_} or @samp{AS_}.  The prefix is @samp{m4_} forall-lowercase macro names and @samp{AS_} for all-uppercase macronames.@end ifset@printindex MS@node Autotest Macro Index@appendixsec Autotest Macro IndexThis is an alphabetical list of the Autotest macros.@ifset shortindexflagTo make the list easier to use, the macros are listed without theirpreceding @samp{AT_}.@end ifset@printindex AT@node Program & Function Index@appendixsec Program and Function IndexThis is an alphabetical list of the programs and functions whoseportability is discussed in this document.@printindex pr@node Concept Index@appendixsec Concept IndexThis is an alphabetical list of the files, tools, and conceptsintroduced in this document.@printindex cp@bye@c  LocalWords:  texinfo setfilename autoconf texi settitle setchapternewpage@c  LocalWords:  setcontentsaftertitlepage finalout ARG ovar varname dvar acx@c  LocalWords:  makeinfo dvi defcodeindex ev ov CPP cv Autotest mv defindex fn@c  LocalWords:  shortindexflag iftex ifset acindex ACindex ifclear ahindex fu@c  LocalWords:  asindex MSindex atindex ATindex auindex hdrindex prindex FIXME@c  LocalWords:  msindex alloca fnindex Aaarg indices FSF's dircategory ifnames@c  LocalWords:  direntry autoscan autoreconf autoheader autoupdate config FDs@c  LocalWords:  testsuite titlepage Elliston Demaille vskip filll ifnottex hmm@c  LocalWords:  insertcopying Autoconf's detailmenu Automake Libtool Posix ois@c  LocalWords:  Systemology Checkpointing Changequote INTERCAL changequote dfn@c  LocalWords:  Quadrigraphs builtins Shellology acconfig Bugward LIBOBJ Imake@c  LocalWords:  LIBOBJS IFELSE cindex flushright Pinard Metaconfig uref Simons@c  LocalWords:  distclean uninstall noindent versioning Tromey dir@c  LocalWords:  SAMS samp aclocal acsite underquoted emph itemx prepend SUBST@c  LocalWords:  evindex automake Gettext autopoint gettext symlink libtoolize@c  LocalWords:  defmac INIT tarname ovindex cvindex BUGREPORT PREREQ asis PROG@c  LocalWords:  SRCDIR srcdir globbing afterwards cmds foos fooo foooo init cd@c  LocalWords:  builddir timestamp src Imakefile chmod defvar CFLAGS CPPFLAGS@c  LocalWords:  CXXFLAGS DEFS DHAVE defvarx FCFLAGS FFLAGS LDFLAGS bindir GCC@c  LocalWords:  datadir datarootdir docdir dvidir htmldir libdir ifnothtml kbd@c  LocalWords:  includedir infodir libexecdir localedir localstatedir mandir@c  LocalWords:  oldincludedir pdfdir PDF psdir PostScript sbindir sysconfdir@c  LocalWords:  sharedstatedir DDATADIR sed tmp pkgdatadir VPATH conf unistd@c  LocalWords:  undef endif builtin FUNCS ifndef STACKSEG getb GETB YMP fubar@c  LocalWords:  PRE dest SUBDIRS subdirs fi struct STDC stdlib stddef INTTYPES@c  LocalWords:  inttypes STDINT stdint AWK AIX Solaris NeXT env EGREP FGREP yy@c  LocalWords:  LEXLIB YYTEXT lfl nonportable Automake's LN RANLIB byacc INETD@c  LocalWords:  inetd prog PROGS progs ranlib lmp lXt lX nsl gethostbyname UX@c  LocalWords:  NextStep isinf isnan glibc IRIX sunmath lm lsunmath pre sizeof@c  LocalWords:  ld inline malloc putenv setenv FreeBSD realloc SunOS MinGW@c  LocalWords:  snprintf vsnprintf sprintf vsprintf sscanf gcc strerror ifdef@c  LocalWords:  strnlen sysconf PAGESIZE unsetenv va fallback memcpy dst FUNC@c  LocalWords:  PowerPC GNUC libPW pragma Olibcalls CHOWN chown CLOSEDIR VFORK@c  LocalWords:  closedir FNMATCH fnmatch vfork FSEEKO LARGEFILE fseeko SVR sc@c  LocalWords:  largefile GETGROUPS getgroups GETLOADAVG DGUX UMAX NLIST KMEM@c  LocalWords:  SETGID getloadavg nlist GETMNTENT irix@c  LocalWords:  getmntent UnixWare GETPGRP getpgid getpgrp Posix's pid LSTAT@c  LocalWords:  lstat rpl MEMCMP memcmp OpenStep MBRTOWC mbrtowc MKTIME mktime@c  LocalWords:  localtime MMAP mmap OBSTACK obstack obstacks ARGTYPES timeval@c  LocalWords:  SETPGRP setpgrp defmacx Hurd SETVBUF setvbuf STRCOLL strcoll@c  LocalWords:  STRTOD strtod DECL STRFTIME strftime SCO UTIME utime VPRINTF@c  LocalWords:  DOPRNT vprintf doprnt sp unfixable LIBSOURCE LIBSOURCES Eggert@c  LocalWords:  linux netinet ia Tru XFree DIRENT NDIR dirent ndir multitable@c  LocalWords:  NAMLEN strlen namlen MKDEV SYSMACROS makedev RESOLV resolv DNS@c  LocalWords:  inet structs NAMESER arpa NETDB netdb UTekV UTS GCC's kB@c  LocalWords:  STDBOOL BOOL stdbool cplusplus bool Bool stdarg tm@c  LocalWords:  ctype strchr strrchr rindex bcopy memmove memchr WEXITSTATUS@c  LocalWords:  WIFEXITED TIOCGWINSZ GWINSZ termios preprocess preprocessable@c  LocalWords:  DECLS strdup calloc BLKSIZE blksize RDEV rdev TZNAME tzname pw@c  LocalWords:  passwd gecos pwd MBSTATE mbstate wchar RETSIGTYPE hup UID uid@c  LocalWords:  gid ptrdiff uintmax EXEEXT OBJEXT Ae conftest AXP str@c  LocalWords:  ALIGNOF WERROR Werror cpp HP's WorkShop egcs un fied stdc CXX@c  LocalWords:  varargs BIGENDIAN Endianness SPARC endianness grep'ed CONST FC@c  LocalWords:  const STRINGIZE stringizing PARAMS unprotoize protos KCC cxx@c  LocalWords:  xlC aCC CXXCPP FREEFORM xlf FLIBS FCLIBS ish SRCEXT XTRA LFS@c  LocalWords:  ISC lcposix MINIX Minix conditionalized inlines hw dD confdefs@c  LocalWords:  fputs stdout PREPROC ar UFS HFS QNX realtime fstype STATVFS se@c  LocalWords:  statvfs STATFS statfs func machfile hdr lelf raboof DEFUN GTK@c  LocalWords:  GTKMM Grmph ified ine defn baz EOF qar Ahhh changecom algol io@c  LocalWords:  changeword quadrigraphs quadrigraph dnl SGI atoi overquoting@c  LocalWords:  Aas Wcross sep args namespace undefine bpatsubst popdef dquote@c  LocalWords:  bregexp Overquote overquotation meisch maisch meische maische@c  LocalWords:  miscian DIRNAME dirname MKDIR CATFILE XMKMF TRAVOLTA celsius@c  LocalWords:  EMX emxos Emacsen Korn DYNIX subshell posix Ksh ksh Pdksh Zsh@c  LocalWords:  pdksh zsh Allbery Lipe Kubota UWS zorglub stderr eval esac lfn@c  LocalWords:  drivespec Posixy DJGPP doschk prettybird LPT pfew Zsh's yu yaa@c  LocalWords:  yM uM aM firebird IP subdir misparses ok Unpatched abc bc zA@c  LocalWords:  CDPATH DUALCASE LINENO prepass Subshells lineno NULLCMD cmp wc@c  LocalWords:  MAILPATH scanset arg NetBSD Almquist printf expr cp@c  LocalWords:  Oliva awk Aaaaarg cmd regex xfoo GNV OpenVMS VM@c  LocalWords:  sparc Proulx nbar nfoo maxdepth acdilrtu TWG mc@c  LocalWords:  mkdir exe uname OpenBSD Fileutils mktemp umask TMPDIR guid os@c  LocalWords:  fooXXXXXX Unicos utimes hpux hppa unescaped@c  LocalWords:  pmake DOS's gmake ifoo DESTDIR autoconfiscated pc coff mips gg@c  LocalWords:  dec ultrix cpu wildcards rpcc rdtsc powerpc readline@c  LocalWords:  withval vxworks gless localcache usr LOFF loff CYGWIN Cygwin@c  LocalWords:  cygwin SIGLIST siglist SYSNDIR SYSDIR ptx lseq rusage elif MSC@c  LocalWords:  lfoo POUNDBANG lsun NIS getpwnam SYSCALLS RSH INTL lintl aix@c  LocalWords:  intl lx ldir syslog bsd EPI toolchain netbsd objext de KNR nn@c  LocalWords:  fication LTLIBOBJS Wdiff TESTDIR atconfig atlocal akim XFAIL@c  LocalWords:  ChangeLog prepended errexit smallexample TESTSUITEFLAGS GPL er@c  LocalWords:  installcheck autotest indir Pixley Bothner Eichin Kerberos adl@c  LocalWords:  DISTCLEANFILES preprocessor's fileutils Stallman Murphey Stenn@c  LocalWords:  Manfredi Autoconfig TCL FSP david zuhn Blandy MACRODIR Raeburn@c  LocalWords:  autoconfiscate Savoye Haertel Avera Meyering fdl appendixsec@c  LocalWords:  printindex american LIBOBJDIR LibdirTest ERLCFLAGS OBJCFLAGS@c  LocalWords:  VER Gnulib online xyes strcpy TYPEOF typeof OBJC objcc objc ln@c  LocalWords:  GOBJC OTP ERLC erl valloc decr dumpdef errprint incr@c  LocalWords:  esyscmd len maketemp pushdef substr syscmd sysval translit txt@c  LocalWords:  sinclude foreach myvar tolower toupper uniq BASENAME STDIN@c  LocalWords:  Dynix basename aname cname macroexpands xno xcheck@c  LocalWords:  LIBREADLINE lreadline lncurses libreadline@c Local Variables:@c fill-column: 72@c ispell-local-dictionary: "american"@c indent-tabs-mode: nil@c whitespace-check-buffer-indent: nil@c End:
 |