2
0

autoconf.texi 951 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667
  1. \input texinfo @c -*-texinfo-*-
  2. @comment ========================================================
  3. @comment %**start of header
  4. @setfilename autoconf.info
  5. @include version.texi
  6. @settitle Autoconf
  7. @setchapternewpage odd
  8. @ifnothtml
  9. @setcontentsaftertitlepage
  10. @end ifnothtml
  11. @finalout
  12. @c @ovar(ARG)
  13. @c ----------
  14. @c The ARG is an optional argument. To be used for macro arguments in
  15. @c their documentation (@defmac).
  16. @macro ovar{varname}
  17. @r{[}@var{\varname\}@r{]}@c
  18. @end macro
  19. @c @dvar(ARG, DEFAULT)
  20. @c -------------------
  21. @c The ARG is an optional argument, defaulting to DEFAULT. To be used
  22. @c for macro arguments in their documentation (@defmac).
  23. @macro dvar{varname, default}
  24. @r{[}@var{\varname\} = @samp{\default\}@r{]}@c
  25. @end macro
  26. @c Handling the indexes with Texinfo yields several different problems.
  27. @c
  28. @c Because we want to drop out the AC_ part of the macro names in the
  29. @c printed manual, but not in the other outputs, we need a layer above
  30. @c the usual @acindex{} etc. That's why we first define indexes such as
  31. @c acx meant to become the macro @acindex. First of all, using ``ac_''
  32. @c does not work with makeinfo, and using ``ac1'' doesn't work with TeX.
  33. @c So use something more regular ``acx''. Then you finish with a printed
  34. @c index saying ``index is not existent''. Of course: you ought to use
  35. @c two letters :( So you use capitals.
  36. @c
  37. @c Second, when defining a macro in the TeX world, following spaces are
  38. @c eaten. But then, since we embed @acxindex commands that use the end
  39. @c of line as an end marker, the whole things wrecks itself. So make
  40. @c sure you do *force* an additional end of line, add a ``@c''.
  41. @c
  42. @c Finally, you might want to get rid of TeX expansion, using --expand
  43. @c with texi2dvi. But then you wake up an old problem: we use macros
  44. @c in @defmac etc. where TeX does perform the expansion, but not makeinfo.
  45. @c Define an environment variable index, for variables users may set
  46. @c in their environment or on the configure command line.
  47. @defcodeindex ev
  48. @c Define an output variable index, for commonly AC_SUBST'ed variables.
  49. @defcodeindex ov
  50. @c Define a cache variable index, for variables matching *_cv_*.
  51. @defcodeindex CA
  52. @c Other shell variables not fitting the above categories should be
  53. @c listed in the predefined vrindex, which we merge in the concept index.
  54. @syncodeindex vr cp
  55. @c Define a CPP preprocessor macro index, for #define'd strings.
  56. @defcodeindex cv
  57. @c Define an Autoconf macro index that @defmac doesn't write to.
  58. @defcodeindex AC
  59. @c Define an Autotest macro index that @defmac doesn't write to.
  60. @defcodeindex AT
  61. @c Define an M4sugar macro index that @defmac doesn't write to.
  62. @defcodeindex MS
  63. @c Define an index for *foreign* programs: `mv' etc. Used for the
  64. @c portability sections and so on.
  65. @defindex pr
  66. @c shortindexflag
  67. @c --------------
  68. @c Shall we factor AC_ out of the Autoconf macro index etc.?
  69. @iftex
  70. @set shortindexflag
  71. @end iftex
  72. @c @acindex{MACRO}
  73. @c ---------------
  74. @c Registering an AC_\MACRO\.
  75. @ifset shortindexflag
  76. @macro acindex{macro}
  77. @ACindex \macro\
  78. @c
  79. @end macro
  80. @end ifset
  81. @ifclear shortindexflag
  82. @macro acindex{macro}
  83. @ACindex AC_\macro\
  84. @end macro
  85. @end ifclear
  86. @c @ahindex{MACRO}
  87. @c ---------------
  88. @c Registering an AH_\MACRO\.
  89. @macro ahindex{macro}
  90. @ACindex AH_\macro\
  91. @c
  92. @end macro
  93. @c @asindex{MACRO}
  94. @c ---------------
  95. @c Registering an AS_\MACRO\.
  96. @ifset shortindexflag
  97. @macro asindex{macro}
  98. @MSindex \macro\
  99. @c
  100. @end macro
  101. @end ifset
  102. @ifclear shortindexflag
  103. @macro asindex{macro}
  104. @MSindex AS_\macro\
  105. @end macro
  106. @end ifclear
  107. @c @atindex{MACRO}
  108. @c ---------------
  109. @c Registering an AT_\MACRO\.
  110. @ifset shortindexflag
  111. @macro atindex{macro}
  112. @ATindex \macro\
  113. @c
  114. @end macro
  115. @end ifset
  116. @ifclear shortindexflag
  117. @macro atindex{macro}
  118. @ATindex AT_\macro\
  119. @end macro
  120. @end ifclear
  121. @c @auindex{MACRO}
  122. @c ---------------
  123. @c Registering an AU_\MACRO\.
  124. @macro auindex{macro}
  125. @ACindex AU_\macro\
  126. @c
  127. @end macro
  128. @c @hdrindex{MACRO}
  129. @c ----------------
  130. @c Indexing a header.
  131. @macro hdrindex{macro}
  132. @prindex @file{\macro\}
  133. @c
  134. @end macro
  135. @c @msindex{MACRO}
  136. @c ---------------
  137. @c Registering an m4_\MACRO\.
  138. @ifset shortindexflag
  139. @macro msindex{macro}
  140. @MSindex \macro\
  141. @c
  142. @end macro
  143. @end ifset
  144. @ifclear shortindexflag
  145. @macro msindex{macro}
  146. @MSindex m4_\macro\
  147. @end macro
  148. @end ifclear
  149. @c @caindex{VARIABLE}
  150. @c ------------------
  151. @c Registering an ac_cv_\VARIABLE\ cache variable.
  152. @ifset shortindexflag
  153. @macro caindex{macro}
  154. @CAindex \macro\
  155. @end macro
  156. @end ifset
  157. @ifclear shortindexflag
  158. @macro caindex{macro}
  159. @CAindex ac_cv_\macro\
  160. @end macro
  161. @end ifclear
  162. @c Define an index for functions: `alloca' etc. Used for the
  163. @c portability sections and so on. We can't use `fn' (aka `fnindex),
  164. @c since `@defmac' goes into it => we'd get all the macros too.
  165. @c FIXME: Aaarg! It seems there are too many indices for TeX :(
  166. @c
  167. @c ! No room for a new @write .
  168. @c l.112 @defcodeindex fu
  169. @c
  170. @c so don't define yet another one :( Just put some tags before each
  171. @c @prindex which is actually a @funindex.
  172. @c
  173. @c @defcodeindex fu
  174. @c
  175. @c
  176. @c @c Put the programs and functions into their own index.
  177. @c @syncodeindex fu pr
  178. @comment %**end of header
  179. @comment ========================================================
  180. @copying
  181. This manual (@value{UPDATED}) is for GNU Autoconf
  182. (version @value{VERSION}),
  183. a package for creating scripts to configure source code packages using
  184. templates and an M4 macro package.
  185. Copyright @copyright{} 1992-1996, 1998-2012 Free Software Foundation,
  186. Inc.
  187. @quotation
  188. Permission is granted to copy, distribute and/or modify this document
  189. under the terms of the GNU Free Documentation License,
  190. Version 1.3 or any later version published by the Free Software
  191. Foundation; with no Invariant Sections, no Front-Cover texts, and
  192. no Back-Cover Texts. A copy of the license is included in the section
  193. entitled ``GNU Free Documentation License.''
  194. @end quotation
  195. @end copying
  196. @dircategory Software development
  197. @direntry
  198. * Autoconf: (autoconf). Create source code configuration scripts.
  199. @end direntry
  200. @dircategory Individual utilities
  201. @direntry
  202. * autoscan: (autoconf)autoscan Invocation.
  203. Semi-automatic @file{configure.ac} writing
  204. * ifnames: (autoconf)ifnames Invocation. Listing conditionals in source.
  205. * autoconf-invocation: (autoconf)autoconf Invocation.
  206. How to create configuration scripts
  207. * autoreconf: (autoconf)autoreconf Invocation.
  208. Remaking multiple @command{configure} scripts
  209. * autoheader: (autoconf)autoheader Invocation.
  210. How to create configuration templates
  211. * autom4te: (autoconf)autom4te Invocation.
  212. The Autoconf executables backbone
  213. * configure: (autoconf)configure Invocation. Configuring a package.
  214. * autoupdate: (autoconf)autoupdate Invocation.
  215. Automatic update of @file{configure.ac}
  216. * config.status: (autoconf)config.status Invocation. Recreating configurations.
  217. * testsuite: (autoconf)testsuite Invocation. Running an Autotest test suite.
  218. @end direntry
  219. @titlepage
  220. @title Autoconf
  221. @subtitle Creating Automatic Configuration Scripts
  222. @subtitle for version @value{VERSION}, @value{UPDATED}
  223. @author David MacKenzie
  224. @author Ben Elliston
  225. @author Akim Demaille
  226. @page
  227. @vskip 0pt plus 1filll
  228. @insertcopying
  229. @end titlepage
  230. @contents
  231. @ifnottex
  232. @node Top
  233. @top Autoconf
  234. @insertcopying
  235. @end ifnottex
  236. @c The master menu, created with texinfo-master-menu, goes here.
  237. @menu
  238. * Introduction:: Autoconf's purpose, strengths, and weaknesses
  239. * The GNU Build System:: A set of tools for portable software packages
  240. * Making configure Scripts:: How to organize and produce Autoconf scripts
  241. * Setup:: Initialization and output
  242. * Existing Tests:: Macros that check for particular features
  243. * Writing Tests:: How to write new feature checks
  244. * Results:: What to do with results from feature checks
  245. * Programming in M4:: Layers on top of which Autoconf is written
  246. * Programming in M4sh:: Shell portability layer
  247. * Writing Autoconf Macros:: Adding new macros to Autoconf
  248. * Portable Shell:: Shell script portability pitfalls
  249. * Portable Make:: Makefile portability pitfalls
  250. * Portable C and C++:: C and C++ portability pitfalls
  251. * Manual Configuration:: Selecting features that can't be guessed
  252. * Site Configuration:: Local defaults for @command{configure}
  253. * Running configure Scripts:: How to use the Autoconf output
  254. * config.status Invocation:: Recreating a configuration
  255. * Obsolete Constructs:: Kept for backward compatibility
  256. * Using Autotest:: Creating portable test suites
  257. * FAQ:: Frequent Autoconf Questions, with answers
  258. * History:: History of Autoconf
  259. * GNU Free Documentation License:: License for copying this manual
  260. * Indices:: Indices of symbols, concepts, etc.
  261. @detailmenu
  262. --- The Detailed Node Listing ---
  263. The GNU Build System
  264. * Automake:: Escaping makefile hell
  265. * Gnulib:: The GNU portability library
  266. * Libtool:: Building libraries portably
  267. * Pointers:: More info on the GNU build system
  268. Making @command{configure} Scripts
  269. * Writing Autoconf Input:: What to put in an Autoconf input file
  270. * autoscan Invocation:: Semi-automatic @file{configure.ac} writing
  271. * ifnames Invocation:: Listing the conditionals in source code
  272. * autoconf Invocation:: How to create configuration scripts
  273. * autoreconf Invocation:: Remaking multiple @command{configure} scripts
  274. Writing @file{configure.ac}
  275. * Shell Script Compiler:: Autoconf as solution of a problem
  276. * Autoconf Language:: Programming in Autoconf
  277. * Autoconf Input Layout:: Standard organization of @file{configure.ac}
  278. Initialization and Output Files
  279. * Initializing configure:: Option processing etc.
  280. * Versioning:: Dealing with Autoconf versions
  281. * Notices:: Copyright, version numbers in @command{configure}
  282. * Input:: Where Autoconf should find files
  283. * Output:: Outputting results from the configuration
  284. * Configuration Actions:: Preparing the output based on results
  285. * Configuration Files:: Creating output files
  286. * Makefile Substitutions:: Using output variables in makefiles
  287. * Configuration Headers:: Creating a configuration header file
  288. * Configuration Commands:: Running arbitrary instantiation commands
  289. * Configuration Links:: Links depending on the configuration
  290. * Subdirectories:: Configuring independent packages together
  291. * Default Prefix:: Changing the default installation prefix
  292. Substitutions in Makefiles
  293. * Preset Output Variables:: Output variables that are always set
  294. * Installation Directory Variables:: Other preset output variables
  295. * Changed Directory Variables:: Warnings about @file{datarootdir}
  296. * Build Directories:: Supporting multiple concurrent compiles
  297. * Automatic Remaking:: Makefile rules for configuring
  298. Configuration Header Files
  299. * Header Templates:: Input for the configuration headers
  300. * autoheader Invocation:: How to create configuration templates
  301. * Autoheader Macros:: How to specify CPP templates
  302. Existing Tests
  303. * Common Behavior:: Macros' standard schemes
  304. * Alternative Programs:: Selecting between alternative programs
  305. * Files:: Checking for the existence of files
  306. * Libraries:: Library archives that might be missing
  307. * Library Functions:: C library functions that might be missing
  308. * Header Files:: Header files that might be missing
  309. * Declarations:: Declarations that may be missing
  310. * Structures:: Structures or members that might be missing
  311. * Types:: Types that might be missing
  312. * Compilers and Preprocessors:: Checking for compiling programs
  313. * System Services:: Operating system services
  314. * Posix Variants:: Special kludges for specific Posix variants
  315. * Erlang Libraries:: Checking for the existence of Erlang libraries
  316. Common Behavior
  317. * Standard Symbols:: Symbols defined by the macros
  318. * Default Includes:: Includes used by the generic macros
  319. Alternative Programs
  320. * Particular Programs:: Special handling to find certain programs
  321. * Generic Programs:: How to find other programs
  322. Library Functions
  323. * Function Portability:: Pitfalls with usual functions
  324. * Particular Functions:: Special handling to find certain functions
  325. * Generic Functions:: How to find other functions
  326. Header Files
  327. * Header Portability:: Collected knowledge on common headers
  328. * Particular Headers:: Special handling to find certain headers
  329. * Generic Headers:: How to find other headers
  330. Declarations
  331. * Particular Declarations:: Macros to check for certain declarations
  332. * Generic Declarations:: How to find other declarations
  333. Structures
  334. * Particular Structures:: Macros to check for certain structure members
  335. * Generic Structures:: How to find other structure members
  336. Types
  337. * Particular Types:: Special handling to find certain types
  338. * Generic Types:: How to find other types
  339. Compilers and Preprocessors
  340. * Specific Compiler Characteristics:: Some portability issues
  341. * Generic Compiler Characteristics:: Language independent tests and features
  342. * C Compiler:: Checking its characteristics
  343. * C++ Compiler:: Likewise
  344. * Objective C Compiler:: Likewise
  345. * Objective C++ Compiler:: Likewise
  346. * Erlang Compiler and Interpreter:: Likewise
  347. * Fortran Compiler:: Likewise
  348. * Go Compiler:: Likewise
  349. Writing Tests
  350. * Language Choice:: Selecting which language to use for testing
  351. * Writing Test Programs:: Forging source files for compilers
  352. * Running the Preprocessor:: Detecting preprocessor symbols
  353. * Running the Compiler:: Detecting language or header features
  354. * Running the Linker:: Detecting library features
  355. * Runtime:: Testing for runtime features
  356. * Systemology:: A zoology of operating systems
  357. * Multiple Cases:: Tests for several possible values
  358. Writing Test Programs
  359. * Guidelines:: General rules for writing test programs
  360. * Test Functions:: Avoiding pitfalls in test programs
  361. * Generating Sources:: Source program boilerplate
  362. Results of Tests
  363. * Defining Symbols:: Defining C preprocessor symbols
  364. * Setting Output Variables:: Replacing variables in output files
  365. * Special Chars in Variables:: Characters to beware of in variables
  366. * Caching Results:: Speeding up subsequent @command{configure} runs
  367. * Printing Messages:: Notifying @command{configure} users
  368. Caching Results
  369. * Cache Variable Names:: Shell variables used in caches
  370. * Cache Files:: Files @command{configure} uses for caching
  371. * Cache Checkpointing:: Loading and saving the cache file
  372. Programming in M4
  373. * M4 Quotation:: Protecting macros from unwanted expansion
  374. * Using autom4te:: The Autoconf executables backbone
  375. * Programming in M4sugar:: Convenient pure M4 macros
  376. * Debugging via autom4te:: Figuring out what M4 was doing
  377. M4 Quotation
  378. * Active Characters:: Characters that change the behavior of M4
  379. * One Macro Call:: Quotation and one macro call
  380. * Quoting and Parameters:: M4 vs. shell parameters
  381. * Quotation and Nested Macros:: Macros calling macros
  382. * Changequote is Evil:: Worse than INTERCAL: M4 + changequote
  383. * Quadrigraphs:: Another way to escape special characters
  384. * Balancing Parentheses:: Dealing with unbalanced parentheses
  385. * Quotation Rule Of Thumb:: One parenthesis, one quote
  386. Using @command{autom4te}
  387. * autom4te Invocation:: A GNU M4 wrapper
  388. * Customizing autom4te:: Customizing the Autoconf package
  389. Programming in M4sugar
  390. * Redefined M4 Macros:: M4 builtins changed in M4sugar
  391. * Diagnostic Macros:: Diagnostic messages from M4sugar
  392. * Diversion support:: Diversions in M4sugar
  393. * Conditional constructs:: Conditions in M4
  394. * Looping constructs:: Iteration in M4
  395. * Evaluation Macros:: More quotation and evaluation control
  396. * Text processing Macros:: String manipulation in M4
  397. * Number processing Macros:: Arithmetic computation in M4
  398. * Set manipulation Macros:: Set manipulation in M4
  399. * Forbidden Patterns:: Catching unexpanded macros
  400. Programming in M4sh
  401. * Common Shell Constructs:: Portability layer for common shell constructs
  402. * Polymorphic Variables:: Support for indirect variable names
  403. * Initialization Macros:: Macros to establish a sane shell environment
  404. * File Descriptor Macros:: File descriptor macros for input and output
  405. Writing Autoconf Macros
  406. * Macro Definitions:: Basic format of an Autoconf macro
  407. * Macro Names:: What to call your new macros
  408. * Reporting Messages:: Notifying @command{autoconf} users
  409. * Dependencies Between Macros:: What to do when macros depend on other macros
  410. * Obsoleting Macros:: Warning about old ways of doing things
  411. * Coding Style:: Writing Autoconf macros @`a la Autoconf
  412. Dependencies Between Macros
  413. * Prerequisite Macros:: Ensuring required information
  414. * Suggested Ordering:: Warning about possible ordering problems
  415. * One-Shot Macros:: Ensuring a macro is called only once
  416. Portable Shell Programming
  417. * Shellology:: A zoology of shells
  418. * Invoking the Shell:: Invoking the shell as a command
  419. * Here-Documents:: Quirks and tricks
  420. * File Descriptors:: FDs and redirections
  421. * Signal Handling:: Shells, signals, and headaches
  422. * File System Conventions:: File names
  423. * Shell Pattern Matching:: Pattern matching
  424. * Shell Substitutions:: Variable and command expansions
  425. * Assignments:: Varying side effects of assignments
  426. * Parentheses:: Parentheses in shell scripts
  427. * Slashes:: Slashes in shell scripts
  428. * Special Shell Variables:: Variables you should not change
  429. * Shell Functions:: What to look out for if you use them
  430. * Limitations of Builtins:: Portable use of not so portable /bin/sh
  431. * Limitations of Usual Tools:: Portable use of portable tools
  432. Portable Make Programming
  433. * $< in Ordinary Make Rules:: $< in ordinary rules
  434. * Failure in Make Rules:: Failing portably in rules
  435. * Special Chars in Names:: Special Characters in Macro Names
  436. * Backslash-Newline-Empty:: Empty lines after backslash-newline
  437. * Backslash-Newline Comments:: Spanning comments across line boundaries
  438. * Long Lines in Makefiles:: Line length limitations
  439. * Macros and Submakes:: @code{make macro=value} and submakes
  440. * The Make Macro MAKEFLAGS:: @code{$(MAKEFLAGS)} portability issues
  441. * The Make Macro SHELL:: @code{$(SHELL)} portability issues
  442. * Parallel Make:: Parallel @command{make} quirks
  443. * Comments in Make Rules:: Other problems with Make comments
  444. * Newlines in Make Rules:: Using literal newlines in rules
  445. * Comments in Make Macros:: Other problems with Make comments in macros
  446. * Trailing whitespace in Make Macros:: Macro substitution problems
  447. * Command-line Macros and whitespace:: Whitespace trimming of values
  448. * obj/ and Make:: Don't name a subdirectory @file{obj}
  449. * make -k Status:: Exit status of @samp{make -k}
  450. * VPATH and Make:: @code{VPATH} woes
  451. * Single Suffix Rules:: Single suffix rules and separated dependencies
  452. * Timestamps and Make:: Subsecond timestamp resolution
  453. @code{VPATH} and Make
  454. * Variables listed in VPATH:: @code{VPATH} must be literal on ancient hosts
  455. * VPATH and Double-colon:: Problems with @samp{::} on ancient hosts
  456. * $< in Explicit Rules:: @code{$<} does not work in ordinary rules
  457. * Automatic Rule Rewriting:: @code{VPATH} goes wild on Solaris
  458. * Tru64 Directory Magic:: @command{mkdir} goes wild on Tru64
  459. * Make Target Lookup:: More details about @code{VPATH} lookup
  460. Portable C and C++ Programming
  461. * Varieties of Unportability:: How to make your programs unportable
  462. * Integer Overflow:: When integers get too large
  463. * Preprocessor Arithmetic:: @code{#if} expression problems
  464. * Null Pointers:: Properties of null pointers
  465. * Buffer Overruns:: Subscript errors and the like
  466. * Volatile Objects:: @code{volatile} and signals
  467. * Floating Point Portability:: Portable floating-point arithmetic
  468. * Exiting Portably:: Exiting and the exit status
  469. Integer Overflow
  470. * Integer Overflow Basics:: Why integer overflow is a problem
  471. * Signed Overflow Examples:: Examples of code assuming wraparound
  472. * Optimization and Wraparound:: Optimizations that break uses of wraparound
  473. * Signed Overflow Advice:: Practical advice for signed overflow issues
  474. * Signed Integer Division:: @code{INT_MIN / -1} and @code{INT_MIN % -1}
  475. Manual Configuration
  476. * Specifying Target Triplets:: Specifying target triplets
  477. * Canonicalizing:: Getting the canonical system type
  478. * Using System Type:: What to do with the system type
  479. Site Configuration
  480. * Help Formatting:: Customizing @samp{configure --help}
  481. * External Software:: Working with other optional software
  482. * Package Options:: Selecting optional features
  483. * Pretty Help Strings:: Formatting help string
  484. * Option Checking:: Controlling checking of @command{configure} options
  485. * Site Details:: Configuring site details
  486. * Transforming Names:: Changing program names when installing
  487. * Site Defaults:: Giving @command{configure} local defaults
  488. Transforming Program Names When Installing
  489. * Transformation Options:: @command{configure} options to transform names
  490. * Transformation Examples:: Sample uses of transforming names
  491. * Transformation Rules:: Makefile uses of transforming names
  492. Running @command{configure} Scripts
  493. * Basic Installation:: Instructions for typical cases
  494. * Compilers and Options:: Selecting compilers and optimization
  495. * Multiple Architectures:: Compiling for multiple architectures at once
  496. * Installation Names:: Installing in different directories
  497. * Optional Features:: Selecting optional features
  498. * Particular Systems:: Particular systems
  499. * System Type:: Specifying the system type
  500. * Sharing Defaults:: Setting site-wide defaults for @command{configure}
  501. * Defining Variables:: Specifying the compiler etc.
  502. * configure Invocation:: Changing how @command{configure} runs
  503. Obsolete Constructs
  504. * Obsolete config.status Use:: Obsolete convention for @command{config.status}
  505. * acconfig Header:: Additional entries in @file{config.h.in}
  506. * autoupdate Invocation:: Automatic update of @file{configure.ac}
  507. * Obsolete Macros:: Backward compatibility macros
  508. * Autoconf 1:: Tips for upgrading your files
  509. * Autoconf 2.13:: Some fresher tips
  510. Upgrading From Version 1
  511. * Changed File Names:: Files you might rename
  512. * Changed Makefiles:: New things to put in @file{Makefile.in}
  513. * Changed Macros:: Macro calls you might replace
  514. * Changed Results:: Changes in how to check test results
  515. * Changed Macro Writing:: Better ways to write your own macros
  516. Upgrading From Version 2.13
  517. * Changed Quotation:: Broken code which used to work
  518. * New Macros:: Interaction with foreign macros
  519. * Hosts and Cross-Compilation:: Bugward compatibility kludges
  520. * AC_LIBOBJ vs LIBOBJS:: LIBOBJS is a forbidden token
  521. * AC_ACT_IFELSE vs AC_TRY_ACT:: A more generic scheme for testing sources
  522. Generating Test Suites with Autotest
  523. * Using an Autotest Test Suite:: Autotest and the user
  524. * Writing Testsuites:: Autotest macros
  525. * testsuite Invocation:: Running @command{testsuite} scripts
  526. * Making testsuite Scripts:: Using autom4te to create @command{testsuite}
  527. Using an Autotest Test Suite
  528. * testsuite Scripts:: The concepts of Autotest
  529. * Autotest Logs:: Their contents
  530. Frequent Autoconf Questions, with answers
  531. * Distributing:: Distributing @command{configure} scripts
  532. * Why GNU M4:: Why not use the standard M4?
  533. * Bootstrapping:: Autoconf and GNU M4 require each other?
  534. * Why Not Imake:: Why GNU uses @command{configure} instead of Imake
  535. * Defining Directories:: Passing @code{datadir} to program
  536. * Autom4te Cache:: What is it? Can I remove it?
  537. * Present But Cannot Be Compiled:: Compiler and Preprocessor Disagree
  538. * Expanded Before Required:: Expanded Before Required
  539. * Debugging:: Debugging @command{configure} scripts
  540. History of Autoconf
  541. * Genesis:: Prehistory and naming of @command{configure}
  542. * Exodus:: The plagues of M4 and Perl
  543. * Leviticus:: The priestly code of portability arrives
  544. * Numbers:: Growth and contributors
  545. * Deuteronomy:: Approaching the promises of easy configuration
  546. Indices
  547. * Environment Variable Index:: Index of environment variables used
  548. * Output Variable Index:: Index of variables set in output files
  549. * Preprocessor Symbol Index:: Index of C preprocessor symbols defined
  550. * Cache Variable Index:: Index of documented cache variables
  551. * Autoconf Macro Index:: Index of Autoconf macros
  552. * M4 Macro Index:: Index of M4, M4sugar, and M4sh macros
  553. * Autotest Macro Index:: Index of Autotest macros
  554. * Program & Function Index:: Index of those with portability problems
  555. * Concept Index:: General index
  556. @end detailmenu
  557. @end menu
  558. @c ============================================================= Introduction.
  559. @node Introduction
  560. @chapter Introduction
  561. @cindex Introduction
  562. @flushright
  563. A physicist, an engineer, and a computer scientist were discussing the
  564. nature of God. ``Surely a Physicist,'' said the physicist, ``because
  565. early in the Creation, God made Light; and you know, Maxwell's
  566. equations, the dual nature of electromagnetic waves, the relativistic
  567. consequences@enddots{}'' ``An Engineer!,'' said the engineer, ``because
  568. before making Light, God split the Chaos into Land and Water; it takes a
  569. hell of an engineer to handle that big amount of mud, and orderly
  570. separation of solids from liquids@enddots{}'' The computer scientist
  571. shouted: ``And the Chaos, where do you think it was coming from, hmm?''
  572. ---Anonymous
  573. @end flushright
  574. @c (via Franc,ois Pinard)
  575. Autoconf is a tool for producing shell scripts that automatically
  576. configure software source code packages to adapt to many kinds of
  577. Posix-like systems. The configuration scripts produced by Autoconf
  578. are independent of Autoconf when they are run, so their users do not
  579. need to have Autoconf.
  580. The configuration scripts produced by Autoconf require no manual user
  581. intervention when run; they do not normally even need an argument
  582. specifying the system type. Instead, they individually test for the
  583. presence of each feature that the software package they are for might need.
  584. (Before each check, they print a one-line message stating what they are
  585. checking for, so the user doesn't get too bored while waiting for the
  586. script to finish.) As a result, they deal well with systems that are
  587. hybrids or customized from the more common Posix variants. There is
  588. no need to maintain files that list the features supported by each
  589. release of each variant of Posix.
  590. For each software package that Autoconf is used with, it creates a
  591. configuration script from a template file that lists the system features
  592. that the package needs or can use. After the shell code to recognize
  593. and respond to a system feature has been written, Autoconf allows it to
  594. be shared by many software packages that can use (or need) that feature.
  595. If it later turns out that the shell code needs adjustment for some
  596. reason, it needs to be changed in only one place; all of the
  597. configuration scripts can be regenerated automatically to take advantage
  598. of the updated code.
  599. @c "Those who do not understand Unix are condemned to reinvent it, poorly."
  600. @c --Henry Spencer, 1987 (see http://en.wikipedia.org/wiki/Unix_philosophy)
  601. Those who do not understand Autoconf are condemned to reinvent it, poorly.
  602. The primary goal of Autoconf is making the @emph{user's} life easier;
  603. making the @emph{maintainer's} life easier is only a secondary goal.
  604. Put another way, the primary goal is not to make the generation of
  605. @file{configure} automatic for package maintainers (although patches
  606. along that front are welcome, since package maintainers form the user
  607. base of Autoconf); rather, the goal is to make @file{configure}
  608. painless, portable, and predictable for the end user of each
  609. @dfn{autoconfiscated} package. And to this degree, Autoconf is highly
  610. successful at its goal --- most complaints to the Autoconf list are
  611. about difficulties in writing Autoconf input, and not in the behavior of
  612. the resulting @file{configure}. Even packages that don't use Autoconf
  613. will generally provide a @file{configure} script, and the most common
  614. complaint about these alternative home-grown scripts is that they fail
  615. to meet one or more of the GNU Coding Standards (@pxref{Configuration, , ,
  616. standards, The GNU Coding Standards}) that users
  617. have come to expect from Autoconf-generated @file{configure} scripts.
  618. The Metaconfig package is similar in purpose to Autoconf, but the
  619. scripts it produces require manual user intervention, which is quite
  620. inconvenient when configuring large source trees. Unlike Metaconfig
  621. scripts, Autoconf scripts can support cross-compiling, if some care is
  622. taken in writing them.
  623. Autoconf does not solve all problems related to making portable
  624. software packages---for a more complete solution, it should be used in
  625. concert with other GNU build tools like Automake and
  626. Libtool. These other tools take on jobs like the creation of a
  627. portable, recursive makefile with all of the standard targets,
  628. linking of shared libraries, and so on. @xref{The GNU Build System},
  629. for more information.
  630. Autoconf imposes some restrictions on the names of macros used with
  631. @code{#if} in C programs (@pxref{Preprocessor Symbol Index}).
  632. Autoconf requires GNU M4 version 1.4.6 or later in order to
  633. generate the scripts. It uses features that some versions of M4,
  634. including GNU M4 1.3, do not have. Autoconf works better
  635. with GNU M4 version 1.4.14 or later, though this is not
  636. required.
  637. @xref{Autoconf 1}, for information about upgrading from version 1.
  638. @xref{History}, for the story of Autoconf's development. @xref{FAQ},
  639. for answers to some common questions about Autoconf.
  640. See the @uref{http://@/www.gnu.org/@/software/@/autoconf/,
  641. Autoconf web page} for up-to-date information, details on the mailing
  642. lists, pointers to a list of known bugs, etc.
  643. Mail suggestions to @email{autoconf@@gnu.org, the Autoconf mailing
  644. list}. Past suggestions are
  645. @uref{http://@/lists.gnu.org/@/archive/@/html/@/autoconf/, archived}.
  646. Mail bug reports to @email{bug-autoconf@@gnu.org, the
  647. Autoconf Bugs mailing list}. Past bug reports are
  648. @uref{http://@/lists.gnu.org/@/archive/@/html/@/bug-autoconf/, archived}.
  649. If possible, first check that your bug is
  650. not already solved in current development versions, and that it has not
  651. been reported yet. Be sure to include all the needed information and a
  652. short @file{configure.ac} that demonstrates the problem.
  653. Autoconf's development tree is accessible via @command{git}; see the
  654. @uref{http://@/savannah.gnu.org/@/projects/@/autoconf/, Autoconf
  655. Summary} for details, or view
  656. @uref{http://@/git.sv.gnu.org/@/gitweb/@/?p=autoconf.git, the actual
  657. repository}. Anonymous CVS access is also available, see
  658. @file{README} for more details. Patches relative to the
  659. current @command{git} version can be sent for review to the
  660. @email{autoconf-patches@@gnu.org, Autoconf Patches mailing list}, with
  661. discussion on prior patches
  662. @uref{http://@/lists.gnu.org/@/archive/@/html/@/autoconf-@/patches/,
  663. archived}; and all commits are posted in the read-only
  664. @email{autoconf-commit@@gnu.org, Autoconf Commit mailing list}, which is
  665. also @uref{http://@/lists.gnu.org/@/archive/@/html/@/autoconf-commit/,
  666. archived}.
  667. Because of its mission, the Autoconf package itself
  668. includes only a set of often-used
  669. macros that have already demonstrated their usefulness. Nevertheless,
  670. if you wish to share your macros, or find existing ones, see the
  671. @uref{http://@/www.gnu.org/@/software/@/autoconf-archive/, Autoconf Macro
  672. Archive}, which is kindly run by @email{simons@@cryp.to,
  673. Peter Simons}.
  674. @c ================================================= The GNU Build System
  675. @node The GNU Build System
  676. @chapter The GNU Build System
  677. @cindex GNU build system
  678. Autoconf solves an important problem---reliable discovery of
  679. system-specific build and runtime information---but this is only one
  680. piece of the puzzle for the development of portable software. To this
  681. end, the GNU project has developed a suite of integrated
  682. utilities to finish the job Autoconf started: the GNU build
  683. system, whose most important components are Autoconf, Automake, and
  684. Libtool. In this chapter, we introduce you to those tools, point you
  685. to sources of more information, and try to convince you to use the
  686. entire GNU build system for your software.
  687. @menu
  688. * Automake:: Escaping makefile hell
  689. * Gnulib:: The GNU portability library
  690. * Libtool:: Building libraries portably
  691. * Pointers:: More info on the GNU build system
  692. @end menu
  693. @node Automake
  694. @section Automake
  695. The ubiquity of @command{make} means that a makefile is almost the
  696. only viable way to distribute automatic build rules for software, but
  697. one quickly runs into its numerous limitations. Its lack of
  698. support for automatic dependency tracking, recursive builds in
  699. subdirectories, reliable timestamps (e.g., for network file systems), and
  700. so on, mean that developers must painfully (and often incorrectly)
  701. reinvent the wheel for each project. Portability is non-trivial, thanks
  702. to the quirks of @command{make} on many systems. On top of all this is the
  703. manual labor required to implement the many standard targets that users
  704. have come to expect (@code{make install}, @code{make distclean},
  705. @code{make uninstall}, etc.). Since you are, of course, using Autoconf,
  706. you also have to insert repetitive code in your @file{Makefile.in} to
  707. recognize @code{@@CC@@}, @code{@@CFLAGS@@}, and other substitutions
  708. provided by @command{configure}. Into this mess steps @dfn{Automake}.
  709. @cindex Automake
  710. Automake allows you to specify your build needs in a @file{Makefile.am}
  711. file with a vastly simpler and more powerful syntax than that of a plain
  712. makefile, and then generates a portable @file{Makefile.in} for
  713. use with Autoconf. For example, the @file{Makefile.am} to build and
  714. install a simple ``Hello world'' program might look like:
  715. @example
  716. bin_PROGRAMS = hello
  717. hello_SOURCES = hello.c
  718. @end example
  719. @noindent
  720. The resulting @file{Makefile.in} (~400 lines) automatically supports all
  721. the standard targets, the substitutions provided by Autoconf, automatic
  722. dependency tracking, @code{VPATH} building, and so on. @command{make}
  723. builds the @code{hello} program, and @code{make install} installs it
  724. in @file{/usr/local/bin} (or whatever prefix was given to
  725. @command{configure}, if not @file{/usr/local}).
  726. The benefits of Automake increase for larger packages (especially ones
  727. with subdirectories), but even for small programs the added convenience
  728. and portability can be substantial. And that's not all@enddots{}
  729. @node Gnulib
  730. @section Gnulib
  731. GNU software has a well-deserved reputation for running on
  732. many different types of systems. While our primary goal is to write
  733. software for the GNU system, many users and developers have
  734. been introduced to us through the systems that they were already using.
  735. @cindex Gnulib
  736. Gnulib is a central location for common GNU code, intended to
  737. be shared among free software packages. Its components are typically
  738. shared at the source level, rather than being a library that gets built,
  739. installed, and linked against. The idea is to copy files from Gnulib
  740. into your own source tree. There is no distribution tarball; developers
  741. should just grab source modules from the repository. The source files
  742. are available online, under various licenses, mostly GNU
  743. GPL or GNU LGPL.
  744. Gnulib modules typically contain C source code along with Autoconf
  745. macros used to configure the source code. For example, the Gnulib
  746. @code{stdbool} module implements a @file{stdbool.h} header that nearly
  747. conforms to C99, even on old-fashioned hosts that lack @file{stdbool.h}.
  748. This module contains a source file for the replacement header, along
  749. with an Autoconf macro that arranges to use the replacement header on
  750. old-fashioned systems.
  751. @node Libtool
  752. @section Libtool
  753. Often, one wants to build not only programs, but libraries, so that
  754. other programs can benefit from the fruits of your labor. Ideally, one
  755. would like to produce @emph{shared} (dynamically linked) libraries,
  756. which can be used by multiple programs without duplication on disk or in
  757. memory and can be updated independently of the linked programs.
  758. Producing shared libraries portably, however, is the stuff of
  759. nightmares---each system has its own incompatible tools, compiler flags,
  760. and magic incantations. Fortunately, GNU provides a solution:
  761. @dfn{Libtool}.
  762. @cindex Libtool
  763. Libtool handles all the requirements of building shared libraries for
  764. you, and at this time seems to be the @emph{only} way to do so with any
  765. portability. It also handles many other headaches, such as: the
  766. interaction of Make rules with the variable suffixes of
  767. shared libraries, linking reliably with shared libraries before they are
  768. installed by the superuser, and supplying a consistent versioning system
  769. (so that different versions of a library can be installed or upgraded
  770. without breaking binary compatibility). Although Libtool, like
  771. Autoconf, can be used without Automake, it is most simply utilized in
  772. conjunction with Automake---there, Libtool is used automatically
  773. whenever shared libraries are needed, and you need not know its syntax.
  774. @node Pointers
  775. @section Pointers
  776. Developers who are used to the simplicity of @command{make} for small
  777. projects on a single system might be daunted at the prospect of
  778. learning to use Automake and Autoconf. As your software is
  779. distributed to more and more users, however, you otherwise
  780. quickly find yourself putting lots of effort into reinventing the
  781. services that the GNU build tools provide, and making the
  782. same mistakes that they once made and overcame. (Besides, since
  783. you're already learning Autoconf, Automake is a piece of cake.)
  784. There are a number of places that you can go to for more information on
  785. the GNU build tools.
  786. @itemize @minus
  787. @item Web
  788. The project home pages for
  789. @uref{http://@/www@/.gnu@/.org/@/software/@/autoconf/, Autoconf},
  790. @uref{http://@/www@/.gnu@/.org/@/software/@/automake/, Automake},
  791. @uref{http://@/www@/.gnu@/.org/@/software/@/gnulib/, Gnulib}, and
  792. @uref{http://@/www@/.gnu@/.org/@/software/@/libtool/, Libtool}.
  793. @item Automake Manual
  794. @xref{Top, , Automake, automake, GNU Automake}, for more
  795. information on Automake.
  796. @item Books
  797. The book @cite{GNU Autoconf, Automake and
  798. Libtool}@footnote{@cite{GNU Autoconf, Automake and Libtool},
  799. by G. V. Vaughan, B. Elliston, T. Tromey, and I. L. Taylor. SAMS (originally
  800. New Riders), 2000, ISBN 1578701902.} describes the complete GNU
  801. build environment. You can also find
  802. @uref{http://@/sources.redhat.com/@/autobook/, the entire book on-line}.
  803. @end itemize
  804. @c ================================================= Making configure Scripts.
  805. @node Making configure Scripts
  806. @chapter Making @command{configure} Scripts
  807. @cindex @file{aclocal.m4}
  808. @cindex @command{configure}
  809. The configuration scripts that Autoconf produces are by convention
  810. called @command{configure}. When run, @command{configure} creates several
  811. files, replacing configuration parameters in them with appropriate
  812. values. The files that @command{configure} creates are:
  813. @itemize @minus
  814. @item
  815. one or more @file{Makefile} files, usually one in each subdirectory of the
  816. package (@pxref{Makefile Substitutions});
  817. @item
  818. optionally, a C header file, the name of which is configurable,
  819. containing @code{#define} directives (@pxref{Configuration Headers});
  820. @item
  821. a shell script called @file{config.status} that, when run, recreates
  822. the files listed above (@pxref{config.status Invocation});
  823. @item
  824. an optional shell script normally called @file{config.cache}
  825. (created when using @samp{configure --config-cache}) that
  826. saves the results of running many of the tests (@pxref{Cache Files});
  827. @item
  828. a file called @file{config.log} containing any messages produced by
  829. compilers, to help debugging if @command{configure} makes a mistake.
  830. @end itemize
  831. @cindex @file{configure.in}
  832. @cindex @file{configure.ac}
  833. To create a @command{configure} script with Autoconf, you need to write an
  834. Autoconf input file @file{configure.ac} (or @file{configure.in}) and run
  835. @command{autoconf} on it. If you write your own feature tests to
  836. supplement those that come with Autoconf, you might also write files
  837. called @file{aclocal.m4} and @file{acsite.m4}. If you use a C header
  838. file to contain @code{#define} directives, you might also run
  839. @command{autoheader}, and you can distribute the generated file
  840. @file{config.h.in} with the package.
  841. Here is a diagram showing how the files that can be used in
  842. configuration are produced. Programs that are executed are suffixed by
  843. @samp{*}. Optional files are enclosed in square brackets (@samp{[]}).
  844. @command{autoconf} and @command{autoheader} also read the installed Autoconf
  845. macro files (by reading @file{autoconf.m4}).
  846. @noindent
  847. Files used in preparing a software package for distribution, when using
  848. just Autoconf:
  849. @example
  850. your source files --> [autoscan*] --> [configure.scan] --> configure.ac
  851. @group
  852. configure.ac --.
  853. | .------> autoconf* -----> configure
  854. [aclocal.m4] --+---+
  855. | `-----> [autoheader*] --> [config.h.in]
  856. [acsite.m4] ---'
  857. @end group
  858. Makefile.in
  859. @end example
  860. @noindent
  861. Additionally, if you use Automake, the following additional productions
  862. come into play:
  863. @example
  864. @group
  865. [acinclude.m4] --.
  866. |
  867. [local macros] --+--> aclocal* --> aclocal.m4
  868. |
  869. configure.ac ----'
  870. @end group
  871. @group
  872. configure.ac --.
  873. +--> automake* --> Makefile.in
  874. Makefile.am ---'
  875. @end group
  876. @end example
  877. @noindent
  878. Files used in configuring a software package:
  879. @example
  880. @group
  881. .-------------> [config.cache]
  882. configure* ------------+-------------> config.log
  883. |
  884. [config.h.in] -. v .-> [config.h] -.
  885. +--> config.status* -+ +--> make*
  886. Makefile.in ---' `-> Makefile ---'
  887. @end group
  888. @end example
  889. @menu
  890. * Writing Autoconf Input:: What to put in an Autoconf input file
  891. * autoscan Invocation:: Semi-automatic @file{configure.ac} writing
  892. * ifnames Invocation:: Listing the conditionals in source code
  893. * autoconf Invocation:: How to create configuration scripts
  894. * autoreconf Invocation:: Remaking multiple @command{configure} scripts
  895. @end menu
  896. @node Writing Autoconf Input
  897. @section Writing @file{configure.ac}
  898. To produce a @command{configure} script for a software package, create a
  899. file called @file{configure.ac} that contains invocations of the
  900. Autoconf macros that test the system features your package needs or can
  901. use. Autoconf macros already exist to check for many features; see
  902. @ref{Existing Tests}, for their descriptions. For most other features,
  903. you can use Autoconf template macros to produce custom checks; see
  904. @ref{Writing Tests}, for information about them. For especially tricky
  905. or specialized features, @file{configure.ac} might need to contain some
  906. hand-crafted shell commands; see @ref{Portable Shell, , Portable Shell
  907. Programming}. The @command{autoscan} program can give you a good start
  908. in writing @file{configure.ac} (@pxref{autoscan Invocation}, for more
  909. information).
  910. Previous versions of Autoconf promoted the name @file{configure.in},
  911. which is somewhat ambiguous (the tool needed to process this file is not
  912. described by its extension), and introduces a slight confusion with
  913. @file{config.h.in} and so on (for which @samp{.in} means ``to be
  914. processed by @command{configure}''). Using @file{configure.ac} is now
  915. preferred.
  916. @menu
  917. * Shell Script Compiler:: Autoconf as solution of a problem
  918. * Autoconf Language:: Programming in Autoconf
  919. * Autoconf Input Layout:: Standard organization of @file{configure.ac}
  920. @end menu
  921. @node Shell Script Compiler
  922. @subsection A Shell Script Compiler
  923. Just as for any other computer language, in order to properly program
  924. @file{configure.ac} in Autoconf you must understand @emph{what} problem
  925. the language tries to address and @emph{how} it does so.
  926. The problem Autoconf addresses is that the world is a mess. After all,
  927. you are using Autoconf in order to have your package compile easily on
  928. all sorts of different systems, some of them being extremely hostile.
  929. Autoconf itself bears the price for these differences: @command{configure}
  930. must run on all those systems, and thus @command{configure} must limit itself
  931. to their lowest common denominator of features.
  932. Naturally, you might then think of shell scripts; who needs
  933. @command{autoconf}? A set of properly written shell functions is enough to
  934. make it easy to write @command{configure} scripts by hand. Sigh!
  935. Unfortunately, even in 2008, where shells without any function support are
  936. far and few between, there are pitfalls to avoid when making use of them.
  937. Also, finding a Bourne shell that accepts shell functions is not trivial,
  938. even though there is almost always one on interesting porting targets.
  939. So, what is really needed is some kind of compiler, @command{autoconf},
  940. that takes an Autoconf program, @file{configure.ac}, and transforms it
  941. into a portable shell script, @command{configure}.
  942. How does @command{autoconf} perform this task?
  943. There are two obvious possibilities: creating a brand new language or
  944. extending an existing one. The former option is attractive: all
  945. sorts of optimizations could easily be implemented in the compiler and
  946. many rigorous checks could be performed on the Autoconf program
  947. (e.g., rejecting any non-portable construct). Alternatively, you can
  948. extend an existing language, such as the @code{sh} (Bourne shell)
  949. language.
  950. Autoconf does the latter: it is a layer on top of @code{sh}. It was
  951. therefore most convenient to implement @command{autoconf} as a macro
  952. expander: a program that repeatedly performs @dfn{macro expansions} on
  953. text input, replacing macro calls with macro bodies and producing a pure
  954. @code{sh} script in the end. Instead of implementing a dedicated
  955. Autoconf macro expander, it is natural to use an existing
  956. general-purpose macro language, such as M4, and implement the extensions
  957. as a set of M4 macros.
  958. @node Autoconf Language
  959. @subsection The Autoconf Language
  960. @cindex quotation
  961. The Autoconf language differs from many other computer
  962. languages because it treats actual code the same as plain text. Whereas
  963. in C, for instance, data and instructions have different syntactic
  964. status, in Autoconf their status is rigorously the same. Therefore, we
  965. need a means to distinguish literal strings from text to be expanded:
  966. quotation.
  967. When calling macros that take arguments, there must not be any white
  968. space between the macro name and the open parenthesis.
  969. @example
  970. AC_INIT ([oops], [1.0]) # incorrect
  971. AC_INIT([hello], [1.0]) # good
  972. @end example
  973. Arguments should
  974. be enclosed within the quote characters @samp{[} and @samp{]}, and be
  975. separated by commas. Any leading blanks or newlines in arguments are ignored,
  976. unless they are quoted. You should always quote an argument that
  977. might contain a macro name, comma, parenthesis, or a leading blank or
  978. newline. This rule applies recursively for every macro
  979. call, including macros called from other macros. For more details on
  980. quoting rules, see @ref{Programming in M4}.
  981. For instance:
  982. @example
  983. AC_CHECK_HEADER([stdio.h],
  984. [AC_DEFINE([HAVE_STDIO_H], [1],
  985. [Define to 1 if you have <stdio.h>.])],
  986. [AC_MSG_ERROR([sorry, can't do anything for you])])
  987. @end example
  988. @noindent
  989. is quoted properly. You may safely simplify its quotation to:
  990. @example
  991. AC_CHECK_HEADER([stdio.h],
  992. [AC_DEFINE([HAVE_STDIO_H], 1,
  993. [Define to 1 if you have <stdio.h>.])],
  994. [AC_MSG_ERROR([sorry, can't do anything for you])])
  995. @end example
  996. @noindent
  997. because @samp{1} cannot contain a macro call. Here, the argument of
  998. @code{AC_MSG_ERROR} must be quoted; otherwise, its comma would be
  999. interpreted as an argument separator. Also, the second and third arguments
  1000. of @samp{AC_CHECK_HEADER} must be quoted, since they contain
  1001. macro calls. The three arguments @samp{HAVE_STDIO_H}, @samp{stdio.h},
  1002. and @samp{Define to 1 if you have <stdio.h>.} do not need quoting, but
  1003. if you unwisely defined a macro with a name like @samp{Define} or
  1004. @samp{stdio} then they would need quoting. Cautious Autoconf users
  1005. would keep the quotes, but many Autoconf users find such precautions
  1006. annoying, and would rewrite the example as follows:
  1007. @example
  1008. AC_CHECK_HEADER(stdio.h,
  1009. [AC_DEFINE(HAVE_STDIO_H, 1,
  1010. [Define to 1 if you have <stdio.h>.])],
  1011. [AC_MSG_ERROR([sorry, can't do anything for you])])
  1012. @end example
  1013. @noindent
  1014. This is safe, so long as you adopt good naming conventions and do not
  1015. define macros with names like @samp{HAVE_STDIO_H}, @samp{stdio}, or
  1016. @samp{h}. Though it is also safe here to omit the quotes around
  1017. @samp{Define to 1 if you have <stdio.h>.} this is not recommended, as
  1018. message strings are more likely to inadvertently contain commas.
  1019. The following example is wrong and dangerous, as it is underquoted:
  1020. @example
  1021. AC_CHECK_HEADER(stdio.h,
  1022. AC_DEFINE(HAVE_STDIO_H, 1,
  1023. Define to 1 if you have <stdio.h>.),
  1024. AC_MSG_ERROR([sorry, can't do anything for you]))
  1025. @end example
  1026. In other cases, you may have to use text that also resembles a macro
  1027. call. You must quote that text even when it is not passed as a macro
  1028. argument. For example, these two approaches in @file{configure.ac}
  1029. (quoting just the potential problems, or quoting the entire line) will
  1030. protect your script in case autoconf ever adds a macro @code{AC_DC}:
  1031. @example
  1032. echo "Hard rock was here! --[AC_DC]"
  1033. [echo "Hard rock was here! --AC_DC"]
  1034. @end example
  1035. @noindent
  1036. which results in this text in @file{configure}:
  1037. @example
  1038. echo "Hard rock was here! --AC_DC"
  1039. echo "Hard rock was here! --AC_DC"
  1040. @end example
  1041. @noindent
  1042. When you use the same text in a macro argument, you must therefore have
  1043. an extra quotation level (since one is stripped away by the macro
  1044. substitution). In general, then, it is a good idea to @emph{use double
  1045. quoting for all literal string arguments}, either around just the
  1046. problematic portions, or over the entire argument:
  1047. @example
  1048. AC_MSG_WARN([[AC_DC] stinks --Iron Maiden])
  1049. AC_MSG_WARN([[AC_DC stinks --Iron Maiden]])
  1050. @end example
  1051. However, the above example triggers a warning about a possibly
  1052. unexpanded macro when running @command{autoconf}, because it collides
  1053. with the namespace of macros reserved for the Autoconf language. To be
  1054. really safe, you can use additional escaping (either a quadrigraph, or
  1055. creative shell constructs) to silence that particular warning:
  1056. @example
  1057. echo "Hard rock was here! --AC""_DC"
  1058. AC_MSG_WARN([[AC@@&t@@_DC stinks --Iron Maiden]])
  1059. @end example
  1060. You are now able to understand one of the constructs of Autoconf that
  1061. has been continually misunderstood@enddots{} The rule of thumb is that
  1062. @emph{whenever you expect macro expansion, expect quote expansion};
  1063. i.e., expect one level of quotes to be lost. For instance:
  1064. @example
  1065. AC_COMPILE_IFELSE(AC_LANG_SOURCE([char b[10];]), [],
  1066. [AC_MSG_ERROR([you lose])])
  1067. @end example
  1068. @noindent
  1069. is incorrect: here, the first argument of @code{AC_LANG_SOURCE} is
  1070. @samp{char b[10];} and is expanded once, which results in
  1071. @samp{char b10;}; and the @code{AC_LANG_SOURCE} is also expanded prior
  1072. to being passed to @code{AC_COMPILE_IFELSE}. (There was an idiom common
  1073. in Autoconf's past to
  1074. address this issue via the M4 @code{changequote} primitive, but do not
  1075. use it!) Let's take a closer look: the author meant the first argument
  1076. to be understood as a literal, and therefore it must be quoted twice;
  1077. likewise, the intermediate @code{AC_LANG_SOURCE} macro should be quoted
  1078. once so that it is only expanded after the rest of the body of
  1079. @code{AC_COMPILE_IFELSE} is in place:
  1080. @example
  1081. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char b[10];]])], [],
  1082. [AC_MSG_ERROR([you lose])])
  1083. @end example
  1084. @noindent
  1085. Voil@`a, you actually produce @samp{char b[10];} this time!
  1086. On the other hand, descriptions (e.g., the last parameter of
  1087. @code{AC_DEFINE} or @code{AS_HELP_STRING}) are not literals---they
  1088. are subject to line breaking, for example---and should not be double quoted.
  1089. Even if these descriptions are short and are not actually broken, double
  1090. quoting them yields weird results.
  1091. Some macros take optional arguments, which this documentation represents
  1092. as @ovar{arg} (not to be confused with the quote characters). You may
  1093. just leave them empty, or use @samp{[]} to make the emptiness of the
  1094. argument explicit, or you may simply omit the trailing commas. The
  1095. three lines below are equivalent:
  1096. @example
  1097. AC_CHECK_HEADERS([stdio.h], [], [], [])
  1098. AC_CHECK_HEADERS([stdio.h],,,)
  1099. AC_CHECK_HEADERS([stdio.h])
  1100. @end example
  1101. It is best to put each macro call on its own line in
  1102. @file{configure.ac}. Most of the macros don't add extra newlines; they
  1103. rely on the newline after the macro call to terminate the commands.
  1104. This approach makes the generated @command{configure} script a little
  1105. easier to read by not inserting lots of blank lines. It is generally
  1106. safe to set shell variables on the same line as a macro call, because
  1107. the shell allows assignments without intervening newlines.
  1108. You can include comments in @file{configure.ac} files by starting them
  1109. with the @samp{#}. For example, it is helpful to begin
  1110. @file{configure.ac} files with a line like this:
  1111. @example
  1112. # Process this file with autoconf to produce a configure script.
  1113. @end example
  1114. @node Autoconf Input Layout
  1115. @subsection Standard @file{configure.ac} Layout
  1116. The order in which @file{configure.ac} calls the Autoconf macros is not
  1117. important, with a few exceptions. Every @file{configure.ac} must
  1118. contain a call to @code{AC_INIT} before the checks, and a call to
  1119. @code{AC_OUTPUT} at the end (@pxref{Output}). Additionally, some macros
  1120. rely on other macros having been called first, because they check
  1121. previously set values of some variables to decide what to do. These
  1122. macros are noted in the individual descriptions (@pxref{Existing
  1123. Tests}), and they also warn you when @command{configure} is created if they
  1124. are called out of order.
  1125. To encourage consistency, here is a suggested order for calling the
  1126. Autoconf macros. Generally speaking, the things near the end of this
  1127. list are those that could depend on things earlier in it. For example,
  1128. library functions could be affected by types and libraries.
  1129. @display
  1130. @group
  1131. Autoconf requirements
  1132. @code{AC_INIT(@var{package}, @var{version}, @var{bug-report-address})}
  1133. information on the package
  1134. checks for programs
  1135. checks for libraries
  1136. checks for header files
  1137. checks for types
  1138. checks for structures
  1139. checks for compiler characteristics
  1140. checks for library functions
  1141. checks for system services
  1142. @code{AC_CONFIG_FILES(@r{[}@var{file@dots{}}@r{]})}
  1143. @code{AC_OUTPUT}
  1144. @end group
  1145. @end display
  1146. @node autoscan Invocation
  1147. @section Using @command{autoscan} to Create @file{configure.ac}
  1148. @cindex @command{autoscan}
  1149. The @command{autoscan} program can help you create and/or maintain a
  1150. @file{configure.ac} file for a software package. @command{autoscan}
  1151. examines source files in the directory tree rooted at a directory given
  1152. as a command line argument, or the current directory if none is given.
  1153. It searches the source files for common portability problems and creates
  1154. a file @file{configure.scan} which is a preliminary @file{configure.ac}
  1155. for that package, and checks a possibly existing @file{configure.ac} for
  1156. completeness.
  1157. When using @command{autoscan} to create a @file{configure.ac}, you
  1158. should manually examine @file{configure.scan} before renaming it to
  1159. @file{configure.ac}; it probably needs some adjustments.
  1160. Occasionally, @command{autoscan} outputs a macro in the wrong order
  1161. relative to another macro, so that @command{autoconf} produces a warning;
  1162. you need to move such macros manually. Also, if you want the package to
  1163. use a configuration header file, you must add a call to
  1164. @code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers}). You might
  1165. also have to change or add some @code{#if} directives to your program in
  1166. order to make it work with Autoconf (@pxref{ifnames Invocation}, for
  1167. information about a program that can help with that job).
  1168. When using @command{autoscan} to maintain a @file{configure.ac}, simply
  1169. consider adding its suggestions. The file @file{autoscan.log}
  1170. contains detailed information on why a macro is requested.
  1171. @command{autoscan} uses several data files (installed along with Autoconf)
  1172. to determine which macros to output when it finds particular symbols in
  1173. a package's source files. These data files all have the same format:
  1174. each line consists of a symbol, one or more blanks, and the Autoconf macro to
  1175. output if that symbol is encountered. Lines starting with @samp{#} are
  1176. comments.
  1177. @command{autoscan} accepts the following options:
  1178. @table @option
  1179. @item --help
  1180. @itemx -h
  1181. Print a summary of the command line options and exit.
  1182. @item --version
  1183. @itemx -V
  1184. Print the version number of Autoconf and exit.
  1185. @item --verbose
  1186. @itemx -v
  1187. Print the names of the files it examines and the potentially interesting
  1188. symbols it finds in them. This output can be voluminous.
  1189. @item --debug
  1190. @itemx -d
  1191. Don't remove temporary files.
  1192. @item --include=@var{dir}
  1193. @itemx -I @var{dir}
  1194. Append @var{dir} to the include path. Multiple invocations accumulate.
  1195. @item --prepend-include=@var{dir}
  1196. @itemx -B @var{dir}
  1197. Prepend @var{dir} to the include path. Multiple invocations accumulate.
  1198. @end table
  1199. @node ifnames Invocation
  1200. @section Using @command{ifnames} to List Conditionals
  1201. @cindex @command{ifnames}
  1202. @command{ifnames} can help you write @file{configure.ac} for a software
  1203. package. It prints the identifiers that the package already uses in C
  1204. preprocessor conditionals. If a package has already been set up to have
  1205. some portability, @command{ifnames} can thus help you figure out what its
  1206. @command{configure} needs to check for. It may help fill in some gaps in a
  1207. @file{configure.ac} generated by @command{autoscan} (@pxref{autoscan
  1208. Invocation}).
  1209. @command{ifnames} scans all of the C source files named on the command line
  1210. (or the standard input, if none are given) and writes to the standard
  1211. output a sorted list of all the identifiers that appear in those files
  1212. in @code{#if}, @code{#elif}, @code{#ifdef}, or @code{#ifndef}
  1213. directives. It prints each identifier on a line, followed by a
  1214. space-separated list of the files in which that identifier occurs.
  1215. @noindent
  1216. @command{ifnames} accepts the following options:
  1217. @table @option
  1218. @item --help
  1219. @itemx -h
  1220. Print a summary of the command line options and exit.
  1221. @item --version
  1222. @itemx -V
  1223. Print the version number of Autoconf and exit.
  1224. @end table
  1225. @node autoconf Invocation
  1226. @section Using @command{autoconf} to Create @command{configure}
  1227. @cindex @command{autoconf}
  1228. To create @command{configure} from @file{configure.ac}, run the
  1229. @command{autoconf} program with no arguments. @command{autoconf} processes
  1230. @file{configure.ac} with the M4 macro processor, using the
  1231. Autoconf macros. If you give @command{autoconf} an argument, it reads that
  1232. file instead of @file{configure.ac} and writes the configuration script
  1233. to the standard output instead of to @command{configure}. If you give
  1234. @command{autoconf} the argument @option{-}, it reads from the standard
  1235. input instead of @file{configure.ac} and writes the configuration script
  1236. to the standard output.
  1237. The Autoconf macros are defined in several files. Some of the files are
  1238. distributed with Autoconf; @command{autoconf} reads them first. Then it
  1239. looks for the optional file @file{acsite.m4} in the directory that
  1240. contains the distributed Autoconf macro files, and for the optional file
  1241. @file{aclocal.m4} in the current directory. Those files can contain
  1242. your site's or the package's own Autoconf macro definitions
  1243. (@pxref{Writing Autoconf Macros}, for more information). If a macro is
  1244. defined in more than one of the files that @command{autoconf} reads, the
  1245. last definition it reads overrides the earlier ones.
  1246. @command{autoconf} accepts the following options:
  1247. @table @option
  1248. @item --help
  1249. @itemx -h
  1250. Print a summary of the command line options and exit.
  1251. @item --version
  1252. @itemx -V
  1253. Print the version number of Autoconf and exit.
  1254. @item --verbose
  1255. @itemx -v
  1256. Report processing steps.
  1257. @item --debug
  1258. @itemx -d
  1259. Don't remove the temporary files.
  1260. @item --force
  1261. @itemx -f
  1262. Remake @file{configure} even if newer than its input files.
  1263. @item --include=@var{dir}
  1264. @itemx -I @var{dir}
  1265. Append @var{dir} to the include path. Multiple invocations accumulate.
  1266. @item --prepend-include=@var{dir}
  1267. @itemx -B @var{dir}
  1268. Prepend @var{dir} to the include path. Multiple invocations accumulate.
  1269. @item --output=@var{file}
  1270. @itemx -o @var{file}
  1271. Save output (script or trace) to @var{file}. The file @option{-} stands
  1272. for the standard output.
  1273. @item --warnings=@var{category}
  1274. @itemx -W @var{category}
  1275. @evindex WARNINGS
  1276. Report the warnings related to @var{category} (which can actually be a
  1277. comma separated list). @xref{Reporting Messages}, macro
  1278. @code{AC_DIAGNOSE}, for a comprehensive list of categories. Special
  1279. values include:
  1280. @table @samp
  1281. @item all
  1282. report all the warnings
  1283. @item none
  1284. report none
  1285. @item error
  1286. treats warnings as errors
  1287. @item no-@var{category}
  1288. disable warnings falling into @var{category}
  1289. @end table
  1290. Warnings about @samp{syntax} are enabled by default, and the environment
  1291. variable @env{WARNINGS}, a comma separated list of categories, is
  1292. honored as well. Passing @option{-W @var{category}} actually behaves as if
  1293. you had passed @option{--warnings syntax,$WARNINGS,@var{category}}. To
  1294. disable the defaults and @env{WARNINGS}, and then
  1295. enable warnings about obsolete constructs, use @option{-W
  1296. none,obsolete}.
  1297. @cindex Back trace
  1298. @cindex Macro invocation stack
  1299. Because @command{autoconf} uses @command{autom4te} behind the scenes, it
  1300. displays a back trace for errors, but not for warnings; if you want
  1301. them, just pass @option{-W error}. @xref{autom4te Invocation}, for some
  1302. examples.
  1303. @item --trace=@var{macro}[:@var{format}]
  1304. @itemx -t @var{macro}[:@var{format}]
  1305. Do not create the @command{configure} script, but list the calls to
  1306. @var{macro} according to the @var{format}. Multiple @option{--trace}
  1307. arguments can be used to list several macros. Multiple @option{--trace}
  1308. arguments for a single macro are not cumulative; instead, you should
  1309. just make @var{format} as long as needed.
  1310. The @var{format} is a regular string, with newlines if desired, and
  1311. several special escape codes. It defaults to @samp{$f:$l:$n:$%}; see
  1312. @ref{autom4te Invocation}, for details on the @var{format}.
  1313. @item --initialization
  1314. @itemx -i
  1315. By default, @option{--trace} does not trace the initialization of the
  1316. Autoconf macros (typically the @code{AC_DEFUN} definitions). This
  1317. results in a noticeable speedup, but can be disabled by this option.
  1318. @end table
  1319. It is often necessary to check the content of a @file{configure.ac}
  1320. file, but parsing it yourself is extremely fragile and error-prone. It
  1321. is suggested that you rely upon @option{--trace} to scan
  1322. @file{configure.ac}. For instance, to find the list of variables that
  1323. are substituted, use:
  1324. @example
  1325. @group
  1326. $ @kbd{autoconf -t AC_SUBST}
  1327. configure.ac:2:AC_SUBST:ECHO_C
  1328. configure.ac:2:AC_SUBST:ECHO_N
  1329. configure.ac:2:AC_SUBST:ECHO_T
  1330. @i{More traces deleted}
  1331. @end group
  1332. @end example
  1333. @noindent
  1334. The example below highlights the difference between @samp{$@@},
  1335. @samp{$*}, and @samp{$%}.
  1336. @example
  1337. @group
  1338. $ @kbd{cat configure.ac}
  1339. AC_DEFINE(This, is, [an
  1340. [example]])
  1341. $ @kbd{autoconf -t 'AC_DEFINE:@@: $@@}
  1342. *: $*
  1343. %: $%'
  1344. @@: [This],[is],[an
  1345. [example]]
  1346. *: This,is,an
  1347. [example]
  1348. %: This:is:an [example]
  1349. @end group
  1350. @end example
  1351. @noindent
  1352. The @var{format} gives you a lot of freedom:
  1353. @example
  1354. @group
  1355. $ @kbd{autoconf -t 'AC_SUBST:$$ac_subst@{"$1"@} = "$f:$l";'}
  1356. $ac_subst@{"ECHO_C"@} = "configure.ac:2";
  1357. $ac_subst@{"ECHO_N"@} = "configure.ac:2";
  1358. $ac_subst@{"ECHO_T"@} = "configure.ac:2";
  1359. @i{More traces deleted}
  1360. @end group
  1361. @end example
  1362. @noindent
  1363. A long @var{separator} can be used to improve the readability of complex
  1364. structures, and to ease their parsing (for instance when no single
  1365. character is suitable as a separator):
  1366. @example
  1367. @group
  1368. $ @kbd{autoconf -t 'AM_MISSING_PROG:$@{|:::::|@}*'}
  1369. ACLOCAL|:::::|aclocal|:::::|$missing_dir
  1370. AUTOCONF|:::::|autoconf|:::::|$missing_dir
  1371. AUTOMAKE|:::::|automake|:::::|$missing_dir
  1372. @i{More traces deleted}
  1373. @end group
  1374. @end example
  1375. @node autoreconf Invocation
  1376. @section Using @command{autoreconf} to Update @command{configure} Scripts
  1377. @cindex @command{autoreconf}
  1378. Installing the various components of the GNU Build System can be
  1379. tedious: running @command{autopoint} for Gettext, @command{automake} for
  1380. @file{Makefile.in} etc.@: in each directory. It may be needed either
  1381. because some tools such as @command{automake} have been updated on your
  1382. system, or because some of the sources such as @file{configure.ac} have
  1383. been updated, or finally, simply in order to install the GNU Build
  1384. System in a fresh tree.
  1385. @command{autoreconf} runs @command{autoconf}, @command{autoheader},
  1386. @command{aclocal}, @command{automake}, @command{libtoolize}, and
  1387. @command{autopoint} (when appropriate) repeatedly to update the
  1388. GNU Build System in the specified directories and their
  1389. subdirectories (@pxref{Subdirectories}). By default, it only remakes
  1390. those files that are older than their sources. The environment variables
  1391. @env{AUTOM4TE}, @env{AUTOCONF}, @env{AUTOHEADER}, @env{AUTOMAKE},
  1392. @env{ACLOCAL}, @env{AUTOPOINT}, @env{LIBTOOLIZE}, @env{M4}, and @env{MAKE}
  1393. may be used to override the invocation of the respective tools.
  1394. If you install a new version of some tool, you can make
  1395. @command{autoreconf} remake @emph{all} of the files by giving it the
  1396. @option{--force} option.
  1397. @xref{Automatic Remaking}, for Make rules to automatically
  1398. rebuild @command{configure} scripts when their source files change. That
  1399. method handles the timestamps of configuration header templates
  1400. properly, but does not pass @option{--autoconf-dir=@var{dir}} or
  1401. @option{--localdir=@var{dir}}.
  1402. @cindex Gettext
  1403. @cindex @command{autopoint}
  1404. Gettext supplies the @command{autopoint} command to add translation
  1405. infrastructure to a source package. If you use @command{autopoint},
  1406. your @file{configure.ac} should invoke both @code{AM_GNU_GETTEXT} and
  1407. @code{AM_GNU_GETTEXT_VERSION(@var{gettext-version})}. @xref{autopoint
  1408. Invocation, , Invoking the @code{autopoint} Program, gettext,
  1409. GNU @code{gettext} utilities}, for further details.
  1410. @noindent
  1411. @command{autoreconf} accepts the following options:
  1412. @table @option
  1413. @item --help
  1414. @itemx -h
  1415. Print a summary of the command line options and exit.
  1416. @item --version
  1417. @itemx -V
  1418. Print the version number of Autoconf and exit.
  1419. @item --verbose
  1420. @itemx -v
  1421. Print the name of each directory @command{autoreconf} examines and the
  1422. commands it runs. If given two or more times, pass @option{--verbose}
  1423. to subordinate tools that support it.
  1424. @item --debug
  1425. @itemx -d
  1426. Don't remove the temporary files.
  1427. @item --force
  1428. @itemx -f
  1429. Remake even @file{configure} scripts and configuration headers that are
  1430. newer than their input files (@file{configure.ac} and, if present,
  1431. @file{aclocal.m4}).
  1432. @item --install
  1433. @itemx -i
  1434. Install the missing auxiliary files in the package. By default, files
  1435. are copied; this can be changed with @option{--symlink}.
  1436. If deemed appropriate, this option triggers calls to
  1437. @samp{automake --add-missing},
  1438. @samp{libtoolize}, @samp{autopoint}, etc.
  1439. @item --no-recursive
  1440. Do not rebuild files in subdirectories to configure (see @ref{Subdirectories},
  1441. macro @code{AC_CONFIG_SUBDIRS}).
  1442. @item --symlink
  1443. @itemx -s
  1444. When used with @option{--install}, install symbolic links to the missing
  1445. auxiliary files instead of copying them.
  1446. @item --make
  1447. @itemx -m
  1448. When the directories were configured, update the configuration by
  1449. running @samp{./config.status --recheck && ./config.status}, and then
  1450. run @samp{make}.
  1451. @item --include=@var{dir}
  1452. @itemx -I @var{dir}
  1453. Append @var{dir} to the include path. Multiple invocations accumulate.
  1454. Passed on to @command{aclocal}, @command{autoconf} and
  1455. @command{autoheader} internally.
  1456. @item --prepend-include=@var{dir}
  1457. @itemx -B @var{dir}
  1458. Prepend @var{dir} to the include path. Multiple invocations accumulate.
  1459. Passed on to @command{autoconf} and @command{autoheader} internally.
  1460. @item --warnings=@var{category}
  1461. @itemx -W @var{category}
  1462. @evindex WARNINGS
  1463. Report the warnings related to @var{category} (which can actually be a
  1464. comma separated list).
  1465. @table @samp
  1466. @item cross
  1467. related to cross compilation issues.
  1468. @item obsolete
  1469. report the uses of obsolete constructs.
  1470. @item portability
  1471. portability issues
  1472. @item syntax
  1473. dubious syntactic constructs.
  1474. @item all
  1475. report all the warnings
  1476. @item none
  1477. report none
  1478. @item error
  1479. treats warnings as errors
  1480. @item no-@var{category}
  1481. disable warnings falling into @var{category}
  1482. @end table
  1483. Warnings about @samp{syntax} are enabled by default, and the environment
  1484. variable @env{WARNINGS}, a comma separated list of categories, is
  1485. honored as well. Passing @option{-W @var{category}} actually behaves as if
  1486. you had passed @option{--warnings syntax,$WARNINGS,@var{category}}. To
  1487. disable the defaults and @env{WARNINGS}, and then
  1488. enable warnings about obsolete constructs, use @option{-W
  1489. none,obsolete}.
  1490. @end table
  1491. If you want @command{autoreconf} to pass flags that are not listed here
  1492. on to @command{aclocal}, set @code{ACLOCAL_AMFLAGS} in your @file{Makefile.am}.
  1493. Due to a limitation in the Autoconf implementation these flags currently
  1494. must be set on a single line in @file{Makefile.am}, without any
  1495. backslash-newlines.
  1496. @c ========================================= Initialization and Output Files.
  1497. @node Setup
  1498. @chapter Initialization and Output Files
  1499. Autoconf-generated @command{configure} scripts need some information about
  1500. how to initialize, such as how to find the package's source files and
  1501. about the output files to produce. The following sections describe the
  1502. initialization and the creation of output files.
  1503. @menu
  1504. * Initializing configure:: Option processing etc.
  1505. * Versioning:: Dealing with Autoconf versions
  1506. * Notices:: Copyright, version numbers in @command{configure}
  1507. * Input:: Where Autoconf should find files
  1508. * Output:: Outputting results from the configuration
  1509. * Configuration Actions:: Preparing the output based on results
  1510. * Configuration Files:: Creating output files
  1511. * Makefile Substitutions:: Using output variables in makefiles
  1512. * Configuration Headers:: Creating a configuration header file
  1513. * Configuration Commands:: Running arbitrary instantiation commands
  1514. * Configuration Links:: Links depending on the configuration
  1515. * Subdirectories:: Configuring independent packages together
  1516. * Default Prefix:: Changing the default installation prefix
  1517. @end menu
  1518. @node Initializing configure
  1519. @section Initializing @command{configure}
  1520. Every @command{configure} script must call @code{AC_INIT} before doing
  1521. anything else that produces output. Calls to silent macros, such as
  1522. @code{AC_DEFUN}, may also occur prior to @code{AC_INIT}, although these
  1523. are generally used via @file{aclocal.m4}, since that is implicitly
  1524. included before the start of @file{configure.ac}. The only other
  1525. required macro is @code{AC_OUTPUT} (@pxref{Output}).
  1526. @anchor{AC_INIT}
  1527. @defmac AC_INIT (@var{package}, @var{version}, @ovar{bug-report}, @
  1528. @ovar{tarname}, @ovar{url})
  1529. @acindex{INIT}
  1530. Process any command-line arguments and perform initialization
  1531. and verification.
  1532. Set the name of the @var{package} and its @var{version}. These are
  1533. typically used in @option{--version} support, including that of
  1534. @command{configure}. The optional argument @var{bug-report} should be
  1535. the email to which users should send bug reports. The package
  1536. @var{tarname} differs from @var{package}: the latter designates the full
  1537. package name (e.g., @samp{GNU Autoconf}), while the former is meant for
  1538. distribution tar ball names (e.g., @samp{autoconf}). It defaults to
  1539. @var{package} with @samp{GNU } stripped, lower-cased, and all characters
  1540. other than alphanumerics and underscores are changed to @samp{-}. If
  1541. provided, @var{url} should be the home page for the package.
  1542. The arguments of @code{AC_INIT} must be static, i.e., there should not
  1543. be any shell computation, quotes, or newlines, but they can be computed
  1544. by M4. This is because the package information strings are expanded at
  1545. M4 time into several contexts, and must give the same text at shell time
  1546. whether used in single-quoted strings, double-quoted strings, quoted
  1547. here-documents, or unquoted here-documents. It is permissible to use
  1548. @code{m4_esyscmd} or @code{m4_esyscmd_s} for computing a version string
  1549. that changes with every commit to a version control system (in fact,
  1550. Autoconf does just that, for all builds of the development tree made
  1551. between releases).
  1552. The following M4 macros (e.g., @code{AC_PACKAGE_NAME}), output variables
  1553. (e.g., @code{PACKAGE_NAME}), and preprocessor symbols (e.g.,
  1554. @code{PACKAGE_NAME}), are defined by @code{AC_INIT}:
  1555. @table @asis
  1556. @item @code{AC_PACKAGE_NAME}, @code{PACKAGE_NAME}
  1557. @acindex{PACKAGE_NAME}
  1558. @ovindex PACKAGE_NAME
  1559. @cvindex PACKAGE_NAME
  1560. Exactly @var{package}.
  1561. @item @code{AC_PACKAGE_TARNAME}, @code{PACKAGE_TARNAME}
  1562. @acindex{PACKAGE_TARNAME}
  1563. @ovindex PACKAGE_TARNAME
  1564. @cvindex PACKAGE_TARNAME
  1565. Exactly @var{tarname}, possibly generated from @var{package}.
  1566. @item @code{AC_PACKAGE_VERSION}, @code{PACKAGE_VERSION}
  1567. @acindex{PACKAGE_VERSION}
  1568. @ovindex PACKAGE_VERSION
  1569. @cvindex PACKAGE_VERSION
  1570. Exactly @var{version}.
  1571. @item @code{AC_PACKAGE_STRING}, @code{PACKAGE_STRING}
  1572. @acindex{PACKAGE_STRING}
  1573. @ovindex PACKAGE_STRING
  1574. @cvindex PACKAGE_STRING
  1575. Exactly @samp{@var{package} @var{version}}.
  1576. @item @code{AC_PACKAGE_BUGREPORT}, @code{PACKAGE_BUGREPORT}
  1577. @acindex{PACKAGE_BUGREPORT}
  1578. @ovindex PACKAGE_BUGREPORT
  1579. @cvindex PACKAGE_BUGREPORT
  1580. Exactly @var{bug-report}, if one was provided. Typically an email
  1581. address, or URL to a bug management web page.
  1582. @item @code{AC_PACKAGE_URL}, @code{PACKAGE_URL}
  1583. @acindex{PACKAGE_URL}
  1584. @ovindex PACKAGE_URL
  1585. @cvindex PACKAGE_URL
  1586. Exactly @var{url}, if one was provided. If @var{url} was empty, but
  1587. @var{package} begins with @samp{GNU }, then this defaults to
  1588. @samp{http://@/www.gnu.org/@/software/@/@var{tarname}/}, otherwise, no URL is
  1589. assumed.
  1590. @end table
  1591. @end defmac
  1592. If your @command{configure} script does its own option processing, it
  1593. should inspect @samp{$@@} or @samp{$*} immediately after calling
  1594. @code{AC_INIT}, because other Autoconf macros liberally use the
  1595. @command{set} command to process strings, and this has the side effect
  1596. of updating @samp{$@@} and @samp{$*}. However, we suggest that you use
  1597. standard macros like @code{AC_ARG_ENABLE} instead of attempting to
  1598. implement your own option processing. @xref{Site Configuration}.
  1599. @node Versioning
  1600. @section Dealing with Autoconf versions
  1601. @cindex Autoconf version
  1602. @cindex version, Autoconf
  1603. The following optional macros can be used to help choose the minimum
  1604. version of Autoconf that can successfully compile a given
  1605. @file{configure.ac}.
  1606. @defmac AC_PREREQ (@var{version})
  1607. @acindex{PREREQ}
  1608. @cindex Version
  1609. Ensure that a recent enough version of Autoconf is being used. If the
  1610. version of Autoconf being used to create @command{configure} is
  1611. earlier than @var{version}, print an error message to the standard
  1612. error output and exit with failure (exit status is 63). For example:
  1613. @example
  1614. AC_PREREQ([@value{VERSION}])
  1615. @end example
  1616. This macro may be used before @code{AC_INIT}.
  1617. @end defmac
  1618. @defmac AC_AUTOCONF_VERSION
  1619. @acindex{AUTOCONF_VERSION}
  1620. This macro was introduced in Autoconf 2.62. It identifies the version
  1621. of Autoconf that is currently parsing the input file, in a format
  1622. suitable for @code{m4_version_compare} (@pxref{m4_version_compare}); in
  1623. other words, for this release of Autoconf, its value is
  1624. @samp{@value{VERSION}}. One potential use of this macro is for writing
  1625. conditional fallbacks based on when a feature was added to Autoconf,
  1626. rather than using @code{AC_PREREQ} to require the newer version of
  1627. Autoconf. However, remember that the Autoconf philosophy favors feature
  1628. checks over version checks.
  1629. You should not expand this macro directly; use
  1630. @samp{m4_defn([AC_AUTOCONF_VERSION])} instead. This is because some
  1631. users might
  1632. have a beta version of Autoconf installed, with arbitrary letters
  1633. included in its version string. This means it is possible for the
  1634. version string to contain the name of a defined macro, such that
  1635. expanding @code{AC_AUTOCONF_VERSION} would trigger the expansion of that
  1636. macro during rescanning, and change the version string to be different
  1637. than what you intended to check.
  1638. @end defmac
  1639. @node Notices
  1640. @section Notices in @command{configure}
  1641. @cindex Notices in @command{configure}
  1642. The following macros manage version numbers for @command{configure}
  1643. scripts. Using them is optional.
  1644. @defmac AC_COPYRIGHT (@var{copyright-notice})
  1645. @acindex{COPYRIGHT}
  1646. @cindex Copyright Notice
  1647. State that, in addition to the Free Software Foundation's copyright on
  1648. the Autoconf macros, parts of your @command{configure} are covered by the
  1649. @var{copyright-notice}.
  1650. The @var{copyright-notice} shows up in both the head of
  1651. @command{configure} and in @samp{configure --version}.
  1652. @end defmac
  1653. @defmac AC_REVISION (@var{revision-info})
  1654. @acindex{REVISION}
  1655. @cindex Revision
  1656. Copy revision stamp @var{revision-info} into the @command{configure}
  1657. script, with any dollar signs or double-quotes removed. This macro lets
  1658. you put a revision stamp from @file{configure.ac} into @command{configure}
  1659. without RCS or CVS changing it when you check in
  1660. @command{configure}. That way, you can determine easily which revision of
  1661. @file{configure.ac} a particular @command{configure} corresponds to.
  1662. For example, this line in @file{configure.ac}:
  1663. @c The @w prevents RCS from changing the example in the manual.
  1664. @example
  1665. AC_REVISION([@w{$}Revision: 1.30 $])
  1666. @end example
  1667. @noindent
  1668. produces this in @command{configure}:
  1669. @example
  1670. #!/bin/sh
  1671. # From configure.ac Revision: 1.30
  1672. @end example
  1673. @end defmac
  1674. @node Input
  1675. @section Finding @command{configure} Input
  1676. @anchor{AC_CONFIG_SRCDIR}
  1677. @defmac AC_CONFIG_SRCDIR (@var{unique-file-in-source-dir})
  1678. @acindex{CONFIG_SRCDIR}
  1679. @var{unique-file-in-source-dir} is some file that is in the package's
  1680. source directory; @command{configure} checks for this file's existence to
  1681. make sure that the directory that it is told contains the source code in
  1682. fact does. Occasionally people accidentally specify the wrong directory
  1683. with @option{--srcdir}; this is a safety check. @xref{configure
  1684. Invocation}, for more information.
  1685. @end defmac
  1686. @c FIXME: Remove definitively once --install explained.
  1687. @c
  1688. @c Small packages may store all their macros in @code{aclocal.m4}. As the
  1689. @c set of macros grows, or for maintenance reasons, a maintainer may prefer
  1690. @c to split the macros in several files. In this case, Autoconf must be
  1691. @c told which files to load, and in which order.
  1692. @c
  1693. @c @defmac AC_INCLUDE (@var{file}@dots{})
  1694. @c @acindex{INCLUDE}
  1695. @c @c FIXME: There is no longer shell globbing.
  1696. @c Read the macro definitions that appear in the listed files. A list of
  1697. @c space-separated file names or shell globbing patterns is expected. The
  1698. @c files are read in the order they're listed.
  1699. @c
  1700. @c Because the order of definition of macros is important (only the last
  1701. @c definition of a macro is used), beware that it is @code{AC_INIT} that
  1702. @c loads @file{acsite.m4} and @file{aclocal.m4}. Note that
  1703. @c @code{AC_INCLUDE}ing a file before @code{AC_INIT} or within
  1704. @c @file{aclocal.m4} is different from doing so after @code{AC_INIT}: in
  1705. @c the latter case, non-macro lines from included files may end up in the
  1706. @c @file{configure} script, whereas in the former case, they'd be discarded
  1707. @c just like any text that appear before @code{AC_INIT}.
  1708. @c @end defmac
  1709. Packages that do manual configuration or use the @command{install} program
  1710. might need to tell @command{configure} where to find some other shell
  1711. scripts by calling @code{AC_CONFIG_AUX_DIR}, though the default places
  1712. it looks are correct for most cases.
  1713. @defmac AC_CONFIG_AUX_DIR (@var{dir})
  1714. @acindex{CONFIG_AUX_DIR}
  1715. Use the auxiliary build tools (e.g., @file{install-sh},
  1716. @file{config.sub}, @file{config.guess}, Cygnus @command{configure},
  1717. Automake and Libtool scripts, etc.)@: that are in directory @var{dir}.
  1718. These are auxiliary files used in configuration. @var{dir} can be
  1719. either absolute or relative to @file{@var{srcdir}}. The default is
  1720. @file{@var{srcdir}} or @file{@var{srcdir}/..} or
  1721. @file{@var{srcdir}/../..}, whichever is the first that contains
  1722. @file{install-sh}. The other files are not checked for, so that using
  1723. @code{AC_PROG_INSTALL} does not automatically require distributing the
  1724. other auxiliary files. It checks for @file{install.sh} also, but that
  1725. name is obsolete because some @command{make} have a rule that creates
  1726. @file{install} from it if there is no makefile.
  1727. The auxiliary directory is commonly named @file{build-aux}.
  1728. If you need portability to DOS variants, do not name the
  1729. auxiliary directory @file{aux}. @xref{File System Conventions}.
  1730. @end defmac
  1731. @defmac AC_REQUIRE_AUX_FILE (@var{file})
  1732. @acindex{REQUIRE_AUX_FILE}
  1733. Declares that @var{file} is expected in the directory defined above. In
  1734. Autoconf proper, this macro does nothing: its sole purpose is to be
  1735. traced by third-party tools to produce a list of expected auxiliary
  1736. files. For instance it is called by macros like @code{AC_PROG_INSTALL}
  1737. (@pxref{Particular Programs}) or @code{AC_CANONICAL_BUILD}
  1738. (@pxref{Canonicalizing}) to register the auxiliary files they need.
  1739. @end defmac
  1740. Similarly, packages that use @command{aclocal} should declare where
  1741. local macros can be found using @code{AC_CONFIG_MACRO_DIR}.
  1742. @defmac AC_CONFIG_MACRO_DIR (@var{dir})
  1743. @acindex{CONFIG_MACRO_DIR}
  1744. Specify @var{dir} as the location of additional local Autoconf macros.
  1745. This macro is intended for use by future versions of commands like
  1746. @command{autoreconf} that trace macro calls. It should be called
  1747. directly from @file{configure.ac} so that tools that install macros for
  1748. @command{aclocal} can find the macros' declarations.
  1749. Note that if you use @command{aclocal} from Automake to generate
  1750. @file{aclocal.m4}, you must also set @code{ACLOCAL_AMFLAGS = -I
  1751. @var{dir}} in your top-level @file{Makefile.am}. Due to a limitation in
  1752. the Autoconf implementation of @command{autoreconf}, these include
  1753. directives currently must be set on a single line in @file{Makefile.am},
  1754. without any backslash-newlines.
  1755. @end defmac
  1756. @node Output
  1757. @section Outputting Files
  1758. @cindex Outputting files
  1759. Every Autoconf script, e.g., @file{configure.ac}, should finish by
  1760. calling @code{AC_OUTPUT}. That is the macro that generates and runs
  1761. @file{config.status}, which in turn creates the makefiles and any
  1762. other files resulting from configuration. This is the only required
  1763. macro besides @code{AC_INIT} (@pxref{Input}).
  1764. @anchor{AC_OUTPUT}
  1765. @defmac AC_OUTPUT
  1766. @acindex{OUTPUT}
  1767. @cindex Instantiation
  1768. Generate @file{config.status} and launch it. Call this macro once, at
  1769. the end of @file{configure.ac}.
  1770. @file{config.status} performs all the configuration actions: all the
  1771. output files (see @ref{Configuration Files}, macro
  1772. @code{AC_CONFIG_FILES}), header files (see @ref{Configuration Headers},
  1773. macro @code{AC_CONFIG_HEADERS}), commands (see @ref{Configuration
  1774. Commands}, macro @code{AC_CONFIG_COMMANDS}), links (see
  1775. @ref{Configuration Links}, macro @code{AC_CONFIG_LINKS}), subdirectories
  1776. to configure (see @ref{Subdirectories}, macro @code{AC_CONFIG_SUBDIRS})
  1777. are honored.
  1778. The location of your @code{AC_OUTPUT} invocation is the exact point
  1779. where configuration actions are taken: any code afterwards is
  1780. executed by @command{configure} once @command{config.status} was run. If
  1781. you want to bind actions to @command{config.status} itself
  1782. (independently of whether @command{configure} is being run), see
  1783. @ref{Configuration Commands, , Running Arbitrary Configuration
  1784. Commands}.
  1785. @end defmac
  1786. Historically, the usage of @code{AC_OUTPUT} was somewhat different.
  1787. @xref{Obsolete Macros}, for a description of the arguments that
  1788. @code{AC_OUTPUT} used to support.
  1789. If you run @command{make} in subdirectories, you should run it using the
  1790. @command{make} variable @code{MAKE}. Most versions of @command{make} set
  1791. @code{MAKE} to the name of the @command{make} program plus any options it
  1792. was given. (But many do not include in it the values of any variables
  1793. set on the command line, so those are not passed on automatically.)
  1794. Some old versions of @command{make} do not set this variable. The
  1795. following macro allows you to use it even with those versions.
  1796. @anchor{AC_PROG_MAKE_SET}
  1797. @defmac AC_PROG_MAKE_SET
  1798. @acindex{PROG_MAKE_SET}
  1799. @ovindex SET_MAKE
  1800. If the Make command, @code{$MAKE} if set or else @samp{make}, predefines
  1801. @code{$(MAKE)}, define output variable @code{SET_MAKE} to be empty.
  1802. Otherwise, define @code{SET_MAKE} to a macro definition that sets
  1803. @code{$(MAKE)}, such as @samp{MAKE=make}. Calls @code{AC_SUBST} for
  1804. @code{SET_MAKE}.
  1805. @end defmac
  1806. If you use this macro, place a line like this in each @file{Makefile.in}
  1807. that runs @command{MAKE} on other directories:
  1808. @example
  1809. @@SET_MAKE@@
  1810. @end example
  1811. @node Configuration Actions
  1812. @section Performing Configuration Actions
  1813. @cindex Configuration actions
  1814. @file{configure} is designed so that it appears to do everything itself,
  1815. but there is actually a hidden slave: @file{config.status}.
  1816. @file{configure} is in charge of examining your system, but it is
  1817. @file{config.status} that actually takes the proper actions based on the
  1818. results of @file{configure}. The most typical task of
  1819. @file{config.status} is to @emph{instantiate} files.
  1820. @acindex{CONFIG_@var{ITEMS}}
  1821. This section describes the common behavior of the four standard
  1822. instantiating macros: @code{AC_CONFIG_FILES}, @code{AC_CONFIG_HEADERS},
  1823. @code{AC_CONFIG_COMMANDS} and @code{AC_CONFIG_LINKS}. They all
  1824. have this prototype:
  1825. @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
  1826. @c awful.
  1827. @example
  1828. AC_CONFIG_@var{ITEMS}(@var{tag}@dots{}, @r{[}@var{commands}@r{]}, @r{[}@var{init-cmds}@r{]})
  1829. @end example
  1830. @noindent
  1831. where the arguments are:
  1832. @table @var
  1833. @item tag@dots{}
  1834. A blank-or-newline-separated list of tags, which are typically the names of
  1835. the files to instantiate.
  1836. You are encouraged to use literals as @var{tags}. In particular, you
  1837. should avoid
  1838. @example
  1839. @dots{} && my_foos="$my_foos fooo"
  1840. @dots{} && my_foos="$my_foos foooo"
  1841. AC_CONFIG_@var{ITEMS}([$my_foos])
  1842. @end example
  1843. @noindent
  1844. and use this instead:
  1845. @example
  1846. @dots{} && AC_CONFIG_@var{ITEMS}([fooo])
  1847. @dots{} && AC_CONFIG_@var{ITEMS}([foooo])
  1848. @end example
  1849. The macros @code{AC_CONFIG_FILES} and @code{AC_CONFIG_HEADERS} use
  1850. special @var{tag} values: they may have the form @samp{@var{output}} or
  1851. @samp{@var{output}:@var{inputs}}. The file @var{output} is instantiated
  1852. from its templates, @var{inputs} (defaulting to @samp{@var{output}.in}).
  1853. @samp{AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk])},
  1854. for example, asks for
  1855. the creation of the file @file{Makefile} that contains the expansion of the
  1856. output variables in the concatenation of @file{boiler/top.mk} and
  1857. @file{boiler/bot.mk}.
  1858. The special value @samp{-} might be used to denote the standard output
  1859. when used in @var{output}, or the standard input when used in the
  1860. @var{inputs}. You most probably don't need to use this in
  1861. @file{configure.ac}, but it is convenient when using the command line
  1862. interface of @file{./config.status}, see @ref{config.status Invocation},
  1863. for more details.
  1864. The @var{inputs} may be absolute or relative file names. In the latter
  1865. case they are first looked for in the build tree, and then in the source
  1866. tree. Input files should be text files, and a line length below 2000
  1867. bytes should be safe.
  1868. @item commands
  1869. Shell commands output literally into @file{config.status}, and
  1870. associated with a tag that the user can use to tell @file{config.status}
  1871. which commands to run. The commands are run each time a @var{tag}
  1872. request is given to @file{config.status}, typically each time the file
  1873. @file{@var{tag}} is created.
  1874. The variables set during the execution of @command{configure} are
  1875. @emph{not} available here: you first need to set them via the
  1876. @var{init-cmds}. Nonetheless the following variables are precomputed:
  1877. @table @code
  1878. @item srcdir
  1879. @vrindex srcdir
  1880. The name of the top source directory, assuming that the working
  1881. directory is the top build directory. This
  1882. is what the @command{configure} option @option{--srcdir} sets.
  1883. @item ac_top_srcdir
  1884. @vrindex ac_top_srcdir
  1885. The name of the top source directory, assuming that the working
  1886. directory is the current build directory.
  1887. @item ac_top_build_prefix
  1888. @vrindex ac_top_build_prefix
  1889. The name of the top build directory, assuming that the working
  1890. directory is the current build directory.
  1891. It can be empty, or else ends with a slash, so that you may concatenate
  1892. it.
  1893. @item ac_srcdir
  1894. @vrindex ac_srcdir
  1895. The name of the corresponding source directory, assuming that the
  1896. working directory is the current build directory.
  1897. @item tmp
  1898. @vrindex tmp
  1899. The name of a temporary directory within the build tree, which you
  1900. can use if you need to create additional temporary files. The
  1901. directory is cleaned up when @command{config.status} is done or
  1902. interrupted. Please use package-specific file name prefixes to
  1903. avoid clashing with files that @command{config.status} may use
  1904. internally.
  1905. @end table
  1906. @noindent
  1907. The @dfn{current} directory refers to the directory (or
  1908. pseudo-directory) containing the input part of @var{tags}. For
  1909. instance, running
  1910. @example
  1911. AC_CONFIG_COMMANDS([deep/dir/out:in/in.in], [@dots{}], [@dots{}])
  1912. @end example
  1913. @noindent
  1914. with @option{--srcdir=../package} produces the following values:
  1915. @example
  1916. # Argument of --srcdir
  1917. srcdir='../package'
  1918. # Reversing deep/dir
  1919. ac_top_build_prefix='../../'
  1920. # Concatenation of $ac_top_build_prefix and srcdir
  1921. ac_top_srcdir='../../../package'
  1922. # Concatenation of $ac_top_srcdir and deep/dir
  1923. ac_srcdir='../../../package/deep/dir'
  1924. @end example
  1925. @noindent
  1926. independently of @samp{in/in.in}.
  1927. @item init-cmds
  1928. Shell commands output @emph{unquoted} near the beginning of
  1929. @file{config.status}, and executed each time @file{config.status} runs
  1930. (regardless of the tag). Because they are unquoted, for example,
  1931. @samp{$var} is output as the value of @code{var}. @var{init-cmds}
  1932. is typically used by @file{configure} to give @file{config.status} some
  1933. variables it needs to run the @var{commands}.
  1934. You should be extremely cautious in your variable names: all the
  1935. @var{init-cmds} share the same name space and may overwrite each other
  1936. in unpredictable ways. Sorry@enddots{}
  1937. @end table
  1938. All these macros can be called multiple times, with different
  1939. @var{tag} values, of course!
  1940. @node Configuration Files
  1941. @section Creating Configuration Files
  1942. @cindex Creating configuration files
  1943. @cindex Configuration file creation
  1944. Be sure to read the previous section, @ref{Configuration Actions}.
  1945. @anchor{AC_CONFIG_FILES}
  1946. @defmac AC_CONFIG_FILES (@var{file}@dots{}, @ovar{cmds}, @ovar{init-cmds})
  1947. @acindex{CONFIG_FILES}
  1948. Make @code{AC_OUTPUT} create each @file{@var{file}} by copying an input
  1949. file (by default @file{@var{file}.in}), substituting the output variable
  1950. values.
  1951. @c Before we used to have this feature, which was later rejected
  1952. @c because it complicates the writing of makefiles:
  1953. @c If the file would be unchanged, it is left untouched, to preserve
  1954. @c timestamp.
  1955. This macro is one of the instantiating macros; see @ref{Configuration
  1956. Actions}. @xref{Makefile Substitutions}, for more information on using
  1957. output variables. @xref{Setting Output Variables}, for more information
  1958. on creating them. This macro creates the directory that the file is in
  1959. if it doesn't exist. Usually, makefiles are created this way,
  1960. but other files, such as @file{.gdbinit}, can be specified as well.
  1961. Typical calls to @code{AC_CONFIG_FILES} look like this:
  1962. @example
  1963. AC_CONFIG_FILES([Makefile src/Makefile man/Makefile X/Imakefile])
  1964. AC_CONFIG_FILES([autoconf], [chmod +x autoconf])
  1965. @end example
  1966. You can override an input file name by appending to @var{file} a
  1967. colon-separated list of input files. Examples:
  1968. @example
  1969. AC_CONFIG_FILES([Makefile:boiler/top.mk:boiler/bot.mk]
  1970. [lib/Makefile:boiler/lib.mk])
  1971. @end example
  1972. @noindent
  1973. Doing this allows you to keep your file names acceptable to
  1974. DOS variants, or
  1975. to prepend and/or append boilerplate to the file.
  1976. @end defmac
  1977. @node Makefile Substitutions
  1978. @section Substitutions in Makefiles
  1979. @cindex Substitutions in makefiles
  1980. @cindex Makefile substitutions
  1981. Each subdirectory in a distribution that contains something to be
  1982. compiled or installed should come with a file @file{Makefile.in}, from
  1983. which @command{configure} creates a file @file{Makefile} in that directory.
  1984. To create @file{Makefile}, @command{configure} performs a simple variable
  1985. substitution, replacing occurrences of @samp{@@@var{variable}@@} in
  1986. @file{Makefile.in} with the value that @command{configure} has determined
  1987. for that variable. Variables that are substituted into output files in
  1988. this way are called @dfn{output variables}. They are ordinary shell
  1989. variables that are set in @command{configure}. To make @command{configure}
  1990. substitute a particular variable into the output files, the macro
  1991. @code{AC_SUBST} must be called with that variable name as an argument.
  1992. Any occurrences of @samp{@@@var{variable}@@} for other variables are
  1993. left unchanged. @xref{Setting Output Variables}, for more information
  1994. on creating output variables with @code{AC_SUBST}.
  1995. A software package that uses a @command{configure} script should be
  1996. distributed with a file @file{Makefile.in}, but no makefile; that
  1997. way, the user has to properly configure the package for the local system
  1998. before compiling it.
  1999. @xref{Makefile Conventions, , Makefile Conventions, standards, The
  2000. GNU Coding Standards}, for more information on what to put in
  2001. makefiles.
  2002. @menu
  2003. * Preset Output Variables:: Output variables that are always set
  2004. * Installation Directory Variables:: Other preset output variables
  2005. * Changed Directory Variables:: Warnings about @file{datarootdir}
  2006. * Build Directories:: Supporting multiple concurrent compiles
  2007. * Automatic Remaking:: Makefile rules for configuring
  2008. @end menu
  2009. @node Preset Output Variables
  2010. @subsection Preset Output Variables
  2011. @cindex Output variables
  2012. Some output variables are preset by the Autoconf macros. Some of the
  2013. Autoconf macros set additional output variables, which are mentioned in
  2014. the descriptions for those macros. @xref{Output Variable Index}, for a
  2015. complete list of output variables. @xref{Installation Directory
  2016. Variables}, for the list of the preset ones related to installation
  2017. directories. Below are listed the other preset ones, many of which are
  2018. precious variables (@pxref{Setting Output Variables},
  2019. @code{AC_ARG_VAR}).
  2020. The preset variables which are available during @file{config.status}
  2021. (@pxref{Configuration Actions}) may also be used during
  2022. @command{configure} tests. For example, it is permissible to reference
  2023. @samp{$srcdir} when constructing a list of directories to pass via
  2024. option @option{-I} during a compiler feature check. When used in this
  2025. manner, coupled with the fact that @command{configure} is always run
  2026. from the top build directory, it is sufficient to use just
  2027. @samp{$srcdir} instead of @samp{$top_srcdir}.
  2028. @c Just say no to ASCII sorting! We're humans, not computers.
  2029. @c These variables are listed as they would be in a dictionary:
  2030. @c actor
  2031. @c Actress
  2032. @c actress
  2033. @defvar CFLAGS
  2034. @evindex CFLAGS
  2035. @ovindex CFLAGS
  2036. Debugging and optimization options for the C compiler. If it is not set
  2037. in the environment when @command{configure} runs, the default value is set
  2038. when you call @code{AC_PROG_CC} (or empty if you don't). @command{configure}
  2039. uses this variable when compiling or linking programs to test for C features.
  2040. If a compiler option affects only the behavior of the preprocessor
  2041. (e.g., @option{-D@var{name}}), it should be put into @code{CPPFLAGS}
  2042. instead. If it affects only the linker (e.g., @option{-L@var{directory}}),
  2043. it should be put into @code{LDFLAGS} instead. If it
  2044. affects only the compiler proper, @code{CFLAGS} is the natural home for
  2045. it. If an option affects multiple phases of the compiler, though,
  2046. matters get tricky. One approach to put such options directly into
  2047. @code{CC}, e.g., @code{CC='gcc -m64'}. Another is to put them into both
  2048. @code{CPPFLAGS} and @code{LDFLAGS}, but not into @code{CFLAGS}.
  2049. However, remember that some @file{Makefile} variables are reserved by
  2050. the GNU Coding Standards for the use of the ``user''---the person
  2051. building the package. For instance, @code{CFLAGS} is one such variable.
  2052. Sometimes package developers are tempted to set user variables such as
  2053. @code{CFLAGS} because it appears to make their job easier. However, the
  2054. package itself should never set a user variable, particularly not to
  2055. include switches that are required for proper compilation of the
  2056. package. Since these variables are documented as being for the package
  2057. builder, that person rightfully expects to be able to override any of
  2058. these variables at build time. If the package developer needs to add
  2059. switches without interfering with the user, the proper way to do that is
  2060. to introduce an additional variable. Automake makes this easy by
  2061. introducing @code{AM_CFLAGS} (@pxref{Flag Variables Ordering, , ,
  2062. automake, GNU Automake}), but the concept is the same even if
  2063. Automake is not used.
  2064. @end defvar
  2065. @defvar configure_input
  2066. @ovindex configure_input
  2067. A comment saying that the file was generated automatically by
  2068. @command{configure} and giving the name of the input file.
  2069. @code{AC_OUTPUT} adds a comment line containing this variable to the top
  2070. of every makefile it creates. For other files, you should
  2071. reference this variable in a comment at the top of each input file. For
  2072. example, an input shell script should begin like this:
  2073. @example
  2074. #!/bin/sh
  2075. # @@configure_input@@
  2076. @end example
  2077. @noindent
  2078. The presence of that line also reminds people editing the file that it
  2079. needs to be processed by @command{configure} in order to be used.
  2080. @end defvar
  2081. @defvar CPPFLAGS
  2082. @evindex CPPFLAGS
  2083. @ovindex CPPFLAGS
  2084. Preprocessor options for the C, C++, Objective C, and Objective C++
  2085. preprocessors and compilers. If
  2086. it is not set in the environment when @command{configure} runs, the default
  2087. value is empty. @command{configure} uses this variable when preprocessing
  2088. or compiling programs to test for C, C++, Objective C, and Objective C++
  2089. features.
  2090. This variable's contents should contain options like @option{-I},
  2091. @option{-D}, and @option{-U} that affect only the behavior of the
  2092. preprocessor. Please see the explanation of @code{CFLAGS} for what you
  2093. can do if an option affects other phases of the compiler as well.
  2094. Currently, @command{configure} always links as part of a single
  2095. invocation of the compiler that also preprocesses and compiles, so it
  2096. uses this variable also when linking programs. However, it is unwise to
  2097. depend on this behavior because the GNU Coding Standards do
  2098. not require it and many packages do not use @code{CPPFLAGS} when linking
  2099. programs.
  2100. @xref{Special Chars in Variables}, for limitations that @code{CPPFLAGS}
  2101. might run into.
  2102. @end defvar
  2103. @defvar CXXFLAGS
  2104. @evindex CXXFLAGS
  2105. @ovindex CXXFLAGS
  2106. Debugging and optimization options for the C++ compiler. It acts like
  2107. @code{CFLAGS}, but for C++ instead of C.
  2108. @end defvar
  2109. @defvar DEFS
  2110. @ovindex DEFS
  2111. @option{-D} options to pass to the C compiler. If @code{AC_CONFIG_HEADERS}
  2112. is called, @command{configure} replaces @samp{@@DEFS@@} with
  2113. @option{-DHAVE_CONFIG_H} instead (@pxref{Configuration Headers}). This
  2114. variable is not defined while @command{configure} is performing its tests,
  2115. only when creating the output files. @xref{Setting Output Variables}, for
  2116. how to check the results of previous tests.
  2117. @end defvar
  2118. @defvar ECHO_C
  2119. @defvarx ECHO_N
  2120. @defvarx ECHO_T
  2121. @ovindex ECHO_C
  2122. @ovindex ECHO_N
  2123. @ovindex ECHO_T
  2124. How does one suppress the trailing newline from @command{echo} for
  2125. question-answer message pairs? These variables provide a way:
  2126. @example
  2127. echo $ECHO_N "And the winner is... $ECHO_C"
  2128. sleep 100000000000
  2129. echo "$@{ECHO_T@}dead."
  2130. @end example
  2131. @noindent
  2132. Some old and uncommon @command{echo} implementations offer no means to
  2133. achieve this, in which case @code{ECHO_T} is set to tab. You might not
  2134. want to use it.
  2135. @end defvar
  2136. @defvar ERLCFLAGS
  2137. @evindex ERLCFLAGS
  2138. @ovindex ERLCFLAGS
  2139. Debugging and optimization options for the Erlang compiler. If it is not set
  2140. in the environment when @command{configure} runs, the default value is empty.
  2141. @command{configure} uses this variable when compiling
  2142. programs to test for Erlang features.
  2143. @end defvar
  2144. @defvar FCFLAGS
  2145. @evindex FCFLAGS
  2146. @ovindex FCFLAGS
  2147. Debugging and optimization options for the Fortran compiler. If it
  2148. is not set in the environment when @command{configure} runs, the default
  2149. value is set when you call @code{AC_PROG_FC} (or empty if you don't).
  2150. @command{configure} uses this variable when compiling or linking
  2151. programs to test for Fortran features.
  2152. @end defvar
  2153. @defvar FFLAGS
  2154. @evindex FFLAGS
  2155. @ovindex FFLAGS
  2156. Debugging and optimization options for the Fortran 77 compiler. If it
  2157. is not set in the environment when @command{configure} runs, the default
  2158. value is set when you call @code{AC_PROG_F77} (or empty if you don't).
  2159. @command{configure} uses this variable when compiling or linking
  2160. programs to test for Fortran 77 features.
  2161. @end defvar
  2162. @defvar LDFLAGS
  2163. @evindex LDFLAGS
  2164. @ovindex LDFLAGS
  2165. Options for the linker. If it is not set
  2166. in the environment when @command{configure} runs, the default value is empty.
  2167. @command{configure} uses this variable when linking programs to test for
  2168. C, C++, Objective C, Objective C++, Fortran, and Go features.
  2169. This variable's contents should contain options like @option{-s} and
  2170. @option{-L} that affect only the behavior of the linker. Please see the
  2171. explanation of @code{CFLAGS} for what you can do if an option also
  2172. affects other phases of the compiler.
  2173. Don't use this variable to pass library names
  2174. (@option{-l}) to the linker; use @code{LIBS} instead.
  2175. @end defvar
  2176. @defvar LIBS
  2177. @evindex LIBS
  2178. @ovindex LIBS
  2179. @option{-l} options to pass to the linker. The default value is empty,
  2180. but some Autoconf macros may prepend extra libraries to this variable if
  2181. those libraries are found and provide necessary functions, see
  2182. @ref{Libraries}. @command{configure} uses this variable when linking
  2183. programs to test for C, C++, Objective C, Objective C++, Fortran, and Go
  2184. features.
  2185. @end defvar
  2186. @defvar OBJCFLAGS
  2187. @evindex OBJCFLAGS
  2188. @ovindex OBJCFLAGS
  2189. Debugging and optimization options for the Objective C compiler. It
  2190. acts like @code{CFLAGS}, but for Objective C instead of C.
  2191. @end defvar
  2192. @defvar OBJCXXFLAGS
  2193. @evindex OBJCXXFLAGS
  2194. @ovindex OBJCXXFLAGS
  2195. Debugging and optimization options for the Objective C++ compiler. It
  2196. acts like @code{CXXFLAGS}, but for Objective C++ instead of C++.
  2197. @end defvar
  2198. @defvar GOFLAGS
  2199. @evindex GOFLAGS
  2200. @ovindex GOFLAGS
  2201. Debugging and optimization options for the Go compiler. It acts like
  2202. @code{CFLAGS}, but for Go instead of C.
  2203. @end defvar
  2204. @defvar builddir
  2205. @ovindex builddir
  2206. Rigorously equal to @samp{.}. Added for symmetry only.
  2207. @end defvar
  2208. @defvar abs_builddir
  2209. @ovindex abs_builddir
  2210. Absolute name of @code{builddir}.
  2211. @end defvar
  2212. @defvar top_builddir
  2213. @ovindex top_builddir
  2214. The relative name of the top level of the current build tree. In the
  2215. top-level directory, this is the same as @code{builddir}.
  2216. @end defvar
  2217. @defvar top_build_prefix
  2218. @ovindex top_build_prefix
  2219. The relative name of the top level of the current build tree with final
  2220. slash if nonempty. This is the same as @code{top_builddir}, except that
  2221. it contains zero or more runs of @code{../}, so it should not be
  2222. appended with a slash for concatenation. This helps for @command{make}
  2223. implementations that otherwise do not treat @file{./file} and @file{file}
  2224. as equal in the toplevel build directory.
  2225. @end defvar
  2226. @defvar abs_top_builddir
  2227. @ovindex abs_top_builddir
  2228. Absolute name of @code{top_builddir}.
  2229. @end defvar
  2230. @defvar srcdir
  2231. @ovindex srcdir
  2232. The name of the directory that contains the source code for
  2233. that makefile.
  2234. @end defvar
  2235. @defvar abs_srcdir
  2236. @ovindex abs_srcdir
  2237. Absolute name of @code{srcdir}.
  2238. @end defvar
  2239. @defvar top_srcdir
  2240. @ovindex top_srcdir
  2241. The name of the top-level source code directory for the
  2242. package. In the top-level directory, this is the same as @code{srcdir}.
  2243. @end defvar
  2244. @defvar abs_top_srcdir
  2245. @ovindex abs_top_srcdir
  2246. Absolute name of @code{top_srcdir}.
  2247. @end defvar
  2248. @node Installation Directory Variables
  2249. @subsection Installation Directory Variables
  2250. @cindex Installation directories
  2251. @cindex Directories, installation
  2252. The following variables specify the directories for
  2253. package installation, see @ref{Directory Variables, , Variables for
  2254. Installation Directories, standards, The GNU Coding
  2255. Standards}, for more information. Each variable corresponds to an
  2256. argument of @command{configure}; trailing slashes are stripped so that
  2257. expressions such as @samp{$@{prefix@}/lib} expand with only one slash
  2258. between directory names. See the end of this section for
  2259. details on when and how to use these variables.
  2260. @defvar bindir
  2261. @ovindex bindir
  2262. The directory for installing executables that users run.
  2263. @end defvar
  2264. @defvar datadir
  2265. @ovindex datadir
  2266. The directory for installing idiosyncratic read-only
  2267. architecture-independent data.
  2268. @end defvar
  2269. @defvar datarootdir
  2270. @ovindex datarootdir
  2271. The root of the directory tree for read-only architecture-independent
  2272. data files.
  2273. @end defvar
  2274. @defvar docdir
  2275. @ovindex docdir
  2276. The directory for installing documentation files (other than Info and
  2277. man).
  2278. @end defvar
  2279. @defvar dvidir
  2280. @ovindex dvidir
  2281. The directory for installing documentation files in DVI format.
  2282. @end defvar
  2283. @defvar exec_prefix
  2284. @ovindex exec_prefix
  2285. The installation prefix for architecture-dependent files. By default
  2286. it's the same as @code{prefix}. You should avoid installing anything
  2287. directly to @code{exec_prefix}. However, the default value for
  2288. directories containing architecture-dependent files should be relative
  2289. to @code{exec_prefix}.
  2290. @end defvar
  2291. @defvar htmldir
  2292. @ovindex htmldir
  2293. The directory for installing HTML documentation.
  2294. @end defvar
  2295. @defvar includedir
  2296. @ovindex includedir
  2297. The directory for installing C header files.
  2298. @end defvar
  2299. @defvar infodir
  2300. @ovindex infodir
  2301. The directory for installing documentation in Info format.
  2302. @end defvar
  2303. @defvar libdir
  2304. @ovindex libdir
  2305. The directory for installing object code libraries.
  2306. @end defvar
  2307. @defvar libexecdir
  2308. @ovindex libexecdir
  2309. The directory for installing executables that other programs run.
  2310. @end defvar
  2311. @defvar localedir
  2312. @ovindex localedir
  2313. The directory for installing locale-dependent but
  2314. architecture-independent data, such as message catalogs. This directory
  2315. usually has a subdirectory per locale.
  2316. @end defvar
  2317. @defvar localstatedir
  2318. @ovindex localstatedir
  2319. The directory for installing modifiable single-machine data.
  2320. @end defvar
  2321. @defvar mandir
  2322. @ovindex mandir
  2323. The top-level directory for installing documentation in man format.
  2324. @end defvar
  2325. @defvar oldincludedir
  2326. @ovindex oldincludedir
  2327. The directory for installing C header files for non-GCC compilers.
  2328. @end defvar
  2329. @defvar pdfdir
  2330. @ovindex pdfdir
  2331. The directory for installing PDF documentation.
  2332. @end defvar
  2333. @defvar prefix
  2334. @ovindex prefix
  2335. The common installation prefix for all files. If @code{exec_prefix}
  2336. is defined to a different value, @code{prefix} is used only for
  2337. architecture-independent files.
  2338. @end defvar
  2339. @defvar psdir
  2340. @ovindex psdir
  2341. The directory for installing PostScript documentation.
  2342. @end defvar
  2343. @defvar sbindir
  2344. @ovindex sbindir
  2345. The directory for installing executables that system
  2346. administrators run.
  2347. @end defvar
  2348. @defvar sharedstatedir
  2349. @ovindex sharedstatedir
  2350. The directory for installing modifiable architecture-independent data.
  2351. @end defvar
  2352. @defvar sysconfdir
  2353. @ovindex sysconfdir
  2354. The directory for installing read-only single-machine data.
  2355. @end defvar
  2356. Most of these variables have values that rely on @code{prefix} or
  2357. @code{exec_prefix}. It is deliberate that the directory output
  2358. variables keep them unexpanded: typically @samp{@@datarootdir@@} is
  2359. replaced by @samp{$@{prefix@}/share}, not @samp{/usr/local/share}, and
  2360. @samp{@@datadir@@} is replaced by @samp{$@{datarootdir@}}.
  2361. This behavior is mandated by the GNU Coding Standards, so that when
  2362. the user runs:
  2363. @table @samp
  2364. @item make
  2365. she can still specify a different prefix from the one specified to
  2366. @command{configure}, in which case, if needed, the package should hard
  2367. code dependencies corresponding to the make-specified prefix.
  2368. @item make install
  2369. she can specify a different installation location, in which case the
  2370. package @emph{must} still depend on the location which was compiled in
  2371. (i.e., never recompile when @samp{make install} is run). This is an
  2372. extremely important feature, as many people may decide to install all
  2373. the files of a package grouped together, and then install links from
  2374. the final locations to there.
  2375. @end table
  2376. In order to support these features, it is essential that
  2377. @code{datarootdir} remains defined as @samp{$@{prefix@}/share},
  2378. so that its value can be expanded based
  2379. on the current value of @code{prefix}.
  2380. A corollary is that you should not use these variables except in
  2381. makefiles. For instance, instead of trying to evaluate @code{datadir}
  2382. in @file{configure} and hard-coding it in makefiles using
  2383. e.g., @samp{AC_DEFINE_UNQUOTED([DATADIR], ["$datadir"], [Data directory.])},
  2384. you should add
  2385. @option{-DDATADIR='$(datadir)'} to your makefile's definition of
  2386. @code{CPPFLAGS} (@code{AM_CPPFLAGS} if you are also using Automake).
  2387. Similarly, you should not rely on @code{AC_CONFIG_FILES} to replace
  2388. @code{bindir} and friends in your shell scripts and other files; instead,
  2389. let @command{make} manage their replacement. For instance Autoconf
  2390. ships templates of its shell scripts ending with @samp{.in}, and uses a
  2391. makefile snippet similar to the following to build scripts like
  2392. @command{autoheader} and @command{autom4te}:
  2393. @example
  2394. @group
  2395. edit = sed \
  2396. -e 's|@@bindir[@@]|$(bindir)|g' \
  2397. -e 's|@@pkgdatadir[@@]|$(pkgdatadir)|g' \
  2398. -e 's|@@prefix[@@]|$(prefix)|g'
  2399. @end group
  2400. @group
  2401. autoheader autom4te: Makefile
  2402. rm -f $@@ $@@.tmp
  2403. srcdir=''; \
  2404. test -f ./$@@.in || srcdir=$(srcdir)/; \
  2405. $(edit) $$@{srcdir@}$@@.in >$@@.tmp
  2406. @c $$ restore font-lock
  2407. chmod +x $@@.tmp
  2408. chmod a-w $@@.tmp
  2409. mv $@@.tmp $@@
  2410. @end group
  2411. @group
  2412. autoheader: $(srcdir)/autoheader.in
  2413. autom4te: $(srcdir)/autom4te.in
  2414. @end group
  2415. @end example
  2416. Some details are noteworthy:
  2417. @table @asis
  2418. @item @samp{@@bindir[@@]}
  2419. The brackets prevent @command{configure} from replacing
  2420. @samp{@@bindir@@} in the Sed expression itself.
  2421. Brackets are preferable to a backslash here, since
  2422. Posix says @samp{\@@} is not portable.
  2423. @item @samp{$(bindir)}
  2424. Don't use @samp{@@bindir@@}! Use the matching makefile variable
  2425. instead.
  2426. @item @samp{$(pkgdatadir)}
  2427. The example takes advantage of the variable @samp{$(pkgdatadir)}
  2428. provided by Automake; it is equivalent to @samp{$(datadir)/$(PACKAGE)}.
  2429. @item @samp{/}
  2430. Don't use @samp{/} in the Sed expressions that replace file names since
  2431. most likely the
  2432. variables you use, such as @samp{$(bindir)}, contain @samp{/}.
  2433. Use a shell metacharacter instead, such as @samp{|}.
  2434. @item special characters
  2435. File names, file name components, and the value of @code{VPATH} should
  2436. not contain shell metacharacters or white
  2437. space. @xref{Special Chars in Variables}.
  2438. @item dependency on @file{Makefile}
  2439. Since @code{edit} uses values that depend on the configuration specific
  2440. values (@code{prefix}, etc.)@: and not only on @code{VERSION} and so forth,
  2441. the output depends on @file{Makefile}, not @file{configure.ac}.
  2442. @item @samp{$@@}
  2443. The main rule is generic, and uses @samp{$@@} extensively to
  2444. avoid the need for multiple copies of the rule.
  2445. @item Separated dependencies and single suffix rules
  2446. You can't use them! The above snippet cannot be (portably) rewritten
  2447. as:
  2448. @example
  2449. autoconf autoheader: Makefile
  2450. @group
  2451. .in:
  2452. rm -f $@@ $@@.tmp
  2453. $(edit) $< >$@@.tmp
  2454. chmod +x $@@.tmp
  2455. mv $@@.tmp $@@
  2456. @end group
  2457. @end example
  2458. @xref{Single Suffix Rules}, for details.
  2459. @item @samp{$(srcdir)}
  2460. Be sure to specify the name of the source directory,
  2461. otherwise the package won't support separated builds.
  2462. @end table
  2463. For the more specific installation of Erlang libraries, the following variables
  2464. are defined:
  2465. @defvar ERLANG_INSTALL_LIB_DIR
  2466. @ovindex ERLANG_INSTALL_LIB_DIR
  2467. @acindex{ERLANG_SUBST_INSTALL_LIB_DIR}
  2468. The common parent directory of Erlang library installation directories.
  2469. This variable is set by calling the @code{AC_ERLANG_SUBST_INSTALL_LIB_DIR}
  2470. macro in @file{configure.ac}.
  2471. @end defvar
  2472. @defvar ERLANG_INSTALL_LIB_DIR_@var{library}
  2473. @ovindex ERLANG_INSTALL_LIB_DIR_@var{library}
  2474. @acindex{ERLANG_SUBST_INSTALL_LIB_SUBDIR}
  2475. The installation directory for Erlang library @var{library}.
  2476. This variable is set by using the
  2477. @samp{AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR}
  2478. macro in @file{configure.ac}.
  2479. @end defvar
  2480. @xref{Erlang Libraries}, for details.
  2481. @node Changed Directory Variables
  2482. @subsection Changed Directory Variables
  2483. @cindex @file{datarootdir}
  2484. In Autoconf 2.60, the set of directory variables has changed, and the
  2485. defaults of some variables have been adjusted
  2486. (@pxref{Installation Directory Variables}) to changes in the
  2487. GNU Coding Standards. Notably, @file{datadir}, @file{infodir}, and
  2488. @file{mandir} are now expressed in terms of @file{datarootdir}. If you are
  2489. upgrading from an earlier Autoconf version, you may need to adjust your files
  2490. to ensure that the directory variables are substituted correctly
  2491. (@pxref{Defining Directories}), and that a definition of @file{datarootdir} is
  2492. in place. For example, in a @file{Makefile.in}, adding
  2493. @example
  2494. datarootdir = @@datarootdir@@
  2495. @end example
  2496. @noindent
  2497. is usually sufficient. If you use Automake to create @file{Makefile.in},
  2498. it will add this for you.
  2499. To help with the transition, Autoconf warns about files that seem to use
  2500. @code{datarootdir} without defining it. In some cases, it then expands
  2501. the value of @code{$datarootdir} in substitutions of the directory
  2502. variables. The following example shows such a warning:
  2503. @example
  2504. $ @kbd{cat configure.ac}
  2505. AC_INIT
  2506. AC_CONFIG_FILES([Makefile])
  2507. AC_OUTPUT
  2508. $ @kbd{cat Makefile.in}
  2509. prefix = @@prefix@@
  2510. datadir = @@datadir@@
  2511. $ @kbd{autoconf}
  2512. $ @kbd{configure}
  2513. configure: creating ./config.status
  2514. config.status: creating Makefile
  2515. config.status: WARNING:
  2516. Makefile.in seems to ignore the --datarootdir setting
  2517. $ @kbd{cat Makefile}
  2518. prefix = /usr/local
  2519. datadir = $@{prefix@}/share
  2520. @end example
  2521. Usually one can easily change the file to accommodate both older and newer
  2522. Autoconf releases:
  2523. @example
  2524. $ @kbd{cat Makefile.in}
  2525. prefix = @@prefix@@
  2526. datarootdir = @@datarootdir@@
  2527. datadir = @@datadir@@
  2528. $ @kbd{configure}
  2529. configure: creating ./config.status
  2530. config.status: creating Makefile
  2531. $ @kbd{cat Makefile}
  2532. prefix = /usr/local
  2533. datarootdir = $@{prefix@}/share
  2534. datadir = $@{datarootdir@}
  2535. @end example
  2536. @acindex{DATAROOTDIR_CHECKED}
  2537. In some cases, however, the checks may not be able to detect that a suitable
  2538. initialization of @code{datarootdir} is in place, or they may fail to detect
  2539. that such an initialization is necessary in the output file. If, after
  2540. auditing your package, there are still spurious @file{configure} warnings about
  2541. @code{datarootdir}, you may add the line
  2542. @example
  2543. AC_DEFUN([AC_DATAROOTDIR_CHECKED])
  2544. @end example
  2545. @noindent
  2546. to your @file{configure.ac} to disable the warnings. This is an exception
  2547. to the usual rule that you should not define a macro whose name begins with
  2548. @code{AC_} (@pxref{Macro Names}).
  2549. @node Build Directories
  2550. @subsection Build Directories
  2551. @cindex Build directories
  2552. @cindex Directories, build
  2553. You can support compiling a software package for several architectures
  2554. simultaneously from the same copy of the source code. The object files
  2555. for each architecture are kept in their own directory.
  2556. To support doing this, @command{make} uses the @code{VPATH} variable to
  2557. find the files that are in the source directory. GNU Make
  2558. can do this. Most other recent @command{make} programs can do this as
  2559. well, though they may have difficulties and it is often simpler to
  2560. recommend GNU @command{make} (@pxref{VPATH and Make}). Older
  2561. @command{make} programs do not support @code{VPATH}; when using them, the
  2562. source code must be in the same directory as the object files.
  2563. If you are using GNU Automake, the remaining details in this
  2564. section are already covered for you, based on the contents of your
  2565. @file{Makefile.am}. But if you are using Autoconf in isolation, then
  2566. supporting @code{VPATH} requires the following in your
  2567. @file{Makefile.in}:
  2568. @example
  2569. srcdir = @@srcdir@@
  2570. VPATH = @@srcdir@@
  2571. @end example
  2572. Do not set @code{VPATH} to the value of another variable (@pxref{Variables
  2573. listed in VPATH}.
  2574. @command{configure} substitutes the correct value for @code{srcdir} when
  2575. it produces @file{Makefile}.
  2576. Do not use the @command{make} variable @code{$<}, which expands to the
  2577. file name of the file in the source directory (found with @code{VPATH}),
  2578. except in implicit rules. (An implicit rule is one such as @samp{.c.o},
  2579. which tells how to create a @file{.o} file from a @file{.c} file.) Some
  2580. versions of @command{make} do not set @code{$<} in explicit rules; they
  2581. expand it to an empty value.
  2582. Instead, Make command lines should always refer to source
  2583. files by prefixing them with @samp{$(srcdir)/}. For example:
  2584. @example
  2585. time.info: time.texinfo
  2586. $(MAKEINFO) '$(srcdir)/time.texinfo'
  2587. @end example
  2588. @node Automatic Remaking
  2589. @subsection Automatic Remaking
  2590. @cindex Automatic remaking
  2591. @cindex Remaking automatically
  2592. You can put rules like the following in the top-level @file{Makefile.in}
  2593. for a package to automatically update the configuration information when
  2594. you change the configuration files. This example includes all of the
  2595. optional files, such as @file{aclocal.m4} and those related to
  2596. configuration header files. Omit from the @file{Makefile.in} rules for
  2597. any of these files that your package does not use.
  2598. The @samp{$(srcdir)/} prefix is included because of limitations in the
  2599. @code{VPATH} mechanism.
  2600. The @file{stamp-} files are necessary because the timestamps of
  2601. @file{config.h.in} and @file{config.h} are not changed if remaking
  2602. them does not change their contents. This feature avoids unnecessary
  2603. recompilation. You should include the file @file{stamp-h.in} in your
  2604. package's distribution, so that @command{make} considers
  2605. @file{config.h.in} up to date. Don't use @command{touch}
  2606. (@pxref{touch, , Limitations of Usual Tools}); instead, use
  2607. @command{echo} (using
  2608. @command{date} would cause needless differences, hence CVS
  2609. conflicts, etc.).
  2610. @example
  2611. @group
  2612. $(srcdir)/configure: configure.ac aclocal.m4
  2613. cd '$(srcdir)' && autoconf
  2614. # autoheader might not change config.h.in, so touch a stamp file.
  2615. $(srcdir)/config.h.in: stamp-h.in
  2616. $(srcdir)/stamp-h.in: configure.ac aclocal.m4
  2617. cd '$(srcdir)' && autoheader
  2618. echo timestamp > '$(srcdir)/stamp-h.in'
  2619. config.h: stamp-h
  2620. stamp-h: config.h.in config.status
  2621. ./config.status
  2622. Makefile: Makefile.in config.status
  2623. ./config.status
  2624. config.status: configure
  2625. ./config.status --recheck
  2626. @end group
  2627. @end example
  2628. @noindent
  2629. (Be careful if you copy these lines directly into your makefile, as you
  2630. need to convert the indented lines to start with the tab character.)
  2631. In addition, you should use
  2632. @example
  2633. AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
  2634. @end example
  2635. @noindent
  2636. so @file{config.status} ensures that @file{config.h} is considered up to
  2637. date. @xref{Output}, for more information about @code{AC_OUTPUT}.
  2638. @xref{config.status Invocation}, for more examples of handling
  2639. configuration-related dependencies.
  2640. @node Configuration Headers
  2641. @section Configuration Header Files
  2642. @cindex Configuration Header
  2643. @cindex @file{config.h}
  2644. When a package contains more than a few tests that define C preprocessor
  2645. symbols, the command lines to pass @option{-D} options to the compiler
  2646. can get quite long. This causes two problems. One is that the
  2647. @command{make} output is hard to visually scan for errors. More
  2648. seriously, the command lines can exceed the length limits of some
  2649. operating systems. As an alternative to passing @option{-D} options to
  2650. the compiler, @command{configure} scripts can create a C header file
  2651. containing @samp{#define} directives. The @code{AC_CONFIG_HEADERS}
  2652. macro selects this kind of output. Though it can be called anywhere
  2653. between @code{AC_INIT} and @code{AC_OUTPUT}, it is customary to call
  2654. it right after @code{AC_INIT}.
  2655. The package should @samp{#include} the configuration header file before
  2656. any other header files, to prevent inconsistencies in declarations (for
  2657. example, if it redefines @code{const}).
  2658. To provide for VPATH builds, remember to pass the C compiler a @option{-I.}
  2659. option (or @option{-I..}; whichever directory contains @file{config.h}).
  2660. Even if you use @samp{#include "config.h"}, the preprocessor searches only
  2661. the directory of the currently read file, i.e., the source directory, not
  2662. the build directory.
  2663. With the appropriate @option{-I} option, you can use
  2664. @samp{#include <config.h>}. Actually, it's a good habit to use it,
  2665. because in the rare case when the source directory contains another
  2666. @file{config.h}, the build directory should be searched first.
  2667. @defmac AC_CONFIG_HEADERS (@var{header} @dots{}, @ovar{cmds}, @ovar{init-cmds})
  2668. @acindex{CONFIG_HEADERS}
  2669. @cvindex HAVE_CONFIG_H
  2670. This macro is one of the instantiating macros; see @ref{Configuration
  2671. Actions}. Make @code{AC_OUTPUT} create the file(s) in the
  2672. blank-or-newline-separated list @var{header} containing C preprocessor
  2673. @code{#define} statements, and replace @samp{@@DEFS@@} in generated
  2674. files with @option{-DHAVE_CONFIG_H} instead of the value of @code{DEFS}.
  2675. The usual name for @var{header} is @file{config.h}.
  2676. If @var{header} already exists and its contents are identical to what
  2677. @code{AC_OUTPUT} would put in it, it is left alone. Doing this allows
  2678. making some changes in the configuration without needlessly causing
  2679. object files that depend on the header file to be recompiled.
  2680. Usually the input file is named @file{@var{header}.in}; however, you can
  2681. override the input file name by appending to @var{header} a
  2682. colon-separated list of input files. For example, you might need to make
  2683. the input file name acceptable to DOS variants:
  2684. @example
  2685. AC_CONFIG_HEADERS([config.h:config.hin])
  2686. @end example
  2687. @end defmac
  2688. @defmac AH_HEADER
  2689. @ahindex{HEADER}
  2690. This macro is defined as the name of the first declared config header
  2691. and undefined if no config headers have been declared up to this point.
  2692. A third-party macro may, for example, require use of a config header
  2693. without invoking AC_CONFIG_HEADERS twice, like this:
  2694. @example
  2695. AC_CONFIG_COMMANDS_PRE(
  2696. [m4_ifndef([AH_HEADER], [AC_CONFIG_HEADERS([config.h])])])
  2697. @end example
  2698. @end defmac
  2699. @xref{Configuration Actions}, for more details on @var{header}.
  2700. @menu
  2701. * Header Templates:: Input for the configuration headers
  2702. * autoheader Invocation:: How to create configuration templates
  2703. * Autoheader Macros:: How to specify CPP templates
  2704. @end menu
  2705. @node Header Templates
  2706. @subsection Configuration Header Templates
  2707. @cindex Configuration Header Template
  2708. @cindex Header templates
  2709. @cindex @file{config.h.in}
  2710. Your distribution should contain a template file that looks as you want
  2711. the final header file to look, including comments, with @code{#undef}
  2712. statements which are used as hooks. For example, suppose your
  2713. @file{configure.ac} makes these calls:
  2714. @example
  2715. AC_CONFIG_HEADERS([conf.h])
  2716. AC_CHECK_HEADERS([unistd.h])
  2717. @end example
  2718. @noindent
  2719. Then you could have code like the following in @file{conf.h.in}.
  2720. The @file{conf.h} created by @command{configure} defines @samp{HAVE_UNISTD_H}
  2721. to 1, if and only if the system has @file{unistd.h}.
  2722. @example
  2723. @group
  2724. /* Define as 1 if you have unistd.h. */
  2725. #undef HAVE_UNISTD_H
  2726. @end group
  2727. @end example
  2728. The format of the template file is stricter than what the C preprocessor
  2729. is required to accept. A directive line should contain only whitespace,
  2730. @samp{#undef}, and @samp{HAVE_UNISTD_H}. The use of @samp{#define}
  2731. instead of @samp{#undef}, or of comments on the same line as
  2732. @samp{#undef}, is strongly discouraged. Each hook should only be listed
  2733. once. Other preprocessor lines, such as @samp{#ifdef} or
  2734. @samp{#include}, are copied verbatim from the template into the
  2735. generated header.
  2736. Since it is a tedious task to keep a template header up to date, you may
  2737. use @command{autoheader} to generate it, see @ref{autoheader Invocation}.
  2738. During the instantiation of the header, each @samp{#undef} line in the
  2739. template file for each symbol defined by @samp{AC_DEFINE} is changed to an
  2740. appropriate @samp{#define}. If the corresponding @samp{AC_DEFINE} has not
  2741. been executed during the @command{configure} run, the @samp{#undef} line is
  2742. commented out. (This is important, e.g., for @samp{_POSIX_SOURCE}:
  2743. on many systems, it can be implicitly defined by the compiler, and
  2744. undefining it in the header would then break compilation of subsequent
  2745. headers.)
  2746. Currently, @emph{all} remaining @samp{#undef} lines in the header
  2747. template are commented out, whether or not there was a corresponding
  2748. @samp{AC_DEFINE} for the macro name; but this behavior is not guaranteed
  2749. for future releases of Autoconf.
  2750. Generally speaking, since you should not use @samp{#define}, and you
  2751. cannot guarantee whether a @samp{#undef} directive in the header
  2752. template will be converted to a @samp{#define} or commented out in the
  2753. generated header file, the template file cannot be used for conditional
  2754. definition effects. Consequently, if you need to use the construct
  2755. @example
  2756. @group
  2757. #ifdef THIS
  2758. # define THAT
  2759. #endif
  2760. @end group
  2761. @end example
  2762. @noindent
  2763. you must place it outside of the template.
  2764. If you absolutely need to hook it to the config header itself, please put
  2765. the directives to a separate file, and @samp{#include} that file from the
  2766. config header template. If you are using @command{autoheader}, you would
  2767. probably use @samp{AH_BOTTOM} to append the @samp{#include} directive.
  2768. @node autoheader Invocation
  2769. @subsection Using @command{autoheader} to Create @file{config.h.in}
  2770. @cindex @command{autoheader}
  2771. The @command{autoheader} program can create a template file of C
  2772. @samp{#define} statements for @command{configure} to use.
  2773. It searches for the first invocation of @code{AC_CONFIG_HEADERS} in
  2774. @file{configure} sources to determine the name of the template.
  2775. (If the first call of @code{AC_CONFIG_HEADERS} specifies more than one
  2776. input file name, @command{autoheader} uses the first one.)
  2777. It is recommended that only one input file is used. If you want to append
  2778. a boilerplate code, it is preferable to use
  2779. @samp{AH_BOTTOM([#include <conf_post.h>])}.
  2780. File @file{conf_post.h} is not processed during the configuration then,
  2781. which make things clearer. Analogically, @code{AH_TOP} can be used to
  2782. prepend a boilerplate code.
  2783. In order to do its job, @command{autoheader} needs you to document all
  2784. of the symbols that you might use. Typically this is done via an
  2785. @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED} call whose first argument
  2786. is a literal symbol and whose third argument describes the symbol
  2787. (@pxref{Defining Symbols}). Alternatively, you can use
  2788. @code{AH_TEMPLATE} (@pxref{Autoheader Macros}), or you can supply a
  2789. suitable input file for a subsequent configuration header file.
  2790. Symbols defined by Autoconf's builtin tests are already documented properly;
  2791. you need to document only those that you
  2792. define yourself.
  2793. You might wonder why @command{autoheader} is needed: after all, why
  2794. would @command{configure} need to ``patch'' a @file{config.h.in} to
  2795. produce a @file{config.h} instead of just creating @file{config.h} from
  2796. scratch? Well, when everything rocks, the answer is just that we are
  2797. wasting our time maintaining @command{autoheader}: generating
  2798. @file{config.h} directly is all that is needed. When things go wrong,
  2799. however, you'll be thankful for the existence of @command{autoheader}.
  2800. The fact that the symbols are documented is important in order to
  2801. @emph{check} that @file{config.h} makes sense. The fact that there is a
  2802. well-defined list of symbols that should be defined (or not) is
  2803. also important for people who are porting packages to environments where
  2804. @command{configure} cannot be run: they just have to @emph{fill in the
  2805. blanks}.
  2806. But let's come back to the point: the invocation of @command{autoheader}@dots{}
  2807. If you give @command{autoheader} an argument, it uses that file instead
  2808. of @file{configure.ac} and writes the header file to the standard output
  2809. instead of to @file{config.h.in}. If you give @command{autoheader} an
  2810. argument of @option{-}, it reads the standard input instead of
  2811. @file{configure.ac} and writes the header file to the standard output.
  2812. @command{autoheader} accepts the following options:
  2813. @table @option
  2814. @item --help
  2815. @itemx -h
  2816. Print a summary of the command line options and exit.
  2817. @item --version
  2818. @itemx -V
  2819. Print the version number of Autoconf and exit.
  2820. @item --verbose
  2821. @itemx -v
  2822. Report processing steps.
  2823. @item --debug
  2824. @itemx -d
  2825. Don't remove the temporary files.
  2826. @item --force
  2827. @itemx -f
  2828. Remake the template file even if newer than its input files.
  2829. @item --include=@var{dir}
  2830. @itemx -I @var{dir}
  2831. Append @var{dir} to the include path. Multiple invocations accumulate.
  2832. @item --prepend-include=@var{dir}
  2833. @itemx -B @var{dir}
  2834. Prepend @var{dir} to the include path. Multiple invocations accumulate.
  2835. @item --warnings=@var{category}
  2836. @itemx -W @var{category}
  2837. @evindex WARNINGS
  2838. Report the warnings related to @var{category} (which can actually be a
  2839. comma separated list). Current categories include:
  2840. @table @samp
  2841. @item obsolete
  2842. report the uses of obsolete constructs
  2843. @item all
  2844. report all the warnings
  2845. @item none
  2846. report none
  2847. @item error
  2848. treats warnings as errors
  2849. @item no-@var{category}
  2850. disable warnings falling into @var{category}
  2851. @end table
  2852. @end table
  2853. @node Autoheader Macros
  2854. @subsection Autoheader Macros
  2855. @cindex Autoheader macros
  2856. @command{autoheader} scans @file{configure.ac} and figures out which C
  2857. preprocessor symbols it might define. It knows how to generate
  2858. templates for symbols defined by @code{AC_CHECK_HEADERS},
  2859. @code{AC_CHECK_FUNCS} etc., but if you @code{AC_DEFINE} any additional
  2860. symbol, you must define a template for it. If there are missing
  2861. templates, @command{autoheader} fails with an error message.
  2862. The template for a @var{symbol} is created
  2863. by @command{autoheader} from
  2864. the @var{description} argument to an @code{AC_DEFINE};
  2865. see @ref{Defining Symbols}.
  2866. For special needs, you can use the following macros.
  2867. @defmac AH_TEMPLATE (@var{key}, @var{description})
  2868. @ahindex{TEMPLATE}
  2869. Tell @command{autoheader} to generate a template for @var{key}. This macro
  2870. generates standard templates just like @code{AC_DEFINE} when a
  2871. @var{description} is given.
  2872. For example:
  2873. @example
  2874. AH_TEMPLATE([CRAY_STACKSEG_END],
  2875. [Define to one of _getb67, GETB67, getb67
  2876. for Cray-2 and Cray-YMP systems. This
  2877. function is required for alloca.c support
  2878. on those systems.])
  2879. @end example
  2880. @noindent
  2881. generates the following template, with the description properly
  2882. justified.
  2883. @example
  2884. /* Define to one of _getb67, GETB67, getb67 for Cray-2 and
  2885. Cray-YMP systems. This function is required for alloca.c
  2886. support on those systems. */
  2887. #undef CRAY_STACKSEG_END
  2888. @end example
  2889. @end defmac
  2890. @defmac AH_VERBATIM (@var{key}, @var{template})
  2891. @ahindex{VERBATIM}
  2892. Tell @command{autoheader} to include the @var{template} as-is in the header
  2893. template file. This @var{template} is associated with the @var{key},
  2894. which is used to sort all the different templates and guarantee their
  2895. uniqueness. It should be a symbol that can be defined via @code{AC_DEFINE}.
  2896. @end defmac
  2897. @defmac AH_TOP (@var{text})
  2898. @ahindex{TOP}
  2899. Include @var{text} at the top of the header template file.
  2900. @end defmac
  2901. @defmac AH_BOTTOM (@var{text})
  2902. @ahindex{BOTTOM}
  2903. Include @var{text} at the bottom of the header template file.
  2904. @end defmac
  2905. Please note that @var{text} gets included ``verbatim'' to the template file,
  2906. not to the resulting config header, so it can easily get mangled when the
  2907. template is processed. There is rarely a need for something other than
  2908. @example
  2909. AH_BOTTOM([#include <custom.h>])
  2910. @end example
  2911. @node Configuration Commands
  2912. @section Running Arbitrary Configuration Commands
  2913. @cindex Configuration commands
  2914. @cindex Commands for configuration
  2915. You can execute arbitrary commands before, during, and after
  2916. @file{config.status} is run. The three following macros accumulate the
  2917. commands to run when they are called multiple times.
  2918. @code{AC_CONFIG_COMMANDS} replaces the obsolete macro
  2919. @code{AC_OUTPUT_COMMANDS}; see @ref{Obsolete Macros}, for details.
  2920. @anchor{AC_CONFIG_COMMANDS}
  2921. @defmac AC_CONFIG_COMMANDS (@var{tag}@dots{}, @ovar{cmds}, @ovar{init-cmds})
  2922. @acindex{CONFIG_COMMANDS}
  2923. Specify additional shell commands to run at the end of
  2924. @file{config.status}, and shell commands to initialize any variables
  2925. from @command{configure}. Associate the commands with @var{tag}.
  2926. Since typically the @var{cmds} create a file, @var{tag} should
  2927. naturally be the name of that file. If needed, the directory hosting
  2928. @var{tag} is created. This macro is one of the instantiating macros;
  2929. see @ref{Configuration Actions}.
  2930. Here is an unrealistic example:
  2931. @example
  2932. fubar=42
  2933. AC_CONFIG_COMMANDS([fubar],
  2934. [echo this is extra $fubar, and so on.],
  2935. [fubar=$fubar])
  2936. @end example
  2937. Here is a better one:
  2938. @example
  2939. AC_CONFIG_COMMANDS([timestamp], [date >timestamp])
  2940. @end example
  2941. @end defmac
  2942. The following two macros look similar, but in fact they are not of the same
  2943. breed: they are executed directly by @file{configure}, so you cannot use
  2944. @file{config.status} to rerun them.
  2945. @c Yet it is good to leave them here. The user sees them together and
  2946. @c decides which best fits their needs.
  2947. @defmac AC_CONFIG_COMMANDS_PRE (@var{cmds})
  2948. @acindex{CONFIG_COMMANDS_PRE}
  2949. Execute the @var{cmds} right before creating @file{config.status}.
  2950. This macro presents the last opportunity to call @code{AC_SUBST},
  2951. @code{AC_DEFINE}, or @code{AC_CONFIG_@var{ITEMS}} macros.
  2952. @end defmac
  2953. @defmac AC_CONFIG_COMMANDS_POST (@var{cmds})
  2954. @acindex{CONFIG_COMMANDS_POST}
  2955. Execute the @var{cmds} right after creating @file{config.status}.
  2956. @end defmac
  2957. @node Configuration Links
  2958. @section Creating Configuration Links
  2959. @cindex Configuration links
  2960. @cindex Links for configuration
  2961. You may find it convenient to create links whose destinations depend upon
  2962. results of tests. One can use @code{AC_CONFIG_COMMANDS} but the
  2963. creation of relative symbolic links can be delicate when the package is
  2964. built in a directory different from the source directory.
  2965. @anchor{AC_CONFIG_LINKS}
  2966. @defmac AC_CONFIG_LINKS (@var{dest}:@var{source}@dots{}, @ovar{cmds}, @
  2967. @ovar{init-cmds})
  2968. @acindex{CONFIG_LINKS}
  2969. @cindex Links
  2970. Make @code{AC_OUTPUT} link each of the existing files @var{source} to
  2971. the corresponding link name @var{dest}. Makes a symbolic link if
  2972. possible, otherwise a hard link if possible, otherwise a copy. The
  2973. @var{dest} and @var{source} names should be relative to the top level
  2974. source or build directory. This macro is one of the instantiating
  2975. macros; see @ref{Configuration Actions}.
  2976. For example, this call:
  2977. @example
  2978. AC_CONFIG_LINKS([host.h:config/$machine.h
  2979. object.h:config/$obj_format.h])
  2980. @end example
  2981. @noindent
  2982. creates in the current directory @file{host.h} as a link to
  2983. @file{@var{srcdir}/config/$machine.h}, and @file{object.h} as a
  2984. link to @file{@var{srcdir}/config/$obj_format.h}.
  2985. The tempting value @samp{.} for @var{dest} is invalid: it makes it
  2986. impossible for @samp{config.status} to guess the links to establish.
  2987. One can then run:
  2988. @example
  2989. ./config.status host.h object.h
  2990. @end example
  2991. @noindent
  2992. to create the links.
  2993. @end defmac
  2994. @node Subdirectories
  2995. @section Configuring Other Packages in Subdirectories
  2996. @cindex Configure subdirectories
  2997. @cindex Subdirectory configure
  2998. In most situations, calling @code{AC_OUTPUT} is sufficient to produce
  2999. makefiles in subdirectories. However, @command{configure} scripts
  3000. that control more than one independent package can use
  3001. @code{AC_CONFIG_SUBDIRS} to run @command{configure} scripts for other
  3002. packages in subdirectories.
  3003. @defmac AC_CONFIG_SUBDIRS (@var{dir} @dots{})
  3004. @acindex{CONFIG_SUBDIRS}
  3005. @ovindex subdirs
  3006. Make @code{AC_OUTPUT} run @command{configure} in each subdirectory
  3007. @var{dir} in the given blank-or-newline-separated list. Each @var{dir} should
  3008. be a literal, i.e., please do not use:
  3009. @example
  3010. @c If you change this example, adjust tests/torture.at:Non-literal AC_CONFIG_SUBDIRS.
  3011. if test "x$package_foo_enabled" = xyes; then
  3012. my_subdirs="$my_subdirs foo"
  3013. fi
  3014. AC_CONFIG_SUBDIRS([$my_subdirs])
  3015. @end example
  3016. @noindent
  3017. because this prevents @samp{./configure --help=recursive} from
  3018. displaying the options of the package @code{foo}. Instead, you should
  3019. write:
  3020. @example
  3021. if test "x$package_foo_enabled" = xyes; then
  3022. AC_CONFIG_SUBDIRS([foo])
  3023. fi
  3024. @end example
  3025. If a given @var{dir} is not found at @command{configure} run time, a
  3026. warning is reported; if the subdirectory is optional, write:
  3027. @example
  3028. if test -d "$srcdir/foo"; then
  3029. AC_CONFIG_SUBDIRS([foo])
  3030. fi
  3031. @end example
  3032. @c NB: Yes, below we mean configure.in, not configure.ac.
  3033. If a given @var{dir} contains @command{configure.gnu}, it is run instead
  3034. of @command{configure}. This is for packages that might use a
  3035. non-Autoconf script @command{Configure}, which can't be called through a
  3036. wrapper @command{configure} since it would be the same file on
  3037. case-insensitive file systems. Likewise, if a @var{dir} contains
  3038. @file{configure.in} but no @command{configure}, the Cygnus
  3039. @command{configure} script found by @code{AC_CONFIG_AUX_DIR} is used.
  3040. The subdirectory @command{configure} scripts are given the same command
  3041. line options that were given to this @command{configure} script, with minor
  3042. changes if needed, which include:
  3043. @itemize @minus
  3044. @item
  3045. adjusting a relative name for the cache file;
  3046. @item
  3047. adjusting a relative name for the source directory;
  3048. @item
  3049. propagating the current value of @code{$prefix}, including if it was
  3050. defaulted, and if the default values of the top level and of the subdirectory
  3051. @file{configure} differ.
  3052. @end itemize
  3053. This macro also sets the output variable @code{subdirs} to the list of
  3054. directories @samp{@var{dir} @dots{}}. Make rules can use
  3055. this variable to determine which subdirectories to recurse into.
  3056. This macro may be called multiple times.
  3057. @end defmac
  3058. @node Default Prefix
  3059. @section Default Prefix
  3060. @cindex Install prefix
  3061. @cindex Prefix for install
  3062. By default, @command{configure} sets the prefix for files it installs to
  3063. @file{/usr/local}. The user of @command{configure} can select a different
  3064. prefix using the @option{--prefix} and @option{--exec-prefix} options.
  3065. There are two ways to change the default: when creating
  3066. @command{configure}, and when running it.
  3067. Some software packages might want to install in a directory other than
  3068. @file{/usr/local} by default. To accomplish that, use the
  3069. @code{AC_PREFIX_DEFAULT} macro.
  3070. @defmac AC_PREFIX_DEFAULT (@var{prefix})
  3071. @acindex{PREFIX_DEFAULT}
  3072. Set the default installation prefix to @var{prefix} instead of
  3073. @file{/usr/local}.
  3074. @end defmac
  3075. It may be convenient for users to have @command{configure} guess the
  3076. installation prefix from the location of a related program that they
  3077. have already installed. If you wish to do that, you can call
  3078. @code{AC_PREFIX_PROGRAM}.
  3079. @anchor{AC_PREFIX_PROGRAM}
  3080. @defmac AC_PREFIX_PROGRAM (@var{program})
  3081. @acindex{PREFIX_PROGRAM}
  3082. If the user did not specify an installation prefix (using the
  3083. @option{--prefix} option), guess a value for it by looking for
  3084. @var{program} in @env{PATH}, the way the shell does. If @var{program}
  3085. is found, set the prefix to the parent of the directory containing
  3086. @var{program}, else default the prefix as described above
  3087. (@file{/usr/local} or @code{AC_PREFIX_DEFAULT}). For example, if
  3088. @var{program} is @code{gcc} and the @env{PATH} contains
  3089. @file{/usr/local/gnu/bin/gcc}, set the prefix to @file{/usr/local/gnu}.
  3090. @end defmac
  3091. @c ======================================================== Existing tests
  3092. @node Existing Tests
  3093. @chapter Existing Tests
  3094. These macros test for particular system features that packages might
  3095. need or want to use. If you need to test for a kind of feature that
  3096. none of these macros check for, you can probably do it by calling
  3097. primitive test macros with appropriate arguments (@pxref{Writing
  3098. Tests}).
  3099. These tests print messages telling the user which feature they're
  3100. checking for, and what they find. They cache their results for future
  3101. @command{configure} runs (@pxref{Caching Results}).
  3102. Some of these macros set output variables. @xref{Makefile
  3103. Substitutions}, for how to get their values. The phrase ``define
  3104. @var{name}'' is used below as a shorthand to mean ``define the C
  3105. preprocessor symbol @var{name} to the value 1''. @xref{Defining
  3106. Symbols}, for how to get those symbol definitions into your program.
  3107. @menu
  3108. * Common Behavior:: Macros' standard schemes
  3109. * Alternative Programs:: Selecting between alternative programs
  3110. * Files:: Checking for the existence of files
  3111. * Libraries:: Library archives that might be missing
  3112. * Library Functions:: C library functions that might be missing
  3113. * Header Files:: Header files that might be missing
  3114. * Declarations:: Declarations that may be missing
  3115. * Structures:: Structures or members that might be missing
  3116. * Types:: Types that might be missing
  3117. * Compilers and Preprocessors:: Checking for compiling programs
  3118. * System Services:: Operating system services
  3119. * Posix Variants:: Special kludges for specific Posix variants
  3120. * Erlang Libraries:: Checking for the existence of Erlang libraries
  3121. @end menu
  3122. @node Common Behavior
  3123. @section Common Behavior
  3124. @cindex Common autoconf behavior
  3125. Much effort has been expended to make Autoconf easy to learn. The most
  3126. obvious way to reach this goal is simply to enforce standard interfaces
  3127. and behaviors, avoiding exceptions as much as possible. Because of
  3128. history and inertia, unfortunately, there are still too many exceptions
  3129. in Autoconf; nevertheless, this section describes some of the common
  3130. rules.
  3131. @menu
  3132. * Standard Symbols:: Symbols defined by the macros
  3133. * Default Includes:: Includes used by the generic macros
  3134. @end menu
  3135. @node Standard Symbols
  3136. @subsection Standard Symbols
  3137. @cindex Standard symbols
  3138. All the generic macros that @code{AC_DEFINE} a symbol as a result of
  3139. their test transform their @var{argument} values to a standard alphabet.
  3140. First, @var{argument} is converted to upper case and any asterisks
  3141. (@samp{*}) are each converted to @samp{P}. Any remaining characters
  3142. that are not alphanumeric are converted to underscores.
  3143. For instance,
  3144. @example
  3145. AC_CHECK_TYPES([struct $Expensive*])
  3146. @end example
  3147. @noindent
  3148. defines the symbol @samp{HAVE_STRUCT__EXPENSIVEP} if the check
  3149. succeeds.
  3150. @node Default Includes
  3151. @subsection Default Includes
  3152. @cindex Default includes
  3153. @cindex Includes, default
  3154. Several tests depend upon a set of header files. Since these headers
  3155. are not universally available, tests actually have to provide a set of
  3156. protected includes, such as:
  3157. @example
  3158. @group
  3159. #ifdef TIME_WITH_SYS_TIME
  3160. # include <sys/time.h>
  3161. # include <time.h>
  3162. #else
  3163. # ifdef HAVE_SYS_TIME_H
  3164. # include <sys/time.h>
  3165. # else
  3166. # include <time.h>
  3167. # endif
  3168. #endif
  3169. @end group
  3170. @end example
  3171. @noindent
  3172. Unless you know exactly what you are doing, you should avoid using
  3173. unconditional includes, and check the existence of the headers you
  3174. include beforehand (@pxref{Header Files}).
  3175. Most generic macros use the following macro to provide the default set
  3176. of includes:
  3177. @defmac AC_INCLUDES_DEFAULT (@ovar{include-directives})
  3178. @acindex{INCLUDES_DEFAULT}
  3179. Expand to @var{include-directives} if defined, otherwise to:
  3180. @example
  3181. @group
  3182. #include <stdio.h>
  3183. #ifdef HAVE_SYS_TYPES_H
  3184. # include <sys/types.h>
  3185. #endif
  3186. #ifdef HAVE_SYS_STAT_H
  3187. # include <sys/stat.h>
  3188. #endif
  3189. #ifdef STDC_HEADERS
  3190. # include <stdlib.h>
  3191. # include <stddef.h>
  3192. #else
  3193. # ifdef HAVE_STDLIB_H
  3194. # include <stdlib.h>
  3195. # endif
  3196. #endif
  3197. #ifdef HAVE_STRING_H
  3198. # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
  3199. # include <memory.h>
  3200. # endif
  3201. # include <string.h>
  3202. #endif
  3203. #ifdef HAVE_STRINGS_H
  3204. # include <strings.h>
  3205. #endif
  3206. #ifdef HAVE_INTTYPES_H
  3207. # include <inttypes.h>
  3208. #endif
  3209. #ifdef HAVE_STDINT_H
  3210. # include <stdint.h>
  3211. #endif
  3212. #ifdef HAVE_UNISTD_H
  3213. # include <unistd.h>
  3214. #endif
  3215. @end group
  3216. @end example
  3217. If the default includes are used, then check for the presence of these
  3218. headers and their compatibility, i.e., you don't need to run
  3219. @code{AC_HEADER_STDC}, nor check for @file{stdlib.h} etc.
  3220. These headers are checked for in the same order as they are included.
  3221. For instance, on some systems @file{string.h} and @file{strings.h} both
  3222. exist, but conflict. Then @code{HAVE_STRING_H} is defined, not
  3223. @code{HAVE_STRINGS_H}.
  3224. @end defmac
  3225. @node Alternative Programs
  3226. @section Alternative Programs
  3227. @cindex Programs, checking
  3228. These macros check for the presence or behavior of particular programs.
  3229. They are used to choose between several alternative programs and to
  3230. decide what to do once one has been chosen. If there is no macro
  3231. specifically defined to check for a program you need, and you don't need
  3232. to check for any special properties of it, then you can use one of the
  3233. general program-check macros.
  3234. @menu
  3235. * Particular Programs:: Special handling to find certain programs
  3236. * Generic Programs:: How to find other programs
  3237. @end menu
  3238. @node Particular Programs
  3239. @subsection Particular Program Checks
  3240. These macros check for particular programs---whether they exist, and
  3241. in some cases whether they support certain features.
  3242. @defmac AC_PROG_AWK
  3243. @acindex{PROG_AWK}
  3244. @ovindex AWK
  3245. @caindex prog_AWK
  3246. Check for @code{gawk}, @code{mawk}, @code{nawk}, and @code{awk}, in that
  3247. order, and set output variable @code{AWK} to the first one that is found.
  3248. It tries @code{gawk} first because that is reported to be the
  3249. best implementation. The result can be overridden by setting the
  3250. variable @code{AWK} or the cache variable @code{ac_cv_prog_AWK}.
  3251. Using this macro is sufficient to avoid the pitfalls of traditional
  3252. @command{awk} (@pxref{awk, , Limitations of Usual Tools}).
  3253. @end defmac
  3254. @defmac AC_PROG_GREP
  3255. @acindex{PROG_GREP}
  3256. @ovindex GREP
  3257. @caindex prog_GREP
  3258. Look for the best available @code{grep} or @code{ggrep} that accepts the
  3259. longest input lines possible, and that supports multiple @option{-e} options.
  3260. Set the output variable @code{GREP} to whatever is chosen.
  3261. @xref{grep, , Limitations of Usual Tools}, for more information about
  3262. portability problems with the @command{grep} command family. The result
  3263. can be overridden by setting the @code{GREP} variable and is cached in the
  3264. @code{ac_cv_path_GREP} variable.
  3265. @end defmac
  3266. @defmac AC_PROG_EGREP
  3267. @acindex{PROG_EGREP}
  3268. @ovindex EGREP
  3269. @caindex prog_EGREP
  3270. Check whether @code{$GREP -E} works, or else look for the best available
  3271. @code{egrep} or @code{gegrep} that accepts the longest input lines possible.
  3272. Set the output variable @code{EGREP} to whatever is chosen. The result
  3273. can be overridden by setting the @code{EGREP} variable and is cached in the
  3274. @code{ac_cv_path_EGREP} variable.
  3275. @end defmac
  3276. @defmac AC_PROG_FGREP
  3277. @acindex{PROG_FGREP}
  3278. @ovindex FGREP
  3279. @caindex prog_FGREP
  3280. Check whether @code{$GREP -F} works, or else look for the best available
  3281. @code{fgrep} or @code{gfgrep} that accepts the longest input lines possible.
  3282. Set the output variable @code{FGREP} to whatever is chosen. The result
  3283. can be overridden by setting the @code{FGREP} variable and is cached in the
  3284. @code{ac_cv_path_FGREP} variable.
  3285. @end defmac
  3286. @defmac AC_PROG_INSTALL
  3287. @acindex{PROG_INSTALL}
  3288. @ovindex INSTALL
  3289. @ovindex INSTALL_PROGRAM
  3290. @ovindex INSTALL_DATA
  3291. @ovindex INSTALL_SCRIPT
  3292. @caindex path_install
  3293. Set output variable @code{INSTALL} to the name of a BSD-compatible
  3294. @command{install} program, if one is found in the current @env{PATH}.
  3295. Otherwise, set @code{INSTALL} to @samp{@var{dir}/install-sh -c},
  3296. checking the directories specified to @code{AC_CONFIG_AUX_DIR} (or its
  3297. default directories) to determine @var{dir} (@pxref{Output}). Also set
  3298. the variables @code{INSTALL_PROGRAM} and @code{INSTALL_SCRIPT} to
  3299. @samp{$@{INSTALL@}} and @code{INSTALL_DATA} to @samp{$@{INSTALL@} -m 644}.
  3300. @samp{@@INSTALL@@} is special, as its value may vary for different
  3301. configuration files.
  3302. This macro screens out various instances of @command{install} known not to
  3303. work. It prefers to find a C program rather than a shell script, for
  3304. speed. Instead of @file{install-sh}, it can also use @file{install.sh},
  3305. but that name is obsolete because some @command{make} programs have a rule
  3306. that creates @file{install} from it if there is no makefile. Further, this
  3307. macro requires @command{install} to be able to install multiple files into a
  3308. target directory in a single invocation.
  3309. Autoconf comes with a copy of @file{install-sh} that you can use. If
  3310. you use @code{AC_PROG_INSTALL}, you must include either
  3311. @file{install-sh} or @file{install.sh} in your distribution; otherwise
  3312. @command{configure} produces an error message saying it can't find
  3313. them---even if the system you're on has a good @command{install} program.
  3314. This check is a safety measure to prevent you from accidentally leaving
  3315. that file out, which would prevent your package from installing on
  3316. systems that don't have a BSD-compatible @command{install} program.
  3317. If you need to use your own installation program because it has features
  3318. not found in standard @command{install} programs, there is no reason to use
  3319. @code{AC_PROG_INSTALL}; just put the file name of your program into your
  3320. @file{Makefile.in} files.
  3321. The result of the test can be overridden by setting the variable
  3322. @code{INSTALL} or the cache variable @code{ac_cv_path_install}.
  3323. @end defmac
  3324. @defmac AC_PROG_MKDIR_P
  3325. @acindex{PROG_MKDIR_P}
  3326. @ovindex MKDIR_P
  3327. @caindex path_mkdir
  3328. Set output variable @code{MKDIR_P} to a program that ensures that for
  3329. each argument, a directory named by this argument exists, creating it
  3330. and its parent directories if needed, and without race conditions when
  3331. two instances of the program attempt to make the same directory at
  3332. nearly the same time.
  3333. This macro uses the @samp{mkdir -p} command if possible. Otherwise, it
  3334. falls back on invoking @command{install-sh} with the @option{-d} option,
  3335. so your package should
  3336. contain @file{install-sh} as described under @code{AC_PROG_INSTALL}.
  3337. An @file{install-sh} file that predates Autoconf 2.60 or Automake 1.10
  3338. is vulnerable to race conditions, so if you want to support parallel
  3339. installs from
  3340. different packages into the same directory you need to make sure you
  3341. have an up-to-date @file{install-sh}. In particular, be careful about
  3342. using @samp{autoreconf -if} if your Automake predates Automake 1.10.
  3343. This macro is related to the @code{AS_MKDIR_P} macro (@pxref{Programming
  3344. in M4sh}), but it sets an output variable intended for use in other
  3345. files, whereas @code{AS_MKDIR_P} is intended for use in scripts like
  3346. @command{configure}. Also, @code{AS_MKDIR_P} does not accept options,
  3347. but @code{MKDIR_P} supports the @option{-m} option, e.g., a makefile
  3348. might invoke @code{$(MKDIR_P) -m 0 dir} to create an inaccessible
  3349. directory, and conversely a makefile should use @code{$(MKDIR_P) --
  3350. $(FOO)} if @var{FOO} might yield a value that begins with @samp{-}.
  3351. Finally, @code{AS_MKDIR_P} does not check for race condition
  3352. vulnerability, whereas @code{AC_PROG_MKDIR_P} does.
  3353. @samp{@@MKDIR_P@@} is special, as its value may vary for different
  3354. configuration files.
  3355. The result of the test can be overridden by setting the variable
  3356. @code{MKDIR_P} or the cache variable @code{ac_cv_path_mkdir}.
  3357. @end defmac
  3358. @anchor{AC_PROG_LEX}
  3359. @defmac AC_PROG_LEX
  3360. @acindex{PROG_LEX}
  3361. @ovindex LEX
  3362. @ovindex LEXLIB
  3363. @cvindex YYTEXT_POINTER
  3364. @ovindex LEX_OUTPUT_ROOT
  3365. @caindex prog_LEX
  3366. If @code{flex} is found, set output variable @code{LEX} to @samp{flex}
  3367. and @code{LEXLIB} to @option{-lfl}, if that library is in a standard
  3368. place. Otherwise set @code{LEX} to @samp{lex} and @code{LEXLIB} to
  3369. @option{-ll}, if found. If neither variant is available, set @code{LEX}
  3370. to @samp{:}; for packages that ship the generated @file{file.yy.c}
  3371. alongside the source @file{file.l}, this default allows users without a
  3372. lexer generator to still build the package even if the timestamp for
  3373. @file{file.l} is inadvertently changed.
  3374. Define @code{YYTEXT_POINTER} if @code{yytext} defaults to @samp{char *} instead
  3375. of to @samp{char []}. Also set output variable @code{LEX_OUTPUT_ROOT} to
  3376. the base of the file name that the lexer generates; usually
  3377. @file{lex.yy}, but sometimes something else. These results vary
  3378. according to whether @code{lex} or @code{flex} is being used.
  3379. You are encouraged to use Flex in your sources, since it is both more
  3380. pleasant to use than plain Lex and the C source it produces is portable.
  3381. In order to ensure portability, however, you must either provide a
  3382. function @code{yywrap} or, if you don't use it (e.g., your scanner has
  3383. no @samp{#include}-like feature), simply include a @samp{%noyywrap}
  3384. statement in the scanner's source. Once this done, the scanner is
  3385. portable (unless @emph{you} felt free to use nonportable constructs) and
  3386. does not depend on any library. In this case, and in this case only, it
  3387. is suggested that you use this Autoconf snippet:
  3388. @example
  3389. AC_PROG_LEX
  3390. if test "x$LEX" != xflex; then
  3391. LEX="$SHELL $missing_dir/missing flex"
  3392. AC_SUBST([LEX_OUTPUT_ROOT], [lex.yy])
  3393. AC_SUBST([LEXLIB], [''])
  3394. fi
  3395. @end example
  3396. The shell script @command{missing} can be found in the Automake
  3397. distribution.
  3398. Remember that the user may have supplied an alternate location in
  3399. @env{LEX}, so if Flex is required, it is better to check that the user
  3400. provided something sufficient by parsing the output of @samp{$LEX
  3401. --version} than by simply relying on @code{test "x$LEX" = xflex}.
  3402. To ensure backward compatibility, Automake's @code{AM_PROG_LEX} invokes
  3403. (indirectly) this macro twice, which causes an annoying but benign
  3404. ``@code{AC_PROG_LEX} invoked multiple times'' warning. Future versions
  3405. of Automake will fix this issue; meanwhile, just ignore this message.
  3406. As part of running the test, this macro may delete any file in the
  3407. configuration directory named @file{lex.yy.c} or @file{lexyy.c}.
  3408. The result of this test can be influenced by setting the variable
  3409. @code{LEX} or the cache variable @code{ac_cv_prog_LEX}.
  3410. @end defmac
  3411. @anchor{AC_PROG_LN_S}
  3412. @defmac AC_PROG_LN_S
  3413. @acindex{PROG_LN_S}
  3414. @ovindex LN_S
  3415. If @samp{ln -s} works on the current file system (the operating system
  3416. and file system support symbolic links), set the output variable
  3417. @code{LN_S} to @samp{ln -s}; otherwise, if @samp{ln} works, set
  3418. @code{LN_S} to @samp{ln}, and otherwise set it to @samp{cp -pR}.
  3419. If you make a link in a directory other than the current directory, its
  3420. meaning depends on whether @samp{ln} or @samp{ln -s} is used. To safely
  3421. create links using @samp{$(LN_S)}, either find out which form is used
  3422. and adjust the arguments, or always invoke @code{ln} in the directory
  3423. where the link is to be created.
  3424. In other words, it does not work to do:
  3425. @example
  3426. $(LN_S) foo /x/bar
  3427. @end example
  3428. Instead, do:
  3429. @example
  3430. (cd /x && $(LN_S) foo bar)
  3431. @end example
  3432. @end defmac
  3433. @defmac AC_PROG_RANLIB
  3434. @acindex{PROG_RANLIB}
  3435. @ovindex RANLIB
  3436. @c @caindex prog_RANLIB
  3437. @c @caindex prog_ac_ct_RANLIB
  3438. Set output variable @code{RANLIB} to @samp{ranlib} if @code{ranlib}
  3439. is found, and otherwise to @samp{:} (do nothing).
  3440. @end defmac
  3441. @defmac AC_PROG_SED
  3442. @acindex{PROG_SED}
  3443. @ovindex SED
  3444. @caindex path_SED
  3445. Set output variable @code{SED} to a Sed implementation that conforms to
  3446. Posix and does not have arbitrary length limits. Report an error if no
  3447. acceptable Sed is found. @xref{sed, , Limitations of Usual Tools}, for more
  3448. information about portability problems with Sed.
  3449. The result of this test can be overridden by setting the @code{SED} variable
  3450. and is cached in the @code{ac_cv_path_SED} variable.
  3451. @end defmac
  3452. @defmac AC_PROG_YACC
  3453. @acindex{PROG_YACC}
  3454. @evindex YACC
  3455. @evindex YFLAGS
  3456. @ovindex YACC
  3457. @caindex prog_YACC
  3458. If @code{bison} is found, set output variable @code{YACC} to @samp{bison
  3459. -y}. Otherwise, if @code{byacc} is found, set @code{YACC} to
  3460. @samp{byacc}. Otherwise set @code{YACC} to @samp{yacc}.
  3461. The result of this test can be influenced by setting the variable
  3462. @code{YACC} or the cache variable @code{ac_cv_prog_YACC}.
  3463. @end defmac
  3464. @node Generic Programs
  3465. @subsection Generic Program and File Checks
  3466. These macros are used to find programs not covered by the ``particular''
  3467. test macros. If you need to check the behavior of a program as well as
  3468. find out whether it is present, you have to write your own test for it
  3469. (@pxref{Writing Tests}). By default, these macros use the environment
  3470. variable @env{PATH}. If you need to check for a program that might not
  3471. be in the user's @env{PATH}, you can pass a modified path to use
  3472. instead, like this:
  3473. @example
  3474. AC_PATH_PROG([INETD], [inetd], [/usr/libexec/inetd],
  3475. [$PATH$PATH_SEPARATOR/usr/libexec$PATH_SEPARATOR]dnl
  3476. [/usr/sbin$PATH_SEPARATOR/usr/etc$PATH_SEPARATOR/etc])
  3477. @end example
  3478. You are strongly encouraged to declare the @var{variable} passed to
  3479. @code{AC_CHECK_PROG} etc.@: as precious. @xref{Setting Output Variables},
  3480. @code{AC_ARG_VAR}, for more details.
  3481. @anchor{AC_CHECK_PROG}
  3482. @defmac AC_CHECK_PROG (@var{variable}, @var{prog-to-check-for}, @
  3483. @var{value-if-found}, @ovar{value-if-not-found}, @dvar{path, $PATH}, @
  3484. @ovar{reject})
  3485. @acindex{CHECK_PROG}
  3486. @caindex prog_@var{variable}
  3487. Check whether program @var{prog-to-check-for} exists in @var{path}. If
  3488. it is found, set @var{variable} to @var{value-if-found}, otherwise to
  3489. @var{value-if-not-found}, if given. Always pass over @var{reject} (an
  3490. absolute file name) even if it is the first found in the search path; in
  3491. that case, set @var{variable} using the absolute file name of the
  3492. @var{prog-to-check-for} found that is not @var{reject}. If
  3493. @var{variable} was already set, do nothing. Calls @code{AC_SUBST} for
  3494. @var{variable}. The result of this test can be overridden by setting the
  3495. @var{variable} variable or the cache variable
  3496. @code{ac_cv_prog_@var{variable}}.
  3497. @end defmac
  3498. @anchor{AC_CHECK_PROGS}
  3499. @defmac AC_CHECK_PROGS (@var{variable}, @var{progs-to-check-for}, @
  3500. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3501. @acindex{CHECK_PROGS}
  3502. @caindex prog_@var{variable}
  3503. Check for each program in the blank-separated list
  3504. @var{progs-to-check-for} existing in the @var{path}. If one is found, set
  3505. @var{variable} to the name of that program. Otherwise, continue
  3506. checking the next program in the list. If none of the programs in the
  3507. list are found, set @var{variable} to @var{value-if-not-found}; if
  3508. @var{value-if-not-found} is not specified, the value of @var{variable}
  3509. is not changed. Calls @code{AC_SUBST} for @var{variable}. The result of
  3510. this test can be overridden by setting the @var{variable} variable or the
  3511. cache variable @code{ac_cv_prog_@var{variable}}.
  3512. @end defmac
  3513. @defmac AC_CHECK_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @
  3514. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3515. @acindex{CHECK_TARGET_TOOL}
  3516. Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
  3517. with a prefix of the target type as determined by
  3518. @code{AC_CANONICAL_TARGET}, followed by a dash (@pxref{Canonicalizing}).
  3519. If the tool cannot be found with a prefix, and if the build and target
  3520. types are equal, then it is also searched for without a prefix.
  3521. As noted in @ref{Specifying Target Triplets}, the
  3522. target is rarely specified, because most of the time it is the same
  3523. as the host: it is the type of system for which any compiler tool in
  3524. the package produces code. What this macro looks for is,
  3525. for example, @emph{a tool @r{(assembler, linker, etc.)}@: that the
  3526. compiler driver @r{(@command{gcc} for the GNU C Compiler)}
  3527. uses to produce objects, archives or executables}.
  3528. @end defmac
  3529. @defmac AC_CHECK_TOOL (@var{variable}, @var{prog-to-check-for}, @
  3530. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3531. @acindex{CHECK_TOOL}
  3532. @c @caindex prog_@var{VARIABLE}
  3533. @c @caindex prog_ac_ct_@var{VARIABLE}
  3534. Like @code{AC_CHECK_PROG}, but first looks for @var{prog-to-check-for}
  3535. with a prefix of the host type as specified by @option{--host}, followed by a
  3536. dash. For example, if the user runs
  3537. @samp{configure --build=x86_64-gnu --host=i386-gnu}, then this call:
  3538. @example
  3539. AC_CHECK_TOOL([RANLIB], [ranlib], [:])
  3540. @end example
  3541. @noindent
  3542. sets @code{RANLIB} to @file{i386-gnu-ranlib} if that program exists in
  3543. @var{path}, or otherwise to @samp{ranlib} if that program exists in
  3544. @var{path}, or to @samp{:} if neither program exists.
  3545. When cross-compiling, this macro will issue a warning if no program
  3546. prefixed with the host type could be found.
  3547. For more information, see @ref{Specifying Target Triplets}.
  3548. @end defmac
  3549. @defmac AC_CHECK_TARGET_TOOLS (@var{variable}, @var{progs-to-check-for}, @
  3550. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3551. @acindex{CHECK_TARGET_TOOLS}
  3552. Like @code{AC_CHECK_TARGET_TOOL}, each of the tools in the list
  3553. @var{progs-to-check-for} are checked with a prefix of the target type as
  3554. determined by @code{AC_CANONICAL_TARGET}, followed by a dash
  3555. (@pxref{Canonicalizing}). If none of the tools can be found with a
  3556. prefix, and if the build and target types are equal, then the first one
  3557. without a prefix is used. If a tool is found, set @var{variable} to
  3558. the name of that program. If none of the tools in the list are found,
  3559. set @var{variable} to @var{value-if-not-found}; if @var{value-if-not-found}
  3560. is not specified, the value of @var{variable} is not changed. Calls
  3561. @code{AC_SUBST} for @var{variable}.
  3562. @end defmac
  3563. @defmac AC_CHECK_TOOLS (@var{variable}, @var{progs-to-check-for}, @
  3564. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3565. @acindex{CHECK_TOOLS}
  3566. Like @code{AC_CHECK_TOOL}, each of the tools in the list
  3567. @var{progs-to-check-for} are checked with a prefix of the host type as
  3568. determined by @code{AC_CANONICAL_HOST}, followed by a dash
  3569. (@pxref{Canonicalizing}). If none of the tools can be found with a
  3570. prefix, then the first one without a prefix is used. If a tool is found,
  3571. set @var{variable} to the name of that program. If none of the tools in
  3572. the list are found, set @var{variable} to @var{value-if-not-found}; if
  3573. @var{value-if-not-found} is not specified, the value of @var{variable}
  3574. is not changed. Calls @code{AC_SUBST} for @var{variable}.
  3575. When cross-compiling, this macro will issue a warning if no program
  3576. prefixed with the host type could be found.
  3577. For more information, see @ref{Specifying Target Triplets}.
  3578. @end defmac
  3579. @anchor{AC_PATH_PROG}
  3580. @defmac AC_PATH_PROG (@var{variable}, @var{prog-to-check-for}, @
  3581. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3582. @acindex{PATH_PROG}
  3583. @caindex path_@var{variable}
  3584. Like @code{AC_CHECK_PROG}, but set @var{variable} to the absolute
  3585. name of @var{prog-to-check-for} if found. The result of this test
  3586. can be overridden by setting the @var{variable} variable. A positive
  3587. result of this test is cached in the @code{ac_cv_path_@var{variable}}
  3588. variable.
  3589. @end defmac
  3590. @anchor{AC_PATH_PROGS}
  3591. @defmac AC_PATH_PROGS (@var{variable}, @var{progs-to-check-for}, @
  3592. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3593. @acindex{PATH_PROGS}
  3594. @caindex path_@var{variable}
  3595. Like @code{AC_CHECK_PROGS}, but if any of @var{progs-to-check-for}
  3596. are found, set @var{variable} to the absolute name of the program
  3597. found. The result of this test can be overridden by setting the
  3598. @var{variable} variable. A positive result of this test is cached in
  3599. the @code{ac_cv_path_@var{variable}} variable.
  3600. @end defmac
  3601. @defmac AC_PATH_PROGS_FEATURE_CHECK (@var{variable}, @
  3602. @var{progs-to-check-for}, @var{feature-test}, @
  3603. @ovar{action-if-not-found}, @dvar{path, $PATH})
  3604. @acindex{PATH_PROGS_FEATURE_CHECK}
  3605. @caindex path_@var{variable}
  3606. @vrindex ac_path_@var{variable}
  3607. @vrindex ac_path_@var{variable}_found
  3608. This macro was introduced in Autoconf 2.62. If @var{variable} is not
  3609. empty, then set the cache variable @code{ac_cv_path_@var{variable}} to
  3610. its value. Otherwise, check for each program in the blank-separated
  3611. list @var{progs-to-check-for} existing in @var{path}. For each program
  3612. found, execute @var{feature-test} with @code{ac_path_@var{variable}}
  3613. set to the absolute name of the candidate program. If no invocation of
  3614. @var{feature-test} sets the shell variable
  3615. @code{ac_cv_path_@var{variable}}, then @var{action-if-not-found} is
  3616. executed. @var{feature-test} will be run even when
  3617. @code{ac_cv_path_@var{variable}} is set, to provide the ability to
  3618. choose a better candidate found later in @var{path}; to accept the
  3619. current setting and bypass all further checks, @var{feature-test} can
  3620. execute @code{ac_path_@var{variable}_found=:}.
  3621. Note that this macro has some subtle differences from
  3622. @code{AC_CHECK_PROGS}. It is designed to be run inside
  3623. @code{AC_CACHE_VAL}, therefore, it should have no side effects. In
  3624. particular, @var{variable} is not set to the final value of
  3625. @code{ac_cv_path_@var{variable}}, nor is @code{AC_SUBST} automatically
  3626. run. Also, on failure, any action can be performed, whereas
  3627. @code{AC_CHECK_PROGS} only performs
  3628. @code{@var{variable}=@var{value-if-not-found}}.
  3629. Here is an example, similar to what Autoconf uses in its own configure
  3630. script. It will search for an implementation of @command{m4} that
  3631. supports the @code{indir} builtin, even if it goes by the name
  3632. @command{gm4} or is not the first implementation on @env{PATH}.
  3633. @example
  3634. AC_CACHE_CHECK([for m4 that supports indir], [ac_cv_path_M4],
  3635. [AC_PATH_PROGS_FEATURE_CHECK([M4], [m4 gm4],
  3636. [[m4out=`echo 'changequote([,])indir([divnum])' | $ac_path_M4`
  3637. test "x$m4out" = x0 \
  3638. && ac_cv_path_M4=$ac_path_M4 ac_path_M4_found=:]],
  3639. [AC_MSG_ERROR([could not find m4 that supports indir])])])
  3640. AC_SUBST([M4], [$ac_cv_path_M4])
  3641. @end example
  3642. @end defmac
  3643. @defmac AC_PATH_TARGET_TOOL (@var{variable}, @var{prog-to-check-for}, @
  3644. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3645. @acindex{PATH_TARGET_TOOL}
  3646. Like @code{AC_CHECK_TARGET_TOOL}, but set @var{variable} to the absolute
  3647. name of the program if it is found.
  3648. @end defmac
  3649. @defmac AC_PATH_TOOL (@var{variable}, @var{prog-to-check-for}, @
  3650. @ovar{value-if-not-found}, @dvar{path, $PATH})
  3651. @acindex{PATH_TOOL}
  3652. Like @code{AC_CHECK_TOOL}, but set @var{variable} to the absolute
  3653. name of the program if it is found.
  3654. When cross-compiling, this macro will issue a warning if no program
  3655. prefixed with the host type could be found.
  3656. For more information, see @ref{Specifying Target Triplets}.
  3657. @end defmac
  3658. @node Files
  3659. @section Files
  3660. @cindex File, checking
  3661. You might also need to check for the existence of files. Before using
  3662. these macros, ask yourself whether a runtime test might not be a better
  3663. solution. Be aware that, like most Autoconf macros, they test a feature
  3664. of the host machine, and therefore, they die when cross-compiling.
  3665. @defmac AC_CHECK_FILE (@var{file}, @ovar{action-if-found}, @
  3666. @ovar{action-if-not-found})
  3667. @acindex{CHECK_FILE}
  3668. @caindex file_@var{file}
  3669. Check whether file @var{file} exists on the native system. If it is
  3670. found, execute @var{action-if-found}, otherwise do
  3671. @var{action-if-not-found}, if given. The result of this test is cached
  3672. in the @code{ac_cv_file_@var{file}} variable, with characters not
  3673. suitable for a variable name mapped to underscores.
  3674. @end defmac
  3675. @defmac AC_CHECK_FILES (@var{files}, @ovar{action-if-found}, @
  3676. @ovar{action-if-not-found})
  3677. @acindex{CHECK_FILES}
  3678. @caindex file_@var{file}
  3679. Executes @code{AC_CHECK_FILE} once for each file listed in @var{files}.
  3680. Additionally, defines @samp{HAVE_@var{file}} (@pxref{Standard Symbols})
  3681. for each file found. The results of each test are cached in the
  3682. @code{ac_cv_file_@var{file}} variable, with characters not suitable for
  3683. a variable name mapped to underscores.
  3684. @end defmac
  3685. @node Libraries
  3686. @section Library Files
  3687. @cindex Library, checking
  3688. The following macros check for the presence of certain C, C++, Fortran,
  3689. or Go library archive files.
  3690. @anchor{AC_CHECK_LIB}
  3691. @defmac AC_CHECK_LIB (@var{library}, @var{function}, @
  3692. @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
  3693. @acindex{CHECK_LIB}
  3694. @caindex lib_@var{library}_@var{function}
  3695. Test whether the library @var{library} is available by trying to link
  3696. a test program that calls function @var{function} with the library.
  3697. @var{function} should be a function provided by the library.
  3698. Use the base
  3699. name of the library; e.g., to check for @option{-lmp}, use @samp{mp} as
  3700. the @var{library} argument.
  3701. @var{action-if-found} is a list of shell commands to run if the link
  3702. with the library succeeds; @var{action-if-not-found} is a list of shell
  3703. commands to run if the link fails. If @var{action-if-found} is not
  3704. specified, the default action prepends @option{-l@var{library}} to
  3705. @code{LIBS} and defines @samp{HAVE_LIB@var{library}} (in all
  3706. capitals). This macro is intended to support building @code{LIBS} in
  3707. a right-to-left (least-dependent to most-dependent) fashion such that
  3708. library dependencies are satisfied as a natural side effect of
  3709. consecutive tests. Linkers are sensitive to library ordering
  3710. so the order in which @code{LIBS} is generated is important to reliable
  3711. detection of libraries.
  3712. If linking with @var{library} results in unresolved symbols that would
  3713. be resolved by linking with additional libraries, give those libraries
  3714. as the @var{other-libraries} argument, separated by spaces:
  3715. e.g., @option{-lXt -lX11}. Otherwise, this macro may fail to detect
  3716. that @var{library} is present, because linking the test program can
  3717. fail with unresolved symbols. The @var{other-libraries} argument
  3718. should be limited to cases where it is desirable to test for one library
  3719. in the presence of another that is not already in @code{LIBS}.
  3720. @code{AC_CHECK_LIB} requires some care in usage, and should be avoided
  3721. in some common cases. Many standard functions like @code{gethostbyname}
  3722. appear in the standard C library on some hosts, and in special libraries
  3723. like @code{nsl} on other hosts. On some hosts the special libraries
  3724. contain variant implementations that you may not want to use. These
  3725. days it is normally better to use @code{AC_SEARCH_LIBS([gethostbyname],
  3726. [nsl])} instead of @code{AC_CHECK_LIB([nsl], [gethostbyname])}.
  3727. The result of this test is cached in the
  3728. @code{ac_cv_lib_@var{library}_@var{function}} variable.
  3729. @end defmac
  3730. @anchor{AC_SEARCH_LIBS}
  3731. @defmac AC_SEARCH_LIBS (@var{function}, @var{search-libs}, @
  3732. @ovar{action-if-found}, @ovar{action-if-not-found}, @ovar{other-libraries})
  3733. @acindex{SEARCH_LIBS}
  3734. @caindex search_@var{function}
  3735. Search for a library defining @var{function} if it's not already
  3736. available. This equates to calling
  3737. @samp{AC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])])} first with
  3738. no libraries, then for each library listed in @var{search-libs}.
  3739. Prepend @option{-l@var{library}} to @code{LIBS} for the first library found
  3740. to contain @var{function}, and run @var{action-if-found}. If the
  3741. function is not found, run @var{action-if-not-found}.
  3742. If linking with @var{library} results in unresolved symbols that would
  3743. be resolved by linking with additional libraries, give those libraries
  3744. as the @var{other-libraries} argument, separated by spaces:
  3745. e.g., @option{-lXt -lX11}. Otherwise, this macro fails to detect
  3746. that @var{function} is present, because linking the test program
  3747. always fails with unresolved symbols.
  3748. The result of this test is cached in the
  3749. @code{ac_cv_search_@var{function}} variable as @samp{none required} if
  3750. @var{function} is already available, as @samp{no} if no library
  3751. containing @var{function} was found, otherwise as the
  3752. @option{-l@var{library}} option that needs to be prepended to @code{LIBS}.
  3753. @end defmac
  3754. @node Library Functions
  3755. @section Library Functions
  3756. The following macros check for particular C library functions.
  3757. If there is no macro specifically defined to check for a function you need,
  3758. and you don't need to check for any special properties of
  3759. it, then you can use one of the general function-check macros.
  3760. @menu
  3761. * Function Portability:: Pitfalls with usual functions
  3762. * Particular Functions:: Special handling to find certain functions
  3763. * Generic Functions:: How to find other functions
  3764. @end menu
  3765. @node Function Portability
  3766. @subsection Portability of C Functions
  3767. @cindex Portability of C functions
  3768. @cindex C function portability
  3769. Most usual functions can either be missing, or be buggy, or be limited
  3770. on some architectures. This section tries to make an inventory of these
  3771. portability issues. By definition, this list always requires
  3772. additions. A much more complete list is maintained by the Gnulib
  3773. project (@pxref{Gnulib}), covering @ref{Function Substitutes, ,
  3774. Current Posix Functions, gnulib, GNU gnulib}, @ref{Legacy Function
  3775. Substitutes, , Legacy Functions, gnulib, GNU gnulib}, and @ref{Glibc
  3776. Function Substitutes, , Glibc Functions, gnulib, GNU gnulib}. Please
  3777. help us keep the gnulib list as complete as possible.
  3778. @table @asis
  3779. @item @code{exit}
  3780. @c @fuindex exit
  3781. @prindex @code{exit}
  3782. On ancient hosts, @code{exit} returned @code{int}.
  3783. This is because @code{exit} predates @code{void}, and there was a long
  3784. tradition of it returning @code{int}.
  3785. On current hosts, the problem more likely is that @code{exit} is not
  3786. declared, due to C++ problems of some sort or another. For this reason
  3787. we suggest that test programs not invoke @code{exit}, but return from
  3788. @code{main} instead.
  3789. @item @code{free}
  3790. @c @fuindex free
  3791. @prindex @code{free}
  3792. The C standard says a call @code{free (NULL)} does nothing, but
  3793. some old systems don't support this (e.g., NextStep).
  3794. @item @code{isinf}
  3795. @itemx @code{isnan}
  3796. @c @fuindex isinf
  3797. @c @fuindex isnan
  3798. @prindex @code{isinf}
  3799. @prindex @code{isnan}
  3800. The C99 standard says that @code{isinf} and @code{isnan} are
  3801. macros. On some systems just macros are available
  3802. (e.g., HP-UX and Solaris 10), on
  3803. some systems both macros and functions (e.g., glibc 2.3.2), and on some
  3804. systems only functions (e.g., IRIX 6 and Solaris 9). In some cases
  3805. these functions are declared in nonstandard headers like
  3806. @code{<sunmath.h>} and defined in non-default libraries like
  3807. @option{-lm} or @option{-lsunmath}.
  3808. The C99 @code{isinf} and @code{isnan} macros work correctly with
  3809. @code{long double} arguments, but pre-C99 systems that use functions
  3810. typically assume @code{double} arguments. On such a system,
  3811. @code{isinf} incorrectly returns true for a finite @code{long double}
  3812. argument that is outside the range of @code{double}.
  3813. The best workaround for these issues is to use gnulib modules
  3814. @code{isinf} and @code{isnan} (@pxref{Gnulib}). But a lighter weight
  3815. solution involves code like the following.
  3816. @smallexample
  3817. #include <math.h>
  3818. #ifndef isnan
  3819. # define isnan(x) \
  3820. (sizeof (x) == sizeof (long double) ? isnan_ld (x) \
  3821. : sizeof (x) == sizeof (double) ? isnan_d (x) \
  3822. : isnan_f (x))
  3823. static inline int isnan_f (float x) @{ return x != x; @}
  3824. static inline int isnan_d (double x) @{ return x != x; @}
  3825. static inline int isnan_ld (long double x) @{ return x != x; @}
  3826. #endif
  3827. #ifndef isinf
  3828. # define isinf(x) \
  3829. (sizeof (x) == sizeof (long double) ? isinf_ld (x) \
  3830. : sizeof (x) == sizeof (double) ? isinf_d (x) \
  3831. : isinf_f (x))
  3832. static inline int isinf_f (float x)
  3833. @{ return !isnan (x) && isnan (x - x); @}
  3834. static inline int isinf_d (double x)
  3835. @{ return !isnan (x) && isnan (x - x); @}
  3836. static inline int isinf_ld (long double x)
  3837. @{ return !isnan (x) && isnan (x - x); @}
  3838. #endif
  3839. @end smallexample
  3840. Use @code{AC_C_INLINE} (@pxref{C Compiler}) so that this code works on
  3841. compilers that lack the @code{inline} keyword. Some optimizing
  3842. compilers mishandle these definitions, but systems with that bug
  3843. typically have many other floating point corner-case compliance problems
  3844. anyway, so it's probably not worth worrying about.
  3845. @item @code{malloc}
  3846. @c @fuindex malloc
  3847. @prindex @code{malloc}
  3848. The C standard says a call @code{malloc (0)} is implementation
  3849. dependent. It can return either @code{NULL} or a new non-null pointer.
  3850. The latter is more common (e.g., the GNU C Library) but is by
  3851. no means universal. @code{AC_FUNC_MALLOC}
  3852. can be used to insist on non-@code{NULL} (@pxref{Particular Functions}).
  3853. @item @code{putenv}
  3854. @c @fuindex putenv
  3855. @prindex @code{putenv}
  3856. Posix prefers @code{setenv} to @code{putenv}; among other things,
  3857. @code{putenv} is not required of all Posix implementations, but
  3858. @code{setenv} is.
  3859. Posix specifies that @code{putenv} puts the given string directly in
  3860. @code{environ}, but some systems make a copy of it instead (e.g.,
  3861. glibc 2.0, or BSD). And when a copy is made, @code{unsetenv} might
  3862. not free it, causing a memory leak (e.g., FreeBSD 4).
  3863. On some systems @code{putenv ("FOO")} removes @samp{FOO} from the
  3864. environment, but this is not standard usage and it dumps core
  3865. on some systems (e.g., AIX).
  3866. On MinGW, a call @code{putenv ("FOO=")} removes @samp{FOO} from the
  3867. environment, rather than inserting it with an empty value.
  3868. @item @code{realloc}
  3869. @c @fuindex realloc
  3870. @prindex @code{realloc}
  3871. The C standard says a call @code{realloc (NULL, size)} is equivalent
  3872. to @code{malloc (size)}, but some old systems don't support this (e.g.,
  3873. NextStep).
  3874. @item @code{signal} handler
  3875. @c @fuindex signal
  3876. @prindex @code{signal}
  3877. @prindex @code{sigaction}
  3878. Normally @code{signal} takes a handler function with a return type of
  3879. @code{void}, but some old systems required @code{int} instead. Any
  3880. actual @code{int} value returned is not used; this is only a
  3881. difference in the function prototype demanded.
  3882. All systems we know of in current use return @code{void}. The
  3883. @code{int} was to support K&R C, where of course @code{void} is not
  3884. available. The obsolete macro @code{AC_TYPE_SIGNAL}
  3885. (@pxref{AC_TYPE_SIGNAL}) can be used to establish the correct type in
  3886. all cases.
  3887. In most cases, it is more robust to use @code{sigaction} when it is
  3888. available, rather than @code{signal}.
  3889. @item @code{snprintf}
  3890. @c @fuindex snprintf
  3891. @prindex @code{snprintf}
  3892. @c @fuindex vsnprintf
  3893. @prindex @code{vsnprintf}
  3894. The C99 standard says that if the output array isn't big enough
  3895. and if no other errors occur, @code{snprintf} and @code{vsnprintf}
  3896. truncate the output and return the number of bytes that ought to have
  3897. been produced. Some older systems return the truncated length (e.g.,
  3898. GNU C Library 2.0.x or IRIX 6.5), some a negative value
  3899. (e.g., earlier GNU C Library versions), and some the buffer
  3900. length without truncation (e.g., 32-bit Solaris 7). Also, some buggy
  3901. older systems ignore the length and overrun the buffer (e.g., 64-bit
  3902. Solaris 7).
  3903. @item @code{sprintf}
  3904. @c @fuindex sprintf
  3905. @prindex @code{sprintf}
  3906. @c @fuindex vsprintf
  3907. @prindex @code{vsprintf}
  3908. The C standard says @code{sprintf} and @code{vsprintf} return the
  3909. number of bytes written. On some ancient systems (SunOS 4 for
  3910. instance) they return the buffer pointer instead, but these no
  3911. longer need to be worried about.
  3912. @item @code{sscanf}
  3913. @c @fuindex sscanf
  3914. @prindex @code{sscanf}
  3915. On various old systems, e.g., HP-UX 9, @code{sscanf} requires
  3916. that its
  3917. input string be writable (though it doesn't actually change it). This
  3918. can be a problem when using @command{gcc} since it normally puts
  3919. constant strings in read-only memory (@pxref{Incompatibilities,
  3920. Incompatibilities of GCC, , gcc, Using and
  3921. Porting the GNU Compiler Collection}). Apparently in some cases even
  3922. having format strings read-only can be a problem.
  3923. @item @code{strerror_r}
  3924. @c @fuindex strerror_r
  3925. @prindex @code{strerror_r}
  3926. Posix specifies that @code{strerror_r} returns an @code{int}, but many
  3927. systems (e.g., GNU C Library version 2.2.4) provide a
  3928. different version returning a @code{char *}. @code{AC_FUNC_STRERROR_R}
  3929. can detect which is in use (@pxref{Particular Functions}).
  3930. @item @code{strnlen}
  3931. @c @fuindex strnlen
  3932. @prindex @code{strnlen}
  3933. AIX 4.3 provides a broken version which produces the
  3934. following results:
  3935. @example
  3936. strnlen ("foobar", 0) = 0
  3937. strnlen ("foobar", 1) = 3
  3938. strnlen ("foobar", 2) = 2
  3939. strnlen ("foobar", 3) = 1
  3940. strnlen ("foobar", 4) = 0
  3941. strnlen ("foobar", 5) = 6
  3942. strnlen ("foobar", 6) = 6
  3943. strnlen ("foobar", 7) = 6
  3944. strnlen ("foobar", 8) = 6
  3945. strnlen ("foobar", 9) = 6
  3946. @end example
  3947. @item @code{sysconf}
  3948. @c @fuindex sysconf
  3949. @prindex @code{sysconf}
  3950. @code{_SC_PAGESIZE} is standard, but some older systems (e.g., HP-UX
  3951. 9) have @code{_SC_PAGE_SIZE} instead. This can be tested with
  3952. @code{#ifdef}.
  3953. @item @code{unlink}
  3954. @c @fuindex unlink
  3955. @prindex @code{unlink}
  3956. The Posix spec says that @code{unlink} causes the given file to be
  3957. removed only after there are no more open file handles for it. Some
  3958. non-Posix hosts have trouble with this requirement, though,
  3959. and some DOS variants even corrupt the file system.
  3960. @item @code{unsetenv}
  3961. @c @fuindex unsetenv
  3962. @prindex @code{unsetenv}
  3963. On MinGW, @code{unsetenv} is not available, but a variable @samp{FOO}
  3964. can be removed with a call @code{putenv ("FOO=")}, as described under
  3965. @code{putenv} above.
  3966. @item @code{va_copy}
  3967. @c @fuindex va_copy
  3968. @prindex @code{va_copy}
  3969. The C99 standard provides @code{va_copy} for copying
  3970. @code{va_list} variables. It may be available in older environments
  3971. too, though possibly as @code{__va_copy} (e.g., @command{gcc} in strict
  3972. pre-C99 mode). These can be tested with @code{#ifdef}. A fallback to
  3973. @code{memcpy (&dst, &src, sizeof (va_list))} gives maximum
  3974. portability.
  3975. @item @code{va_list}
  3976. @c @fuindex va_list
  3977. @prindex @code{va_list}
  3978. @code{va_list} is not necessarily just a pointer. It can be a
  3979. @code{struct} (e.g., @command{gcc} on Alpha), which means @code{NULL} is
  3980. not portable. Or it can be an array (e.g., @command{gcc} in some
  3981. PowerPC configurations), which means as a function parameter it can be
  3982. effectively call-by-reference and library routines might modify the
  3983. value back in the caller (e.g., @code{vsnprintf} in the GNU C Library
  3984. 2.1).
  3985. @item Signed @code{>>}
  3986. Normally the C @code{>>} right shift of a signed type replicates the
  3987. high bit, giving a so-called ``arithmetic'' shift. But care should be
  3988. taken since Standard C doesn't require that behavior. On those
  3989. few processors without a native arithmetic shift (for instance Cray
  3990. vector systems) zero bits may be shifted in, the same as a shift of an
  3991. unsigned type.
  3992. @item Integer @code{/}
  3993. C divides signed integers by truncating their quotient toward zero,
  3994. yielding the same result as Fortran. However, before C99 the standard
  3995. allowed C implementations to take the floor or ceiling of the quotient
  3996. in some cases. Hardly any implementations took advantage of this
  3997. freedom, though, and it's probably not worth worrying about this issue
  3998. nowadays.
  3999. @end table
  4000. @node Particular Functions
  4001. @subsection Particular Function Checks
  4002. @cindex Function, checking
  4003. These macros check for particular C functions---whether they exist, and
  4004. in some cases how they respond when given certain arguments.
  4005. @anchor{AC_FUNC_ALLOCA}
  4006. @defmac AC_FUNC_ALLOCA
  4007. @acindex{FUNC_ALLOCA}
  4008. @cvindex C_ALLOCA
  4009. @cvindex HAVE_ALLOCA_H
  4010. @ovindex ALLOCA
  4011. @c @fuindex alloca
  4012. @prindex @code{alloca}
  4013. @hdrindex{alloca.h}
  4014. @c @caindex working_alloca_h
  4015. Check how to get @code{alloca}. Tries to get a builtin version by
  4016. checking for @file{alloca.h} or the predefined C preprocessor macros
  4017. @code{__GNUC__} and @code{_AIX}. If this macro finds @file{alloca.h},
  4018. it defines @code{HAVE_ALLOCA_H}.
  4019. If those attempts fail, it looks for the function in the standard C
  4020. library. If any of those methods succeed, it defines
  4021. @code{HAVE_ALLOCA}. Otherwise, it sets the output variable
  4022. @code{ALLOCA} to @samp{$@{LIBOBJDIR@}alloca.o} and defines
  4023. @code{C_ALLOCA} (so programs can periodically call @samp{alloca (0)} to
  4024. garbage collect). This variable is separate from @code{LIBOBJS} so
  4025. multiple programs can share the value of @code{ALLOCA} without needing
  4026. to create an actual library, in case only some of them use the code in
  4027. @code{LIBOBJS}. The @samp{$@{LIBOBJDIR@}} prefix serves the same
  4028. purpose as in @code{LIBOBJS} (@pxref{AC_LIBOBJ vs LIBOBJS}).
  4029. This macro does not try to get @code{alloca} from the System V R3
  4030. @file{libPW} or the System V R4 @file{libucb} because those libraries
  4031. contain some incompatible functions that cause trouble. Some versions
  4032. do not even contain @code{alloca} or contain a buggy version. If you
  4033. still want to use their @code{alloca}, use @code{ar} to extract
  4034. @file{alloca.o} from them instead of compiling @file{alloca.c}.
  4035. Source files that use @code{alloca} should start with a piece of code
  4036. like the following, to declare it properly.
  4037. @example
  4038. @group
  4039. #ifdef STDC_HEADERS
  4040. # include <stdlib.h>
  4041. # include <stddef.h>
  4042. #else
  4043. # ifdef HAVE_STDLIB_H
  4044. # include <stdlib.h>
  4045. # endif
  4046. #endif
  4047. #ifdef HAVE_ALLOCA_H
  4048. # include <alloca.h>
  4049. #elif !defined alloca
  4050. # ifdef __GNUC__
  4051. # define alloca __builtin_alloca
  4052. # elif defined _AIX
  4053. # define alloca __alloca
  4054. # elif defined _MSC_VER
  4055. # include <malloc.h>
  4056. # define alloca _alloca
  4057. # elif !defined HAVE_ALLOCA
  4058. # ifdef __cplusplus
  4059. extern "C"
  4060. # endif
  4061. void *alloca (size_t);
  4062. # endif
  4063. #endif
  4064. @end group
  4065. @end example
  4066. @end defmac
  4067. @defmac AC_FUNC_CHOWN
  4068. @acindex{FUNC_CHOWN}
  4069. @cvindex HAVE_CHOWN
  4070. @c @fuindex chown
  4071. @prindex @code{chown}
  4072. @caindex func_chown_works
  4073. If the @code{chown} function is available and works (in particular, it
  4074. should accept @option{-1} for @code{uid} and @code{gid}), define
  4075. @code{HAVE_CHOWN}. The result of this macro is cached in the
  4076. @code{ac_cv_func_chown_works} variable.
  4077. @end defmac
  4078. @anchor{AC_FUNC_CLOSEDIR_VOID}
  4079. @defmac AC_FUNC_CLOSEDIR_VOID
  4080. @acindex{FUNC_CLOSEDIR_VOID}
  4081. @cvindex CLOSEDIR_VOID
  4082. @c @fuindex closedir
  4083. @prindex @code{closedir}
  4084. @caindex func_closedir_void
  4085. If the @code{closedir} function does not return a meaningful value,
  4086. define @code{CLOSEDIR_VOID}. Otherwise, callers ought to check its
  4087. return value for an error indicator.
  4088. Currently this test is implemented by running a test program. When
  4089. cross compiling the pessimistic assumption that @code{closedir} does not
  4090. return a meaningful value is made.
  4091. The result of this macro is cached in the @code{ac_cv_func_closedir_void}
  4092. variable.
  4093. This macro is obsolescent, as @code{closedir} returns a meaningful value
  4094. on current systems. New programs need not use this macro.
  4095. @end defmac
  4096. @defmac AC_FUNC_ERROR_AT_LINE
  4097. @acindex{FUNC_ERROR_AT_LINE}
  4098. @c @fuindex error_at_line
  4099. @prindex @code{error_at_line}
  4100. @caindex lib_error_at_line
  4101. If the @code{error_at_line} function is not found, require an
  4102. @code{AC_LIBOBJ} replacement of @samp{error}.
  4103. The result of this macro is cached in the @code{ac_cv_lib_error_at_line}
  4104. variable.
  4105. The @code{AC_FUNC_ERROR_AT_LINE} macro is obsolescent. New programs
  4106. should use Gnulib's @code{error} module. @xref{Gnulib}.
  4107. @end defmac
  4108. @defmac AC_FUNC_FNMATCH
  4109. @acindex{FUNC_FNMATCH}
  4110. @c @fuindex fnmatch
  4111. @prindex @code{fnmatch}
  4112. @caindex func_fnmatch_works
  4113. If the @code{fnmatch} function conforms to Posix, define
  4114. @code{HAVE_FNMATCH}. Detect common implementation bugs, for example,
  4115. the bugs in Solaris 2.4.
  4116. Unlike the other specific
  4117. @code{AC_FUNC} macros, @code{AC_FUNC_FNMATCH} does not replace a
  4118. broken/missing @code{fnmatch}. This is for historical reasons.
  4119. See @code{AC_REPLACE_FNMATCH} below.
  4120. The result of this macro is cached in the @code{ac_cv_func_fnmatch_works}
  4121. variable.
  4122. This macro is obsolescent. New programs should use Gnulib's
  4123. @code{fnmatch-posix} module. @xref{Gnulib}.
  4124. @end defmac
  4125. @defmac AC_FUNC_FNMATCH_GNU
  4126. @acindex{FUNC_FNMATCH_GNU}
  4127. @c @fuindex fnmatch
  4128. @prindex @code{fnmatch}
  4129. @caindex func_fnmatch_gnu
  4130. Behave like @code{AC_REPLACE_FNMATCH} (@emph{replace}) but also test
  4131. whether @code{fnmatch} supports GNU extensions. Detect common
  4132. implementation bugs, for example, the bugs in the GNU C
  4133. Library 2.1.
  4134. The result of this macro is cached in the @code{ac_cv_func_fnmatch_gnu}
  4135. variable.
  4136. This macro is obsolescent. New programs should use Gnulib's
  4137. @code{fnmatch-gnu} module. @xref{Gnulib}.
  4138. @end defmac
  4139. @anchor{AC_FUNC_FORK}
  4140. @defmac AC_FUNC_FORK
  4141. @acindex{FUNC_FORK}
  4142. @cvindex HAVE_VFORK_H
  4143. @cvindex HAVE_WORKING_FORK
  4144. @cvindex HAVE_WORKING_VFORK
  4145. @cvindex vfork
  4146. @c @fuindex fork
  4147. @prindex @code{fork}
  4148. @c @fuindex vfork
  4149. @prindex @code{vfork}
  4150. @hdrindex{vfork.h}
  4151. @c @caindex func_fork
  4152. @c @caindex func_fork_works
  4153. This macro checks for the @code{fork} and @code{vfork} functions. If a
  4154. working @code{fork} is found, define @code{HAVE_WORKING_FORK}. This macro
  4155. checks whether @code{fork} is just a stub by trying to run it.
  4156. If @file{vfork.h} is found, define @code{HAVE_VFORK_H}. If a working
  4157. @code{vfork} is found, define @code{HAVE_WORKING_VFORK}. Otherwise,
  4158. define @code{vfork} to be @code{fork} for backward compatibility with
  4159. previous versions of @command{autoconf}. This macro checks for several known
  4160. errors in implementations of @code{vfork} and considers the system to not
  4161. have a working @code{vfork} if it detects any of them. It is not considered
  4162. to be an implementation error if a child's invocation of @code{signal}
  4163. modifies the parent's signal handler, since child processes rarely change
  4164. their signal handlers.
  4165. Since this macro defines @code{vfork} only for backward compatibility with
  4166. previous versions of @command{autoconf} you're encouraged to define it
  4167. yourself in new code:
  4168. @example
  4169. @group
  4170. #ifndef HAVE_WORKING_VFORK
  4171. # define vfork fork
  4172. #endif
  4173. @end group
  4174. @end example
  4175. The results of this macro are cached in the @code{ac_cv_func_fork_works}
  4176. and @code{ac_cv_func_vfork_works} variables. In order to override the
  4177. test, you also need to set the @code{ac_cv_func_fork} and
  4178. @code{ac_cv_func_vfork} variables.
  4179. @end defmac
  4180. @defmac AC_FUNC_FSEEKO
  4181. @acindex{FUNC_FSEEKO}
  4182. @cvindex _LARGEFILE_SOURCE
  4183. @cvindex HAVE_FSEEKO
  4184. @c @fuindex fseeko
  4185. @prindex @code{fseeko}
  4186. @c @fuindex ftello
  4187. @prindex @code{ftello}
  4188. @c @caindex sys_largefile_source
  4189. If the @code{fseeko} function is available, define @code{HAVE_FSEEKO}.
  4190. Define @code{_LARGEFILE_SOURCE} if necessary to make the prototype
  4191. visible on some systems (e.g., glibc 2.2). Otherwise linkage problems
  4192. may occur when compiling with @code{AC_SYS_LARGEFILE} on
  4193. largefile-sensitive systems where @code{off_t} does not default to a
  4194. 64bit entity. All systems with @code{fseeko} also supply @code{ftello}.
  4195. @end defmac
  4196. @defmac AC_FUNC_GETGROUPS
  4197. @acindex{FUNC_GETGROUPS}
  4198. @cvindex HAVE_GETGROUPS
  4199. @ovindex GETGROUPS_LIBS
  4200. @c @fuindex getgroups
  4201. @prindex @code{getgroups}
  4202. @caindex func_getgroups_works
  4203. If the @code{getgroups} function is available and works (unlike on
  4204. Ultrix 4.3, where @samp{getgroups (0, 0)} always fails), define
  4205. @code{HAVE_GETGROUPS}. Set @code{GETGROUPS_LIBS} to any libraries
  4206. needed to get that function. This macro runs @code{AC_TYPE_GETGROUPS}.
  4207. @end defmac
  4208. @anchor{AC_FUNC_GETLOADAVG}
  4209. @defmac AC_FUNC_GETLOADAVG
  4210. @acindex{FUNC_GETLOADAVG}
  4211. @cvindex SVR4
  4212. @cvindex DGUX
  4213. @cvindex UMAX
  4214. @cvindex UMAX4_3
  4215. @cvindex HAVE_NLIST_H
  4216. @cvindex NLIST_NAME_UNION
  4217. @cvindex GETLOADAVG_PRIVILEGED
  4218. @cvindex NEED_SETGID
  4219. @cvindex C_GETLOADAVG
  4220. @ovindex LIBOBJS
  4221. @ovindex NEED_SETGID
  4222. @ovindex KMEM_GROUP
  4223. @ovindex GETLOADAVG_LIBS
  4224. @c @fuindex getloadavg
  4225. @prindex @code{getloadavg}
  4226. Check how to get the system load averages. To perform its tests
  4227. properly, this macro needs the file @file{getloadavg.c}; therefore, be
  4228. sure to set the @code{AC_LIBOBJ} replacement directory properly (see
  4229. @ref{Generic Functions}, @code{AC_CONFIG_LIBOBJ_DIR}).
  4230. If the system has the @code{getloadavg} function, define
  4231. @code{HAVE_GETLOADAVG}, and set @code{GETLOADAVG_LIBS} to any libraries
  4232. necessary to get that function. Also add @code{GETLOADAVG_LIBS} to
  4233. @code{LIBS}. Otherwise, require an @code{AC_LIBOBJ} replacement for
  4234. @samp{getloadavg} with source code in @file{@var{dir}/getloadavg.c}, and
  4235. possibly define several other C preprocessor macros and output
  4236. variables:
  4237. @enumerate
  4238. @item
  4239. Define @code{C_GETLOADAVG}.
  4240. @item
  4241. Define @code{SVR4}, @code{DGUX}, @code{UMAX}, or @code{UMAX4_3} if on
  4242. those systems.
  4243. @item
  4244. @hdrindex{nlist.h}
  4245. If @file{nlist.h} is found, define @code{HAVE_NLIST_H}.
  4246. @item
  4247. If @samp{struct nlist} has an @samp{n_un.n_name} member, define
  4248. @code{HAVE_STRUCT_NLIST_N_UN_N_NAME}. The obsolete symbol
  4249. @code{NLIST_NAME_UNION} is still defined, but do not depend upon it.
  4250. @item
  4251. Programs may need to be installed set-group-ID (or set-user-ID) for
  4252. @code{getloadavg} to work. In this case, define
  4253. @code{GETLOADAVG_PRIVILEGED}, set the output variable @code{NEED_SETGID}
  4254. to @samp{true} (and otherwise to @samp{false}), and set
  4255. @code{KMEM_GROUP} to the name of the group that should own the installed
  4256. program.
  4257. @end enumerate
  4258. The @code{AC_FUNC_GETLOADAVG} macro is obsolescent. New programs should
  4259. use Gnulib's @code{getloadavg} module. @xref{Gnulib}.
  4260. @end defmac
  4261. @anchor{AC_FUNC_GETMNTENT}
  4262. @defmac AC_FUNC_GETMNTENT
  4263. @acindex{FUNC_GETMNTENT}
  4264. @cvindex HAVE_GETMNTENT
  4265. @c @fuindex getmntent
  4266. @prindex @code{getmntent}
  4267. @caindex search_getmntent
  4268. Check for @code{getmntent} in the standard C library, and then in the
  4269. @file{sun}, @file{seq}, and @file{gen} libraries, for UNICOS,
  4270. IRIX 4, PTX, and UnixWare, respectively. Then, if
  4271. @code{getmntent} is available, define @code{HAVE_GETMNTENT} and set
  4272. @code{ac_cv_func_getmntent} to @code{yes}. Otherwise set
  4273. @code{ac_cv_func_getmntent} to @code{no}.
  4274. The result of this macro can be overridden by setting the cache variable
  4275. @code{ac_cv_search_getmntent}.
  4276. @end defmac
  4277. @defmac AC_FUNC_GETPGRP
  4278. @acindex{FUNC_GETPGRP}
  4279. @cvindex GETPGRP_VOID
  4280. @c @fuindex getpgid
  4281. @c @fuindex getpgrp
  4282. @prindex @code{getpgid}
  4283. @prindex @code{getpgrp}
  4284. @caindex func_getpgrp_void
  4285. Define @code{GETPGRP_VOID} if it is an error to pass 0 to
  4286. @code{getpgrp}; this is the Posix behavior. On older BSD
  4287. systems, you must pass 0 to @code{getpgrp}, as it takes an argument and
  4288. behaves like Posix's @code{getpgid}.
  4289. @example
  4290. #ifdef GETPGRP_VOID
  4291. pid = getpgrp ();
  4292. #else
  4293. pid = getpgrp (0);
  4294. #endif
  4295. @end example
  4296. This macro does not check whether
  4297. @code{getpgrp} exists at all; if you need to work in that situation,
  4298. first call @code{AC_CHECK_FUNC} for @code{getpgrp}.
  4299. The result of this macro is cached in the @code{ac_cv_func_getpgrp_void}
  4300. variable.
  4301. This macro is obsolescent, as current systems have a @code{getpgrp}
  4302. whose signature conforms to Posix. New programs need not use this macro.
  4303. @end defmac
  4304. @defmac AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
  4305. @acindex{FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK}
  4306. @cvindex LSTAT_FOLLOWS_SLASHED_SYMLINK
  4307. @c @fuindex lstat
  4308. @prindex @code{lstat}
  4309. @caindex func_lstat_dereferences_slashed_symlink
  4310. If @file{link} is a symbolic link, then @code{lstat} should treat
  4311. @file{link/} the same as @file{link/.}. However, many older
  4312. @code{lstat} implementations incorrectly ignore trailing slashes.
  4313. It is safe to assume that if @code{lstat} incorrectly ignores
  4314. trailing slashes, then other symbolic-link-aware functions like
  4315. @code{unlink} also incorrectly ignore trailing slashes.
  4316. If @code{lstat} behaves properly, define
  4317. @code{LSTAT_FOLLOWS_SLASHED_SYMLINK}, otherwise require an
  4318. @code{AC_LIBOBJ} replacement of @code{lstat}.
  4319. The result of this macro is cached in the
  4320. @code{ac_cv_func_lstat_dereferences_slashed_symlink} variable.
  4321. The @code{AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK} macro is obsolescent.
  4322. New programs should use Gnulib's @code{lstat} module. @xref{Gnulib}.
  4323. @end defmac
  4324. @defmac AC_FUNC_MALLOC
  4325. @acindex{FUNC_MALLOC}
  4326. @cvindex HAVE_MALLOC
  4327. @cvindex malloc
  4328. @c @fuindex malloc
  4329. @prindex @code{malloc}
  4330. @caindex func_malloc_0_nonnull
  4331. If the @code{malloc} function is compatible with the GNU C
  4332. library @code{malloc} (i.e., @samp{malloc (0)} returns a valid
  4333. pointer), define @code{HAVE_MALLOC} to 1. Otherwise define
  4334. @code{HAVE_MALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
  4335. @samp{malloc}, and define @code{malloc} to @code{rpl_malloc} so that the
  4336. native @code{malloc} is not used in the main project.
  4337. Typically, the replacement file @file{malloc.c} should look like (note
  4338. the @samp{#undef malloc}):
  4339. @verbatim
  4340. #include <config.h>
  4341. #undef malloc
  4342. #include <sys/types.h>
  4343. void *malloc ();
  4344. /* Allocate an N-byte block of memory from the heap.
  4345. If N is zero, allocate a 1-byte block. */
  4346. void *
  4347. rpl_malloc (size_t n)
  4348. {
  4349. if (n == 0)
  4350. n = 1;
  4351. return malloc (n);
  4352. }
  4353. @end verbatim
  4354. The result of this macro is cached in the
  4355. @code{ac_cv_func_malloc_0_nonnull} variable.
  4356. @end defmac
  4357. @defmac AC_FUNC_MBRTOWC
  4358. @acindex{FUNC_MBRTOWC}
  4359. @cvindex HAVE_MBRTOWC
  4360. @c @fuindex mbrtowc
  4361. @prindex @code{mbrtowc}
  4362. @caindex func_mbrtowc
  4363. Define @code{HAVE_MBRTOWC} to 1 if the function @code{mbrtowc} and the
  4364. type @code{mbstate_t} are properly declared.
  4365. The result of this macro is cached in the @code{ac_cv_func_mbrtowc}
  4366. variable.
  4367. @end defmac
  4368. @defmac AC_FUNC_MEMCMP
  4369. @acindex{FUNC_MEMCMP}
  4370. @ovindex LIBOBJS
  4371. @c @fuindex memcmp
  4372. @prindex @code{memcmp}
  4373. @caindex func_memcmp_working
  4374. If the @code{memcmp} function is not available, or does not work on
  4375. 8-bit data (like the one on SunOS 4.1.3), or fails when comparing 16
  4376. bytes or more and with at least one buffer not starting on a 4-byte
  4377. boundary (such as the one on NeXT x86 OpenStep), require an
  4378. @code{AC_LIBOBJ} replacement for @samp{memcmp}.
  4379. The result of this macro is cached in the
  4380. @code{ac_cv_func_memcmp_working} variable.
  4381. This macro is obsolescent, as current systems have a working
  4382. @code{memcmp}. New programs need not use this macro.
  4383. @end defmac
  4384. @defmac AC_FUNC_MKTIME
  4385. @acindex{FUNC_MKTIME}
  4386. @ovindex LIBOBJS
  4387. @c @fuindex mktime
  4388. @prindex @code{mktime}
  4389. @caindex func_working_mktime
  4390. If the @code{mktime} function is not available, or does not work
  4391. correctly, require an @code{AC_LIBOBJ} replacement for @samp{mktime}.
  4392. For the purposes of this test, @code{mktime} should conform to the
  4393. Posix standard and should be the inverse of
  4394. @code{localtime}.
  4395. The result of this macro is cached in the
  4396. @code{ac_cv_func_working_mktime} variable.
  4397. The @code{AC_FUNC_MKTIME} macro is obsolescent. New programs should
  4398. use Gnulib's @code{mktime} module. @xref{Gnulib}.
  4399. @end defmac
  4400. @anchor{AC_FUNC_MMAP}
  4401. @defmac AC_FUNC_MMAP
  4402. @acindex{FUNC_MMAP}
  4403. @cvindex HAVE_MMAP
  4404. @c @fuindex mmap
  4405. @prindex @code{mmap}
  4406. @caindex func_mmap_fixed_mapped
  4407. If the @code{mmap} function exists and works correctly, define
  4408. @code{HAVE_MMAP}. This checks only private fixed mapping of already-mapped
  4409. memory.
  4410. The result of this macro is cached in the
  4411. @code{ac_cv_func_mmap_fixed_mapped} variable.
  4412. @end defmac
  4413. @defmac AC_FUNC_OBSTACK
  4414. @acindex{FUNC_OBSTACK}
  4415. @cvindex HAVE_OBSTACK
  4416. @cindex obstack
  4417. @caindex func_obstack
  4418. If the obstacks are found, define @code{HAVE_OBSTACK}, else require an
  4419. @code{AC_LIBOBJ} replacement for @samp{obstack}.
  4420. The result of this macro is cached in the @code{ac_cv_func_obstack}
  4421. variable.
  4422. @end defmac
  4423. @defmac AC_FUNC_REALLOC
  4424. @acindex{FUNC_REALLOC}
  4425. @cvindex HAVE_REALLOC
  4426. @cvindex realloc
  4427. @c @fuindex realloc
  4428. @prindex @code{realloc}
  4429. @caindex func_realloc_0_nonnull
  4430. If the @code{realloc} function is compatible with the GNU C
  4431. library @code{realloc} (i.e., @samp{realloc (NULL, 0)} returns a
  4432. valid pointer), define @code{HAVE_REALLOC} to 1. Otherwise define
  4433. @code{HAVE_REALLOC} to 0, ask for an @code{AC_LIBOBJ} replacement for
  4434. @samp{realloc}, and define @code{realloc} to @code{rpl_realloc} so that
  4435. the native @code{realloc} is not used in the main project. See
  4436. @code{AC_FUNC_MALLOC} for details.
  4437. The result of this macro is cached in the
  4438. @code{ac_cv_func_realloc_0_nonnull} variable.
  4439. @end defmac
  4440. @defmac AC_FUNC_SELECT_ARGTYPES
  4441. @acindex{FUNC_SELECT_ARGTYPES}
  4442. @cvindex SELECT_TYPE_ARG1
  4443. @cvindex SELECT_TYPE_ARG234
  4444. @cvindex SELECT_TYPE_ARG5
  4445. @c @fuindex select
  4446. @prindex @code{select}
  4447. @c @caindex func_select_args
  4448. Determines the correct type to be passed for each of the
  4449. @code{select} function's arguments, and defines those types
  4450. in @code{SELECT_TYPE_ARG1}, @code{SELECT_TYPE_ARG234}, and
  4451. @code{SELECT_TYPE_ARG5} respectively. @code{SELECT_TYPE_ARG1} defaults
  4452. to @samp{int}, @code{SELECT_TYPE_ARG234} defaults to @samp{int *},
  4453. and @code{SELECT_TYPE_ARG5} defaults to @samp{struct timeval *}.
  4454. This macro is obsolescent, as current systems have a @code{select} whose
  4455. signature conforms to Posix. New programs need not use this macro.
  4456. @end defmac
  4457. @defmac AC_FUNC_SETPGRP
  4458. @acindex{FUNC_SETPGRP}
  4459. @cvindex SETPGRP_VOID
  4460. @c @fuindex setpgrp
  4461. @prindex @code{setpgrp}
  4462. @caindex func_setpgrp_void
  4463. If @code{setpgrp} takes no argument (the Posix version), define
  4464. @code{SETPGRP_VOID}. Otherwise, it is the BSD version, which takes
  4465. two process IDs as arguments. This macro does not check whether
  4466. @code{setpgrp} exists at all; if you need to work in that situation,
  4467. first call @code{AC_CHECK_FUNC} for @code{setpgrp}.
  4468. The result of this macro is cached in the @code{ac_cv_func_setpgrp_void}
  4469. variable.
  4470. This macro is obsolescent, as current systems have a @code{setpgrp}
  4471. whose signature conforms to Posix. New programs need not use this macro.
  4472. @end defmac
  4473. @defmac AC_FUNC_STAT
  4474. @defmacx AC_FUNC_LSTAT
  4475. @acindex{FUNC_STAT}
  4476. @acindex{FUNC_LSTAT}
  4477. @cvindex HAVE_STAT_EMPTY_STRING_BUG
  4478. @cvindex HAVE_LSTAT_EMPTY_STRING_BUG
  4479. @c @fuindex stat
  4480. @prindex @code{stat}
  4481. @c @fuindex lstat
  4482. @prindex @code{lstat}
  4483. @caindex func_stat_empty_string_bug
  4484. @caindex func_lstat_empty_string_bug
  4485. Determine whether @code{stat} or @code{lstat} have the bug that it
  4486. succeeds when given the zero-length file name as argument. The @code{stat}
  4487. and @code{lstat} from SunOS 4.1.4 and the Hurd (as of 1998-11-01) do
  4488. this.
  4489. If it does, then define @code{HAVE_STAT_EMPTY_STRING_BUG} (or
  4490. @code{HAVE_LSTAT_EMPTY_STRING_BUG}) and ask for an @code{AC_LIBOBJ}
  4491. replacement of it.
  4492. The results of these macros are cached in the
  4493. @code{ac_cv_func_stat_empty_string_bug} and the
  4494. @code{ac_cv_func_lstat_empty_string_bug} variables, respectively.
  4495. These macros are obsolescent, as no current systems have the bug.
  4496. New programs need not use these macros.
  4497. @end defmac
  4498. @anchor{AC_FUNC_STRCOLL}
  4499. @defmac AC_FUNC_STRCOLL
  4500. @acindex{FUNC_STRCOLL}
  4501. @cvindex HAVE_STRCOLL
  4502. @c @fuindex strcoll
  4503. @prindex @code{strcoll}
  4504. @caindex func_strcoll_works
  4505. If the @code{strcoll} function exists and works correctly, define
  4506. @code{HAVE_STRCOLL}. This does a bit more than
  4507. @samp{AC_CHECK_FUNCS(strcoll)}, because some systems have incorrect
  4508. definitions of @code{strcoll} that should not be used.
  4509. The result of this macro is cached in the @code{ac_cv_func_strcoll_works}
  4510. variable.
  4511. @end defmac
  4512. @defmac AC_FUNC_STRERROR_R
  4513. @acindex{FUNC_STRERROR_R}
  4514. @cvindex HAVE_STRERROR_R
  4515. @cvindex HAVE_DECL_STRERROR_R
  4516. @cvindex STRERROR_R_CHAR_P
  4517. @c @fuindex strerror_r
  4518. @caindex func_strerror_r_char_p
  4519. @prindex @code{strerror_r}
  4520. If @code{strerror_r} is available, define @code{HAVE_STRERROR_R}, and if
  4521. it is declared, define @code{HAVE_DECL_STRERROR_R}. If it returns a
  4522. @code{char *} message, define @code{STRERROR_R_CHAR_P}; otherwise it
  4523. returns an @code{int} error number. The Thread-Safe Functions option of
  4524. Posix requires @code{strerror_r} to return @code{int}, but
  4525. many systems (including, for example, version 2.2.4 of the GNU C
  4526. Library) return a @code{char *} value that is not necessarily equal to
  4527. the buffer argument.
  4528. The result of this macro is cached in the
  4529. @code{ac_cv_func_strerror_r_char_p} variable.
  4530. @end defmac
  4531. @anchor{AC_FUNC_STRFTIME}
  4532. @defmac AC_FUNC_STRFTIME
  4533. @acindex{FUNC_STRFTIME}
  4534. @cvindex HAVE_STRFTIME
  4535. @c @fuindex strftime
  4536. @prindex @code{strftime}
  4537. Check for @code{strftime} in the @file{intl} library, for SCO Unix.
  4538. Then, if @code{strftime} is available, define @code{HAVE_STRFTIME}.
  4539. This macro is obsolescent, as no current systems require the @file{intl}
  4540. library for @code{strftime}. New programs need not use this macro.
  4541. @end defmac
  4542. @defmac AC_FUNC_STRTOD
  4543. @acindex{FUNC_STRTOD}
  4544. @ovindex POW_LIB
  4545. @c @fuindex strtod
  4546. @prindex @code{strtod}
  4547. @caindex func_strtod
  4548. @caindex func_pow
  4549. If the @code{strtod} function does not exist or doesn't work correctly,
  4550. ask for an @code{AC_LIBOBJ} replacement of @samp{strtod}. In this case,
  4551. because @file{strtod.c} is likely to need @samp{pow}, set the output
  4552. variable @code{POW_LIB} to the extra library needed.
  4553. This macro caches its result in the @code{ac_cv_func_strtod} variable
  4554. and depends upon the result in the @code{ac_cv_func_pow} variable.
  4555. The @code{AC_FUNC_STRTOD} macro is obsolescent. New programs should
  4556. use Gnulib's @code{strtod} module. @xref{Gnulib}.
  4557. @end defmac
  4558. @defmac AC_FUNC_STRTOLD
  4559. @acindex{FUNC_STRTOLD}
  4560. @cvindex HAVE_STRTOLD
  4561. @prindex @code{strtold}
  4562. @caindex func_strtold
  4563. If the @code{strtold} function exists and conforms to C99, define
  4564. @code{HAVE_STRTOLD}.
  4565. This macro caches its result in the @code{ac_cv_func_strtold} variable.
  4566. @end defmac
  4567. @defmac AC_FUNC_STRNLEN
  4568. @acindex{FUNC_STRNLEN}
  4569. @cvindex HAVE_STRNLEN
  4570. @c @fuindex strnlen
  4571. @prindex @code{strnlen}
  4572. @caindex func_strnlen_working
  4573. If the @code{strnlen} function is not available, or is buggy (like the one
  4574. from AIX 4.3), require an @code{AC_LIBOBJ} replacement for it.
  4575. This macro caches its result in the @code{ac_cv_func_strnlen_working}
  4576. variable.
  4577. @end defmac
  4578. @anchor{AC_FUNC_UTIME_NULL}
  4579. @defmac AC_FUNC_UTIME_NULL
  4580. @acindex{FUNC_UTIME_NULL}
  4581. @cvindex HAVE_UTIME_NULL
  4582. @c @fuindex utime
  4583. @prindex @code{utime}
  4584. @caindex func_utime_null
  4585. If @samp{utime (@var{file}, NULL)} sets @var{file}'s timestamp to
  4586. the present, define @code{HAVE_UTIME_NULL}.
  4587. This macro caches its result in the @code{ac_cv_func_utime_null}
  4588. variable.
  4589. This macro is obsolescent, as all current systems have a @code{utime}
  4590. that behaves this way. New programs need not use this macro.
  4591. @end defmac
  4592. @anchor{AC_FUNC_VPRINTF}
  4593. @defmac AC_FUNC_VPRINTF
  4594. @acindex{FUNC_VPRINTF}
  4595. @cvindex HAVE_VPRINTF
  4596. @cvindex HAVE_DOPRNT
  4597. @c @fuindex vprintf
  4598. @prindex @code{vprintf}
  4599. @c @fuindex vsprintf
  4600. @prindex @code{vsprintf}
  4601. If @code{vprintf} is found, define @code{HAVE_VPRINTF}. Otherwise, if
  4602. @code{_doprnt} is found, define @code{HAVE_DOPRNT}. (If @code{vprintf}
  4603. is available, you may assume that @code{vfprintf} and @code{vsprintf}
  4604. are also available.)
  4605. This macro is obsolescent, as all current systems have @code{vprintf}.
  4606. New programs need not use this macro.
  4607. @end defmac
  4608. @defmac AC_REPLACE_FNMATCH
  4609. @acindex{REPLACE_FNMATCH}
  4610. @c @fuindex fnmatch
  4611. @prindex @code{fnmatch}
  4612. @hdrindex{fnmatch.h}
  4613. @caindex func_fnmatch_works
  4614. If the @code{fnmatch} function does not conform to Posix (see
  4615. @code{AC_FUNC_FNMATCH}), ask for its @code{AC_LIBOBJ} replacement.
  4616. The files @file{fnmatch.c}, @file{fnmatch_loop.c}, and @file{fnmatch_.h}
  4617. in the @code{AC_LIBOBJ} replacement directory are assumed to contain a
  4618. copy of the source code of GNU @code{fnmatch}. If necessary,
  4619. this source code is compiled as an @code{AC_LIBOBJ} replacement, and the
  4620. @file{fnmatch_.h} file is linked to @file{fnmatch.h} so that it can be
  4621. included in place of the system @code{<fnmatch.h>}.
  4622. This macro caches its result in the @code{ac_cv_func_fnmatch_works}
  4623. variable.
  4624. This macro is obsolescent, as it assumes the use of particular source
  4625. files. New programs should use Gnulib's @code{fnmatch-posix} module,
  4626. which provides this macro along with the source files. @xref{Gnulib}.
  4627. @end defmac
  4628. @node Generic Functions
  4629. @subsection Generic Function Checks
  4630. These macros are used to find functions not covered by the ``particular''
  4631. test macros. If the functions might be in libraries other than the
  4632. default C library, first call @code{AC_CHECK_LIB} for those libraries.
  4633. If you need to check the behavior of a function as well as find out
  4634. whether it is present, you have to write your own test for
  4635. it (@pxref{Writing Tests}).
  4636. @anchor{AC_CHECK_FUNC}
  4637. @defmac AC_CHECK_FUNC (@var{function}, @ovar{action-if-found}, @
  4638. @ovar{action-if-not-found})
  4639. @acindex{CHECK_FUNC}
  4640. @caindex func_@var{function}
  4641. If C function @var{function} is available, run shell commands
  4642. @var{action-if-found}, otherwise @var{action-if-not-found}. If you just
  4643. want to define a symbol if the function is available, consider using
  4644. @code{AC_CHECK_FUNCS} instead. This macro checks for functions with C
  4645. linkage even when @code{AC_LANG(C++)} has been called, since C is more
  4646. standardized than C++. (@pxref{Language Choice}, for more information
  4647. about selecting the language for checks.)
  4648. This macro caches its result in the @code{ac_cv_func_@var{function}}
  4649. variable.
  4650. @end defmac
  4651. @anchor{AC_CHECK_FUNCS}
  4652. @defmac AC_CHECK_FUNCS (@var{function}@dots{}, @ovar{action-if-found}, @
  4653. @ovar{action-if-not-found})
  4654. @acindex{CHECK_FUNCS}
  4655. @cvindex HAVE_@var{function}
  4656. For each @var{function} enumerated in the blank-or-newline-separated argument
  4657. list, define @code{HAVE_@var{function}} (in all capitals) if it is available.
  4658. If @var{action-if-found} is given, it is additional shell code to
  4659. execute when one of the functions is found. You can give it a value of
  4660. @samp{break} to break out of the loop on the first match. If
  4661. @var{action-if-not-found} is given, it is executed when one of the
  4662. functions is not found.
  4663. Results are cached for each @var{function} as in @code{AC_CHECK_FUNC}.
  4664. @end defmac
  4665. @defmac AC_CHECK_FUNCS_ONCE (@var{function}@dots{})
  4666. @acindex{CHECK_FUNCS_ONCE}
  4667. @cvindex HAVE_@var{function}
  4668. For each @var{function} enumerated in the blank-or-newline-separated argument
  4669. list, define @code{HAVE_@var{function}} (in all capitals) if it is available.
  4670. This is a once-only variant of @code{AC_CHECK_FUNCS}. It generates the
  4671. checking code at most once, so that @command{configure} is smaller and
  4672. faster; but the checks cannot be conditionalized and are always done once,
  4673. early during the @command{configure} run.
  4674. @end defmac
  4675. @sp 1
  4676. Autoconf follows a philosophy that was formed over the years by those
  4677. who have struggled for portability: isolate the portability issues in
  4678. specific files, and then program as if you were in a Posix
  4679. environment. Some functions may be missing or unfixable, and your
  4680. package must be ready to replace them.
  4681. Suitable replacements for many such problem functions are available from
  4682. Gnulib (@pxref{Gnulib}).
  4683. @defmac AC_LIBOBJ (@var{function})
  4684. @acindex{LIBOBJ}
  4685. @ovindex LIBOBJS
  4686. Specify that @samp{@var{function}.c} must be included in the executables
  4687. to replace a missing or broken implementation of @var{function}.
  4688. @vrindex ac_objext
  4689. Technically, it adds @samp{@var{function}.$ac_objext} to the output
  4690. variable @code{LIBOBJS} if it is not already in, and calls
  4691. @code{AC_LIBSOURCE} for @samp{@var{function}.c}. You should not
  4692. directly change @code{LIBOBJS}, since this is not traceable.
  4693. @end defmac
  4694. @defmac AC_LIBSOURCE (@var{file})
  4695. @acindex{LIBSOURCE}
  4696. Specify that @var{file} might be needed to compile the project. If you
  4697. need to know what files might be needed by a @file{configure.ac}, you
  4698. should trace @code{AC_LIBSOURCE}. @var{file} must be a literal.
  4699. This macro is called automatically from @code{AC_LIBOBJ}, but you must
  4700. call it explicitly if you pass a shell variable to @code{AC_LIBOBJ}. In
  4701. that case, since shell variables cannot be traced statically, you must
  4702. pass to @code{AC_LIBSOURCE} any possible files that the shell variable
  4703. might cause @code{AC_LIBOBJ} to need. For example, if you want to pass
  4704. a variable @code{$foo_or_bar} to @code{AC_LIBOBJ} that holds either
  4705. @code{"foo"} or @code{"bar"}, you should do:
  4706. @example
  4707. AC_LIBSOURCE([foo.c])
  4708. AC_LIBSOURCE([bar.c])
  4709. AC_LIBOBJ([$foo_or_bar])
  4710. @end example
  4711. @noindent
  4712. There is usually a way to avoid this, however, and you are encouraged to
  4713. simply call @code{AC_LIBOBJ} with literal arguments.
  4714. Note that this macro replaces the obsolete @code{AC_LIBOBJ_DECL}, with
  4715. slightly different semantics: the old macro took the function name,
  4716. e.g., @code{foo}, as its argument rather than the file name.
  4717. @end defmac
  4718. @defmac AC_LIBSOURCES (@var{files})
  4719. @acindex{LIBSOURCES}
  4720. Like @code{AC_LIBSOURCE}, but accepts one or more @var{files} in a
  4721. comma-separated M4 list. Thus, the above example might be rewritten:
  4722. @example
  4723. AC_LIBSOURCES([foo.c, bar.c])
  4724. AC_LIBOBJ([$foo_or_bar])
  4725. @end example
  4726. @end defmac
  4727. @defmac AC_CONFIG_LIBOBJ_DIR (@var{directory})
  4728. @acindex{CONFIG_LIBOBJ_DIR}
  4729. Specify that @code{AC_LIBOBJ} replacement files are to be found in
  4730. @var{directory}, a name relative to the top level of the
  4731. source tree. The replacement directory defaults to @file{.}, the top
  4732. level directory, and the most typical value is @file{lib}, corresponding
  4733. to @samp{AC_CONFIG_LIBOBJ_DIR([lib])}.
  4734. @command{configure} might need to know the replacement directory for the
  4735. following reasons: (i) some checks use the replacement files, (ii) some
  4736. macros bypass broken system headers by installing links to the
  4737. replacement headers (iii) when used in conjunction with Automake,
  4738. within each makefile, @var{directory} is used as a relative path
  4739. from @code{$(top_srcdir)} to each object named in @code{LIBOBJS} and
  4740. @code{LTLIBOBJS}, etc.
  4741. @end defmac
  4742. @sp 1
  4743. It is common to merely check for the existence of a function, and ask
  4744. for its @code{AC_LIBOBJ} replacement if missing. The following macro is
  4745. a convenient shorthand.
  4746. @defmac AC_REPLACE_FUNCS (@var{function}@dots{})
  4747. @acindex{REPLACE_FUNCS}
  4748. @cvindex HAVE_@var{function}
  4749. @ovindex LIBOBJS
  4750. Like @code{AC_CHECK_FUNCS}, but uses @samp{AC_LIBOBJ(@var{function})} as
  4751. @var{action-if-not-found}. You can declare your replacement function by
  4752. enclosing the prototype in @samp{#ifndef HAVE_@var{function}}. If the
  4753. system has the function, it probably declares it in a header file you
  4754. should be including, so you shouldn't redeclare it lest your declaration
  4755. conflict.
  4756. @end defmac
  4757. @node Header Files
  4758. @section Header Files
  4759. @cindex Header, checking
  4760. The following macros check for the presence of certain C header files.
  4761. If there is no macro specifically defined to check for a header file you need,
  4762. and you don't need to check for any special properties of
  4763. it, then you can use one of the general header-file check macros.
  4764. @menu
  4765. * Header Portability:: Collected knowledge on common headers
  4766. * Particular Headers:: Special handling to find certain headers
  4767. * Generic Headers:: How to find other headers
  4768. @end menu
  4769. @node Header Portability
  4770. @subsection Portability of Headers
  4771. @cindex Portability of headers
  4772. @cindex Header portability
  4773. This section documents some collected knowledge about common headers,
  4774. and the problems they cause. By definition, this list always requires
  4775. additions. A much more complete list is maintained by the Gnulib
  4776. project (@pxref{Gnulib}), covering @ref{Header File Substitutes, ,
  4777. Posix Headers, gnulib, GNU gnulib} and @ref{Glibc Header File
  4778. Substitutes, , Glibc Headers, gnulib, GNU gnulib}. Please help us keep
  4779. the gnulib list as complete as possible.
  4780. @table @asis
  4781. @item @file{limits.h}
  4782. C99 says that @file{limits.h} defines @code{LLONG_MIN},
  4783. @code{LLONG_MAX}, and @code{ULLONG_MAX}, but many almost-C99
  4784. environments (e.g., default GCC 4.0.2 + glibc 2.4) do not
  4785. define them.
  4786. @item @file{inttypes.h} vs.@: @file{stdint.h}
  4787. @hdrindex{inttypes.h}
  4788. @hdrindex{stdint.h}
  4789. The C99 standard says that @file{inttypes.h} includes
  4790. @file{stdint.h}, so there's no need to include @file{stdint.h}
  4791. separately in a standard environment. Some implementations have
  4792. @file{inttypes.h} but not @file{stdint.h} (e.g., Solaris 7), but we don't
  4793. know of any implementation that has @file{stdint.h} but not
  4794. @file{inttypes.h}.
  4795. @item @file{linux/irda.h}
  4796. @hdrindex{linux/irda.h}
  4797. It requires @file{linux/types.h} and @file{sys/socket.h}.
  4798. @item @file{linux/random.h}
  4799. @hdrindex{linux/random.h}
  4800. It requires @file{linux/types.h}.
  4801. @item @file{net/if.h}
  4802. @hdrindex{net/if.h}
  4803. On Darwin, this file requires that @file{sys/socket.h} be included
  4804. beforehand. One should run:
  4805. @example
  4806. AC_CHECK_HEADERS([sys/socket.h])
  4807. AC_CHECK_HEADERS([net/if.h], [], [],
  4808. [#include <stdio.h>
  4809. #ifdef STDC_HEADERS
  4810. # include <stdlib.h>
  4811. # include <stddef.h>
  4812. #else
  4813. # ifdef HAVE_STDLIB_H
  4814. # include <stdlib.h>
  4815. # endif
  4816. #endif
  4817. #ifdef HAVE_SYS_SOCKET_H
  4818. # include <sys/socket.h>
  4819. #endif
  4820. ])
  4821. @end example
  4822. @item @file{netinet/if_ether.h}
  4823. @hdrindex{netinet/if_ether.h}
  4824. On Darwin, this file requires that @file{stdio.h} and
  4825. @file{sys/socket.h} be included beforehand. One should run:
  4826. @example
  4827. AC_CHECK_HEADERS([sys/socket.h])
  4828. AC_CHECK_HEADERS([netinet/if_ether.h], [], [],
  4829. [#include <stdio.h>
  4830. #ifdef STDC_HEADERS
  4831. # include <stdlib.h>
  4832. # include <stddef.h>
  4833. #else
  4834. # ifdef HAVE_STDLIB_H
  4835. # include <stdlib.h>
  4836. # endif
  4837. #endif
  4838. #ifdef HAVE_SYS_SOCKET_H
  4839. # include <sys/socket.h>
  4840. #endif
  4841. ])
  4842. @end example
  4843. @item @file{stdint.h}
  4844. See above, item @file{inttypes.h} vs.@: @file{stdint.h}.
  4845. @item @file{stdlib.h}
  4846. @hdrindex{stdlib.h}
  4847. On many systems (e.g., Darwin), @file{stdio.h} is a prerequisite.
  4848. @item @file{sys/mount.h}
  4849. @hdrindex{sys/mount.h}
  4850. On FreeBSD 4.8 on ia32 and using gcc version 2.95.4,
  4851. @file{sys/params.h} is a prerequisite.
  4852. @item @file{sys/ptem.h}
  4853. @hdrindex{sys/ptem.h}
  4854. On Solaris 8, @file{sys/stream.h} is a prerequisite.
  4855. @item @file{sys/socket.h}
  4856. @hdrindex{sys/socket.h}
  4857. On Darwin, @file{stdlib.h} is a prerequisite.
  4858. @item @file{sys/ucred.h}
  4859. @hdrindex{sys/ucred.h}
  4860. On Tru64 5.1, @file{sys/types.h} is a prerequisite.
  4861. @item @file{X11/extensions/scrnsaver.h}
  4862. @hdrindex{X11/extensions/scrnsaver.h}
  4863. Using XFree86, this header requires @file{X11/Xlib.h}, which is probably
  4864. so required that you might not even consider looking for it.
  4865. @example
  4866. AC_CHECK_HEADERS([X11/extensions/scrnsaver.h], [], [],
  4867. [[#include <X11/Xlib.h>
  4868. ]])
  4869. @end example
  4870. @end table
  4871. @node Particular Headers
  4872. @subsection Particular Header Checks
  4873. These macros check for particular system header files---whether they
  4874. exist, and in some cases whether they declare certain symbols.
  4875. @defmac AC_CHECK_HEADER_STDBOOL
  4876. @acindex{CHECK_HEADER_STDBOOL}
  4877. @cvindex HAVE__BOOL
  4878. @hdrindex{stdbool.h}
  4879. @caindex header_stdbool_h
  4880. Check whether @file{stdbool.h} exists and conforms to C99, and cache the
  4881. result in the @code{ac_cv_header_stdbool_h} variable. If the type
  4882. @code{_Bool} is defined, define @code{HAVE__BOOL} to 1.
  4883. This macro is intended for use by Gnulib (@pxref{Gnulib}) and other
  4884. packages that supply a substitute @file{stdbool.h} on platforms lacking
  4885. a conforming one. The @code{AC_HEADER_STDBOOL} macro is better for code
  4886. that explicitly checks for @file{stdbool.h}.
  4887. @end defmac
  4888. @defmac AC_HEADER_ASSERT
  4889. @acindex{HEADER_ASSERT}
  4890. @cvindex NDEBUG
  4891. @hdrindex{assert.h}
  4892. Check whether to enable assertions in the style of @file{assert.h}.
  4893. Assertions are enabled by default, but the user can override this by
  4894. invoking @command{configure} with the @option{--disable-assert} option.
  4895. @end defmac
  4896. @anchor{AC_HEADER_DIRENT}
  4897. @defmac AC_HEADER_DIRENT
  4898. @acindex{HEADER_DIRENT}
  4899. @cvindex HAVE_DIRENT_H
  4900. @cvindex HAVE_NDIR_H
  4901. @cvindex HAVE_SYS_DIR_H
  4902. @cvindex HAVE_SYS_NDIR_H
  4903. @hdrindex{dirent.h}
  4904. @hdrindex{sys/ndir.h}
  4905. @hdrindex{sys/dir.h}
  4906. @hdrindex{ndir.h}
  4907. Check for the following header files. For the first one that is
  4908. found and defines @samp{DIR}, define the listed C preprocessor macro:
  4909. @multitable {@file{sys/ndir.h}} {@code{HAVE_SYS_NDIR_H}}
  4910. @item @file{dirent.h} @tab @code{HAVE_DIRENT_H}
  4911. @item @file{sys/ndir.h} @tab @code{HAVE_SYS_NDIR_H}
  4912. @item @file{sys/dir.h} @tab @code{HAVE_SYS_DIR_H}
  4913. @item @file{ndir.h} @tab @code{HAVE_NDIR_H}
  4914. @end multitable
  4915. The directory-library declarations in your source code should look
  4916. something like the following:
  4917. @example
  4918. @group
  4919. #include <sys/types.h>
  4920. #ifdef HAVE_DIRENT_H
  4921. # include <dirent.h>
  4922. # define NAMLEN(dirent) strlen ((dirent)->d_name)
  4923. #else
  4924. # define dirent direct
  4925. # define NAMLEN(dirent) ((dirent)->d_namlen)
  4926. # ifdef HAVE_SYS_NDIR_H
  4927. # include <sys/ndir.h>
  4928. # endif
  4929. # ifdef HAVE_SYS_DIR_H
  4930. # include <sys/dir.h>
  4931. # endif
  4932. # ifdef HAVE_NDIR_H
  4933. # include <ndir.h>
  4934. # endif
  4935. #endif
  4936. @end group
  4937. @end example
  4938. Using the above declarations, the program would declare variables to be
  4939. of type @code{struct dirent}, not @code{struct direct}, and would access
  4940. the length of a directory entry name by passing a pointer to a
  4941. @code{struct dirent} to the @code{NAMLEN} macro.
  4942. This macro also checks for the SCO Xenix @file{dir} and @file{x} libraries.
  4943. This macro is obsolescent, as all current systems with directory
  4944. libraries have @code{<dirent.h>}. New programs need not use this macro.
  4945. Also see @code{AC_STRUCT_DIRENT_D_INO} and
  4946. @code{AC_STRUCT_DIRENT_D_TYPE} (@pxref{Particular Structures}).
  4947. @end defmac
  4948. @anchor{AC_HEADER_MAJOR}
  4949. @defmac AC_HEADER_MAJOR
  4950. @acindex{HEADER_MAJOR}
  4951. @cvindex MAJOR_IN_MKDEV
  4952. @cvindex MAJOR_IN_SYSMACROS
  4953. @hdrindex{sys/mkdev.h}
  4954. @hdrindex{sys/sysmacros.h}
  4955. If @file{sys/types.h} does not define @code{major}, @code{minor}, and
  4956. @code{makedev}, but @file{sys/mkdev.h} does, define
  4957. @code{MAJOR_IN_MKDEV}; otherwise, if @file{sys/sysmacros.h} does, define
  4958. @code{MAJOR_IN_SYSMACROS}.
  4959. @end defmac
  4960. @defmac AC_HEADER_RESOLV
  4961. @acindex{HEADER_RESOLV}
  4962. @cvindex HAVE_RESOLV_H
  4963. @hdrindex{resolv.h}
  4964. Checks for header @file{resolv.h}, checking for prerequisites first.
  4965. To properly use @file{resolv.h}, your code should contain something like
  4966. the following:
  4967. @verbatim
  4968. #ifdef HAVE_SYS_TYPES_H
  4969. # include <sys/types.h>
  4970. #endif
  4971. #ifdef HAVE_NETINET_IN_H
  4972. # include <netinet/in.h> /* inet_ functions / structs */
  4973. #endif
  4974. #ifdef HAVE_ARPA_NAMESER_H
  4975. # include <arpa/nameser.h> /* DNS HEADER struct */
  4976. #endif
  4977. #ifdef HAVE_NETDB_H
  4978. # include <netdb.h>
  4979. #endif
  4980. #include <resolv.h>
  4981. @end verbatim
  4982. @end defmac
  4983. @anchor{AC_HEADER_STAT}
  4984. @defmac AC_HEADER_STAT
  4985. @acindex{HEADER_STAT}
  4986. @cvindex STAT_MACROS_BROKEN
  4987. @hdrindex{sys/stat.h}
  4988. If the macros @code{S_ISDIR}, @code{S_ISREG}, etc.@: defined in
  4989. @file{sys/stat.h} do not work properly (returning false positives),
  4990. define @code{STAT_MACROS_BROKEN}. This is the case on Tektronix UTekV,
  4991. Amdahl UTS and Motorola System V/88.
  4992. This macro is obsolescent, as no current systems have the bug.
  4993. New programs need not use this macro.
  4994. @end defmac
  4995. @defmac AC_HEADER_STDBOOL
  4996. @acindex{HEADER_STDBOOL}
  4997. @cvindex HAVE_STDBOOL_H
  4998. @cvindex HAVE__BOOL
  4999. @hdrindex{stdbool.h}
  5000. @caindex header_stdbool_h
  5001. If @file{stdbool.h} exists and conforms to C99, define
  5002. @code{HAVE_STDBOOL_H} to 1; if the type @code{_Bool} is defined, define
  5003. @code{HAVE__BOOL} to 1. To fulfill the C99 requirements, your
  5004. program could contain the following code:
  5005. @example
  5006. @group
  5007. #ifdef HAVE_STDBOOL_H
  5008. # include <stdbool.h>
  5009. #else
  5010. # ifndef HAVE__BOOL
  5011. # ifdef __cplusplus
  5012. typedef bool _Bool;
  5013. # else
  5014. # define _Bool signed char
  5015. # endif
  5016. # endif
  5017. # define bool _Bool
  5018. # define false 0
  5019. # define true 1
  5020. # define __bool_true_false_are_defined 1
  5021. #endif
  5022. @end group
  5023. @end example
  5024. Alternatively you can use the @samp{stdbool} package of Gnulib
  5025. (@pxref{Gnulib}). It simplifies your code so that it can say just
  5026. @code{#include <stdbool.h>}, and it adds support for less-common
  5027. platforms.
  5028. This macro caches its result in the @code{ac_cv_header_stdbool_h}
  5029. variable.
  5030. This macro differs from @code{AC_CHECK_HEADER_STDBOOL} only in that it
  5031. defines @code{HAVE_STDBOOL_H} whereas @code{AC_CHECK_HEADER_STDBOOL}
  5032. does not.
  5033. @end defmac
  5034. @anchor{AC_HEADER_STDC}
  5035. @defmac AC_HEADER_STDC
  5036. @acindex{HEADER_STDC}
  5037. @cvindex STDC_HEADERS
  5038. @hdrindex{stdlib.h}
  5039. @hdrindex{stdarg.h}
  5040. @hdrindex{string.h}
  5041. @hdrindex{float.h}
  5042. @hdrindex{ctype.h}
  5043. @caindex header_stdc
  5044. Define @code{STDC_HEADERS} if the system has C header files
  5045. conforming to ANSI C89 (ISO C90).
  5046. Specifically, this macro checks for @file{stdlib.h}, @file{stdarg.h},
  5047. @file{string.h}, and @file{float.h}; if the system has those, it
  5048. probably has the rest of the C89 header files. This macro also
  5049. checks whether @file{string.h} declares @code{memchr} (and thus
  5050. presumably the other @code{mem} functions), whether @file{stdlib.h}
  5051. declare @code{free} (and thus presumably @code{malloc} and other related
  5052. functions), and whether the @file{ctype.h} macros work on characters
  5053. with the high bit set, as the C standard requires.
  5054. If you use this macro, your code can refer to @code{STDC_HEADERS} to
  5055. determine whether the system has conforming header files (and probably C
  5056. library functions).
  5057. This macro caches its result in the @code{ac_cv_header_stdc} variable.
  5058. This macro is obsolescent, as current systems have conforming header
  5059. files. New programs need not use this macro.
  5060. @hdrindex{string.h}
  5061. @hdrindex{strings.h}
  5062. Nowadays @file{string.h} is part of the C standard and declares functions like
  5063. @code{strcpy}, and @file{strings.h} is standardized by Posix and declares
  5064. BSD functions like @code{bcopy}; but
  5065. historically, string functions were a major sticking point in this area.
  5066. If you still want to worry about portability to ancient systems without
  5067. standard headers, there is so much variation
  5068. that it is probably easier to declare the functions you use than to
  5069. figure out exactly what the system header files declare. Some ancient systems
  5070. contained a mix of functions from the C standard and from BSD;
  5071. some were mostly standard but lacked @samp{memmove}; some defined the
  5072. BSD functions as macros in @file{string.h} or
  5073. @file{strings.h}; some had only the BSD functions but
  5074. @file{string.h}; some declared the memory functions in @file{memory.h},
  5075. some in @file{string.h}; etc. It is probably sufficient to check for
  5076. one string function and one memory function; if the library had the
  5077. standard versions of those then it probably had most of the others.
  5078. If you put the following in @file{configure.ac}:
  5079. @example
  5080. # This example is obsolescent.
  5081. # Nowadays you can omit these macro calls.
  5082. AC_HEADER_STDC
  5083. AC_CHECK_FUNCS([strchr memcpy])
  5084. @end example
  5085. @noindent
  5086. then, in your code, you can use declarations like this:
  5087. @example
  5088. @group
  5089. /* This example is obsolescent.
  5090. Nowadays you can just #include <string.h>. */
  5091. #ifdef STDC_HEADERS
  5092. # include <string.h>
  5093. #else
  5094. # ifndef HAVE_STRCHR
  5095. # define strchr index
  5096. # define strrchr rindex
  5097. # endif
  5098. char *strchr (), *strrchr ();
  5099. # ifndef HAVE_MEMCPY
  5100. # define memcpy(d, s, n) bcopy ((s), (d), (n))
  5101. # define memmove(d, s, n) bcopy ((s), (d), (n))
  5102. # endif
  5103. #endif
  5104. @end group
  5105. @end example
  5106. @noindent
  5107. If you use a function like @code{memchr}, @code{memset}, @code{strtok},
  5108. or @code{strspn}, which have no BSD equivalent, then macros don't
  5109. suffice to port to ancient hosts; you must provide an implementation of
  5110. each function. An easy
  5111. way to incorporate your implementations only when needed (since the ones
  5112. in system C libraries may be hand optimized) is to, taking @code{memchr}
  5113. for example, put it in @file{memchr.c} and use
  5114. @samp{AC_REPLACE_FUNCS([memchr])}.
  5115. @end defmac
  5116. @defmac AC_HEADER_SYS_WAIT
  5117. @acindex{HEADER_SYS_WAIT}
  5118. @cvindex HAVE_SYS_WAIT_H
  5119. @hdrindex{sys/wait.h}
  5120. @caindex header_sys_wait_h
  5121. If @file{sys/wait.h} exists and is compatible with Posix, define
  5122. @code{HAVE_SYS_WAIT_H}. Incompatibility can occur if @file{sys/wait.h}
  5123. does not exist, or if it uses the old BSD @code{union wait} instead
  5124. of @code{int} to store a status value. If @file{sys/wait.h} is not
  5125. Posix compatible, then instead of including it, define the
  5126. Posix macros with their usual interpretations. Here is an
  5127. example:
  5128. @example
  5129. @group
  5130. #include <sys/types.h>
  5131. #ifdef HAVE_SYS_WAIT_H
  5132. # include <sys/wait.h>
  5133. #endif
  5134. #ifndef WEXITSTATUS
  5135. # define WEXITSTATUS(stat_val) ((unsigned int) (stat_val) >> 8)
  5136. #endif
  5137. #ifndef WIFEXITED
  5138. # define WIFEXITED(stat_val) (((stat_val) & 255) == 0)
  5139. #endif
  5140. @end group
  5141. @end example
  5142. @noindent
  5143. This macro caches its result in the @code{ac_cv_header_sys_wait_h}
  5144. variable.
  5145. This macro is obsolescent, as current systems are compatible with Posix.
  5146. New programs need not use this macro.
  5147. @end defmac
  5148. @cvindex _POSIX_VERSION
  5149. @hdrindex{unistd.h}
  5150. @code{_POSIX_VERSION} is defined when @file{unistd.h} is included on
  5151. Posix systems. If there is no @file{unistd.h}, it is definitely
  5152. not a Posix system. However, some non-Posix systems do
  5153. have @file{unistd.h}.
  5154. The way to check whether the system supports Posix is:
  5155. @example
  5156. @group
  5157. #ifdef HAVE_UNISTD_H
  5158. # include <sys/types.h>
  5159. # include <unistd.h>
  5160. #endif
  5161. #ifdef _POSIX_VERSION
  5162. /* Code for Posix systems. */
  5163. #endif
  5164. @end group
  5165. @end example
  5166. @anchor{AC_HEADER_TIME}
  5167. @defmac AC_HEADER_TIME
  5168. @acindex{HEADER_TIME}
  5169. @cvindex TIME_WITH_SYS_TIME
  5170. @hdrindex{time.h}
  5171. @hdrindex{sys/time.h}
  5172. @caindex header_time
  5173. If a program may include both @file{time.h} and @file{sys/time.h},
  5174. define @code{TIME_WITH_SYS_TIME}. On some ancient systems,
  5175. @file{sys/time.h} included @file{time.h}, but @file{time.h} was not
  5176. protected against multiple inclusion, so programs could not explicitly
  5177. include both files. This macro is useful in programs that use, for
  5178. example, @code{struct timeval} as well as
  5179. @code{struct tm}. It is best used in conjunction with
  5180. @code{HAVE_SYS_TIME_H}, which can be checked for using
  5181. @code{AC_CHECK_HEADERS([sys/time.h])}.
  5182. @example
  5183. @group
  5184. #ifdef TIME_WITH_SYS_TIME
  5185. # include <sys/time.h>
  5186. # include <time.h>
  5187. #else
  5188. # ifdef HAVE_SYS_TIME_H
  5189. # include <sys/time.h>
  5190. # else
  5191. # include <time.h>
  5192. # endif
  5193. #endif
  5194. @end group
  5195. @end example
  5196. @noindent
  5197. This macro caches its result in the @code{ac_cv_header_time} variable.
  5198. This macro is obsolescent, as current systems can include both files
  5199. when they exist. New programs need not use this macro.
  5200. @end defmac
  5201. @defmac AC_HEADER_TIOCGWINSZ
  5202. @acindex{HEADER_TIOCGWINSZ}
  5203. @cvindex GWINSZ_IN_SYS_IOCTL
  5204. @hdrindex{sys/ioctl.h}
  5205. @hdrindex{termios.h}
  5206. @c FIXME: I need clarifications from Jim.
  5207. If the use of @code{TIOCGWINSZ} requires @file{<sys/ioctl.h>}, then
  5208. define @code{GWINSZ_IN_SYS_IOCTL}. Otherwise @code{TIOCGWINSZ} can be
  5209. found in @file{<termios.h>}.
  5210. Use:
  5211. @example
  5212. @group
  5213. #ifdef HAVE_TERMIOS_H
  5214. # include <termios.h>
  5215. #endif
  5216. #ifdef GWINSZ_IN_SYS_IOCTL
  5217. # include <sys/ioctl.h>
  5218. #endif
  5219. @end group
  5220. @end example
  5221. @end defmac
  5222. @node Generic Headers
  5223. @subsection Generic Header Checks
  5224. These macros are used to find system header files not covered by the
  5225. ``particular'' test macros. If you need to check the contents of a header
  5226. as well as find out whether it is present, you have to write your own
  5227. test for it (@pxref{Writing Tests}).
  5228. @anchor{AC_CHECK_HEADER}
  5229. @defmac AC_CHECK_HEADER (@var{header-file}, @ovar{action-if-found}, @
  5230. @ovar{action-if-not-found}, @ovar{includes})
  5231. @acindex{CHECK_HEADER}
  5232. @caindex header_@var{header-file}
  5233. If the system header file @var{header-file} is compilable, execute shell
  5234. commands @var{action-if-found}, otherwise execute
  5235. @var{action-if-not-found}. If you just want to define a symbol if the
  5236. header file is available, consider using @code{AC_CHECK_HEADERS}
  5237. instead.
  5238. @var{includes} is decoded to determine the appropriate include
  5239. directives. If omitted or empty, @file{configure} will check for both header
  5240. existence (with the preprocessor) and usability (with the compiler),
  5241. using @code{AC_INCLUDES_DEFAULT} for the compile test. If
  5242. there is a discrepancy between the results, a warning is issued to the
  5243. user, and the compiler results are favored (@pxref{Present But
  5244. Cannot Be Compiled}). In general, favoring the compiler results means
  5245. that a header will be treated as not found even though the file exists,
  5246. because you did not provide enough prerequisites.
  5247. Providing a non-empty @var{includes} argument allows the code to provide
  5248. any prerequisites prior to including the header under test; it is common
  5249. to use the argument @code{AC_INCLUDES_DEFAULT} (@pxref{Default
  5250. Includes}). With an explicit fourth argument, no preprocessor test is
  5251. needed. As a special case, an @var{includes} of exactly @samp{-}
  5252. triggers the older preprocessor check, which merely determines existence
  5253. of the file in the preprocessor search path; this should only be used as
  5254. a last resort (it is safer to determine the actual prerequisites and
  5255. perform a compiler check, or else use @code{AC_PREPROC_IFELSE} to make
  5256. it obvious that only a preprocessor check is desired).
  5257. This macro caches its result in the @code{ac_cv_header_@var{header-file}}
  5258. variable, with characters not suitable for a variable name mapped to
  5259. underscores.
  5260. @end defmac
  5261. @anchor{AC_CHECK_HEADERS}
  5262. @defmac AC_CHECK_HEADERS (@var{header-file}@dots{}, @
  5263. @ovar{action-if-found}, @ovar{action-if-not-found}, @
  5264. @ovar{includes})
  5265. @acindex{CHECK_HEADERS}
  5266. @cvindex HAVE_@var{header}
  5267. @caindex header_@var{header-file}
  5268. For each given system header file @var{header-file} in the
  5269. blank-separated argument list that exists, define
  5270. @code{HAVE_@var{header-file}} (in all capitals). If @var{action-if-found}
  5271. is given, it is additional shell code to execute when one of the header
  5272. files is found. You can give it a value of @samp{break} to break out of
  5273. the loop on the first match. If @var{action-if-not-found} is given, it
  5274. is executed when one of the header files is not found.
  5275. @var{includes} is interpreted as in @code{AC_CHECK_HEADER}, in order to
  5276. choose the set of preprocessor directives supplied before the header
  5277. under test.
  5278. This macro caches its result in the @code{ac_cv_header_@var{header-file}}
  5279. variable, with characters not suitable for a variable name mapped to
  5280. underscores.
  5281. @end defmac
  5282. Previous versions of Autoconf merely checked whether the header was
  5283. accepted by the preprocessor. This was changed because the old test was
  5284. inappropriate for typical uses. Headers are typically used to compile,
  5285. not merely to preprocess, and the old behavior sometimes accepted
  5286. headers that clashed at compile-time (@pxref{Present But Cannot Be
  5287. Compiled}). If you need to check whether a header is preprocessable,
  5288. you can use @code{AC_PREPROC_IFELSE} (@pxref{Running the Preprocessor}).
  5289. Actually requiring a header to compile improves the robustness of the
  5290. test, but it also requires
  5291. that you make sure that headers that must be included before the
  5292. @var{header-file} be part of the @var{includes}, (@pxref{Default
  5293. Includes}). If looking for @file{bar.h}, which requires that
  5294. @file{foo.h} be included before if it exists, we suggest the following
  5295. scheme:
  5296. @verbatim
  5297. AC_CHECK_HEADERS([foo.h])
  5298. AC_CHECK_HEADERS([bar.h], [], [],
  5299. [#ifdef HAVE_FOO_H
  5300. # include <foo.h>
  5301. #endif
  5302. ])
  5303. @end verbatim
  5304. The following variant generates smaller, faster @command{configure}
  5305. files if you do not need the full power of @code{AC_CHECK_HEADERS}.
  5306. @defmac AC_CHECK_HEADERS_ONCE (@var{header-file}@dots{})
  5307. @acindex{CHECK_HEADERS_ONCE}
  5308. @cvindex HAVE_@var{header}
  5309. For each given system header file @var{header-file} in the
  5310. blank-separated argument list that exists, define
  5311. @code{HAVE_@var{header-file}} (in all capitals).
  5312. This is a once-only variant of @code{AC_CHECK_HEADERS}. It generates the
  5313. checking code at most once, so that @command{configure} is smaller and
  5314. faster; but the checks cannot be conditionalized and are always done once,
  5315. early during the @command{configure} run. Thus, this macro is only safe
  5316. for checking headers that do not have prerequisites beyond what
  5317. @code{AC_INCLUDES_DEFAULT} provides.
  5318. @end defmac
  5319. @node Declarations
  5320. @section Declarations
  5321. @cindex Declaration, checking
  5322. The following macros check for the declaration of variables and
  5323. functions. If there is no macro specifically defined to check for a
  5324. symbol you need, then you can use the general macros (@pxref{Generic
  5325. Declarations}) or, for more complex tests, you may use
  5326. @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
  5327. @menu
  5328. * Particular Declarations:: Macros to check for certain declarations
  5329. * Generic Declarations:: How to find other declarations
  5330. @end menu
  5331. @node Particular Declarations
  5332. @subsection Particular Declaration Checks
  5333. There are no specific macros for declarations.
  5334. @node Generic Declarations
  5335. @subsection Generic Declaration Checks
  5336. These macros are used to find declarations not covered by the ``particular''
  5337. test macros.
  5338. @defmac AC_CHECK_DECL (@var{symbol}, @ovar{action-if-found}, @
  5339. @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})
  5340. @acindex{CHECK_DECL}
  5341. @caindex have_decl_@var{symbol}
  5342. If @var{symbol} (a function, variable, or constant) is not declared in
  5343. @var{includes} and a declaration is needed, run the shell commands
  5344. @var{action-if-not-found}, otherwise @var{action-if-found}.
  5345. @var{includes} is a series of include directives, defaulting to
  5346. @code{AC_INCLUDES_DEFAULT} (@pxref{Default Includes}), which are used
  5347. prior to the declaration under test.
  5348. This macro actually tests whether @var{symbol} is defined as a macro or
  5349. can be used as an r-value, not whether it is really declared, because it
  5350. is much safer to avoid introducing extra declarations when they are not
  5351. needed. In order to facilitate use of C++ and overloaded function
  5352. declarations, it is possible to specify function argument types in
  5353. parentheses for types which can be zero-initialized:
  5354. @example
  5355. AC_CHECK_DECL([basename(char *)])
  5356. @end example
  5357. This macro caches its result in the @code{ac_cv_have_decl_@var{symbol}}
  5358. variable, with characters not suitable for a variable name mapped to
  5359. underscores.
  5360. @end defmac
  5361. @anchor{AC_CHECK_DECLS}
  5362. @defmac AC_CHECK_DECLS (@var{symbols}, @ovar{action-if-found}, @
  5363. @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})
  5364. @acindex{CHECK_DECLS}
  5365. @cvindex HAVE_DECL_@var{symbol}
  5366. @caindex have_decl_@var{symbol}
  5367. For each of the @var{symbols} (@emph{comma}-separated list with optional
  5368. function argument types for C++ overloads), define
  5369. @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
  5370. @var{symbol} is declared, otherwise to @samp{0}. If
  5371. @var{action-if-not-found} is given, it is additional shell code to
  5372. execute when one of the function declarations is needed, otherwise
  5373. @var{action-if-found} is executed.
  5374. @var{includes} is a series of include directives, defaulting to
  5375. @code{AC_INCLUDES_DEFAULT} (@pxref{Default Includes}), which are used
  5376. prior to the declarations under test.
  5377. This macro uses an M4 list as first argument:
  5378. @example
  5379. AC_CHECK_DECLS([strdup])
  5380. AC_CHECK_DECLS([strlen])
  5381. AC_CHECK_DECLS([malloc, realloc, calloc, free])
  5382. AC_CHECK_DECLS([j0], [], [], [[#include <math.h>]])
  5383. AC_CHECK_DECLS([[basename(char *)], [dirname(char *)]])
  5384. @end example
  5385. Unlike the other @samp{AC_CHECK_*S} macros, when a @var{symbol} is not
  5386. declared, @code{HAVE_DECL_@var{symbol}} is defined to @samp{0} instead
  5387. of leaving @code{HAVE_DECL_@var{symbol}} undeclared. When you are
  5388. @emph{sure} that the check was performed, use
  5389. @code{HAVE_DECL_@var{symbol}} in @code{#if}:
  5390. @example
  5391. #if !HAVE_DECL_SYMBOL
  5392. extern char *symbol;
  5393. #endif
  5394. @end example
  5395. @noindent
  5396. If the test may have not been performed, however, because it is safer
  5397. @emph{not} to declare a symbol than to use a declaration that conflicts
  5398. with the system's one, you should use:
  5399. @example
  5400. #if defined HAVE_DECL_MALLOC && !HAVE_DECL_MALLOC
  5401. void *malloc (size_t *s);
  5402. #endif
  5403. @end example
  5404. @noindent
  5405. You fall into the second category only in extreme situations: either
  5406. your files may be used without being configured, or they are used during
  5407. the configuration. In most cases the traditional approach is enough.
  5408. This macro caches its results in @code{ac_cv_have_decl_@var{symbol}}
  5409. variables, with characters not suitable for a variable name mapped to
  5410. underscores.
  5411. @end defmac
  5412. @defmac AC_CHECK_DECLS_ONCE (@var{symbols})
  5413. @acindex{CHECK_DECLS_ONCE}
  5414. @cvindex HAVE_DECL_@var{symbol}
  5415. For each of the @var{symbols} (@emph{comma}-separated list), define
  5416. @code{HAVE_DECL_@var{symbol}} (in all capitals) to @samp{1} if
  5417. @var{symbol} is declared in the default include files, otherwise to
  5418. @samp{0}. This is a once-only variant of @code{AC_CHECK_DECLS}. It
  5419. generates the checking code at most once, so that @command{configure} is
  5420. smaller and faster; but the checks cannot be conditionalized and are
  5421. always done once, early during the @command{configure} run.
  5422. @end defmac
  5423. @node Structures
  5424. @section Structures
  5425. @cindex Structure, checking
  5426. The following macros check for the presence of certain members in C
  5427. structures. If there is no macro specifically defined to check for a
  5428. member you need, then you can use the general structure-member macros
  5429. (@pxref{Generic Structures}) or, for more complex tests, you may use
  5430. @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}).
  5431. @menu
  5432. * Particular Structures:: Macros to check for certain structure members
  5433. * Generic Structures:: How to find other structure members
  5434. @end menu
  5435. @node Particular Structures
  5436. @subsection Particular Structure Checks
  5437. The following macros check for certain structures or structure members.
  5438. @defmac AC_STRUCT_DIRENT_D_INO
  5439. @acindex{STRUCT_DIRENT_D_INO}
  5440. @cvindex HAVE_STRUCT_DIRENT_D_INO
  5441. @c @caindex header_dirent_dirent_h
  5442. @c @caindex member_struct_dirent_d_ino
  5443. Perform all the actions of @code{AC_HEADER_DIRENT} (@pxref{Particular
  5444. Headers}). Then, if @code{struct dirent} contains a @code{d_ino}
  5445. member, define @code{HAVE_STRUCT_DIRENT_D_INO}.
  5446. @code{HAVE_STRUCT_DIRENT_D_INO} indicates only the presence of
  5447. @code{d_ino}, not whether its contents are always reliable.
  5448. Traditionally, a zero @code{d_ino} indicated a deleted directory entry,
  5449. though current systems hide this detail from the user and never return
  5450. zero @code{d_ino} values.
  5451. Many current systems report an incorrect @code{d_ino} for a directory
  5452. entry that is a mount point.
  5453. @end defmac
  5454. @defmac AC_STRUCT_DIRENT_D_TYPE
  5455. @acindex{STRUCT_DIRENT_D_TYPE}
  5456. @cvindex HAVE_STRUCT_DIRENT_D_TYPE
  5457. @c @caindex header_dirent_dirent_h
  5458. @c @caindex member_struct_dirent_d_type
  5459. Perform all the actions of @code{AC_HEADER_DIRENT} (@pxref{Particular
  5460. Headers}). Then, if @code{struct dirent} contains a @code{d_type}
  5461. member, define @code{HAVE_STRUCT_DIRENT_D_TYPE}.
  5462. @end defmac
  5463. @anchor{AC_STRUCT_ST_BLOCKS}
  5464. @defmac AC_STRUCT_ST_BLOCKS
  5465. @acindex{STRUCT_ST_BLOCKS}
  5466. @cvindex HAVE_STRUCT_STAT_ST_BLOCKS
  5467. @cvindex HAVE_ST_BLOCKS
  5468. @ovindex LIBOBJS
  5469. @caindex member_struct_stat_st_blocks
  5470. If @code{struct stat} contains an @code{st_blocks} member, define
  5471. @code{HAVE_STRUCT_STAT_ST_BLOCKS}. Otherwise, require an
  5472. @code{AC_LIBOBJ} replacement of @samp{fileblocks}. The former name,
  5473. @code{HAVE_ST_BLOCKS} is to be avoided, as its support will cease in the
  5474. future.
  5475. This macro caches its result in the @code{ac_cv_member_struct_stat_st_blocks}
  5476. variable.
  5477. @end defmac
  5478. @defmac AC_STRUCT_TM
  5479. @acindex{STRUCT_TM}
  5480. @cvindex TM_IN_SYS_TIME
  5481. @hdrindex{time.h}
  5482. @hdrindex{sys/time.h}
  5483. If @file{time.h} does not define @code{struct tm}, define
  5484. @code{TM_IN_SYS_TIME}, which means that including @file{sys/time.h}
  5485. had better define @code{struct tm}.
  5486. This macro is obsolescent, as @file{time.h} defines @code{struct tm} in
  5487. current systems. New programs need not use this macro.
  5488. @end defmac
  5489. @anchor{AC_STRUCT_TIMEZONE}
  5490. @defmac AC_STRUCT_TIMEZONE
  5491. @acindex{STRUCT_TIMEZONE}
  5492. @cvindex HAVE_DECL_TZNAME
  5493. @cvindex HAVE_STRUCT_TM_TM_ZONE
  5494. @cvindex HAVE_TM_ZONE
  5495. @cvindex HAVE_TZNAME
  5496. @c @caindex member_struct_tm_tm_zone
  5497. @c @caindex struct_tm
  5498. Figure out how to get the current timezone. If @code{struct tm} has a
  5499. @code{tm_zone} member, define @code{HAVE_STRUCT_TM_TM_ZONE} (and the
  5500. obsoleted @code{HAVE_TM_ZONE}). Otherwise, if the external array
  5501. @code{tzname} is found, define @code{HAVE_TZNAME}; if it is declared,
  5502. define @code{HAVE_DECL_TZNAME}.
  5503. @end defmac
  5504. @node Generic Structures
  5505. @subsection Generic Structure Checks
  5506. These macros are used to find structure members not covered by the
  5507. ``particular'' test macros.
  5508. @defmac AC_CHECK_MEMBER (@var{aggregate}.@var{member}, @
  5509. @ovar{action-if-found}, @ovar{action-if-not-found}, @
  5510. @dvar{includes, AC_INCLUDES_DEFAULT})
  5511. @acindex{CHECK_MEMBER}
  5512. @caindex member_@var{aggregate}_@var{member}
  5513. Check whether @var{member} is a member of the aggregate @var{aggregate}.
  5514. If no @var{includes} are specified, the default includes are used
  5515. (@pxref{Default Includes}).
  5516. @example
  5517. AC_CHECK_MEMBER([struct passwd.pw_gecos], [],
  5518. [AC_MSG_ERROR([we need `passwd.pw_gecos'])],
  5519. [[#include <pwd.h>]])
  5520. @end example
  5521. You can use this macro for submembers:
  5522. @example
  5523. AC_CHECK_MEMBER(struct top.middle.bot)
  5524. @end example
  5525. This macro caches its result in the
  5526. @code{ac_cv_member_@var{aggregate}_@var{member}} variable, with
  5527. characters not suitable for a variable name mapped to underscores.
  5528. @end defmac
  5529. @anchor{AC_CHECK_MEMBERS}
  5530. @defmac AC_CHECK_MEMBERS (@var{members}, @ovar{action-if-found}, @
  5531. @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})
  5532. @acindex{CHECK_MEMBERS}
  5533. @cvindex HAVE_@var{aggregate}_@var{member}
  5534. Check for the existence of each @samp{@var{aggregate}.@var{member}} of
  5535. @var{members} using the previous macro. When @var{member} belongs to
  5536. @var{aggregate}, define @code{HAVE_@var{aggregate}_@var{member}} (in all
  5537. capitals, with spaces and dots replaced by underscores). If
  5538. @var{action-if-found} is given, it is executed for each of the found
  5539. members. If @var{action-if-not-found} is given, it is executed for each
  5540. of the members that could not be found.
  5541. @var{includes} is a series of include directives, defaulting to
  5542. @code{AC_INCLUDES_DEFAULT} (@pxref{Default Includes}), which are used
  5543. prior to the members under test.
  5544. This macro uses M4 lists:
  5545. @example
  5546. AC_CHECK_MEMBERS([struct stat.st_rdev, struct stat.st_blksize])
  5547. @end example
  5548. @end defmac
  5549. @node Types
  5550. @section Types
  5551. @cindex Types
  5552. @cindex C types
  5553. The following macros check for C types, either builtin or typedefs. If
  5554. there is no macro specifically defined to check for a type you need, and
  5555. you don't need to check for any special properties of it, then you can
  5556. use a general type-check macro.
  5557. @menu
  5558. * Particular Types:: Special handling to find certain types
  5559. * Generic Types:: How to find other types
  5560. @end menu
  5561. @node Particular Types
  5562. @subsection Particular Type Checks
  5563. @hdrindex{sys/types.h}
  5564. @hdrindex{stdlib.h}
  5565. @hdrindex{stdint.h}
  5566. @hdrindex{inttypes.h}
  5567. These macros check for particular C types in @file{sys/types.h},
  5568. @file{stdlib.h}, @file{stdint.h}, @file{inttypes.h} and others, if they
  5569. exist.
  5570. The Gnulib @code{stdint} module is an alternate way to define many of
  5571. these symbols; it is useful if you prefer your code to assume a
  5572. C99-or-better environment. @xref{Gnulib}.
  5573. @anchor{AC_TYPE_GETGROUPS}
  5574. @defmac AC_TYPE_GETGROUPS
  5575. @acindex{TYPE_GETGROUPS}
  5576. @cvindex GETGROUPS_T
  5577. @caindex type_getgroups
  5578. Define @code{GETGROUPS_T} to be whichever of @code{gid_t} or @code{int}
  5579. is the base type of the array argument to @code{getgroups}.
  5580. This macro caches the base type in the @code{ac_cv_type_getgroups}
  5581. variable.
  5582. @end defmac
  5583. @defmac AC_TYPE_INT8_T
  5584. @acindex{TYPE_INT8_T}
  5585. @cvindex HAVE_INT8_T
  5586. @cvindex int8_t
  5587. @caindex c_int8_t
  5588. If @file{stdint.h} or @file{inttypes.h} does not define the type
  5589. @code{int8_t}, define @code{int8_t} to a signed
  5590. integer type that is exactly 8 bits wide and that uses two's complement
  5591. representation, if such a type exists.
  5592. If you are worried about porting to hosts that lack such a type, you can
  5593. use the results of this macro in C89-or-later code as follows:
  5594. @example
  5595. #if HAVE_STDINT_H
  5596. # include <stdint.h>
  5597. #endif
  5598. #if defined INT8_MAX || defined int8_t
  5599. @emph{code using int8_t}
  5600. #else
  5601. @emph{complicated alternative using >8-bit 'signed char'}
  5602. #endif
  5603. @end example
  5604. This macro caches the type in the @code{ac_cv_c_int8_t} variable.
  5605. @end defmac
  5606. @defmac AC_TYPE_INT16_T
  5607. @acindex{TYPE_INT16_T}
  5608. @cvindex HAVE_INT16_T
  5609. @cvindex int16_t
  5610. @caindex c_int16_t
  5611. This is like @code{AC_TYPE_INT8_T}, except for 16-bit integers.
  5612. @end defmac
  5613. @defmac AC_TYPE_INT32_T
  5614. @acindex{TYPE_INT32_T}
  5615. @cvindex HAVE_INT32_T
  5616. @cvindex int32_t
  5617. @caindex c_int32_t
  5618. This is like @code{AC_TYPE_INT8_T}, except for 32-bit integers.
  5619. @end defmac
  5620. @defmac AC_TYPE_INT64_T
  5621. @acindex{TYPE_INT64_T}
  5622. @cvindex HAVE_INT64_T
  5623. @cvindex int64_t
  5624. @caindex c_int64_t
  5625. This is like @code{AC_TYPE_INT8_T}, except for 64-bit integers.
  5626. @end defmac
  5627. @defmac AC_TYPE_INTMAX_T
  5628. @acindex{TYPE_INTMAX_T}
  5629. @cvindex HAVE_INTMAX_T
  5630. @cvindex intmax_t
  5631. @c @caindex type_intmax_t
  5632. If @file{stdint.h} or @file{inttypes.h} defines the type @code{intmax_t},
  5633. define @code{HAVE_INTMAX_T}. Otherwise, define @code{intmax_t} to the
  5634. widest signed integer type.
  5635. @end defmac
  5636. @defmac AC_TYPE_INTPTR_T
  5637. @acindex{TYPE_INTPTR_T}
  5638. @cvindex HAVE_INTPTR_T
  5639. @cvindex intptr_t
  5640. @c @caindex type_intptr_t
  5641. If @file{stdint.h} or @file{inttypes.h} defines the type @code{intptr_t},
  5642. define @code{HAVE_INTPTR_T}. Otherwise, define @code{intptr_t} to a
  5643. signed integer type wide enough to hold a pointer, if such a type
  5644. exists.
  5645. @end defmac
  5646. @defmac AC_TYPE_LONG_DOUBLE
  5647. @acindex{TYPE_LONG_DOUBLE}
  5648. @cvindex HAVE_LONG_DOUBLE
  5649. @caindex type_long_double
  5650. If the C compiler supports a working @code{long double} type, define
  5651. @code{HAVE_LONG_DOUBLE}. The @code{long double} type might have the
  5652. same range and precision as @code{double}.
  5653. This macro caches its result in the @code{ac_cv_type_long_double}
  5654. variable.
  5655. This macro is obsolescent, as current C compilers support @code{long
  5656. double}. New programs need not use this macro.
  5657. @end defmac
  5658. @defmac AC_TYPE_LONG_DOUBLE_WIDER
  5659. @acindex{TYPE_LONG_DOUBLE_WIDER}
  5660. @cvindex HAVE_LONG_DOUBLE_WIDER
  5661. @caindex type_long_double_wider
  5662. If the C compiler supports a working @code{long double} type with more
  5663. range or precision than the @code{double} type, define
  5664. @code{HAVE_LONG_DOUBLE_WIDER}.
  5665. This macro caches its result in the @code{ac_cv_type_long_double_wider}
  5666. variable.
  5667. @end defmac
  5668. @defmac AC_TYPE_LONG_LONG_INT
  5669. @acindex{TYPE_LONG_LONG_INT}
  5670. @cvindex HAVE_LONG_LONG_INT
  5671. @caindex type_long_long_int
  5672. If the C compiler supports a working @code{long long int} type, define
  5673. @code{HAVE_LONG_LONG_INT}. However, this test does not test
  5674. @code{long long int} values in preprocessor @code{#if} expressions,
  5675. because too many compilers mishandle such expressions.
  5676. @xref{Preprocessor Arithmetic}.
  5677. This macro caches its result in the @code{ac_cv_type_long_long_int}
  5678. variable.
  5679. @end defmac
  5680. @defmac AC_TYPE_MBSTATE_T
  5681. @acindex{TYPE_MBSTATE_T}
  5682. @cvindex mbstate_t
  5683. @hdrindex{wchar.h}
  5684. @caindex type_mbstate_t
  5685. Define @code{HAVE_MBSTATE_T} if @code{<wchar.h>} declares the
  5686. @code{mbstate_t} type. Also, define @code{mbstate_t} to be a type if
  5687. @code{<wchar.h>} does not declare it.
  5688. This macro caches its result in the @code{ac_cv_type_mbstate_t}
  5689. variable.
  5690. @end defmac
  5691. @anchor{AC_TYPE_MODE_T}
  5692. @defmac AC_TYPE_MODE_T
  5693. @acindex{TYPE_MODE_T}
  5694. @cvindex mode_t
  5695. @caindex type_mode_t
  5696. Define @code{mode_t} to a suitable type, if standard headers do not
  5697. define it.
  5698. This macro caches its result in the @code{ac_cv_type_mode_t} variable.
  5699. @end defmac
  5700. @anchor{AC_TYPE_OFF_T}
  5701. @defmac AC_TYPE_OFF_T
  5702. @acindex{TYPE_OFF_T}
  5703. @cvindex off_t
  5704. @caindex type_off_t
  5705. Define @code{off_t} to a suitable type, if standard headers do not
  5706. define it.
  5707. This macro caches its result in the @code{ac_cv_type_off_t} variable.
  5708. @end defmac
  5709. @anchor{AC_TYPE_PID_T}
  5710. @defmac AC_TYPE_PID_T
  5711. @acindex{TYPE_PID_T}
  5712. @cvindex pid_t
  5713. @caindex type_pid_t
  5714. Define @code{pid_t} to a suitable type, if standard headers do not
  5715. define it.
  5716. This macro caches its result in the @code{ac_cv_type_pid_t} variable.
  5717. @end defmac
  5718. @anchor{AC_TYPE_SIZE_T}
  5719. @defmac AC_TYPE_SIZE_T
  5720. @acindex{TYPE_SIZE_T}
  5721. @cvindex size_t
  5722. @caindex type_size_t
  5723. Define @code{size_t} to a suitable type, if standard headers do not
  5724. define it.
  5725. This macro caches its result in the @code{ac_cv_type_size_t} variable.
  5726. @end defmac
  5727. @defmac AC_TYPE_SSIZE_T
  5728. @acindex{TYPE_SSIZE_T}
  5729. @cvindex ssize_t
  5730. @caindex type_ssize_t
  5731. Define @code{ssize_t} to a suitable type, if standard headers do not
  5732. define it.
  5733. This macro caches its result in the @code{ac_cv_type_ssize_t} variable.
  5734. @end defmac
  5735. @anchor{AC_TYPE_UID_T}
  5736. @defmac AC_TYPE_UID_T
  5737. @acindex{TYPE_UID_T}
  5738. @cvindex uid_t
  5739. @cvindex gid_t
  5740. @caindex type_uid_t
  5741. Define @code{uid_t} and @code{gid_t} to suitable types, if standard
  5742. headers do not define them.
  5743. This macro caches its result in the @code{ac_cv_type_uid_t} variable.
  5744. @end defmac
  5745. @defmac AC_TYPE_UINT8_T
  5746. @acindex{TYPE_UINT8_T}
  5747. @cvindex HAVE_UINT8_T
  5748. @cvindex uint8_t
  5749. @caindex c_uint8_t
  5750. If @file{stdint.h} or @file{inttypes.h} does not define the type
  5751. @code{uint8_t}, define @code{uint8_t} to an
  5752. unsigned integer type that is exactly 8 bits wide, if such a type
  5753. exists.
  5754. This is like @code{AC_TYPE_INT8_T}, except for unsigned integers.
  5755. @end defmac
  5756. @defmac AC_TYPE_UINT16_T
  5757. @acindex{TYPE_UINT16_T}
  5758. @cvindex HAVE_UINT16_T
  5759. @cvindex uint16_t
  5760. @caindex c_uint16_t
  5761. This is like @code{AC_TYPE_UINT8_T}, except for 16-bit integers.
  5762. @end defmac
  5763. @defmac AC_TYPE_UINT32_T
  5764. @acindex{TYPE_UINT32_T}
  5765. @cvindex HAVE_UINT32_T
  5766. @cvindex uint32_t
  5767. @caindex c_uint32_t
  5768. This is like @code{AC_TYPE_UINT8_T}, except for 32-bit integers.
  5769. @end defmac
  5770. @defmac AC_TYPE_UINT64_T
  5771. @acindex{TYPE_UINT64_T}
  5772. @cvindex HAVE_UINT64_T
  5773. @cvindex uint64_t
  5774. @caindex c_uint64_t
  5775. This is like @code{AC_TYPE_UINT8_T}, except for 64-bit integers.
  5776. @end defmac
  5777. @defmac AC_TYPE_UINTMAX_T
  5778. @acindex{TYPE_UINTMAX_T}
  5779. @cvindex HAVE_UINTMAX_T
  5780. @cvindex uintmax_t
  5781. @c @caindex type_uintmax_t
  5782. If @file{stdint.h} or @file{inttypes.h} defines the type @code{uintmax_t},
  5783. define @code{HAVE_UINTMAX_T}. Otherwise, define @code{uintmax_t} to the
  5784. widest unsigned integer type.
  5785. @end defmac
  5786. @defmac AC_TYPE_UINTPTR_T
  5787. @acindex{TYPE_UINTPTR_T}
  5788. @cvindex HAVE_UINTPTR_T
  5789. @cvindex uintptr_t
  5790. @c @caindex type_uintptr_t
  5791. If @file{stdint.h} or @file{inttypes.h} defines the type @code{uintptr_t},
  5792. define @code{HAVE_UINTPTR_T}. Otherwise, define @code{uintptr_t} to an
  5793. unsigned integer type wide enough to hold a pointer, if such a type
  5794. exists.
  5795. @end defmac
  5796. @defmac AC_TYPE_UNSIGNED_LONG_LONG_INT
  5797. @acindex{TYPE_UNSIGNED_LONG_LONG_INT}
  5798. @cvindex HAVE_UNSIGNED_LONG_LONG_INT
  5799. @caindex type_unsigned_long_long_int
  5800. If the C compiler supports a working @code{unsigned long long int} type,
  5801. define @code{HAVE_UNSIGNED_LONG_LONG_INT}. However, this test does not test
  5802. @code{unsigned long long int} values in preprocessor @code{#if} expressions,
  5803. because too many compilers mishandle such expressions.
  5804. @xref{Preprocessor Arithmetic}.
  5805. This macro caches its result in the @code{ac_cv_type_unsigned_long_long_int}
  5806. variable.
  5807. @end defmac
  5808. @node Generic Types
  5809. @subsection Generic Type Checks
  5810. These macros are used to check for types not covered by the ``particular''
  5811. test macros.
  5812. @defmac AC_CHECK_TYPE (@var{type}, @ovar{action-if-found}, @
  5813. @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})
  5814. @acindex{CHECK_TYPE}
  5815. @caindex type_@var{type}
  5816. Check whether @var{type} is defined. It may be a compiler builtin type
  5817. or defined by the @var{includes}. @var{includes} is a series of include
  5818. directives, defaulting to @code{AC_INCLUDES_DEFAULT} (@pxref{Default
  5819. Includes}), which are used prior to the type under test.
  5820. In C, @var{type} must be a type-name, so that the expression @samp{sizeof
  5821. (@var{type})} is valid (but @samp{sizeof ((@var{type}))} is not). The
  5822. same test is applied when compiling for C++, which means that in C++
  5823. @var{type} should be a type-id and should not be an anonymous
  5824. @samp{struct} or @samp{union}.
  5825. This macro caches its result in the @code{ac_cv_type_@var{type}}
  5826. variable, with @samp{*} mapped to @samp{p} and other characters not
  5827. suitable for a variable name mapped to underscores.
  5828. @end defmac
  5829. @defmac AC_CHECK_TYPES (@var{types}, @ovar{action-if-found}, @
  5830. @ovar{action-if-not-found}, @dvar{includes, AC_INCLUDES_DEFAULT})
  5831. @acindex{CHECK_TYPES}
  5832. @cvindex HAVE_@var{type}
  5833. For each @var{type} of the @var{types} that is defined, define
  5834. @code{HAVE_@var{type}} (in all capitals). Each @var{type} must follow
  5835. the rules of @code{AC_CHECK_TYPE}. If no @var{includes} are
  5836. specified, the default includes are used (@pxref{Default Includes}). If
  5837. @var{action-if-found} is given, it is additional shell code to execute
  5838. when one of the types is found. If @var{action-if-not-found} is given,
  5839. it is executed when one of the types is not found.
  5840. This macro uses M4 lists:
  5841. @example
  5842. AC_CHECK_TYPES([ptrdiff_t])
  5843. AC_CHECK_TYPES([unsigned long long int, uintmax_t])
  5844. AC_CHECK_TYPES([float_t], [], [], [[#include <math.h>]])
  5845. @end example
  5846. @end defmac
  5847. Autoconf, up to 2.13, used to provide to another version of
  5848. @code{AC_CHECK_TYPE}, broken by design. In order to keep backward
  5849. compatibility, a simple heuristic, quite safe but not totally, is
  5850. implemented. In case of doubt, read the documentation of the former
  5851. @code{AC_CHECK_TYPE}, see @ref{Obsolete Macros}.
  5852. @node Compilers and Preprocessors
  5853. @section Compilers and Preprocessors
  5854. @cindex Compilers
  5855. @cindex Preprocessors
  5856. @ovindex EXEEXT
  5857. All the tests for compilers (@code{AC_PROG_CC}, @code{AC_PROG_CXX},
  5858. @code{AC_PROG_F77}) define the output variable @code{EXEEXT} based on
  5859. the output of the compiler, typically to the empty string if
  5860. Posix and @samp{.exe} if a DOS variant.
  5861. @ovindex OBJEXT
  5862. They also define the output variable @code{OBJEXT} based on the
  5863. output of the compiler, after @file{.c} files have been excluded, typically
  5864. to @samp{o} if Posix, @samp{obj} if a DOS variant.
  5865. If the compiler being used does not produce executables, the tests fail. If
  5866. the executables can't be run, and cross-compilation is not enabled, they
  5867. fail too. @xref{Manual Configuration}, for more on support for cross
  5868. compiling.
  5869. @menu
  5870. * Specific Compiler Characteristics:: Some portability issues
  5871. * Generic Compiler Characteristics:: Language independent tests and features
  5872. * C Compiler:: Checking its characteristics
  5873. * C++ Compiler:: Likewise
  5874. * Objective C Compiler:: Likewise
  5875. * Objective C++ Compiler:: Likewise
  5876. * Erlang Compiler and Interpreter:: Likewise
  5877. * Fortran Compiler:: Likewise
  5878. * Go Compiler:: Likewise
  5879. @end menu
  5880. @node Specific Compiler Characteristics
  5881. @subsection Specific Compiler Characteristics
  5882. Some compilers exhibit different behaviors.
  5883. @table @asis
  5884. @item Static/Dynamic Expressions
  5885. Autoconf relies on a trick to extract one bit of information from the C
  5886. compiler: using negative array sizes. For instance the following
  5887. excerpt of a C source demonstrates how to test whether @samp{int} objects are 4
  5888. bytes wide:
  5889. @example
  5890. static int test_array[sizeof (int) == 4 ? 1 : -1];
  5891. @end example
  5892. @noindent
  5893. To our knowledge, there is a single compiler that does not support this
  5894. trick: the HP C compilers (the real ones, not only the
  5895. ``bundled'') on HP-UX 11.00.
  5896. They incorrectly reject the above program with the diagnostic
  5897. ``Variable-length arrays cannot have static storage.''
  5898. This bug comes from HP compilers' mishandling of @code{sizeof (int)},
  5899. not from the @code{? 1 : -1}, and
  5900. Autoconf works around this problem by casting @code{sizeof (int)} to
  5901. @code{long int} before comparing it.
  5902. @end table
  5903. @node Generic Compiler Characteristics
  5904. @subsection Generic Compiler Characteristics
  5905. @anchor{AC_CHECK_SIZEOF}
  5906. @defmac AC_CHECK_SIZEOF (@var{type-or-expr}, @ovar{unused}, @
  5907. @dvar{includes, AC_INCLUDES_DEFAULT})
  5908. @acindex{CHECK_SIZEOF}
  5909. @cvindex SIZEOF_@var{type-or-expr}
  5910. @caindex sizeof_@var{type-or-expr}
  5911. Define @code{SIZEOF_@var{type-or-expr}} (@pxref{Standard Symbols}) to be
  5912. the size in bytes of @var{type-or-expr}, which may be either a type or
  5913. an expression returning a value that has a size. If the expression
  5914. @samp{sizeof (@var{type-or-expr})} is invalid, the result is 0.
  5915. @var{includes} is a series of include directives, defaulting to
  5916. @code{AC_INCLUDES_DEFAULT} (@pxref{Default Includes}), which are used
  5917. prior to the expression under test.
  5918. This macro now works even when cross-compiling. The @var{unused}
  5919. argument was used when cross-compiling.
  5920. For example, the call
  5921. @example
  5922. @c If you change this example, adjust tests/semantics.at:AC_CHECK_SIZEOF struct.
  5923. AC_CHECK_SIZEOF([int *])
  5924. @end example
  5925. @noindent
  5926. defines @code{SIZEOF_INT_P} to be 8 on DEC Alpha AXP systems.
  5927. This macro caches its result in the @code{ac_cv_sizeof_@var{type-or-expr}}
  5928. variable, with @samp{*} mapped to @samp{p} and other characters not
  5929. suitable for a variable name mapped to underscores.
  5930. @end defmac
  5931. @defmac AC_CHECK_ALIGNOF (@var{type}, @dvar{includes, AC_INCLUDES_DEFAULT})
  5932. @acindex{CHECK_ALIGNOF}
  5933. @cvindex ALIGNOF_@var{type}
  5934. @caindex alignof_@var{type-or-expr}
  5935. Define @code{ALIGNOF_@var{type}} (@pxref{Standard Symbols}) to be the
  5936. alignment in bytes of @var{type}. @samp{@var{type} y;} must be valid as
  5937. a structure member declaration. If @samp{type} is unknown, the result
  5938. is 0. If no @var{includes} are specified, the default includes are used
  5939. (@pxref{Default Includes}).
  5940. This macro caches its result in the @code{ac_cv_alignof_@var{type-or-expr}}
  5941. variable, with @samp{*} mapped to @samp{p} and other characters not
  5942. suitable for a variable name mapped to underscores.
  5943. @end defmac
  5944. @defmac AC_COMPUTE_INT (@var{var}, @var{expression}, @
  5945. @dvar{includes, AC_INCLUDES_DEFAULT}, @ovar{action-if-fails})
  5946. @acindex{COMPUTE_INT}
  5947. Store into the shell variable @var{var} the value of the integer
  5948. @var{expression}. The
  5949. value should fit in an initializer in a C variable of type @code{signed
  5950. long}. To support cross compilation (in which case, the macro only works on
  5951. hosts that use twos-complement arithmetic), it should be possible to evaluate
  5952. the expression at compile-time. If no @var{includes} are specified, the
  5953. default includes are used (@pxref{Default Includes}).
  5954. Execute @var{action-if-fails} if the value cannot be determined correctly.
  5955. @end defmac
  5956. @defmac AC_LANG_WERROR
  5957. @acindex{LANG_WERROR}
  5958. Normally Autoconf ignores warnings generated by the compiler, linker, and
  5959. preprocessor. If this macro is used, warnings count as fatal
  5960. errors for the current language. This macro is useful when the
  5961. results of configuration are used where warnings are unacceptable; for
  5962. instance, if parts of a program are built with the GCC
  5963. @option{-Werror}
  5964. option. If the whole program is built using @option{-Werror} it is
  5965. often simpler to put @option{-Werror} in the compiler flags (@code{CFLAGS},
  5966. etc.).
  5967. @end defmac
  5968. @defmac AC_OPENMP
  5969. @acindex{OPENMP}
  5970. @cvindex _OPENMP
  5971. @ovindex OPENMP_CFLAGS
  5972. @ovindex OPENMP_CXXFLAGS
  5973. @ovindex OPENMP_FFLAGS
  5974. @ovindex OPENMP_FCFLAGS
  5975. @caindex prog_c_openmp
  5976. @caindex prog_cxx_openmp
  5977. @caindex prog_f77_openmp
  5978. @caindex prog_fc_openmp
  5979. @uref{http://@/www.openmp.org/, OpenMP} specifies extensions of C, C++,
  5980. and Fortran that simplify optimization of shared memory parallelism,
  5981. which is a common problem on multicore CPUs.
  5982. If the current language is C, the macro @code{AC_OPENMP} sets the
  5983. variable @code{OPENMP_CFLAGS} to the C compiler flags needed for
  5984. supporting OpenMP@. @code{OPENMP_CFLAGS} is set to empty if the
  5985. compiler already supports OpenMP, if it has no way to activate OpenMP
  5986. support, or if the user rejects OpenMP support by invoking
  5987. @samp{configure} with the @samp{--disable-openmp} option.
  5988. @code{OPENMP_CFLAGS} needs to be used when compiling programs, when
  5989. preprocessing program source, and when linking programs. Therefore you
  5990. need to add @code{$(OPENMP_CFLAGS)} to the @code{CFLAGS} of C programs
  5991. that use OpenMP@. If you preprocess OpenMP-specific C code, you also
  5992. need to add @code{$(OPENMP_CFLAGS)} to @code{CPPFLAGS}. The presence of
  5993. OpenMP support is revealed at compile time by the preprocessor macro
  5994. @code{_OPENMP}.
  5995. Linking a program with @code{OPENMP_CFLAGS} typically adds one more
  5996. shared library to the program's dependencies, so its use is recommended
  5997. only on programs that actually require OpenMP.
  5998. If the current language is C++, @code{AC_OPENMP} sets the variable
  5999. @code{OPENMP_CXXFLAGS}, suitably for the C++ compiler. The same remarks
  6000. hold as for C.
  6001. If the current language is Fortran 77 or Fortran, @code{AC_OPENMP} sets
  6002. the variable @code{OPENMP_FFLAGS} or @code{OPENMP_FCFLAGS},
  6003. respectively. Similar remarks as for C hold, except that
  6004. @code{CPPFLAGS} is not used for Fortran, and no preprocessor macro
  6005. signals OpenMP support.
  6006. For portability, it is best to avoid spaces between @samp{#} and
  6007. @samp{pragma omp}. That is, write @samp{#pragma omp}, not
  6008. @samp{# pragma omp}. The Sun WorkShop 6.2 C compiler chokes on the
  6009. latter.
  6010. This macro caches its result in the @code{ac_cv_prog_c_openmp},
  6011. @code{ac_cv_prog_cxx_openmp}, @code{ac_cv_prog_f77_openmp}, or
  6012. @code{ac_cv_prog_fc_openmp} variable, depending on the current language.
  6013. @end defmac
  6014. @node C Compiler
  6015. @subsection C Compiler Characteristics
  6016. The following macros provide ways to find and exercise a C Compiler.
  6017. There are a few constructs that ought to be avoided, but do not deserve
  6018. being checked for, since they can easily be worked around.
  6019. @table @asis
  6020. @item Don't use lines containing solitary backslashes
  6021. They tickle a bug in the HP-UX C compiler (checked on
  6022. HP-UX 10.20,
  6023. 11.00, and 11i). When given the following source:
  6024. @example
  6025. #ifdef __STDC__
  6026. /\
  6027. * A comment with backslash-newlines in it. %@{ %@} *\
  6028. \
  6029. /
  6030. char str[] = "\\
  6031. " A string with backslash-newlines in it %@{ %@} \\
  6032. "";
  6033. char apostrophe = '\\
  6034. \
  6035. '\
  6036. ';
  6037. #endif
  6038. @end example
  6039. @noindent
  6040. the compiler incorrectly fails with the diagnostics ``Non-terminating
  6041. comment at end of file'' and ``Missing @samp{#endif} at end of file.''
  6042. Removing the lines with solitary backslashes solves the problem.
  6043. @item Don't compile several files at once if output matters to you
  6044. Some compilers, such as HP's, report names of files being
  6045. compiled when given more than one file operand. For instance:
  6046. @example
  6047. $ @kbd{cc a.c b.c}
  6048. a.c:
  6049. b.c:
  6050. @end example
  6051. @noindent
  6052. This can cause problems if you observe the output of the compiler to
  6053. detect failures. Invoking @samp{cc -c a.c && cc -c b.c && cc -o c a.o
  6054. b.o} solves the issue.
  6055. @item Don't rely on @code{#error} failing
  6056. The IRIX C compiler does not fail when #error is preprocessed; it
  6057. simply emits a diagnostic and continues, exiting successfully. So,
  6058. instead of an error directive like @code{#error "Unsupported word size"}
  6059. it is more portable to use an invalid directive like @code{#Unsupported
  6060. word size} in Autoconf tests. In ordinary source code, @code{#error} is
  6061. OK, since installers with inadequate compilers like IRIX can simply
  6062. examine these compilers' diagnostic output.
  6063. @item Don't rely on correct @code{#line} support
  6064. On Solaris, @command{c89} (at least Sun C 5.3 through 5.8)
  6065. diagnoses @code{#line} directives whose line
  6066. numbers are greater than 32767. Nothing in Posix
  6067. makes this invalid. That is why Autoconf stopped issuing
  6068. @code{#line} directives.
  6069. @end table
  6070. @defmac AC_PROG_CC (@ovar{compiler-search-list})
  6071. @acindex{PROG_CC}
  6072. @evindex CC
  6073. @evindex CFLAGS
  6074. @ovindex CC
  6075. @ovindex CFLAGS
  6076. @caindex prog_cc_c89
  6077. Determine a C compiler to use. If @code{CC} is not already set in the
  6078. environment, check for @code{gcc} and @code{cc}, then for other C
  6079. compilers. Set output variable @code{CC} to the name of the compiler
  6080. found.
  6081. This macro may, however, be invoked with an optional first argument
  6082. which, if specified, must be a blank-separated list of C compilers to
  6083. search for. This just gives the user an opportunity to specify an
  6084. alternative search list for the C compiler. For example, if you didn't
  6085. like the default order, then you could invoke @code{AC_PROG_CC} like
  6086. this:
  6087. @example
  6088. AC_PROG_CC([gcc cl cc])
  6089. @end example
  6090. If the C compiler does not handle function prototypes correctly by
  6091. default, try to add an option to output variable @code{CC} to make it
  6092. so. This macro tries various options that select standard-conformance
  6093. modes on various systems.
  6094. After calling this macro you can check whether the C compiler has been
  6095. set to accept ANSI C89 (ISO C90); if not, the shell
  6096. variable
  6097. @code{ac_cv_prog_cc_c89} is set to @samp{no}. See also
  6098. @code{AC_C_PROTOTYPES} below.
  6099. If using the GNU C compiler, set shell variable @code{GCC} to
  6100. @samp{yes}. If output variable @code{CFLAGS} was not already set, set
  6101. it to @option{-g -O2} for the GNU C compiler (@option{-O2} on systems
  6102. where GCC does not accept @option{-g}), or @option{-g} for
  6103. other compilers. If your package does not like this default, then it is
  6104. acceptable to insert the line @samp{: $@{CFLAGS=""@}} after @code{AC_INIT}
  6105. and before @code{AC_PROG_CC} to select an empty default instead.
  6106. Many Autoconf macros use a compiler, and thus call
  6107. @samp{AC_REQUIRE([AC_PROG_CC])} to ensure that the compiler has been
  6108. determined before the body of the outermost @code{AC_DEFUN} macro.
  6109. Although @code{AC_PROG_CC} is safe to directly expand multiple times, it
  6110. performs certain checks (such as the proper value of @env{EXEEXT}) only
  6111. on the first invocation. Therefore, care must be used when invoking
  6112. this macro from within another macro rather than at the top level
  6113. (@pxref{Expanded Before Required}).
  6114. @end defmac
  6115. @anchor{AC_PROG_CC_C_O}
  6116. @defmac AC_PROG_CC_C_O
  6117. @acindex{PROG_CC_C_O}
  6118. @cvindex NO_MINUS_C_MINUS_O
  6119. @caindex prog_cc_@var{compiler}_c_o
  6120. If the C compiler does not accept the @option{-c} and @option{-o} options
  6121. simultaneously, define @code{NO_MINUS_C_MINUS_O}. This macro actually
  6122. tests both the compiler found by @code{AC_PROG_CC}, and, if different,
  6123. the first @code{cc} in the path. The test fails if one fails. This
  6124. macro was created for GNU Make to choose the default C compilation
  6125. rule.
  6126. For the compiler @var{compiler}, this macro caches its result in the
  6127. @code{ac_cv_prog_cc_@var{compiler}_c_o} variable.
  6128. @end defmac
  6129. @defmac AC_PROG_CPP
  6130. @acindex{PROG_CPP}
  6131. @evindex CPP
  6132. @ovindex CPP
  6133. Set output variable @code{CPP} to a command that runs the
  6134. C preprocessor. If @samp{$CC -E} doesn't work, @file{/lib/cpp} is used.
  6135. It is only portable to run @code{CPP} on files with a @file{.c}
  6136. extension.
  6137. Some preprocessors don't indicate missing include files by the error
  6138. status. For such preprocessors an internal variable is set that causes
  6139. other macros to check the standard error from the preprocessor and
  6140. consider the test failed if any warnings have been reported.
  6141. For most preprocessors, though, warnings do not cause include-file
  6142. tests to fail unless @code{AC_PROG_CPP_WERROR} is also specified.
  6143. @end defmac
  6144. @defmac AC_PROG_CPP_WERROR
  6145. @acindex{PROG_CPP_WERROR}
  6146. @ovindex CPP
  6147. This acts like @code{AC_PROG_CPP}, except it treats warnings from the
  6148. preprocessor as errors even if the preprocessor exit status indicates
  6149. success. This is useful for avoiding headers that generate mandatory
  6150. warnings, such as deprecation notices.
  6151. @end defmac
  6152. The following macros check for C compiler or machine architecture
  6153. features. To check for characteristics not listed here, use
  6154. @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
  6155. @code{AC_RUN_IFELSE} (@pxref{Runtime}).
  6156. @defmac AC_PROG_CC_STDC
  6157. @acindex{PROG_CC_STDC}
  6158. @caindex prog_cc_stdc
  6159. If the C compiler cannot compile ISO Standard C (currently
  6160. C99), try to add an option to output variable @code{CC} to make it work.
  6161. If the compiler does not support C99, fall back to supporting
  6162. ANSI C89 (ISO C90).
  6163. After calling this macro you can check whether the C compiler has been
  6164. set to accept Standard C; if not, the shell variable
  6165. @code{ac_cv_prog_cc_stdc} is set to @samp{no}.
  6166. @end defmac
  6167. @defmac AC_PROG_CC_C89
  6168. @acindex{PROG_CC_C89}
  6169. @caindex prog_cc_c89
  6170. If the C compiler is not in ANSI C89 (ISO C90) mode by
  6171. default, try to add an option to output variable @code{CC} to make it
  6172. so. This macro tries various options that select ANSI C89 on
  6173. some system or another, preferring extended functionality modes over
  6174. strict conformance modes. It considers the compiler to be in
  6175. ANSI C89 mode if it handles function prototypes correctly.
  6176. After calling this macro you can check whether the C compiler has been
  6177. set to accept ANSI C89; if not, the shell variable
  6178. @code{ac_cv_prog_cc_c89} is set to @samp{no}.
  6179. This macro is called automatically by @code{AC_PROG_CC}.
  6180. @end defmac
  6181. @defmac AC_PROG_CC_C99
  6182. @acindex{PROG_CC_C99}
  6183. @caindex prog_cc_c99
  6184. If the C compiler is not in C99 mode by default, try to add an
  6185. option to output variable @code{CC} to make it so. This macro tries
  6186. various options that select C99 on some system or another, preferring
  6187. extended functionality modes over strict conformance modes. It
  6188. considers the compiler to be in C99 mode if it handles @code{_Bool},
  6189. @code{//} comments, flexible array members, @code{inline}, signed and
  6190. unsigned @code{long long int}, mixed code and declarations, named
  6191. initialization of structs,
  6192. @code{restrict}, @code{va_copy}, varargs macros, variable declarations
  6193. in @code{for} loops, and variable length arrays.
  6194. After calling this macro you can check whether the C compiler has been
  6195. set to accept C99; if not, the shell variable
  6196. @code{ac_cv_prog_cc_c99} is set to @samp{no}.
  6197. @end defmac
  6198. @defmac AC_C_BACKSLASH_A
  6199. @acindex{C_BACKSLASH_A}
  6200. @cvindex HAVE_C_BACKSLASH_A
  6201. Define @samp{HAVE_C_BACKSLASH_A} to 1 if the C compiler understands
  6202. @samp{\a}.
  6203. This macro is obsolescent, as current C compilers understand @samp{\a}.
  6204. New programs need not use this macro.
  6205. @end defmac
  6206. @anchor{AC_C_BIGENDIAN}
  6207. @defmac AC_C_BIGENDIAN (@ovar{action-if-true}, @ovar{action-if-false}, @
  6208. @ovar{action-if-unknown}, @ovar{action-if-universal})
  6209. @acindex{C_BIGENDIAN}
  6210. @cvindex WORDS_BIGENDIAN
  6211. @cindex Endianness
  6212. If words are stored with the most significant byte first (like Motorola
  6213. and SPARC CPUs), execute @var{action-if-true}. If words are stored with
  6214. the least significant byte first (like Intel and VAX CPUs), execute
  6215. @var{action-if-false}.
  6216. This macro runs a test-case if endianness cannot be determined from the
  6217. system header files. When cross-compiling, the test-case is not run but
  6218. grep'ed for some magic values. @var{action-if-unknown} is executed if
  6219. the latter case fails to determine the byte sex of the host system.
  6220. In some cases a single run of a compiler can generate code for multiple
  6221. architectures. This can happen, for example, when generating Mac OS X
  6222. universal binary files, which work on both PowerPC and Intel
  6223. architectures. In this case, the different variants might be for
  6224. different architectures whose endiannesses differ. If
  6225. @command{configure} detects this, it executes @var{action-if-universal}
  6226. instead of @var{action-if-unknown}.
  6227. The default for @var{action-if-true} is to define
  6228. @samp{WORDS_BIGENDIAN}. The default for @var{action-if-false} is to do
  6229. nothing. The default for @var{action-if-unknown} is to
  6230. abort configure and tell the installer how to bypass this test.
  6231. And finally, the default for @var{action-if-universal} is to ensure that
  6232. @samp{WORDS_BIGENDIAN} is defined if and only if a universal build is
  6233. detected and the current code is big-endian; this default works only if
  6234. @command{autoheader} is used (@pxref{autoheader Invocation}).
  6235. If you use this macro without specifying @var{action-if-universal}, you
  6236. should also use @code{AC_CONFIG_HEADERS}; otherwise
  6237. @samp{WORDS_BIGENDIAN} may be set incorrectly for Mac OS X universal
  6238. binary files.
  6239. @end defmac
  6240. @anchor{AC_C_CONST}
  6241. @defmac AC_C_CONST
  6242. @acindex{C_CONST}
  6243. @cvindex const
  6244. @caindex c_const
  6245. If the C compiler does not fully support the @code{const} keyword,
  6246. define @code{const} to be empty. Some C compilers that do
  6247. not define @code{__STDC__} do support @code{const}; some compilers that
  6248. define @code{__STDC__} do not completely support @code{const}. Programs
  6249. can simply use @code{const} as if every C compiler supported it; for
  6250. those that don't, the makefile or configuration header file
  6251. defines it as empty.
  6252. Occasionally installers use a C++ compiler to compile C code, typically
  6253. because they lack a C compiler. This causes problems with @code{const},
  6254. because C and C++ treat @code{const} differently. For example:
  6255. @example
  6256. const int foo;
  6257. @end example
  6258. @noindent
  6259. is valid in C but not in C++. These differences unfortunately cannot be
  6260. papered over by defining @code{const} to be empty.
  6261. If @command{autoconf} detects this situation, it leaves @code{const} alone,
  6262. as this generally yields better results in practice. However, using a
  6263. C++ compiler to compile C code is not recommended or supported, and
  6264. installers who run into trouble in this area should get a C compiler
  6265. like GCC to compile their C code.
  6266. This macro caches its result in the @code{ac_cv_c_const} variable.
  6267. This macro is obsolescent, as current C compilers support @code{const}.
  6268. New programs need not use this macro.
  6269. @end defmac
  6270. @defmac AC_C_RESTRICT
  6271. @acindex{C_RESTRICT}
  6272. @cvindex restrict
  6273. @caindex c_restrict
  6274. If the C compiler recognizes a variant spelling for the @code{restrict}
  6275. keyword (@code{__restrict}, @code{__restrict__}, or @code{_Restrict}),
  6276. then define @code{restrict} to that; this is more likely to do the right
  6277. thing with compilers that support language variants where plain
  6278. @code{restrict} is not a keyword. Otherwise, if the C compiler
  6279. recognizes the @code{restrict} keyword, don't do anything.
  6280. Otherwise, define @code{restrict} to be empty.
  6281. Thus, programs may simply use @code{restrict} as if every C compiler
  6282. supported it; for those that do not, the makefile
  6283. or configuration header defines it away.
  6284. Although support in C++ for the @code{restrict} keyword is not
  6285. required, several C++ compilers do accept the keyword.
  6286. This macro works for them, too.
  6287. This macro caches @samp{no} in the @code{ac_cv_c_restrict} variable
  6288. if @code{restrict} is not supported, and a supported spelling otherwise.
  6289. @end defmac
  6290. @defmac AC_C_VOLATILE
  6291. @acindex{C_VOLATILE}
  6292. @cvindex volatile
  6293. If the C compiler does not understand the keyword @code{volatile},
  6294. define @code{volatile} to be empty. Programs can simply use
  6295. @code{volatile} as if every C compiler supported it; for those that do
  6296. not, the makefile or configuration header defines it as
  6297. empty.
  6298. If the correctness of your program depends on the semantics of
  6299. @code{volatile}, simply defining it to be empty does, in a sense, break
  6300. your code. However, given that the compiler does not support
  6301. @code{volatile}, you are at its mercy anyway. At least your
  6302. program compiles, when it wouldn't before.
  6303. @xref{Volatile Objects}, for more about @code{volatile}.
  6304. In general, the @code{volatile} keyword is a standard C feature, so
  6305. you might expect that @code{volatile} is available only when
  6306. @code{__STDC__} is defined. However, Ultrix 4.3's native compiler does
  6307. support volatile, but does not define @code{__STDC__}.
  6308. This macro is obsolescent, as current C compilers support @code{volatile}.
  6309. New programs need not use this macro.
  6310. @end defmac
  6311. @anchor{AC_C_INLINE}
  6312. @defmac AC_C_INLINE
  6313. @acindex{C_INLINE}
  6314. @cvindex inline
  6315. If the C compiler supports the keyword @code{inline}, do nothing.
  6316. Otherwise define @code{inline} to @code{__inline__} or @code{__inline}
  6317. if it accepts one of those, otherwise define @code{inline} to be empty.
  6318. @end defmac
  6319. @anchor{AC_C_CHAR_UNSIGNED}
  6320. @defmac AC_C_CHAR_UNSIGNED
  6321. @acindex{C_CHAR_UNSIGNED}
  6322. @cvindex __CHAR_UNSIGNED__
  6323. If the C type @code{char} is unsigned, define @code{__CHAR_UNSIGNED__},
  6324. unless the C compiler predefines it.
  6325. These days, using this macro is not necessary. The same information can
  6326. be determined by this portable alternative, thus avoiding the use of
  6327. preprocessor macros in the namespace reserved for the implementation.
  6328. @example
  6329. #include <limits.h>
  6330. #if CHAR_MIN == 0
  6331. # define CHAR_UNSIGNED 1
  6332. #endif
  6333. @end example
  6334. @end defmac
  6335. @defmac AC_C_STRINGIZE
  6336. @acindex{C_STRINGIZE}
  6337. @cvindex HAVE_STRINGIZE
  6338. If the C preprocessor supports the stringizing operator, define
  6339. @code{HAVE_STRINGIZE}. The stringizing operator is @samp{#} and is
  6340. found in macros such as this:
  6341. @example
  6342. #define x(y) #y
  6343. @end example
  6344. This macro is obsolescent, as current C compilers support the
  6345. stringizing operator. New programs need not use this macro.
  6346. @end defmac
  6347. @defmac AC_C_FLEXIBLE_ARRAY_MEMBER
  6348. @acindex{C_FLEXIBLE_ARRAY_MEMBER}
  6349. @cvindex FLEXIBLE_ARRAY_MEMBER
  6350. If the C compiler supports flexible array members, define
  6351. @code{FLEXIBLE_ARRAY_MEMBER} to nothing; otherwise define it to 1.
  6352. That way, a declaration like this:
  6353. @example
  6354. struct s
  6355. @{
  6356. size_t n_vals;
  6357. double val[FLEXIBLE_ARRAY_MEMBER];
  6358. @};
  6359. @end example
  6360. @noindent
  6361. will let applications use the ``struct hack'' even with compilers that
  6362. do not support flexible array members. To allocate and use such an
  6363. object, you can use code like this:
  6364. @example
  6365. size_t i;
  6366. size_t n = compute_value_count ();
  6367. struct s *p =
  6368. malloc (offsetof (struct s, val)
  6369. + n * sizeof (double));
  6370. p->n_vals = n;
  6371. for (i = 0; i < n; i++)
  6372. p->val[i] = compute_value (i);
  6373. @end example
  6374. @end defmac
  6375. @defmac AC_C_VARARRAYS
  6376. @acindex{C_VARARRAYS}
  6377. @cvindex HAVE_C_VARARRAYS
  6378. If the C compiler supports variable-length arrays, define
  6379. @code{HAVE_C_VARARRAYS}. A variable-length array is an array of automatic
  6380. storage duration whose length is determined at run time, when the array
  6381. is declared.
  6382. @end defmac
  6383. @defmac AC_C_TYPEOF
  6384. @acindex{C_TYPEOF}
  6385. @cvindex HAVE_TYPEOF
  6386. @cvindex typeof
  6387. If the C compiler supports GCC's @code{typeof} syntax either
  6388. directly or
  6389. through a different spelling of the keyword (e.g., @code{__typeof__}),
  6390. define @code{HAVE_TYPEOF}. If the support is available only through a
  6391. different spelling, define @code{typeof} to that spelling.
  6392. @end defmac
  6393. @defmac AC_C_PROTOTYPES
  6394. @acindex{C_PROTOTYPES}
  6395. @cvindex PROTOTYPES
  6396. @cvindex __PROTOTYPES
  6397. @cvindex PARAMS
  6398. If function prototypes are understood by the compiler (as determined by
  6399. @code{AC_PROG_CC}), define @code{PROTOTYPES} and @code{__PROTOTYPES}.
  6400. Defining @code{__PROTOTYPES} is for the benefit of
  6401. header files that cannot use macros that infringe on user name space.
  6402. This macro is obsolescent, as current C compilers support prototypes.
  6403. New programs need not use this macro.
  6404. @end defmac
  6405. @anchor{AC_PROG_GCC_TRADITIONAL}
  6406. @defmac AC_PROG_GCC_TRADITIONAL
  6407. @acindex{PROG_GCC_TRADITIONAL}
  6408. @ovindex CC
  6409. Add @option{-traditional} to output variable @code{CC} if using the
  6410. GNU C compiler and @code{ioctl} does not work properly without
  6411. @option{-traditional}. That usually happens when the fixed header files
  6412. have not been installed on an old system.
  6413. This macro is obsolescent, since current versions of the GNU C
  6414. compiler fix the header files automatically when installed.
  6415. @end defmac
  6416. @node C++ Compiler
  6417. @subsection C++ Compiler Characteristics
  6418. @defmac AC_PROG_CXX (@ovar{compiler-search-list})
  6419. @acindex{PROG_CXX}
  6420. @evindex CXX
  6421. @evindex CXXFLAGS
  6422. @ovindex CXX
  6423. @ovindex CXXFLAGS
  6424. Determine a C++ compiler to use. Check whether the environment variable
  6425. @code{CXX} or @code{CCC} (in that order) is set; if so, then set output
  6426. variable @code{CXX} to its value.
  6427. Otherwise, if the macro is invoked without an argument, then search for
  6428. a C++ compiler under the likely names (first @code{g++} and @code{c++}
  6429. then other names). If none of those checks succeed, then as a last
  6430. resort set @code{CXX} to @code{g++}.
  6431. This macro may, however, be invoked with an optional first argument
  6432. which, if specified, must be a blank-separated list of C++ compilers to
  6433. search for. This just gives the user an opportunity to specify an
  6434. alternative search list for the C++ compiler. For example, if you
  6435. didn't like the default order, then you could invoke @code{AC_PROG_CXX}
  6436. like this:
  6437. @example
  6438. AC_PROG_CXX([gcc cl KCC CC cxx cc++ xlC aCC c++ g++])
  6439. @end example
  6440. If using the GNU C++ compiler, set shell variable @code{GXX} to
  6441. @samp{yes}. If output variable @code{CXXFLAGS} was not already set, set
  6442. it to @option{-g -O2} for the GNU C++ compiler (@option{-O2} on
  6443. systems where G++ does not accept @option{-g}), or @option{-g} for other
  6444. compilers. If your package does not like this default, then it is
  6445. acceptable to insert the line @samp{: $@{CXXFLAGS=""@}} after @code{AC_INIT}
  6446. and before @code{AC_PROG_CXX} to select an empty default instead.
  6447. @end defmac
  6448. @defmac AC_PROG_CXXCPP
  6449. @acindex{PROG_CXXCPP}
  6450. @evindex CXXCPP
  6451. @ovindex CXXCPP
  6452. Set output variable @code{CXXCPP} to a command that runs the C++
  6453. preprocessor. If @samp{$CXX -E} doesn't work, @file{/lib/cpp} is used.
  6454. It is portable to run @code{CXXCPP} only on files with a @file{.c},
  6455. @file{.C}, @file{.cc}, or @file{.cpp} extension.
  6456. Some preprocessors don't indicate missing include files by the error
  6457. status. For such preprocessors an internal variable is set that causes
  6458. other macros to check the standard error from the preprocessor and
  6459. consider the test failed if any warnings have been reported. However,
  6460. it is not known whether such broken preprocessors exist for C++.
  6461. @end defmac
  6462. @defmac AC_PROG_CXX_C_O
  6463. @acindex{PROG_CXX_C_O}
  6464. @cvindex CXX_NO_MINUS_C_MINUS_O
  6465. Test whether the C++ compiler accepts the options @option{-c} and
  6466. @option{-o} simultaneously, and define @code{CXX_NO_MINUS_C_MINUS_O},
  6467. if it does not.
  6468. @end defmac
  6469. @node Objective C Compiler
  6470. @subsection Objective C Compiler Characteristics
  6471. @defmac AC_PROG_OBJC (@ovar{compiler-search-list})
  6472. @acindex{PROG_OBJC}
  6473. @evindex OBJC
  6474. @evindex OBJCFLAGS
  6475. @ovindex OBJC
  6476. @ovindex OBJCFLAGS
  6477. Determine an Objective C compiler to use. If @code{OBJC} is not already
  6478. set in the environment, check for Objective C compilers. Set output
  6479. variable @code{OBJC} to the name of the compiler found.
  6480. This macro may, however, be invoked with an optional first argument
  6481. which, if specified, must be a blank-separated list of Objective C compilers to
  6482. search for. This just gives the user an opportunity to specify an
  6483. alternative search list for the Objective C compiler. For example, if you
  6484. didn't like the default order, then you could invoke @code{AC_PROG_OBJC}
  6485. like this:
  6486. @example
  6487. AC_PROG_OBJC([gcc objcc objc])
  6488. @end example
  6489. If using the GNU Objective C compiler, set shell variable
  6490. @code{GOBJC} to @samp{yes}. If output variable @code{OBJCFLAGS} was not
  6491. already set, set it to @option{-g -O2} for the GNU Objective C
  6492. compiler (@option{-O2} on systems where @command{gcc} does not accept
  6493. @option{-g}), or @option{-g} for other compilers.
  6494. @end defmac
  6495. @defmac AC_PROG_OBJCPP
  6496. @acindex{PROG_OBJCPP}
  6497. @evindex OBJCPP
  6498. @ovindex OBJCPP
  6499. Set output variable @code{OBJCPP} to a command that runs the Objective C
  6500. preprocessor. If @samp{$OBJC -E} doesn't work, @file{/lib/cpp} is used.
  6501. @end defmac
  6502. @node Objective C++ Compiler
  6503. @subsection Objective C++ Compiler Characteristics
  6504. @defmac AC_PROG_OBJCXX (@ovar{compiler-search-list})
  6505. @acindex{PROG_OBJCXX}
  6506. @evindex OBJCXX
  6507. @evindex OBJCXXFLAGS
  6508. @ovindex OBJCXX
  6509. @ovindex OBJCXXFLAGS
  6510. Determine an Objective C++ compiler to use. If @code{OBJCXX} is not already
  6511. set in the environment, check for Objective C++ compilers. Set output
  6512. variable @code{OBJCXX} to the name of the compiler found.
  6513. This macro may, however, be invoked with an optional first argument
  6514. which, if specified, must be a blank-separated list of Objective C++ compilers
  6515. to search for. This just gives the user an opportunity to specify an
  6516. alternative search list for the Objective C++ compiler. For example, if you
  6517. didn't like the default order, then you could invoke @code{AC_PROG_OBJCXX}
  6518. like this:
  6519. @example
  6520. AC_PROG_OBJCXX([gcc g++ objcc++ objcxx])
  6521. @end example
  6522. If using the GNU Objective C++ compiler, set shell variable
  6523. @code{GOBJCXX} to @samp{yes}. If output variable @code{OBJCXXFLAGS} was not
  6524. already set, set it to @option{-g -O2} for the GNU Objective C++
  6525. compiler (@option{-O2} on systems where @command{gcc} does not accept
  6526. @option{-g}), or @option{-g} for other compilers.
  6527. @end defmac
  6528. @defmac AC_PROG_OBJCXXCPP
  6529. @acindex{PROG_OBJCXXCPP}
  6530. @evindex OBJCXXCPP
  6531. @ovindex OBJCXXCPP
  6532. Set output variable @code{OBJCXXCPP} to a command that runs the Objective C++
  6533. preprocessor. If @samp{$OBJCXX -E} doesn't work, @file{/lib/cpp} is used.
  6534. @end defmac
  6535. @node Erlang Compiler and Interpreter
  6536. @subsection Erlang Compiler and Interpreter Characteristics
  6537. @cindex Erlang
  6538. Autoconf defines the following macros for determining paths to the essential
  6539. Erlang/OTP programs:
  6540. @defmac AC_ERLANG_PATH_ERLC (@ovar{value-if-not-found}, @dvar{path, $PATH})
  6541. @acindex{ERLANG_PATH_ERLC}
  6542. @evindex ERLC
  6543. @evindex ERLCFLAGS
  6544. @ovindex ERLC
  6545. @ovindex ERLCFLAGS
  6546. Determine an Erlang compiler to use. If @code{ERLC} is not already set in the
  6547. environment, check for @command{erlc}. Set output variable @code{ERLC} to the
  6548. complete path of the compiler command found. In addition, if @code{ERLCFLAGS}
  6549. is not set in the environment, set it to an empty value.
  6550. The two optional arguments have the same meaning as the two last arguments of
  6551. macro @code{AC_PATH_PROG} for looking for the @command{erlc} program. For
  6552. example, to look for @command{erlc} only in the @file{/usr/lib/erlang/bin}
  6553. directory:
  6554. @example
  6555. AC_ERLANG_PATH_ERLC([not found], [/usr/lib/erlang/bin])
  6556. @end example
  6557. @end defmac
  6558. @defmac AC_ERLANG_NEED_ERLC (@dvar{path, $PATH})
  6559. @acindex{ERLANG_NEED_ERLC}
  6560. A simplified variant of the @code{AC_ERLANG_PATH_ERLC} macro, that prints an
  6561. error message and exits the @command{configure} script if the @command{erlc}
  6562. program is not found.
  6563. @end defmac
  6564. @defmac AC_ERLANG_PATH_ERL (@ovar{value-if-not-found}, @dvar{path, $PATH})
  6565. @acindex{ERLANG_PATH_ERL}
  6566. @evindex ERL
  6567. @ovindex ERL
  6568. Determine an Erlang interpreter to use. If @code{ERL} is not already
  6569. set in the
  6570. environment, check for @command{erl}. Set output variable @code{ERL} to the
  6571. complete path of the interpreter command found.
  6572. The two optional arguments have the same meaning as the two last arguments of
  6573. macro @code{AC_PATH_PROG} for looking for the @command{erl} program. For
  6574. example, to look for @command{erl} only in the @file{/usr/lib/erlang/bin}
  6575. directory:
  6576. @example
  6577. AC_ERLANG_PATH_ERL([not found], [/usr/lib/erlang/bin])
  6578. @end example
  6579. @end defmac
  6580. @defmac AC_ERLANG_NEED_ERL (@dvar{path, $PATH})
  6581. @acindex{ERLANG_NEED_ERL}
  6582. A simplified variant of the @code{AC_ERLANG_PATH_ERL} macro, that prints an
  6583. error message and exits the @command{configure} script if the @command{erl}
  6584. program is not found.
  6585. @end defmac
  6586. @node Fortran Compiler
  6587. @subsection Fortran Compiler Characteristics
  6588. @cindex Fortran
  6589. @cindex F77
  6590. The Autoconf Fortran support is divided into two categories: legacy
  6591. Fortran 77 macros (@code{F77}), and modern Fortran macros (@code{FC}).
  6592. The former are intended for traditional Fortran 77 code, and have output
  6593. variables like @code{F77}, @code{FFLAGS}, and @code{FLIBS}. The latter
  6594. are for newer programs that can (or must) compile under the newer
  6595. Fortran standards, and have output variables like @code{FC},
  6596. @code{FCFLAGS}, and @code{FCLIBS}.
  6597. Except for the macros @code{AC_FC_SRCEXT}, @code{AC_FC_FREEFORM},
  6598. @code{AC_FC_FIXEDFORM}, and @code{AC_FC_LINE_LENGTH} (see below), the
  6599. @code{FC} and @code{F77} macros behave almost identically, and so they
  6600. are documented together in this section.
  6601. @defmac AC_PROG_F77 (@ovar{compiler-search-list})
  6602. @acindex{PROG_F77}
  6603. @evindex F77
  6604. @evindex FFLAGS
  6605. @ovindex F77
  6606. @ovindex FFLAGS
  6607. @caindex f77_compiler_gnu
  6608. @caindex prog_f77_g
  6609. Determine a Fortran 77 compiler to use. If @code{F77} is not already
  6610. set in the environment, then check for @code{g77} and @code{f77}, and
  6611. then some other names. Set the output variable @code{F77} to the name
  6612. of the compiler found.
  6613. This macro may, however, be invoked with an optional first argument
  6614. which, if specified, must be a blank-separated list of Fortran 77
  6615. compilers to search for. This just gives the user an opportunity to
  6616. specify an alternative search list for the Fortran 77 compiler. For
  6617. example, if you didn't like the default order, then you could invoke
  6618. @code{AC_PROG_F77} like this:
  6619. @example
  6620. AC_PROG_F77([fl32 f77 fort77 xlf g77 f90 xlf90])
  6621. @end example
  6622. If using @code{g77} (the GNU Fortran 77 compiler), then
  6623. set the shell variable @code{G77} to @samp{yes}.
  6624. If the output variable @code{FFLAGS} was not already set in the
  6625. environment, then set it to @option{-g -02} for @code{g77} (or @option{-O2}
  6626. where @code{g77} does not accept @option{-g}). Otherwise, set
  6627. @code{FFLAGS} to @option{-g} for all other Fortran 77 compilers.
  6628. The result of the GNU test is cached in the
  6629. @code{ac_cv_f77_compiler_gnu} variable, acceptance of @option{-g} in the
  6630. @code{ac_cv_prog_f77_g} variable.
  6631. @end defmac
  6632. @defmac AC_PROG_FC (@ovar{compiler-search-list}, @ovar{dialect})
  6633. @acindex{PROG_FC}
  6634. @evindex FC
  6635. @evindex FCFLAGS
  6636. @ovindex FC
  6637. @ovindex FCFLAGS
  6638. @caindex fc_compiler_gnu
  6639. @caindex prog_fc_g
  6640. Determine a Fortran compiler to use. If @code{FC} is not already set in
  6641. the environment, then @code{dialect} is a hint to indicate what Fortran
  6642. dialect to search for; the default is to search for the newest available
  6643. dialect. Set the output variable @code{FC} to the name of the compiler
  6644. found.
  6645. By default, newer dialects are preferred over older dialects, but if
  6646. @code{dialect} is specified then older dialects are preferred starting
  6647. with the specified dialect. @code{dialect} can currently be one of
  6648. Fortran 77, Fortran 90, or Fortran 95. However, this is only a hint of
  6649. which compiler @emph{name} to prefer (e.g., @code{f90} or @code{f95}),
  6650. and no attempt is made to guarantee that a particular language standard
  6651. is actually supported. Thus, it is preferable that you avoid the
  6652. @code{dialect} option, and use AC_PROG_FC only for code compatible with
  6653. the latest Fortran standard.
  6654. This macro may, alternatively, be invoked with an optional first argument
  6655. which, if specified, must be a blank-separated list of Fortran
  6656. compilers to search for, just as in @code{AC_PROG_F77}.
  6657. If using @code{gfortran} or @code{g77} (the GNU Fortran compilers), then
  6658. set the shell variable @code{GFC} to @samp{yes}.
  6659. If the output variable @code{FCFLAGS} was not already set in the
  6660. environment, then set it to @option{-g -02} for GNU @code{g77} (or
  6661. @option{-O2} where @code{g77} does not accept @option{-g}). Otherwise,
  6662. set @code{FCFLAGS} to @option{-g} for all other Fortran compilers.
  6663. The result of the GNU test is cached in the @code{ac_cv_fc_compiler_gnu}
  6664. variable, acceptance of @option{-g} in the @code{ac_cv_prog_fc_g}
  6665. variable.
  6666. @end defmac
  6667. @defmac AC_PROG_F77_C_O
  6668. @defmacx AC_PROG_FC_C_O
  6669. @acindex{PROG_F77_C_O}
  6670. @acindex{PROG_FC_C_O}
  6671. @cvindex F77_NO_MINUS_C_MINUS_O
  6672. @cvindex FC_NO_MINUS_C_MINUS_O
  6673. @caindex prog_f77_c_o
  6674. @caindex prog_fc_c_o
  6675. Test whether the Fortran compiler accepts the options @option{-c} and
  6676. @option{-o} simultaneously, and define @code{F77_NO_MINUS_C_MINUS_O} or
  6677. @code{FC_NO_MINUS_C_MINUS_O}, respectively, if it does not.
  6678. The result of the test is cached in the @code{ac_cv_prog_f77_c_o} or
  6679. @code{ac_cv_prog_fc_c_o} variable, respectively.
  6680. @end defmac
  6681. The following macros check for Fortran compiler characteristics.
  6682. To check for characteristics not listed here, use
  6683. @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}) or
  6684. @code{AC_RUN_IFELSE} (@pxref{Runtime}), making sure to first set the
  6685. current language to Fortran 77 or Fortran via @code{AC_LANG([Fortran 77])}
  6686. or @code{AC_LANG(Fortran)} (@pxref{Language Choice}).
  6687. @defmac AC_F77_LIBRARY_LDFLAGS
  6688. @defmacx AC_FC_LIBRARY_LDFLAGS
  6689. @acindex{F77_LIBRARY_LDFLAGS}
  6690. @ovindex FLIBS
  6691. @acindex{FC_LIBRARY_LDFLAGS}
  6692. @ovindex FCLIBS
  6693. @caindex prog_f77_v
  6694. @caindex prog_fc_v
  6695. @caindex f77_libs
  6696. @caindex fc_libs
  6697. Determine the linker flags (e.g., @option{-L} and @option{-l}) for the
  6698. @dfn{Fortran intrinsic and runtime libraries} that are required to
  6699. successfully link a Fortran program or shared library. The output
  6700. variable @code{FLIBS} or @code{FCLIBS} is set to these flags (which
  6701. should be included after @code{LIBS} when linking).
  6702. This macro is intended to be used in those situations when it is
  6703. necessary to mix, e.g., C++ and Fortran source code in a single
  6704. program or shared library (@pxref{Mixing Fortran 77 With C and C++, , ,
  6705. automake, GNU Automake}).
  6706. For example, if object files from a C++ and Fortran compiler must be
  6707. linked together, then the C++ compiler/linker must be used for linking
  6708. (since special C++-ish things need to happen at link time like calling
  6709. global constructors, instantiating templates, enabling exception
  6710. support, etc.).
  6711. However, the Fortran intrinsic and runtime libraries must be linked in
  6712. as well, but the C++ compiler/linker doesn't know by default how to add
  6713. these Fortran 77 libraries. Hence, this macro was created to determine
  6714. these Fortran libraries.
  6715. The macros @code{AC_F77_DUMMY_MAIN} and @code{AC_FC_DUMMY_MAIN} or
  6716. @code{AC_F77_MAIN} and @code{AC_FC_MAIN} are probably also necessary to
  6717. link C/C++ with Fortran; see below. Further, it is highly recommended
  6718. that you use @code{AC_CONFIG_HEADERS} (@pxref{Configuration Headers})
  6719. because the complex defines that the function wrapper macros create
  6720. may not work with C/C++ compiler drivers.
  6721. These macros internally compute the flag needed to verbose linking
  6722. output and cache it in @code{ac_cv_prog_f77_v} or @code{ac_cv_prog_fc_v}
  6723. variables, respectively. The computed linker flags are cached in
  6724. @code{ac_cv_f77_libs} or @code{ac_cv_fc_libs}, respectively.
  6725. @end defmac
  6726. @defmac AC_F77_DUMMY_MAIN (@ovar{action-if-found}, @dvar{action-if-not-found, @
  6727. AC_MSG_FAILURE})
  6728. @defmacx AC_FC_DUMMY_MAIN (@ovar{action-if-found}, @dvar{action-if-not-found, @
  6729. AC_MSG_FAILURE})
  6730. @acindex{F77_DUMMY_MAIN}
  6731. @cvindex F77_DUMMY_MAIN
  6732. @acindex{FC_DUMMY_MAIN}
  6733. @cvindex FC_DUMMY_MAIN
  6734. @caindex f77_dummy_main
  6735. @caindex fc_dummy_main
  6736. With many compilers, the Fortran libraries detected by
  6737. @code{AC_F77_LIBRARY_LDFLAGS} or @code{AC_FC_LIBRARY_LDFLAGS} provide
  6738. their own @code{main} entry function that initializes things like
  6739. Fortran I/O, and which then calls a user-provided entry function named
  6740. (say) @code{MAIN__} to run the user's program. The
  6741. @code{AC_F77_DUMMY_MAIN} and @code{AC_FC_DUMMY_MAIN} or
  6742. @code{AC_F77_MAIN} and @code{AC_FC_MAIN} macros figure out how to deal with
  6743. this interaction.
  6744. When using Fortran for purely numerical functions (no I/O, etc.)@: often
  6745. one prefers to provide one's own @code{main} and skip the Fortran
  6746. library initializations. In this case, however, one may still need to
  6747. provide a dummy @code{MAIN__} routine in order to prevent linking errors
  6748. on some systems. @code{AC_F77_DUMMY_MAIN} or @code{AC_FC_DUMMY_MAIN}
  6749. detects whether any such routine is @emph{required} for linking, and
  6750. what its name is; the shell variable @code{F77_DUMMY_MAIN} or
  6751. @code{FC_DUMMY_MAIN} holds this name, @code{unknown} when no solution
  6752. was found, and @code{none} when no such dummy main is needed.
  6753. By default, @var{action-if-found} defines @code{F77_DUMMY_MAIN} or
  6754. @code{FC_DUMMY_MAIN} to the name of this routine (e.g., @code{MAIN__})
  6755. @emph{if} it is required. @var{action-if-not-found} defaults to
  6756. exiting with an error.
  6757. In order to link with Fortran routines, the user's C/C++ program should
  6758. then include the following code to define the dummy main if it is
  6759. needed:
  6760. @example
  6761. @c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.
  6762. #ifdef F77_DUMMY_MAIN
  6763. # ifdef __cplusplus
  6764. extern "C"
  6765. # endif
  6766. int F77_DUMMY_MAIN () @{ return 1; @}
  6767. #endif
  6768. @end example
  6769. (Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
  6770. Note that this macro is called automatically from @code{AC_F77_WRAPPERS}
  6771. or @code{AC_FC_WRAPPERS}; there is generally no need to call it
  6772. explicitly unless one wants to change the default actions.
  6773. The result of this macro is cached in the @code{ac_cv_f77_dummy_main} or
  6774. @code{ac_cv_fc_dummy_main} variable, respectively.
  6775. @end defmac
  6776. @defmac AC_F77_MAIN
  6777. @defmacx AC_FC_MAIN
  6778. @acindex{F77_MAIN}
  6779. @cvindex F77_MAIN
  6780. @acindex{FC_MAIN}
  6781. @cvindex FC_MAIN
  6782. @caindex f77_main
  6783. @caindex fc_main
  6784. As discussed above, many Fortran libraries allow you to provide an entry
  6785. point called (say) @code{MAIN__} instead of the usual @code{main}, which
  6786. is then called by a @code{main} function in the Fortran libraries that
  6787. initializes things like Fortran I/O@. The
  6788. @code{AC_F77_MAIN} and @code{AC_FC_MAIN} macros detect whether it is
  6789. @emph{possible} to utilize such an alternate main function, and defines
  6790. @code{F77_MAIN} and @code{FC_MAIN} to the name of the function. (If no
  6791. alternate main function name is found, @code{F77_MAIN} and @code{FC_MAIN} are
  6792. simply defined to @code{main}.)
  6793. Thus, when calling Fortran routines from C that perform things like I/O,
  6794. one should use this macro and declare the "main" function like so:
  6795. @example
  6796. @c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.
  6797. #ifdef __cplusplus
  6798. extern "C"
  6799. #endif
  6800. int F77_MAIN (int argc, char *argv[]);
  6801. @end example
  6802. (Again, replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
  6803. The result of this macro is cached in the @code{ac_cv_f77_main} or
  6804. @code{ac_cv_fc_main} variable, respectively.
  6805. @end defmac
  6806. @defmac AC_F77_WRAPPERS
  6807. @defmacx AC_FC_WRAPPERS
  6808. @acindex{F77_WRAPPERS}
  6809. @cvindex F77_FUNC
  6810. @cvindex F77_FUNC_
  6811. @acindex{FC_WRAPPERS}
  6812. @cvindex FC_FUNC
  6813. @cvindex FC_FUNC_
  6814. @caindex f77_mangling
  6815. @caindex fc_mangling
  6816. Defines C macros @code{F77_FUNC (name, NAME)}, @code{FC_FUNC (name, NAME)},
  6817. @code{F77_FUNC_(name, NAME)}, and @code{FC_FUNC_(name, NAME)} to properly
  6818. mangle the names of C/C++ identifiers, and identifiers with underscores,
  6819. respectively, so that they match the name-mangling scheme used by the
  6820. Fortran compiler.
  6821. Fortran is case-insensitive, and in order to achieve this the Fortran
  6822. compiler converts all identifiers into a canonical case and format. To
  6823. call a Fortran subroutine from C or to write a C function that is
  6824. callable from Fortran, the C program must explicitly use identifiers in
  6825. the format expected by the Fortran compiler. In order to do this, one
  6826. simply wraps all C identifiers in one of the macros provided by
  6827. @code{AC_F77_WRAPPERS} or @code{AC_FC_WRAPPERS}. For example, suppose
  6828. you have the following Fortran 77 subroutine:
  6829. @example
  6830. @c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.
  6831. subroutine foobar (x, y)
  6832. double precision x, y
  6833. y = 3.14159 * x
  6834. return
  6835. end
  6836. @end example
  6837. You would then declare its prototype in C or C++ as:
  6838. @example
  6839. @c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.
  6840. #define FOOBAR_F77 F77_FUNC (foobar, FOOBAR)
  6841. #ifdef __cplusplus
  6842. extern "C" /* prevent C++ name mangling */
  6843. #endif
  6844. void FOOBAR_F77 (double *x, double *y);
  6845. @end example
  6846. Note that we pass both the lowercase and uppercase versions of the
  6847. function name to @code{F77_FUNC} so that it can select the right one.
  6848. Note also that all parameters to Fortran 77 routines are passed as
  6849. pointers (@pxref{Mixing Fortran 77 With C and C++, , , automake, GNU
  6850. Automake}).
  6851. (Replace @code{F77} with @code{FC} for Fortran instead of Fortran 77.)
  6852. Although Autoconf tries to be intelligent about detecting the
  6853. name-mangling scheme of the Fortran compiler, there may be Fortran
  6854. compilers that it doesn't support yet. In this case, the above code
  6855. generates a compile-time error, but some other behavior
  6856. (e.g., disabling Fortran-related features) can be induced by checking
  6857. whether @code{F77_FUNC} or @code{FC_FUNC} is defined.
  6858. Now, to call that routine from a C program, we would do something like:
  6859. @example
  6860. @c If you change this example, adjust tests/fortran.at:AC_F77_DUMMY_MAIN usage.
  6861. @{
  6862. double x = 2.7183, y;
  6863. FOOBAR_F77 (&x, &y);
  6864. @}
  6865. @end example
  6866. If the Fortran identifier contains an underscore (e.g., @code{foo_bar}),
  6867. you should use @code{F77_FUNC_} or @code{FC_FUNC_} instead of
  6868. @code{F77_FUNC} or @code{FC_FUNC} (with the same arguments). This is
  6869. because some Fortran compilers mangle names differently if they contain
  6870. an underscore.
  6871. The name mangling scheme is encoded in the @code{ac_cv_f77_mangling} or
  6872. @code{ac_cv_fc_mangling} cache variable, respectively, and also used for
  6873. the @code{AC_F77_FUNC} and @code{AC_FC_FUNC} macros described below.
  6874. @end defmac
  6875. @defmac AC_F77_FUNC (@var{name}, @ovar{shellvar})
  6876. @defmacx AC_FC_FUNC (@var{name}, @ovar{shellvar})
  6877. @acindex{F77_FUNC}
  6878. @acindex{FC_FUNC}
  6879. Given an identifier @var{name}, set the shell variable @var{shellvar} to
  6880. hold the mangled version @var{name} according to the rules of the
  6881. Fortran linker (see also @code{AC_F77_WRAPPERS} or
  6882. @code{AC_FC_WRAPPERS}). @var{shellvar} is optional; if it is not
  6883. supplied, the shell variable is simply @var{name}. The purpose of
  6884. this macro is to give the caller a way to access the name-mangling
  6885. information other than through the C preprocessor as above, for example,
  6886. to call Fortran routines from some language other than C/C++.
  6887. @end defmac
  6888. @defmac AC_FC_SRCEXT (@var{ext}, @ovar{action-if-success}, @
  6889. @dvar{action-if-failure, AC_MSG_FAILURE})
  6890. @defmacx AC_FC_PP_SRCEXT (@var{ext}, @ovar{action-if-success}, @
  6891. @dvar{action-if-failure, AC_MSG_FAILURE})
  6892. @acindex{FC_SRCEXT}
  6893. @acindex{FC_PP_SRCEXT}
  6894. @caindex fc_srcext_@var{ext}
  6895. @caindex fc_pp_srcext_@var{ext}
  6896. By default, the @code{FC} macros perform their tests using a @file{.f}
  6897. extension for source-code files. Some compilers, however, only enable
  6898. newer language features for appropriately named files, e.g., Fortran 90
  6899. features only for @file{.f90} files, or preprocessing only with
  6900. @file{.F} files or maybe other upper-case extensions. On the other
  6901. hand, some other compilers expect all source files to end in @file{.f}
  6902. and require special flags to support other file name extensions. The
  6903. @code{AC_FC_SRCEXT} and @code{AC_FC_PP_SRCEXT} macros deal with these
  6904. issues.
  6905. The @code{AC_FC_SRCEXT} macro tries to get the @code{FC} compiler to
  6906. accept files ending with the extension @file{.@var{ext}} (i.e.,
  6907. @var{ext} does @emph{not} contain the dot). If any special compiler
  6908. flags are needed for this, it stores them in the output variable
  6909. @code{FCFLAGS_@var{ext}}. This extension and these flags are then used
  6910. for all subsequent @code{FC} tests (until @code{AC_FC_SRCEXT} or
  6911. @code{AC_FC_PP_SRCEXT} is called another time).
  6912. For example, you would use @code{AC_FC_SRCEXT(f90)} to employ the
  6913. @file{.f90} extension in future tests, and it would set the
  6914. @code{FCFLAGS_f90} output variable with any extra flags that are needed
  6915. to compile such files.
  6916. Similarly, the @code{AC_FC_PP_SRCEXT} macro tries to get the @code{FC}
  6917. compiler to preprocess and compile files with the extension
  6918. @file{.@var{ext}}. When both @command{fpp} and @command{cpp} style
  6919. preprocessing are provided, the former is preferred, as the latter may
  6920. treat continuation lines, @code{//} tokens, and white space differently
  6921. from what some Fortran dialects expect. Conversely, if you do not want
  6922. files to be preprocessed, use only lower-case characters in the file
  6923. name extension. Like with @code{AC_FC_SRCEXT(f90)}, any needed flags
  6924. are stored in the @code{FCFLAGS_@var{ext}} variable.
  6925. The @code{FCFLAGS_@var{ext}} flags can @emph{not} be simply absorbed
  6926. into @code{FCFLAGS}, for two reasons based on the limitations of some
  6927. compilers. First, only one @code{FCFLAGS_@var{ext}} can be used at a
  6928. time, so files with different extensions must be compiled separately.
  6929. Second, @code{FCFLAGS_@var{ext}} must appear @emph{immediately} before
  6930. the source-code file name when compiling. So, continuing the example
  6931. above, you might compile a @file{foo.f90} file in your makefile with the
  6932. command:
  6933. @example
  6934. foo.o: foo.f90
  6935. $(FC) -c $(FCFLAGS) $(FCFLAGS_f90) '$(srcdir)/foo.f90'
  6936. @end example
  6937. If @code{AC_FC_SRCEXT} or @code{AC_FC_PP_SRCEXT} succeeds in compiling
  6938. files with the @var{ext} extension, it calls @var{action-if-success}
  6939. (defaults to nothing). If it fails, and cannot find a way to make the
  6940. @code{FC} compiler accept such files, it calls @var{action-if-failure}
  6941. (defaults to exiting with an error message).
  6942. The @code{AC_FC_SRCEXT} and @code{AC_FC_PP_SRCEXT} macros cache their
  6943. results in @code{ac_cv_fc_srcext_@var{ext}} and
  6944. @code{ac_cv_fc_pp_srcext_@var{ext}} variables, respectively.
  6945. @end defmac
  6946. @defmac AC_FC_PP_DEFINE (@ovar{action-if-success}, @dvar{action-if-failure, @
  6947. AC_MSG_FAILURE})
  6948. @acindex{FC_PP_DEFINE}
  6949. @caindex fc_pp_define
  6950. Find a flag to specify defines for preprocessed Fortran. Not all
  6951. Fortran compilers use @option{-D}. Substitute @code{FC_DEFINE} with
  6952. the result and call @var{action-if-success} (defaults to nothing) if
  6953. successful, and @var{action-if-failure} (defaults to failing with an
  6954. error message) if not.
  6955. This macro calls @code{AC_FC_PP_SRCEXT([F])} in order to learn how to
  6956. preprocess a @file{conftest.F} file, but restores a previously used
  6957. Fortran source file extension afterwards again.
  6958. The result of this test is cached in the @code{ac_cv_fc_pp_define}
  6959. variable.
  6960. @end defmac
  6961. @defmac AC_FC_FREEFORM (@ovar{action-if-success}, @dvar{action-if-failure, @
  6962. AC_MSG_FAILURE})
  6963. @acindex{FC_FREEFORM}
  6964. @caindex fc_freeform
  6965. Try to ensure that the Fortran compiler (@code{$FC}) allows free-format
  6966. source code (as opposed to the older fixed-format style from Fortran
  6967. 77). If necessary, it may add some additional flags to @code{FCFLAGS}.
  6968. This macro is most important if you are using the default @file{.f}
  6969. extension, since many compilers interpret this extension as indicating
  6970. fixed-format source unless an additional flag is supplied. If you
  6971. specify a different extension with @code{AC_FC_SRCEXT}, such as
  6972. @file{.f90}, then @code{AC_FC_FREEFORM} ordinarily succeeds without
  6973. modifying @code{FCFLAGS}. For extensions which the compiler does not
  6974. know about, the flag set by the @code{AC_FC_SRCEXT} macro might let
  6975. the compiler assume Fortran 77 by default, however.
  6976. If @code{AC_FC_FREEFORM} succeeds in compiling free-form source, it
  6977. calls @var{action-if-success} (defaults to nothing). If it fails, it
  6978. calls @var{action-if-failure} (defaults to exiting with an error
  6979. message).
  6980. The result of this test, or @samp{none} or @samp{unknown}, is cached in
  6981. the @code{ac_cv_fc_freeform} variable.
  6982. @end defmac
  6983. @defmac AC_FC_FIXEDFORM (@ovar{action-if-success}, @dvar{action-if-failure, @
  6984. AC_MSG_FAILURE})
  6985. @acindex{FC_FIXEDFORM}
  6986. @caindex fc_fixedform
  6987. Try to ensure that the Fortran compiler (@code{$FC}) allows the old
  6988. fixed-format source code (as opposed to free-format style). If
  6989. necessary, it may add some additional flags to @code{FCFLAGS}.
  6990. This macro is needed for some compilers alias names like @command{xlf95}
  6991. which assume free-form source code by default, and in case you want to
  6992. use fixed-form source with an extension like @file{.f90} which many
  6993. compilers interpret as free-form by default. If you specify a different
  6994. extension with @code{AC_FC_SRCEXT}, such as @file{.f}, then
  6995. @code{AC_FC_FIXEDFORM} ordinarily succeeds without modifying
  6996. @code{FCFLAGS}.
  6997. If @code{AC_FC_FIXEDFORM} succeeds in compiling fixed-form source, it
  6998. calls @var{action-if-success} (defaults to nothing). If it fails, it
  6999. calls @var{action-if-failure} (defaults to exiting with an error
  7000. message).
  7001. The result of this test, or @samp{none} or @samp{unknown}, is cached in
  7002. the @code{ac_cv_fc_fixedform} variable.
  7003. @end defmac
  7004. @defmac AC_FC_LINE_LENGTH (@ovar{length}, @ovar{action-if-success}, @
  7005. @dvar{action-if-failure, AC_MSG_FAILURE})
  7006. @acindex{FC_LINE_LENGTH}
  7007. @caindex fc_line_length
  7008. Try to ensure that the Fortran compiler (@code{$FC}) accepts long source
  7009. code lines. The @var{length} argument may be given as 80, 132, or
  7010. unlimited, and defaults to 132. Note that line lengths above 254
  7011. columns are not portable, and some compilers do not accept more than 132
  7012. columns at least for fixed format source. If necessary, it may add some
  7013. additional flags to @code{FCFLAGS}.
  7014. If @code{AC_FC_LINE_LENGTH} succeeds in compiling fixed-form source, it
  7015. calls @var{action-if-success} (defaults to nothing). If it fails, it
  7016. calls @var{action-if-failure} (defaults to exiting with an error
  7017. message).
  7018. The result of this test, or @samp{none} or @samp{unknown}, is cached in
  7019. the @code{ac_cv_fc_line_length} variable.
  7020. @end defmac
  7021. @defmac AC_FC_CHECK_BOUNDS (@ovar{action-if-success}, @
  7022. @dvar{action-if-failure, AC_MSG_FAILURE})
  7023. @acindex{FC_CHECK_BOUNDS}
  7024. @caindex fc_check_bounds
  7025. The @code{AC_FC_CHECK_BOUNDS} macro tries to enable array bounds checking
  7026. in the Fortran compiler. If successful, the @var{action-if-success}
  7027. is called and any needed flags are added to @code{FCFLAGS}. Otherwise,
  7028. @var{action-if-failure} is called, which defaults to failing with an error
  7029. message. The macro currently requires Fortran 90 or a newer dialect.
  7030. The result of the macro is cached in the @code{ac_cv_fc_check_bounds}
  7031. variable.
  7032. @end defmac
  7033. @defmac AC_F77_IMPLICIT_NONE (@ovar{action-if-success}, @
  7034. @dvar{action-if-failure, AC_MSG_FAILURE})
  7035. @defmacx AC_FC_IMPLICIT_NONE (@ovar{action-if-success}, @
  7036. @dvar{action-if-failure, AC_MSG_FAILURE})
  7037. @acindex{F77_IMPLICIT_NONE}
  7038. @acindex{FC_IMPLICIT_NONE}
  7039. @caindex f77_implicit_none
  7040. @caindex fc_implicit_none
  7041. Try to disallow implicit declarations in the Fortran compiler. If
  7042. successful, @var{action-if-success} is called and any needed flags
  7043. are added to @code{FFLAGS} or @code{FCFLAGS}, respectively. Otherwise,
  7044. @var{action-if-failure} is called, which defaults to failing with an error
  7045. message.
  7046. The result of these macros are cached in the
  7047. @code{ac_cv_f77_implicit_none} and @code{ac_cv_fc_implicit_none}
  7048. variables, respectively.
  7049. @end defmac
  7050. @defmac AC_FC_MODULE_EXTENSION
  7051. @acindex{FC_MODULE_EXTENSION}
  7052. @caindex fc_module_ext
  7053. @ovindex FC_MODEXT
  7054. Find the Fortran 90 module file name extension. Most Fortran 90
  7055. compilers store module information in files separate from the object
  7056. files. The module files are usually named after the name of the module
  7057. rather than the source file name, with characters possibly turned to
  7058. upper case, plus an extension, often @file{.mod}.
  7059. Not all compilers use module files at all, or by default. The Cray
  7060. Fortran compiler requires @option{-e m} in order to store and search
  7061. module information in @file{.mod} files rather than in object files.
  7062. Likewise, the Fujitsu Fortran compilers uses the @option{-Am} option to
  7063. indicate how module information is stored.
  7064. The @code{AC_FC_MODULE_EXTENSION} macro computes the module extension
  7065. without the leading dot, and stores that in the @code{FC_MODEXT}
  7066. variable. If the compiler does not produce module files, or the
  7067. extension cannot be determined, @code{FC_MODEXT} is empty. Typically,
  7068. the result of this macro may be used in cleanup @command{make} rules as
  7069. follows:
  7070. @example
  7071. clean-modules:
  7072. -test -z "$(FC_MODEXT)" || rm -f *.$(FC_MODEXT)
  7073. @end example
  7074. The extension, or @samp{unknown}, is cached in the
  7075. @code{ac_cv_fc_module_ext} variable.
  7076. @end defmac
  7077. @defmac AC_FC_MODULE_FLAG (@ovar{action-if-success}, @
  7078. @dvar{action-if-failure, AC_MSG_FAILURE})
  7079. @acindex{FC_MODULE_FLAG}
  7080. @caindex fc_module_flag
  7081. @ovindex FC_MODINC
  7082. @ovindex ac_empty
  7083. Find the compiler flag to include Fortran 90 module information from
  7084. another directory, and store that in the @code{FC_MODINC} variable.
  7085. Call @var{action-if-success} (defaults to nothing) if successful, and
  7086. set @code{FC_MODINC} to empty and call @var{action-if-failure} (defaults
  7087. to exiting with an error message) if not.
  7088. Most Fortran 90 compilers provide a way to specify module directories.
  7089. Some have separate flags for the directory to write module files to,
  7090. and directories to search them in, whereas others only allow writing to
  7091. the current directory or to the first directory specified in the include
  7092. path. Further, with some compilers, the module search path and the
  7093. preprocessor search path can only be modified with the same flag. Thus,
  7094. for portability, write module files to the current directory only and
  7095. list that as first directory in the search path.
  7096. There may be no whitespace between @code{FC_MODINC} and the following
  7097. directory name, but @code{FC_MODINC} may contain trailing white space.
  7098. For example, if you use Automake and would like to search @file{../lib}
  7099. for module files, you can use the following:
  7100. @example
  7101. AM_FCFLAGS = $(FC_MODINC). $(FC_MODINC)../lib
  7102. @end example
  7103. Inside @command{configure} tests, you can use:
  7104. @example
  7105. if test -n "$FC_MODINC"; then
  7106. FCFLAGS="$FCFLAGS $FC_MODINC. $FC_MODINC../lib"
  7107. fi
  7108. @end example
  7109. The flag is cached in the @code{ac_cv_fc_module_flag} variable.
  7110. The substituted value of @code{FC_MODINC} may refer to the
  7111. @code{ac_empty} dummy placeholder empty variable, to avoid losing
  7112. the significant trailing whitespace in a @file{Makefile}.
  7113. @end defmac
  7114. @defmac AC_FC_MODULE_OUTPUT_FLAG (@ovar{action-if-success}, @
  7115. @dvar{action-if-failure, AC_MSG_FAILURE})
  7116. @acindex{FC_MODULE_OUTPUT_FLAG}
  7117. @caindex fc_module_output_flag
  7118. @ovindex FC_MODOUT
  7119. Find the compiler flag to write Fortran 90 module information to
  7120. another directory, and store that in the @code{FC_MODOUT} variable.
  7121. Call @var{action-if-success} (defaults to nothing) if successful, and
  7122. set @code{FC_MODOUT} to empty and call @var{action-if-failure} (defaults
  7123. to exiting with an error message) if not.
  7124. Not all Fortran 90 compilers write module files, and of those that do,
  7125. not all allow writing to a directory other than the current one, nor
  7126. do all have separate flags for writing and reading; see the description
  7127. of @code{AC_FC_MODULE_FLAG} above. If you need to be able to write to
  7128. another directory, for maximum portability use @code{FC_MODOUT} before
  7129. any @code{FC_MODINC} and include both the current directory and the one
  7130. you write to in the search path:
  7131. @example
  7132. AM_FCFLAGS = $(FC_MODOUT)../mod $(FC_MODINC)../mod $(FC_MODINC). @dots{}
  7133. @end example
  7134. The flag is cached in the @code{ac_cv_fc_module_output_flag} variable.
  7135. The substituted value of @code{FC_MODOUT} may refer to the
  7136. @code{ac_empty} dummy placeholder empty variable, to avoid losing
  7137. the significant trailing whitespace in a @file{Makefile}.
  7138. @end defmac
  7139. @node Go Compiler
  7140. @subsection Go Compiler Characteristics
  7141. @cindex Go
  7142. Autoconf provides basic support for the Go programming language when
  7143. using the @code{gccgo} compiler (there is currently no support for the
  7144. @code{6g} and @code{8g} compilers).
  7145. @defmac AC_PROG_GO (@ovar{compiler-search-list})
  7146. Find the Go compiler to use. Check whether the environment variable
  7147. @code{GOC} is set; if so, then set output variable @code{GOC} to its
  7148. value.
  7149. Otherwise, if the macro is invoked without an argument, then search for
  7150. a Go compiler named @code{gccgo}. If it is not found, then as a last
  7151. resort set @code{GOC} to @code{gccgo}.
  7152. This macro may be invoked with an optional first argument which, if
  7153. specified, must be a blank-separated list of Go compilers to search for.
  7154. If output variable @code{GOFLAGS} was not already set, set it to
  7155. @option{-g -O2}. If your package does not like this default,
  7156. @code{GOFLAGS} may be set before @code{AC_PROG_GO}.
  7157. @end defmac
  7158. @node System Services
  7159. @section System Services
  7160. The following macros check for operating system services or capabilities.
  7161. @anchor{AC_PATH_X}
  7162. @defmac AC_PATH_X
  7163. @acindex{PATH_X}
  7164. @evindex XMKMF
  7165. @cindex X Window System
  7166. Try to locate the X Window System include files and libraries. If the
  7167. user gave the command line options @option{--x-includes=@var{dir}} and
  7168. @option{--x-libraries=@var{dir}}, use those directories.
  7169. If either or both were not given, get the missing values by running
  7170. @code{xmkmf} (or an executable pointed to by the @code{XMKMF}
  7171. environment variable) on a trivial @file{Imakefile} and examining the
  7172. makefile that it produces. Setting @code{XMKMF} to @samp{false}
  7173. disables this method.
  7174. If this method fails to find the X Window System, @command{configure}
  7175. looks for the files in several directories where they often reside.
  7176. If either method is successful, set the shell variables
  7177. @code{x_includes} and @code{x_libraries} to their locations, unless they
  7178. are in directories the compiler searches by default.
  7179. If both methods fail, or the user gave the command line option
  7180. @option{--without-x}, set the shell variable @code{no_x} to @samp{yes};
  7181. otherwise set it to the empty string.
  7182. @end defmac
  7183. @anchor{AC_PATH_XTRA}
  7184. @defmac AC_PATH_XTRA
  7185. @acindex{PATH_XTRA}
  7186. @ovindex X_CFLAGS
  7187. @ovindex X_LIBS
  7188. @ovindex X_EXTRA_LIBS
  7189. @ovindex X_PRE_LIBS
  7190. @cvindex X_DISPLAY_MISSING
  7191. An enhanced version of @code{AC_PATH_X}. It adds the C compiler flags
  7192. that X needs to output variable @code{X_CFLAGS}, and the X linker flags
  7193. to @code{X_LIBS}. Define @code{X_DISPLAY_MISSING} if X is not
  7194. available.
  7195. This macro also checks for special libraries that some systems need in
  7196. order to compile X programs. It adds any that the system needs to
  7197. output variable @code{X_EXTRA_LIBS}. And it checks for special X11R6
  7198. libraries that need to be linked with before @option{-lX11}, and adds
  7199. any found to the output variable @code{X_PRE_LIBS}.
  7200. @c This is an incomplete kludge. Make a real way to do it.
  7201. @c If you need to check for other X functions or libraries yourself, then
  7202. @c after calling this macro, add the contents of @code{X_EXTRA_LIBS} to
  7203. @c @code{LIBS} temporarily, like this: (FIXME - add example)
  7204. @end defmac
  7205. @anchor{AC_SYS_INTERPRETER}
  7206. @defmac AC_SYS_INTERPRETER
  7207. @acindex{SYS_INTERPRETER}
  7208. Check whether the system supports starting scripts with a line of the
  7209. form @samp{#!/bin/sh} to select the interpreter to use for the script.
  7210. After running this macro, shell code in @file{configure.ac} can check
  7211. the shell variable @code{interpval}; it is set to @samp{yes}
  7212. if the system supports @samp{#!}, @samp{no} if not.
  7213. @end defmac
  7214. @defmac AC_SYS_LARGEFILE
  7215. @acindex{SYS_LARGEFILE}
  7216. @cvindex _FILE_OFFSET_BITS
  7217. @cvindex _LARGE_FILES
  7218. @ovindex CC
  7219. @cindex Large file support
  7220. @cindex LFS
  7221. Arrange for 64-bit file offsets, known as
  7222. @uref{http://@/www.unix-systems@/.org/@/version2/@/whatsnew/@/lfs20mar.html,
  7223. large-file support}. On some hosts, one must use special compiler
  7224. options to build programs that can access large files. Append any such
  7225. options to the output variable @code{CC}. Define
  7226. @code{_FILE_OFFSET_BITS} and @code{_LARGE_FILES} if necessary.
  7227. Large-file support can be disabled by configuring with the
  7228. @option{--disable-largefile} option.
  7229. If you use this macro, check that your program works even when
  7230. @code{off_t} is wider than @code{long int}, since this is common when
  7231. large-file support is enabled. For example, it is not correct to print
  7232. an arbitrary @code{off_t} value @code{X} with @code{printf ("%ld",
  7233. (long int) X)}.
  7234. The LFS introduced the @code{fseeko} and @code{ftello} functions to
  7235. replace their C counterparts @code{fseek} and @code{ftell} that do not
  7236. use @code{off_t}. Take care to use @code{AC_FUNC_FSEEKO} to make their
  7237. prototypes available when using them and large-file support is
  7238. enabled.
  7239. @end defmac
  7240. @anchor{AC_SYS_LONG_FILE_NAMES}
  7241. @defmac AC_SYS_LONG_FILE_NAMES
  7242. @acindex{SYS_LONG_FILE_NAMES}
  7243. @cvindex HAVE_LONG_FILE_NAMES
  7244. If the system supports file names longer than 14 characters, define
  7245. @code{HAVE_LONG_FILE_NAMES}.
  7246. @end defmac
  7247. @defmac AC_SYS_POSIX_TERMIOS
  7248. @acindex{SYS_POSIX_TERMIOS}
  7249. @cindex Posix termios headers
  7250. @cindex termios Posix headers
  7251. @caindex sys_posix_termios
  7252. Check to see if the Posix termios headers and functions are available on the
  7253. system. If so, set the shell variable @code{ac_cv_sys_posix_termios} to
  7254. @samp{yes}. If not, set the variable to @samp{no}.
  7255. @end defmac
  7256. @node Posix Variants
  7257. @section Posix Variants
  7258. The following macro makes it possible to use features of Posix that are
  7259. extensions to C, as well as platform extensions not defined by Posix.
  7260. @anchor{AC_USE_SYSTEM_EXTENSIONS}
  7261. @defmac AC_USE_SYSTEM_EXTENSIONS
  7262. @acindex{USE_SYSTEM_EXTENSIONS}
  7263. @cvindex _ALL_SOURCE
  7264. @cvindex _GNU_SOURCE
  7265. @cvindex _MINIX
  7266. @cvindex _POSIX_1_SOURCE
  7267. @cvindex _POSIX_PTHREAD_SEMANTICS
  7268. @cvindex _POSIX_SOURCE
  7269. @cvindex _TANDEM_SOURCE
  7270. @cvindex __EXTENSIONS__
  7271. This macro was introduced in Autoconf 2.60. If possible, enable
  7272. extensions to C or Posix on hosts that normally disable the extensions,
  7273. typically due to standards-conformance namespace issues. This should be
  7274. called before any macros that run the C compiler. The following
  7275. preprocessor macros are defined where appropriate:
  7276. @table @code
  7277. @item _GNU_SOURCE
  7278. Enable extensions on GNU/Linux.
  7279. @item __EXTENSIONS__
  7280. Enable general extensions on Solaris.
  7281. @item _POSIX_PTHREAD_SEMANTICS
  7282. Enable threading extensions on Solaris.
  7283. @item _TANDEM_SOURCE
  7284. Enable extensions for the HP NonStop platform.
  7285. @item _ALL_SOURCE
  7286. Enable extensions for AIX 3, and for Interix.
  7287. @item _POSIX_SOURCE
  7288. Enable Posix functions for Minix.
  7289. @item _POSIX_1_SOURCE
  7290. Enable additional Posix functions for Minix.
  7291. @item _MINIX
  7292. Identify Minix platform. This particular preprocessor macro is
  7293. obsolescent, and may be removed in a future release of Autoconf.
  7294. @end table
  7295. @end defmac
  7296. @node Erlang Libraries
  7297. @section Erlang Libraries
  7298. @cindex Erlang, Library, checking
  7299. The following macros check for an installation of Erlang/OTP, and for the
  7300. presence of certain Erlang libraries. All those macros require the
  7301. configuration of an Erlang interpreter and an Erlang compiler
  7302. (@pxref{Erlang Compiler and Interpreter}).
  7303. @defmac AC_ERLANG_SUBST_ERTS_VER
  7304. @acindex{ERLANG_SUBST_ERTS_VER}
  7305. @ovindex ERLANG_ERTS_VER
  7306. Set the output variable @code{ERLANG_ERTS_VER} to the version of the
  7307. Erlang runtime system (as returned by Erlang's
  7308. @code{erlang:system_info(version)} function). The result of this test
  7309. is cached if caching is enabled when running @command{configure}. The
  7310. @code{ERLANG_ERTS_VER} variable is not intended to be used for testing
  7311. for features of specific ERTS versions, but to be used for substituting
  7312. the ERTS version in Erlang/OTP release resource files (@code{.rel}
  7313. files), as shown below.
  7314. @end defmac
  7315. @defmac AC_ERLANG_SUBST_ROOT_DIR
  7316. @acindex{ERLANG_SUBST_ROOT_DIR}
  7317. @ovindex ERLANG_ROOT_DIR
  7318. Set the output variable @code{ERLANG_ROOT_DIR} to the path to the base
  7319. directory in which Erlang/OTP is installed (as returned by Erlang's
  7320. @code{code:root_dir/0} function). The result of this test is cached if
  7321. caching is enabled when running @command{configure}.
  7322. @end defmac
  7323. @defmac AC_ERLANG_SUBST_LIB_DIR
  7324. @acindex{ERLANG_SUBST_LIB_DIR}
  7325. @ovindex ERLANG_LIB_DIR
  7326. Set the output variable @code{ERLANG_LIB_DIR} to the path of the library
  7327. directory of Erlang/OTP (as returned by Erlang's
  7328. @code{code:lib_dir/0} function), which subdirectories each contain an installed
  7329. Erlang/OTP library. The result of this test is cached if caching is enabled
  7330. when running @command{configure}.
  7331. @end defmac
  7332. @defmac AC_ERLANG_CHECK_LIB (@var{library}, @ovar{action-if-found}, @
  7333. @ovar{action-if-not-found})
  7334. @acindex{ERLANG_CHECK_LIB}
  7335. @ovindex ERLANG_LIB_DIR_@var{library}
  7336. @ovindex ERLANG_LIB_VER_@var{library}
  7337. Test whether the Erlang/OTP library @var{library} is installed by
  7338. calling Erlang's @code{code:lib_dir/1} function. The result of this
  7339. test is cached if caching is enabled when running @command{configure}.
  7340. @var{action-if-found} is a list of shell commands to run if the library
  7341. is installed; @var{action-if-not-found} is a list of shell commands to
  7342. run if it is not. Additionally, if the library is installed, the output
  7343. variable @samp{ERLANG_LIB_DIR_@var{library}} is set to the path to the
  7344. library installation directory, and the output variable
  7345. @samp{ERLANG_LIB_VER_@var{library}} is set to the version number that is
  7346. part of the subdirectory name, if it is in the standard form
  7347. (@code{@var{library}-@var{version}}). If the directory name does not
  7348. have a version part, @samp{ERLANG_LIB_VER_@var{library}} is set to the
  7349. empty string. If the library is not installed,
  7350. @samp{ERLANG_LIB_DIR_@var{library}} and
  7351. @samp{ERLANG_LIB_VER_@var{library}} are set to @code{"not found"}. For
  7352. example, to check if library @code{stdlib} is installed:
  7353. @example
  7354. AC_ERLANG_CHECK_LIB([stdlib],
  7355. [echo "stdlib version \"$ERLANG_LIB_VER_stdlib\""
  7356. echo "is installed in \"$ERLANG_LIB_DIR_stdlib\""],
  7357. [AC_MSG_ERROR([stdlib was not found!])])
  7358. @end example
  7359. The @samp{ERLANG_LIB_VER_@var{library}} variables (set by
  7360. @code{AC_ERLANG_CHECK_LIB}) and the @code{ERLANG_ERTS_VER} variable (set
  7361. by @code{AC_ERLANG_SUBST_ERTS_VER}) are not intended to be used for
  7362. testing for features of specific versions of libraries or of the Erlang
  7363. runtime system. Those variables are intended to be substituted in
  7364. Erlang release resource files (@code{.rel} files). For instance, to
  7365. generate a @file{example.rel} file for an application depending on the
  7366. @code{stdlib} library, @file{configure.ac} could contain:
  7367. @example
  7368. AC_ERLANG_SUBST_ERTS_VER
  7369. AC_ERLANG_CHECK_LIB([stdlib],
  7370. [],
  7371. [AC_MSG_ERROR([stdlib was not found!])])
  7372. AC_CONFIG_FILES([example.rel])
  7373. @end example
  7374. @noindent
  7375. The @file{example.rel.in} file used to generate @file{example.rel}
  7376. should contain:
  7377. @example
  7378. @{release,
  7379. @{"@@PACKAGE@@", "@@VERSION@@"@},
  7380. @{erts, "@@ERLANG_ERTS_VER@@"@},
  7381. [@{stdlib, "@@ERLANG_LIB_VER_stdlib@@"@},
  7382. @{@@PACKAGE@@, "@@VERSION@@"@}]@}.
  7383. @end example
  7384. @end defmac
  7385. In addition to the above macros, which test installed Erlang libraries, the
  7386. following macros determine the paths to the directories into which newly built
  7387. Erlang libraries are to be installed:
  7388. @defmac AC_ERLANG_SUBST_INSTALL_LIB_DIR
  7389. @acindex{ERLANG_SUBST_INSTALL_LIB_DIR}
  7390. @ovindex ERLANG_INSTALL_LIB_DIR
  7391. Set the @code{ERLANG_INSTALL_LIB_DIR} output variable to the directory into
  7392. which every built Erlang library should be installed in a separate
  7393. subdirectory.
  7394. If this variable is not set in the environment when @command{configure} runs,
  7395. its default value is @code{$@{libdir@}/erlang/lib}.
  7396. @end defmac
  7397. @defmac AC_ERLANG_SUBST_INSTALL_LIB_SUBDIR (@var{library}, @var{version})
  7398. @acindex{ERLANG_SUBST_INSTALL_LIB_SUBDIR}
  7399. @ovindex ERLANG_INSTALL_LIB_DIR_@var{library}
  7400. Set the @samp{ERLANG_INSTALL_LIB_DIR_@var{library}} output variable to the
  7401. directory into which the built Erlang library @var{library} version
  7402. @var{version} should be installed. If this variable is not set in the
  7403. environment when @command{configure} runs, its default value is
  7404. @samp{$ERLANG_INSTALL_LIB_DIR/@var{library}-@var{version}}, the value of the
  7405. @code{ERLANG_INSTALL_LIB_DIR} variable being set by the
  7406. @code{AC_ERLANG_SUBST_INSTALL_LIB_DIR} macro.
  7407. @end defmac
  7408. @c ========================================================= Writing Tests
  7409. @node Writing Tests
  7410. @chapter Writing Tests
  7411. If the existing feature tests don't do something you need, you have to
  7412. write new ones. These macros are the building blocks. They provide
  7413. ways for other macros to check whether various kinds of features are
  7414. available and report the results.
  7415. This chapter contains some suggestions and some of the reasons why the
  7416. existing tests are written the way they are. You can also learn a lot
  7417. about how to write Autoconf tests by looking at the existing ones. If
  7418. something goes wrong in one or more of the Autoconf tests, this
  7419. information can help you understand the assumptions behind them, which
  7420. might help you figure out how to best solve the problem.
  7421. These macros check the output of the compiler system of the current
  7422. language (@pxref{Language Choice}). They do not cache the results of
  7423. their tests for future use (@pxref{Caching Results}), because they don't
  7424. know enough about the information they are checking for to generate a
  7425. cache variable name. They also do not print any messages, for the same
  7426. reason. The checks for particular kinds of features call these macros
  7427. and do cache their results and print messages about what they're
  7428. checking for.
  7429. When you write a feature test that could be applicable to more than one
  7430. software package, the best thing to do is encapsulate it in a new macro.
  7431. @xref{Writing Autoconf Macros}, for how to do that.
  7432. @menu
  7433. * Language Choice:: Selecting which language to use for testing
  7434. * Writing Test Programs:: Forging source files for compilers
  7435. * Running the Preprocessor:: Detecting preprocessor symbols
  7436. * Running the Compiler:: Detecting language or header features
  7437. * Running the Linker:: Detecting library features
  7438. * Runtime:: Testing for runtime features
  7439. * Systemology:: A zoology of operating systems
  7440. * Multiple Cases:: Tests for several possible values
  7441. @end menu
  7442. @node Language Choice
  7443. @section Language Choice
  7444. @cindex Language
  7445. Autoconf-generated @command{configure} scripts check for the C compiler and
  7446. its features by default. Packages that use other programming languages
  7447. (maybe more than one, e.g., C and C++) need to test features of the
  7448. compilers for the respective languages. The following macros determine
  7449. which programming language is used in the subsequent tests in
  7450. @file{configure.ac}.
  7451. @anchor{AC_LANG}
  7452. @defmac AC_LANG (@var{language})
  7453. @acindex{LANG}
  7454. Do compilation tests using the compiler, preprocessor, and file
  7455. extensions for the specified @var{language}.
  7456. Supported languages are:
  7457. @table @samp
  7458. @item C
  7459. Do compilation tests using @code{CC} and @code{CPP} and use extension
  7460. @file{.c} for test programs. Use compilation flags: @code{CPPFLAGS} with
  7461. @code{CPP}, and both @code{CPPFLAGS} and @code{CFLAGS} with @code{CC}.
  7462. @item C++
  7463. Do compilation tests using @code{CXX} and @code{CXXCPP} and use
  7464. extension @file{.C} for test programs. Use compilation flags:
  7465. @code{CPPFLAGS} with @code{CXXCPP}, and both @code{CPPFLAGS} and
  7466. @code{CXXFLAGS} with @code{CXX}.
  7467. @item Fortran 77
  7468. Do compilation tests using @code{F77} and use extension @file{.f} for
  7469. test programs. Use compilation flags: @code{FFLAGS}.
  7470. @item Fortran
  7471. Do compilation tests using @code{FC} and use extension @file{.f} (or
  7472. whatever has been set by @code{AC_FC_SRCEXT}) for test programs. Use
  7473. compilation flags: @code{FCFLAGS}.
  7474. @item Erlang
  7475. @ovindex ERLC
  7476. @ovindex ERL
  7477. @ovindex ERLCFLAGS
  7478. Compile and execute tests using @code{ERLC} and @code{ERL} and use extension
  7479. @file{.erl} for test Erlang modules. Use compilation flags: @code{ERLCFLAGS}.
  7480. @item Objective C
  7481. Do compilation tests using @code{OBJC} and @code{OBJCPP} and use
  7482. extension @file{.m} for test programs. Use compilation flags:
  7483. @code{CPPFLAGS} with @code{OBJCPP}, and both @code{CPPFLAGS} and
  7484. @code{OBJCFLAGS} with @code{OBJC}.
  7485. @item Objective C++
  7486. Do compilation tests using @code{OBJCXX} and @code{OBJCXXCPP} and use
  7487. extension @file{.mm} for test programs. Use compilation flags:
  7488. @code{CPPFLAGS} with @code{OBJCXXCPP}, and both @code{CPPFLAGS} and
  7489. @code{OBJCXXFLAGS} with @code{OBJCXX}.
  7490. @item Go
  7491. Do compilation tests using @code{GOC} and use extension @file{.go} for
  7492. test programs. Use compilation flags @code{GOFLAGS}.
  7493. @end table
  7494. @end defmac
  7495. @anchor{AC_LANG_PUSH}
  7496. @defmac AC_LANG_PUSH (@var{language})
  7497. @acindex{LANG_PUSH}
  7498. Remember the current language (as set by @code{AC_LANG}) on a stack, and
  7499. then select the @var{language}. Use this macro and @code{AC_LANG_POP}
  7500. in macros that need to temporarily switch to a particular language.
  7501. @end defmac
  7502. @defmac AC_LANG_POP (@ovar{language})
  7503. @acindex{LANG_POP}
  7504. Select the language that is saved on the top of the stack, as set by
  7505. @code{AC_LANG_PUSH}, and remove it from the stack.
  7506. If given, @var{language} specifies the language we just @emph{quit}. It
  7507. is a good idea to specify it when it's known (which should be the
  7508. case@dots{}), since Autoconf detects inconsistencies.
  7509. @example
  7510. AC_LANG_PUSH([Fortran 77])
  7511. # Perform some tests on Fortran 77.
  7512. # @dots{}
  7513. AC_LANG_POP([Fortran 77])
  7514. @end example
  7515. @end defmac
  7516. @defmac AC_LANG_ASSERT (@var{language})
  7517. @acindex{LANG_ASSERT}
  7518. Check statically that the current language is @var{language}.
  7519. You should use this in your language specific macros
  7520. to avoid that they be called with an inappropriate language.
  7521. This macro runs only at @command{autoconf} time, and incurs no cost at
  7522. @command{configure} time. Sadly enough and because Autoconf is a two
  7523. layer language @footnote{Because M4 is not aware of Sh code,
  7524. especially conditionals, some optimizations that look nice statically
  7525. may produce incorrect results at runtime.}, the macros
  7526. @code{AC_LANG_PUSH} and @code{AC_LANG_POP} cannot be ``optimizing'',
  7527. therefore as much as possible you ought to avoid using them to wrap
  7528. your code, rather, require from the user to run the macro with a
  7529. correct current language, and check it with @code{AC_LANG_ASSERT}.
  7530. And anyway, that may help the user understand she is running a Fortran
  7531. macro while expecting a result about her Fortran 77 compiler@enddots{}
  7532. @end defmac
  7533. @defmac AC_REQUIRE_CPP
  7534. @acindex{REQUIRE_CPP}
  7535. Ensure that whichever preprocessor would currently be used for tests has
  7536. been found. Calls @code{AC_REQUIRE} (@pxref{Prerequisite Macros}) with an
  7537. argument of either @code{AC_PROG_CPP} or @code{AC_PROG_CXXCPP},
  7538. depending on which language is current.
  7539. @end defmac
  7540. @node Writing Test Programs
  7541. @section Writing Test Programs
  7542. Autoconf tests follow a common scheme: feed some program with some
  7543. input, and most of the time, feed a compiler with some source file.
  7544. This section is dedicated to these source samples.
  7545. @menu
  7546. * Guidelines:: General rules for writing test programs
  7547. * Test Functions:: Avoiding pitfalls in test programs
  7548. * Generating Sources:: Source program boilerplate
  7549. @end menu
  7550. @node Guidelines
  7551. @subsection Guidelines for Test Programs
  7552. The most important rule to follow when writing testing samples is:
  7553. @center @emph{Look for realism.}
  7554. This motto means that testing samples must be written with the same
  7555. strictness as real programs are written. In particular, you should
  7556. avoid ``shortcuts'' and simplifications.
  7557. Don't just play with the preprocessor if you want to prepare a
  7558. compilation. For instance, using @command{cpp} to check whether a header is
  7559. functional might let your @command{configure} accept a header which
  7560. causes some @emph{compiler} error. Do not hesitate to check a header with
  7561. other headers included before, especially required headers.
  7562. Make sure the symbols you use are properly defined, i.e., refrain from
  7563. simply declaring a function yourself instead of including the proper
  7564. header.
  7565. Test programs should not write to standard output. They
  7566. should exit with status 0 if the test succeeds, and with status 1
  7567. otherwise, so that success
  7568. can be distinguished easily from a core dump or other failure;
  7569. segmentation violations and other failures produce a nonzero exit
  7570. status. Unless you arrange for @code{exit} to be declared, test
  7571. programs should @code{return}, not @code{exit}, from @code{main},
  7572. because on many systems @code{exit} is not declared by default.
  7573. Test programs can use @code{#if} or @code{#ifdef} to check the values of
  7574. preprocessor macros defined by tests that have already run. For
  7575. example, if you call @code{AC_HEADER_STDBOOL}, then later on in
  7576. @file{configure.ac} you can have a test program that includes
  7577. @file{stdbool.h} conditionally:
  7578. @example
  7579. @group
  7580. #ifdef HAVE_STDBOOL_H
  7581. # include <stdbool.h>
  7582. #endif
  7583. @end group
  7584. @end example
  7585. Both @code{#if HAVE_STDBOOL_H} and @code{#ifdef HAVE_STDBOOL_H} will
  7586. work with any standard C compiler. Some developers prefer @code{#if}
  7587. because it is easier to read, while others prefer @code{#ifdef} because
  7588. it avoids diagnostics with picky compilers like GCC with the
  7589. @option{-Wundef} option.
  7590. If a test program needs to use or create a data file, give it a name
  7591. that starts with @file{conftest}, such as @file{conftest.data}. The
  7592. @command{configure} script cleans up by running @samp{rm -f -r conftest*}
  7593. after running test programs and if the script is interrupted.
  7594. @node Test Functions
  7595. @subsection Test Functions
  7596. These days it's safe to assume support for function prototypes
  7597. (introduced in C89).
  7598. Functions that test programs declare should also be conditionalized for
  7599. C++, which requires @samp{extern "C"} prototypes. Make sure to not
  7600. include any header files containing clashing prototypes.
  7601. @example
  7602. #ifdef __cplusplus
  7603. extern "C"
  7604. #endif
  7605. void *valloc (size_t);
  7606. @end example
  7607. If a test program calls a function with invalid parameters (just to see
  7608. whether it exists), organize the program to ensure that it never invokes
  7609. that function. You can do this by calling it in another function that is
  7610. never invoked. You can't do it by putting it after a call to
  7611. @code{exit}, because GCC version 2 knows that @code{exit}
  7612. never returns
  7613. and optimizes out any code that follows it in the same block.
  7614. If you include any header files, be sure to call the functions
  7615. relevant to them with the correct number of arguments, even if they are
  7616. just 0, to avoid compilation errors due to prototypes. GCC
  7617. version 2
  7618. has internal prototypes for several functions that it automatically
  7619. inlines; for example, @code{memcpy}. To avoid errors when checking for
  7620. them, either pass them the correct number of arguments or redeclare them
  7621. with a different return type (such as @code{char}).
  7622. @node Generating Sources
  7623. @subsection Generating Sources
  7624. Autoconf provides a set of macros that can be used to generate test
  7625. source files. They are written to be language generic, i.e., they
  7626. actually depend on the current language (@pxref{Language Choice}) to
  7627. ``format'' the output properly.
  7628. @defmac AC_LANG_CONFTEST (@var{source})
  7629. @acindex{LANG_CONFTEST}
  7630. Save the @var{source} text in the current test source file:
  7631. @file{conftest.@var{extension}} where the @var{extension} depends on the
  7632. current language. As of Autoconf 2.63b, the source file also contains
  7633. the results of all of the @code{AC_DEFINE} performed so far.
  7634. Note that the @var{source} is evaluated exactly once, like regular
  7635. Autoconf macro arguments, and therefore (i) you may pass a macro
  7636. invocation, (ii) if not, be sure to double quote if needed.
  7637. This macro issues a warning during @command{autoconf} processing if
  7638. @var{source} does not include an expansion of the macro
  7639. @code{AC_LANG_DEFINES_PROVIDED} (note that both @code{AC_LANG_SOURCE} and
  7640. @code{AC_LANG_PROGRAM} call this macro, and thus avoid the warning).
  7641. This macro is seldom called directly, but is used under the hood by more
  7642. common macros such as @code{AC_COMPILE_IFELSE} and @code{AC_RUN_IFELSE}.
  7643. @end defmac
  7644. @defmac AC_LANG_DEFINES_PROVIDED
  7645. @acindex{LANG_DEFINES_PROVIDED}
  7646. This macro is called as a witness that the file
  7647. @file{conftest.@var{extension}} appropriate for the current language is
  7648. complete, including all previously determined results from
  7649. @code{AC_DEFINE}. This macro is seldom called directly, but exists if
  7650. you have a compelling reason to write a conftest file without using
  7651. @code{AC_LANG_SOURCE}, yet still want to avoid a syntax warning from
  7652. @code{AC_LANG_CONFTEST}.
  7653. @end defmac
  7654. @defmac AC_LANG_SOURCE (@var{source})
  7655. @acindex{LANG_SOURCE}
  7656. Expands into the @var{source}, with the definition of
  7657. all the @code{AC_DEFINE} performed so far. This macro includes an
  7658. expansion of @code{AC_LANG_DEFINES_PROVIDED}.
  7659. In many cases, you may find it more convenient to use the wrapper
  7660. @code{AC_LANG_PROGRAM}.
  7661. @end defmac
  7662. For instance, executing (observe the double quotation!):
  7663. @example
  7664. @c If you change this example, adjust tests/compile.at:AC_LANG_SOURCE example.
  7665. AC_INIT([Hello], [1.0], [bug-hello@@example.org], [],
  7666. [http://www.example.org/])
  7667. AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
  7668. [Greetings string.])
  7669. AC_LANG([C])
  7670. AC_LANG_CONFTEST(
  7671. [AC_LANG_SOURCE([[const char hw[] = "Hello, World\n";]])])
  7672. gcc -E -dD conftest.c
  7673. @end example
  7674. @noindent
  7675. on a system with @command{gcc} installed, results in:
  7676. @example
  7677. @c If you change this example, adjust tests/compile.at:AC_LANG_SOURCE example.
  7678. @dots{}
  7679. # 1 "conftest.c"
  7680. #define PACKAGE_NAME "Hello"
  7681. #define PACKAGE_TARNAME "hello"
  7682. #define PACKAGE_VERSION "1.0"
  7683. #define PACKAGE_STRING "Hello 1.0"
  7684. #define PACKAGE_BUGREPORT "bug-hello@@example.org"
  7685. #define PACKAGE_URL "http://www.example.org/"
  7686. #define HELLO_WORLD "Hello, World\n"
  7687. const char hw[] = "Hello, World\n";
  7688. @end example
  7689. When the test language is Fortran, Erlang, or Go, the @code{AC_DEFINE}
  7690. definitions are not automatically translated into constants in the
  7691. source code by this macro.
  7692. @defmac AC_LANG_PROGRAM (@var{prologue}, @var{body})
  7693. @acindex{LANG_PROGRAM}
  7694. Expands into a source file which consists of the @var{prologue}, and
  7695. then @var{body} as body of the main function (e.g., @code{main} in
  7696. C). Since it uses @code{AC_LANG_SOURCE}, the features of the latter are
  7697. available.
  7698. @end defmac
  7699. For instance:
  7700. @example
  7701. @c If you change this example, adjust tests/compile.at:AC_LANG_PROGRAM example.
  7702. AC_INIT([Hello], [1.0], [bug-hello@@example.org], [],
  7703. [http://www.example.org/])
  7704. AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
  7705. [Greetings string.])
  7706. AC_LANG_CONFTEST(
  7707. [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
  7708. [[fputs (hw, stdout);]])])
  7709. gcc -E -dD conftest.c
  7710. @end example
  7711. @noindent
  7712. on a system with @command{gcc} installed, results in:
  7713. @example
  7714. @c If you change this example, adjust tests/compile.at:AC_LANG_PROGRAM example.
  7715. @dots{}
  7716. # 1 "conftest.c"
  7717. #define PACKAGE_NAME "Hello"
  7718. #define PACKAGE_TARNAME "hello"
  7719. #define PACKAGE_VERSION "1.0"
  7720. #define PACKAGE_STRING "Hello 1.0"
  7721. #define PACKAGE_BUGREPORT "bug-hello@@example.org"
  7722. #define PACKAGE_URL "http://www.example.org/"
  7723. #define HELLO_WORLD "Hello, World\n"
  7724. const char hw[] = "Hello, World\n";
  7725. int
  7726. main ()
  7727. @{
  7728. fputs (hw, stdout);
  7729. ;
  7730. return 0;
  7731. @}
  7732. @end example
  7733. In Erlang tests, the created source file is that of an Erlang module called
  7734. @code{conftest} (@file{conftest.erl}). This module defines and exports
  7735. at least
  7736. one @code{start/0} function, which is called to perform the test. The
  7737. @var{prologue} is optional code that is inserted between the module header and
  7738. the @code{start/0} function definition. @var{body} is the body of the
  7739. @code{start/0} function without the final period (@pxref{Runtime}, about
  7740. constraints on this function's behavior).
  7741. For instance:
  7742. @example
  7743. AC_INIT([Hello], [1.0], [bug-hello@@example.org])
  7744. AC_LANG(Erlang)
  7745. AC_LANG_CONFTEST(
  7746. [AC_LANG_PROGRAM([[-define(HELLO_WORLD, "Hello, world!").]],
  7747. [[io:format("~s~n", [?HELLO_WORLD])]])])
  7748. cat conftest.erl
  7749. @end example
  7750. @noindent
  7751. results in:
  7752. @example
  7753. -module(conftest).
  7754. -export([start/0]).
  7755. -define(HELLO_WORLD, "Hello, world!").
  7756. start() ->
  7757. io:format("~s~n", [?HELLO_WORLD])
  7758. .
  7759. @end example
  7760. @defmac AC_LANG_CALL (@var{prologue}, @var{function})
  7761. @acindex{LANG_CALL}
  7762. Expands into a source file which consists of the @var{prologue}, and
  7763. then a call to the @var{function} as body of the main function (e.g.,
  7764. @code{main} in C). Since it uses @code{AC_LANG_PROGRAM}, the feature
  7765. of the latter are available.
  7766. This function will probably be replaced in the future by a version
  7767. which would enable specifying the arguments. The use of this macro is
  7768. not encouraged, as it violates strongly the typing system.
  7769. This macro cannot be used for Erlang tests.
  7770. @end defmac
  7771. @defmac AC_LANG_FUNC_LINK_TRY (@var{function})
  7772. @acindex{LANG_FUNC_LINK_TRY}
  7773. Expands into a source file which uses the @var{function} in the body of
  7774. the main function (e.g., @code{main} in C). Since it uses
  7775. @code{AC_LANG_PROGRAM}, the features of the latter are available.
  7776. As @code{AC_LANG_CALL}, this macro is documented only for completeness.
  7777. It is considered to be severely broken, and in the future will be
  7778. removed in favor of actual function calls (with properly typed
  7779. arguments).
  7780. This macro cannot be used for Erlang tests.
  7781. @end defmac
  7782. @node Running the Preprocessor
  7783. @section Running the Preprocessor
  7784. Sometimes one might need to run the preprocessor on some source file.
  7785. @emph{Usually it is a bad idea}, as you typically need to @emph{compile}
  7786. your project, not merely run the preprocessor on it; therefore you
  7787. certainly want to run the compiler, not the preprocessor. Resist the
  7788. temptation of following the easiest path.
  7789. Nevertheless, if you need to run the preprocessor, then use
  7790. @code{AC_PREPROC_IFELSE}.
  7791. The macros described in this section cannot be used for tests in Erlang,
  7792. Fortran, or Go, since those languages require no preprocessor.
  7793. @anchor{AC_PREPROC_IFELSE}
  7794. @defmac AC_PREPROC_IFELSE (@var{input}, @ovar{action-if-true}, @
  7795. @ovar{action-if-false})
  7796. @acindex{PREPROC_IFELSE}
  7797. Run the preprocessor of the current language (@pxref{Language Choice})
  7798. on the @var{input}, run the shell commands @var{action-if-true} on
  7799. success, @var{action-if-false} otherwise. The @var{input} can be made
  7800. by @code{AC_LANG_PROGRAM} and friends.
  7801. This macro uses @code{CPPFLAGS}, but not @code{CFLAGS}, because
  7802. @option{-g}, @option{-O}, etc.@: are not valid options to many C
  7803. preprocessors.
  7804. It is customary to report unexpected failures with
  7805. @code{AC_MSG_FAILURE}. If needed, @var{action-if-true} can further access
  7806. the preprocessed output in the file @file{conftest.i}.
  7807. @end defmac
  7808. For instance:
  7809. @example
  7810. AC_INIT([Hello], [1.0], [bug-hello@@example.org])
  7811. AC_DEFINE([HELLO_WORLD], ["Hello, World\n"],
  7812. [Greetings string.])
  7813. AC_PREPROC_IFELSE(
  7814. [AC_LANG_PROGRAM([[const char hw[] = "Hello, World\n";]],
  7815. [[fputs (hw, stdout);]])],
  7816. [AC_MSG_RESULT([OK])],
  7817. [AC_MSG_FAILURE([unexpected preprocessor failure])])
  7818. @end example
  7819. @noindent
  7820. results in:
  7821. @example
  7822. checking for gcc... gcc
  7823. checking for C compiler default output file name... a.out
  7824. checking whether the C compiler works... yes
  7825. checking whether we are cross compiling... no
  7826. checking for suffix of executables...
  7827. checking for suffix of object files... o
  7828. checking whether we are using the GNU C compiler... yes
  7829. checking whether gcc accepts -g... yes
  7830. checking for gcc option to accept ISO C89... none needed
  7831. checking how to run the C preprocessor... gcc -E
  7832. OK
  7833. @end example
  7834. @sp 1
  7835. The macro @code{AC_TRY_CPP} (@pxref{Obsolete Macros}) used to play the
  7836. role of @code{AC_PREPROC_IFELSE}, but double quotes its argument, making
  7837. it impossible to use it to elaborate sources. You are encouraged to
  7838. get rid of your old use of the macro @code{AC_TRY_CPP} in favor of
  7839. @code{AC_PREPROC_IFELSE}, but, in the first place, are you sure you need
  7840. to run the @emph{preprocessor} and not the compiler?
  7841. @anchor{AC_EGREP_HEADER}
  7842. @defmac AC_EGREP_HEADER (@var{pattern}, @var{header-file}, @
  7843. @var{action-if-found}, @ovar{action-if-not-found})
  7844. @acindex{EGREP_HEADER}
  7845. If the output of running the preprocessor on the system header file
  7846. @var{header-file} matches the extended regular expression
  7847. @var{pattern}, execute shell commands @var{action-if-found}, otherwise
  7848. execute @var{action-if-not-found}.
  7849. @end defmac
  7850. @anchor{AC_EGREP_CPP}
  7851. @defmac AC_EGREP_CPP (@var{pattern}, @var{program}, @
  7852. @ovar{action-if-found}, @ovar{action-if-not-found})
  7853. @acindex{EGREP_CPP}
  7854. @var{program} is the text of a C or C++ program, on which shell
  7855. variable, back quote, and backslash substitutions are performed. If the
  7856. output of running the preprocessor on @var{program} matches the
  7857. extended regular expression @var{pattern}, execute shell commands
  7858. @var{action-if-found}, otherwise execute @var{action-if-not-found}.
  7859. @end defmac
  7860. @node Running the Compiler
  7861. @section Running the Compiler
  7862. To check for a syntax feature of the current language's (@pxref{Language
  7863. Choice}) compiler, such as whether it recognizes a certain keyword, or
  7864. simply to try some library feature, use @code{AC_COMPILE_IFELSE} to try
  7865. to compile a small program that uses that feature.
  7866. @defmac AC_COMPILE_IFELSE (@var{input}, @ovar{action-if-true}, @
  7867. @ovar{action-if-false})
  7868. @acindex{COMPILE_IFELSE}
  7869. Run the compiler and compilation flags of the current language
  7870. (@pxref{Language Choice}) on the @var{input}, run the shell commands
  7871. @var{action-if-true} on success, @var{action-if-false} otherwise. The
  7872. @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.
  7873. It is customary to report unexpected failures with
  7874. @code{AC_MSG_FAILURE}. This macro does not try to link; use
  7875. @code{AC_LINK_IFELSE} if you need to do that (@pxref{Running the
  7876. Linker}). If needed, @var{action-if-true} can further access the
  7877. just-compiled object file @file{conftest.$OBJEXT}.
  7878. This macro uses @code{AC_REQUIRE} for the compiler associated with the
  7879. current language, which means that if the compiler has not yet been
  7880. determined, the compiler determination will be made prior to the body of
  7881. the outermost @code{AC_DEFUN} macro that triggered this macro to
  7882. expand (@pxref{Expanded Before Required}).
  7883. @end defmac
  7884. @ovindex ERL
  7885. For tests in Erlang, the @var{input} must be the source code of a module named
  7886. @code{conftest}. @code{AC_COMPILE_IFELSE} generates a @file{conftest.beam}
  7887. file that can be interpreted by the Erlang virtual machine (@code{ERL}). It is
  7888. recommended to use @code{AC_LANG_PROGRAM} to specify the test program,
  7889. to ensure that the Erlang module has the right name.
  7890. @node Running the Linker
  7891. @section Running the Linker
  7892. To check for a library, a function, or a global variable, Autoconf
  7893. @command{configure} scripts try to compile and link a small program that
  7894. uses it. This is unlike Metaconfig, which by default uses @code{nm} or
  7895. @code{ar} on the C library to try to figure out which functions are
  7896. available. Trying to link with the function is usually a more reliable
  7897. approach because it avoids dealing with the variations in the options
  7898. and output formats of @code{nm} and @code{ar} and in the location of the
  7899. standard libraries. It also allows configuring for cross-compilation or
  7900. checking a function's runtime behavior if needed. On the other hand,
  7901. it can be slower than scanning the libraries once, but accuracy is more
  7902. important than speed.
  7903. @code{AC_LINK_IFELSE} is used to compile test programs to test for
  7904. functions and global variables. It is also used by @code{AC_CHECK_LIB}
  7905. to check for libraries (@pxref{Libraries}), by adding the library being
  7906. checked for to @code{LIBS} temporarily and trying to link a small
  7907. program.
  7908. @anchor{AC_LINK_IFELSE}
  7909. @defmac AC_LINK_IFELSE (@var{input}, @ovar{action-if-true}, @
  7910. @ovar{action-if-false})
  7911. @acindex{LINK_IFELSE}
  7912. Run the compiler (and compilation flags) and the linker of the current
  7913. language (@pxref{Language Choice}) on the @var{input}, run the shell
  7914. commands @var{action-if-true} on success, @var{action-if-false}
  7915. otherwise. The @var{input} can be made by @code{AC_LANG_PROGRAM} and
  7916. friends. If needed, @var{action-if-true} can further access the
  7917. just-linked program file @file{conftest$EXEEXT}.
  7918. @code{LDFLAGS} and @code{LIBS} are used for linking, in addition to the
  7919. current compilation flags.
  7920. It is customary to report unexpected failures with
  7921. @code{AC_MSG_FAILURE}. This macro does not try to execute the program;
  7922. use @code{AC_RUN_IFELSE} if you need to do that (@pxref{Runtime}).
  7923. @end defmac
  7924. The @code{AC_LINK_IFELSE} macro cannot be used for Erlang tests, since Erlang
  7925. programs are interpreted and do not require linking.
  7926. @node Runtime
  7927. @section Checking Runtime Behavior
  7928. Sometimes you need to find out how a system performs at runtime, such
  7929. as whether a given function has a certain capability or bug. If you
  7930. can, make such checks when your program runs instead of when it is
  7931. configured. You can check for things like the machine's endianness when
  7932. your program initializes itself.
  7933. If you really need to test for a runtime behavior while configuring,
  7934. you can write a test program to determine the result, and compile and
  7935. run it using @code{AC_RUN_IFELSE}. Avoid running test programs if
  7936. possible, because this prevents people from configuring your package for
  7937. cross-compiling.
  7938. @anchor{AC_RUN_IFELSE}
  7939. @defmac AC_RUN_IFELSE (@var{input}, @ovar{action-if-true}, @
  7940. @ovar{action-if-false}, @dvar{action-if-cross-compiling, AC_MSG_FAILURE})
  7941. @acindex{RUN_IFELSE}
  7942. Run the compiler (and compilation flags) and the linker of the current
  7943. language (@pxref{Language Choice}) on the @var{input}, then execute the
  7944. resulting program. If the program returns an exit
  7945. status of 0 when executed, run shell commands @var{action-if-true}.
  7946. Otherwise, run shell commands @var{action-if-false}.
  7947. The @var{input} can be made by @code{AC_LANG_PROGRAM} and friends.
  7948. @code{LDFLAGS} and @code{LIBS} are used for linking, in addition to the
  7949. compilation flags of the current language (@pxref{Language Choice}).
  7950. Additionally, @var{action-if-true} can run @command{./conftest$EXEEXT}
  7951. for further testing.
  7952. In the @var{action-if-false} section, the failing exit status is
  7953. available in the shell variable @samp{$?}. This exit status might be
  7954. that of a failed compilation, or it might be that of a failed program
  7955. execution.
  7956. If cross-compilation mode is enabled (this is the case if either the
  7957. compiler being used does not produce executables that run on the system
  7958. where @command{configure} is being run, or if the options @code{--build}
  7959. and @code{--host} were both specified and their values are different),
  7960. then the test program is
  7961. not run. If the optional shell commands @var{action-if-cross-compiling}
  7962. are given, those commands are run instead; typically these commands
  7963. provide pessimistic defaults that allow cross-compilation to work even
  7964. if the guess was wrong. If the fourth argument is empty or omitted, but
  7965. cross-compilation is detected, then @command{configure} prints an error
  7966. message and exits. If you want your package to be useful in a
  7967. cross-compilation scenario, you @emph{should} provide a non-empty
  7968. @var{action-if-cross-compiling} clause, as well as wrap the
  7969. @code{AC_RUN_IFELSE} compilation inside an @code{AC_CACHE_CHECK}
  7970. (@pxref{Caching Results}) which allows the user to override the
  7971. pessimistic default if needed.
  7972. It is customary to report unexpected failures with
  7973. @code{AC_MSG_FAILURE}.
  7974. @end defmac
  7975. @command{autoconf} prints a warning message when creating
  7976. @command{configure} each time it encounters a call to
  7977. @code{AC_RUN_IFELSE} with no @var{action-if-cross-compiling} argument
  7978. given. If you are not concerned about users configuring your package
  7979. for cross-compilation, you may ignore the warning. A few of the macros
  7980. distributed with Autoconf produce this warning message; but if this is a
  7981. problem for you, please report it as a bug, along with an appropriate
  7982. pessimistic guess to use instead.
  7983. To configure for cross-compiling you can also choose a value for those
  7984. parameters based on the canonical system name (@pxref{Manual
  7985. Configuration}). Alternatively, set up a test results cache file with
  7986. the correct values for the host system (@pxref{Caching Results}).
  7987. @ovindex cross_compiling
  7988. To provide a default for calls of @code{AC_RUN_IFELSE} that are embedded
  7989. in other macros, including a few of the ones that come with Autoconf,
  7990. you can test whether the shell variable @code{cross_compiling} is set to
  7991. @samp{yes}, and then use an alternate method to get the results instead
  7992. of calling the macros.
  7993. It is also permissible to temporarily assign to @code{cross_compiling}
  7994. in order to force tests to behave as though they are in a
  7995. cross-compilation environment, particularly since this provides a way to
  7996. test your @var{action-if-cross-compiling} even when you are not using a
  7997. cross-compiler.
  7998. @example
  7999. # We temporarily set cross-compile mode to force AC_COMPUTE_INT
  8000. # to use the slow link-only method
  8001. save_cross_compiling=$cross_compiling
  8002. cross_compiling=yes
  8003. AC_COMPUTE_INT([@dots{}])
  8004. cross_compiling=$save_cross_compiling
  8005. @end example
  8006. A C or C++ runtime test should be portable.
  8007. @xref{Portable C and C++}.
  8008. Erlang tests must exit themselves the Erlang VM by calling the @code{halt/1}
  8009. function: the given status code is used to determine the success of the test
  8010. (status is @code{0}) or its failure (status is different than @code{0}), as
  8011. explained above. It must be noted that data output through the standard output
  8012. (e.g., using @code{io:format/2}) may be truncated when halting the VM.
  8013. Therefore, if a test must output configuration information, it is recommended
  8014. to create and to output data into the temporary file named @file{conftest.out},
  8015. using the functions of module @code{file}. The @code{conftest.out} file is
  8016. automatically deleted by the @code{AC_RUN_IFELSE} macro. For instance, a
  8017. simplified implementation of Autoconf's @code{AC_ERLANG_SUBST_LIB_DIR}
  8018. macro is:
  8019. @example
  8020. AC_INIT([LibdirTest], [1.0], [bug-libdirtest@@example.org])
  8021. AC_ERLANG_NEED_ERL
  8022. AC_LANG(Erlang)
  8023. AC_RUN_IFELSE(
  8024. [AC_LANG_PROGRAM([], [dnl
  8025. file:write_file("conftest.out", code:lib_dir()),
  8026. halt(0)])],
  8027. [echo "code:lib_dir() returned: `cat conftest.out`"],
  8028. [AC_MSG_FAILURE([test Erlang program execution failed])])
  8029. @end example
  8030. @node Systemology
  8031. @section Systemology
  8032. @cindex Systemology
  8033. This section aims at presenting some systems and pointers to
  8034. documentation. It may help you addressing particular problems reported
  8035. by users.
  8036. @uref{http://@/www.opengroup.org/@/susv3, Posix-conforming systems} are
  8037. derived from the @uref{http://@/www.bell-labs.com/@/history/@/unix/, Unix
  8038. operating system}.
  8039. The @uref{http://@/bhami.com/@/rosetta.html, Rosetta Stone for Unix}
  8040. contains a table correlating the features of various Posix-conforming
  8041. systems. @uref{http://@/www.levenez.com/@/unix/, Unix History} is a
  8042. simplified diagram of how many Unix systems were derived from each
  8043. other.
  8044. @uref{http://@/heirloom.sourceforge.net/, The Heirloom Project}
  8045. provides some variants of traditional implementations of Unix utilities.
  8046. @table @asis
  8047. @item Darwin
  8048. @cindex Darwin
  8049. Darwin is also known as Mac OS X@. Beware that the file system @emph{can} be
  8050. case-preserving, but case insensitive. This can cause nasty problems,
  8051. since for instance the installation attempt for a package having an
  8052. @file{INSTALL} file can result in @samp{make install} report that
  8053. nothing was to be done!
  8054. That's all dependent on whether the file system is a UFS (case
  8055. sensitive) or HFS+ (case preserving). By default Apple wants you to
  8056. install the OS on HFS+. Unfortunately, there are some pieces of
  8057. software which really need to be built on UFS@. We may want to rebuild
  8058. Darwin to have both UFS and HFS+ available (and put the /local/build
  8059. tree on the UFS).
  8060. @item QNX 4.25
  8061. @cindex QNX 4.25
  8062. @c FIXME: Please, if you feel like writing something more precise,
  8063. @c it'd be great. In particular, I can't understand the difference with
  8064. @c QNX Neutrino.
  8065. QNX is a realtime operating system running on Intel architecture
  8066. meant to be scalable from the small embedded systems to the hundred
  8067. processor super-computer. It claims to be Posix certified. More
  8068. information is available on the
  8069. @uref{http://@/www.qnx.com/, QNX home page}.
  8070. @item Tru64
  8071. @cindex Tru64
  8072. @uref{http://@/h30097.www3.hp.com/@/docs/,
  8073. Documentation of several versions of Tru64} is available in different
  8074. formats.
  8075. @item Unix version 7
  8076. @cindex Unix version 7
  8077. @cindex V7
  8078. Officially this was called the ``Seventh Edition'' of ``the UNIX
  8079. time-sharing system'' but we use the more-common name ``Unix version 7''.
  8080. Documentation is available in the
  8081. @uref{http://@/plan9.bell-labs.com/@/7thEdMan/, Unix Seventh Edition Manual}.
  8082. Previous versions of Unix are called ``Unix version 6'', etc., but
  8083. they were not as widely used.
  8084. @end table
  8085. @node Multiple Cases
  8086. @section Multiple Cases
  8087. Some operations are accomplished in several possible ways, depending on
  8088. the OS variant. Checking for them essentially requires a ``case
  8089. statement''. Autoconf does not directly provide one; however, it is
  8090. easy to simulate by using a shell variable to keep track of whether a
  8091. way to perform the operation has been found yet.
  8092. Here is an example that uses the shell variable @code{fstype} to keep
  8093. track of whether the remaining cases need to be checked. Note that
  8094. since the value of @code{fstype} is under our control, we don't have to
  8095. use the longer @samp{test "x$fstype" = xno}.
  8096. @example
  8097. @group
  8098. AC_MSG_CHECKING([how to get file system type])
  8099. fstype=no
  8100. # The order of these tests is important.
  8101. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statvfs.h>
  8102. #include <sys/fstyp.h>]])],
  8103. [AC_DEFINE([FSTYPE_STATVFS], [1],
  8104. [Define if statvfs exists.])
  8105. fstype=SVR4])
  8106. if test $fstype = no; then
  8107. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
  8108. #include <sys/fstyp.h>]])],
  8109. [AC_DEFINE([FSTYPE_USG_STATFS], [1],
  8110. [Define if USG statfs.])
  8111. fstype=SVR3])
  8112. fi
  8113. if test $fstype = no; then
  8114. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/statfs.h>
  8115. #include <sys/vmount.h>]])]),
  8116. [AC_DEFINE([FSTYPE_AIX_STATFS], [1],
  8117. [Define if AIX statfs.])
  8118. fstype=AIX])
  8119. fi
  8120. # (more cases omitted here)
  8121. AC_MSG_RESULT([$fstype])
  8122. @end group
  8123. @end example
  8124. @c ====================================================== Results of Tests.
  8125. @node Results
  8126. @chapter Results of Tests
  8127. Once @command{configure} has determined whether a feature exists, what can
  8128. it do to record that information? There are four sorts of things it can
  8129. do: define a C preprocessor symbol, set a variable in the output files,
  8130. save the result in a cache file for future @command{configure} runs, and
  8131. print a message letting the user know the result of the test.
  8132. @menu
  8133. * Defining Symbols:: Defining C preprocessor symbols
  8134. * Setting Output Variables:: Replacing variables in output files
  8135. * Special Chars in Variables:: Characters to beware of in variables
  8136. * Caching Results:: Speeding up subsequent @command{configure} runs
  8137. * Printing Messages:: Notifying @command{configure} users
  8138. @end menu
  8139. @node Defining Symbols
  8140. @section Defining C Preprocessor Symbols
  8141. A common action to take in response to a feature test is to define a C
  8142. preprocessor symbol indicating the results of the test. That is done by
  8143. calling @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}.
  8144. By default, @code{AC_OUTPUT} places the symbols defined by these macros
  8145. into the output variable @code{DEFS}, which contains an option
  8146. @option{-D@var{symbol}=@var{value}} for each symbol defined. Unlike in
  8147. Autoconf version 1, there is no variable @code{DEFS} defined while
  8148. @command{configure} is running. To check whether Autoconf macros have
  8149. already defined a certain C preprocessor symbol, test the value of the
  8150. appropriate cache variable, as in this example:
  8151. @example
  8152. AC_CHECK_FUNC([vprintf], [AC_DEFINE([HAVE_VPRINTF], [1],
  8153. [Define if vprintf exists.])])
  8154. if test "x$ac_cv_func_vprintf" != xyes; then
  8155. AC_CHECK_FUNC([_doprnt], [AC_DEFINE([HAVE_DOPRNT], [1],
  8156. [Define if _doprnt exists.])])
  8157. fi
  8158. @end example
  8159. If @code{AC_CONFIG_HEADERS} has been called, then instead of creating
  8160. @code{DEFS}, @code{AC_OUTPUT} creates a header file by substituting the
  8161. correct values into @code{#define} statements in a template file.
  8162. @xref{Configuration Headers}, for more information about this kind of
  8163. output.
  8164. @defmac AC_DEFINE (@var{variable}, @var{value}, @ovar{description})
  8165. @defmacx AC_DEFINE (@var{variable})
  8166. @cvindex @var{variable}
  8167. @acindex{DEFINE}
  8168. Define @var{variable} to @var{value} (verbatim), by defining a C
  8169. preprocessor macro for @var{variable}. @var{variable} should be a C
  8170. identifier, optionally suffixed by a parenthesized argument list to
  8171. define a C preprocessor macro with arguments. The macro argument list,
  8172. if present, should be a comma-separated list of C identifiers, possibly
  8173. terminated by an ellipsis @samp{...} if C99 syntax is employed.
  8174. @var{variable} should not contain comments, white space, trigraphs,
  8175. backslash-newlines, universal character names, or non-ASCII
  8176. characters.
  8177. @var{value} may contain backslash-escaped newlines, which will be
  8178. preserved if you use @code{AC_CONFIG_HEADERS} but flattened if passed
  8179. via @code{@@DEFS@@} (with no effect on the compilation, since the
  8180. preprocessor sees only one line in the first place). @var{value} should
  8181. not contain raw newlines. If you are not using
  8182. @code{AC_CONFIG_HEADERS}, @var{value} should not contain any @samp{#}
  8183. characters, as @command{make} tends to eat them. To use a shell
  8184. variable, use @code{AC_DEFINE_UNQUOTED} instead.
  8185. @var{description} is only useful if you are using
  8186. @code{AC_CONFIG_HEADERS}. In this case, @var{description} is put into
  8187. the generated @file{config.h.in} as the comment before the macro define.
  8188. The following example defines the C preprocessor variable
  8189. @code{EQUATION} to be the string constant @samp{"$a > $b"}:
  8190. @example
  8191. AC_DEFINE([EQUATION], ["$a > $b"],
  8192. [Equation string.])
  8193. @end example
  8194. If neither @var{value} nor @var{description} are given, then
  8195. @var{value} defaults to 1 instead of to the empty string. This is for
  8196. backwards compatibility with older versions of Autoconf, but this usage
  8197. is obsolescent and may be withdrawn in future versions of Autoconf.
  8198. If the @var{variable} is a literal string, it is passed to
  8199. @code{m4_pattern_allow} (@pxref{Forbidden Patterns}).
  8200. If multiple @code{AC_DEFINE} statements are executed for the same
  8201. @var{variable} name (not counting any parenthesized argument list),
  8202. the last one wins.
  8203. @end defmac
  8204. @defmac AC_DEFINE_UNQUOTED (@var{variable}, @var{value}, @ovar{description})
  8205. @defmacx AC_DEFINE_UNQUOTED (@var{variable})
  8206. @acindex{DEFINE_UNQUOTED}
  8207. @cvindex @var{variable}
  8208. Like @code{AC_DEFINE}, but three shell expansions are
  8209. performed---once---on @var{variable} and @var{value}: variable expansion
  8210. (@samp{$}), command substitution (@samp{`}), and backslash escaping
  8211. (@samp{\}), as if in an unquoted here-document. Single and double quote
  8212. characters in the value have no
  8213. special meaning. Use this macro instead of @code{AC_DEFINE} when
  8214. @var{variable} or @var{value} is a shell variable. Examples:
  8215. @example
  8216. AC_DEFINE_UNQUOTED([config_machfile], ["$machfile"],
  8217. [Configuration machine file.])
  8218. AC_DEFINE_UNQUOTED([GETGROUPS_T], [$ac_cv_type_getgroups],
  8219. [getgroups return type.])
  8220. AC_DEFINE_UNQUOTED([$ac_tr_hdr], [1],
  8221. [Translated header name.])
  8222. @end example
  8223. @end defmac
  8224. Due to a syntactical bizarreness of the Bourne shell, do not use
  8225. semicolons to separate @code{AC_DEFINE} or @code{AC_DEFINE_UNQUOTED}
  8226. calls from other macro calls or shell code; that can cause syntax errors
  8227. in the resulting @command{configure} script. Use either blanks or
  8228. newlines. That is, do this:
  8229. @example
  8230. AC_CHECK_HEADER([elf.h],
  8231. [AC_DEFINE([SVR4], [1], [System V Release 4]) LIBS="-lelf $LIBS"])
  8232. @end example
  8233. @noindent
  8234. or this:
  8235. @example
  8236. AC_CHECK_HEADER([elf.h],
  8237. [AC_DEFINE([SVR4], [1], [System V Release 4])
  8238. LIBS="-lelf $LIBS"])
  8239. @end example
  8240. @noindent
  8241. instead of this:
  8242. @example
  8243. AC_CHECK_HEADER([elf.h],
  8244. [AC_DEFINE([SVR4], [1], [System V Release 4]); LIBS="-lelf $LIBS"])
  8245. @end example
  8246. @node Setting Output Variables
  8247. @section Setting Output Variables
  8248. @cindex Output variables
  8249. Another way to record the results of tests is to set @dfn{output
  8250. variables}, which are shell variables whose values are substituted into
  8251. files that @command{configure} outputs. The two macros below create new
  8252. output variables. @xref{Preset Output Variables}, for a list of output
  8253. variables that are always available.
  8254. @defmac AC_SUBST (@var{variable}, @ovar{value})
  8255. @acindex{SUBST}
  8256. Create an output variable from a shell variable. Make @code{AC_OUTPUT}
  8257. substitute the variable @var{variable} into output files (typically one
  8258. or more makefiles). This means that @code{AC_OUTPUT}
  8259. replaces instances of @samp{@@@var{variable}@@} in input files with the
  8260. value that the shell variable @var{variable} has when @code{AC_OUTPUT}
  8261. is called. The value can contain any non-@code{NUL} character, including
  8262. newline. If you are using Automake 1.11 or newer, for newlines in values
  8263. you might want to consider using @code{AM_SUBST_NOTMAKE} to prevent
  8264. @command{automake} from adding a line @code{@var{variable} =
  8265. @@@var{variable}@@} to the @file{Makefile.in} files (@pxref{Optional, ,
  8266. Automake, automake, Other things Automake recognizes}).
  8267. Variable occurrences should not overlap: e.g., an input file should
  8268. not contain @samp{@@@var{var1}@@@var{var2}@@} if @var{var1} and @var{var2}
  8269. are variable names.
  8270. The substituted value is not rescanned for more output variables;
  8271. occurrences of @samp{@@@var{variable}@@} in the value are inserted
  8272. literally into the output file. (The algorithm uses the special marker
  8273. @code{|#_!!_#|} internally, so neither the substituted value nor the
  8274. output file may contain @code{|#_!!_#|}.)
  8275. If @var{value} is given, in addition assign it to @var{variable}.
  8276. The string @var{variable} is passed to @code{m4_pattern_allow}
  8277. (@pxref{Forbidden Patterns}).
  8278. @end defmac
  8279. @defmac AC_SUBST_FILE (@var{variable})
  8280. @acindex{SUBST_FILE}
  8281. Another way to create an output variable from a shell variable. Make
  8282. @code{AC_OUTPUT} insert (without substitutions) the contents of the file
  8283. named by shell variable @var{variable} into output files. This means
  8284. that @code{AC_OUTPUT} replaces instances of
  8285. @samp{@@@var{variable}@@} in output files (such as @file{Makefile.in})
  8286. with the contents of the file that the shell variable @var{variable}
  8287. names when @code{AC_OUTPUT} is called. Set the variable to
  8288. @file{/dev/null} for cases that do not have a file to insert.
  8289. This substitution occurs only when the @samp{@@@var{variable}@@} is on a
  8290. line by itself, optionally surrounded by spaces and tabs. The
  8291. substitution replaces the whole line, including the spaces, tabs, and
  8292. the terminating newline.
  8293. This macro is useful for inserting makefile fragments containing
  8294. special dependencies or other @command{make} directives for particular host
  8295. or target types into makefiles. For example, @file{configure.ac}
  8296. could contain:
  8297. @example
  8298. AC_SUBST_FILE([host_frag])
  8299. host_frag=$srcdir/conf/sun4.mh
  8300. @end example
  8301. @noindent
  8302. and then a @file{Makefile.in} could contain:
  8303. @example
  8304. @@host_frag@@
  8305. @end example
  8306. The string @var{variable} is passed to @code{m4_pattern_allow}
  8307. (@pxref{Forbidden Patterns}).
  8308. @end defmac
  8309. @cindex Precious Variable
  8310. @cindex Variable, Precious
  8311. Running @command{configure} in varying environments can be extremely
  8312. dangerous. If for instance the user runs @samp{CC=bizarre-cc
  8313. ./configure}, then the cache, @file{config.h}, and many other output
  8314. files depend upon @command{bizarre-cc} being the C compiler. If
  8315. for some reason the user runs @command{./configure} again, or if it is
  8316. run via @samp{./config.status --recheck}, (@xref{Automatic Remaking},
  8317. and @pxref{config.status Invocation}), then the configuration can be
  8318. inconsistent, composed of results depending upon two different
  8319. compilers.
  8320. Environment variables that affect this situation, such as @samp{CC}
  8321. above, are called @dfn{precious variables}, and can be declared as such
  8322. by @code{AC_ARG_VAR}.
  8323. @defmac AC_ARG_VAR (@var{variable}, @var{description})
  8324. @acindex{ARG_VAR}
  8325. Declare @var{variable} is a precious variable, and include its
  8326. @var{description} in the variable section of @samp{./configure --help}.
  8327. Being precious means that
  8328. @itemize @minus
  8329. @item
  8330. @var{variable} is substituted via @code{AC_SUBST}.
  8331. @item
  8332. The value of @var{variable} when @command{configure} was launched is
  8333. saved in the cache, including if it was not specified on the command
  8334. line but via the environment. Indeed, while @command{configure} can
  8335. notice the definition of @code{CC} in @samp{./configure CC=bizarre-cc},
  8336. it is impossible to notice it in @samp{CC=bizarre-cc ./configure},
  8337. which, unfortunately, is what most users do.
  8338. We emphasize that it is the @emph{initial} value of @var{variable} which
  8339. is saved, not that found during the execution of @command{configure}.
  8340. Indeed, specifying @samp{./configure FOO=foo} and letting
  8341. @samp{./configure} guess that @code{FOO} is @code{foo} can be two
  8342. different things.
  8343. @item
  8344. @var{variable} is checked for consistency between two
  8345. @command{configure} runs. For instance:
  8346. @example
  8347. $ @kbd{./configure --silent --config-cache}
  8348. $ @kbd{CC=cc ./configure --silent --config-cache}
  8349. configure: error: `CC' was not set in the previous run
  8350. configure: error: changes in the environment can compromise \
  8351. the build
  8352. configure: error: run `make distclean' and/or \
  8353. `rm config.cache' and start over
  8354. @end example
  8355. @noindent
  8356. and similarly if the variable is unset, or if its content is changed.
  8357. If the content has white space changes only, then the error is degraded
  8358. to a warning only, but the old value is reused.
  8359. @item
  8360. @var{variable} is kept during automatic reconfiguration
  8361. (@pxref{config.status Invocation}) as if it had been passed as a command
  8362. line argument, including when no cache is used:
  8363. @example
  8364. $ @kbd{CC=/usr/bin/cc ./configure var=raboof --silent}
  8365. $ @kbd{./config.status --recheck}
  8366. running CONFIG_SHELL=/bin/sh /bin/sh ./configure var=raboof \
  8367. CC=/usr/bin/cc --no-create --no-recursion
  8368. @end example
  8369. @end itemize
  8370. @end defmac
  8371. @node Special Chars in Variables
  8372. @section Special Characters in Output Variables
  8373. @cindex Output variables, special characters in
  8374. Many output variables are intended to be evaluated both by
  8375. @command{make} and by the shell. Some characters are expanded
  8376. differently in these two contexts, so to avoid confusion these
  8377. variables' values should not contain any of the following characters:
  8378. @example
  8379. " # $ & ' ( ) * ; < > ? [ \ ^ ` |
  8380. @end example
  8381. Also, these variables' values should neither contain newlines, nor start
  8382. with @samp{~}, nor contain white space or @samp{:} immediately followed
  8383. by @samp{~}. The values can contain nonempty sequences of white space
  8384. characters like tabs and spaces, but each such sequence might
  8385. arbitrarily be replaced by a single space during substitution.
  8386. These restrictions apply both to the values that @command{configure}
  8387. computes, and to the values set directly by the user. For example, the
  8388. following invocations of @command{configure} are problematic, since they
  8389. attempt to use special characters within @code{CPPFLAGS} and white space
  8390. within @code{$(srcdir)}:
  8391. @example
  8392. CPPFLAGS='-DOUCH="&\"#$*?"' '../My Source/ouch-1.0/configure'
  8393. '../My Source/ouch-1.0/configure' CPPFLAGS='-DOUCH="&\"#$*?"'
  8394. @end example
  8395. @node Caching Results
  8396. @section Caching Results
  8397. @cindex Cache
  8398. To avoid checking for the same features repeatedly in various
  8399. @command{configure} scripts (or in repeated runs of one script),
  8400. @command{configure} can optionally save the results of many checks in a
  8401. @dfn{cache file} (@pxref{Cache Files}). If a @command{configure} script
  8402. runs with caching enabled and finds a cache file, it reads the results
  8403. of previous runs from the cache and avoids rerunning those checks. As a
  8404. result, @command{configure} can then run much faster than if it had to
  8405. perform all of the checks every time.
  8406. @defmac AC_CACHE_VAL (@var{cache-id}, @var{commands-to-set-it})
  8407. @acindex{CACHE_VAL}
  8408. Ensure that the results of the check identified by @var{cache-id} are
  8409. available. If the results of the check were in the cache file that was
  8410. read, and @command{configure} was not given the @option{--quiet} or
  8411. @option{--silent} option, print a message saying that the result was
  8412. cached; otherwise, run the shell commands @var{commands-to-set-it}. If
  8413. the shell commands are run to determine the value, the value is
  8414. saved in the cache file just before @command{configure} creates its output
  8415. files. @xref{Cache Variable Names}, for how to choose the name of the
  8416. @var{cache-id} variable.
  8417. The @var{commands-to-set-it} @emph{must have no side effects} except for
  8418. setting the variable @var{cache-id}, see below.
  8419. @end defmac
  8420. @defmac AC_CACHE_CHECK (@var{message}, @var{cache-id}, @
  8421. @var{commands-to-set-it})
  8422. @acindex{CACHE_CHECK}
  8423. A wrapper for @code{AC_CACHE_VAL} that takes care of printing the
  8424. messages. This macro provides a convenient shorthand for the most
  8425. common way to use these macros. It calls @code{AC_MSG_CHECKING} for
  8426. @var{message}, then @code{AC_CACHE_VAL} with the @var{cache-id} and
  8427. @var{commands} arguments, and @code{AC_MSG_RESULT} with @var{cache-id}.
  8428. The @var{commands-to-set-it} @emph{must have no side effects} except for
  8429. setting the variable @var{cache-id}, see below.
  8430. @end defmac
  8431. It is common to find buggy macros using @code{AC_CACHE_VAL} or
  8432. @code{AC_CACHE_CHECK}, because people are tempted to call
  8433. @code{AC_DEFINE} in the @var{commands-to-set-it}. Instead, the code that
  8434. @emph{follows} the call to @code{AC_CACHE_VAL} should call
  8435. @code{AC_DEFINE}, by examining the value of the cache variable. For
  8436. instance, the following macro is broken:
  8437. @example
  8438. @c If you change this example, adjust tests/base.at:AC_CACHE_CHECK.
  8439. @group
  8440. AC_DEFUN([AC_SHELL_TRUE],
  8441. [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
  8442. [my_cv_shell_true_works=no
  8443. (true) 2>/dev/null && my_cv_shell_true_works=yes
  8444. if test "x$my_cv_shell_true_works" = xyes; then
  8445. AC_DEFINE([TRUE_WORKS], [1],
  8446. [Define if `true(1)' works properly.])
  8447. fi])
  8448. ])
  8449. @end group
  8450. @end example
  8451. @noindent
  8452. This fails if the cache is enabled: the second time this macro is run,
  8453. @code{TRUE_WORKS} @emph{will not be defined}. The proper implementation
  8454. is:
  8455. @example
  8456. @c If you change this example, adjust tests/base.at:AC_CACHE_CHECK.
  8457. @group
  8458. AC_DEFUN([AC_SHELL_TRUE],
  8459. [AC_CACHE_CHECK([whether true(1) works], [my_cv_shell_true_works],
  8460. [my_cv_shell_true_works=no
  8461. (true) 2>/dev/null && my_cv_shell_true_works=yes])
  8462. if test "x$my_cv_shell_true_works" = xyes; then
  8463. AC_DEFINE([TRUE_WORKS], [1],
  8464. [Define if `true(1)' works properly.])
  8465. fi
  8466. ])
  8467. @end group
  8468. @end example
  8469. Also, @var{commands-to-set-it} should not print any messages, for
  8470. example with @code{AC_MSG_CHECKING}; do that before calling
  8471. @code{AC_CACHE_VAL}, so the messages are printed regardless of whether
  8472. the results of the check are retrieved from the cache or determined by
  8473. running the shell commands.
  8474. @menu
  8475. * Cache Variable Names:: Shell variables used in caches
  8476. * Cache Files:: Files @command{configure} uses for caching
  8477. * Cache Checkpointing:: Loading and saving the cache file
  8478. @end menu
  8479. @node Cache Variable Names
  8480. @subsection Cache Variable Names
  8481. @cindex Cache variable
  8482. The names of cache variables should have the following format:
  8483. @example
  8484. @var{package-prefix}_cv_@var{value-type}_@var{specific-value}_@ovar{additional-options}
  8485. @end example
  8486. @noindent
  8487. for example, @samp{ac_cv_header_stat_broken} or
  8488. @samp{ac_cv_prog_gcc_traditional}. The parts of the variable name are:
  8489. @table @asis
  8490. @item @var{package-prefix}
  8491. An abbreviation for your package or organization; the same prefix you
  8492. begin local Autoconf macros with, except lowercase by convention.
  8493. For cache values used by the distributed Autoconf macros, this value is
  8494. @samp{ac}.
  8495. @item @code{_cv_}
  8496. Indicates that this shell variable is a cache value. This string
  8497. @emph{must} be present in the variable name, including the leading
  8498. underscore.
  8499. @item @var{value-type}
  8500. A convention for classifying cache values, to produce a rational naming
  8501. system. The values used in Autoconf are listed in @ref{Macro Names}.
  8502. @item @var{specific-value}
  8503. Which member of the class of cache values this test applies to.
  8504. For example, which function (@samp{alloca}), program (@samp{gcc}), or
  8505. output variable (@samp{INSTALL}).
  8506. @item @var{additional-options}
  8507. Any particular behavior of the specific member that this test applies to.
  8508. For example, @samp{broken} or @samp{set}. This part of the name may
  8509. be omitted if it does not apply.
  8510. @end table
  8511. The values assigned to cache variables may not contain newlines.
  8512. Usually, their values are Boolean (@samp{yes} or @samp{no}) or the
  8513. names of files or functions; so this is not an important restriction.
  8514. @ref{Cache Variable Index} for an index of cache variables with
  8515. documented semantics.
  8516. @node Cache Files
  8517. @subsection Cache Files
  8518. A cache file is a shell script that caches the results of configure
  8519. tests run on one system so they can be shared between configure scripts
  8520. and configure runs. It is not useful on other systems. If its contents
  8521. are invalid for some reason, the user may delete or edit it, or override
  8522. documented cache variables on the @command{configure} command line.
  8523. By default, @command{configure} uses no cache file,
  8524. to avoid problems caused by accidental
  8525. use of stale cache files.
  8526. To enable caching, @command{configure} accepts @option{--config-cache} (or
  8527. @option{-C}) to cache results in the file @file{config.cache}.
  8528. Alternatively, @option{--cache-file=@var{file}} specifies that
  8529. @var{file} be the cache file. The cache file is created if it does not
  8530. exist already. When @command{configure} calls @command{configure} scripts in
  8531. subdirectories, it uses the @option{--cache-file} argument so that they
  8532. share the same cache. @xref{Subdirectories}, for information on
  8533. configuring subdirectories with the @code{AC_CONFIG_SUBDIRS} macro.
  8534. @file{config.status} only pays attention to the cache file if it is
  8535. given the @option{--recheck} option, which makes it rerun
  8536. @command{configure}.
  8537. It is wrong to try to distribute cache files for particular system types.
  8538. There is too much room for error in doing that, and too much
  8539. administrative overhead in maintaining them. For any features that
  8540. can't be guessed automatically, use the standard method of the canonical
  8541. system type and linking files (@pxref{Manual Configuration}).
  8542. The site initialization script can specify a site-wide cache file to
  8543. use, instead of the usual per-program cache. In this case, the cache
  8544. file gradually accumulates information whenever someone runs a new
  8545. @command{configure} script. (Running @command{configure} merges the new cache
  8546. results with the existing cache file.) This may cause problems,
  8547. however, if the system configuration (e.g., the installed libraries or
  8548. compilers) changes and the stale cache file is not deleted.
  8549. If @command{configure} is interrupted at the right time when it updates
  8550. a cache file outside of the build directory where the @command{configure}
  8551. script is run, it may leave behind a temporary file named after the
  8552. cache file with digits following it. You may safely delete such a file.
  8553. @node Cache Checkpointing
  8554. @subsection Cache Checkpointing
  8555. If your configure script, or a macro called from @file{configure.ac}, happens
  8556. to abort the configure process, it may be useful to checkpoint the cache
  8557. a few times at key points using @code{AC_CACHE_SAVE}. Doing so
  8558. reduces the amount of time it takes to rerun the configure script with
  8559. (hopefully) the error that caused the previous abort corrected.
  8560. @c FIXME: Do we really want to document this guy?
  8561. @defmac AC_CACHE_LOAD
  8562. @acindex{CACHE_LOAD}
  8563. Loads values from existing cache file, or creates a new cache file if a
  8564. cache file is not found. Called automatically from @code{AC_INIT}.
  8565. @end defmac
  8566. @defmac AC_CACHE_SAVE
  8567. @acindex{CACHE_SAVE}
  8568. Flushes all cached values to the cache file. Called automatically from
  8569. @code{AC_OUTPUT}, but it can be quite useful to call
  8570. @code{AC_CACHE_SAVE} at key points in @file{configure.ac}.
  8571. @end defmac
  8572. For instance:
  8573. @example
  8574. @r{ @dots{} AC_INIT, etc. @dots{}}
  8575. @group
  8576. # Checks for programs.
  8577. AC_PROG_CC
  8578. AC_PROG_AWK
  8579. @r{ @dots{} more program checks @dots{}}
  8580. AC_CACHE_SAVE
  8581. @end group
  8582. @group
  8583. # Checks for libraries.
  8584. AC_CHECK_LIB([nsl], [gethostbyname])
  8585. AC_CHECK_LIB([socket], [connect])
  8586. @r{ @dots{} more lib checks @dots{}}
  8587. AC_CACHE_SAVE
  8588. @end group
  8589. @group
  8590. # Might abort@dots{}
  8591. AM_PATH_GTK([1.0.2], [], [AC_MSG_ERROR([GTK not in path])])
  8592. AM_PATH_GTKMM([0.9.5], [], [AC_MSG_ERROR([GTK not in path])])
  8593. @end group
  8594. @r{ @dots{} AC_OUTPUT, etc. @dots{}}
  8595. @end example
  8596. @node Printing Messages
  8597. @section Printing Messages
  8598. @cindex Messages, from @command{configure}
  8599. @command{configure} scripts need to give users running them several kinds
  8600. of information. The following macros print messages in ways appropriate
  8601. for each kind. The arguments to all of them get enclosed in shell
  8602. double quotes, so the shell performs variable and back-quote
  8603. substitution on them.
  8604. These macros are all wrappers around the @command{echo} shell command.
  8605. They direct output to the appropriate file descriptor (@pxref{File
  8606. Descriptor Macros}).
  8607. @command{configure} scripts should rarely need to run @command{echo} directly
  8608. to print messages for the user. Using these macros makes it easy to
  8609. change how and when each kind of message is printed; such changes need
  8610. only be made to the macro definitions and all the callers change
  8611. automatically.
  8612. To diagnose static issues, i.e., when @command{autoconf} is run, see
  8613. @ref{Diagnostic Macros}.
  8614. @defmac AC_MSG_CHECKING (@var{feature-description})
  8615. @acindex{MSG_CHECKING}
  8616. Notify the user that @command{configure} is checking for a particular
  8617. feature. This macro prints a message that starts with @samp{checking }
  8618. and ends with @samp{...} and no newline. It must be followed by a call
  8619. to @code{AC_MSG_RESULT} to print the result of the check and the
  8620. newline. The @var{feature-description} should be something like
  8621. @samp{whether the Fortran compiler accepts C++ comments} or @samp{for
  8622. c89}.
  8623. This macro prints nothing if @command{configure} is run with the
  8624. @option{--quiet} or @option{--silent} option.
  8625. @end defmac
  8626. @anchor{AC_MSG_RESULT}
  8627. @defmac AC_MSG_RESULT (@var{result-description})
  8628. @acindex{MSG_RESULT}
  8629. Notify the user of the results of a check. @var{result-description} is
  8630. almost always the value of the cache variable for the check, typically
  8631. @samp{yes}, @samp{no}, or a file name. This macro should follow a call
  8632. to @code{AC_MSG_CHECKING}, and the @var{result-description} should be
  8633. the completion of the message printed by the call to
  8634. @code{AC_MSG_CHECKING}.
  8635. This macro prints nothing if @command{configure} is run with the
  8636. @option{--quiet} or @option{--silent} option.
  8637. @end defmac
  8638. @anchor{AC_MSG_NOTICE}
  8639. @defmac AC_MSG_NOTICE (@var{message})
  8640. @acindex{MSG_NOTICE}
  8641. Deliver the @var{message} to the user. It is useful mainly to print a
  8642. general description of the overall purpose of a group of feature checks,
  8643. e.g.,
  8644. @example
  8645. AC_MSG_NOTICE([checking if stack overflow is detectable])
  8646. @end example
  8647. This macro prints nothing if @command{configure} is run with the
  8648. @option{--quiet} or @option{--silent} option.
  8649. @end defmac
  8650. @anchor{AC_MSG_ERROR}
  8651. @defmac AC_MSG_ERROR (@var{error-description}, @dvar{exit-status, $?/1})
  8652. @acindex{MSG_ERROR}
  8653. Notify the user of an error that prevents @command{configure} from
  8654. completing. This macro prints an error message to the standard error
  8655. output and exits @command{configure} with @var{exit-status} (@samp{$?}
  8656. by default, except that @samp{0} is converted to @samp{1}).
  8657. @var{error-description} should be something like @samp{invalid value
  8658. $HOME for \$HOME}.
  8659. The @var{error-description} should start with a lower-case letter, and
  8660. ``cannot'' is preferred to ``can't''.
  8661. @end defmac
  8662. @defmac AC_MSG_FAILURE (@var{error-description}, @ovar{exit-status})
  8663. @acindex{MSG_FAILURE}
  8664. This @code{AC_MSG_ERROR} wrapper notifies the user of an error that
  8665. prevents @command{configure} from completing @emph{and} that additional
  8666. details are provided in @file{config.log}. This is typically used when
  8667. abnormal results are found during a compilation.
  8668. @end defmac
  8669. @anchor{AC_MSG_WARN}
  8670. @defmac AC_MSG_WARN (@var{problem-description})
  8671. @acindex{MSG_WARN}
  8672. Notify the @command{configure} user of a possible problem. This macro
  8673. prints the message to the standard error output; @command{configure}
  8674. continues running afterward, so macros that call @code{AC_MSG_WARN} should
  8675. provide a default (back-up) behavior for the situations they warn about.
  8676. @var{problem-description} should be something like @samp{ln -s seems to
  8677. make hard links}.
  8678. @end defmac
  8679. @c ====================================================== Programming in M4.
  8680. @node Programming in M4
  8681. @chapter Programming in M4
  8682. @cindex M4
  8683. Autoconf is written on top of two layers: @dfn{M4sugar}, which provides
  8684. convenient macros for pure M4 programming, and @dfn{M4sh}, which
  8685. provides macros dedicated to shell script generation.
  8686. As of this version of Autoconf, these two layers still contain
  8687. experimental macros, whose interface might change in the future. As a
  8688. matter of fact, @emph{anything that is not documented must not be used}.
  8689. @menu
  8690. * M4 Quotation:: Protecting macros from unwanted expansion
  8691. * Using autom4te:: The Autoconf executables backbone
  8692. * Programming in M4sugar:: Convenient pure M4 macros
  8693. * Debugging via autom4te:: Figuring out what M4 was doing
  8694. @end menu
  8695. @node M4 Quotation
  8696. @section M4 Quotation
  8697. @cindex M4 quotation
  8698. @cindex quotation
  8699. The most common problem with existing macros is an improper quotation.
  8700. This section, which users of Autoconf can skip, but which macro writers
  8701. @emph{must} read, first justifies the quotation scheme that was chosen
  8702. for Autoconf and then ends with a rule of thumb. Understanding the
  8703. former helps one to follow the latter.
  8704. @menu
  8705. * Active Characters:: Characters that change the behavior of M4
  8706. * One Macro Call:: Quotation and one macro call
  8707. * Quoting and Parameters:: M4 vs. shell parameters
  8708. * Quotation and Nested Macros:: Macros calling macros
  8709. * Changequote is Evil:: Worse than INTERCAL: M4 + changequote
  8710. * Quadrigraphs:: Another way to escape special characters
  8711. * Balancing Parentheses:: Dealing with unbalanced parentheses
  8712. * Quotation Rule Of Thumb:: One parenthesis, one quote
  8713. @end menu
  8714. @node Active Characters
  8715. @subsection Active Characters
  8716. To fully understand where proper quotation is important, you first need
  8717. to know what the special characters are in Autoconf: @samp{#} introduces
  8718. a comment inside which no macro expansion is performed, @samp{,}
  8719. separates arguments, @samp{[} and @samp{]} are the quotes
  8720. themselves@footnote{By itself, M4 uses @samp{`} and @samp{'}; it is the
  8721. M4sugar layer that sets up the preferred quotes of @samp{[} and @samp{]}.},
  8722. @samp{(} and @samp{)} (which M4 tries to match by pairs), and finally
  8723. @samp{$} inside a macro definition.
  8724. In order to understand the delicate case of macro calls, we first have
  8725. to present some obvious failures. Below they are ``obvious-ified'',
  8726. but when you find them in real life, they are usually in disguise.
  8727. Comments, introduced by a hash and running up to the newline, are opaque
  8728. tokens to the top level: active characters are turned off, and there is
  8729. no macro expansion:
  8730. @example
  8731. # define([def], ine)
  8732. @result{}# define([def], ine)
  8733. @end example
  8734. Each time there can be a macro expansion, there is a quotation
  8735. expansion, i.e., one level of quotes is stripped:
  8736. @example
  8737. int tab[10];
  8738. @result{}int tab10;
  8739. [int tab[10];]
  8740. @result{}int tab[10];
  8741. @end example
  8742. Without this in mind, the reader might try hopelessly to use her macro
  8743. @code{array}:
  8744. @example
  8745. define([array], [int tab[10];])
  8746. array
  8747. @result{}int tab10;
  8748. [array]
  8749. @result{}array
  8750. @end example
  8751. @noindent
  8752. How can you correctly output the intended results@footnote{Using
  8753. @code{defn}.}?
  8754. @node One Macro Call
  8755. @subsection One Macro Call
  8756. Let's proceed on the interaction between active characters and macros
  8757. with this small macro, which just returns its first argument:
  8758. @example
  8759. define([car], [$1])
  8760. @end example
  8761. @noindent
  8762. The two pairs of quotes above are not part of the arguments of
  8763. @code{define}; rather, they are understood by the top level when it
  8764. tries to find the arguments of @code{define}. Therefore, assuming
  8765. @code{car} is not already defined, it is equivalent to write:
  8766. @example
  8767. define(car, $1)
  8768. @end example
  8769. @noindent
  8770. But, while it is acceptable for a @file{configure.ac} to avoid unnecessary
  8771. quotes, it is bad practice for Autoconf macros which must both be more
  8772. robust and also advocate perfect style.
  8773. At the top level, there are only two possibilities: either you
  8774. quote or you don't:
  8775. @example
  8776. car(foo, bar, baz)
  8777. @result{}foo
  8778. [car(foo, bar, baz)]
  8779. @result{}car(foo, bar, baz)
  8780. @end example
  8781. Let's pay attention to the special characters:
  8782. @example
  8783. car(#)
  8784. @error{}EOF in argument list
  8785. @end example
  8786. The closing parenthesis is hidden in the comment; with a hypothetical
  8787. quoting, the top level understood it this way:
  8788. @example
  8789. car([#)]
  8790. @end example
  8791. @noindent
  8792. Proper quotation, of course, fixes the problem:
  8793. @example
  8794. car([#])
  8795. @result{}#
  8796. @end example
  8797. Here are more examples:
  8798. @example
  8799. car(foo, bar)
  8800. @result{}foo
  8801. car([foo, bar])
  8802. @result{}foo, bar
  8803. car((foo, bar))
  8804. @result{}(foo, bar)
  8805. car([(foo], [bar)])
  8806. @result{}(foo
  8807. define([a], [b])
  8808. @result{}
  8809. car(a)
  8810. @result{}b
  8811. car([a])
  8812. @result{}b
  8813. car([[a]])
  8814. @result{}a
  8815. car([[[a]]])
  8816. @result{}[a]
  8817. @end example
  8818. @node Quoting and Parameters
  8819. @subsection Quoting and Parameters
  8820. When M4 encounters @samp{$} within a macro definition, followed
  8821. immediately by a character it recognizes (@samp{0}@dots{}@samp{9},
  8822. @samp{#}, @samp{@@}, or @samp{*}), it will perform M4 parameter
  8823. expansion. This happens regardless of how many layers of quotes the
  8824. parameter expansion is nested within, or even if it occurs in text that
  8825. will be rescanned as a comment.
  8826. @example
  8827. define([none], [$1])
  8828. @result{}
  8829. define([one], [[$1]])
  8830. @result{}
  8831. define([two], [[[$1]]])
  8832. @result{}
  8833. define([comment], [# $1])
  8834. @result{}
  8835. define([active], [ACTIVE])
  8836. @result{}
  8837. none([active])
  8838. @result{}ACTIVE
  8839. one([active])
  8840. @result{}active
  8841. two([active])
  8842. @result{}[active]
  8843. comment([active])
  8844. @result{}# active
  8845. @end example
  8846. On the other hand, since autoconf generates shell code, you often want
  8847. to output shell variable expansion, rather than performing M4 parameter
  8848. expansion. To do this, you must use M4 quoting to separate the @samp{$}
  8849. from the next character in the definition of your macro. If the macro
  8850. definition occurs in single-quoted text, then insert another level of
  8851. quoting; if the usage is already inside a double-quoted string, then
  8852. split it into concatenated strings.
  8853. @example
  8854. define([single], [a single-quoted $[]1 definition])
  8855. @result{}
  8856. define([double], [[a double-quoted $][1 definition]])
  8857. @result{}
  8858. single
  8859. @result{}a single-quoted $1 definition
  8860. double
  8861. @result{}a double-quoted $1 definition
  8862. @end example
  8863. Posix states that M4 implementations are free to provide implementation
  8864. extensions when @samp{$@{} is encountered in a macro definition.
  8865. Autoconf reserves the longer sequence @samp{$@{@{} for use with planned
  8866. extensions that will be available in the future GNU M4 2.0,
  8867. but guarantees that all other instances of @samp{$@{} will be output
  8868. literally. Therefore, this idiom can also be used to output shell code
  8869. parameter references:
  8870. @example
  8871. define([first], [$@{1@}])first
  8872. @result{}$@{1@}
  8873. @end example
  8874. Posix also states that @samp{$11} should expand to the first parameter
  8875. concatenated with a literal @samp{1}, although some versions of
  8876. GNU M4 expand the eleventh parameter instead. For
  8877. portability, you should only use single-digit M4 parameter expansion.
  8878. With this in mind, we can explore the cases where macros invoke
  8879. macros@enddots{}
  8880. @node Quotation and Nested Macros
  8881. @subsection Quotation and Nested Macros
  8882. The examples below use the following macros:
  8883. @example
  8884. define([car], [$1])
  8885. define([active], [ACT, IVE])
  8886. define([array], [int tab[10]])
  8887. @end example
  8888. Each additional embedded macro call introduces other possible
  8889. interesting quotations:
  8890. @example
  8891. car(active)
  8892. @result{}ACT
  8893. car([active])
  8894. @result{}ACT, IVE
  8895. car([[active]])
  8896. @result{}active
  8897. @end example
  8898. In the first case, the top level looks for the arguments of @code{car},
  8899. and finds @samp{active}. Because M4 evaluates its arguments
  8900. before applying the macro, @samp{active} is expanded, which results in:
  8901. @example
  8902. car(ACT, IVE)
  8903. @result{}ACT
  8904. @end example
  8905. @noindent
  8906. In the second case, the top level gives @samp{active} as first and only
  8907. argument of @code{car}, which results in:
  8908. @example
  8909. active
  8910. @result{}ACT, IVE
  8911. @end example
  8912. @noindent
  8913. i.e., the argument is evaluated @emph{after} the macro that invokes it.
  8914. In the third case, @code{car} receives @samp{[active]}, which results in:
  8915. @example
  8916. [active]
  8917. @result{}active
  8918. @end example
  8919. @noindent
  8920. exactly as we already saw above.
  8921. The example above, applied to a more realistic example, gives:
  8922. @example
  8923. car(int tab[10];)
  8924. @result{}int tab10;
  8925. car([int tab[10];])
  8926. @result{}int tab10;
  8927. car([[int tab[10];]])
  8928. @result{}int tab[10];
  8929. @end example
  8930. @noindent
  8931. Huh? The first case is easily understood, but why is the second wrong,
  8932. and the third right? To understand that, you must know that after
  8933. M4 expands a macro, the resulting text is immediately subjected
  8934. to macro expansion and quote removal. This means that the quote removal
  8935. occurs twice---first before the argument is passed to the @code{car}
  8936. macro, and second after the @code{car} macro expands to the first
  8937. argument.
  8938. As the author of the Autoconf macro @code{car}, you then consider it to
  8939. be incorrect that your users have to double-quote the arguments of
  8940. @code{car}, so you ``fix'' your macro. Let's call it @code{qar} for
  8941. quoted car:
  8942. @example
  8943. define([qar], [[$1]])
  8944. @end example
  8945. @noindent
  8946. and check that @code{qar} is properly fixed:
  8947. @example
  8948. qar([int tab[10];])
  8949. @result{}int tab[10];
  8950. @end example
  8951. @noindent
  8952. Ahhh! That's much better.
  8953. But note what you've done: now that the result of @code{qar} is always
  8954. a literal string, the only time a user can use nested macros is if she
  8955. relies on an @emph{unquoted} macro call:
  8956. @example
  8957. qar(active)
  8958. @result{}ACT
  8959. qar([active])
  8960. @result{}active
  8961. @end example
  8962. @noindent
  8963. leaving no way for her to reproduce what she used to do with @code{car}:
  8964. @example
  8965. car([active])
  8966. @result{}ACT, IVE
  8967. @end example
  8968. @noindent
  8969. Worse yet: she wants to use a macro that produces a set of @code{cpp}
  8970. macros:
  8971. @example
  8972. define([my_includes], [#include <stdio.h>])
  8973. car([my_includes])
  8974. @result{}#include <stdio.h>
  8975. qar(my_includes)
  8976. @error{}EOF in argument list
  8977. @end example
  8978. This macro, @code{qar}, because it double quotes its arguments, forces
  8979. its users to leave their macro calls unquoted, which is dangerous.
  8980. Commas and other active symbols are interpreted by M4 before
  8981. they are given to the macro, often not in the way the users expect.
  8982. Also, because @code{qar} behaves differently from the other macros,
  8983. it's an exception that should be avoided in Autoconf.
  8984. @node Changequote is Evil
  8985. @subsection @code{changequote} is Evil
  8986. @cindex @code{changequote}
  8987. The temptation is often high to bypass proper quotation, in particular
  8988. when it's late at night. Then, many experienced Autoconf hackers
  8989. finally surrender to the dark side of the force and use the ultimate
  8990. weapon: @code{changequote}.
  8991. The M4 builtin @code{changequote} belongs to a set of primitives that
  8992. allow one to adjust the syntax of the language to adjust it to one's
  8993. needs. For instance, by default M4 uses @samp{`} and @samp{'} as
  8994. quotes, but in the context of shell programming (and actually of most
  8995. programming languages), that's about the worst choice one can make:
  8996. because of strings and back-quoted expressions in shell code (such as
  8997. @samp{'this'} and @samp{`that`}), and because of literal characters in usual
  8998. programming languages (as in @samp{'0'}), there are many unbalanced
  8999. @samp{`} and @samp{'}. Proper M4 quotation then becomes a nightmare, if
  9000. not impossible. In order to make M4 useful in such a context, its
  9001. designers have equipped it with @code{changequote}, which makes it
  9002. possible to choose another pair of quotes. M4sugar, M4sh, Autoconf, and
  9003. Autotest all have chosen to use @samp{[} and @samp{]}. Not especially
  9004. because they are unlikely characters, but @emph{because they are
  9005. characters unlikely to be unbalanced}.
  9006. There are other magic primitives, such as @code{changecom} to specify
  9007. what syntactic forms are comments (it is common to see
  9008. @samp{changecom(<!--, -->)} when M4 is used to produce HTML pages),
  9009. @code{changeword} and @code{changesyntax} to change other syntactic
  9010. details (such as the character to denote the @var{n}th argument, @samp{$} by
  9011. default, the parentheses around arguments, etc.).
  9012. These primitives are really meant to make M4 more useful for specific
  9013. domains: they should be considered like command line options:
  9014. @option{--quotes}, @option{--comments}, @option{--words}, and
  9015. @option{--syntax}. Nevertheless, they are implemented as M4 builtins, as
  9016. it makes M4 libraries self contained (no need for additional options).
  9017. There lies the problem@enddots{}
  9018. @sp 1
  9019. The problem is that it is then tempting to use them in the middle of an
  9020. M4 script, as opposed to its initialization. This, if not carefully
  9021. thought out, can lead to disastrous effects: @emph{you are changing the
  9022. language in the middle of the execution}. Changing and restoring the
  9023. syntax is often not enough: if you happened to invoke macros in between,
  9024. these macros are lost, as the current syntax is probably not
  9025. the one they were implemented with.
  9026. @c FIXME: I've been looking for a short, real case example, but I
  9027. @c lost them all :(
  9028. @node Quadrigraphs
  9029. @subsection Quadrigraphs
  9030. @cindex quadrigraphs
  9031. @cindex @samp{@@S|@@}
  9032. @cindex @samp{@@&t@@}
  9033. @c Info cannot handle `:' in index entries.
  9034. @ifnotinfo
  9035. @cindex @samp{@@<:@@}
  9036. @cindex @samp{@@:>@@}
  9037. @cindex @samp{@@%:@@}
  9038. @cindex @samp{@@@{:@@}
  9039. @cindex @samp{@@:@}@@}
  9040. @end ifnotinfo
  9041. When writing an Autoconf macro you may occasionally need to generate
  9042. special characters that are difficult to express with the standard
  9043. Autoconf quoting rules. For example, you may need to output the regular
  9044. expression @samp{[^[]}, which matches any character other than @samp{[}.
  9045. This expression contains unbalanced brackets so it cannot be put easily
  9046. into an M4 macro.
  9047. Additionally, there are a few m4sugar macros (such as @code{m4_split}
  9048. and @code{m4_expand}) which internally use special markers in addition
  9049. to the regular quoting characters. If the arguments to these macros
  9050. contain the literal strings @samp{-=<@{(} or @samp{)@}>=-}, the macros
  9051. might behave incorrectly.
  9052. You can work around these problems by using one of the following
  9053. @dfn{quadrigraphs}:
  9054. @table @samp
  9055. @item @@<:@@
  9056. @samp{[}
  9057. @item @@:>@@
  9058. @samp{]}
  9059. @item @@S|@@
  9060. @samp{$}
  9061. @item @@%:@@
  9062. @samp{#}
  9063. @item @@@{:@@
  9064. @samp{(}
  9065. @item @@:@}@@
  9066. @samp{)}
  9067. @item @@&t@@
  9068. Expands to nothing.
  9069. @end table
  9070. Quadrigraphs are replaced at a late stage of the translation process,
  9071. after @command{m4} is run, so they do not get in the way of M4 quoting.
  9072. For example, the string @samp{^@@<:@@}, independently of its quotation,
  9073. appears as @samp{^[} in the output.
  9074. The empty quadrigraph can be used:
  9075. @itemize @minus
  9076. @item to mark trailing spaces explicitly
  9077. Trailing spaces are smashed by @command{autom4te}. This is a feature.
  9078. @item to produce quadrigraphs and other strings reserved by m4sugar
  9079. For instance @samp{@@<@@&t@@:@@} produces @samp{@@<:@@}. For a more
  9080. contrived example:
  9081. @example
  9082. m4_define([a], [A])m4_define([b], [B])m4_define([c], [C])dnl
  9083. m4_split([a )@}>=- b -=<@{( c])
  9084. @result{}[a], [], [B], [], [c]
  9085. m4_split([a )@}@@&t@@>=- b -=<@@&t@@@{( c])
  9086. @result{}[a], [)@}>=-], [b], [-=<@{(], [c]
  9087. @end example
  9088. @item to escape @emph{occurrences} of forbidden patterns
  9089. For instance you might want to mention @code{AC_FOO} in a comment, while
  9090. still being sure that @command{autom4te} still catches unexpanded
  9091. @samp{AC_*}. Then write @samp{AC@@&t@@_FOO}.
  9092. @end itemize
  9093. The name @samp{@@&t@@} was suggested by Paul Eggert:
  9094. @quotation
  9095. I should give some credit to the @samp{@@&t@@} pun. The @samp{&} is my
  9096. own invention, but the @samp{t} came from the source code of the
  9097. ALGOL68C compiler, written by Steve Bourne (of Bourne shell fame),
  9098. and which used @samp{mt} to denote the empty string. In C, it would
  9099. have looked like something like:
  9100. @example
  9101. char const mt[] = "";
  9102. @end example
  9103. @noindent
  9104. but of course the source code was written in Algol 68.
  9105. I don't know where he got @samp{mt} from: it could have been his own
  9106. invention, and I suppose it could have been a common pun around the
  9107. Cambridge University computer lab at the time.
  9108. @end quotation
  9109. @node Balancing Parentheses
  9110. @subsection Dealing with unbalanced parentheses
  9111. @cindex balancing parentheses
  9112. @cindex parentheses, balancing
  9113. @cindex unbalanced parentheses, managing
  9114. One of the pitfalls of portable shell programming is that @command{case}
  9115. statements require unbalanced parentheses (@pxref{case, , Limitations of
  9116. Shell Builtins}). With syntax highlighting
  9117. editors, the presence of unbalanced @samp{)} can interfere with editors
  9118. that perform syntax highlighting of macro contents based on finding the
  9119. matching @samp{(}. Another concern is how much editing must be done
  9120. when transferring code snippets between shell scripts and macro
  9121. definitions. But most importantly, the presence of unbalanced
  9122. parentheses can introduce expansion bugs.
  9123. For an example, here is an underquoted attempt to use the macro
  9124. @code{my_case}, which happens to expand to a portable @command{case}
  9125. statement:
  9126. @example
  9127. AC_DEFUN([my_case],
  9128. [case $file_name in
  9129. *.c) echo "C source code";;
  9130. esac])
  9131. AS_IF(:, my_case)
  9132. @end example
  9133. @noindent
  9134. In the above example, the @code{AS_IF} call underquotes its arguments.
  9135. As a result, the unbalanced @samp{)} generated by the premature
  9136. expansion of @code{my_case} results in expanding @code{AS_IF} with a
  9137. truncated parameter, and the expansion is syntactically invalid:
  9138. @example
  9139. if :; then
  9140. case $file_name in
  9141. *.c
  9142. fi echo "C source code";;
  9143. esac)
  9144. @end example
  9145. If nothing else, this should emphasize the importance of the quoting
  9146. arguments to macro calls. On the other hand, there are several
  9147. variations for defining @code{my_case} to be more robust, even when used
  9148. without proper quoting, each with some benefits and some drawbacks.
  9149. @itemize @w{}
  9150. @item Creative literal shell comment
  9151. @example
  9152. AC_DEFUN([my_case],
  9153. [case $file_name in #(
  9154. *.c) echo "C source code";;
  9155. esac])
  9156. @end example
  9157. @noindent
  9158. This version provides balanced parentheses to several editors, and can
  9159. be copied and pasted into a terminal as is. Unfortunately, it is still
  9160. unbalanced as an Autoconf argument, since @samp{#(} is an M4 comment
  9161. that masks the normal properties of @samp{(}.
  9162. @item Quadrigraph shell comment
  9163. @example
  9164. AC_DEFUN([my_case],
  9165. [case $file_name in @@%:@@(
  9166. *.c) echo "C source code";;
  9167. esac])
  9168. @end example
  9169. @noindent
  9170. This version provides balanced parentheses to even more editors, and can
  9171. be used as a balanced Autoconf argument. Unfortunately, it requires
  9172. some editing before it can be copied and pasted into a terminal, and the
  9173. use of the quadrigraph @samp{@@%:@@} for @samp{#} reduces readability.
  9174. @item Quoting just the parenthesis
  9175. @example
  9176. AC_DEFUN([my_case],
  9177. [case $file_name in
  9178. *.c[)] echo "C source code";;
  9179. esac])
  9180. @end example
  9181. @noindent
  9182. This version quotes the @samp{)}, so that it can be used as a balanced
  9183. Autoconf argument. As written, this is not balanced to an editor, but
  9184. it can be coupled with @samp{[#(]} to meet that need, too. However, it
  9185. still requires some edits before it can be copied and pasted into a
  9186. terminal.
  9187. @item Double-quoting the entire statement
  9188. @example
  9189. AC_DEFUN([my_case],
  9190. [[case $file_name in #(
  9191. *.c) echo "C source code";;
  9192. esac]])
  9193. @end example
  9194. @noindent
  9195. Since the entire macro is double-quoted, there is no problem with using
  9196. this as an Autoconf argument; and since the double-quoting is over the
  9197. entire statement, this code can be easily copied and pasted into a
  9198. terminal. However, the double quoting prevents the expansion of any
  9199. macros inside the case statement, which may cause its own set of
  9200. problems.
  9201. @item Using @code{AS_CASE}
  9202. @example
  9203. AC_DEFUN([my_case],
  9204. [AS_CASE([$file_name],
  9205. [*.c], [echo "C source code"])])
  9206. @end example
  9207. @noindent
  9208. This version avoids the balancing issue altogether, by relying on
  9209. @code{AS_CASE} (@pxref{Common Shell Constructs}); it also allows for the
  9210. expansion of @code{AC_REQUIRE} to occur prior to the entire case
  9211. statement, rather than within a branch of the case statement that might
  9212. not be taken. However, the abstraction comes with a penalty that it is
  9213. no longer a quick copy, paste, and edit to get back to shell code.
  9214. @end itemize
  9215. @node Quotation Rule Of Thumb
  9216. @subsection Quotation Rule Of Thumb
  9217. To conclude, the quotation rule of thumb is:
  9218. @center @emph{One pair of quotes per pair of parentheses.}
  9219. Never over-quote, never under-quote, in particular in the definition of
  9220. macros. In the few places where the macros need to use brackets
  9221. (usually in C program text or regular expressions), properly quote
  9222. @emph{the arguments}!
  9223. It is common to read Autoconf programs with snippets like:
  9224. @example
  9225. AC_TRY_LINK(
  9226. changequote(<<, >>)dnl
  9227. <<#include <time.h>
  9228. #ifndef tzname /* For SGI. */
  9229. extern char *tzname[]; /* RS6000 and others reject char **tzname. */
  9230. #endif>>,
  9231. changequote([, ])dnl
  9232. [atoi (*tzname);], ac_cv_var_tzname=yes, ac_cv_var_tzname=no)
  9233. @end example
  9234. @noindent
  9235. which is incredibly useless since @code{AC_TRY_LINK} is @emph{already}
  9236. double quoting, so you just need:
  9237. @example
  9238. AC_TRY_LINK(
  9239. [#include <time.h>
  9240. #ifndef tzname /* For SGI. */
  9241. extern char *tzname[]; /* RS6000 and others reject char **tzname. */
  9242. #endif],
  9243. [atoi (*tzname);],
  9244. [ac_cv_var_tzname=yes],
  9245. [ac_cv_var_tzname=no])
  9246. @end example
  9247. @noindent
  9248. The M4-fluent reader might note that these two examples are rigorously
  9249. equivalent, since M4 swallows both the @samp{changequote(<<, >>)}
  9250. and @samp{<<} @samp{>>} when it @dfn{collects} the arguments: these
  9251. quotes are not part of the arguments!
  9252. Simplified, the example above is just doing this:
  9253. @example
  9254. changequote(<<, >>)dnl
  9255. <<[]>>
  9256. changequote([, ])dnl
  9257. @end example
  9258. @noindent
  9259. instead of simply:
  9260. @example
  9261. [[]]
  9262. @end example
  9263. With macros that do not double quote their arguments (which is the
  9264. rule), double-quote the (risky) literals:
  9265. @example
  9266. AC_LINK_IFELSE([AC_LANG_PROGRAM(
  9267. [[#include <time.h>
  9268. #ifndef tzname /* For SGI. */
  9269. extern char *tzname[]; /* RS6000 and others reject char **tzname. */
  9270. #endif]],
  9271. [atoi (*tzname);])],
  9272. [ac_cv_var_tzname=yes],
  9273. [ac_cv_var_tzname=no])
  9274. @end example
  9275. Please note that the macro @code{AC_TRY_LINK} is obsolete, so you really
  9276. should be using @code{AC_LINK_IFELSE} instead.
  9277. @xref{Quadrigraphs}, for what to do if you run into a hopeless case
  9278. where quoting does not suffice.
  9279. When you create a @command{configure} script using newly written macros,
  9280. examine it carefully to check whether you need to add more quotes in
  9281. your macros. If one or more words have disappeared in the M4
  9282. output, you need more quotes. When in doubt, quote.
  9283. However, it's also possible to put on too many layers of quotes. If
  9284. this happens, the resulting @command{configure} script may contain
  9285. unexpanded macros. The @command{autoconf} program checks for this problem
  9286. by looking for the string @samp{AC_} in @file{configure}. However, this
  9287. heuristic does not work in general: for example, it does not catch
  9288. overquoting in @code{AC_DEFINE} descriptions.
  9289. @c ---------------------------------------- Using autom4te
  9290. @node Using autom4te
  9291. @section Using @command{autom4te}
  9292. The Autoconf suite, including M4sugar, M4sh, and Autotest, in addition
  9293. to Autoconf per se, heavily rely on M4. All these different uses
  9294. revealed common needs factored into a layer over M4:
  9295. @command{autom4te}@footnote{
  9296. @c
  9297. Yet another great name from Lars J. Aas.
  9298. @c
  9299. }.
  9300. @command{autom4te} is a preprocessor that is like @command{m4}.
  9301. It supports M4 extensions designed for use in tools like Autoconf.
  9302. @menu
  9303. * autom4te Invocation:: A GNU M4 wrapper
  9304. * Customizing autom4te:: Customizing the Autoconf package
  9305. @end menu
  9306. @node autom4te Invocation
  9307. @subsection Invoking @command{autom4te}
  9308. The command line arguments are modeled after M4's:
  9309. @example
  9310. autom4te @var{options} @var{files}
  9311. @end example
  9312. @noindent
  9313. @evindex M4
  9314. where the @var{files} are directly passed to @command{m4}. By default,
  9315. GNU M4 is found during configuration, but the environment
  9316. variable
  9317. @env{M4} can be set to tell @command{autom4te} where to look. In addition
  9318. to the regular expansion, it handles the replacement of the quadrigraphs
  9319. (@pxref{Quadrigraphs}), and of @samp{__oline__}, the current line in the
  9320. output. It supports an extended syntax for the @var{files}:
  9321. @table @file
  9322. @item @var{file}.m4f
  9323. This file is an M4 frozen file. Note that @emph{all the previous files
  9324. are ignored}. See the option @option{--melt} for the rationale.
  9325. @item @var{file}?
  9326. If found in the library path, the @var{file} is included for expansion,
  9327. otherwise it is ignored instead of triggering a failure.
  9328. @end table
  9329. @sp 1
  9330. Of course, it supports the Autoconf common subset of options:
  9331. @table @option
  9332. @item --help
  9333. @itemx -h
  9334. Print a summary of the command line options and exit.
  9335. @item --version
  9336. @itemx -V
  9337. Print the version number of Autoconf and exit.
  9338. @item --verbose
  9339. @itemx -v
  9340. Report processing steps.
  9341. @item --debug
  9342. @itemx -d
  9343. Don't remove the temporary files and be even more verbose.
  9344. @item --include=@var{dir}
  9345. @itemx -I @var{dir}
  9346. Also look for input files in @var{dir}. Multiple invocations
  9347. accumulate.
  9348. @item --output=@var{file}
  9349. @itemx -o @var{file}
  9350. Save output (script or trace) to @var{file}. The file @option{-} stands
  9351. for the standard output.
  9352. @end table
  9353. @sp 1
  9354. As an extension of @command{m4}, it includes the following options:
  9355. @table @option
  9356. @item --warnings=@var{category}
  9357. @itemx -W @var{category}
  9358. @evindex WARNINGS
  9359. @c FIXME: Point to the M4sugar macros, not Autoconf's.
  9360. Report the warnings related to @var{category} (which can actually be a
  9361. comma separated list). @xref{Reporting Messages}, macro
  9362. @code{AC_DIAGNOSE}, for a comprehensive list of categories. Special
  9363. values include:
  9364. @table @samp
  9365. @item all
  9366. report all the warnings
  9367. @item none
  9368. report none
  9369. @item error
  9370. treats warnings as errors
  9371. @item no-@var{category}
  9372. disable warnings falling into @var{category}
  9373. @end table
  9374. Warnings about @samp{syntax} are enabled by default, and the environment
  9375. variable @env{WARNINGS}, a comma separated list of categories, is
  9376. honored. @samp{autom4te -W @var{category}} actually
  9377. behaves as if you had run:
  9378. @example
  9379. autom4te --warnings=syntax,$WARNINGS,@var{category}
  9380. @end example
  9381. @noindent
  9382. For example, if you want to disable defaults and @env{WARNINGS}
  9383. of @command{autom4te}, but enable the warnings about obsolete
  9384. constructs, you would use @option{-W none,obsolete}.
  9385. @cindex Back trace
  9386. @cindex Macro invocation stack
  9387. @command{autom4te} displays a back trace for errors, but not for
  9388. warnings; if you want them, just pass @option{-W error}.
  9389. @item --melt
  9390. @itemx -M
  9391. Do not use frozen files. Any argument @code{@var{file}.m4f} is
  9392. replaced by @code{@var{file}.m4}. This helps tracing the macros which
  9393. are executed only when the files are frozen, typically
  9394. @code{m4_define}. For instance, running:
  9395. @example
  9396. autom4te --melt 1.m4 2.m4f 3.m4 4.m4f input.m4
  9397. @end example
  9398. @noindent
  9399. is roughly equivalent to running:
  9400. @example
  9401. m4 1.m4 2.m4 3.m4 4.m4 input.m4
  9402. @end example
  9403. @noindent
  9404. while
  9405. @example
  9406. autom4te 1.m4 2.m4f 3.m4 4.m4f input.m4
  9407. @end example
  9408. @noindent
  9409. is equivalent to:
  9410. @example
  9411. m4 --reload-state=4.m4f input.m4
  9412. @end example
  9413. @item --freeze
  9414. @itemx -F
  9415. Produce a frozen state file. @command{autom4te} freezing is stricter
  9416. than M4's: it must produce no warnings, and no output other than empty
  9417. lines (a line with white space is @emph{not} empty) and comments
  9418. (starting with @samp{#}). Unlike @command{m4}'s similarly-named option,
  9419. this option takes no argument:
  9420. @example
  9421. autom4te 1.m4 2.m4 3.m4 --freeze --output=3.m4f
  9422. @end example
  9423. @noindent
  9424. corresponds to
  9425. @example
  9426. m4 1.m4 2.m4 3.m4 --freeze-state=3.m4f
  9427. @end example
  9428. @item --mode=@var{octal-mode}
  9429. @itemx -m @var{octal-mode}
  9430. Set the mode of the non-traces output to @var{octal-mode}; by default
  9431. @samp{0666}.
  9432. @end table
  9433. @sp 1
  9434. @cindex @file{autom4te.cache}
  9435. As another additional feature over @command{m4}, @command{autom4te}
  9436. caches its results. GNU M4 is able to produce a regular
  9437. output and traces at the same time. Traces are heavily used in the
  9438. GNU Build System: @command{autoheader} uses them to build
  9439. @file{config.h.in}, @command{autoreconf} to determine what
  9440. GNU Build System components are used, @command{automake} to
  9441. ``parse'' @file{configure.ac} etc. To avoid recomputation,
  9442. traces are cached while performing regular expansion,
  9443. and conversely. This cache is (actually, the caches are) stored in
  9444. the directory @file{autom4te.cache}. @emph{It can safely be removed}
  9445. at any moment (especially if for some reason @command{autom4te}
  9446. considers it trashed).
  9447. @table @option
  9448. @item --cache=@var{directory}
  9449. @itemx -C @var{directory}
  9450. Specify the name of the directory where the result should be cached.
  9451. Passing an empty value disables caching. Be sure to pass a relative
  9452. file name, as for the time being, global caches are not supported.
  9453. @item --no-cache
  9454. Don't cache the results.
  9455. @item --force
  9456. @itemx -f
  9457. If a cache is used, consider it obsolete (but update it anyway).
  9458. @end table
  9459. @sp 1
  9460. Because traces are so important to the GNU Build System,
  9461. @command{autom4te} provides high level tracing features as compared to
  9462. M4, and helps exploiting the cache:
  9463. @table @option
  9464. @item --trace=@var{macro}[:@var{format}]
  9465. @itemx -t @var{macro}[:@var{format}]
  9466. Trace the invocations of @var{macro} according to the @var{format}.
  9467. Multiple @option{--trace} arguments can be used to list several macros.
  9468. Multiple @option{--trace} arguments for a single macro are not
  9469. cumulative; instead, you should just make @var{format} as long as
  9470. needed.
  9471. The @var{format} is a regular string, with newlines if desired, and
  9472. several special escape codes. It defaults to @samp{$f:$l:$n:$%}. It can
  9473. use the following special escapes:
  9474. @table @samp
  9475. @item $$
  9476. @c $$ restore font-lock
  9477. The character @samp{$}.
  9478. @item $f
  9479. The file name from which @var{macro} is called.
  9480. @item $l
  9481. The line number from which @var{macro} is called.
  9482. @item $d
  9483. The depth of the @var{macro} call. This is an M4 technical detail that
  9484. you probably don't want to know about.
  9485. @item $n
  9486. The name of the @var{macro}.
  9487. @item $@var{num}
  9488. The @var{num}th argument of the call to @var{macro}.
  9489. @item $@@
  9490. @itemx $@var{sep}@@
  9491. @itemx $@{@var{separator}@}@@
  9492. All the arguments passed to @var{macro}, separated by the character
  9493. @var{sep} or the string @var{separator} (@samp{,} by default). Each
  9494. argument is quoted, i.e., enclosed in a pair of square brackets.
  9495. @item $*
  9496. @itemx $@var{sep}*
  9497. @itemx $@{@var{separator}@}*
  9498. As above, but the arguments are not quoted.
  9499. @item $%
  9500. @itemx $@var{sep}%
  9501. @itemx $@{@var{separator}@}%
  9502. As above, but the arguments are not quoted, all new line characters in
  9503. the arguments are smashed, and the default separator is @samp{:}.
  9504. The escape @samp{$%} produces single-line trace outputs (unless you put
  9505. newlines in the @samp{separator}), while @samp{$@@} and @samp{$*} do
  9506. not.
  9507. @end table
  9508. @xref{autoconf Invocation}, for examples of trace uses.
  9509. @item --preselect=@var{macro}
  9510. @itemx -p @var{macro}
  9511. Cache the traces of @var{macro}, but do not enable traces. This is
  9512. especially important to save CPU cycles in the future. For instance,
  9513. when invoked, @command{autoconf} preselects all the macros that
  9514. @command{autoheader}, @command{automake}, @command{autoreconf}, etc.,
  9515. trace, so that running @command{m4} is not needed to trace them: the
  9516. cache suffices. This results in a huge speed-up.
  9517. @end table
  9518. @sp 1
  9519. @cindex Autom4te Library
  9520. Finally, @command{autom4te} introduces the concept of @dfn{Autom4te
  9521. libraries}. They consists in a powerful yet extremely simple feature:
  9522. sets of combined command line arguments:
  9523. @table @option
  9524. @item --language=@var{language}
  9525. @itemx -l @var{language}
  9526. Use the @var{language} Autom4te library. Current languages include:
  9527. @table @code
  9528. @item M4sugar
  9529. create M4sugar output.
  9530. @item M4sh
  9531. create M4sh executable shell scripts.
  9532. @item Autotest
  9533. create Autotest executable test suites.
  9534. @item Autoconf-without-aclocal-m4
  9535. create Autoconf executable configure scripts without
  9536. reading @file{aclocal.m4}.
  9537. @item Autoconf
  9538. create Autoconf executable configure scripts. This language inherits
  9539. all the characteristics of @code{Autoconf-without-aclocal-m4} and
  9540. additionally reads @file{aclocal.m4}.
  9541. @end table
  9542. @item --prepend-include=@var{dir}
  9543. @itemx -B @var{dir}
  9544. Prepend directory @var{dir} to the search path. This is used to include
  9545. the language-specific files before any third-party macros.
  9546. @end table
  9547. @cindex @file{autom4te.cfg}
  9548. As an example, if Autoconf is installed in its default location,
  9549. @file{/usr/local}, the command @samp{autom4te -l m4sugar foo.m4} is
  9550. strictly equivalent to the command:
  9551. @example
  9552. autom4te --prepend-include /usr/local/share/autoconf \
  9553. m4sugar/m4sugar.m4f --warnings syntax foo.m4
  9554. @end example
  9555. @noindent
  9556. Recursive expansion applies here: the command @samp{autom4te -l m4sh foo.m4}
  9557. is the same as @samp{autom4te --language M4sugar m4sugar/m4sh.m4f
  9558. foo.m4}, i.e.:
  9559. @example
  9560. autom4te --prepend-include /usr/local/share/autoconf \
  9561. m4sugar/m4sugar.m4f m4sugar/m4sh.m4f --mode 777 foo.m4
  9562. @end example
  9563. @noindent
  9564. The definition of the languages is stored in @file{autom4te.cfg}.
  9565. @node Customizing autom4te
  9566. @subsection Customizing @command{autom4te}
  9567. One can customize @command{autom4te} via @file{~/.autom4te.cfg} (i.e.,
  9568. as found in the user home directory), and @file{./.autom4te.cfg} (i.e.,
  9569. as found in the directory from which @command{autom4te} is run). The
  9570. order is first reading @file{autom4te.cfg}, then @file{~/.autom4te.cfg},
  9571. then @file{./.autom4te.cfg}, and finally the command line arguments.
  9572. In these text files, comments are introduced with @code{#}, and empty
  9573. lines are ignored. Customization is performed on a per-language basis,
  9574. wrapped in between a @samp{begin-language: "@var{language}"},
  9575. @samp{end-language: "@var{language}"} pair.
  9576. Customizing a language stands for appending options (@pxref{autom4te
  9577. Invocation}) to the current definition of the language. Options, and
  9578. more generally arguments, are introduced by @samp{args:
  9579. @var{arguments}}. You may use the traditional shell syntax to quote the
  9580. @var{arguments}.
  9581. As an example, to disable Autoconf caches (@file{autom4te.cache})
  9582. globally, include the following lines in @file{~/.autom4te.cfg}:
  9583. @verbatim
  9584. ## ------------------ ##
  9585. ## User Preferences. ##
  9586. ## ------------------ ##
  9587. begin-language: "Autoconf-without-aclocal-m4"
  9588. args: --no-cache
  9589. end-language: "Autoconf-without-aclocal-m4"
  9590. @end verbatim
  9591. @node Programming in M4sugar
  9592. @section Programming in M4sugar
  9593. @cindex M4sugar
  9594. M4 by itself provides only a small, but sufficient, set of all-purpose
  9595. macros. M4sugar introduces additional generic macros. Its name was
  9596. coined by Lars J. Aas: ``Readability And Greater Understanding Stands 4
  9597. M4sugar''.
  9598. M4sugar reserves the macro namespace @samp{^_m4_} for internal use, and
  9599. the macro namespace @samp{^m4_} for M4sugar macros. You should not
  9600. define your own macros into these namespaces.
  9601. @menu
  9602. * Redefined M4 Macros:: M4 builtins changed in M4sugar
  9603. * Diagnostic Macros:: Diagnostic messages from M4sugar
  9604. * Diversion support:: Diversions in M4sugar
  9605. * Conditional constructs:: Conditions in M4
  9606. * Looping constructs:: Iteration in M4
  9607. * Evaluation Macros:: More quotation and evaluation control
  9608. * Text processing Macros:: String manipulation in M4
  9609. * Number processing Macros:: Arithmetic computation in M4
  9610. * Set manipulation Macros:: Set manipulation in M4
  9611. * Forbidden Patterns:: Catching unexpanded macros
  9612. @end menu
  9613. @node Redefined M4 Macros
  9614. @subsection Redefined M4 Macros
  9615. @msindex{builtin}
  9616. @msindex{changecom}
  9617. @msindex{changequote}
  9618. @msindex{debugfile}
  9619. @msindex{debugmode}
  9620. @msindex{decr}
  9621. @msindex{define}
  9622. @msindex{divnum}
  9623. @msindex{errprint}
  9624. @msindex{esyscmd}
  9625. @msindex{eval}
  9626. @msindex{format}
  9627. @msindex{ifdef}
  9628. @msindex{incr}
  9629. @msindex{index}
  9630. @msindex{indir}
  9631. @msindex{len}
  9632. @msindex{pushdef}
  9633. @msindex{shift}
  9634. @msindex{substr}
  9635. @msindex{syscmd}
  9636. @msindex{sysval}
  9637. @msindex{traceoff}
  9638. @msindex{traceon}
  9639. @msindex{translit}
  9640. With a few exceptions, all the M4 native macros are moved in the
  9641. @samp{m4_} pseudo-namespace, e.g., M4sugar renames @code{define} as
  9642. @code{m4_define} etc.
  9643. The list of macros unchanged from M4, except for their name, is:
  9644. @itemize @minus
  9645. @item m4_builtin
  9646. @item m4_changecom
  9647. @item m4_changequote
  9648. @item m4_debugfile
  9649. @item m4_debugmode
  9650. @item m4_decr
  9651. @item m4_define
  9652. @item m4_divnum
  9653. @item m4_errprint
  9654. @item m4_esyscmd
  9655. @item m4_eval
  9656. @item m4_format
  9657. @item m4_ifdef
  9658. @item m4_incr
  9659. @item m4_index
  9660. @item m4_indir
  9661. @item m4_len
  9662. @item m4_pushdef
  9663. @item m4_shift
  9664. @item m4_substr
  9665. @item m4_syscmd
  9666. @item m4_sysval
  9667. @item m4_traceoff
  9668. @item m4_traceon
  9669. @item m4_translit
  9670. @end itemize
  9671. Some M4 macros are redefined, and are slightly incompatible with their
  9672. native equivalent.
  9673. @defmac __file__
  9674. @defmacx __line__
  9675. @MSindex __file__
  9676. @MSindex __line__
  9677. All M4 macros starting with @samp{__} retain their original name: for
  9678. example, no @code{m4__file__} is defined.
  9679. @end defmac
  9680. @defmac __oline__
  9681. @MSindex __oline__
  9682. This is not technically a macro, but a feature of Autom4te. The
  9683. sequence @code{__oline__} can be used similarly to the other m4sugar
  9684. location macros, but rather than expanding to the location of the input
  9685. file, it is translated to the line number where it appears in the output
  9686. file after all other M4 expansions.
  9687. @end defmac
  9688. @defmac dnl
  9689. @MSindex dnl
  9690. This macro kept its original name: no @code{m4_dnl} is defined.
  9691. @end defmac
  9692. @defmac m4_bpatsubst (@var{string}, @var{regexp}, @ovar{replacement})
  9693. @msindex{bpatsubst}
  9694. This macro corresponds to @code{patsubst}. The name @code{m4_patsubst}
  9695. is kept for future versions of M4sugar, once GNU M4 2.0 is
  9696. released and supports extended regular expression syntax.
  9697. @end defmac
  9698. @defmac m4_bregexp (@var{string}, @var{regexp}, @ovar{replacement})
  9699. @msindex{bregexp}
  9700. This macro corresponds to @code{regexp}. The name @code{m4_regexp}
  9701. is kept for future versions of M4sugar, once GNU M4 2.0 is
  9702. released and supports extended regular expression syntax.
  9703. @end defmac
  9704. @defmac m4_copy (@var{source}, @var{dest})
  9705. @defmacx m4_copy_force (@var{source}, @var{dest})
  9706. @defmacx m4_rename (@var{source}, @var{dest})
  9707. @defmacx m4_rename_force (@var{source}, @var{dest})
  9708. @msindex{copy}
  9709. @msindex{copy_force}
  9710. @msindex{rename}
  9711. @msindex{rename_force}
  9712. These macros aren't directly builtins, but are closely related to
  9713. @code{m4_pushdef} and @code{m4_defn}. @code{m4_copy} and
  9714. @code{m4_rename} ensure that @var{dest} is undefined, while
  9715. @code{m4_copy_force} and @code{m4_rename_force} overwrite any existing
  9716. definition. All four macros then proceed to copy the entire pushdef
  9717. stack of definitions of @var{source} over to @var{dest}. @code{m4_copy}
  9718. and @code{m4_copy_force} preserve the source (including in the special
  9719. case where @var{source} is undefined), while @code{m4_rename} and
  9720. @code{m4_rename_force} undefine the original macro name (making it an
  9721. error to rename an undefined @var{source}).
  9722. Note that attempting to invoke a renamed macro might not work, since the
  9723. macro may have a dependence on helper macros accessed via composition of
  9724. @samp{$0} but that were not also renamed; likewise, other macros may
  9725. have a hard-coded dependence on @var{source} and could break if
  9726. @var{source} has been deleted. On the other hand, it is always safe to
  9727. rename a macro to temporarily move it out of the way, then rename it
  9728. back later to restore original semantics.
  9729. @end defmac
  9730. @defmac m4_defn (@var{macro}@dots{})
  9731. @msindex{defn}
  9732. This macro fails if @var{macro} is not defined, even when using older
  9733. versions of M4 that did not warn. See @code{m4_undefine}.
  9734. Unfortunately, in order to support these older versions of M4, there are
  9735. some situations involving unbalanced quotes where concatenating multiple
  9736. macros together will work in newer M4 but not in m4sugar; use
  9737. quadrigraphs to work around this.
  9738. @end defmac
  9739. @defmac m4_divert (@var{diversion})
  9740. @msindex{divert}
  9741. M4sugar relies heavily on diversions, so rather than behaving as a
  9742. primitive, @code{m4_divert} behaves like:
  9743. @example
  9744. m4_divert_pop()m4_divert_push([@var{diversion}])
  9745. @end example
  9746. @noindent
  9747. @xref{Diversion support}, for more details about the use of the
  9748. diversion stack. In particular, this implies that @var{diversion}
  9749. should be a named diversion rather than a raw number. But be aware that
  9750. it is seldom necessary to explicitly change the diversion stack, and
  9751. that when done incorrectly, it can lead to syntactically invalid
  9752. scripts.
  9753. @end defmac
  9754. @defmac m4_dumpdef (@var{name}@dots{})
  9755. @defmacx m4_dumpdefs (@var{name}@dots{})
  9756. @msindex{dumpdef}
  9757. @msindex{dumpdefs}
  9758. @code{m4_dumpdef} is like the M4 builtin, except that this version
  9759. requires at least one argument, output always goes to standard error
  9760. rather than the current debug file, no sorting is done on multiple
  9761. arguments, and an error is issued if any
  9762. @var{name} is undefined. @code{m4_dumpdefs} is a convenience macro that
  9763. calls @code{m4_dumpdef} for all of the
  9764. @code{m4_pushdef} stack of definitions, starting with the current, and
  9765. silently does nothing if @var{name} is undefined.
  9766. Unfortunately, due to a limitation in M4 1.4.x, any macro defined as a
  9767. builtin is output as the empty string. This behavior is rectified by
  9768. using M4 1.6 or newer. However, this behavior difference means that
  9769. @code{m4_dumpdef} should only be used while developing m4sugar macros,
  9770. and never in the final published form of a macro.
  9771. @end defmac
  9772. @defmac m4_esyscmd_s (@var{command})
  9773. @msindex{esyscmd_s}
  9774. Like @code{m4_esyscmd}, this macro expands to the result of running
  9775. @var{command} in a shell. The difference is that any trailing newlines
  9776. are removed, so that the output behaves more like shell command
  9777. substitution.
  9778. @end defmac
  9779. @defmac m4_exit (@var{exit-status})
  9780. @msindex{exit}
  9781. This macro corresponds to @code{m4exit}.
  9782. @end defmac
  9783. @defmac m4_if (@var{comment})
  9784. @defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal}, @ovar{not-equal})
  9785. @defmacx m4_if (@var{string-1}, @var{string-2}, @var{equal-1}, @
  9786. @var{string-3}, @var{string-4}, @var{equal-2}, @dots{}, @ovar{not-equal})
  9787. @msindex{if}
  9788. This macro corresponds to @code{ifelse}. @var{string-1} and
  9789. @var{string-2} are compared literally, so usually one of the two
  9790. arguments is passed unquoted. @xref{Conditional constructs}, for more
  9791. conditional idioms.
  9792. @end defmac
  9793. @defmac m4_include (@var{file})
  9794. @defmacx m4_sinclude (@var{file})
  9795. @msindex{include}
  9796. @msindex{sinclude}
  9797. Like the M4 builtins, but warn against multiple inclusions of @var{file}.
  9798. @end defmac
  9799. @defmac m4_mkstemp (@var{template})
  9800. @defmacx m4_maketemp (@var{template})
  9801. @msindex{maketemp}
  9802. @msindex{mkstemp}
  9803. Posix requires @code{maketemp} to replace the trailing @samp{X}
  9804. characters in @var{template} with the process id, without regards to the
  9805. existence of a file by that name, but this a security hole. When this
  9806. was pointed out to the Posix folks, they agreed to invent a new macro
  9807. @code{mkstemp} that always creates a uniquely named file, but not all
  9808. versions of GNU M4 support the new macro. In M4sugar,
  9809. @code{m4_maketemp} and @code{m4_mkstemp} are synonyms for each other,
  9810. and both have the secure semantics regardless of which macro the
  9811. underlying M4 provides.
  9812. @end defmac
  9813. @defmac m4_popdef (@var{macro}@dots{})
  9814. @msindex{popdef}
  9815. This macro fails if @var{macro} is not defined, even when using older
  9816. versions of M4 that did not warn. See @code{m4_undefine}.
  9817. @end defmac
  9818. @defmac m4_undefine (@var{macro}@dots{})
  9819. @msindex{undefine}
  9820. This macro fails if @var{macro} is not defined, even when using older
  9821. versions of M4 that did not warn. Use
  9822. @example
  9823. m4_ifdef([@var{macro}], [m4_undefine([@var{macro}])])
  9824. @end example
  9825. @noindent
  9826. if you are not sure whether @var{macro} is defined.
  9827. @end defmac
  9828. @defmac m4_undivert (@var{diversion}@dots{})
  9829. @msindex{undivert}
  9830. Unlike the M4 builtin, at least one @var{diversion} must be specified.
  9831. Also, since the M4sugar diversion stack prefers named
  9832. diversions, the use of @code{m4_undivert} to include files is risky.
  9833. @xref{Diversion support}, for more details about the use of the
  9834. diversion stack. But be aware that it is seldom necessary to explicitly
  9835. change the diversion stack, and that when done incorrectly, it can lead
  9836. to syntactically invalid scripts.
  9837. @end defmac
  9838. @defmac m4_wrap (@var{text})
  9839. @defmacx m4_wrap_lifo (@var{text})
  9840. @msindex{wrap}
  9841. @msindex{wrap_lifo}
  9842. These macros correspond to @code{m4wrap}. Posix requires arguments of
  9843. multiple wrap calls to be reprocessed at EOF in the same order
  9844. as the original calls (first-in, first-out). GNU M4 versions
  9845. through 1.4.10, however, reprocess them in reverse order (last-in,
  9846. first-out). Both orders are useful, therefore, you can rely on
  9847. @code{m4_wrap} to provide FIFO semantics and @code{m4_wrap_lifo} for
  9848. LIFO semantics, regardless of the underlying GNU M4 version.
  9849. Unlike the GNU M4 builtin, these macros only recognize one
  9850. argument, and avoid token pasting between consecutive invocations. On
  9851. the other hand, nested calls to @code{m4_wrap} from within wrapped text
  9852. work just as in the builtin.
  9853. @end defmac
  9854. @node Diagnostic Macros
  9855. @subsection Diagnostic messages from M4sugar
  9856. @cindex Messages, from @command{M4sugar}
  9857. When macros statically diagnose abnormal situations, benign or fatal,
  9858. they should report them using these macros. For issuing dynamic issues,
  9859. i.e., when @command{configure} is run, see @ref{Printing Messages}.
  9860. @defmac m4_assert (@var{expression}, @dvar{exit-status, 1})
  9861. @msindex{assert}
  9862. Assert that the arithmetic @var{expression} evaluates to non-zero.
  9863. Otherwise, issue a fatal error, and exit @command{autom4te} with
  9864. @var{exit-status}.
  9865. @end defmac
  9866. @defmac m4_errprintn (@var{message})
  9867. @msindex{errprintn}
  9868. Similar to the builtin @code{m4_errprint}, except that a newline is
  9869. guaranteed after @var{message}.
  9870. @end defmac
  9871. @anchor{m4_fatal}
  9872. @defmac m4_fatal (@var{message})
  9873. @msindex{fatal}
  9874. Report a severe error @var{message} prefixed with the current location,
  9875. and have @command{autom4te} die.
  9876. @end defmac
  9877. @defmac m4_location
  9878. @msindex{location}
  9879. Useful as a prefix in a message line. Short for:
  9880. @example
  9881. __file__:__line__
  9882. @end example
  9883. @end defmac
  9884. @anchor{m4_warn}
  9885. @defmac m4_warn (@var{category}, @var{message})
  9886. @msindex{warn}
  9887. Report @var{message} as a warning (or as an error if requested by the
  9888. user) if warnings of the @var{category} are turned on. If the message
  9889. is emitted, it is prefixed with the current location, and followed by a
  9890. call trace of all macros defined via @code{AC_DEFUN} used to get to the
  9891. current expansion. You are encouraged to use standard categories, which
  9892. currently include:
  9893. @table @samp
  9894. @item all
  9895. messages that don't fall into one of the following categories. Use of an
  9896. empty @var{category} is equivalent.
  9897. @item cross
  9898. related to cross compilation issues.
  9899. @item obsolete
  9900. use of an obsolete construct.
  9901. @item syntax
  9902. dubious syntactic constructs, incorrectly ordered macro calls.
  9903. @end table
  9904. @end defmac
  9905. @node Diversion support
  9906. @subsection Diversion support
  9907. M4sugar makes heavy use of diversions under the hood, because it is
  9908. often the case that
  9909. text that must appear early in the output is not discovered until late
  9910. in the input. Additionally, some of the topological sorting algorithms
  9911. used in resolving macro dependencies use diversions. However, most
  9912. macros should not need to change diversions directly, but rather rely on
  9913. higher-level M4sugar macros to manage diversions transparently. If you
  9914. change diversions improperly, you risk generating a syntactically
  9915. invalid script, because an incorrect diversion will violate assumptions
  9916. made by many macros about whether prerequisite text has been previously
  9917. output. In short, if you manually change the diversion, you should not
  9918. expect any macros provided by the Autoconf package to work until you
  9919. have restored the diversion stack back to its original state.
  9920. In the rare case that it is necessary to write a macro that explicitly
  9921. outputs text to a different diversion, it is important to be aware of an
  9922. M4 limitation regarding diversions: text only goes to a diversion if it
  9923. is not part of argument collection. Therefore, any macro that changes
  9924. the current diversion cannot be used as an unquoted argument to another
  9925. macro, but must be expanded at the top level. The macro
  9926. @code{m4_expand} will diagnose any attempt to change diversions, since
  9927. it is generally useful only as an argument to another macro. The
  9928. following example shows what happens when diversion manipulation is
  9929. attempted within macro arguments:
  9930. @example
  9931. m4_do([normal text]
  9932. m4_divert_push([KILL])unwanted[]m4_divert_pop([KILL])
  9933. [m4_divert_push([KILL])discarded[]m4_divert_pop([KILL])])dnl
  9934. @result{}normal text
  9935. @result{}unwanted
  9936. @end example
  9937. @noindent
  9938. Notice that the unquoted text @code{unwanted} is output, even though it
  9939. was processed while the current diversion was @code{KILL}, because it
  9940. was collected as part of the argument to @code{m4_do}. However, the
  9941. text @code{discarded} disappeared as desired, because the diversion
  9942. changes were single-quoted, and were not expanded until the top-level
  9943. rescan of the output of @code{m4_do}.
  9944. To make diversion management easier, M4sugar uses the concept of named
  9945. diversions. Rather than using diversion numbers directly, it is nicer
  9946. to associate a name with each diversion. The diversion number associated
  9947. with a particular diversion name is an implementation detail, and a
  9948. syntax warning is issued if a diversion number is used instead of a
  9949. name. In general, you should not output text
  9950. to a named diversion until after calling the appropriate initialization
  9951. routine for your language (@code{m4_init}, @code{AS_INIT},
  9952. @code{AT_INIT}, @dots{}), although there are some exceptions documented
  9953. below.
  9954. M4sugar defines two named diversions.
  9955. @table @code
  9956. @item KILL
  9957. Text written to this diversion is discarded. This is the default
  9958. diversion once M4sugar is initialized.
  9959. @item GROW
  9960. This diversion is used behind the scenes by topological sorting macros,
  9961. such as @code{AC_REQUIRE}.
  9962. @end table
  9963. M4sh adds several more named diversions.
  9964. @table @code
  9965. @item BINSH
  9966. This diversion is reserved for the @samp{#!} interpreter line.
  9967. @item HEADER-REVISION
  9968. This diversion holds text from @code{AC_REVISION}.
  9969. @item HEADER-COMMENT
  9970. This diversion holds comments about the purpose of a file.
  9971. @item HEADER-COPYRIGHT
  9972. This diversion is managed by @code{AC_COPYRIGHT}.
  9973. @item M4SH-SANITIZE
  9974. This diversion contains M4sh sanitization code, used to ensure M4sh is
  9975. executing in a reasonable shell environment.
  9976. @item M4SH-INIT
  9977. This diversion contains M4sh initialization code, initializing variables
  9978. that are required by other M4sh macros.
  9979. @item BODY
  9980. This diversion contains the body of the shell code, and is the default
  9981. diversion once M4sh is initialized.
  9982. @end table
  9983. Autotest inherits diversions from M4sh, and changes the default
  9984. diversion from @code{BODY} back to @code{KILL}. It also adds several
  9985. more named diversions, with the following subset designed for developer
  9986. use.
  9987. @table @code
  9988. @item PREPARE_TESTS
  9989. This diversion contains initialization sequences which are executed
  9990. after @file{atconfig} and @file{atlocal}, and after all command line
  9991. arguments have been parsed, but prior to running any tests. It can be
  9992. used to set up state that is required across all tests. This diversion
  9993. will work even before @code{AT_INIT}.
  9994. @end table
  9995. Autoconf inherits diversions from M4sh, and adds the following named
  9996. diversions which developers can utilize.
  9997. @table @code
  9998. @item DEFAULTS
  9999. This diversion contains shell variable assignments to set defaults that
  10000. must be in place before arguments are parsed. This diversion is placed
  10001. early enough in @file{configure} that it is unsafe to expand any
  10002. autoconf macros into this diversion.
  10003. @item HELP_ENABLE
  10004. If @code{AC_PRESERVE_HELP_ORDER} was used, then text placed in this
  10005. diversion will be included as part of a quoted here-doc providing all of
  10006. the @option{--help} output of @file{configure} related to options
  10007. created by @code{AC_ARG_WITH} and @code{AC_ARG_ENABLE}.
  10008. @item INIT_PREPARE
  10009. This diversion occurs after all command line options have been parsed,
  10010. but prior to the main body of the @file{configure} script. This
  10011. diversion is the last chance to insert shell code such as variable
  10012. assignments or shell function declarations that will used by the
  10013. expansion of other macros.
  10014. @end table
  10015. For now, the remaining named diversions of Autoconf, Autoheader, and
  10016. Autotest are not documented. In other words,
  10017. intentionally outputting text into an undocumented diversion is subject
  10018. to breakage in a future release of Autoconf.
  10019. @defmac m4_cleardivert (@var{diversion}@dots{})
  10020. @msindex{cleardivert}
  10021. Permanently discard any text that has been diverted into
  10022. @var{diversion}.
  10023. @end defmac
  10024. @defmac m4_divert_once (@var{diversion}, @ovar{content})
  10025. @msindex{divert_once}
  10026. Similar to @code{m4_divert_text}, except that @var{content} is only
  10027. output to @var{diversion} if this is the first time that
  10028. @code{m4_divert_once} has been called with its particular arguments.
  10029. @end defmac
  10030. @defmac m4_divert_pop (@ovar{diversion})
  10031. @msindex{divert_pop}
  10032. If provided, check that the current diversion is indeed @var{diversion}.
  10033. Then change to the diversion located earlier on the stack, giving an
  10034. error if an attempt is made to pop beyond the initial m4sugar diversion
  10035. of @code{KILL}.
  10036. @end defmac
  10037. @defmac m4_divert_push (@var{diversion})
  10038. @msindex{divert_push}
  10039. Remember the former diversion on the diversion stack, and output
  10040. subsequent text into @var{diversion}. M4sugar maintains a diversion
  10041. stack, and issues an error if there is not a matching pop for every
  10042. push.
  10043. @end defmac
  10044. @defmac m4_divert_text (@var{diversion}, @ovar{content})
  10045. @msindex{divert_text}
  10046. Output @var{content} and a newline into @var{diversion}, without
  10047. affecting the current diversion. Shorthand for:
  10048. @example
  10049. m4_divert_push([@var{diversion}])@var{content}
  10050. m4_divert_pop([@var{diversion}])dnl
  10051. @end example
  10052. One use of @code{m4_divert_text} is to develop two related macros, where
  10053. macro @samp{MY_A} does the work, but adjusts what work is performed
  10054. based on whether the optional macro @samp{MY_B} has also been expanded.
  10055. Of course, it is possible to use @code{AC_BEFORE} within @code{MY_A} to
  10056. require that @samp{MY_B} occurs first, if it occurs at all. But this
  10057. imposes an ordering restriction on the user; it would be nicer if macros
  10058. @samp{MY_A} and @samp{MY_B} can be invoked in either order. The trick
  10059. is to let @samp{MY_B} leave a breadcrumb in an early diversion, which
  10060. @samp{MY_A} can then use to determine whether @samp{MY_B} has been
  10061. expanded.
  10062. @example
  10063. AC_DEFUN([MY_A],
  10064. [# various actions
  10065. if test -n "$b_was_used"; then
  10066. # extra action
  10067. fi])
  10068. AC_DEFUN([MY_B],
  10069. [AC_REQUIRE([MY_A])dnl
  10070. m4_divert_text([INIT_PREPARE], [b_was_used=true])])
  10071. @end example
  10072. @end defmac
  10073. @defmac m4_init
  10074. @msindex{init}
  10075. Initialize the M4sugar environment, setting up the default named
  10076. diversion to be @code{KILL}.
  10077. @end defmac
  10078. @node Conditional constructs
  10079. @subsection Conditional constructs
  10080. The following macros provide additional conditional constructs as
  10081. convenience wrappers around @code{m4_if}.
  10082. @defmac m4_bmatch (@var{string}, @var{regex-1}, @var{value-1}, @
  10083. @ovar{regex-2}, @ovar{value-2}, @dots{}, @ovar{default})
  10084. @msindex{bmatch}
  10085. The string @var{string} is repeatedly compared against a series of
  10086. @var{regex} arguments; if a match is found, the expansion is the
  10087. corresponding @var{value}, otherwise, the macro moves on to the next
  10088. @var{regex}. If no @var{regex} match, then the result is the optional
  10089. @var{default}, or nothing.
  10090. @end defmac
  10091. @defmac m4_bpatsubsts (@var{string}, @var{regex-1}, @var{subst-1}, @
  10092. @ovar{regex-2}, @ovar{subst-2}, @dots{})
  10093. @msindex{bpatsubsts}
  10094. The string @var{string} is altered by @var{regex-1} and @var{subst-1},
  10095. as if by:
  10096. @example
  10097. m4_bpatsubst([[@var{string}]], [@var{regex}], [@var{subst}])
  10098. @end example
  10099. @noindent
  10100. The result of the substitution is then passed through the next set of
  10101. @var{regex} and @var{subst}, and so forth. An empty @var{subst} implies
  10102. deletion of any matched portions in the current string. Note that this
  10103. macro over-quotes @var{string}; this behavior is intentional, so that
  10104. the result of each step of the recursion remains as a quoted string.
  10105. However, it means that anchors (@samp{^} and @samp{$} in the @var{regex}
  10106. will line up with the extra quotations, and not the characters of the
  10107. original string. The overquoting is removed after the final
  10108. substitution.
  10109. @end defmac
  10110. @defmac m4_case (@var{string}, @var{value-1}, @var{if-value-1}, @
  10111. @ovar{value-2}, @ovar{if-value-2}, @dots{}, @ovar{default})
  10112. @msindex{case}
  10113. Test @var{string} against multiple @var{value} possibilities, resulting
  10114. in the first @var{if-value} for a match, or in the optional
  10115. @var{default}. This is shorthand for:
  10116. @example
  10117. m4_if([@var{string}], [@var{value-1}], [@var{if-value-1}],
  10118. [@var{string}], [@var{value-2}], [@var{if-value-2}], @dots{},
  10119. [@var{default}])
  10120. @end example
  10121. @end defmac
  10122. @defmac m4_cond (@var{test-1}, @var{value-1}, @var{if-value-1}, @
  10123. @ovar{test-2}, @ovar{value-2}, @ovar{if-value-2}, @dots{}, @ovar{default})
  10124. @msindex{cond}
  10125. This macro was introduced in Autoconf 2.62. Similar to @code{m4_if},
  10126. except that each @var{test} is expanded only when it is encountered.
  10127. This is useful for short-circuiting expensive tests; while @code{m4_if}
  10128. requires all its strings to be expanded up front before doing
  10129. comparisons, @code{m4_cond} only expands a @var{test} when all earlier
  10130. tests have failed.
  10131. For an example, these two sequences give the same result, but in the
  10132. case where @samp{$1} does not contain a backslash, the @code{m4_cond}
  10133. version only expands @code{m4_index} once, instead of five times, for
  10134. faster computation if this is a common case for @samp{$1}. Notice that
  10135. every third argument is unquoted for @code{m4_if}, and quoted for
  10136. @code{m4_cond}:
  10137. @example
  10138. m4_if(m4_index([$1], [\]), [-1], [$2],
  10139. m4_eval(m4_index([$1], [\\]) >= 0), [1], [$2],
  10140. m4_eval(m4_index([$1], [\$]) >= 0), [1], [$2],
  10141. m4_eval(m4_index([$1], [\`]) >= 0), [1], [$3],
  10142. m4_eval(m4_index([$1], [\"]) >= 0), [1], [$3],
  10143. [$2])
  10144. m4_cond([m4_index([$1], [\])], [-1], [$2],
  10145. [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2],
  10146. [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2],
  10147. [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3],
  10148. [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3],
  10149. [$2])
  10150. @end example
  10151. @end defmac
  10152. @defmac m4_default (@var{expr-1}, @var{expr-2})
  10153. @defmacx m4_default_quoted (@var{expr-1}, @var{expr-2})
  10154. @defmacx m4_default_nblank (@var{expr-1}, @ovar{expr-2})
  10155. @defmacx m4_default_nblank_quoted (@var{expr-1}, @ovar{expr-2})
  10156. @msindex{default}
  10157. @msindex{default_quoted}
  10158. @msindex{default_nblank}
  10159. @msindex{default_nblank_quoted}
  10160. If @var{expr-1} contains text, use it. Otherwise, select @var{expr-2}.
  10161. @code{m4_default} expands the result, while @code{m4_default_quoted}
  10162. does not. Useful for providing a fixed default if the expression that
  10163. results in @var{expr-1} would otherwise be empty. The difference
  10164. between @code{m4_default} and @code{m4_default_nblank} is whether an
  10165. argument consisting of just blanks (space, tab, newline) is
  10166. significant. When using the expanding versions, note that an argument
  10167. may contain text but still expand to an empty string.
  10168. @example
  10169. m4_define([active], [ACTIVE])dnl
  10170. m4_define([empty], [])dnl
  10171. m4_define([demo1], [m4_default([$1], [$2])])dnl
  10172. m4_define([demo2], [m4_default_quoted([$1], [$2])])dnl
  10173. m4_define([demo3], [m4_default_nblank([$1], [$2])])dnl
  10174. m4_define([demo4], [m4_default_nblank_quoted([$1], [$2])])dnl
  10175. demo1([active], [default])
  10176. @result{}ACTIVE
  10177. demo1([], [active])
  10178. @result{}ACTIVE
  10179. demo1([empty], [text])
  10180. @result{}
  10181. -demo1([ ], [active])-
  10182. @result{}- -
  10183. demo2([active], [default])
  10184. @result{}active
  10185. demo2([], [active])
  10186. @result{}active
  10187. demo2([empty], [text])
  10188. @result{}empty
  10189. -demo2([ ], [active])-
  10190. @result{}- -
  10191. demo3([active], [default])
  10192. @result{}ACTIVE
  10193. demo3([], [active])
  10194. @result{}ACTIVE
  10195. demo3([empty], [text])
  10196. @result{}
  10197. -demo3([ ], [active])-
  10198. @result{}-ACTIVE-
  10199. demo4([active], [default])
  10200. @result{}active
  10201. demo4([], [active])
  10202. @result{}active
  10203. demo4([empty], [text])
  10204. @result{}empty
  10205. -demo4([ ], [active])-
  10206. @result{}-active-
  10207. @end example
  10208. @end defmac
  10209. @defmac m4_define_default (@var{macro}, @ovar{default-definition})
  10210. @msindex{define_default}
  10211. If @var{macro} does not already have a definition, then define it to
  10212. @var{default-definition}.
  10213. @end defmac
  10214. @defmac m4_ifblank (@var{cond}, @ovar{if-blank}, @ovar{if-text})
  10215. @defmacx m4_ifnblank (@var{cond}, @ovar{if-text}, @ovar{if-blank})
  10216. @msindex{ifblank}
  10217. @msindex{ifnblank}
  10218. If @var{cond} is empty or consists only of blanks (space, tab, newline),
  10219. then expand @var{if-blank}; otherwise, expand @var{if-text}. Two
  10220. variants exist, in order to make it easier to select the correct logical
  10221. sense when using only two parameters. Note that this is more efficient
  10222. than the equivalent behavior of:
  10223. @example
  10224. m4_ifval(m4_normalize([@var{cond}]), @var{if-text}, @var{if-blank})
  10225. @end example
  10226. @end defmac
  10227. @defmac m4_ifndef (@var{macro}, @var{if-not-defined}, @ovar{if-defined})
  10228. @msindex{ifndef}
  10229. This is shorthand for:
  10230. @example
  10231. m4_ifdef([@var{macro}], [@var{if-defined}], [@var{if-not-defined}])
  10232. @end example
  10233. @end defmac
  10234. @defmac m4_ifset (@var{macro}, @ovar{if-true}, @ovar{if-false})
  10235. @msindex{ifset}
  10236. If @var{macro} is undefined, or is defined as the empty string, expand
  10237. to @var{if-false}. Otherwise, expands to @var{if-true}. Similar to:
  10238. @example
  10239. m4_ifval(m4_defn([@var{macro}]), [@var{if-true}], [@var{if-false}])
  10240. @end example
  10241. @noindent
  10242. except that it is not an error if @var{macro} is undefined.
  10243. @end defmac
  10244. @defmac m4_ifval (@var{cond}, @ovar{if-true}, @ovar{if-false})
  10245. @msindex{ifval}
  10246. Expands to @var{if-true} if @var{cond} is not empty, otherwise to
  10247. @var{if-false}. This is shorthand for:
  10248. @example
  10249. m4_if([@var{cond}], [], [@var{if-false}], [@var{if-true}])
  10250. @end example
  10251. @end defmac
  10252. @defmac m4_ifvaln (@var{cond}, @ovar{if-true}, @ovar{if-false})
  10253. @msindex{ifvaln}
  10254. Similar to @code{m4_ifval}, except guarantee that a newline is present
  10255. after any non-empty expansion. Often followed by @code{dnl}.
  10256. @end defmac
  10257. @defmac m4_n (@var{text})
  10258. @msindex{n}
  10259. Expand to @var{text}, and add a newline if @var{text} is not empty.
  10260. Often followed by @code{dnl}.
  10261. @end defmac
  10262. @node Looping constructs
  10263. @subsection Looping constructs
  10264. The following macros are useful in implementing recursive algorithms in
  10265. M4, including loop operations. An M4 list is formed by quoting a list
  10266. of quoted elements; generally the lists are comma-separated, although
  10267. @code{m4_foreach_w} is whitespace-separated. For example, the list
  10268. @samp{[[a], [b,c]]} contains two elements: @samp{[a]} and @samp{[b,c]}.
  10269. It is common to see lists with unquoted elements when those elements are
  10270. not likely to be macro names, as in @samp{[fputc_unlocked,
  10271. fgetc_unlocked]}.
  10272. Although not generally recommended, it is possible for quoted lists to
  10273. have side effects; all side effects are expanded only once, and prior to
  10274. visiting any list element. On the other hand, the fact that unquoted
  10275. macros are expanded exactly once means that macros without side effects
  10276. can be used to generate lists. For example,
  10277. @example
  10278. m4_foreach([i], [[1], [2], [3]m4_errprintn([hi])], [i])
  10279. @error{}hi
  10280. @result{}123
  10281. m4_define([list], [[1], [2], [3]])
  10282. @result{}
  10283. m4_foreach([i], [list], [i])
  10284. @result{}123
  10285. @end example
  10286. @defmac m4_argn (@var{n}, @ovar{arg}@dots{})
  10287. @msindex{argn}
  10288. Extracts argument @var{n} (larger than 0) from the remaining arguments.
  10289. If there are too few arguments, the empty string is used. For any
  10290. @var{n} besides 1, this is more efficient than the similar
  10291. @samp{m4_car(m4_shiftn([@var{n}], [], [@var{arg}@dots{}]))}.
  10292. @end defmac
  10293. @defmac m4_car (@var{arg}@dots{})
  10294. @msindex{car}
  10295. Expands to the quoted first @var{arg}. Can be used with @code{m4_cdr}
  10296. to recursively iterate
  10297. through a list. Generally, when using quoted lists of quoted elements,
  10298. @code{m4_car} should be called without any extra quotes.
  10299. @end defmac
  10300. @defmac m4_cdr (@var{arg}@dots{})
  10301. @msindex{cdr}
  10302. Expands to a quoted list of all but the first @var{arg}, or the empty
  10303. string if there was only one argument. Generally, when using quoted
  10304. lists of quoted elements, @code{m4_cdr} should be called without any
  10305. extra quotes.
  10306. For example, this is a simple implementation of @code{m4_map}; note how
  10307. each iteration checks for the end of recursion, then merely applies the
  10308. first argument to the first element of the list, then repeats with the
  10309. rest of the list. (The actual implementation in M4sugar is a bit more
  10310. involved, to gain some speed and share code with @code{m4_map_sep}, and
  10311. also to avoid expanding side effects in @samp{$2} twice).
  10312. @example
  10313. m4_define([m4_map], [m4_ifval([$2],
  10314. [m4_apply([$1], m4_car($2))[]$0([$1], m4_cdr($2))])])dnl
  10315. m4_map([ m4_eval], [[[1]], [[1+1]], [[10],[16]]])
  10316. @result{} 1 2 a
  10317. @end example
  10318. @end defmac
  10319. @defmac m4_for (@var{var}, @var{first}, @var{last}, @ovar{step}, @
  10320. @var{expression})
  10321. @msindex{for}
  10322. Loop over the numeric values between @var{first} and @var{last}
  10323. including bounds by increments of @var{step}. For each iteration,
  10324. expand @var{expression} with the numeric value assigned to @var{var}.
  10325. If @var{step} is omitted, it defaults to @samp{1} or @samp{-1} depending
  10326. on the order of the limits. If given, @var{step} has to match this
  10327. order. The number of iterations is determined independently from
  10328. definition of @var{var}; iteration cannot be short-circuited or
  10329. lengthened by modifying @var{var} from within @var{expression}.
  10330. @end defmac
  10331. @defmac m4_foreach (@var{var}, @var{list}, @var{expression})
  10332. @msindex{foreach}
  10333. Loop over the comma-separated M4 list @var{list}, assigning each value
  10334. to @var{var}, and expand @var{expression}. The following example
  10335. outputs two lines:
  10336. @example
  10337. m4_foreach([myvar], [[foo], [bar, baz]],
  10338. [echo myvar
  10339. ])dnl
  10340. @result{}echo foo
  10341. @result{}echo bar, baz
  10342. @end example
  10343. Note that for some forms of @var{expression}, it may be faster to use
  10344. @code{m4_map_args}.
  10345. @end defmac
  10346. @anchor{m4_foreach_w}
  10347. @defmac m4_foreach_w (@var{var}, @var{list}, @var{expression})
  10348. @msindex{foreach_w}
  10349. Loop over the white-space-separated list @var{list}, assigning each value
  10350. to @var{var}, and expand @var{expression}. If @var{var} is only
  10351. referenced once in @var{expression}, it is more efficient to use
  10352. @code{m4_map_args_w}.
  10353. The deprecated macro @code{AC_FOREACH} is an alias of
  10354. @code{m4_foreach_w}.
  10355. @end defmac
  10356. @defmac m4_map (@var{macro}, @var{list})
  10357. @defmacx m4_mapall (@var{macro}, @var{list})
  10358. @defmacx m4_map_sep (@var{macro}, @var{separator}, @var{list})
  10359. @defmacx m4_mapall_sep (@var{macro}, @var{separator}, @var{list})
  10360. @msindex{map}
  10361. @msindex{mapall}
  10362. @msindex{map_sep}
  10363. @msindex{mapall_sep}
  10364. Loop over the comma separated quoted list of argument descriptions in
  10365. @var{list}, and invoke @var{macro} with the arguments. An argument
  10366. description is in turn a comma-separated quoted list of quoted elements,
  10367. suitable for @code{m4_apply}. The macros @code{m4_map} and
  10368. @code{m4_map_sep} ignore empty argument descriptions, while
  10369. @code{m4_mapall} and @code{m4_mapall_sep} invoke @var{macro} with no
  10370. arguments. The macros @code{m4_map_sep} and @code{m4_mapall_sep}
  10371. additionally expand @var{separator} between invocations of @var{macro}.
  10372. Note that @var{separator} is expanded, unlike in @code{m4_join}. When
  10373. separating output with commas, this means that the map result can be
  10374. used as a series of arguments, by using a single-quoted comma as
  10375. @var{separator}, or as a single string, by using a double-quoted comma.
  10376. @example
  10377. m4_map([m4_count], [])
  10378. @result{}
  10379. m4_map([ m4_count], [[],
  10380. [[1]],
  10381. [[1], [2]]])
  10382. @result{} 1 2
  10383. m4_mapall([ m4_count], [[],
  10384. [[1]],
  10385. [[1], [2]]])
  10386. @result{} 0 1 2
  10387. m4_map_sep([m4_eval], [,], [[[1+2]],
  10388. [[10], [16]]])
  10389. @result{}3,a
  10390. m4_map_sep([m4_echo], [,], [[[a]], [[b]]])
  10391. @result{}a,b
  10392. m4_count(m4_map_sep([m4_echo], [,], [[[a]], [[b]]]))
  10393. @result{}2
  10394. m4_map_sep([m4_echo], [[,]], [[[a]], [[b]]])
  10395. @result{}a,b
  10396. m4_count(m4_map_sep([m4_echo], [[,]], [[[a]], [[b]]]))
  10397. @result{}1
  10398. @end example
  10399. @end defmac
  10400. @defmac m4_map_args (@var{macro}, @var{arg}@dots{})
  10401. @msindex{map_args}
  10402. Repeatedly invoke @var{macro} with each successive @var{arg} as its only
  10403. argument. In the following example, three solutions are presented with
  10404. the same expansion; the solution using @code{m4_map_args} is the most
  10405. efficient.
  10406. @example
  10407. m4_define([active], [ACTIVE])dnl
  10408. m4_foreach([var], [[plain], [active]], [ m4_echo(m4_defn([var]))])
  10409. @result{} plain active
  10410. m4_map([ m4_echo], [[[plain]], [[active]]])
  10411. @result{} plain active
  10412. m4_map_args([ m4_echo], [plain], [active])
  10413. @result{} plain active
  10414. @end example
  10415. In cases where it is useful to operate on additional parameters besides
  10416. the list elements, the macro @code{m4_curry} can be used in @var{macro}
  10417. to supply the argument currying necessary to generate the desired
  10418. argument list. In the following example, @code{list_add_n} is more
  10419. efficient than @code{list_add_x}. On the other hand, using
  10420. @code{m4_map_args_sep} can be even more efficient.
  10421. @example
  10422. m4_define([list], [[1], [2], [3]])dnl
  10423. m4_define([add], [m4_eval(([$1]) + ([$2]))])dnl
  10424. dnl list_add_n(N, ARG...)
  10425. dnl Output a list consisting of each ARG added to N
  10426. m4_define([list_add_n],
  10427. [m4_shift(m4_map_args([,m4_curry([add], [$1])], m4_shift($@@)))])dnl
  10428. list_add_n([1], list)
  10429. @result{}2,3,4
  10430. list_add_n([2], list)
  10431. @result{}3,4,5
  10432. m4_define([list_add_x],
  10433. [m4_shift(m4_foreach([var], m4_dquote(m4_shift($@@)),
  10434. [,add([$1],m4_defn([var]))]))])dnl
  10435. list_add_x([1], list)
  10436. @result{}2,3,4
  10437. @end example
  10438. @end defmac
  10439. @defmac m4_map_args_pair (@var{macro}, @dvar{macro-end, macro}, @
  10440. @var{arg}@dots{})
  10441. @msindex{map_args_pair}
  10442. For every pair of arguments @var{arg}, invoke @var{macro} with two
  10443. arguments. If there is an odd number of arguments, invoke
  10444. @var{macro-end}, which defaults to @var{macro}, with the remaining
  10445. argument.
  10446. @example
  10447. m4_map_args_pair([, m4_reverse], [], [1], [2], [3])
  10448. @result{}, 2, 1, 3
  10449. m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3])
  10450. @result{}, 2, 1, [3]
  10451. m4_map_args_pair([, m4_reverse], [, m4_dquote], [1], [2], [3], [4])
  10452. @result{}, 2, 1, 4, 3
  10453. @end example
  10454. @end defmac
  10455. @defmac m4_map_args_sep (@ovar{pre}, @ovar{post}, @ovar{sep}, @var{arg}@dots{})
  10456. @msindex{map_args_sep}
  10457. Expand the sequence @code{@var{pre}[@var{arg}]@var{post}} for each
  10458. argument, additionally expanding @var{sep} between arguments. One
  10459. common use of this macro is constructing a macro call, where the opening
  10460. and closing parentheses are split between @var{pre} and @var{post}; in
  10461. particular, @code{m4_map_args([@var{macro}], [@var{arg}])} is equivalent
  10462. to @code{m4_map_args_sep([@var{macro}(], [)], [], [@var{arg}])}. This
  10463. macro provides the most efficient means for iterating over an arbitrary
  10464. list of arguments, particularly when repeatedly constructing a macro
  10465. call with more arguments than @var{arg}.
  10466. @end defmac
  10467. @defmac m4_map_args_w (@var{string}, @ovar{pre}, @ovar{post}, @ovar{sep})
  10468. @msindex{map_args_w}
  10469. Expand the sequence @code{@var{pre}[word]@var{post}} for each word in
  10470. the whitespace-separated @var{string}, additionally expanding @var{sep}
  10471. between words. This macro provides the most efficient means for
  10472. iterating over a whitespace-separated string. In particular,
  10473. @code{m4_map_args_w([@var{string}], [@var{action}(], [)])} is more
  10474. efficient than @code{m4_foreach_w([var], [@var{string}],
  10475. [@var{action}(m4_defn([var]))])}.
  10476. @end defmac
  10477. @defmac m4_shiftn (@var{count}, @dots{})
  10478. @defmacx m4_shift2 (@dots{})
  10479. @defmacx m4_shift3 (@dots{})
  10480. @msindex{shift2}
  10481. @msindex{shift3}
  10482. @msindex{shiftn}
  10483. @code{m4_shiftn} performs @var{count} iterations of @code{m4_shift},
  10484. along with validation that enough arguments were passed in to match the
  10485. shift count, and that the count is positive. @code{m4_shift2} and
  10486. @code{m4_shift3} are specializations
  10487. of @code{m4_shiftn}, introduced in Autoconf 2.62, and are more efficient
  10488. for two and three shifts, respectively.
  10489. @end defmac
  10490. @defmac m4_stack_foreach (@var{macro}, @var{action})
  10491. @defmacx m4_stack_foreach_lifo (@var{macro}, @var{action})
  10492. @msindex{stack_foreach}
  10493. @msindex{stack_foreach_lifo}
  10494. For each of the @code{m4_pushdef} definitions of @var{macro}, expand
  10495. @var{action} with the single argument of a definition of @var{macro}.
  10496. @code{m4_stack_foreach} starts with the oldest definition, while
  10497. @code{m4_stack_foreach_lifo} starts with the current definition.
  10498. @var{action} should not push or pop definitions of @var{macro}, nor is
  10499. there any guarantee that the current definition of @var{macro} matches
  10500. the argument that was passed to @var{action}. The macro @code{m4_curry}
  10501. can be used if @var{action} needs more than one argument, although in
  10502. that case it is more efficient to use @var{m4_stack_foreach_sep}.
  10503. Due to technical limitations, there are a few low-level m4sugar
  10504. functions, such as @code{m4_pushdef}, that cannot be used as the
  10505. @var{macro} argument.
  10506. @example
  10507. m4_pushdef([a], [1])m4_pushdef([a], [2])dnl
  10508. m4_stack_foreach([a], [ m4_incr])
  10509. @result{} 2 3
  10510. m4_stack_foreach_lifo([a], [ m4_curry([m4_substr], [abcd])])
  10511. @result{} cd bcd
  10512. @end example
  10513. @end defmac
  10514. @defmac m4_stack_foreach_sep (@var{macro}, @ovar{pre}, @ovar{post}, @ovar{sep})
  10515. @defmacx m4_stack_foreach_sep_lifo (@var{macro}, @ovar{pre}, @ovar{post}, @
  10516. @ovar{sep})
  10517. @msindex{stack_foreach_sep}
  10518. @msindex{stack_foreach_sep_lifo}
  10519. Expand the sequence @code{@var{pre}[definition]@var{post}} for each
  10520. @code{m4_pushdef} definition of @var{macro}, additionally expanding
  10521. @var{sep} between definitions. @code{m4_stack_foreach_sep} visits the
  10522. oldest definition first, while @code{m4_stack_foreach_sep_lifo} visits
  10523. the current definition first. This macro provides the most efficient
  10524. means for iterating over a pushdef stack. In particular,
  10525. @code{m4_stack_foreach([@var{macro}], [@var{action}])} is short for
  10526. @code{m4_stack_foreach_sep([@var{macro}], [@var{action}(], [)])}.
  10527. @end defmac
  10528. @node Evaluation Macros
  10529. @subsection Evaluation Macros
  10530. The following macros give some control over the order of the evaluation
  10531. by adding or removing levels of quotes.
  10532. @defmac m4_apply (@var{macro}, @var{list})
  10533. @msindex{apply}
  10534. Apply the elements of the quoted, comma-separated @var{list} as the
  10535. arguments to @var{macro}. If @var{list} is empty, invoke @var{macro}
  10536. without arguments. Note the difference between @code{m4_indir}, which
  10537. expects its first argument to be a macro name but can use names that are
  10538. otherwise invalid, and @code{m4_apply}, where @var{macro} can contain
  10539. other text, but must end in a valid macro name.
  10540. @example
  10541. m4_apply([m4_count], [])
  10542. @result{}0
  10543. m4_apply([m4_count], [[]])
  10544. @result{}1
  10545. m4_apply([m4_count], [[1], [2]])
  10546. @result{}2
  10547. m4_apply([m4_join], [[|], [1], [2]])
  10548. @result{}1|2
  10549. @end example
  10550. @end defmac
  10551. @defmac m4_count (@var{arg}, @dots{})
  10552. @msindex{count}
  10553. This macro returns the decimal count of the number of arguments it was
  10554. passed.
  10555. @end defmac
  10556. @defmac m4_curry (@var{macro}, @var{arg}@dots{})
  10557. @msindex{curry}
  10558. This macro performs argument currying. The expansion of this macro is
  10559. another macro name that expects exactly one argument; that argument is
  10560. then appended to the @var{arg} list, and then @var{macro} is expanded
  10561. with the resulting argument list.
  10562. @example
  10563. m4_curry([m4_curry], [m4_reverse], [1])([2])([3])
  10564. @result{}3, 2, 1
  10565. @end example
  10566. Unfortunately, due to a limitation in M4 1.4.x, it is not possible to
  10567. pass the definition of a builtin macro as the argument to the output of
  10568. @code{m4_curry}; the empty string is used instead of the builtin token.
  10569. This behavior is rectified by using M4 1.6 or newer.
  10570. @end defmac
  10571. @defmac m4_do (@var{arg}, @dots{})
  10572. @msindex{do}
  10573. This macro loops over its arguments and expands each @var{arg} in
  10574. sequence. Its main use is for readability; it allows the use of
  10575. indentation and fewer @code{dnl} to result in the same expansion. This
  10576. macro guarantees that no expansion will be concatenated with subsequent
  10577. text; to achieve full concatenation, use @code{m4_unquote(m4_join([],
  10578. @var{arg@dots{}}))}.
  10579. @example
  10580. m4_define([ab],[1])m4_define([bc],[2])m4_define([abc],[3])dnl
  10581. m4_do([a],[b])c
  10582. @result{}abc
  10583. m4_unquote(m4_join([],[a],[b]))c
  10584. @result{}3
  10585. m4_define([a],[A])m4_define([b],[B])m4_define([c],[C])dnl
  10586. m4_define([AB],[4])m4_define([BC],[5])m4_define([ABC],[6])dnl
  10587. m4_do([a],[b])c
  10588. @result{}ABC
  10589. m4_unquote(m4_join([],[a],[b]))c
  10590. @result{}3
  10591. @end example
  10592. @end defmac
  10593. @defmac m4_dquote (@var{arg}, @dots{})
  10594. @msindex{dquote}
  10595. Return the arguments as a quoted list of quoted arguments.
  10596. Conveniently, if there is just one @var{arg}, this effectively adds a
  10597. level of quoting.
  10598. @end defmac
  10599. @defmac m4_dquote_elt (@var{arg}, @dots{})
  10600. @msindex{dquote_elt}
  10601. Return the arguments as a series of double-quoted arguments. Whereas
  10602. @code{m4_dquote} returns a single argument, @code{m4_dquote_elt} returns
  10603. as many arguments as it was passed.
  10604. @end defmac
  10605. @defmac m4_echo (@var{arg}, @dots{})
  10606. @msindex{echo}
  10607. Return the arguments, with the same level of quoting. Other than
  10608. discarding whitespace after unquoted commas, this macro is a no-op.
  10609. @end defmac
  10610. @defmac m4_expand (@var{arg})
  10611. @msindex{expand}
  10612. Return the expansion of @var{arg} as a quoted string. Whereas
  10613. @code{m4_quote} is designed to collect expanded text into a single
  10614. argument, @code{m4_expand} is designed to perform one level of expansion
  10615. on quoted text. One distinction is in the treatment of whitespace
  10616. following a comma in the original @var{arg}. Any time multiple
  10617. arguments are collected into one with @code{m4_quote}, the M4 argument
  10618. collection rules discard the whitespace. However, with @code{m4_expand},
  10619. whitespace is preserved, even after the expansion of macros contained in
  10620. @var{arg}. Additionally, @code{m4_expand} is able to expand text that
  10621. would involve an unterminated comment, whereas expanding that same text
  10622. as the argument to @code{m4_quote} runs into difficulty in finding the
  10623. end of the argument. Since manipulating diversions during argument
  10624. collection is inherently unsafe, @code{m4_expand} issues an error if
  10625. @var{arg} attempts to change the current diversion (@pxref{Diversion
  10626. support}).
  10627. @example
  10628. m4_define([active], [ACT, IVE])dnl
  10629. m4_define([active2], [[ACT, IVE]])dnl
  10630. m4_quote(active, active)
  10631. @result{}ACT,IVE,ACT,IVE
  10632. m4_expand([active, active])
  10633. @result{}ACT, IVE, ACT, IVE
  10634. m4_quote(active2, active2)
  10635. @result{}ACT, IVE,ACT, IVE
  10636. m4_expand([active2, active2])
  10637. @result{}ACT, IVE, ACT, IVE
  10638. m4_expand([# m4_echo])
  10639. @result{}# m4_echo
  10640. m4_quote(# m4_echo)
  10641. )
  10642. @result{}# m4_echo)
  10643. @result{}
  10644. @end example
  10645. Note that @code{m4_expand} cannot handle an @var{arg} that expands to
  10646. literal unbalanced quotes, but that quadrigraphs can be used when
  10647. unbalanced output is necessary. Likewise, unbalanced parentheses should
  10648. be supplied with double quoting or a quadrigraph.
  10649. @example
  10650. m4_define([pattern], [[!@@<:@@]])dnl
  10651. m4_define([bar], [BAR])dnl
  10652. m4_expand([case $foo in
  10653. m4_defn([pattern])@@:@}@@ bar ;;
  10654. *[)] blah ;;
  10655. esac])
  10656. @result{}case $foo in
  10657. @result{} [![]) BAR ;;
  10658. @result{} *) blah ;;
  10659. @result{}esac
  10660. @end example
  10661. @end defmac
  10662. @defmac m4_ignore (@dots{})
  10663. @msindex{ignore}
  10664. This macro was introduced in Autoconf 2.62. Expands to nothing,
  10665. ignoring all of its arguments. By itself, this isn't very useful.
  10666. However, it can be used to conditionally ignore an arbitrary number of
  10667. arguments, by deciding which macro name to apply to a list of arguments.
  10668. @example
  10669. dnl foo outputs a message only if [debug] is defined.
  10670. m4_define([foo],
  10671. [m4_ifdef([debug],[AC_MSG_NOTICE],[m4_ignore])([debug message])])
  10672. @end example
  10673. Note that for earlier versions of Autoconf, the macro @code{__gnu__} can
  10674. serve the same purpose, although it is less readable.
  10675. @end defmac
  10676. @defmac m4_make_list (@var{arg}, @dots{})
  10677. @msindex{make_list}
  10678. This macro exists to aid debugging of M4sugar algorithms. Its net
  10679. effect is similar to @code{m4_dquote}---it produces a quoted list of
  10680. quoted arguments, for each @var{arg}. The difference is that this
  10681. version uses a comma-newline separator instead of just comma, to improve
  10682. readability of the list; with the result that it is less efficient than
  10683. @code{m4_dquote}.
  10684. @example
  10685. m4_define([zero],[0])m4_define([one],[1])m4_define([two],[2])dnl
  10686. m4_dquote(zero, [one], [[two]])
  10687. @result{}[0],[one],[[two]]
  10688. m4_make_list(zero, [one], [[two]])
  10689. @result{}[0],
  10690. @result{}[one],
  10691. @result{}[[two]]
  10692. m4_foreach([number], m4_dquote(zero, [one], [[two]]), [ number])
  10693. @result{} 0 1 two
  10694. m4_foreach([number], m4_make_list(zero, [one], [[two]]), [ number])
  10695. @result{} 0 1 two
  10696. @end example
  10697. @end defmac
  10698. @c m4_noquote is too dangerous to document - it invokes macros that
  10699. @c probably rely on @samp{[]} nested quoting for proper operation. The
  10700. @c user should generally prefer m4_unquote instead.
  10701. @defmac m4_quote (@var{arg}, @dots{})
  10702. @msindex{quote}
  10703. Return the arguments as a single entity, i.e., wrap them into a pair of
  10704. quotes. This effectively collapses multiple arguments into one,
  10705. although it loses whitespace after unquoted commas in the process.
  10706. @end defmac
  10707. @defmac m4_reverse (@var{arg}, @dots{})
  10708. @msindex{reverse}
  10709. Outputs each argument with the same level of quoting, but in reverse
  10710. order, and with space following each comma for readability.
  10711. @example
  10712. m4_define([active], [ACT,IVE])
  10713. @result{}
  10714. m4_reverse(active, [active])
  10715. @result{}active, IVE, ACT
  10716. @end example
  10717. @end defmac
  10718. @defmac m4_unquote (@var{arg}, @dots{})
  10719. @msindex{unquote}
  10720. This macro was introduced in Autoconf 2.62. Expand each argument,
  10721. separated by commas. For a single @var{arg}, this effectively removes a
  10722. layer of quoting, and @code{m4_unquote([@var{arg}])} is more efficient
  10723. than the equivalent @code{m4_do([@var{arg}])}. For multiple arguments,
  10724. this results in an unquoted list of expansions. This is commonly used
  10725. with @code{m4_split}, in order to convert a single quoted list into a
  10726. series of quoted elements.
  10727. @end defmac
  10728. The following example aims at emphasizing the difference between several
  10729. scenarios: not using these macros, using @code{m4_defn}, using
  10730. @code{m4_quote}, using @code{m4_dquote}, and using @code{m4_expand}.
  10731. @example
  10732. $ @kbd{cat example.m4}
  10733. dnl Overquote, so that quotes are visible.
  10734. m4_define([show], [$[]1 = [$1], $[]@@ = [$@@]])
  10735. m4_define([a], [A])
  10736. m4_define([mkargs], [1, 2[,] 3])
  10737. m4_define([arg1], [[$1]])
  10738. m4_divert([0])dnl
  10739. show(a, b)
  10740. show([a, b])
  10741. show(m4_quote(a, b))
  10742. show(m4_dquote(a, b))
  10743. show(m4_expand([a, b]))
  10744. arg1(mkargs)
  10745. arg1([mkargs])
  10746. arg1(m4_defn([mkargs]))
  10747. arg1(m4_quote(mkargs))
  10748. arg1(m4_dquote(mkargs))
  10749. arg1(m4_expand([mkargs]))
  10750. $ @kbd{autom4te -l m4sugar example.m4}
  10751. $1 = A, $@@ = [A],[b]
  10752. $1 = a, b, $@@ = [a, b]
  10753. $1 = A,b, $@@ = [A,b]
  10754. $1 = [A],[b], $@@ = [[A],[b]]
  10755. $1 = A, b, $@@ = [A, b]
  10756. 1
  10757. mkargs
  10758. 1, 2[,] 3
  10759. 1,2, 3
  10760. [1],[2, 3]
  10761. 1, 2, 3
  10762. @end example
  10763. @node Text processing Macros
  10764. @subsection String manipulation in M4
  10765. The following macros may be used to manipulate strings in M4. Many of
  10766. the macros in this section intentionally result in quoted strings as
  10767. output, rather than subjecting the arguments to further expansions. As
  10768. a result, if you are manipulating text that contains active M4
  10769. characters, the arguments are passed with single quoting rather than
  10770. double.
  10771. @defmac m4_append (@var{macro-name}, @var{string}, @ovar{separator})
  10772. @defmacx m4_append_uniq (@var{macro-name}, @var{string}, @ovar{separator} @
  10773. @ovar{if-uniq}, @ovar{if-duplicate})
  10774. @msindex{append}
  10775. @msindex{append_uniq}
  10776. Redefine @var{macro-name} to its former contents with @var{separator}
  10777. and @var{string} added at the end. If @var{macro-name} was undefined
  10778. before (but not if it was defined but empty), then no @var{separator} is
  10779. added. As of Autoconf 2.62, neither @var{string} nor @var{separator}
  10780. are expanded during this macro; instead, they are expanded when
  10781. @var{macro-name} is invoked.
  10782. @code{m4_append} can be used to grow strings, and @code{m4_append_uniq}
  10783. to grow strings without duplicating substrings. Additionally,
  10784. @code{m4_append_uniq} takes two optional parameters as of Autoconf 2.62;
  10785. @var{if-uniq} is expanded if @var{string} was appended, and
  10786. @var{if-duplicate} is expanded if @var{string} was already present.
  10787. Also, @code{m4_append_uniq} warns if @var{separator} is not empty, but
  10788. occurs within @var{string}, since that can lead to duplicates.
  10789. Note that @code{m4_append} can scale linearly in the length of the final
  10790. string, depending on the quality of the underlying M4 implementation,
  10791. while @code{m4_append_uniq} has an inherent quadratic scaling factor.
  10792. If an algorithm can tolerate duplicates in the final string, use the
  10793. former for speed. If duplicates must be avoided, consider using
  10794. @code{m4_set_add} instead (@pxref{Set manipulation Macros}).
  10795. @example
  10796. m4_define([active], [ACTIVE])dnl
  10797. m4_append([sentence], [This is an])dnl
  10798. m4_append([sentence], [ active ])dnl
  10799. m4_append([sentence], [symbol.])dnl
  10800. sentence
  10801. @result{}This is an ACTIVE symbol.
  10802. m4_undefine([active])dnl
  10803. @result{}This is an active symbol.
  10804. m4_append_uniq([list], [one], [, ], [new], [existing])
  10805. @result{}new
  10806. m4_append_uniq([list], [one], [, ], [new], [existing])
  10807. @result{}existing
  10808. m4_append_uniq([list], [two], [, ], [new], [existing])
  10809. @result{}new
  10810. m4_append_uniq([list], [three], [, ], [new], [existing])
  10811. @result{}new
  10812. m4_append_uniq([list], [two], [, ], [new], [existing])
  10813. @result{}existing
  10814. list
  10815. @result{}one, two, three
  10816. m4_dquote(list)
  10817. @result{}[one],[two],[three]
  10818. m4_append([list2], [one], [[, ]])dnl
  10819. m4_append_uniq([list2], [two], [[, ]])dnl
  10820. m4_append([list2], [three], [[, ]])dnl
  10821. list2
  10822. @result{}one, two, three
  10823. m4_dquote(list2)
  10824. @result{}[one, two, three]
  10825. @end example
  10826. @end defmac
  10827. @defmac m4_append_uniq_w (@var{macro-name}, @var{strings})
  10828. @msindex{append_uniq_w}
  10829. This macro was introduced in Autoconf 2.62. It is similar to
  10830. @code{m4_append_uniq}, but treats @var{strings} as a whitespace
  10831. separated list of words to append, and only appends unique words.
  10832. @var{macro-name} is updated with a single space between new words.
  10833. @example
  10834. m4_append_uniq_w([numbers], [1 1 2])dnl
  10835. m4_append_uniq_w([numbers], [ 2 3 ])dnl
  10836. numbers
  10837. @result{}1 2 3
  10838. @end example
  10839. @end defmac
  10840. @defmac m4_chomp (@var{string})
  10841. @defmacx m4_chomp_all (@var{string})
  10842. @msindex{chomp}
  10843. @msindex{chomp_all}
  10844. Output @var{string} in quotes, but without a trailing newline. The
  10845. macro @code{m4_chomp} is slightly faster, and removes at most one
  10846. newline; the macro @code{m4_chomp_all} removes all consecutive trailing
  10847. newlines. Unlike @code{m4_flatten}, embedded newlines are left intact,
  10848. and backslash does not influence the result.
  10849. @end defmac
  10850. @defmac m4_combine (@ovar{separator}, @var{prefix-list}, @ovar{infix}, @
  10851. @var{suffix-1}, @ovar{suffix-2}, @dots{})
  10852. @msindex{combine}
  10853. This macro produces a quoted string containing the pairwise combination
  10854. of every element of the quoted, comma-separated @var{prefix-list}, and
  10855. every element from the @var{suffix} arguments. Each pairwise
  10856. combination is joined with @var{infix} in the middle, and successive
  10857. pairs are joined by @var{separator}. No expansion occurs on any of the
  10858. arguments. No output occurs if either the @var{prefix} or @var{suffix}
  10859. list is empty, but the lists can contain empty elements.
  10860. @example
  10861. m4_define([a], [oops])dnl
  10862. m4_combine([, ], [[a], [b], [c]], [-], [1], [2], [3])
  10863. @result{}a-1, a-2, a-3, b-1, b-2, b-3, c-1, c-2, c-3
  10864. m4_combine([, ], [[a], [b]], [-])
  10865. @result{}
  10866. m4_combine([, ], [[a], [b]], [-], [])
  10867. @result{}a-, b-
  10868. m4_combine([, ], [], [-], [1], [2])
  10869. @result{}
  10870. m4_combine([, ], [[]], [-], [1], [2])
  10871. @result{}-1, -2
  10872. @end example
  10873. @end defmac
  10874. @defmac m4_escape (@var{string})
  10875. @msindex{escape}
  10876. Convert all instances of @samp{[}, @samp{]}, @samp{#}, and @samp{$}
  10877. within @var{string} into their respective quadrigraphs. The result is
  10878. still a quoted string.
  10879. @end defmac
  10880. @defmac m4_flatten (@var{string})
  10881. @msindex{flatten}
  10882. Flatten @var{string} into a single line. Delete all backslash-newline
  10883. pairs, and replace all remaining newlines with a space. The result is
  10884. still a quoted string.
  10885. @end defmac
  10886. @defmac m4_join (@ovar{separator}, @var{args}@dots{})
  10887. @defmacx m4_joinall (@ovar{separator}, @var{args}@dots{})
  10888. @msindex{join}
  10889. @msindex{joinall}
  10890. Concatenate each @var{arg}, separated by @var{separator}.
  10891. @code{joinall} uses every argument, while @code{join} omits empty
  10892. arguments so that there are no back-to-back separators in the output.
  10893. The result is a quoted string.
  10894. @example
  10895. m4_define([active], [ACTIVE])dnl
  10896. m4_join([|], [one], [], [active], [two])
  10897. @result{}one|active|two
  10898. m4_joinall([|], [one], [], [active], [two])
  10899. @result{}one||active|two
  10900. @end example
  10901. Note that if all you intend to do is join @var{args} with commas between
  10902. them, to form a quoted list suitable for @code{m4_foreach}, it is more
  10903. efficient to use @code{m4_dquote}.
  10904. @end defmac
  10905. @defmac m4_newline (@ovar{text})
  10906. @msindex{newline}
  10907. This macro was introduced in Autoconf 2.62, and expands to a newline,
  10908. followed by any @var{text}.
  10909. It is primarily useful for maintaining macro formatting, and ensuring
  10910. that M4 does not discard leading whitespace during argument collection.
  10911. @end defmac
  10912. @defmac m4_normalize (@var{string})
  10913. @msindex{normalize}
  10914. Remove leading and trailing spaces and tabs, sequences of
  10915. backslash-then-newline, and replace multiple spaces, tabs, and newlines
  10916. with a single space. This is a combination of @code{m4_flatten} and
  10917. @code{m4_strip}. To determine if @var{string} consists only of bytes
  10918. that would be removed by @code{m4_normalize}, you can use
  10919. @code{m4_ifblank}.
  10920. @end defmac
  10921. @defmac m4_re_escape (@var{string})
  10922. @msindex{re_escape}
  10923. Backslash-escape all characters in @var{string} that are active in
  10924. regexps.
  10925. @end defmac
  10926. @c We cannot use @dvar because the macro expansion mistreats backslashes.
  10927. @defmac m4_split (@var{string}, @r{[}@var{regexp} = @samp{[\t ]+}@r{]})
  10928. @msindex{split}
  10929. Split @var{string} into an M4 list of elements quoted by @samp{[} and
  10930. @samp{]}, while keeping white space at the beginning and at the end.
  10931. If @var{regexp} is given, use it instead of @samp{[\t ]+} for splitting.
  10932. If @var{string} is empty, the result is an empty list.
  10933. @end defmac
  10934. @defmac m4_strip (@var{string})
  10935. @msindex{strip}
  10936. Strip whitespace from @var{string}. Sequences of spaces and tabs are
  10937. reduced to a single space, then leading and trailing spaces are removed.
  10938. The result is still a quoted string. Note that this does not interfere
  10939. with newlines; if you want newlines stripped as well, consider
  10940. @code{m4_flatten}, or do it all at once with @code{m4_normalize}. To
  10941. quickly test if @var{string} has only whitespace, use @code{m4_ifblank}.
  10942. @end defmac
  10943. @defmac m4_text_box (@var{message}, @dvar{frame, -})
  10944. @msindex{text_box}
  10945. Add a text box around @var{message}, using @var{frame} as the border
  10946. character above and below the message. The @var{frame} argument must be
  10947. a single byte, and does not support quadrigraphs.
  10948. The frame correctly accounts for
  10949. the subsequent expansion of @var{message}. For example:
  10950. @example
  10951. m4_define([macro], [abc])dnl
  10952. m4_text_box([macro])
  10953. @result{}## --- ##
  10954. @result{}## abc ##
  10955. @result{}## --- ##
  10956. @end example
  10957. The @var{message} must contain balanced quotes and parentheses, although
  10958. quadrigraphs can be used to work around this.
  10959. @end defmac
  10960. @defmac m4_text_wrap (@var{string}, @ovar{prefix}, @
  10961. @dvar{prefix1, @var{prefix}}, @dvar{width, 79})
  10962. @msindex{text_wrap}
  10963. Break @var{string} into a series of whitespace-separated words, then
  10964. output those words separated by spaces, and wrapping lines any time the
  10965. output would exceed @var{width} columns. If given, @var{prefix1} begins
  10966. the first line, and @var{prefix} begins all wrapped lines. If
  10967. @var{prefix1} is longer than @var{prefix}, then the first line consists
  10968. of just @var{prefix1}. If @var{prefix} is longer than @var{prefix1},
  10969. padding is inserted so that the first word of @var{string} begins at the
  10970. same indentation as all wrapped lines. Note that using literal tab
  10971. characters in any of the arguments will interfere with the calculation
  10972. of width. No expansions occur on @var{prefix}, @var{prefix1}, or the
  10973. words of @var{string}, although quadrigraphs are recognized.
  10974. For some examples:
  10975. @example
  10976. m4_text_wrap([Short string */], [ ], [/* ], [20])
  10977. @result{}/* Short string */
  10978. m4_text_wrap([Much longer string */], [ ], [/* ], [20])
  10979. @result{}/* Much longer
  10980. @result{} string */
  10981. m4_text_wrap([Short doc.], [ ], [ --short ], [30])
  10982. @result{} --short Short doc.
  10983. m4_text_wrap([Short doc.], [ ], [ --too-wide ], [30])
  10984. @result{} --too-wide
  10985. @result{} Short doc.
  10986. m4_text_wrap([Super long documentation.], [ ],
  10987. [ --too-wide ], 30)
  10988. @result{} --too-wide
  10989. @result{} Super long
  10990. @result{} documentation.
  10991. @end example
  10992. @end defmac
  10993. @defmac m4_tolower (@var{string})
  10994. @defmacx m4_toupper (@var{string})
  10995. @msindex{tolower}
  10996. @msindex{toupper}
  10997. Return @var{string} with letters converted to upper or lower case,
  10998. respectively.
  10999. @end defmac
  11000. @node Number processing Macros
  11001. @subsection Arithmetic computation in M4
  11002. The following macros facilitate integer arithmetic operations.
  11003. Where a parameter is documented as taking an arithmetic expression, you
  11004. can use anything that can be parsed by @code{m4_eval}.
  11005. @defmac m4_cmp (@var{expr-1}, @var{expr-2})
  11006. @msindex{cmp}
  11007. Compare the arithmetic expressions @var{expr-1} and @var{expr-2}, and
  11008. expand to @samp{-1} if @var{expr-1} is smaller, @samp{0} if they are
  11009. equal, and @samp{1} if @var{expr-1} is larger.
  11010. @end defmac
  11011. @defmac m4_list_cmp (@var{list-1}, @var{list-2})
  11012. @msindex{list_cmp}
  11013. Compare the two M4 lists consisting of comma-separated arithmetic
  11014. expressions, left to right. Expand to @samp{-1} for the first element
  11015. pairing where the value from @var{list-1} is smaller, @samp{1} where the
  11016. value from @var{list-2} is smaller, or @samp{0} if both lists have the
  11017. same values. If one list is shorter than the other, the remaining
  11018. elements of the longer list are compared against zero.
  11019. @example
  11020. m4_list_cmp([1, 0], [1])
  11021. @result{}0
  11022. m4_list_cmp([1, [1 * 0]], [1, 0])
  11023. @result{}0
  11024. m4_list_cmp([1, 2], [1, 0])
  11025. @result{}1
  11026. m4_list_cmp([1, [1+1], 3],[1, 2])
  11027. @result{}1
  11028. m4_list_cmp([1, 2, -3], [1, 2])
  11029. @result{}-1
  11030. m4_list_cmp([1, 0], [1, 2])
  11031. @result{}-1
  11032. m4_list_cmp([1], [1, 2])
  11033. @result{}-1
  11034. @end example
  11035. @end defmac
  11036. @defmac m4_max (@var{arg}, @dots{})
  11037. @msindex{max}
  11038. This macro was introduced in Autoconf 2.62. Expand to the decimal value
  11039. of the maximum arithmetic expression among all the arguments.
  11040. @end defmac
  11041. @defmac m4_min (@var{arg}, @dots{})
  11042. @msindex{min}
  11043. This macro was introduced in Autoconf 2.62. Expand to the decimal value
  11044. of the minimum arithmetic expression among all the arguments.
  11045. @end defmac
  11046. @defmac m4_sign (@var{expr})
  11047. @msindex{sign}
  11048. Expand to @samp{-1} if the arithmetic expression @var{expr} is negative,
  11049. @samp{1} if it is positive, and @samp{0} if it is zero.
  11050. @end defmac
  11051. @anchor{m4_version_compare}
  11052. @defmac m4_version_compare (@var{version-1}, @var{version-2})
  11053. @msindex{version_compare}
  11054. This macro was introduced in Autoconf 2.53, but had a number of
  11055. usability limitations that were not lifted until Autoconf 2.62. Compare
  11056. the version strings @var{version-1} and @var{version-2}, and expand to
  11057. @samp{-1} if @var{version-1} is smaller, @samp{0} if they are the same,
  11058. or @samp{1} @var{version-2} is smaller. Version strings must be a list
  11059. of elements separated by @samp{.}, @samp{,} or @samp{-}, where each
  11060. element is a number along with optional case-insensitive letters
  11061. designating beta releases. The comparison stops at the leftmost element
  11062. that contains a difference, although a 0 element compares equal to a
  11063. missing element.
  11064. It is permissible to include commit identifiers in @var{version}, such
  11065. as an abbreviated SHA1 of the commit, provided there is still a
  11066. monotonically increasing prefix to allow for accurate version-based
  11067. comparisons. For example, this paragraph was written when the
  11068. development snapshot of autoconf claimed to be at version
  11069. @samp{2.61a-248-dc51}, or 248 commits after the 2.61a release, with an
  11070. abbreviated commit identification of @samp{dc51}.
  11071. @example
  11072. m4_version_compare([1.1], [2.0])
  11073. @result{}-1
  11074. m4_version_compare([2.0b], [2.0a])
  11075. @result{}1
  11076. m4_version_compare([1.1.1], [1.1.1a])
  11077. @result{}-1
  11078. m4_version_compare([1.2], [1.1.1a])
  11079. @result{}1
  11080. m4_version_compare([1.0], [1])
  11081. @result{}0
  11082. m4_version_compare([1.1pre], [1.1PRE])
  11083. @result{}0
  11084. m4_version_compare([1.1a], [1,10])
  11085. @result{}-1
  11086. m4_version_compare([2.61a], [2.61a-248-dc51])
  11087. @result{}-1
  11088. m4_version_compare([2.61b], [2.61a-248-dc51])
  11089. @result{}1
  11090. @end example
  11091. @end defmac
  11092. @defmac m4_version_prereq (@var{version}, @ovar{if-new-enough}, @
  11093. @dvar{if-old, m4_fatal})
  11094. @msindex{version_prereq}
  11095. Compares @var{version} against the version of Autoconf currently
  11096. running. If the running version is at @var{version} or newer, expand
  11097. @var{if-new-enough}, but if @var{version} is larger than the version
  11098. currently executing, expand @var{if-old}, which defaults to printing an
  11099. error message and exiting m4sugar with status 63. When given only one
  11100. argument, this behaves like @code{AC_PREREQ} (@pxref{Versioning}).
  11101. Remember that the autoconf philosophy favors feature checks over version
  11102. checks.
  11103. @end defmac
  11104. @node Set manipulation Macros
  11105. @subsection Set manipulation in M4
  11106. @cindex Set manipulation
  11107. @cindex Data structure, set
  11108. @cindex Unordered set manipulation
  11109. Sometimes, it is necessary to track a set of data, where the order does
  11110. not matter and where there are no duplicates in the set. The following
  11111. macros facilitate set manipulations. Each set is an opaque object,
  11112. which can only be accessed via these basic operations. The underlying
  11113. implementation guarantees linear scaling for set creation, which is more
  11114. efficient than using the quadratic @code{m4_append_uniq}. Both set
  11115. names and values can be arbitrary strings, except for unbalanced quotes.
  11116. This implementation ties up memory for removed elements until the next
  11117. operation that must traverse all the elements of a set; and although
  11118. that may slow down some operations until the memory for removed elements
  11119. is pruned, it still guarantees linear performance.
  11120. @defmac m4_set_add (@var{set}, @var{value}, @ovar{if-uniq}, @ovar{if-dup})
  11121. @msindex{set_add}
  11122. Adds the string @var{value} as a member of set @var{set}. Expand
  11123. @var{if-uniq} if the element was added, or @var{if-dup} if it was
  11124. previously in the set. Operates in amortized constant time, so that set
  11125. creation scales linearly.
  11126. @end defmac
  11127. @defmac m4_set_add_all (@var{set}, @var{value}@dots{})
  11128. @msindex{set_add_all}
  11129. Adds each @var{value} to the set @var{set}. This is slightly more
  11130. efficient than repeatedly invoking @code{m4_set_add}.
  11131. @end defmac
  11132. @defmac m4_set_contains (@var{set}, @var{value}, @ovar{if-present}, @
  11133. @ovar{if-absent})
  11134. @msindex{set_contains}
  11135. Expands @var{if-present} if the string @var{value} is a member of
  11136. @var{set}, otherwise @var{if-absent}.
  11137. @example
  11138. m4_set_contains([a], [1], [yes], [no])
  11139. @result{}no
  11140. m4_set_add([a], [1], [added], [dup])
  11141. @result{}added
  11142. m4_set_add([a], [1], [added], [dup])
  11143. @result{}dup
  11144. m4_set_contains([a], [1], [yes], [no])
  11145. @result{}yes
  11146. m4_set_remove([a], [1], [removed], [missing])
  11147. @result{}removed
  11148. m4_set_contains([a], [1], [yes], [no])
  11149. @result{}no
  11150. m4_set_remove([a], [1], [removed], [missing])
  11151. @result{}missing
  11152. @end example
  11153. @end defmac
  11154. @defmac m4_set_contents (@var{set}, @ovar{sep})
  11155. @defmacx m4_set_dump (@var{set}, @ovar{sep})
  11156. @msindex{set_contents}
  11157. @msindex{set_dump}
  11158. Expands to a single string consisting of all the members of the set
  11159. @var{set}, each separated by @var{sep}, which is not expanded.
  11160. @code{m4_set_contents} leaves the elements in @var{set} but reclaims any
  11161. memory occupied by removed elements, while @code{m4_set_dump} is a
  11162. faster one-shot action that also deletes the set. No provision is made
  11163. for disambiguating members that contain a non-empty @var{sep} as a
  11164. substring; use @code{m4_set_empty} to distinguish between an empty set
  11165. and the set containing only the empty string. The order of the output
  11166. is unspecified; in the current implementation, part of the speed of
  11167. @code{m4_set_dump} results from using a different output order than
  11168. @code{m4_set_contents}. These macros scale linearly in the size of the
  11169. set before memory pruning, and @code{m4_set_contents([@var{set}],
  11170. [@var{sep}])} is faster than
  11171. @code{m4_joinall([@var{sep}]m4_set_listc([@var{set}]))}.
  11172. @example
  11173. m4_set_add_all([a], [1], [2], [3])
  11174. @result{}
  11175. m4_set_contents([a], [-])
  11176. @result{}1-2-3
  11177. m4_joinall([-]m4_set_listc([a]))
  11178. @result{}1-2-3
  11179. m4_set_dump([a], [-])
  11180. @result{}3-2-1
  11181. m4_set_contents([a])
  11182. @result{}
  11183. m4_set_add([a], [])
  11184. @result{}
  11185. m4_set_contents([a], [-])
  11186. @result{}
  11187. @end example
  11188. @end defmac
  11189. @defmac m4_set_delete (@var{set})
  11190. @msindex{set_delete}
  11191. Delete all elements and memory associated with @var{set}. This is
  11192. linear in the set size, and faster than removing one element at a time.
  11193. @end defmac
  11194. @defmac m4_set_difference (@var{seta}, @var{setb})
  11195. @defmacx m4_set_intersection (@var{seta}, @var{setb})
  11196. @defmacx m4_set_union (@var{seta}, @var{setb})
  11197. @msindex{set_difference}
  11198. @msindex{set_intersection}
  11199. @msindex{set_union}
  11200. Compute the relation between @var{seta} and @var{setb}, and output the
  11201. result as a list of quoted arguments without duplicates and with a
  11202. leading comma. Set difference selects the elements in @var{seta} but
  11203. not @var{setb}, intersection selects only elements in both sets, and
  11204. union selects elements in either set. These actions are linear in the
  11205. sum of the set sizes. The leading comma is necessary to distinguish
  11206. between no elements and the empty string as the only element.
  11207. @example
  11208. m4_set_add_all([a], [1], [2], [3])
  11209. @result{}
  11210. m4_set_add_all([b], [3], [], [4])
  11211. @result{}
  11212. m4_set_difference([a], [b])
  11213. @result{},1,2
  11214. m4_set_difference([b], [a])
  11215. @result{},,4
  11216. m4_set_intersection([a], [b])
  11217. @result{},3
  11218. m4_set_union([a], [b])
  11219. @result{},1,2,3,,4
  11220. @end example
  11221. @end defmac
  11222. @defmac m4_set_empty (@var{set}, @ovar{if-empty}, @ovar{if-elements})
  11223. @msindex{set_empty}
  11224. Expand @var{if-empty} if the set @var{set} has no elements, otherwise
  11225. expand @var{if-elements}. This macro operates in constant time. Using
  11226. this macro can help disambiguate output from @code{m4_set_contents} or
  11227. @code{m4_set_list}.
  11228. @end defmac
  11229. @defmac m4_set_foreach (@var{set}, @var{variable}, @var{action})
  11230. @msindex{set_foreach}
  11231. For each element in the set @var{set}, expand @var{action} with the
  11232. macro @var{variable} defined as the set element. Behavior is
  11233. unspecified if @var{action} recursively lists the contents of @var{set}
  11234. (although listing other sets is acceptable), or if it modifies the set
  11235. in any way other than removing the element currently contained in
  11236. @var{variable}. This macro is faster than the corresponding
  11237. @code{m4_foreach([@var{variable}],
  11238. m4_indir([m4_dquote]m4_set_listc([@var{set}])), [@var{action}])},
  11239. although @code{m4_set_map} might be faster still.
  11240. @example
  11241. m4_set_add_all([a]m4_for([i], [1], [5], [], [,i]))
  11242. @result{}
  11243. m4_set_contents([a])
  11244. @result{}12345
  11245. m4_set_foreach([a], [i],
  11246. [m4_if(m4_eval(i&1), [0], [m4_set_remove([a], i, [i])])])
  11247. @result{}24
  11248. m4_set_contents([a])
  11249. @result{}135
  11250. @end example
  11251. @end defmac
  11252. @defmac m4_set_list (@var{set})
  11253. @defmacx m4_set_listc (@var{set})
  11254. @msindex{set_list}
  11255. @msindex{set_listc}
  11256. Produce a list of arguments, where each argument is a quoted element
  11257. from the set @var{set}. The variant @code{m4_set_listc} is unambiguous,
  11258. by adding a leading comma if there are any set elements, whereas the
  11259. variant @code{m4_set_list} cannot distinguish between an empty set and a
  11260. set containing only the empty string. These can be directly used in
  11261. macros that take multiple arguments, such as @code{m4_join} or
  11262. @code{m4_set_add_all}, or wrapped by @code{m4_dquote} for macros that
  11263. take a quoted list, such as @code{m4_map} or @code{m4_foreach}. Any
  11264. memory occupied by removed elements is reclaimed during these macros.
  11265. @example
  11266. m4_set_add_all([a], [1], [2], [3])
  11267. @result{}
  11268. m4_set_list([a])
  11269. @result{}1,2,3
  11270. m4_set_list([b])
  11271. @result{}
  11272. m4_set_listc([b])
  11273. @result{}
  11274. m4_count(m4_set_list([b]))
  11275. @result{}1
  11276. m4_set_empty([b], [0], [m4_count(m4_set_list([b]))])
  11277. @result{}0
  11278. m4_set_add([b], [])
  11279. @result{}
  11280. m4_set_list([b])
  11281. @result{}
  11282. m4_set_listc([b])
  11283. @result{},
  11284. m4_count(m4_set_list([b]))
  11285. @result{}1
  11286. m4_set_empty([b], [0], [m4_count(m4_set_list([b]))])
  11287. @result{}1
  11288. @end example
  11289. @end defmac
  11290. @defmac m4_set_map (@var{set}, @var{action})
  11291. @msindex{set_map}
  11292. For each element in the set @var{set}, expand @var{action} with a single
  11293. argument of the set element. Behavior is unspecified if @var{action}
  11294. recursively lists the contents of @var{set} (although listing other sets
  11295. is acceptable), or if it modifies the set in any way other than removing
  11296. the element passed as an argument. This macro is faster than either
  11297. corresponding counterpart of
  11298. @code{m4_map_args([@var{action}]m4_set_listc([@var{set}]))} or
  11299. @code{m4_set_foreach([@var{set}], [var],
  11300. [@var{action}(m4_defn([var]))])}. It is possible to use @code{m4_curry}
  11301. if more than one argument is needed for @var{action}, although it is
  11302. more efficient to use @code{m4_set_map_sep} in that case.
  11303. @end defmac
  11304. @defmac m4_set_map_sep (@var{set}, @ovar{pre}, @ovar{post}, @ovar{sep})
  11305. @msindex{set_map_sep}
  11306. For each element in the set @var{set}, expand
  11307. @code{@var{pre}[element]@var{post}}, additionally expanding @var{sep}
  11308. between elements. Behavior is unspecified if the expansion recursively
  11309. lists the contents of @var{set} (although listing other sets
  11310. is acceptable), or if it modifies the set in any way other than removing
  11311. the element visited by the expansion. This macro provides the most
  11312. efficient means for non-destructively visiting the elements of a set; in
  11313. particular, @code{m4_set_map([@var{set}], [@var{action}])} is equivalent
  11314. to @code{m4_set_map_sep([@var{set}], [@var{action}(], [)])}.
  11315. @end defmac
  11316. @defmac m4_set_remove (@var{set}, @var{value}, @ovar{if-present}, @
  11317. @ovar{if-absent})
  11318. @msindex{set_remove}
  11319. If @var{value} is an element in the set @var{set}, then remove it and
  11320. expand @var{if-present}. Otherwise expand @var{if-absent}. This macro
  11321. operates in constant time so that multiple removals will scale linearly
  11322. rather than quadratically; but when used outside of
  11323. @code{m4_set_foreach} or @code{m4_set_map}, it leaves memory occupied
  11324. until the set is later
  11325. compacted by @code{m4_set_contents} or @code{m4_set_list}. Several
  11326. other set operations are then less efficient between the time of element
  11327. removal and subsequent memory compaction, but still maintain their
  11328. guaranteed scaling performance.
  11329. @end defmac
  11330. @defmac m4_set_size (@var{set})
  11331. @msindex{set_size}
  11332. Expand to the size of the set @var{set}. This implementation operates
  11333. in constant time, and is thus more efficient than
  11334. @code{m4_eval(m4_count(m4_set_listc([set])) - 1)}.
  11335. @end defmac
  11336. @node Forbidden Patterns
  11337. @subsection Forbidden Patterns
  11338. @cindex Forbidden patterns
  11339. @cindex Patterns, forbidden
  11340. M4sugar provides a means to define suspicious patterns, patterns
  11341. describing tokens which should not be found in the output. For
  11342. instance, if an Autoconf @file{configure} script includes tokens such as
  11343. @samp{AC_DEFINE}, or @samp{dnl}, then most probably something went
  11344. wrong (typically a macro was not evaluated because of overquotation).
  11345. M4sugar forbids all the tokens matching @samp{^_?m4_} and @samp{^dnl$}.
  11346. Additional layers, such as M4sh and Autoconf, add additional forbidden
  11347. patterns to the list.
  11348. @defmac m4_pattern_forbid (@var{pattern})
  11349. @msindex{pattern_forbid}
  11350. Declare that no token matching @var{pattern} must be found in the output.
  11351. Comments are not checked; this can be a problem if, for instance, you
  11352. have some macro left unexpanded after an @samp{#include}. No consensus
  11353. is currently found in the Autoconf community, as some people consider it
  11354. should be valid to name macros in comments (which doesn't make sense to
  11355. the authors of this documentation: input, such as macros, should be
  11356. documented by @samp{dnl} comments; reserving @samp{#}-comments to
  11357. document the output).
  11358. @end defmac
  11359. Of course, you might encounter exceptions to these generic rules, for
  11360. instance you might have to refer to @samp{$m4_flags}.
  11361. @defmac m4_pattern_allow (@var{pattern})
  11362. @msindex{pattern_allow}
  11363. Any token matching @var{pattern} is allowed, including if it matches an
  11364. @code{m4_pattern_forbid} pattern.
  11365. @end defmac
  11366. @node Debugging via autom4te
  11367. @section Debugging via autom4te
  11368. @cindex debugging tips
  11369. @cindex autom4te debugging tips
  11370. @cindex m4sugar debugging tips
  11371. At times, it is desirable to see what was happening inside m4, to see
  11372. why output was not matching expectations. However, post-processing done
  11373. by @command{autom4te} means that directly using the m4 builtin
  11374. @code{m4_traceon} is likely to interfere with operation. Also, frequent
  11375. diversion changes and the concept of forbidden tokens make it difficult
  11376. to use @code{m4_defn} to generate inline comments in the final output.
  11377. There are a couple of tools to help with this. One is the use of the
  11378. @option{--trace} option provided by @command{autom4te} (as well as each
  11379. of the programs that wrap @command{autom4te}, such as
  11380. @command{autoconf}), in order to inspect when a macro is called and with
  11381. which arguments. For example, when this paragraph was written, the
  11382. autoconf version could be found by:
  11383. @example
  11384. $ @kbd{autoconf --trace=AC_INIT}
  11385. configure.ac:23:AC_INIT:GNU Autoconf:2.63b.95-3963:bug-autoconf@@gnu.org
  11386. $ @kbd{autoconf --trace='AC_INIT:version is $2'}
  11387. version is 2.63b.95-3963
  11388. @end example
  11389. Another trick is to print out the expansion of various m4 expressions to
  11390. standard error or to an independent file, with no further m4 expansion,
  11391. and without interfering with diversion changes or the post-processing
  11392. done to standard output. @code{m4_errprintn} shows a given expression
  11393. on standard error. For example, if you want to see the expansion of an
  11394. autoconf primitive or of one of your autoconf macros, you can do it like
  11395. this:
  11396. @example
  11397. $ @kbd{cat <<\EOF > configure.ac}
  11398. AC_INIT
  11399. m4_errprintn([The definition of AC_DEFINE_UNQUOTED:])
  11400. m4_errprintn(m4_defn([AC_DEFINE_UNQUOTED]))
  11401. AC_OUTPUT
  11402. EOF
  11403. $ @kbd{autoconf}
  11404. @error{}The definition of AC_DEFINE_UNQUOTED:
  11405. @error{}_AC_DEFINE_Q([], $@@)
  11406. @end example
  11407. @node Programming in M4sh
  11408. @chapter Programming in M4sh
  11409. M4sh, pronounced ``mash'', is aiming at producing portable Bourne shell
  11410. scripts. This name was coined by Lars J. Aas, who notes that,
  11411. according to the Webster's Revised Unabridged Dictionary (1913):
  11412. @quotation
  11413. Mash \Mash\, n. [Akin to G. meisch, maisch, meische, maische, mash,
  11414. wash, and prob.@: to AS. miscian to mix. See ``Mix''.]
  11415. @enumerate 1
  11416. @item
  11417. A mass of mixed ingredients reduced to a soft pulpy state by beating or
  11418. pressure@enddots{}
  11419. @item
  11420. A mixture of meal or bran and water fed to animals.
  11421. @item
  11422. A mess; trouble. [Obs.] --Beau.@: & Fl.
  11423. @end enumerate
  11424. @end quotation
  11425. M4sh reserves the M4 macro namespace @samp{^_AS_} for internal use, and
  11426. the namespace @samp{^AS_} for M4sh macros. It also reserves the shell
  11427. and environment variable namespace @samp{^as_}, and the here-document
  11428. delimiter namespace @samp{^_AS[A-Z]} in the output file. You should not
  11429. define your own macros or output shell code that conflicts with these
  11430. namespaces.
  11431. @menu
  11432. * Common Shell Constructs:: Portability layer for common shell constructs
  11433. * Polymorphic Variables:: Support for indirect variable names
  11434. * Initialization Macros:: Macros to establish a sane shell environment
  11435. * File Descriptor Macros:: File descriptor macros for input and output
  11436. @end menu
  11437. @node Common Shell Constructs
  11438. @section Common Shell Constructs
  11439. M4sh provides portable alternatives for some common shell constructs
  11440. that unfortunately are not portable in practice.
  11441. @c Deprecated, to be replaced by a better API
  11442. @ignore
  11443. @defmac AS_BASENAME (@var{file-name})
  11444. @asindex{BASENAME}
  11445. Output the non-directory portion of @var{file-name}. For example,
  11446. if @code{$file} is @samp{/one/two/three}, the command
  11447. @code{base=`AS_BASENAME(["$file"])`} sets @code{base} to @samp{three}.
  11448. @end defmac
  11449. @end ignore
  11450. @defmac AS_BOX (@var{text}, @dvar{char, -})
  11451. @asindex{BOX}
  11452. Expand into shell code that will output @var{text} surrounded by a box
  11453. with @var{char} in the top and bottom border. @var{text} should not
  11454. contain a newline, but may contain shell expansions valid for unquoted
  11455. here-documents. @var{char} defaults to @samp{-}, but can be any
  11456. character except @samp{/}, @samp{'}, @samp{"}, @samp{\},
  11457. @samp{&}, or @samp{`}. This is useful for outputting a comment box into
  11458. log files to separate distinct phases of script operation.
  11459. @end defmac
  11460. @defmac AS_CASE (@var{word}, @ovar{pattern1}, @ovar{if-matched1}, @
  11461. @dots{}, @ovar{default})
  11462. @asindex{CASE}
  11463. Expand into a shell @samp{case} statement, where @var{word} is matched
  11464. against one or more patterns. @var{if-matched} is run if the
  11465. corresponding pattern matched @var{word}, else @var{default} is run.
  11466. Avoids several portability issues (@pxref{case, , Limitations of Shell
  11467. Builtins}).
  11468. @end defmac
  11469. @c Deprecated, to be replaced by a better API
  11470. @defmac AS_DIRNAME (@var{file-name})
  11471. @asindex{DIRNAME}
  11472. Output the directory portion of @var{file-name}. For example,
  11473. if @code{$file} is @samp{/one/two/three}, the command
  11474. @code{dir=`AS_DIRNAME(["$file"])`} sets @code{dir} to @samp{/one/two}.
  11475. This interface may be improved in the future to avoid forks and losing
  11476. trailing newlines.
  11477. @end defmac
  11478. @defmac AS_ECHO (@var{word})
  11479. @asindex{ECHO}
  11480. Emits @var{word} to the standard output, followed by a newline. @var{word}
  11481. must be a single shell word (typically a quoted string). The bytes of
  11482. @var{word} are output as-is, even if it starts with "-" or contains "\".
  11483. Redirections can be placed outside the macro invocation. This is much
  11484. more portable than using @command{echo} (@pxref{echo, , Limitations of
  11485. Shell Builtins}).
  11486. @end defmac
  11487. @defmac AS_ECHO_N (@var{word})
  11488. @asindex{ECHO_N}
  11489. Emits @var{word} to the standard output, without a following newline.
  11490. @var{word} must be a single shell word (typically a quoted string) and,
  11491. for portability, should not include more than one newline. The bytes of
  11492. @var{word} are output as-is, even if it starts with "-" or contains "\".
  11493. Redirections can be placed outside the macro invocation.
  11494. @end defmac
  11495. @c We cannot use @dvar because the macro expansion mistreats backslashes.
  11496. @defmac AS_ESCAPE (@var{string}, @r{[}@var{chars} = @samp{`\"$}@r{]})
  11497. @asindex{ESCAPE}
  11498. Expands to @var{string}, with any characters in @var{chars} escaped with
  11499. a backslash (@samp{\}). @var{chars} should be at most four bytes long,
  11500. and only contain characters from the set @samp{`\"$}; however,
  11501. characters may be safely listed more than once in @var{chars} for the
  11502. sake of syntax highlighting editors. The current implementation expands
  11503. @var{string} after adding escapes; if @var{string} contains macro calls
  11504. that in turn expand to text needing shell quoting, you can use
  11505. @code{AS_ESCAPE(m4_dquote(m4_expand([string])))}.
  11506. The default for @var{chars} (@samp{\"$`}) is the set of characters
  11507. needing escapes when @var{string} will be used literally within double
  11508. quotes. One common variant is the set of characters to protect when
  11509. @var{string} will be used literally within back-ticks or an unquoted
  11510. here-document (@samp{\$`}). Another common variant is @samp{""}, which can
  11511. be used to form a double-quoted string containing the same expansions
  11512. that would have occurred if @var{string} were expanded in an unquoted
  11513. here-document; however, when using this variant, care must be taken that
  11514. @var{string} does not use double quotes within complex variable
  11515. expansions (such as @samp{$@{foo-`echo "hi"`@}}) that would be broken
  11516. with improper escapes.
  11517. This macro is often used with @code{AS_ECHO}. For an example, observe
  11518. the output generated by the shell code generated from this snippet:
  11519. @example
  11520. foo=bar
  11521. AS_ECHO(["AS_ESCAPE(["$foo" = ])AS_ESCAPE(["$foo"], [""])"])
  11522. @result{}"$foo" = "bar"
  11523. m4_define([macro], [a, [\b]])
  11524. AS_ECHO(["AS_ESCAPE([[macro]])"])
  11525. @result{}macro
  11526. AS_ECHO(["AS_ESCAPE([macro])"])
  11527. @result{}a, b
  11528. AS_ECHO(["AS_ESCAPE(m4_dquote(m4_expand([macro])))"])
  11529. @result{}a, \b
  11530. @end example
  11531. @comment Should we add AS_ESCAPE_SINGLE? If we do, we can optimize in
  11532. @comment the case of @var{string} that does not contain '.
  11533. To escape a string that will be placed within single quotes, use:
  11534. @example
  11535. m4_bpatsubst([[@var{string}]], ['], ['\\''])
  11536. @end example
  11537. @end defmac
  11538. @defmac AS_EXECUTABLE_P (@var{file})
  11539. @asindex{EXECUTABLE_P}
  11540. Emit code to probe whether @var{file} is a regular file with executable
  11541. permissions (and not a directory with search permissions). The caller
  11542. is responsible for quoting @var{file}.
  11543. @end defmac
  11544. @defmac AS_EXIT (@dvar{status, $?})
  11545. @asindex{EXIT}
  11546. Emit code to exit the shell with @var{status}, defaulting to @samp{$?}.
  11547. This macro
  11548. works around shells that see the exit status of the command prior to
  11549. @code{exit} inside a @samp{trap 0} handler (@pxref{trap, , Limitations
  11550. of Shell Builtins}).
  11551. @end defmac
  11552. @defmac AS_IF (@var{test1}, @ovar{run-if-true1}, @dots{}, @ovar{run-if-false})
  11553. @asindex{IF}
  11554. Run shell code @var{test1}. If @var{test1} exits with a zero status then
  11555. run shell code @var{run-if-true1}, else examine further tests. If no test
  11556. exits with a zero status, run shell code @var{run-if-false}, with
  11557. simplifications if either @var{run-if-true1} or @var{run-if-false}
  11558. is empty. For example,
  11559. @example
  11560. AS_IF([test "x$foo" = xyes], [HANDLE_FOO([yes])],
  11561. [test "x$foo" != xno], [HANDLE_FOO([maybe])],
  11562. [echo foo not specified])
  11563. @end example
  11564. @noindent
  11565. ensures any required macros of @code{HANDLE_FOO}
  11566. are expanded before the first test.
  11567. @end defmac
  11568. @defmac AS_MKDIR_P (@var{file-name})
  11569. @asindex{MKDIR_P}
  11570. Make the directory @var{file-name}, including intervening directories
  11571. as necessary. This is equivalent to @samp{mkdir -p -- @var{file-name}},
  11572. except that it is portable to older versions of @command{mkdir} that
  11573. lack support for the @option{-p} option or for the @option{--}
  11574. delimiter (@pxref{mkdir, , Limitations of Usual Tools}). Also,
  11575. @code{AS_MKDIR_P}
  11576. succeeds if @var{file-name} is a symbolic link to an existing directory,
  11577. even though Posix is unclear whether @samp{mkdir -p} should
  11578. succeed in that case. If creation of @var{file-name} fails, exit the
  11579. script.
  11580. Also see the @code{AC_PROG_MKDIR_P} macro (@pxref{Particular Programs}).
  11581. @end defmac
  11582. @defmac AS_SET_STATUS (@var{status})
  11583. @asindex{SET_STATUS}
  11584. Emit shell code to set the value of @samp{$?} to @var{status}, as
  11585. efficiently as possible. However, this is not guaranteed to abort a
  11586. shell running with @code{set -e} (@pxref{set, , Limitations of Shell
  11587. Builtins}). This should also be used at the end of a complex shell
  11588. function instead of @samp{return} (@pxref{Shell Functions}) to avoid
  11589. a DJGPP shell bug.
  11590. @end defmac
  11591. @defmac AS_TR_CPP (@var{expression})
  11592. @asindex{TR_CPP}
  11593. Transform @var{expression} into a valid right-hand side for a C @code{#define}.
  11594. For example:
  11595. @example
  11596. # This outputs "#define HAVE_CHAR_P 1".
  11597. # Notice the m4 quoting around #, to prevent an m4 comment
  11598. type="char *"
  11599. echo "[#]define AS_TR_CPP([HAVE_$type]) 1"
  11600. @end example
  11601. @end defmac
  11602. @defmac AS_TR_SH (@var{expression})
  11603. @asindex{TR_SH}
  11604. Transform @var{expression} into shell code that generates a valid shell
  11605. variable name. The result is literal when possible at m4 time, but must
  11606. be used with @code{eval} if @var{expression} causes shell indirections.
  11607. For example:
  11608. @example
  11609. # This outputs "Have it!".
  11610. header="sys/some file.h"
  11611. eval AS_TR_SH([HAVE_$header])=yes
  11612. if test "x$HAVE_sys_some_file_h" = xyes; then echo "Have it!"; fi
  11613. @end example
  11614. @end defmac
  11615. @defmac AS_SET_CATFILE (@var{var}, @var{dir}, @var{file})
  11616. @asindex{SET_CATFILE}
  11617. Set the polymorphic shell variable @var{var} to @var{dir}/@var{file},
  11618. but optimizing the common cases (@var{dir} or @var{file} is @samp{.},
  11619. @var{file} is absolute, etc.).
  11620. @end defmac
  11621. @defmac AS_UNSET (@var{var})
  11622. @asindex{UNSET}
  11623. Unsets the shell variable @var{var}, working around bugs in older
  11624. shells (@pxref{unset, , Limitations of Shell
  11625. Builtins}). @var{var} can be a literal or indirect variable name.
  11626. @end defmac
  11627. @defmac AS_VERSION_COMPARE (@var{version-1}, @var{version-2}, @
  11628. @ovar{action-if-less}, @ovar{action-if-equal}, @ovar{action-if-greater})
  11629. @asindex{VERSION_COMPARE}
  11630. Compare two strings @var{version-1} and @var{version-2}, possibly
  11631. containing shell variables, as version strings, and expand
  11632. @var{action-if-less}, @var{action-if-equal}, or @var{action-if-greater}
  11633. depending upon the result.
  11634. The algorithm to compare is similar to the one used by strverscmp in
  11635. glibc (@pxref{String/Array Comparison, , String/Array Comparison, libc,
  11636. The GNU C Library}).
  11637. @end defmac
  11638. @node Polymorphic Variables
  11639. @section Support for indirect variable names
  11640. @cindex variable name indirection
  11641. @cindex polymorphic variable name
  11642. @cindex indirection, variable name
  11643. Often, it is convenient to write a macro that will emit shell code
  11644. operating on a shell variable. The simplest case is when the variable
  11645. name is known. But a more powerful idiom is writing shell code that can
  11646. work through an indirection, where another variable or command
  11647. substitution produces the name of the variable to actually manipulate.
  11648. M4sh supports the notion of polymorphic shell variables, making it easy
  11649. to write a macro that can deal with either literal or indirect variable
  11650. names and output shell code appropriate for both use cases. Behavior is
  11651. undefined if expansion of an indirect variable does not result in a
  11652. literal variable name.
  11653. @defmac AS_LITERAL_IF (@var{expression}, @ovar{if-literal}, @ovar{if-not}, @
  11654. @dvar{if-simple-ref, @var{if-not}})
  11655. @defmacx AS_LITERAL_WORD_IF (@var{expression}, @ovar{if-literal}, @
  11656. @ovar{if-not}, @dvar{if-simple-ref, @var{if-not}})
  11657. @asindex{LITERAL_IF}
  11658. @asindex{LITERAL_WORD_IF}
  11659. If the expansion of @var{expression} is definitely a shell literal,
  11660. expand @var{if-literal}. If the expansion of @var{expression} looks
  11661. like it might contain shell indirections (such as @code{$var} or
  11662. @code{`expr`}), then @var{if-not} is expanded. Sometimes, it is
  11663. possible to output optimized code if @var{expression} consists only of
  11664. shell variable expansions (such as @code{$@{var@}}), in which case
  11665. @var{if-simple-ref} can be provided; but defaulting to @var{if-not}
  11666. should always be safe. @code{AS_LITERAL_WORD_IF} only expands
  11667. @var{if-literal} if @var{expression} looks like a single shell word,
  11668. containing no whitespace; while @code{AS_LITERAL_IF} allows whitespace
  11669. in @var{expression}.
  11670. In order to reduce the time spent recognizing whether an
  11671. @var{expression} qualifies as a literal or a simple indirection, the
  11672. implementation is somewhat conservative: @var{expression} must be a
  11673. single shell word (possibly after stripping whitespace), consisting only
  11674. of bytes that would have the same meaning whether unquoted or enclosed
  11675. in double quotes (for example, @samp{a.b} results in @var{if-literal},
  11676. even though it is not a valid shell variable name; while both @samp{'a'}
  11677. and @samp{[$]} result in @var{if-not}, because they behave differently
  11678. than @samp{"'a'"} and @samp{"[$]"}). This macro can be used in contexts
  11679. for recognizing portable file names (such as in the implementation of
  11680. @code{AC_LIBSOURCE}), or coupled with some transliterations for forming
  11681. valid variable names (such as in the implementation of @code{AS_TR_SH},
  11682. which uses an additional @code{m4_translit} to convert @samp{.} to
  11683. @samp{_}).
  11684. This example shows how to read the contents of the shell variable
  11685. @code{bar}, exercising all three arguments to @code{AS_LITERAL_IF}. It
  11686. results in a script that will output the line @samp{hello} three times.
  11687. @example
  11688. AC_DEFUN([MY_ACTION],
  11689. [AS_LITERAL_IF([$1],
  11690. [echo "$$1"],
  11691. @c $$
  11692. [AS_VAR_COPY([var], [$1])
  11693. echo "$var"],
  11694. [eval 'echo "$'"$1"\"])])
  11695. foo=bar bar=hello
  11696. MY_ACTION([bar])
  11697. MY_ACTION([`echo bar`])
  11698. MY_ACTION([$foo])
  11699. @end example
  11700. @end defmac
  11701. @defmac AS_VAR_APPEND (@var{var}, @var{text})
  11702. @asindex{VAR_APPEND}
  11703. Emit shell code to append the shell expansion of @var{text} to the end
  11704. of the current contents of the polymorphic shell variable @var{var},
  11705. taking advantage of shells that provide the @samp{+=} extension for more
  11706. efficient scaling.
  11707. For situations where the final contents of @var{var} are relatively
  11708. short (less than 256 bytes), it is more efficient to use the simpler
  11709. code sequence of @code{@var{var}=$@{@var{var}@}@var{text}} (or its
  11710. polymorphic equivalent of @code{AS_VAR_COPY([t], [@var{var}])} and
  11711. @code{AS_VAR_SET([@var{var}], ["$t"@var{text}])}). But in the case
  11712. when the script will be repeatedly appending text into @code{var},
  11713. issues of scaling start to become apparent. A naive implementation
  11714. requires execution time linear to the length of the current contents of
  11715. @var{var} as well as the length of @var{text} for a single append, for
  11716. an overall quadratic scaling with multiple appends. This macro takes
  11717. advantage of shells which provide the extension
  11718. @code{@var{var}+=@var{text}}, which can provide amortized constant time
  11719. for a single append, for an overall linear scaling with multiple
  11720. appends. Note that unlike @code{AS_VAR_SET}, this macro requires that
  11721. @var{text} be quoted properly to avoid field splitting and file name
  11722. expansion.
  11723. @end defmac
  11724. @defmac AS_VAR_ARITH (@var{var}, @var{expression})
  11725. @asindex{VAR_ARITH}
  11726. Emit shell code to compute the arithmetic expansion of @var{expression},
  11727. assigning the result as the contents of the polymorphic shell variable
  11728. @var{var}. The code takes advantage of shells that provide @samp{$(())}
  11729. for fewer forks, but uses @command{expr} as a fallback. Therefore, the
  11730. syntax for a valid @var{expression} is rather limited: all operators
  11731. must occur as separate shell arguments and with proper quoting, there is
  11732. no portable equality operator, all variables containing numeric values
  11733. must be expanded prior to the computation, all numeric values must be
  11734. provided in decimal without leading zeroes, and the first shell argument
  11735. should not be a negative number. In the following example, this snippet
  11736. will print @samp{(2+3)*4 == 20}.
  11737. @example
  11738. bar=3
  11739. AS_VAR_ARITH([foo], [\( 2 + $bar \) \* 4])
  11740. echo "(2+$bar)*4 == $foo"
  11741. @end example
  11742. @end defmac
  11743. @defmac AS_VAR_COPY (@var{dest}, @var{source})
  11744. @asindex{VAR_COPY}
  11745. Emit shell code to assign the contents of the polymorphic shell variable
  11746. @var{source} to the polymorphic shell variable @var{dest}. For example,
  11747. executing this M4sh snippet will output @samp{bar hi}:
  11748. @example
  11749. foo=bar bar=hi
  11750. AS_VAR_COPY([a], [foo])
  11751. AS_VAR_COPY([b], [$foo])
  11752. echo "$a $b"
  11753. @end example
  11754. When it is necessary to access the contents of an indirect variable
  11755. inside a shell double-quoted context, the recommended idiom is to first
  11756. copy the contents into a temporary literal shell variable.
  11757. @smallexample
  11758. for header in stdint_h inttypes_h ; do
  11759. AS_VAR_COPY([var], [ac_cv_header_$header])
  11760. echo "$header detected: $var"
  11761. done
  11762. @end smallexample
  11763. @end defmac
  11764. @comment AS_VAR_GET is intentionally undocumented; it can't handle
  11765. @comment trailing newlines uniformly, and forks too much.
  11766. @defmac AS_VAR_IF (@var{var}, @ovar{word}, @ovar{if-equal}, @
  11767. @ovar{if-not-equal})
  11768. @asindex{VAR_IF}
  11769. Output a shell conditional statement. If the contents of the
  11770. polymorphic shell variable @var{var} match the string @var{word},
  11771. execute @var{if-equal}; otherwise execute @var{if-not-equal}. @var{word}
  11772. must be a single shell word (typically a quoted string). Avoids
  11773. shell bugs if an interrupt signal arrives while a command substitution
  11774. in @var{var} is being expanded.
  11775. @end defmac
  11776. @defmac AS_VAR_PUSHDEF (@var{m4-name}, @var{value})
  11777. @defmacx AS_VAR_POPDEF (@var{m4-name})
  11778. @asindex{VAR_PUSHDEF}
  11779. @asindex{VAR_POPDEF}
  11780. @cindex composing variable names
  11781. @cindex variable names, composing
  11782. A common M4sh idiom involves composing shell variable names from an m4
  11783. argument (for example, writing a macro that uses a cache variable).
  11784. @var{value} can be an arbitrary string, which will be transliterated
  11785. into a valid shell name by @code{AS_TR_SH}. In order to access the
  11786. composed variable name based on @var{value}, it is easier to declare a
  11787. temporary m4 macro @var{m4-name} with @code{AS_VAR_PUSHDEF}, then use
  11788. that macro as the argument to subsequent @code{AS_VAR} macros as a
  11789. polymorphic variable name, and finally free the temporary macro with
  11790. @code{AS_VAR_POPDEF}. These macros are often followed with @code{dnl},
  11791. to avoid excess newlines in the output.
  11792. Here is an involved example, that shows the power of writing macros that
  11793. can handle composed shell variable names:
  11794. @example
  11795. m4_define([MY_CHECK_HEADER],
  11796. [AS_VAR_PUSHDEF([my_Header], [ac_cv_header_$1])dnl
  11797. AS_VAR_IF([my_Header], [yes], [echo "header $1 detected"])dnl
  11798. AS_VAR_POPDEF([my_Header])dnl
  11799. ])
  11800. MY_CHECK_HEADER([stdint.h])
  11801. for header in inttypes.h stdlib.h ; do
  11802. MY_CHECK_HEADER([$header])
  11803. done
  11804. @end example
  11805. @noindent
  11806. In the above example, @code{MY_CHECK_HEADER} can operate on polymorphic
  11807. variable names. In the first invocation, the m4 argument is
  11808. @code{stdint.h}, which transliterates into a literal @code{stdint_h}.
  11809. As a result, the temporary macro @code{my_Header} expands to the literal
  11810. shell name @samp{ac_cv_header_stdint_h}. In the second invocation, the
  11811. m4 argument to @code{MY_CHECK_HEADER} is @code{$header}, and the
  11812. temporary macro @code{my_Header} expands to the indirect shell name
  11813. @samp{$as_my_Header}. During the shell execution of the for loop, when
  11814. @samp{$header} contains @samp{inttypes.h}, then @samp{$as_my_Header}
  11815. contains @samp{ac_cv_header_inttypes_h}. If this script is then run on a
  11816. platform where all three headers have been previously detected, the
  11817. output of the script will include:
  11818. @smallexample
  11819. header stdint.h detected
  11820. header inttypes.h detected
  11821. header stdlib.h detected
  11822. @end smallexample
  11823. @end defmac
  11824. @defmac AS_VAR_SET (@var{var}, @ovar{value})
  11825. @asindex{VAR_SET}
  11826. Emit shell code to assign the contents of the polymorphic shell variable
  11827. @var{var} to the shell expansion of @var{value}. @var{value} is not
  11828. subject to field splitting or file name expansion, so if command
  11829. substitution is used, it may be done with @samp{`""`} rather than using
  11830. an intermediate variable (@pxref{Shell Substitutions}). However,
  11831. @var{value} does undergo rescanning for additional macro names; behavior
  11832. is unspecified if late expansion results in any shell meta-characters.
  11833. @end defmac
  11834. @defmac AS_VAR_SET_IF (@var{var}, @ovar{if-set}, @ovar{if-undef})
  11835. @asindex{VAR_SET_IF}
  11836. Emit a shell conditional statement, which executes @var{if-set} if the
  11837. polymorphic shell variable @code{var} is set to any value, and
  11838. @var{if-undef} otherwise.
  11839. @end defmac
  11840. @defmac AS_VAR_TEST_SET (@var{var})
  11841. @asindex{VAR_TEST_SET}
  11842. Emit a shell statement that results in a successful exit status only if
  11843. the polymorphic shell variable @code{var} is set.
  11844. @end defmac
  11845. @node Initialization Macros
  11846. @section Initialization Macros
  11847. @defmac AS_BOURNE_COMPATIBLE
  11848. @asindex{BOURNE_COMPATIBLE}
  11849. Set up the shell to be more compatible with the Bourne shell as
  11850. standardized by Posix, if possible. This may involve setting
  11851. environment variables, or setting options, or similar
  11852. implementation-specific actions. This macro is deprecated, since
  11853. @code{AS_INIT} already invokes it.
  11854. @end defmac
  11855. @defmac AS_INIT
  11856. @asindex{INIT}
  11857. @evindex LC_ALL
  11858. @evindex SHELL
  11859. Initialize the M4sh environment. This macro calls @code{m4_init}, then
  11860. outputs the @code{#! /bin/sh} line, a notice about where the output was
  11861. generated from, and code to sanitize the environment for the rest of the
  11862. script. Among other initializations, this sets @env{SHELL} to the shell
  11863. chosen to run the script (@pxref{CONFIG_SHELL}), and @env{LC_ALL} to
  11864. ensure the C locale. Finally, it changes the current diversion to
  11865. @code{BODY}. @code{AS_INIT} is called automatically by @code{AC_INIT}
  11866. and @code{AT_INIT}, so shell code in @file{configure},
  11867. @file{config.status}, and @file{testsuite} all benefit from a sanitized
  11868. shell environment.
  11869. @end defmac
  11870. @defmac AS_INIT_GENERATED (@var{file}, @ovar{comment})
  11871. @asindex{INIT_GENERATED}
  11872. Emit shell code to start the creation of a subsidiary shell script in
  11873. @var{file}, including changing @var{file} to be executable. This macro
  11874. populates the child script with information learned from the parent
  11875. (thus, the emitted code is equivalent in effect, but more efficient,
  11876. than the code output by @code{AS_INIT}, @code{AS_BOURNE_COMPATIBLE}, and
  11877. @code{AS_SHELL_SANITIZE}). If present, @var{comment} is output near the
  11878. beginning of the child, prior to the shell initialization code, and is
  11879. subject to parameter expansion, command substitution, and backslash
  11880. quote removal. The
  11881. parent script should check the exit status after this macro, in case
  11882. @var{file} could not be properly created (for example, if the disk was
  11883. full). If successfully created, the parent script can then proceed to
  11884. append additional M4sh constructs into the child script.
  11885. Note that the child script starts life without a log file open, so if
  11886. the parent script uses logging (@pxref{AS_MESSAGE_LOG_FD}), you
  11887. must temporarily disable any attempts to use the log file until after
  11888. emitting code to open a log within the child. On the other hand, if the
  11889. parent script has @code{AS_MESSAGE_FD} redirected somewhere besides
  11890. @samp{1}, then the child script already has code that copies stdout to
  11891. that descriptor. Currently, the suggested
  11892. idiom for writing a M4sh shell script from within another script is:
  11893. @example
  11894. AS_INIT_GENERATED([@var{file}], [[# My child script.
  11895. ]]) || @{ AS_ECHO(["Failed to create child script"]); AS_EXIT; @}
  11896. m4_pushdef([AS_MESSAGE_LOG_FD])dnl
  11897. cat >> "@var{file}" <<\__EOF__
  11898. # Code to initialize AS_MESSAGE_LOG_FD
  11899. m4_popdef([AS_MESSAGE_LOG_FD])dnl
  11900. # Additional code
  11901. __EOF__
  11902. @end example
  11903. This, however, may change in the future as the M4sh interface is
  11904. stabilized further.
  11905. Also, be aware that use of @env{LINENO} within the child script may
  11906. report line numbers relative to their location in the parent script,
  11907. even when using @code{AS_LINENO_PREPARE}, if the parent script was
  11908. unable to locate a shell with working @env{LINENO} support.
  11909. @end defmac
  11910. @defmac AS_LINENO_PREPARE
  11911. @asindex{LINENO_PREPARE}
  11912. @evindex LINENO
  11913. Find a shell that supports the special variable @env{LINENO}, which
  11914. contains the number of the currently executing line. This macro is
  11915. automatically invoked by @code{AC_INIT} in configure scripts.
  11916. @end defmac
  11917. @defmac AS_ME_PREPARE
  11918. @asindex{ME_PREPARE}
  11919. Set up variable @env{as_me} to be the basename of the currently executing
  11920. script. This macro is automatically invoked by @code{AC_INIT} in
  11921. configure scripts.
  11922. @end defmac
  11923. @defmac AS_TMPDIR (@var{prefix}, @dvar{dir, $@{TMPDIR:=/tmp@}})
  11924. @asindex{TMPDIR}
  11925. @evindex TMPDIR
  11926. @ovindex tmp
  11927. Create, as safely as possible, a temporary sub-directory within
  11928. @var{dir} with a name starting with @var{prefix}. @var{prefix} should
  11929. be 2-4 characters, to make it slightly easier to identify the owner of
  11930. the directory. If @var{dir} is omitted, then the value of @env{TMPDIR}
  11931. will be used (defaulting to @samp{/tmp}). On success, the name of the
  11932. newly created directory is stored in the shell variable @code{tmp}. On
  11933. error, the script is aborted.
  11934. Typically, this macro is coupled with some exit traps to delete the created
  11935. directory and its contents on exit or interrupt. However, there is a
  11936. slight window between when the directory is created and when the name is
  11937. actually known to the shell, so an interrupt at the right moment might
  11938. leave the temporary directory behind. Hence it is important to use a
  11939. @var{prefix} that makes it easier to determine if a leftover temporary
  11940. directory from an interrupted script is safe to delete.
  11941. The use of the output variable @samp{$tmp} rather than something in the
  11942. @samp{as_} namespace is historical; it has the unfortunate consequence
  11943. that reusing this otherwise common name for any other purpose inside
  11944. your script has the potential to break any cleanup traps designed to
  11945. remove the temporary directory.
  11946. @end defmac
  11947. @defmac AS_SHELL_SANITIZE
  11948. @asindex{SHELL_SANITIZE}
  11949. Initialize the shell suitably for @command{configure} scripts. This has
  11950. the effect of @code{AS_BOURNE_COMPATIBLE}, and sets some other
  11951. environment variables for predictable results from configuration tests.
  11952. For example, it sets @env{LC_ALL} to change to the default C locale.
  11953. @xref{Special Shell Variables}. This macro is deprecated, since
  11954. @code{AS_INIT} already invokes it.
  11955. @end defmac
  11956. @node File Descriptor Macros
  11957. @section File Descriptor Macros
  11958. @cindex input
  11959. @cindex standard input
  11960. @cindex file descriptors
  11961. @cindex descriptors
  11962. @cindex low-level output
  11963. @cindex output, low-level
  11964. The following macros define file descriptors used to output messages
  11965. (or input values) from @file{configure} scripts.
  11966. For example:
  11967. @example
  11968. echo "$wombats found" >&AS_MESSAGE_LOG_FD
  11969. echo 'Enter desired kangaroo count:' >&AS_MESSAGE_FD
  11970. read kangaroos <&AS_ORIGINAL_STDIN_FD`
  11971. @end example
  11972. @noindent
  11973. However doing so is seldom needed, because Autoconf provides higher
  11974. level macros as described below.
  11975. @defmac AS_MESSAGE_FD
  11976. @asindex{MESSAGE_FD}
  11977. The file descriptor for @samp{checking for...} messages and results.
  11978. By default, @code{AS_INIT} sets this to @samp{1} for standalone M4sh
  11979. clients. However, @code{AC_INIT} shuffles things around to another file
  11980. descriptor, in order to allow the @option{-q} option of
  11981. @command{configure} to choose whether messages should go to the script's
  11982. standard output or be discarded.
  11983. If you want to display some messages, consider using one of the printing
  11984. macros (@pxref{Printing Messages}) instead. Copies of messages output
  11985. via these macros are also recorded in @file{config.log}.
  11986. @end defmac
  11987. @anchor{AS_MESSAGE_LOG_FD}
  11988. @defmac AS_MESSAGE_LOG_FD
  11989. @asindex{MESSAGE_LOG_FD}
  11990. This must either be empty, or expand to a file descriptor for log
  11991. messages. By default, @code{AS_INIT} sets this macro to the empty
  11992. string for standalone M4sh clients, thus disabling logging. However,
  11993. @code{AC_INIT} shuffles things around so that both @command{configure}
  11994. and @command{config.status} use @file{config.log} for log messages.
  11995. Macros that run tools, like @code{AC_COMPILE_IFELSE} (@pxref{Running the
  11996. Compiler}), redirect all output to this descriptor. You may want to do
  11997. so if you develop such a low-level macro.
  11998. @end defmac
  11999. @defmac AS_ORIGINAL_STDIN_FD
  12000. @asindex{ORIGINAL_STDIN_FD}
  12001. This must expand to a file descriptor for the original standard input.
  12002. By default, @code{AS_INIT} sets this macro to @samp{0} for standalone
  12003. M4sh clients. However, @code{AC_INIT} shuffles things around for
  12004. safety.
  12005. When @command{configure} runs, it may accidentally execute an
  12006. interactive command that has the same name as the non-interactive meant
  12007. to be used or checked. If the standard input was the terminal, such
  12008. interactive programs would cause @command{configure} to stop, pending
  12009. some user input. Therefore @command{configure} redirects its standard
  12010. input from @file{/dev/null} during its initialization. This is not
  12011. normally a problem, since @command{configure} normally does not need
  12012. user input.
  12013. In the extreme case where your @file{configure} script really needs to
  12014. obtain some values from the original standard input, you can read them
  12015. explicitly from @code{AS_ORIGINAL_STDIN_FD}.
  12016. @end defmac
  12017. @c =================================================== Writing Autoconf Macros.
  12018. @node Writing Autoconf Macros
  12019. @chapter Writing Autoconf Macros
  12020. When you write a feature test that could be applicable to more than one
  12021. software package, the best thing to do is encapsulate it in a new macro.
  12022. Here are some instructions and guidelines for writing Autoconf macros.
  12023. @menu
  12024. * Macro Definitions:: Basic format of an Autoconf macro
  12025. * Macro Names:: What to call your new macros
  12026. * Reporting Messages:: Notifying @command{autoconf} users
  12027. * Dependencies Between Macros:: What to do when macros depend on other macros
  12028. * Obsoleting Macros:: Warning about old ways of doing things
  12029. * Coding Style:: Writing Autoconf macros @`a la Autoconf
  12030. @end menu
  12031. @node Macro Definitions
  12032. @section Macro Definitions
  12033. @defmac AC_DEFUN (@var{name}, @ovar{body})
  12034. @acindex{DEFUN}
  12035. Autoconf macros are defined using the @code{AC_DEFUN} macro, which is
  12036. similar to the M4 builtin @code{m4_define} macro; this creates a macro
  12037. named @var{name} and with @var{body} as its expansion. In addition to
  12038. defining a macro, @code{AC_DEFUN} adds to it some code that is used to
  12039. constrain the order in which macros are called, while avoiding redundant
  12040. output (@pxref{Prerequisite Macros}).
  12041. @end defmac
  12042. An Autoconf macro definition looks like this:
  12043. @example
  12044. AC_DEFUN(@var{macro-name}, @var{macro-body})
  12045. @end example
  12046. You can refer to any arguments passed to the macro as @samp{$1},
  12047. @samp{$2}, etc. @xref{Definitions, , How to define new macros, m4.info,
  12048. GNU M4}, for more complete information on writing M4 macros.
  12049. Most macros fall in one of two general categories. The first category
  12050. includes macros which take arguments, in order to generate output
  12051. parameterized by those arguments. Macros in this category are designed
  12052. to be directly expanded, often multiple times, and should not be used as
  12053. the argument to @code{AC_REQUIRE}. The other category includes macros
  12054. which are shorthand for a fixed block of text, and therefore do not take
  12055. arguments. For this category of macros, directly expanding the macro
  12056. multiple times results in redundant output, so it is more common to use
  12057. the macro as the argument to @code{AC_REQUIRE}, or to declare the macro
  12058. with @code{AC_DEFUN_ONCE} (@pxref{One-Shot Macros}).
  12059. Be sure to properly quote both the @var{macro-body} @emph{and} the
  12060. @var{macro-name} to avoid any problems if the macro happens to have
  12061. been previously defined.
  12062. Each macro should have a header comment that gives its prototype, and a
  12063. brief description. When arguments have default values, display them in
  12064. the prototype. For example:
  12065. @example
  12066. # AC_MSG_ERROR(ERROR, [EXIT-STATUS = 1])
  12067. # --------------------------------------
  12068. m4_define([AC_MSG_ERROR],
  12069. [@{ AS_MESSAGE([error: $1], [2])
  12070. exit m4_default([$2], [1]); @}])
  12071. @end example
  12072. Comments about the macro should be left in the header comment. Most
  12073. other comments make their way into @file{configure}, so just keep
  12074. using @samp{#} to introduce comments.
  12075. @cindex @code{dnl}
  12076. If you have some special comments about pure M4 code, comments
  12077. that make no sense in @file{configure} and in the header comment, then
  12078. use the builtin @code{dnl}: it causes M4 to discard the text
  12079. through the next newline.
  12080. Keep in mind that @code{dnl} is rarely needed to introduce comments;
  12081. @code{dnl} is more useful to get rid of the newlines following macros
  12082. that produce no output, such as @code{AC_REQUIRE}.
  12083. Public third-party macros need to use @code{AC_DEFUN}, and not
  12084. @code{m4_define}, in order to be found by @command{aclocal}
  12085. (@pxref{Extending aclocal,,, automake, GNU Automake}).
  12086. Additionally, if it is ever determined that a macro should be made
  12087. obsolete, it is easy to convert from @code{AC_DEFUN} to @code{AU_DEFUN}
  12088. in order to have @command{autoupdate} assist the user in choosing a
  12089. better alternative, but there is no corresponding way to make
  12090. @code{m4_define} issue an upgrade notice (@pxref{AU_DEFUN}).
  12091. There is another subtle, but important, difference between using
  12092. @code{m4_define} and @code{AC_DEFUN}: only the former is unaffected by
  12093. @code{AC_REQUIRE}. When writing a file, it is always safe to replace a
  12094. block of text with a @code{m4_define} macro that will expand to the same
  12095. text. But replacing a block of text with an @code{AC_DEFUN} macro with
  12096. the same content does not necessarily give the same results, because it
  12097. changes the location where any embedded but unsatisfied
  12098. @code{AC_REQUIRE} invocations within the block will be expanded. For an
  12099. example of this, see @ref{Expanded Before Required}.
  12100. @node Macro Names
  12101. @section Macro Names
  12102. All of the public Autoconf macros have all-uppercase names in the
  12103. namespace @samp{^AC_} to prevent them from accidentally conflicting with
  12104. other text; Autoconf also reserves the namespace @samp{^_AC_} for
  12105. internal macros. All shell variables that they use for internal
  12106. purposes have mostly-lowercase names starting with @samp{ac_}. Autoconf
  12107. also uses here-document delimiters in the namespace @samp{^_AC[A-Z]}. During
  12108. @command{configure}, files produced by Autoconf make heavy use of the
  12109. file system namespace @samp{^conf}.
  12110. Since Autoconf is built on top of M4sugar (@pxref{Programming in
  12111. M4sugar}) and M4sh (@pxref{Programming in M4sh}), you must also be aware
  12112. of those namespaces (@samp{^_?\(m4\|AS\)_}). And since
  12113. @file{configure.ac} is also designed to be scanned by Autoheader,
  12114. Autoscan, Autoupdate, and Automake, you should be aware of the
  12115. @samp{^_?A[HNUM]_} namespaces. In general, you @emph{should not use}
  12116. the namespace of a package that does not own the macro or shell code you
  12117. are writing.
  12118. To ensure that your macros don't conflict with present or future
  12119. Autoconf macros, you should prefix your own macro names and any shell
  12120. variables they use with some other sequence. Possibilities include your
  12121. initials, or an abbreviation for the name of your organization or
  12122. software package. Historically, people have not always followed the
  12123. rule of using a namespace appropriate for their package, and this has
  12124. made it difficult for determining the origin of a macro (and where to
  12125. report bugs about that macro), as well as difficult for the true
  12126. namespace owner to add new macros without interference from pre-existing
  12127. uses of third-party macros. Perhaps the best example of this confusion
  12128. is the @code{AM_GNU_GETTEXT} macro, which belongs, not to Automake, but
  12129. to Gettext.
  12130. Most of the Autoconf macros' names follow a structured naming convention
  12131. that indicates the kind of feature check by the name. The macro names
  12132. consist of several words, separated by underscores, going from most
  12133. general to most specific. The names of their cache variables use the
  12134. same convention (@pxref{Cache Variable Names}, for more information on
  12135. them).
  12136. The first word of the name after the namespace initials (such as
  12137. @samp{AC_}) usually tells the category
  12138. of the feature being tested. Here are the categories used in Autoconf for
  12139. specific test macros, the kind of macro that you are more likely to
  12140. write. They are also used for cache variables, in all-lowercase. Use
  12141. them where applicable; where they're not, invent your own categories.
  12142. @table @code
  12143. @item C
  12144. C language builtin features.
  12145. @item DECL
  12146. Declarations of C variables in header files.
  12147. @item FUNC
  12148. Functions in libraries.
  12149. @item GROUP
  12150. Posix group owners of files.
  12151. @item HEADER
  12152. Header files.
  12153. @item LIB
  12154. C libraries.
  12155. @item PROG
  12156. The base names of programs.
  12157. @item MEMBER
  12158. Members of aggregates.
  12159. @item SYS
  12160. Operating system features.
  12161. @item TYPE
  12162. C builtin or declared types.
  12163. @item VAR
  12164. C variables in libraries.
  12165. @end table
  12166. After the category comes the name of the particular feature being
  12167. tested. Any further words in the macro name indicate particular aspects
  12168. of the feature. For example, @code{AC_PROG_CC_STDC} checks whether the
  12169. C compiler supports ISO Standard C.
  12170. An internal macro should have a name that starts with an underscore;
  12171. Autoconf internals should therefore start with @samp{_AC_}.
  12172. Additionally, a macro that is an internal subroutine of another macro
  12173. should have a name that starts with an underscore and the name of that
  12174. other macro, followed by one or more words saying what the internal
  12175. macro does. For example, @code{AC_PATH_X} has internal macros
  12176. @code{_AC_PATH_X_XMKMF} and @code{_AC_PATH_X_DIRECT}.
  12177. @node Reporting Messages
  12178. @section Reporting Messages
  12179. @cindex Messages, from @command{autoconf}
  12180. When macros statically diagnose abnormal situations, benign or fatal, it
  12181. is possible to make @command{autoconf} detect the problem, and refuse to
  12182. create @file{configure} in the case of an error. The macros in this
  12183. section are considered obsolescent, and new code should use M4sugar
  12184. macros for this purpose, see @ref{Diagnostic Macros}.
  12185. On the other hand, it is possible to want to detect errors when
  12186. @command{configure} is run, which are dependent on the environment of
  12187. the user rather than the maintainer. For dynamic diagnostics, see
  12188. @ref{Printing Messages}.
  12189. @defmac AC_DIAGNOSE (@var{category}, @var{message})
  12190. @acindex{DIAGNOSE}
  12191. Report @var{message} as a warning (or as an error if requested by the
  12192. user) if warnings of the @var{category} are turned on. This macro is
  12193. obsolescent; you are encouraged to use:
  12194. @example
  12195. m4_warn([@var{category}], [@var{message}])
  12196. @end example
  12197. @noindent
  12198. instead. @xref{m4_warn}, for more details, including valid
  12199. @var{category} names.
  12200. @end defmac
  12201. @defmac AC_WARNING (@var{message})
  12202. @acindex{WARNING}
  12203. Report @var{message} as a syntax warning. This macro is obsolescent;
  12204. you are encouraged to use:
  12205. @example
  12206. m4_warn([syntax], [@var{message}])
  12207. @end example
  12208. @noindent
  12209. instead. @xref{m4_warn}, for more details, as well as better
  12210. finer-grained categories of warnings (not all problems have to do with
  12211. syntax).
  12212. @end defmac
  12213. @defmac AC_FATAL (@var{message})
  12214. @acindex{FATAL}
  12215. Report a severe error @var{message}, and have @command{autoconf} die.
  12216. This macro is obsolescent; you are encouraged to use:
  12217. @example
  12218. m4_fatal([@var{message}])
  12219. @end example
  12220. @noindent
  12221. instead. @xref{m4_fatal}, for more details.
  12222. @end defmac
  12223. When the user runs @samp{autoconf -W error}, warnings from
  12224. @code{m4_warn} (including those issued through @code{AC_DIAGNOSE} and
  12225. @code{AC_WARNING}) are reported as errors, see @ref{autoconf Invocation}.
  12226. @node Dependencies Between Macros
  12227. @section Dependencies Between Macros
  12228. @cindex Dependencies between macros
  12229. Some Autoconf macros depend on other macros having been called first in
  12230. order to work correctly. Autoconf provides a way to ensure that certain
  12231. macros are called if needed and a way to warn the user if macros are
  12232. called in an order that might cause incorrect operation.
  12233. @menu
  12234. * Prerequisite Macros:: Ensuring required information
  12235. * Suggested Ordering:: Warning about possible ordering problems
  12236. * One-Shot Macros:: Ensuring a macro is called only once
  12237. @end menu
  12238. @node Prerequisite Macros
  12239. @subsection Prerequisite Macros
  12240. @cindex Prerequisite macros
  12241. @cindex Macros, prerequisites
  12242. A macro that you write might need to use values that have previously
  12243. been computed by other macros. For example, @code{AC_DECL_YYTEXT}
  12244. examines the output of @code{flex} or @code{lex}, so it depends on
  12245. @code{AC_PROG_LEX} having been called first to set the shell variable
  12246. @code{LEX}.
  12247. Rather than forcing the user of the macros to keep track of the
  12248. dependencies between them, you can use the @code{AC_REQUIRE} macro to do
  12249. it automatically. @code{AC_REQUIRE} can ensure that a macro is only
  12250. called if it is needed, and only called once.
  12251. @defmac AC_REQUIRE (@var{macro-name})
  12252. @acindex{REQUIRE}
  12253. If the M4 macro @var{macro-name} has not already been called, call it
  12254. (without any arguments). Make sure to quote @var{macro-name} with
  12255. square brackets. @var{macro-name} must have been defined using
  12256. @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
  12257. that it has been called.
  12258. @code{AC_REQUIRE} must be used inside a macro defined by @code{AC_DEFUN}; it
  12259. must not be called from the top level. Also, it does not make sense to
  12260. require a macro that takes parameters.
  12261. @end defmac
  12262. @code{AC_REQUIRE} is often misunderstood. It really implements
  12263. dependencies between macros in the sense that if one macro depends upon
  12264. another, the latter is expanded @emph{before} the body of the
  12265. former. To be more precise, the required macro is expanded before
  12266. the outermost defined macro in the current expansion stack.
  12267. In particular, @samp{AC_REQUIRE([FOO])} is not replaced with the body of
  12268. @code{FOO}. For instance, this definition of macros:
  12269. @example
  12270. @group
  12271. AC_DEFUN([TRAVOLTA],
  12272. [test "$body_temperature_in_celsius" -gt "38" &&
  12273. dance_floor=occupied])
  12274. AC_DEFUN([NEWTON_JOHN],
  12275. [test "x$hair_style" = xcurly &&
  12276. dance_floor=occupied])
  12277. @end group
  12278. @group
  12279. AC_DEFUN([RESERVE_DANCE_FLOOR],
  12280. [if date | grep '^Sat.*pm' >/dev/null 2>&1; then
  12281. AC_REQUIRE([TRAVOLTA])
  12282. AC_REQUIRE([NEWTON_JOHN])
  12283. fi])
  12284. @end group
  12285. @end example
  12286. @noindent
  12287. with this @file{configure.ac}
  12288. @example
  12289. AC_INIT([Dance Manager], [1.0], [bug-dance@@example.org])
  12290. RESERVE_DANCE_FLOOR
  12291. if test "x$dance_floor" = xoccupied; then
  12292. AC_MSG_ERROR([cannot pick up here, let's move])
  12293. fi
  12294. @end example
  12295. @noindent
  12296. does not leave you with a better chance to meet a kindred soul at
  12297. other times than Saturday night since it expands into:
  12298. @example
  12299. @group
  12300. test "$body_temperature_in_Celsius" -gt "38" &&
  12301. dance_floor=occupied
  12302. test "x$hair_style" = xcurly &&
  12303. dance_floor=occupied
  12304. fi
  12305. if date | grep '^Sat.*pm' >/dev/null 2>&1; then
  12306. fi
  12307. @end group
  12308. @end example
  12309. This behavior was chosen on purpose: (i) it prevents messages in
  12310. required macros from interrupting the messages in the requiring macros;
  12311. (ii) it avoids bad surprises when shell conditionals are used, as in:
  12312. @example
  12313. @group
  12314. if @dots{}; then
  12315. AC_REQUIRE([SOME_CHECK])
  12316. fi
  12317. @dots{}
  12318. SOME_CHECK
  12319. @end group
  12320. @end example
  12321. However, this implementation can lead to another class of problems.
  12322. Consider the case where an outer macro first expands, then indirectly
  12323. requires, an inner macro:
  12324. @example
  12325. AC_DEFUN([TESTA], [[echo in A
  12326. if test -n "$SEEN_A" ; then echo duplicate ; fi
  12327. SEEN_A=:]])
  12328. AC_DEFUN([TESTB], [AC_REQUIRE([TESTA])[echo in B
  12329. if test -z "$SEEN_A" ; then echo bug ; fi]])
  12330. AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])
  12331. AC_DEFUN([OUTER], [[echo in OUTER]
  12332. TESTA
  12333. TESTC])
  12334. OUTER
  12335. @end example
  12336. @noindent
  12337. Prior to Autoconf 2.64, the implementation of @code{AC_REQUIRE}
  12338. recognized that @code{TESTB} needed to be hoisted prior to the expansion
  12339. of @code{OUTER}, but because @code{TESTA} had already been directly
  12340. expanded, it failed to hoist @code{TESTA}. Therefore, the expansion of
  12341. @code{TESTB} occurs prior to its prerequisites, leading to the following
  12342. output:
  12343. @example
  12344. in B
  12345. bug
  12346. in OUTER
  12347. in A
  12348. in C
  12349. @end example
  12350. @noindent
  12351. Newer Autoconf is smart enough to recognize this situation, and hoists
  12352. @code{TESTA} even though it has already been expanded, but issues a
  12353. syntax warning in the process. This is because the hoisted expansion of
  12354. @code{TESTA} defeats the purpose of using @code{AC_REQUIRE} to avoid
  12355. redundant code, and causes its own set of problems if the hoisted macro
  12356. is not idempotent:
  12357. @example
  12358. in A
  12359. in B
  12360. in OUTER
  12361. in A
  12362. duplicate
  12363. in C
  12364. @end example
  12365. The bug is not in Autoconf, but in the macro definitions. If you ever
  12366. pass a particular macro name to @code{AC_REQUIRE}, then you are implying
  12367. that the macro only needs to be expanded once. But to enforce this,
  12368. either the macro must be declared with @code{AC_DEFUN_ONCE} (although
  12369. this only helps in Autoconf 2.64 or newer), or all
  12370. uses of that macro should be through @code{AC_REQUIRE}; directly
  12371. expanding the macro defeats the point of using @code{AC_REQUIRE} to
  12372. eliminate redundant expansion. In the example, this rule of thumb was
  12373. violated because @code{TESTB} requires @code{TESTA} while @code{OUTER}
  12374. directly expands it. One way of fixing the bug is to factor
  12375. @code{TESTA} into two macros, the portion designed for direct and
  12376. repeated use (here, named @code{TESTA}), and the portion designed for
  12377. one-shot output and used only inside @code{AC_REQUIRE} (here, named
  12378. @code{TESTA_PREREQ}). Then, by fixing all clients to use the correct
  12379. calling convention according to their needs:
  12380. @example
  12381. AC_DEFUN([TESTA], [AC_REQUIRE([TESTA_PREREQ])[echo in A]])
  12382. AC_DEFUN([TESTA_PREREQ], [[echo in A_PREREQ
  12383. if test -n "$SEEN_A" ; then echo duplicate ; fi
  12384. SEEN_A=:]])
  12385. AC_DEFUN([TESTB], [AC_REQUIRE([TESTA_PREREQ])[echo in B
  12386. if test -z "$SEEN_A" ; then echo bug ; fi]])
  12387. AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])
  12388. AC_DEFUN([OUTER], [[echo in OUTER]
  12389. TESTA
  12390. TESTC])
  12391. OUTER
  12392. @end example
  12393. @noindent
  12394. the resulting output will then obey all dependency rules and avoid any
  12395. syntax warnings, whether the script is built with old or new Autoconf
  12396. versions:
  12397. @example
  12398. in A_PREREQ
  12399. in B
  12400. in OUTER
  12401. in A
  12402. in C
  12403. @end example
  12404. The helper macros @code{AS_IF} and @code{AS_CASE} may be used to
  12405. enforce expansion of required macros outside of shell conditional
  12406. constructs. You are furthermore encouraged, although not required, to
  12407. put all @code{AC_REQUIRE} calls
  12408. at the beginning of a macro. You can use @code{dnl} to avoid the empty
  12409. lines they leave.
  12410. @node Suggested Ordering
  12411. @subsection Suggested Ordering
  12412. @cindex Macros, ordering
  12413. @cindex Ordering macros
  12414. Some macros should be run before another macro if both are called, but
  12415. neither @emph{requires} that the other be called. For example, a macro
  12416. that changes the behavior of the C compiler should be called before any
  12417. macros that run the C compiler. Many of these dependencies are noted in
  12418. the documentation.
  12419. Autoconf provides the @code{AC_BEFORE} macro to warn users when macros
  12420. with this kind of dependency appear out of order in a
  12421. @file{configure.ac} file. The warning occurs when creating
  12422. @command{configure} from @file{configure.ac}, not when running
  12423. @command{configure}.
  12424. For example, @code{AC_PROG_CPP} checks whether the C compiler
  12425. can run the C preprocessor when given the @option{-E} option. It should
  12426. therefore be called after any macros that change which C compiler is
  12427. being used, such as @code{AC_PROG_CC}. So @code{AC_PROG_CC} contains:
  12428. @example
  12429. AC_BEFORE([$0], [AC_PROG_CPP])dnl
  12430. @end example
  12431. @noindent
  12432. This warns the user if a call to @code{AC_PROG_CPP} has already occurred
  12433. when @code{AC_PROG_CC} is called.
  12434. @defmac AC_BEFORE (@var{this-macro-name}, @var{called-macro-name})
  12435. @acindex{BEFORE}
  12436. Make M4 print a warning message to the standard error output if
  12437. @var{called-macro-name} has already been called. @var{this-macro-name}
  12438. should be the name of the macro that is calling @code{AC_BEFORE}. The
  12439. macro @var{called-macro-name} must have been defined using
  12440. @code{AC_DEFUN} or else contain a call to @code{AC_PROVIDE} to indicate
  12441. that it has been called.
  12442. @end defmac
  12443. @node One-Shot Macros
  12444. @subsection One-Shot Macros
  12445. @cindex One-shot macros
  12446. @cindex Macros, called once
  12447. Some macros should be called only once, either because calling them
  12448. multiple time is unsafe, or because it is bad style. For instance
  12449. Autoconf ensures that @code{AC_CANONICAL_BUILD} and cousins
  12450. (@pxref{Canonicalizing}) are evaluated only once, because it makes no
  12451. sense to run these expensive checks more than once. Such one-shot
  12452. macros can be defined using @code{AC_DEFUN_ONCE}.
  12453. @defmac AC_DEFUN_ONCE (@var{macro-name}, @var{macro-body})
  12454. @acindex{DEFUN_ONCE}
  12455. Declare macro @var{macro-name} like @code{AC_DEFUN} would (@pxref{Macro
  12456. Definitions}), but add additional logic that guarantees that only the
  12457. first use of the macro (whether by direct expansion or
  12458. @code{AC_REQUIRE}) causes an expansion of @var{macro-body}; the
  12459. expansion will occur before the start of any enclosing macro defined by
  12460. @code{AC_DEFUN}. Subsequent expansions are silently ignored.
  12461. Generally, it does not make sense for @var{macro-body} to use parameters
  12462. such as @code{$1}.
  12463. @end defmac
  12464. Prior to Autoconf 2.64, a macro defined by @code{AC_DEFUN_ONCE} would
  12465. emit a warning if it was directly expanded a second time, so for
  12466. portability, it is better to use @code{AC_REQUIRE} than direct
  12467. invocation of @var{macro-name} inside a macro defined by @code{AC_DEFUN}
  12468. (@pxref{Prerequisite Macros}).
  12469. @node Obsoleting Macros
  12470. @section Obsoleting Macros
  12471. @cindex Obsoleting macros
  12472. @cindex Macros, obsoleting
  12473. Configuration and portability technology has evolved over the years.
  12474. Often better ways of solving a particular problem are developed, or
  12475. ad-hoc approaches are systematized. This process has occurred in many
  12476. parts of Autoconf. One result is that some of the macros are now
  12477. considered @dfn{obsolete}; they still work, but are no longer considered
  12478. the best thing to do, hence they should be replaced with more modern
  12479. macros. Ideally, @command{autoupdate} should replace the old macro calls
  12480. with their modern implementation.
  12481. Autoconf provides a simple means to obsolete a macro.
  12482. @anchor{AU_DEFUN}
  12483. @defmac AU_DEFUN (@var{old-macro}, @var{implementation}, @ovar{message})
  12484. @auindex{DEFUN}
  12485. Define @var{old-macro} as @var{implementation}. The only difference
  12486. with @code{AC_DEFUN} is that the user is warned that
  12487. @var{old-macro} is now obsolete.
  12488. If she then uses @command{autoupdate}, the call to @var{old-macro} is
  12489. replaced by the modern @var{implementation}. @var{message} should
  12490. include information on what to do after running @command{autoupdate};
  12491. @command{autoupdate} prints it as a warning, and includes it
  12492. in the updated @file{configure.ac} file.
  12493. The details of this macro are hairy: if @command{autoconf} encounters an
  12494. @code{AU_DEFUN}ed macro, all macros inside its second argument are expanded
  12495. as usual. However, when @command{autoupdate} is run, only M4 and M4sugar
  12496. macros are expanded here, while all other macros are disabled and
  12497. appear literally in the updated @file{configure.ac}.
  12498. @end defmac
  12499. @defmac AU_ALIAS (@var{old-name}, @var{new-name})
  12500. @auindex{ALIAS}
  12501. Used if the @var{old-name} is to be replaced by a call to @var{new-macro}
  12502. with the same parameters. This happens for example if the macro was renamed.
  12503. @end defmac
  12504. @node Coding Style
  12505. @section Coding Style
  12506. @cindex Coding style
  12507. The Autoconf macros follow a strict coding style. You are encouraged to
  12508. follow this style, especially if you intend to distribute your macro,
  12509. either by contributing it to Autoconf itself or the
  12510. @uref{http://@/www.gnu.org/@/software/@/autoconf-archive/, Autoconf Macro
  12511. Archive}, or by other means.
  12512. The first requirement is to pay great attention to the quotation. For
  12513. more details, see @ref{Autoconf Language}, and @ref{M4 Quotation}.
  12514. Do not try to invent new interfaces. It is likely that there is a macro
  12515. in Autoconf that resembles the macro you are defining: try to stick to
  12516. this existing interface (order of arguments, default values, etc.). We
  12517. @emph{are} conscious that some of these interfaces are not perfect;
  12518. nevertheless, when harmless, homogeneity should be preferred over
  12519. creativity.
  12520. Be careful about clashes both between M4 symbols and between shell
  12521. variables.
  12522. If you stick to the suggested M4 naming scheme (@pxref{Macro Names}),
  12523. you are unlikely to generate conflicts. Nevertheless, when you need to
  12524. set a special value, @emph{avoid using a regular macro name}; rather,
  12525. use an ``impossible'' name. For instance, up to version 2.13, the macro
  12526. @code{AC_SUBST} used to remember what @var{symbol} macros were already defined
  12527. by setting @code{AC_SUBST_@var{symbol}}, which is a regular macro name.
  12528. But since there is a macro named @code{AC_SUBST_FILE}, it was just
  12529. impossible to @samp{AC_SUBST(FILE)}! In this case,
  12530. @code{AC_SUBST(@var{symbol})} or @code{_AC_SUBST(@var{symbol})} should
  12531. have been used (yes, with the parentheses).
  12532. @c or better yet, high-level macros such as @code{m4_expand_once}
  12533. No Autoconf macro should ever enter the user-variable name space; i.e.,
  12534. except for the variables that are the actual result of running the
  12535. macro, all shell variables should start with @code{ac_}. In
  12536. addition, small macros or any macro that is likely to be embedded in
  12537. other macros should be careful not to use obvious names.
  12538. @cindex @code{dnl}
  12539. Do not use @code{dnl} to introduce comments: most of the comments you
  12540. are likely to write are either header comments which are not output
  12541. anyway, or comments that should make their way into @file{configure}.
  12542. There are exceptional cases where you do want to comment special M4
  12543. constructs, in which case @code{dnl} is right, but keep in mind that it
  12544. is unlikely.
  12545. M4 ignores the leading blanks and newlines before each argument.
  12546. Use this feature to
  12547. indent in such a way that arguments are (more or less) aligned with the
  12548. opening parenthesis of the macro being called. For instance, instead of
  12549. @example
  12550. AC_CACHE_CHECK(for EMX OS/2 environment,
  12551. ac_cv_emxos2,
  12552. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [return __EMX__;])],
  12553. [ac_cv_emxos2=yes], [ac_cv_emxos2=no])])
  12554. @end example
  12555. @noindent
  12556. write
  12557. @example
  12558. AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
  12559. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
  12560. [ac_cv_emxos2=yes],
  12561. [ac_cv_emxos2=no])])
  12562. @end example
  12563. @noindent
  12564. or even
  12565. @example
  12566. AC_CACHE_CHECK([for EMX OS/2 environment],
  12567. [ac_cv_emxos2],
  12568. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  12569. [return __EMX__;])],
  12570. [ac_cv_emxos2=yes],
  12571. [ac_cv_emxos2=no])])
  12572. @end example
  12573. When using @code{AC_RUN_IFELSE} or any macro that cannot work when
  12574. cross-compiling, provide a pessimistic value (typically @samp{no}).
  12575. Feel free to use various tricks to prevent auxiliary tools, such as
  12576. syntax-highlighting editors, from behaving improperly. For instance,
  12577. instead of:
  12578. @example
  12579. m4_bpatsubst([$1], [$"])
  12580. @end example
  12581. @noindent
  12582. use
  12583. @example
  12584. m4_bpatsubst([$1], [$""])
  12585. @end example
  12586. @noindent
  12587. so that Emacsen do not open an endless ``string'' at the first quote.
  12588. For the same reasons, avoid:
  12589. @example
  12590. test $[#] != 0
  12591. @end example
  12592. @noindent
  12593. and use:
  12594. @example
  12595. test $[@@%:@@] != 0
  12596. @end example
  12597. @noindent
  12598. Otherwise, the closing bracket would be hidden inside a @samp{#}-comment,
  12599. breaking the bracket-matching highlighting from Emacsen. Note the
  12600. preferred style to escape from M4: @samp{$[1]}, @samp{$[@@]}, etc. Do
  12601. not escape when it is unnecessary. Common examples of useless quotation
  12602. are @samp{[$]$1} (write @samp{$$1}), @samp{[$]var} (use @samp{$var}),
  12603. etc. If you add portability issues to the picture, you'll prefer
  12604. @samp{$@{1+"$[@@]"@}} to @samp{"[$]@@"}, and you'll prefer do something
  12605. better than hacking Autoconf @code{:-)}.
  12606. When using @command{sed}, don't use @option{-e} except for indenting
  12607. purposes. With the @code{s} and @code{y} commands, the preferred
  12608. separator is @samp{/} unless @samp{/} itself might appear in the pattern
  12609. or replacement, in which case you should use @samp{|}, or optionally
  12610. @samp{,} if you know the pattern and replacement cannot contain a file
  12611. name. If none of these characters will do, choose a printable character
  12612. that cannot appear in the pattern or replacement. Characters from the
  12613. set @samp{"#$&'()*;<=>?`|~} are good choices if the pattern or
  12614. replacement might contain a file name, since they have special meaning
  12615. to the shell and are less likely to occur in file names.
  12616. @xref{Macro Definitions}, for details on how to define a macro. If a
  12617. macro doesn't use @code{AC_REQUIRE}, is expected to never be the object
  12618. of an @code{AC_REQUIRE} directive, and macros required by other macros
  12619. inside arguments do not need to be expanded before this macro, then
  12620. use @code{m4_define}. In case of doubt, use @code{AC_DEFUN}.
  12621. Also take into account that public third-party macros need to use
  12622. @code{AC_DEFUN} in order to be found by @command{aclocal}
  12623. (@pxref{Extending aclocal,,, automake, GNU Automake}).
  12624. All the @code{AC_REQUIRE} statements should be at the beginning of the
  12625. macro, and each statement should be followed by @code{dnl}.
  12626. You should not rely on the number of arguments: instead of checking
  12627. whether an argument is missing, test that it is not empty. It provides
  12628. both a simpler and a more predictable interface to the user, and saves
  12629. room for further arguments.
  12630. Unless the macro is short, try to leave the closing @samp{])} at the
  12631. beginning of a line, followed by a comment that repeats the name of the
  12632. macro being defined. This introduces an additional newline in
  12633. @command{configure}; normally, that is not a problem, but if you want to
  12634. remove it you can use @samp{[]dnl} on the last line. You can similarly
  12635. use @samp{[]dnl} after a macro call to remove its newline. @samp{[]dnl}
  12636. is recommended instead of @samp{dnl} to ensure that M4 does not
  12637. interpret the @samp{dnl} as being attached to the preceding text or
  12638. macro output. For example, instead of:
  12639. @example
  12640. AC_DEFUN([AC_PATH_X],
  12641. [AC_MSG_CHECKING([for X])
  12642. AC_REQUIRE_CPP()
  12643. @r{# @dots{}omitted@dots{}}
  12644. AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
  12645. fi])
  12646. @end example
  12647. @noindent
  12648. you would write:
  12649. @example
  12650. AC_DEFUN([AC_PATH_X],
  12651. [AC_REQUIRE_CPP()[]dnl
  12652. AC_MSG_CHECKING([for X])
  12653. @r{# @dots{}omitted@dots{}}
  12654. AC_MSG_RESULT([libraries $x_libraries, headers $x_includes])
  12655. fi[]dnl
  12656. ])# AC_PATH_X
  12657. @end example
  12658. If the macro is long, try to split it into logical chunks. Typically,
  12659. macros that check for a bug in a function and prepare its
  12660. @code{AC_LIBOBJ} replacement should have an auxiliary macro to perform
  12661. this setup. Do not hesitate to introduce auxiliary macros to factor
  12662. your code.
  12663. In order to highlight the recommended coding style, here is a macro
  12664. written the old way:
  12665. @example
  12666. dnl Check for EMX on OS/2.
  12667. dnl _AC_EMXOS2
  12668. AC_DEFUN(_AC_EMXOS2,
  12669. [AC_CACHE_CHECK(for EMX OS/2 environment, ac_cv_emxos2,
  12670. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, return __EMX__;)],
  12671. ac_cv_emxos2=yes, ac_cv_emxos2=no)])
  12672. test "x$ac_cv_emxos2" = xyes && EMXOS2=yes])
  12673. @end example
  12674. @noindent
  12675. and the new way:
  12676. @example
  12677. # _AC_EMXOS2
  12678. # ----------
  12679. # Check for EMX on OS/2.
  12680. m4_define([_AC_EMXOS2],
  12681. [AC_CACHE_CHECK([for EMX OS/2 environment], [ac_cv_emxos2],
  12682. [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [return __EMX__;])],
  12683. [ac_cv_emxos2=yes],
  12684. [ac_cv_emxos2=no])])
  12685. test "x$ac_cv_emxos2" = xyes && EMXOS2=yes[]dnl
  12686. ])# _AC_EMXOS2
  12687. @end example
  12688. @c ============================================= Portable Shell Programming
  12689. @node Portable Shell
  12690. @chapter Portable Shell Programming
  12691. @cindex Portable shell programming
  12692. When writing your own checks, there are some shell-script programming
  12693. techniques you should avoid in order to make your code portable. The
  12694. Bourne shell and upward-compatible shells like the Korn shell and Bash
  12695. have evolved over the years, and many features added to the original
  12696. System7 shell are now supported on all interesting porting targets.
  12697. However, the following discussion between Russ Allbery and Robert Lipe
  12698. is worth reading:
  12699. @noindent
  12700. Russ Allbery:
  12701. @quotation
  12702. The GNU assumption that @command{/bin/sh} is the one and only shell
  12703. leads to a permanent deadlock. Vendors don't want to break users'
  12704. existing shell scripts, and there are some corner cases in the Bourne
  12705. shell that are not completely compatible with a Posix shell. Thus,
  12706. vendors who have taken this route will @emph{never} (OK@dots{}``never say
  12707. never'') replace the Bourne shell (as @command{/bin/sh}) with a
  12708. Posix shell.
  12709. @end quotation
  12710. @noindent
  12711. Robert Lipe:
  12712. @quotation
  12713. This is exactly the problem. While most (at least most System V's) do
  12714. have a Bourne shell that accepts shell functions most vendor
  12715. @command{/bin/sh} programs are not the Posix shell.
  12716. So while most modern systems do have a shell @emph{somewhere} that meets the
  12717. Posix standard, the challenge is to find it.
  12718. @end quotation
  12719. For this reason, part of the job of M4sh (@pxref{Programming in M4sh})
  12720. is to find such a shell. But to prevent trouble, if you're not using
  12721. M4sh you should not take advantage of features that were added after Unix
  12722. version 7, circa 1977 (@pxref{Systemology}); you should not use aliases,
  12723. negated character classes, or even @command{unset}. @code{#} comments,
  12724. while not in Unix version 7, were retrofitted in the original Bourne
  12725. shell and can be assumed to be part of the least common denominator.
  12726. On the other hand, if you're using M4sh you can assume that the shell
  12727. has the features that were added in SVR2 (circa 1984), including shell
  12728. functions,
  12729. @command{return}, @command{unset}, and I/O redirection for builtins. For
  12730. more information, refer to @uref{http://@/www.in-ulm.de/@/~mascheck/@/bourne/}.
  12731. However, some pitfalls have to be avoided for portable use of these
  12732. constructs; these will be documented in the rest of this chapter.
  12733. See in particular @ref{Shell Functions} and @ref{Limitations of
  12734. Builtins, , Limitations of Shell Builtins}.
  12735. Some ancient systems have quite
  12736. small limits on the length of the @samp{#!} line; for instance, 32
  12737. bytes (not including the newline) on SunOS 4.
  12738. However, these ancient systems are no longer of practical concern.
  12739. The set of external programs you should run in a @command{configure} script
  12740. is fairly small. @xref{Utilities in Makefiles, , Utilities in
  12741. Makefiles, standards, The GNU Coding Standards}, for the list. This
  12742. restriction allows users to start out with a fairly small set of
  12743. programs and build the rest, avoiding too many interdependencies between
  12744. packages.
  12745. Some of these external utilities have a portable subset of features; see
  12746. @ref{Limitations of Usual Tools}.
  12747. There are other sources of documentation about shells. The
  12748. specification for the Posix
  12749. @uref{http://@/www.opengroup.org/@/susv3/@/utilities/@/xcu_chap02@/.html, Shell
  12750. Command Language}, though more generous than the restrictive shell
  12751. subset described above, is fairly portable nowadays. Also please see
  12752. @uref{http://@/www.faqs.org/@/faqs/@/unix-faq/@/shell/, the Shell FAQs}.
  12753. @menu
  12754. * Shellology:: A zoology of shells
  12755. * Invoking the Shell:: Invoking the shell as a command
  12756. * Here-Documents:: Quirks and tricks
  12757. * File Descriptors:: FDs and redirections
  12758. * Signal Handling:: Shells, signals, and headaches
  12759. * File System Conventions:: File names
  12760. * Shell Pattern Matching:: Pattern matching
  12761. * Shell Substitutions:: Variable and command expansions
  12762. * Assignments:: Varying side effects of assignments
  12763. * Parentheses:: Parentheses in shell scripts
  12764. * Slashes:: Slashes in shell scripts
  12765. * Special Shell Variables:: Variables you should not change
  12766. * Shell Functions:: What to look out for if you use them
  12767. * Limitations of Builtins:: Portable use of not so portable /bin/sh
  12768. * Limitations of Usual Tools:: Portable use of portable tools
  12769. @end menu
  12770. @node Shellology
  12771. @section Shellology
  12772. @cindex Shellology
  12773. There are several families of shells, most prominently the Bourne family
  12774. and the C shell family which are deeply incompatible. If you want to
  12775. write portable shell scripts, avoid members of the C shell family. The
  12776. @uref{http://@/www.faqs.org/@/faqs/@/unix-faq/@/shell/@/shell-differences/, the
  12777. Shell difference FAQ} includes a small history of Posix shells, and a
  12778. comparison between several of them.
  12779. Below we describe some of the members of the Bourne shell family.
  12780. @table @asis
  12781. @item Ash
  12782. @cindex Ash
  12783. Ash is often used on GNU/Linux and BSD
  12784. systems as a light-weight Bourne-compatible shell. Ash 0.2 has some
  12785. bugs that are fixed in the 0.3.x series, but portable shell scripts
  12786. should work around them, since version 0.2 is still shipped with many
  12787. GNU/Linux distributions.
  12788. To be compatible with Ash 0.2:
  12789. @itemize @minus
  12790. @item
  12791. don't use @samp{$?} after expanding empty or unset variables,
  12792. or at the start of an @command{eval}:
  12793. @example
  12794. foo=
  12795. false
  12796. $foo
  12797. echo "Do not use it: $?"
  12798. false
  12799. eval 'echo "Do not use it: $?"'
  12800. @end example
  12801. @item
  12802. don't use command substitution within variable expansion:
  12803. @example
  12804. cat $@{FOO=`bar`@}
  12805. @end example
  12806. @item
  12807. beware that single builtin substitutions are not performed by a
  12808. subshell, hence their effect applies to the current shell! @xref{Shell
  12809. Substitutions}, item ``Command Substitution''.
  12810. @end itemize
  12811. @item Bash
  12812. @cindex Bash
  12813. To detect whether you are running Bash, test whether
  12814. @code{BASH_VERSION} is set. To require
  12815. Posix compatibility, run @samp{set -o posix}. @xref{Bash POSIX
  12816. Mode, , Bash Posix Mode, bash, The GNU Bash Reference
  12817. Manual}, for details.
  12818. @item Bash 2.05 and later
  12819. @cindex Bash 2.05 and later
  12820. Versions 2.05 and later of Bash use a different format for the
  12821. output of the @command{set} builtin, designed to make evaluating its
  12822. output easier. However, this output is not compatible with earlier
  12823. versions of Bash (or with many other shells, probably). So if
  12824. you use Bash 2.05 or higher to execute @command{configure},
  12825. you'll need to use Bash 2.05 for all other build tasks as well.
  12826. @item Ksh
  12827. @cindex Ksh
  12828. @cindex Korn shell
  12829. @prindex @samp{ksh}
  12830. @prindex @samp{ksh88}
  12831. @prindex @samp{ksh93}
  12832. The Korn shell is compatible with the Bourne family and it mostly
  12833. conforms to Posix. It has two major variants commonly
  12834. called @samp{ksh88} and @samp{ksh93}, named after the years of initial
  12835. release. It is usually called @command{ksh}, but is called @command{sh}
  12836. on some hosts if you set your path appropriately.
  12837. Solaris systems have three variants:
  12838. @prindex @command{/usr/bin/ksh} on Solaris
  12839. @command{/usr/bin/ksh} is @samp{ksh88}; it is
  12840. standard on Solaris 2.0 and later.
  12841. @prindex @command{/usr/xpg4/bin/sh} on Solaris
  12842. @command{/usr/xpg4/bin/sh} is a Posix-compliant variant of
  12843. @samp{ksh88}; it is standard on Solaris 9 and later.
  12844. @prindex @command{/usr/dt/bin/dtksh} on Solaris
  12845. @command{/usr/dt/bin/dtksh} is @samp{ksh93}.
  12846. Variants that are not standard may be parts of optional
  12847. packages. There is no extra charge for these packages, but they are
  12848. not part of a minimal OS install and therefore some installations may
  12849. not have it.
  12850. Starting with Tru64 Version 4.0, the Korn shell @command{/usr/bin/ksh}
  12851. is also available as @command{/usr/bin/posix/sh}. If the environment
  12852. variable @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations of
  12853. the standard shell conform to Posix.
  12854. @item Pdksh
  12855. @prindex @samp{pdksh}
  12856. A public-domain clone of the Korn shell called @command{pdksh} is widely
  12857. available: it has most of the @samp{ksh88} features along with a few of
  12858. its own. It usually sets @code{KSH_VERSION}, except if invoked as
  12859. @command{/bin/sh} on OpenBSD, and similarly to Bash you can require
  12860. Posix compatibility by running @samp{set -o posix}. Unfortunately, with
  12861. @command{pdksh} 5.2.14 (the latest stable version as of January 2007)
  12862. Posix mode is buggy and causes @command{pdksh} to depart from Posix in
  12863. at least one respect, see @ref{Shell Substitutions}.
  12864. @item Zsh
  12865. @cindex Zsh
  12866. To detect whether you are running @command{zsh}, test whether
  12867. @code{ZSH_VERSION} is set. By default @command{zsh} is @emph{not}
  12868. compatible with the Bourne shell: you must execute @samp{emulate sh},
  12869. and for @command{zsh} versions before 3.1.6-dev-18 you must also
  12870. set @code{NULLCMD} to @samp{:}. @xref{Compatibility, , Compatibility,
  12871. zsh, The Z Shell Manual}, for details.
  12872. The default Mac OS X @command{sh} was originally Zsh; it was changed to
  12873. Bash in Mac OS X 10.2.
  12874. @end table
  12875. @node Invoking the Shell
  12876. @section Invoking the Shell
  12877. @cindex invoking the shell
  12878. @cindex shell invocation
  12879. The Korn shell (up to at least version M-12/28/93d) has a bug when
  12880. invoked on a file whose name does not contain a slash. It first
  12881. searches for the file's name in @env{PATH}, and if found it executes
  12882. that rather than the original file. For example, assuming there is a
  12883. binary executable @file{/usr/bin/script} in your @env{PATH}, the last
  12884. command in the following example fails because the Korn shell finds
  12885. @file{/usr/bin/script} and refuses to execute it as a shell script:
  12886. @example
  12887. $ @kbd{touch xxyzzyz script}
  12888. $ @kbd{ksh xxyzzyz}
  12889. $ @kbd{ksh ./script}
  12890. $ @kbd{ksh script}
  12891. ksh: script: cannot execute
  12892. @end example
  12893. Bash 2.03 has a bug when invoked with the @option{-c} option: if the
  12894. option-argument ends in backslash-newline, Bash incorrectly reports a
  12895. syntax error. The problem does not occur if a character follows the
  12896. backslash:
  12897. @example
  12898. $ @kbd{$ bash -c 'echo foo \}
  12899. > @kbd{'}
  12900. bash: -c: line 2: syntax error: unexpected end of file
  12901. $ @kbd{bash -c 'echo foo \}
  12902. > @kbd{ '}
  12903. foo
  12904. @end example
  12905. @noindent
  12906. @xref{Backslash-Newline-Empty}, for how this can cause problems in makefiles.
  12907. @node Here-Documents
  12908. @section Here-Documents
  12909. @cindex Here-documents
  12910. @cindex Shell here-documents
  12911. Don't rely on @samp{\} being preserved just because it has no special
  12912. meaning together with the next symbol. In the native @command{sh}
  12913. on OpenBSD 2.7 @samp{\"} expands to @samp{"} in here-documents with
  12914. unquoted delimiter. As a general rule, if @samp{\\} expands to @samp{\}
  12915. use @samp{\\} to get @samp{\}.
  12916. With OpenBSD 2.7's @command{sh}
  12917. @example
  12918. @group
  12919. $ @kbd{cat <<EOF
  12920. > \" \\
  12921. > EOF}
  12922. " \
  12923. @end group
  12924. @end example
  12925. @noindent
  12926. and with Bash:
  12927. @example
  12928. @group
  12929. bash-2.04$ @kbd{cat <<EOF
  12930. > \" \\
  12931. > EOF}
  12932. \" \
  12933. @end group
  12934. @end example
  12935. Using command substitutions in a here-document that is fed to a shell
  12936. function is not portable. For example, with Solaris 10 @command{/bin/sh}:
  12937. @example
  12938. $ @kbd{kitty () @{ cat; @}}
  12939. $ @kbd{kitty <<EOF
  12940. > `echo ok`
  12941. > EOF}
  12942. /tmp/sh199886: cannot open
  12943. $ @kbd{echo $?}
  12944. 1
  12945. @end example
  12946. Some shells mishandle large here-documents: for example,
  12947. Solaris 10 @command{dtksh} and the UnixWare 7.1.1 Posix shell, which are
  12948. derived from Korn shell version M-12/28/93d, mishandle braced variable
  12949. expansion that crosses a 1024- or 4096-byte buffer boundary
  12950. within a here-document. Only the part of the variable name after the boundary
  12951. is used. For example, @code{$@{variable@}} could be replaced by the expansion
  12952. of @code{$@{ble@}}. If the end of the variable name is aligned with the block
  12953. boundary, the shell reports an error, as if you used @code{$@{@}}.
  12954. Instead of @code{$@{variable-default@}}, the shell may expand
  12955. @code{$@{riable-default@}}, or even @code{$@{fault@}}. This bug can often
  12956. be worked around by omitting the braces: @code{$variable}. The bug was
  12957. fixed in
  12958. @samp{ksh93g} (1998-04-30) but as of 2006 many operating systems were
  12959. still shipping older versions with the bug.
  12960. Empty here-documents are not portable either; with the following code,
  12961. @command{zsh} up to at least version 4.3.10 creates a file with a single
  12962. newline, whereas other shells create an empty file:
  12963. @example
  12964. cat >file <<EOF
  12965. EOF
  12966. @end example
  12967. Many shells (including the Bourne shell) implement here-documents
  12968. inefficiently. In particular, some shells can be extremely inefficient when
  12969. a single statement contains many here-documents. For instance if your
  12970. @file{configure.ac} includes something like:
  12971. @example
  12972. @group
  12973. if <cross_compiling>; then
  12974. assume this and that
  12975. else
  12976. check this
  12977. check that
  12978. check something else
  12979. @dots{}
  12980. on and on forever
  12981. @dots{}
  12982. fi
  12983. @end group
  12984. @end example
  12985. A shell parses the whole @code{if}/@code{fi} construct, creating
  12986. temporary files for each here-document in it. Some shells create links
  12987. for such here-documents on every @code{fork}, so that the clean-up code
  12988. they had installed correctly removes them. It is creating the links
  12989. that can take the shell forever.
  12990. Moving the tests out of the @code{if}/@code{fi}, or creating multiple
  12991. @code{if}/@code{fi} constructs, would improve the performance
  12992. significantly. Anyway, this kind of construct is not exactly the
  12993. typical use of Autoconf. In fact, it's even not recommended, because M4
  12994. macros can't look into shell conditionals, so we may fail to expand a
  12995. macro when it was expanded before in a conditional path, and the
  12996. condition turned out to be false at runtime, and we end up not
  12997. executing the macro at all.
  12998. Be careful with the use of @samp{<<-} to unindent here-documents. The
  12999. behavior is only portable for stripping leading @key{TAB}s, and things
  13000. can silently break if an overzealous editor converts to using leading
  13001. spaces (not all shells are nice enough to warn about unterminated
  13002. here-documents).
  13003. @example
  13004. $ @kbd{printf 'cat <<-x\n\t1\n\t 2\n\tx\n' | bash && echo done}
  13005. 1
  13006. 2
  13007. done
  13008. $ @kbd{printf 'cat <<-x\n 1\n 2\n x\n' | bash-3.2 && echo done}
  13009. 1
  13010. 2
  13011. x
  13012. done
  13013. @end example
  13014. @node File Descriptors
  13015. @section File Descriptors
  13016. @cindex Descriptors
  13017. @cindex File descriptors
  13018. @cindex Shell file descriptors
  13019. Most shells, if not all (including Bash, Zsh, Ash), output traces on
  13020. stderr, even for subshells. This might result in undesirable content
  13021. if you meant to capture the standard-error output of the inner command:
  13022. @example
  13023. $ @kbd{ash -x -c '(eval "echo foo >&2") 2>stderr'}
  13024. $ @kbd{cat stderr}
  13025. + eval echo foo >&2
  13026. + echo foo
  13027. foo
  13028. $ @kbd{bash -x -c '(eval "echo foo >&2") 2>stderr'}
  13029. $ @kbd{cat stderr}
  13030. + eval 'echo foo >&2'
  13031. ++ echo foo
  13032. foo
  13033. $ @kbd{zsh -x -c '(eval "echo foo >&2") 2>stderr'}
  13034. @i{# Traces on startup files deleted here.}
  13035. $ @kbd{cat stderr}
  13036. +zsh:1> eval echo foo >&2
  13037. +zsh:1> echo foo
  13038. foo
  13039. @end example
  13040. @noindent
  13041. One workaround is to grep out uninteresting lines, hoping not to remove
  13042. good ones.
  13043. If you intend to redirect both standard error and standard output,
  13044. redirect standard output first. This works better with HP-UX,
  13045. since its shell mishandles tracing if standard error is redirected
  13046. first:
  13047. @example
  13048. $ @kbd{sh -x -c ': 2>err >out'}
  13049. + :
  13050. + 2> err $ @kbd{cat err}
  13051. 1> out
  13052. @end example
  13053. Don't try to redirect the standard error of a command substitution. It
  13054. must be done @emph{inside} the command substitution. When running
  13055. @samp{: `cd /zorglub` 2>/dev/null} expect the error message to
  13056. escape, while @samp{: `cd /zorglub 2>/dev/null`} works properly.
  13057. On the other hand, some shells, such as Solaris or FreeBSD
  13058. @command{/bin/sh}, warn about missing programs before performing
  13059. redirections. Therefore, to silently check whether a program exists, it
  13060. is necessary to perform redirections on a subshell or brace group:
  13061. @example
  13062. $ @kbd{/bin/sh -c 'nosuch 2>/dev/null'}
  13063. nosuch: not found
  13064. $ @kbd{/bin/sh -c '(nosuch) 2>/dev/null'}
  13065. $ @kbd{/bin/sh -c '@{ nosuch; @} 2>/dev/null'}
  13066. $ @kbd{bash -c 'nosuch 2>/dev/null'}
  13067. @end example
  13068. FreeBSD 6.2 sh may mix the trace output lines from the statements in a
  13069. shell pipeline.
  13070. It is worth noting that Zsh (but not Ash nor Bash) makes it possible
  13071. in assignments though: @samp{foo=`cd /zorglub` 2>/dev/null}.
  13072. Some shells, like @command{ash}, don't recognize bi-directional
  13073. redirection (@samp{<>}). And even on shells that recognize it, it is
  13074. not portable to use on fifos: Posix does not require read-write support
  13075. for named pipes, and Cygwin does not support it:
  13076. @example
  13077. $ @kbd{mkfifo fifo}
  13078. $ @kbd{exec 5<>fifo}
  13079. $ @kbd{echo hi >&5}
  13080. bash: echo: write error: Communication error on send
  13081. @end example
  13082. @noindent
  13083. Furthermore, versions of @command{dash} before 0.5.6 mistakenly truncate
  13084. regular files when using @samp{<>}:
  13085. @example
  13086. $ @kbd{echo a > file}
  13087. $ @kbd{bash -c ': 1<>file'; cat file}
  13088. a
  13089. $ @kbd{dash -c ': 1<>file'; cat file}
  13090. $ rm a
  13091. @end example
  13092. When catering to old systems, don't redirect the same file descriptor
  13093. several times, as you are doomed to failure under Ultrix.
  13094. @example
  13095. ULTRIX V4.4 (Rev. 69) System #31: Thu Aug 10 19:42:23 GMT 1995
  13096. UWS V4.4 (Rev. 11)
  13097. $ @kbd{eval 'echo matter >fullness' >void}
  13098. illegal io
  13099. $ @kbd{eval '(echo matter >fullness)' >void}
  13100. illegal io
  13101. $ @kbd{(eval '(echo matter >fullness)') >void}
  13102. Ambiguous output redirect.
  13103. @end example
  13104. @noindent
  13105. In each case the expected result is of course @file{fullness} containing
  13106. @samp{matter} and @file{void} being empty. However, this bug is
  13107. probably not of practical concern to modern platforms.
  13108. Solaris 10 @command{sh} will try to optimize away a @command{:} command
  13109. (even if it is redirected) in a loop after the first iteration, or in a
  13110. shell function after the first call:
  13111. @example
  13112. $ @kbd{for i in 1 2 3 ; do : >x$i; done}
  13113. $ @kbd{ls x*}
  13114. x1
  13115. $ @kbd{f () @{ : >$1; @}; f y1; f y2; f y3;}
  13116. $ @kbd{ls y*}
  13117. y1
  13118. @end example
  13119. @noindent
  13120. As a workaround, @command{echo} or @command{eval} can be used.
  13121. Don't rely on file descriptors 0, 1, and 2 remaining closed in a
  13122. subsidiary program. If any of these descriptors is closed, the
  13123. operating system may open an unspecified file for the descriptor in the
  13124. new process image. Posix 2008 says this may be done only if the
  13125. subsidiary program is set-user-ID or set-group-ID, but HP-UX 11.23 does
  13126. it even for ordinary programs, and the next version of Posix will allow
  13127. HP-UX behavior.
  13128. If you want a file descriptor above 2 to be inherited into a child
  13129. process, then you must use redirections specific to that command or a
  13130. containing subshell or command group, rather than relying on
  13131. @command{exec} in the shell. In @command{ksh} as well as HP-UX
  13132. @command{sh}, file descriptors above 2 which are opened using
  13133. @samp{exec @var{n}>file} are closed by a subsequent @samp{exec} (such as
  13134. that involved in the fork-and-exec which runs a program or script):
  13135. @example
  13136. $ @kbd{echo 'echo hello >&5' >k}
  13137. $ @kbd{/bin/sh -c 'exec 5>t; ksh ./k; exec 5>&-; cat t}
  13138. hello
  13139. $ @kbd{bash -c 'exec 5>t; ksh ./k; exec 5>&-; cat t}
  13140. hello
  13141. $ @kbd{ksh -c 'exec 5>t; ksh ./k; exec 5>&-; cat t}
  13142. ./k[1]: 5: cannot open [Bad file number]
  13143. $ @kbd{ksh -c '(ksh ./k) 5>t; cat t'}
  13144. hello
  13145. $ @kbd{ksh -c '@{ ksh ./k; @} 5>t; cat t'}
  13146. hello
  13147. $ @kbd{ksh -c '5>t ksh ./k; cat t}
  13148. hello
  13149. @end example
  13150. Don't rely on duplicating a closed file descriptor to cause an
  13151. error. With Solaris @command{/bin/sh}, failed duplication is silently
  13152. ignored, which can cause unintended leaks to the original file
  13153. descriptor. In this example, observe the leak to standard output:
  13154. @example
  13155. $ @kbd{bash -c 'echo hi >&3' 3>&-; echo $?}
  13156. bash: 3: Bad file descriptor
  13157. 1
  13158. $ @kbd{/bin/sh -c 'echo hi >&3' 3>&-; echo $?}
  13159. hi
  13160. 0
  13161. @end example
  13162. Fortunately, an attempt to close an already closed file descriptor will
  13163. portably succeed. Likewise, it is safe to use either style of
  13164. @samp{@var{n}<&-} or @samp{@var{n}>&-} for closing a file descriptor,
  13165. even if it doesn't match the read/write mode that the file descriptor
  13166. was opened with.
  13167. DOS variants cannot rename or remove open files, such as in
  13168. @samp{mv foo bar >foo} or @samp{rm foo >foo}, even though this is
  13169. perfectly portable among Posix hosts.
  13170. A few ancient systems reserved some file descriptors. By convention,
  13171. file descriptor 3 was opened to @file{/dev/tty} when you logged into
  13172. Eighth Edition (1985) through Tenth Edition Unix (1989). File
  13173. descriptor 4 had a special use on the Stardent/Kubota Titan (circa
  13174. 1990), though we don't now remember what it was. Both these systems are
  13175. obsolete, so it's now safe to treat file descriptors 3 and 4 like any
  13176. other file descriptors.
  13177. On the other hand, you can't portably use multi-digit file descriptors.
  13178. Solaris @command{ksh} doesn't understand any file descriptor larger than
  13179. @samp{9}:
  13180. @example
  13181. $ @kbd{bash -c 'exec 10>&-'; echo $?}
  13182. 0
  13183. $ @kbd{ksh -c 'exec 9>&-'; echo $?}
  13184. 0
  13185. $ @kbd{ksh -c 'exec 10>&-'; echo $?}
  13186. ksh[1]: exec: 10: not found
  13187. 127
  13188. @end example
  13189. @c <http://lists.gnu.org/archive/html/bug-autoconf/2011-09/msg00004.html>
  13190. @node Signal Handling
  13191. @section Signal Handling
  13192. @cindex Signal handling in the shell
  13193. @cindex Signals, shells and
  13194. Portable handling of signals within the shell is another major source of
  13195. headaches. This is worsened by the fact that various different, mutually
  13196. incompatible approaches are possible in this area, each with its
  13197. distinctive merits and demerits. A detailed description of these possible
  13198. approaches, as well as of their pros and cons, can be found in
  13199. @uref{http://www.cons.org/cracauer/sigint.html, this article}.
  13200. Solaris 10 @command{/bin/sh} automatically traps most signals by default;
  13201. @c See: <http://dbaspot.com/shell/396118-bourne-shell-exit-code-term.html>
  13202. the shell still exits with error upon termination by one of those signals,
  13203. but in such a case the exit status might be somewhat unexpected (even if
  13204. allowed by POSIX, strictly speaking):
  13205. @example
  13206. $ @kbd{bash -c 'kill -1 $$'; echo $?} # Will exit 128 + (signal number).
  13207. Hangup
  13208. 129
  13209. $ @kbd{/bin/ksh -c 'kill -15 $$'; echo $?} # Likewise.
  13210. Terminated
  13211. 143
  13212. $ @kbd{for sig in 1 2 3 15; do}
  13213. > @kbd{ echo $sig:}
  13214. > @kbd{ /bin/sh -c "kill -$s \$\$"; echo $?}
  13215. > @kbd{done}
  13216. signal 1:
  13217. Hangup
  13218. 129
  13219. signal 2:
  13220. 208
  13221. signal 3:
  13222. 208
  13223. signal 15:
  13224. 208
  13225. @end example
  13226. This gets even worse if one is using the POSIX `wait' interface to get
  13227. details about the shell process terminations: it will result in the shell
  13228. having exited normally, rather than by receiving a signal.
  13229. @example
  13230. $ @kbd{cat > foo.c <<'END'}
  13231. #include <stdio.h> /* for printf */
  13232. #include <stdlib.h> /* for system */
  13233. #include <sys/wait.h> /* for WIF* macros */
  13234. int main(void)
  13235. @{
  13236. int status = system ("kill -15 $$");
  13237. printf ("Terminated by signal: %s\n",
  13238. WIFSIGNALED (status) ? "yes" : "no");
  13239. printf ("Exited normally: %s\n",
  13240. WIFEXITED (status) ? "yes" : "no");
  13241. return 0;
  13242. @}
  13243. END
  13244. @c $$ font-lock
  13245. $ @kbd{cc -o foo foo.c}
  13246. $ @kbd{./a.out} # On GNU/Linux
  13247. Terminated by signal: no
  13248. Exited normally: yes
  13249. $ @kbd{./a.out} # On Solaris 10
  13250. Terminated by signal: yes
  13251. Exited normally: no
  13252. @end example
  13253. Various shells seem to handle @code{SIGQUIT} specially: they ignore it even
  13254. if it is not blocked, and even if the shell is not running interactively
  13255. (in fact, even if the shell has no attached tty); among these shells
  13256. are at least Bash (from version 2 onwards), Zsh 4.3.12, Solaris 10
  13257. @code{/bin/ksh} and @code{/usr/xpg4/bin/sh}, and AT&T @code{ksh93} (2011).
  13258. Still, @code{SIGQUIT} seems to be trappable quite portably within all
  13259. these shells. OTOH, some other shells doesn't special-case the handling
  13260. of @code{SIGQUIT}; among these shells are at least @code{pdksh} 5.2.14,
  13261. Solaris 10 and NetBSD 5.1 @code{/bin/sh}, and the Almquist Shell 0.5.5.1.
  13262. @c See: <http://mail.opensolaris.org/pipermail/ksh93-integration-discuss/2009-February/004121.html>
  13263. Some shells (especially Korn shells and derivatives) might try to
  13264. propagate to themselves a signal that has killed a child process; this is
  13265. not a bug, but a conscious design choice (although its overall value might
  13266. be debatable). The exact details of how this is attained vary from shell
  13267. to shell. For example, upon running @code{perl -e 'kill 2, $$'}, after
  13268. the perl process has been interrupted AT&T @code{ksh93} (2011) will
  13269. proceed to send itself a @code{SIGINT}, while Solaris 10 @code{/bin/ksh}
  13270. and @code{/usr/xpg4/bin/sh} will proceed to exit with status 130 (i.e.,
  13271. 128 + 2). In any case, if there is an active trap associated with
  13272. @code{SIGINT}, those shells will correctly execute it.
  13273. @c See: <http://www.austingroupbugs.net/view.php?id=51>
  13274. Some Korn shells, when a child process die due receiving a signal with
  13275. signal number @var{n}, can leave in @samp{$?} an exit status of
  13276. 256+@var{n} instead of the more common 128+@var{n}. Observe the
  13277. difference between AT&T @code{ksh93} (2011) and @code{bash} 4.1.5 on
  13278. Debian:
  13279. @example
  13280. $ @kbd{/bin/ksh -c 'sh -c "kill -1 \$\$"; echo $?'}
  13281. /bin/ksh: line 1: 7837: Hangup
  13282. 257
  13283. $ @kbd{/bin/bash -c 'sh -c "kill -1 \$\$"; echo $?'}
  13284. /bin/bash: line 1: 7861 Hangup (sh -c "kill -1 \$\$")
  13285. 129
  13286. @end example
  13287. @noindent
  13288. This @command{ksh} behavior is allowed by POSIX, if implemented with
  13289. due care; see this @uref{http://www.austingroupbugs.net/view.php?id=51,
  13290. Austin Group discussion} for more background. However, if it is not
  13291. implemented with proper care, such a behavior might cause problems
  13292. in some corner cases. To see why, assume we have a ``wrapper'' script
  13293. like this:
  13294. @example
  13295. #!/bin/sh
  13296. # Ignore some signals in the shell only, not in its child processes.
  13297. trap : 1 2 13 15
  13298. wrapped_command "$@@"
  13299. ret=$?
  13300. other_command
  13301. exit $ret
  13302. @end example
  13303. @noindent
  13304. If @command{wrapped_command} is interrupted by a @code{SIGHUP} (which
  13305. has signal number 1), @code{ret} will be set to 257. Unless the
  13306. @command{exit} shell builtin is smart enough to understand that such
  13307. a value can only have originated from a signal, and adjust the final
  13308. wait status of the shell appropriately, the value 257 will just get
  13309. truncated to 1 by the closing @code{exit} call, so that a caller of
  13310. the script will have no way to determine that termination by a signal
  13311. was involved. Observe the different behavior of AT&T @code{ksh93}
  13312. (2011) and @code{bash} 4.1.5 on Debian:
  13313. @example
  13314. $ @kbd{cat foo.sh}
  13315. #!/bin/sh
  13316. sh -c 'kill -1 $$'
  13317. ret=$?
  13318. echo $ret
  13319. exit $ret
  13320. $ @kbd{/bin/ksh foo.sh; echo $?}
  13321. foo.sh: line 2: 12479: Hangup
  13322. 257
  13323. 1
  13324. $ @kbd{/bin/bash foo.sh; echo $?}
  13325. foo.sh: line 2: 12487 Hangup (sh -c 'kill -1 $$')
  13326. 129
  13327. 129
  13328. @end example
  13329. @node File System Conventions
  13330. @section File System Conventions
  13331. @cindex File system conventions
  13332. Autoconf uses shell-script processing extensively, so the file names
  13333. that it processes should not contain characters that are special to the
  13334. shell. Special characters include space, tab, newline, NUL, and
  13335. the following:
  13336. @example
  13337. " # $ & ' ( ) * ; < = > ? [ \ ` |
  13338. @end example
  13339. Also, file names should not begin with @samp{~} or @samp{-}, and should
  13340. contain neither @samp{-} immediately after @samp{/} nor @samp{~}
  13341. immediately after @samp{:}. On Posix-like platforms, directory names
  13342. should not contain @samp{:}, as this runs afoul of @samp{:} used as the
  13343. path separator.
  13344. These restrictions apply not only to the files that you distribute, but
  13345. also to the absolute file names of your source, build, and destination
  13346. directories.
  13347. On some Posix-like platforms, @samp{!} and @samp{^} are special too, so
  13348. they should be avoided.
  13349. Posix lets implementations treat leading @file{//} specially, but
  13350. requires leading @file{///} and beyond to be equivalent to @file{/}.
  13351. Most Unix variants treat @file{//} like @file{/}. However, some treat
  13352. @file{//} as a ``super-root'' that can provide access to files that are
  13353. not otherwise reachable from @file{/}. The super-root tradition began
  13354. with Apollo Domain/OS, which died out long ago, but unfortunately Cygwin
  13355. has revived it.
  13356. While @command{autoconf} and friends are usually run on some Posix
  13357. variety, they can be used on other systems, most notably DOS
  13358. variants. This impacts several assumptions regarding file names.
  13359. @noindent
  13360. For example, the following code:
  13361. @example
  13362. case $foo_dir in
  13363. /*) # Absolute
  13364. ;;
  13365. *)
  13366. foo_dir=$dots$foo_dir ;;
  13367. esac
  13368. @end example
  13369. @noindent
  13370. fails to properly detect absolute file names on those systems, because
  13371. they can use a drivespec, and usually use a backslash as directory
  13372. separator. If you want to be portable to DOS variants (at the
  13373. price of rejecting valid but oddball Posix file names like @file{a:\b}),
  13374. you can check for absolute file names like this:
  13375. @cindex absolute file names, detect
  13376. @example
  13377. case $foo_dir in
  13378. [\\/]* | ?:[\\/]* ) # Absolute
  13379. ;;
  13380. *)
  13381. foo_dir=$dots$foo_dir ;;
  13382. esac
  13383. @end example
  13384. @noindent
  13385. Make sure you quote the brackets if appropriate and keep the backslash as
  13386. first character (@pxref{case, , Limitations of Shell Builtins}).
  13387. Also, because the colon is used as part of a drivespec, these systems don't
  13388. use it as path separator. When creating or accessing paths, you can use the
  13389. @code{PATH_SEPARATOR} output variable instead. @command{configure} sets this
  13390. to the appropriate value for the build system (@samp{:} or @samp{;}) when it
  13391. starts up.
  13392. File names need extra care as well. While DOS variants
  13393. that are Posixy enough to run @command{autoconf} (such as DJGPP)
  13394. are usually able to handle long file names properly, there are still
  13395. limitations that can seriously break packages. Several of these issues
  13396. can be easily detected by the
  13397. @uref{ftp://@/ftp.gnu.org/@/gnu/@/non-gnu/@/doschk/@/doschk-1.1.tar.gz, doschk}
  13398. package.
  13399. A short overview follows; problems are marked with SFN/LFN to
  13400. indicate where they apply: SFN means the issues are only relevant to
  13401. plain DOS, not to DOS under Microsoft Windows
  13402. variants, while LFN identifies problems that exist even under
  13403. Microsoft Windows variants.
  13404. @table @asis
  13405. @item No multiple dots (SFN)
  13406. DOS cannot handle multiple dots in file names. This is an especially
  13407. important thing to remember when building a portable configure script,
  13408. as @command{autoconf} uses a .in suffix for template files.
  13409. This is perfectly OK on Posix variants:
  13410. @example
  13411. AC_CONFIG_HEADERS([config.h])
  13412. AC_CONFIG_FILES([source.c foo.bar])
  13413. AC_OUTPUT
  13414. @end example
  13415. @noindent
  13416. but it causes problems on DOS, as it requires @samp{config.h.in},
  13417. @samp{source.c.in} and @samp{foo.bar.in}. To make your package more portable
  13418. to DOS-based environments, you should use this instead:
  13419. @example
  13420. AC_CONFIG_HEADERS([config.h:config.hin])
  13421. AC_CONFIG_FILES([source.c:source.cin foo.bar:foobar.in])
  13422. AC_OUTPUT
  13423. @end example
  13424. @item No leading dot (SFN)
  13425. DOS cannot handle file names that start with a dot. This is usually
  13426. not important for @command{autoconf}.
  13427. @item Case insensitivity (LFN)
  13428. DOS is case insensitive, so you cannot, for example, have both a
  13429. file called @samp{INSTALL} and a directory called @samp{install}. This
  13430. also affects @command{make}; if there's a file called @samp{INSTALL} in
  13431. the directory, @samp{make install} does nothing (unless the
  13432. @samp{install} target is marked as PHONY).
  13433. @item The 8+3 limit (SFN)
  13434. Because the DOS file system only stores the first 8 characters of
  13435. the file name and the first 3 of the extension, those must be unique.
  13436. That means that @file{foobar-part1.c}, @file{foobar-part2.c} and
  13437. @file{foobar-prettybird.c} all resolve to the same file name
  13438. (@file{FOOBAR-P.C}). The same goes for @file{foo.bar} and
  13439. @file{foo.bartender}.
  13440. The 8+3 limit is not usually a problem under Microsoft Windows, as it
  13441. uses numeric
  13442. tails in the short version of file names to make them unique. However, a
  13443. registry setting can turn this behavior off. While this makes it
  13444. possible to share file trees containing long file names between SFN
  13445. and LFN environments, it also means the above problem applies there
  13446. as well.
  13447. @item Invalid characters (LFN)
  13448. Some characters are invalid in DOS file names, and should therefore
  13449. be avoided. In a LFN environment, these are @samp{/}, @samp{\},
  13450. @samp{?}, @samp{*}, @samp{:}, @samp{<}, @samp{>}, @samp{|} and @samp{"}.
  13451. In a SFN environment, other characters are also invalid. These
  13452. include @samp{+}, @samp{,}, @samp{[} and @samp{]}.
  13453. @item Invalid names (LFN)
  13454. Some DOS file names are reserved, and cause problems if you
  13455. try to use files with those names. These names include @file{CON},
  13456. @file{AUX}, @file{COM1}, @file{COM2}, @file{COM3}, @file{COM4},
  13457. @file{LPT1}, @file{LPT2}, @file{LPT3}, @file{NUL}, and @file{PRN}.
  13458. File names are case insensitive, so even names like
  13459. @file{aux/config.guess} are disallowed.
  13460. @end table
  13461. @node Shell Pattern Matching
  13462. @section Shell Pattern Matching
  13463. @cindex Shell pattern matching
  13464. Nowadays portable patterns can use negated character classes like
  13465. @samp{[!-aeiou]}. The older syntax @samp{[^-aeiou]} is supported by
  13466. some shells but not others; hence portable scripts should never use
  13467. @samp{^} as the first character of a bracket pattern.
  13468. Outside the C locale, patterns like @samp{[a-z]} are problematic since
  13469. they may match characters that are not lower-case letters.
  13470. @node Shell Substitutions
  13471. @section Shell Substitutions
  13472. @cindex Shell substitutions
  13473. Contrary to a persistent urban legend, the Bourne shell does not
  13474. systematically split variables and back-quoted expressions, in particular
  13475. on the right-hand side of assignments and in the argument of @code{case}.
  13476. For instance, the following code:
  13477. @example
  13478. case "$given_srcdir" in
  13479. .) top_srcdir="`echo "$dots" | sed 's|/$||'`" ;;
  13480. *) top_srcdir="$dots$given_srcdir" ;;
  13481. esac
  13482. @end example
  13483. @noindent
  13484. is more readable when written as:
  13485. @example
  13486. case $given_srcdir in
  13487. .) top_srcdir=`echo "$dots" | sed 's|/$||'` ;;
  13488. *) top_srcdir=$dots$given_srcdir ;;
  13489. esac
  13490. @end example
  13491. @noindent
  13492. and in fact it is even @emph{more} portable: in the first case of the
  13493. first attempt, the computation of @code{top_srcdir} is not portable,
  13494. since not all shells properly understand @code{"`@dots{}"@dots{}"@dots{}`"},
  13495. for example Solaris 10 ksh:
  13496. @example
  13497. $ @kbd{foo="`echo " bar" | sed 's, ,,'`"}
  13498. ksh: : cannot execute
  13499. ksh: bar | sed 's, ,,': cannot execute
  13500. @end example
  13501. @noindent
  13502. Posix does not specify behavior for this sequence. On the other hand,
  13503. behavior for @code{"`@dots{}\"@dots{}\"@dots{}`"} is specified by Posix,
  13504. but in practice, not all shells understand it the same way: pdksh 5.2.14
  13505. prints spurious quotes when in Posix mode:
  13506. @example
  13507. $ @kbd{echo "`echo \"hello\"`"}
  13508. hello
  13509. $ @kbd{set -o posix}
  13510. $ @kbd{echo "`echo \"hello\"`"}
  13511. "hello"
  13512. @end example
  13513. @noindent
  13514. There is just no portable way to use double-quoted strings inside
  13515. double-quoted back-quoted expressions (pfew!).
  13516. Bash 4.1 has a bug where quoted empty strings adjacent to unquoted
  13517. parameter expansions are elided during word splitting. Meanwhile, zsh
  13518. does not perform word splitting except when in Bourne compatibility
  13519. mode. In the example below, the correct behavior is to have five
  13520. arguments to the function, and exactly two spaces on either side of the
  13521. middle @samp{-}, since word splitting collapses multiple spaces in
  13522. @samp{$f} but leaves empty arguments intact.
  13523. @example
  13524. $ @kbd{bash -c 'n() @{ echo "$#$@@"; @}; f=" - "; n - ""$f"" -'}
  13525. 3- - -
  13526. $ @kbd{ksh -c 'n() @{ echo "$#$@@"; @}; f=" - "; n - ""$f"" -'}
  13527. 5- - -
  13528. $ @kbd{zsh -c 'n() @{ echo "$#$@@"; @}; f=" - "; n - ""$f"" -'}
  13529. 3- - -
  13530. $ @kbd{zsh -c 'emulate sh;}
  13531. > @kbd{n() @{ echo "$#$@@"; @}; f=" - "; n - ""$f"" -'}
  13532. 5- - -
  13533. @end example
  13534. @noindent
  13535. You can work around this by doing manual word splitting, such as using
  13536. @samp{"$str" $list} rather than @samp{"$str"$list}.
  13537. There are also portability pitfalls with particular expansions:
  13538. @table @code
  13539. @item $@@
  13540. @cindex @code{"$@@"}
  13541. One of the most famous shell-portability issues is related to
  13542. @samp{"$@@"}. When there are no positional arguments, Posix says
  13543. that @samp{"$@@"} is supposed to be equivalent to nothing, but the
  13544. original Unix version 7 Bourne shell treated it as equivalent to
  13545. @samp{""} instead, and this behavior survives in later implementations
  13546. like Digital Unix 5.0.
  13547. The traditional way to work around this portability problem is to use
  13548. @samp{$@{1+"$@@"@}}. Unfortunately this method does not work with
  13549. Zsh (3.x and 4.x), which is used on Mac OS X@. When emulating
  13550. the Bourne shell, Zsh performs word splitting on @samp{$@{1+"$@@"@}}:
  13551. @example
  13552. zsh $ @kbd{emulate sh}
  13553. zsh $ @kbd{for i in "$@@"; do echo $i; done}
  13554. Hello World
  13555. !
  13556. zsh $ @kbd{for i in $@{1+"$@@"@}; do echo $i; done}
  13557. Hello
  13558. World
  13559. !
  13560. @end example
  13561. @noindent
  13562. Zsh handles plain @samp{"$@@"} properly, but we can't use plain
  13563. @samp{"$@@"} because of the portability problems mentioned above.
  13564. One workaround relies on Zsh's ``global aliases'' to convert
  13565. @samp{$@{1+"$@@"@}} into @samp{"$@@"} by itself:
  13566. @example
  13567. test "$@{ZSH_VERSION+set@}" = set && alias -g '$@{1+"$@@"@}'='"$@@"'
  13568. @end example
  13569. Zsh only recognizes this alias when a shell word matches it exactly;
  13570. @samp{"foo"$@{1+"$@@"@}} remains subject to word splitting. Since this
  13571. case always yields at least one shell word, use plain @samp{"$@@"}.
  13572. A more conservative workaround is to avoid @samp{"$@@"} if it is
  13573. possible that there may be no positional arguments. For example,
  13574. instead of:
  13575. @example
  13576. cat conftest.c "$@@"
  13577. @end example
  13578. you can use this instead:
  13579. @example
  13580. case $# in
  13581. 0) cat conftest.c;;
  13582. *) cat conftest.c "$@@";;
  13583. esac
  13584. @end example
  13585. Autoconf macros often use the @command{set} command to update
  13586. @samp{$@@}, so if you are writing shell code intended for
  13587. @command{configure} you should not assume that the value of @samp{$@@}
  13588. persists for any length of time.
  13589. @item $@{10@}
  13590. @cindex positional parameters
  13591. The 10th, 11th, @dots{} positional parameters can be accessed only after
  13592. a @code{shift}. The 7th Edition shell reported an error if given
  13593. @code{$@{10@}}, and
  13594. Solaris 10 @command{/bin/sh} still acts that way:
  13595. @example
  13596. $ @kbd{set 1 2 3 4 5 6 7 8 9 10}
  13597. $ @kbd{echo $@{10@}}
  13598. bad substitution
  13599. @end example
  13600. Conversely, not all shells obey the Posix rule that when braces are
  13601. omitted, multiple digits beyond a @samp{$} imply the single-digit
  13602. positional parameter expansion concatenated with the remaining literal
  13603. digits. To work around the issue, you must use braces.
  13604. @example
  13605. $ @kbd{bash -c 'set a b c d e f g h i j; echo $10 $@{1@}0'}
  13606. a0 a0
  13607. $ @kbd{dash -c 'set a b c d e f g h i j; echo $10 $@{1@}0'}
  13608. j a0
  13609. @end example
  13610. @item $@{@var{var}:-@var{value}@}
  13611. @c Info cannot handle `:' in index entries.
  13612. @ifnotinfo
  13613. @cindex @code{$@{@var{var}:-@var{value}@}}
  13614. @end ifnotinfo
  13615. @cindex @code{$@{@var{var}-@var{value}@}}
  13616. Old BSD shells, including the Ultrix @code{sh}, don't accept the
  13617. colon for any shell substitution, and complain and die.
  13618. Similarly for $@{@var{var}:=@var{value}@}, $@{@var{var}:?@var{value}@}, etc.
  13619. However, all shells that support functions allow the use of colon in
  13620. shell substitution, and since m4sh requires functions, you can portably
  13621. use null variable substitution patterns in configure scripts.
  13622. @item $@{@var{var}+@var{value}@}
  13623. @cindex @code{$@{@var{var}+@var{value}@}}
  13624. When using @samp{$@{@var{var}-@var{value}@}} or
  13625. @samp{$@{@var{var}-@var{value}@}} for providing alternate substitutions,
  13626. @var{value} must either be a single shell word, quoted, or in the
  13627. context of an unquoted here-document. Solaris
  13628. @command{/bin/sh} complains otherwise.
  13629. @example
  13630. $ @kbd{/bin/sh -c 'echo $@{a-b c@}'}
  13631. /bin/sh: bad substitution
  13632. $ @kbd{/bin/sh -c 'echo $@{a-'\''b c'\''@}'}
  13633. b c
  13634. $ @kbd{/bin/sh -c 'echo "$@{a-b c@}"'}
  13635. b c
  13636. $ @kbd{/bin/sh -c 'cat <<EOF
  13637. $@{a-b c@}
  13638. EOF}
  13639. b c
  13640. @end example
  13641. According to Posix, if an expansion occurs inside double quotes, then
  13642. the use of unquoted double quotes within @var{value} is unspecified, and
  13643. any single quotes become literal characters; in that case, escaping must
  13644. be done with backslash. Likewise, the use of unquoted here-documents is
  13645. a case where double quotes have unspecified results:
  13646. @example
  13647. $ @kbd{/bin/sh -c 'echo "$@{a-"b c"@}"'}
  13648. /bin/sh: bad substitution
  13649. $ @kbd{ksh -c 'echo "$@{a-"b c"@}"'}
  13650. b c
  13651. $ @kbd{bash -c 'echo "$@{a-"b c"@}"'}
  13652. b c
  13653. $ @kbd{/bin/sh -c 'a=; echo $@{a+'\''b c'\''@}'}
  13654. b c
  13655. $ @kbd{/bin/sh -c 'a=; echo "$@{a+'\''b c'\''@}"'}
  13656. 'b c'
  13657. $ @kbd{/bin/sh -c 'a=; echo "$@{a+\"b c\"@}"'}
  13658. "b c"
  13659. $ @kbd{/bin/sh -c 'a=; echo "$@{a+b c@}"'}
  13660. b c
  13661. $ @kbd{/bin/sh -c 'cat <<EOF
  13662. $@{a-"b c"@}
  13663. EOF'}
  13664. "b c"
  13665. $ @kbd{/bin/sh -c 'cat <<EOF
  13666. $@{a-'b c'@}
  13667. EOF'}
  13668. 'b c'
  13669. $ @kbd{bash -c 'cat <<EOF
  13670. $@{a-"b c"@}
  13671. EOF'}
  13672. b c
  13673. $ @kbd{bash -c 'cat <<EOF
  13674. $@{a-'b c'@}
  13675. EOF'}
  13676. 'b c'
  13677. @end example
  13678. Perhaps the easiest way to work around quoting issues in a manner
  13679. portable to all shells is to place the results in a temporary variable,
  13680. then use @samp{$t} as the @var{value}, rather than trying to inline
  13681. the expression needing quoting.
  13682. @example
  13683. $ @kbd{/bin/sh -c 't="b c\"'\''@}\\"; echo "$@{a-$t@}"'}
  13684. b c"'@}\
  13685. $ @kbd{ksh -c 't="b c\"'\''@}\\"; echo "$@{a-$t@}"'}
  13686. b c"'@}\
  13687. $ @kbd{bash -c 't="b c\"'\''@}\\"; echo "$@{a-$t@}"'}
  13688. b c"'@}\
  13689. @end example
  13690. @item $@{@var{var}=@var{value}@}
  13691. @cindex @code{$@{@var{var}=@var{value}@}}
  13692. When using @samp{$@{@var{var}=@var{value}@}} to assign a default value
  13693. to @var{var}, remember that even though the assignment to @var{var} does
  13694. not undergo file name expansion, the result of the variable expansion
  13695. does unless the expansion occurred within double quotes. In particular,
  13696. when using @command{:} followed by unquoted variable expansion for the
  13697. side effect of setting a default value, if the final value of
  13698. @samp{$var} contains any globbing characters (either from @var{value} or
  13699. from prior contents), the shell has to spend time performing file name
  13700. expansion and field splitting even though those results will not be
  13701. used. Therefore, it is a good idea to consider double quotes when performing
  13702. default initialization; while remembering how this impacts any quoting
  13703. characters appearing in @var{value}.
  13704. @example
  13705. $ @kbd{time bash -c ': "$@{a=/usr/bin/*@}"; echo "$a"'}
  13706. /usr/bin/*
  13707. real 0m0.005s
  13708. user 0m0.002s
  13709. sys 0m0.003s
  13710. $ @kbd{time bash -c ': $@{a=/usr/bin/*@}; echo "$a"'}
  13711. /usr/bin/*
  13712. real 0m0.039s
  13713. user 0m0.026s
  13714. sys 0m0.009s
  13715. $ @kbd{time bash -c 'a=/usr/bin/*; : $@{a=noglob@}; echo "$a"'}
  13716. /usr/bin/*
  13717. real 0m0.031s
  13718. user 0m0.020s
  13719. sys 0m0.010s
  13720. $ @kbd{time bash -c 'a=/usr/bin/*; : "$@{a=noglob@}"; echo "$a"'}
  13721. /usr/bin/*
  13722. real 0m0.006s
  13723. user 0m0.002s
  13724. sys 0m0.003s
  13725. @end example
  13726. As with @samp{+} and @samp{-}, you must use quotes when using @samp{=}
  13727. if the @var{value} contains more than one shell word; either single
  13728. quotes for just the @var{value}, or double quotes around the entire
  13729. expansion:
  13730. @example
  13731. $ @kbd{: $@{var1='Some words'@}}
  13732. $ @kbd{: "$@{var2=like this@}"}
  13733. $ @kbd{echo $var1 $var2}
  13734. Some words like this
  13735. @end example
  13736. @noindent
  13737. otherwise some shells, such as Solaris @command{/bin/sh} or on Digital
  13738. Unix V 5.0, die because of a ``bad substitution''. Meanwhile, Posix
  13739. requires that with @samp{=}, quote removal happens prior to the
  13740. assignment, and the expansion be the final contents of @var{var} without
  13741. quoting (and thus subject to field splitting), in contrast to the
  13742. behavior with @samp{-} passing the quoting through to the final
  13743. expansion. However, @command{bash} 4.1 does not obey this rule.
  13744. @example
  13745. $ @kbd{ksh -c 'echo $@{var-a\ \ b@}'}
  13746. a b
  13747. $ @kbd{ksh -c 'echo $@{var=a\ \ b@}'}
  13748. a b
  13749. $ @kbd{bash -c 'echo $@{var=a\ \ b@}'}
  13750. a b
  13751. @end example
  13752. Finally, Posix states that when mixing @samp{$@{a=b@}} with regular
  13753. commands, it is unspecified whether the assignments affect the parent
  13754. shell environment. It is best to perform assignments independently from
  13755. commands, to avoid the problems demonstrated in this example:
  13756. @example
  13757. $ @kbd{bash -c 'x= y=$@{x:=b@} sh -c "echo +\$x+\$y+";echo -$x-'}
  13758. +b+b+
  13759. -b-
  13760. $ @kbd{/bin/sh -c 'x= y=$@{x:=b@} sh -c "echo +\$x+\$y+";echo -$x-'}
  13761. ++b+
  13762. --
  13763. $ @kbd{ksh -c 'x= y=$@{x:=b@} sh -c "echo +\$x+\$y+";echo -$x-'}
  13764. +b+b+
  13765. --
  13766. @end example
  13767. @item $@{@var{var}=@var{value}@}
  13768. @cindex @code{$@{@var{var}=@var{literal}@}}
  13769. Solaris @command{/bin/sh} has a frightening bug in its handling of
  13770. literal assignments. Imagine you need set a variable to a string containing
  13771. @samp{@}}. This @samp{@}} character confuses Solaris @command{/bin/sh}
  13772. when the affected variable was already set. This bug can be exercised
  13773. by running:
  13774. @example
  13775. $ @kbd{unset foo}
  13776. $ @kbd{foo=$@{foo='@}'@}}
  13777. $ @kbd{echo $foo}
  13778. @}
  13779. $ @kbd{foo=$@{foo='@}' # no error; this hints to what the bug is}
  13780. $ @kbd{echo $foo}
  13781. @}
  13782. $ @kbd{foo=$@{foo='@}'@}}
  13783. $ @kbd{echo $foo}
  13784. @}@}
  13785. ^ ugh!
  13786. @end example
  13787. It seems that @samp{@}} is interpreted as matching @samp{$@{}, even
  13788. though it is enclosed in single quotes. The problem doesn't happen
  13789. using double quotes, or when using a temporary variable holding the
  13790. problematic string.
  13791. @item $@{@var{var}=@var{expanded-value}@}
  13792. @cindex @code{$@{@var{var}=@var{expanded-value}@}}
  13793. On Ultrix,
  13794. running
  13795. @example
  13796. default="yu,yaa"
  13797. : $@{var="$default"@}
  13798. @end example
  13799. @noindent
  13800. sets @var{var} to @samp{M-yM-uM-,M-yM-aM-a}, i.e., the 8th bit of
  13801. each char is set. You don't observe the phenomenon using a simple
  13802. @samp{echo $var} since apparently the shell resets the 8th bit when it
  13803. expands $var. Here are two means to make this shell confess its sins:
  13804. @example
  13805. $ @kbd{cat -v <<EOF
  13806. $var
  13807. EOF}
  13808. @end example
  13809. @noindent
  13810. and
  13811. @example
  13812. $ @kbd{set | grep '^var=' | cat -v}
  13813. @end example
  13814. One classic incarnation of this bug is:
  13815. @example
  13816. default="a b c"
  13817. : $@{list="$default"@}
  13818. for c in $list; do
  13819. echo $c
  13820. done
  13821. @end example
  13822. @noindent
  13823. You'll get @samp{a b c} on a single line. Why? Because there are no
  13824. spaces in @samp{$list}: there are @samp{M- }, i.e., spaces with the 8th
  13825. bit set, hence no IFS splitting is performed!!!
  13826. One piece of good news is that Ultrix works fine with @samp{:
  13827. $@{list=$default@}}; i.e., if you @emph{don't} quote. The bad news is
  13828. then that QNX 4.25 then sets @var{list} to the @emph{last} item of
  13829. @var{default}!
  13830. The portable way out consists in using a double assignment, to switch
  13831. the 8th bit twice on Ultrix:
  13832. @example
  13833. list=$@{list="$default"@}
  13834. @end example
  13835. @noindent
  13836. @dots{}but beware of the @samp{@}} bug from Solaris (see above). For safety,
  13837. use:
  13838. @example
  13839. test "$@{var+set@}" = set || var=@var{@{value@}}
  13840. @end example
  13841. @item $@{#@var{var}@}
  13842. @itemx $@{@var{var}%@var{word}@}
  13843. @itemx $@{@var{var}%%@var{word}@}
  13844. @itemx $@{@var{var}#@var{word}@}
  13845. @itemx $@{@var{var}##@var{word}@}
  13846. @cindex @code{$@{#@var{var}@}}
  13847. @cindex @code{$@{@var{var}%@var{word}@}}
  13848. @cindex @code{$@{@var{var}%%@var{word}@}}
  13849. @cindex @code{$@{@var{var}#@var{word}@}}
  13850. @cindex @code{$@{@var{var}##@var{word}@}}
  13851. Posix requires support for these usages, but they do not work with many
  13852. traditional shells, e.g., Solaris 10 @command{/bin/sh}.
  13853. Also, @command{pdksh} 5.2.14 mishandles some @var{word} forms. For
  13854. example if @samp{$1} is @samp{a/b} and @samp{$2} is @samp{a}, then
  13855. @samp{$@{1#$2@}} should yield @samp{/b}, but with @command{pdksh} it
  13856. yields the empty string.
  13857. @item `@var{commands}`
  13858. @cindex @code{`@var{commands}`}
  13859. @cindex Command Substitution
  13860. Posix requires shells to trim all trailing newlines from command
  13861. output before substituting it, so assignments like
  13862. @samp{dir=`echo "$file" | tr a A`} do not work as expected if
  13863. @samp{$file} ends in a newline.
  13864. While in general it makes no sense, do not substitute a single builtin
  13865. with side effects, because Ash 0.2, trying to optimize, does not fork a
  13866. subshell to perform the command.
  13867. For instance, if you wanted to check that @command{cd} is silent, do not
  13868. use @samp{test -z "`cd /`"} because the following can happen:
  13869. @example
  13870. $ @kbd{pwd}
  13871. /tmp
  13872. $ @kbd{test -z "`cd /`" && pwd}
  13873. /
  13874. @end example
  13875. @noindent
  13876. The result of @samp{foo=`exit 1`} is left as an exercise to the reader.
  13877. The MSYS shell leaves a stray byte in the expansion of a double-quoted
  13878. command substitution of a native program, if the end of the substitution
  13879. is not aligned with the end of the double quote. This may be worked
  13880. around by inserting another pair of quotes:
  13881. @example
  13882. $ @kbd{echo "`printf 'foo\r\n'` bar" > broken}
  13883. $ @kbd{echo "`printf 'foo\r\n'`"" bar" | cmp - broken}
  13884. - broken differ: char 4, line 1
  13885. @end example
  13886. Upon interrupt or SIGTERM, some shells may abort a command substitution,
  13887. replace it with a null string, and wrongly evaluate the enclosing
  13888. command before entering the trap or ending the script. This can lead to
  13889. spurious errors:
  13890. @example
  13891. $ @kbd{sh -c 'if test `sleep 5; echo hi` = hi; then echo yes; fi'}
  13892. $ @kbd{^C}
  13893. sh: test: hi: unexpected operator/operand
  13894. @end example
  13895. @noindent
  13896. You can avoid this by assigning the command substitution to a temporary
  13897. variable:
  13898. @example
  13899. $ @kbd{sh -c 'res=`sleep 5; echo hi`
  13900. if test "x$res" = xhi; then echo yes; fi'}
  13901. $ @kbd{^C}
  13902. @end example
  13903. @item $(@var{commands})
  13904. @cindex @code{$(@var{commands})}
  13905. This construct is meant to replace @samp{`@var{commands}`},
  13906. and it has most of the problems listed under @code{`@var{commands}`}.
  13907. This construct can be
  13908. nested while this is impossible to do portably with back quotes.
  13909. Unfortunately it is not yet universally supported. Most notably, even recent
  13910. releases of Solaris don't support it:
  13911. @example
  13912. $ @kbd{showrev -c /bin/sh | grep version}
  13913. Command version: SunOS 5.10 Generic 121005-03 Oct 2006
  13914. $ @kbd{echo $(echo blah)}
  13915. syntax error: `(' unexpected
  13916. @end example
  13917. @noindent
  13918. nor does IRIX 6.5's Bourne shell:
  13919. @example
  13920. $ @kbd{uname -a}
  13921. IRIX firebird-image 6.5 07151432 IP22
  13922. $ @kbd{echo $(echo blah)}
  13923. $(echo blah)
  13924. @end example
  13925. If you do use @samp{$(@var{commands})}, make sure that the commands
  13926. do not start with a parenthesis, as that would cause confusion with
  13927. a different notation @samp{$((@var{expression}))} that in modern
  13928. shells is an arithmetic expression not a command. To avoid the
  13929. confusion, insert a space between the two opening parentheses.
  13930. Avoid @var{commands} that contain unbalanced parentheses in
  13931. here-documents, comments, or case statement patterns, as many shells
  13932. mishandle them. For example, Bash 3.1, @samp{ksh88}, @command{pdksh}
  13933. 5.2.14, and Zsh 4.2.6 all mishandle the following valid command:
  13934. @example
  13935. echo $(case x in x) echo hello;; esac)
  13936. @end example
  13937. @item $((@var{expression}))
  13938. @cindex @code{$((@var{expression}))}
  13939. Arithmetic expansion is not portable as some shells (most
  13940. notably Solaris 10 @command{/bin/sh}) don't support it.
  13941. Among shells that do support @samp{$(( ))}, not all of them obey the
  13942. Posix rule that octal and hexadecimal constants must be recognized:
  13943. @example
  13944. $ @kbd{bash -c 'echo $(( 010 + 0x10 ))'}
  13945. 24
  13946. $ @kbd{zsh -c 'echo $(( 010 + 0x10 ))'}
  13947. 26
  13948. $ @kbd{zsh -c 'emulate sh; echo $(( 010 + 0x10 ))'}
  13949. 24
  13950. $ @kbd{pdksh -c 'echo $(( 010 + 0x10 ))'}
  13951. pdksh: 010 + 0x10 : bad number `0x10'
  13952. $ @kbd{pdksh -c 'echo $(( 010 ))'}
  13953. 10
  13954. @end example
  13955. When it is available, using arithmetic expansion provides a noticeable
  13956. speedup in script execution; but testing for support requires
  13957. @command{eval} to avoid syntax errors. The following construct is used
  13958. by @code{AS_VAR_ARITH} to provide arithmetic computation when all
  13959. arguments are provided in decimal and without a leading zero, and all
  13960. operators are properly quoted and appear as distinct arguments:
  13961. @example
  13962. if ( eval 'test $(( 1 + 1 )) = 2' ) 2>/dev/null; then
  13963. eval 'func_arith ()
  13964. @{
  13965. func_arith_result=$(( $* ))
  13966. @}'
  13967. else
  13968. func_arith ()
  13969. @{
  13970. func_arith_result=`expr "$@@"`
  13971. @}
  13972. fi
  13973. func_arith 1 + 1
  13974. foo=$func_arith_result
  13975. @end example
  13976. @item ^
  13977. @cindex @code{^} quoting
  13978. Always quote @samp{^}, otherwise traditional shells such as
  13979. @command{/bin/sh} on Solaris 10 treat this like @samp{|}.
  13980. @end table
  13981. @node Assignments
  13982. @section Assignments
  13983. @cindex Shell assignments
  13984. When setting several variables in a row, be aware that the order of the
  13985. evaluation is undefined. For instance @samp{foo=1 foo=2; echo $foo}
  13986. gives @samp{1} with Solaris @command{/bin/sh}, but @samp{2} with Bash.
  13987. You must use
  13988. @samp{;} to enforce the order: @samp{foo=1; foo=2; echo $foo}.
  13989. Don't rely on the following to find @file{subdir/program}:
  13990. @example
  13991. PATH=subdir$PATH_SEPARATOR$PATH program
  13992. @end example
  13993. @noindent
  13994. as this does not work with Zsh 3.0.6. Use something like this
  13995. instead:
  13996. @example
  13997. (PATH=subdir$PATH_SEPARATOR$PATH; export PATH; exec program)
  13998. @end example
  13999. Don't rely on the exit status of an assignment: Ash 0.2 does not change
  14000. the status and propagates that of the last statement:
  14001. @example
  14002. $ @kbd{false || foo=bar; echo $?}
  14003. 1
  14004. $ @kbd{false || foo=`:`; echo $?}
  14005. 0
  14006. @end example
  14007. @noindent
  14008. and to make things even worse, QNX 4.25 just sets the exit status
  14009. to 0 in any case:
  14010. @example
  14011. $ @kbd{foo=`exit 1`; echo $?}
  14012. 0
  14013. @end example
  14014. To assign default values, follow this algorithm:
  14015. @enumerate
  14016. @item
  14017. If the default value is a literal and does not contain any closing
  14018. brace, use:
  14019. @example
  14020. : "$@{var='my literal'@}"
  14021. @end example
  14022. @item
  14023. If the default value contains no closing brace, has to be expanded, and
  14024. the variable being initialized is not intended to be IFS-split
  14025. (i.e., it's not a list), then use:
  14026. @example
  14027. : $@{var="$default"@}
  14028. @end example
  14029. @item
  14030. If the default value contains no closing brace, has to be expanded, and
  14031. the variable being initialized is intended to be IFS-split (i.e., it's a list),
  14032. then use:
  14033. @example
  14034. var=$@{var="$default"@}
  14035. @end example
  14036. @item
  14037. If the default value contains a closing brace, then use:
  14038. @example
  14039. test "$@{var+set@}" = set || var="has a '@}'"
  14040. @end example
  14041. @end enumerate
  14042. In most cases @samp{var=$@{var="$default"@}} is fine, but in case of
  14043. doubt, just use the last form. @xref{Shell Substitutions}, items
  14044. @samp{$@{@var{var}:-@var{value}@}} and @samp{$@{@var{var}=@var{value}@}}
  14045. for the rationale.
  14046. @node Parentheses
  14047. @section Parentheses in Shell Scripts
  14048. @cindex Shell parentheses
  14049. Beware of two opening parentheses in a row, as many shell
  14050. implementations treat them specially, and Posix says that a portable
  14051. script cannot use @samp{((} outside the @samp{$((} form used for shell
  14052. arithmetic. In traditional shells, @samp{((cat))} behaves like
  14053. @samp{(cat)}; but many shells, including
  14054. Bash and the Korn shell, treat @samp{((cat))} as an arithmetic
  14055. expression equivalent to @samp{let "cat"}, and may or may not report an
  14056. error when they detect that @samp{cat} is not a number. As another
  14057. example, @samp{pdksh} 5.2.14 does not treat the following code
  14058. as a traditional shell would:
  14059. @example
  14060. if ((true) || false); then
  14061. echo ok
  14062. fi
  14063. @end example
  14064. @noindent
  14065. To work around this problem, insert a space between the two opening
  14066. parentheses. There is a similar problem and workaround with
  14067. @samp{$((}; see @ref{Shell Substitutions}.
  14068. @node Slashes
  14069. @section Slashes in Shell Scripts
  14070. @cindex Shell slashes
  14071. Unpatched Tru64 5.1 @command{sh} omits the last slash of command-line
  14072. arguments that contain two trailing slashes:
  14073. @example
  14074. $ @kbd{echo / // /// //// .// //.}
  14075. / / // /// ./ //.
  14076. $ @kbd{x=//}
  14077. $ @kbd{eval "echo \$x"}
  14078. /
  14079. $ @kbd{set -x}
  14080. $ @kbd{echo abc | tr -t ab //}
  14081. + echo abc
  14082. + tr -t ab /
  14083. /bc
  14084. @end example
  14085. Unpatched Tru64 4.0 @command{sh} adds a slash after @samp{"$var"} if the
  14086. variable is empty and the second double-quote is followed by a word that
  14087. begins and ends with slash:
  14088. @example
  14089. $ @kbd{sh -xc 'p=; echo "$p"/ouch/'}
  14090. p=
  14091. + echo //ouch/
  14092. //ouch/
  14093. @end example
  14094. However, our understanding is that patches are available, so perhaps
  14095. it's not worth worrying about working around these horrendous bugs.
  14096. @node Special Shell Variables
  14097. @section Special Shell Variables
  14098. @cindex Shell variables
  14099. @cindex Special shell variables
  14100. Some shell variables should not be used, since they can have a deep
  14101. influence on the behavior of the shell. In order to recover a sane
  14102. behavior from the shell, some variables should be unset; M4sh takes
  14103. care of this and provides fallback values, whenever needed, to cater
  14104. for a very old @file{/bin/sh} that does not support @command{unset}.
  14105. (@pxref{Portable Shell, , Portable Shell Programming}).
  14106. As a general rule, shell variable names containing a lower-case letter
  14107. are safe; you can define and use these variables without worrying about
  14108. their effect on the underlying system, and without worrying about
  14109. whether the shell changes them unexpectedly. (The exception is the
  14110. shell variable @code{status}, as described below.)
  14111. Here is a list of names that are known to cause trouble. This list is
  14112. not exhaustive, but you should be safe if you avoid the name
  14113. @code{status} and names containing only upper-case letters and
  14114. underscores.
  14115. @c Alphabetical order, case insensitive, `A' before `a'.
  14116. @table @code
  14117. @item ?
  14118. Not all shells correctly reset @samp{$?} after conditionals (@pxref{if,
  14119. , Limitations of Shell Builtins}). Not all shells manage @samp{$?}
  14120. correctly in shell functions (@pxref{Shell Functions}) or in traps
  14121. (@pxref{trap, , Limitations of Shell Builtins}). Not all shells reset
  14122. @samp{$?} to zero after an empty command.
  14123. @example
  14124. $ @kbd{bash -c 'false; $empty; echo $?'}
  14125. 0
  14126. $ @kbd{zsh -c 'false; $empty; echo $?'}
  14127. 1
  14128. @end example
  14129. @item _
  14130. @evindex _
  14131. Many shells reserve @samp{$_} for various purposes, e.g., the name of
  14132. the last command executed.
  14133. @item BIN_SH
  14134. @evindex BIN_SH
  14135. In Tru64, if @env{BIN_SH} is set to @code{xpg4}, subsidiary invocations of
  14136. the standard shell conform to Posix.
  14137. @item CDPATH
  14138. @evindex CDPATH
  14139. When this variable is set it specifies a list of directories to search
  14140. when invoking @code{cd} with a relative file name that did not start
  14141. with @samp{./} or @samp{../}. Posix
  14142. 1003.1-2001 says that if a nonempty directory name from @env{CDPATH}
  14143. is used successfully, @code{cd} prints the resulting absolute
  14144. file name. Unfortunately this output can break idioms like
  14145. @samp{abs=`cd src && pwd`} because @code{abs} receives the name twice.
  14146. Also, many shells do not conform to this part of Posix; for
  14147. example, @command{zsh} prints the result only if a directory name
  14148. other than @file{.} was chosen from @env{CDPATH}.
  14149. In practice the shells that have this problem also support
  14150. @command{unset}, so you can work around the problem as follows:
  14151. @example
  14152. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH
  14153. @end example
  14154. You can also avoid output by ensuring that your directory name is
  14155. absolute or anchored at @samp{./}, as in @samp{abs=`cd ./src && pwd`}.
  14156. Configure scripts use M4sh, which automatically unsets @env{CDPATH} if
  14157. possible, so you need not worry about this problem in those scripts.
  14158. @item CLICOLOR_FORCE
  14159. @evindex CLICOLOR_FORCE
  14160. When this variable is set, some implementations of tools like
  14161. @command{ls} attempt to add color to their output via terminal escape
  14162. sequences, even when the output is not directed to a terminal, and can
  14163. thus cause spurious failures in scripts. Configure scripts use M4sh,
  14164. which automatically unsets this variable.
  14165. @item DUALCASE
  14166. @evindex DUALCASE
  14167. In the MKS shell, case statements and file name generation are
  14168. case-insensitive unless @env{DUALCASE} is nonzero.
  14169. Autoconf-generated scripts export this variable when they start up.
  14170. @item ENV
  14171. @itemx MAIL
  14172. @itemx MAILPATH
  14173. @itemx PS1
  14174. @itemx PS2
  14175. @itemx PS4
  14176. @evindex ENV
  14177. @evindex MAIL
  14178. @evindex MAILPATH
  14179. @evindex PS1
  14180. @evindex PS2
  14181. @evindex PS4
  14182. These variables should not matter for shell scripts, since they are
  14183. supposed to affect only interactive shells. However, at least one
  14184. shell (the pre-3.0 UWIN Korn shell) gets confused about
  14185. whether it is interactive, which means that (for example) a @env{PS1}
  14186. with a side effect can unexpectedly modify @samp{$?}. To work around
  14187. this bug, M4sh scripts (including @file{configure} scripts) do something
  14188. like this:
  14189. @example
  14190. (unset ENV) >/dev/null 2>&1 && unset ENV MAIL MAILPATH
  14191. PS1='$ '
  14192. PS2='> '
  14193. PS4='+ '
  14194. @end example
  14195. @noindent
  14196. (actually, there is some complication due to bugs in @command{unset};
  14197. @pxref{unset, , Limitations of Shell Builtins}).
  14198. @item FPATH
  14199. @evindex FPATH
  14200. The Korn shell uses @env{FPATH} to find shell functions, so avoid
  14201. @env{FPATH} in portable scripts. @env{FPATH} is consulted after
  14202. @env{PATH}, but you still need to be wary of tests that use @env{PATH}
  14203. to find whether a command exists, since they might report the wrong
  14204. result if @env{FPATH} is also set.
  14205. @item GREP_OPTIONS
  14206. @evindex GREP_OPTIONS
  14207. When this variable is set, some implementations of @command{grep} honor
  14208. these options, even if the options include direction to enable colored
  14209. output via terminal escape sequences, and the result can cause spurious
  14210. failures when the output is not directed to a terminal. Configure
  14211. scripts use M4sh, which automatically unsets this variable.
  14212. @item IFS
  14213. @evindex IFS
  14214. Long ago, shell scripts inherited @env{IFS} from the environment,
  14215. but this caused many problems so modern shells ignore any environment
  14216. settings for @env{IFS}.
  14217. Don't set the first character of @env{IFS} to backslash. Indeed,
  14218. Bourne shells use the first character (backslash) when joining the
  14219. components in @samp{"$@@"} and some shells then reinterpret (!)@: the
  14220. backslash escapes, so you can end up with backspace and other strange
  14221. characters.
  14222. The proper value for @env{IFS} (in regular code, not when performing
  14223. splits) is @samp{@key{SPC}@key{TAB}@key{RET}}. The first character is
  14224. especially important, as it is used to join the arguments in @samp{$*};
  14225. however, note that traditional shells, but also bash-2.04, fail to adhere
  14226. to this and join with a space anyway.
  14227. M4sh guarantees that @env{IFS} will have the default value at the
  14228. beginning of a script, and many macros within autoconf rely on this
  14229. setting. It is okay to use blocks of shell code that temporarily change
  14230. the value of @env{IFS} in order to split on another character, but
  14231. remember to restore it before expanding further macros.
  14232. Unsetting @code{IFS} instead of resetting it to the default sequence
  14233. is not suggested, since code that tries to save and restore the
  14234. variable's value will incorrectly reset it to an empty value, thus
  14235. disabling field splitting:
  14236. @example
  14237. unset IFS
  14238. # default separators used for field splitting
  14239. save_IFS=$IFS
  14240. IFS=:
  14241. # ...
  14242. IFS=$save_IFS
  14243. # no field splitting performed
  14244. @end example
  14245. @item LANG
  14246. @itemx LC_ALL
  14247. @itemx LC_COLLATE
  14248. @itemx LC_CTYPE
  14249. @itemx LC_MESSAGES
  14250. @itemx LC_MONETARY
  14251. @itemx LC_NUMERIC
  14252. @itemx LC_TIME
  14253. @evindex LANG
  14254. @evindex LC_ALL
  14255. @evindex LC_COLLATE
  14256. @evindex LC_CTYPE
  14257. @evindex LC_MESSAGES
  14258. @evindex LC_MONETARY
  14259. @evindex LC_NUMERIC
  14260. @evindex LC_TIME
  14261. You should set all these variables to @samp{C} because so much
  14262. configuration code assumes the C locale and Posix requires that locale
  14263. environment variables be set to @samp{C} if the C locale is desired;
  14264. @file{configure} scripts and M4sh do that for you.
  14265. Export these variables after setting them.
  14266. @c However, some older, nonstandard
  14267. @c systems (notably SCO) break if locale environment variables
  14268. @c are set to @samp{C}, so when running on these systems
  14269. @c Autoconf-generated scripts unset the variables instead.
  14270. @item LANGUAGE
  14271. @evindex LANGUAGE
  14272. @env{LANGUAGE} is not specified by Posix, but it is a GNU
  14273. extension that overrides @env{LC_ALL} in some cases, so you (or M4sh)
  14274. should set it too.
  14275. @item LC_ADDRESS
  14276. @itemx LC_IDENTIFICATION
  14277. @itemx LC_MEASUREMENT
  14278. @itemx LC_NAME
  14279. @itemx LC_PAPER
  14280. @itemx LC_TELEPHONE
  14281. @evindex LC_ADDRESS
  14282. @evindex LC_IDENTIFICATION
  14283. @evindex LC_MEASUREMENT
  14284. @evindex LC_NAME
  14285. @evindex LC_PAPER
  14286. @evindex LC_TELEPHONE
  14287. These locale environment variables are GNU extensions. They
  14288. are treated like their Posix brethren (@env{LC_COLLATE},
  14289. etc.)@: as described above.
  14290. @item LINENO
  14291. @evindex LINENO
  14292. Most modern shells provide the current line number in @code{LINENO}.
  14293. Its value is the line number of the beginning of the current command.
  14294. M4sh, and hence Autoconf, attempts to execute @command{configure} with
  14295. a shell that supports @code{LINENO}. If no such shell is available, it
  14296. attempts to implement @code{LINENO} with a Sed prepass that replaces each
  14297. instance of the string @code{$LINENO} (not followed by an alphanumeric
  14298. character) with the line's number. In M4sh scripts you should execute
  14299. @code{AS_LINENO_PREPARE} so that these workarounds are included in
  14300. your script; configure scripts do this automatically in @code{AC_INIT}.
  14301. You should not rely on @code{LINENO} within @command{eval} or shell
  14302. functions, as the behavior differs in practice. The presence of a
  14303. quoted newline within simple commands can alter which line number is
  14304. used as the starting point for @code{$LINENO} substitutions within that
  14305. command. Also, the possibility of the Sed prepass means that you should
  14306. not rely on @code{$LINENO} when quoted, when in here-documents, or when
  14307. line continuations are used. Subshells should be OK, though. In the
  14308. following example, lines 1, 9, and 14 are portable, but the other
  14309. instances of @code{$LINENO} do not have deterministic values:
  14310. @example
  14311. @group
  14312. $ @kbd{cat lineno}
  14313. echo 1. $LINENO
  14314. echo "2. $LINENO
  14315. 3. $LINENO"
  14316. cat <<EOF
  14317. 5. $LINENO
  14318. 6. $LINENO
  14319. 7. \$LINENO
  14320. EOF
  14321. ( echo 9. $LINENO )
  14322. eval 'echo 10. $LINENO'
  14323. eval 'echo 11. $LINENO
  14324. echo 12. $LINENO'
  14325. echo 13. '$LINENO'
  14326. echo 14. $LINENO '
  14327. 15.' $LINENO
  14328. f () @{ echo $1 $LINENO;
  14329. echo $1 $LINENO @}
  14330. f 18.
  14331. echo 19. \
  14332. $LINENO
  14333. @end group
  14334. @group
  14335. $ @kbd{bash-3.2 ./lineno}
  14336. 1. 1
  14337. 2. 3
  14338. 3. 3
  14339. 5. 4
  14340. 6. 4
  14341. 7. $LINENO
  14342. 9. 9
  14343. 10. 10
  14344. 11. 12
  14345. 12. 13
  14346. 13. $LINENO
  14347. 14. 14
  14348. 15. 14
  14349. 18. 16
  14350. 18. 17
  14351. 19. 19
  14352. @end group
  14353. @group
  14354. $ @kbd{zsh-4.3.4 ./lineno}
  14355. 1. 1
  14356. 2. 2
  14357. 3. 2
  14358. 5. 4
  14359. 6. 4
  14360. 7. $LINENO
  14361. 9. 9
  14362. 10. 1
  14363. 11. 1
  14364. 12. 2
  14365. 13. $LINENO
  14366. 14. 14
  14367. 15. 14
  14368. 18. 0
  14369. 18. 1
  14370. 19. 19
  14371. @end group
  14372. @group
  14373. $ @kbd{pdksh-5.2.14 ./lineno}
  14374. 1. 1
  14375. 2. 2
  14376. 3. 2
  14377. 5. 4
  14378. 6. 4
  14379. 7. $LINENO
  14380. 9. 9
  14381. 10. 0
  14382. 11. 0
  14383. 12. 0
  14384. 13. $LINENO
  14385. 14. 14
  14386. 15. 14
  14387. 18. 16
  14388. 18. 17
  14389. 19. 19
  14390. @end group
  14391. @group
  14392. $ @kbd{sed '=' <lineno |}
  14393. > @kbd{ sed '}
  14394. > @kbd{ N}
  14395. > @kbd{ s,$,-,}
  14396. > @kbd{ t loop}
  14397. > @kbd{ :loop}
  14398. > @kbd{ s,^\([0-9]*\)\(.*\)[$]LINENO\([^a-zA-Z0-9_]\),\1\2\1\3,}
  14399. > @kbd{ t loop}
  14400. > @kbd{ s,-$,,}
  14401. > @kbd{ s,^[0-9]*\n,,}
  14402. > @kbd{ ' |}
  14403. > @kbd{ sh}
  14404. 1. 1
  14405. 2. 2
  14406. 3. 3
  14407. 5. 5
  14408. 6. 6
  14409. 7. \7
  14410. 9. 9
  14411. 10. 10
  14412. 11. 11
  14413. 12. 12
  14414. 13. 13
  14415. 14. 14
  14416. 15. 15
  14417. 18. 16
  14418. 18. 17
  14419. 19. 20
  14420. @end group
  14421. @end example
  14422. In particular, note that @file{config.status} (and any other subsidiary
  14423. script created by @code{AS_INIT_GENERATED}) might report line numbers
  14424. relative to the parent script as a result of the potential Sed pass.
  14425. @item NULLCMD
  14426. @evindex NULLCMD
  14427. When executing the command @samp{>foo}, @command{zsh} executes
  14428. @samp{$NULLCMD >foo} unless it is operating in Bourne shell
  14429. compatibility mode and the @command{zsh} version is newer
  14430. than 3.1.6-dev-18. If you are using an older @command{zsh}
  14431. and forget to set @env{NULLCMD},
  14432. your script might be suspended waiting for data on its standard input.
  14433. @item options
  14434. @evindex options
  14435. For @command{zsh} 4.3.10, @env{options} is treated as an associative
  14436. array even after @code{emulate sh}, so it should not be used.
  14437. @item PATH_SEPARATOR
  14438. @evindex PATH_SEPARATOR
  14439. On DJGPP systems, the @env{PATH_SEPARATOR} environment
  14440. variable can be set to either @samp{:} or @samp{;} to control the path
  14441. separator Bash uses to set up certain environment variables (such as
  14442. @env{PATH}). You can set this variable to @samp{;} if you want
  14443. @command{configure} to use @samp{;} as a separator; this might be useful
  14444. if you plan to use non-Posix shells to execute files. @xref{File System
  14445. Conventions}, for more information about @code{PATH_SEPARATOR}.
  14446. @item POSIXLY_CORRECT
  14447. @evindex POSIXLY_CORRECT
  14448. In the GNU environment, exporting @env{POSIXLY_CORRECT} with any value
  14449. (even empty) causes programs to try harder to conform to Posix.
  14450. Autoconf does not directly manipulate this variable, but @command{bash}
  14451. ties the shell variable @env{POSIXLY_CORRECT} to whether the script is
  14452. running in Posix mode. Therefore, take care when exporting or unsetting
  14453. this variable, so as not to change whether @command{bash} is in Posix
  14454. mode.
  14455. @example
  14456. $ @kbd{bash --posix -c 'set -o | grep posix}
  14457. > @kbd{unset POSIXLY_CORRECT}
  14458. > @kbd{set -o | grep posix'}
  14459. posix on
  14460. posix off
  14461. @end example
  14462. @item PWD
  14463. @evindex PWD
  14464. Posix 1003.1-2001 requires that @command{cd} and
  14465. @command{pwd} must update the @env{PWD} environment variable to point
  14466. to the logical name of the current directory, but traditional shells
  14467. do not support this. This can cause confusion if one shell instance
  14468. maintains @env{PWD} but a subsidiary and different shell does not know
  14469. about @env{PWD} and executes @command{cd}; in this case @env{PWD}
  14470. points to the wrong directory. Use @samp{`pwd`} rather than
  14471. @samp{$PWD}.
  14472. @item RANDOM
  14473. @evindex RANDOM
  14474. Many shells provide @code{RANDOM}, a variable that returns a different
  14475. integer each time it is used. Most of the time, its value does not
  14476. change when it is not used, but on IRIX 6.5 the value changes all
  14477. the time. This can be observed by using @command{set}. It is common
  14478. practice to use @code{$RANDOM} as part of a file name, but code
  14479. shouldn't rely on @code{$RANDOM} expanding to a nonempty string.
  14480. @item status
  14481. @evindex status
  14482. This variable is an alias to @samp{$?} for @code{zsh} (at least 3.1.6),
  14483. hence read-only. Do not use it.
  14484. @end table
  14485. @node Shell Functions
  14486. @section Shell Functions
  14487. @cindex Shell Functions
  14488. Nowadays, it is difficult to find a shell that does not support
  14489. shell functions at all. However, some differences should be expected.
  14490. When declaring a shell function, you must include whitespace between the
  14491. @samp{)} after the function name and the start of the compound
  14492. expression, to avoid upsetting @command{ksh}. While it is possible to
  14493. use any compound command, most scripts use @samp{@{@dots{}@}}.
  14494. @example
  14495. $ @kbd{/bin/sh -c 'a()@{ echo hi;@}; a'}
  14496. hi
  14497. $ @kbd{ksh -c 'a()@{ echo hi;@}; a'}
  14498. ksh: syntax error at line 1: `@}' unexpected
  14499. $ @kbd{ksh -c 'a() @{ echo hi;@}; a'}
  14500. hi
  14501. @end example
  14502. Inside a shell function, you should not rely on the error status of a
  14503. subshell if the last command of that subshell was @code{exit} or
  14504. @code{trap}, as this triggers bugs in zsh 4.x; while Autoconf tries to
  14505. find a shell that does not exhibit the bug, zsh might be the only shell
  14506. present on the user's machine.
  14507. Likewise, the state of @samp{$?} is not reliable when entering a shell
  14508. function. This has the effect that using a function as the first
  14509. command in a @command{trap} handler can cause problems.
  14510. @example
  14511. $ @kbd{bash -c 'foo() @{ echo $?; @}; trap foo 0; (exit 2); exit 2'; echo $?}
  14512. 2
  14513. 2
  14514. $ @kbd{ash -c 'foo() @{ echo $?; @}; trap foo 0; (exit 2); exit 2'; echo $?}
  14515. 0
  14516. 2
  14517. @end example
  14518. DJGPP bash 2.04 has a bug in that @command{return} from a
  14519. shell function which also used a command substitution causes a
  14520. segmentation fault. To work around the issue, you can use
  14521. @command{return} from a subshell, or @samp{AS_SET_STATUS} as last command
  14522. in the execution flow of the function (@pxref{Common Shell Constructs}).
  14523. Not all shells treat shell functions as simple commands impacted by
  14524. @samp{set -e}, for example with Solaris 10 @command{/bin/sh}:
  14525. @example
  14526. $ @kbd{bash -c 'f() @{ return 1; @}; set -e; f; echo oops'}
  14527. $ @kbd{/bin/sh -c 'f() @{ return 1; @}; set -e; f; echo oops'}
  14528. oops
  14529. @end example
  14530. Shell variables and functions may share the same namespace, for example
  14531. with Solaris 10 @command{/bin/sh}:
  14532. @example
  14533. $ @kbd{f () @{ :; @}; f=; f}
  14534. f: not found
  14535. @end example
  14536. @noindent
  14537. For this reason, Autoconf (actually M4sh, @pxref{Programming in M4sh})
  14538. uses the prefix @samp{as_fn_} for its functions.
  14539. Handling of positional parameters and shell options varies among shells.
  14540. For example, Korn shells reset and restore trace output (@samp{set -x})
  14541. and other options upon function entry and exit. Inside a function,
  14542. IRIX sh sets @samp{$0} to the function name.
  14543. It is not portable to pass temporary environment variables to shell
  14544. functions. Solaris @command{/bin/sh} does not see the variable.
  14545. Meanwhile, not all shells follow the Posix rule that the assignment must
  14546. affect the current environment in the same manner as special built-ins.
  14547. @example
  14548. $ @kbd{/bin/sh -c 'func() @{ echo $a;@}; a=1 func; echo $a'}
  14549. @result{}
  14550. @result{}
  14551. $ @kbd{ash -c 'func() @{ echo $a;@}; a=1 func; echo $a'}
  14552. @result{}1
  14553. @result{}
  14554. $ @kbd{bash -c 'set -o posix; func() @{ echo $a;@}; a=1 func; echo $a'}
  14555. @result{}1
  14556. @result{}1
  14557. @end example
  14558. Some ancient Bourne shell variants with function support did not reset
  14559. @samp{$@var{i}, @var{i} >= 0}, upon function exit, so effectively the
  14560. arguments of the script were lost after the first function invocation.
  14561. It is probably not worth worrying about these shells any more.
  14562. With AIX sh, a @command{trap} on 0 installed in a shell function
  14563. triggers at function exit rather than at script exit. @xref{trap, ,
  14564. Limitations of Shell Builtins}.
  14565. @node Limitations of Builtins
  14566. @section Limitations of Shell Builtins
  14567. @cindex Shell builtins
  14568. @cindex Limitations of shell builtins
  14569. No, no, we are serious: some shells do have limitations! :)
  14570. You should always keep in mind that any builtin or command may support
  14571. options, and therefore differ in behavior with arguments
  14572. starting with a dash. For instance, even the innocent @samp{echo "$word"}
  14573. can give unexpected results when @code{word} starts with a dash. It is
  14574. often possible to avoid this problem using @samp{echo "x$word"}, taking
  14575. the @samp{x} into account later in the pipe. Many of these limitations
  14576. can be worked around using M4sh (@pxref{Programming in M4sh}).
  14577. @c This table includes things like `@command{test} (files)', so we can't
  14578. @c use @table @command.
  14579. @table @asis
  14580. @item @command{.}
  14581. @c --------------
  14582. @prindex @command{.}
  14583. Use @command{.} only with regular files (use @samp{test -f}). Bash
  14584. 2.03, for instance, chokes on @samp{. /dev/null}. Remember that
  14585. @command{.} uses @env{PATH} if its argument contains no slashes. Also,
  14586. some shells, including bash 3.2, implicitly append the current directory
  14587. to this @env{PATH} search, even though Posix forbids it. So if you want
  14588. to use @command{.} on a file @file{foo} in the current directory, you
  14589. must use @samp{. ./foo}.
  14590. Not all shells gracefully handle syntax errors within a sourced file.
  14591. On one extreme, some non-interactive shells abort the entire script. On
  14592. the other, @command{zsh} 4.3.10 has a bug where it fails to react to the
  14593. syntax error.
  14594. @example
  14595. $ @kbd{echo 'fi' > syntax}
  14596. $ @kbd{bash -c '. ./syntax; echo $?'}
  14597. ./syntax: line 1: syntax error near unexpected token `fi'
  14598. ./syntax: line 1: `fi'
  14599. 1
  14600. $ @kbd{ash -c '. ./syntax; echo $?'}
  14601. ./syntax: 1: Syntax error: "fi" unexpected
  14602. $ @kbd{zsh -c '. ./syntax; echo $?'}
  14603. ./syntax:1: parse error near `fi'
  14604. 0
  14605. @end example
  14606. @item @command{!}
  14607. @c --------------
  14608. @prindex @command{!}
  14609. The Unix version 7 shell did not support
  14610. negating the exit status of commands with @command{!}, and this feature
  14611. is still absent from some shells (e.g., Solaris @command{/bin/sh}).
  14612. Other shells, such as FreeBSD @command{/bin/sh} or @command{ash}, have
  14613. bugs when using @command{!}:
  14614. @example
  14615. $ @kbd{sh -c '! : | :'; echo $?}
  14616. 1
  14617. $ @kbd{ash -c '! : | :'; echo $?}
  14618. 0
  14619. $ @kbd{sh -c '! @{ :; @}'; echo $?}
  14620. 1
  14621. $ @kbd{ash -c '! @{ :; @}'; echo $?}
  14622. @{: not found
  14623. Syntax error: "@}" unexpected
  14624. 2
  14625. @end example
  14626. Shell code like this:
  14627. @example
  14628. if ! cmp file1 file2 >/dev/null 2>&1; then
  14629. echo files differ or trouble
  14630. fi
  14631. @end example
  14632. is therefore not portable in practice. Typically it is easy to rewrite
  14633. such code, e.g.:
  14634. @example
  14635. cmp file1 file2 >/dev/null 2>&1 ||
  14636. echo files differ or trouble
  14637. @end example
  14638. More generally, one can always rewrite @samp{! @var{command}} as:
  14639. @example
  14640. if @var{command}; then (exit 1); else :; fi
  14641. @end example
  14642. @item @command{@{...@}}
  14643. @c --------------------
  14644. @prindex @command{@{...@}}
  14645. Bash 3.2 (and earlier versions) sometimes does not properly set
  14646. @samp{$?} when failing to write redirected output of a compound command.
  14647. This problem is most commonly observed with @samp{@{@dots{}@}}; it does
  14648. not occur with @samp{(@dots{})}. For example:
  14649. @example
  14650. $ @kbd{bash -c '@{ echo foo; @} >/bad; echo $?'}
  14651. bash: line 1: /bad: Permission denied
  14652. 0
  14653. $ @kbd{bash -c 'while :; do echo; done >/bad; echo $?'}
  14654. bash: line 1: /bad: Permission denied
  14655. 0
  14656. @end example
  14657. To work around the bug, prepend @samp{:;}:
  14658. @example
  14659. $ @kbd{bash -c ':;@{ echo foo; @} >/bad; echo $?'}
  14660. bash: line 1: /bad: Permission denied
  14661. 1
  14662. @end example
  14663. Posix requires a syntax error if a brace list has no contents. However,
  14664. not all shells obey this rule; and on shells where empty lists are
  14665. permitted, the effect on @samp{$?} is inconsistent. To avoid problems,
  14666. ensure that a brace list is never empty.
  14667. @example
  14668. $ @kbd{bash -c 'false; @{ @}; echo $?' || echo $?}
  14669. bash: line 1: syntax error near unexpected token `@}'
  14670. bash: line 1: `false; @{ @}; echo $?'
  14671. 2
  14672. $ @kbd{zsh -c 'false; @{ @}; echo $?' || echo $?}
  14673. 1
  14674. $ @kbd{pdksh -c 'false; @{ @}; echo $?' || echo $?}
  14675. 0
  14676. @end example
  14677. @item @command{break}
  14678. @c ------------------
  14679. @prindex @command{break}
  14680. The use of @samp{break 2} etc.@: is safe.
  14681. @anchor{case}
  14682. @item @command{case}
  14683. @c -----------------
  14684. @prindex @command{case}
  14685. You don't need to quote the argument; no splitting is performed.
  14686. You don't need the final @samp{;;}, but you should use it.
  14687. Posix requires support for @code{case} patterns with opening
  14688. parentheses like this:
  14689. @example
  14690. case $file_name in
  14691. (*.c) echo "C source code";;
  14692. esac
  14693. @end example
  14694. @noindent
  14695. but the @code{(} in this example is not portable to many Bourne
  14696. shell implementations, which is a pity for those of us using tools that
  14697. rely on balanced parentheses. For instance, with Solaris
  14698. @command{/bin/sh}:
  14699. @example
  14700. $ @kbd{case foo in (foo) echo foo;; esac}
  14701. @error{}syntax error: `(' unexpected
  14702. @end example
  14703. @noindent
  14704. The leading @samp{(} can be omitted safely. Unfortunately, there are
  14705. contexts where unbalanced parentheses cause other problems, such as when
  14706. using a syntax-highlighting editor that searches for the balancing
  14707. counterpart, or more importantly, when using a case statement as an
  14708. underquoted argument to an Autoconf macro. @xref{Balancing
  14709. Parentheses}, for tradeoffs involved in various styles of dealing with
  14710. unbalanced @samp{)}.
  14711. Zsh handles pattern fragments derived from parameter expansions or
  14712. command substitutions as though quoted:
  14713. @example
  14714. $ pat=\?; case aa in ?$pat) echo match;; esac
  14715. $ pat=\?; case a? in ?$pat) echo match;; esac
  14716. match
  14717. @end example
  14718. @noindent
  14719. Because of a bug in its @code{fnmatch}, Bash fails to properly
  14720. handle backslashes in character classes:
  14721. @example
  14722. bash-2.02$ @kbd{case /tmp in [/\\]*) echo OK;; esac}
  14723. bash-2.02$
  14724. @end example
  14725. @noindent
  14726. This is extremely unfortunate, since you are likely to use this code to
  14727. handle Posix or MS-DOS absolute file names. To work around this
  14728. bug, always put the backslash first:
  14729. @example
  14730. bash-2.02$ @kbd{case '\TMP' in [\\/]*) echo OK;; esac}
  14731. OK
  14732. bash-2.02$ @kbd{case /tmp in [\\/]*) echo OK;; esac}
  14733. OK
  14734. @end example
  14735. Many Bourne shells cannot handle closing brackets in character classes
  14736. correctly.
  14737. Some shells also have problems with backslash escaping in case you do not want
  14738. to match the backslash: both a backslash and the escaped character match this
  14739. pattern. To work around this, specify the character class in a variable, so
  14740. that quote removal does not apply afterwards, and the special characters don't
  14741. have to be backslash-escaped:
  14742. @example
  14743. $ @kbd{case '\' in [\<]) echo OK;; esac}
  14744. OK
  14745. $ @kbd{scanset='[<]'; case '\' in $scanset) echo OK;; esac}
  14746. $
  14747. @end example
  14748. Even with this, Solaris @command{ksh} matches a backslash if the set
  14749. contains any
  14750. of the characters @samp{|}, @samp{&}, @samp{(}, or @samp{)}.
  14751. Conversely, Tru64 @command{ksh} (circa 2003) erroneously always matches
  14752. a closing parenthesis if not specified in a character class:
  14753. @example
  14754. $ @kbd{case foo in *\)*) echo fail ;; esac}
  14755. fail
  14756. $ @kbd{case foo in *')'*) echo fail ;; esac}
  14757. fail
  14758. @end example
  14759. Some shells, such as Ash 0.3.8, are confused by an empty
  14760. @code{case}/@code{esac}:
  14761. @example
  14762. ash-0.3.8 $ @kbd{case foo in esac;}
  14763. @error{}Syntax error: ";" unexpected (expecting ")")
  14764. @end example
  14765. Posix requires @command{case} to give an exit status of 0 if no cases
  14766. match. However, @command{/bin/sh} in Solaris 10 does not obey this
  14767. rule. Meanwhile, it is unclear whether a case that matches, but
  14768. contains no statements, must also change the exit status to 0. The M4sh
  14769. macro @code{AS_CASE} works around these inconsistencies.
  14770. @example
  14771. $ @kbd{bash -c 'case `false` in ?) ;; esac; echo $?'}
  14772. 0
  14773. $ @kbd{/bin/sh -c 'case `false` in ?) ;; esac; echo $?'}
  14774. 255
  14775. @end example
  14776. @item @command{cd}
  14777. @c ---------------
  14778. @prindex @command{cd}
  14779. Posix 1003.1-2001 requires that @command{cd} must support
  14780. the @option{-L} (``logical'') and @option{-P} (``physical'') options,
  14781. with @option{-L} being the default. However, traditional shells do
  14782. not support these options, and their @command{cd} command has the
  14783. @option{-P} behavior.
  14784. Portable scripts should assume neither option is supported, and should
  14785. assume neither behavior is the default. This can be a bit tricky,
  14786. since the Posix default behavior means that, for example,
  14787. @samp{ls ..} and @samp{cd ..} may refer to different directories if
  14788. the current logical directory is a symbolic link. It is safe to use
  14789. @code{cd @var{dir}} if @var{dir} contains no @file{..} components.
  14790. Also, Autoconf-generated scripts check for this problem when computing
  14791. variables like @code{ac_top_srcdir} (@pxref{Configuration Actions}),
  14792. so it is safe to @command{cd} to these variables.
  14793. Posix states that behavior is undefined if @command{cd} is given an
  14794. explicit empty argument. Some shells do nothing, some change to the
  14795. first entry in @env{CDPATH}, some change to @env{HOME}, and some exit
  14796. the shell rather than returning an error. Unfortunately, this means
  14797. that if @samp{$var} is empty, then @samp{cd "$var"} is less predictable
  14798. than @samp{cd $var} (at least the latter is well-behaved in all shells
  14799. at changing to @env{HOME}, although this is probably not what you wanted
  14800. in a script). You should check that a directory name was supplied
  14801. before trying to change locations.
  14802. @xref{Special Shell Variables}, for portability problems involving
  14803. @command{cd} and the @env{CDPATH} environment variable.
  14804. Also please see the discussion of the @command{pwd} command.
  14805. @anchor{echo}
  14806. @item @command{echo}
  14807. @c -----------------
  14808. @prindex @command{echo}
  14809. The simple @command{echo} is probably the most surprising source of
  14810. portability troubles. It is not possible to use @samp{echo} portably
  14811. unless both options and escape sequences are omitted. Don't expect any
  14812. option.
  14813. Do not use backslashes in the arguments, as there is no consensus on
  14814. their handling. For @samp{echo '\n' | wc -l}, the @command{sh} of
  14815. Solaris outputs 2, but Bash and Zsh (in @command{sh} emulation mode) output 1.
  14816. The problem is truly @command{echo}: all the shells
  14817. understand @samp{'\n'} as the string composed of a backslash and an
  14818. @samp{n}. Within a command substitution, @samp{echo 'string\c'} will
  14819. mess up the internal state of ksh88 on AIX 6.1 so that it will print
  14820. the first character @samp{s} only, followed by a newline, and then
  14821. entirely drop the output of the next echo in a command substitution.
  14822. Because of these problems, do not pass a string containing arbitrary
  14823. characters to @command{echo}. For example, @samp{echo "$foo"} is safe
  14824. only if you know that @var{foo}'s value cannot contain backslashes and
  14825. cannot start with @samp{-}.
  14826. If this may not be true, @command{printf} is in general safer and
  14827. easier to use than @command{echo} and @command{echo -n}. Thus, scripts
  14828. where portability is not a major concern should use @command{printf
  14829. '%s\n'} whenever @command{echo} could fail, and similarly use
  14830. @command{printf %s} instead of @command{echo -n}. For portable shell
  14831. scripts, instead, it is suggested to use a here-document like this:
  14832. @example
  14833. cat <<EOF
  14834. $foo
  14835. EOF
  14836. @end example
  14837. Alternatively, M4sh provides @code{AS_ECHO} and @code{AS_ECHO_N} macros
  14838. which choose between various portable implementations: @samp{echo}
  14839. or @samp{print} where they work, @command{printf} if it is available,
  14840. or else other creative tricks in order to work around the above problems.
  14841. @item @command{eval}
  14842. @c -----------------
  14843. @prindex @command{eval}
  14844. The @command{eval} command is useful in limited circumstances, e.g.,
  14845. using commands like @samp{eval table_$key=\$value} and @samp{eval
  14846. value=table_$key} to simulate a hash table when the key is known to be
  14847. alphanumeric.
  14848. You should also be wary of common bugs in @command{eval} implementations.
  14849. In some shell implementations (e.g., older @command{ash}, OpenBSD 3.8
  14850. @command{sh}, @command{pdksh} v5.2.14 99/07/13.2, and @command{zsh}
  14851. 4.2.5), the arguments of @samp{eval} are evaluated in a context where
  14852. @samp{$?} is 0, so they exhibit behavior like this:
  14853. @example
  14854. $ @kbd{false; eval 'echo $?'}
  14855. 0
  14856. @end example
  14857. The correct behavior here is to output a nonzero value,
  14858. but portable scripts should not rely on this.
  14859. You should not rely on @code{LINENO} within @command{eval}.
  14860. @xref{Special Shell Variables}.
  14861. Note that, even though these bugs are easily avoided,
  14862. @command{eval} is tricky to use on arbitrary arguments.
  14863. It is obviously unwise to use @samp{eval $cmd} if the string value of
  14864. @samp{cmd} was derived from an untrustworthy source. But even if the
  14865. string value is valid, @samp{eval $cmd} might not work as intended,
  14866. since it causes field splitting and file name expansion to occur twice,
  14867. once for the @command{eval} and once for the command itself. It is
  14868. therefore safer to use @samp{eval "$cmd"}. For example, if @var{cmd}
  14869. has the value @samp{cat test?.c}, @samp{eval $cmd} might expand to the
  14870. equivalent of @samp{cat test;.c} if there happens to be a file named
  14871. @file{test;.c} in the current directory; and this in turn
  14872. mistakenly attempts to invoke @command{cat} on the file @file{test} and
  14873. then execute the command @command{.c}. To avoid this problem, use
  14874. @samp{eval "$cmd"} rather than @samp{eval $cmd}.
  14875. However, suppose that you want to output the text of the evaluated
  14876. command just before executing it. Assuming the previous example,
  14877. @samp{echo "Executing: $cmd"} outputs @samp{Executing: cat test?.c}, but
  14878. this output doesn't show the user that @samp{test;.c} is the actual name
  14879. of the copied file. Conversely, @samp{eval "echo Executing: $cmd"}
  14880. works on this example, but it fails with @samp{cmd='cat foo >bar'},
  14881. since it mistakenly replaces the contents of @file{bar} by the
  14882. string @samp{cat foo}. No simple, general, and portable solution to
  14883. this problem is known.
  14884. @item @command{exec}
  14885. @c -----------------
  14886. @prindex @command{exec}
  14887. Posix describes several categories of shell built-ins. Special
  14888. built-ins (such as @command{exit}) must impact the environment of the
  14889. current shell, and need not be available through @command{exec}. All
  14890. other built-ins are regular, and must not propagate variable assignments
  14891. to the environment of the current shell. However, the group of regular
  14892. built-ins is further distinguished by commands that do not require a
  14893. @env{PATH} search (such as @command{cd}), in contrast to built-ins that
  14894. are offered as a more efficient version of something that must still be
  14895. found in a @env{PATH} search (such as @command{echo}). Posix is not
  14896. clear on whether @command{exec} must work with the list of 17 utilities
  14897. that are invoked without a @env{PATH} search, and many platforms lack an
  14898. executable for some of those built-ins:
  14899. @example
  14900. $ @kbd{sh -c 'exec cd /tmp'}
  14901. sh: line 0: exec: cd: not found
  14902. @end example
  14903. All other built-ins that provide utilities specified by Posix must have
  14904. a counterpart executable that exists on @env{PATH}, although Posix
  14905. allows @command{exec} to use the built-in instead of the executable.
  14906. For example, contrast @command{bash} 3.2 and @command{pdksh} 5.2.14:
  14907. @example
  14908. $ @kbd{bash -c 'pwd --version' | head -n1}
  14909. bash: line 0: pwd: --: invalid option
  14910. pwd: usage: pwd [-LP]
  14911. $ @kbd{bash -c 'exec pwd --version' | head -n1}
  14912. pwd (GNU coreutils) 6.10
  14913. $ @kbd{pdksh -c 'exec pwd --version' | head -n1}
  14914. pdksh: pwd: --: unknown option
  14915. @end example
  14916. When it is desired to avoid a regular shell built-in, the workaround is
  14917. to use some other forwarding command, such as @command{env} or
  14918. @command{nice}, that will ensure a path search:
  14919. @example
  14920. $ @kbd{pdksh -c 'exec true --version' | head -n1}
  14921. $ @kbd{pdksh -c 'nice true --version' | head -n1}
  14922. true (GNU coreutils) 6.10
  14923. $ @kbd{pdksh -c 'env true --version' | head -n1}
  14924. true (GNU coreutils) 6.10
  14925. @end example
  14926. @item @command{exit}
  14927. @c -----------------
  14928. @prindex @command{exit}
  14929. The default value of @command{exit} is supposed to be @code{$?};
  14930. unfortunately, some shells, such as the DJGPP port of Bash 2.04, just
  14931. perform @samp{exit 0}.
  14932. @example
  14933. bash-2.04$ @kbd{foo=`exit 1` || echo fail}
  14934. fail
  14935. bash-2.04$ @kbd{foo=`(exit 1)` || echo fail}
  14936. fail
  14937. bash-2.04$ @kbd{foo=`(exit 1); exit` || echo fail}
  14938. bash-2.04$
  14939. @end example
  14940. Using @samp{exit $?} restores the expected behavior.
  14941. Some shell scripts, such as those generated by @command{autoconf}, use a
  14942. trap to clean up before exiting. If the last shell command exited with
  14943. nonzero status, the trap also exits with nonzero status so that the
  14944. invoker can tell that an error occurred.
  14945. Unfortunately, in some shells, such as Solaris @command{/bin/sh}, an exit
  14946. trap ignores the @code{exit} command's argument. In these shells, a trap
  14947. cannot determine whether it was invoked by plain @code{exit} or by
  14948. @code{exit 1}. Instead of calling @code{exit} directly, use the
  14949. @code{AC_MSG_ERROR} macro that has a workaround for this problem.
  14950. @anchor{export}
  14951. @item @command{export}
  14952. @c -------------------
  14953. @prindex @command{export}
  14954. The builtin @command{export} dubs a shell variable @dfn{environment
  14955. variable}. Each update of exported variables corresponds to an update
  14956. of the environment variables. Conversely, each environment variable
  14957. received by the shell when it is launched should be imported as a shell
  14958. variable marked as exported.
  14959. Alas, many shells, such as Solaris @command{/bin/sh},
  14960. IRIX 6.3, IRIX 5.2,
  14961. AIX 4.1.5, and Digital Unix 4.0, forget to
  14962. @command{export} the environment variables they receive. As a result,
  14963. two variables coexist: the environment variable and the shell
  14964. variable. The following code demonstrates this failure:
  14965. @example
  14966. #!/bin/sh
  14967. echo $FOO
  14968. FOO=bar
  14969. echo $FOO
  14970. exec /bin/sh $0
  14971. @end example
  14972. @noindent
  14973. when run with @samp{FOO=foo} in the environment, these shells print
  14974. alternately @samp{foo} and @samp{bar}, although they should print only
  14975. @samp{foo} and then a sequence of @samp{bar}s.
  14976. Therefore you should @command{export} again each environment variable
  14977. that you update; the export can occur before or after the assignment.
  14978. Posix is not clear on whether the @command{export} of an undefined
  14979. variable causes the variable to be defined with the value of an empty
  14980. string, or merely marks any future definition of a variable by that name
  14981. for export. Various shells behave differently in this regard:
  14982. @example
  14983. $ @kbd{sh -c 'export foo; env | grep foo'}
  14984. $ @kbd{ash -c 'export foo; env | grep foo'}
  14985. foo=
  14986. @end example
  14987. Posix requires @command{export} to honor assignments made as arguments,
  14988. but older shells do not support this, including @command{/bin/sh} in
  14989. Solaris 10. Portable scripts should separate assignments and exports
  14990. into different statements.
  14991. @example
  14992. $ @kbd{bash -c 'export foo=bar; echo $foo'}
  14993. bar
  14994. $ @kbd{/bin/sh -c 'export foo=bar; echo $foo'}
  14995. /bin/sh: foo=bar: is not an identifier
  14996. $ @kbd{/bin/sh -c 'export foo; foo=bar; echo $foo'}
  14997. bar
  14998. @end example
  14999. @item @command{false}
  15000. @c ------------------
  15001. @prindex @command{false}
  15002. Don't expect @command{false} to exit with status 1: in native
  15003. Solaris @file{/bin/false} exits with status 255.
  15004. @item @command{for}
  15005. @c ----------------
  15006. @prindex @command{for}
  15007. To loop over positional arguments, use:
  15008. @example
  15009. for arg
  15010. do
  15011. echo "$arg"
  15012. done
  15013. @end example
  15014. @noindent
  15015. You may @emph{not} leave the @code{do} on the same line as @code{for},
  15016. since some shells improperly grok:
  15017. @example
  15018. for arg; do
  15019. echo "$arg"
  15020. done
  15021. @end example
  15022. If you want to explicitly refer to the positional arguments, given the
  15023. @samp{$@@} bug (@pxref{Shell Substitutions}), use:
  15024. @example
  15025. for arg in $@{1+"$@@"@}; do
  15026. echo "$arg"
  15027. done
  15028. @end example
  15029. @noindent
  15030. But keep in mind that Zsh, even in Bourne shell emulation mode, performs
  15031. word splitting on @samp{$@{1+"$@@"@}}; see @ref{Shell Substitutions},
  15032. item @samp{$@@}, for more.
  15033. In Solaris @command{/bin/sh}, when the list of arguments of a
  15034. @command{for} loop starts with @emph{unquoted} tokens looking like
  15035. variable assignments, the loop is not executed on those tokens:
  15036. @example
  15037. $ @kbd{/bin/sh -c 'for v in a=b c=d x e=f; do echo $v; done'}
  15038. x
  15039. e=f
  15040. @end example
  15041. @noindent
  15042. Thankfully, quoting the assignment-like tokens, or starting the list
  15043. with other tokens (including unquoted variable expansion that results in
  15044. an assignment-like result), avoids the problem, so it is easy to work
  15045. around:
  15046. @example
  15047. $ @kbd{/bin/sh -c 'for v in "a=b"; do echo $v; done'}
  15048. a=b
  15049. $ @kbd{/bin/sh -c 'x=a=b; for v in $x c=d; do echo $v; done'}
  15050. a=b
  15051. c=d
  15052. @end example
  15053. @anchor{if}
  15054. @item @command{if}
  15055. @c ---------------
  15056. @prindex @command{if}
  15057. Using @samp{!} is not portable. Instead of:
  15058. @example
  15059. if ! cmp -s file file.new; then
  15060. mv file.new file
  15061. fi
  15062. @end example
  15063. @noindent
  15064. use:
  15065. @example
  15066. if cmp -s file file.new; then :; else
  15067. mv file.new file
  15068. fi
  15069. @end example
  15070. @noindent
  15071. Or, especially if the @dfn{else} branch is short, you can use @code{||}.
  15072. In M4sh, the @code{AS_IF} macro provides an easy way to write these kinds
  15073. of conditionals:
  15074. @example
  15075. AS_IF([cmp -s file file.new], [], [mv file.new file])
  15076. @end example
  15077. This is especially useful in other M4 macros, where the @dfn{then} and
  15078. @dfn{else} branches might be macro arguments.
  15079. Some very old shells did not reset the exit status from an @command{if}
  15080. with no @command{else}:
  15081. @example
  15082. $ @kbd{if (exit 42); then true; fi; echo $?}
  15083. 42
  15084. @end example
  15085. @noindent
  15086. whereas a proper shell should have printed @samp{0}. But this is no
  15087. longer a portability problem; any shell that supports functions gets it
  15088. correct. However, it explains why some makefiles have lengthy
  15089. constructs:
  15090. @example
  15091. if test -f "$file"; then
  15092. install "$file" "$dest"
  15093. else
  15094. :
  15095. fi
  15096. @end example
  15097. @item @command{printf}
  15098. @c ------------------
  15099. @prindex @command{printf}
  15100. A format string starting with a @samp{-} can cause problems.
  15101. Bash interprets it as an option and
  15102. gives an error. And @samp{--} to mark the end of options is not good
  15103. in the NetBSD Almquist shell (e.g., 0.4.6) which takes that
  15104. literally as the format string. Putting the @samp{-} in a @samp{%c}
  15105. or @samp{%s} is probably easiest:
  15106. @example
  15107. printf %s -foo
  15108. @end example
  15109. Bash 2.03 mishandles an escape sequence that happens to evaluate to @samp{%}:
  15110. @example
  15111. $ @kbd{printf '\045'}
  15112. bash: printf: `%': missing format character
  15113. @end example
  15114. Large outputs may cause trouble. On Solaris 2.5.1 through 10, for
  15115. example, @file{/usr/bin/printf} is buggy, so when using
  15116. @command{/bin/sh} the command @samp{printf %010000x 123} normally dumps
  15117. core.
  15118. Since @command{printf} is not always a shell builtin, there is a
  15119. potential speed penalty for using @code{printf '%s\n'} as a replacement
  15120. for an @command{echo} that does not interpret @samp{\} or leading
  15121. @samp{-}. With Solaris @command{ksh}, it is possible to use @code{print
  15122. -r --} for this role instead.
  15123. @xref{echo, , Limitations of Shell Builtins} for a discussion of
  15124. portable alternatives to both @command{printf} and @command{echo}.
  15125. @item @command{pwd}
  15126. @c ----------------
  15127. @prindex @command{pwd}
  15128. With modern shells, plain @command{pwd} outputs a ``logical''
  15129. directory name, some of whose components may be symbolic links. These
  15130. directory names are in contrast to ``physical'' directory names, whose
  15131. components are all directories.
  15132. Posix 1003.1-2001 requires that @command{pwd} must support
  15133. the @option{-L} (``logical'') and @option{-P} (``physical'') options,
  15134. with @option{-L} being the default. However, traditional shells do
  15135. not support these options, and their @command{pwd} command has the
  15136. @option{-P} behavior.
  15137. Portable scripts should assume neither option is supported, and should
  15138. assume neither behavior is the default. Also, on many hosts
  15139. @samp{/bin/pwd} is equivalent to @samp{pwd -P}, but Posix
  15140. does not require this behavior and portable scripts should not rely on
  15141. it.
  15142. Typically it's best to use plain @command{pwd}. On modern hosts this
  15143. outputs logical directory names, which have the following advantages:
  15144. @itemize @bullet
  15145. @item
  15146. Logical names are what the user specified.
  15147. @item
  15148. Physical names may not be portable from one installation
  15149. host to another due to network file system gymnastics.
  15150. @item
  15151. On modern hosts @samp{pwd -P} may fail due to lack of permissions to
  15152. some parent directory, but plain @command{pwd} cannot fail for this
  15153. reason.
  15154. @end itemize
  15155. Also please see the discussion of the @command{cd} command.
  15156. @item @command{read}
  15157. @c -----------------
  15158. @prindex @command{read}
  15159. No options are portable, not even support @option{-r} (Solaris
  15160. @command{/bin/sh} for example). Tru64/OSF 5.1 @command{sh} treats
  15161. @command{read} as a special built-in, so it may exit if input is
  15162. redirected from a non-existent or unreadable file.
  15163. @anchor{set}
  15164. @item @command{set}
  15165. @c ----------------
  15166. @prindex @command{set}
  15167. With the FreeBSD 6.0 shell, the @command{set} command (without
  15168. any options) does not sort its output.
  15169. The @command{set} builtin faces the usual problem with arguments
  15170. starting with a
  15171. dash. Modern shells such as Bash or Zsh understand @option{--} to specify
  15172. the end of the options (any argument after @option{--} is a parameter,
  15173. even @samp{-x} for instance), but many traditional shells (e.g., Solaris
  15174. 10 @command{/bin/sh}) simply stop option
  15175. processing as soon as a non-option argument is found. Therefore, use
  15176. @samp{dummy} or simply @samp{x} to end the option processing, and use
  15177. @command{shift} to pop it out:
  15178. @example
  15179. set x $my_list; shift
  15180. @end example
  15181. Avoid @samp{set -}, e.g., @samp{set - $my_list}. Posix no
  15182. longer requires support for this command, and in traditional shells
  15183. @samp{set - $my_list} resets the @option{-v} and @option{-x} options, which
  15184. makes scripts harder to debug.
  15185. Some nonstandard shells do not recognize more than one option
  15186. (e.g., @samp{set -e -x} assigns @samp{-x} to the command line). It is
  15187. better to combine them:
  15188. @example
  15189. set -ex
  15190. @end example
  15191. @cindex @command{set -e}
  15192. The option @option{-e} has historically been underspecified, with enough
  15193. ambiguities to cause numerous differences across various shell
  15194. implementations; see for example
  15195. @uref{http://www.in-ulm.de/@/~mascheck/@/various/@/set-e/, this overview},
  15196. or @uref{http://www.austingroupbugs.net/@/view.php?id=52, this link},
  15197. documenting a change to Posix 2008 to match @command{ksh88} behavior.
  15198. Note that mixing @code{set -e} and shell functions is asking for surprises:
  15199. @example
  15200. set -e
  15201. doit()
  15202. @{
  15203. rm file
  15204. echo one
  15205. @}
  15206. doit || echo two
  15207. @end example
  15208. @noindent
  15209. According to the recommendation, @samp{one} should always be output
  15210. regardless of whether the @command{rm} failed, because it occurs within
  15211. the body of the shell function @samp{doit} invoked on the left side of
  15212. @samp{||}, where the effects of @samp{set -e} are not enforced.
  15213. Likewise, @samp{two} should never be printed, since the failure of
  15214. @command{rm} does not abort the function, such that the status of
  15215. @samp{doit} is 0.
  15216. The BSD shell has had several problems with the @option{-e}
  15217. option. Older versions of the BSD
  15218. shell (circa 1990) mishandled @samp{&&}, @samp{||}, @samp{if}, and
  15219. @samp{case} when @option{-e} was in effect, causing the shell to exit
  15220. unexpectedly in some cases. This was particularly a problem with
  15221. makefiles, and led to circumlocutions like @samp{sh -c 'test -f file ||
  15222. touch file'}, where the seemingly-unnecessary @samp{sh -c '@dots{}'}
  15223. wrapper works around the bug (@pxref{Failure in Make Rules}).
  15224. Even relatively-recent versions of the BSD shell (e.g., OpenBSD 3.4)
  15225. wrongly exit with @option{-e} if the last command within a compound
  15226. statement fails and is guarded by an @samp{&&} only. For example:
  15227. @example
  15228. #! /bin/sh
  15229. set -e
  15230. foo=''
  15231. test -n "$foo" && exit 1
  15232. echo one
  15233. if :; then
  15234. test -n "$foo" && exit 1
  15235. echo two
  15236. test -n "$foo" && exit 1
  15237. fi
  15238. echo three
  15239. @end example
  15240. @noindent
  15241. does not print @samp{three}. One workaround is to change the last
  15242. instance of @samp{test -n "$foo" && exit 1} to be @samp{if test -n
  15243. "$foo"; then exit 1; fi} instead. Another possibility is to warn BSD
  15244. users not to use @samp{sh -e}.
  15245. When @samp{set -e} is in effect, a failed command substitution in
  15246. Solaris @command{/bin/sh} cannot be ignored, even with @samp{||}.
  15247. @example
  15248. $ @kbd{/bin/sh -c 'set -e; foo=`false` || echo foo; echo bar'}
  15249. $ @kbd{bash -c 'set -e; foo=`false` || echo foo; echo bar'}
  15250. foo
  15251. bar
  15252. @end example
  15253. @noindent
  15254. Moreover, a command substitution, successful or not, causes this shell to
  15255. exit from a failing outer command even in presence of an @samp{&&} list:
  15256. @example
  15257. $ @kbd{bash -c 'set -e; false `true` && echo notreached; echo ok'}
  15258. ok
  15259. $ @kbd{sh -c 'set -e; false `true` && echo notreached; echo ok'}
  15260. $
  15261. @end example
  15262. Portable scripts should not use @samp{set -e} if @command{trap} is used
  15263. to install an exit handler. This is because Tru64/OSF 5.1 @command{sh}
  15264. sometimes enters the trap handler with the exit status of the command
  15265. prior to the one that triggered the errexit handler:
  15266. @example
  15267. $ @kbd{sh -ec 'trap '\''echo $?'\'' 0; false'}
  15268. 0
  15269. $ @kbd{sh -c 'set -e; trap '\''echo $?'\'' 0; false'}
  15270. 1
  15271. @end example
  15272. @noindent
  15273. Thus, when writing a script in M4sh, rather than trying to rely on
  15274. @samp{set -e}, it is better to append @samp{|| AS_EXIT} to any
  15275. statement where it is desirable to abort on failure.
  15276. @cindex @command{set -b}
  15277. @cindex @command{set -m}
  15278. Job control is not provided by all shells, so the use of @samp{set -m}
  15279. or @samp{set -b} must be done with care. When using @command{zsh} in
  15280. native mode, asynchronous notification (@samp{set -b}) is enabled by
  15281. default, and using @samp{emulate sh} to switch to Posix mode does not
  15282. clear this setting (although asynchronous notification has no impact
  15283. unless job monitoring is also enabled). Also, @command{zsh} 4.3.10 and
  15284. earlier have a bug where job control can be manipulated in interactive
  15285. shells, but not in subshells or scripts. Furthermore, some shells, like
  15286. @command{pdksh}, fail to treat subshells as interactive, even though the
  15287. parent shell was.
  15288. @example
  15289. $ @kbd{echo $ZSH_VERSION}
  15290. 4.3.10
  15291. $ @kbd{set -m; echo $?}
  15292. 0
  15293. $ @kbd{zsh -c 'set -m; echo $?'}
  15294. set: can't change option: -m
  15295. $ @kbd{(set -m); echo $?}
  15296. set: can't change option: -m
  15297. 1
  15298. $ @kbd{pdksh -ci 'echo $-; (echo $-)'}
  15299. cim
  15300. c
  15301. @end example
  15302. @cindex @command{set -n}
  15303. Use of @command{set -n} (typically via @command{sh -n script}) to
  15304. validate a script is not foolproof. Modern @command{ksh93} tries to be
  15305. helpful by informing you about better syntax, but switching the script
  15306. to use the suggested syntax in order to silence the warnings would
  15307. render the script no longer portable to older shells:
  15308. @example
  15309. $ @kbd{ksh -nc '``'}
  15310. ksh: warning: line 1: `...` obsolete, use $(...)
  15311. 0
  15312. @end example
  15313. Furthermore, on ancient hosts, such as SunOS 4, @command{sh -n} could go
  15314. into an infinite loop; even with that bug fixed, Solaris 8
  15315. @command{/bin/sh} takes extremely long to parse large scripts. Autoconf
  15316. itself uses @command{sh -n} within its testsuite to check that correct
  15317. scripts were generated, but only after first probing for other shell
  15318. features (such as @code{test -n "$@{BASH_VERSION+set@}"}) that indicate
  15319. a reasonably fast and working implementation.
  15320. @item @command{shift}
  15321. @c ------------------
  15322. @prindex @command{shift}
  15323. Not only is @command{shift}ing a bad idea when there is nothing left to
  15324. shift, but in addition it is not portable: the shell of MIPS
  15325. RISC/OS 4.52 refuses to do it.
  15326. Don't use @samp{shift 2} etc.; while it in the SVR1 shell (1983),
  15327. it is also absent in many pre-Posix shells.
  15328. @item @command{source}
  15329. @c -------------------
  15330. @prindex @command{source}
  15331. This command is not portable, as Posix does not require it; use
  15332. @command{.} instead.
  15333. @item @command{test}
  15334. @c -----------------
  15335. @prindex @command{test}
  15336. The @code{test} program is the way to perform many file and string
  15337. tests. It is often invoked by the alternate name @samp{[}, but using
  15338. that name in Autoconf code is asking for trouble since it is an M4 quote
  15339. character.
  15340. The @option{-a}, @option{-o}, @samp{(}, and @samp{)} operands are not
  15341. present in all implementations, and have been marked obsolete by Posix
  15342. 2008. This is because there are inherent ambiguities in using them.
  15343. For example, @samp{test "$1" -a "$2"} looks like a binary operator to
  15344. check whether two strings are both non-empty, but if @samp{$1} is the
  15345. literal @samp{!}, then some implementations of @command{test} treat it
  15346. as a negation of the unary operator @option{-a}.
  15347. Thus, portable uses of @command{test} should never have more than four
  15348. arguments, and scripts should use shell constructs like @samp{&&} and
  15349. @samp{||} instead. If you combine @samp{&&} and @samp{||} in the same
  15350. statement, keep in mind that they have equal precedence, so it is often
  15351. better to parenthesize even when this is redundant. For example:
  15352. @smallexample
  15353. # Not portable:
  15354. test "X$a" = "X$b" -a \
  15355. '(' "X$c" != "X$d" -o "X$e" = "X$f" ')'
  15356. # Portable:
  15357. test "X$a" = "X$b" &&
  15358. @{ test "X$c" != "X$d" || test "X$e" = "X$f"; @}
  15359. @end smallexample
  15360. @command{test} does not process options like most other commands do; for
  15361. example, it does not recognize the @option{--} argument as marking the
  15362. end of options.
  15363. It is safe to use @samp{!} as a @command{test} operator. For example,
  15364. @samp{if test ! -d foo; @dots{}} is portable even though @samp{if ! test
  15365. -d foo; @dots{}} is not.
  15366. @item @command{test} (files)
  15367. @c -------------------------
  15368. To enable @command{configure} scripts to support cross-compilation, they
  15369. shouldn't do anything that tests features of the build system instead of
  15370. the host system. But occasionally you may find it necessary to check
  15371. whether some arbitrary file exists. To do so, use @samp{test -f},
  15372. @samp{test -r}, or @samp{test -x}. Do not use @samp{test -e}, because
  15373. Solaris 10 @command{/bin/sh}
  15374. lacks it. To test for symbolic links on systems that have them, use
  15375. @samp{test -h} rather than @samp{test -L}; either form conforms to
  15376. Posix 1003.1-2001, but older shells like Solaris 8
  15377. @code{/bin/sh} support only @option{-h}.
  15378. For historical reasons, Posix reluctantly allows implementations of
  15379. @samp{test -x} that will succeed for the root user, even if no execute
  15380. permissions are present. Furthermore, shells do not all agree on
  15381. whether Access Control Lists should affect @samp{test -r}, @samp{test
  15382. -w}, and @samp{test -x}; some shells base test results strictly on the
  15383. current user id compared to file owner and mode, as if by
  15384. @code{stat(2)}; while other shells base test results on whether the
  15385. current user has the given right, even if that right is only granted by
  15386. an ACL, as if by @code{faccessat(2)}. Furthermore, there is a classic
  15387. time of check to time of use race between any use of @command{test}
  15388. followed by operating on the just-checked file. Therefore, it is a good
  15389. idea to write scripts that actually attempt an operation, and are
  15390. prepared for the resulting failure if permission is denied, rather than
  15391. trying to avoid an operation based solely on whether @command{test}
  15392. guessed that it might not be permitted.
  15393. @item @command{test} (strings)
  15394. @c ---------------------------
  15395. Posix says that @samp{test "@var{string}"} succeeds if @var{string} is
  15396. not null, but this usage is not portable to traditional platforms like
  15397. Solaris 10 @command{/bin/sh}, which mishandle strings like @samp{!} and
  15398. @samp{-n}.
  15399. Posix also says that @samp{test ! "@var{string}"},
  15400. @samp{test -n "@var{string}"} and
  15401. @samp{test -z "@var{string}"} work with any string, but many
  15402. shells (such as Solaris, AIX 3.2, UNICOS 10.0.0.6,
  15403. Digital Unix 4, etc.)@: get confused if
  15404. @var{string} looks like an operator:
  15405. @example
  15406. $ @kbd{test -n =}
  15407. test: argument expected
  15408. $ @kbd{test ! -n}
  15409. test: argument expected
  15410. $ @kbd{test -z ")"; echo $?}
  15411. 0
  15412. @end example
  15413. Similarly, Posix says that both @samp{test "@var{string1}" = "@var{string2"}}
  15414. and @samp{test "@var{string1}" != "@var{string2"}} work for any pairs of
  15415. strings, but in practice this is not true for troublesome strings that
  15416. look like operators or parentheses, or that begin with @samp{-}.
  15417. It is best to protect such strings with a leading @samp{X}, e.g.,
  15418. @samp{test "X@var{string}" != X} rather than @samp{test -n
  15419. "@var{string}"} or @samp{test ! "@var{string}"}.
  15420. It is common to find variations of the following idiom:
  15421. @example
  15422. test -n "`echo $ac_feature | sed 's/[-a-zA-Z0-9_]//g'`" &&
  15423. @var{action}
  15424. @end example
  15425. @noindent
  15426. to take an action when a token matches a given pattern. Such constructs
  15427. should be avoided by using:
  15428. @example
  15429. case $ac_feature in
  15430. *[!-a-zA-Z0-9_]*) @var{action};;
  15431. esac
  15432. @end example
  15433. If the pattern is a complicated regular expression that cannot be
  15434. expressed as a shell pattern, use something like this instead:
  15435. @example
  15436. expr "X$ac_feature" : 'X.*[^-a-zA-Z0-9_]' >/dev/null &&
  15437. @var{action}
  15438. @end example
  15439. @samp{expr "X@var{foo}" : "X@var{bar}"} is more robust than @samp{echo
  15440. "X@var{foo}" | grep "^X@var{bar}"}, because it avoids problems when
  15441. @samp{@var{foo}} contains backslashes.
  15442. @anchor{trap}
  15443. @item @command{trap}
  15444. @c -----------------
  15445. @prindex @command{trap}
  15446. It is safe to trap at least the signals 1, 2, 13, and 15. You can also
  15447. trap 0, i.e., have the @command{trap} run when the script ends (either via an
  15448. explicit @command{exit}, or the end of the script). The trap for 0 should be
  15449. installed outside of a shell function, or AIX 5.3 @command{/bin/sh}
  15450. will invoke the trap at the end of this function.
  15451. Posix says that @samp{trap - 1 2 13 15} resets the traps for the
  15452. specified signals to their default values, but many common shells (e.g.,
  15453. Solaris @command{/bin/sh}) misinterpret this and attempt to execute a
  15454. ``command'' named @command{-} when the specified conditions arise.
  15455. Posix 2008 also added a requirement to support @samp{trap 1 2 13 15} to
  15456. reset traps, as this is supported by a larger set of shells, but there
  15457. are still shells like @command{dash} that mistakenly try to execute
  15458. @command{1} instead of resetting the traps. Therefore, there is no
  15459. portable workaround, except for @samp{trap - 0}, for which
  15460. @samp{trap '' 0} is a portable substitute.
  15461. Although Posix is not absolutely clear on this point, it is widely
  15462. admitted that when entering the trap @samp{$?} should be set to the exit
  15463. status of the last command run before the trap. The ambiguity can be
  15464. summarized as: ``when the trap is launched by an @command{exit}, what is
  15465. the @emph{last} command run: that before @command{exit}, or
  15466. @command{exit} itself?''
  15467. Bash considers @command{exit} to be the last command, while Zsh and
  15468. Solaris @command{/bin/sh} consider that when the trap is run it is
  15469. @emph{still} in the @command{exit}, hence it is the previous exit status
  15470. that the trap receives:
  15471. @example
  15472. $ @kbd{cat trap.sh}
  15473. trap 'echo $?' 0
  15474. (exit 42); exit 0
  15475. $ @kbd{zsh trap.sh}
  15476. 42
  15477. $ @kbd{bash trap.sh}
  15478. 0
  15479. @end example
  15480. The portable solution is then simple: when you want to @samp{exit 42},
  15481. run @samp{(exit 42); exit 42}, the first @command{exit} being used to
  15482. set the exit status to 42 for Zsh, and the second to trigger the trap
  15483. and pass 42 as exit status for Bash. In M4sh, this is covered by using
  15484. @code{AS_EXIT}.
  15485. The shell in FreeBSD 4.0 has the following bug: @samp{$?} is
  15486. reset to 0 by empty lines if the code is inside @command{trap}.
  15487. @example
  15488. $ @kbd{trap 'false}
  15489. echo $?' 0
  15490. $ @kbd{exit}
  15491. 0
  15492. @end example
  15493. @noindent
  15494. Fortunately, this bug only affects @command{trap}.
  15495. Several shells fail to execute an exit trap that is defined inside a
  15496. subshell, when the last command of that subshell is not a builtin. A
  15497. workaround is to use @samp{exit $?} as the shell builtin.
  15498. @example
  15499. $ @kbd{bash -c '(trap "echo hi" 0; /bin/true)'}
  15500. hi
  15501. $ @kbd{/bin/sh -c '(trap "echo hi" 0; /bin/true)'}
  15502. $ @kbd{/bin/sh -c '(trap "echo hi" 0; /bin/true; exit $?)'}
  15503. hi
  15504. @end example
  15505. @noindent
  15506. Likewise, older implementations of @command{bash} failed to preserve
  15507. @samp{$?} across an exit trap consisting of a single cleanup command.
  15508. @example
  15509. $ @kbd{bash -c 'trap "/bin/true" 0; exit 2'; echo $?}
  15510. 2
  15511. $ @kbd{bash-2.05b -c 'trap "/bin/true" 0; exit 2'; echo $?}
  15512. 0
  15513. $ @kbd{bash-2.05b -c 'trap ":; /bin/true" 0; exit 2'; echo $?}
  15514. 2
  15515. @end example
  15516. @item @command{true}
  15517. @c -----------------
  15518. @prindex @command{true}
  15519. @c Info cannot handle `:' in index entries.
  15520. @c @prindex @command{:}
  15521. Don't worry: as far as we know @command{true} is portable.
  15522. Nevertheless, it's not always a builtin (e.g., Bash 1.x), and the
  15523. portable shell community tends to prefer using @command{:}. This has a
  15524. funny side effect: when asked whether @command{false} is more portable
  15525. than @command{true} Alexandre Oliva answered:
  15526. @quotation
  15527. In a sense, yes, because if it doesn't exist, the shell will produce an
  15528. exit status of failure, which is correct for @command{false}, but not
  15529. for @command{true}.
  15530. @end quotation
  15531. Remember that even though @samp{:} ignores its arguments, it still takes
  15532. time to compute those arguments. It is a good idea to use double quotes
  15533. around any arguments to @samp{:} to avoid time spent in field splitting
  15534. and file name expansion.
  15535. @anchor{unset}
  15536. @item @command{unset}
  15537. @c ------------------
  15538. @prindex @command{unset}
  15539. In some nonconforming shells (e.g., Solaris 10 @command{/bin/ksh} and
  15540. @command{/usr/xpg4/bin/sh}, NetBSD 5.99.43 sh, or Bash 2.05a),
  15541. @code{unset FOO} fails when @code{FOO} is not set. This can interfere
  15542. with @code{set -e} operation. You can use
  15543. @smallexample
  15544. FOO=; unset FOO
  15545. @end smallexample
  15546. @noindent
  15547. if you are not sure that @code{FOO} is set.
  15548. A few ancient shells lack @command{unset} entirely. For some variables
  15549. such as @code{PS1}, you can use a neutralizing value instead:
  15550. @smallexample
  15551. PS1='$ '
  15552. @end smallexample
  15553. Usually, shells that do not support @command{unset} need less effort to
  15554. make the environment sane, so for example is not a problem if you cannot
  15555. unset @command{CDPATH} on those shells. However, Bash 2.01 mishandles
  15556. @code{unset MAIL} and @code{unset MAILPATH} in some cases and dumps core.
  15557. So, you should do something like
  15558. @smallexample
  15559. ( (unset MAIL) || exit 1) >/dev/null 2>&1 && unset MAIL || :
  15560. @end smallexample
  15561. @noindent
  15562. @xref{Special Shell Variables}, for some neutralizing values. Also, see
  15563. @ref{export, , Limitations of Builtins}, for
  15564. the case of environment variables.
  15565. @item @command{wait}
  15566. @c -----------------
  15567. @prindex @command{wait}
  15568. The exit status of @command{wait} is not always reliable.
  15569. @end table
  15570. @node Limitations of Usual Tools
  15571. @section Limitations of Usual Tools
  15572. @cindex Limitations of usual tools
  15573. The small set of tools you can expect to find on any machine can still
  15574. include some limitations you should be aware of.
  15575. @comment Between this list and the list of builtins above, we should
  15576. @comment mention all the tools in GNU Coding Standards ``Utilities in
  15577. @comment Makefiles''.
  15578. @c This table includes things like `@command{expr} (|)', so we can't
  15579. @c use @table @command.
  15580. @table @asis
  15581. @anchor{awk}
  15582. @item @command{awk}
  15583. @c ----------------
  15584. @prindex @command{awk}
  15585. Don't leave white space before the opening parenthesis in a user function call.
  15586. Posix does not allow this and GNU Awk rejects it:
  15587. @example
  15588. $ @kbd{gawk 'function die () @{ print "Aaaaarg!" @}
  15589. BEGIN @{ die () @}'}
  15590. gawk: cmd. line:2: BEGIN @{ die () @}
  15591. gawk: cmd. line:2: ^ parse error
  15592. $ @kbd{gawk 'function die () @{ print "Aaaaarg!" @}
  15593. BEGIN @{ die() @}'}
  15594. Aaaaarg!
  15595. @end example
  15596. Posix says that if a program contains only @samp{BEGIN} actions, and
  15597. contains no instances of @code{getline}, then the program merely
  15598. executes the actions without reading input. However, traditional Awk
  15599. implementations (such as Solaris 10 @command{awk}) read and discard
  15600. input in this case. Portable scripts can redirect input from
  15601. @file{/dev/null} to work around the problem. For example:
  15602. @example
  15603. awk 'BEGIN @{print "hello world"@}' </dev/null
  15604. @end example
  15605. Posix says that in an @samp{END} action, @samp{$NF} (and presumably,
  15606. @samp{$1}) retain their value from the last record read, if no
  15607. intervening @samp{getline} occurred. However, some implementations
  15608. (such as Solaris 10 @samp{/usr/bin/awk}, @samp{nawk}, or Darwin
  15609. @samp{awk}) reset these variables. A workaround is to use an
  15610. intermediate variable prior to the @samp{END} block. For example:
  15611. @example
  15612. $ @kbd{cat end.awk}
  15613. @{ tmp = $1 @}
  15614. END @{ print "a", $1, $NF, "b", tmp @}
  15615. $ @kbd{echo 1 | awk -f end.awk}
  15616. a b 1
  15617. $ @kbd{echo 1 | gawk -f end.awk}
  15618. a 1 1 b 1
  15619. @end example
  15620. If you want your program to be deterministic, don't depend on @code{for}
  15621. on arrays:
  15622. @example
  15623. $ @kbd{cat for.awk}
  15624. END @{
  15625. arr["foo"] = 1
  15626. arr["bar"] = 1
  15627. for (i in arr)
  15628. print i
  15629. @}
  15630. $ @kbd{gawk -f for.awk </dev/null}
  15631. foo
  15632. bar
  15633. $ @kbd{nawk -f for.awk </dev/null}
  15634. bar
  15635. foo
  15636. @end example
  15637. Some Awk implementations, such as HP-UX 11.0's native one,
  15638. mishandle anchors:
  15639. @example
  15640. $ @kbd{echo xfoo | $AWK '/foo|^bar/ @{ print @}'}
  15641. $ @kbd{echo bar | $AWK '/foo|^bar/ @{ print @}'}
  15642. bar
  15643. $ @kbd{echo xfoo | $AWK '/^bar|foo/ @{ print @}'}
  15644. xfoo
  15645. $ @kbd{echo bar | $AWK '/^bar|foo/ @{ print @}'}
  15646. bar
  15647. @end example
  15648. @noindent
  15649. Either do not depend on such patterns (i.e., use @samp{/^(.*foo|bar)/},
  15650. or use a simple test to reject such implementations.
  15651. On @samp{ia64-hp-hpux11.23}, Awk mishandles @code{printf} conversions
  15652. after @code{%u}:
  15653. @example
  15654. $ @kbd{awk 'BEGIN @{ printf "%u %d\n", 0, -1 @}'}
  15655. 0 0
  15656. @end example
  15657. AIX version 5.2 has an arbitrary limit of 399 on the
  15658. length of regular expressions and literal strings in an Awk program.
  15659. Traditional Awk implementations derived from Unix version 7, such as
  15660. Solaris @command{/bin/awk}, have many limitations and do not
  15661. conform to Posix. Nowadays @code{AC_PROG_AWK} (@pxref{Particular
  15662. Programs}) finds you an Awk that doesn't have these problems, but if
  15663. for some reason you prefer not to use @code{AC_PROG_AWK} you may need to
  15664. address them. For more detailed descriptions, see @ref{Language
  15665. History, , @command{awk} language history, gawk, GNU Awk User's Guide}.
  15666. Traditional Awk does not support multidimensional arrays or user-defined
  15667. functions.
  15668. Traditional Awk does not support the @option{-v} option. You can use
  15669. assignments after the program instead, e.g., @code{$AWK '@{print v
  15670. $1@}' v=x}; however, don't forget that such assignments are not
  15671. evaluated until they are encountered (e.g., after any @code{BEGIN}
  15672. action).
  15673. Traditional Awk does not support the keywords @code{delete} or @code{do}.
  15674. Traditional Awk does not support the expressions
  15675. @code{@var{a}?@var{b}:@var{c}}, @code{!@var{a}}, @code{@var{a}^@var{b}},
  15676. or @code{@var{a}^=@var{b}}.
  15677. Traditional Awk does not support the predefined @code{CONVFMT} or
  15678. @code{ENVIRON} variables.
  15679. Traditional Awk supports only the predefined functions @code{exp}, @code{index},
  15680. @code{int}, @code{length}, @code{log}, @code{split}, @code{sprintf},
  15681. @code{sqrt}, and @code{substr}.
  15682. Traditional Awk @code{getline} is not at all compatible with Posix;
  15683. avoid it.
  15684. Traditional Awk has @code{for (i in a) @dots{}} but no other uses of the
  15685. @code{in} keyword. For example, it lacks @code{if (i in a) @dots{}}.
  15686. In code portable to both traditional and modern Awk, @code{FS} must be a
  15687. string containing just one ordinary character, and similarly for the
  15688. field-separator argument to @code{split}.
  15689. Traditional Awk has a limit of 99 fields in a record. Since some Awk
  15690. implementations, like Tru64's, split the input even if you don't refer
  15691. to any field in the script, to circumvent this problem, set @samp{FS}
  15692. to an unusual character and use @code{split}.
  15693. Traditional Awk has a limit of at most 99 bytes in a number formatted by
  15694. @code{OFMT}; for example, @code{OFMT="%.300e"; print 0.1;} typically
  15695. dumps core.
  15696. The original version of Awk had a limit of at most 99 bytes per
  15697. @code{split} field, 99 bytes per @code{substr} substring, and 99 bytes
  15698. per run of non-special characters in a @code{printf} format, but these
  15699. bugs have been fixed on all practical hosts that we know of.
  15700. HP-UX 11.00 and IRIX 6.5 Awk require that input files have a line length
  15701. of at most 3070 bytes.
  15702. @item @command{basename}
  15703. @c ---------------------
  15704. @prindex @command{basename}
  15705. Not all hosts have a working @command{basename}.
  15706. You can use @command{expr} instead.
  15707. @c AS_BASENAME is to be replaced by a better API.
  15708. @ignore
  15709. Not all hosts have a working @command{basename}, and you should instead
  15710. use @code{AS_BASENAME} (@pxref{Programming in M4sh}), followed by
  15711. @command{expr} if you need to strip a suffix. For example:
  15712. @example
  15713. a=`basename "$aname"` # This is not portable.
  15714. a=`AS_BASENAME(["$aname"])` # This is more portable.
  15715. # This is not portable.
  15716. c=`basename "$cname" .c`
  15717. # This is more portable.
  15718. c=`AS_BASENAME(["$cname"])`
  15719. case $c in
  15720. ?*.c) c=`expr "X$c" : 'X\(.*\)\.c'`;;
  15721. esac
  15722. @end example
  15723. @end ignore
  15724. @item @command{cat}
  15725. @c ----------------
  15726. @prindex @command{cat}
  15727. Don't rely on any option.
  15728. @item @command{cc}
  15729. @c ---------------
  15730. @prindex @command{cc}
  15731. The command @samp{cc -c foo.c} traditionally produces an object file
  15732. named @file{foo.o}. Most compilers allow @option{-c} to be combined
  15733. with @option{-o} to specify a different object file name, but
  15734. Posix does not require this combination and a few compilers
  15735. lack support for it. @xref{C Compiler}, for how GNU Make
  15736. tests for this feature with @code{AC_PROG_CC_C_O}.
  15737. When a compilation such as @samp{cc -o foo foo.c} fails, some compilers
  15738. (such as CDS on Reliant Unix) leave a @file{foo.o}.
  15739. HP-UX @command{cc} doesn't accept @file{.S} files to preprocess and
  15740. assemble. @samp{cc -c foo.S} appears to succeed, but in fact does
  15741. nothing.
  15742. The default executable, produced by @samp{cc foo.c}, can be
  15743. @itemize
  15744. @item @file{a.out} --- usual Posix convention.
  15745. @item @file{b.out} --- i960 compilers (including @command{gcc}).
  15746. @item @file{a.exe} --- DJGPP port of @command{gcc}.
  15747. @item @file{a_out.exe} --- GNV @command{cc} wrapper for DEC C on OpenVMS.
  15748. @item @file{foo.exe} --- various MS-DOS compilers.
  15749. @end itemize
  15750. The C compiler's traditional name is @command{cc}, but other names like
  15751. @command{gcc} are common. Posix 1003.1-2001 specifies the
  15752. name @command{c99}, but older Posix editions specified
  15753. @command{c89} and anyway these standard names are rarely used in
  15754. practice. Typically the C compiler is invoked from makefiles that use
  15755. @samp{$(CC)}, so the value of the @samp{CC} make variable selects the
  15756. compiler name.
  15757. @item @command{chgrp}
  15758. @itemx @command{chown}
  15759. @c -------------------
  15760. @prindex @command{chgrp}
  15761. @prindex @command{chown}
  15762. It is not portable to change a file's group to a group that the owner
  15763. does not belong to.
  15764. @item @command{chmod}
  15765. @c ------------------
  15766. @prindex @command{chmod}
  15767. Avoid usages like @samp{chmod -w file}; use @samp{chmod a-w file}
  15768. instead, for two reasons. First, plain @option{-w} does not necessarily
  15769. make the file unwritable, since it does not affect mode bits that
  15770. correspond to bits in the file mode creation mask. Second,
  15771. Posix says that the @option{-w} might be interpreted as an
  15772. implementation-specific option, not as a mode; Posix suggests
  15773. using @samp{chmod -- -w file} to avoid this confusion, but unfortunately
  15774. @samp{--} does not work on some older hosts.
  15775. @item @command{cmp}
  15776. @c ----------------
  15777. @prindex @command{cmp}
  15778. @command{cmp} performs a raw data comparison of two files, while
  15779. @command{diff} compares two text files. Therefore, if you might compare
  15780. DOS files, even if only checking whether two files are different, use
  15781. @command{diff} to avoid spurious differences due to differences of
  15782. newline encoding.
  15783. @item @command{cp}
  15784. @c ---------------
  15785. @prindex @command{cp}
  15786. Avoid the @option{-r} option, since Posix 1003.1-2004 marks it as
  15787. obsolescent and its behavior on special files is implementation-defined.
  15788. Use @option{-R} instead. On GNU hosts the two options
  15789. are equivalent, but on Solaris hosts (for example) @code{cp -r}
  15790. reads from pipes instead of replicating them. AIX 5.3 @code{cp -R} may
  15791. corrupt its own memory with some directory hierarchies and error out or
  15792. dump core:
  15793. @example
  15794. @kbd{mkdir -p 12345678/12345678/12345678/12345678}
  15795. @kbd{touch 12345678/12345678/x}
  15796. @kbd{cp -R 12345678 t}
  15797. cp: 0653-440 12345678/12345678/: name too long.
  15798. @end example
  15799. Some @command{cp} implementations (e.g., BSD/OS 4.2) do not allow
  15800. trailing slashes at the end of nonexistent destination directories. To
  15801. avoid this problem, omit the trailing slashes. For example, use
  15802. @samp{cp -R source /tmp/newdir} rather than @samp{cp -R source
  15803. /tmp/newdir/} if @file{/tmp/newdir} does not exist.
  15804. @c This is thanks to Ian.
  15805. The ancient SunOS 4 @command{cp} does not support @option{-f}, although
  15806. its @command{mv} does.
  15807. @cindex timestamp resolution
  15808. Traditionally, file timestamps had 1-second resolution, and @samp{cp
  15809. -p} copied the timestamps exactly. However, many modern file systems
  15810. have timestamps with 1-nanosecond resolution. Unfortunately, some older
  15811. @samp{cp -p} implementations truncate timestamps when copying files,
  15812. which can cause the destination file to appear to be older than the
  15813. source. The exact amount of truncation depends on the resolution of
  15814. the system calls that @command{cp} uses. Traditionally this was
  15815. @code{utime}, which has 1-second resolution. Less-ancient @command{cp}
  15816. implementations such as GNU Core Utilities 5.0.91 (2003) use
  15817. @code{utimes}, which has 1-microsecond resolution. Modern
  15818. implementations such as GNU Core Utilities 6.12 (2008) can set timestamps to
  15819. the full nanosecond resolution, using the modern system calls
  15820. @code{futimens} and @code{utimensat} when they are available. As of
  15821. 2011, though, many platforms do not yet fully support these new system
  15822. calls.
  15823. Bob Proulx notes that @samp{cp -p} always @emph{tries} to copy
  15824. ownerships. But whether it actually does copy ownerships or not is a
  15825. system dependent policy decision implemented by the kernel. If the
  15826. kernel allows it then it happens. If the kernel does not allow it then
  15827. it does not happen. It is not something @command{cp} itself has control
  15828. over.
  15829. In Unix System V any user can chown files to any other user, and System
  15830. V also has a non-sticky @file{/tmp}. That probably derives from the
  15831. heritage of System V in a business environment without hostile users.
  15832. BSD changed this
  15833. to be a more secure model where only root can @command{chown} files and
  15834. a sticky @file{/tmp} is used. That undoubtedly derives from the heritage
  15835. of BSD in a campus environment.
  15836. GNU/Linux and Solaris by default follow BSD, but
  15837. can be configured to allow a System V style @command{chown}. On the
  15838. other hand, HP-UX follows System V, but can
  15839. be configured to use the modern security model and disallow
  15840. @command{chown}. Since it is an administrator-configurable parameter
  15841. you can't use the name of the kernel as an indicator of the behavior.
  15842. @item @command{date}
  15843. @c -----------------
  15844. @prindex @command{date}
  15845. Some versions of @command{date} do not recognize special @samp{%} directives,
  15846. and unfortunately, instead of complaining, they just pass them through,
  15847. and exit with success:
  15848. @example
  15849. $ @kbd{uname -a}
  15850. OSF1 medusa.sis.pasteur.fr V5.1 732 alpha
  15851. $ @kbd{date "+%s"}
  15852. %s
  15853. @end example
  15854. @item @command{diff}
  15855. @c -----------------
  15856. @prindex @command{diff}
  15857. Option @option{-u} is nonportable.
  15858. Some implementations, such as Tru64's, fail when comparing to
  15859. @file{/dev/null}. Use an empty file instead.
  15860. @item @command{dirname}
  15861. @c --------------------
  15862. @prindex @command{dirname}
  15863. Not all hosts have a working @command{dirname}, and you should instead
  15864. use @code{AS_DIRNAME} (@pxref{Programming in M4sh}). For example:
  15865. @example
  15866. dir=`dirname "$file"` # This is not portable.
  15867. dir=`AS_DIRNAME(["$file"])` # This is more portable.
  15868. @end example
  15869. @item @command{egrep}
  15870. @c ------------------
  15871. @prindex @command{egrep}
  15872. Posix 1003.1-2001 no longer requires @command{egrep},
  15873. but many hosts do not yet support the Posix
  15874. replacement @code{grep -E}. Also, some traditional implementations do
  15875. not work on long input lines. To work around these problems, invoke
  15876. @code{AC_PROG_EGREP} and then use @code{$EGREP}.
  15877. Portable extended regular expressions should use @samp{\} only to escape
  15878. characters in the string @samp{$()*+.?[\^@{|}. For example, @samp{\@}}
  15879. is not portable, even though it typically matches @samp{@}}.
  15880. The empty alternative is not portable. Use @samp{?} instead. For
  15881. instance with Digital Unix v5.0:
  15882. @example
  15883. > printf "foo\n|foo\n" | $EGREP '^(|foo|bar)$'
  15884. |foo
  15885. > printf "bar\nbar|\n" | $EGREP '^(foo|bar|)$'
  15886. bar|
  15887. > printf "foo\nfoo|\n|bar\nbar\n" | $EGREP '^(foo||bar)$'
  15888. foo
  15889. |bar
  15890. @end example
  15891. @command{$EGREP} also suffers the limitations of @command{grep}
  15892. (@pxref{grep, , Limitations of Usual Tools}).
  15893. @item @command{expr}
  15894. @c -----------------
  15895. @prindex @command{expr}
  15896. Not all implementations obey the Posix rule that @samp{--} separates
  15897. options from arguments; likewise, not all implementations provide the
  15898. extension to Posix that the first argument can be treated as part of a
  15899. valid expression rather than an invalid option if it begins with
  15900. @samp{-}. When performing arithmetic, use @samp{expr 0 + $var} if
  15901. @samp{$var} might be a negative number, to keep @command{expr} from
  15902. interpreting it as an option.
  15903. No @command{expr} keyword starts with @samp{X}, so use @samp{expr
  15904. X"@var{word}" : 'X@var{regex}'} to keep @command{expr} from
  15905. misinterpreting @var{word}.
  15906. Don't use @code{length}, @code{substr}, @code{match} and @code{index}.
  15907. @item @command{expr} (@samp{|})
  15908. @prindex @command{expr} (@samp{|})
  15909. You can use @samp{|}. Although Posix does require that @samp{expr
  15910. ''} return the empty string, it does not specify the result when you
  15911. @samp{|} together the empty string (or zero) with the empty string. For
  15912. example:
  15913. @example
  15914. expr '' \| ''
  15915. @end example
  15916. Posix 1003.2-1992 returns the empty string
  15917. for this case, but traditional Unix returns @samp{0} (Solaris is
  15918. one such example). In Posix 1003.1-2001, the specification was
  15919. changed to match traditional Unix's behavior (which is
  15920. bizarre, but it's too late to fix this). Please note that the same
  15921. problem does arise when the empty string results from a computation,
  15922. as in:
  15923. @example
  15924. expr bar : foo \| foo : bar
  15925. @end example
  15926. @noindent
  15927. Avoid this portability problem by avoiding the empty string.
  15928. @item @command{expr} (@samp{:})
  15929. @c ----------------------------
  15930. @prindex @command{expr}
  15931. Portable @command{expr} regular expressions should use @samp{\} to
  15932. escape only characters in the string @samp{$()*.0123456789[\^n@{@}}.
  15933. For example, alternation, @samp{\|}, is common but Posix does not
  15934. require its support, so it should be avoided in portable scripts.
  15935. Similarly, @samp{\+} and @samp{\?} should be avoided.
  15936. Portable @command{expr} regular expressions should not begin with
  15937. @samp{^}. Patterns are automatically anchored so leading @samp{^} is
  15938. not needed anyway.
  15939. On the other hand, the behavior of the @samp{$} anchor is not portable
  15940. on multi-line strings. Posix is ambiguous whether the anchor applies to
  15941. each line, as was done in older versions of the GNU Core Utilities, or
  15942. whether it applies only to the end of the overall string, as in
  15943. Coreutils 6.0 and most other implementations.
  15944. @example
  15945. $ @kbd{baz='foo}
  15946. > @kbd{bar'}
  15947. $ @kbd{expr "X$baz" : 'X\(foo\)$'}
  15948. $ @kbd{expr-5.97 "X$baz" : 'X\(foo\)$'}
  15949. foo
  15950. @end example
  15951. The Posix standard is ambiguous as to whether
  15952. @samp{expr 'a' : '\(b\)'} outputs @samp{0} or the empty string.
  15953. In practice, it outputs the empty string on most platforms, but portable
  15954. scripts should not assume this. For instance, the QNX 4.25 native
  15955. @command{expr} returns @samp{0}.
  15956. One might think that a way to get a uniform behavior would be to use
  15957. the empty string as a default value:
  15958. @example
  15959. expr a : '\(b\)' \| ''
  15960. @end example
  15961. @noindent
  15962. Unfortunately this behaves exactly as the original expression; see the
  15963. @command{expr} (@samp{|}) entry for more information.
  15964. Some ancient @command{expr} implementations (e.g., SunOS 4 @command{expr} and
  15965. Solaris 8 @command{/usr/ucb/expr}) have a silly length limit that causes
  15966. @command{expr} to fail if the matched substring is longer than 120
  15967. bytes. In this case, you might want to fall back on @samp{echo|sed} if
  15968. @command{expr} fails. Nowadays this is of practical importance only for
  15969. the rare installer who mistakenly puts @file{/usr/ucb} before
  15970. @file{/usr/bin} in @env{PATH}.
  15971. On Mac OS X 10.4, @command{expr} mishandles the pattern @samp{[^-]} in
  15972. some cases. For example, the command
  15973. @example
  15974. expr Xpowerpc-apple-darwin8.1.0 : 'X[^-]*-[^-]*-\(.*\)'
  15975. @end example
  15976. @noindent
  15977. outputs @samp{apple-darwin8.1.0} rather than the correct @samp{darwin8.1.0}.
  15978. This particular case can be worked around by substituting @samp{[^--]}
  15979. for @samp{[^-]}.
  15980. Don't leave, there is some more!
  15981. The QNX 4.25 @command{expr}, in addition of preferring @samp{0} to
  15982. the empty string, has a funny behavior in its exit status: it's always 1
  15983. when parentheses are used!
  15984. @example
  15985. $ @kbd{val=`expr 'a' : 'a'`; echo "$?: $val"}
  15986. 0: 1
  15987. $ @kbd{val=`expr 'a' : 'b'`; echo "$?: $val"}
  15988. 1: 0
  15989. $ @kbd{val=`expr 'a' : '\(a\)'`; echo "?: $val"}
  15990. 1: a
  15991. $ @kbd{val=`expr 'a' : '\(b\)'`; echo "?: $val"}
  15992. 1: 0
  15993. @end example
  15994. @noindent
  15995. In practice this can be a big problem if you are ready to catch failures
  15996. of @command{expr} programs with some other method (such as using
  15997. @command{sed}), since you may get twice the result. For instance
  15998. @example
  15999. $ @kbd{expr 'a' : '\(a\)' || echo 'a' | sed 's/^\(a\)$/\1/'}
  16000. @end example
  16001. @noindent
  16002. outputs @samp{a} on most hosts, but @samp{aa} on QNX 4.25. A
  16003. simple workaround consists of testing @command{expr} and using a variable
  16004. set to @command{expr} or to @command{false} according to the result.
  16005. Tru64 @command{expr} incorrectly treats the result as a number, if it
  16006. can be interpreted that way:
  16007. @example
  16008. $ @kbd{expr 00001 : '.*\(...\)'}
  16009. 1
  16010. @end example
  16011. On HP-UX 11, @command{expr} only supports a single
  16012. sub-expression.
  16013. @example
  16014. $ @kbd{expr 'Xfoo' : 'X\(f\(oo\)*\)$'}
  16015. expr: More than one '\(' was used.
  16016. @end example
  16017. @item @command{fgrep}
  16018. @c ------------------
  16019. @prindex @command{fgrep}
  16020. Posix 1003.1-2001 no longer requires @command{fgrep},
  16021. but many hosts do not yet support the Posix
  16022. replacement @code{grep -F}. Also, some traditional implementations do
  16023. not work on long input lines. To work around these problems, invoke
  16024. @code{AC_PROG_FGREP} and then use @code{$FGREP}.
  16025. Tru64/OSF 5.1 @command{fgrep} does not match an empty pattern.
  16026. @item @command{find}
  16027. @c -----------------
  16028. @prindex @command{find}
  16029. The option @option{-maxdepth} seems to be GNU specific.
  16030. Tru64 v5.1, NetBSD 1.5 and Solaris @command{find}
  16031. commands do not understand it.
  16032. The replacement of @samp{@{@}} is guaranteed only if the argument is
  16033. exactly @emph{@{@}}, not if it's only a part of an argument. For
  16034. instance on DU, and HP-UX 10.20 and HP-UX 11:
  16035. @example
  16036. $ @kbd{touch foo}
  16037. $ @kbd{find . -name foo -exec echo "@{@}-@{@}" \;}
  16038. @{@}-@{@}
  16039. @end example
  16040. @noindent
  16041. while GNU @command{find} reports @samp{./foo-./foo}.
  16042. @anchor{grep}
  16043. @item @command{grep}
  16044. @c -----------------
  16045. @prindex @command{grep}
  16046. Portable scripts can rely on the @command{grep} options @option{-c},
  16047. @option{-l}, @option{-n}, and @option{-v}, but should avoid other
  16048. options. For example, don't use @option{-w}, as Posix does not require
  16049. it and Irix 6.5.16m's @command{grep} does not support it. Also,
  16050. portable scripts should not combine @option{-c} with @option{-l},
  16051. as Posix does not allow this.
  16052. Some of the options required by Posix are not portable in practice.
  16053. Don't use @samp{grep -q} to suppress output, because many @command{grep}
  16054. implementations (e.g., Solaris) do not support @option{-q}.
  16055. Don't use @samp{grep -s} to suppress output either, because Posix
  16056. says @option{-s} does not suppress output, only some error messages;
  16057. also, the @option{-s} option of traditional @command{grep} behaved
  16058. like @option{-q} does in most modern implementations. Instead,
  16059. redirect the standard output and standard error (in case the file
  16060. doesn't exist) of @code{grep} to @file{/dev/null}. Check the exit
  16061. status of @code{grep} to determine whether it found a match.
  16062. The QNX4 implementation fails to count lines with @code{grep -c '$'},
  16063. but works with @code{grep -c '^'}. Other alternatives for counting
  16064. lines are to use @code{sed -n '$='} or @code{wc -l}.
  16065. Some traditional @command{grep} implementations do not work on long
  16066. input lines. On AIX the default @code{grep} silently truncates long
  16067. lines on the input before matching.
  16068. Also, many implementations do not support multiple regexps
  16069. with @option{-e}: they either reject @option{-e} entirely (e.g., Solaris)
  16070. or honor only the last pattern (e.g., IRIX 6.5 and NeXT). To
  16071. work around these problems, invoke @code{AC_PROG_GREP} and then use
  16072. @code{$GREP}.
  16073. Another possible workaround for the multiple @option{-e} problem is to
  16074. separate the patterns by newlines, for example:
  16075. @example
  16076. grep 'foo
  16077. bar' in.txt
  16078. @end example
  16079. @noindent
  16080. except that this fails with traditional @command{grep}
  16081. implementations and with OpenBSD 3.8 @command{grep}.
  16082. Traditional @command{grep} implementations (e.g., Solaris) do not
  16083. support the @option{-E} or @option{-F} options. To work around these
  16084. problems, invoke @code{AC_PROG_EGREP} and then use @code{$EGREP}, and
  16085. similarly for @code{AC_PROG_FGREP} and @code{$FGREP}. Even if you are
  16086. willing to require support for Posix @command{grep}, your script should
  16087. not use both @option{-E} and @option{-F}, since Posix does not allow
  16088. this combination.
  16089. Portable @command{grep} regular expressions should use @samp{\} only to
  16090. escape characters in the string @samp{$()*.0123456789[\^@{@}}. For example,
  16091. alternation, @samp{\|}, is common but Posix does not require its
  16092. support in basic regular expressions, so it should be avoided in
  16093. portable scripts. Solaris and HP-UX @command{grep} do not support it.
  16094. Similarly, the following escape sequences should also be avoided:
  16095. @samp{\<}, @samp{\>}, @samp{\+}, @samp{\?}, @samp{\`}, @samp{\'},
  16096. @samp{\B}, @samp{\b}, @samp{\S}, @samp{\s}, @samp{\W}, and @samp{\w}.
  16097. Posix does not specify the behavior of @command{grep} on binary files.
  16098. An example where this matters is using BSD @command{grep} to
  16099. search text that includes embedded ANSI escape sequences for
  16100. colored output to terminals (@samp{\033[m} is the sequence to restore
  16101. normal output); the behavior depends on whether input is seekable:
  16102. @example
  16103. $ @kbd{printf 'esc\033[mape\n' > sample}
  16104. $ @kbd{grep . sample}
  16105. Binary file sample matches
  16106. $ @kbd{cat sample | grep .}
  16107. escape
  16108. @end example
  16109. @item @command{join}
  16110. @c -----------------
  16111. @prindex @command{join}
  16112. Solaris 8 @command{join} has bugs when the second operand is standard
  16113. input, and when standard input is a pipe. For example, the following
  16114. shell script causes Solaris 8 @command{join} to loop forever:
  16115. @example
  16116. cat >file <<'EOF'
  16117. 1 x
  16118. 2 y
  16119. EOF
  16120. cat file | join file -
  16121. @end example
  16122. Use @samp{join - file} instead.
  16123. On NetBSD, @command{join -a 1 file1 file2} mistakenly behaves like
  16124. @command{join -a 1 -a 2 1 file1 file2}, resulting in a usage warning;
  16125. the workaround is to use @command{join -a1 file1 file2} instead.
  16126. @item @command{ln}
  16127. @c ---------------
  16128. @prindex @command{ln}
  16129. @cindex Symbolic links
  16130. Don't rely on @command{ln} having a @option{-f} option. Symbolic links
  16131. are not available on old systems; use @samp{$(LN_S)} as a portable substitute.
  16132. For versions of the DJGPP before 2.04,
  16133. @command{ln} emulates symbolic links
  16134. to executables by generating a stub that in turn calls the real
  16135. program. This feature also works with nonexistent files like in the
  16136. Posix spec. So @samp{ln -s file link} generates @file{link.exe},
  16137. which attempts to call @file{file.exe} if run. But this feature only
  16138. works for executables, so @samp{cp -p} is used instead for these
  16139. systems. DJGPP versions 2.04 and later have full support
  16140. for symbolic links.
  16141. @item @command{ls}
  16142. @c ---------------
  16143. @prindex @command{ls}
  16144. @cindex Listing directories
  16145. The portable options are @option{-acdilrtu}. Current practice is for
  16146. @option{-l} to output both owner and group, even though ancient versions
  16147. of @command{ls} omitted the group.
  16148. On ancient hosts, @samp{ls foo} sent the diagnostic @samp{foo not found}
  16149. to standard output if @file{foo} did not exist. Hence a shell command
  16150. like @samp{sources=`ls *.c 2>/dev/null`} did not always work, since it
  16151. was equivalent to @samp{sources='*.c not found'} in the absence of
  16152. @samp{.c} files. This is no longer a practical problem, since current
  16153. @command{ls} implementations send diagnostics to standard error.
  16154. The behavior of @command{ls} on a directory that is being concurrently
  16155. modified is not always predictable, because of a data race where cached
  16156. information returned by @code{readdir} does not match the current
  16157. directory state. In fact, MacOS 10.5 has an intermittent bug where
  16158. @code{readdir}, and thus @command{ls}, sometimes lists a file more than
  16159. once if other files were added or removed from the directory immediately
  16160. prior to the @command{ls} call. Since @command{ls} already sorts its
  16161. output, the duplicate entries can be avoided by piping the results
  16162. through @code{uniq}.
  16163. @anchor{mkdir}
  16164. @item @command{mkdir}
  16165. @c ------------------
  16166. @prindex @command{mkdir}
  16167. @cindex Making directories
  16168. No @command{mkdir} option is portable to older systems. Instead of
  16169. @samp{mkdir -p @var{file-name}}, you should use
  16170. @code{AS_MKDIR_P(@var{file-name})} (@pxref{Programming in M4sh})
  16171. or @code{AC_PROG_MKDIR_P} (@pxref{Particular Programs}).
  16172. Combining the @option{-m} and @option{-p} options, as in @samp{mkdir -m
  16173. go-w -p @var{dir}}, often leads to trouble. FreeBSD
  16174. @command{mkdir} incorrectly attempts to change the permissions of
  16175. @var{dir} even if it already exists. HP-UX 11.23 and
  16176. IRIX 6.5 @command{mkdir} often assign the wrong permissions to
  16177. any newly-created parents of @var{dir}.
  16178. Posix does not clearly specify whether @samp{mkdir -p foo}
  16179. should succeed when @file{foo} is a symbolic link to an already-existing
  16180. directory. The GNU Core Utilities 5.1.0 @command{mkdir}
  16181. succeeds, but Solaris @command{mkdir} fails.
  16182. Traditional @code{mkdir -p} implementations suffer from race conditions.
  16183. For example, if you invoke @code{mkdir -p a/b} and @code{mkdir -p a/c}
  16184. at the same time, both processes might detect that @file{a} is missing,
  16185. one might create @file{a}, then the other might try to create @file{a}
  16186. and fail with a @code{File exists} diagnostic. The GNU Core
  16187. Utilities (@samp{fileutils} version 4.1), FreeBSD 5.0,
  16188. NetBSD 2.0.2, and OpenBSD 2.4 are known to be
  16189. race-free when two processes invoke @code{mkdir -p} simultaneously, but
  16190. earlier versions are vulnerable. Solaris @command{mkdir} is still
  16191. vulnerable as of Solaris 10, and other traditional Unix systems are
  16192. probably vulnerable too. This possible race is harmful in parallel
  16193. builds when several Make rules call @code{mkdir -p} to
  16194. construct directories. You may use
  16195. @code{install-sh -d} as a safe replacement, provided this script is
  16196. recent enough; the copy shipped with Autoconf 2.60 and Automake 1.10 is
  16197. OK, but copies from older versions are vulnerable.
  16198. @item @command{mkfifo}
  16199. @itemx @command{mknod}
  16200. @c -------------------
  16201. @prindex @command{mkfifo}
  16202. @prindex @command{mknod}
  16203. The GNU Coding Standards state that @command{mknod} is safe to use on
  16204. platforms where it has been tested to exist; but it is generally portable
  16205. only for creating named FIFOs, since device numbers are
  16206. platform-specific. Autotest uses @command{mkfifo} to implement parallel
  16207. testsuites. Posix states that behavior is unspecified when opening a
  16208. named FIFO for both reading and writing; on at least Cygwin, this
  16209. results in failure on any attempt to read or write to that file
  16210. descriptor.
  16211. @item @command{mktemp}
  16212. @c -------------------
  16213. @prindex @command{mktemp}
  16214. @cindex Creating temporary files
  16215. Shell scripts can use temporary files safely with @command{mktemp}, but
  16216. it does not exist on all systems. A portable way to create a safe
  16217. temporary file name is to create a temporary directory with mode 700 and
  16218. use a file inside this directory. Both methods prevent attackers from
  16219. gaining control, though @command{mktemp} is far less likely to fail
  16220. gratuitously under attack.
  16221. Here is sample code to create a new temporary directory @samp{$dir} safely:
  16222. @example
  16223. # Create a temporary directory $dir in $TMPDIR (default /tmp).
  16224. # Use mktemp if possible; otherwise fall back on mkdir,
  16225. # with $RANDOM to make collisions less likely.
  16226. : "$@{TMPDIR:=/tmp@}"
  16227. @{
  16228. dir=`
  16229. (umask 077 && mktemp -d "$TMPDIR/fooXXXXXX") 2>/dev/null
  16230. ` &&
  16231. test -d "$dir"
  16232. @} || @{
  16233. dir=$TMPDIR/foo$$-$RANDOM
  16234. @c $$ restore font-lock
  16235. (umask 077 && mkdir "$dir")
  16236. @} || exit $?
  16237. @end example
  16238. @item @command{mv}
  16239. @c ---------------
  16240. @prindex @command{mv}
  16241. @cindex Moving open files
  16242. The only portable options are @option{-f} and @option{-i}.
  16243. Moving individual files between file systems is portable (it was in Unix
  16244. version 6),
  16245. but it is not always atomic: when doing @samp{mv new existing}, there's
  16246. a critical section where neither the old nor the new version of
  16247. @file{existing} actually exists.
  16248. On some systems moving files from @file{/tmp} can sometimes cause
  16249. undesirable (but perfectly valid) warnings, even if you created these
  16250. files. This is because @file{/tmp} belongs to a group that ordinary
  16251. users are not members of, and files created in @file{/tmp} inherit
  16252. the group of @file{/tmp}. When the file is copied, @command{mv} issues
  16253. a diagnostic without failing:
  16254. @smallexample
  16255. $ @kbd{touch /tmp/foo}
  16256. $ @kbd{mv /tmp/foo .}
  16257. @error{}mv: ./foo: set owner/group (was: 100/0): Operation not permitted
  16258. $ @kbd{echo $?}
  16259. 0
  16260. $ @kbd{ls foo}
  16261. foo
  16262. @end smallexample
  16263. @noindent
  16264. This annoying behavior conforms to Posix, unfortunately.
  16265. Moving directories across mount points is not portable, use @command{cp}
  16266. and @command{rm}.
  16267. DOS variants cannot rename or remove open files, and do not
  16268. support commands like @samp{mv foo bar >foo}, even though this is
  16269. perfectly portable among Posix hosts.
  16270. @item @command{od}
  16271. @c ---------------
  16272. @prindex @command{od}
  16273. In Mac OS X 10.3, @command{od} does not support the
  16274. standard Posix options @option{-A}, @option{-j}, @option{-N}, or
  16275. @option{-t}, or the XSI option @option{-s}. The only
  16276. supported Posix option is @option{-v}, and the only supported
  16277. XSI options are those in @option{-bcdox}. The BSD
  16278. @command{hexdump} program can be used instead.
  16279. This problem no longer exists in Mac OS X 10.4.3.
  16280. @item @command{rm}
  16281. @c ---------------
  16282. @prindex @command{rm}
  16283. The @option{-f} and @option{-r} options are portable.
  16284. It is not portable to invoke @command{rm} without options or operands.
  16285. On the other hand, Posix now requires @command{rm -f} to silently
  16286. succeed when there are no operands (useful for constructs like
  16287. @command{rm -rf $filelist} without first checking if @samp{$filelist}
  16288. was empty). But this was not always portable; at least NetBSD
  16289. @command{rm} built before 2008 would fail with a diagnostic.
  16290. A file might not be removed even if its parent directory is writable
  16291. and searchable. Many Posix hosts cannot remove a mount point, a named
  16292. stream, a working directory, or a last link to a file that is being
  16293. executed.
  16294. DOS variants cannot rename or remove open files, and do not
  16295. support commands like @samp{rm foo >foo}, even though this is
  16296. perfectly portable among Posix hosts.
  16297. @item @command{rmdir}
  16298. @c ------------------
  16299. @prindex @command{rmdir}
  16300. Just as with @command{rm}, some platforms refuse to remove a working
  16301. directory.
  16302. @anchor{sed}
  16303. @item @command{sed}
  16304. @c ----------------
  16305. @prindex @command{sed}
  16306. Patterns should not include the separator (unless escaped), even as part
  16307. of a character class. In conformance with Posix, the Cray
  16308. @command{sed} rejects @samp{s/[^/]*$//}: use @samp{s%[^/]*$%%}.
  16309. Even when escaped, patterns should not include separators that are also
  16310. used as @command{sed} metacharacters. For example, GNU sed 4.0.9 rejects
  16311. @samp{s,x\@{1\,\@},,}, while sed 4.1 strips the backslash before the comma
  16312. before evaluating the basic regular expression.
  16313. Avoid empty patterns within parentheses (i.e., @samp{\(\)}). Posix does
  16314. not require support for empty patterns, and Unicos 9 @command{sed} rejects
  16315. them.
  16316. Unicos 9 @command{sed} loops endlessly on patterns like @samp{.*\n.*}.
  16317. Sed scripts should not use branch labels longer than 7 characters and
  16318. should not contain comments; AIX 5.3 @command{sed} rejects indented comments.
  16319. HP-UX sed has a limit of 99 commands (not counting @samp{:} commands) and
  16320. 48 labels, which cannot be circumvented by using more than one script
  16321. file. It can execute up to 19 reads with the @samp{r} command per cycle.
  16322. Solaris @command{/usr/ucb/sed} rejects usages that exceed a limit of
  16323. about 6000 bytes for the internal representation of commands.
  16324. Avoid redundant @samp{;}, as some @command{sed} implementations, such as
  16325. NetBSD 1.4.2's, incorrectly try to interpret the second
  16326. @samp{;} as a command:
  16327. @example
  16328. $ @kbd{echo a | sed 's/x/x/;;s/x/x/'}
  16329. sed: 1: "s/x/x/;;s/x/x/": invalid command code ;
  16330. @end example
  16331. Some @command{sed} implementations have a buffer limited to 4000 bytes,
  16332. and this limits the size of input lines, output lines, and internal
  16333. buffers that can be processed portably. Likewise,
  16334. not all @command{sed} implementations can handle embedded @code{NUL} or
  16335. a missing trailing newline.
  16336. Remember that ranges within a bracket expression of a regular expression
  16337. are only well-defined in the @samp{C} (or @samp{POSIX}) locale.
  16338. Meanwhile, support for character classes like @samp{[[:upper:]]} is not
  16339. yet universal, so if you cannot guarantee the setting of @env{LC_ALL},
  16340. it is better to spell out a range @samp{[ABCDEFGHIJKLMNOPQRSTUVWXYZ]}
  16341. than to rely on @samp{[A-Z]}.
  16342. Additionally, Posix states that regular expressions are only
  16343. well-defined on characters. Unfortunately, there exist platforms such
  16344. as MacOS X 10.5 where not all 8-bit byte values are valid characters,
  16345. even though that platform has a single-byte @samp{C} locale. And Posix
  16346. allows the existence of a multi-byte @samp{C} locale, although that does
  16347. not yet appear to be a common implementation. At any rate, it means
  16348. that not all bytes will be matched by the regular expression @samp{.}:
  16349. @example
  16350. $ @kbd{printf '\200\n' | LC_ALL=C sed -n /./p | wc -l}
  16351. 0
  16352. $ @kbd{printf '\200\n' | LC_ALL=en_US.ISO8859-1 sed -n /./p | wc -l}
  16353. 1
  16354. @end example
  16355. Portable @command{sed} regular expressions should use @samp{\} only to escape
  16356. characters in the string @samp{$()*.0123456789[\^n@{@}}. For example,
  16357. alternation, @samp{\|}, is common but Posix does not require its
  16358. support, so it should be avoided in portable scripts. Solaris
  16359. @command{sed} does not support alternation; e.g., @samp{sed '/a\|b/d'}
  16360. deletes only lines that contain the literal string @samp{a|b}.
  16361. Similarly, @samp{\+} and @samp{\?} should be avoided.
  16362. Anchors (@samp{^} and @samp{$}) inside groups are not portable.
  16363. Nested parentheses in patterns (e.g., @samp{\(\(a*\)b*)\)}) are
  16364. quite portable to current hosts, but was not supported by some ancient
  16365. @command{sed} implementations like SVR3.
  16366. Some @command{sed} implementations, e.g., Solaris, restrict the special
  16367. role of the asterisk @samp{*} to one-character regular expressions and
  16368. back-references, and the special role of interval expressions
  16369. @samp{\@{@var{m}\@}}, @samp{\@{@var{m},\@}}, or @samp{\@{@var{m},@var{n}\@}}
  16370. to one-character regular expressions. This may lead to unexpected behavior:
  16371. @example
  16372. $ @kbd{echo '1*23*4' | /usr/bin/sed 's/\(.\)*/x/g'}
  16373. x2x4
  16374. $ @kbd{echo '1*23*4' | /usr/xpg4/bin/sed 's/\(.\)*/x/g'}
  16375. x
  16376. @end example
  16377. The @option{-e} option is mostly portable.
  16378. However, its argument
  16379. cannot start with @samp{a}, @samp{c}, or @samp{i},
  16380. as this runs afoul of a Tru64 5.1 bug.
  16381. Also, its argument cannot be empty, as this fails on AIX 5.3.
  16382. Some people prefer to use @samp{-e}:
  16383. @example
  16384. sed -e '@var{command-1}' \
  16385. -e '@var{command-2}'
  16386. @end example
  16387. @noindent
  16388. as opposed to the equivalent:
  16389. @example
  16390. sed '
  16391. @var{command-1}
  16392. @var{command-2}
  16393. '
  16394. @end example
  16395. @noindent
  16396. The following usage is sometimes equivalent:
  16397. @example
  16398. sed '@var{command-1};@var{command-2}'
  16399. @end example
  16400. but Posix says that this use of a semicolon has undefined effect if
  16401. @var{command-1}'s verb is @samp{@{}, @samp{a}, @samp{b}, @samp{c},
  16402. @samp{i}, @samp{r}, @samp{t}, @samp{w}, @samp{:}, or @samp{#}, so you
  16403. should use semicolon only with simple scripts that do not use these
  16404. verbs.
  16405. Posix up to the 2008 revision requires the argument of the @option{-e}
  16406. option to be a syntactically complete script. GNU @command{sed} allows
  16407. to pass multiple script fragments, each as argument of a separate
  16408. @option{-e} option, that are then combined, with newlines between the
  16409. fragments, and a future Posix revision may allow this as well. This
  16410. approach is not portable with script fragments ending in backslash; for
  16411. example, the @command{sed} programs on Solaris 10, HP-UX 11, and AIX
  16412. don't allow splitting in this case:
  16413. @example
  16414. $ @kbd{echo a | sed -n -e 'i\}
  16415. @kbd{0'}
  16416. 0
  16417. $ @kbd{echo a | sed -n -e 'i\' -e 0}
  16418. Unrecognized command: 0
  16419. @end example
  16420. @noindent
  16421. In practice, however, this technique of joining fragments
  16422. through @option{-e} works for multiple @command{sed} functions within
  16423. @samp{@{} and @samp{@}}, even if that is not specified by Posix:
  16424. @example
  16425. @c The quote around the closing brace silences interactive zsh.
  16426. $ @kbd{echo a | sed -n -e '/a/@{' -e s/a/b/ -e p -e '@}'}
  16427. b
  16428. @end example
  16429. Commands inside @{ @} brackets are further restricted. Posix 2008 says that
  16430. they cannot be preceded by addresses, @samp{!}, or @samp{;}, and that
  16431. each command must be followed immediately by a newline, without any
  16432. intervening blanks or semicolons. The closing bracket must be alone on
  16433. a line, other than white space preceding or following it. However, a
  16434. future version of Posix may standardize the use of addresses within brackets.
  16435. Contrary to yet another urban legend, you may portably use @samp{&} in
  16436. the replacement part of the @code{s} command to mean ``what was
  16437. matched''. All descendants of Unix version 7 @command{sed}
  16438. (at least; we
  16439. don't have first hand experience with older @command{sed} implementations) have
  16440. supported it.
  16441. Posix requires that you must not have any white space between
  16442. @samp{!} and the following command. It is OK to have blanks between
  16443. the address and the @samp{!}. For instance, on Solaris:
  16444. @example
  16445. $ @kbd{echo "foo" | sed -n '/bar/ ! p'}
  16446. @error{}Unrecognized command: /bar/ ! p
  16447. $ @kbd{echo "foo" | sed -n '/bar/! p'}
  16448. @error{}Unrecognized command: /bar/! p
  16449. $ @kbd{echo "foo" | sed -n '/bar/ !p'}
  16450. foo
  16451. @end example
  16452. Posix also says that you should not combine @samp{!} and @samp{;}. If
  16453. you use @samp{!}, it is best to put it on a command that is delimited by
  16454. newlines rather than @samp{;}.
  16455. Also note that Posix requires that the @samp{b}, @samp{t}, @samp{r}, and
  16456. @samp{w} commands be followed by exactly one space before their argument.
  16457. On the other hand, no white space is allowed between @samp{:} and the
  16458. subsequent label name.
  16459. If a sed script is specified on the command line and ends in an
  16460. @samp{a}, @samp{c}, or @samp{i} command, the last line of inserted text
  16461. should be followed by a newline. Otherwise some @command{sed}
  16462. implementations (e.g., OpenBSD 3.9) do not append a newline to the
  16463. inserted text.
  16464. Many @command{sed} implementations (e.g., MacOS X 10.4,
  16465. OpenBSD 3.9, Solaris 10
  16466. @command{/usr/ucb/sed}) strip leading white space from the text of
  16467. @samp{a}, @samp{c}, and @samp{i} commands. Prepend a backslash to
  16468. work around this incompatibility with Posix:
  16469. @example
  16470. $ @kbd{echo flushleft | sed 'a\}
  16471. > @kbd{ indented}
  16472. > @kbd{'}
  16473. flushleft
  16474. indented
  16475. $ @kbd{echo foo | sed 'a\}
  16476. > @kbd{\ indented}
  16477. > @kbd{'}
  16478. flushleft
  16479. indented
  16480. @end example
  16481. Posix requires that with an empty regular expression, the last non-empty
  16482. regular expression from either an address specification or substitution
  16483. command is applied. However, busybox 1.6.1 complains when using a
  16484. substitution command with a replacement containing a back-reference to
  16485. an empty regular expression; the workaround is repeating the regular
  16486. expression.
  16487. @example
  16488. $ @kbd{echo abc | busybox sed '/a\(b\)c/ s//\1/'}
  16489. sed: No previous regexp.
  16490. $ @kbd{echo abc | busybox sed '/a\(b\)c/ s/a\(b\)c/\1/'}
  16491. b
  16492. @end example
  16493. @item @command{sed} (@samp{t})
  16494. @c ---------------------------
  16495. @prindex @command{sed} (@samp{t})
  16496. Some old systems have @command{sed} that ``forget'' to reset their
  16497. @samp{t} flag when starting a new cycle. For instance on MIPS
  16498. RISC/OS, and on IRIX 5.3, if you run the following @command{sed}
  16499. script (the line numbers are not actual part of the texts):
  16500. @example
  16501. s/keep me/kept/g # a
  16502. t end # b
  16503. s/.*/deleted/g # c
  16504. :end # d
  16505. @end example
  16506. @noindent
  16507. on
  16508. @example
  16509. delete me # 1
  16510. delete me # 2
  16511. keep me # 3
  16512. delete me # 4
  16513. @end example
  16514. @noindent
  16515. you get
  16516. @example
  16517. deleted
  16518. delete me
  16519. kept
  16520. deleted
  16521. @end example
  16522. @noindent
  16523. instead of
  16524. @example
  16525. deleted
  16526. deleted
  16527. kept
  16528. deleted
  16529. @end example
  16530. Why? When processing line 1, (c) matches, therefore sets the @samp{t}
  16531. flag, and the output is produced. When processing
  16532. line 2, the @samp{t} flag is still set (this is the bug). Command (a)
  16533. fails to match, but @command{sed} is not supposed to clear the @samp{t}
  16534. flag when a substitution fails. Command (b) sees that the flag is set,
  16535. therefore it clears it, and jumps to (d), hence you get @samp{delete me}
  16536. instead of @samp{deleted}. When processing line (3), @samp{t} is clear,
  16537. (a) matches, so the flag is set, hence (b) clears the flags and jumps.
  16538. Finally, since the flag is clear, line 4 is processed properly.
  16539. There are two things one should remember about @samp{t} in @command{sed}.
  16540. Firstly, always remember that @samp{t} jumps if @emph{some} substitution
  16541. succeeded, not only the immediately preceding substitution. Therefore,
  16542. always use a fake @samp{t clear} followed by a @samp{:clear} on the next
  16543. line, to reset the @samp{t} flag where needed.
  16544. Secondly, you cannot rely on @command{sed} to clear the flag at each new
  16545. cycle.
  16546. One portable implementation of the script above is:
  16547. @example
  16548. t clear
  16549. :clear
  16550. s/keep me/kept/g
  16551. t end
  16552. s/.*/deleted/g
  16553. :end
  16554. @end example
  16555. @item @command{sleep}
  16556. @c ------------------
  16557. @prindex @command{sleep}
  16558. Using @command{sleep} is generally portable. However, remember that
  16559. adding a @command{sleep} to work around timestamp issues, with a minimum
  16560. granularity of one second, doesn't scale well for parallel builds on
  16561. modern machines with sub-second process completion.
  16562. @item @command{sort}
  16563. @c -----------------
  16564. @prindex @command{sort}
  16565. Remember that sort order is influenced by the current locale. Inside
  16566. @file{configure}, the C locale is in effect, but in Makefile snippets,
  16567. you may need to specify @code{LC_ALL=C sort}.
  16568. @item @command{tar}
  16569. @c ----------------
  16570. @prindex @command{tar}
  16571. There are multiple file formats for @command{tar}; if you use Automake,
  16572. the macro @code{AM_INIT_AUTOMAKE} has some options controlling which
  16573. level of portability to use.
  16574. @anchor{touch}
  16575. @item @command{touch}
  16576. @c ------------------
  16577. @prindex @command{touch}
  16578. @cindex timestamp resolution
  16579. If you specify the desired timestamp (e.g., with the @option{-r}
  16580. option), older @command{touch} implementations use the @code{utime} or
  16581. @code{utimes} system call, which can result in the same kind of
  16582. timestamp truncation problems that @samp{cp -p} has.
  16583. On ancient BSD systems, @command{touch} or any command that
  16584. results in an empty file does not update the timestamps, so use a
  16585. command like @command{echo} as a workaround.
  16586. Also,
  16587. GNU @command{touch} 3.16r (and presumably all before that)
  16588. fails to work on SunOS 4.1.3 when the empty file is on an
  16589. NFS-mounted 4.2 volume.
  16590. However, these problems are no longer of practical concern.
  16591. @item @command{tr}
  16592. @c ---------------
  16593. @prindex @command{tr}
  16594. @cindex carriage return, deleting
  16595. @cindex newline, deleting
  16596. @cindex deleting carriage return
  16597. Not all versions of @command{tr} handle all backslash character escapes.
  16598. For example, Solaris 10 @command{/usr/ucb/tr} falls over, even though
  16599. Solaris contains more modern @command{tr} in other locations.
  16600. Using octal escapes is more portable for carriage returns, since
  16601. @samp{\015} is the same for both ASCII and EBCDIC, and since use of
  16602. literal carriage returns in scripts causes a number of other problems.
  16603. But for other characters, like newline, using octal escapes ties the
  16604. operation to ASCII, so it is better to use literal characters.
  16605. @example
  16606. $ @kbd{@{ echo moon; echo light; @} | /usr/ucb/tr -d '\n' ; echo}
  16607. moo
  16608. light
  16609. $ @kbd{@{ echo moon; echo light; @} | /usr/bin/tr -d '\n' ; echo}
  16610. moonlight
  16611. $ @kbd{@{ echo moon; echo light; @} | /usr/ucb/tr -d '\012' ; echo}
  16612. moonlight
  16613. $ @kbd{nl='}
  16614. @kbd{'; @{ echo moon; echo light; @} | /usr/ucb/tr -d "$nl" ; echo}
  16615. moonlight
  16616. @end example
  16617. Not all versions of @command{tr} recognize direct ranges of characters: at
  16618. least Solaris @command{/usr/bin/tr} still fails to do so. But you can
  16619. use @command{/usr/xpg4/bin/tr} instead, or add brackets (which in Posix
  16620. transliterate to themselves).
  16621. @example
  16622. $ @kbd{echo "Hazy Fantazy" | LC_ALL=C /usr/bin/tr a-z A-Z}
  16623. HAZy FAntAZy
  16624. $ @kbd{echo "Hazy Fantazy" | LC_ALL=C /usr/bin/tr '[a-z]' '[A-Z]'}
  16625. HAZY FANTAZY
  16626. $ @kbd{echo "Hazy Fantazy" | LC_ALL=C /usr/xpg4/bin/tr a-z A-Z}
  16627. HAZY FANTAZY
  16628. @end example
  16629. When providing two arguments, be sure the second string is at least as
  16630. long as the first.
  16631. @example
  16632. $ @kbd{echo abc | /usr/xpg4/bin/tr bc d}
  16633. adc
  16634. $ @kbd{echo abc | coreutils/tr bc d}
  16635. add
  16636. @end example
  16637. Posix requires @command{tr} to operate on binary files. But at least
  16638. Solaris @command{/usr/ucb/tr} and @command{/usr/bin/tr} silently discard
  16639. @code{NUL} in the input prior to doing any translation. When using
  16640. @command{tr} to process a binary file that may contain @code{NUL} bytes,
  16641. it is necessary to use @command{/usr/xpg4/bin/tr} instead, or
  16642. @command{/usr/xpg6/bin/tr} if that is available.
  16643. @example
  16644. $ @kbd{printf 'a\0b' | /usr/ucb/tr x x | od -An -tx1}
  16645. 61 62
  16646. $ @kbd{printf 'a\0b' | /usr/bin/tr x x | od -An -tx1}
  16647. 61 62
  16648. $ @kbd{printf 'a\0b' | /usr/xpg4/bin/tr x x | od -An -tx1}
  16649. 61 00 62
  16650. @end example
  16651. Solaris @command{/usr/ucb/tr} additionally fails to handle @samp{\0} as the
  16652. octal escape for @code{NUL}.
  16653. @example
  16654. $ @kbd{printf 'abc' | /usr/ucb/tr 'bc' '\0d' | od -An -tx1}
  16655. 61 62 63
  16656. $ @kbd{printf 'abc' | /usr/bin/tr 'bc' '\0d' | od -An -tx1}
  16657. 61 00 64
  16658. $ @kbd{printf 'abc' | /usr/xpg4/bin/tr 'bc' '\0d' | od -An -tx1}
  16659. 61 00 64
  16660. @end example
  16661. @end table
  16662. @node Portable Make
  16663. @chapter Portable Make Programming
  16664. @prindex @command{make}
  16665. @cindex Limitations of @command{make}
  16666. Writing portable makefiles is an art. Since a makefile's commands are
  16667. executed by the shell, you must consider the shell portability issues
  16668. already mentioned. However, other issues are specific to @command{make}
  16669. itself.
  16670. @menu
  16671. * $< in Ordinary Make Rules:: $< in ordinary rules
  16672. * Failure in Make Rules:: Failing portably in rules
  16673. * Special Chars in Names:: Special Characters in Macro Names
  16674. * Backslash-Newline-Empty:: Empty lines after backslash-newline
  16675. * Backslash-Newline Comments:: Spanning comments across line boundaries
  16676. * Long Lines in Makefiles:: Line length limitations
  16677. * Macros and Submakes:: @code{make macro=value} and submakes
  16678. * The Make Macro MAKEFLAGS:: @code{$(MAKEFLAGS)} portability issues
  16679. * The Make Macro SHELL:: @code{$(SHELL)} portability issues
  16680. * Parallel Make:: Parallel @command{make} quirks
  16681. * Comments in Make Rules:: Other problems with Make comments
  16682. * Newlines in Make Rules:: Using literal newlines in rules
  16683. * Comments in Make Macros:: Other problems with Make comments in macros
  16684. * Trailing whitespace in Make Macros:: Macro substitution problems
  16685. * Command-line Macros and whitespace:: Whitespace trimming of values
  16686. * obj/ and Make:: Don't name a subdirectory @file{obj}
  16687. * make -k Status:: Exit status of @samp{make -k}
  16688. * VPATH and Make:: @code{VPATH} woes
  16689. * Single Suffix Rules:: Single suffix rules and separated dependencies
  16690. * Timestamps and Make:: Subsecond timestamp resolution
  16691. @end menu
  16692. @node $< in Ordinary Make Rules
  16693. @section @code{$<} in Ordinary Make Rules
  16694. Posix says that the @samp{$<} construct in makefiles can be
  16695. used only in inference rules and in the @samp{.DEFAULT} rule; its
  16696. meaning in ordinary rules is unspecified. Solaris @command{make}
  16697. for instance replaces it with the empty string. OpenBSD (3.0 and
  16698. later) @command{make} diagnoses these uses and errors out.
  16699. @node Failure in Make Rules
  16700. @section Failure in Make Rules
  16701. Posix 2008 requires that @command{make} must invoke each command with
  16702. the equivalent of a @samp{sh -e -c} subshell, which causes the
  16703. subshell to exit immediately if a subsidiary simple-command fails,
  16704. although not all @command{make} implementations have historically
  16705. followed this rule. For
  16706. example, the command @samp{touch T; rm -f U} may attempt to
  16707. remove @file{U} even if the @command{touch} fails, although this is not
  16708. permitted with Posix make. One way to work around failures in simple
  16709. commands is to reword them so that they always succeed, e.g., @samp{touch
  16710. T || :; rm -f U}.
  16711. However, even this approach can run into common bugs in BSD
  16712. implementations of the @option{-e} option of @command{sh} and
  16713. @command{set} (@pxref{set, , Limitations of Shell Builtins}), so if you
  16714. are worried
  16715. about porting to buggy BSD shells it may be simpler to migrate
  16716. complicated @command{make} actions into separate scripts.
  16717. @node Special Chars in Names
  16718. @section Special Characters in Make Macro Names
  16719. Posix limits macro names to nonempty strings containing only
  16720. ASCII letters and digits, @samp{.}, and @samp{_}. Many
  16721. @command{make} implementations allow a wider variety of characters, but
  16722. portable makefiles should avoid them. It is portable to start a name
  16723. with a special character, e.g., @samp{$(.FOO)}.
  16724. Some ancient @command{make} implementations don't support leading
  16725. underscores in macro names. An example is NEWS-OS 4.2R.
  16726. @example
  16727. $ @kbd{cat Makefile}
  16728. _am_include = #
  16729. _am_quote =
  16730. all:; @@echo this is test
  16731. $ @kbd{make}
  16732. Make: Must be a separator on rules line 2. Stop.
  16733. $ @kbd{cat Makefile2}
  16734. am_include = #
  16735. am_quote =
  16736. all:; @@echo this is test
  16737. $ @kbd{make -f Makefile2}
  16738. this is test
  16739. @end example
  16740. @noindent
  16741. However, this problem is no longer of practical concern.
  16742. @node Backslash-Newline-Empty
  16743. @section Backslash-Newline Before Empty Lines
  16744. A bug in Bash 2.03 can cause problems if a Make rule contains a
  16745. backslash-newline followed by line that expands to nothing.
  16746. For example, on Solaris 8:
  16747. @example
  16748. SHELL = /bin/bash
  16749. EMPTY =
  16750. foo:
  16751. touch foo \
  16752. $(EMPTY)
  16753. @end example
  16754. @noindent
  16755. executes
  16756. @example
  16757. /bin/bash -c 'touch foo \
  16758. '
  16759. @end example
  16760. @noindent
  16761. which fails with a syntax error, due to the Bash bug. To avoid this
  16762. problem, avoid nullable macros in the last line of a multiline command.
  16763. @c This has been seen on ia64 hpux 11.20, and on one hppa hpux 10.20,
  16764. @c but another hppa hpux 10.20 didn't have it. Bob Proulx
  16765. @c <bob@proulx.com> thinks it was in hpux 8.0 too.
  16766. On some versions of HP-UX, @command{make} reads multiple newlines
  16767. following a backslash, continuing to the next non-empty line. For
  16768. example,
  16769. @example
  16770. FOO = one \
  16771. BAR = two
  16772. test:
  16773. : FOO is "$(FOO)"
  16774. : BAR is "$(BAR)"
  16775. @end example
  16776. @noindent
  16777. shows @code{FOO} equal to @code{one BAR = two}. Other implementations
  16778. sensibly let a backslash continue only to the immediately following
  16779. line.
  16780. @node Backslash-Newline Comments
  16781. @section Backslash-Newline in Make Comments
  16782. According to Posix, Make comments start with @code{#}
  16783. and continue until an unescaped newline is reached.
  16784. @example
  16785. $ @kbd{cat Makefile}
  16786. # A = foo \
  16787. bar \
  16788. baz
  16789. all:
  16790. @@echo ok
  16791. $ @kbd{make} # GNU make
  16792. ok
  16793. @end example
  16794. @noindent
  16795. However this is not always the case. Some implementations
  16796. discard everything from @code{#} through the end of the line, ignoring any
  16797. trailing backslash.
  16798. @example
  16799. $ @kbd{pmake} # BSD make
  16800. "Makefile", line 3: Need an operator
  16801. Fatal errors encountered -- cannot continue
  16802. @end example
  16803. @noindent
  16804. Therefore, if you want to comment out a multi-line definition, prefix each
  16805. line with @code{#}, not only the first.
  16806. @example
  16807. # A = foo \
  16808. # bar \
  16809. # baz
  16810. @end example
  16811. @node Long Lines in Makefiles
  16812. @section Long Lines in Makefiles
  16813. Tru64 5.1's @command{make} has been reported to crash when given a
  16814. makefile with lines longer than around 20 kB. Earlier versions are
  16815. reported to exit with @code{Line too long} diagnostics.
  16816. @node Macros and Submakes
  16817. @section @code{make macro=value} and Submakes
  16818. A command-line variable definition such as @code{foo=bar} overrides any
  16819. definition of @code{foo} in a makefile. Some @command{make}
  16820. implementations (such as GNU @command{make}) propagate this
  16821. override to subsidiary invocations of @command{make}. Some other
  16822. implementations do not pass the substitution along to submakes.
  16823. @example
  16824. $ @kbd{cat Makefile}
  16825. foo = foo
  16826. one:
  16827. @@echo $(foo)
  16828. $(MAKE) two
  16829. two:
  16830. @@echo $(foo)
  16831. $ @kbd{make foo=bar} # GNU make 3.79.1
  16832. bar
  16833. make two
  16834. make[1]: Entering directory `/home/adl'
  16835. bar
  16836. make[1]: Leaving directory `/home/adl'
  16837. $ @kbd{pmake foo=bar} # BSD make
  16838. bar
  16839. pmake two
  16840. foo
  16841. @end example
  16842. You have a few possibilities if you do want the @code{foo=bar} override
  16843. to propagate to submakes. One is to use the @option{-e}
  16844. option, which causes all environment variables to have precedence over
  16845. the makefile macro definitions, and declare foo as an environment
  16846. variable:
  16847. @example
  16848. $ @kbd{env foo=bar make -e}
  16849. @end example
  16850. The @option{-e} option is propagated to submakes automatically,
  16851. and since the environment is inherited between @command{make}
  16852. invocations, the @code{foo} macro is overridden in
  16853. submakes as expected.
  16854. This syntax (@code{foo=bar make -e}) is portable only when used
  16855. outside of a makefile, for instance from a script or from the
  16856. command line. When run inside a @command{make} rule, GNU
  16857. @command{make} 3.80 and prior versions forget to propagate the
  16858. @option{-e} option to submakes.
  16859. Moreover, using @option{-e} could have unexpected side effects if your
  16860. environment contains some other macros usually defined by the
  16861. makefile. (See also the note about @code{make -e} and @code{SHELL}
  16862. below.)
  16863. If you can foresee all macros that a user might want to override, then
  16864. you can propagate them to submakes manually, from your makefile:
  16865. @example
  16866. foo = foo
  16867. one:
  16868. @@echo $(foo)
  16869. $(MAKE) foo=$(foo) two
  16870. two:
  16871. @@echo $(foo)
  16872. @end example
  16873. Another way to propagate a variable to submakes in a portable way is to
  16874. expand an extra variable in every invocation of @samp{$(MAKE)} within
  16875. your makefile:
  16876. @example
  16877. foo = foo
  16878. one:
  16879. @@echo $(foo)
  16880. $(MAKE) $(SUBMAKEFLAGS) two
  16881. two:
  16882. @@echo $(foo)
  16883. @end example
  16884. Users must be aware that this technique is in use to take advantage of
  16885. it, e.g.@: with @code{make foo=bar SUBMAKEFLAGS='foo=bar'}, but it
  16886. allows any macro to be overridden. Makefiles generated by
  16887. @command{automake} use this technique, expanding @code{$(AM_MAKEFLAGS)}
  16888. on the command lines of submakes (@pxref{Subdirectories, , Automake,
  16889. automake, GNU Automake}).
  16890. @node The Make Macro MAKEFLAGS
  16891. @section The Make Macro MAKEFLAGS
  16892. @cindex @code{MAKEFLAGS} and @command{make}
  16893. @cindex @command{make} and @code{MAKEFLAGS}
  16894. Posix requires @command{make} to use @code{MAKEFLAGS} to affect the
  16895. current and recursive invocations of make, but allows implementations
  16896. several formats for the variable. It is tricky to parse
  16897. @code{$MAKEFLAGS} to determine whether @option{-s} for silent execution
  16898. or @option{-k} for continued execution are in effect. For example, you
  16899. cannot assume that the first space-separated word in @code{$MAKEFLAGS}
  16900. contains single-letter options, since in the Cygwin version of
  16901. GNU @command{make} it is either @option{--unix} or
  16902. @option{--win32} with the second word containing single-letter options.
  16903. @example
  16904. $ @kbd{cat Makefile}
  16905. all:
  16906. @@echo MAKEFLAGS = $(MAKEFLAGS)
  16907. $ @kbd{make}
  16908. MAKEFLAGS = --unix
  16909. $ @kbd{make -k}
  16910. MAKEFLAGS = --unix -k
  16911. @end example
  16912. @node The Make Macro SHELL
  16913. @section The Make Macro @code{SHELL}
  16914. @cindex @code{SHELL} and @command{make}
  16915. @cindex @command{make} and @code{SHELL}
  16916. Posix-compliant @command{make} internally uses the @code{$(SHELL)}
  16917. macro to spawn shell processes and execute Make rules. This
  16918. is a builtin macro supplied by @command{make}, but it can be modified
  16919. by a makefile or by a command-line argument.
  16920. Not all @command{make} implementations define this @code{SHELL} macro.
  16921. Tru64
  16922. @command{make} is an example; this implementation always uses
  16923. @code{/bin/sh}. So it's a good idea to always define @code{SHELL} in
  16924. your makefiles. If you use Autoconf, do
  16925. @example
  16926. SHELL = @@SHELL@@
  16927. @end example
  16928. @noindent
  16929. If you use Automake, this is done for you.
  16930. Do not force @code{SHELL = /bin/sh} because that is not correct
  16931. everywhere. Remember, @file{/bin/sh} is not Posix compliant on many
  16932. systems, such as FreeBSD 4, NetBSD 3, AIX 3, Solaris 10, or Tru64.
  16933. Additionally, DJGPP lacks @code{/bin/sh}, and when its
  16934. GNU @command{make} port sees such a setting it enters a
  16935. special emulation mode where features like pipes and redirections are
  16936. emulated on top of DOS's @command{command.com}. Unfortunately this
  16937. emulation is incomplete; for instance it does not handle command
  16938. substitutions. Using @code{@@SHELL@@} means that your makefile will
  16939. benefit from the same improved shell, such as @command{bash} or
  16940. @command{ksh}, that was discovered during @command{configure}, so that
  16941. you aren't fighting two different sets of shell bugs between the two
  16942. contexts.
  16943. Posix-compliant @command{make} should never acquire the value of
  16944. $(SHELL) from the environment, even when @code{make -e} is used
  16945. (otherwise, think about what would happen to your rules if
  16946. @code{SHELL=/bin/tcsh}).
  16947. However not all @command{make} implementations have this exception.
  16948. For instance it's not surprising that Tru64 @command{make} doesn't
  16949. protect @code{SHELL}, since it doesn't use it.
  16950. @example
  16951. $ @kbd{cat Makefile}
  16952. SHELL = /bin/sh
  16953. FOO = foo
  16954. all:
  16955. @@echo $(SHELL)
  16956. @@echo $(FOO)
  16957. $ @kbd{env SHELL=/bin/tcsh FOO=bar make -e} # Tru64 Make
  16958. /bin/tcsh
  16959. bar
  16960. $ @kbd{env SHELL=/bin/tcsh FOO=bar gmake -e} # GNU make
  16961. /bin/sh
  16962. bar
  16963. @end example
  16964. Conversely, @command{make} is not supposed to export any changes to the
  16965. macro @code{SHELL} to child processes. Again, many implementations
  16966. break this rule:
  16967. @example
  16968. $ @kbd{cat Makefile}
  16969. all:
  16970. @@echo $(SHELL)
  16971. @@printenv SHELL
  16972. $ @kbd{env SHELL=sh make -e SHELL=/bin/ksh} # BSD Make, GNU make 3.80
  16973. /bin/ksh
  16974. /bin/ksh
  16975. $ @kbd{env SHELL=sh gmake -e SHELL=/bin/ksh} # GNU make 3.81
  16976. /bin/ksh
  16977. sh
  16978. @end example
  16979. @node Parallel Make
  16980. @section Parallel Make
  16981. @cindex Parallel @command{make}
  16982. Support for parallel execution in @command{make} implementation varies.
  16983. Generally, using GNU make is your best bet.
  16984. When NetBSD or FreeBSD @command{make} are run in parallel mode, they will
  16985. reuse the same shell for multiple commands within one recipe. This can
  16986. have various unexpected consequences. For example, changes of directories
  16987. or variables persist between recipes, so that:
  16988. @example
  16989. all:
  16990. @@var=value; cd /; pwd; echo $$var; echo $$$$
  16991. @@pwd; echo $$var; echo $$$$
  16992. @end example
  16993. @noindent
  16994. may output the following with @code{make -j1}, at least on NetBSD up to
  16995. 5.1 and FreeBSD up to 8.2:
  16996. @example
  16997. /
  16998. value
  16999. 32235
  17000. /
  17001. value
  17002. 32235
  17003. @end example
  17004. @noindent
  17005. while without @option{-j1}, or with @option{-B}, the output looks less
  17006. surprising:
  17007. @example
  17008. /
  17009. value
  17010. 32238
  17011. /tmp
  17012. 32239
  17013. @end example
  17014. @noindent
  17015. Another consequence is that, if one command in a recipe uses @code{exit 0}
  17016. to indicate a successful exit, the shell will be gone and the remaining
  17017. commands of this recipe will not be executed.
  17018. The BSD @command{make} implementations, when run in parallel mode,
  17019. will also pass the @command{Makefile} recipes to the shell through
  17020. its standard input, thus making it unusable from the recipes:
  17021. @example
  17022. $ @kbd{cat Makefile}
  17023. read:
  17024. @@read line; echo LINE: $$line
  17025. @c $$ @c restore font-lock
  17026. $ @kbd{echo foo | make read}
  17027. LINE: foo
  17028. $ @kbd{echo foo | make -j1 read} # NetBSD 5.1 and FreeBSD 8.2
  17029. LINE:
  17030. @end example
  17031. @noindent
  17032. Moreover, when FreeBSD @command{make} (up at least to 8.2) is run in
  17033. parallel mode, it implements the @code{@@} and @code{-} ``recipe
  17034. modifiers'' by dynamically modifying the active shell flags. This
  17035. behavior has the effects of potentially clobbering the exit status
  17036. of recipes silenced with the @code{@@} modifier if they also unset
  17037. the @option{errexit} shell flag, and of mangling the output in
  17038. unexpected ways:
  17039. @example
  17040. $ @kbd{cat Makefile}
  17041. a:
  17042. @@echo $$-; set +e; false
  17043. b:
  17044. -echo $$-; false; echo set -
  17045. $ @kbd{make a; echo status: $?}
  17046. ehBc
  17047. *** Error code 1
  17048. status: 1
  17049. $ @kbd{make -j1 a; echo status: $?}
  17050. ehB
  17051. status: 0
  17052. $ @kbd{make b}
  17053. echo $-; echo set -
  17054. hBc
  17055. set -
  17056. $ @kbd{make -j1 b}
  17057. echo $-; echo hvB
  17058. @end example
  17059. @noindent
  17060. You can avoid all these issues by using the @option{-B} option to enable
  17061. compatibility semantics. However, that will effectively also disable
  17062. all parallelism as that will cause prerequisites to be updated in the
  17063. order they are listed in a rule.
  17064. Some make implementations (among them, FreeBSD @command{make}, NetBSD
  17065. @command{make}, and Solaris @command{dmake}), when invoked with a
  17066. @option{-j@var{N}} option, connect the standard output and standard
  17067. error of all their child processes to pipes or temporary regular
  17068. files. This can lead to subtly different semantics in the behavior
  17069. of the spawned processes. For example, even if the @command{make}
  17070. standard output is connected to a tty, the recipe command will not be:
  17071. @example
  17072. $ @kbd{cat Makefile}
  17073. all:
  17074. @@test -t 1 && echo "Is a tty" || echo "Is not a tty"
  17075. $ @kbd{make -j 2} # FreeBSD 8.2 make
  17076. Is not a tty
  17077. $ @kbd{make -j 2} # NetBSD 5.1 make
  17078. --- all ---
  17079. Is not a tty
  17080. $ @kbd{dmake -j 2} # Solaris 10 dmake
  17081. @var{hostname} --> 1 job
  17082. @var{hostname} --> Job output
  17083. Is not a tty
  17084. @end example
  17085. @noindent
  17086. On the other hand:
  17087. @example
  17088. $ @kbd{make -j 2} # GNU make, Heirloom make
  17089. Is a tty
  17090. @end example
  17091. @noindent
  17092. The above examples also show additional status output produced in parallel
  17093. mode for targets being updated by Solaris @command{dmake} and NetBSD
  17094. @command{make} (but @emph{not} by FreeBSD @command{make}).
  17095. Furthermore, parallel runs of those @command{make} implementations will
  17096. route standard error from commands that they spawn into their own
  17097. standard output, and may remove leading whitespace from output lines.
  17098. @node Comments in Make Rules
  17099. @section Comments in Make Rules
  17100. @cindex Comments in @file{Makefile} rules
  17101. @cindex @file{Makefile} rules and comments
  17102. Never put comments in a rule.
  17103. Some @command{make} treat anything starting with a tab as a command for
  17104. the current rule, even if the tab is immediately followed by a @code{#}.
  17105. The @command{make} from Tru64 Unix V5.1 is one of them. The following
  17106. makefile runs @code{# foo} through the shell.
  17107. @example
  17108. all:
  17109. # foo
  17110. @end example
  17111. As a workaround, you can use the @command{:} no-op command with a string
  17112. argument that gets ignored:
  17113. @example
  17114. all:
  17115. : "foo"
  17116. @end example
  17117. Conversely, if you want to use the @samp{#} character in some command,
  17118. you can only do so by expanding it inside a rule (@pxref{Comments in
  17119. Make Macros}). So for example, if @samp{COMMENT_CHAR} is substituted by
  17120. @command{config.status} as @samp{#}, then the following substitutes
  17121. @samp{@@COMMENT_CHAR@@} in a generated header:
  17122. @example
  17123. foo.h: foo.h.in
  17124. sed -e 's|@@''COMMENT_CHAR''@@|@@COMMENT_CHAR@@|g' \
  17125. $(srcdir)/foo.h.in > $@@
  17126. @end example
  17127. The funny shell quoting avoids a substitution at @command{config.status}
  17128. run time of the left-hand side of the @command{sed} @samp{s} command.
  17129. @node Newlines in Make Rules
  17130. @section Newlines in Make Rules
  17131. @cindex Newlines in @file{Makefile} rules
  17132. @cindex @file{Makefile} rules and newlines
  17133. In shell scripts, newlines can be used inside string literals. But in
  17134. the shell statements of @file{Makefile} rules, this is not possible:
  17135. A newline not preceded by a backslash is a separator between shell
  17136. statements. Whereas a newline that is preceded by a backslash becomes
  17137. part of the shell statement according to POSIX, but gets replaced,
  17138. together with the backslash that precedes it, by a space in GNU
  17139. @command{make} 3.80 and older. So, how can a newline be used in a string
  17140. literal?
  17141. The trick is to set up a shell variable that contains a newline:
  17142. @example
  17143. nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"
  17144. @end example
  17145. For example, in order to create a multiline @samp{sed} expression that
  17146. inserts a blank line after every line of a file, this code can be used:
  17147. @example
  17148. nlinit=`echo 'nl="'; echo '"'`; eval "$$nlinit"; \
  17149. sed -e "s/\$$/\\$$@{nl@}/" < input > output
  17150. @end example
  17151. @node Comments in Make Macros
  17152. @section Comments in Make Macros
  17153. @cindex Comments in @file{Makefile} macros
  17154. @cindex @file{Makefile} macros and comments
  17155. Avoid putting comments in macro values as far as possible. Posix
  17156. specifies that the text starting from the @samp{#} sign until the end of
  17157. the line is to be ignored, which has the unfortunate effect of
  17158. disallowing them even within quotes. Thus, the following might lead to
  17159. a syntax error at compile time:
  17160. @example
  17161. CPPFLAGS = "-DCOMMENT_CHAR='#'"
  17162. @end example
  17163. @noindent
  17164. as @samp{CPPFLAGS} may be expanded to @samp{"-DCOMMENT_CHAR='}.
  17165. Most @command{make} implementations disregard this and treat single and
  17166. double quotes specially here. Also, GNU @command{make} lets you put
  17167. @samp{#} into a macro value by escaping it with a backslash, i.e.,
  17168. @samp{\#}. However, neither of these usages are portable.
  17169. @xref{Comments in Make Rules}, for a portable alternative.
  17170. Even without quoting involved, comments can have surprising effects,
  17171. because the whitespace before them is part of the variable value:
  17172. @example
  17173. foo = bar # trailing comment
  17174. print: ; @@echo "$(foo)."
  17175. @end example
  17176. @noindent
  17177. prints @samp{bar .}, which is usually not intended, and can expose
  17178. @command{make} bugs as described below.
  17179. @node Trailing whitespace in Make Macros
  17180. @section Trailing whitespace in Make Macros
  17181. @cindex whitespace in @file{Makefile} macros
  17182. @cindex @file{Makefile} macros and whitespace
  17183. GNU @command{make} 3.80 mistreats trailing whitespace in macro
  17184. substitutions and appends another spurious suffix:
  17185. @example
  17186. empty =
  17187. foo = bar $(empty)
  17188. print: ; @@echo $(foo:=.test)
  17189. @end example
  17190. @noindent
  17191. prints @samp{bar.test .test}.
  17192. BSD and Solaris @command{make} implementations do not honor trailing
  17193. whitespace in macro definitions as Posix requires:
  17194. @example
  17195. foo = bar # Note the space after "bar".
  17196. print: ; @@echo $(foo)t
  17197. @end example
  17198. @noindent
  17199. prints @samp{bart} instead of @samp{bar t}. To work around this, you
  17200. can use a helper macro as in the previous example.
  17201. @node Command-line Macros and whitespace
  17202. @section Command-line Macros and whitespace
  17203. @cindex whitespace in command-line macros
  17204. @cindex command-line, macros set on
  17205. @cindex environment, macros set from
  17206. Some @command{make} implementations may strip trailing whitespace off
  17207. of macros set on the command line in addition to leading whitespace.
  17208. Further, some may strip leading whitespace off of macros set from
  17209. environment variables:
  17210. @example
  17211. $ @kbd{echo 'print: ; @@echo "x$(foo)x$(bar)x"' |
  17212. foo=' f f ' make -f - bar=' b b '}
  17213. x f f xb b x # AIX, BSD, GNU make
  17214. xf f xb b x # HP-UX, IRIX, Tru64/OSF make
  17215. x f f xb bx # Solaris make
  17216. @end example
  17217. @node obj/ and Make
  17218. @section The @file{obj/} Subdirectory and Make
  17219. @cindex @file{obj/}, subdirectory
  17220. @cindex BSD @command{make} and @file{obj/}
  17221. Never name one of your subdirectories @file{obj/} if you don't like
  17222. surprises.
  17223. If an @file{obj/} directory exists, BSD @command{make} enters it
  17224. before reading the makefile. Hence the makefile in the
  17225. current directory is not read.
  17226. @example
  17227. $ @kbd{cat Makefile}
  17228. all:
  17229. echo Hello
  17230. $ @kbd{cat obj/Makefile}
  17231. all:
  17232. echo World
  17233. $ @kbd{make} # GNU make
  17234. echo Hello
  17235. Hello
  17236. $ @kbd{pmake} # BSD make
  17237. echo World
  17238. World
  17239. @end example
  17240. @node make -k Status
  17241. @section Exit Status of @code{make -k}
  17242. @cindex @code{make -k}
  17243. Do not rely on the exit status of @code{make -k}. Some implementations
  17244. reflect whether they encountered an error in their exit status; other
  17245. implementations always succeed.
  17246. @example
  17247. $ @kbd{cat Makefile}
  17248. all:
  17249. false
  17250. $ @kbd{make -k; echo exit status: $?} # GNU make
  17251. false
  17252. make: *** [all] Error 1
  17253. exit status: 2
  17254. $ @kbd{pmake -k; echo exit status: $?} # BSD make
  17255. false
  17256. *** Error code 1 (continuing)
  17257. exit status: 0
  17258. @end example
  17259. @node VPATH and Make
  17260. @section @code{VPATH} and Make
  17261. @cindex @code{VPATH}
  17262. Posix does not specify the semantics of @code{VPATH}. Typically,
  17263. @command{make} supports @code{VPATH}, but its implementation is not
  17264. consistent.
  17265. Autoconf and Automake support makefiles whose usages of @code{VPATH} are
  17266. portable to recent-enough popular implementations of @command{make}, but
  17267. to keep the resulting makefiles portable, a package's makefile
  17268. prototypes must take the following issues into account. These issues
  17269. are complicated and are often poorly understood, and installers who use
  17270. @code{VPATH} should expect to find many bugs in this area. If you use
  17271. @code{VPATH}, the simplest way to avoid these portability bugs is to
  17272. stick with GNU @command{make}, since it is the most
  17273. commonly-used @command{make} among Autoconf users.
  17274. Here are some known issues with some @code{VPATH}
  17275. implementations.
  17276. @menu
  17277. * Variables listed in VPATH:: @code{VPATH} must be literal on ancient hosts
  17278. * VPATH and Double-colon:: Problems with @samp{::} on ancient hosts
  17279. * $< in Explicit Rules:: @code{$<} does not work in ordinary rules
  17280. * Automatic Rule Rewriting:: @code{VPATH} goes wild on Solaris
  17281. * Tru64 Directory Magic:: @command{mkdir} goes wild on Tru64
  17282. * Make Target Lookup:: More details about @code{VPATH} lookup
  17283. @end menu
  17284. @node Variables listed in VPATH
  17285. @subsection Variables listed in @code{VPATH}
  17286. @cindex @code{VPATH} and variables
  17287. @cindex variables and @code{VPATH}
  17288. Do not set @code{VPATH} to the value of another variable, for example
  17289. @samp{VPATH = $(srcdir)}, because some ancient versions of
  17290. @command{make} do not do variable substitutions on the value of
  17291. @code{VPATH}. For example, use this
  17292. @example
  17293. srcdir = @@srcdir@@
  17294. VPATH = @@srcdir@@
  17295. @end example
  17296. @noindent
  17297. rather than @samp{VPATH = $(srcdir)}. Note that with GNU
  17298. Automake, there is no need to set this yourself.
  17299. @node VPATH and Double-colon
  17300. @subsection @code{VPATH} and Double-colon Rules
  17301. @cindex @code{VPATH} and double-colon rules
  17302. @cindex double-colon rules and @code{VPATH}
  17303. With ancient versions of Sun @command{make},
  17304. any assignment to @code{VPATH} causes @command{make} to execute only
  17305. the first set of double-colon rules.
  17306. However, this problem is no longer of practical concern.
  17307. @node $< in Explicit Rules
  17308. @subsection @code{$<} Not Supported in Explicit Rules
  17309. @cindex explicit rules, @code{$<}, and @code{VPATH}
  17310. @cindex @code{$<}, explicit rules, and @code{VPATH}
  17311. @cindex @code{VPATH}, explicit rules, and @code{$<}
  17312. Using @code{$<} in explicit rules is not portable.
  17313. The prerequisite file must be named explicitly in the rule. If you want
  17314. to find the prerequisite via a @code{VPATH} search, you have to code the
  17315. whole thing manually. @xref{Build Directories}.
  17316. @node Automatic Rule Rewriting
  17317. @subsection Automatic Rule Rewriting
  17318. @cindex @code{VPATH} and automatic rule rewriting
  17319. @cindex automatic rule rewriting and @code{VPATH}
  17320. Some @command{make} implementations, such as Solaris and Tru64,
  17321. search for prerequisites in @code{VPATH} and
  17322. then rewrite each occurrence as a plain word in the rule.
  17323. For instance:
  17324. @example
  17325. # This isn't portable to GNU make.
  17326. VPATH = ../pkg/src
  17327. f.c: if.c
  17328. cp if.c f.c
  17329. @end example
  17330. @noindent
  17331. executes @code{cp ../pkg/src/if.c f.c} if @file{if.c} is
  17332. found in @file{../pkg/src}.
  17333. However, this rule leads to real problems in practice. For example, if
  17334. the source directory contains an ordinary file named @file{test} that is
  17335. used in a dependency, Solaris @command{make} rewrites commands like
  17336. @samp{if test -r foo; @dots{}} to @samp{if ../pkg/src/test -r foo;
  17337. @dots{}}, which is typically undesirable. In fact, @command{make} is
  17338. completely unaware of shell syntax used in the rules, so the VPATH
  17339. rewrite can potentially apply to @emph{any} whitespace-separated word
  17340. in a rule, including shell variables, functions, and keywords.
  17341. @example
  17342. $ @kbd{mkdir build}
  17343. $ @kbd{cd build}
  17344. $ @kbd{cat > Makefile <<'END'}
  17345. VPATH = ..
  17346. all: arg func for echo
  17347. func () @{ for arg in "$$@@"; do echo $$arg; done; @}; \
  17348. func "hello world"
  17349. END
  17350. $ @kbd{touch ../arg ../func ../for ../echo}
  17351. $ @kbd{make}
  17352. ../func () @{ ../for ../arg in "$@@"; do ../echo $arg; done; @}; \
  17353. ../func "hello world"
  17354. sh: syntax error at line 1: `do' unexpected
  17355. *** Error code 2
  17356. @end example
  17357. @noindent
  17358. To avoid this problem, portable makefiles should never mention a source
  17359. file or dependency whose name is that of a shell keyword like @file{for}
  17360. or @file{until}, a shell command like @command{cat} or @command{gcc} or
  17361. @command{test}, or a shell function or variable used in the corresponding
  17362. @command{Makefile} recipe.
  17363. Because of these problems GNU @command{make} and many other @command{make}
  17364. implementations do not rewrite commands, so portable makefiles should
  17365. search @code{VPATH} manually. It is tempting to write this:
  17366. @smallexample
  17367. # This isn't portable to Solaris make.
  17368. VPATH = ../pkg/src
  17369. f.c: if.c
  17370. cp `test -f if.c || echo $(VPATH)/`if.c f.c
  17371. @end smallexample
  17372. @noindent
  17373. However, the ``prerequisite rewriting'' still applies here. So if
  17374. @file{if.c} is in @file{../pkg/src}, Solaris and Tru64 @command{make}
  17375. execute
  17376. @smallexample
  17377. cp `test -f ../pkg/src/if.c || echo ../pkg/src/`if.c f.c
  17378. @end smallexample
  17379. @noindent
  17380. which reduces to
  17381. @example
  17382. cp if.c f.c
  17383. @end example
  17384. @noindent
  17385. and thus fails. Oops.
  17386. A simple workaround, and good practice anyway, is to use @samp{$?} and
  17387. @samp{$@@} when possible:
  17388. @smallexample
  17389. VPATH = ../pkg/src
  17390. f.c: if.c
  17391. cp $? $@@
  17392. @end smallexample
  17393. @noindent
  17394. but this does not generalize well to commands with multiple
  17395. prerequisites. A more general workaround is to rewrite the rule so that
  17396. the prerequisite @file{if.c} never appears as a plain word. For
  17397. example, these three rules would be safe, assuming @file{if.c} is in
  17398. @file{../pkg/src} and the other files are in the working directory:
  17399. @smallexample
  17400. VPATH = ../pkg/src
  17401. f.c: if.c f1.c
  17402. cat `test -f ./if.c || echo $(VPATH)/`if.c f1.c >$@@
  17403. g.c: if.c g1.c
  17404. cat `test -f 'if.c' || echo $(VPATH)/`if.c g1.c >$@@
  17405. h.c: if.c h1.c
  17406. cat `test -f "if.c" || echo $(VPATH)/`if.c h1.c >$@@
  17407. @end smallexample
  17408. Things get worse when your prerequisites are in a macro.
  17409. @example
  17410. VPATH = ../pkg/src
  17411. HEADERS = f.h g.h h.h
  17412. install-HEADERS: $(HEADERS)
  17413. for i in $(HEADERS); do \
  17414. $(INSTALL) -m 644 \
  17415. `test -f $$i || echo $(VPATH)/`$$i \
  17416. $(DESTDIR)$(includedir)/$$i; \
  17417. @c $$ restore font-lock
  17418. done
  17419. @end example
  17420. The above @code{install-HEADERS} rule is not Solaris-proof because @code{for
  17421. i in $(HEADERS);} is expanded to @code{for i in f.h g.h h.h;}
  17422. where @code{f.h} and @code{g.h} are plain words and are hence
  17423. subject to @code{VPATH} adjustments.
  17424. If the three files are in @file{../pkg/src}, the rule is run as:
  17425. @example
  17426. for i in ../pkg/src/f.h ../pkg/src/g.h h.h; do \
  17427. install -m 644 \
  17428. `test -f $i || echo ../pkg/src/`$i \
  17429. /usr/local/include/$i; \
  17430. done
  17431. @end example
  17432. where the two first @command{install} calls fail. For instance,
  17433. consider the @code{f.h} installation:
  17434. @example
  17435. install -m 644 \
  17436. `test -f ../pkg/src/f.h || \
  17437. echo ../pkg/src/ \
  17438. `../pkg/src/f.h \
  17439. /usr/local/include/../pkg/src/f.h;
  17440. @end example
  17441. @noindent
  17442. It reduces to:
  17443. @example
  17444. install -m 644 \
  17445. ../pkg/src/f.h \
  17446. /usr/local/include/../pkg/src/f.h;
  17447. @end example
  17448. Note that the manual @code{VPATH} search did not cause any problems here;
  17449. however this command installs @file{f.h} in an incorrect directory.
  17450. Trying to quote @code{$(HEADERS)} in some way, as we did for
  17451. @code{foo.c} a few makefiles ago, does not help:
  17452. @example
  17453. install-HEADERS: $(HEADERS)
  17454. headers='$(HEADERS)'; \
  17455. for i in $$headers; do \
  17456. $(INSTALL) -m 644 \
  17457. `test -f $$i || echo $(VPATH)/`$$i \
  17458. $(DESTDIR)$(includedir)/$$i; \
  17459. done
  17460. @end example
  17461. Now, @code{headers='$(HEADERS)'} macro-expands to:
  17462. @example
  17463. headers='f.h g.h h.h'
  17464. @end example
  17465. @noindent
  17466. but @code{g.h} is still a plain word. (As an aside, the idiom
  17467. @code{headers='$(HEADERS)'; for i in $$headers;} is a good
  17468. idea if @code{$(HEADERS)} can be empty, because some shells diagnose a
  17469. syntax error on @code{for i in;}.)
  17470. One workaround is to strip this unwanted @file{../pkg/src/} prefix manually:
  17471. @example
  17472. VPATH = ../pkg/src
  17473. HEADERS = f.h g.h h.h
  17474. install-HEADERS: $(HEADERS)
  17475. headers='$(HEADERS)'; \
  17476. for i in $$headers; do \
  17477. i=`expr "$$i" : '$(VPATH)/\(.*\)'`;
  17478. $(INSTALL) -m 644 \
  17479. `test -f $$i || echo $(VPATH)/`$$i \
  17480. $(DESTDIR)$(includedir)/$$i; \
  17481. @c $$ restore font-lock
  17482. done
  17483. @end example
  17484. Automake does something similar. However the above hack works only if
  17485. the files listed in @code{HEADERS} are in the current directory or a
  17486. subdirectory; they should not be in an enclosing directory. If we had
  17487. @code{HEADERS = ../f.h}, the above fragment would fail in a VPATH
  17488. build with Tru64 @command{make}. The reason is that not only does
  17489. Tru64 @command{make} rewrite dependencies, but it also simplifies
  17490. them. Hence @code{../f.h} becomes @code{../pkg/f.h} instead of
  17491. @code{../pkg/src/../f.h}. This obviously defeats any attempt to strip
  17492. a leading @file{../pkg/src/} component.
  17493. The following example makes the behavior of Tru64 @command{make}
  17494. more apparent.
  17495. @example
  17496. $ @kbd{cat Makefile}
  17497. VPATH = sub
  17498. all: ../foo
  17499. echo ../foo
  17500. $ @kbd{ls}
  17501. Makefile foo
  17502. $ @kbd{make}
  17503. echo foo
  17504. foo
  17505. @end example
  17506. @noindent
  17507. Dependency @file{../foo} was found in @file{sub/../foo}, but Tru64
  17508. @command{make} simplified it as @file{foo}. (Note that the @file{sub/}
  17509. directory does not even exist, this just means that the simplification
  17510. occurred before the file was checked for.)
  17511. For the record here is how SunOS 4 @command{make} behaves on this
  17512. example.
  17513. @smallexample
  17514. $ @kbd{make}
  17515. make: Fatal error: Don't know how to make target `../foo'
  17516. $ @kbd{mkdir sub}
  17517. $ @kbd{make}
  17518. echo sub/../foo
  17519. sub/../foo
  17520. @end smallexample
  17521. @node Tru64 Directory Magic
  17522. @subsection Tru64 @command{make} Creates Prerequisite Directories Magically
  17523. @cindex @code{VPATH} and prerequisite directories
  17524. @cindex prerequisite directories and @code{VPATH}
  17525. When a prerequisite is a subdirectory of @code{VPATH}, Tru64
  17526. @command{make} creates it in the current directory.
  17527. @example
  17528. $ @kbd{mkdir -p foo/bar build}
  17529. $ @kbd{cd build}
  17530. $ @kbd{cat >Makefile <<END
  17531. VPATH = ..
  17532. all: foo/bar
  17533. END}
  17534. $ @kbd{make}
  17535. mkdir foo
  17536. mkdir foo/bar
  17537. @end example
  17538. This can yield unexpected results if a rule uses a manual @code{VPATH}
  17539. search as presented before.
  17540. @example
  17541. VPATH = ..
  17542. all : foo/bar
  17543. command `test -d foo/bar || echo ../`foo/bar
  17544. @end example
  17545. The above @command{command} is run on the empty @file{foo/bar}
  17546. directory that was created in the current directory.
  17547. @node Make Target Lookup
  17548. @subsection Make Target Lookup
  17549. @cindex @code{VPATH}, resolving target pathnames
  17550. GNU @command{make} uses a complex algorithm to decide when it
  17551. should use files found via a @code{VPATH} search. @xref{Search
  17552. Algorithm, , How Directory Searches are Performed, make, The GNU Make
  17553. Manual}.
  17554. If a target needs to be rebuilt, GNU @command{make} discards the
  17555. file name found during the @code{VPATH} search for this target, and
  17556. builds the file locally using the file name given in the makefile.
  17557. If a target does not need to be rebuilt, GNU @command{make} uses the
  17558. file name found during the @code{VPATH} search.
  17559. Other @command{make} implementations, like NetBSD @command{make}, are
  17560. easier to describe: the file name found during the @code{VPATH} search
  17561. is used whether the target needs to be rebuilt or not. Therefore
  17562. new files are created locally, but existing files are updated at their
  17563. @code{VPATH} location.
  17564. OpenBSD and FreeBSD @command{make}, however,
  17565. never perform a
  17566. @code{VPATH} search for a dependency that has an explicit rule.
  17567. This is extremely annoying.
  17568. When attempting a @code{VPATH} build for an autoconfiscated package
  17569. (e.g., @code{mkdir build && cd build && ../configure}), this means
  17570. GNU
  17571. @command{make} builds everything locally in the @file{build}
  17572. directory, while BSD @command{make} builds new files locally and
  17573. updates existing files in the source directory.
  17574. @example
  17575. $ @kbd{cat Makefile}
  17576. VPATH = ..
  17577. all: foo.x bar.x
  17578. foo.x bar.x: newer.x
  17579. @@echo Building $@@
  17580. $ @kbd{touch ../bar.x}
  17581. $ @kbd{touch ../newer.x}
  17582. $ @kbd{make} # GNU make
  17583. Building foo.x
  17584. Building bar.x
  17585. $ @kbd{pmake} # NetBSD make
  17586. Building foo.x
  17587. Building ../bar.x
  17588. $ @kbd{fmake} # FreeBSD make, OpenBSD make
  17589. Building foo.x
  17590. Building bar.x
  17591. $ @kbd{tmake} # Tru64 make
  17592. Building foo.x
  17593. Building bar.x
  17594. $ @kbd{touch ../bar.x}
  17595. $ @kbd{make} # GNU make
  17596. Building foo.x
  17597. $ @kbd{pmake} # NetBSD make
  17598. Building foo.x
  17599. $ @kbd{fmake} # FreeBSD make, OpenBSD make
  17600. Building foo.x
  17601. Building bar.x
  17602. $ @kbd{tmake} # Tru64 make
  17603. Building foo.x
  17604. Building bar.x
  17605. @end example
  17606. Note how NetBSD @command{make} updates @file{../bar.x} in its
  17607. VPATH location, and how FreeBSD, OpenBSD, and Tru64
  17608. @command{make} always
  17609. update @file{bar.x}, even when @file{../bar.x} is up to date.
  17610. Another point worth mentioning is that once GNU @command{make} has
  17611. decided to ignore a @code{VPATH} file name (e.g., it ignored
  17612. @file{../bar.x} in the above example) it continues to ignore it when
  17613. the target occurs as a prerequisite of another rule.
  17614. The following example shows that GNU @command{make} does not look up
  17615. @file{bar.x} in @code{VPATH} before performing the @code{.x.y} rule,
  17616. because it ignored the @code{VPATH} result of @file{bar.x} while running
  17617. the @code{bar.x: newer.x} rule.
  17618. @example
  17619. $ @kbd{cat Makefile}
  17620. VPATH = ..
  17621. all: bar.y
  17622. bar.x: newer.x
  17623. @@echo Building $@@
  17624. .SUFFIXES: .x .y
  17625. .x.y:
  17626. cp $< $@@
  17627. $ @kbd{touch ../bar.x}
  17628. $ @kbd{touch ../newer.x}
  17629. $ @kbd{make} # GNU make
  17630. Building bar.x
  17631. cp bar.x bar.y
  17632. cp: cannot stat `bar.x': No such file or directory
  17633. make: *** [bar.y] Error 1
  17634. $ @kbd{pmake} # NetBSD make
  17635. Building ../bar.x
  17636. cp ../bar.x bar.y
  17637. $ @kbd{rm bar.y}
  17638. $ @kbd{fmake} # FreeBSD make, OpenBSD make
  17639. echo Building bar.x
  17640. cp bar.x bar.y
  17641. cp: cannot stat `bar.x': No such file or directory
  17642. *** Error code 1
  17643. $ @kbd{tmake} # Tru64 make
  17644. Building bar.x
  17645. cp: bar.x: No such file or directory
  17646. *** Exit 1
  17647. @end example
  17648. Note that if you drop away the command from the @code{bar.x: newer.x}
  17649. rule, GNU @command{make} magically starts to work: it
  17650. knows that @code{bar.x} hasn't been updated, therefore it doesn't
  17651. discard the result from @code{VPATH} (@file{../bar.x}) in succeeding
  17652. uses. Tru64 also works, but FreeBSD and OpenBSD
  17653. still don't.
  17654. @example
  17655. $ @kbd{cat Makefile}
  17656. VPATH = ..
  17657. all: bar.y
  17658. bar.x: newer.x
  17659. .SUFFIXES: .x .y
  17660. .x.y:
  17661. cp $< $@@
  17662. $ @kbd{touch ../bar.x}
  17663. $ @kbd{touch ../newer.x}
  17664. $ @kbd{make} # GNU make
  17665. cp ../bar.x bar.y
  17666. $ @kbd{rm bar.y}
  17667. $ @kbd{pmake} # NetBSD make
  17668. cp ../bar.x bar.y
  17669. $ @kbd{rm bar.y}
  17670. $ @kbd{fmake} # FreeBSD make, OpenBSD make
  17671. cp bar.x bar.y
  17672. cp: cannot stat `bar.x': No such file or directory
  17673. *** Error code 1
  17674. $ @kbd{tmake} # Tru64 make
  17675. cp ../bar.x bar.y
  17676. @end example
  17677. It seems the sole solution that would please every @command{make}
  17678. implementation is to never rely on @code{VPATH} searches for targets.
  17679. In other words, @code{VPATH} should be reserved to unbuilt sources.
  17680. @node Single Suffix Rules
  17681. @section Single Suffix Rules and Separated Dependencies
  17682. @cindex Single Suffix Inference Rule
  17683. @cindex Rule, Single Suffix Inference
  17684. A @dfn{Single Suffix Rule} is basically a usual suffix (inference) rule
  17685. (@samp{.from.to:}), but which @emph{destination} suffix is empty
  17686. (@samp{.from:}).
  17687. @cindex Separated Dependencies
  17688. @dfn{Separated dependencies} simply refers to listing the prerequisite
  17689. of a target, without defining a rule. Usually one can list on the one
  17690. hand side, the rules, and on the other hand side, the dependencies.
  17691. Solaris @command{make} does not support separated dependencies for
  17692. targets defined by single suffix rules:
  17693. @example
  17694. $ @kbd{cat Makefile}
  17695. .SUFFIXES: .in
  17696. foo: foo.in
  17697. .in:
  17698. cp $< $@@
  17699. $ @kbd{touch foo.in}
  17700. $ @kbd{make}
  17701. $ @kbd{ls}
  17702. Makefile foo.in
  17703. @end example
  17704. @noindent
  17705. while GNU Make does:
  17706. @example
  17707. $ @kbd{gmake}
  17708. cp foo.in foo
  17709. $ @kbd{ls}
  17710. Makefile foo foo.in
  17711. @end example
  17712. Note it works without the @samp{foo: foo.in} dependency.
  17713. @example
  17714. $ @kbd{cat Makefile}
  17715. .SUFFIXES: .in
  17716. .in:
  17717. cp $< $@@
  17718. $ @kbd{make foo}
  17719. cp foo.in foo
  17720. @end example
  17721. @noindent
  17722. and it works with double suffix inference rules:
  17723. @example
  17724. $ @kbd{cat Makefile}
  17725. foo.out: foo.in
  17726. .SUFFIXES: .in .out
  17727. .in.out:
  17728. cp $< $@@
  17729. $ @kbd{make}
  17730. cp foo.in foo.out
  17731. @end example
  17732. As a result, in such a case, you have to write target rules.
  17733. @node Timestamps and Make
  17734. @section Timestamp Resolution and Make
  17735. @cindex timestamp resolution
  17736. Traditionally, file timestamps had 1-second resolution, and
  17737. @command{make} used those timestamps to determine whether one file was
  17738. newer than the other. However, many modern file systems have
  17739. timestamps with 1-nanosecond resolution. Some @command{make}
  17740. implementations look at the entire timestamp; others ignore the
  17741. fractional part, which can lead to incorrect results. Normally this
  17742. is not a problem, but in some extreme cases you may need to use tricks
  17743. like @samp{sleep 1} to work around timestamp truncation bugs.
  17744. Commands like @samp{cp -p} and @samp{touch -r} typically do not copy
  17745. file timestamps to their full resolutions (@pxref{touch, , Limitations of Usual
  17746. Tools}). Hence you should be wary of rules like this:
  17747. @example
  17748. dest: src
  17749. cp -p src dest
  17750. @end example
  17751. as @file{dest} often appears to be older than @file{src} after the
  17752. timestamp is truncated, and this can cause @command{make} to do
  17753. needless rework the next time it is invoked. To work around this
  17754. problem, you can use a timestamp file, e.g.:
  17755. @example
  17756. dest-stamp: src
  17757. cp -p src dest
  17758. date >dest-stamp
  17759. @end example
  17760. Apart from timestamp resolution, there are also differences in handling
  17761. equal timestamps. HP-UX @command{make} updates targets if it has the
  17762. same time stamp as one of its prerequisites, in violation of Posix rules.
  17763. This can cause spurious rebuilds for repeated runs of @command{make}.
  17764. This in turn can cause @command{make} to fail if it tries to rebuild
  17765. generated files in a possibly read-only source tree with tools not
  17766. present on the end-user machine. Use GNU @command{make} instead.
  17767. @c ======================================== Portable C and C++ Programming
  17768. @node Portable C and C++
  17769. @chapter Portable C and C++ Programming
  17770. @cindex Portable C and C++ programming
  17771. C and C++ programs often use low-level features of the underlying
  17772. system, and therefore are often more difficult to make portable to other
  17773. platforms.
  17774. Several standards have been developed to help make your programs more
  17775. portable. If you write programs with these standards in mind, you can
  17776. have greater confidence that your programs work on a wide variety
  17777. of systems.
  17778. @ifhtml
  17779. @uref{http://@/gcc.gnu.org/@/onlinedocs/@/gcc/@/Standards.html, Language
  17780. Standards Supported by GCC}
  17781. @end ifhtml
  17782. @ifnothtml
  17783. @xref{Standards, , Language Standards Supported by
  17784. GCC, gcc, Using the GNU Compiler Collection
  17785. (GCC)},
  17786. @end ifnothtml
  17787. for a list of C-related standards. Many programs also assume the
  17788. @uref{http://@/www.opengroup.org/@/susv3, Posix standard}.
  17789. Some old code is written to be portable to K&R C, which predates any C
  17790. standard. K&R C compilers are no longer of practical interest, though,
  17791. and the rest of section assumes at least C89, the first C standard.
  17792. Program portability is a huge topic, and this section can only briefly
  17793. introduce common pitfalls. @xref{System Portability, , Portability
  17794. between System Types, standards, The GNU Coding Standards}, for
  17795. more information.
  17796. @menu
  17797. * Varieties of Unportability:: How to make your programs unportable
  17798. * Integer Overflow:: When integers get too large
  17799. * Preprocessor Arithmetic:: @code{#if} expression problems
  17800. * Null Pointers:: Properties of null pointers
  17801. * Buffer Overruns:: Subscript errors and the like
  17802. * Volatile Objects:: @code{volatile} and signals
  17803. * Floating Point Portability:: Portable floating-point arithmetic
  17804. * Exiting Portably:: Exiting and the exit status
  17805. @end menu
  17806. @node Varieties of Unportability
  17807. @section Varieties of Unportability
  17808. @cindex portability
  17809. Autoconf tests and ordinary programs often need to test what is allowed
  17810. on a system, and therefore they may need to deliberately exceed the
  17811. boundaries of what the standards allow, if only to see whether an
  17812. optional feature is present. When you write such a program, you should
  17813. keep in mind the difference between constraints, unspecified behavior,
  17814. and undefined behavior.
  17815. In C, a @dfn{constraint} is a rule that the compiler must enforce. An
  17816. example constraint is that C programs must not declare a bit-field with
  17817. negative width. Tests can therefore reliably assume that programs with
  17818. negative-width bit-fields are rejected by a compiler that conforms
  17819. to the standard.
  17820. @dfn{Unspecified behavior} is valid behavior, where the standard allows
  17821. multiple possibilities. For example, the order of evaluation of
  17822. function arguments is unspecified. Some unspecified behavior is
  17823. @dfn{implementation-defined}, i.e., documented by the implementation,
  17824. but since Autoconf tests cannot read the documentation they cannot
  17825. distinguish between implementation-defined and other unspecified
  17826. behavior. It is common for Autoconf tests to probe implementations to
  17827. determine otherwise-unspecified behavior.
  17828. @dfn{Undefined behavior} is invalid behavior, where the standard allows
  17829. the implementation to do anything it pleases. For example,
  17830. dereferencing a null pointer leads to undefined behavior. If possible,
  17831. test programs should avoid undefined behavior, since a program with
  17832. undefined behavior might succeed on a test that should fail.
  17833. The above rules apply to programs that are intended to conform to the
  17834. standard. However, strictly-conforming programs are quite rare, since
  17835. the standards are so limiting. A major goal of Autoconf is to support
  17836. programs that use implementation features not described by the standard,
  17837. and it is fairly common for test programs to violate the above rules, if
  17838. the programs work well enough in practice.
  17839. @node Integer Overflow
  17840. @section Integer Overflow
  17841. @cindex integer overflow
  17842. @cindex overflow, signed integer
  17843. @cindex signed integer overflow
  17844. @cindex wraparound arithmetic
  17845. In practice many portable C programs assume that signed integer overflow wraps
  17846. around reliably using two's complement arithmetic. Yet the C standard
  17847. says that program behavior is undefined on overflow, and in a few cases
  17848. C programs do not work on some modern implementations because their
  17849. overflows do not wrap around as their authors expected. Conversely, in
  17850. signed integer remainder, the C standard requires overflow
  17851. behavior that is commonly not implemented.
  17852. @menu
  17853. * Integer Overflow Basics:: Why integer overflow is a problem
  17854. * Signed Overflow Examples:: Examples of code assuming wraparound
  17855. * Optimization and Wraparound:: Optimizations that break uses of wraparound
  17856. * Signed Overflow Advice:: Practical advice for signed overflow issues
  17857. * Signed Integer Division:: @code{INT_MIN / -1} and @code{INT_MIN % -1}
  17858. @end menu
  17859. @node Integer Overflow Basics
  17860. @subsection Basics of Integer Overflow
  17861. @cindex integer overflow
  17862. @cindex overflow, signed integer
  17863. @cindex signed integer overflow
  17864. @cindex wraparound arithmetic
  17865. In languages like C, unsigned integer overflow reliably wraps around;
  17866. e.g., @code{UINT_MAX + 1} yields zero.
  17867. This is guaranteed by the C standard and is
  17868. portable in practice, unless you specify aggressive,
  17869. nonstandard optimization options
  17870. suitable only for special applications.
  17871. In contrast, the C standard says that signed integer overflow leads to
  17872. undefined behavior where a program can do anything, including dumping
  17873. core or overrunning a buffer. The misbehavior can even precede the
  17874. overflow. Such an overflow can occur during addition, subtraction,
  17875. multiplication, division, and left shift.
  17876. Despite this requirement of the standard, many C programs and Autoconf
  17877. tests assume that signed integer overflow silently wraps around modulo a
  17878. power of two, using two's complement arithmetic, so long as you cast the
  17879. resulting value to a signed integer type or store it into a signed
  17880. integer variable. If you use conservative optimization flags, such
  17881. programs are generally portable to the vast majority of modern
  17882. platforms, with a few exceptions discussed later.
  17883. For historical reasons the C standard also allows implementations with
  17884. ones' complement or signed magnitude arithmetic, but it is safe to
  17885. assume two's complement nowadays.
  17886. Also, overflow can occur when converting an out-of-range value to a
  17887. signed integer type. Here a standard implementation must define what
  17888. happens, but this might include raising an exception. In practice all
  17889. known implementations support silent wraparound in this case, so you need
  17890. not worry about other possibilities.
  17891. @node Signed Overflow Examples
  17892. @subsection Examples of Code Assuming Wraparound Overflow
  17893. @cindex integer overflow
  17894. @cindex overflow, signed integer
  17895. @cindex signed integer overflow
  17896. @cindex wraparound arithmetic
  17897. There has long been a tension between what the C standard requires for
  17898. signed integer overflow, and what C programs commonly assume. The
  17899. standard allows aggressive optimizations based on assumptions that
  17900. overflow never occurs, but many practical C programs rely on overflow
  17901. wrapping around. These programs do not conform to the standard, but
  17902. they commonly work in practice because compiler writers are
  17903. understandably reluctant to implement optimizations that would break
  17904. many programs, unless perhaps a user specifies aggressive optimization.
  17905. The C Standard says that if a program has signed integer overflow its
  17906. behavior is undefined, and the undefined behavior can even precede the
  17907. overflow. To take an extreme example:
  17908. @c Inspired by Robert Dewar's example in
  17909. @c <http://gcc.gnu.org/ml/gcc/2007-01/msg00038.html> (2007-01-01).
  17910. @example
  17911. if (password == expected_password)
  17912. allow_superuser_privileges ();
  17913. else if (counter++ == INT_MAX)
  17914. abort ();
  17915. else
  17916. printf ("%d password mismatches\n", counter);
  17917. @end example
  17918. @noindent
  17919. If the @code{int} variable @code{counter} equals @code{INT_MAX},
  17920. @code{counter++} must overflow and the behavior is undefined, so the C
  17921. standard allows the compiler to optimize away the test against
  17922. @code{INT_MAX} and the @code{abort} call.
  17923. Worse, if an earlier bug in the program lets the compiler deduce that
  17924. @code{counter == INT_MAX} or that @code{counter} previously overflowed,
  17925. the C standard allows the compiler to optimize away the password test
  17926. and generate code that allows superuser privileges unconditionally.
  17927. Despite this requirement by the standard, it has long been common for C
  17928. code to assume wraparound arithmetic after signed overflow, and all
  17929. known practical C implementations support some C idioms that assume
  17930. wraparound signed arithmetic, even if the idioms do not conform
  17931. strictly to the standard. If your code looks like the following
  17932. examples it will almost surely work with real-world compilers.
  17933. Here is an example derived from the 7th Edition Unix implementation of
  17934. @code{atoi} (1979-01-10):
  17935. @example
  17936. char *p;
  17937. int f, n;
  17938. @dots{}
  17939. while (*p >= '0' && *p <= '9')
  17940. n = n * 10 + *p++ - '0';
  17941. return (f ? -n : n);
  17942. @end example
  17943. @noindent
  17944. Even if the input string is in range, on most modern machines this has
  17945. signed overflow when computing the most negative integer (the @code{-n}
  17946. overflows) or a value near an extreme integer (the first @code{+}
  17947. overflows).
  17948. Here is another example, derived from the 7th Edition implementation of
  17949. @code{rand} (1979-01-10). Here the programmer expects both
  17950. multiplication and addition to wrap on overflow:
  17951. @example
  17952. static long int randx = 1;
  17953. @dots{}
  17954. randx = randx * 1103515245 + 12345;
  17955. return (randx >> 16) & 077777;
  17956. @end example
  17957. In the following example, derived from the GNU C Library 2.5
  17958. implementation of @code{mktime} (2006-09-09), the code assumes
  17959. wraparound arithmetic in @code{+} to detect signed overflow:
  17960. @example
  17961. time_t t, t1, t2;
  17962. int sec_requested, sec_adjustment;
  17963. @dots{}
  17964. t1 = t + sec_requested;
  17965. t2 = t1 + sec_adjustment;
  17966. if (((t1 < t) != (sec_requested < 0))
  17967. | ((t2 < t1) != (sec_adjustment < 0)))
  17968. return -1;
  17969. @end example
  17970. If your code looks like these examples, it is probably safe even though
  17971. it does not strictly conform to the C standard. This might lead one to
  17972. believe that one can generally assume wraparound on overflow, but that
  17973. is not always true, as can be seen in the next section.
  17974. @node Optimization and Wraparound
  17975. @subsection Optimizations That Break Wraparound Arithmetic
  17976. @cindex loop induction
  17977. Compilers sometimes generate code that is incompatible with wraparound
  17978. integer arithmetic. A simple example is an algebraic simplification: a
  17979. compiler might translate @code{(i * 2000) / 1000} to @code{i * 2}
  17980. because it assumes that @code{i * 2000} does not overflow. The
  17981. translation is not equivalent to the original when overflow occurs:
  17982. e.g., in the typical case of 32-bit signed two's complement wraparound
  17983. @code{int}, if @code{i} has type @code{int} and value @code{1073742},
  17984. the original expression returns @minus{}2147483 but the optimized
  17985. version returns the mathematically correct value 2147484.
  17986. More subtly, loop induction optimizations often exploit the undefined
  17987. behavior of signed overflow. Consider the following contrived function
  17988. @code{sumc}:
  17989. @example
  17990. int
  17991. sumc (int lo, int hi)
  17992. @{
  17993. int sum = 0;
  17994. int i;
  17995. for (i = lo; i <= hi; i++)
  17996. sum ^= i * 53;
  17997. return sum;
  17998. @}
  17999. @end example
  18000. @noindent
  18001. To avoid multiplying by 53 each time through the loop, an optimizing
  18002. compiler might internally transform @code{sumc} to the equivalent of the
  18003. following:
  18004. @example
  18005. int
  18006. transformed_sumc (int lo, int hi)
  18007. @{
  18008. int sum = 0;
  18009. int hic = hi * 53;
  18010. int ic;
  18011. for (ic = lo * 53; ic <= hic; ic += 53)
  18012. sum ^= ic;
  18013. return sum;
  18014. @}
  18015. @end example
  18016. @noindent
  18017. This transformation is allowed by the C standard, but it is invalid for
  18018. wraparound arithmetic when @code{INT_MAX / 53 < hi}, because then the
  18019. overflow in computing expressions like @code{hi * 53} can cause the
  18020. expression @code{i <= hi} to yield a different value from the
  18021. transformed expression @code{ic <= hic}.
  18022. For this reason, compilers that use loop induction and similar
  18023. techniques often do not support reliable wraparound arithmetic when a
  18024. loop induction variable like @code{ic} is involved. Since loop
  18025. induction variables are generated by the compiler, and are not visible
  18026. in the source code, it is not always trivial to say whether the problem
  18027. affects your code.
  18028. Hardly any code actually depends on wraparound arithmetic in cases like
  18029. these, so in practice these loop induction optimizations are almost
  18030. always useful. However, edge cases in this area can cause problems.
  18031. For example:
  18032. @example
  18033. int j;
  18034. for (j = 1; 0 < j; j *= 2)
  18035. test (j);
  18036. @end example
  18037. @noindent
  18038. Here, the loop attempts to iterate through all powers of 2 that
  18039. @code{int} can represent, but the C standard allows a compiler to
  18040. optimize away the comparison and generate an infinite loop,
  18041. under the argument that behavior is undefined on overflow. As of this
  18042. writing this optimization is not done by any production version of
  18043. GCC with @option{-O2}, but it might be performed by other
  18044. compilers, or by more aggressive GCC optimization options,
  18045. and the GCC developers have not decided whether it will
  18046. continue to work with GCC and @option{-O2}.
  18047. @node Signed Overflow Advice
  18048. @subsection Practical Advice for Signed Overflow Issues
  18049. @cindex integer overflow
  18050. @cindex overflow, signed integer
  18051. @cindex signed integer overflow
  18052. @cindex wraparound arithmetic
  18053. Ideally the safest approach is to avoid signed integer overflow
  18054. entirely. For example, instead of multiplying two signed integers, you
  18055. can convert them to unsigned integers, multiply the unsigned values,
  18056. then test whether the result is in signed range.
  18057. Rewriting code in this way will be inconvenient, though, particularly if
  18058. the signed values might be negative. Also, it may hurt
  18059. performance. Using unsigned arithmetic to check for overflow is
  18060. particularly painful to do portably and efficiently when dealing with an
  18061. integer type like @code{uid_t} whose width and signedness vary from
  18062. platform to platform.
  18063. Furthermore, many C applications pervasively assume wraparound behavior
  18064. and typically it is not easy to find and remove all these assumptions.
  18065. Hence it is often useful to maintain nonstandard code that assumes
  18066. wraparound on overflow, instead of rewriting the code. The rest of this
  18067. section attempts to give practical advice for this situation.
  18068. If your code wants to detect signed integer overflow in @code{sum = a +
  18069. b}, it is generally safe to use an expression like @code{(sum < a) != (b
  18070. < 0)}.
  18071. If your code uses a signed loop index, make sure that the index cannot
  18072. overflow, along with all signed expressions derived from the index.
  18073. Here is a contrived example of problematic code with two instances of
  18074. overflow.
  18075. @example
  18076. for (i = INT_MAX - 10; i <= INT_MAX; i++)
  18077. if (i + 1 < 0)
  18078. @{
  18079. report_overflow ();
  18080. break;
  18081. @}
  18082. @end example
  18083. @noindent
  18084. Because of the two overflows, a compiler might optimize away or
  18085. transform the two comparisons in a way that is incompatible with the
  18086. wraparound assumption.
  18087. If your code uses an expression like @code{(i * 2000) / 1000} and you
  18088. actually want the multiplication to wrap around on overflow, use
  18089. unsigned arithmetic
  18090. to do it, e.g., @code{((int) (i * 2000u)) / 1000}.
  18091. If your code assumes wraparound behavior and you want to insulate it
  18092. against any GCC optimizations that would fail to support that
  18093. behavior, you should use GCC's @option{-fwrapv} option, which
  18094. causes signed overflow to wrap around reliably (except for division and
  18095. remainder, as discussed in the next section).
  18096. If you need to port to platforms where signed integer overflow does not
  18097. reliably wrap around (e.g., due to hardware overflow checking, or to
  18098. highly aggressive optimizations), you should consider debugging with
  18099. GCC's @option{-ftrapv} option, which causes signed overflow to
  18100. raise an exception.
  18101. @node Signed Integer Division
  18102. @subsection Signed Integer Division and Integer Overflow
  18103. @cindex division, integer
  18104. Overflow in signed
  18105. integer division is not always harmless: for example, on CPUs of the
  18106. i386 family, dividing @code{INT_MIN} by @code{-1} yields a SIGFPE signal
  18107. which by default terminates the program. Worse, taking the remainder
  18108. of these two values typically yields the same signal on these CPUs,
  18109. even though the C standard requires @code{INT_MIN % -1} to yield zero
  18110. because the expression does not overflow.
  18111. @node Preprocessor Arithmetic
  18112. @section Preprocessor Arithmetic
  18113. @cindex preprocessor arithmetic
  18114. In C99, preprocessor arithmetic, used for @code{#if} expressions, must
  18115. be evaluated as if all signed values are of type @code{intmax_t} and all
  18116. unsigned values of type @code{uintmax_t}. Many compilers are buggy in
  18117. this area, though. For example, as of 2007, Sun C mishandles @code{#if
  18118. LLONG_MIN < 0} on a platform with 32-bit @code{long int} and 64-bit
  18119. @code{long long int}. Also, some older preprocessors mishandle
  18120. constants ending in @code{LL}. To work around these problems, you can
  18121. compute the value of expressions like @code{LONG_MAX < LLONG_MAX} at
  18122. @code{configure}-time rather than at @code{#if}-time.
  18123. @node Null Pointers
  18124. @section Properties of Null Pointers
  18125. @cindex null pointers
  18126. Most modern hosts reliably fail when you attempt to dereference a null
  18127. pointer.
  18128. On almost all modern hosts, null pointers use an all-bits-zero internal
  18129. representation, so you can reliably use @code{memset} with 0 to set all
  18130. the pointers in an array to null values.
  18131. If @code{p} is a null pointer to an object type, the C expression
  18132. @code{p + 0} always evaluates to @code{p} on modern hosts, even though
  18133. the standard says that it has undefined behavior.
  18134. @node Buffer Overruns
  18135. @section Buffer Overruns and Subscript Errors
  18136. @cindex buffer overruns
  18137. Buffer overruns and subscript errors are the most common dangerous
  18138. errors in C programs. They result in undefined behavior because storing
  18139. outside an array typically modifies storage that is used by some other
  18140. object, and most modern systems lack runtime checks to catch these
  18141. errors. Programs should not rely on buffer overruns being caught.
  18142. There is one exception to the usual rule that a portable program cannot
  18143. address outside an array. In C, it is valid to compute the address just
  18144. past an object, e.g., @code{&a[N]} where @code{a} has @code{N} elements,
  18145. so long as you do not dereference the resulting pointer. But it is not
  18146. valid to compute the address just before an object, e.g., @code{&a[-1]};
  18147. nor is it valid to compute two past the end, e.g., @code{&a[N+1]}. On
  18148. most platforms @code{&a[-1] < &a[0] && &a[N] < &a[N+1]}, but this is not
  18149. reliable in general, and it is usually easy enough to avoid the
  18150. potential portability problem, e.g., by allocating an extra unused array
  18151. element at the start or end.
  18152. @uref{http://@/valgrind.org/, Valgrind} can catch many overruns.
  18153. GCC
  18154. users might also consider using the @option{-fmudflap} option to catch
  18155. overruns.
  18156. Buffer overruns are usually caused by off-by-one errors, but there are
  18157. more subtle ways to get them.
  18158. Using @code{int} values to index into an array or compute array sizes
  18159. causes problems on typical 64-bit hosts where an array index might
  18160. be @math{2^{31}} or larger. Index values of type @code{size_t} avoid this
  18161. problem, but cannot be negative. Index values of type @code{ptrdiff_t}
  18162. are signed, and are wide enough in practice.
  18163. If you add or multiply two numbers to calculate an array size, e.g.,
  18164. @code{malloc (x * sizeof y + z)}, havoc ensues if the addition or
  18165. multiplication overflows.
  18166. Many implementations of the @code{alloca} function silently misbehave
  18167. and can generate buffer overflows if given sizes that are too large.
  18168. The size limits are implementation dependent, but are at least 4000
  18169. bytes on all platforms that we know about.
  18170. The standard functions @code{asctime}, @code{asctime_r}, @code{ctime},
  18171. @code{ctime_r}, and @code{gets} are prone to buffer overflows, and
  18172. portable code should not use them unless the inputs are known to be
  18173. within certain limits. The time-related functions can overflow their
  18174. buffers if given timestamps out of range (e.g., a year less than -999
  18175. or greater than 9999). Time-related buffer overflows cannot happen with
  18176. recent-enough versions of the GNU C library, but are possible
  18177. with other
  18178. implementations. The @code{gets} function is the worst, since it almost
  18179. invariably overflows its buffer when presented with an input line larger
  18180. than the buffer.
  18181. @node Volatile Objects
  18182. @section Volatile Objects
  18183. @cindex volatile objects
  18184. The keyword @code{volatile} is often misunderstood in portable code.
  18185. Its use inhibits some memory-access optimizations, but programmers often
  18186. wish that it had a different meaning than it actually does.
  18187. @code{volatile} was designed for code that accesses special objects like
  18188. memory-mapped device registers whose contents spontaneously change.
  18189. Such code is inherently low-level, and it is difficult to specify
  18190. portably what @code{volatile} means in these cases. The C standard
  18191. says, ``What constitutes an access to an object that has
  18192. volatile-qualified type is implementation-defined,'' so in theory each
  18193. implementation is supposed to fill in the gap by documenting what
  18194. @code{volatile} means for that implementation. In practice, though,
  18195. this documentation is usually absent or incomplete.
  18196. One area of confusion is the distinction between objects defined with
  18197. volatile types, and volatile lvalues. From the C standard's point of
  18198. view, an object defined with a volatile type has externally visible
  18199. behavior. You can think of such objects as having little oscilloscope
  18200. probes attached to them, so that the user can observe some properties of
  18201. accesses to them, just as the user can observe data written to output
  18202. files. However, the standard does not make it clear whether users can
  18203. observe accesses by volatile lvalues to ordinary objects. For example:
  18204. @example
  18205. /* Declare and access a volatile object.
  18206. Accesses to X are "visible" to users. */
  18207. static int volatile x;
  18208. x = 1;
  18209. /* Access two ordinary objects via a volatile lvalue.
  18210. It's not clear whether accesses to *P are "visible". */
  18211. int y;
  18212. int *z = malloc (sizeof (int));
  18213. int volatile *p;
  18214. p = &y;
  18215. *p = 1;
  18216. p = z;
  18217. *p = 1;
  18218. @end example
  18219. Programmers often wish that @code{volatile} meant ``Perform the memory
  18220. access here and now, without merging several memory accesses, without
  18221. changing the memory word size, and without reordering.'' But the C
  18222. standard does not require this. For objects defined with a volatile
  18223. type, accesses must be done before the next sequence point; but
  18224. otherwise merging, reordering, and word-size change is allowed. Worse,
  18225. it is not clear from the standard whether volatile lvalues provide more
  18226. guarantees in general than nonvolatile lvalues, if the underlying
  18227. objects are ordinary.
  18228. Even when accessing objects defined with a volatile type,
  18229. the C standard allows only
  18230. extremely limited signal handlers: the behavior is undefined if a signal
  18231. handler reads any nonlocal object, or writes to any nonlocal object
  18232. whose type is not @code{sig_atomic_t volatile}, or calls any standard
  18233. library function other than @code{abort}, @code{signal}, and (if C99)
  18234. @code{_Exit}. Hence C compilers need not worry about a signal handler
  18235. disturbing ordinary computation, unless the computation accesses a
  18236. @code{sig_atomic_t volatile} lvalue that is not a local variable.
  18237. (There is an obscure exception for accesses via a pointer to a volatile
  18238. character, since it may point into part of a @code{sig_atomic_t
  18239. volatile} object.) Posix
  18240. adds to the list of library functions callable from a portable signal
  18241. handler, but otherwise is like the C standard in this area.
  18242. Some C implementations allow memory-access optimizations within each
  18243. translation unit, such that actual behavior agrees with the behavior
  18244. required by the standard only when calling a function in some other
  18245. translation unit, and a signal handler acts like it was called from a
  18246. different translation unit. The C standard hints that in these
  18247. implementations, objects referred to by signal handlers ``would require
  18248. explicit specification of @code{volatile} storage, as well as other
  18249. implementation-defined restrictions.'' But unfortunately even for this
  18250. special case these other restrictions are often not documented well.
  18251. @xref{Volatiles, , When is a Volatile Object Accessed?, gcc, Using the
  18252. GNU Compiler Collection (GCC)}, for some
  18253. restrictions imposed by GCC. @xref{Defining Handlers, ,
  18254. Defining Signal Handlers, libc, The GNU C Library}, for some
  18255. restrictions imposed by the GNU C library. Restrictions
  18256. differ on other platforms.
  18257. If possible, it is best to use a signal handler that fits within the
  18258. limits imposed by the C and Posix standards.
  18259. If this is not practical, you can try the following rules of thumb. A
  18260. signal handler should access only volatile lvalues, preferably lvalues
  18261. that refer to objects defined with a volatile type, and should not
  18262. assume that the accessed objects have an internally consistent state
  18263. if they are larger than a machine word. Furthermore, installers
  18264. should employ compilers and compiler options that are commonly used
  18265. for building operating system kernels, because kernels often need more
  18266. from @code{volatile} than the C Standard requires, and installers who
  18267. compile an application in a similar environment can sometimes benefit
  18268. from the extra constraints imposed by kernels on compilers.
  18269. Admittedly we are handwaving somewhat here, as there are few
  18270. guarantees in this area; the rules of thumb may help to fix some bugs
  18271. but there is a good chance that they will not fix them all.
  18272. For @code{volatile}, C++ has the same problems that C does.
  18273. Multithreaded applications have even more problems with @code{volatile},
  18274. but they are beyond the scope of this section.
  18275. The bottom line is that using @code{volatile} typically hurts
  18276. performance but should not hurt correctness. In some cases its use
  18277. does help correctness, but these cases are often so poorly understood
  18278. that all too often adding @code{volatile} to a data structure merely
  18279. alleviates some symptoms of a bug while not fixing the bug in general.
  18280. @node Floating Point Portability
  18281. @section Floating Point Portability
  18282. @cindex floating point
  18283. Almost all modern systems use IEEE-754 floating point, and it is safe to
  18284. assume IEEE-754 in most portable code these days. For more information,
  18285. please see David Goldberg's classic paper
  18286. @uref{http://@/www.validlab.com/@/goldberg/@/paper.pdf, What Every Computer
  18287. Scientist Should Know About Floating-Point Arithmetic}.
  18288. @node Exiting Portably
  18289. @section Exiting Portably
  18290. @cindex exiting portably
  18291. A C or C++ program can exit with status @var{N} by returning
  18292. @var{N} from the @code{main} function. Portable programs are supposed
  18293. to exit either with status 0 or @code{EXIT_SUCCESS} to succeed, or with
  18294. status @code{EXIT_FAILURE} to fail, but in practice it is portable to
  18295. fail by exiting with status 1, and test programs that assume Posix can
  18296. fail by exiting with status values from 1 through 255. Programs on
  18297. SunOS 2.0 (1985) through 3.5.2 (1988) incorrectly exited with zero
  18298. status when @code{main} returned nonzero, but ancient systems like these
  18299. are no longer of practical concern.
  18300. A program can also exit with status @var{N} by passing @var{N} to the
  18301. @code{exit} function, and a program can fail by calling the @code{abort}
  18302. function. If a program is specialized to just some platforms, it can fail
  18303. by calling functions specific to those platforms, e.g., @code{_exit}
  18304. (Posix) and @code{_Exit} (C99). However, like other functions, an exit
  18305. function should be declared, typically by including a header. For
  18306. example, if a C program calls @code{exit}, it should include @file{stdlib.h}
  18307. either directly or via the default includes (@pxref{Default Includes}).
  18308. A program can fail due to undefined behavior such as dereferencing a null
  18309. pointer, but this is not recommended as undefined behavior allows an
  18310. implementation to do whatever it pleases and this includes exiting
  18311. successfully.
  18312. @c ================================================== Manual Configuration
  18313. @node Manual Configuration
  18314. @chapter Manual Configuration
  18315. A few kinds of features can't be guessed automatically by running test
  18316. programs. For example, the details of the object-file format, or
  18317. special options that need to be passed to the compiler or linker. You
  18318. can check for such features using ad-hoc means, such as having
  18319. @command{configure} check the output of the @code{uname} program, or
  18320. looking for libraries that are unique to particular systems. However,
  18321. Autoconf provides a uniform method for handling unguessable features.
  18322. @menu
  18323. * Specifying Target Triplets:: Specifying target triplets
  18324. * Canonicalizing:: Getting the canonical system type
  18325. * Using System Type:: What to do with the system type
  18326. @end menu
  18327. @node Specifying Target Triplets
  18328. @section Specifying target triplets
  18329. @cindex System type
  18330. @cindex Target triplet
  18331. @c This node used to be named Specifying Names. The @anchor allows old
  18332. @c links to still work.
  18333. @anchor{Specifying Names}
  18334. Autoconf-generated
  18335. @command{configure} scripts can make decisions based on a canonical name
  18336. for the system type, or @dfn{target triplet}, which has the form:
  18337. @samp{@var{cpu}-@var{vendor}-@var{os}}, where @var{os} can be
  18338. @samp{@var{system}} or @samp{@var{kernel}-@var{system}}
  18339. @command{configure} can usually guess the canonical name for the type of
  18340. system it's running on. To do so it runs a script called
  18341. @command{config.guess}, which infers the name using the @code{uname}
  18342. command or symbols predefined by the C preprocessor.
  18343. Alternately, the user can specify the system type with command line
  18344. arguments to @command{configure} (@pxref{System Type}. Doing so is
  18345. necessary when
  18346. cross-compiling. In the most complex case of cross-compiling, three
  18347. system types are involved. The options to specify them are:
  18348. @table @option
  18349. @item --build=@var{build-type}
  18350. the type of system on which the package is being configured and
  18351. compiled. It defaults to the result of running @command{config.guess}.
  18352. Specifying a @var{build-type} that differs from @var{host-type} enables
  18353. cross-compilation mode.
  18354. @item --host=@var{host-type}
  18355. the type of system on which the package runs. By default it is the
  18356. same as the build machine. Specifying a @var{host-type} that differs
  18357. from @var{build-type}, when @var{build-type} was also explicitly
  18358. specified, enables cross-compilation mode.
  18359. @item --target=@var{target-type}
  18360. the type of system for which any compiler tools in the package
  18361. produce code (rarely needed). By default, it is the same as host.
  18362. @end table
  18363. If you mean to override the result of @command{config.guess}, use
  18364. @option{--build}, not @option{--host}, since the latter enables
  18365. cross-compilation. For historical reasons,
  18366. whenever you specify @option{--host},
  18367. be sure to specify @option{--build} too; this will be fixed in the
  18368. future. So, to enter cross-compilation mode, use a command like this
  18369. @example
  18370. ./configure --build=i686-pc-linux-gnu --host=m68k-coff
  18371. @end example
  18372. @noindent
  18373. Note that if you do not specify @option{--host}, @command{configure}
  18374. fails if it can't run the code generated by the specified compiler. For
  18375. example, configuring as follows fails:
  18376. @example
  18377. ./configure CC=m68k-coff-gcc
  18378. @end example
  18379. When cross-compiling, @command{configure} will warn about any tools
  18380. (compilers, linkers, assemblers) whose name is not prefixed with the
  18381. host type. This is an aid to users performing cross-compilation.
  18382. Continuing the example above, if a cross-compiler named @command{cc} is
  18383. used with a native @command{pkg-config}, then libraries found by
  18384. @command{pkg-config} will likely cause subtle build failures; but using
  18385. the names @command{m68k-coff-cc} and @command{m68k-coff-pkg-config}
  18386. avoids any confusion. Avoiding the warning is as simple as creating the
  18387. correct symlinks naming the cross tools.
  18388. @cindex @command{config.sub}
  18389. @command{configure} recognizes short aliases for many system types; for
  18390. example, @samp{decstation} can be used instead of
  18391. @samp{mips-dec-ultrix4.2}. @command{configure} runs a script called
  18392. @command{config.sub} to canonicalize system type aliases.
  18393. This section deliberately omits the description of the obsolete
  18394. interface; see @ref{Hosts and Cross-Compilation}.
  18395. @node Canonicalizing
  18396. @section Getting the Canonical System Type
  18397. @cindex System type
  18398. @cindex Canonical system type
  18399. The following macros make the system type available to @command{configure}
  18400. scripts.
  18401. @ovindex build_alias
  18402. @ovindex host_alias
  18403. @ovindex target_alias
  18404. The variables @samp{build_alias}, @samp{host_alias}, and
  18405. @samp{target_alias} are always exactly the arguments of @option{--build},
  18406. @option{--host}, and @option{--target}; in particular, they are left empty
  18407. if the user did not use them, even if the corresponding
  18408. @code{AC_CANONICAL} macro was run. Any configure script may use these
  18409. variables anywhere. These are the variables that should be used when in
  18410. interaction with the user.
  18411. If you need to recognize some special environments based on their system
  18412. type, run the following macros to get canonical system names. These
  18413. variables are not set before the macro call.
  18414. If you use these macros, you must distribute @command{config.guess} and
  18415. @command{config.sub} along with your source code. @xref{Output}, for
  18416. information about the @code{AC_CONFIG_AUX_DIR} macro which you can use
  18417. to control in which directory @command{configure} looks for those scripts.
  18418. @defmac AC_CANONICAL_BUILD
  18419. @acindex{CANONICAL_BUILD}
  18420. @ovindex build
  18421. @ovindex build_cpu
  18422. @ovindex build_vendor
  18423. @ovindex build_os
  18424. Compute the canonical build-system type variable, @code{build}, and its
  18425. three individual parts @code{build_cpu}, @code{build_vendor}, and
  18426. @code{build_os}.
  18427. If @option{--build} was specified, then @code{build} is the
  18428. canonicalization of @code{build_alias} by @command{config.sub},
  18429. otherwise it is determined by the shell script @command{config.guess}.
  18430. @end defmac
  18431. @defmac AC_CANONICAL_HOST
  18432. @acindex{CANONICAL_HOST}
  18433. @ovindex host
  18434. @ovindex host_cpu
  18435. @ovindex host_vendor
  18436. @ovindex host_os
  18437. Compute the canonical host-system type variable, @code{host}, and its
  18438. three individual parts @code{host_cpu}, @code{host_vendor}, and
  18439. @code{host_os}.
  18440. If @option{--host} was specified, then @code{host} is the
  18441. canonicalization of @code{host_alias} by @command{config.sub},
  18442. otherwise it defaults to @code{build}.
  18443. @end defmac
  18444. @defmac AC_CANONICAL_TARGET
  18445. @acindex{CANONICAL_TARGET}
  18446. @ovindex target
  18447. @ovindex target_cpu
  18448. @ovindex target_vendor
  18449. @ovindex target_os
  18450. Compute the canonical target-system type variable, @code{target}, and its
  18451. three individual parts @code{target_cpu}, @code{target_vendor}, and
  18452. @code{target_os}.
  18453. If @option{--target} was specified, then @code{target} is the
  18454. canonicalization of @code{target_alias} by @command{config.sub},
  18455. otherwise it defaults to @code{host}.
  18456. @end defmac
  18457. Note that there can be artifacts due to the backward compatibility
  18458. code. @xref{Hosts and Cross-Compilation}, for more.
  18459. @node Using System Type
  18460. @section Using the System Type
  18461. In @file{configure.ac} the system type is generally used by one or more
  18462. @code{case} statements to select system-specifics. Shell wildcards can
  18463. be used to match a group of system types.
  18464. For example, an extra assembler code object file could be chosen, giving
  18465. access to a CPU cycle counter register. @code{$(CYCLE_OBJ)} in the
  18466. following would be used in a makefile to add the object to a
  18467. program or library.
  18468. @example
  18469. AS_CASE([$host],
  18470. [alpha*-*-*], [CYCLE_OBJ=rpcc.o],
  18471. [i?86-*-*], [CYCLE_OBJ=rdtsc.o],
  18472. [CYCLE_OBJ=""]
  18473. )
  18474. AC_SUBST([CYCLE_OBJ])
  18475. @end example
  18476. @code{AC_CONFIG_LINKS} (@pxref{Configuration Links}) is another good way
  18477. to select variant source files, for example optimized code for some
  18478. CPUs. The configured CPU type doesn't always indicate exact CPU types,
  18479. so some runtime capability checks may be necessary too.
  18480. @example
  18481. case $host in
  18482. alpha*-*-*) AC_CONFIG_LINKS([dither.c:alpha/dither.c]) ;;
  18483. powerpc*-*-*) AC_CONFIG_LINKS([dither.c:powerpc/dither.c]) ;;
  18484. *-*-*) AC_CONFIG_LINKS([dither.c:generic/dither.c]) ;;
  18485. esac
  18486. @end example
  18487. The host system type can also be used to find cross-compilation tools
  18488. with @code{AC_CHECK_TOOL} (@pxref{Generic Programs}).
  18489. The above examples all show @samp{$host}, since this is where the code
  18490. is going to run. Only rarely is it necessary to test @samp{$build}
  18491. (which is where the build is being done).
  18492. Whenever you're tempted to use @samp{$host} it's worth considering
  18493. whether some sort of probe would be better. New system types come along
  18494. periodically or previously missing features are added. Well-written
  18495. probes can adapt themselves to such things, but hard-coded lists of
  18496. names can't. Here are some guidelines,
  18497. @itemize @bullet
  18498. @item
  18499. Availability of libraries and library functions should always be checked
  18500. by probing.
  18501. @item
  18502. Variant behavior of system calls is best identified with runtime tests
  18503. if possible, but bug workarounds or obscure difficulties might have to
  18504. be driven from @samp{$host}.
  18505. @item
  18506. Assembler code is inevitably highly CPU-specific and is best selected
  18507. according to @samp{$host_cpu}.
  18508. @item
  18509. Assembler variations like underscore prefix on globals or ELF versus
  18510. COFF type directives are however best determined by probing, perhaps
  18511. even examining the compiler output.
  18512. @end itemize
  18513. @samp{$target} is for use by a package creating a compiler or similar.
  18514. For ordinary packages it's meaningless and should not be used. It
  18515. indicates what the created compiler should generate code for, if it can
  18516. cross-compile. @samp{$target} generally selects various hard-coded CPU
  18517. and system conventions, since usually the compiler or tools under
  18518. construction themselves determine how the target works.
  18519. @c ===================================================== Site Configuration.
  18520. @node Site Configuration
  18521. @chapter Site Configuration
  18522. @command{configure} scripts support several kinds of local configuration
  18523. decisions. There are ways for users to specify where external software
  18524. packages are, include or exclude optional features, install programs
  18525. under modified names, and set default values for @command{configure}
  18526. options.
  18527. @menu
  18528. * Help Formatting:: Customizing @samp{configure --help}
  18529. * External Software:: Working with other optional software
  18530. * Package Options:: Selecting optional features
  18531. * Pretty Help Strings:: Formatting help string
  18532. * Option Checking:: Controlling checking of @command{configure} options
  18533. * Site Details:: Configuring site details
  18534. * Transforming Names:: Changing program names when installing
  18535. * Site Defaults:: Giving @command{configure} local defaults
  18536. @end menu
  18537. @node Help Formatting
  18538. @section Controlling Help Output
  18539. Users consult @samp{configure --help} to learn of configuration
  18540. decisions specific to your package. By default, @command{configure}
  18541. breaks this output into sections for each type of option; within each
  18542. section, help strings appear in the order @file{configure.ac} defines
  18543. them:
  18544. @example
  18545. Optional Features:
  18546. @dots{}
  18547. --enable-bar include bar
  18548. Optional Packages:
  18549. @dots{}
  18550. --with-foo use foo
  18551. @end example
  18552. @defmac AC_PRESERVE_HELP_ORDER
  18553. @acindex{PRESERVE_HELP_ORDER}
  18554. Request an alternate @option{--help} format, in which options of all
  18555. types appear together, in the order defined. Call this macro before any
  18556. @code{AC_ARG_ENABLE} or @code{AC_ARG_WITH}.
  18557. @example
  18558. Optional Features and Packages:
  18559. @dots{}
  18560. --enable-bar include bar
  18561. --with-foo use foo
  18562. @end example
  18563. @end defmac
  18564. @node External Software
  18565. @section Working With External Software
  18566. @cindex External software
  18567. Some packages require, or can optionally use, other software packages
  18568. that are already installed. The user can give @command{configure}
  18569. command line options to specify which such external software to use.
  18570. The options have one of these forms:
  18571. @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
  18572. @c awful.
  18573. @example
  18574. --with-@var{package}@r{[}=@var{arg}@r{]}
  18575. --without-@var{package}
  18576. @end example
  18577. For example, @option{--with-gnu-ld} means work with the GNU linker
  18578. instead of some other linker. @option{--with-x} means work with The X
  18579. Window System.
  18580. The user can give an argument by following the package name with
  18581. @samp{=} and the argument. Giving an argument of @samp{no} is for
  18582. packages that are used by default; it says to @emph{not} use the
  18583. package. An argument that is neither @samp{yes} nor @samp{no} could
  18584. include a name or number of a version of the other package, to specify
  18585. more precisely which other package this program is supposed to work
  18586. with. If no argument is given, it defaults to @samp{yes}.
  18587. @option{--without-@var{package}} is equivalent to
  18588. @option{--with-@var{package}=no}.
  18589. Normally @command{configure} scripts complain about
  18590. @option{--with-@var{package}} options that they do not support.
  18591. @xref{Option Checking}, for details, and for how to override the
  18592. defaults.
  18593. For each external software package that may be used, @file{configure.ac}
  18594. should call @code{AC_ARG_WITH} to detect whether the @command{configure}
  18595. user asked to use it. Whether each package is used or not by default,
  18596. and which arguments are valid, is up to you.
  18597. @anchor{AC_ARG_WITH}
  18598. @defmac AC_ARG_WITH (@var{package}, @var{help-string}, @
  18599. @ovar{action-if-given}, @ovar{action-if-not-given})
  18600. @acindex{ARG_WITH}
  18601. If the user gave @command{configure} the option @option{--with-@var{package}}
  18602. or @option{--without-@var{package}}, run shell commands
  18603. @var{action-if-given}. If neither option was given, run shell commands
  18604. @var{action-if-not-given}. The name @var{package} indicates another
  18605. software package that this program should work with. It should consist
  18606. only of alphanumeric characters, dashes, plus signs, and dots.
  18607. The option's argument is available to the shell commands
  18608. @var{action-if-given} in the shell variable @code{withval}, which is
  18609. actually just the value of the shell variable named
  18610. @code{with_@var{package}}, with any non-alphanumeric characters in
  18611. @var{package} changed into @samp{_}. You may use that variable instead,
  18612. if you wish.
  18613. The argument @var{help-string} is a description of the option that
  18614. looks like this:
  18615. @example
  18616. --with-readline support fancy command line editing
  18617. @end example
  18618. @noindent
  18619. @var{help-string} may be more than one line long, if more detail is
  18620. needed. Just make sure the columns line up in @samp{configure
  18621. --help}. Avoid tabs in the help string. The easiest way to provide the
  18622. proper leading whitespace is to format your @var{help-string} with the macro
  18623. @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
  18624. The following example shows how to use the @code{AC_ARG_WITH} macro in
  18625. a common situation. You want to let the user decide whether to enable
  18626. support for an external library (e.g., the readline library); if the user
  18627. specified neither @option{--with-readline} nor @option{--without-readline},
  18628. you want to enable support for readline only if the library is available
  18629. on the system.
  18630. @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
  18631. @example
  18632. AC_ARG_WITH([readline],
  18633. [AS_HELP_STRING([--with-readline],
  18634. [support fancy command line editing @@<:@@default=check@@:>@@])],
  18635. [],
  18636. [with_readline=check])
  18637. LIBREADLINE=
  18638. AS_IF([test "x$with_readline" != xno],
  18639. [AC_CHECK_LIB([readline], [main],
  18640. [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
  18641. AC_DEFINE([HAVE_LIBREADLINE], [1],
  18642. [Define if you have libreadline])
  18643. ],
  18644. [if test "x$with_readline" != xcheck; then
  18645. AC_MSG_FAILURE(
  18646. [--with-readline was given, but test for readline failed])
  18647. fi
  18648. ], -lncurses)])
  18649. @end example
  18650. The next example shows how to use @code{AC_ARG_WITH} to give the user the
  18651. possibility to enable support for the readline library, in case it is still
  18652. experimental and not well tested, and is therefore disabled by default.
  18653. @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
  18654. @example
  18655. AC_ARG_WITH([readline],
  18656. [AS_HELP_STRING([--with-readline],
  18657. [enable experimental support for readline])],
  18658. [],
  18659. [with_readline=no])
  18660. LIBREADLINE=
  18661. AS_IF([test "x$with_readline" != xno],
  18662. [AC_CHECK_LIB([readline], [main],
  18663. [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
  18664. AC_DEFINE([HAVE_LIBREADLINE], [1],
  18665. [Define if you have libreadline])
  18666. ],
  18667. [AC_MSG_FAILURE(
  18668. [--with-readline was given, but test for readline failed])],
  18669. [-lncurses])])
  18670. @end example
  18671. The last example shows how to use @code{AC_ARG_WITH} to give the user the
  18672. possibility to disable support for the readline library, given that it is
  18673. an important feature and that it should be enabled by default.
  18674. @c FIXME: Remove AS_IF when the problem of AC_REQUIRE within `if' is solved.
  18675. @example
  18676. AC_ARG_WITH([readline],
  18677. [AS_HELP_STRING([--without-readline],
  18678. [disable support for readline])],
  18679. [],
  18680. [with_readline=yes])
  18681. LIBREADLINE=
  18682. AS_IF([test "x$with_readline" != xno],
  18683. [AC_CHECK_LIB([readline], [main],
  18684. [AC_SUBST([LIBREADLINE], ["-lreadline -lncurses"])
  18685. AC_DEFINE([HAVE_LIBREADLINE], [1],
  18686. [Define if you have libreadline])
  18687. ],
  18688. [AC_MSG_FAILURE(
  18689. [readline test failed (--without-readline to disable)])],
  18690. [-lncurses])])
  18691. @end example
  18692. These three examples can be easily adapted to the case where
  18693. @code{AC_ARG_ENABLE} should be preferred to @code{AC_ARG_WITH} (see
  18694. @ref{Package Options}).
  18695. @end defmac
  18696. @node Package Options
  18697. @section Choosing Package Options
  18698. @cindex Package options
  18699. @cindex Options, package
  18700. If a software package has optional compile-time features, the user can
  18701. give @command{configure} command line options to specify whether to
  18702. compile them. The options have one of these forms:
  18703. @c FIXME: Can't use @ovar here, Texinfo 4.0 goes lunatic and emits something
  18704. @c awful.
  18705. @example
  18706. --enable-@var{feature}@r{[}=@var{arg}@r{]}
  18707. --disable-@var{feature}
  18708. @end example
  18709. These options allow users to choose which optional features to build and
  18710. install. @option{--enable-@var{feature}} options should never make a
  18711. feature behave differently or cause one feature to replace another.
  18712. They should only cause parts of the program to be built rather than left
  18713. out.
  18714. The user can give an argument by following the feature name with
  18715. @samp{=} and the argument. Giving an argument of @samp{no} requests
  18716. that the feature @emph{not} be made available. A feature with an
  18717. argument looks like @option{--enable-debug=stabs}. If no argument is
  18718. given, it defaults to @samp{yes}. @option{--disable-@var{feature}} is
  18719. equivalent to @option{--enable-@var{feature}=no}.
  18720. Normally @command{configure} scripts complain about
  18721. @option{--enable-@var{package}} options that they do not support.
  18722. @xref{Option Checking}, for details, and for how to override the
  18723. defaults.
  18724. For each optional feature, @file{configure.ac} should call
  18725. @code{AC_ARG_ENABLE} to detect whether the @command{configure} user asked
  18726. to include it. Whether each feature is included or not by default, and
  18727. which arguments are valid, is up to you.
  18728. @anchor{AC_ARG_ENABLE}
  18729. @defmac AC_ARG_ENABLE (@var{feature}, @var{help-string}, @
  18730. @ovar{action-if-given}, @ovar{action-if-not-given})
  18731. @acindex{ARG_ENABLE}
  18732. If the user gave @command{configure} the option
  18733. @option{--enable-@var{feature}} or @option{--disable-@var{feature}}, run
  18734. shell commands @var{action-if-given}. If neither option was given, run
  18735. shell commands @var{action-if-not-given}. The name @var{feature}
  18736. indicates an optional user-level facility. It should consist only of
  18737. alphanumeric characters, dashes, plus signs, and dots.
  18738. The option's argument is available to the shell commands
  18739. @var{action-if-given} in the shell variable @code{enableval}, which is
  18740. actually just the value of the shell variable named
  18741. @code{enable_@var{feature}}, with any non-alphanumeric characters in
  18742. @var{feature} changed into @samp{_}. You may use that variable instead,
  18743. if you wish. The @var{help-string} argument is like that of
  18744. @code{AC_ARG_WITH} (@pxref{External Software}).
  18745. You should format your @var{help-string} with the macro
  18746. @code{AS_HELP_STRING} (@pxref{Pretty Help Strings}).
  18747. See the examples suggested with the definition of @code{AC_ARG_WITH}
  18748. (@pxref{External Software}) to get an idea of possible applications of
  18749. @code{AC_ARG_ENABLE}.
  18750. @end defmac
  18751. @node Pretty Help Strings
  18752. @section Making Your Help Strings Look Pretty
  18753. @cindex Help strings
  18754. Properly formatting the @samp{help strings} which are used in
  18755. @code{AC_ARG_WITH} (@pxref{External Software}) and @code{AC_ARG_ENABLE}
  18756. (@pxref{Package Options}) can be challenging. Specifically, you want
  18757. your own @samp{help strings} to line up in the appropriate columns of
  18758. @samp{configure --help} just like the standard Autoconf @samp{help
  18759. strings} do. This is the purpose of the @code{AS_HELP_STRING} macro.
  18760. @anchor{AS_HELP_STRING}
  18761. @defmac AS_HELP_STRING (@var{left-hand-side}, @var{right-hand-side} @
  18762. @dvar{indent-column, 26}, @dvar{wrap-column, 79})
  18763. @asindex{HELP_STRING}
  18764. Expands into a help string that looks pretty when the user executes
  18765. @samp{configure --help}. It is typically used in @code{AC_ARG_WITH}
  18766. (@pxref{External Software}) or @code{AC_ARG_ENABLE} (@pxref{Package
  18767. Options}). The following example makes this clearer.
  18768. @example
  18769. AC_ARG_WITH([foo],
  18770. [AS_HELP_STRING([--with-foo],
  18771. [use foo (default is no)])],
  18772. [use_foo=$withval],
  18773. [use_foo=no])
  18774. @end example
  18775. Then the last few lines of @samp{configure --help} appear like
  18776. this:
  18777. @example
  18778. --enable and --with options recognized:
  18779. --with-foo use foo (default is no)
  18780. @end example
  18781. Macro expansion is performed on the first argument. However, the second
  18782. argument of @code{AS_HELP_STRING} is treated as a whitespace separated
  18783. list of text to be reformatted, and is not subject to macro expansion.
  18784. Since it is not expanded, it should not be double quoted.
  18785. @xref{Autoconf Language}, for a more detailed explanation.
  18786. The @code{AS_HELP_STRING} macro is particularly helpful when the
  18787. @var{left-hand-side} and/or @var{right-hand-side} are composed of macro
  18788. arguments, as shown in the following example. Be aware that
  18789. @var{left-hand-side} may not expand to unbalanced quotes,
  18790. although quadrigraphs can be used.
  18791. @example
  18792. AC_DEFUN([MY_ARG_WITH],
  18793. [AC_ARG_WITH(m4_translit([[$1]], [_], [-]),
  18794. [AS_HELP_STRING([--with-m4_translit([$1], [_], [-])],
  18795. [use $1 (default is $2)])],
  18796. [use_[]$1=$withval],
  18797. [use_[]$1=$2])])
  18798. MY_ARG_WITH([a_b], [no])
  18799. @end example
  18800. @noindent
  18801. Here, the last few lines of @samp{configure --help} will include:
  18802. @example
  18803. --enable and --with options recognized:
  18804. --with-a-b use a_b (default is no)
  18805. @end example
  18806. The parameters @var{indent-column} and @var{wrap-column} were introduced
  18807. in Autoconf 2.62. Generally, they should not be specified; they exist
  18808. for fine-tuning of the wrapping.
  18809. @example
  18810. AS_HELP_STRING([--option], [description of option])
  18811. @result{} --option description of option
  18812. AS_HELP_STRING([--option], [description of option], [15], [30])
  18813. @result{} --option description of
  18814. @result{} option
  18815. @end example
  18816. @end defmac
  18817. @node Option Checking
  18818. @section Controlling Checking of @command{configure} Options
  18819. @cindex Options, Package
  18820. The @command{configure} script checks its command-line options against a
  18821. list of known options, like @option{--help} or @option{--config-cache}.
  18822. An unknown option ordinarily indicates a mistake by the user and
  18823. @command{configure} halts with an error. However, by default unknown
  18824. @option{--with-@var{package}} and @option{--enable-@var{feature}}
  18825. options elicit only a warning, to support configuring entire source
  18826. trees.
  18827. Source trees often contain multiple packages with a top-level
  18828. @command{configure} script that uses the @code{AC_CONFIG_SUBDIRS} macro
  18829. (@pxref{Subdirectories}). Because the packages generally support
  18830. different @option{--with-@var{package}} and
  18831. @option{--enable-@var{feature}} options, the GNU Coding
  18832. Standards say they must accept unrecognized options without halting.
  18833. Even a warning message is undesirable here, so @code{AC_CONFIG_SUBDIRS}
  18834. automatically disables the warnings.
  18835. This default behavior may be modified in two ways. First, the installer
  18836. can invoke @code{configure --disable-option-checking} to disable
  18837. these warnings, or invoke @code{configure --enable-option-checking=fatal}
  18838. options to turn them into fatal errors, respectively. Second, the
  18839. maintainer can use @code{AC_DISABLE_OPTION_CHECKING}.
  18840. @defmac AC_DISABLE_OPTION_CHECKING
  18841. @acindex{DISABLE_OPTION_CHECKING}
  18842. By default, disable warnings related to any unrecognized
  18843. @option{--with-@var{package}} or @option{--enable-@var{feature}}
  18844. options. This is implied by @code{AC_CONFIG_SUBDIRS}.
  18845. The installer can override this behavior by passing
  18846. @option{--enable-option-checking} (enable warnings) or
  18847. @option{--enable-option-checking=fatal} (enable errors) to
  18848. @command{configure}.
  18849. @end defmac
  18850. @node Site Details
  18851. @section Configuring Site Details
  18852. @cindex Site details
  18853. Some software packages require complex site-specific information. Some
  18854. examples are host names to use for certain services, company names, and
  18855. email addresses to contact. Since some configuration scripts generated
  18856. by Metaconfig ask for such information interactively, people sometimes
  18857. wonder how to get that information in Autoconf-generated configuration
  18858. scripts, which aren't interactive.
  18859. Such site configuration information should be put in a file that is
  18860. edited @emph{only by users}, not by programs. The location of the file
  18861. can either be based on the @code{prefix} variable, or be a standard
  18862. location such as the user's home directory. It could even be specified
  18863. by an environment variable. The programs should examine that file at
  18864. runtime, rather than at compile time. Runtime configuration is more
  18865. convenient for users and makes the configuration process simpler than
  18866. getting the information while configuring. @xref{Directory Variables, ,
  18867. Variables for Installation Directories, standards, The GNU Coding
  18868. Standards}, for more information on where to put data files.
  18869. @node Transforming Names
  18870. @section Transforming Program Names When Installing
  18871. @cindex Transforming program names
  18872. @cindex Program names, transforming
  18873. Autoconf supports changing the names of programs when installing them.
  18874. In order to use these transformations, @file{configure.ac} must call the
  18875. macro @code{AC_ARG_PROGRAM}.
  18876. @defmac AC_ARG_PROGRAM
  18877. @acindex{ARG_PROGRAM}
  18878. @ovindex program_transform_name
  18879. Place in output variable @code{program_transform_name} a sequence of
  18880. @code{sed} commands for changing the names of installed programs.
  18881. If any of the options described below are given to @command{configure},
  18882. program names are transformed accordingly. Otherwise, if
  18883. @code{AC_CANONICAL_TARGET} has been called and a @option{--target} value
  18884. is given, the target type followed by a dash is used as a prefix.
  18885. Otherwise, no program name transformation is done.
  18886. @end defmac
  18887. @menu
  18888. * Transformation Options:: @command{configure} options to transform names
  18889. * Transformation Examples:: Sample uses of transforming names
  18890. * Transformation Rules:: Makefile uses of transforming names
  18891. @end menu
  18892. @node Transformation Options
  18893. @subsection Transformation Options
  18894. You can specify name transformations by giving @command{configure} these
  18895. command line options:
  18896. @table @option
  18897. @item --program-prefix=@var{prefix}
  18898. prepend @var{prefix} to the names;
  18899. @item --program-suffix=@var{suffix}
  18900. append @var{suffix} to the names;
  18901. @item --program-transform-name=@var{expression}
  18902. perform @code{sed} substitution @var{expression} on the names.
  18903. @end table
  18904. @node Transformation Examples
  18905. @subsection Transformation Examples
  18906. These transformations are useful with programs that can be part of a
  18907. cross-compilation development environment. For example, a
  18908. cross-assembler running on a Sun 4 configured with
  18909. @option{--target=i960-vxworks} is normally installed as
  18910. @file{i960-vxworks-as}, rather than @file{as}, which could be confused
  18911. with a native Sun 4 assembler.
  18912. You can force a program name to begin with @file{g}, if you don't want
  18913. GNU programs installed on your system to shadow other programs with
  18914. the same name. For example, if you configure GNU @code{diff} with
  18915. @option{--program-prefix=g}, then when you run @samp{make install} it is
  18916. installed as @file{/usr/local/bin/gdiff}.
  18917. As a more sophisticated example, you could use
  18918. @example
  18919. --program-transform-name='s/^/g/; s/^gg/g/; s/^gless/less/'
  18920. @end example
  18921. @noindent
  18922. to prepend @samp{g} to most of the program names in a source tree,
  18923. excepting those like @code{gdb} that already have one and those like
  18924. @code{less} and @code{lesskey} that aren't GNU programs. (That is
  18925. assuming that you have a source tree containing those programs that is
  18926. set up to use this feature.)
  18927. One way to install multiple versions of some programs simultaneously is
  18928. to append a version number to the name of one or both. For example, if
  18929. you want to keep Autoconf version 1 around for awhile, you can configure
  18930. Autoconf version 2 using @option{--program-suffix=2} to install the
  18931. programs as @file{/usr/local/bin/autoconf2},
  18932. @file{/usr/local/bin/autoheader2}, etc. Nevertheless, pay attention
  18933. that only the binaries are renamed, therefore you'd have problems with
  18934. the library files which might overlap.
  18935. @node Transformation Rules
  18936. @subsection Transformation Rules
  18937. Here is how to use the variable @code{program_transform_name} in a
  18938. @file{Makefile.in}:
  18939. @example
  18940. PROGRAMS = cp ls rm
  18941. transform = @@program_transform_name@@
  18942. install:
  18943. for p in $(PROGRAMS); do \
  18944. $(INSTALL_PROGRAM) $$p $(DESTDIR)$(bindir)/`echo $$p | \
  18945. sed '$(transform)'`; \
  18946. done
  18947. uninstall:
  18948. for p in $(PROGRAMS); do \
  18949. rm -f $(DESTDIR)$(bindir)/`echo $$p | sed '$(transform)'`; \
  18950. @c $$ restore font-lock
  18951. done
  18952. @end example
  18953. It is guaranteed that @code{program_transform_name} is never empty, and
  18954. that there are no useless separators. Therefore you may safely embed
  18955. @code{program_transform_name} within a sed program using @samp{;}:
  18956. @example
  18957. transform = @@program_transform_name@@
  18958. transform_exe = s/$(EXEEXT)$$//;$(transform);s/$$/$(EXEEXT)/
  18959. @end example
  18960. Whether to do the transformations on documentation files (Texinfo or
  18961. @code{man}) is a tricky question; there seems to be no perfect answer,
  18962. due to the several reasons for name transforming. Documentation is not
  18963. usually particular to a specific architecture, and Texinfo files do not
  18964. conflict with system documentation. But they might conflict with
  18965. earlier versions of the same files, and @code{man} pages sometimes do
  18966. conflict with system documentation. As a compromise, it is probably
  18967. best to do name transformations on @code{man} pages but not on Texinfo
  18968. manuals.
  18969. @node Site Defaults
  18970. @section Setting Site Defaults
  18971. @cindex Site defaults
  18972. @cindex config.site
  18973. Autoconf-generated @command{configure} scripts allow your site to provide
  18974. default values for some configuration values. You do this by creating
  18975. site- and system-wide initialization files.
  18976. @evindex CONFIG_SITE
  18977. If the environment variable @code{CONFIG_SITE} is set, @command{configure}
  18978. uses its value as the name of a shell script to read; it is recommended
  18979. that this be an absolute file name. Otherwise, it
  18980. reads the shell script @file{@var{prefix}/share/config.site} if it exists,
  18981. then @file{@var{prefix}/etc/config.site} if it exists. Thus,
  18982. settings in machine-specific files override those in machine-independent
  18983. ones in case of conflict.
  18984. Site files can be arbitrary shell scripts, but only certain kinds of
  18985. code are really appropriate to be in them. Because @command{configure}
  18986. reads any cache file after it has read any site files, a site file can
  18987. define a default cache file to be shared between all Autoconf-generated
  18988. @command{configure} scripts run on that system (@pxref{Cache Files}). If
  18989. you set a default cache file in a site file, it is a good idea to also
  18990. set the output variable @code{CC} in that site file, because the cache
  18991. file is only valid for a particular compiler, but many systems have
  18992. several available.
  18993. You can examine or override the value set by a command line option to
  18994. @command{configure} in a site file; options set shell variables that have
  18995. the same names as the options, with any dashes turned into underscores.
  18996. The exceptions are that @option{--without-} and @option{--disable-} options
  18997. are like giving the corresponding @option{--with-} or @option{--enable-}
  18998. option and the value @samp{no}. Thus, @option{--cache-file=localcache}
  18999. sets the variable @code{cache_file} to the value @samp{localcache};
  19000. @option{--enable-warnings=no} or @option{--disable-warnings} sets the variable
  19001. @code{enable_warnings} to the value @samp{no}; @option{--prefix=/usr} sets the
  19002. variable @code{prefix} to the value @samp{/usr}; etc.
  19003. Site files are also good places to set default values for other output
  19004. variables, such as @code{CFLAGS}, if you need to give them non-default
  19005. values: anything you would normally do, repetitively, on the command
  19006. line. If you use non-default values for @var{prefix} or
  19007. @var{exec_prefix} (wherever you locate the site file), you can set them
  19008. in the site file if you specify it with the @code{CONFIG_SITE}
  19009. environment variable.
  19010. You can set some cache values in the site file itself. Doing this is
  19011. useful if you are cross-compiling, where it is impossible to check features
  19012. that require running a test program. You could ``prime the cache'' by
  19013. setting those values correctly for that system in
  19014. @file{@var{prefix}/etc/config.site}. To find out the names of the cache
  19015. variables you need to set, see the documentation of the respective
  19016. Autoconf macro. If the variables or their semantics are undocumented,
  19017. you may need to look for shell variables with @samp{_cv_} in their names
  19018. in the affected @command{configure} scripts, or in the Autoconf M4
  19019. source code for those macros; but in that case, their name or semantics
  19020. may change in a future Autoconf version.
  19021. The cache file is careful to not override any variables set in the site
  19022. files. Similarly, you should not override command-line options in the
  19023. site files. Your code should check that variables such as @code{prefix}
  19024. and @code{cache_file} have their default values (as set near the top of
  19025. @command{configure}) before changing them.
  19026. Here is a sample file @file{/usr/share/local/@/gnu/share/@/config.site}. The
  19027. command @samp{configure --prefix=/usr/share/local/gnu} would read this
  19028. file (if @code{CONFIG_SITE} is not set to a different file).
  19029. @example
  19030. # /usr/share/local/gnu/share/config.site for configure
  19031. #
  19032. # Change some defaults.
  19033. test "$prefix" = NONE && prefix=/usr/share/local/gnu
  19034. test "$exec_prefix" = NONE && exec_prefix=/usr/local/gnu
  19035. test "$sharedstatedir" = '$@{prefix@}/com' && sharedstatedir=/var
  19036. test "$localstatedir" = '$@{prefix@}/var' && localstatedir=/var
  19037. # Give Autoconf 2.x generated configure scripts a shared default
  19038. # cache file for feature test results, architecture-specific.
  19039. if test "$cache_file" = /dev/null; then
  19040. cache_file="$prefix/var/config.cache"
  19041. # A cache file is only valid for one C compiler.
  19042. CC=gcc
  19043. fi
  19044. @end example
  19045. @c Leave this use of ``File system'' rendered as one word, but
  19046. @c slightly obfuscated so as not to trigger the syntax-check prohibition.
  19047. @cindex File@/system Hierarchy Standard
  19048. @cindex FHS
  19049. Another use of @file{config.site} is for priming the directory variables
  19050. @c ``File system'', but slightly obfuscated, as above.
  19051. in a manner consistent with the File@/system Hierarchy Standard
  19052. (FHS). Once the following file is installed at
  19053. @file{/usr/share/config.site}, a user can execute simply
  19054. @code{./configure --prefix=/usr} to get all the directories chosen in
  19055. the locations recommended by FHS.
  19056. @example
  19057. # /usr/share/config.site for FHS defaults when installing below /usr,
  19058. # and the respective settings were not changed on the command line.
  19059. if test "$prefix" = /usr; then
  19060. test "$sysconfdir" = '$@{prefix@}/etc' && sysconfdir=/etc
  19061. test "$sharedstatedir" = '$@{prefix@}/com' && sharedstatedir=/var
  19062. test "$localstatedir" = '$@{prefix@}/var' && localstatedir=/var
  19063. fi
  19064. @end example
  19065. @cindex @file{lib64}
  19066. @cindex 64-bit libraries
  19067. Likewise, on platforms where 64-bit libraries are built by default, then
  19068. installed in @file{/usr/local/@/lib64} instead of @file{/usr/local/@/lib},
  19069. it is appropriate to install @file{/usr/local/@/share/config.site}:
  19070. @example
  19071. # /usr/local/share/config.site for platforms that prefer
  19072. # the directory /usr/local/lib64 over /usr/local/lib.
  19073. test "$libdir" = '$@{exec_prefix@}/lib' && libdir='$@{exec_prefix@}/lib64'
  19074. @end example
  19075. @c ============================================== Running configure Scripts.
  19076. @node Running configure Scripts
  19077. @chapter Running @command{configure} Scripts
  19078. @cindex @command{configure}
  19079. Below are instructions on how to configure a package that uses a
  19080. @command{configure} script, suitable for inclusion as an @file{INSTALL}
  19081. file in the package. A plain-text version of @file{INSTALL} which you
  19082. may use comes with Autoconf.
  19083. @menu
  19084. * Basic Installation:: Instructions for typical cases
  19085. * Compilers and Options:: Selecting compilers and optimization
  19086. * Multiple Architectures:: Compiling for multiple architectures at once
  19087. * Installation Names:: Installing in different directories
  19088. * Optional Features:: Selecting optional features
  19089. * Particular Systems:: Particular systems
  19090. * System Type:: Specifying the system type
  19091. * Sharing Defaults:: Setting site-wide defaults for @command{configure}
  19092. * Defining Variables:: Specifying the compiler etc.
  19093. * configure Invocation:: Changing how @command{configure} runs
  19094. @end menu
  19095. @set autoconf
  19096. @include install.texi
  19097. @c ============================================== config.status Invocation
  19098. @node config.status Invocation
  19099. @chapter config.status Invocation
  19100. @cindex @command{config.status}
  19101. The @command{configure} script creates a file named @file{config.status},
  19102. which actually configures, @dfn{instantiates}, the template files. It
  19103. also records the configuration options that were specified when the
  19104. package was last configured in case reconfiguring is needed.
  19105. Synopsis:
  19106. @example
  19107. ./config.status @ovar{option}@dots{} @ovar{tag}@dots{}
  19108. @end example
  19109. It configures each @var{tag}; if none are specified, all the templates
  19110. are instantiated. A @var{tag} refers to a file or other tag associated
  19111. with a configuration action, as specified by an @code{AC_CONFIG_@var{ITEMS}}
  19112. macro (@pxref{Configuration Actions}). The files must be specified
  19113. without their dependencies, as in
  19114. @example
  19115. ./config.status foobar
  19116. @end example
  19117. @noindent
  19118. not
  19119. @example
  19120. ./config.status foobar:foo.in:bar.in
  19121. @end example
  19122. The supported options are:
  19123. @table @option
  19124. @item --help
  19125. @itemx -h
  19126. Print a summary of the command line options, the list of the template
  19127. files, and exit.
  19128. @item --version
  19129. @itemx -V
  19130. Print the version number of Autoconf and the configuration settings,
  19131. and exit.
  19132. @item --config
  19133. Print the configuration settings in reusable way, quoted for the shell,
  19134. and exit. For example, for a debugging build that otherwise reuses the
  19135. configuration from a different build directory @var{build-dir} of a
  19136. package in @var{src-dir}, you could use the following:
  19137. @example
  19138. args=`@var{build-dir}/config.status --config`
  19139. eval @var{src-dir}/configure "$args" CFLAGS=-g --srcdir=@var{src-dir}
  19140. @end example
  19141. @noindent
  19142. Note that it may be necessary to override a @option{--srcdir} setting
  19143. that was saved in the configuration, if the arguments are used in a
  19144. different build directory.
  19145. @item --silent
  19146. @itemx --quiet
  19147. @itemx -q
  19148. Do not print progress messages.
  19149. @item --debug
  19150. @itemx -d
  19151. Don't remove the temporary files.
  19152. @item --file=@var{file}[:@var{template}]
  19153. Require that @var{file} be instantiated as if
  19154. @samp{AC_CONFIG_FILES(@var{file}:@var{template})} was used. Both
  19155. @var{file} and @var{template} may be @samp{-} in which case the standard
  19156. output and/or standard input, respectively, is used. If a
  19157. @var{template} file name is relative, it is first looked for in the build
  19158. tree, and then in the source tree. @xref{Configuration Actions}, for
  19159. more details.
  19160. This option and the following ones provide one way for separately
  19161. distributed packages to share the values computed by @command{configure}.
  19162. Doing so can be useful if some of the packages need a superset of the
  19163. features that one of them, perhaps a common library, does. These
  19164. options allow a @file{config.status} file to create files other than the
  19165. ones that its @file{configure.ac} specifies, so it can be used for a
  19166. different package, or for extracting a subset of values. For example,
  19167. @example
  19168. echo '@@CC@@' | ./config.status --file=-
  19169. @end example
  19170. @noindent
  19171. provides the value of @code{@@CC@@} on standard output.
  19172. @item --header=@var{file}[:@var{template}]
  19173. Same as @option{--file} above, but with @samp{AC_CONFIG_HEADERS}.
  19174. @item --recheck
  19175. Ask @file{config.status} to update itself and exit (no instantiation).
  19176. This option is useful if you change @command{configure}, so that the
  19177. results of some tests might be different from the previous run. The
  19178. @option{--recheck} option reruns @command{configure} with the same arguments
  19179. you used before, plus the @option{--no-create} option, which prevents
  19180. @command{configure} from running @file{config.status} and creating
  19181. @file{Makefile} and other files, and the @option{--no-recursion} option,
  19182. which prevents @command{configure} from running other @command{configure}
  19183. scripts in subdirectories. (This is so other Make rules can
  19184. run @file{config.status} when it changes; @pxref{Automatic Remaking},
  19185. for an example).
  19186. @end table
  19187. @file{config.status} checks several optional environment variables that
  19188. can alter its behavior:
  19189. @anchor{CONFIG_SHELL}
  19190. @defvar CONFIG_SHELL
  19191. @evindex CONFIG_SHELL
  19192. The shell with which to run @command{configure}. It must be
  19193. Bourne-compatible, and the absolute name of the shell should be passed.
  19194. The default is a shell that supports @code{LINENO} if available, and
  19195. @file{/bin/sh} otherwise.
  19196. @end defvar
  19197. @defvar CONFIG_STATUS
  19198. @evindex CONFIG_STATUS
  19199. The file name to use for the shell script that records the
  19200. configuration. The default is @file{./config.status}. This variable is
  19201. useful when one package uses parts of another and the @command{configure}
  19202. scripts shouldn't be merged because they are maintained separately.
  19203. @end defvar
  19204. You can use @file{./config.status} in your makefiles. For example, in
  19205. the dependencies given above (@pxref{Automatic Remaking}),
  19206. @file{config.status} is run twice when @file{configure.ac} has changed.
  19207. If that bothers you, you can make each run only regenerate the files for
  19208. that rule:
  19209. @example
  19210. @group
  19211. config.h: stamp-h
  19212. stamp-h: config.h.in config.status
  19213. ./config.status config.h
  19214. echo > stamp-h
  19215. Makefile: Makefile.in config.status
  19216. ./config.status Makefile
  19217. @end group
  19218. @end example
  19219. The calling convention of @file{config.status} has changed; see
  19220. @ref{Obsolete config.status Use}, for details.
  19221. @c =================================================== Obsolete Constructs
  19222. @node Obsolete Constructs
  19223. @chapter Obsolete Constructs
  19224. @cindex Obsolete constructs
  19225. Autoconf changes, and throughout the years some constructs have been
  19226. obsoleted. Most of the changes involve the macros, but in some cases
  19227. the tools themselves, or even some concepts, are now considered
  19228. obsolete.
  19229. You may completely skip this chapter if you are new to Autoconf. Its
  19230. intention is mainly to help maintainers updating their packages by
  19231. understanding how to move to more modern constructs.
  19232. @menu
  19233. * Obsolete config.status Use:: Obsolete convention for @command{config.status}
  19234. * acconfig Header:: Additional entries in @file{config.h.in}
  19235. * autoupdate Invocation:: Automatic update of @file{configure.ac}
  19236. * Obsolete Macros:: Backward compatibility macros
  19237. * Autoconf 1:: Tips for upgrading your files
  19238. * Autoconf 2.13:: Some fresher tips
  19239. @end menu
  19240. @node Obsolete config.status Use
  19241. @section Obsolete @file{config.status} Invocation
  19242. @file{config.status} now supports arguments to specify the files to
  19243. instantiate; see @ref{config.status Invocation}, for more details.
  19244. Before, environment variables had to be used.
  19245. @defvar CONFIG_COMMANDS
  19246. @evindex CONFIG_COMMANDS
  19247. The tags of the commands to execute. The default is the arguments given
  19248. to @code{AC_OUTPUT} and @code{AC_CONFIG_COMMANDS} in
  19249. @file{configure.ac}.
  19250. @end defvar
  19251. @defvar CONFIG_FILES
  19252. @evindex CONFIG_FILES
  19253. The files in which to perform @samp{@@@var{variable}@@} substitutions.
  19254. The default is the arguments given to @code{AC_OUTPUT} and
  19255. @code{AC_CONFIG_FILES} in @file{configure.ac}.
  19256. @end defvar
  19257. @defvar CONFIG_HEADERS
  19258. @evindex CONFIG_HEADERS
  19259. The files in which to substitute C @code{#define} statements. The
  19260. default is the arguments given to @code{AC_CONFIG_HEADERS}; if that
  19261. macro was not called, @file{config.status} ignores this variable.
  19262. @end defvar
  19263. @defvar CONFIG_LINKS
  19264. @evindex CONFIG_LINKS
  19265. The symbolic links to establish. The default is the arguments given to
  19266. @code{AC_CONFIG_LINKS}; if that macro was not called,
  19267. @file{config.status} ignores this variable.
  19268. @end defvar
  19269. In @ref{config.status Invocation}, using this old interface, the example
  19270. would be:
  19271. @example
  19272. @group
  19273. config.h: stamp-h
  19274. stamp-h: config.h.in config.status
  19275. CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_FILES= \
  19276. CONFIG_HEADERS=config.h ./config.status
  19277. echo > stamp-h
  19278. Makefile: Makefile.in config.status
  19279. CONFIG_COMMANDS= CONFIG_LINKS= CONFIG_HEADERS= \
  19280. CONFIG_FILES=Makefile ./config.status
  19281. @end group
  19282. @end example
  19283. @noindent
  19284. (If @file{configure.ac} does not call @code{AC_CONFIG_HEADERS}, there is
  19285. no need to set @code{CONFIG_HEADERS} in the @command{make} rules. Equally
  19286. for @code{CONFIG_COMMANDS}, etc.)
  19287. @node acconfig Header
  19288. @section @file{acconfig.h}
  19289. @cindex @file{acconfig.h}
  19290. @cindex @file{config.h.top}
  19291. @cindex @file{config.h.bot}
  19292. In order to produce @file{config.h.in}, @command{autoheader} needs to
  19293. build or to find templates for each symbol. Modern releases of Autoconf
  19294. use @code{AH_VERBATIM} and @code{AH_TEMPLATE} (@pxref{Autoheader
  19295. Macros}), but in older releases a file, @file{acconfig.h}, contained the
  19296. list of needed templates. @command{autoheader} copied comments and
  19297. @code{#define} and @code{#undef} statements from @file{acconfig.h} in
  19298. the current directory, if present. This file used to be mandatory if
  19299. you @code{AC_DEFINE} any additional symbols.
  19300. Modern releases of Autoconf also provide @code{AH_TOP} and
  19301. @code{AH_BOTTOM} if you need to prepend/append some information to
  19302. @file{config.h.in}. Ancient versions of Autoconf had a similar feature:
  19303. if @file{./acconfig.h} contains the string @samp{@@TOP@@},
  19304. @command{autoheader} copies the lines before the line containing
  19305. @samp{@@TOP@@} into the top of the file that it generates. Similarly,
  19306. if @file{./acconfig.h} contains the string @samp{@@BOTTOM@@},
  19307. @command{autoheader} copies the lines after that line to the end of the
  19308. file it generates. Either or both of those strings may be omitted. An
  19309. even older alternate way to produce the same effect in ancient versions
  19310. of Autoconf is to create the files @file{@var{file}.top} (typically
  19311. @file{config.h.top}) and/or @file{@var{file}.bot} in the current
  19312. directory. If they exist, @command{autoheader} copies them to the
  19313. beginning and end, respectively, of its output.
  19314. In former versions of Autoconf, the files used in preparing a software
  19315. package for distribution were:
  19316. @example
  19317. @group
  19318. configure.ac --. .------> autoconf* -----> configure
  19319. +---+
  19320. [aclocal.m4] --+ `---.
  19321. [acsite.m4] ---' |
  19322. +--> [autoheader*] -> [config.h.in]
  19323. [acconfig.h] ----. |
  19324. +-----'
  19325. [config.h.top] --+
  19326. [config.h.bot] --'
  19327. @end group
  19328. @end example
  19329. Using only the @code{AH_} macros, @file{configure.ac} should be
  19330. self-contained, and should not depend upon @file{acconfig.h} etc.
  19331. @node autoupdate Invocation
  19332. @section Using @command{autoupdate} to Modernize @file{configure.ac}
  19333. @cindex @command{autoupdate}
  19334. The @command{autoupdate} program updates a @file{configure.ac} file that
  19335. calls Autoconf macros by their old names to use the current macro names.
  19336. In version 2 of Autoconf, most of the macros were renamed to use a more
  19337. uniform and descriptive naming scheme. @xref{Macro Names}, for a
  19338. description of the new scheme. Although the old names still work
  19339. (@pxref{Obsolete Macros}, for a list of the old macros and the corresponding
  19340. new names), you can make your @file{configure.ac} files more readable
  19341. and make it easier to use the current Autoconf documentation if you
  19342. update them to use the new macro names.
  19343. @evindex SIMPLE_BACKUP_SUFFIX
  19344. If given no arguments, @command{autoupdate} updates @file{configure.ac},
  19345. backing up the original version with the suffix @file{~} (or the value
  19346. of the environment variable @code{SIMPLE_BACKUP_SUFFIX}, if that is
  19347. set). If you give @command{autoupdate} an argument, it reads that file
  19348. instead of @file{configure.ac} and writes the updated file to the
  19349. standard output.
  19350. @noindent
  19351. @command{autoupdate} accepts the following options:
  19352. @table @option
  19353. @item --help
  19354. @itemx -h
  19355. Print a summary of the command line options and exit.
  19356. @item --version
  19357. @itemx -V
  19358. Print the version number of Autoconf and exit.
  19359. @item --verbose
  19360. @itemx -v
  19361. Report processing steps.
  19362. @item --debug
  19363. @itemx -d
  19364. Don't remove the temporary files.
  19365. @item --force
  19366. @itemx -f
  19367. Force the update even if the file has not changed. Disregard the cache.
  19368. @item --include=@var{dir}
  19369. @itemx -I @var{dir}
  19370. Also look for input files in @var{dir}. Multiple invocations accumulate.
  19371. Directories are browsed from last to first.
  19372. @item --prepend-include=@var{dir}
  19373. @itemx -B @var{dir}
  19374. Prepend directory @var{dir} to the search path. This is used to include
  19375. the language-specific files before any third-party macros.
  19376. @end table
  19377. @node Obsolete Macros
  19378. @section Obsolete Macros
  19379. Several macros are obsoleted in Autoconf, for various reasons (typically
  19380. they failed to quote properly, couldn't be extended for more recent
  19381. issues, etc.). They are still supported, but deprecated: their use
  19382. should be avoided.
  19383. During the jump from Autoconf version 1 to version 2, most of the
  19384. macros were renamed to use a more uniform and descriptive naming scheme,
  19385. but their signature did not change. @xref{Macro Names}, for a
  19386. description of the new naming scheme. Below, if there is just the mapping
  19387. from old names to new names for these macros, the reader is invited to
  19388. refer to the definition of the new macro for the signature and the
  19389. description.
  19390. @defmac AC_AIX
  19391. @acindex{AIX}
  19392. @cvindex _ALL_SOURCE
  19393. This macro is a platform-specific subset of
  19394. @code{AC_USE_SYSTEM_EXTENSIONS} (@pxref{AC_USE_SYSTEM_EXTENSIONS}).
  19395. @end defmac
  19396. @defmac AC_ALLOCA
  19397. @acindex{ALLOCA}
  19398. Replaced by @code{AC_FUNC_ALLOCA} (@pxref{AC_FUNC_ALLOCA}).
  19399. @end defmac
  19400. @defmac AC_ARG_ARRAY
  19401. @acindex{ARG_ARRAY}
  19402. Removed because of limited usefulness.
  19403. @end defmac
  19404. @defmac AC_C_CROSS
  19405. @acindex{C_CROSS}
  19406. This macro is obsolete; it does nothing.
  19407. @end defmac
  19408. @defmac AC_C_LONG_DOUBLE
  19409. @acindex{C_LONG_DOUBLE}
  19410. @cvindex HAVE_LONG_DOUBLE
  19411. If the C compiler supports a working @code{long double} type with more
  19412. range or precision than the @code{double} type, define
  19413. @code{HAVE_LONG_DOUBLE}.
  19414. You should use @code{AC_TYPE_LONG_DOUBLE} or
  19415. @code{AC_TYPE_LONG_DOUBLE_WIDER} instead. @xref{Particular Types}.
  19416. @end defmac
  19417. @defmac AC_CANONICAL_SYSTEM
  19418. @acindex{CANONICAL_SYSTEM}
  19419. Determine the system type and set output variables to the names of the
  19420. canonical system types. @xref{Canonicalizing}, for details about the
  19421. variables this macro sets.
  19422. The user is encouraged to use either @code{AC_CANONICAL_BUILD}, or
  19423. @code{AC_CANONICAL_HOST}, or @code{AC_CANONICAL_TARGET}, depending on
  19424. the needs. Using @code{AC_CANONICAL_TARGET} is enough to run the two
  19425. other macros (@pxref{Canonicalizing}).
  19426. @end defmac
  19427. @defmac AC_CHAR_UNSIGNED
  19428. @acindex{CHAR_UNSIGNED}
  19429. Replaced by @code{AC_C_CHAR_UNSIGNED} (@pxref{AC_C_CHAR_UNSIGNED}).
  19430. @end defmac
  19431. @defmac AC_CHECK_TYPE (@var{type}, @var{default})
  19432. @acindex{CHECK_TYPE}
  19433. Autoconf, up to 2.13, used to provide this version of
  19434. @code{AC_CHECK_TYPE}, deprecated because of its flaws. First, although
  19435. it is a member of the @code{CHECK} clan, it does
  19436. more than just checking. Secondly, missing types are defined
  19437. using @code{#define}, not @code{typedef}, and this can lead to
  19438. problems in the case of pointer types.
  19439. This use of @code{AC_CHECK_TYPE} is obsolete and discouraged; see
  19440. @ref{Generic Types}, for the description of the current macro.
  19441. If the type @var{type} is not defined, define it to be the C (or C++)
  19442. builtin type @var{default}, e.g., @samp{short int} or @samp{unsigned int}.
  19443. This macro is equivalent to:
  19444. @example
  19445. AC_CHECK_TYPE([@var{type}], [],
  19446. [AC_DEFINE_UNQUOTED([@var{type}], [@var{default}],
  19447. [Define to `@var{default}'
  19448. if <sys/types.h> does not define.])])
  19449. @end example
  19450. In order to keep backward compatibility, the two versions of
  19451. @code{AC_CHECK_TYPE} are implemented, selected using these heuristics:
  19452. @enumerate
  19453. @item
  19454. If there are three or four arguments, the modern version is used.
  19455. @item
  19456. If the second argument appears to be a C or C++ type, then the
  19457. obsolete version is used. This happens if the argument is a C or C++
  19458. @emph{builtin} type or a C identifier ending in @samp{_t}, optionally
  19459. followed by one of @samp{[(* } and then by a string of zero or more
  19460. characters taken from the set @samp{[]()* _a-zA-Z0-9}.
  19461. @item
  19462. If the second argument is spelled with the alphabet of valid C and C++
  19463. types, the user is warned and the modern version is used.
  19464. @item
  19465. Otherwise, the modern version is used.
  19466. @end enumerate
  19467. @noindent
  19468. You are encouraged either to use a valid builtin type, or to use the
  19469. equivalent modern code (see above), or better yet, to use
  19470. @code{AC_CHECK_TYPES} together with
  19471. @example
  19472. #ifndef HAVE_LOFF_T
  19473. typedef loff_t off_t;
  19474. #endif
  19475. @end example
  19476. @end defmac
  19477. @c end of AC_CHECK_TYPE
  19478. @defmac AC_CHECKING (@var{feature-description})
  19479. @acindex{CHECKING}
  19480. Same as
  19481. @example
  19482. AC_MSG_NOTICE([checking @var{feature-description}@dots{}]
  19483. @end example
  19484. @noindent
  19485. @xref{AC_MSG_NOTICE}.
  19486. @end defmac
  19487. @defmac AC_COMPILE_CHECK (@var{echo-text}, @var{includes}, @
  19488. @var{function-body}, @var{action-if-true}, @ovar{action-if-false})
  19489. @acindex{COMPILE_CHECK}
  19490. This is an obsolete version of @code{AC_TRY_COMPILE} itself replaced by
  19491. @code{AC_COMPILE_IFELSE} (@pxref{Running the Compiler}), with the
  19492. addition that it prints @samp{checking for @var{echo-text}} to the
  19493. standard output first, if @var{echo-text} is non-empty. Use
  19494. @code{AC_MSG_CHECKING} and @code{AC_MSG_RESULT} instead to print
  19495. messages (@pxref{Printing Messages}).
  19496. @end defmac
  19497. @defmac AC_CONST
  19498. @acindex{CONST}
  19499. Replaced by @code{AC_C_CONST} (@pxref{AC_C_CONST}).
  19500. @end defmac
  19501. @defmac AC_CROSS_CHECK
  19502. @acindex{CROSS_CHECK}
  19503. Same as @code{AC_C_CROSS}, which is obsolete too, and does nothing
  19504. @code{:-)}.
  19505. @end defmac
  19506. @defmac AC_CYGWIN
  19507. @acindex{CYGWIN}
  19508. @evindex CYGWIN
  19509. Check for the Cygwin environment in which case the shell variable
  19510. @code{CYGWIN} is set to @samp{yes}. Don't use this macro, the dignified
  19511. means to check the nature of the host is using @code{AC_CANONICAL_HOST}
  19512. (@pxref{Canonicalizing}). As a matter of fact this macro is defined as:
  19513. @example
  19514. AC_REQUIRE([AC_CANONICAL_HOST])[]dnl
  19515. case $host_os in
  19516. *cygwin* ) CYGWIN=yes;;
  19517. * ) CYGWIN=no;;
  19518. esac
  19519. @end example
  19520. Beware that the variable @env{CYGWIN} has a special meaning when
  19521. running Cygwin, and should not be changed. That's yet another reason
  19522. not to use this macro.
  19523. @end defmac
  19524. @defmac AC_DECL_SYS_SIGLIST
  19525. @acindex{DECL_SYS_SIGLIST}
  19526. @cvindex SYS_SIGLIST_DECLARED
  19527. Same as:
  19528. @example
  19529. AC_CHECK_DECLS([sys_siglist], [], [],
  19530. [#include <signal.h>
  19531. /* NetBSD declares sys_siglist in unistd.h. */
  19532. #ifdef HAVE_UNISTD_H
  19533. # include <unistd.h>
  19534. #endif
  19535. ])
  19536. @end example
  19537. @noindent
  19538. @xref{AC_CHECK_DECLS}.
  19539. @end defmac
  19540. @defmac AC_DECL_YYTEXT
  19541. @acindex{DECL_YYTEXT}
  19542. Does nothing, now integrated in @code{AC_PROG_LEX} (@pxref{AC_PROG_LEX}).
  19543. @end defmac
  19544. @defmac AC_DIR_HEADER
  19545. @acindex{DIR_HEADER}
  19546. @cvindex DIRENT
  19547. @cvindex SYSNDIR
  19548. @cvindex SYSDIR
  19549. @cvindex NDIR
  19550. Like calling @code{AC_FUNC_CLOSEDIR_VOID}
  19551. (@pxref{AC_FUNC_CLOSEDIR_VOID}) and @code{AC_HEADER_DIRENT}
  19552. (@pxref{AC_HEADER_DIRENT}),
  19553. but defines a different set of C preprocessor macros to indicate which
  19554. header file is found:
  19555. @multitable {@file{sys/ndir.h}} {Old Symbol} {@code{HAVE_SYS_NDIR_H}}
  19556. @item Header @tab Old Symbol @tab New Symbol
  19557. @item @file{dirent.h} @tab @code{DIRENT} @tab @code{HAVE_DIRENT_H}
  19558. @item @file{sys/ndir.h} @tab @code{SYSNDIR} @tab @code{HAVE_SYS_NDIR_H}
  19559. @item @file{sys/dir.h} @tab @code{SYSDIR} @tab @code{HAVE_SYS_DIR_H}
  19560. @item @file{ndir.h} @tab @code{NDIR} @tab @code{HAVE_NDIR_H}
  19561. @end multitable
  19562. @end defmac
  19563. @defmac AC_DYNIX_SEQ
  19564. @acindex{DYNIX_SEQ}
  19565. If on DYNIX/ptx, add @option{-lseq} to output variable
  19566. @code{LIBS}. This macro used to be defined as
  19567. @example
  19568. AC_CHECK_LIB([seq], [getmntent], [LIBS="-lseq $LIBS"])
  19569. @end example
  19570. @noindent
  19571. now it is just @code{AC_FUNC_GETMNTENT} (@pxref{AC_FUNC_GETMNTENT}).
  19572. @end defmac
  19573. @defmac AC_EXEEXT
  19574. @acindex{EXEEXT}
  19575. @ovindex EXEEXT
  19576. Defined the output variable @code{EXEEXT} based on the output of the
  19577. compiler, which is now done automatically. Typically set to empty
  19578. string if Posix and @samp{.exe} if a DOS variant.
  19579. @end defmac
  19580. @defmac AC_EMXOS2
  19581. @acindex{EMXOS2}
  19582. Similar to @code{AC_CYGWIN} but checks for the EMX environment on OS/2
  19583. and sets @code{EMXOS2}. Don't use this macro, the dignified means to
  19584. check the nature of the host is using @code{AC_CANONICAL_HOST}
  19585. (@pxref{Canonicalizing}).
  19586. @end defmac
  19587. @defmac AC_ENABLE (@var{feature}, @var{action-if-given}, @
  19588. @ovar{action-if-not-given})
  19589. @acindex{ENABLE}
  19590. This is an obsolete version of @code{AC_ARG_ENABLE} that does not
  19591. support providing a help string (@pxref{AC_ARG_ENABLE}).
  19592. @end defmac
  19593. @defmac AC_ERROR
  19594. @acindex{ERROR}
  19595. Replaced by @code{AC_MSG_ERROR} (@pxref{AC_MSG_ERROR}).
  19596. @end defmac
  19597. @defmac AC_FIND_X
  19598. @acindex{FIND_X}
  19599. Replaced by @code{AC_PATH_X} (@pxref{AC_PATH_X}).
  19600. @end defmac
  19601. @defmac AC_FIND_XTRA
  19602. @acindex{FIND_XTRA}
  19603. Replaced by @code{AC_PATH_XTRA} (@pxref{AC_PATH_XTRA}).
  19604. @end defmac
  19605. @defmac AC_FOREACH
  19606. @acindex{FOREACH}
  19607. Replaced by @code{m4_foreach_w} (@pxref{m4_foreach_w}).
  19608. @end defmac
  19609. @defmac AC_FUNC_CHECK
  19610. @acindex{FUNC_CHECK}
  19611. Replaced by @code{AC_CHECK_FUNC} (@pxref{AC_CHECK_FUNC}).
  19612. @end defmac
  19613. @anchor{AC_FUNC_SETVBUF_REVERSED}
  19614. @defmac AC_FUNC_SETVBUF_REVERSED
  19615. @acindex{FUNC_SETVBUF_REVERSED}
  19616. @cvindex SETVBUF_REVERSED
  19617. @c @fuindex setvbuf
  19618. @prindex @code{setvbuf}
  19619. Do nothing. Formerly, this macro checked whether @code{setvbuf} takes
  19620. the buffering type as its second argument and the buffer pointer as the
  19621. third, instead of the other way around, and defined
  19622. @code{SETVBUF_REVERSED}. However, the last systems to have the problem
  19623. were those based on SVR2, which became obsolete in 1987, and the macro
  19624. is no longer needed.
  19625. @end defmac
  19626. @defmac AC_FUNC_WAIT3
  19627. @acindex{FUNC_WAIT3}
  19628. @cvindex HAVE_WAIT3
  19629. @c @fuindex wait3
  19630. @prindex @code{wait3}
  19631. If @code{wait3} is found and fills in the contents of its third argument
  19632. (a @samp{struct rusage *}), which HP-UX does not do, define
  19633. @code{HAVE_WAIT3}.
  19634. These days portable programs should use @code{waitpid}, not
  19635. @code{wait3}, as @code{wait3} has been removed from Posix.
  19636. @end defmac
  19637. @defmac AC_GCC_TRADITIONAL
  19638. @acindex{GCC_TRADITIONAL}
  19639. Replaced by @code{AC_PROG_GCC_TRADITIONAL} (@pxref{AC_PROG_GCC_TRADITIONAL}).
  19640. @end defmac
  19641. @defmac AC_GETGROUPS_T
  19642. @acindex{GETGROUPS_T}
  19643. Replaced by @code{AC_TYPE_GETGROUPS} (@pxref{AC_TYPE_GETGROUPS}).
  19644. @end defmac
  19645. @defmac AC_GETLOADAVG
  19646. @acindex{GETLOADAVG}
  19647. Replaced by @code{AC_FUNC_GETLOADAVG} (@pxref{AC_FUNC_GETLOADAVG}).
  19648. @end defmac
  19649. @defmac AC_GNU_SOURCE
  19650. @acindex{GNU_SOURCE}
  19651. @cvindex _GNU_SOURCE
  19652. This macro is a platform-specific subset of
  19653. @code{AC_USE_SYSTEM_EXTENSIONS} (@pxref{AC_USE_SYSTEM_EXTENSIONS}).
  19654. @end defmac
  19655. @defmac AC_HAVE_FUNCS
  19656. @acindex{HAVE_FUNCS}
  19657. Replaced by @code{AC_CHECK_FUNCS} (@pxref{AC_CHECK_FUNCS}).
  19658. @end defmac
  19659. @defmac AC_HAVE_HEADERS
  19660. @acindex{HAVE_HEADERS}
  19661. Replaced by @code{AC_CHECK_HEADERS} (@pxref{AC_CHECK_HEADERS}).
  19662. @end defmac
  19663. @defmac AC_HAVE_LIBRARY (@var{library}, @ovar{action-if-found}, @
  19664. @ovar{action-if-not-found}, @ovar{other-libraries})
  19665. @acindex{HAVE_LIBRARY}
  19666. This macro is equivalent to calling @code{AC_CHECK_LIB} with a
  19667. @var{function} argument of @code{main}. In addition, @var{library} can
  19668. be written as any of @samp{foo}, @option{-lfoo}, or @samp{libfoo.a}. In
  19669. all of those cases, the compiler is passed @option{-lfoo}. However,
  19670. @var{library} cannot be a shell variable; it must be a literal name.
  19671. @xref{AC_CHECK_LIB}.
  19672. @end defmac
  19673. @defmac AC_HAVE_POUNDBANG
  19674. @acindex{HAVE_POUNDBANG}
  19675. Replaced by @code{AC_SYS_INTERPRETER} (@pxref{AC_SYS_INTERPRETER}).
  19676. @end defmac
  19677. @defmac AC_HEADER_CHECK
  19678. @acindex{HEADER_CHECK}
  19679. Replaced by @code{AC_CHECK_HEADER} (@pxref{AC_CHECK_HEADER}).
  19680. @end defmac
  19681. @defmac AC_HEADER_EGREP
  19682. @acindex{HEADER_EGREP}
  19683. Replaced by @code{AC_EGREP_HEADER} (@pxref{AC_EGREP_HEADER}).
  19684. @end defmac
  19685. @defmac AC_HELP_STRING
  19686. @acindex{HELP_STRING}
  19687. Replaced by @code{AS_HELP_STRING} (@pxref{AS_HELP_STRING}).
  19688. @end defmac
  19689. @defmac AC_INIT (@var{unique-file-in-source-dir})
  19690. @acindex{INIT}
  19691. Formerly @code{AC_INIT} used to have a single argument, and was
  19692. equivalent to:
  19693. @example
  19694. AC_INIT
  19695. AC_CONFIG_SRCDIR(@var{unique-file-in-source-dir})
  19696. @end example
  19697. See @ref{AC_INIT} and @ref{AC_CONFIG_SRCDIR}.
  19698. @end defmac
  19699. @defmac AC_INLINE
  19700. @acindex{INLINE}
  19701. Replaced by @code{AC_C_INLINE} (@pxref{AC_C_INLINE}).
  19702. @end defmac
  19703. @defmac AC_INT_16_BITS
  19704. @acindex{INT_16_BITS}
  19705. @cvindex INT_16_BITS
  19706. If the C type @code{int} is 16 bits wide, define @code{INT_16_BITS}.
  19707. Use @samp{AC_CHECK_SIZEOF(int)} instead (@pxref{AC_CHECK_SIZEOF}).
  19708. @end defmac
  19709. @defmac AC_IRIX_SUN
  19710. @acindex{IRIX_SUN}
  19711. If on IRIX (Silicon Graphics Unix), add @option{-lsun} to output
  19712. @code{LIBS}. If you were using it to get @code{getmntent}, use
  19713. @code{AC_FUNC_GETMNTENT} instead. If you used it for the NIS versions
  19714. of the password and group functions, use @samp{AC_CHECK_LIB(sun,
  19715. getpwnam)}. Up to Autoconf 2.13, it used to be
  19716. @example
  19717. AC_CHECK_LIB([sun], [getmntent], [LIBS="-lsun $LIBS"])
  19718. @end example
  19719. @noindent
  19720. now it is defined as
  19721. @example
  19722. AC_FUNC_GETMNTENT
  19723. AC_CHECK_LIB([sun], [getpwnam])
  19724. @end example
  19725. @noindent
  19726. See @ref{AC_FUNC_GETMNTENT} and @ref{AC_CHECK_LIB}.
  19727. @end defmac
  19728. @defmac AC_ISC_POSIX
  19729. @acindex{ISC_POSIX}
  19730. @ovindex LIBS
  19731. This macro adds @option{-lcposix} to output variable @code{LIBS} if
  19732. necessary for Posix facilities. Sun dropped support for the obsolete
  19733. INTERACTIVE Systems Corporation Unix on 2006-07-23. New programs
  19734. need not use this macro. It is implemented as
  19735. @code{AC_SEARCH_LIBS([strerror], [cposix])} (@pxref{AC_SEARCH_LIBS}).
  19736. @end defmac
  19737. @defmac AC_LANG_C
  19738. @acindex{LANG_C}
  19739. Same as @samp{AC_LANG([C])} (@pxref{AC_LANG}).
  19740. @end defmac
  19741. @defmac AC_LANG_CPLUSPLUS
  19742. @acindex{LANG_CPLUSPLUS}
  19743. Same as @samp{AC_LANG([C++])} (@pxref{AC_LANG}).
  19744. @end defmac
  19745. @defmac AC_LANG_FORTRAN77
  19746. @acindex{LANG_FORTRAN77}
  19747. Same as @samp{AC_LANG([Fortran 77])} (@pxref{AC_LANG}).
  19748. @end defmac
  19749. @defmac AC_LANG_RESTORE
  19750. @acindex{LANG_RESTORE}
  19751. Select the @var{language} that is saved on the top of the stack, as set
  19752. by @code{AC_LANG_SAVE}, remove it from the stack, and call
  19753. @code{AC_LANG(@var{language})}. @xref{Language Choice}, for the
  19754. preferred way to change languages.
  19755. @end defmac
  19756. @defmac AC_LANG_SAVE
  19757. @acindex{LANG_SAVE}
  19758. Remember the current language (as set by @code{AC_LANG}) on a stack.
  19759. The current language does not change. @code{AC_LANG_PUSH} is preferred
  19760. (@pxref{AC_LANG_PUSH}).
  19761. @end defmac
  19762. @defmac AC_LINK_FILES (@var{source}@dots{}, @var{dest}@dots{})
  19763. @acindex{LINK_FILES}
  19764. This is an obsolete version of @code{AC_CONFIG_LINKS}
  19765. (@pxref{AC_CONFIG_LINKS}. An updated version of:
  19766. @example
  19767. AC_LINK_FILES(config/$machine.h config/$obj_format.h,
  19768. host.h object.h)
  19769. @end example
  19770. @noindent
  19771. is:
  19772. @example
  19773. AC_CONFIG_LINKS([host.h:config/$machine.h
  19774. object.h:config/$obj_format.h])
  19775. @end example
  19776. @end defmac
  19777. @defmac AC_LN_S
  19778. @acindex{LN_S}
  19779. Replaced by @code{AC_PROG_LN_S} (@pxref{AC_PROG_LN_S}).
  19780. @end defmac
  19781. @defmac AC_LONG_64_BITS
  19782. @acindex{LONG_64_BITS}
  19783. @cvindex LONG_64_BITS
  19784. Define @code{LONG_64_BITS} if the C type @code{long int} is 64 bits wide.
  19785. Use the generic macro @samp{AC_CHECK_SIZEOF([long int])} instead
  19786. (@pxref{AC_CHECK_SIZEOF}).
  19787. @end defmac
  19788. @defmac AC_LONG_DOUBLE
  19789. @acindex{LONG_DOUBLE}
  19790. If the C compiler supports a working @code{long double} type with more
  19791. range or precision than the @code{double} type, define
  19792. @code{HAVE_LONG_DOUBLE}.
  19793. You should use @code{AC_TYPE_LONG_DOUBLE} or
  19794. @code{AC_TYPE_LONG_DOUBLE_WIDER} instead. @xref{Particular Types}.
  19795. @end defmac
  19796. @defmac AC_LONG_FILE_NAMES
  19797. @acindex{LONG_FILE_NAMES}
  19798. Replaced by
  19799. @example
  19800. AC_SYS_LONG_FILE_NAMES
  19801. @end example
  19802. @noindent
  19803. @xref{AC_SYS_LONG_FILE_NAMES}.
  19804. @end defmac
  19805. @defmac AC_MAJOR_HEADER
  19806. @acindex{MAJOR_HEADER}
  19807. Replaced by @code{AC_HEADER_MAJOR} (@pxref{AC_HEADER_MAJOR}).
  19808. @end defmac
  19809. @defmac AC_MEMORY_H
  19810. @acindex{MEMORY_H}
  19811. @cvindex NEED_MEMORY_H
  19812. Used to define @code{NEED_MEMORY_H} if the @code{mem} functions were
  19813. defined in @file{memory.h}. Today it is equivalent to
  19814. @samp{AC_CHECK_HEADERS([memory.h])} (@pxref{AC_CHECK_HEADERS}). Adjust
  19815. your code to depend upon
  19816. @code{HAVE_MEMORY_H}, not @code{NEED_MEMORY_H}; see @ref{Standard
  19817. Symbols}.
  19818. @end defmac
  19819. @defmac AC_MINGW32
  19820. @acindex{MINGW32}
  19821. Similar to @code{AC_CYGWIN} but checks for the MinGW compiler
  19822. environment and sets @code{MINGW32}. Don't use this macro, the
  19823. dignified means to check the nature of the host is using
  19824. @code{AC_CANONICAL_HOST} (@pxref{Canonicalizing}).
  19825. @end defmac
  19826. @defmac AC_MINIX
  19827. @acindex{MINIX}
  19828. @cvindex _MINIX
  19829. @cvindex _POSIX_SOURCE
  19830. @cvindex _POSIX_1_SOURCE
  19831. This macro is a platform-specific subset of
  19832. @code{AC_USE_SYSTEM_EXTENSIONS} (@pxref{AC_USE_SYSTEM_EXTENSIONS}).
  19833. @end defmac
  19834. @defmac AC_MINUS_C_MINUS_O
  19835. @acindex{MINUS_C_MINUS_O}
  19836. Replaced by @code{AC_PROG_CC_C_O} (@pxref{AC_PROG_CC_C_O}).
  19837. @end defmac
  19838. @defmac AC_MMAP
  19839. @acindex{MMAP}
  19840. Replaced by @code{AC_FUNC_MMAP} (@pxref{AC_FUNC_MMAP}).
  19841. @end defmac
  19842. @defmac AC_MODE_T
  19843. @acindex{MODE_T}
  19844. Replaced by @code{AC_TYPE_MODE_T} (@pxref{AC_TYPE_MODE_T}).
  19845. @end defmac
  19846. @defmac AC_OBJEXT
  19847. @acindex{OBJEXT}
  19848. @ovindex OBJEXT
  19849. Defined the output variable @code{OBJEXT} based on the output of the
  19850. compiler, after .c files have been excluded. Typically set to @samp{o}
  19851. if Posix, @samp{obj} if a DOS variant.
  19852. Now the compiler checking macros handle
  19853. this automatically.
  19854. @end defmac
  19855. @defmac AC_OBSOLETE (@var{this-macro-name}, @ovar{suggestion})
  19856. @acindex{OBSOLETE}
  19857. Make M4 print a message to the standard error output warning that
  19858. @var{this-macro-name} is obsolete, and giving the file and line number
  19859. where it was called. @var{this-macro-name} should be the name of the
  19860. macro that is calling @code{AC_OBSOLETE}. If @var{suggestion} is given,
  19861. it is printed at the end of the warning message; for example, it can be
  19862. a suggestion for what to use instead of @var{this-macro-name}.
  19863. For instance
  19864. @example
  19865. AC_OBSOLETE([$0], [; use AC_CHECK_HEADERS(unistd.h) instead])dnl
  19866. @end example
  19867. @noindent
  19868. You are encouraged to use @code{AU_DEFUN} instead, since it gives better
  19869. services to the user (@pxref{AU_DEFUN}).
  19870. @end defmac
  19871. @defmac AC_OFF_T
  19872. @acindex{OFF_T}
  19873. Replaced by @code{AC_TYPE_OFF_T} (@pxref{AC_TYPE_OFF_T}).
  19874. @end defmac
  19875. @defmac AC_OUTPUT (@ovar{file}@dots{}, @ovar{extra-cmds}, @ovar{init-cmds})
  19876. @acindex{OUTPUT}
  19877. The use of @code{AC_OUTPUT} with arguments is deprecated. This obsoleted
  19878. interface is equivalent to:
  19879. @example
  19880. @group
  19881. AC_CONFIG_FILES(@var{file}@dots{})
  19882. AC_CONFIG_COMMANDS([default],
  19883. @var{extra-cmds}, @var{init-cmds})
  19884. AC_OUTPUT
  19885. @end group
  19886. @end example
  19887. @noindent
  19888. See @ref{AC_CONFIG_FILES}, @ref{AC_CONFIG_COMMANDS}, and @ref{AC_OUTPUT}.
  19889. @end defmac
  19890. @defmac AC_OUTPUT_COMMANDS (@var{extra-cmds}, @ovar{init-cmds})
  19891. @acindex{OUTPUT_COMMANDS}
  19892. Specify additional shell commands to run at the end of
  19893. @file{config.status}, and shell commands to initialize any variables
  19894. from @command{configure}. This macro may be called multiple times. It is
  19895. obsolete, replaced by @code{AC_CONFIG_COMMANDS} (@pxref{AC_CONFIG_COMMANDS}).
  19896. Here is an unrealistic example:
  19897. @example
  19898. fubar=27
  19899. AC_OUTPUT_COMMANDS([echo this is extra $fubar, and so on.],
  19900. [fubar=$fubar])
  19901. AC_OUTPUT_COMMANDS([echo this is another, extra, bit],
  19902. [echo init bit])
  19903. @end example
  19904. Aside from the fact that @code{AC_CONFIG_COMMANDS} requires an
  19905. additional key, an important difference is that
  19906. @code{AC_OUTPUT_COMMANDS} is quoting its arguments twice, unlike
  19907. @code{AC_CONFIG_COMMANDS}. This means that @code{AC_CONFIG_COMMANDS}
  19908. can safely be given macro calls as arguments:
  19909. @example
  19910. AC_CONFIG_COMMANDS(foo, [my_FOO()])
  19911. @end example
  19912. @noindent
  19913. Conversely, where one level of quoting was enough for literal strings
  19914. with @code{AC_OUTPUT_COMMANDS}, you need two with
  19915. @code{AC_CONFIG_COMMANDS}. The following lines are equivalent:
  19916. @example
  19917. @group
  19918. AC_OUTPUT_COMMANDS([echo "Square brackets: []"])
  19919. AC_CONFIG_COMMANDS([default], [[echo "Square brackets: []"]])
  19920. @end group
  19921. @end example
  19922. @end defmac
  19923. @defmac AC_PID_T
  19924. @acindex{PID_T}
  19925. Replaced by @code{AC_TYPE_PID_T} (@pxref{AC_TYPE_PID_T}).
  19926. @end defmac
  19927. @defmac AC_PREFIX
  19928. @acindex{PREFIX}
  19929. Replaced by @code{AC_PREFIX_PROGRAM} (@pxref{AC_PREFIX_PROGRAM}).
  19930. @end defmac
  19931. @defmac AC_PROGRAMS_CHECK
  19932. @acindex{PROGRAMS_CHECK}
  19933. Replaced by @code{AC_CHECK_PROGS} (@pxref{AC_CHECK_PROGS}).
  19934. @end defmac
  19935. @defmac AC_PROGRAMS_PATH
  19936. @acindex{PROGRAMS_PATH}
  19937. Replaced by @code{AC_PATH_PROGS} (@pxref{AC_PATH_PROGS}).
  19938. @end defmac
  19939. @defmac AC_PROGRAM_CHECK
  19940. @acindex{PROGRAM_CHECK}
  19941. Replaced by @code{AC_CHECK_PROG} (@pxref{AC_CHECK_PROG}).
  19942. @end defmac
  19943. @defmac AC_PROGRAM_EGREP
  19944. @acindex{PROGRAM_EGREP}
  19945. Replaced by @code{AC_EGREP_CPP} (@pxref{AC_EGREP_CPP}).
  19946. @end defmac
  19947. @defmac AC_PROGRAM_PATH
  19948. @acindex{PROGRAM_PATH}
  19949. Replaced by @code{AC_PATH_PROG} (@pxref{AC_PATH_PROG}).
  19950. @end defmac
  19951. @defmac AC_REMOTE_TAPE
  19952. @acindex{REMOTE_TAPE}
  19953. Removed because of limited usefulness.
  19954. @end defmac
  19955. @defmac AC_RESTARTABLE_SYSCALLS
  19956. @acindex{RESTARTABLE_SYSCALLS}
  19957. This macro was renamed @code{AC_SYS_RESTARTABLE_SYSCALLS}. However,
  19958. these days portable programs should use @code{sigaction} with
  19959. @code{SA_RESTART} if they want restartable system calls. They should
  19960. not rely on @code{HAVE_RESTARTABLE_SYSCALLS}, since nowadays whether a
  19961. system call is restartable is a dynamic issue, not a configuration-time
  19962. issue.
  19963. @end defmac
  19964. @defmac AC_RETSIGTYPE
  19965. @acindex{RETSIGTYPE}
  19966. Replaced by @code{AC_TYPE_SIGNAL} (@pxref{AC_TYPE_SIGNAL}), which itself
  19967. is obsolete when assuming C89 or better.
  19968. @end defmac
  19969. @defmac AC_RSH
  19970. @acindex{RSH}
  19971. Removed because of limited usefulness.
  19972. @end defmac
  19973. @defmac AC_SCO_INTL
  19974. @acindex{SCO_INTL}
  19975. @ovindex LIBS
  19976. If on SCO Unix, add @option{-lintl} to output variable @code{LIBS}. This
  19977. macro used to do this:
  19978. @example
  19979. AC_CHECK_LIB([intl], [strftime], [LIBS="-lintl $LIBS"])
  19980. @end example
  19981. @noindent
  19982. Now it just calls @code{AC_FUNC_STRFTIME} instead (@pxref{AC_FUNC_STRFTIME}).
  19983. @end defmac
  19984. @defmac AC_SETVBUF_REVERSED
  19985. @acindex{SETVBUF_REVERSED}
  19986. Replaced by
  19987. @example
  19988. AC_FUNC_SETVBUF_REVERSED
  19989. @end example
  19990. @noindent
  19991. @xref{AC_FUNC_SETVBUF_REVERSED}.
  19992. @end defmac
  19993. @defmac AC_SET_MAKE
  19994. @acindex{SET_MAKE}
  19995. Replaced by @code{AC_PROG_MAKE_SET} (@pxref{AC_PROG_MAKE_SET}).
  19996. @end defmac
  19997. @defmac AC_SIZEOF_TYPE
  19998. @acindex{SIZEOF_TYPE}
  19999. Replaced by @code{AC_CHECK_SIZEOF} (@pxref{AC_CHECK_SIZEOF}).
  20000. @end defmac
  20001. @defmac AC_SIZE_T
  20002. @acindex{SIZE_T}
  20003. Replaced by @code{AC_TYPE_SIZE_T} (@pxref{AC_TYPE_SIZE_T}).
  20004. @end defmac
  20005. @defmac AC_STAT_MACROS_BROKEN
  20006. @acindex{STAT_MACROS_BROKEN}
  20007. Replaced by @code{AC_HEADER_STAT} (@pxref{AC_HEADER_STAT}).
  20008. @end defmac
  20009. @defmac AC_STDC_HEADERS
  20010. @acindex{STDC_HEADERS}
  20011. Replaced by @code{AC_HEADER_STDC} (@pxref{AC_HEADER_STDC}).
  20012. @end defmac
  20013. @defmac AC_STRCOLL
  20014. @acindex{STRCOLL}
  20015. Replaced by @code{AC_FUNC_STRCOLL} (@pxref{AC_FUNC_STRCOLL}).
  20016. @end defmac
  20017. @defmac AC_STRUCT_ST_BLKSIZE
  20018. @acindex{STRUCT_ST_BLKSIZE}
  20019. @cvindex HAVE_STRUCT_STAT_ST_BLKSIZE
  20020. @cvindex HAVE_ST_BLKSIZE
  20021. If @code{struct stat} contains an @code{st_blksize} member, define
  20022. @code{HAVE_STRUCT_STAT_ST_BLKSIZE}. The former name,
  20023. @code{HAVE_ST_BLKSIZE} is to be avoided, as its support will cease in
  20024. the future. This macro is obsoleted, and should be replaced by
  20025. @example
  20026. AC_CHECK_MEMBERS([struct stat.st_blksize])
  20027. @end example
  20028. @noindent
  20029. @xref{AC_CHECK_MEMBERS}.
  20030. @end defmac
  20031. @defmac AC_STRUCT_ST_RDEV
  20032. @acindex{STRUCT_ST_RDEV}
  20033. @cvindex HAVE_ST_RDEV
  20034. @cvindex HAVE_STRUCT_STAT_ST_RDEV
  20035. If @code{struct stat} contains an @code{st_rdev} member, define
  20036. @code{HAVE_STRUCT_STAT_ST_RDEV}. The former name for this macro,
  20037. @code{HAVE_ST_RDEV}, is to be avoided as it will cease to be supported
  20038. in the future. Actually, even the new macro is obsolete and should be
  20039. replaced by:
  20040. @example
  20041. AC_CHECK_MEMBERS([struct stat.st_rdev])
  20042. @end example
  20043. @noindent
  20044. @xref{AC_CHECK_MEMBERS}.
  20045. @end defmac
  20046. @defmac AC_ST_BLKSIZE
  20047. @acindex{ST_BLKSIZE}
  20048. Replaced by @code{AC_CHECK_MEMBERS} (@pxref{AC_CHECK_MEMBERS}).
  20049. @end defmac
  20050. @defmac AC_ST_BLOCKS
  20051. @acindex{ST_BLOCKS}
  20052. Replaced by @code{AC_STRUCT_ST_BLOCKS} (@pxref{AC_STRUCT_ST_BLOCKS}).
  20053. @end defmac
  20054. @defmac AC_ST_RDEV
  20055. @acindex{ST_RDEV}
  20056. Replaced by @code{AC_CHECK_MEMBERS} (@pxref{AC_CHECK_MEMBERS}).
  20057. @end defmac
  20058. @defmac AC_SYS_RESTARTABLE_SYSCALLS
  20059. @acindex{SYS_RESTARTABLE_SYSCALLS}
  20060. @cvindex HAVE_RESTARTABLE_SYSCALLS
  20061. If the system automatically restarts a system call that is interrupted
  20062. by a signal, define @code{HAVE_RESTARTABLE_SYSCALLS}. This macro does
  20063. not check whether system calls are restarted in general---it checks whether a
  20064. signal handler installed with @code{signal} (but not @code{sigaction})
  20065. causes system calls to be restarted. It does not check whether system calls
  20066. can be restarted when interrupted by signals that have no handler.
  20067. These days portable programs should use @code{sigaction} with
  20068. @code{SA_RESTART} if they want restartable system calls. They should
  20069. not rely on @code{HAVE_RESTARTABLE_SYSCALLS}, since nowadays whether a
  20070. system call is restartable is a dynamic issue, not a configuration-time
  20071. issue.
  20072. @end defmac
  20073. @defmac AC_SYS_SIGLIST_DECLARED
  20074. @acindex{SYS_SIGLIST_DECLARED}
  20075. This macro was renamed @code{AC_DECL_SYS_SIGLIST}. However, even that
  20076. name is obsolete, as the same functionality is now achieved via
  20077. @code{AC_CHECK_DECLS} (@pxref{AC_CHECK_DECLS}).
  20078. @end defmac
  20079. @defmac AC_TEST_CPP
  20080. @acindex{TEST_CPP}
  20081. This macro was renamed @code{AC_TRY_CPP}, which in turn was replaced by
  20082. @code{AC_PREPROC_IFELSE} (@pxref{AC_PREPROC_IFELSE}).
  20083. @end defmac
  20084. @defmac AC_TEST_PROGRAM
  20085. @acindex{TEST_PROGRAM}
  20086. This macro was renamed @code{AC_TRY_RUN}, which in turn was replaced by
  20087. @code{AC_RUN_IFELSE} (@pxref{AC_RUN_IFELSE}).
  20088. @end defmac
  20089. @defmac AC_TIMEZONE
  20090. @acindex{TIMEZONE}
  20091. Replaced by @code{AC_STRUCT_TIMEZONE} (@pxref{AC_STRUCT_TIMEZONE}).
  20092. @end defmac
  20093. @defmac AC_TIME_WITH_SYS_TIME
  20094. @acindex{TIME_WITH_SYS_TIME}
  20095. Replaced by @code{AC_HEADER_TIME} (@pxref{AC_HEADER_TIME}).
  20096. @end defmac
  20097. @defmac AC_TRY_COMPILE (@var{includes}, @var{function-body}, @
  20098. @ovar{action-if-true}, @ovar{action-if-false})
  20099. @acindex{TRY_COMPILE}
  20100. Same as:
  20101. @example
  20102. AC_COMPILE_IFELSE(
  20103. [AC_LANG_PROGRAM([[@var{includes}]],
  20104. [[@var{function-body}]])],
  20105. [@var{action-if-true}],
  20106. [@var{action-if-false}])
  20107. @end example
  20108. @noindent
  20109. @xref{Running the Compiler}.
  20110. This macro double quotes both @var{includes} and @var{function-body}.
  20111. For C and C++, @var{includes} is any @code{#include} statements needed
  20112. by the code in @var{function-body} (@var{includes} is ignored if
  20113. the currently selected language is Fortran or Fortran 77). The compiler
  20114. and compilation flags are determined by the current language
  20115. (@pxref{Language Choice}).
  20116. @end defmac
  20117. @defmac AC_TRY_CPP (@var{input}, @ovar{action-if-true}, @ovar{action-if-false})
  20118. @acindex{TRY_CPP}
  20119. Same as:
  20120. @example
  20121. AC_PREPROC_IFELSE(
  20122. [AC_LANG_SOURCE([[@var{input}]])],
  20123. [@var{action-if-true}],
  20124. [@var{action-if-false}])
  20125. @end example
  20126. @noindent
  20127. @xref{Running the Preprocessor}.
  20128. This macro double quotes the @var{input}.
  20129. @end defmac
  20130. @defmac AC_TRY_LINK (@var{includes}, @var{function-body}, @
  20131. @ovar{action-if-true}, @ovar{action-if-false})
  20132. @acindex{TRY_LINK}
  20133. Same as:
  20134. @example
  20135. AC_LINK_IFELSE(
  20136. [AC_LANG_PROGRAM([[@var{includes}]],
  20137. [[@var{function-body}]])],
  20138. [@var{action-if-true}],
  20139. [@var{action-if-false}])
  20140. @end example
  20141. @noindent
  20142. @xref{Running the Compiler}.
  20143. This macro double quotes both @var{includes} and @var{function-body}.
  20144. Depending on the current language (@pxref{Language Choice}), create a
  20145. test program to see whether a function whose body consists of
  20146. @var{function-body} can be compiled and linked. If the file compiles
  20147. and links successfully, run shell commands @var{action-if-found},
  20148. otherwise run @var{action-if-not-found}.
  20149. This macro double quotes both @var{includes} and @var{function-body}.
  20150. For C and C++, @var{includes} is any @code{#include} statements needed
  20151. by the code in @var{function-body} (@var{includes} is ignored if
  20152. the currently selected language is Fortran or Fortran 77). The compiler
  20153. and compilation flags are determined by the current language
  20154. (@pxref{Language Choice}), and in addition @code{LDFLAGS} and
  20155. @code{LIBS} are used for linking.
  20156. @end defmac
  20157. @defmac AC_TRY_LINK_FUNC (@var{function}, @ovar{action-if-found}, @
  20158. @ovar{action-if-not-found})
  20159. @acindex{TRY_LINK_FUNC}
  20160. This macro is equivalent to
  20161. @example
  20162. AC_LINK_IFELSE([AC_LANG_CALL([], [@var{function}])],
  20163. [@var{action-if-found}], [@var{action-if-not-found}])
  20164. @end example
  20165. @noindent
  20166. @xref{AC_LINK_IFELSE}.
  20167. @end defmac
  20168. @defmac AC_TRY_RUN (@var{program}, @ovar{action-if-true}, @
  20169. @ovar{action-if-false}, @dvar{action-if-cross-compiling, AC_MSG_FAILURE})
  20170. @acindex{TRY_RUN}
  20171. Same as:
  20172. @example
  20173. AC_RUN_IFELSE(
  20174. [AC_LANG_SOURCE([[@var{program}]])],
  20175. [@var{action-if-true}],
  20176. [@var{action-if-false}],
  20177. [@var{action-if-cross-compiling}])
  20178. @end example
  20179. @noindent
  20180. @xref{Runtime}.
  20181. @end defmac
  20182. @anchor{AC_TYPE_SIGNAL}
  20183. @defmac AC_TYPE_SIGNAL
  20184. @acindex{TYPE_SIGNAL}
  20185. @cvindex RETSIGTYPE
  20186. @hdrindex{signal.h}
  20187. If @file{signal.h} declares @code{signal} as returning a pointer to a
  20188. function returning @code{void}, define @code{RETSIGTYPE} to be
  20189. @code{void}; otherwise, define it to be @code{int}. These days, it is
  20190. portable to assume C89, and that signal handlers return @code{void},
  20191. without needing to use this macro or @code{RETSIGTYPE}.
  20192. When targeting older K&R C, it is possible to define signal handlers as
  20193. returning type @code{RETSIGTYPE}, and omit a return statement:
  20194. @example
  20195. @group
  20196. RETSIGTYPE
  20197. hup_handler ()
  20198. @{
  20199. @dots{}
  20200. @}
  20201. @end group
  20202. @end example
  20203. @end defmac
  20204. @defmac AC_UID_T
  20205. @acindex{UID_T}
  20206. Replaced by @code{AC_TYPE_UID_T} (@pxref{AC_TYPE_UID_T}).
  20207. @end defmac
  20208. @defmac AC_UNISTD_H
  20209. @acindex{UNISTD_H}
  20210. Same as @samp{AC_CHECK_HEADERS([unistd.h])} (@pxref{AC_CHECK_HEADERS}).
  20211. @end defmac
  20212. @defmac AC_USG
  20213. @acindex{USG}
  20214. @cvindex USG
  20215. Define @code{USG} if the BSD string functions are defined in
  20216. @file{strings.h}. You should no longer depend upon @code{USG}, but on
  20217. @code{HAVE_STRING_H}; see @ref{Standard Symbols}.
  20218. @end defmac
  20219. @defmac AC_UTIME_NULL
  20220. @acindex{UTIME_NULL}
  20221. Replaced by @code{AC_FUNC_UTIME_NULL} (@pxref{AC_FUNC_UTIME_NULL}).
  20222. @end defmac
  20223. @defmac AC_VALIDATE_CACHED_SYSTEM_TUPLE (@ovar{cmd})
  20224. @acindex{VALIDATE_CACHED_SYSTEM_TUPLE}
  20225. If the cache file is inconsistent with the current host, target and
  20226. build system types, it used to execute @var{cmd} or print a default
  20227. error message. This is now handled by default.
  20228. @end defmac
  20229. @defmac AC_VERBOSE (@var{result-description})
  20230. @acindex{VERBOSE}
  20231. Replaced by @code{AC_MSG_RESULT} (@pxref{AC_MSG_RESULT}).
  20232. @end defmac
  20233. @defmac AC_VFORK
  20234. @acindex{VFORK}
  20235. Replaced by @code{AC_FUNC_FORK} (@pxref{AC_FUNC_FORK}).
  20236. @end defmac
  20237. @defmac AC_VPRINTF
  20238. @acindex{VPRINTF}
  20239. Replaced by @code{AC_FUNC_VPRINTF} (@pxref{AC_FUNC_VPRINTF}).
  20240. @end defmac
  20241. @defmac AC_WAIT3
  20242. @acindex{WAIT3}
  20243. This macro was renamed @code{AC_FUNC_WAIT3}. However, these days
  20244. portable programs should use @code{waitpid}, not @code{wait3}, as
  20245. @code{wait3} has been removed from Posix.
  20246. @end defmac
  20247. @defmac AC_WARN
  20248. @acindex{WARN}
  20249. Replaced by @code{AC_MSG_WARN} (@pxref{AC_MSG_WARN}).
  20250. @end defmac
  20251. @defmac AC_WITH (@var{package}, @var{action-if-given}, @
  20252. @ovar{action-if-not-given})
  20253. @acindex{WITH}
  20254. This is an obsolete version of @code{AC_ARG_WITH} that does not
  20255. support providing a help string (@pxref{AC_ARG_WITH}).
  20256. @end defmac
  20257. @defmac AC_WORDS_BIGENDIAN
  20258. @acindex{WORDS_BIGENDIAN}
  20259. Replaced by @code{AC_C_BIGENDIAN} (@pxref{AC_C_BIGENDIAN}).
  20260. @end defmac
  20261. @defmac AC_XENIX_DIR
  20262. @acindex{XENIX_DIR}
  20263. @ovindex LIBS
  20264. This macro used to add @option{-lx} to output variable @code{LIBS} if on
  20265. Xenix. Also, if @file{dirent.h} is being checked for, added
  20266. @option{-ldir} to @code{LIBS}. Now it is merely an alias of
  20267. @code{AC_HEADER_DIRENT} instead, plus some code to detect whether
  20268. running XENIX on which you should not depend:
  20269. @example
  20270. AC_MSG_CHECKING([for Xenix])
  20271. AC_EGREP_CPP([yes],
  20272. [#if defined M_XENIX && !defined M_UNIX
  20273. yes
  20274. #endif],
  20275. [AC_MSG_RESULT([yes]); XENIX=yes],
  20276. [AC_MSG_RESULT([no]); XENIX=])
  20277. @end example
  20278. @noindent
  20279. Don't use this macro, the dignified means to check the nature of the
  20280. host is using @code{AC_CANONICAL_HOST} (@pxref{Canonicalizing}).
  20281. @end defmac
  20282. @defmac AC_YYTEXT_POINTER
  20283. @acindex{YYTEXT_POINTER}
  20284. This macro was renamed @code{AC_DECL_YYTEXT}, which in turn was
  20285. integrated into @code{AC_PROG_LEX} (@pxref{AC_PROG_LEX}).
  20286. @end defmac
  20287. @node Autoconf 1
  20288. @section Upgrading From Version 1
  20289. @cindex Upgrading autoconf
  20290. @cindex Autoconf upgrading
  20291. Autoconf version 2 is mostly backward compatible with version 1.
  20292. However, it introduces better ways to do some things, and doesn't
  20293. support some of the ugly things in version 1. So, depending on how
  20294. sophisticated your @file{configure.ac} files are, you might have to do
  20295. some manual work in order to upgrade to version 2. This chapter points
  20296. out some problems to watch for when upgrading. Also, perhaps your
  20297. @command{configure} scripts could benefit from some of the new features in
  20298. version 2; the changes are summarized in the file @file{NEWS} in the
  20299. Autoconf distribution.
  20300. @menu
  20301. * Changed File Names:: Files you might rename
  20302. * Changed Makefiles:: New things to put in @file{Makefile.in}
  20303. * Changed Macros:: Macro calls you might replace
  20304. * Changed Results:: Changes in how to check test results
  20305. * Changed Macro Writing:: Better ways to write your own macros
  20306. @end menu
  20307. @node Changed File Names
  20308. @subsection Changed File Names
  20309. If you have an @file{aclocal.m4} installed with Autoconf (as opposed to
  20310. in a particular package's source directory), you must rename it to
  20311. @file{acsite.m4}. @xref{autoconf Invocation}.
  20312. If you distribute @file{install.sh} with your package, rename it to
  20313. @file{install-sh} so @command{make} builtin rules don't inadvertently
  20314. create a file called @file{install} from it. @code{AC_PROG_INSTALL}
  20315. looks for the script under both names, but it is best to use the new name.
  20316. If you were using @file{config.h.top}, @file{config.h.bot}, or
  20317. @file{acconfig.h}, you still can, but you have less clutter if you
  20318. use the @code{AH_} macros. @xref{Autoheader Macros}.
  20319. @node Changed Makefiles
  20320. @subsection Changed Makefiles
  20321. Add @samp{@@CFLAGS@@}, @samp{@@CPPFLAGS@@}, and @samp{@@LDFLAGS@@} in
  20322. your @file{Makefile.in} files, so they can take advantage of the values
  20323. of those variables in the environment when @command{configure} is run.
  20324. Doing this isn't necessary, but it's a convenience for users.
  20325. Also add @samp{@@configure_input@@} in a comment to each input file for
  20326. @code{AC_OUTPUT}, so that the output files contain a comment saying
  20327. they were produced by @command{configure}. Automatically selecting the
  20328. right comment syntax for all the kinds of files that people call
  20329. @code{AC_OUTPUT} on became too much work.
  20330. Add @file{config.log} and @file{config.cache} to the list of files you
  20331. remove in @code{distclean} targets.
  20332. If you have the following in @file{Makefile.in}:
  20333. @example
  20334. prefix = /usr/local
  20335. exec_prefix = $(prefix)
  20336. @end example
  20337. @noindent
  20338. you must change it to:
  20339. @example
  20340. prefix = @@prefix@@
  20341. exec_prefix = @@exec_prefix@@
  20342. @end example
  20343. @noindent
  20344. The old behavior of replacing those variables without @samp{@@}
  20345. characters around them has been removed.
  20346. @node Changed Macros
  20347. @subsection Changed Macros
  20348. Many of the macros were renamed in Autoconf version 2. You can still
  20349. use the old names, but the new ones are clearer, and it's easier to find
  20350. the documentation for them. @xref{Obsolete Macros}, for a table showing the
  20351. new names for the old macros. Use the @command{autoupdate} program to
  20352. convert your @file{configure.ac} to using the new macro names.
  20353. @xref{autoupdate Invocation}.
  20354. Some macros have been superseded by similar ones that do the job better,
  20355. but are not call-compatible. If you get warnings about calling obsolete
  20356. macros while running @command{autoconf}, you may safely ignore them, but
  20357. your @command{configure} script generally works better if you follow
  20358. the advice that is printed about what to replace the obsolete macros with. In
  20359. particular, the mechanism for reporting the results of tests has
  20360. changed. If you were using @command{echo} or @code{AC_VERBOSE} (perhaps
  20361. via @code{AC_COMPILE_CHECK}), your @command{configure} script's output
  20362. looks better if you switch to @code{AC_MSG_CHECKING} and
  20363. @code{AC_MSG_RESULT}. @xref{Printing Messages}. Those macros work best
  20364. in conjunction with cache variables. @xref{Caching Results}.
  20365. @node Changed Results
  20366. @subsection Changed Results
  20367. If you were checking the results of previous tests by examining the
  20368. shell variable @code{DEFS}, you need to switch to checking the values of
  20369. the cache variables for those tests. @code{DEFS} no longer exists while
  20370. @command{configure} is running; it is only created when generating output
  20371. files. This difference from version 1 is because properly quoting the
  20372. contents of that variable turned out to be too cumbersome and
  20373. inefficient to do every time @code{AC_DEFINE} is called. @xref{Cache
  20374. Variable Names}.
  20375. For example, here is a @file{configure.ac} fragment written for Autoconf
  20376. version 1:
  20377. @example
  20378. AC_HAVE_FUNCS(syslog)
  20379. case "$DEFS" in
  20380. *-DHAVE_SYSLOG*) ;;
  20381. *) # syslog is not in the default libraries. See if it's in some other.
  20382. saved_LIBS="$LIBS"
  20383. for lib in bsd socket inet; do
  20384. AC_CHECKING(for syslog in -l$lib)
  20385. LIBS="-l$lib $saved_LIBS"
  20386. AC_HAVE_FUNCS(syslog)
  20387. case "$DEFS" in
  20388. *-DHAVE_SYSLOG*) break ;;
  20389. *) ;;
  20390. esac
  20391. LIBS="$saved_LIBS"
  20392. done ;;
  20393. esac
  20394. @end example
  20395. Here is a way to write it for version 2:
  20396. @example
  20397. AC_CHECK_FUNCS([syslog])
  20398. if test "x$ac_cv_func_syslog" = xno; then
  20399. # syslog is not in the default libraries. See if it's in some other.
  20400. for lib in bsd socket inet; do
  20401. AC_CHECK_LIB([$lib], [syslog], [AC_DEFINE([HAVE_SYSLOG])
  20402. LIBS="-l$lib $LIBS"; break])
  20403. done
  20404. fi
  20405. @end example
  20406. If you were working around bugs in @code{AC_DEFINE_UNQUOTED} by adding
  20407. backslashes before quotes, you need to remove them. It now works
  20408. predictably, and does not treat quotes (except back quotes) specially.
  20409. @xref{Setting Output Variables}.
  20410. All of the Boolean shell variables set by Autoconf macros now use
  20411. @samp{yes} for the true value. Most of them use @samp{no} for false,
  20412. though for backward compatibility some use the empty string instead. If
  20413. you were relying on a shell variable being set to something like 1 or
  20414. @samp{t} for true, you need to change your tests.
  20415. @node Changed Macro Writing
  20416. @subsection Changed Macro Writing
  20417. When defining your own macros, you should now use @code{AC_DEFUN}
  20418. instead of @code{define}. @code{AC_DEFUN} automatically calls
  20419. @code{AC_PROVIDE} and ensures that macros called via @code{AC_REQUIRE}
  20420. do not interrupt other macros, to prevent nested @samp{checking@dots{}}
  20421. messages on the screen. There's no actual harm in continuing to use the
  20422. older way, but it's less convenient and attractive. @xref{Macro
  20423. Definitions}.
  20424. You probably looked at the macros that came with Autoconf as a guide for
  20425. how to do things. It would be a good idea to take a look at the new
  20426. versions of them, as the style is somewhat improved and they take
  20427. advantage of some new features.
  20428. If you were doing tricky things with undocumented Autoconf internals
  20429. (macros, variables, diversions), check whether you need to change
  20430. anything to account for changes that have been made. Perhaps you can
  20431. even use an officially supported technique in version 2 instead of
  20432. kludging. Or perhaps not.
  20433. To speed up your locally written feature tests, add caching to them.
  20434. See whether any of your tests are of general enough usefulness to
  20435. encapsulate them into macros that you can share.
  20436. @node Autoconf 2.13
  20437. @section Upgrading From Version 2.13
  20438. @cindex Upgrading autoconf
  20439. @cindex Autoconf upgrading
  20440. The introduction of the previous section (@pxref{Autoconf 1}) perfectly
  20441. suits this section@enddots{}
  20442. @quotation
  20443. Autoconf version 2.50 is mostly backward compatible with version 2.13.
  20444. However, it introduces better ways to do some things, and doesn't
  20445. support some of the ugly things in version 2.13. So, depending on how
  20446. sophisticated your @file{configure.ac} files are, you might have to do
  20447. some manual work in order to upgrade to version 2.50. This chapter
  20448. points out some problems to watch for when upgrading. Also, perhaps
  20449. your @command{configure} scripts could benefit from some of the new
  20450. features in version 2.50; the changes are summarized in the file
  20451. @file{NEWS} in the Autoconf distribution.
  20452. @end quotation
  20453. @menu
  20454. * Changed Quotation:: Broken code which used to work
  20455. * New Macros:: Interaction with foreign macros
  20456. * Hosts and Cross-Compilation:: Bugward compatibility kludges
  20457. * AC_LIBOBJ vs LIBOBJS:: LIBOBJS is a forbidden token
  20458. * AC_ACT_IFELSE vs AC_TRY_ACT:: A more generic scheme for testing sources
  20459. @end menu
  20460. @node Changed Quotation
  20461. @subsection Changed Quotation
  20462. The most important changes are invisible to you: the implementation of
  20463. most macros have completely changed. This allowed more factorization of
  20464. the code, better error messages, a higher uniformity of the user's
  20465. interface etc. Unfortunately, as a side effect, some construct which
  20466. used to (miraculously) work might break starting with Autoconf 2.50.
  20467. The most common culprit is bad quotation.
  20468. For instance, in the following example, the message is not properly
  20469. quoted:
  20470. @example
  20471. AC_INIT
  20472. AC_CHECK_HEADERS(foo.h, ,
  20473. AC_MSG_ERROR(cannot find foo.h, bailing out))
  20474. AC_OUTPUT
  20475. @end example
  20476. @noindent
  20477. Autoconf 2.13 simply ignores it:
  20478. @example
  20479. $ @kbd{autoconf-2.13; ./configure --silent}
  20480. creating cache ./config.cache
  20481. configure: error: cannot find foo.h
  20482. $
  20483. @end example
  20484. @noindent
  20485. while Autoconf 2.50 produces a broken @file{configure}:
  20486. @example
  20487. $ @kbd{autoconf-2.50; ./configure --silent}
  20488. configure: error: cannot find foo.h
  20489. ./configure: exit: bad non-numeric arg `bailing'
  20490. ./configure: exit: bad non-numeric arg `bailing'
  20491. $
  20492. @end example
  20493. The message needs to be quoted, and the @code{AC_MSG_ERROR} invocation
  20494. too!
  20495. @example
  20496. AC_INIT([Example], [1.0], [bug-example@@example.org])
  20497. AC_CHECK_HEADERS([foo.h], [],
  20498. [AC_MSG_ERROR([cannot find foo.h, bailing out])])
  20499. AC_OUTPUT
  20500. @end example
  20501. Many many (and many more) Autoconf macros were lacking proper quotation,
  20502. including no less than@dots{} @code{AC_DEFUN} itself!
  20503. @example
  20504. $ @kbd{cat configure.in}
  20505. AC_DEFUN([AC_PROG_INSTALL],
  20506. [# My own much better version
  20507. ])
  20508. AC_INIT
  20509. AC_PROG_INSTALL
  20510. AC_OUTPUT
  20511. $ @kbd{autoconf-2.13}
  20512. autoconf: Undefined macros:
  20513. ***BUG in Autoconf--please report*** AC_FD_MSG
  20514. ***BUG in Autoconf--please report*** AC_EPI
  20515. configure.in:1:AC_DEFUN([AC_PROG_INSTALL],
  20516. configure.in:5:AC_PROG_INSTALL
  20517. $ @kbd{autoconf-2.50}
  20518. $
  20519. @end example
  20520. @node New Macros
  20521. @subsection New Macros
  20522. @cindex undefined macro
  20523. @cindex @code{_m4_divert_diversion}
  20524. While Autoconf was relatively dormant in the late 1990s, Automake
  20525. provided Autoconf-like macros for a while. Starting with Autoconf 2.50
  20526. in 2001, Autoconf provided
  20527. versions of these macros, integrated in the @code{AC_} namespace,
  20528. instead of @code{AM_}. But in order to ease the upgrading via
  20529. @command{autoupdate}, bindings to such @code{AM_} macros are provided.
  20530. Unfortunately older versions of Automake (e.g., Automake 1.4)
  20531. did not quote the names of these macros.
  20532. Therefore, when @command{m4} finds something like
  20533. @samp{AC_DEFUN(AM_TYPE_PTRDIFF_T, @dots{})} in @file{aclocal.m4},
  20534. @code{AM_TYPE_PTRDIFF_T} is
  20535. expanded, replaced with its Autoconf definition.
  20536. Fortunately Autoconf catches pre-@code{AC_INIT} expansions, and
  20537. complains, in its own words:
  20538. @example
  20539. $ @kbd{cat configure.ac}
  20540. AC_INIT([Example], [1.0], [bug-example@@example.org])
  20541. AM_TYPE_PTRDIFF_T
  20542. $ @kbd{aclocal-1.4}
  20543. $ @kbd{autoconf}
  20544. aclocal.m4:17: error: m4_defn: undefined macro: _m4_divert_diversion
  20545. aclocal.m4:17: the top level
  20546. autom4te: m4 failed with exit status: 1
  20547. $
  20548. @end example
  20549. Modern versions of Automake no longer define most of these
  20550. macros, and properly quote the names of the remaining macros.
  20551. If you must use an old Automake, do not depend upon macros from Automake
  20552. as it is simply not its job
  20553. to provide macros (but the one it requires itself):
  20554. @example
  20555. $ @kbd{cat configure.ac}
  20556. AC_INIT([Example], [1.0], [bug-example@@example.org])
  20557. AM_TYPE_PTRDIFF_T
  20558. $ @kbd{rm aclocal.m4}
  20559. $ @kbd{autoupdate}
  20560. autoupdate: `configure.ac' is updated
  20561. $ @kbd{cat configure.ac}
  20562. AC_INIT([Example], [1.0], [bug-example@@example.org])
  20563. AC_CHECK_TYPES([ptrdiff_t])
  20564. $ @kbd{aclocal-1.4}
  20565. $ @kbd{autoconf}
  20566. $
  20567. @end example
  20568. @node Hosts and Cross-Compilation
  20569. @subsection Hosts and Cross-Compilation
  20570. @cindex Cross compilation
  20571. Based on the experience of compiler writers, and after long public
  20572. debates, many aspects of the cross-compilation chain have changed:
  20573. @itemize @minus
  20574. @item
  20575. the relationship between the build, host, and target architecture types,
  20576. @item
  20577. the command line interface for specifying them to @command{configure},
  20578. @item
  20579. the variables defined in @command{configure},
  20580. @item
  20581. the enabling of cross-compilation mode.
  20582. @end itemize
  20583. @sp 1
  20584. The relationship between build, host, and target have been cleaned up:
  20585. the chain of default is now simply: target defaults to host, host to
  20586. build, and build to the result of @command{config.guess}. Nevertheless,
  20587. in order to ease the transition from 2.13 to 2.50, the following
  20588. transition scheme is implemented. @emph{Do not rely on it}, as it will
  20589. be completely disabled in a couple of releases (we cannot keep it, as it
  20590. proves to cause more problems than it cures).
  20591. They all default to the result of running @command{config.guess}, unless
  20592. you specify either @option{--build} or @option{--host}. In this case,
  20593. the default becomes the system type you specified. If you specify both,
  20594. and they're different, @command{configure} enters cross compilation
  20595. mode, so it doesn't run any tests that require execution.
  20596. Hint: if you mean to override the result of @command{config.guess},
  20597. prefer @option{--build} over @option{--host}.
  20598. @sp 1
  20599. For backward compatibility, @command{configure} accepts a system
  20600. type as an option by itself. Such an option overrides the
  20601. defaults for build, host, and target system types. The following
  20602. configure statement configures a cross toolchain that runs on
  20603. NetBSD/alpha but generates code for GNU Hurd/sparc,
  20604. which is also the build platform.
  20605. @example
  20606. ./configure --host=alpha-netbsd sparc-gnu
  20607. @end example
  20608. @sp 1
  20609. In Autoconf 2.13 and before, the variables @code{build}, @code{host},
  20610. and @code{target} had a different semantics before and after the
  20611. invocation of @code{AC_CANONICAL_BUILD} etc. Now, the argument of
  20612. @option{--build} is strictly copied into @code{build_alias}, and is left
  20613. empty otherwise. After the @code{AC_CANONICAL_BUILD}, @code{build} is
  20614. set to the canonicalized build type. To ease the transition, before,
  20615. its contents is the same as that of @code{build_alias}. Do @emph{not}
  20616. rely on this broken feature.
  20617. For consistency with the backward compatibility scheme exposed above,
  20618. when @option{--host} is specified but @option{--build} isn't, the build
  20619. system is assumed to be the same as @option{--host}, and
  20620. @samp{build_alias} is set to that value. Eventually, this
  20621. historically incorrect behavior will go away.
  20622. @sp 1
  20623. The former scheme to enable cross-compilation proved to cause more harm
  20624. than good, in particular, it used to be triggered too easily, leaving
  20625. regular end users puzzled in front of cryptic error messages.
  20626. @command{configure} could even enter cross-compilation mode only
  20627. because the compiler was not functional. This is mainly because
  20628. @command{configure} used to try to detect cross-compilation, instead of
  20629. waiting for an explicit flag from the user.
  20630. Now, @command{configure} enters cross-compilation mode if and only if
  20631. @option{--host} is passed.
  20632. That's the short documentation. To ease the transition between 2.13 and
  20633. its successors, a more complicated scheme is implemented. @emph{Do not
  20634. rely on the following}, as it will be removed in the near future.
  20635. If you specify @option{--host}, but not @option{--build}, when
  20636. @command{configure} performs the first compiler test it tries to run
  20637. an executable produced by the compiler. If the execution fails, it
  20638. enters cross-compilation mode. This is fragile. Moreover, by the time
  20639. the compiler test is performed, it may be too late to modify the
  20640. build-system type: other tests may have already been performed.
  20641. Therefore, whenever you specify @option{--host}, be sure to specify
  20642. @option{--build} too.
  20643. @example
  20644. ./configure --build=i686-pc-linux-gnu --host=m68k-coff
  20645. @end example
  20646. @noindent
  20647. enters cross-compilation mode. The former interface, which
  20648. consisted in setting the compiler to a cross-compiler without informing
  20649. @command{configure} is obsolete. For instance, @command{configure}
  20650. fails if it can't run the code generated by the specified compiler if you
  20651. configure as follows:
  20652. @example
  20653. ./configure CC=m68k-coff-gcc
  20654. @end example
  20655. @node AC_LIBOBJ vs LIBOBJS
  20656. @subsection @code{AC_LIBOBJ} vs.@: @code{LIBOBJS}
  20657. Up to Autoconf 2.13, the replacement of functions was triggered via the
  20658. variable @code{LIBOBJS}. Since Autoconf 2.50, the macro
  20659. @code{AC_LIBOBJ} should be used instead (@pxref{Generic Functions}).
  20660. Starting at Autoconf 2.53, the use of @code{LIBOBJS} is an error.
  20661. This change is mandated by the unification of the GNU Build System
  20662. components. In particular, the various fragile techniques used to parse
  20663. a @file{configure.ac} are all replaced with the use of traces. As a
  20664. consequence, any action must be traceable, which obsoletes critical
  20665. variable assignments. Fortunately, @code{LIBOBJS} was the only problem,
  20666. and it can even be handled gracefully (read, ``without your having to
  20667. change something'').
  20668. There were two typical uses of @code{LIBOBJS}: asking for a replacement
  20669. function, and adjusting @code{LIBOBJS} for Automake and/or Libtool.
  20670. @sp 1
  20671. As for function replacement, the fix is immediate: use
  20672. @code{AC_LIBOBJ}. For instance:
  20673. @example
  20674. LIBOBJS="$LIBOBJS fnmatch.o"
  20675. LIBOBJS="$LIBOBJS malloc.$ac_objext"
  20676. @end example
  20677. @noindent
  20678. should be replaced with:
  20679. @example
  20680. AC_LIBOBJ([fnmatch])
  20681. AC_LIBOBJ([malloc])
  20682. @end example
  20683. @sp 1
  20684. @ovindex LIBOBJDIR
  20685. When used with Automake 1.10 or newer, a suitable value for
  20686. @code{LIBOBJDIR} is set so that the @code{LIBOBJS} and @code{LTLIBOBJS}
  20687. can be referenced from any @file{Makefile.am}. Even without Automake,
  20688. arranging for @code{LIBOBJDIR} to be set correctly enables
  20689. referencing @code{LIBOBJS} and @code{LTLIBOBJS} in another directory.
  20690. The @code{LIBOBJDIR} feature is experimental.
  20691. @node AC_ACT_IFELSE vs AC_TRY_ACT
  20692. @subsection @code{AC_@var{ACT}_IFELSE} vs.@: @code{AC_TRY_@var{ACT}}
  20693. @c the anchor keeps the old node name, to try to avoid breaking links
  20694. @anchor{AC_FOO_IFELSE vs AC_TRY_FOO}
  20695. @acindex{@var{ACT}_IFELSE}
  20696. @acindex{TRY_@var{ACT}}
  20697. Since Autoconf 2.50, internal codes uses @code{AC_PREPROC_IFELSE},
  20698. @code{AC_COMPILE_IFELSE}, @code{AC_LINK_IFELSE}, and
  20699. @code{AC_RUN_IFELSE} on one hand and @code{AC_LANG_SOURCE},
  20700. and @code{AC_LANG_PROGRAM} on the other hand instead of the deprecated
  20701. @code{AC_TRY_CPP}, @code{AC_TRY_COMPILE}, @code{AC_TRY_LINK}, and
  20702. @code{AC_TRY_RUN}. The motivations where:
  20703. @itemize @minus
  20704. @item
  20705. a more consistent interface: @code{AC_TRY_COMPILE} etc.@: were double
  20706. quoting their arguments;
  20707. @item
  20708. the combinatoric explosion is solved by decomposing on the one hand the
  20709. generation of sources, and on the other hand executing the program;
  20710. @item
  20711. this scheme helps supporting more languages than plain C and C++.
  20712. @end itemize
  20713. In addition to the change of syntax, the philosophy has changed too:
  20714. while emphasis was put on speed at the expense of accuracy, today's
  20715. Autoconf promotes accuracy of the testing framework at, ahem@dots{}, the
  20716. expense of speed.
  20717. As a perfect example of what is @emph{not} to be done, here is how to
  20718. find out whether a header file contains a particular declaration, such
  20719. as a typedef, a structure, a structure member, or a function. Use
  20720. @code{AC_EGREP_HEADER} instead of running @code{grep} directly on the
  20721. header file; on some systems the symbol might be defined in another
  20722. header file that the file you are checking includes.
  20723. As a (bad) example, here is how you should not check for C preprocessor
  20724. symbols, either defined by header files or predefined by the C
  20725. preprocessor: using @code{AC_EGREP_CPP}:
  20726. @example
  20727. @group
  20728. AC_EGREP_CPP(yes,
  20729. [#ifdef _AIX
  20730. yes
  20731. #endif
  20732. ], is_aix=yes, is_aix=no)
  20733. @end group
  20734. @end example
  20735. The above example, properly written would (i) use
  20736. @code{AC_LANG_PROGRAM}, and (ii) run the compiler:
  20737. @example
  20738. @group
  20739. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  20740. [[#ifndef _AIX
  20741. error: This isn't AIX!
  20742. #endif
  20743. ]])],
  20744. [is_aix=yes],
  20745. [is_aix=no])
  20746. @end group
  20747. @end example
  20748. @c ============================= Generating Test Suites with Autotest
  20749. @node Using Autotest
  20750. @chapter Generating Test Suites with Autotest
  20751. @cindex Autotest
  20752. @display
  20753. @strong{N.B.: This section describes a feature which is still
  20754. stabilizing. Although we believe that Autotest is useful as-is, this
  20755. documentation describes an interface which might change in the future:
  20756. do not depend upon Autotest without subscribing to the Autoconf mailing
  20757. lists.}
  20758. @end display
  20759. It is paradoxical that portable projects depend on nonportable tools
  20760. to run their test suite. Autoconf by itself is the paragon of this
  20761. problem: although it aims at perfectly portability, up to 2.13 its
  20762. test suite was using DejaGNU, a rich and complex testing
  20763. framework, but which is far from being standard on Posix systems.
  20764. Worse yet, it was likely to be missing on the most fragile platforms,
  20765. the very platforms that are most likely to torture Autoconf and
  20766. exhibit deficiencies.
  20767. To circumvent this problem, many package maintainers have developed their
  20768. own testing framework, based on simple shell scripts whose sole outputs
  20769. are exit status values describing whether the test succeeded. Most of
  20770. these tests share common patterns, and this can result in lots of
  20771. duplicated code and tedious maintenance.
  20772. Following exactly the same reasoning that yielded to the inception of
  20773. Autoconf, Autotest provides a test suite generation framework, based on
  20774. M4 macros building a portable shell script. The suite itself is
  20775. equipped with automatic logging and tracing facilities which greatly
  20776. diminish the interaction with bug reporters, and simple timing reports.
  20777. Autoconf itself has been using Autotest for years, and we do attest that
  20778. it has considerably improved the strength of the test suite and the
  20779. quality of bug reports. Other projects are known to use some generation
  20780. of Autotest, such as Bison, Free Recode, Free Wdiff, GNU Tar, each of
  20781. them with different needs, and this usage has validated Autotest as a general
  20782. testing framework.
  20783. Nonetheless, compared to DejaGNU, Autotest is inadequate for
  20784. interactive tool testing, which is probably its main limitation.
  20785. @menu
  20786. * Using an Autotest Test Suite:: Autotest and the user
  20787. * Writing Testsuites:: Autotest macros
  20788. * testsuite Invocation:: Running @command{testsuite} scripts
  20789. * Making testsuite Scripts:: Using autom4te to create @command{testsuite}
  20790. @end menu
  20791. @node Using an Autotest Test Suite
  20792. @section Using an Autotest Test Suite
  20793. @menu
  20794. * testsuite Scripts:: The concepts of Autotest
  20795. * Autotest Logs:: Their contents
  20796. @end menu
  20797. @node testsuite Scripts
  20798. @subsection @command{testsuite} Scripts
  20799. @cindex @command{testsuite}
  20800. Generating testing or validation suites using Autotest is rather easy.
  20801. The whole validation suite is held in a file to be processed through
  20802. @command{autom4te}, itself using GNU M4 under the hood, to
  20803. produce a stand-alone Bourne shell script which then gets distributed.
  20804. Neither @command{autom4te} nor GNU M4 are needed at
  20805. the installer's end.
  20806. @cindex test group
  20807. Each test of the validation suite should be part of some test group. A
  20808. @dfn{test group} is a sequence of interwoven tests that ought to be
  20809. executed together, usually because one test in the group creates data
  20810. files that a later test in the same group needs to read. Complex test
  20811. groups make later debugging more tedious. It is much better to
  20812. keep only a few tests per test group. Ideally there is only one test
  20813. per test group.
  20814. For all but the simplest packages, some file such as @file{testsuite.at}
  20815. does not fully hold all test sources, as these are often easier to
  20816. maintain in separate files. Each of these separate files holds a single
  20817. test group, or a sequence of test groups all addressing some common
  20818. functionality in the package. In such cases, @file{testsuite.at}
  20819. merely initializes the validation suite, and sometimes does elementary
  20820. health checking, before listing include statements for all other test
  20821. files. The special file @file{package.m4}, containing the
  20822. identification of the package, is automatically included if found.
  20823. A convenient alternative consists in moving all the global issues
  20824. (local Autotest macros, elementary health checking, and @code{AT_INIT}
  20825. invocation) into the file @code{local.at}, and making
  20826. @file{testsuite.at} be a simple list of @code{m4_include}s of sub test
  20827. suites. In such case, generating the whole test suite or pieces of it
  20828. is only a matter of choosing the @command{autom4te} command line
  20829. arguments.
  20830. The validation scripts that Autotest produces are by convention called
  20831. @command{testsuite}. When run, @command{testsuite} executes each test
  20832. group in turn, producing only one summary line per test to say if that
  20833. particular test succeeded or failed. At end of all tests, summarizing
  20834. counters get printed. One debugging directory is left for each test
  20835. group which failed, if any: such directories are named
  20836. @file{testsuite.dir/@var{nn}}, where @var{nn} is the sequence number of
  20837. the test group, and they include:
  20838. @itemize @bullet
  20839. @item a debugging script named @file{run} which reruns the test in
  20840. @dfn{debug mode} (@pxref{testsuite Invocation}). The automatic generation
  20841. of debugging scripts has the purpose of easing the chase for bugs.
  20842. @item all the files created with @code{AT_DATA}
  20843. @item all the Erlang source code files created with @code{AT_CHECK_EUNIT}
  20844. @item a log of the run, named @file{testsuite.log}
  20845. @end itemize
  20846. In the ideal situation, none of the tests fail, and consequently no
  20847. debugging directory is left behind for validation.
  20848. It often happens in practice that individual tests in the validation
  20849. suite need to get information coming out of the configuration process.
  20850. Some of this information, common for all validation suites, is provided
  20851. through the file @file{atconfig}, automatically created by
  20852. @code{AC_CONFIG_TESTDIR}. For configuration information which your
  20853. testing environment specifically needs, you might prepare an optional
  20854. file named @file{atlocal.in}, instantiated by @code{AC_CONFIG_FILES}.
  20855. The configuration process produces @file{atconfig} and @file{atlocal}
  20856. out of these two input files, and these two produced files are
  20857. automatically read by the @file{testsuite} script.
  20858. Here is a diagram showing the relationship between files.
  20859. @noindent
  20860. Files used in preparing a software package for distribution:
  20861. @example
  20862. [package.m4] -->.
  20863. \
  20864. subfile-1.at ->. [local.at] ---->+
  20865. ... \ \
  20866. subfile-i.at ---->-- testsuite.at -->-- autom4te* -->testsuite
  20867. ... /
  20868. subfile-n.at ->'
  20869. @end example
  20870. @noindent
  20871. Files used in configuring a software package:
  20872. @example
  20873. .--> atconfig
  20874. /
  20875. [atlocal.in] --> config.status* --<
  20876. \
  20877. `--> [atlocal]
  20878. @end example
  20879. @noindent
  20880. Files created during test suite execution:
  20881. @example
  20882. atconfig -->. .--> testsuite.log
  20883. \ /
  20884. >-- testsuite* --<
  20885. / \
  20886. [atlocal] ->' `--> [testsuite.dir]
  20887. @end example
  20888. @node Autotest Logs
  20889. @subsection Autotest Logs
  20890. When run, the test suite creates a log file named after itself, e.g., a
  20891. test suite named @command{testsuite} creates @file{testsuite.log}. It
  20892. contains a lot of information, usually more than maintainers actually
  20893. need, but therefore most of the time it contains all that is needed:
  20894. @table @asis
  20895. @item command line arguments
  20896. A bad but unfortunately widespread habit consists of
  20897. setting environment variables before the command, such as in
  20898. @samp{CC=my-home-grown-cc ./testsuite}. The test suite does not
  20899. know this change, hence (i) it cannot report it to you, and (ii)
  20900. it cannot preserve the value of @code{CC} for subsequent runs.
  20901. Autoconf faced exactly the same problem, and solved it by asking
  20902. users to pass the variable definitions as command line arguments.
  20903. Autotest requires this rule, too, but has no means to enforce it; the log
  20904. then contains a trace of the variables that were changed by the user.
  20905. @item @file{ChangeLog} excerpts
  20906. The topmost lines of all the @file{ChangeLog} files found in the source
  20907. hierarchy. This is especially useful when bugs are reported against
  20908. development versions of the package, since the version string does not
  20909. provide sufficient information to know the exact state of the sources
  20910. the user compiled. Of course, this relies on the use of a
  20911. @file{ChangeLog}.
  20912. @item build machine
  20913. Running a test suite in a cross-compile environment is not an easy task,
  20914. since it would mean having the test suite run on a machine @var{build},
  20915. while running programs on a machine @var{host}. It is much simpler to
  20916. run both the test suite and the programs on @var{host}, but then, from
  20917. the point of view of the test suite, there remains a single environment,
  20918. @var{host} = @var{build}. The log contains relevant information on the
  20919. state of the @var{build} machine, including some important environment
  20920. variables.
  20921. @c FIXME: How about having an M4sh macro to say `hey, log the value
  20922. @c of `@dots{}'? This would help both Autoconf and Autotest.
  20923. @item tested programs
  20924. The absolute file name and answers to @option{--version} of the tested
  20925. programs (see @ref{Writing Testsuites}, @code{AT_TESTED}).
  20926. @item configuration log
  20927. The contents of @file{config.log}, as created by @command{configure},
  20928. are appended. It contains the configuration flags and a detailed report
  20929. on the configuration itself.
  20930. @end table
  20931. @node Writing Testsuites
  20932. @section Writing @file{testsuite.at}
  20933. The @file{testsuite.at} is a Bourne shell script making use of special
  20934. Autotest M4 macros. It often contains a call to @code{AT_INIT} near
  20935. its beginning followed by one call to @code{m4_include} per source file
  20936. for tests. Each such included file, or the remainder of
  20937. @file{testsuite.at} if include files are not used, contain a sequence of
  20938. test groups. Each test group begins with a call to @code{AT_SETUP},
  20939. then an arbitrary number of shell commands or calls to @code{AT_CHECK},
  20940. and then completes with a call to @code{AT_CLEANUP}. Multiple test
  20941. groups can be categorized by a call to @code{AT_BANNER}.
  20942. All of the public Autotest macros have all-uppercase names in the
  20943. namespace @samp{^AT_} to prevent them from accidentally conflicting with
  20944. other text; Autoconf also reserves the namespace @samp{^_AT_} for
  20945. internal macros. All shell variables used in the testsuite for internal
  20946. purposes have mostly-lowercase names starting with @samp{at_}. Autotest
  20947. also uses here-document delimiters in the namespace @samp{^_AT[A-Z]}, and
  20948. makes use of the file system namespace @samp{^at-}.
  20949. Since Autoconf is built on top of M4sugar (@pxref{Programming in
  20950. M4sugar}) and M4sh (@pxref{Programming in M4sh}), you must also be aware
  20951. of those namespaces (@samp{^_?\(m4\|AS\)_}). In general, you
  20952. @emph{should not use} the namespace of a package that does not own the
  20953. macro or shell code you are writing.
  20954. @defmac AT_INIT (@ovar{name})
  20955. @atindex{INIT}
  20956. @c FIXME: Not clear, plus duplication of the information.
  20957. Initialize Autotest. Giving a @var{name} to the test suite is
  20958. encouraged if your package includes several test suites. Before this
  20959. macro is called, @code{AT_PACKAGE_STRING} and
  20960. @code{AT_PACKAGE_BUGREPORT} must be defined, which are used to display
  20961. information about the testsuite to the user. Typically, these macros
  20962. are provided by a file @file{package.m4} built by @command{make}
  20963. (@pxref{Making testsuite Scripts}), in order to inherit the package
  20964. name, version, and bug reporting address from @file{configure.ac}.
  20965. @end defmac
  20966. @defmac AT_COPYRIGHT (@var{copyright-notice})
  20967. @atindex{COPYRIGHT}
  20968. @cindex Copyright Notice
  20969. State that, in addition to the Free Software Foundation's copyright on
  20970. the Autotest macros, parts of your test suite are covered by
  20971. @var{copyright-notice}.
  20972. The @var{copyright-notice} shows up in both the head of
  20973. @command{testsuite} and in @samp{testsuite --version}.
  20974. @end defmac
  20975. @defmac AT_ARG_OPTION (@var{options}, @var{help-text}, @
  20976. @ovar{action-if-given}, @ovar{action-if-not-given})
  20977. @atindex{ARG_OPTION}
  20978. @vrindex at_arg_@var{option}
  20979. Accept options from the space-separated list @var{options}, a list that
  20980. has leading dashes removed from the options. Long options will be
  20981. prefixed with @samp{--}, single-character options with @samp{-}. The
  20982. first word in this list is the primary @var{option}, any others are
  20983. assumed to be short-hand aliases. The variable associated with it
  20984. is @code{at_arg_@var{option}}, with any dashes in @var{option} replaced
  20985. with underscores.
  20986. If the user passes @option{--@var{option}} to the @command{testsuite},
  20987. the variable will be set to @samp{:}. If the user does not pass the
  20988. option, or passes @option{--no-@var{option}}, then the variable will be
  20989. set to @samp{false}.
  20990. @vrindex at_optarg
  20991. @vrindex at_optarg_@var{option}
  20992. @var{action-if-given} is run each time the option is encountered; here,
  20993. the variable @code{at_optarg} will be set to @samp{:} or @samp{false} as
  20994. appropriate. @code{at_optarg} is actually just a copy of
  20995. @code{at_arg_@var{option}}.
  20996. @var{action-if-not-given} will be run once after option parsing is
  20997. complete and if no option from @var{options} was used.
  20998. @var{help-text} is added to the end of the list of options shown in
  20999. @command{testsuite --help} (@pxref{AS_HELP_STRING}).
  21000. It is recommended that you use a package-specific prefix to @var{options}
  21001. names in order to avoid clashes with future Autotest built-in options.
  21002. @end defmac
  21003. @defmac AT_ARG_OPTION_ARG (@var{options}, @var{help-text}, @
  21004. @ovar{action-if-given}, @ovar{action-if-not-given})
  21005. @atindex{ARG_OPTION_ARG}
  21006. @vrindex at_arg_@var{option}
  21007. Accept options with arguments from the space-separated list
  21008. @var{options}, a list that has leading dashes removed from the options.
  21009. Long options will be prefixed with @samp{--}, single-character options
  21010. with @samp{-}. The first word in this list is the primary @var{option},
  21011. any others are assumed to be short-hand aliases. The variable associated
  21012. with it is @code{at_arg_@var{option}}, with any dashes in @var{option}
  21013. replaced with underscores.
  21014. If the user passes @option{--@var{option}=@var{arg}} or
  21015. @option{--@var{option} @var{arg}} to the @command{testsuite}, the
  21016. variable will be set to @samp{@var{arg}}.
  21017. @vrindex at_optarg
  21018. @var{action-if-given} is run each time the option is encountered; here,
  21019. the variable @code{at_optarg} will be set to @samp{@var{arg}}.
  21020. @code{at_optarg} is actually just a copy of @code{at_arg_@var{option}}.
  21021. @var{action-if-not-given} will be run once after option parsing is
  21022. complete and if no option from @var{options} was used.
  21023. @var{help-text} is added to the end of the list of options shown in
  21024. @command{testsuite --help} (@pxref{AS_HELP_STRING}).
  21025. It is recommended that you use a package-specific prefix to @var{options}
  21026. names in order to avoid clashes with future Autotest built-in options.
  21027. @end defmac
  21028. @defmac AT_COLOR_TESTS
  21029. @atindex{COLOR_TESTS}
  21030. Enable colored test results by default when the output is connected to
  21031. a terminal.
  21032. @end defmac
  21033. @defmac AT_TESTED (@var{executables})
  21034. @atindex{TESTED}
  21035. Log the file name and answer to @option{--version} of each program in
  21036. space-separated list @var{executables}. Several invocations register
  21037. new executables, in other words, don't fear registering one program
  21038. several times.
  21039. Autotest test suites rely on @env{PATH} to find the tested program.
  21040. This avoids the need to generate absolute names of the various tools, and
  21041. makes it possible to test installed programs. Therefore, knowing which
  21042. programs are being exercised is crucial to understanding problems in
  21043. the test suite itself, or its occasional misuses. It is a good idea to
  21044. also subscribe foreign programs you depend upon, to avoid incompatible
  21045. diagnostics.
  21046. @end defmac
  21047. @sp 1
  21048. @defmac AT_BANNER (@var{test-category-name})
  21049. @atindex{BANNER}
  21050. This macro identifies the start of a category of related test groups.
  21051. When the resulting @file{testsuite} is invoked with more than one test
  21052. group to run, its output will include a banner containing
  21053. @var{test-category-name} prior to any tests run from that category. The
  21054. banner should be no more than about 40 or 50 characters. A blank banner
  21055. indicates uncategorized tests; an empty line will be inserted after
  21056. tests from an earlier category, effectively ending that category.
  21057. @end defmac
  21058. @defmac AT_SETUP (@var{test-group-name})
  21059. @atindex{SETUP}
  21060. This macro starts a group of related tests, all to be executed in the
  21061. same subshell. It accepts a single argument, which holds a few words
  21062. (no more than about 30 or 40 characters) quickly describing the purpose
  21063. of the test group being started. @var{test-group-name} must not expand
  21064. to unbalanced quotes, although quadrigraphs can be used.
  21065. @end defmac
  21066. @defmac AT_KEYWORDS (@var{keywords})
  21067. @atindex{KEYWORDS}
  21068. Associate the space-separated list of @var{keywords} to the enclosing
  21069. test group. This makes it possible to run ``slices'' of the test suite.
  21070. For instance, if some of your test groups exercise some @samp{foo}
  21071. feature, then using @samp{AT_KEYWORDS(foo)} lets you run
  21072. @samp{./testsuite -k foo} to run exclusively these test groups. The
  21073. @var{test-group-name} of the test group is automatically recorded to
  21074. @code{AT_KEYWORDS}.
  21075. Several invocations within a test group accumulate new keywords. In
  21076. other words, don't fear registering the same keyword several times in a
  21077. test group.
  21078. @end defmac
  21079. @defmac AT_CAPTURE_FILE (@var{file})
  21080. @atindex{CAPTURE_FILE}
  21081. If the current test group fails, log the contents of @var{file}.
  21082. Several identical calls within one test group have no additional effect.
  21083. @end defmac
  21084. @defmac AT_FAIL_IF (@var{shell-condition})
  21085. @atindex{FAIL_IF}
  21086. Make the test group fail and skip the rest of its execution, if
  21087. @var{shell-condition} is true. @var{shell-condition} is a shell expression
  21088. such as a @code{test} command. Tests before @command{AT_FAIL_IF}
  21089. will be executed and may still cause the test group to be skipped.
  21090. You can instantiate this macro many times from within the same test group.
  21091. You should use this macro only for very simple failure conditions. If the
  21092. @var{shell-condition} could emit any kind of output you should instead
  21093. use @command{AT_CHECK} like
  21094. @example
  21095. AT_CHECK([if @var{shell-condition}; then exit 99; fi])
  21096. @end example
  21097. @noindent
  21098. so that such output is properly recorded in the @file{testsuite.log}
  21099. file.
  21100. @end defmac
  21101. @defmac AT_SKIP_IF (@var{shell-condition})
  21102. @atindex{SKIP_IF}
  21103. Determine whether the test should be skipped because it requires
  21104. features that are unsupported on the machine under test.
  21105. @var{shell-condition} is a shell expression such as a @code{test}
  21106. command. Tests before @command{AT_SKIP_IF} will be executed
  21107. and may still cause the test group to fail. You can instantiate this
  21108. macro many times from within the same test group.
  21109. You should use this macro only for very simple skip conditions. If the
  21110. @var{shell-condition} could emit any kind of output you should instead
  21111. use @command{AT_CHECK} like
  21112. @example
  21113. AT_CHECK([if @var{shell-condition}; then exit 77; fi])
  21114. @end example
  21115. @noindent
  21116. so that such output is properly recorded in the @file{testsuite.log}
  21117. file.
  21118. @end defmac
  21119. @defmac AT_XFAIL_IF (@var{shell-condition})
  21120. @atindex{XFAIL_IF}
  21121. Determine whether the test is expected to fail because it is a known
  21122. bug (for unsupported features, you should skip the test).
  21123. @var{shell-condition} is a shell expression such as a @code{test}
  21124. command; you can instantiate this macro many times from within the
  21125. same test group, and one of the conditions is enough to turn
  21126. the test into an expected failure.
  21127. @end defmac
  21128. @defmac AT_CLEANUP
  21129. @atindex{CLEANUP}
  21130. End the current test group.
  21131. @end defmac
  21132. @sp 1
  21133. @defmac AT_DATA (@var{file}, @var{contents})
  21134. @atindex{DATA}
  21135. Initialize an input data @var{file} with given @var{contents}. Of
  21136. course, the @var{contents} have to be properly quoted between square
  21137. brackets to protect against included commas or spurious M4
  21138. expansion. @var{contents} must be empty or end with a newline.
  21139. @var{file} must
  21140. be a single shell word that expands into a single file name.
  21141. @end defmac
  21142. @defmac AT_CHECK (@var{commands}, @dvar{status, 0}, @ovar{stdout}, @
  21143. @ovar{stderr}, @ovar{run-if-fail}, @ovar{run-if-pass})
  21144. @defmacx AT_CHECK_UNQUOTED (@var{commands}, @dvar{status, 0}, @ovar{stdout}, @
  21145. @ovar{stderr}, @ovar{run-if-fail}, @ovar{run-if-pass})
  21146. @atindex{CHECK}
  21147. @atindex{CHECK_UNQUOTED}
  21148. @vrindex at_status
  21149. Execute a test by performing given shell @var{commands} in a subshell.
  21150. @var{commands} is output as-is, so shell expansions are honored. These
  21151. commands should normally exit with @var{status}, while producing expected
  21152. @var{stdout} and @var{stderr} contents. If @var{commands} exit with
  21153. unexpected status 77, then the rest of the test group is skipped. If
  21154. @var{commands} exit with unexpected status 99, then the test group is
  21155. immediately failed. Otherwise, if this test fails, run shell commands
  21156. @var{run-if-fail} or, if this test passes, run shell commands
  21157. @var{run-if-pass}, both inside the current shell execution environment.
  21158. At the beginning of @var{run-if-fail} and @var{run-if-pass}, the status of
  21159. @var{commands} is available in the @code{at_status} shell variable.
  21160. This macro must be invoked in between @code{AT_SETUP} and @code{AT_CLEANUP}.
  21161. If @var{status} is the literal @samp{ignore}, then the corresponding
  21162. exit status is not checked, except for the special cases of 77 (skip)
  21163. and 99 (hard failure). The existence of hard failures allows one to
  21164. mark a test as an expected failure with @code{AT_XFAIL_IF} because a
  21165. feature has not yet been implemented, but to still distinguish between
  21166. gracefully handling the missing feature and dumping core. A hard
  21167. failure also inhibits post-test actions in @var{run-if-fail}.
  21168. If the value of the @var{stdout} or @var{stderr} parameter is one of the
  21169. literals in the following table, then the test treats the output
  21170. according to the rules of that literal. Otherwise, the value of the
  21171. parameter is treated as text that must exactly match the output given by
  21172. @var{commands} on standard output and standard error (including an empty
  21173. parameter for no output); any differences are captured in the testsuite
  21174. log and the test is failed (unless an unexpected exit status of 77
  21175. skipped the test instead). The difference between @code{AT_CHECK} and
  21176. @code{AT_CHECK_UNQUOTED} is that only the latter performs shell variable
  21177. expansion (@samp{$}), command substitution (@samp{`}), and backslash
  21178. escaping (@samp{\}) on comparison text given in the @var{stdout} and
  21179. @var{stderr} arguments; if the text includes a trailing newline, this
  21180. would be the same as if it were specified via an unquoted
  21181. here-document. (However, there is no difference in the interpretation
  21182. of @var{commands}).
  21183. @table @samp
  21184. @item ignore
  21185. The content of the output is ignored, but still captured in the test
  21186. group log (if the testsuite is run with option @option{-v}, the test
  21187. group log is displayed as the test is run; if the test group later
  21188. fails, the test group log is also copied into the overall testsuite
  21189. log). This action is valid for both @var{stdout} and @var{stderr}.
  21190. @item ignore-nolog
  21191. The content of the output is ignored, and nothing is captured in the log
  21192. files. If @var{commands} are likely to produce binary output (including
  21193. long lines) or large amounts of output, then logging the output can make
  21194. it harder to locate details related to subsequent tests within the
  21195. group, and could potentially corrupt terminal display of a user running
  21196. @command{testsuite -v}.
  21197. @item stdout
  21198. For the @var{stdout} parameter, capture the content of standard output
  21199. to both the file @file{stdout} and the test group log. Subsequent
  21200. commands in the test group can then post-process the file. This action
  21201. is often used when it is desired to use @command{grep} to look for a
  21202. substring in the output, or when the output must be post-processed to
  21203. normalize error messages into a common form.
  21204. @item stderr
  21205. Like @samp{stdout}, except that it only works for the @var{stderr}
  21206. parameter, and the standard error capture file will be named
  21207. @file{stderr}.
  21208. @item stdout-nolog
  21209. @itemx stderr-nolog
  21210. Like @samp{stdout} or @samp{stderr}, except that the captured output is
  21211. not duplicated into the test group log. This action is particularly
  21212. useful for an intermediate check that produces large amounts of data,
  21213. which will be followed by another check that filters down to the
  21214. relevant data, as it makes it easier to locate details in the log.
  21215. @item expout
  21216. For the @var{stdout} parameter, compare standard output contents with
  21217. the previously created file @file{expout}, and list any differences in
  21218. the testsuite log.
  21219. @item experr
  21220. Like @samp{expout}, except that it only works for the @var{stderr}
  21221. parameter, and the standard error contents are compared with
  21222. @file{experr}.
  21223. @end table
  21224. @end defmac
  21225. @defmac AT_CHECK_EUNIT (@var{module}, @var{test-spec}, @ovar{erlflags}, @
  21226. @ovar{run-if-fail}, @ovar{run-if-pass})
  21227. @atindex{CHECK_EUNIT}
  21228. Initialize and execute an Erlang module named @var{module} that performs
  21229. tests following the @var{test-spec} EUnit test specification.
  21230. @var{test-spec} must be a valid EUnit test specification, as defined in
  21231. the @uref{http://@/erlang.org/@/doc/@/apps/@/eunit/@/index.html, EUnit
  21232. Reference Manual}. @var{erlflags} are optional command-line options
  21233. passed to the Erlang interpreter to execute the test Erlang module.
  21234. Typically, @var{erlflags} defines at least the paths to directories
  21235. containing the compiled Erlang modules under test, as @samp{-pa path1
  21236. path2 ...}.
  21237. For example, the unit tests associated with Erlang module @samp{testme},
  21238. which compiled code is in subdirectory @file{src}, can be performed
  21239. with:
  21240. @example
  21241. AT_CHECK_EUNIT([testme_testsuite], [@{module, testme@}],
  21242. [-pa "$@{abs_top_builddir@}/src"])
  21243. @end example
  21244. This macro must be invoked in between @code{AT_SETUP} and @code{AT_CLEANUP}.
  21245. Variables @code{ERL}, @code{ERLC}, and (optionally) @code{ERLCFLAGS}
  21246. must be defined as the path of the Erlang interpreter, the path of the
  21247. Erlang compiler, and the command-line flags to pass to the compiler,
  21248. respectively. Those variables should be configured in
  21249. @file{configure.ac} using the @command{AC_ERLANG_PATH_ERL} and
  21250. @command{AC_ERLANG_PATH_ERLC} macros, and the configured values of those
  21251. variables are automatically defined in the testsuite. If @code{ERL} or
  21252. @code{ERLC} is not defined, the test group is skipped.
  21253. If the EUnit library cannot be found, i.e. if module @code{eunit} cannot
  21254. be loaded, the test group is skipped. Otherwise, if @var{test-spec} is
  21255. an invalid EUnit test specification, the test group fails. Otherwise,
  21256. if the EUnit test passes, shell commands @var{run-if-pass} are executed
  21257. or, if the EUnit test fails, shell commands @var{run-if-fail} are
  21258. executed and the test group fails.
  21259. Only the generated test Erlang module is automatically compiled and
  21260. executed. If @var{test-spec} involves testing other Erlang modules,
  21261. e.g. module @samp{testme} in the example above, those modules must be
  21262. already compiled.
  21263. If the testsuite is run in verbose mode, with option @option{--verbose},
  21264. EUnit is also run in verbose mode to output more details about
  21265. individual unit tests.
  21266. @end defmac
  21267. @node testsuite Invocation
  21268. @section Running @command{testsuite} Scripts
  21269. @cindex @command{testsuite}
  21270. Autotest test suites support the following options:
  21271. @table @option
  21272. @item --help
  21273. @itemx -h
  21274. Display the list of options and exit successfully.
  21275. @item --version
  21276. @itemx -V
  21277. Display the version of the test suite and exit successfully.
  21278. @item --directory=@var{dir}
  21279. @itemx -C @var{dir}
  21280. Change the current directory to @var{dir} before creating any files.
  21281. Useful for running the testsuite in a subdirectory from a top-level
  21282. Makefile.
  21283. @item --jobs@r{[}=@var{n}@r{]}
  21284. @itemx -j@ovar{n}
  21285. Run @var{n} tests in parallel, if possible. If @var{n} is not given,
  21286. run all given tests in parallel. Note that there should be no space
  21287. before the argument to @option{-j}, as @option{-j @var{number}} denotes
  21288. the separate arguments @option{-j} and @option{@var{number}}, see below.
  21289. In parallel mode, the standard input device of the testsuite script is
  21290. not available to commands inside a test group. Furthermore, banner
  21291. lines are not printed, and the summary line for each test group is
  21292. output after the test group completes. Summary lines may appear
  21293. unordered. If verbose and trace output are enabled (see below), they
  21294. may appear intermixed from concurrently running tests.
  21295. Parallel mode requires the @command{mkfifo} command to work, and will be
  21296. silently disabled otherwise.
  21297. @item --clean
  21298. @itemx -c
  21299. Remove all the files the test suite might have created and exit. Meant
  21300. for @code{clean} Make targets.
  21301. @item --list
  21302. @itemx -l
  21303. List all the tests (or only the selection), including their possible
  21304. keywords.
  21305. @end table
  21306. @sp 1
  21307. By default all tests are performed (or described with @option{--list})
  21308. silently in the default environment, but the environment, set of tests,
  21309. and verbosity level can be tuned:
  21310. @table @samp
  21311. @item @var{variable}=@var{value}
  21312. Set the environment @var{variable} to @var{value}. Use this rather
  21313. than @samp{FOO=foo ./testsuite} as debugging scripts would then run in a
  21314. different environment.
  21315. @cindex @code{AUTOTEST_PATH}
  21316. The variable @code{AUTOTEST_PATH} specifies the testing path to prepend
  21317. to @env{PATH}. Relative directory names (not starting with
  21318. @samp{/}) are considered to be relative to the top level of the
  21319. package being built. All directories are made absolute, first
  21320. starting from the top level @emph{build} tree, then from the
  21321. @emph{source} tree. For instance @samp{./testsuite
  21322. AUTOTEST_PATH=tests:bin} for a @file{/src/foo-1.0} source package built
  21323. in @file{/tmp/foo} results in @samp{/tmp/foo/tests:/tmp/foo/bin} and
  21324. then @samp{/src/foo-1.0/tests:/src/foo-1.0/bin} being prepended to
  21325. @env{PATH}.
  21326. @item @var{number}
  21327. @itemx @var{number}-@var{number}
  21328. @itemx @var{number}-
  21329. @itemx -@var{number}
  21330. Add the corresponding test groups, with obvious semantics, to the
  21331. selection.
  21332. @item --keywords=@var{keywords}
  21333. @itemx -k @var{keywords}
  21334. Add to the selection the test groups with title or keywords (arguments
  21335. to @code{AT_SETUP} or @code{AT_KEYWORDS}) that match @emph{all} keywords
  21336. of the comma separated list @var{keywords}, case-insensitively. Use
  21337. @samp{!} immediately before the keyword to invert the selection for this
  21338. keyword. By default, the keywords match whole words; enclose them in
  21339. @samp{.*} to also match parts of words.
  21340. For example, running
  21341. @example
  21342. @kbd{./testsuite -k 'autoupdate,.*FUNC.*'}
  21343. @end example
  21344. @noindent
  21345. selects all tests tagged @samp{autoupdate} @emph{and} with tags
  21346. containing @samp{FUNC} (as in @samp{AC_CHECK_FUNC}, @samp{AC_FUNC_ALLOCA},
  21347. etc.), while
  21348. @example
  21349. @kbd{./testsuite -k '!autoupdate' -k '.*FUNC.*'}
  21350. @end example
  21351. @noindent
  21352. selects all tests not tagged @samp{autoupdate} @emph{or} with tags
  21353. containing @samp{FUNC}.
  21354. @item --errexit
  21355. @itemx -e
  21356. If any test fails, immediately abort testing. This implies
  21357. @option{--debug}: post test group clean up, and top-level logging
  21358. are inhibited. This option is meant for the full test
  21359. suite, it is not really useful for generated debugging scripts.
  21360. If the testsuite is run in parallel mode using @option{--jobs},
  21361. then concurrently running tests will finish before exiting.
  21362. @item --verbose
  21363. @itemx -v
  21364. Force more verbosity in the detailed output of what is being done. This
  21365. is the default for debugging scripts.
  21366. @item --color
  21367. @itemx --color@r{[}=never@r{|}auto@r{|}always@r{]}
  21368. Enable colored test results. Without an argument, or with @samp{always},
  21369. test results will be colored. With @samp{never}, color mode is turned
  21370. off. Otherwise, if either the macro @code{AT_COLOR_TESTS} is used by
  21371. the testsuite author, or the argument @samp{auto} is given, then test
  21372. results are colored if standard output is connected to a terminal.
  21373. @item --debug
  21374. @itemx -d
  21375. Do not remove the files after a test group was performed---but they are
  21376. still removed @emph{before}, therefore using this option is sane when
  21377. running several test groups. Create debugging scripts. Do not
  21378. overwrite the top-level
  21379. log (in order to preserve a supposedly existing full log file). This is
  21380. the default for debugging scripts, but it can also be useful to debug
  21381. the testsuite itself.
  21382. @item --recheck
  21383. Add to the selection all test groups that failed or passed unexpectedly
  21384. during the last non-debugging test run.
  21385. @item --trace
  21386. @itemx -x
  21387. Trigger shell tracing of the test groups.
  21388. @end table
  21389. Besides these options accepted by every Autotest testsuite, the
  21390. testsuite author might have added package-specific options
  21391. via the @code{AT_ARG_OPTION} and @code{AT_ARG_OPTION_ARG} macros
  21392. (@pxref{Writing Testsuites}); refer to @command{testsuite --help} and
  21393. the package documentation for details.
  21394. @node Making testsuite Scripts
  21395. @section Making @command{testsuite} Scripts
  21396. For putting Autotest into movement, you need some configuration and
  21397. makefile machinery. We recommend, at least if your package uses deep or
  21398. shallow hierarchies, that you use @file{tests/} as the name of the
  21399. directory holding all your tests and their makefile. Here is a
  21400. check list of things to do.
  21401. @itemize @minus
  21402. @item
  21403. @cindex @file{package.m4}
  21404. @atindex{PACKAGE_STRING}
  21405. @atindex{PACKAGE_BUGREPORT}
  21406. @atindex{PACKAGE_NAME}
  21407. @atindex{PACKAGE_TARNAME}
  21408. @atindex{PACKAGE_VERSION}
  21409. @atindex{PACKAGE_URL}
  21410. Make sure to create the file @file{package.m4}, which defines the
  21411. identity of the package. It must define @code{AT_PACKAGE_STRING}, the
  21412. full signature of the package, and @code{AT_PACKAGE_BUGREPORT}, the
  21413. address to which bug reports should be sent. For sake of completeness,
  21414. we suggest that you also define @code{AT_PACKAGE_NAME},
  21415. @code{AT_PACKAGE_TARNAME}, @code{AT_PACKAGE_VERSION}, and
  21416. @code{AT_PACKAGE_URL}.
  21417. @xref{Initializing configure}, for a description of these variables.
  21418. Be sure to distribute @file{package.m4} and to put it into the source
  21419. hierarchy: the test suite ought to be shipped! See below for an example
  21420. @file{Makefile} excerpt.
  21421. @item
  21422. Invoke @code{AC_CONFIG_TESTDIR}.
  21423. @defmac AC_CONFIG_TESTDIR (@var{directory}, @dvar{test-path, directory})
  21424. @acindex{CONFIG_TESTDIR}
  21425. An Autotest test suite is to be configured in @var{directory}. This
  21426. macro causes @file{@var{directory}/atconfig} to be created by
  21427. @command{config.status} and sets the default @code{AUTOTEST_PATH} to
  21428. @var{test-path} (@pxref{testsuite Invocation}).
  21429. @end defmac
  21430. @item
  21431. Still within @file{configure.ac}, as appropriate, ensure that some
  21432. @code{AC_CONFIG_FILES} command includes substitution for
  21433. @file{tests/atlocal}.
  21434. @item
  21435. The appropriate @file{Makefile} should be modified so the validation in
  21436. your package is triggered by @samp{make check}. An example is provided
  21437. below.
  21438. @end itemize
  21439. With Automake, here is a minimal example for inclusion in
  21440. @file{tests/Makefile.am}, in order to link @samp{make check} with a
  21441. validation suite.
  21442. @example
  21443. # The `:;' works around a Bash 3.2 bug when the output is not writable.
  21444. $(srcdir)/package.m4: $(top_srcdir)/configure.ac
  21445. :;@{ \
  21446. echo '# Signature of the current package.' && \
  21447. echo 'm4_define([AT_PACKAGE_NAME],' && \
  21448. echo ' [$(PACKAGE_NAME)])' && \
  21449. echo 'm4_define([AT_PACKAGE_TARNAME],' && \
  21450. echo ' [$(PACKAGE_TARNAME)])' && \
  21451. echo 'm4_define([AT_PACKAGE_VERSION],' && \
  21452. echo ' [$(PACKAGE_VERSION)])' && \
  21453. echo 'm4_define([AT_PACKAGE_STRING],' && \
  21454. echo ' [$(PACKAGE_STRING)])' && \
  21455. echo 'm4_define([AT_PACKAGE_BUGREPORT],' && \
  21456. echo ' [$(PACKAGE_BUGREPORT)])'; \
  21457. echo 'm4_define([AT_PACKAGE_URL],' && \
  21458. echo ' [$(PACKAGE_URL)])'; \
  21459. @} >'$(srcdir)/package.m4'
  21460. EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) atlocal.in
  21461. TESTSUITE = $(srcdir)/testsuite
  21462. check-local: atconfig atlocal $(TESTSUITE)
  21463. $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS)
  21464. installcheck-local: atconfig atlocal $(TESTSUITE)
  21465. $(SHELL) '$(TESTSUITE)' AUTOTEST_PATH='$(bindir)' \
  21466. $(TESTSUITEFLAGS)
  21467. clean-local:
  21468. test ! -f '$(TESTSUITE)' || \
  21469. $(SHELL) '$(TESTSUITE)' --clean
  21470. AUTOM4TE = $(SHELL) $(srcdir)/build-aux/missing --run autom4te
  21471. AUTOTEST = $(AUTOM4TE) --language=autotest
  21472. $(TESTSUITE): $(srcdir)/testsuite.at $(srcdir)/package.m4
  21473. $(AUTOTEST) -I '$(srcdir)' -o $@@.tmp $@@.at
  21474. mv $@@.tmp $@@
  21475. @end example
  21476. Note that the built testsuite is distributed; this is necessary because
  21477. users might not have Autoconf installed, and thus would not be able to
  21478. rebuild it. Likewise, the use of @file{missing} provides the user with
  21479. a nicer error message if they modify a source file to the testsuite, and
  21480. accidentally trigger the rebuild rules.
  21481. You might want to list explicitly the dependencies, i.e., the list of
  21482. the files @file{testsuite.at} includes.
  21483. If you don't use Automake, you should include the above example in
  21484. @file{tests/@/Makefile.in}, along with additional lines inspired from
  21485. the following:
  21486. @example
  21487. subdir = tests
  21488. PACKAGE_NAME = @@PACKAGE_NAME@@
  21489. PACKAGE_TARNAME = @@PACKAGE_TARNAME@@
  21490. PACKAGE_VERSION = @@PACKAGE_VERSION@@
  21491. PACKAGE_STRING = @@PACKAGE_STRING@@
  21492. PACKAGE_BUGREPORT = @@PACKAGE_BUGREPORT@@
  21493. PACKAGE_URL = @@PACKAGE_URL@@
  21494. atconfig: $(top_builddir)/config.status
  21495. cd $(top_builddir) && \
  21496. $(SHELL) ./config.status $(subdir)/$@@
  21497. atlocal: $(srcdir)/atlocal.in $(top_builddir)/config.status
  21498. cd $(top_builddir) && \
  21499. $(SHELL) ./config.status $(subdir)/$@@
  21500. @end example
  21501. @noindent
  21502. and manage to have @code{$(EXTRA_DIST)} distributed. You will also want
  21503. to distribute the file @file{build-aux/@/missing} from the Automake
  21504. project; a copy of this file resides in the Autoconf source tree.
  21505. With all this in place, and if you have not initialized @samp{TESTSUITEFLAGS}
  21506. within your makefile, you can fine-tune test suite execution with this
  21507. variable, for example:
  21508. @example
  21509. make check TESTSUITEFLAGS='-v -d -x 75 -k AC_PROG_CC CFLAGS=-g'
  21510. @end example
  21511. @c =============================== Frequent Autoconf Questions, with answers
  21512. @node FAQ
  21513. @chapter Frequent Autoconf Questions, with answers
  21514. Several questions about Autoconf come up occasionally. Here some of them
  21515. are addressed.
  21516. @menu
  21517. * Distributing:: Distributing @command{configure} scripts
  21518. * Why GNU M4:: Why not use the standard M4?
  21519. * Bootstrapping:: Autoconf and GNU M4 require each other?
  21520. * Why Not Imake:: Why GNU uses @command{configure} instead of Imake
  21521. * Defining Directories:: Passing @code{datadir} to program
  21522. * Autom4te Cache:: What is it? Can I remove it?
  21523. * Present But Cannot Be Compiled:: Compiler and Preprocessor Disagree
  21524. * Expanded Before Required:: Expanded Before Required
  21525. * Debugging:: Debugging @command{configure} scripts
  21526. @end menu
  21527. @node Distributing
  21528. @section Distributing @command{configure} Scripts
  21529. @cindex License
  21530. @display
  21531. What are the restrictions on distributing @command{configure}
  21532. scripts that Autoconf generates? How does that affect my
  21533. programs that use them?
  21534. @end display
  21535. There are no restrictions on how the configuration scripts that Autoconf
  21536. produces may be distributed or used. In Autoconf version 1, they were
  21537. covered by the GNU General Public License. We still encourage
  21538. software authors to distribute their work under terms like those of the
  21539. GPL, but doing so is not required to use Autoconf.
  21540. Of the other files that might be used with @command{configure},
  21541. @file{config.h.in} is under whatever copyright you use for your
  21542. @file{configure.ac}. @file{config.sub} and @file{config.guess} have an
  21543. exception to the GPL when they are used with an Autoconf-generated
  21544. @command{configure} script, which permits you to distribute them under the
  21545. same terms as the rest of your package. @file{install-sh} is from the X
  21546. Consortium and is not copyrighted.
  21547. @node Why GNU M4
  21548. @section Why Require GNU M4?
  21549. @display
  21550. Why does Autoconf require GNU M4?
  21551. @end display
  21552. Many M4 implementations have hard-coded limitations on the size and
  21553. number of macros that Autoconf exceeds. They also lack several
  21554. builtin macros that it would be difficult to get along without in a
  21555. sophisticated application like Autoconf, including:
  21556. @example
  21557. m4_builtin
  21558. m4_indir
  21559. m4_bpatsubst
  21560. __file__
  21561. __line__
  21562. @end example
  21563. Autoconf requires version 1.4.6 or later of GNU M4.
  21564. Since only software maintainers need to use Autoconf, and since GNU
  21565. M4 is simple to configure and install, it seems reasonable to require
  21566. GNU M4 to be installed also. Many maintainers of GNU and
  21567. other free software already have most of the GNU utilities
  21568. installed, since they prefer them.
  21569. @node Bootstrapping
  21570. @section How Can I Bootstrap?
  21571. @cindex Bootstrap
  21572. @display
  21573. If Autoconf requires GNU M4 and GNU M4 has an Autoconf
  21574. @command{configure} script, how do I bootstrap? It seems like a chicken
  21575. and egg problem!
  21576. @end display
  21577. This is a misunderstanding. Although GNU M4 does come with a
  21578. @command{configure} script produced by Autoconf, Autoconf is not required
  21579. in order to run the script and install GNU M4. Autoconf is only
  21580. required if you want to change the M4 @command{configure} script, which few
  21581. people have to do (mainly its maintainer).
  21582. @node Why Not Imake
  21583. @section Why Not Imake?
  21584. @cindex Imake
  21585. @display
  21586. Why not use Imake instead of @command{configure} scripts?
  21587. @end display
  21588. Several people have written addressing this question, so
  21589. adaptations of their explanations are included here.
  21590. The following answer is based on one written by Richard Pixley:
  21591. @quotation
  21592. Autoconf generated scripts frequently work on machines that it has
  21593. never been set up to handle before. That is, it does a good job of
  21594. inferring a configuration for a new system. Imake cannot do this.
  21595. Imake uses a common database of host specific data. For X11, this makes
  21596. sense because the distribution is made as a collection of tools, by one
  21597. central authority who has control over the database.
  21598. GNU tools are not released this way. Each GNU tool has a
  21599. maintainer; these maintainers are scattered across the world. Using a
  21600. common database would be a maintenance nightmare. Autoconf may appear
  21601. to be this kind of database, but in fact it is not. Instead of listing
  21602. host dependencies, it lists program requirements.
  21603. If you view the GNU suite as a collection of native tools, then the
  21604. problems are similar. But the GNU development tools can be
  21605. configured as cross tools in almost any host+target permutation. All of
  21606. these configurations can be installed concurrently. They can even be
  21607. configured to share host independent files across hosts. Imake doesn't
  21608. address these issues.
  21609. Imake templates are a form of standardization. The GNU coding
  21610. standards address the same issues without necessarily imposing the same
  21611. restrictions.
  21612. @end quotation
  21613. Here is some further explanation, written by Per Bothner:
  21614. @quotation
  21615. One of the advantages of Imake is that it is easy to generate large
  21616. makefiles using the @samp{#include} and macro mechanisms of @command{cpp}.
  21617. However, @code{cpp} is not programmable: it has limited conditional
  21618. facilities, and no looping. And @code{cpp} cannot inspect its
  21619. environment.
  21620. All of these problems are solved by using @code{sh} instead of
  21621. @code{cpp}. The shell is fully programmable, has macro substitution,
  21622. can execute (or source) other shell scripts, and can inspect its
  21623. environment.
  21624. @end quotation
  21625. Paul Eggert elaborates more:
  21626. @quotation
  21627. With Autoconf, installers need not assume that Imake itself is already
  21628. installed and working well. This may not seem like much of an advantage
  21629. to people who are accustomed to Imake. But on many hosts Imake is not
  21630. installed or the default installation is not working well, and requiring
  21631. Imake to install a package hinders the acceptance of that package on
  21632. those hosts. For example, the Imake template and configuration files
  21633. might not be installed properly on a host, or the Imake build procedure
  21634. might wrongly assume that all source files are in one big directory
  21635. tree, or the Imake configuration might assume one compiler whereas the
  21636. package or the installer needs to use another, or there might be a
  21637. version mismatch between the Imake expected by the package and the Imake
  21638. supported by the host. These problems are much rarer with Autoconf,
  21639. where each package comes with its own independent configuration
  21640. processor.
  21641. Also, Imake often suffers from unexpected interactions between
  21642. @command{make} and the installer's C preprocessor. The fundamental problem
  21643. here is that the C preprocessor was designed to preprocess C programs,
  21644. not makefiles. This is much less of a problem with Autoconf,
  21645. which uses the general-purpose preprocessor M4, and where the
  21646. package's author (rather than the installer) does the preprocessing in a
  21647. standard way.
  21648. @end quotation
  21649. Finally, Mark Eichin notes:
  21650. @quotation
  21651. Imake isn't all that extensible, either. In order to add new features to
  21652. Imake, you need to provide your own project template, and duplicate most
  21653. of the features of the existing one. This means that for a sophisticated
  21654. project, using the vendor-provided Imake templates fails to provide any
  21655. leverage---since they don't cover anything that your own project needs
  21656. (unless it is an X11 program).
  21657. On the other side, though:
  21658. The one advantage that Imake has over @command{configure}:
  21659. @file{Imakefile} files tend to be much shorter (likewise, less redundant)
  21660. than @file{Makefile.in} files. There is a fix to this, however---at least
  21661. for the Kerberos V5 tree, we've modified things to call in common
  21662. @file{post.in} and @file{pre.in} makefile fragments for the
  21663. entire tree. This means that a lot of common things don't have to be
  21664. duplicated, even though they normally are in @command{configure} setups.
  21665. @end quotation
  21666. @node Defining Directories
  21667. @section How Do I @code{#define} Installation Directories?
  21668. @display
  21669. My program needs library files, installed in @code{datadir} and
  21670. similar. If I use
  21671. @example
  21672. AC_DEFINE_UNQUOTED([DATADIR], [$datadir],
  21673. [Define to the read-only architecture-independent
  21674. data directory.])
  21675. @end example
  21676. @noindent
  21677. I get
  21678. @example
  21679. #define DATADIR "$@{prefix@}/share"
  21680. @end example
  21681. @end display
  21682. As already explained, this behavior is on purpose, mandated by the
  21683. GNU Coding Standards, see @ref{Installation Directory
  21684. Variables}. There are several means to achieve a similar goal:
  21685. @itemize @minus
  21686. @item
  21687. Do not use @code{AC_DEFINE} but use your makefile to pass the
  21688. actual value of @code{datadir} via compilation flags.
  21689. @xref{Installation Directory Variables}, for the details.
  21690. @item
  21691. This solution can be simplified when compiling a program: you may either
  21692. extend the @code{CPPFLAGS}:
  21693. @example
  21694. CPPFLAGS = -DDATADIR='"$(datadir)"' @@CPPFLAGS@@
  21695. @end example
  21696. @noindent
  21697. If you are using Automake, you should use @code{AM_CPPFLAGS} instead:
  21698. @example
  21699. AM_CPPFLAGS = -DDATADIR='"$(datadir)"'
  21700. @end example
  21701. @noindent
  21702. Alternatively, create a dedicated header file:
  21703. @example
  21704. DISTCLEANFILES = myprog-paths.h
  21705. myprog-paths.h: Makefile
  21706. echo '#define DATADIR "$(datadir)"' >$@@
  21707. @end example
  21708. @noindent
  21709. The gnulib module @samp{configmake} provides such a header with all the
  21710. standard directory variables defined, @pxref{configmake,,, gnulib, GNU
  21711. Gnulib}.
  21712. @item
  21713. Use @code{AC_DEFINE} but have @command{configure} compute the literal
  21714. value of @code{datadir} and others. Many people have wrapped macros to
  21715. automate this task; for an example, see the macro @code{AC_DEFINE_DIR} from
  21716. the @uref{http://@/www.gnu.org/@/software/@/autoconf-archive/, Autoconf Macro
  21717. Archive}.
  21718. This solution does not conform to the GNU Coding Standards.
  21719. @item
  21720. Note that all the previous solutions hard wire the absolute name of
  21721. these directories in the executables, which is not a good property. You
  21722. may try to compute the names relative to @code{prefix}, and try to
  21723. find @code{prefix} at runtime, this way your package is relocatable.
  21724. @end itemize
  21725. @node Autom4te Cache
  21726. @section What is @file{autom4te.cache}?
  21727. @display
  21728. What is this directory @file{autom4te.cache}? Can I safely remove it?
  21729. @end display
  21730. In the GNU Build System, @file{configure.ac} plays a central
  21731. role and is read by many tools: @command{autoconf} to create
  21732. @file{configure}, @command{autoheader} to create @file{config.h.in},
  21733. @command{automake} to create @file{Makefile.in}, @command{autoscan} to
  21734. check the completeness of @file{configure.ac}, @command{autoreconf} to
  21735. check the GNU Build System components that are used. To
  21736. ``read @file{configure.ac}'' actually means to compile it with M4,
  21737. which can be a long process for complex @file{configure.ac}.
  21738. This is why all these tools, instead of running directly M4, invoke
  21739. @command{autom4te} (@pxref{autom4te Invocation}) which, while answering to
  21740. a specific demand, stores additional information in
  21741. @file{autom4te.cache} for future runs. For instance, if you run
  21742. @command{autoconf}, behind the scenes, @command{autom4te} also
  21743. stores information for the other tools, so that when you invoke
  21744. @command{autoheader} or @command{automake} etc., reprocessing
  21745. @file{configure.ac} is not needed. The speed up is frequently 30%,
  21746. and is increasing with the size of @file{configure.ac}.
  21747. But it is and remains being simply a cache: you can safely remove it.
  21748. @sp 1
  21749. @display
  21750. Can I permanently get rid of it?
  21751. @end display
  21752. The creation of this cache can be disabled from
  21753. @file{~/.autom4te.cfg}, see @ref{Customizing autom4te}, for more
  21754. details. You should be aware that disabling the cache slows down the
  21755. Autoconf test suite by 40%. The more GNU Build System
  21756. components are used, the more the cache is useful; for instance
  21757. running @samp{autoreconf -f} on the Core Utilities is twice slower without
  21758. the cache @emph{although @option{--force} implies that the cache is
  21759. not fully exploited}, and eight times slower than without
  21760. @option{--force}.
  21761. @node Present But Cannot Be Compiled
  21762. @section Header Present But Cannot Be Compiled
  21763. The most important guideline to bear in mind when checking for
  21764. features is to mimic as much as possible the intended use.
  21765. Unfortunately, old versions of @code{AC_CHECK_HEADER} and
  21766. @code{AC_CHECK_HEADERS} failed to follow this idea, and called
  21767. the preprocessor, instead of the compiler, to check for headers. As a
  21768. result, incompatibilities between headers went unnoticed during
  21769. configuration, and maintainers finally had to deal with this issue
  21770. elsewhere.
  21771. The transition began with Autoconf 2.56. As of Autoconf 2.64 both
  21772. checks are performed, and @command{configure} complains loudly if the
  21773. compiler and the preprocessor do not agree. However, only the compiler
  21774. result is considered.
  21775. Consider the following example:
  21776. @smallexample
  21777. $ @kbd{cat number.h}
  21778. typedef int number;
  21779. $ @kbd{cat pi.h}
  21780. const number pi = 3;
  21781. $ @kbd{cat configure.ac}
  21782. AC_INIT([Example], [1.0], [bug-example@@example.org])
  21783. AC_CHECK_HEADERS([pi.h])
  21784. $ @kbd{autoconf -Wall}
  21785. $ @kbd{./configure}
  21786. checking for gcc... gcc
  21787. checking for C compiler default output file name... a.out
  21788. checking whether the C compiler works... yes
  21789. checking whether we are cross compiling... no
  21790. checking for suffix of executables...
  21791. checking for suffix of object files... o
  21792. checking whether we are using the GNU C compiler... yes
  21793. checking whether gcc accepts -g... yes
  21794. checking for gcc option to accept ISO C89... none needed
  21795. checking how to run the C preprocessor... gcc -E
  21796. checking for grep that handles long lines and -e... grep
  21797. checking for egrep... grep -E
  21798. checking for ANSI C header files... yes
  21799. checking for sys/types.h... yes
  21800. checking for sys/stat.h... yes
  21801. checking for stdlib.h... yes
  21802. checking for string.h... yes
  21803. checking for memory.h... yes
  21804. checking for strings.h... yes
  21805. checking for inttypes.h... yes
  21806. checking for stdint.h... yes
  21807. checking for unistd.h... yes
  21808. checking pi.h usability... no
  21809. checking pi.h presence... yes
  21810. configure: WARNING: pi.h: present but cannot be compiled
  21811. configure: WARNING: pi.h: check for missing prerequisite headers?
  21812. configure: WARNING: pi.h: see the Autoconf documentation
  21813. configure: WARNING: pi.h: section "Present But Cannot Be Compiled"
  21814. configure: WARNING: pi.h: proceeding with the compiler's result
  21815. configure: WARNING: ## -------------------------------------- ##
  21816. configure: WARNING: ## Report this to bug-example@@example.org ##
  21817. configure: WARNING: ## -------------------------------------- ##
  21818. checking for pi.h... yes
  21819. @end smallexample
  21820. @noindent
  21821. The proper way the handle this case is using the fourth argument
  21822. (@pxref{Generic Headers}):
  21823. @example
  21824. $ @kbd{cat configure.ac}
  21825. AC_INIT([Example], [1.0], [bug-example@@example.org])
  21826. AC_CHECK_HEADERS([number.h pi.h], [], [],
  21827. [[#ifdef HAVE_NUMBER_H
  21828. # include <number.h>
  21829. #endif
  21830. ]])
  21831. $ @kbd{autoconf -Wall}
  21832. $ @kbd{./configure}
  21833. checking for gcc... gcc
  21834. checking for C compiler default output... a.out
  21835. checking whether the C compiler works... yes
  21836. checking whether we are cross compiling... no
  21837. checking for suffix of executables...
  21838. checking for suffix of object files... o
  21839. checking whether we are using the GNU C compiler... yes
  21840. checking whether gcc accepts -g... yes
  21841. checking for gcc option to accept ANSI C... none needed
  21842. checking for number.h... yes
  21843. checking for pi.h... yes
  21844. @end example
  21845. See @ref{Particular Headers}, for a list of headers with their
  21846. prerequisites.
  21847. @node Expanded Before Required
  21848. @section Expanded Before Required
  21849. @cindex expanded before required
  21850. Older versions of Autoconf silently built files with incorrect ordering
  21851. between dependent macros if an outer macro first expanded, then later
  21852. indirectly required, an inner macro. Starting with Autoconf 2.64, this
  21853. situation no longer generates out-of-order code, but results in
  21854. duplicate output and a syntax warning:
  21855. @example
  21856. $ @kbd{cat configure.ac}
  21857. @result{}AC_DEFUN([TESTA], [[echo in A
  21858. @result{}if test -n "$SEEN_A" ; then echo duplicate ; fi
  21859. @result{}SEEN_A=:]])
  21860. @result{}AC_DEFUN([TESTB], [AC_REQUIRE([TESTA])[echo in B
  21861. @result{}if test -z "$SEEN_A" ; then echo bug ; fi]])
  21862. @result{}AC_DEFUN([TESTC], [AC_REQUIRE([TESTB])[echo in C]])
  21863. @result{}AC_DEFUN([OUTER], [[echo in OUTER]
  21864. @result{}TESTA
  21865. @result{}TESTC])
  21866. @result{}AC_INIT
  21867. @result{}OUTER
  21868. @result{}AC_OUTPUT
  21869. $ @kbd{autoconf}
  21870. @result{}configure.ac:11: warning: AC_REQUIRE:
  21871. @result{} `TESTA' was expanded before it was required
  21872. @result{}configure.ac:4: TESTB is expanded from...
  21873. @result{}configure.ac:6: TESTC is expanded from...
  21874. @result{}configure.ac:7: OUTER is expanded from...
  21875. @result{}configure.ac:11: the top level
  21876. @end example
  21877. @noindent
  21878. To avoid this warning, decide what purpose the macro in question serves.
  21879. If it only needs to be expanded once (for example, if it provides
  21880. initialization text used by later macros), then the simplest fix is to
  21881. change the macro to be declared with @code{AC_DEFUN_ONCE}
  21882. (@pxref{One-Shot Macros}), although this only works in Autoconf 2.64 and
  21883. newer. A more portable fix is to change all
  21884. instances of direct calls to instead go through @code{AC_REQUIRE}
  21885. (@pxref{Prerequisite Macros}). If, instead, the macro is parameterized
  21886. by arguments or by the current definition of other macros in the m4
  21887. environment, then the macro should always be directly expanded instead
  21888. of required.
  21889. For another case study, consider this example trimmed down from an
  21890. actual package. Originally, the package contained shell code and
  21891. multiple macro invocations at the top level of @file{configure.ac}:
  21892. @example
  21893. AC_DEFUN([FOO], [AC_COMPILE_IFELSE([@dots{}])])
  21894. foobar=
  21895. AC_PROG_CC
  21896. FOO
  21897. @end example
  21898. @noindent
  21899. but that was getting complex, so the author wanted to offload some of
  21900. the text into a new macro in another file included via
  21901. @file{aclocal.m4}. The na@"ive approach merely wraps the text in a new
  21902. macro:
  21903. @example
  21904. AC_DEFUN([FOO], [AC_COMPILE_IFELSE([@dots{}])])
  21905. AC_DEFUN([BAR], [
  21906. foobar=
  21907. AC_PROG_CC
  21908. FOO
  21909. ])
  21910. BAR
  21911. @end example
  21912. @noindent
  21913. With older versions of Autoconf, the setting of @samp{foobar=} occurs
  21914. before the single compiler check, as the author intended. But with
  21915. Autoconf 2.64, this issues the ``expanded before it was required''
  21916. warning for @code{AC_PROG_CC}, and outputs two copies of the compiler
  21917. check, one before @samp{foobar=}, and one after. To understand why this
  21918. is happening, remember that the use of @code{AC_COMPILE_IFELSE} includes
  21919. a call to @code{AC_REQUIRE([AC_PROG_CC])} under the hood. According to
  21920. the documented semantics of @code{AC_REQUIRE}, this means that
  21921. @code{AC_PROG_CC} @emph{must} occur before the body of the outermost
  21922. @code{AC_DEFUN}, which in this case is @code{BAR}, thus preceding the
  21923. use of @samp{foobar=}. The older versions of Autoconf were broken with
  21924. regards to the rules of @code{AC_REQUIRE}, which explains why the code
  21925. changed from one over to two copies of @code{AC_PROG_CC} when upgrading
  21926. autoconf. In other words, the author was unknowingly relying on a bug
  21927. exploit to get the desired results, and that exploit broke once the bug
  21928. was fixed.
  21929. So, what recourse does the author have, to restore their intended
  21930. semantics of setting @samp{foobar=} prior to a single compiler check,
  21931. regardless of whether Autoconf 2.63 or 2.64 is used? One idea is to
  21932. remember that only @code{AC_DEFUN} is impacted by @code{AC_REQUIRE};
  21933. there is always the possibility of using the lower-level
  21934. @code{m4_define}:
  21935. @example
  21936. AC_DEFUN([FOO], [AC_COMPILE_IFELSE([@dots{}])])
  21937. m4_define([BAR], [
  21938. foobar=
  21939. AC_PROG_CC
  21940. FOO
  21941. ])
  21942. BAR
  21943. @end example
  21944. @noindent
  21945. This works great if everything is in the same file. However, it does
  21946. not help in the case where the author wants to have @command{aclocal}
  21947. find the definition of @code{BAR} from its own file, since
  21948. @command{aclocal} requires the use of @code{AC_DEFUN}. In this case, a
  21949. better fix is to recognize that if @code{BAR} also uses
  21950. @code{AC_REQUIRE}, then there will no longer be direct expansion prior
  21951. to a subsequent require. Then, by creating yet another helper macro,
  21952. the author can once again guarantee a single invocation of
  21953. @code{AC_PROG_CC}, which will still occur after @code{foobar=}. The
  21954. author can also use @code{AC_BEFORE} to make sure no other macro
  21955. appearing before @code{BAR} has triggered an unwanted expansion of
  21956. @code{AC_PROG_CC}.
  21957. @example
  21958. AC_DEFUN([FOO], [AC_COMPILE_IFELSE([@dots{}])])
  21959. AC_DEFUN([BEFORE_CC], [
  21960. foobar=
  21961. ])
  21962. AC_DEFUN([BAR], [
  21963. AC_BEFORE([$0], [AC_PROG_CC])dnl
  21964. AC_REQUIRE([BEFORE_CC])dnl
  21965. AC_REQUIRE([AC_PROG_CC])dnl
  21966. FOO
  21967. ])
  21968. BAR
  21969. @end example
  21970. @node Debugging
  21971. @section Debugging @command{configure} scripts
  21972. While in general, @command{configure} scripts generated by Autoconf
  21973. strive to be fairly portable to various systems, compilers, shells, and
  21974. other tools, it may still be necessary to debug a failing test, broken
  21975. script or makefile, or fix or override an incomplete, faulty, or erroneous
  21976. test, especially during macro development. Failures can occur at all levels,
  21977. in M4 syntax or semantics, shell script issues, or due to bugs in the
  21978. test or the tools invoked by @command{configure}. Together with the
  21979. rather arcane error message that @command{m4} and @command{make} may
  21980. produce when their input contains syntax errors, this can make debugging
  21981. rather painful.
  21982. Nevertheless, here is a list of hints and strategies that may help:
  21983. @itemize
  21984. @item
  21985. When @command{autoconf} fails, common causes for error include:
  21986. @itemize
  21987. @item
  21988. mismatched or unbalanced parentheses or braces (@pxref{Balancing
  21989. Parentheses}),
  21990. @item under- or overquoted macro arguments (@pxref{Autoconf
  21991. Language}, @pxref{Quoting and Parameters}, @pxref{Quotation and Nested
  21992. Macros}),
  21993. @item spaces between macro name and opening parenthesis (@pxref{Autoconf
  21994. Language}).
  21995. @end itemize
  21996. Typically, it helps to go back to the last working version of the input
  21997. and compare the differences for each of these errors. Another
  21998. possibility is to sprinkle pairs of @code{m4_traceon} and
  21999. @code{m4_traceoff} judiciously in the code, either without a parameter
  22000. or listing some macro names and watch @command{m4} expand its input
  22001. verbosely (@pxref{Debugging via autom4te}).
  22002. @item
  22003. Sometimes @command{autoconf} succeeds but the generated
  22004. @command{configure} script has invalid shell syntax. You can detect this
  22005. case by running @samp{bash -n configure} or @samp{sh -n configure}.
  22006. If this command fails, the same tips apply, as if @command{autoconf} had
  22007. failed.
  22008. @item
  22009. Debugging @command{configure} script execution may be done by sprinkling
  22010. pairs of @code{set -x} and @code{set +x} into the shell script before
  22011. and after the region that contains a bug. Running the whole script with
  22012. @samp{@var{shell} -vx ./configure 2>&1 | tee @var{log-file}} with a decent
  22013. @var{shell} may work, but produces lots of output. Here, it can help to
  22014. search for markers like @samp{checking for} a particular test in the
  22015. @var{log-file}.
  22016. @item
  22017. Alternatively, you might use a shell with debugging capabilities like
  22018. @uref{http://bashdb.sourceforge.net/, bashdb}.
  22019. @item
  22020. When @command{configure} tests produce invalid results for your system,
  22021. it may be necessary to override them:
  22022. @itemize
  22023. @item
  22024. For programs, tools or libraries variables, preprocessor, compiler, or
  22025. linker flags, it is often sufficient to override them at @command{make}
  22026. run time with some care (@pxref{Macros and Submakes}). Since this
  22027. normally won't cause @command{configure} to be run again with these
  22028. changed settings, it may fail if the changed variable would have caused
  22029. different test results from @command{configure}, so this may work only
  22030. for simple differences.
  22031. @item
  22032. Most tests which produce their result in a substituted variable allow to
  22033. override the test by setting the variable on the @command{configure}
  22034. command line (@pxref{Compilers and Options}, @pxref{Defining Variables},
  22035. @pxref{Particular Systems}).
  22036. @item
  22037. Many tests store their result in a cache variable (@pxref{Caching
  22038. Results}). This lets you override them either on the
  22039. @command{configure} command line as above, or through a primed cache or
  22040. site file (@pxref{Cache Files}, @pxref{Site Defaults}). The name of a
  22041. cache variable is documented with a test macro or may be inferred from
  22042. @ref{Cache Variable Names}; the precise semantics of undocumented
  22043. variables are often internal details, subject to change.
  22044. @end itemize
  22045. @item
  22046. Alternatively, @command{configure} may produce invalid results because
  22047. of uncaught programming errors, in your package or in an upstream
  22048. library package. For example, when @code{AC_CHECK_LIB} fails to find a
  22049. library with a specified function, always check @file{config.log}. This
  22050. will reveal the exact error that produced the failing result: the
  22051. library linked by @code{AC_CHECK_LIB} probably has a fatal bug.
  22052. @end itemize
  22053. Conversely, as macro author, you can make it easier for users of your
  22054. macro:
  22055. @itemize
  22056. @item
  22057. by minimizing dependencies between tests and between test results as far
  22058. as possible,
  22059. @item
  22060. by using @command{make} variables to factorize and allow
  22061. override of settings at @command{make} run time,
  22062. @item
  22063. by honoring the GNU Coding Standards and not overriding flags
  22064. reserved for the user except temporarily during @command{configure}
  22065. tests,
  22066. @item
  22067. by not requiring users of your macro to use the cache variables.
  22068. Instead, expose the result of the test via @var{run-if-true} and
  22069. @var{run-if-false} parameters. If the result is not a boolean,
  22070. then provide it through documented shell variables.
  22071. @end itemize
  22072. @c ===================================================== History of Autoconf.
  22073. @node History
  22074. @chapter History of Autoconf
  22075. @cindex History of autoconf
  22076. @emph{This chapter was written by the original author, David MacKenzie.}
  22077. You may be wondering, Why was Autoconf originally written? How did it
  22078. get into its present form? (Why does it look like gorilla spit?) If
  22079. you're not wondering, then this chapter contains no information useful
  22080. to you, and you might as well skip it. If you @emph{are} wondering,
  22081. then let there be light@enddots{}
  22082. @menu
  22083. * Genesis:: Prehistory and naming of @command{configure}
  22084. * Exodus:: The plagues of M4 and Perl
  22085. * Leviticus:: The priestly code of portability arrives
  22086. * Numbers:: Growth and contributors
  22087. * Deuteronomy:: Approaching the promises of easy configuration
  22088. @end menu
  22089. @node Genesis
  22090. @section Genesis
  22091. In June 1991 I was maintaining many of the GNU utilities for the
  22092. Free Software Foundation. As they were ported to more platforms and
  22093. more programs were added, the number of @option{-D} options that users
  22094. had to select in the makefile (around 20) became burdensome.
  22095. Especially for me---I had to test each new release on a bunch of
  22096. different systems. So I wrote a little shell script to guess some of
  22097. the correct settings for the fileutils package, and released it as part
  22098. of fileutils 2.0. That @command{configure} script worked well enough that
  22099. the next month I adapted it (by hand) to create similar @command{configure}
  22100. scripts for several other GNU utilities packages. Brian Berliner
  22101. also adapted one of my scripts for his CVS revision control system.
  22102. Later that summer, I learned that Richard Stallman and Richard Pixley
  22103. were developing similar scripts to use in the GNU compiler tools;
  22104. so I adapted my @command{configure} scripts to support their evolving
  22105. interface: using the file name @file{Makefile.in} as the templates;
  22106. adding @samp{+srcdir}, the first option (of many); and creating
  22107. @file{config.status} files.
  22108. @node Exodus
  22109. @section Exodus
  22110. As I got feedback from users, I incorporated many improvements, using
  22111. Emacs to search and replace, cut and paste, similar changes in each of
  22112. the scripts. As I adapted more GNU utilities packages to use
  22113. @command{configure} scripts, updating them all by hand became impractical.
  22114. Rich Murphey, the maintainer of the GNU graphics utilities, sent me
  22115. mail saying that the @command{configure} scripts were great, and asking if
  22116. I had a tool for generating them that I could send him. No, I thought,
  22117. but I should! So I started to work out how to generate them. And the
  22118. journey from the slavery of hand-written @command{configure} scripts to the
  22119. abundance and ease of Autoconf began.
  22120. Cygnus @command{configure}, which was being developed at around that time,
  22121. is table driven; it is meant to deal mainly with a discrete number of
  22122. system types with a small number of mainly unguessable features (such as
  22123. details of the object file format). The automatic configuration system
  22124. that Brian Fox had developed for Bash takes a similar approach. For
  22125. general use, it seems to me a hopeless cause to try to maintain an
  22126. up-to-date database of which features each variant of each operating
  22127. system has. It's easier and more reliable to check for most features on
  22128. the fly---especially on hybrid systems that people have hacked on
  22129. locally or that have patches from vendors installed.
  22130. I considered using an architecture similar to that of Cygnus
  22131. @command{configure}, where there is a single @command{configure} script that
  22132. reads pieces of @file{configure.in} when run. But I didn't want to have
  22133. to distribute all of the feature tests with every package, so I settled
  22134. on having a different @command{configure} made from each
  22135. @file{configure.in} by a preprocessor. That approach also offered more
  22136. control and flexibility.
  22137. I looked briefly into using the Metaconfig package, by Larry Wall,
  22138. Harlan Stenn, and Raphael Manfredi, but I decided not to for several
  22139. reasons. The @command{Configure} scripts it produces are interactive,
  22140. which I find quite inconvenient; I didn't like the ways it checked for
  22141. some features (such as library functions); I didn't know that it was
  22142. still being maintained, and the @command{Configure} scripts I had
  22143. seen didn't work on many modern systems (such as System V R4 and NeXT);
  22144. it wasn't flexible in what it could do in response to a feature's
  22145. presence or absence; I found it confusing to learn; and it was too big
  22146. and complex for my needs (I didn't realize then how much Autoconf would
  22147. eventually have to grow).
  22148. I considered using Perl to generate my style of @command{configure}
  22149. scripts, but decided that M4 was better suited to the job of simple
  22150. textual substitutions: it gets in the way less, because output is
  22151. implicit. Plus, everyone already has it. (Initially I didn't rely on
  22152. the GNU extensions to M4.) Also, some of my friends at the
  22153. University of Maryland had recently been putting M4 front ends on
  22154. several programs, including @code{tvtwm}, and I was interested in trying
  22155. out a new language.
  22156. @node Leviticus
  22157. @section Leviticus
  22158. Since my @command{configure} scripts determine the system's capabilities
  22159. automatically, with no interactive user intervention, I decided to call
  22160. the program that generates them Autoconfig. But with a version number
  22161. tacked on, that name would be too long for old Unix file systems,
  22162. so I shortened it to Autoconf.
  22163. In the fall of 1991 I called together a group of fellow questers after
  22164. the Holy Grail of portability (er, that is, alpha testers) to give me
  22165. feedback as I encapsulated pieces of my handwritten scripts in M4 macros
  22166. and continued to add features and improve the techniques used in the
  22167. checks. Prominent among the testers were Fran@,{c}ois Pinard, who came up
  22168. with the idea of making an Autoconf shell script to run M4
  22169. and check for unresolved macro calls; Richard Pixley, who suggested
  22170. running the compiler instead of searching the file system to find
  22171. include files and symbols, for more accurate results; Karl Berry, who
  22172. got Autoconf to configure @TeX{} and added the macro index to the
  22173. documentation; and Ian Lance Taylor, who added support for creating a C
  22174. header file as an alternative to putting @option{-D} options in a
  22175. makefile, so he could use Autoconf for his UUCP package.
  22176. The alpha testers cheerfully adjusted their files again and again as the
  22177. names and calling conventions of the Autoconf macros changed from
  22178. release to release. They all contributed many specific checks, great
  22179. ideas, and bug fixes.
  22180. @node Numbers
  22181. @section Numbers
  22182. In July 1992, after months of alpha testing, I released Autoconf 1.0,
  22183. and converted many GNU packages to use it. I was surprised by how
  22184. positive the reaction to it was. More people started using it than I
  22185. could keep track of, including people working on software that wasn't
  22186. part of the GNU Project (such as TCL, FSP, and Kerberos V5).
  22187. Autoconf continued to improve rapidly, as many people using the
  22188. @command{configure} scripts reported problems they encountered.
  22189. Autoconf turned out to be a good torture test for M4 implementations.
  22190. Unix M4 started to dump core because of the length of the
  22191. macros that Autoconf defined, and several bugs showed up in GNU
  22192. M4 as well. Eventually, we realized that we needed to use some
  22193. features that only GNU M4 has. 4.3BSD M4, in
  22194. particular, has an impoverished set of builtin macros; the System V
  22195. version is better, but still doesn't provide everything we need.
  22196. More development occurred as people put Autoconf under more stresses
  22197. (and to uses I hadn't anticipated). Karl Berry added checks for X11.
  22198. david zuhn contributed C++ support. Fran@,{c}ois Pinard made it diagnose
  22199. invalid arguments. Jim Blandy bravely coerced it into configuring
  22200. GNU Emacs, laying the groundwork for several later improvements.
  22201. Roland McGrath got it to configure the GNU C Library, wrote the
  22202. @command{autoheader} script to automate the creation of C header file
  22203. templates, and added a @option{--verbose} option to @command{configure}.
  22204. Noah Friedman added the @option{--autoconf-dir} option and
  22205. @code{AC_MACRODIR} environment variable. (He also coined the term
  22206. @dfn{autoconfiscate} to mean ``adapt a software package to use
  22207. Autoconf''.) Roland and Noah improved the quoting protection in
  22208. @code{AC_DEFINE} and fixed many bugs, especially when I got sick of
  22209. dealing with portability problems from February through June, 1993.
  22210. @node Deuteronomy
  22211. @section Deuteronomy
  22212. A long wish list for major features had accumulated, and the effect of
  22213. several years of patching by various people had left some residual
  22214. cruft. In April 1994, while working for Cygnus Support, I began a major
  22215. revision of Autoconf. I added most of the features of the Cygnus
  22216. @command{configure} that Autoconf had lacked, largely by adapting the
  22217. relevant parts of Cygnus @command{configure} with the help of david zuhn
  22218. and Ken Raeburn. These features include support for using
  22219. @file{config.sub}, @file{config.guess}, @option{--host}, and
  22220. @option{--target}; making links to files; and running @command{configure}
  22221. scripts in subdirectories. Adding these features enabled Ken to convert
  22222. GNU @code{as}, and Rob Savoye to convert DejaGNU, to using
  22223. Autoconf.
  22224. I added more features in response to other peoples' requests. Many
  22225. people had asked for @command{configure} scripts to share the results of
  22226. the checks between runs, because (particularly when configuring a large
  22227. source tree, like Cygnus does) they were frustratingly slow. Mike
  22228. Haertel suggested adding site-specific initialization scripts. People
  22229. distributing software that had to unpack on MS-DOS asked for a way to
  22230. override the @file{.in} extension on the file names, which produced file
  22231. names like @file{config.h.in} containing two dots. Jim Avera did an
  22232. extensive examination of the problems with quoting in @code{AC_DEFINE}
  22233. and @code{AC_SUBST}; his insights led to significant improvements.
  22234. Richard Stallman asked that compiler output be sent to @file{config.log}
  22235. instead of @file{/dev/null}, to help people debug the Emacs
  22236. @command{configure} script.
  22237. I made some other changes because of my dissatisfaction with the quality
  22238. of the program. I made the messages showing results of the checks less
  22239. ambiguous, always printing a result. I regularized the names of the
  22240. macros and cleaned up coding style inconsistencies. I added some
  22241. auxiliary utilities that I had developed to help convert source code
  22242. packages to use Autoconf. With the help of Fran@,{c}ois Pinard, I made
  22243. the macros not interrupt each others' messages. (That feature revealed
  22244. some performance bottlenecks in GNU M4, which he hastily
  22245. corrected!) I reorganized the documentation around problems people want
  22246. to solve. And I began a test suite, because experience had shown that
  22247. Autoconf has a pronounced tendency to regress when we change it.
  22248. Again, several alpha testers gave invaluable feedback, especially
  22249. Fran@,{c}ois Pinard, Jim Meyering, Karl Berry, Rob Savoye, Ken Raeburn,
  22250. and Mark Eichin.
  22251. Finally, version 2.0 was ready. And there was much rejoicing. (And I
  22252. have free time again. I think. Yeah, right.)
  22253. @c ========================================================== Appendices
  22254. @node GNU Free Documentation License
  22255. @appendix GNU Free Documentation License
  22256. @include fdl.texi
  22257. @node Indices
  22258. @appendix Indices
  22259. @menu
  22260. * Environment Variable Index:: Index of environment variables used
  22261. * Output Variable Index:: Index of variables set in output files
  22262. * Preprocessor Symbol Index:: Index of C preprocessor symbols defined
  22263. * Cache Variable Index:: Index of documented cache variables
  22264. * Autoconf Macro Index:: Index of Autoconf macros
  22265. * M4 Macro Index:: Index of M4, M4sugar, and M4sh macros
  22266. * Autotest Macro Index:: Index of Autotest macros
  22267. * Program & Function Index:: Index of those with portability problems
  22268. * Concept Index:: General index
  22269. @end menu
  22270. @node Environment Variable Index
  22271. @appendixsec Environment Variable Index
  22272. This is an alphabetical list of the environment variables that might
  22273. influence Autoconf checks.
  22274. @printindex ev
  22275. @node Output Variable Index
  22276. @appendixsec Output Variable Index
  22277. This is an alphabetical list of the variables that Autoconf can
  22278. substitute into files that it creates, typically one or more
  22279. makefiles. @xref{Setting Output Variables}, for more information
  22280. on how this is done.
  22281. @printindex ov
  22282. @node Preprocessor Symbol Index
  22283. @appendixsec Preprocessor Symbol Index
  22284. This is an alphabetical list of the C preprocessor symbols that the
  22285. Autoconf macros define. To work with Autoconf, C source code needs to
  22286. use these names in @code{#if} or @code{#ifdef} directives.
  22287. @printindex cv
  22288. @node Cache Variable Index
  22289. @appendixsec Cache Variable Index
  22290. This is an alphabetical list of documented cache variables used
  22291. by macros defined in Autoconf. Autoconf macros may use additional cache
  22292. variables internally.
  22293. @ifset shortindexflag
  22294. To make the list easier to use, the variables are listed without their
  22295. preceding @samp{ac_cv_}.
  22296. @end ifset
  22297. @printindex CA
  22298. @node Autoconf Macro Index
  22299. @appendixsec Autoconf Macro Index
  22300. This is an alphabetical list of the Autoconf macros.
  22301. @ifset shortindexflag
  22302. To make the list easier to use, the macros are listed without their
  22303. preceding @samp{AC_}.
  22304. @end ifset
  22305. @printindex AC
  22306. @node M4 Macro Index
  22307. @appendixsec M4 Macro Index
  22308. This is an alphabetical list of the M4, M4sugar, and M4sh macros.
  22309. @ifset shortindexflag
  22310. To make the list easier to use, the macros are listed without their
  22311. preceding @samp{m4_} or @samp{AS_}. The prefix is @samp{m4_} for
  22312. all-lowercase macro names and @samp{AS_} for all-uppercase macro
  22313. names.
  22314. @end ifset
  22315. @printindex MS
  22316. @node Autotest Macro Index
  22317. @appendixsec Autotest Macro Index
  22318. This is an alphabetical list of the Autotest macros.
  22319. @ifset shortindexflag
  22320. To make the list easier to use, the macros are listed without their
  22321. preceding @samp{AT_}.
  22322. @end ifset
  22323. @printindex AT
  22324. @node Program & Function Index
  22325. @appendixsec Program and Function Index
  22326. This is an alphabetical list of the programs and functions whose
  22327. portability is discussed in this document.
  22328. @printindex pr
  22329. @node Concept Index
  22330. @appendixsec Concept Index
  22331. This is an alphabetical list of the files, tools, and concepts
  22332. introduced in this document.
  22333. @printindex cp
  22334. @bye
  22335. @c LocalWords: texinfo setfilename autoconf texi settitle setchapternewpage
  22336. @c LocalWords: setcontentsaftertitlepage finalout ARG ovar varname dvar acx
  22337. @c LocalWords: makeinfo dvi defcodeindex ev ov CPP cv Autotest mv defindex fn
  22338. @c LocalWords: shortindexflag iftex ifset acindex ACindex ifclear ahindex fu
  22339. @c LocalWords: asindex MSindex atindex ATindex auindex hdrindex prindex FIXME
  22340. @c LocalWords: msindex alloca fnindex Aaarg indices FSF's dircategory ifnames
  22341. @c LocalWords: direntry autoscan autoreconf autoheader autoupdate config FDs
  22342. @c LocalWords: testsuite titlepage Elliston Demaille vskip filll ifnottex hmm
  22343. @c LocalWords: insertcopying Autoconf's detailmenu Automake Libtool Posix ois
  22344. @c LocalWords: Systemology Checkpointing Changequote INTERCAL changequote dfn
  22345. @c LocalWords: Quadrigraphs builtins Shellology acconfig Bugward LIBOBJ Imake
  22346. @c LocalWords: LIBOBJS IFELSE cindex flushright Pinard Metaconfig uref Simons
  22347. @c LocalWords: distclean uninstall noindent versioning Tromey dir
  22348. @c LocalWords: SAMS samp aclocal acsite underquoted emph itemx prepend SUBST
  22349. @c LocalWords: evindex automake Gettext autopoint gettext symlink libtoolize
  22350. @c LocalWords: defmac INIT tarname ovindex cvindex BUGREPORT PREREQ asis PROG
  22351. @c LocalWords: SRCDIR srcdir globbing afterwards cmds foos fooo foooo init cd
  22352. @c LocalWords: builddir timestamp src Imakefile chmod defvar CFLAGS CPPFLAGS
  22353. @c LocalWords: CXXFLAGS DEFS DHAVE defvarx FCFLAGS FFLAGS LDFLAGS bindir GCC
  22354. @c LocalWords: datadir datarootdir docdir dvidir htmldir libdir ifnothtml kbd
  22355. @c LocalWords: includedir infodir libexecdir localedir localstatedir mandir
  22356. @c LocalWords: oldincludedir pdfdir PDF psdir PostScript sbindir sysconfdir
  22357. @c LocalWords: sharedstatedir DDATADIR sed tmp pkgdatadir VPATH conf unistd
  22358. @c LocalWords: undef endif builtin FUNCS ifndef STACKSEG getb GETB YMP fubar
  22359. @c LocalWords: PRE dest SUBDIRS subdirs fi struct STDC stdlib stddef INTTYPES
  22360. @c LocalWords: inttypes STDINT stdint AWK AIX Solaris NeXT env EGREP FGREP yy
  22361. @c LocalWords: LEXLIB YYTEXT lfl nonportable Automake's LN RANLIB byacc INETD
  22362. @c LocalWords: inetd prog PROGS progs ranlib lmp lXt lX nsl gethostbyname UX
  22363. @c LocalWords: NextStep isinf isnan glibc IRIX sunmath lm lsunmath pre sizeof
  22364. @c LocalWords: ld inline malloc putenv setenv FreeBSD realloc SunOS MinGW
  22365. @c LocalWords: snprintf vsnprintf sprintf vsprintf sscanf gcc strerror ifdef
  22366. @c LocalWords: strnlen sysconf PAGESIZE unsetenv va fallback memcpy dst FUNC
  22367. @c LocalWords: PowerPC GNUC libPW pragma Olibcalls CHOWN chown CLOSEDIR VFORK
  22368. @c LocalWords: closedir FNMATCH fnmatch vfork FSEEKO LARGEFILE fseeko SVR sc
  22369. @c LocalWords: largefile GETGROUPS getgroups GETLOADAVG DGUX UMAX NLIST KMEM
  22370. @c LocalWords: SETGID getloadavg nlist GETMNTENT irix
  22371. @c LocalWords: getmntent UnixWare GETPGRP getpgid getpgrp Posix's pid LSTAT
  22372. @c LocalWords: lstat rpl MEMCMP memcmp OpenStep MBRTOWC mbrtowc MKTIME mktime
  22373. @c LocalWords: localtime MMAP mmap OBSTACK obstack obstacks ARGTYPES timeval
  22374. @c LocalWords: SETPGRP setpgrp defmacx Hurd SETVBUF setvbuf STRCOLL strcoll
  22375. @c LocalWords: STRTOD strtod DECL STRFTIME strftime SCO UTIME utime VPRINTF
  22376. @c LocalWords: DOPRNT vprintf doprnt sp unfixable LIBSOURCE LIBSOURCES Eggert
  22377. @c LocalWords: linux netinet ia Tru XFree DIRENT NDIR dirent ndir multitable
  22378. @c LocalWords: NAMLEN strlen namlen MKDEV SYSMACROS makedev RESOLV resolv DNS
  22379. @c LocalWords: inet structs NAMESER arpa NETDB netdb UTekV UTS GCC's kB
  22380. @c LocalWords: STDBOOL BOOL stdbool cplusplus bool Bool stdarg tm
  22381. @c LocalWords: ctype strchr strrchr rindex bcopy memmove memchr WEXITSTATUS
  22382. @c LocalWords: WIFEXITED TIOCGWINSZ GWINSZ termios preprocess preprocessable
  22383. @c LocalWords: DECLS strdup calloc BLKSIZE blksize RDEV rdev TZNAME tzname pw
  22384. @c LocalWords: passwd gecos pwd MBSTATE mbstate wchar RETSIGTYPE hup UID uid
  22385. @c LocalWords: gid ptrdiff uintmax EXEEXT OBJEXT Ae conftest AXP str
  22386. @c LocalWords: ALIGNOF WERROR Werror cpp HP's WorkShop egcs un fied stdc CXX
  22387. @c LocalWords: varargs BIGENDIAN Endianness SPARC endianness grep'ed CONST FC
  22388. @c LocalWords: const STRINGIZE stringizing PARAMS unprotoize protos KCC cxx
  22389. @c LocalWords: xlC aCC CXXCPP FREEFORM xlf FLIBS FCLIBS ish SRCEXT XTRA LFS
  22390. @c LocalWords: ISC lcposix MINIX Minix conditionalized inlines hw dD confdefs
  22391. @c LocalWords: fputs stdout PREPROC ar UFS HFS QNX realtime fstype STATVFS se
  22392. @c LocalWords: statvfs STATFS statfs func machfile hdr lelf raboof DEFUN GTK
  22393. @c LocalWords: GTKMM Grmph ified ine defn baz EOF qar Ahhh changecom algol io
  22394. @c LocalWords: changeword quadrigraphs quadrigraph dnl SGI atoi overquoting
  22395. @c LocalWords: Aas Wcross sep args namespace undefine bpatsubst popdef dquote
  22396. @c LocalWords: bregexp Overquote overquotation meisch maisch meische maische
  22397. @c LocalWords: miscian DIRNAME dirname MKDIR CATFILE XMKMF TRAVOLTA celsius
  22398. @c LocalWords: EMX emxos Emacsen Korn DYNIX subshell posix Ksh ksh Pdksh Zsh
  22399. @c LocalWords: pdksh zsh Allbery Lipe Kubota UWS zorglub stderr eval esac lfn
  22400. @c LocalWords: drivespec Posixy DJGPP doschk prettybird LPT pfew Zsh's yu yaa
  22401. @c LocalWords: yM uM aM firebird IP subdir misparses ok Unpatched abc bc zA
  22402. @c LocalWords: CDPATH DUALCASE LINENO prepass Subshells lineno NULLCMD cmp wc
  22403. @c LocalWords: MAILPATH scanset arg NetBSD Almquist printf expr cp
  22404. @c LocalWords: Oliva awk Aaaaarg cmd regex xfoo GNV OpenVMS VM
  22405. @c LocalWords: sparc Proulx nbar nfoo maxdepth acdilrtu TWG mc
  22406. @c LocalWords: mkdir exe uname OpenBSD Fileutils mktemp umask TMPDIR guid os
  22407. @c LocalWords: fooXXXXXX Unicos utimes hpux hppa unescaped
  22408. @c LocalWords: pmake DOS's gmake ifoo DESTDIR autoconfiscated pc coff mips gg
  22409. @c LocalWords: dec ultrix cpu wildcards rpcc rdtsc powerpc readline
  22410. @c LocalWords: withval vxworks gless localcache usr LOFF loff CYGWIN Cygwin
  22411. @c LocalWords: cygwin SIGLIST siglist SYSNDIR SYSDIR ptx lseq rusage elif MSC
  22412. @c LocalWords: lfoo POUNDBANG lsun NIS getpwnam SYSCALLS RSH INTL lintl aix
  22413. @c LocalWords: intl lx ldir syslog bsd EPI toolchain netbsd objext de KNR nn
  22414. @c LocalWords: fication LTLIBOBJS Wdiff TESTDIR atconfig atlocal akim XFAIL
  22415. @c LocalWords: ChangeLog prepended errexit smallexample TESTSUITEFLAGS GPL er
  22416. @c LocalWords: installcheck autotest indir Pixley Bothner Eichin Kerberos adl
  22417. @c LocalWords: DISTCLEANFILES preprocessor's fileutils Stallman Murphey Stenn
  22418. @c LocalWords: Manfredi Autoconfig TCL FSP david zuhn Blandy MACRODIR Raeburn
  22419. @c LocalWords: autoconfiscate Savoye Haertel Avera Meyering fdl appendixsec
  22420. @c LocalWords: printindex american LIBOBJDIR LibdirTest ERLCFLAGS OBJCFLAGS
  22421. @c LocalWords: VER Gnulib online xyes strcpy TYPEOF typeof OBJC objcc objc ln
  22422. @c LocalWords: GOBJC OTP ERLC erl valloc decr dumpdef errprint incr
  22423. @c LocalWords: esyscmd len maketemp pushdef substr syscmd sysval translit txt
  22424. @c LocalWords: sinclude foreach myvar tolower toupper uniq BASENAME STDIN
  22425. @c LocalWords: Dynix basename aname cname macroexpands xno xcheck
  22426. @c LocalWords: LIBREADLINE lreadline lncurses libreadline
  22427. @c Local Variables:
  22428. @c fill-column: 72
  22429. @c ispell-local-dictionary: "american"
  22430. @c indent-tabs-mode: nil
  22431. @c whitespace-check-buffer-indent: nil
  22432. @c End: