configure.ac 192 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039
  1. # This file is part of libmicrohttpd.
  2. # (C) 2006-2021 Christian Grothoff (and other contributing authors)
  3. # (C) 2014-2024 Evgeny Grin (Karlson2k)
  4. #
  5. # libmicrohttpd is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published
  7. # by the Free Software Foundation; either version 3, or (at your
  8. # option) any later version.
  9. #
  10. # libmicrohttpd is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License
  16. # along with libmicrohttpd; see the file COPYING. If not, write to the
  17. # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. # Boston, MA 02110-1301, USA.
  19. #
  20. #
  21. # Process this file with autoconf to produce a configure script.
  22. #
  23. #
  24. AC_PREREQ([2.64])
  25. LT_PREREQ([2.4.0])
  26. AC_INIT([GNU libmicrohttpd],[1.0.2],[[email protected]])
  27. AC_CONFIG_AUX_DIR([build-aux])
  28. MHD_AUX_DIR='build-aux' # Must be set to the same value as in the previous line
  29. AC_CONFIG_HEADERS([MHD_config.h])
  30. AC_CONFIG_MACRO_DIR([m4])
  31. m4_pattern_forbid([^_?MHD_[A-Z_]+_CC_])dnl
  32. LIB_VERSION_CURRENT=74
  33. LIB_VERSION_REVISION=2
  34. LIB_VERSION_AGE=62
  35. AC_SUBST([LIB_VERSION_CURRENT])
  36. AC_SUBST([LIB_VERSION_REVISION])
  37. AC_SUBST([LIB_VERSION_AGE])
  38. PACKAGE_VERSION_MAJOR='m4_car(m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  39. PACKAGE_VERSION_MINOR='m4_argn(2, m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  40. PACKAGE_VERSION_SUBMINOR='m4_argn(3, m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  41. AS_VAR_ARITH([MHD_W32_DLL_SUFF],[[$LIB_VERSION_CURRENT - $LIB_VERSION_AGE]])
  42. AC_SUBST([PACKAGE_VERSION_MAJOR])
  43. AC_SUBST([PACKAGE_VERSION_MINOR])
  44. AC_SUBST([PACKAGE_VERSION_SUBMINOR])
  45. AC_SUBST([MHD_W32_DLL_SUFF])
  46. AC_CONFIG_FILES([src/microhttpd/microhttpd_dll_res.rc])
  47. CONF_FINAL_WARNS=""
  48. MHD_LIB_CPPFLAGS=""
  49. MHD_LIB_CFLAGS=""
  50. MHD_LIB_LDFLAGS=""
  51. MHD_LIBDEPS=""
  52. # for pkg-config
  53. MHD_REQ_PRIVATE=''
  54. MHD_LIBDEPS_PKGCFG=''
  55. AS_IF([test -z "$CC" && test -z "$CPP"], [
  56. AC_MSG_CHECKING([[whether z/OS special settings are required]])
  57. AS_IF([test `uname -s` = "OS/390"],
  58. [
  59. # configure binaries for z/OS
  60. AS_IF([test -z "$CC"],
  61. [CC=`pwd`"/contrib/xcc"
  62. chmod +x $CC || true])
  63. AS_IF([test -z "$CPP"],
  64. CPP="c89 -E")
  65. AC_MSG_RESULT([[yes]])
  66. ],
  67. [AC_MSG_RESULT([[no]])]
  68. )
  69. ])
  70. AC_MSG_CHECKING([for build type])
  71. AC_ARG_ENABLE([build-type],
  72. [AS_HELP_STRING([[--enable-build-type=TYPE]],
  73. [enable build TYPE, a set of configuration parameters; individual settings ]
  74. [(asserts, sanitizers, compiler and linker flags) can be overridden by ]
  75. [additional configure parameters (debug, debugger, neutral, release, release-compact, ]
  76. [release-hardened) [neutral]])],
  77. [], [enable_build_type=neutral])
  78. AS_IF([test "x${enable_build_type}" = "x"], [enable_build_type="neutral"])
  79. AS_VAR_IF([enable_build_type], ["no"], [enable_build_type="neutral"])
  80. AS_VAR_IF([enable_build_type], ["yes"], [AC_MSG_ERROR([[Missing TYPE for --enable-build-type=]])])
  81. AS_CASE([${enable_build_type}],
  82. [debug], [AC_MSG_RESULT([debug. Defaults: enable asserts, sanitizers (if any supported), debug information, compiler optimisation for debugging])],
  83. [debugger], [AC_MSG_RESULT([debugger. Defaults: enable asserts, disable sanitizers, debug information, no compiler optimisation, static lib])],
  84. [neutral], [AC_MSG_RESULT([neutral. Defaults: use only user-specified compiler and linker flags])],
  85. [release], [AC_MSG_RESULT([release. Defaults: disable asserts, enable compiler optimisations])],
  86. [release-compact], [AC_MSG_RESULT([release-compact. Defaults: disable asserts, enable compiler optimisations for size, enable compact code])],
  87. [release-hardened], [AC_MSG_RESULT([release-hardened. Defaults: disable asserts, enable compiler optimisations, enable linker and compiler hardening])],
  88. [AC_MSG_ERROR([[Unknown build type: ${enable_build_type}]])]
  89. )
  90. AS_VAR_IF([enable_build_type], ["neutral"], [:],
  91. [
  92. # For all non-neutral build types do not use automatic "-g -O2" for CFLAGS
  93. AS_IF([test -z "${CFLAGS}"], [CFLAGS=""])
  94. ]
  95. )
  96. AS_VAR_IF([enable_build_type], ["debugger"],
  97. [ # Build only static version unless something else is specified by the user
  98. AS_IF([test -z "${enable_static}" || test "x${enable_static}" = "xyes"],
  99. [
  100. AS_IF([test -z "${enable_shared}"],
  101. [
  102. enable_shared="no"
  103. enable_static="yes"
  104. ]
  105. )
  106. ],
  107. [
  108. AS_CASE([${enable_static}],[*libmicrohttpd*],
  109. [AS_IF([test -z "${enable_shared}"], [enable_shared="no"])],
  110. )
  111. ]
  112. )
  113. ]
  114. )
  115. AS_CASE([${enable_build_type}],[debug|debugger],
  116. [ AS_IF([test -z "${enable_silent_rules}"], [ enable_silent_rules="yes" ])]
  117. )
  118. AM_INIT_AUTOMAKE([gnu] [check-news] [filename-length-max=99] [tar-v7] [silent-rules] [subdir-objects])
  119. # Checks for programs.
  120. AC_PROG_AWK
  121. AC_PROG_GREP
  122. AC_PROG_FGREP
  123. AC_PROG_INSTALL
  124. AC_PROG_LN_S
  125. AC_PROG_MAKE_SET
  126. AC_CANONICAL_HOST
  127. m4_version_prereq([2.70],
  128. [
  129. # Find C compiler and compiler options to support
  130. # the latest C standard (C11). Fallback to C99 and C89
  131. # if later C versions are not supported.
  132. AC_PROG_CC
  133. ],
  134. [
  135. # Find C compiler and compiler options to support
  136. # the latest C standard (C99). Fallback to C89
  137. # if later C versions are not supported.
  138. AC_PROG_CC_STDC
  139. ]
  140. )
  141. # Workaround for libgcrypt
  142. AS_IF([[test "x$lt_sysroot" != "x" && test "x$SYSROOT" = "x"]], [[SYSROOT="$lt_sysroot"]])
  143. user_CFLAGS="$CFLAGS"
  144. user_LDFLAGS="$LDFLAGS"
  145. user_CPPFLAGS="$CPPFLAGS"
  146. CFLAGS_ac=""
  147. LDFLAGS_ac=""
  148. CPPFLAGS_ac=""
  149. MHD_SYS_EXT([CPPFLAGS_ac])
  150. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  151. m4_version_prereq([2.72],
  152. [
  153. AC_SYS_YEAR2038
  154. ],
  155. [
  156. AC_SYS_LARGEFILE
  157. ]
  158. )
  159. AC_FUNC_FSEEKO
  160. LT_INIT([win32-dll])
  161. LT_LANG([Windows Resource])
  162. lt_prog_compiler_pic_RC="$lt_prog_compiler_pic_RC -DDLL_EXPORT" # Used only on W32
  163. AC_ARG_ENABLE([compact-code],
  164. [AS_HELP_STRING([[--enable-compact-code]],
  165. [enable use of a reduced size version of the code, resulting in smaller ]
  166. [binaries with a slight performance hit [auto]])],
  167. [], [enable_compact_code=auto])
  168. AS_IF([test "x${enable_compact_code}" = "x"], [enable_compact_code="auto"])
  169. AH_TEMPLATE([[MHD_FAVOR_SMALL_CODE]], [Define to '1' to use compact code version])
  170. AH_TEMPLATE([[MHD_FAVOR_FAST_CODE]], [Define to '1' to use fast (and larger) code version])
  171. AS_UNSET([compact_code_MSG])
  172. AS_CASE([${enable_compact_code}], [auto],
  173. [
  174. # Parameter not set.
  175. # Check preprocessor macros
  176. AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],
  177. [
  178. enable_compact_code="yes"
  179. compact_code_MSG="enabled by preprocessor macro"
  180. ],
  181. [],[/* no includes */]
  182. )
  183. AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],
  184. [
  185. AS_VAR_IF([enable_compact_code],["yes"],
  186. [AC_MSG_ERROR([Both MHD_FAVOR_SMALL_CODE and MHD_FAVOR_FAST_CODE macros are defined])]
  187. )
  188. enable_compact_code="no"
  189. compact_code_MSG="set by preprocessor macro"
  190. ],[],[/* no includes */]
  191. )
  192. AS_VAR_IF([enable_compact_code], ["auto"],
  193. [
  194. # No preference by preprocessor macros
  195. AC_CACHE_CHECK([whether compiler is configured to optimize for size],
  196. [mhd_cv_cc_optim_size],
  197. [
  198. AC_COMPILE_IFELSE(
  199. [
  200. AC_LANG_PROGRAM([[
  201. #ifndef __OPTIMIZE_SIZE__
  202. #error Looks like compiler does not optimize for size
  203. choke me now
  204. #endif
  205. ]],[])
  206. ],
  207. [mhd_cv_cc_optim_size="yes"],[mhd_cv_cc_optim_size="no"]
  208. )
  209. ]
  210. )
  211. AS_VAR_IF([mhd_cv_cc_optim_size], ["yes"],
  212. [
  213. enable_compact_code="yes"
  214. compact_code_MSG="enabled automatically as compiler optimizes for size"
  215. AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1])
  216. ]
  217. )
  218. ]
  219. )
  220. AS_VAR_IF([enable_compact_code], ["auto"],
  221. [
  222. # No preference by preprocessor macros and compiler flags
  223. AS_CASE([${enable_build_type}],[*-compact],
  224. [
  225. enable_compact_code="yes"
  226. compact_code_MSG="enabled by --enable-build-type=${enable_build_type}"
  227. AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1])
  228. ]
  229. )
  230. ]
  231. )
  232. AS_VAR_IF([enable_compact_code], ["auto"],
  233. [
  234. # No preference
  235. enable_compact_code="no"
  236. compact_code_MSG="by default"
  237. AC_DEFINE([MHD_FAVOR_FAST_CODE],[1])
  238. ]
  239. )
  240. ],
  241. [yes],
  242. [
  243. compact_code_MSG="enabled by configure parameter"
  244. AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],
  245. [],
  246. [AC_DEFINE([MHD_FAVOR_SMALL_CODE],[1])],[/* no includes */]
  247. )
  248. AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],
  249. [AC_MSG_ERROR([MHD_FAVOR_FAST_CODE macro is defined, --enable-compact-code could not be used])
  250. ],
  251. [],[/* no includes */]
  252. )
  253. ],
  254. [no],
  255. [
  256. compact_code_MSG="disabled by configure parameter"
  257. AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],
  258. [],
  259. [AC_DEFINE([MHD_FAVOR_FAST_CODE],[1])],[/* no includes */]
  260. )
  261. AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],
  262. [AC_MSG_ERROR([MHD_FAVOR_SMALL_CODE macro is defined, --disable-compact-code could not be used])
  263. ],
  264. [],[/* no includes */]
  265. )
  266. ],
  267. [AC_MSG_ERROR([[Unknown parameter value: --enable-compact-code=${enable_compact_code}]])]
  268. )
  269. AC_MSG_CHECKING([whether to use a reduced size version of the code])
  270. AC_MSG_RESULT([${enable_compact_code} (${compact_code_MSG})])
  271. CFLAGS="${user_CFLAGS}"
  272. # Compiler options to always enable (if supported)
  273. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-fno-strict-aliasing], [-qnoansialias])
  274. # '-qlonglong' is XLC option for C89, not used with C99 or later
  275. MHD_CHECK_ADD_CC_CFLAG([-qlonglong], [CFLAGS_ac])
  276. # Set basic optimisation flags
  277. AS_VAR_IF([enable_build_type],["neutral"],[],
  278. [ # Any non-neutral build types
  279. AC_CACHE_CHECK([whether workarounds for clang or clang-based compiler are required],
  280. [mhd_cv_cc_clang_based],
  281. [
  282. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  283. #if ! defined(__clang__) && ! defined(__llvm__)
  284. #error Compiler is not clang-based
  285. choke me now
  286. #endif
  287. ]]
  288. )
  289. ],
  290. [mhd_cv_cc_clang_based="yes"],[mhd_cv_cc_clang_based="no"]
  291. )
  292. ]
  293. )
  294. ]
  295. )
  296. AS_CASE([${enable_build_type}],[debug|debugger],
  297. [ # Debug build or build for walking with debugger
  298. CFLAGS="${user_CFLAGS}"
  299. AS_VAR_IF([enable_build_type],["debug"],
  300. [
  301. # Clang has ASAN (pointer compare) broken when '-Og' optimisations are used
  302. AS_IF([test "x${enable_sanitizers}" != "xno" && test "x${mhd_cv_cc_clang_based}" = "xyes"],
  303. [MHD_CHECK_ADD_CC_CFLAG([-O0], [CFLAGS_ac])],
  304. [MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Og], [-O0])]
  305. )
  306. ],
  307. [MHD_CHECK_ADD_CC_CFLAG([-O0], [CFLAGS_ac])]
  308. )
  309. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  310. ]
  311. )
  312. AS_CASE([${enable_build_type}],[release|release-*],
  313. [ # All release types
  314. AS_VAR_IF([enable_build_type],["release-compact"],
  315. [
  316. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  317. AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[],
  318. [AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[],
  319. [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_SMALL_CODE=1])],
  320. [/* no includes */])],[/* no includes */])
  321. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  322. CFLAGS="${user_CFLAGS}"
  323. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Oz], [-Os], [-O])
  324. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  325. ],
  326. [ # All non-compact release types
  327. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  328. AC_CHECK_DECL([MHD_FAVOR_SMALL_CODE],[],
  329. [AC_CHECK_DECL([MHD_FAVOR_FAST_CODE],[],
  330. [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DMHD_FAVOR_FAST_CODE=1])],
  331. [/* no includes */])],[/* no includes */])
  332. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  333. CFLAGS="${user_CFLAGS}"
  334. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-O2], [-O])
  335. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  336. ]
  337. )
  338. ]
  339. )
  340. AS_VAR_IF([enable_build_type],["neutral"],[],
  341. [ # Any non-neutral build types
  342. MHD_CHECK_ADD_CC_CFLAGS([-Wall -Wnull-dereference], [CFLAGS_ac])
  343. MHD_CHECK_ADD_CC_CFLAGS([-Wdeclaration-after-statement -Wimplicit -Wnested-externs], [CFLAGS_ac])
  344. MHD_CHECK_ADD_CC_CFLAGS([-Wredundant-decls -Wtrampolines -Wunsafe-loop-optimizations], [CFLAGS_ac])
  345. MHD_CHECK_ADD_CC_CFLAGS([-Wpoison-system-directories], [CFLAGS_ac])
  346. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  347. LDFLAGS="${user_LDFLAGS}"
  348. MHD_CHECK_ADD_CC_LDFLAG([-Wl,--warn-common], [LDFLAGS_ac])
  349. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  350. ]
  351. )
  352. AS_CASE([${enable_build_type}],[debug|debugger],
  353. [ # Debug build or build for walking with debugger
  354. CFLAGS="${user_CFLAGS}"
  355. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-ggdb3], [-g3], [-ggdb], [-g])
  356. MHD_CHECK_ADD_CC_CFLAGS([-Wextra -Wdouble-promotion], [CFLAGS_ac])
  357. MHD_FIND_ADD_CC_CFLAG_IFELSE(
  358. [
  359. # clang produce warning when string pointer is used as a format specifier for v*printf() function
  360. AS_VAR_IF([mhd_cv_cc_clang_based],["yes"],[MHD_CHECK_ADD_CC_CFLAG([-Wno-format-nonliteral], [CFLAGS_ac])])
  361. ],[],
  362. [CFLAGS_ac], [-Wformat=2], [-Wformat]
  363. )
  364. MHD_CHECK_ADD_CC_CFLAGS([-Wformat-overflow -Wformat-truncation -Wformat-security -Wformat-signedness], [CFLAGS_ac])
  365. MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-include-dirs -Wshift-overflow=2 -Wstringop-overflow=4 -Walloc-zero], [CFLAGS_ac])
  366. MHD_CHECK_ADD_CC_CFLAGS([-Wduplicated-branches -Wduplicated-cond -Wfloat-equal -Wshadow -Wpointer-arith], [CFLAGS_ac])
  367. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wshadow-all], [-Wshadow])
  368. MHD_CHECK_ADD_CC_CFLAGS([-Wbad-function-cast -Wcast-qual -Wwrite-strings -Wconversion], [CFLAGS_ac])
  369. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wcast-align=strict], [-Wcast-align])
  370. MHD_CHECK_ADD_CC_CFLAGS([-Wjump-misses-init -Wlogical-op -Waggregate-return -Wstrict-prototypes], [CFLAGS_ac])
  371. MHD_CHECK_ADD_CC_CFLAGS([-Wold-style-definition -Wmissing-declarations -Wmissing-prototypes], [CFLAGS_ac])
  372. MHD_CHECK_ADD_CC_CFLAGS([-Wuninitialized -Winit-self -Wshift-negative-value -Wswitch-enum], [CFLAGS_ac])
  373. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wstrict-overflow=4], [-Wstrict-overflow])
  374. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac], [-Wnormalized=nfkc], [-Wnormalized])
  375. MHD_CHECK_ADD_CC_CFLAGS([-Walloca -Wbidi-chars=any -Warray-bounds -Wpacked -Wvariadic-macros], [CFLAGS_ac])
  376. MHD_CHECK_ADD_CC_CFLAGS([-Wundef], [CFLAGS_ac])
  377. MHD_CHECK_ADD_CC_CFLAGS([-Wanon-enum-enum-conversion -Warray-bounds-pointer-arithmetic -Wassign-enum], [CFLAGS_ac])
  378. MHD_CHECK_ADD_CC_CFLAGS([-Wbit-int-extension -Wbitfield-enum-conversion -Wparentheses -Wbool-operation], [CFLAGS_ac])
  379. MHD_CHECK_ADD_CC_CFLAGS([-Wcast-function-type -Wcomma -Wcomment -Wcompound-token-split], [CFLAGS_ac])
  380. MHD_CHECK_ADD_CC_CFLAGS([-Wconditional-uninitialized -Wdeprecated], [CFLAGS_ac])
  381. MHD_CHECK_ADD_CC_CFLAGS([-Wdocumentation-pedantic -Wempty-init-stmt -Wenum-conversion -Wexpansion-to-defined], [CFLAGS_ac])
  382. MHD_CHECK_ADD_CC_CFLAGS([-Wflexible-array-extensions -Wloop-analysis -Wformat-pedantic], [CFLAGS_ac])
  383. MHD_CHECK_ADD_CC_CFLAGS([-Wformat-type-confusion -Wfour-char-constants], [CFLAGS_ac])
  384. MHD_CHECK_ADD_CC_CFLAGS([-Wgcc-compat -Wgnu-anonymous-struct -Wgnu-compound-literal-initializer], [CFLAGS_ac])
  385. MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-conditional-omitted-operand -Wgnu-designator -Wgnu-empty-initializer], [CFLAGS_ac])
  386. MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-empty-struct -Wgnu-flexible-array-initializer -Wgnu-folding-constant], [CFLAGS_ac])
  387. MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-null-pointer-arithmetic -Wgnu-pointer-arith -Wgnu-redeclared-enum], [CFLAGS_ac])
  388. MHD_CHECK_ADD_CC_CFLAGS([-Wgnu-union-cast -Wgnu-variable-sized-type-not-at-end -Widiomatic-parentheses], [CFLAGS_ac])
  389. MHD_CHECK_ADD_CC_CFLAGS([-Wmissing-noreturn -Wmissing-variable-declarations -Wnested-anon-types], [CFLAGS_ac])
  390. MHD_CHECK_ADD_CC_CFLAGS([-Wnewline-eof -Wover-aligned -Wredundant-parens], [CFLAGS_ac])
  391. MHD_CHECK_ADD_CC_CFLAGS([-Wshift-sign-overflow -Wtautological-compare -Wunaligned-access], [CFLAGS_ac])
  392. MHD_CHECK_ADD_CC_CFLAGS([-Wunused -Wzero-as-null-pointer-constant -Wzero-length-array], [CFLAGS_ac])
  393. MHD_CHECK_CC_CFLAG([-Wused-but-marked-unused],[CFLAGS_ac],
  394. [
  395. AC_CACHE_CHECK([whether $[]CC -Wused-but-marked-unused works with system headers],
  396. [mhd_cv_wused_but_marked_unused_sys_header],
  397. [
  398. SAVE_ac_c_werror_flag="$ac_c_werror_flag"
  399. ac_c_werror_flag="yes"
  400. CFLAGS="${CFLAGS_ac} -Wused-but-marked-unused ${user_CFLAGS}"
  401. AC_COMPILE_IFELSE(
  402. [
  403. AC_LANG_SOURCE([[
  404. #include <stdio.h>
  405. int main(void)
  406. {
  407. char buf[16];
  408. return (int) snprintf(buf, 16, "test");
  409. }
  410. ]]
  411. )
  412. ],
  413. [mhd_cv_wused_but_marked_unused_sys_header="yes"],
  414. [mhd_cv_wused_but_marked_unused_sys_header="no"]
  415. )
  416. ac_c_werror_flag="$SAVE_ac_c_werror_flag"
  417. ]
  418. )
  419. AS_VAR_IF([mhd_cv_wused_but_marked_unused_sys_header],["yes"],
  420. [MHD_APPEND_FLAG_TO_VAR([CFLAGS_ac],[-Wused-but-marked-unused])]
  421. )
  422. ]
  423. )
  424. #
  425. # Removed flags:
  426. #
  427. # -Wdisabled-macro-expansion - warns about macros from system headers
  428. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  429. LDFLAGS="${user_LDFLAGS}"
  430. MHD_CHECK_ADD_CC_LDFLAG([-Wl,--enable-long-section-names], [LDFLAGS_ac])
  431. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  432. ]
  433. )
  434. AS_CASE([${enable_build_type}],[release|release-*],
  435. [ # All release types
  436. CFLAGS="${user_CFLAGS}"
  437. AS_VAR_IF([enable_build_type],["release-compact"],
  438. [],
  439. [ # All non-compact release types
  440. MHD_CHECK_ADD_CC_CFLAGS([-fsched-pressure -fira-loop-pressure -fmerge-all-constants], [CFLAGS_ac]) # These flags may improve size, recheck with LTO and linker garbage collection
  441. MHD_CHECK_ADD_CC_CFLAGS([-ftree-partial-pre -fgcse-after-reload -fipa-pta], [CFLAGS_ac])
  442. MHD_CHECK_ADD_CC_CFLAGS([-fisolate-erroneous-paths-attribute -ffinite-loops -floop-nest-optimize], [CFLAGS_ac])
  443. MHD_CHECK_ADD_CC_CFLAGS([-fpredictive-commoning -frename-registers], [CFLAGS_ac])
  444. MHD_CHECK_ADD_CC_CFLAGS([-ftree-loop-distribute-patterns -fpeel-loops -fsplit-loops -ftree-vectorize], [CFLAGS_ac])
  445. ]
  446. )
  447. AS_VAR_IF([enable_build_type],["release-hardened"],
  448. [
  449. MHD_CHECK_ADD_CC_CFLAGS([-Wformat-security -Wstack-protector], [CFLAGS_ac])
  450. MHD_CHECK_ADD_CC_CFLAGS([-Wuninitialized -Winit-self -Walloc-zero -Wbidi-chars=any], [CFLAGS_ac])
  451. ]
  452. )
  453. AS_VAR_IF([enable_build_type],["release"],
  454. [ # Flags are not suitable for 'compact' and for 'hardened'
  455. MHD_CHECK_ADD_CC_CFLAGS([-ffast-math -fno-trapping-math], [CFLAGS_ac])
  456. ]
  457. )
  458. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  459. # W32-specific
  460. LDFLAGS="${user_LDFLAGS}"
  461. MHD_CHECK_ADD_CC_LDFLAG([-Wl,--disable-long-section-names], [LDFLAGS_ac])
  462. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  463. ]
  464. )
  465. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  466. # Additional flags are checked and added at the end of 'configure'
  467. # Check for headers that are ALWAYS required
  468. AC_CHECK_HEADERS_ONCE([stdio.h string.h stdint.h errno.h limits.h fcntl.h], [],
  469. [AC_MSG_ERROR([Compiling libmicrohttpd requires standard POSIX headers files])], [AC_INCLUDES_DEFAULT])
  470. # Check for basic optional headers
  471. AC_CHECK_HEADERS([stddef.h stdlib.h inttypes.h sys/types.h sys/stat.h unistd.h \
  472. sys/uio.h], [], [], [AC_INCLUDES_DEFAULT])
  473. # Check for clock-specific optional headers
  474. AC_CHECK_HEADERS([sys/time.h time.h], [], [], [AC_INCLUDES_DEFAULT])
  475. # Check for system information and parameters optional headers
  476. AC_CHECK_HEADERS([endian.h machine/endian.h sys/endian.h sys/byteorder.h \
  477. sys/machine.h machine/param.h sys/param.h sys/isa_defs.h \
  478. sys/ioctl.h], [], [], [AC_INCLUDES_DEFAULT])
  479. # Check for network and sockets optional headers
  480. AC_CHECK_HEADERS([sys/socket.h sys/select.h netinet/in_systm.h netinet/in.h \
  481. arpa/inet.h netinet/ip.h netinet/tcp.h net/if.h \
  482. netdb.h sockLib.h inetLib.h], [], [],
  483. [AC_INCLUDES_DEFAULT
  484. [
  485. #ifdef HAVE_SYS_TYPES_H
  486. #include <sys/types.h>
  487. #endif /* HAVE_SYS_TYPES_H */
  488. #ifdef HAVE_INTTYPES_H
  489. #include <inttypes.h>
  490. #endif /* HAVE_INTTYPES_H */
  491. #ifdef HAVE_SYS_SOCKET_H
  492. #include <sys/socket.h>
  493. #endif /* HAVE_SYS_SOCKET_H */
  494. #ifdef HAVE_NETINET_IN_SYSTM_H
  495. #include <netinet/in_systm.h>
  496. #endif /* HAVE_NETINET_IN_SYSTM_H */
  497. #ifdef HAVE_NETINET_IN_H
  498. #include <netinet/in.h>
  499. #endif /* HAVE_NETINET_IN_H */
  500. #ifdef HAVE_NETINET_IP_H
  501. #include <netinet/ip.h>
  502. #endif /* HAVE_NETINET_IP_H */
  503. #ifdef HAVE_NETINET_TCP_H
  504. #include <netinet/tcp.h>
  505. #endif /* HAVE_NETINET_TCP_H */
  506. ]]
  507. )
  508. # Check for other optional headers
  509. AC_CHECK_HEADERS([sys/msg.h sys/mman.h signal.h], [], [], [AC_INCLUDES_DEFAULT])
  510. AC_CHECK_HEADER([[search.h]],
  511. [
  512. MHD_CHECK_LINK_RUN([[for proper tsearch(), tfind() and tdelete()]],[[mhd_cv_sys_tsearch_usable]],
  513. [
  514. AS_CASE([$host_os],
  515. [openbsd*],
  516. [[ # Some OpenBSD versions have wrong return value for tdelete()
  517. mhd_cv_sys_tsearch_usable='assuming no'
  518. ]],
  519. [netbsd*],
  520. [[ # NetBSD had leaked root node for years
  521. mhd_cv_sys_tsearch_usable='assuming no'
  522. ]],
  523. [[mhd_cv_sys_tsearch_usable='assuming yes']]
  524. )
  525. ],
  526. [
  527. AC_LANG_SOURCE(
  528. [[
  529. #ifdef HAVE_STDDEF_H
  530. #include <stddef.h>
  531. #endif /* HAVE_STDDEF_H */
  532. #ifdef HAVE_STDLIB_H
  533. #include <stdlib.h>
  534. #endif /* HAVE_STDLIB_H */
  535. #include <stdio.h>
  536. #include <search.h>
  537. static int cmp_func(const void *p1, const void *p2)
  538. {
  539. return (*((const int *)p1)) - (*((const int *)p2));
  540. }
  541. int main(void)
  542. {
  543. int ret = 0;
  544. void *root_ptr = NULL;
  545. int element1 = 1;
  546. int **element_ptr_ptr1;
  547. int **element_ptr_ptr2;
  548. element_ptr_ptr1 =
  549. (int **) tsearch ((void*) &element1, &root_ptr, &cmp_func);
  550. if (NULL == element_ptr_ptr1)
  551. {
  552. fprintf (stderr, "NULL pointer has been returned when tsearch() called for the first time.\n");
  553. return ++ret;
  554. }
  555. if (*element_ptr_ptr1 != &element1)
  556. {
  557. fprintf (stderr, "Wrong pointer has been returned when tsearch() called for the first time.\n");
  558. return ++ret;
  559. }
  560. if (NULL == root_ptr)
  561. {
  562. fprintf (stderr, "Root pointer has not been set by tsearch().\n");
  563. return ++ret;
  564. }
  565. element_ptr_ptr2 =
  566. (int **) tsearch ((void*) &element1, &root_ptr, &cmp_func);
  567. if (NULL == element_ptr_ptr2)
  568. {
  569. fprintf (stderr, "NULL pointer has been returned when tsearch() called for the second time.\n");
  570. return ++ret;
  571. }
  572. if (*element_ptr_ptr2 != &element1)
  573. {
  574. fprintf (stderr, "Wrong pointer has been returned when tsearch() called for the second time.\n");
  575. ++ret;
  576. }
  577. if (element_ptr_ptr2 != element_ptr_ptr1)
  578. {
  579. fprintf (stderr, "Wrong element has been returned when tsearch() called for the second time.\n");
  580. ++ret;
  581. }
  582. element_ptr_ptr2 =
  583. (int **) tfind ((void*) &element1, &root_ptr, &cmp_func);
  584. if (NULL == element_ptr_ptr2)
  585. {
  586. fprintf (stderr, "NULL pointer has been returned by tfind().\n");
  587. ++ret;
  588. }
  589. if (*element_ptr_ptr2 != &element1)
  590. {
  591. fprintf (stderr, "Wrong pointer has been returned when by tfind().\n");
  592. ++ret;
  593. }
  594. if (element_ptr_ptr2 != element_ptr_ptr1)
  595. {
  596. fprintf (stderr, "Wrong element has been returned when tsearch() called for the second time.\n");
  597. ++ret;
  598. }
  599. element_ptr_ptr1 =
  600. (int **) tdelete ((void*) &element1, &root_ptr, &cmp_func);
  601. if (NULL == element_ptr_ptr1)
  602. {
  603. fprintf (stderr, "NULL pointer has been returned by tdelete().\n");
  604. ++ret;
  605. }
  606. if (NULL != root_ptr)
  607. {
  608. fprintf (stderr, "Root pointer has not been set to NULL by tdelete().\n");
  609. ++ret;
  610. }
  611. return ret;
  612. }
  613. ]]
  614. )
  615. ],
  616. [AC_DEFINE([[MHD_USE_SYS_TSEARCH]], [[1]], [Define to 1 if you have properly working tsearch(), tfind() and tdelete() functions.])]
  617. )
  618. ],
  619. [], [AC_INCLUDES_DEFAULT]
  620. )
  621. AM_CONDITIONAL([MHD_USE_SYS_TSEARCH], [[test "x$mhd_cv_sys_tsearch_usable" = "xyes" || test "x$mhd_cv_sys_tsearch_usable" = "xassuming yes"]])
  622. # Optional headers used for tests
  623. AC_CHECK_HEADERS([sys/sysctl.h netinet/ip_icmp.h netinet/icmp_var.h], [], [],
  624. [[
  625. #ifdef HAVE_SYS_TYPES_H
  626. #include <sys/types.h>
  627. #endif /* HAVE_SYS_TYPES_H */
  628. #ifdef HAVE_SYS_SYSCTL_H
  629. #include <sys/sysctl.h>
  630. #endif /* HAVE_SYS_SYSCTL_H */
  631. #ifdef HAVE_SYS_SOCKET_H
  632. #include <sys/socket.h>
  633. #endif /* HAVE_SYS_SOCKET_H */
  634. #ifdef HAVE_NETINET_IN_SYSTM_H
  635. #include <netinet/in_systm.h>
  636. #endif /* HAVE_NETINET_IN_SYSTM_H */
  637. #ifdef HAVE_NETINET_IN_H
  638. #include <netinet/in.h>
  639. #endif /* HAVE_NETINET_IN_H */
  640. #ifdef HAVE_NETINET_IP_H
  641. #include <netinet/ip.h>
  642. #endif /* HAVE_NETINET_IP_H */
  643. #ifdef HAVE_NETINET_IP_ICMP_H
  644. #include <netinet/ip_icmp.h>
  645. #endif /* HAVE_NETINET_IP_ICMP_H */
  646. ]]
  647. )
  648. AC_ARG_ENABLE([compiler-hardening],
  649. [AS_HELP_STRING([--enable-compiler-hardening], [enable compiler security checks])],
  650. [],
  651. [AS_CASE([${enable_build_type}],[*-hardened],
  652. [enable_compiler_hardening='yes'],[enable_compiler_hardening='no'])]
  653. )
  654. AS_VAR_IF([enable_compiler_hardening],["yes"],
  655. [
  656. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  657. AC_CHECK_DECL([_FORTIFY_SOURCE],
  658. [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])],
  659. [],[/* no includes */])
  660. MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_FORTIFY_SOURCE=2])
  661. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  662. CFLAGS="${user_CFLAGS}"
  663. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac],[-fstack-protector-strong],[-fstack-protector-all],[-fstack-protector])
  664. MHD_CHECK_ADD_CC_CFLAGS([-fstack-clash-protection],[CFLAGS_ac])
  665. MHD_FIND_ADD_CC_CFLAG([CFLAGS_ac],[-ftrivial-auto-var-init=pattern],[-ftrivial-auto-var-init=zero])
  666. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  667. AS_IF([test "x${enable_static}" = "xyes" && test "x${pic_mode}" != "xyes"],
  668. [
  669. # PIE static lib can be used within non-PIE application, but
  670. # PIE static lib cannot be used in non-PIE shared lib. Let's assume
  671. # that static lib will not be used in shared lib
  672. # All "pie" flags will be used automatically by libtool only
  673. # for static library objects.
  674. CFLAGS="${user_CFLAGS}"
  675. # Perform tests here with "-pie" enabled
  676. LDFLAGS="${LDFLAGS_ac} -pie ${user_LDFLAGS}"
  677. MHD_CHECK_ADD_CC_CFLAG([-fPIE],[CFLAGS_ac],
  678. [
  679. MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie])
  680. ],
  681. [
  682. MHD_CHECK_ADD_CC_CFLAG([-fpie],[CFLAGS_ac],
  683. [
  684. MHD_APPEND_FLAG_TO_VAR([LDFLAGS_ac],[-pie])
  685. ]
  686. )
  687. ]
  688. )
  689. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  690. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  691. ]
  692. )
  693. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  694. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  695. ]
  696. )
  697. # Linker hardening options
  698. # Currently these options are ELF specific, they don't work on Darwin and W32
  699. AC_ARG_ENABLE([linker-hardening],
  700. [AS_HELP_STRING([--enable-linker-hardening], [enable linker security fixups])],
  701. [],
  702. [AS_CASE([${enable_build_type}],[*-hardened],
  703. [enable_linker_hardening='yes'],[enable_linker_hardening='no'])]
  704. )
  705. AS_VAR_IF([enable_linker_hardening],["yes"],
  706. [
  707. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  708. LDFLAGS="${user_LDFLAGS}"
  709. MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,relro],[LDFLAGS_ac],
  710. [MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,now],[LDFLAGS_ac])])
  711. # Actually should be "noexec" by default, but let's try to enforce it.
  712. MHD_CHECK_ADD_CC_LDFLAG([-Wl,-z,noexecstack],[LDFLAGS_ac])
  713. # W32-specific. Some are enabled by default, but they will be enfored to be sure.
  714. MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--large-address-aware -Wl,--enable-auto-image-base],[LDFLAGS_ac])
  715. MHD_CHECK_ADD_CC_LDFLAGS([-Wl,--dynamicbase -Wl,--nxcompat -Wl,--high-entropy-va],[LDFLAGS_ac])
  716. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  717. ]
  718. )
  719. MHD_BOOL
  720. AC_C_INLINE
  721. AS_UNSET([errattr_CFLAGS])
  722. CFLAGS="${user_CFLAGS}"
  723. MHD_CHECK_CC_CFLAG([-Werror=attributes],[CFLAGS_ac],
  724. [
  725. AC_CACHE_CHECK([whether -Werror=attributes actually works],[mhd_cv_cflag_werror_attr_works],
  726. [
  727. CFLAGS="${CFLAGS_ac} ${user_CFLAGS} -Werror=attributes"
  728. AC_COMPILE_IFELSE([
  729. AC_LANG_PROGRAM(
  730. [[__attribute__((non_existing_attrb_dummy)) static int SimpleFunc(void) {return 3;}]],
  731. [[int r = SimpleFunc(); if (r) return r;]]
  732. )
  733. ],
  734. [mhd_cv_cflag_werror_attr_works="no"],
  735. [mhd_cv_cflag_werror_attr_works="yes"]
  736. )
  737. ]
  738. )
  739. AS_VAR_IF([mhd_cv_cflag_werror_attr_works],["yes"],
  740. [errattr_CFLAGS="-Werror=attributes"]
  741. )
  742. ]
  743. )
  744. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  745. AS_IF([test "x$ac_cv_c_inline" != "xno"],
  746. [
  747. AC_DEFINE([HAVE_INLINE_FUNCS],[1],[Define to 1 if your C compiler supports inline functions.])
  748. AC_CACHE_CHECK([for function force inline keywords supported by $CC],[mhd_cv_cc_kwd_forceinline],
  749. [
  750. MHD_SAVED_ac_c_werror_flag="$ac_c_werror_flag"
  751. ac_c_werror_flag=yes
  752. mhd_cv_cc_kwd_forceinline="none"
  753. CFLAGS="${CFLAGS_ac} ${user_CFLAGS} $errattr_CFLAGS"
  754. for keyword_chk in "inline __attribute__((always_inline))" __forceinline
  755. do
  756. AS_CASE([${keyword_chk}],
  757. [*attribute*],
  758. [AS_IF([test "x$errattr_CFLAGS" = "x"],[continue])]
  759. )
  760. AC_LINK_IFELSE([
  761. AC_LANG_SOURCE([[
  762. #ifdef HAVE_STDBOOL_H
  763. #include <stdbool.h>
  764. #endif
  765. static ${keyword_chk} bool cmpfn(int x, int y)
  766. { return x > y; }
  767. static ${keyword_chk} int sumfn(int x, int y)
  768. { return x + y; }
  769. int main(void)
  770. {
  771. int a = 1, b = 100, c;
  772. if (cmpfn(a, b))
  773. c = sumfn(a, b);
  774. else
  775. c = 0 - sumfn(a, b);
  776. return (cmpfn(0, c) ? 0 : 5);
  777. }
  778. ]]
  779. )
  780. ],
  781. [mhd_cv_cc_kwd_forceinline="${keyword_chk}"]
  782. )
  783. test "x${mhd_cv_cc_kwd_forceinline}" != "xnone" && break
  784. done
  785. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  786. ac_c_werror_flag="$MHD_SAVED_ac_c_werror_flag"
  787. AS_UNSET([MHD_SAVED_ac_c_werror_flag])
  788. ]
  789. )
  790. ]
  791. )
  792. AS_IF([test "x$ac_cv_c_inline" != "xno" && test "x${mhd_cv_cc_kwd_forceinline}" != "xnone"],
  793. [AC_DEFINE_UNQUOTED([_MHD_static_inline],[static $mhd_cv_cc_kwd_forceinline],[Define to prefix which will be used with MHD static inline functions.])]
  794. ,
  795. [AC_DEFINE([_MHD_static_inline],[static inline],[Define to prefix which will be used with MHD static inline functions.])]
  796. )
  797. AC_CHECK_HEADERS([stdalign.h], [], [], [AC_INCLUDES_DEFAULT])
  798. AC_CACHE_CHECK([[for C11 'alignof()' support]], [[mhd_cv_c_alignof]],
  799. [AC_COMPILE_IFELSE(
  800. [AC_LANG_PROGRAM(
  801. [[
  802. #ifdef HAVE_STDALIGN_H
  803. #include <stdalign.h>
  804. #endif
  805. ]], [[
  806. int var1[(alignof(int) >= 2) ? 1 : -1];
  807. int var2[alignof(unsigned int) - 1];
  808. int var3[(alignof(char) > 0) ? 1 : -1];
  809. int var4[(alignof(long) >= 4) ? 1 : -1];
  810. /* Mute compiler warnings */
  811. var1[0] = var2[0] = var3[0] = 0;
  812. var4[0] = 1;
  813. if (var1[0] + var2[0] + var3[0] == var4[0])
  814. return 1;
  815. ]])
  816. ], [
  817. AC_COMPILE_IFELSE(
  818. [AC_LANG_PROGRAM(
  819. [[
  820. #ifdef HAVE_STDALIGN_H
  821. #include <stdalign.h>
  822. #endif
  823. ]], [[
  824. /* Should fail if 'alignof()' works */
  825. int var1[alignof(nonexisting_type) - 1];
  826. /* Mute compiler warnings */
  827. var1[0] = 1;
  828. if (var1[0] + 1 == 1)
  829. return 1;
  830. ]])
  831. ], [[mhd_cv_c_alignof='no']], [[mhd_cv_c_alignof='yes']])
  832. ], [[mhd_cv_c_alignof='no']])
  833. ])
  834. AS_VAR_IF([mhd_cv_c_alignof], ["yes"],
  835. [AC_DEFINE([[HAVE_C_ALIGNOF]], [1], [Define to 1 if your compiler supports 'alignof()'])])
  836. # Check system type
  837. AC_MSG_CHECKING([[for target host OS]])
  838. os_is_windows="no"
  839. os_is_native_w32="no"
  840. AS_CASE(["$host_os"],
  841. [*darwin* | *rhapsody* | *macosx*],
  842. [AC_DEFINE([OSX],[1],[This is an OS X system])
  843. mhd_host_os='Darwin'
  844. AC_MSG_RESULT([[$mhd_host_os]])],
  845. [kfreebsd*-gnu],
  846. [AC_DEFINE([SOMEBSD],[1],[This is a BSD system])
  847. AC_DEFINE([FREEBSD],[1],[This is a FreeBSD system])
  848. mhd_host_os='FreeBSD kernel with GNU userland'
  849. AC_MSG_RESULT([[$mhd_host_os]])],
  850. [freebsd*],
  851. [AC_DEFINE([SOMEBSD],[1],[This is a BSD system])
  852. AC_DEFINE([FREEBSD],[1],[This is a FreeBSD system])
  853. mhd_host_os='FreeBSD'
  854. AC_MSG_RESULT([[$mhd_host_os]])],
  855. [openbsd*],
  856. [AC_DEFINE([SOMEBSD],[1],[This is a BSD system])
  857. AC_DEFINE([OPENBSD],[1],[This is an OpenBSD system])
  858. mhd_host_os='OpenBSD'
  859. AC_MSG_RESULT([[$mhd_host_os]])],
  860. [netbsd*],
  861. [AC_DEFINE([SOMEBSD],[1],[This is a BSD system])
  862. AC_DEFINE([NETBSD],[1],[This is a NetBSD system])
  863. mhd_host_os='NetBSD'
  864. AC_MSG_RESULT([[$mhd_host_os]])],
  865. [*solaris*],
  866. [AC_DEFINE([SOLARIS],[1],[This is a Solaris system])
  867. AC_DEFINE([_REENTRANT],[1],[Need with solaris or errno does not work])
  868. mhd_host_os='Solaris'
  869. AC_MSG_RESULT([[$mhd_host_os]])],
  870. [linux-gnu],
  871. [AC_DEFINE([LINUX],[1],[This is a Linux kernel])
  872. mhd_host_os='GNU/Linux'
  873. AC_MSG_RESULT([[$mhd_host_os]])],
  874. [linux-android*],
  875. [AC_DEFINE([LINUX],[1],[This is a Linux kernel])
  876. mhd_host_os='Android'
  877. AC_MSG_RESULT([[$mhd_host_os]])],
  878. [*linux*],
  879. [AC_DEFINE([LINUX],[1],[This is a Linux kernel])
  880. mhd_host_os='Linux'
  881. AC_MSG_RESULT([[$mhd_host_os]])],
  882. [*cygwin*],
  883. [AC_DEFINE([CYGWIN],[1],[This is a Cygwin system])
  884. mhd_host_os='Windows/Cygwin'
  885. AC_MSG_RESULT([[$mhd_host_os]])
  886. os_is_windows="yes"],
  887. [*mingw*],
  888. [
  889. AC_DEFINE([MINGW],[1],[This is a MinGW system])
  890. AC_DEFINE([WINDOWS],[1],[This is a Windows system])
  891. mhd_host_os='Windows/MinGW'
  892. AC_MSG_RESULT([[$mhd_host_os]])
  893. AC_CHECK_HEADERS([winsock2.h ws2tcpip.h], [], [AC_MSG_ERROR([[Winsock2 headers are required for W32]])], [AC_INCLUDES_DEFAULT])
  894. AC_CACHE_CHECK([for MS lib utility], [ac_cv_use_ms_lib_tool],
  895. [mslibcheck=`lib 2>&1`
  896. AS_IF([echo "$mslibcheck" | $GREP -e '^Microsoft (R) Library Manager' - >/dev/null],
  897. [ac_cv_use_ms_lib_tool=yes],
  898. [ac_cv_use_ms_lib_tool=no])
  899. ])
  900. AS_IF([test "x$ac_cv_use_ms_lib_tool" = "xyes"],
  901. [AC_SUBST([MS_LIB_TOOL], [[lib]])])
  902. AC_SUBST([lt_cv_objdir])
  903. os_is_windows="yes"
  904. os_is_native_w32="yes"
  905. ],
  906. [*openedition*],
  907. [AC_DEFINE([OS390],[1],[This is a OS/390 system])
  908. mhd_host_os='OS/390'
  909. AC_MSG_RESULT([[$mhd_host_os]])],
  910. [gnu*],
  911. [AC_DEFINE([[GNU_HURD]], [[1]], [Define to `1' if host machine runs on GNU Hurd.])
  912. mhd_host_os='GNU Hurd'
  913. AC_MSG_RESULT([[$mhd_host_os]])
  914. ],
  915. [
  916. AC_MSG_RESULT([unrecognised OS])
  917. mhd_host_os="${host_os}"
  918. AC_MSG_WARN([Unrecognised OS $host_os])
  919. AC_DEFINE([OTHEROS],1,[Some strange OS])
  920. ])
  921. AM_CONDITIONAL([CYGWIN_TARGET], [[test "x$os_is_windows" = "xyes" && \
  922. test "x${os_is_native_w32}" != "xyes"]])
  923. AS_VAR_IF([os_is_windows], ["yes"],
  924. [
  925. AC_MSG_CHECKING([[whether target W32 version is specified by precompiler defines]])
  926. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  927. /* Note: check logic is reversed for easy log reading */
  928. #ifdef WINVER
  929. #error WINVER is defined
  930. choke me now;
  931. #endif
  932. #ifdef _WIN32_WINNT
  933. #error _WIN32_WINNT is defined
  934. choke me now;
  935. #endif
  936. #ifdef NTDDI
  937. #error NTDDI is defined
  938. choke me now;
  939. #endif
  940. ]],[[(void)0]])
  941. ], [[mhd_w32_ver_preselect=no]], [[mhd_w32_ver_preselect=yes]]
  942. )
  943. AC_MSG_RESULT([[${mhd_w32_ver_preselect}]])
  944. AC_CHECK_HEADERS([windows.h sdkddkver.h], [], [], [AC_INCLUDES_DEFAULT])
  945. AS_VAR_IF([mhd_w32_ver_preselect],["yes"],
  946. [
  947. AC_MSG_CHECKING([[for specified target W32 version]])
  948. AS_UNSET([[mhd_w32_ver]])
  949. AS_UNSET([[mhd_w32_ver_msg]])
  950. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  951. #if _WIN32_WINNT+0 < 0x0501
  952. /* Check before headers inclusion */
  953. #error _WIN32_WINNT is less than 0x0501
  954. choke me now;
  955. #endif
  956. #ifdef HAVE_SDKDDKVER_H
  957. #include <sdkddkver.h>
  958. #endif
  959. #ifdef HAVE_WINDOWS_H
  960. #include <windows.h>
  961. #endif
  962. #if _WIN32_WINNT+0 < 0x0501
  963. #error _WIN32_WINNT is less than 0x0501
  964. choke me now;
  965. #endif
  966. ]],[[(void)0]])
  967. ], [], [
  968. AC_MSG_RESULT([[pre-WinXP]])
  969. AC_MSG_ERROR([[libmicrohttpd cannot be compiled for Windows version before Windows XP]])
  970. ]
  971. )
  972. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  973. #ifdef HAVE_SDKDDKVER_H
  974. #include <sdkddkver.h>
  975. #endif
  976. #ifdef HAVE_WINDOWS_H
  977. #include <windows.h>
  978. #endif
  979. #if _WIN32_WINNT+0 == 0x0501
  980. #error _WIN32_WINNT is 0x0501
  981. choke me now;
  982. #endif
  983. #if _WIN32_WINNT+0 == 0x0502
  984. #error _WIN32_WINNT is 0x0502
  985. choke me now;
  986. #endif
  987. ]],[[(void)0]])
  988. ], [], [
  989. mhd_w32_ver="WinXP"
  990. mhd_w32_ver_msg="WinXP (selected by precompiler flags)"
  991. ]
  992. )
  993. AS_VAR_SET_IF([mhd_w32_ver], [],
  994. [
  995. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  996. #ifdef HAVE_SDKDDKVER_H
  997. #include <sdkddkver.h>
  998. #endif
  999. #ifdef HAVE_WINDOWS_H
  1000. #include <windows.h>
  1001. #endif
  1002. #if _WIN32_WINNT+0 < 0x0600
  1003. #error _WIN32_WINNT is less than 0x0600 but greater than 0x0502
  1004. choke me now;
  1005. #endif
  1006. ]],[[(void)0]])
  1007. ], [], [
  1008. AC_MSG_ERROR([[_WIN32_WINNT value is wrong (less than 0x0600 but greater than 0x0502)]])
  1009. ]
  1010. )
  1011. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1012. #ifdef HAVE_SDKDDKVER_H
  1013. #include <sdkddkver.h>
  1014. #endif
  1015. #ifdef HAVE_WINDOWS_H
  1016. #include <windows.h>
  1017. #endif
  1018. #if _WIN32_WINNT+0 == 0x0600
  1019. #error _WIN32_WINNT is 0x0600
  1020. choke me now;
  1021. #endif
  1022. ]],[[(void)0]])
  1023. ], [], [
  1024. mhd_w32_ver="Vista"
  1025. mhd_w32_ver_msg="Vista (selected by precompiler flags)"
  1026. ]
  1027. )
  1028. ]
  1029. )
  1030. AS_VAR_SET_IF([mhd_w32_ver], [],
  1031. [
  1032. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1033. #ifdef HAVE_SDKDDKVER_H
  1034. #include <sdkddkver.h>
  1035. #endif
  1036. #ifdef HAVE_WINDOWS_H
  1037. #include <windows.h>
  1038. #endif
  1039. #if _WIN32_WINNT+0 > 0x0600
  1040. #error _WIN32_WINNT is greater than 0x0600
  1041. choke me now;
  1042. #endif
  1043. ]],[[(void)0]])
  1044. ], [
  1045. mhd_w32_ver="unknown"
  1046. mhd_w32_ver_msg="unknown (cannot be detected)"
  1047. ], [
  1048. mhd_w32_ver="newer than Vista"
  1049. mhd_w32_ver_msg="newer than Vista (selected by precompiler flags)"
  1050. ]
  1051. )
  1052. ]
  1053. )
  1054. AC_MSG_RESULT([[${mhd_w32_ver}]])
  1055. ], [
  1056. mhd_w32_ver="Vista"
  1057. mhd_w32_ver_msg="Vista (default, override by CPPFLAGS=-D_WIN32_WINNT=0xNNNN)"
  1058. CPPFLAGS_ac="${CPPFLAGS_ac} -D_WIN32_WINNT=0x0600"
  1059. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  1060. AC_MSG_CHECKING([[whether headers accept _WIN32_WINNT=0x0600]])
  1061. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1062. #ifdef HAVE_SDKDDKVER_H
  1063. #include <sdkddkver.h>
  1064. #endif
  1065. #ifdef HAVE_WINDOWS_H
  1066. #include <windows.h>
  1067. #endif
  1068. #include <stdio.h>
  1069. ]],[[(void)0]])
  1070. ], [
  1071. AC_MSG_RESULT([[yes]])
  1072. ], [
  1073. AC_MSG_RESULT([[no]])
  1074. AC_MSG_ERROR([Headers do not accept _WIN32_WINNT=0x0600. Consider override target W32 version by CPPFLAGS=-D_WIN32_WINNT=0xNNNN])
  1075. ]
  1076. )
  1077. ]
  1078. )
  1079. ]
  1080. )
  1081. AS_IF([test "x${os_is_windows}" = "xyes" && test "x${os_is_native_w32}" = "xyes"],
  1082. [
  1083. AC_CACHE_CHECK([W32 run-time library type], [mhd_cv_wctr_type],
  1084. [
  1085. AC_EGREP_CPP([MHDMARKER: UCRT run-time library in use!], [
  1086. #include <stdio.h>
  1087. #if defined(_UCRT)
  1088. #define CRT_STR "MHDMARKER: UCRT run-time library in use!"
  1089. #endif
  1090. #if defined(__MSVCRT_VERSION__)
  1091. #if (__MSVCRT_VERSION__ >= 0xE00) && (__MSVCRT_VERSION__ < 0x1000)
  1092. #define CRT_STR "MHDMARKER: UCRT run-time library in use!"
  1093. #endif
  1094. #if (__MSVCRT_VERSION__ > 0x1400)
  1095. #define CRT_STR "MHDMARKER: UCRT run-time library in use!"
  1096. #endif
  1097. #endif
  1098. #ifndef CRT_STR
  1099. #define CRT_STR "MHDMARKER: MSVCRT run-time library in use!"
  1100. #endif
  1101. int main(void)
  1102. {
  1103. printf ("%\n", CRT_STR);
  1104. return 0;
  1105. }
  1106. ],
  1107. [mhd_cv_wctr_type="ucrt"], [mhd_cv_wctr_type="msvcrt"])
  1108. ]
  1109. )
  1110. mhd_host_os="${mhd_host_os}-${mhd_cv_wctr_type}"
  1111. AS_VAR_IF([mhd_cv_wctr_type], ["msvcrt"],
  1112. [
  1113. # Use CFLAGS here to override user-supplied wrong CPPFLAGS. Durty trick, but choice is limited.
  1114. AX_APPEND_COMPILE_FLAGS([-U__USE_MINGW_ANSI_STDIO -D__USE_MINGW_ANSI_STDIO=0], [CFLAGS_ac])
  1115. AC_SUBST([W32CRT], [MSVCRT])
  1116. ], [AC_SUBST([W32CRT], [UCRT])]
  1117. )
  1118. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  1119. LDFLAGS="${user_LDFLAGS}"
  1120. AS_CASE([$mhd_w32_ver],
  1121. [WinXP],
  1122. [MHD_CHECK_ADD_CC_LDFLAG([-Wl,--major-subsystem-version,5,--minor-subsystem-version,1],[LDFLAGS_ac])],
  1123. [Vista],
  1124. [MHD_CHECK_ADD_CC_LDFLAG([-Wl,--major-subsystem-version,6,--minor-subsystem-version,0],[LDFLAGS_ac])]
  1125. )
  1126. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  1127. ]
  1128. )
  1129. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  1130. AC_ARG_WITH([threads],
  1131. [AS_HELP_STRING([--with-threads=LIB],[choose threading library (posix, w32, auto, none) [auto]])],
  1132. [], [with_threads='auto'])
  1133. AS_CASE([[$with_threads]],
  1134. [[win32]], [[with_threads='w32']],
  1135. [[pthreads]], [[with_threads='posix']],
  1136. [[posix]], [[:]],
  1137. [[w32]], [[:]],
  1138. [[none]], [[with_threads='none']],
  1139. [[no]], [[with_threads='none']],
  1140. [[auto]], [[:]],
  1141. [AC_MSG_ERROR([[incorrect parameter "$with_threads" specified for --with-threads]])]
  1142. )
  1143. # Check for posix threads support.
  1144. # As the testsuite uses only posix threads, the checks are required even
  1145. # if the library does not use posit threads.
  1146. AX_PTHREAD(
  1147. [
  1148. mhd_have_posix_threads='yes'
  1149. AC_DEFINE([[HAVE_PTHREAD_H]],[[1]],[Define to 1 if you have the <pthread.h> header file.])
  1150. CFLAGS="${CFLAGS_ac} ${PTHREAD_CFLAGS} ${user_CFLAGS}"
  1151. MHD_CHECK_FUNC([pthread_sigmask],
  1152. [[
  1153. #include <pthread.h>
  1154. #include <signal.h>
  1155. ]],
  1156. [[
  1157. sigset_t nset, oset;
  1158. sigemptyset (&nset);
  1159. sigaddset (&nset, SIGPIPE);
  1160. i][f (0 != pthread_sigmask(SIG_BLOCK, &nset, &oset)) return 1;
  1161. ]],
  1162. [AC_DEFINE([[HAVE_PTHREAD_SIGMASK]],[[1]],[Define to 1 if you have the pthread_sigmask(3) function.])]
  1163. )
  1164. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  1165. ],[[mhd_have_posix_threads='no']])
  1166. AM_CONDITIONAL([HAVE_POSIX_THREADS],[test "x$mhd_have_posix_threads" = "xyes"])
  1167. mhd_have_w32_threads='no'
  1168. AS_IF([[test "x$with_threads" = "xauto"]],
  1169. [
  1170. AS_IF([[test "x$os_is_windows" = "xyes"]],
  1171. [
  1172. AC_MSG_CHECKING([[for W32 threads]])
  1173. AC_LINK_IFELSE(
  1174. [AC_LANG_PROGRAM([[
  1175. #include <windows.h>
  1176. ]], [ HANDLE h = CreateThread(NULL, 0, NULL, NULL, 0, NULL);])]
  1177. , [[mhd_have_w32_threads='yes']], [[mhd_have_w32_threads='no']]
  1178. )
  1179. AC_MSG_RESULT([[$mhd_have_w32_threads]])
  1180. ])
  1181. ]
  1182. )
  1183. AC_MSG_CHECKING([[for threading lib to use with libmicrohttpd ($with_threads)]])
  1184. AS_IF([test "x$with_threads" = "xposix"],
  1185. [ # forced posix threads
  1186. AS_IF([test "x$mhd_have_posix_threads" = "xyes"], [USE_THREADS='posix'],
  1187. [ AS_IF([[test "x$os_is_windows" = "xyes"]] ,
  1188. [ AC_MSG_ERROR([[Posix threads are not available. Try to configure --with-threads=auto]])],
  1189. [ AC_MSG_ERROR([[No threading lib is available. Consider installing pthreads]])] )
  1190. ])
  1191. ])
  1192. AS_IF([test "x$with_threads" = "xw32"],
  1193. [ # forced w32 threads
  1194. AS_IF([[test "x$mhd_have_w32_threads" = "xyes"]],
  1195. [[ USE_THREADS='w32' ]],
  1196. [ AC_MSG_ERROR([[W32 threads are not available. Try to configure --with-threads=auto]])])
  1197. ])
  1198. AS_IF([test "x$with_threads" = "xauto"],
  1199. [# automatic threads lib selection
  1200. AS_IF([[test "x$os_is_native_w32" = "xyes" && test "x$mhd_have_w32_threads" = "xyes"]] ,
  1201. [[ USE_THREADS='w32' ]] ,
  1202. [[ test "x$mhd_have_posix_threads" = "xyes" ]], [[ USE_THREADS='posix' ]],
  1203. [[ test "x$mhd_have_w32_threads" = "xyes" ]], [[ USE_THREADS='w32' ]],
  1204. [ AC_MSG_ERROR([[No threading lib is available. Consider installing pthreads]]) ]
  1205. )])
  1206. AS_IF([test "x$with_threads" = "xnone"],
  1207. [USE_THREADS='none'])
  1208. AS_IF([test "x$USE_THREADS" = "xposix"],
  1209. [CC="$PTHREAD_CC"
  1210. AC_DEFINE([MHD_USE_POSIX_THREADS],[1],[define to use pthreads])
  1211. MHD_LIB_CFLAGS="$MHD_LIB_CFLAGS $PTHREAD_CFLAGS"
  1212. MHD_LIBDEPS="$PTHREAD_LIBS $MHD_LIBDEPS"
  1213. MHD_LIBDEPS_PKGCFG="$PTHREAD_LIBS $MHD_LIBDEPS_PKGCFG"],
  1214. [AS_IF([test "x$USE_THREADS" = "xw32"],
  1215. [AC_DEFINE([MHD_USE_W32_THREADS],[1],[define to use W32 threads])])])
  1216. AM_CONDITIONAL([USE_POSIX_THREADS], [test "x$USE_THREADS" = "xposix"])
  1217. AM_CONDITIONAL([USE_W32_THREADS], [test "x$USE_THREADS" = "xw32"])
  1218. AM_CONDITIONAL([USE_THREADS], [test "x$USE_THREADS" != "xnone"])
  1219. AM_CONDITIONAL([DISABLE_THREADS], [test "x$USE_THREADS" = "xnone"])
  1220. AC_MSG_RESULT([$USE_THREADS])
  1221. AC_ARG_ENABLE([[thread-names]],
  1222. [AS_HELP_STRING([--disable-thread-names],[do not set names on MHD generated threads [auto]])],
  1223. [], [enable_thread_names='auto'])
  1224. AS_IF([test "x$enable_thread_names" != "xno" && test "x$USE_THREADS" = "xposix"],[
  1225. # Check for thread name function
  1226. HAVE_THREAD_NAME_FUNC="no"
  1227. SAVE_LIBS="$LIBS"
  1228. LIBS="$PTHREAD_LIBS $LIBS"
  1229. CFLAGS="${CFLAGS_ac} $PTHREAD_CFLAGS ${user_CFLAGS}"
  1230. AC_CHECK_HEADERS([pthread_np.h],[],[],
  1231. [
  1232. AC_INCLUDES_DEFAULT
  1233. [
  1234. #include <pthread.h>
  1235. ]
  1236. ])
  1237. # Try to find how to set thread name by thread attributes.
  1238. # If pthread_attr_setname_np(3) is not declared, it's not possible to detect
  1239. # form of pthread_attr_setname_np(3) due to C "feature" "implicit declaration".
  1240. AC_CHECK_DECL([[pthread_attr_setname_np]],[],[],[[
  1241. #include <pthread.h>
  1242. #ifdef HAVE_PTHREAD_NP_H
  1243. #include <pthread_np.h>
  1244. #endif
  1245. ]])
  1246. AS_IF([[test "x$ac_cv_have_decl_pthread_attr_setname_np" = "xyes"]],
  1247. [AC_MSG_CHECKING([[for pthread_attr_setname_np(3) in NetBSD or OSF1 form]])
  1248. AC_LINK_IFELSE(
  1249. [AC_LANG_PROGRAM([[
  1250. #include <pthread.h>
  1251. #ifdef HAVE_PTHREAD_NP_H
  1252. #include <pthread_np.h>
  1253. #endif
  1254. ]], [[
  1255. pthread_attr_t thr_attr;
  1256. pthread_attr_init(&thr_attr);
  1257. pthread_attr_setname_np(&thr_attr, "name", 0);
  1258. pthread_attr_destroy(&thr_attr);
  1259. ]])],
  1260. [AC_DEFINE([[HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD]], [[1]], [Define if you have NetBSD form (or OSF1 form) of pthread_attr_setname_np(3) function.])
  1261. HAVE_THREAD_NAME_FUNC="yes"
  1262. AC_MSG_RESULT([[yes]])],
  1263. [AC_MSG_RESULT([[no]])]
  1264. )
  1265. ])
  1266. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_attr_setname_np" = "xyes"]],
  1267. [AC_MSG_CHECKING([[for pthread_attr_setname_np(3) in IBM i or Solaris form]])
  1268. AC_LINK_IFELSE(
  1269. [AC_LANG_PROGRAM([[
  1270. #include <pthread.h>
  1271. #ifdef HAVE_PTHREAD_NP_H
  1272. #include <pthread_np.h>
  1273. #endif
  1274. ]], [[
  1275. pthread_attr_t thr_attr;
  1276. pthread_attr_init(&thr_attr);
  1277. pthread_attr_setname_np(&thr_attr, "name");
  1278. pthread_attr_destroy(&thr_attr);
  1279. ]])],
  1280. [AC_DEFINE([[HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI]], [[1]], [Define if you have IBM i form (or Solaris form) of pthread_attr_setname_np(3) function.])
  1281. HAVE_THREAD_NAME_FUNC="yes"
  1282. AC_MSG_RESULT([[yes]])],
  1283. [AC_MSG_RESULT([[no]])]
  1284. )
  1285. ])
  1286. # Try to find how to set thread name for started thread - less convenient
  1287. # than setting name by attributes.
  1288. # If pthread_setname_np(3) is not declared, it's not possible to detect
  1289. # form of pthread_setname_np(3) due to C "feature" "implicit declaration".
  1290. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes"]],
  1291. [AC_CHECK_DECL([[pthread_setname_np]],[],[],[[
  1292. #include <pthread.h>
  1293. #ifdef HAVE_PTHREAD_NP_H
  1294. #include <pthread_np.h>
  1295. #endif
  1296. ]])
  1297. ])
  1298. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]],
  1299. [AC_MSG_CHECKING([[for pthread_setname_np(3) in NetBSD or OSF1 form]])
  1300. AC_LINK_IFELSE(
  1301. [AC_LANG_PROGRAM([[
  1302. #include <pthread.h>
  1303. #ifdef HAVE_PTHREAD_NP_H
  1304. #include <pthread_np.h>
  1305. #endif
  1306. ]], [[int res = pthread_setname_np(pthread_self(), "name", 0); if (res) return res;]])],
  1307. [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_NETBSD]], [[1]], [Define if you have NetBSD form (or OSF1 form) of pthread_setname_np(3) function.])
  1308. HAVE_THREAD_NAME_FUNC="yes"
  1309. AC_MSG_RESULT([[yes]])],
  1310. [AC_MSG_RESULT([[no]])]
  1311. )
  1312. ])
  1313. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]],
  1314. [AC_MSG_CHECKING([[for pthread_setname_np(3) in GNU/Linux form]])
  1315. AC_LINK_IFELSE(
  1316. [AC_LANG_PROGRAM([[
  1317. #include <pthread.h>
  1318. #ifdef HAVE_PTHREAD_NP_H
  1319. #include <pthread_np.h>
  1320. #endif
  1321. ]], [[int res = pthread_setname_np(pthread_self(), "name"); if (res) return res;]])],
  1322. [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_GNU]], [[1]], [Define if you have GNU/Linux form of pthread_setname_np(3) function.])
  1323. HAVE_THREAD_NAME_FUNC="yes"
  1324. AC_MSG_RESULT([[yes]])],
  1325. [AC_MSG_RESULT([[no]])]
  1326. )
  1327. ])
  1328. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]],
  1329. [AC_MSG_CHECKING([[for pthread_setname_np(3) in Darwin form]])
  1330. AC_LINK_IFELSE(
  1331. [AC_LANG_PROGRAM([[
  1332. #include <pthread.h>
  1333. #ifdef HAVE_PTHREAD_NP_H
  1334. #include <pthread_np.h>
  1335. #endif
  1336. ]], [[int res = pthread_setname_np("name"); if (res) return res;]])],
  1337. [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_DARWIN]], [[1]], [Define if you have Darwin form of pthread_setname_np(3) function.])
  1338. HAVE_THREAD_NAME_FUNC="yes"
  1339. AC_MSG_RESULT([[yes]])],
  1340. [AC_MSG_RESULT([[no]])]
  1341. )
  1342. ])
  1343. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes"]],
  1344. [
  1345. AC_CHECK_DECL([[pthread_set_name_np]],
  1346. [
  1347. AC_MSG_CHECKING([[for pthread_set_name_np(3) in FreeBSD form]])
  1348. AC_LINK_IFELSE(
  1349. [AC_LANG_PROGRAM([[
  1350. #include <pthread.h>
  1351. #ifdef HAVE_PTHREAD_NP_H
  1352. #include <pthread_np.h>
  1353. #endif
  1354. ]], [[pthread_set_name_np(pthread_self(), "name");]])],
  1355. [AC_DEFINE([[HAVE_PTHREAD_SET_NAME_NP_FREEBSD]], [[1]], [Define if you have FreeBSD form of pthread_set_name_np(3) function.])
  1356. HAVE_THREAD_NAME_FUNC="yes"
  1357. AC_MSG_RESULT([[yes]])],
  1358. [AC_MSG_RESULT([[no]])]
  1359. )
  1360. ],[],[[
  1361. #include <pthread.h>
  1362. #ifdef HAVE_PTHREAD_NP_H
  1363. #include <pthread_np.h>
  1364. #endif
  1365. ]]
  1366. )
  1367. ])
  1368. LIBS="$SAVE_LIBS"
  1369. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  1370. ])
  1371. AS_IF([[test "x$enable_thread_names" != "xno"]],
  1372. [
  1373. AC_MSG_CHECKING([[whether to enable thread names]])
  1374. AC_COMPILE_IFELSE(
  1375. [AC_LANG_PROGRAM([], [[
  1376. #ifdef MHD_NO_THREAD_NAMES
  1377. #error Thread names are disabled.
  1378. choke me
  1379. #endif
  1380. /* Keep in sync with mhd_threads.h */
  1381. #if defined(MHD_USE_POSIX_THREADS) && (defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) || \
  1382. defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || \
  1383. defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) )
  1384. (void) 0; /* no-op */
  1385. #elif defined(MHD_USE_W32_THREADS) && defined(_MSC_FULL_VER)
  1386. (void) 0; /* no-op */
  1387. #else
  1388. #error No thread name function is available.
  1389. choke me
  1390. #endif
  1391. ]])
  1392. ], [
  1393. enable_thread_names='yes'
  1394. ], [
  1395. AS_IF([[test "x$enable_thread_names" = "xyes"]],
  1396. [
  1397. AC_MSG_RESULT([[no]])
  1398. AC_MSG_ERROR([[thread names was explicitly requested, but thread name function is not available]])
  1399. ])
  1400. enable_thread_names='no'
  1401. ])
  1402. AC_MSG_RESULT([[$enable_thread_names]])
  1403. ])
  1404. AS_IF([[test "x$enable_thread_names" = "xno"]],
  1405. [AC_DEFINE([[MHD_NO_THREAD_NAMES]], [[1]], [Define to 1 to disable setting name on generated threads])])
  1406. AM_CONDITIONAL(HAVE_W32, [test "x$os_is_native_w32" = "xyes"])
  1407. w32_shared_lib_exp=no
  1408. AS_IF([test "x$enable_shared" = "xyes" && test "x$os_is_native_w32" = "xyes"],
  1409. [
  1410. AS_IF([test "x$ac_cv_use_ms_lib_tool" = "xyes" || test -n "$DLLTOOL"],
  1411. [
  1412. w32_shared_lib_exp=yes
  1413. use_expfile="no"
  1414. AS_VAR_IF([ac_cv_use_ms_lib_tool], ["yes"], [use_expfile="yes"],
  1415. [
  1416. AC_CACHE_CHECK([whether $DLLTOOL supports export file generation], [mhd_cv_dlltool_expfile],
  1417. [
  1418. AS_IF([AC_RUN_LOG([$DLLTOOL -e conftest.exp >&2 ])],
  1419. [
  1420. AS_IF([test -f conftest.exp], [mhd_cv_dlltool_expfile="yes"], [mhd_cv_dlltool_expfile="no"])
  1421. ], [mhd_cv_dlltool_expfile="no"]
  1422. )
  1423. rm -f conftest.exp
  1424. ]
  1425. )
  1426. use_expfile="${mhd_cv_dlltool_expfile}"
  1427. ]
  1428. )
  1429. ],
  1430. [
  1431. AC_MSG_WARN([[GNU dlltool or MS lib.exe is required for creating shared library export on W32]])
  1432. AC_MSG_WARN([[Export library libmicrohttpd.lib will not be created]])
  1433. ]
  1434. )
  1435. ]
  1436. )
  1437. AM_CONDITIONAL([W32_SHARED_LIB_EXP], [test "x$w32_shared_lib_exp" = "xyes"])
  1438. AM_CONDITIONAL([USE_MS_LIB_TOOL], [test "x$ac_cv_use_ms_lib_tool" = "xyes"])
  1439. AM_CONDITIONAL([USE_EXPORT_FILE], [test "x$use_expfile" = "xyes"])
  1440. dnl gethostbyname() is not really needed
  1441. dnl AC_SEARCH_LIBS([gethostbyname], [nsl])
  1442. MHD_FIND_LIB([socket],
  1443. [[
  1444. #ifdef HAVE_SYS_TYPES_H
  1445. #include <sys/types.h>
  1446. #endif
  1447. #ifdef HAVE_SYS_SOCKET_H
  1448. #include <sys/socket.h>
  1449. #endif
  1450. #ifdef HAVE_SOCKLIB_H
  1451. #include <sockLib.h>
  1452. #endif
  1453. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1454. #include <winsock2.h>
  1455. #endif
  1456. ]],
  1457. [(void)socket(0, 0, 0);],
  1458. [socket ws2_32 xnet],
  1459. [
  1460. AS_VAR_IF([[mhd_cv_find_lib_socket]],[["none required"]], [],
  1461. [
  1462. MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_socket} $MHD_LIBDEPS_PKGCFG"
  1463. ]
  1464. )
  1465. ],
  1466. [AC_MSG_ERROR([[cannot find header or library required for function socket()]])]
  1467. )
  1468. MHD_CHECK_SOCKET_SHUTDOWN_TRIGGER([AC_DEFINE([HAVE_LISTEN_SHUTDOWN],[1],[can use shutdown on listen sockets])])
  1469. AM_CONDITIONAL([HAVE_LISTEN_SHUTDOWN], [test "x$mhd_cv_host_shtdwn_trgr_select" = "xyes"])
  1470. AC_CACHE_CHECK([fo][r system default FD_SETSIZE value],[mhd_cv_sys_fd_setsize_value],
  1471. [
  1472. CFLAGS="${CFLAGS_ac} ${user_CFLAGS} -UFD_SETSIZE"
  1473. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS} -UFD_SETSIZE"
  1474. AC_COMPUTE_INT([mhd_cv_sys_fd_setsize_value],[FD_SETSIZE],dnl
  1475. [[
  1476. #ifdef HAVE_SYS_TIME_H
  1477. #include <sys/time.h>
  1478. #endif
  1479. #ifdef HAVE_SYS_TYPES_H
  1480. #include <sys/types.h>
  1481. #endif
  1482. #ifdef HAVE_UNISTD_H
  1483. #include <unistd.h>
  1484. #endif
  1485. #ifdef HAVE_SYS_SOCKET_H
  1486. #include <sys/socket.h>
  1487. #endif
  1488. #ifdef HAVE_SOCKLIB_H
  1489. #include <sockLib.h>
  1490. #endif
  1491. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1492. #include <winsock2.h>
  1493. #endif
  1494. #ifdef HAVE_SYS_SELECT_H
  1495. #include <sys/select.h>
  1496. #endif
  1497. ]], [mhd_cv_sys_fd_setsize_value="unknown"]
  1498. )
  1499. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  1500. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  1501. AS_IF([test "x${mhd_cv_sys_fd_setsize_value}" != "xunknown" && \
  1502. test "${mhd_cv_sys_fd_setsize_value}" -eq "0" \
  1503. ], [mhd_cv_sys_fd_setsize_value="unknown"]
  1504. )
  1505. ]
  1506. )
  1507. AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"],[:],
  1508. [
  1509. AC_DEFINE_UNQUOTED([MHD_SYS_FD_SETSIZE_],[${mhd_cv_sys_fd_setsize_value}],
  1510. [Define to system default value of FD_SETSIZE macro]
  1511. )
  1512. ]
  1513. )
  1514. AM_CONDITIONAL([NEED_SYS_FD_SET_SIZE_VALUE],[test "x${mhd_cv_sys_fd_setsize_value}" = "xunknown"])
  1515. AC_CACHE_CHECK([fo][r current FD_SETSIZE value],[mhd_cv_fd_setsize_value],
  1516. [
  1517. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  1518. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  1519. AS_IF([test "x${cross_compiling}" != "xno" && test "x${mhd_cv_sys_fd_setsize_value}" != "xunknown"],
  1520. [
  1521. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  1522. [[
  1523. #ifdef HAVE_SYS_TIME_H
  1524. #include <sys/time.h>
  1525. #endif
  1526. #ifdef HAVE_SYS_TYPES_H
  1527. #include <sys/types.h>
  1528. #endif
  1529. #ifdef HAVE_UNISTD_H
  1530. #include <unistd.h>
  1531. #endif
  1532. #ifdef HAVE_SYS_SOCKET_H
  1533. #include <sys/socket.h>
  1534. #endif
  1535. #ifdef HAVE_SOCKLIB_H
  1536. #include <sockLib.h>
  1537. #endif
  1538. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1539. #include <winsock2.h>
  1540. #endif
  1541. #ifdef HAVE_SYS_SELECT_H
  1542. #include <sys/select.h>
  1543. #endif
  1544. #define DETECTED_FD_SETZIE_VALUE ${mhd_cv_sys_fd_setsize_value}
  1545. #if (FD_SETSIZE) != (DETECTED_FD_SETZIE_VALUE)
  1546. #error The current default FD_SETSIZE value is different from ${mhd_cv_sys_fd_setsize_value}
  1547. choke me here now
  1548. #endif /* (FD_SETSIZE) != (DETECTED_FD_SETZIE_VALUE) */
  1549. #if (FD_SETSIZE) != (${mhd_cv_sys_fd_setsize_value})
  1550. #error The current default FD_SETSIZE value is different from ${mhd_cv_sys_fd_setsize_value}
  1551. choke me here now
  1552. #endif /* (FD_SETSIZE) != (${mhd_cv_sys_fd_setsize_value}) */
  1553. ]],[]
  1554. )
  1555. ],
  1556. [mhd_cv_fd_setsize_value="${mhd_cv_sys_fd_setsize_value}"]
  1557. )
  1558. ]
  1559. )
  1560. AS_VAR_SET_IF([mhd_cv_fd_setsize_value],[:],
  1561. [
  1562. AC_COMPUTE_INT([mhd_cv_fd_setsize_value],[FD_SETSIZE],dnl
  1563. [[
  1564. #ifdef HAVE_SYS_TIME_H
  1565. #include <sys/time.h>
  1566. #endif
  1567. #ifdef HAVE_SYS_TYPES_H
  1568. #include <sys/types.h>
  1569. #endif
  1570. #ifdef HAVE_UNISTD_H
  1571. #include <unistd.h>
  1572. #endif
  1573. #ifdef HAVE_SYS_SOCKET_H
  1574. #include <sys/socket.h>
  1575. #endif
  1576. #ifdef HAVE_SOCKLIB_H
  1577. #include <sockLib.h>
  1578. #endif
  1579. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1580. #include <winsock2.h>
  1581. #endif
  1582. #ifdef HAVE_SYS_SELECT_H
  1583. #include <sys/select.h>
  1584. #endif
  1585. ]], [mhd_cv_fd_setsize_value="unknown"]
  1586. )
  1587. ]
  1588. )
  1589. AS_IF([test "x${mhd_cv_fd_setsize_value}" != "xunknown" && \
  1590. test "${mhd_cv_fd_setsize_value}" -eq "0"],
  1591. [mhd_cv_fd_setsize_value="unknown"]
  1592. )
  1593. ]
  1594. )
  1595. AC_CACHE_CHECK([whether FD_SETSIZE is overridable],[mhd_cv_fd_setsize_overridable],
  1596. [
  1597. AS_VAR_IF([mhd_cv_fd_setsize_value],["unknown"],
  1598. [
  1599. AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"],
  1600. [
  1601. # Assume the most popular FD_SETSIZE value
  1602. base_fd_setsize=1024
  1603. ],
  1604. [base_fd_setsize="${mhd_cv_sys_fd_setsize_value}"]
  1605. )
  1606. base_min_fd_setsize="${base_fd_setsize}"
  1607. ],
  1608. [
  1609. AS_VAR_IF([mhd_cv_sys_fd_setsize_value],["unknown"],
  1610. [
  1611. base_fd_setsize="${mhd_cv_fd_setsize_value}"
  1612. base_min_fd_setsize="${base_fd_setsize}"
  1613. ],
  1614. [
  1615. AS_IF([test "${mhd_cv_fd_setsize_value}" -ge "${mhd_cv_sys_fd_setsize_value}"],
  1616. [
  1617. base_fd_setsize="${mhd_cv_fd_setsize_value}"
  1618. base_min_fd_setsize="${mhd_cv_sys_fd_setsize_value}"
  1619. ],
  1620. [
  1621. base_fd_setsize="${mhd_cv_sys_fd_setsize_value}"
  1622. base_min_fd_setsize="${mhd_cv_fd_setsize_value}"
  1623. ]
  1624. )
  1625. ]
  1626. )
  1627. ]
  1628. )
  1629. # Use two times larger FD_SETSIZE value for test
  1630. AS_VAR_ARITH([test_fd_setsize],[${base_fd_setsize} '+' ${base_fd_setsize}])
  1631. AS_IF([test "${test_fd_setsize}" -lt "128"],[test_fd_setsize=128])
  1632. test_type_fd_setsize="larger"
  1633. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  1634. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  1635. _AS_ECHO_LOG([testing whether FD_SETSIZE test value (${test_fd_setsize}) is suitable for 'int' type])
  1636. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],
  1637. [[
  1638. static int test_arr1[(((long long)${test_fd_setsize}) != ((int)${test_fd_setsize})) ? -1 : 1];
  1639. static int test_arr2[(0 > ((int)${test_fd_setsize})) ? -1 : 1];
  1640. test_arr1[0] = 0;
  1641. test_arr2[0] = 0;
  1642. i][f (test_arr1[0] != test_arr2[0]) return 1;
  1643. ]]
  1644. )
  1645. ],[],
  1646. [
  1647. _AS_ECHO_LOG([The selected test FD_SETSIZE value (${test_fd_setsize}) is too large for 'int' type])
  1648. AS_VAR_ARITH([test_fd_setsize],[${base_min_fd_setsize} '/' '2'])
  1649. test_type_fd_setsize="smaller"
  1650. ]
  1651. )
  1652. _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE value])
  1653. AS_IF([test "x${cross_compiling}" = "xno" && test "x${test_type_fd_setsize}" = "xlarger"],
  1654. [
  1655. _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE value with run test])
  1656. AC_RUN_IFELSE(
  1657. [
  1658. AC_LANG_SOURCE(
  1659. [[
  1660. #ifdef FD_SETSIZE
  1661. #undef FD_SETSIZE
  1662. #endif /* FD_SETSIZE */
  1663. #define FD_SETSIZE ${test_fd_setsize}
  1664. #define MY_TEST_FD_SETSIZE ${test_fd_setsize}
  1665. #ifdef HAVE_SYS_TIME_H
  1666. #include <sys/time.h>
  1667. #endif
  1668. #ifdef HAVE_SYS_TYPES_H
  1669. #include <sys/types.h>
  1670. #endif
  1671. #ifdef HAVE_UNISTD_H
  1672. #include <unistd.h>
  1673. #endif
  1674. #ifdef HAVE_SYS_SOCKET_H
  1675. #include <sys/socket.h>
  1676. #endif
  1677. #ifdef HAVE_SOCKLIB_H
  1678. #include <sockLib.h>
  1679. #endif
  1680. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1681. #include <winsock2.h>
  1682. #define MHD_TEST_SOCKET_TYPE SOCKET
  1683. #else
  1684. #define MHD_TEST_SOCKET_TYPE int
  1685. #endif
  1686. #ifdef HAVE_SYS_SELECT_H
  1687. #include <sys/select.h>
  1688. #endif
  1689. #include <string.h>
  1690. #include <stdio.h>
  1691. /* Test fo][r mismatch by macro check */
  1692. #if (FD_SETSIZE) != (MY_TEST_FD_SETSIZE)
  1693. #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize}
  1694. choke me here now;
  1695. #endif /* (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) */
  1696. /* Additional test fo][r mismatch by macro check */
  1697. #if (FD_SETSIZE) != (${test_fd_setsize})
  1698. #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize}
  1699. choke me here now;
  1700. #endif /* (FD_SETSIZE) != (${test_fd_setsize}) */
  1701. static unsigned long var_fd_setsize_value = FD_SETSIZE;
  1702. static unsigned long var_my_test_fd_setsize_value = MY_TEST_FD_SETSIZE;
  1703. int main(void)
  1704. {
  1705. fd_set fds_num_one_copy;
  1706. fd_set fds_num_three_copy;
  1707. fd_set test_fdsets[6];
  1708. int i;
  1709. int ret = 0;
  1710. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1711. WSADATA wsa_data;
  1712. if (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data))
  1713. return 21;
  1714. if (MAKEWORD(2, 2) != wsa_data.wVersion)
  1715. {
  1716. WSACleanup();
  1717. return 22;
  1718. }
  1719. #endif /* _WIN32 && ! __CYGWIN__ */
  1720. /* Init with zeros to make sure that slack areas are equal */
  1721. memset(test_fdsets, 0, sizeof(test_fdsets));
  1722. /* Correctly init fd_sets */
  1723. for (i = 0; i < 6; ++i)
  1724. FD_ZERO(test_fdsets + i);
  1725. /* Make copies of zero-inited fd_sets */
  1726. memcpy(&fds_num_one_copy, test_fdsets + 1, sizeof(fd_set));
  1727. memcpy(&fds_num_three_copy, test_fdsets + 3, sizeof(fd_set));
  1728. if (var_fd_setsize_value != var_my_test_fd_setsize_value)
  1729. {
  1730. fprintf (stderr, "System headers redefined FD_SETSIZE to another value (%lu).\n",
  1731. (unsigned long) FD_SETSIZE);
  1732. ret = 2;
  1733. }
  1734. else
  1735. {
  1736. /* Set (almost) all FDs in test_fdset[2] */
  1737. for (i = 1; i < FD_SETSIZE; ++i)
  1738. FD_SET((MHD_TEST_SOCKET_TYPE)i, test_fdsets + 2);
  1739. if (! FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 2))
  1740. {
  1741. fprintf (stderr, "FD number one in original fd_set is unset, while should be set.\n");
  1742. ret |= 3;
  1743. }
  1744. if (! FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 2))
  1745. {
  1746. fprintf (stderr, "FD number %lu in original fd_set is unset, while should be set.\n",
  1747. (unsigned long) FD_SETSIZE);
  1748. ret |= 3;
  1749. }
  1750. if (FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 1))
  1751. {
  1752. fprintf (stderr, "FD number one in the first fd_set is unset, while should be set.\n");
  1753. ret |= 4;
  1754. }
  1755. if (FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 1))
  1756. {
  1757. fprintf (stderr, "FD number %lu in the first fd_set is unset, while should be set.\n",
  1758. (unsigned long) FD_SETSIZE);
  1759. ret |= 4;
  1760. }
  1761. if (0 != memcmp (&fds_num_one_copy, test_fdsets + 1, sizeof(fd_set)))
  1762. {
  1763. fprintf (stderr, "The first fd_set has been altered.\n");
  1764. ret |= 4;
  1765. }
  1766. if (FD_ISSET((MHD_TEST_SOCKET_TYPE)1, test_fdsets + 3))
  1767. {
  1768. fprintf (stderr, "FD number one in the third fd_set is unset, while should be set.\n");
  1769. ret |= 8;
  1770. }
  1771. if (FD_ISSET((MHD_TEST_SOCKET_TYPE)(FD_SETSIZE - 1), test_fdsets + 3))
  1772. {
  1773. fprintf (stderr, "FD number %lu in the third fd_set is unset, while should be set.\n",
  1774. (unsigned long) FD_SETSIZE);
  1775. ret |= 8;
  1776. }
  1777. if (0 != memcmp (&fds_num_three_copy, test_fdsets + 3, sizeof(fd_set)))
  1778. {
  1779. fprintf (stderr, "The third fd_set has been altered.\n");
  1780. ret |= 8;
  1781. }
  1782. }
  1783. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1784. WSACleanup();
  1785. #endif /* _WIN32 && ! __CYGWIN__ */
  1786. return ret;
  1787. }
  1788. ]]
  1789. )
  1790. ],
  1791. [mhd_cv_fd_setsize_overridable="yes"],
  1792. [mhd_cv_fd_setsize_overridable="no"],
  1793. [[# Not used when cross-compiling ]]
  1794. )
  1795. ],
  1796. [
  1797. _AS_ECHO_LOG([will try ${test_fd_setsize} as FD_SETSIZE with simple compile test])
  1798. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  1799. [[
  1800. #ifdef FD_SETSIZE
  1801. #undef FD_SETSIZE
  1802. #endif /* FD_SETSIZE */
  1803. #define FD_SETSIZE ${test_fd_setsize}
  1804. #define MY_TEST_FD_SETSIZE ${test_fd_setsize}
  1805. #ifdef HAVE_SYS_TIME_H
  1806. #include <sys/time.h>
  1807. #endif
  1808. #ifdef HAVE_SYS_TYPES_H
  1809. #include <sys/types.h>
  1810. #endif
  1811. #ifdef HAVE_UNISTD_H
  1812. #include <unistd.h>
  1813. #endif
  1814. #ifdef HAVE_SYS_SOCKET_H
  1815. #include <sys/socket.h>
  1816. #endif
  1817. #ifdef HAVE_SOCKLIB_H
  1818. #include <sockLib.h>
  1819. #endif
  1820. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1821. #include <winsock2.h>
  1822. #endif
  1823. #ifdef HAVE_SYS_SELECT_H
  1824. #include <sys/select.h>
  1825. #endif
  1826. /* Test fo][r mismatch by macro check */
  1827. #if (FD_SETSIZE) != (MY_TEST_FD_SETSIZE)
  1828. #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize}
  1829. choke me here now
  1830. #endif /* (FD_SETSIZE) != (MY_TEST_FD_SETSIZE) */
  1831. /* Additional test fo][r mismatch by macro check */
  1832. #if (FD_SETSIZE) != (${test_fd_setsize})
  1833. #error System headers ignore custom FD_SETSIZE value, FD_SETSIZE is NOT ${test_fd_setsize}
  1834. choke me here now
  1835. #endif /* (FD_SETSIZE) != (${test_fd_setsize}) */
  1836. ]],[]
  1837. )
  1838. ],
  1839. [
  1840. _AS_ECHO_LOG([comple test succeed, will check whether another FD_SETSIZE value changes the size of 'fd_set'])
  1841. # Check current size of fd_set
  1842. _AS_ECHO_LOG([find the sizeof(fd_setsize) with current default (${mhd_cv_fd_setsize_value}) FD_SETSIZE value])
  1843. AC_COMPUTE_INT([sizeof_cur_fd_set],[sizeof(fd_set)],dnl
  1844. [[
  1845. #ifdef HAVE_SYS_TIME_H
  1846. #include <sys/time.h>
  1847. #endif
  1848. #ifdef HAVE_SYS_TYPES_H
  1849. #include <sys/types.h>
  1850. #endif
  1851. #ifdef HAVE_UNISTD_H
  1852. #include <unistd.h>
  1853. #endif
  1854. #ifdef HAVE_SYS_SOCKET_H
  1855. #include <sys/socket.h>
  1856. #endif
  1857. #ifdef HAVE_SOCKLIB_H
  1858. #include <sockLib.h>
  1859. #endif
  1860. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1861. #include <winsock2.h>
  1862. #endif
  1863. #ifdef HAVE_SYS_SELECT_H
  1864. #include <sys/select.h>
  1865. #endif
  1866. ]], [sizeof_cur_fd_set="unknown"]
  1867. )
  1868. _AS_ECHO_LOG([the sizeof(fd_setsize) with current default (${mhd_cv_fd_setsize_value}) FD_SETSIZE value is ${sizeof_cur_fd_set}])
  1869. # Check the size of fd_set with redefined FD_SETSIZE
  1870. _AS_ECHO_LOG([find the sizeof(fd_setsize) with redefined (${test_fd_setsize}) FD_SETSIZE value])
  1871. AC_COMPUTE_INT([sizeof_mod_fd_set],[sizeof(fd_set)],dnl
  1872. [[
  1873. #ifdef FD_SETSIZE
  1874. #undef FD_SETSIZE
  1875. #endif /* FD_SETSIZE */
  1876. #define FD_SETSIZE ${test_fd_setsize}
  1877. #ifdef HAVE_SYS_TIME_H
  1878. #include <sys/time.h>
  1879. #endif
  1880. #ifdef HAVE_SYS_TYPES_H
  1881. #include <sys/types.h>
  1882. #endif
  1883. #ifdef HAVE_UNISTD_H
  1884. #include <unistd.h>
  1885. #endif
  1886. #ifdef HAVE_SYS_SOCKET_H
  1887. #include <sys/socket.h>
  1888. #endif
  1889. #ifdef HAVE_SOCKLIB_H
  1890. #include <sockLib.h>
  1891. #endif
  1892. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1893. #include <winsock2.h>
  1894. #endif
  1895. #ifdef HAVE_SYS_SELECT_H
  1896. #include <sys/select.h>
  1897. #endif
  1898. ]], [sizeof_mod_fd_set="unknown"]
  1899. )
  1900. _AS_ECHO_LOG([the sizeof(fd_setsize) with redefined (${test_fd_setsize}) FD_SETSIZE value is ${sizeof_mod_fd_set}])
  1901. _AS_ECHO_LOG([detected sizes of 'fd_set': '${sizeof_cur_fd_set}' (by default), '${sizeof_mod_fd_set}' with modified FD_SETSIZE])
  1902. AS_IF([test "x${sizeof_cur_fd_set}" != "x${sizeof_mod_fd_set}"],
  1903. [mhd_cv_fd_setsize_overridable="yes"],
  1904. [mhd_cv_fd_setsize_overridable="no"]
  1905. )
  1906. AS_UNSET([sizeof_mod_fd_set])
  1907. AS_UNSET([sizeof_cur_fd_set])
  1908. ],
  1909. [mhd_cv_fd_setsize_overridable="no"]
  1910. )
  1911. ]
  1912. )
  1913. AS_UNSET([test_type_fd_setsize])
  1914. AS_UNSET([test_fd_setsize])
  1915. AS_UNSET([base_min_fd_setsize])
  1916. AS_UNSET([base_fd_setsize])
  1917. ]
  1918. )
  1919. AS_VAR_IF([mhd_cv_fd_setsize_overridable],["no"],
  1920. [
  1921. AS_VAR_IF([os_is_native_w32],["yes"],
  1922. [AC_MSG_ERROR([Non-overridable FD_SETSIZE detected for native W32 build. FD_SETSIZE is overridable on W32.])]
  1923. )
  1924. AS_IF([test "x${mhd_cv_fd_setsize_value}" != "xunknown" && test "x${mhd_cv_sys_fd_setsize_value}" != "xunknown" && test "${mhd_cv_fd_setsize_value}" -ne "${mhd_cv_sys_fd_setsize_value}"],
  1925. [AC_MSG_WARN([Detected non-overridable FD_SETSIZE, but the toolchain uses FD_SETSIZE (${mhd_cv_fd_setsize_value}) different from system default (${mhd_cv_sys_fd_setsize_value})])]
  1926. )
  1927. ],
  1928. [AC_DEFINE([HAS_FD_SETSIZE_OVERRIDABLE],[1],[Define to 1 i][f your system allow overriding the value of FD_SETSIZE macro])]
  1929. )
  1930. AC_CACHE_CHECK([whether socket value is a signed type],[mhd_cv_socket_signed],
  1931. [
  1932. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  1933. #ifdef HAVE_SYS_TIME_H
  1934. #include <sys/time.h>
  1935. #endif
  1936. #ifdef HAVE_SYS_TYPES_H
  1937. #include <sys/types.h>
  1938. #endif
  1939. #ifdef HAVE_UNISTD_H
  1940. #include <unistd.h>
  1941. #endif
  1942. #ifdef HAVE_SYS_SOCKET_H
  1943. #include <sys/socket.h>
  1944. #endif
  1945. #ifdef HAVE_SOCKLIB_H
  1946. #include <sockLib.h>
  1947. #endif
  1948. #if defined(_WIN32) && ! defined(__CYGWIN__)
  1949. #include <winsock2.h>
  1950. #endif
  1951. #ifdef HAVE_SYS_SELECT_H
  1952. #include <sys/select.h>
  1953. #endif
  1954. /* Keep in sync with microhttpd.h */
  1955. #if ! defined(_WIN32) || defined(_SYS_TYPES_FD_SET)
  1956. typedef int MHD_socket;
  1957. #else /* defined(_WIN32) && ! defined(_SYS_TYPES_FD_SET) */
  1958. typedef SOCKET MHD_socket;
  1959. #endif /* defined(_WIN32) && ! defined(_SYS_TYPES_FD_SET) */
  1960. int main(void)
  1961. {
  1962. int test_arr[2 - 5*(!!(0 < ((MHD_socket)-1)))];
  1963. test_arr[1] = 0;
  1964. return test_arr[1];
  1965. }
  1966. ]]
  1967. )
  1968. ],
  1969. [mhd_cv_socket_signed="yes"],
  1970. [mhd_cv_socket_signed="no"]
  1971. )
  1972. ]
  1973. )
  1974. AS_VAR_IF([mhd_cv_socket_signed],["yes"],
  1975. [AC_DEFINE([HAS_SIGNED_SOCKET],[1],[Define to 1 i][f your socket type is signed])]
  1976. )
  1977. MHD_CHECK_FUNC([writev],
  1978. [[#include <sys/uio.h>]],
  1979. [[
  1980. struct iovec iov[2];
  1981. char some_str[4] = "OK\n";
  1982. iov[0].iov_base = (void *) some_str;
  1983. iov[0].iov_len = 3;
  1984. i][f (0 > writev(1, iov, 1))
  1985. return 2;
  1986. ]]
  1987. )
  1988. MHD_FIND_LIB([sendmsg],
  1989. [[
  1990. #ifdef HAVE_SYS_TYPES_H
  1991. #include <sys/types.h>
  1992. #endif
  1993. #ifdef HAVE_SYS_SOCKET_H
  1994. #include <sys/socket.h>
  1995. #endif
  1996. #ifdef HAVE_SOCKLIB_H
  1997. #include <sockLib.h>
  1998. #endif
  1999. #ifdef HAVE_SYS_UIO_H
  2000. #include <sys/uio.h>
  2001. #endif
  2002. ]],
  2003. [[
  2004. struct msghdr msg;
  2005. struct iovec iov;
  2006. unsigned int i;
  2007. char some_str[5] = "test";
  2008. iov.iov_base = (void*)some_str;
  2009. iov.iov_len = 4;
  2010. for (i = 0; i < (unsigned int) sizeof(msg); i++)
  2011. {
  2012. *(((unsigned char *)&msg) + i) = 0;
  2013. }
  2014. msg.msg_iov = &iov;
  2015. msg.msg_iovlen = 1;
  2016. i][f (0 > sendmsg(1, &msg, 0))
  2017. return -1;
  2018. ]],
  2019. [socket],
  2020. [
  2021. AC_DEFINE([HAVE_SENDMSG],[1],[Define to '1' if your have sendmsg() function])
  2022. AS_VAR_IF([[mhd_cv_find_lib_sendmsg]],[["none required"]], [],
  2023. [
  2024. MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_sendmsg} $MHD_LIBDEPS_PKGCFG"
  2025. ]
  2026. )
  2027. ],[],
  2028. [MHD_LIBDEPS]
  2029. )
  2030. AC_C_BIGENDIAN
  2031. AC_C_VARARRAYS
  2032. AC_CACHE_CHECK([[whether __func__ magic-macro is available]],
  2033. [[mhd_cv_macro___func___avail]], [dnl
  2034. AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __func__ ; if (!funcname) return 1;]])],
  2035. [[mhd_cv_macro___func___avail="yes"]],[[mhd_cv_macro___func___avail="no"]])
  2036. ])
  2037. AS_VAR_IF([mhd_cv_macro___func___avail], ["yes"],
  2038. [AC_DEFINE([HAVE___FUNC__], [1], [Define to 1 if your compiler supports __func__ magic-macro.])],
  2039. [
  2040. AC_CACHE_CHECK([[whether __FUNCTION__ magic-macro is available]],
  2041. [[mhd_cv_macro___function___avail]], [dnl
  2042. AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __FUNCTION__ ; if (!funcname) return 1;]])],
  2043. [[mhd_cv_macro___function___avail="yes"]],[[mhd_cv_macro___function___avail="no"]])
  2044. ])
  2045. AS_VAR_IF([mhd_cv_macro___function___avail], ["yes"],
  2046. [AC_DEFINE([HAVE___FUNCTION__], [1], [Define to 1 if your compiler supports __FUNCTION__ magic-macro.])],
  2047. [
  2048. AC_CACHE_CHECK([[whether __PRETTY_FUNCTION__ magic-macro is available]],
  2049. [[mhd_cv_macro___pretty_function___avail]], [dnl
  2050. AC_LINK_IFELSE([AC_LANG_PROGRAM([[]],[[const char *funcname = __PRETTY_FUNCTION__ ; if (!funcname) return 1;]])],
  2051. [[mhd_cv_macro___pretty_function___avail="yes"]],[[mhd_cv_macro___pretty_function___avail="no"]])
  2052. ])
  2053. AS_VAR_IF([mhd_cv_macro___pretty_function___avail], ["yes"],
  2054. [AC_DEFINE([HAVE___PRETTY_FUNCTION__], [1], [Define to 1 if your compiler supports __PRETTY_FUNCTION__ magic-macro.])],
  2055. )
  2056. ]
  2057. )
  2058. ]
  2059. )
  2060. AC_CACHE_CHECK([[whether __builtin_bswap32() is available]],
  2061. [[mhd_cv_func___builtin_bswap32_avail]], [dnl
  2062. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint32_t a = 1; uint32_t b = __builtin_bswap32(a); a = b; (void) a;]])],
  2063. [[mhd_cv_func___builtin_bswap32_avail="yes"]],[[mhd_cv_func___builtin_bswap32_avail="no"]])
  2064. ])
  2065. AS_IF([[test "x$mhd_cv_func___builtin_bswap32_avail" = "xyes"]],
  2066. [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP32]], [[1]], [Define to 1 if you have __builtin_bswap32() builtin function])])
  2067. AC_CACHE_CHECK([[whether __builtin_bswap64() is available]],
  2068. [[mhd_cv_func___builtin_bswap64_avail]], [dnl
  2069. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint64_t a = 1; uint64_t b = __builtin_bswap64(a); a = b; (void) a;]])],
  2070. [[mhd_cv_func___builtin_bswap64_avail="yes"]], [[mhd_cv_func___builtin_bswap64_avail="no"]])
  2071. ])
  2072. AS_IF([[test "x$mhd_cv_func___builtin_bswap64_avail" = "xyes"]],
  2073. [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP64]], [[1]], [Define to 1 if you have __builtin_bswap64() builtin function])])
  2074. AC_CHECK_PROG([HAVE_CURL_BINARY],[curl],[yes],[no])
  2075. AM_CONDITIONAL([HAVE_CURL_BINARY],[test "x$HAVE_CURL_BINARY" = "xyes"])
  2076. AC_CHECK_PROG([HAVE_MAKEINFO_BINARY],[makeinfo],[yes],[no])
  2077. AM_CONDITIONAL([HAVE_MAKEINFO_BINARY],[test "x$HAVE_MAKEINFO_BINARY" = "xyes"])
  2078. AM_CONDITIONAL(W32_STATIC_LIB, [test "x$os_is_native_w32" = "xyes" && test "x$enable_static" = "xyes"])
  2079. AC_ARG_ENABLE([[doc]],
  2080. [AS_HELP_STRING([[--disable-doc]], [do not build any documentation])], ,
  2081. [enable_doc=yes])
  2082. test "x$enable_doc" = "xno" || enable_doc=yes
  2083. AM_CONDITIONAL([BUILD_DOC], [test "x$enable_doc" = "xyes"])
  2084. AC_ARG_ENABLE([[examples]],
  2085. [AS_HELP_STRING([[--disable-examples]], [do not build any examples])], ,
  2086. [enable_examples=yes])
  2087. test "x$enable_examples" = "xno" || enable_examples=yes
  2088. AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" = "xyes"])
  2089. AC_ARG_ENABLE([[tools]],
  2090. [AS_HELP_STRING([[--disable-tools]], [do not build testing and demo tools])], ,
  2091. [enable_tools=yes])
  2092. test "x$enable_tools" = "xyes" || enable_tools=no
  2093. AM_CONDITIONAL([BUILD_TOOLS], [test "x$enable_tools" = "xyes"])
  2094. AC_ARG_ENABLE([[heavy-tests]],
  2095. [AS_HELP_STRING([[--enable-heavy-tests[=SCOPE]]], [use SCOPE of heavy tests in test-suite. WARNING:]
  2096. [a dedicated host with minimal number of background processes and no network]
  2097. [activity is recommended to enable. (basic, full)])], [],
  2098. [enable_heavy_tests=no])
  2099. use_heavy_tests="no"
  2100. use_vheavy_tests="no"
  2101. use_heavy_tests_MSG="no"
  2102. AS_CASE([${enable_heavy_tests}],
  2103. [yes|basic],
  2104. [
  2105. enable_heavy_tests="basic"
  2106. use_heavy_tests="yes"
  2107. use_vheavy_tests="no"
  2108. use_heavy_tests_MSG="yes, basic heavy tests (a dedicated host is recommended)"
  2109. ],
  2110. [all|full],
  2111. [
  2112. enable_heavy_tests="full"
  2113. use_heavy_tests="yes"
  2114. use_vheavy_tests="yes"
  2115. use_heavy_tests_MSG="yes, full set of heavy tests (a dedicated host is recommended)"
  2116. ],
  2117. [no],
  2118. [
  2119. use_heavy_tests="no"
  2120. use_vheavy_tests="no"
  2121. use_heavy_tests_MSG="no"
  2122. ],
  2123. [AC_MSG_ERROR([[Unknown parameter value: --enable-heavy-tests=${enable_heavy_tests}]])]
  2124. )
  2125. AS_VAR_IF([use_heavy_tests], ["yes"],
  2126. [
  2127. HEAVY_TESTS_NOTPARALLEL='.NOTPARALLEL:'
  2128. AC_DEFINE([_MHD_HEAVY_TESTS], [1], [Define to 1 to enable "heavy" test paths.])
  2129. AS_VAR_IF([use_vheavy_tests], ["yes"],
  2130. [AC_DEFINE([_MHD_VHEAVY_TESTS], [1], [Define to 1 to enable "very heavy" test paths.])]
  2131. )
  2132. ],
  2133. [
  2134. HEAVY_TESTS_NOTPARALLEL=" "
  2135. ]
  2136. )
  2137. AM_CONDITIONAL([HEAVY_TESTS],[test "x$use_heavy_tests" = "xyes"])
  2138. AM_CONDITIONAL([VHEAVY_TESTS],[test "x$use_vheavy_tests" = "xyes"])
  2139. AM_CONDITIONAL([TESTS_STRESS_OS],[false])
  2140. AC_ARG_ENABLE([[poll]],
  2141. [AS_HELP_STRING([[--enable-poll[=ARG]]], [enable poll support (yes, no, auto) [auto]])],
  2142. [enable_poll=${enableval}],
  2143. [enable_poll='auto']
  2144. )
  2145. AS_IF([test "$enable_poll" != "no"],
  2146. [
  2147. AS_IF([test "$os_is_native_w32" != "yes"],
  2148. [
  2149. AC_CHECK_HEADERS([poll.h],
  2150. [
  2151. MHD_CHECK_FUNC([poll],
  2152. [[
  2153. #include <poll.h>
  2154. ]],
  2155. [[
  2156. struct pollfd fds[2];
  2157. fds[0].fd = 0;
  2158. fds[0].events = POLLIN;
  2159. if (0 > poll(fds, 1, 0))
  2160. return 2;
  2161. ]],
  2162. [have_poll='yes'], [have_poll='no']
  2163. )
  2164. ], [], [AC_INCLUDES_DEFAULT]
  2165. )
  2166. ],
  2167. [
  2168. MHD_CHECK_FUNC([WSAPoll],
  2169. [[
  2170. #include <winsock2.h>
  2171. ]],
  2172. [[
  2173. WSAPOLLFD fda[2];
  2174. WSAPoll(fda, 2, 0);
  2175. ]],
  2176. [
  2177. have_poll='yes'
  2178. AC_DEFINE([HAVE_POLL],[1])
  2179. ],
  2180. [have_poll='no']
  2181. )
  2182. ]
  2183. )
  2184. AS_IF([test "$enable_poll" = "yes" && test "$have_poll" != "yes"],
  2185. [AC_MSG_ERROR([[Support for poll was explicitly requested but cannot be enabled on this platform.]])])
  2186. enable_poll="$have_poll"
  2187. ]
  2188. )
  2189. AC_ARG_ENABLE([[epoll]],
  2190. [AS_HELP_STRING([[--enable-epoll[=ARG]]], [enable epoll support (yes, no, auto) [auto]])],
  2191. [enable_epoll=${enableval}],
  2192. [enable_epoll='auto']
  2193. )
  2194. AS_IF([test "$enable_epoll" != "no"],
  2195. [
  2196. MHD_CHECK_FUNC_RUN([epoll_create],
  2197. [[
  2198. #include <sys/epoll.h>
  2199. #include <unistd.h>
  2200. ]],
  2201. [[
  2202. int epfd = epoll_create(64);
  2203. i][f (0 > epfd) return -epfd;
  2204. (void) close(epfd);
  2205. return 0;
  2206. ]],
  2207. [cacheVar="assuming yes"],
  2208. [
  2209. AC_DEFINE([[EPOLL_SUPPORT]],[[1]],[Define to 1 to enable epoll support])
  2210. enable_epoll='yes'
  2211. ],
  2212. [
  2213. AS_IF([test "$enable_epoll" = "yes"],
  2214. [AC_MSG_ERROR([[Support for epoll was explicitly requested but cannot be enabled on this platform.]])]
  2215. )
  2216. enable_epoll='no'
  2217. ]
  2218. )
  2219. AS_UNSET([warn_msg])
  2220. AS_VAR_IF([mhd_cv_works_func_epoll_create],["assuming yes"],
  2221. [[warn_msg="When cross-compiling it is not possible to check whether 'epoll_create()' really works on the host (final) platform.
  2222. 'epoll' is enabled as most probably the host kernel supports it (CONFIG_EPOLL option enabled in case of Linux kernel).
  2223. Use './configure mhd_cv_works_func_epoll_create=yes' to mute this warning."]]
  2224. )
  2225. AS_VAR_SET_IF([warn_msg],[AC_MSG_WARN([$warn_msg])
  2226. AS_IF([test -n "${CONF_FINAL_WARNS}" ],
  2227. [
  2228. CONF_FINAL_WARNS="${CONF_FINAL_WARNS}
  2229. WARNING: "
  2230. ]
  2231. )
  2232. CONF_FINAL_WARNS="${CONF_FINAL_WARNS}${warn_msg}"
  2233. ]
  2234. )
  2235. ]
  2236. )
  2237. AM_CONDITIONAL([MHD_HAVE_EPOLL], [[test "x$enable_epoll" = xyes]])
  2238. AS_IF([test "x$enable_epoll" = "xyes"],
  2239. [
  2240. MHD_CHECK_FUNC([epoll_create1],
  2241. [[
  2242. #include <sys/epoll.h>
  2243. ]],
  2244. [[
  2245. i][f (0 > epoll_create1(EPOLL_CLOEXEC))
  2246. return 3;
  2247. ]]
  2248. )
  2249. ]
  2250. )
  2251. AC_CACHE_CHECK([for supported 'noreturn' keyword], [mhd_cv_decl_noreturn],
  2252. [
  2253. mhd_cv_decl_noreturn="none"
  2254. CFLAGS="${CFLAGS_ac} ${user_CFLAGS} ${errattr_CFLAGS}"
  2255. MHD_SAVED_ac_c_werror_flag="$ac_c_werror_flag"
  2256. ac_c_werror_flag=yes
  2257. for decl_noret in ['[[noreturn]]'] '_Noreturn' '__attribute__((__noreturn__))' '__declspec(noreturn)'
  2258. do
  2259. AC_LINK_IFELSE([AC_LANG_SOURCE(
  2260. [[
  2261. #ifdef HAVE_STDLIB_H
  2262. #include <stdlib.h>
  2263. #endif
  2264. ${decl_noret} static void myexitfunc(int code)
  2265. {
  2266. #ifdef HAVE_STDLIB_H
  2267. exit (code);
  2268. #else
  2269. (void)code;
  2270. #endif
  2271. }
  2272. int main (int argc, char *const *argv)
  2273. {
  2274. (void) argv;
  2275. if (argc > 2)
  2276. myexitfunc (2);
  2277. return 0;
  2278. }
  2279. ]]
  2280. )], [mhd_cv_decl_noreturn="${decl_noret}"]
  2281. )
  2282. AS_IF([test "x${mhd_cv_decl_noreturn}" != "xnone"], [break])
  2283. done
  2284. ac_c_werror_flag="$MHD_SAVED_ac_c_werror_flag"
  2285. AS_UNSET([MHD_SAVED_ac_c_werror_flag])
  2286. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  2287. ]
  2288. )
  2289. AS_VAR_IF([mhd_cv_decl_noreturn], ["none"],
  2290. [AC_DEFINE([_MHD_NORETURN], [], [Define to supported 'noreturn' function declaration])],
  2291. [AC_DEFINE_UNQUOTED([_MHD_NORETURN], [${mhd_cv_decl_noreturn}], [Define to supported 'noreturn' function declaration])]
  2292. )
  2293. # Check for types sizes
  2294. # Types sizes are used as an indirect indication of maximum allowed values for types
  2295. # which is used to exclude by preprocessor some compiler checks for values clips
  2296. # Assuming no staffing or uniform staffing for integer types
  2297. AC_CACHE_CHECK([size of tv_sec member of struct timeval], [mhd_cv_size_timeval_tv_sec],
  2298. [
  2299. AC_COMPUTE_INT([mhd_cv_size_timeval_tv_sec], [((long int)sizeof(test_var.tv_sec))],
  2300. [[
  2301. #ifdef HAVE_SYS_TIME_H
  2302. #include <sys/time.h>
  2303. #endif /* HAVE_SYS_TIME_H */
  2304. #ifdef HAVE_TIME_H
  2305. #include <time.h>
  2306. #endif /* HAVE_TIME_H */
  2307. #if HAVE_SYS_TYPES_H
  2308. #include <sys/types.h>
  2309. #endif /* HAVE_SYS_TYPES_H */
  2310. extern struct timeval test_var; /* Declaration */
  2311. struct timeval test_var = {0, 0}; /* Definition */
  2312. ]],
  2313. [
  2314. # The size is used only to exclude additional checks/comparison in code
  2315. # to avoid compiler warnings. With larger size MHD code will use
  2316. # additional checks which ensure that value will fit but it may produce
  2317. # a harmless compiler warning.
  2318. AC_MSG_WARN([The size cannot be determined, assuming 8.])
  2319. mhd_cv_size_timeval_tv_sec=8
  2320. ]
  2321. )
  2322. ]
  2323. )
  2324. AC_DEFINE_UNQUOTED([SIZEOF_STRUCT_TIMEVAL_TV_SEC], [$mhd_cv_size_timeval_tv_sec],
  2325. [The size of `tv_sec' member of `struct timeval', as computed by sizeof])
  2326. AC_CHECK_SIZEOF([int64_t], [], [[#include <stdint.h>]])
  2327. AC_CHECK_SIZEOF([uint64_t], [], [[#include <stdint.h>]])
  2328. AC_CHECK_SIZEOF([int], [], [[#include <stdint.h>]])
  2329. AC_CHECK_SIZEOF([unsigned int], [], [[#include <stdint.h>]])
  2330. AC_CHECK_SIZEOF([unsigned long long], [], [[#include <stdint.h>]])
  2331. AC_CHECK_SIZEOF([size_t], [],
  2332. [[
  2333. #ifdef HAVE_STDLIB_H
  2334. #include <stdlib.h>
  2335. #endif /* HAVE_STDLIB_H */
  2336. #ifdef HAVE_STDDEF_H
  2337. #include <stddef.h>
  2338. #endif /* HAVE_STDDEF_H */
  2339. #include <stdio.h>
  2340. ]]
  2341. )
  2342. AC_CHECK_HEADERS([dlfcn.h],[have_tlsplugin=yes],[have_tlsplugin=no], [AC_INCLUDES_DEFAULT])
  2343. AM_CONDITIONAL([MHD_HAVE_TLS_PLUGIN], [[test "x$have_tlsplugin" = xyes]])
  2344. AC_CHECK_HEADERS([zlib.h],[have_zlib=yes],[have_zlib=no], [AC_INCLUDES_DEFAULT])
  2345. AM_CONDITIONAL([HAVE_ZLIB], [[test "x$have_zlib" = xyes]])
  2346. AC_CHECK_HEADERS([jansson.h],[have_json=yes],[have_json=no], [AC_INCLUDES_DEFAULT])
  2347. AM_CONDITIONAL([HAVE_JANSSON], [[test "x$have_json" = xyes]])
  2348. # Check for generic functions
  2349. MHD_CHECK_FUNC([random],
  2350. [
  2351. AC_INCLUDES_DEFAULT
  2352. [#include <stdlib.h>
  2353. ]],
  2354. [[long int r = random(); (void)r;]],
  2355. [],
  2356. [
  2357. MHD_CHECK_FUNC([rand],
  2358. [
  2359. AC_INCLUDES_DEFAULT
  2360. [#include <stdlib.h>
  2361. ]],
  2362. [[int r = rand(); (void)r;]],
  2363. )
  2364. ]
  2365. )
  2366. AC_CHECK_MEMBERS([struct sockaddr.sa_len, struct sockaddr_storage.ss_len,
  2367. struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len],
  2368. [], [],
  2369. [
  2370. #ifdef HAVE_SYS_TYPES_H
  2371. #include <sys/types.h>
  2372. #endif
  2373. #ifdef HAVE_SYS_SOCKET_H
  2374. #include <sys/socket.h>
  2375. #endif
  2376. #ifdef HAVE_NETINET_IN_H
  2377. #include <netinet/in.h>
  2378. #endif
  2379. #ifdef HAVE_WINSOCK2_H
  2380. #include <winsock2.h>
  2381. #endif
  2382. #ifdef HAVE_WS2TCPIP_H
  2383. #include <ws2tcpip.h>
  2384. #endif
  2385. ])
  2386. MHD_CHECK_FUNC_RUN([getsockname],
  2387. [[
  2388. #ifdef HAVE_SYS_TYPES_H
  2389. #include <sys/types.h>
  2390. #endif
  2391. #include <string.h>
  2392. #ifdef HAVE_SYS_SOCKET_H
  2393. #include <sys/socket.h>
  2394. #endif
  2395. #ifdef HAVE_UNISTD_H
  2396. #include <unistd.h>
  2397. #endif
  2398. #ifdef HAVE_WINSOCK2_H
  2399. #include <winsock2.h>
  2400. #endif
  2401. #ifdef HAVE_WS2TCPIP_H
  2402. #include <ws2tcpip.h>
  2403. #endif
  2404. #ifdef HAVE_NETINET_IN_H
  2405. #include <netinet/in.h>
  2406. #endif
  2407. #ifdef HAVE_NETINET_IP_H
  2408. #include <netinet/ip.h>
  2409. #endif
  2410. #ifdef HAVE_ARPA_INET_H
  2411. #include <arpa/inet.h>
  2412. #endif
  2413. ]],
  2414. [[
  2415. const socklen_t c_addr_size = (socklen_t)sizeof(struct sockaddr_in);
  2416. struct sockaddr_in sa;
  2417. socklen_t addr_size;
  2418. int ret = 1;
  2419. #if !defined(_WIN32) || defined(__CYGWIN__)
  2420. int sckt;
  2421. const int invld_sckt = -1;
  2422. #else
  2423. SOCKET sckt;
  2424. const SOCKET invld_sckt = INVALID_SOCKET;
  2425. WSADATA wsa_data;
  2426. i][f (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data) || MAKEWORD(2, 2) != wsa_data.wVersion)
  2427. return 20;
  2428. #endif
  2429. sckt = socket (PF_INET, SOCK_STREAM, 0);
  2430. i][f (invld_sckt != sckt)
  2431. {
  2432. memset(&sa, 0, c_addr_size);
  2433. sa.sin_family = AF_INET;
  2434. #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
  2435. sa.sin_len = c_addr_size;
  2436. #endif
  2437. i][f (0 == bind (sckt, (struct sockaddr *)&sa, c_addr_size))
  2438. {
  2439. i][f (0 == listen (sckt, 1))
  2440. {
  2441. addr_size = c_addr_size;
  2442. i][f (0 == getsockname (sckt, (struct sockaddr *)&sa, &addr_size))
  2443. {
  2444. i][f (c_addr_size >= addr_size)
  2445. {
  2446. i][f (0 != ntohs(sa.sin_port))
  2447. { ret = 0;
  2448. } el][se ret = 7;
  2449. } el][se ret = 6;
  2450. } el][se ret = 5;
  2451. } el][se ret = 4;
  2452. } el][se ret = 3;
  2453. } el][se ret = 2;
  2454. #if !defined(_WIN32) || defined(__CYGWIN__)
  2455. close (sckt);
  2456. #else
  2457. closesocket (sckt);
  2458. WSACleanup();
  2459. #endif
  2460. return ret;
  2461. ]],
  2462. [cacheVar='assuming yes'],
  2463. [AC_DEFINE([[MHD_USE_GETSOCKNAME]], [[1]], [Define if you have usable `getsockname' function.])]
  2464. )
  2465. AC_CACHE_CHECK([for usable PAGESIZE macro], [mhd_cv_macro_pagesize_usable],
  2466. [
  2467. AC_LINK_IFELSE(
  2468. [
  2469. AC_LANG_PROGRAM(
  2470. [[
  2471. #ifdef HAVE_UNISTD_H
  2472. #include <unistd.h>
  2473. #endif
  2474. #ifdef HAVE_LIMITS_H
  2475. #include <limits.h>
  2476. #endif
  2477. #ifdef HAVE_SYS_PARAM_H
  2478. #include <sys/param.h>
  2479. #endif
  2480. #ifndef PAGESIZE
  2481. #error No PAGESIZE macro defined
  2482. choke me now
  2483. #endif
  2484. ]],
  2485. [[
  2486. long pgsz = PAGESIZE + 0;
  2487. if (1 > pgsz) return 1;
  2488. ]]
  2489. )
  2490. ],
  2491. [[mhd_cv_macro_pagesize_usable="yes"]], [[mhd_cv_macro_pagesize_usable="no"]]
  2492. )
  2493. ]
  2494. )
  2495. AS_VAR_IF([[mhd_cv_macro_pagesize_usable]], [["yes"]],
  2496. [
  2497. AC_DEFINE([[MHD_USE_PAGESIZE_MACRO]],[[1]],[Define if you have usable PAGESIZE macro])
  2498. AC_CACHE_CHECK([whether PAGESIZE macro could be used for static init], [mhd_cv_macro_pagesize_usable_static],
  2499. [
  2500. AC_LINK_IFELSE(
  2501. [
  2502. AC_LANG_PROGRAM(
  2503. [[
  2504. #ifdef HAVE_UNISTD_H
  2505. #include <unistd.h>
  2506. #endif
  2507. #ifdef HAVE_LIMITS_H
  2508. #include <limits.h>
  2509. #endif
  2510. #ifdef HAVE_SYS_PARAM_H
  2511. #include <sys/param.h>
  2512. #endif
  2513. #ifndef PAGESIZE
  2514. #error No PAGESIZE macro defined
  2515. choke me now
  2516. #endif
  2517. static long ac_pgsz = PAGESIZE + 0;
  2518. ]],
  2519. [[
  2520. if (1 > ac_pgsz) return 1;
  2521. ]]
  2522. )
  2523. ],
  2524. [[mhd_cv_macro_pagesize_usable_static="yes"]], [[mhd_cv_macro_pagesize_usable_static="no"]]
  2525. )
  2526. ]
  2527. )
  2528. AS_VAR_IF([[mhd_cv_macro_pagesize_usable_static]], [["yes"]],
  2529. [AC_DEFINE([[MHD_USE_PAGESIZE_MACRO_STATIC]],[[1]],[Define if you have PAGESIZE macro usable for static init])]
  2530. )
  2531. ],
  2532. [
  2533. AC_CACHE_CHECK([for usable PAGE_SIZE macro], [mhd_cv_macro_page_size_usable],
  2534. [
  2535. AC_LINK_IFELSE(
  2536. [
  2537. AC_LANG_PROGRAM(
  2538. [[
  2539. #ifdef HAVE_UNISTD_H
  2540. #include <unistd.h>
  2541. #endif
  2542. #ifdef HAVE_LIMITS_H
  2543. #include <limits.h>
  2544. #endif
  2545. #ifdef HAVE_SYS_PARAM_H
  2546. #include <sys/param.h>
  2547. #endif
  2548. #ifndef PAGE_SIZE
  2549. #error No PAGE_SIZE macro defined
  2550. choke me now
  2551. #endif
  2552. ]],
  2553. [[
  2554. long pgsz = PAGE_SIZE + 0;
  2555. if (1 > pgsz) return 1;
  2556. ]]
  2557. )
  2558. ],
  2559. [[mhd_cv_macro_page_size_usable="yes"]], [[mhd_cv_macro_page_size_usable="no"]]
  2560. )
  2561. ]
  2562. )
  2563. AS_VAR_IF([[mhd_cv_macro_page_size_usable]], [["yes"]],
  2564. [
  2565. AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO]],[[1]],[Define if you have usable PAGE_SIZE macro])
  2566. AC_CACHE_CHECK([whether PAGE_SIZE macro could be used for static init], [mhd_cv_macro_page_size_usable_static],
  2567. [
  2568. AC_LINK_IFELSE(
  2569. [
  2570. AC_LANG_PROGRAM(
  2571. [[
  2572. #ifdef HAVE_UNISTD_H
  2573. #include <unistd.h>
  2574. #endif
  2575. #ifdef HAVE_LIMITS_H
  2576. #include <limits.h>
  2577. #endif
  2578. #ifdef HAVE_SYS_PARAM_H
  2579. #include <sys/param.h>
  2580. #endif
  2581. #ifndef PAGE_SIZE
  2582. #error No PAGE_SIZE macro defined
  2583. choke me now
  2584. #endif
  2585. static long ac_pgsz = PAGE_SIZE + 0;
  2586. ]],
  2587. [[
  2588. if (1 > ac_pgsz) return 1;
  2589. ]]
  2590. )
  2591. ],
  2592. [[mhd_cv_macro_page_size_usable_static="yes"]], [[mhd_cv_macro_page_size_usable_static="no"]]
  2593. )
  2594. ]
  2595. )
  2596. AS_VAR_IF([[mhd_cv_macro_page_size_usable_static]], [["yes"]],
  2597. [AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO_STATIC]],[[1]],[Define if you have PAGE_SIZE macro usable for static init])]
  2598. )
  2599. ]
  2600. )
  2601. ]
  2602. )
  2603. # Check for inter-thread signaling type
  2604. AC_ARG_ENABLE([[itc]],
  2605. [AS_HELP_STRING([[--enable-itc=TYPE]], [use TYPE of inter-thread communication (pipe, socketpair, eventfd) [auto]])], [],
  2606. [[enable_itc='auto']]
  2607. )
  2608. AS_CASE([[$enable_itc]],
  2609. [[pipe]], [[:]],
  2610. [[socketpair]], [[:]],
  2611. [[eventfd]], [[:]],
  2612. [[auto]], [AS_VAR_IF([[os_is_windows]], [["yes"]], [[enable_itc='socketpair']])],
  2613. [[eventFD]], [[enable_itc='eventfd']],
  2614. [[socket]], [[enable_itc='socketpair']],
  2615. [[no]], [AC_MSG_ERROR([[inter-thread communication cannot be disabled]])],
  2616. [AC_MSG_ERROR([[unrecognized type "$enable_itc" of inter-thread communication specified by "--enable-itc=$enable_itc"]])]
  2617. )
  2618. AS_UNSET([[use_itc]])
  2619. AS_IF([[test "x$enable_itc" = "xeventfd" || test "x$enable_itc" = "xauto"]],
  2620. [
  2621. MHD_CHECK_FUNC_RUN([eventfd],[[
  2622. #include <sys/eventfd.h>
  2623. #include <unistd.h>
  2624. ]],
  2625. [[
  2626. static unsigned char buf[8];
  2627. int ret;
  2628. int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
  2629. i][f (0 > efd)
  2630. return 2;
  2631. ret = 0;
  2632. buf[3] = 1;
  2633. i][f (8 != write(efd, buf, 8))
  2634. ret = 3;
  2635. el][se
  2636. {
  2637. i][f (8 != read(efd, buf, 8))
  2638. ret = 4;
  2639. }
  2640. close(efd);
  2641. return ret;
  2642. ]],
  2643. [
  2644. AS_VAR_IF([enable_itc],["eventfd"],
  2645. [cacheVar="assuming yes"],[cacheVar="assuming no"]
  2646. )
  2647. ],
  2648. [
  2649. use_itc='eventfd'
  2650. enable_itc="$use_itc"
  2651. AC_DEFINE([[_MHD_ITC_EVENTFD]], [[1]], [Define to use eventFD f][or inter-thread communication])
  2652. ]
  2653. )
  2654. AS_UNSET([warn_msg])
  2655. AS_VAR_IF([mhd_cv_works_func_eventfd],["assuming yes"],
  2656. [[warn_msg="When cross-compiling it is not possible to check whether 'eventfd()' really works on the host (final) platform.
  2657. 'eventfd' is enabled as requested by configure parameters.
  2658. Use './configure mhd_cv_works_func_eventfd=yes' to mute this warning."]]
  2659. )
  2660. AS_VAR_IF([mhd_cv_works_func_eventfd],["assuming no"],
  2661. [[warn_msg="When cross-compiling it is not possible to check whether 'eventfd()' really works on the host (final) platform.
  2662. 'eventfd()' is disabled. If it is available use './configure mhd_cv_works_func_eventfd=yes' to enable.
  2663. Use './configure mhd_cv_works_func_eventfd=no' to mute this warning."]]
  2664. )
  2665. AS_VAR_SET_IF([warn_msg],[AC_MSG_WARN([$warn_msg])
  2666. AS_IF([test -n "${CONF_FINAL_WARNS}" ],
  2667. [
  2668. CONF_FINAL_WARNS="${CONF_FINAL_WARNS}
  2669. WARNING: "
  2670. ]
  2671. )
  2672. CONF_FINAL_WARNS="${CONF_FINAL_WARNS}${warn_msg}"
  2673. ]
  2674. )
  2675. ]
  2676. )
  2677. AS_IF([[test "x$enable_itc" = "xpipe" || test "x$enable_itc" = "xauto"]], [
  2678. AS_VAR_IF([[os_is_native_w32]], [["yes"]], [], [
  2679. AC_CACHE_CHECK([[whether pipe(3) is usable]], [[mhd_cv_pipe_usable]], [
  2680. AC_LINK_IFELSE([
  2681. AC_LANG_PROGRAM([
  2682. AC_INCLUDES_DEFAULT
  2683. #ifdef HAVE_UNISTD_H
  2684. #include <unistd.h>
  2685. #endif
  2686. ], [[
  2687. int arr[2];
  2688. int res;
  2689. res = pipe(arr);
  2690. if (res != 0) return 33;
  2691. close (arr[0]);
  2692. close (arr[1]);
  2693. ]])
  2694. ], [[mhd_cv_pipe_usable='yes']], [[mhd_cv_pipe_usable='no']])
  2695. ])
  2696. AS_VAR_IF([[mhd_cv_pipe_usable]], [["yes"]], [
  2697. use_itc='pipe'
  2698. enable_itc="$use_itc"
  2699. AC_DEFINE([[_MHD_ITC_PIPE]], [[1]], [Define to use pipe for inter-thread communication])
  2700. MHD_CHECK_FUNC_RUN([pipe2],[
  2701. AC_INCLUDES_DEFAULT
  2702. [
  2703. #ifdef HAVE_FCNTL_H
  2704. #include <fcntl.h>
  2705. #endif
  2706. #ifdef HAVE_UNISTD_H
  2707. #include <unistd.h>
  2708. #endif
  2709. ]],[[
  2710. int arr[2];
  2711. int res;
  2712. res = pipe2(arr, O_CLOEXEC | O_NONBLOCK);
  2713. i][f (res != 0) return 33;
  2714. close (arr[0]);
  2715. close (arr[1]);
  2716. return 0;
  2717. ]],[
  2718. # Cross-compiling
  2719. AS_CASE([${host_os}], [kfreebsd*-gnu], [cacheVar='assuming no'],
  2720. [cacheVar='assuming yes'])
  2721. ],
  2722. [AC_DEFINE([[HAVE_PIPE2_FUNC]], [[1]], [Define i][f you have usable pipe2(2) function])],
  2723. )
  2724. ], [
  2725. AS_VAR_IF([[enable_itc]], [["pipe"]], [AC_MSG_ERROR([[pipe(3) is not usable, consider using other type of inter-thread communication]])])
  2726. ])
  2727. ])
  2728. ])
  2729. AS_IF([[test "x$enable_itc" = "xsocketpair" || test "x$enable_itc" = "xauto"]], [
  2730. AS_VAR_IF([[os_is_native_w32]], [["yes"]], [[mhd_cv_socketpair_usable='yes']], [
  2731. AC_CACHE_CHECK([[whether socketpair(3) is usable]], [[mhd_cv_socketpair_usable]], [
  2732. AC_LINK_IFELSE([
  2733. AC_LANG_PROGRAM([
  2734. AC_INCLUDES_DEFAULT
  2735. #ifdef HAVE_SYS_TYPES_H
  2736. #include <sys/types.h>
  2737. #endif
  2738. #ifdef HAVE_SYS_SOCKET_H
  2739. #include <sys/socket.h>
  2740. #endif
  2741. ], [[
  2742. int arr[2];
  2743. int res;
  2744. #if defined(AF_LOCAL)
  2745. res = socketpair(AF_LOCAL, SOCK_STREAM, 0, arr);
  2746. #elif defined(AF_UNIX)
  2747. res = socketpair(AF_UNIX, SOCK_STREAM, 0, arr);
  2748. #else
  2749. #error AF_LOCAL and AF_UNIX are both undefined
  2750. choke me now;
  2751. #endif
  2752. if (res != 0) return 1
  2753. ]])
  2754. ], [[mhd_cv_socketpair_usable='yes']], [[mhd_cv_socketpair_usable='no']])
  2755. ])
  2756. ])
  2757. AS_VAR_IF([[mhd_cv_socketpair_usable]], [["yes"]], [
  2758. use_itc='socketpair'
  2759. enable_itc="$use_itc"
  2760. AC_DEFINE([[_MHD_ITC_SOCKETPAIR]], [[1]], [Define to use socketpair for inter-thread communication])
  2761. ], [
  2762. AS_VAR_IF([[enable_itc]], [["socketpair"]], [AC_MSG_ERROR([[socketpair(3) is not usable, consider using other type of inter-thread communication]])])
  2763. ])
  2764. ])
  2765. AS_IF([[test -z "$use_itc"]], [AC_MSG_ERROR([[cannot find usable type of inter-thread communication]])])
  2766. MHD_CHECK_FUNC([accept4],
  2767. [[
  2768. #if defined(HAVE_SYS_TYPES_H)
  2769. # include <sys/types.h>
  2770. #endif
  2771. #include <sys/socket.h>
  2772. ]],
  2773. [[
  2774. struct sockaddr sk_addr;
  2775. socklen_t addr_size;
  2776. i][f (0 > accept4(0, &sk_addr, &addr_size, 0))
  2777. return 3;
  2778. ]]
  2779. )
  2780. MHD_CHECK_FUNC([gmtime_r],
  2781. [[
  2782. #if defined(HAVE_SYS_TYPES_H)
  2783. # include <sys/types.h>
  2784. #endif
  2785. #include <time.h>
  2786. ]],
  2787. [[
  2788. time_t timer = (time_t) 0;
  2789. struct tm res;
  2790. i][f (&res != gmtime_r(&timer, &res))
  2791. return 3;
  2792. ]]
  2793. )
  2794. MHD_CHECK_FUNC([memmem],
  2795. [[
  2796. #if defined(HAVE_STDDEF_H)
  2797. # include <stddef.h>
  2798. #elif defined(HAVE_STDLIB_H)
  2799. # include <stdlib.h>
  2800. #endif /* HAVE_STDLIB_H */
  2801. #include <string.h>
  2802. ]],
  2803. [[
  2804. const char *haystack = "abc";
  2805. size_t hslen = 3;
  2806. const char *needle = "b";
  2807. size_t needlelen = 1;
  2808. i][f ((haystack + 1) != memmem(haystack, hslen, needle, needlelen))
  2809. return 3;
  2810. ]]
  2811. )
  2812. MHD_CHECK_FUNC([snprintf],
  2813. [[
  2814. #include <stdio.h>
  2815. ]],
  2816. [[
  2817. char buf[2];
  2818. i][f (1 != snprintf(buf, 2, "a"))
  2819. return 3;
  2820. /* Do not use the next check to avoid compiler warning */
  2821. /* i][f (4 != snprintf(buf, 2, "abcd"))
  2822. return 4; */
  2823. ]]
  2824. )
  2825. AC_CHECK_DECL([gmtime_s],
  2826. [
  2827. AC_MSG_CHECKING([[whether gmtime_s is in C11 form]])
  2828. AC_LINK_IFELSE(
  2829. [ AC_LANG_PROGRAM(
  2830. [[
  2831. #define __STDC_WANT_LIB_EXT1__ 1
  2832. #include <time.h>
  2833. #ifdef __cplusplus
  2834. extern "C"
  2835. #endif
  2836. struct tm* gmtime_s(const time_t* time, struct tm* result);
  2837. ]], [[
  2838. static struct tm res;
  2839. static time_t t = 0;
  2840. gmtime_s (&t, &res);
  2841. ]])
  2842. ],
  2843. [
  2844. AC_DEFINE([HAVE_C11_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in C11 form.])
  2845. AC_MSG_RESULT([[yes]])
  2846. ],
  2847. [
  2848. AC_MSG_RESULT([[no]])
  2849. AC_MSG_CHECKING([[whether gmtime_s is in W32 form]])
  2850. AC_LINK_IFELSE(
  2851. [ AC_LANG_PROGRAM(
  2852. [[
  2853. #include <time.h>
  2854. #ifdef __cplusplus
  2855. extern "C"
  2856. #endif
  2857. errno_t gmtime_s(struct tm* _tm, const time_t* time);
  2858. ]], [[
  2859. static struct tm res;
  2860. static time_t t = 0;
  2861. gmtime_s (&res, &t);
  2862. ]])
  2863. ],
  2864. [
  2865. AC_DEFINE([HAVE_W32_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in W32 form.])
  2866. AC_MSG_RESULT([[yes]])
  2867. ],
  2868. [AC_MSG_RESULT([[no]])
  2869. ])
  2870. ])
  2871. ], [],
  2872. [[#define __STDC_WANT_LIB_EXT1__ 1
  2873. #include <time.h>]])
  2874. AC_CHECK_DECL([SOCK_NONBLOCK], [AC_DEFINE([HAVE_SOCK_NONBLOCK], [1], [SOCK_NONBLOCK is defined in a socket header])], [],
  2875. [[
  2876. #if defined(HAVE_SYS_TYPES_H)
  2877. # include <sys/types.h>
  2878. #endif
  2879. #if defined(HAVE_SYS_SOCKET_H)
  2880. # include <sys/socket.h>
  2881. #elif defined(HAVE_WINSOCK2_H)
  2882. # include <winsock2.h>
  2883. #endif
  2884. ]]
  2885. )
  2886. MHD_FIND_LIB([clock_gettime],[[#include <time.h>]],
  2887. [[
  2888. struct timespec tp;
  2889. i][f (0 > clock_gettime(CLOCK_REALTIME, &tp))
  2890. return 3;
  2891. ]],
  2892. [rt],
  2893. [
  2894. AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define to '1' if you have clock_gettime() function])
  2895. AS_VAR_IF([[mhd_cv_find_lib_clock_gettime]],[["none required"]], [],
  2896. [
  2897. MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_clock_gettime} $MHD_LIBDEPS_PKGCFG"
  2898. ]
  2899. )
  2900. ],[],
  2901. [MHD_LIBDEPS]
  2902. )
  2903. MHD_CHECK_FUNC([clock_get_time],
  2904. [[
  2905. #include <mach/clock.h>
  2906. #include <mach/mach.h>
  2907. ]],
  2908. [[
  2909. clock_serv_t cs;
  2910. mach_timespec_t mt;
  2911. host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cs);
  2912. clock_get_time(cs, &mt);
  2913. mach_port_deallocate(mach_task_self(), cs);
  2914. ]]
  2915. )
  2916. MHD_CHECK_FUNC([gethrtime],
  2917. [[
  2918. #ifdef HAVE_SYS_TIME_H
  2919. /* Solaris define gethrtime() in sys/time.h */
  2920. #include <sys/time.h>
  2921. #endif /* HAVE_SYS_TIME_H */
  2922. #ifdef HAVE_TIME_H
  2923. /* HP-UX define gethrtime() in time.h */
  2924. #include <time.h>
  2925. #endif /* HAVE_TIME_H */
  2926. ]],
  2927. [[
  2928. hrtime_t hrt = gethrtime();
  2929. i][f (0 == hrt)
  2930. return 3;
  2931. ]]
  2932. )
  2933. AS_VAR_IF([ac_cv_header_time_h], ["yes"],
  2934. [
  2935. MHD_CHECK_FUNC([timespec_get],
  2936. [[
  2937. #include <time.h>
  2938. #ifndef TIME_UTC
  2939. #error TIME_UTC must be defined to use timespec_get()
  2940. choke me now
  2941. #endif
  2942. ]],
  2943. [[
  2944. struct timespec ts;
  2945. i][f (TIME_UTC != timespec_get (&ts, TIME_UTC))
  2946. return 3;
  2947. ]]
  2948. )
  2949. ]
  2950. )
  2951. MHD_CHECK_FUNC_GETTIMEOFDAY
  2952. # IPv6
  2953. AC_CACHE_CHECK([for IPv6],[mhd_cv_have_inet6],
  2954. [
  2955. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  2956. #include <stdio.h>
  2957. #ifdef HAVE_NETINET_IN_H
  2958. #include <netinet/in.h>
  2959. #endif
  2960. #ifdef HAVE_SYS_SOCKET_H
  2961. #include <sys/socket.h>
  2962. #endif
  2963. #ifdef HAVE_WINSOCK2_H
  2964. #include <winsock2.h>
  2965. #endif
  2966. #ifdef HAVE_WS2TCPIP_H
  2967. #include <ws2tcpip.h>
  2968. #endif
  2969. ]], [[
  2970. int af=AF_INET6;
  2971. int pf=PF_INET6;
  2972. struct sockaddr_in6 sa;
  2973. printf("%d %d %p\n", af, pf, (void*) &sa);
  2974. ]]
  2975. )
  2976. ],
  2977. [AS_VAR_SET([mhd_cv_have_inet6],["yes"])],
  2978. [AS_VAR_SET([mhd_cv_have_inet6],["no"])]
  2979. )
  2980. ]
  2981. )
  2982. AS_VAR_IF([mhd_cv_have_inet6],["yes"],
  2983. [AC_DEFINE([HAVE_INET6], [1], [Define to '1' if you have IPv6 headers])]
  2984. )
  2985. MHD_CHECK_FUNC([[sysconf]], [[#include <unistd.h>]], [[long a = sysconf(0); if (a) return 1;]])
  2986. MHD_CHECK_FUNC([[sysctl]], [[
  2987. #ifdef HAVE_SYS_TYPES_H
  2988. #include <sys/types.h>
  2989. #endif
  2990. #ifdef HAVE_SYS_SYSCTL_H
  2991. #include <sys/sysctl.h>
  2992. #endif
  2993. #if defined(HAVE_STDDEF_H)
  2994. #include <stddef.h>
  2995. #elif defined(HAVE_STDLIB_H)
  2996. #include <stdlib.h>
  2997. #endif
  2998. ]], [[
  2999. int mib[2] = {0, 0}; /* Avoid any platform-specific values */
  3000. i][f (sysctl(mib, 2, NULL, NULL, NULL, 0)) return 1;
  3001. ]],
  3002. [
  3003. AC_CHECK_DECLS([CTL_NET,PF_INET,IPPROTO_ICMP,ICMPCTL_ICMPLIM],[],[],
  3004. [[
  3005. #ifdef HAVE_SYS_TYPES_H
  3006. #include <sys/types.h>
  3007. #endif /* HAVE_SYS_TYPES_H */
  3008. #ifdef HAVE_SYS_SYSCTL_H
  3009. #include <sys/sysctl.h>
  3010. #endif /* HAVE_SYS_SYSCTL_H */
  3011. #ifdef HAVE_SYS_SYSCTL_H
  3012. #include <sys/sysctl.h>
  3013. #endif /* HAVE_SYS_SYSCTL_H */
  3014. #ifdef HAVE_SYS_SOCKET_H
  3015. #include <sys/socket.h>
  3016. #endif /* HAVE_SYS_SOCKET_H */
  3017. #ifdef HAVE_NETINET_IN_SYSTM_H
  3018. #include <netinet/in_systm.h>
  3019. #endif /* HAVE_NETINET_IN_SYSTM_H */
  3020. #ifdef HAVE_NETINET_IN_H
  3021. #include <netinet/in.h>
  3022. #endif /* HAVE_NETINET_IN_H */
  3023. #ifdef HAVE_NETINET_IP_H
  3024. #include <netinet/ip.h>
  3025. #endif /* HAVE_NETINET_IP_H */
  3026. #ifdef HAVE_NETINET_IP_ICMP_H
  3027. #include <netinet/ip_icmp.h>
  3028. #endif /* HAVE_NETINET_IP_ICMP_H */
  3029. #ifdef HAVE_NETINET_ICMP_VAR_H
  3030. #include <netinet/icmp_var.h>
  3031. #endif /* HAVE_NETINET_ICMP_VAR_H */
  3032. ]]
  3033. )
  3034. ]
  3035. )
  3036. MHD_CHECK_FUNC([[sysctlbyname]], [[
  3037. #ifdef HAVE_SYS_TYPES_H
  3038. #include <sys/types.h>
  3039. #endif
  3040. #ifdef HAVE_SYS_SYSCTL_H
  3041. #include <sys/sysctl.h>
  3042. #endif
  3043. #if defined(HAVE_STDDEF_H)
  3044. #include <stddef.h>
  3045. #elif defined(HAVE_STDLIB_H)
  3046. #include <stdlib.h>
  3047. #endif
  3048. ]], [[sysctlbyname("test", NULL, NULL, NULL, 0);]]
  3049. )
  3050. MHD_CHECK_FUNC([[usleep]], [[#include <unistd.h>]], [[usleep(100000);]])
  3051. MHD_CHECK_FUNC([[nanosleep]], [[#include <time.h>]], [[struct timespec ts2, ts1 = {0, 0}; nanosleep(&ts1, &ts2);]])
  3052. HIDDEN_VISIBILITY_CFLAGS=""
  3053. AH_TEMPLATE([_MHD_EXTERN],[defines how to decorate public symbols w][hile building the library])
  3054. CFLAGS="${user_CFLAGS}"
  3055. MHD_CHECK_CC_CFLAG([-fvisibility=hidden],[CFLAGS_ac],
  3056. [
  3057. # NOTE: require setting of errattr_CFLAGS above
  3058. CFLAGS="${CFLAGS_ac} -fvisibility=hidden ${user_CFLAGS} ${errattr_CFLAGS}"
  3059. AC_CACHE_CHECK([whether $CC supports __attribute__((visibility("default")))],[mhd_cv_cc_attr_visibility],
  3060. [
  3061. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  3062. extern __attribute__((visibility("default"))) int test_extrn_func(void);
  3063. int test_extrn_func(void) {return 0;}
  3064. ]])
  3065. ],
  3066. [mhd_cv_cc_attr_visibility="yes"],[mhd_cv_cc_attr_visibility="no"]
  3067. )
  3068. ]
  3069. )
  3070. AS_VAR_IF([mhd_cv_cc_attr_visibility],["yes"],
  3071. [
  3072. HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"
  3073. AS_IF([test "x$os_is_native_w32" = "xyes" && test "x$enable_shared" = "xyes"],
  3074. [AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern])],
  3075. [AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) extern])]
  3076. )
  3077. ],
  3078. [
  3079. AC_MSG_WARN([$CC supports -fvisibility, but does not support __attribute__((visibility("default"))). Check compiler and compiler flags.])
  3080. AC_DEFINE([_MHD_EXTERN], [extern])
  3081. ]
  3082. )
  3083. ],[AC_DEFINE([_MHD_EXTERN], [extern])]
  3084. )
  3085. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3086. AC_SUBST([HIDDEN_VISIBILITY_CFLAGS])
  3087. # libcurl (required for testing)
  3088. AC_ARG_ENABLE([curl],
  3089. [AS_HELP_STRING([--disable-curl],[disable cURL based testcases])],
  3090. [enable_curl=${enableval}])
  3091. curl=0
  3092. AS_IF([test "$enable_curl" != "no"],
  3093. [LIBCURL_CHECK_CONFIG([yes],[7.16.4],[enable_curl=yes],
  3094. [
  3095. AS_IF([test "x$enable_curl" = "xyes"],
  3096. [AC_MSG_WARN([[cURL-based tests cannot be enabled because libcurl is missing]])])
  3097. enable_curl=no
  3098. ])
  3099. ])
  3100. AM_CONDITIONAL([RUN_LIBCURL_TESTS], [test "x$enable_curl" = "xyes"])
  3101. AS_IF([test "x$enable_curl" = "xyes"],
  3102. [MSG_CURL="yes"],
  3103. [MSG_CURL="no, many unit tests will not run"]
  3104. )
  3105. MHD_CHECK_FUNC([magic_open],
  3106. [[
  3107. #include <magic.h>
  3108. ]],
  3109. [[
  3110. char var_data[256];
  3111. const char *var_mime;
  3112. magic_t var_magic = magic_open (MAGIC_MIME_TYPE);
  3113. (void)magic_load (var_magic, "filename");
  3114. var_data[0] = 0;
  3115. var_mime = magic_buffer (var_magic, var_data, 1);
  3116. i][f (! var_mime)
  3117. return 1;
  3118. magic_close (var_magic);
  3119. ]],
  3120. [AC_DEFINE([MHD_HAVE_LIBMAGIC], [1], [Define to 1 if you have suitable libmagic.])],
  3121. [],
  3122. [-lmagic]
  3123. )
  3124. AM_CONDITIONAL([MHD_HAVE_LIBMAGIC], [[test "x$mhd_cv_have_func_magic_open" = "xyes"]])
  3125. # large file support (> 4 GB)
  3126. MHD_CHECK_FUNC([lseek64],
  3127. [[
  3128. #if defined(HAVE_SYS_TYPES_H)
  3129. # include <sys/types.h>
  3130. #endif
  3131. #include <unistd.h>
  3132. ]],
  3133. [[
  3134. i][f (((off64_t) -1) == lseek64(0, (off64_t) 0, SEEK_SET))
  3135. return 3;
  3136. ]]
  3137. )
  3138. MHD_CHECK_FUNC([pread64],
  3139. [[
  3140. #if defined(HAVE_SYS_TYPES_H)
  3141. # include <sys/types.h>
  3142. #endif
  3143. #include <unistd.h>
  3144. ]],
  3145. [[
  3146. char buf[5];
  3147. i][f (0 > pread64(0, (void *) buf, 1, (off64_t) 0))
  3148. return 3;
  3149. ]]
  3150. )
  3151. MHD_CHECK_FUNC([pread],
  3152. [[
  3153. #if defined(HAVE_SYS_TYPES_H)
  3154. # include <sys/types.h>
  3155. #endif
  3156. #include <unistd.h>
  3157. ]],
  3158. [[
  3159. char buf[5];
  3160. i][f (0 > pread(0, (void *) buf, 1, 0))
  3161. return 3;
  3162. ]]
  3163. )
  3164. # check for various sendfile functions
  3165. AC_ARG_ENABLE([sendfile],
  3166. [AS_HELP_STRING([--disable-sendfile],
  3167. [disable usage of sendfile() for HTTP connections [auto]])],
  3168. [],
  3169. [enable_sendfile="auto"])
  3170. AS_CASE([$enable_sendfile],
  3171. [[auto | yes]],[[found_sendfile="no"]],
  3172. [[no]],[[found_sendfile="disabled"]],
  3173. [AC_MSG_ERROR([[unknown value specified: --enable-sendfile=$enable_sendfile]])]
  3174. )
  3175. AS_VAR_IF([[found_sendfile]], [["no"]],
  3176. [
  3177. AC_MSG_CHECKING([[for Linux-style sendfile(2)]])
  3178. AC_LINK_IFELSE(
  3179. [AC_LANG_PROGRAM(
  3180. [[
  3181. #include <sys/sendfile.h>
  3182. static void empty_func(void)
  3183. {
  3184. /* Check for declaration */
  3185. (void)sendfile;
  3186. }
  3187. /* Declare again to check form match */
  3188. ssize_t sendfile(int, int, off_t*, size_t);
  3189. ]],
  3190. [[
  3191. int fd1=0, fd2=2;
  3192. off_t o = 0;
  3193. size_t s = 5;
  3194. ssize_t r;
  3195. r = sendfile (fd1, fd2, &o, s);
  3196. if (r)
  3197. empty_func();
  3198. ]]
  3199. )
  3200. ],
  3201. [
  3202. AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).])
  3203. found_sendfile="yes, Linux-style"
  3204. AC_MSG_RESULT([[yes]])
  3205. MHD_CHECK_FUNC([sendfile64],
  3206. [[
  3207. #include <sys/sendfile.h>
  3208. ]],
  3209. [[
  3210. off64_t f_offset = (off64_t) 0;
  3211. if (0 > sendfile64 (0, 1, &f_offset, 1))
  3212. return 3;
  3213. ]]
  3214. )
  3215. ],
  3216. [AC_MSG_RESULT([[no]])
  3217. ]
  3218. )
  3219. ]
  3220. )
  3221. AS_VAR_IF([[found_sendfile]], [["no"]],
  3222. [
  3223. AC_MSG_CHECKING([[for FreeBSD-style sendfile(2)]])
  3224. AC_LINK_IFELSE(
  3225. [AC_LANG_PROGRAM(
  3226. [[
  3227. #include <sys/types.h>
  3228. #include <sys/socket.h>
  3229. #include <sys/uio.h>
  3230. static void empty_func(void)
  3231. {
  3232. /* Check for declaration */
  3233. (void)sendfile;
  3234. }
  3235. /* Declare again to check form match */
  3236. int sendfile(int, int, off_t, size_t,
  3237. struct sf_hdtr*, off_t*, int);
  3238. ]],
  3239. [[
  3240. int fd1=0, fd2=1;
  3241. off_t o = 0;
  3242. size_t s = 5;
  3243. off_t r1;
  3244. int r2;
  3245. r2 = sendfile (fd1, fd2, o, s, (void*)0, &r1, 0);
  3246. if (r2)
  3247. empty_func();
  3248. ]]
  3249. )
  3250. ],
  3251. [
  3252. AC_DEFINE([HAVE_FREEBSD_SENDFILE], [1], [Define to 1 if you have FreeBSD-style sendfile(2).])
  3253. found_sendfile="yes, FreeBSD-style"
  3254. AC_MSG_RESULT([[yes]])
  3255. ],
  3256. [AC_MSG_RESULT([[no]])
  3257. ]
  3258. )
  3259. ]
  3260. )
  3261. AS_VAR_IF([[found_sendfile]], [["no"]],
  3262. [
  3263. AC_MSG_CHECKING([[for Darwin-style sendfile(2)]])
  3264. AC_LINK_IFELSE(
  3265. [AC_LANG_PROGRAM(
  3266. [[
  3267. #include <sys/types.h>
  3268. #include <sys/socket.h>
  3269. #include <sys/uio.h>
  3270. static void empty_func(void)
  3271. {
  3272. /* Check for declaration */
  3273. (void)sendfile;
  3274. }
  3275. /* Declare again to check form match */
  3276. int sendfile(int, int, off_t, off_t*,
  3277. struct sf_hdtr *, int);
  3278. ]],
  3279. [[
  3280. int fd=0, s=1;
  3281. off_t o = 0;
  3282. off_t l = 5;
  3283. int r;
  3284. r = sendfile (fd, s, o, &l, (void*)0, 0);
  3285. if (r)
  3286. empty_func();
  3287. ]]
  3288. )
  3289. ],
  3290. [
  3291. AC_DEFINE([HAVE_DARWIN_SENDFILE], [1], [Define to 1 if you have Darwin-style sendfile(2).])
  3292. found_sendfile="yes, Darwin-style"
  3293. AC_MSG_RESULT([[yes]])
  3294. ],
  3295. [AC_MSG_RESULT([[no]])
  3296. ]
  3297. )
  3298. ]
  3299. )
  3300. AS_VAR_IF([[found_sendfile]], [["no"]],
  3301. [
  3302. AC_MSG_CHECKING([[for Solaris-style sendfile(3)]])
  3303. SAVE_LIBS="$LIBS"
  3304. LIBS="-lsendfile $LIBS"
  3305. AC_LINK_IFELSE(
  3306. [AC_LANG_PROGRAM(
  3307. [[
  3308. #include <sys/types.h>
  3309. #include <sys/socket.h>
  3310. #include <sys/sendfile.h>
  3311. static void empty_func(void)
  3312. {
  3313. /* Check for declaration */
  3314. (void)sendfile;
  3315. }
  3316. /* Declare again to check form match */
  3317. ssize_t sendfile(int out_fd, int in_fd,
  3318. off_t *off, size_t len);
  3319. ]],
  3320. [[
  3321. int fd1=0, fd2=1;
  3322. off_t o = 0;
  3323. size_t l = 5;
  3324. ssize_t r;
  3325. r = sendfile (fd1, fd2, &o, l);
  3326. if (r)
  3327. empty_func();
  3328. ]]
  3329. )
  3330. ],
  3331. [
  3332. AC_DEFINE([HAVE_SOLARIS_SENDFILE], [1], [Define to 1 if you have Solaris-style sendfile(3).])
  3333. found_sendfile="yes, Solaris-style"
  3334. MHD_LIBDEPS="-lsendfile $MHD_LIBDEPS"
  3335. MHD_LIBDEPS_PKGCFG="-lsendfile $MHD_LIBDEPS_PKGCFG"
  3336. AC_MSG_RESULT([[yes]])
  3337. MHD_CHECK_FUNC([sendfile64],
  3338. [[
  3339. #include <sys/types.h>
  3340. #include <sys/socket.h>
  3341. #include <sys/sendfile.h>
  3342. ]],
  3343. [[
  3344. off64_t f_offset = (off64_t) 0;
  3345. if (0 > sendfile64 (0, 1, &f_offset, 1))
  3346. return 3;
  3347. ]]
  3348. )
  3349. ],
  3350. [AC_MSG_RESULT([[no]])
  3351. ]
  3352. )
  3353. LIBS="$SAVE_LIBS"
  3354. ]
  3355. )
  3356. AS_IF([[test "x$found_sendfile" = "xno" && test "x$enable_sendfile" = "xyes"]],
  3357. [AC_MSG_ERROR([[sendfile() usage was requested by configure parameter, but no usable sendfile() function is detected]])]
  3358. )
  3359. # optional: enable error and informational messages
  3360. AC_MSG_CHECKING([[whether to generate text messages]])
  3361. AC_ARG_ENABLE([messages],
  3362. [AS_HELP_STRING([--disable-messages],
  3363. [disable error, warning messages and text bodies for ]
  3364. [automatic HTTP responses (to reduce the binary size)])],
  3365. [enable_messages=${enableval}],
  3366. [enable_messages=yes])
  3367. AS_IF([[test "x$enable_messages" = "xyes"]],
  3368. [ AC_DEFINE([HAVE_MESSAGES],[1],[Define to 1 to enable support for text messages.]) ],
  3369. [[ enable_messages=no ]])
  3370. AC_MSG_RESULT([[$enable_messages]])
  3371. AM_CONDITIONAL([HAVE_MESSAGES], [test "x$enable_messages" != "xno"])
  3372. # optional: have postprocessor?
  3373. AC_MSG_CHECKING([[whether to enable postprocessor]])
  3374. AC_ARG_ENABLE([postprocessor],
  3375. [AS_HELP_STRING([--disable-postprocessor],
  3376. [disable MHD PostProcessor functionality])],
  3377. [enable_postprocessor=${enableval}],
  3378. [enable_postprocessor=yes])
  3379. AS_IF([[test "x$enable_postprocessor" != "xno"]],
  3380. [ enable_postprocessor=yes
  3381. AC_DEFINE([HAVE_POSTPROCESSOR],[1],[Define to 1 if libmicrohttpd is compiled with postprocessor support.]) ])
  3382. AM_CONDITIONAL([HAVE_POSTPROCESSOR], [test "x$enable_postprocessor" != "xno"])
  3383. AC_MSG_RESULT([[$enable_postprocessor]])
  3384. have_gnutls=no
  3385. have_gnutls_sni=no
  3386. have_gcrypt=no
  3387. AS_UNSET([GNUTLS_CPPFLAGS])
  3388. AS_UNSET([GNUTLS_LDFLAGS])
  3389. # optional: HTTPS support. Enabled by default
  3390. AC_ARG_ENABLE([https],
  3391. [AS_HELP_STRING([--enable-https],
  3392. [enable HTTPS support (yes, no, auto)[auto]])],
  3393. [enable_https=${enableval}])
  3394. AS_IF([test "x$enable_https" != "xno"],[
  3395. #
  3396. # Next block is large unindented block
  3397. #
  3398. # gnutls
  3399. have_gnutls_pkgcfg=no
  3400. AC_MSG_CHECKING([[how to find GnuTLS library]])
  3401. AC_ARG_WITH([[gnutls]],
  3402. [AS_HELP_STRING([[--with-gnutls[=PFX]]],[use GnuTLS for HTTPS support, optional PFX overrides pkg-config data for GnuTLS headers (PFX/include) and libs (PFX/lib)])],
  3403. [
  3404. AS_CASE([$with_gnutls],
  3405. [no],[
  3406. AC_MSG_RESULT([[GnuTLS disabled]])
  3407. AS_UNSET([GNUTLS_CPPFLAGS])
  3408. AS_UNSET([GNUTLS_CFLAGS])
  3409. AS_UNSET([GNUTLS_LDFLAGS])
  3410. AS_UNSET([GNUTLS_LIBS])
  3411. ],
  3412. [yes],[
  3413. AC_MSG_RESULT([[automatically, forced]])
  3414. ],
  3415. [
  3416. AC_MSG_RESULT([[-I$with_gnutls/include -L$with_gnutls/lib -lgnutls]])
  3417. SAVE_LIBS="$LIBS"
  3418. LDFLAGS="${LDFLAGS_ac} -L$with_gnutls/lib ${user_LDFLAGS}"
  3419. CPPFLAGS="${CPPFLAGS_ac} -I$with_gnutls/include ${user_CPPFLAGS}"
  3420. have_gnutls_pkgcfg=no
  3421. MHD_CHECK_FUNC([gnutls_check_version],[[#include <gnutls/gnutls.h>]],
  3422. [
  3423. if(!gnutls_check_version("2.0.0"))
  3424. return 3;
  3425. ],
  3426. [
  3427. GNUTLS_CPPFLAGS="-I$with_gnutls/include"
  3428. GNUTLS_LDFLAGS="-L$with_gnutls/lib"
  3429. GNUTLS_LIBS="-lgnutls"
  3430. have_gnutls=yes
  3431. ],
  3432. [AC_MSG_ERROR([can't find usable libgnutls at specified prefix $with_gnutls])],
  3433. [-lgnutls]
  3434. )
  3435. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3436. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3437. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3438. LIBS="$SAVE_LIBS"
  3439. ])
  3440. ],
  3441. [AC_MSG_RESULT([[automatically]])
  3442. ])
  3443. AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"],
  3444. [
  3445. PKG_CHECK_MODULES(GNUTLS, [[gnutls]],
  3446. [
  3447. have_gnutls_pkgcfg='yes'
  3448. SAVE_LIBS="$LIBS"
  3449. CFLAGS="${CFLAGS_ac} $GNUTLS_CFLAGS ${user_CFLAGS}"
  3450. LIBS="$GNUTLS_LIBS $LIBS"
  3451. AC_MSG_CHECKING([[whether GnuTLS is usable]])
  3452. AC_LINK_IFELSE([
  3453. AC_LANG_PROGRAM([[
  3454. #include <gnutls/gnutls.h>
  3455. ]], [[
  3456. gnutls_session_t session;
  3457. gnutls_priority_t priorities;
  3458. gnutls_global_init();
  3459. gnutls_priority_init(&priorities, "NORMAL", NULL);
  3460. gnutls_init(&session, GNUTLS_SERVER);
  3461. gnutls_priority_set(session, priorities);
  3462. ]])],
  3463. [
  3464. AC_MSG_RESULT([[yes]])
  3465. have_gnutls=yes
  3466. # GNUTLS_CFLAGS is actually CPPFLAGS
  3467. GNUTLS_CPPFLAGS="$GNUTLS_CFLAGS"
  3468. # GNUTLS_LDFLAGS is a combination of LDFLAGS and LIBS
  3469. GNUTLS_LDFLAGS="$GNUTLS_LIBS"
  3470. ],
  3471. [
  3472. AC_MSG_RESULT([[no]])
  3473. have_gnutls=no
  3474. ])
  3475. AS_IF([test "x$have_gnutls" != "xyes"],
  3476. [
  3477. AC_MSG_WARN([pkg-config reports that GnuTLS is present, but GnuTLS can't be used])
  3478. AS_UNSET([GNUTLS_CPPFLAGS])
  3479. AS_UNSET([GNUTLS_CFLAGS])
  3480. AS_UNSET([GNUTLS_LDFLAGS])
  3481. AS_UNSET([GNUTLS_LIBS])
  3482. ]
  3483. )
  3484. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3485. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3486. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3487. LIBS="$SAVE_LIBS"
  3488. ],
  3489. [
  3490. # check for GnuTLS at default paths
  3491. have_gnutls_pkgcfg='no'
  3492. AC_CHECK_HEADERS([gnutls/gnutls.h],
  3493. [AC_CHECK_LIB([gnutls], [gnutls_priority_set],
  3494. [
  3495. GNUTLS_LIBS="-lgnutls"
  3496. have_gnutls=yes
  3497. ])], [], [AC_INCLUDES_DEFAULT])
  3498. ])
  3499. ])
  3500. have_gcrypt='unknown'
  3501. AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"],
  3502. [
  3503. AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no])
  3504. AS_IF([[test "x$have_gcrypt" = "xyes"]],
  3505. [
  3506. SAVE_LIBS="$LIBS"
  3507. CFLAGS="${CFLAGS_ac} $LIBGCRYPT_CFLAGS ${user_CFLAGS}"
  3508. # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both
  3509. CPPFLAGS="${CPPFLAGS_ac} $LIBGCRYPT_CFLAGS ${user_CPPFLAGS}"
  3510. AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no], [AC_INCLUDES_DEFAULT])
  3511. # Check for GnuTLS with gcrypt flags
  3512. LDFLAGS="${LDFLAGS_ac} ${LIBGCRYPT_LIBS} ${user_LDFLAGS}"
  3513. # A bit of hack: unset cache variable to force recheck
  3514. AS_UNSET([ac_cv_header_gnutls_gnutls_h])
  3515. AC_CHECK_HEADERS([gnutls/gnutls.h],
  3516. [AS_UNSET([ac_cv_lib_gnutls_gnutls_priority_set]) # A bit of hack: unset cache variable to force recheck
  3517. AC_CHECK_LIB([gnutls], [gnutls_priority_set],
  3518. [
  3519. GNUTLS_CPPFLAGS="$LIBGCRYPT_CFLAGS"
  3520. GNUTLS_CFLAGS="$LIBGCRYPT_CFLAGS"
  3521. GNUTLS_LDFLAGS="$LIBGCRYPT_LIBS"
  3522. GNUTLS_LIBS="-lgnutls"
  3523. have_gnutls=yes
  3524. ])], [], [AC_INCLUDES_DEFAULT])
  3525. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3526. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3527. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3528. LIBS="$SAVE_LIBS"
  3529. ]
  3530. )
  3531. ]
  3532. )
  3533. AS_IF([test "x$have_gnutls" != "xyes" && test "x$with_gnutls" = "xyes"],
  3534. [AC_MSG_ERROR([[can't find usable libgnutls]])])
  3535. AS_IF([test "x$have_gnutls" = "xyes"],
  3536. [
  3537. SAVE_LIBS="$LIBS"
  3538. CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}"
  3539. CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}"
  3540. LDFLAGS="${LDFLAGS_ac} ${GNUTLS_LDFLAGS} ${user_LDFLAGS}"
  3541. LIBS="$GNUTLS_LIBS $LIBS"
  3542. AC_MSG_CHECKING([[for gnutls_privkey_import_x509_raw()]])
  3543. AC_LINK_IFELSE([
  3544. AC_LANG_PROGRAM([[
  3545. #include <gnutls/gnutls.h>
  3546. #include <gnutls/abstract.h>
  3547. ]], [[
  3548. gnutls_datum_t data;
  3549. gnutls_privkey_t key = 0;
  3550. #ifndef gnutls_load_file
  3551. (void)gnutls_load_file; /* Check for declaration. */
  3552. #endif
  3553. #ifndef gnutls_privkey_import_x509_raw
  3554. (void)gnutls_privkey_import_x509_raw; /* Check for declaration. */
  3555. #endif
  3556. gnutls_load_file("key.pem", &data);
  3557. gnutls_privkey_import_x509_raw(key, &data, GNUTLS_X509_FMT_PEM, NULL, 0);
  3558. gnutls_free(data.data);
  3559. ]])], [[have_gnutls_sni=yes]], [[have_gnutls_sni=no]])
  3560. AC_MSG_RESULT([[$have_gnutls_sni]])
  3561. AC_CACHE_CHECK([[whether GnuTLS require libgcrypt initialisation]], [mhd_cv_gcrypt_required],
  3562. [
  3563. AC_COMPILE_IFELSE(
  3564. [
  3565. AC_LANG_PROGRAM(
  3566. [
  3567. #include <gnutls/gnutls.h>
  3568. ],
  3569. [
  3570. #if !defined(GNUTLS_VERSION_NUMBER) || GNUTLS_VERSION_NUMBER+0 <= 0x020c14
  3571. #error Old versions of GnuTLS require libgcript initialisation
  3572. choke me now
  3573. #endif
  3574. ]
  3575. )
  3576. ],
  3577. [[mhd_cv_gcrypt_required='no']], [[mhd_cv_gcrypt_required='yes']]
  3578. )
  3579. ]
  3580. )
  3581. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3582. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3583. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3584. LIBS="$SAVE_LIBS"
  3585. ],
  3586. [
  3587. AS_UNSET([GNUTLS_CPPFLAGS])
  3588. AS_UNSET([GNUTLS_LDFLAGS])
  3589. ]
  3590. )
  3591. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes" && test "x$have_gcrypt" = "xunknown"]],
  3592. [
  3593. AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no])
  3594. AS_IF([[test "x$have_gcrypt" = "xyes"]],
  3595. [
  3596. CFLAGS="${CFLAGS_ac} ${LIBGCRYPT_CFLAGS} ${user_CFLAGS}"
  3597. # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both
  3598. CPPFLAGS="${CPPFLAGS_ac} ${LIBGCRYPT_CFLAGS} ${user_CPPFLAGS}"
  3599. AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no], [AC_INCLUDES_DEFAULT])
  3600. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3601. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3602. ]
  3603. )
  3604. ]
  3605. )
  3606. AS_UNSET([[crypt_missing]])
  3607. AS_IF([[test "x$have_gnutls" = "xyes"]],
  3608. [
  3609. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes" && test "x$have_gcrypt" != "xyes"]],
  3610. [
  3611. crypt_missing="required libgcrypt"
  3612. AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])])
  3613. enable_https=no
  3614. MSG_HTTPS="no (lacking $crypt_missing)"
  3615. AS_UNSET([LIBGCRYPT_CFLAGS])
  3616. AS_UNSET([LIBGCRYPT_LIBS])
  3617. AS_UNSET([GNUTLS_CPPFLAGS])
  3618. AS_UNSET([GNUTLS_CFLAGS])
  3619. AS_UNSET([GNUTLS_LDFLAGS])
  3620. AS_UNSET([GNUTLS_LIBS])
  3621. ],
  3622. [
  3623. AC_DEFINE([[HTTPS_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTPS support.])
  3624. enable_https=yes
  3625. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  3626. [
  3627. MSG_HTTPS="yes (using libgnutls and libgcrypt)"
  3628. MHD_TLS_LIB_CPPFLAGS="$LIBGCRYPT_CFLAGS $GNUTLS_CPPFLAGS"
  3629. MHD_TLS_LIB_CFLAGS="$LIBGCRYPT_CFLAGS $GNUTLS_CFLAGS"
  3630. MHD_TLS_LIB_LDFLAGS="$GNUTLS_LDFLAGS"
  3631. MHD_TLS_LIBDEPS="$GNUTLS_LIBS $LIBGCRYPT_LIBS"
  3632. AC_DEFINE([[MHD_HTTPS_REQUIRE_GCRYPT]], [[1]], [Define to `1' if HTTPS require initialisation of libgcrypt])
  3633. ],
  3634. [
  3635. MSG_HTTPS="yes (using libgnutls)"
  3636. AS_UNSET([LIBGCRYPT_CFLAGS])
  3637. AS_UNSET([LIBGCRYPT_LIBS])
  3638. MHD_TLS_LIB_CPPFLAGS="$GNUTLS_CPPFLAGS"
  3639. MHD_TLS_LIB_CFLAGS="$GNUTLS_CFLAGS"
  3640. MHD_TLS_LIB_LDFLAGS="$GNUTLS_LDFLAGS"
  3641. MHD_TLS_LIBDEPS="$GNUTLS_LIBS"
  3642. ]
  3643. )
  3644. AS_IF([[ test "x$have_gnutls_pkgcfg" = "xyes" ]],
  3645. [ # remove GnuTLS from private libs in .pc file as it defined in Requires.private
  3646. MHD_REQ_PRIVATE='gnutls'
  3647. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  3648. [[MHD_LIBDEPS_PKGCFG="$LIBGCRYPT_LIBS $MHD_LIBDEPS_PKGCFG"]]
  3649. )
  3650. ],
  3651. [
  3652. MHD_REQ_PRIVATE=''
  3653. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  3654. [[MHD_LIBDEPS_PKGCFG="$LIBGCRYPT_LIBS $MHD_LIBDEPS_PKGCFG"]]
  3655. )
  3656. MHD_LIBDEPS_PKGCFG="$GNUTLS_LIBS $MHD_LIBDEPS_PKGCFG"
  3657. ])
  3658. ]
  3659. )
  3660. ],
  3661. [
  3662. crypt_missing="libgnutls"
  3663. AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])])
  3664. enable_https=no
  3665. MSG_HTTPS="no (lacking $crypt_missing)"
  3666. AS_UNSET([LIBGCRYPT_CFLAGS])
  3667. AS_UNSET([LIBGCRYPT_LIBS])
  3668. AS_UNSET([GNUTLS_CPPFLAGS])
  3669. AS_UNSET([GNUTLS_CFLAGS])
  3670. AS_UNSET([GNUTLS_LDFLAGS])
  3671. AS_UNSET([GNUTLS_LIBS])
  3672. ]
  3673. )
  3674. ],[
  3675. MSG_HTTPS="no (disabled)"
  3676. ])
  3677. #
  3678. # End of large unindented block
  3679. #
  3680. AC_MSG_CHECKING(whether to support HTTPS)
  3681. AC_MSG_RESULT([$MSG_HTTPS])
  3682. AM_CONDITIONAL([HAVE_GNUTLS], [[test "x$have_gnutls" = "xyes"]])
  3683. AM_CONDITIONAL([HAVE_GNUTLS_SNI], [[test "x$have_gnutls_sni" = "xyes"]])
  3684. AM_CONDITIONAL([ENABLE_HTTPS], [test "x$enable_https" = "xyes"])
  3685. AM_CONDITIONAL([HTTPS_REQUIRE_GCRYPT], [[test "x$enable_https" = "xyes" && test "x$mhd_cv_gcrypt_required" = "xyes"]])
  3686. AC_SUBST([GNUTLS_CPPFLAGS])
  3687. AC_SUBST([GNUTLS_CFLAGS])
  3688. AC_SUBST([GNUTLS_LDFLAGS])
  3689. AC_SUBST([GNUTLS_LIBS])
  3690. AS_VAR_IF([have_gnutls], ["yes"],
  3691. [
  3692. AC_CACHE_CHECK([for GnuTLS quirks], [mhd_cv_gnutls_mthread_broken],
  3693. [
  3694. mhd_cv_gnutls_mthread_broken="no"
  3695. AS_IF([test -r /etc/redhat-release],
  3696. [
  3697. AS_IF([$FGREP ' release 6.' /etc/redhat-release >/dev/null || $FGREP '(Santiago)' /etc/redhat-release >/dev/null],
  3698. [mhd_cv_gnutls_mthread_broken="found"],
  3699. )
  3700. ]
  3701. )
  3702. AS_VAR_IF([mhd_cv_gnutls_mthread_broken], ["no"],
  3703. [
  3704. AS_IF([command -v rpm >/dev/null],
  3705. [
  3706. AS_IF([test "r`rpm -E '%{rhel}' 2>/dev/null`" = "r6"],
  3707. [mhd_cv_gnutls_mthread_broken="found"],
  3708. )
  3709. ]
  3710. )
  3711. ]
  3712. )
  3713. ]
  3714. )
  3715. AC_CACHE_CHECK([for gnutls-cli binary], [mhd_cv_gnutls_cli],
  3716. [
  3717. mhd_cv_gnutls_cli="no"
  3718. AS_IF([command -v gnutls-cli >/dev/null 2>&1],
  3719. [AS_IF([AC_RUN_LOG([gnutls-cli --version >&2])], [mhd_cv_gnutls_cli="yes"])]
  3720. )
  3721. ]
  3722. )
  3723. ]
  3724. )
  3725. AM_CONDITIONAL([HAVE_GNUTLS_MTHREAD_BROKEN], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xfound"]])
  3726. AM_CONDITIONAL([USE_UPGRADE_TLS_TESTS], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xno" || test "x${mhd_cv_gnutls_cli}" = "xyes"]])
  3727. # optional: HTTP Basic Auth support. Enabled by default
  3728. AC_MSG_CHECKING([[whether to support HTTP Basic authentication]])
  3729. AC_ARG_ENABLE([bauth],
  3730. [AS_HELP_STRING([--disable-bauth],[disable HTTP Basic Authentication support])],
  3731. [enable_bauth=${enableval}],
  3732. [enable_bauth=yes])
  3733. AS_IF([[test "x$enable_bauth" != "xno"]],
  3734. [ enable_bauth=yes
  3735. AC_DEFINE([BAUTH_SUPPORT],[1],[Define to 1 if libmicrohttpd is compiled with Basic Auth support.]) ])
  3736. AM_CONDITIONAL([ENABLE_BAUTH], [test "x$enable_bauth" != "xno"])
  3737. AC_MSG_RESULT([[$enable_bauth]])
  3738. # optional: HTTP Digest Auth support. Enabled by default
  3739. AC_MSG_CHECKING([[whether to support HTTP Digest authentication]])
  3740. AC_ARG_ENABLE([dauth],
  3741. [AS_HELP_STRING([--disable-dauth], [disable HTTP Digest Authentication support])],
  3742. [enable_dauth="${enableval}"],
  3743. [enable_dauth="yes"])
  3744. AS_IF([[test "x$enable_dauth" != "xno"]],
  3745. [ enable_dauth=yes
  3746. AC_DEFINE([DAUTH_SUPPORT],[1],[Define to 1 if libmicrohttpd is compiled with Digest Auth support.]) ])
  3747. AM_CONDITIONAL([ENABLE_DAUTH], [test "x$enable_dauth" != "xno"])
  3748. AC_MSG_RESULT([[$enable_dauth]])
  3749. AS_VAR_IF([enable_dauth], ["yes"],
  3750. [
  3751. AC_MSG_CHECKING([[for Digest Authentication default nonce timeout value]])
  3752. AC_ARG_ENABLE([dauth-def-timeout],
  3753. [AS_HELP_STRING([--enable-dauth-def-timeout=NNN],
  3754. [set default Digest Auth nonce validity time to NNN seconds [90]])],
  3755. [enable_dauth_def_timeout="${enableval}"],
  3756. [enable_dauth_def_timeout=""]
  3757. )
  3758. AS_VAR_IF([enable_dauth_def_timeout], ["no"],
  3759. [
  3760. AC_MSG_WARN([Default Diget Auth nonce validity time cannot be disabled, --disable-dauth-def-timeout parameter is ignored])
  3761. enable_dauth_def_timeout=""
  3762. ]
  3763. )
  3764. AS_IF([test -z "${enable_dauth_def_timeout}"],
  3765. [
  3766. enable_dauth_def_timeout="90"
  3767. enable_dauth_def_timeout_MSG="${enable_dauth_def_timeout} seconds (default)"
  3768. ],
  3769. [
  3770. AS_IF([[test "x${enable_dauth_def_timeout}" = "x`echo ${enable_dauth_def_timeout}|${SED-sed} 's/[^0-9]//g'`" && \
  3771. test "${enable_dauth_def_timeout}" -ge "0" 2>/dev/null ]],[:],
  3772. [AC_MSG_ERROR([Invalid parameter --enable-dauth-def-timeout=${enable_dauth_def_timeout}. Timeout value must be a positive integer.])
  3773. ]
  3774. )
  3775. AC_COMPILE_IFELSE(
  3776. [
  3777. AC_LANG_PROGRAM([],
  3778. [[
  3779. static int arr[((int) 2) - 4 * (int)(${enable_dauth_def_timeout} != ((unsigned int)${enable_dauth_def_timeout}))];
  3780. (void) arr;
  3781. ]]
  3782. )
  3783. ],
  3784. [],
  3785. [AC_MSG_ERROR([The value specified by --enable-dauth-def-timeout=${enable_dauth_def_timeout} is too large.])]
  3786. )
  3787. enable_dauth_def_timeout_MSG="${enable_dauth_def_timeout} seconds (set by parameter)"
  3788. ]
  3789. )
  3790. AC_DEFINE_UNQUOTED([MHD_DAUTH_DEF_TIMEOUT_],[${enable_dauth_def_timeout}],
  3791. [The default HTTP Digest Auth default nonce timeout value (in seconds)])
  3792. AC_MSG_RESULT([[${enable_dauth_def_timeout_MSG}]])
  3793. AC_MSG_CHECKING([[for Digest Authentication default maximum nc value]])
  3794. AC_ARG_ENABLE([dauth-def-max-nc],
  3795. [AS_HELP_STRING([--enable-dauth-def-max-nc=NNN],
  3796. [set default Digest Auth maximum nc (nonce count) value to NNN [1000]])],
  3797. [enable_dauth_def_max_nc="${enableval}"],
  3798. [enable_dauth_def_max_nc=""]
  3799. )
  3800. AS_VAR_IF([enable_dauth_def_max_nc], ["no"],
  3801. [
  3802. AC_MSG_WARN([Default Diget Auth maximum nc cannot be disabled, --disable-dauth-def-max-nc parameter is ignored])
  3803. enable_dauth_def_max_nc=""
  3804. ]
  3805. )
  3806. AS_IF([test -z "${enable_dauth_def_max_nc}"],
  3807. [
  3808. enable_dauth_def_max_nc="1000"
  3809. enable_dauth_def_max_nc_MSG="${enable_dauth_def_max_nc} (default)"
  3810. ],
  3811. [
  3812. AS_IF([[test "x${enable_dauth_def_max_nc}" = "x`echo ${enable_dauth_def_max_nc}|${SED-sed} 's/[^0-9]//g'`" && \
  3813. test "${enable_dauth_def_max_nc}" -ge "0" 2>/dev/null ]],[:],
  3814. [AC_MSG_ERROR([Invalid parameter --enable-dauth-def-max-nc=${enable_dauth_def_max_nc}. The value must be a positive integer.])
  3815. ]
  3816. )
  3817. AC_COMPILE_IFELSE(
  3818. [
  3819. AC_LANG_PROGRAM(
  3820. [[
  3821. #include <stdint.h>
  3822. ]],
  3823. [[
  3824. static int arr[((int) 2) - 4 * (int)(${enable_dauth_def_max_nc} != ((uint32_t)${enable_dauth_def_max_nc}))];
  3825. (void) arr;
  3826. ]]
  3827. )
  3828. ],
  3829. [],
  3830. [AC_MSG_ERROR([The value specified by --enable-dauth-def-max-nc=${enable_dauth_def_max_nc} is too large.])]
  3831. )
  3832. enable_dauth_def_max_nc_MSG="${enable_dauth_def_max_nc} (set by parameter)"
  3833. ]
  3834. )
  3835. AC_DEFINE_UNQUOTED([MHD_DAUTH_DEF_MAX_NC_],[${enable_dauth_def_max_nc}],
  3836. [The default HTTP Digest Auth default maximum nc (nonce count) value])
  3837. AC_MSG_RESULT([[${enable_dauth_def_max_nc_MSG}]])
  3838. dauth_defs_MSG="timeout: ${enable_dauth_def_timeout_MSG}, max nc: ${enable_dauth_def_max_nc_MSG}"
  3839. ],
  3840. [
  3841. dauth_defs_MSG="N/A"
  3842. ]
  3843. )
  3844. AM_CONDITIONAL([HAVE_ANYAUTH],[test "x$enable_bauth" != "xno" || test "x$enable_dauth" != "xno"])
  3845. # optional: HTTP "Upgrade" support. Enabled by default
  3846. AC_MSG_CHECKING([[whether to support HTTP "Upgrade"]])
  3847. AC_ARG_ENABLE([[httpupgrade]],
  3848. [AS_HELP_STRING([[--disable-httpupgrade]], [disable HTTP "Upgrade" support])],
  3849. [AS_VAR_IF([[enable_httpupgrade]],[["no"]],[],[[enable_httpupgrade='yes']])],
  3850. [[enable_httpupgrade='yes']])
  3851. AS_VAR_IF([[enable_httpupgrade]],[["yes"]],
  3852. [
  3853. AC_DEFINE([[UPGRADE_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP Upgrade support.]) ])
  3854. AM_CONDITIONAL([ENABLE_UPGRADE], [[test "x$enable_httpupgrade" = "xyes"]])
  3855. AC_MSG_RESULT([[$enable_httpupgrade]])
  3856. # optional: HTTP cookie parsing support. Enabled by default
  3857. AC_MSG_CHECKING([[whether to support HTTP cookie parsing]])
  3858. AC_ARG_ENABLE([[cookie]],
  3859. [AS_HELP_STRING([[--disable-cookie]], [disable HTTP cookie parsing support])],
  3860. [AS_VAR_IF([[enable_cookie]],[["no"]],[],[[enable_cookie='yes']])],
  3861. [[enable_cookie='yes']])
  3862. AS_VAR_IF([[enable_cookie]],[["yes"]],
  3863. [
  3864. AC_DEFINE([[COOKIE_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP cookie parsing support.]) ])
  3865. AM_CONDITIONAL([ENABLE_COOKIE], [[test "x$enable_cookie" = "xyes"]])
  3866. AC_MSG_RESULT([[$enable_cookie]])
  3867. # optional: MD5 support for Digest Auth. Enabled by default.
  3868. AC_ARG_ENABLE([[md5]],
  3869. [AS_HELP_STRING([[--enable-md5=TYPE]],
  3870. [enable TYPE of MD5 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])],
  3871. [
  3872. AS_VAR_IF([enable_md5],["internal"],[enable_md5='builtin'])
  3873. AS_VAR_IF([enable_md5],["built-in"],[enable_md5='builtin'])
  3874. AS_VAR_IF([enable_dauth],["yes"],[],
  3875. [
  3876. AS_VAR_IF([enable_md5],["no"],[],
  3877. [
  3878. AC_MSG_WARN([The parameter --enable-md5=${enable_md5} is ignored as Digest Authentication is disabled])
  3879. enable_md5='no'
  3880. ]
  3881. )
  3882. ]
  3883. )
  3884. ], [[enable_md5="${enable_dauth}"]]
  3885. )
  3886. AS_CASE([${enable_md5}],[yes|tlslib],
  3887. [
  3888. AS_IF([test "x${enable_compact_code}" != "xno" || test "x$enable_md5" = "xtlslib"],
  3889. [
  3890. AS_IF([test "x$enable_https" = "xyes"],
  3891. [
  3892. AC_CACHE_CHECK([whether GnuTLS supports MD5 hashing],[mhd_cv_gnutls_md5],
  3893. [
  3894. CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}"
  3895. CPPFLAGS="${CPPFLAGS_ac} ${MHD_TLS_LIB_CPPFLAGS} ${user_CPPFLAGS}"
  3896. CFLAGS="${CFLAGS_ac} ${MHD_TLS_LIB_CFLAGS} ${user_CFLAGS}"
  3897. LDFLAGS="${LDFLAGS_ac} ${MHD_TLS_LIB_LDFLAGS} ${user_LDFLAGS}"
  3898. save_LIBS="$LIBS"
  3899. LIBS="${MHD_TLS_LIBDEPS} ${LIBS}"
  3900. AC_LINK_IFELSE(
  3901. [
  3902. AC_LANG_PROGRAM(
  3903. [[
  3904. #include <gnutls/crypto.h>
  3905. ]],
  3906. [[
  3907. gnutls_hash_hd_t hash_handle;
  3908. unsigned char digest[16];
  3909. int exit_code;
  3910. if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_MD5))
  3911. {
  3912. if (0 == gnutls_hash(hash_handle, "", 1))
  3913. {
  3914. gnutls_hash_output(hash_handle, digest);
  3915. if (0x93 == digest[0])
  3916. exit_code = 0;
  3917. else
  3918. exit_code = 7;
  3919. }
  3920. else
  3921. exit_code = 5;
  3922. gnutls_hash_deinit(hash_handle, (void *)0);
  3923. }
  3924. else
  3925. exit_code = 2;
  3926. if (exit_code)
  3927. return exit_code;
  3928. ]]
  3929. )
  3930. ],
  3931. [mhd_cv_gnutls_md5='yes'],[mhd_cv_gnutls_md5='no']
  3932. )
  3933. LIBS="${save_LIBS}"
  3934. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3935. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3936. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3937. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3938. ]
  3939. )
  3940. AS_VAR_IF([mhd_cv_gnutls_md5],["no"],
  3941. [
  3942. AS_VAR_IF([enable_md5],["tlslib"],
  3943. [AC_MSG_FAILURE([TLS library MD5 implementation is not available])]
  3944. )
  3945. enable_md5="builtin"
  3946. ],
  3947. [enable_md5="tlslib"]
  3948. )
  3949. ],
  3950. [
  3951. AS_VAR_IF([enable_md5],["tlslib"],
  3952. [AC_MSG_ERROR([HTTPS is not enabled, TLS library MD5 implementation cannot be used])]
  3953. )
  3954. enable_md5="builtin"
  3955. ]
  3956. )
  3957. ],
  3958. [
  3959. enable_md5="builtin"
  3960. ]
  3961. )
  3962. ]
  3963. )
  3964. AC_MSG_CHECKING([[whether to support MD5]])
  3965. AS_UNSET([enable_md5_MSG])
  3966. AS_CASE([${enable_md5}],
  3967. [builtin],[enable_md5_MSG='yes, built-in'],
  3968. [tlslib],[enable_md5_MSG='yes, external (TLS library)'],
  3969. [no],[enable_md5_MSG='no'],
  3970. [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])],
  3971. [AC_MSG_ERROR([Unrecognized parameter --enable-md5=${enable_md5}])]
  3972. )
  3973. AS_IF([test "x${enable_md5}" = "xbuiltin" || test "x${enable_md5}" = "xtlslib" ],
  3974. [
  3975. AC_DEFINE([[MHD_MD5_SUPPORT]],[[1]],
  3976. [Define to 1 if libmicrohttpd is compiled with MD5 hashing support.])
  3977. ]
  3978. )
  3979. AS_IF([test "x${enable_md5}" = "xtlslib" ],
  3980. [
  3981. AC_DEFINE([[MHD_MD5_TLSLIB]],[[1]],
  3982. [Define to 1 if libmicrohttpd is compiled with MD5 hashing by TLS library.])
  3983. ]
  3984. )
  3985. AM_CONDITIONAL([ENABLE_MD5], [[test "x${enable_md5}" = "xbuiltin" || test "x${enable_md5}" = "xtlslib" ]])
  3986. AM_CONDITIONAL([ENABLE_MD5_EXT], [[test "x${enable_md5}" = "xtlslib" ]])
  3987. AC_MSG_RESULT([[${enable_md5_MSG}]])
  3988. # optional: SHA-256 support for Digest Auth. Enabled by default.
  3989. AC_ARG_ENABLE([[sha256]],
  3990. [AS_HELP_STRING([[--enable-sha256=TYPE]],
  3991. [enable TYPE of SHA-256 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])],
  3992. [
  3993. AS_VAR_IF([enable_sha256],["internal"],[enable_sha256='builtin'])
  3994. AS_VAR_IF([enable_sha256],["built-in"],[enable_sha256='builtin'])
  3995. AS_VAR_IF([enable_dauth],["yes"],[],
  3996. [
  3997. AS_VAR_IF([enable_sha256],["no"],[],
  3998. [
  3999. AC_MSG_WARN([The parameter --enable-sha256=${enable_sha256} is ignored as Digest Authentication is disabled])
  4000. enable_sha256='no'
  4001. ]
  4002. )
  4003. ]
  4004. )
  4005. ], [[enable_sha256="${enable_dauth}"]]
  4006. )
  4007. AS_CASE([${enable_sha256}],[yes|tlslib],
  4008. [
  4009. AS_IF([test "x${enable_compact_code}" != "xno" || test "x$enable_sha256" = "xtlslib"],
  4010. [
  4011. AS_IF([test "x$enable_https" = "xyes"],
  4012. [
  4013. AC_CACHE_CHECK([whether GnuTLS supports sha256 hashing],[mhd_cv_gnutls_sha256],
  4014. [
  4015. CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}"
  4016. CPPFLAGS="${CPPFLAGS_ac} ${MHD_TLS_LIB_CPPFLAGS} ${user_CPPFLAGS}"
  4017. CFLAGS="${CFLAGS_ac} ${MHD_TLS_LIB_CFLAGS} ${user_CFLAGS}"
  4018. LDFLAGS="${LDFLAGS_ac} ${MHD_TLS_LIB_LDFLAGS} ${user_LDFLAGS}"
  4019. save_LIBS="$LIBS"
  4020. LIBS="${MHD_TLS_LIBDEPS} ${LIBS}"
  4021. AC_LINK_IFELSE(
  4022. [
  4023. AC_LANG_PROGRAM(
  4024. [[
  4025. #include <gnutls/crypto.h>
  4026. ]],
  4027. [[
  4028. gnutls_hash_hd_t hash_handle;
  4029. unsigned char digest[32];
  4030. int exit_code;
  4031. if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_SHA256))
  4032. {
  4033. if (0 == gnutls_hash(hash_handle, "", 1))
  4034. {
  4035. gnutls_hash_output(hash_handle, digest);
  4036. if (0x6e == digest[0])
  4037. exit_code = 0;
  4038. else
  4039. exit_code = 7;
  4040. }
  4041. else
  4042. exit_code = 5;
  4043. gnutls_hash_deinit(hash_handle, (void *)0);
  4044. }
  4045. else
  4046. exit_code = 2;
  4047. if (exit_code)
  4048. return exit_code;
  4049. ]]
  4050. )
  4051. ],
  4052. [mhd_cv_gnutls_sha256='yes'],[mhd_cv_gnutls_sha256='no']
  4053. )
  4054. LIBS="${save_LIBS}"
  4055. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  4056. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  4057. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  4058. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  4059. ]
  4060. )
  4061. AS_VAR_IF([mhd_cv_gnutls_sha256],["no"],
  4062. [
  4063. AS_VAR_IF([enable_sha256],["tlslib"],
  4064. [AC_MSG_FAILURE([TLS library SHA-256 implementation is not available])]
  4065. )
  4066. enable_sha256="builtin"
  4067. ],
  4068. [enable_sha256="tlslib"]
  4069. )
  4070. ],
  4071. [
  4072. AS_VAR_IF([enable_sha256],["tlslib"],
  4073. [AC_MSG_ERROR([HTTPS is not enabled, TLS library SHA-256 implementation cannot be used])]
  4074. )
  4075. enable_sha256="builtin"
  4076. ]
  4077. )
  4078. ],
  4079. [
  4080. enable_sha256="builtin"
  4081. ]
  4082. )
  4083. ]
  4084. )
  4085. AC_MSG_CHECKING([[whether to support SHA-256]])
  4086. AS_UNSET([enable_sha256_MSG])
  4087. AS_CASE([${enable_sha256}],
  4088. [builtin],[enable_sha256_MSG='yes, built-in'],
  4089. [tlslib],[enable_sha256_MSG='yes, external (TLS library)'],
  4090. [no],[enable_sha256_MSG='no'],
  4091. [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])],
  4092. [AC_MSG_ERROR([Unrecognized parameter --enable-sha256=${enable_sha256}])]
  4093. )
  4094. AS_IF([test "x${enable_sha256}" = "xbuiltin" || test "x${enable_sha256}" = "xtlslib" ],
  4095. [
  4096. AC_DEFINE([[MHD_SHA256_SUPPORT]],[[1]],
  4097. [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing support.])
  4098. ]
  4099. )
  4100. AS_IF([test "x${enable_sha256}" = "xtlslib" ],
  4101. [
  4102. AC_DEFINE([[MHD_SHA256_TLSLIB]],[[1]],
  4103. [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by TLS library.])
  4104. ]
  4105. )
  4106. AM_CONDITIONAL([ENABLE_SHA256], [[test "x${enable_sha256}" = "xbuiltin" || test "x${enable_sha256}" = "xtlslib" ]])
  4107. AM_CONDITIONAL([ENABLE_SHA256_EXT], [[test "x${enable_sha256}" = "xtlslib" ]])
  4108. AC_MSG_RESULT([[${enable_sha256_MSG}]])
  4109. # optional: SHA-512/256 support for Digest Auth. Enabled by default.
  4110. AC_ARG_ENABLE([[sha512-256]],
  4111. [AS_HELP_STRING([[--disable-sha512-256]],
  4112. [disable SHA-512/256 hashing support for Digest Authentication])],
  4113. [
  4114. AS_VAR_IF([[enable_sha512_256]],[["yes"]],
  4115. [
  4116. AS_VAR_IF([enable_dauth],["yes"],[],
  4117. [
  4118. AC_MSG_WARN([The parameter --enable-sha512-256 is ignored as Digest Authentication is disabled])
  4119. enable_sha512_256='no'
  4120. ]
  4121. )
  4122. ],[[enable_sha512_256='no']]
  4123. )
  4124. ], [[enable_sha512_256="${enable_dauth}"]]
  4125. )
  4126. AC_MSG_CHECKING([[whether to support SHA-512/256]])
  4127. AS_UNSET([enable_sha512_256_MSG])
  4128. AS_CASE([${enable_sha512_256}],
  4129. [yes],[enable_sha512_256_MSG='yes, built-in'],
  4130. [no],[enable_sha512_256_MSG='no'],
  4131. [AC_MSG_ERROR([Unrecognized parameter --enable-sha512-256=${enable_sha512_256}])]
  4132. )
  4133. AS_VAR_IF([[enable_sha512_256]],[["yes"]],
  4134. [
  4135. AC_DEFINE([[MHD_SHA512_256_SUPPORT]],[[1]],
  4136. [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing support.])
  4137. ]
  4138. )
  4139. AM_CONDITIONAL([ENABLE_SHA512_256], [[test "x${enable_sha512_256}" = "xyes"]])
  4140. AC_MSG_RESULT([[${enable_sha512_256_MSG}]])
  4141. AS_IF([test "x$enable_dauth" != "xno"],
  4142. [
  4143. AS_IF([test "x${enable_md5}" = "xno" && test "x${enable_sha256}" = "xno" && test "x${enable_sha512_256}" != "xyes"],
  4144. [AC_MSG_ERROR([At least one hashing algorithm must be enabled if Digest Auth is enabled])]
  4145. )
  4146. ]
  4147. )
  4148. AC_CACHE_CHECK([[for calloc()]], [[mhd_cv_have_func_calloc]],
  4149. [
  4150. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  4151. #include <stdlib.h>
  4152. ]],[[void * ptr = calloc(1, 2); if (ptr) return 1;]])
  4153. ],
  4154. [[mhd_cv_have_func_calloc='yes']],
  4155. [[mhd_cv_have_func_calloc='no']]
  4156. )
  4157. ]
  4158. )
  4159. AS_VAR_IF([[mhd_cv_have_func_calloc]], [["yes"]],
  4160. [AC_DEFINE([[HAVE_CALLOC]], [[1]], [Define to 1 if you have the usable `calloc' function.])])
  4161. # Some systems have IPv6 disabled in kernel at run-time
  4162. AS_IF([[test "x${mhd_cv_have_inet6}" = "xyes" && test "x${cross_compiling}" = "xno"]],
  4163. [
  4164. AC_CACHE_CHECK([whether IPv6 could be used for testing],[mhd_cv_ipv6_for_testing],
  4165. [
  4166. AC_RUN_IFELSE(
  4167. [
  4168. AC_LANG_SOURCE([[
  4169. #ifdef HAVE_UNISTD_H
  4170. #include <unistd.h>
  4171. #endif
  4172. #ifdef HAVE_SYS_TYPES_H
  4173. #include <sys/types.h>
  4174. #endif
  4175. #ifdef HAVE_SYS_SOCKET_H
  4176. #include <sys/socket.h>
  4177. #endif
  4178. #ifdef HAVE_WINSOCK2_H
  4179. #include <winsock2.h>
  4180. #endif
  4181. #ifdef HAVE_WS2TCPIP_H
  4182. #include <ws2tcpip.h>
  4183. #endif
  4184. #ifdef HAVE_NETINET_IN_H
  4185. #include <netinet/in.h>
  4186. #endif
  4187. #ifdef HAVE_NETINET_IP_H
  4188. #include <netinet/ip.h>
  4189. #endif
  4190. #ifdef HAVE_ARPA_INET_H
  4191. #include <arpa/inet.h>
  4192. #endif
  4193. #ifdef HAVE_NETINET_TCP_H
  4194. #include <netinet/tcp.h>
  4195. #endif
  4196. static void zr_mem(void *ptr, socklen_t size)
  4197. { char *mem = ptr; while(size--) {mem[0] = 0; mem++;} }
  4198. int main(void)
  4199. {
  4200. int ret = 30;
  4201. struct sockaddr_in6 sa;
  4202. #if !defined(_WIN32) || defined(__CYGWIN__)
  4203. int sckt;
  4204. const int invld_sckt = -1;
  4205. #else
  4206. SOCKET sckt;
  4207. const SOCKET invld_sckt = INVALID_SOCKET;
  4208. WSADATA wsa_data;
  4209. WSAStartup(MAKEWORD(2, 2), &wsa_data);
  4210. #endif
  4211. zr_mem(&sa, sizeof(sa));
  4212. sa.sin6_family = AF_INET6;
  4213. sa.sin6_port = 0;
  4214. sa.sin6_addr = in6addr_loopback;
  4215. #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
  4216. sa.sin6_len = sizeof(sa);
  4217. #endif
  4218. sckt = socket (PF_INET6, SOCK_STREAM, 0);
  4219. if (invld_sckt != sckt)
  4220. {
  4221. if (0 == bind (sckt, (struct sockaddr *)&sa, sizeof(sa)))
  4222. {
  4223. if (0 == listen (sckt, 1))
  4224. ret = 0;
  4225. else
  4226. ret = 1; /* listen() failed */
  4227. } else ret = 2; /* bind() failed */
  4228. #if !defined(_WIN32) || defined(__CYGWIN__)
  4229. close (sckt);
  4230. #else
  4231. closesocket (sckt);
  4232. #endif
  4233. } else ret = 3; /* socket() failed */
  4234. #if defined(_WIN32) && !defined(__CYGWIN__)
  4235. WSACleanup();
  4236. #endif
  4237. return ret;
  4238. }
  4239. ]])
  4240. ], [[mhd_cv_ipv6_for_testing="yes"]], [[mhd_cv_ipv6_for_testing="no"]], [[mhd_cv_ipv6_for_testing="no"]]
  4241. )
  4242. ]
  4243. )
  4244. ]
  4245. )
  4246. AS_VAR_IF([mhd_cv_ipv6_for_testing],["yes"],
  4247. [AC_DEFINE([[USE_IPV6_TESTING]], [[1]], [Define to 1 if your kernel supports IPv6 and IPv6 is enabled and useful for testing.])]
  4248. )
  4249. AS_VAR_IF([enable_tools],["yes"],
  4250. [
  4251. AC_CHECK_HEADERS([features.h sys/pstat.h vxCpuLib.h],[],[],[AC_INCLUDES_DEFAULT])
  4252. AC_CHECK_DECLS(
  4253. [_SC_NPROCESSORS_ONLN,_SC_NPROC_ONLN,_SC_CRAY_NCPU,_SC_NPROCESSORS_CONF,CTL_HW,HW_NCPUONLINE,HW_NCPU,HW_AVAILCPU],
  4254. [],[],
  4255. [[
  4256. #ifdef HAVE_SYS_TYPES_H
  4257. #include <sys/types.h>
  4258. #endif /* HAVE_SYS_TYPES_H */
  4259. #ifdef HAVE_SYS_PARAM_H
  4260. #include <sys/param.h>
  4261. #endif /* HAVE_SYS_PARAM_H */
  4262. #ifdef HAVE_SYS_SYSCTL_H
  4263. #include <sys/sysctl.h>
  4264. #endif /* HAVE_SYS_SYSCTL_H */
  4265. #ifdef HAVE_UNISTD_H
  4266. #include <unistd.h>
  4267. #endif /* HAVE_UNISTD_H */
  4268. ]]
  4269. )
  4270. MHD_CHECK_FUNC([pstat_getdynamic],[[
  4271. #include <sys/param.h>
  4272. #include <sys/pstat.h>
  4273. ]],
  4274. [[
  4275. struct pst_dynamic psd_data;
  4276. i][f (1 != pstat_getdynamic(&psd_data, sizeof(psd_data), (size_t)1, 0))
  4277. return 2;
  4278. i][f (0 >= psd_data.psd_proc_cnt)
  4279. return 3;
  4280. ]]
  4281. )
  4282. MHD_CHECK_FUNC([vxCpuEnabledGet],[[#include <vxCpuLib.h>]],
  4283. [[
  4284. cpuset_t enb_set;
  4285. enb_set = vxCpuEnabledGet();
  4286. (void) enb_set;
  4287. ]]
  4288. )
  4289. AC_CHECK_HEADERS([sched.h sys/_cpuset.h sys/cpuset.h],[],[],[AC_INCLUDES_DEFAULT])
  4290. # glibc / Linux kernel
  4291. MHD_CHECK_FUNC([getpid],[[
  4292. #ifdef HAVE_SYS_TYPES_H
  4293. #include <sys/types.h>
  4294. #endif /* HAVE_SYS_TYPES_H */
  4295. #include <unistd.h>
  4296. ]],
  4297. [[
  4298. pid_t cur_pid;
  4299. cur_pid = getpid();
  4300. (void) &cur_pid; /* Mute possible warning */
  4301. ]],
  4302. [
  4303. MHD_CHECK_FUNC([sched_getaffinity],[[
  4304. #ifdef HAVE_SYS_TYPES_H
  4305. #include <sys/types.h>
  4306. #endif /* HAVE_SYS_TYPES_H */
  4307. #include <unistd.h>
  4308. #include <sched.h>
  4309. ]],
  4310. [[
  4311. cpu_set_t cur_set;
  4312. i][f (0 != sched_getaffinity(getpid(), sizeof(cur_set), &cur_set))
  4313. return 2;
  4314. i][f (0 == CPU_SET (0, &cur_set))
  4315. return 3; /* Actually this could be a valid result */
  4316. ]],
  4317. [
  4318. MHD_CHECK_FUNC([CPU_COUNT],[[
  4319. #include <stddef.h>
  4320. #include <sched.h>
  4321. ]],
  4322. [[
  4323. cpu_set_t cur_set;
  4324. CPU_ZERO(&cur_set);
  4325. i][f (0 != CPU_COUNT(&cur_set))
  4326. return 2;
  4327. ]],
  4328. [
  4329. MHD_CHECK_FUNC([CPU_COUNT_S],[[
  4330. #include <stddef.h>
  4331. #include <sched.h>
  4332. ]],
  4333. [[
  4334. static const unsigned int set_size_cpus = 2048u;
  4335. const size_t set_size_bytes = (size_t) CPU_ALLOC_SIZE(set_size_cpus);
  4336. cpu_set_t *p_set;
  4337. p_set = CPU_ALLOC(set_size_cpus);
  4338. i][f (!p_set)
  4339. return 2;
  4340. CPU_ZERO_S(set_size_bytes, p_set);
  4341. i][f (0 != CPU_COUNT_S(set_size_bytes, p_set))
  4342. {
  4343. CPU_FREE(p_set);
  4344. return 3;
  4345. }
  4346. CPU_FREE(p_set);
  4347. ]],
  4348. [AC_CHECK_DECLS([CPU_SETSIZE],[],[],[#include <sched.h>])]
  4349. )
  4350. ]
  4351. )
  4352. ]
  4353. )
  4354. # NetBSD
  4355. # Should work only with -lrt, but actually works without it.
  4356. MHD_CHECK_FUNC([sched_getaffinity_np],[[
  4357. #ifdef HAVE_SYS_TYPES_H
  4358. #include <sys/types.h>
  4359. #endif /* HAVE_SYS_TYPES_H */
  4360. #include <unistd.h>
  4361. #include <sched.h>
  4362. ]],
  4363. [[
  4364. cpuset_t *cpuset_ptr;
  4365. cpuid_t cpu_num = 0;
  4366. cpuset_ptr = cpuset_create();
  4367. i][f (!cpuset_ptr)
  4368. return 2;
  4369. i][f (0 != sched_getaffinity_np(getpid(), cpuset_size(cpuset_ptr), cpuset_ptr))
  4370. {
  4371. cpuset_destroy(cpuset_ptr);
  4372. return 3;
  4373. }
  4374. i][f (0 >= cpuset_isset(cpu_num, cpuset_ptr))
  4375. {
  4376. cpuset_destroy(cpuset_ptr);
  4377. return 4; /* Actually this could be a valid result */
  4378. }
  4379. cpuset_destroy(cpuset_ptr);
  4380. ]]
  4381. )
  4382. ]
  4383. )
  4384. # FreeBSD
  4385. MHD_CHECK_FUNC([cpuset_getaffinity],[[
  4386. #ifdef HAVE_SYS_PARAM_H
  4387. #include <sys/param.h>
  4388. #endif /* HAVE_SYS_PARAM_H */
  4389. #include <sys/cpuset.h>
  4390. ]],
  4391. [[
  4392. cpuset_t cur_mask;
  4393. i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, sizeof(cur_mask), &cur_mask))
  4394. return 2;
  4395. ]],
  4396. [
  4397. MHD_CHECK_FUNC([CPU_COUNT],[[
  4398. #ifdef HAVE_SYS_PARAM_H
  4399. #include <sys/param.h>
  4400. #endif /* HAVE_SYS_PARAM_H */
  4401. #ifdef HAVE_SYS__CPUSET_H
  4402. #include <sys/_cpuset.h>
  4403. #endif /* HAVE_SYS_PARAM_H */
  4404. #include <sys/cpuset.h>
  4405. ]],
  4406. [[
  4407. cpuset_t test_mask;
  4408. CPU_ZERO(&test_mask);
  4409. i][f (0 != CPU_COUNT(&test_mask))
  4410. return 2;
  4411. ]],
  4412. [
  4413. MHD_CHECK_FUNC([CPU_COUNT_S],[[
  4414. #ifdef HAVE_SYS_PARAM_H
  4415. #include <sys/param.h>
  4416. #endif /* HAVE_SYS_PARAM_H */
  4417. #ifdef HAVE_SYS__CPUSET_H
  4418. #include <sys/_cpuset.h>
  4419. #endif /* HAVE_SYS_PARAM_H */
  4420. #include <sys/cpuset.h>
  4421. ]],
  4422. [[
  4423. static const unsigned int max_cpu_num = 2048u;
  4424. cpuset_t *mask_ptr;
  4425. mask_ptr = CPU_ALLOC(max_cpu_num);
  4426. i][f (! mask_ptr)
  4427. return 2;
  4428. i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1,
  4429. CPU_ALLOC_SIZE(max_cpu_num), mask_ptr))
  4430. {
  4431. CPU_FREE(mask_ptr);
  4432. return 3;
  4433. }
  4434. i][f (0 == CPU_COUNT_S(CPU_ALLOC_SIZE(max_cpu_num), &test_mask))
  4435. {
  4436. CPU_FREE(mask_ptr);
  4437. return 4;
  4438. }
  4439. CPU_FREE(mask_ptr);
  4440. ]]
  4441. )
  4442. ]
  4443. )
  4444. ]
  4445. )
  4446. AS_VAR_IF([mhd_cv_have_func_CPU_COUNT_S],["yes"],
  4447. [
  4448. AC_CACHE_CHECK([whether CPU_COUNT_S() expects max CPU number as 'size' parameter],[mhd_cv_func_cpu_count_s_cpus],
  4449. [
  4450. AS_VAR_IF([cross-compiling],["yes"],[mhd_cv_func_cpu_count_s_cpus="assuming no"],
  4451. [
  4452. AC_LINK_IFELSE(
  4453. [
  4454. AC_LANG_PROGRAM([[
  4455. #ifdef HAVE_SYS_TYPES_H
  4456. #include <sys/types.h>
  4457. #endif /* HAVE_SYS_TYPES_H */
  4458. #ifdef HAVE_SYS_PARAM_H
  4459. #include <sys/param.h>
  4460. #endif /* HAVE_SYS_PARAM_H */
  4461. #ifdef HAVE_SYS__CPUSET_H
  4462. #include <sys/_cpuset.h>
  4463. #endif /* HAVE_SYS_PARAM_H */
  4464. #ifdef HAVE_SYS_CPUSET_H
  4465. #include <sys/cpuset.h>
  4466. #endif /* HAVE_SYS_CPUSET_H */
  4467. #ifdef HAVE_STDDEF_H
  4468. #include <stddef.h>
  4469. #endif /* HAVE_STDDEF_H */
  4470. #ifdef HAVE_UNISTD_H
  4471. #include <unistd.h>
  4472. #endif /* HAVE_UNISTD_H */
  4473. #ifdef HAVE_SCHED_H
  4474. #include <sched.h>
  4475. #endif /* HAVE_SCHED_H */
  4476. #include <stdio.h>
  4477. #ifdef HAVE_SCHED_GETAFFINITY
  4478. #define TEST_CPUSET_TYPE cpu_set_t
  4479. #else /* ! HAVE_SCHED_GETAFFINITY */
  4480. #define TEST_CPUSET_TYPE cpuset_t
  4481. #endif /* ! HAVE_SCHED_GETAFFINITY */
  4482. ]],
  4483. [[
  4484. TEST_CPUSET_TYPE *p_testset;
  4485. /* The size of the cpuset that is larger then the test cpuset (in CPUs) */
  4486. static const unsigned int testset_size_oversized_cpus = (8 * sizeof(long)) * 1024;
  4487. const size_t testset_size_oversized_bytes = CPU_ALLOC_SIZE(testset_size_oversized_cpus);
  4488. /* The size of the test cpuset in number of CPUs */
  4489. const unsigned int testset_size_cpus = (unsigned int) testset_size_oversized_bytes;
  4490. /* The size of the test cpuset in bytes */
  4491. const size_t testset_size_bytes = CPU_ALLOC_SIZE(testset_size_cpus);
  4492. /* The last one CPU in the test set */
  4493. const unsigned int test_cpu_num1 = testset_size_cpus - 1;
  4494. /* The penultimate CPU in the test set */
  4495. const unsigned int test_cpu_num2 = testset_size_cpus - 2;
  4496. /* The CPU numbers that should be cleared */
  4497. const unsigned int test_cpu_clear1 = testset_size_cpus - 3;
  4498. const unsigned int test_cpu_clear2 = testset_size_cpus - 4;
  4499. unsigned int count_res;
  4500. int ret = 0;
  4501. /* Allocate oversize area to ensure that memory outside the buffer is not used */
  4502. p_testset = CPU_ALLOC(testset_size_oversized_cpus);
  4503. if (! p_testset)
  4504. {
  4505. fprintf (stderr, "Error allocating memory.\n");
  4506. return 99;
  4507. }
  4508. /* Set the some CPU numbers and then clear them */
  4509. CPU_SET_S(test_cpu_clear1, testset_size_bytes, p_testset);
  4510. CPU_SET_S(test_cpu_clear2, testset_size_bytes, p_testset);
  4511. CPU_ZERO_S(testset_size_bytes, p_testset);
  4512. /* Set two CPUs on */
  4513. CPU_SET_S(test_cpu_num1, testset_size_bytes, p_testset);
  4514. CPU_SET_S(test_cpu_num2, testset_size_bytes, p_testset);
  4515. count_res = (unsigned int) CPU_COUNT_S(testset_size_bytes, p_testset);
  4516. if (0 == count_res)
  4517. {
  4518. fprintf (stderr, "Full cpuset cannot be read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
  4519. /* Set the some CPU numbers and then clear them */
  4520. CPU_SET_S(test_cpu_clear1, testset_size_cpus, p_testset);
  4521. CPU_SET_S(test_cpu_clear2, testset_size_cpus, p_testset);
  4522. CPU_ZERO_S(testset_size_cpus, p_testset);
  4523. /* Set two CPUs on */
  4524. CPU_SET_S(test_cpu_num1, testset_size_cpus, p_testset);
  4525. CPU_SET_S(test_cpu_num2, testset_size_cpus, p_testset);
  4526. count_res = (unsigned int) CPU_COUNT_S(testset_size_cpus, p_testset);
  4527. if (2 == count_res)
  4528. {
  4529. fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() only when using the maximum CPU number as the size parameter.\n");
  4530. ret = 3;
  4531. }
  4532. else
  4533. {
  4534. fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the maximum CPU number as the size parameter.\n");
  4535. fprintf (stderr, "Number of 'enabled' CPUs: 2\n");
  4536. fprintf (stderr, "Number of counted CPUs: %u\n", count_res);
  4537. fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n");
  4538. ret = 70;
  4539. }
  4540. }
  4541. else if (2 == count_res)
  4542. {
  4543. fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
  4544. }
  4545. else
  4546. {
  4547. fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
  4548. fprintf (stderr, "Number of 'enabled' CPUs: 2\n");
  4549. fprintf (stderr, "Number of counted CPUs: %u\n", count_res);
  4550. fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n");
  4551. ret = 71;
  4552. }
  4553. CPU_FREE(p_testset);
  4554. if (0 != ret)
  4555. return ret;
  4556. ]]
  4557. )
  4558. ],
  4559. [
  4560. AM_RUN_LOG([./conftest$EXEEXT])
  4561. count_test_res=$?
  4562. AS_IF([test $count_test_res -eq 0],[mhd_cv_func_cpu_count_s_cpus="no"],
  4563. [test $count_test_res -eq 3],[mhd_cv_func_cpu_count_s_cpus="yes"],
  4564. [
  4565. AC_MSG_WARN([Unexpected value returned by CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}])
  4566. mhd_cv_func_cpu_count_s_cpus="assuming no"
  4567. ]
  4568. )
  4569. ],
  4570. [
  4571. AC_MSG_WARN([Cannot build CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}])
  4572. mhd_cv_func_cpu_count_s_cpus="assuming no"
  4573. ]
  4574. )
  4575. ]
  4576. )
  4577. ]
  4578. )
  4579. AS_VAR_IF([mhd_cv_func_cpu_count_s_cpus],["yes"],
  4580. [AC_DEFINE([MHD_FUNC_CPU_COUNT_S_GETS_CPUS],[1],
  4581. [Define to '1' if CPU_COUNT_S() function expects max CPU number as 'size' parameter])
  4582. ]
  4583. )
  4584. ]
  4585. )
  4586. ]
  4587. )
  4588. # Check for fork() and waitpid(). They are used for tests.
  4589. AC_MSG_CHECKING([[for fork()]])
  4590. mhd_have_fork_waitpid='no'
  4591. AC_LINK_IFELSE(
  4592. [
  4593. AC_LANG_PROGRAM(
  4594. [[
  4595. #ifdef HAVE_SYS_TYPES_H
  4596. #include <sys/types.h>
  4597. #endif
  4598. #ifdef HAVE_UNISTD_H
  4599. #include <unistd.h>
  4600. #endif
  4601. ]], [[
  4602. pid_t p = fork ();
  4603. if (0 == p)
  4604. return 1;
  4605. ]])
  4606. ], [
  4607. AC_DEFINE([[HAVE_FORK]], [[1]], [Define to 1 if you have the usable `fork' function.])
  4608. AC_MSG_RESULT([[yes]])
  4609. AC_MSG_CHECKING([[for waitpid()]])
  4610. AC_LINK_IFELSE(
  4611. [
  4612. AC_LANG_PROGRAM(
  4613. [[
  4614. #ifdef HAVE_SYS_TYPES_H
  4615. #include <sys/types.h>
  4616. #endif
  4617. #ifdef HAVE_UNISTD_H
  4618. #include <unistd.h>
  4619. #endif
  4620. #include <sys/wait.h>
  4621. ]], [[
  4622. pid_t p = fork ();
  4623. if (0 == p)
  4624. return 1;
  4625. waitpid (p, (void*)0, 0)
  4626. ]])
  4627. ], [
  4628. AC_DEFINE([[HAVE_WAITPID]], [[1]], [Define to 1 if you have the usable `waitpid' function.])
  4629. AC_MSG_RESULT([[yes]])
  4630. mhd_have_fork_waitpid='yes'
  4631. ],[
  4632. AC_MSG_RESULT([[no]])
  4633. ])
  4634. ],[
  4635. AC_MSG_RESULT([[no]])
  4636. ])
  4637. AM_CONDITIONAL([HAVE_FORK_WAITPID], [test "x$mhd_have_fork_waitpid" = "xyes"])
  4638. # gcov compilation
  4639. AC_MSG_CHECKING(whether to compile with support for code coverage analysis)
  4640. AC_ARG_ENABLE([coverage],
  4641. AS_HELP_STRING([--enable-coverage],
  4642. [compile the library with code coverage support]),
  4643. [use_gcov=${enableval}],
  4644. [use_gcov=no])
  4645. AC_MSG_RESULT($use_gcov)
  4646. AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"])
  4647. AX_COUNT_CPUS
  4648. AC_SUBST([MHD_REAL_CPU_COUNT],[${CPU_COUNT}])
  4649. AM_SUBST_NOTMAKE([MHD_REAL_CPU_COUNT])
  4650. AC_MSG_CHECKING([for number of CPU cores to use in tests])
  4651. AS_VAR_IF([use_heavy_tests], ["yes"],
  4652. [
  4653. # Enable usage of many core if heavy tests are enabled
  4654. AS_IF([[test "$CPU_COUNT" -gt "32"]], [[CPU_COUNT="32"]])dnl Limit resource usage
  4655. ],
  4656. [
  4657. # Limit usage to just a few cores if heavy tests are not enabled
  4658. AS_IF([[test "$CPU_COUNT" -gt "6"]], [[CPU_COUNT="6"]])
  4659. AS_IF([[test "$CPU_COUNT" -lt "2"]], [[CPU_COUNT="2"]])
  4660. ]
  4661. )
  4662. AC_MSG_RESULT([$CPU_COUNT])
  4663. AC_ARG_ENABLE([[asserts]],
  4664. [AS_HELP_STRING([[--enable-asserts]],
  4665. [enable test build with debug asserts])],
  4666. [],
  4667. [enable_asserts='auto']
  4668. )
  4669. AS_UNSET([use_asserts_MSG])
  4670. AC_CACHE_CHECK([[whether NDEBUG macro is defined]], [mhd_cv_macro_ndebug_def],
  4671. [
  4672. AC_LINK_IFELSE(
  4673. [
  4674. AC_LANG_SOURCE([[
  4675. #ifndef NDEBUG
  4676. #error NDEBUG is NOT defined
  4677. chome me now
  4678. #endif
  4679. int main(void)
  4680. {
  4681. return 0;
  4682. }
  4683. ]]
  4684. )
  4685. ],
  4686. [[mhd_cv_macro_ndebug_def='yes']],
  4687. [[mhd_cv_macro_ndebug_def='no']]
  4688. )
  4689. ]
  4690. )
  4691. AS_VAR_IF([enable_asserts],["yes"],
  4692. [
  4693. AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"],
  4694. [
  4695. AC_MSG_FAILURE([Parameter --enable-asserts is specified, but NDEBUG macro is defined as well])
  4696. ]
  4697. )
  4698. use_asserts_MSG="yes, enabled by configure parameter"
  4699. ]
  4700. )
  4701. AC_CACHE_CHECK([[whether _DEBUG macro is defined]], [mhd_cv_macro__debug_def],
  4702. [
  4703. AC_LINK_IFELSE(
  4704. [
  4705. AC_LANG_SOURCE([[
  4706. #ifndef _DEBUG
  4707. #error _DEBUG is NOT defined
  4708. chome me now
  4709. #endif
  4710. int main(void)
  4711. {
  4712. return 0;
  4713. }
  4714. ]]
  4715. )
  4716. ],
  4717. [[mhd_cv_macro__debug_def='yes']],
  4718. [[mhd_cv_macro__debug_def='no']]
  4719. )
  4720. ]
  4721. )
  4722. AS_VAR_IF([enable_asserts],["no"],
  4723. [
  4724. AS_VAR_IF([mhd_cv_macro__debug_def],["yes"],
  4725. [
  4726. AC_MSG_FAILURE([Parameter --disable-asserts is specified, but _DEBUG macro is defined as well])
  4727. ]
  4728. )
  4729. use_asserts_MSG="no, set by configure parameter"
  4730. ]
  4731. )
  4732. AS_IF([test "x${mhd_cv_macro_ndebug_def}" = "xyes" && test "x${mhd_cv_macro__debug_def}" = "xyes"],
  4733. [AC_MSG_FAILURE([Both NDEBUG and _DEBUG macros are defined])]
  4734. )
  4735. AS_VAR_IF([enable_asserts],["auto"],
  4736. [
  4737. AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"],
  4738. [
  4739. enable_asserts="no"
  4740. use_asserts_MSG="no, set by NDEBUG preprocessor macro"
  4741. ]
  4742. )
  4743. ]
  4744. )
  4745. AS_VAR_IF([enable_asserts],["auto"],
  4746. [
  4747. AS_VAR_IF([mhd_cv_macro__debug_def],["yes"],
  4748. [
  4749. enable_asserts="yes"
  4750. use_asserts_MSG="yes, enabled by _DEBUG preprocessor macro"
  4751. ]
  4752. )
  4753. ]
  4754. )
  4755. AS_VAR_IF([enable_asserts],["auto"],
  4756. [
  4757. AC_CACHE_CHECK([[whether DEBUG macro is defined]], [mhd_cv_macro_debug_def],
  4758. [
  4759. AC_LINK_IFELSE(
  4760. [
  4761. AC_LANG_SOURCE([[
  4762. #ifndef DEBUG
  4763. #error DEBUG is NOT defined
  4764. chome me now
  4765. #endif
  4766. int main(void)
  4767. {
  4768. return 0;
  4769. }
  4770. ]]
  4771. )
  4772. ],
  4773. [[mhd_cv_macro_debug_def='yes']],
  4774. [[mhd_cv_macro_debug_def='no']]
  4775. )
  4776. ]
  4777. )
  4778. AS_VAR_IF([mhd_cv_macro_debug_def],["yes"],
  4779. [
  4780. enable_asserts="yes"
  4781. use_asserts_MSG="yes, enabled by DEBUG preprocessor macro"
  4782. ]
  4783. )
  4784. ]
  4785. )
  4786. AC_MSG_CHECKING([[whether to enable debug asserts]])
  4787. AS_VAR_IF([enable_asserts],["auto"],
  4788. [
  4789. AS_CASE([${enable_build_type}],
  4790. [debug|debugger],
  4791. [
  4792. enable_asserts="yes"
  4793. use_asserts_MSG="yes, enabled by --enable-bulid-type=${enable_build_type}"
  4794. ],
  4795. [
  4796. enable_asserts="no"
  4797. use_asserts_MSG="no"
  4798. ]
  4799. )
  4800. ]
  4801. )
  4802. AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']])
  4803. AC_MSG_RESULT([[${use_asserts_MSG=no}]])
  4804. AS_VAR_IF([[enable_asserts]], [["yes"]],
  4805. [
  4806. AS_VAR_IF([[mhd_cv_macro__debug_def]], [["yes"]], [:],
  4807. [
  4808. MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_DEBUG=1])
  4809. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  4810. ]
  4811. )
  4812. AC_CACHE_CHECK([[whether system assert() is available]], [mhd_cv_sys_assert_avail],
  4813. [
  4814. AC_LINK_IFELSE(
  4815. [
  4816. AC_LANG_SOURCE([[
  4817. #include <assert.h>
  4818. static int pos_val(void) {return 5;}
  4819. static int neg_val(void) {return -5;}
  4820. int main(void)
  4821. {
  4822. int pos_var = pos_val(), neg_var = neg_val();
  4823. assert(neg_var > pos_var); /* Must trigger assert. */
  4824. return pos_var + neg_var;
  4825. }
  4826. ]])
  4827. ],
  4828. [[mhd_cv_sys_assert_avail='yes']],
  4829. [[mhd_cv_sys_assert_avail='no']]
  4830. )
  4831. ]
  4832. )
  4833. AS_VAR_IF([[mhd_cv_sys_assert_avail]], [["no"]], [],
  4834. [AC_DEFINE([[HAVE_ASSERT]], [[1]], [Define if you have usable assert() and assert.h])])
  4835. ],
  4836. [
  4837. AS_VAR_IF([[mhd_cv_macro_ndebug_def]], [["yes"]], [:],
  4838. [
  4839. MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DNDEBUG=1])
  4840. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  4841. ]
  4842. )
  4843. ]
  4844. )
  4845. AS_UNSET([enabled_sanitizers])
  4846. TESTS_ENVIRONMENT_ac=""
  4847. AM_ASAN_OPTIONS=""
  4848. AM_UBSAN_OPTIONS=""
  4849. AM_LSAN_OPTIONS=""
  4850. AS_UNSET([ASAN_OPTIONS])
  4851. AS_UNSET([UBSAN_OPTIONS])
  4852. AS_UNSET([LSAN_OPTIONS])
  4853. AC_MSG_CHECKING([whether to enable run-time sanitizers])
  4854. AC_ARG_ENABLE([sanitizers],
  4855. [AS_HELP_STRING([[--enable-sanitizers[=address,undefined,leak,user-poison]]],
  4856. [enable run-time sanitizers, specify the list of types of sanitizers to enable, ]
  4857. [leave the list empty (or set to "auto") to enable all supported and available ]
  4858. [sanitizers, or specify "auto-fallback" to use sanitizers even without ]
  4859. [installed sanitizer run-time library])],
  4860. [], [AS_CASE([${enable_build_type}],[debug],
  4861. [enable_sanitizers='auto-optional'],[enable_sanitizers='no'])]
  4862. )
  4863. AS_IF([test "x${enable_sanitizers}" = "x"], [enable_sanitizers="auto"])
  4864. AS_VAR_IF([enable_sanitizers], ["yes"], [enable_sanitizers="auto"])
  4865. AS_VAR_IF([enable_sanitizers], ["autofallback"], [enable_sanitizers="auto-fallback"])
  4866. AS_VAR_IF([enable_sanitizers], ["autooptional"], [enable_sanitizers="auto-optional"])
  4867. AS_IF([test "x${enable_sanitizers}" = "xno"],
  4868. [
  4869. enable_sanitizers="no"
  4870. enable_san_address="no"
  4871. enable_san_undef="no"
  4872. enable_san_leak="no"
  4873. enable_san_upoison="no"
  4874. ],
  4875. [test "x${enable_sanitizers}" = "xauto" || test "x${enable_sanitizers}" = "xauto-optional"],
  4876. [
  4877. AS_VAR_IF([enable_compiler_hardening],["yes"],
  4878. [
  4879. AS_VAR_IF([enable_sanitizers],["auto"],
  4880. [AC_MSG_ERROR([sanitizers cannot be enabled with compiler hardnening])],
  4881. [AC_MSG_WARN([sanitizers cannot be enabled with compiler hardnening])]
  4882. )
  4883. enable_sanitizers="no"
  4884. enable_san_address="no"
  4885. enable_san_undef="no"
  4886. enable_san_leak="no"
  4887. enable_san_upoison="no"
  4888. ],
  4889. [
  4890. enable_san_address="auto"
  4891. enable_san_undef="auto"
  4892. enable_san_leak="auto"
  4893. enable_san_upoison="auto"
  4894. ]
  4895. )
  4896. ],
  4897. [test "x${enable_sanitizers}" = "xauto-fallback"],
  4898. [
  4899. enable_san_address="auto"
  4900. enable_san_undef="auto-fallback"
  4901. enable_san_leak="auto"
  4902. enable_san_upoison="auto"
  4903. ],
  4904. [
  4905. AS_UNSET([san])
  4906. enable_san_address="no"
  4907. enable_san_undef="no"
  4908. enable_san_leak="no"
  4909. enable_san_upoison="no"
  4910. f][or san in `AS_ECHO([${enable_sanitizers}]) | tr ',' ' '`
  4911. do
  4912. AS_CASE([$san],
  4913. [address], [enable_san_address="yes"],
  4914. [undefined], [enable_san_undef="yes"],
  4915. [leak], [enable_san_leak="yes"],
  4916. [user-poison|user_poison], [enable_san_upoison="yes"],
  4917. [no|yes|auto|auto-fallback|autofallback], [AC_MSG_ERROR(["$san" cannot be used with other options for --enable-sanitizers=])],
  4918. [AC_MSG_ERROR([Unknown parameter "$san" for --enable-sanitizers=])]
  4919. )
  4920. done
  4921. AS_IF([test "x${enable_san_upoison}" = "xyes" && test "x${enable_san_address}" = "xno"],
  4922. [AC_MSG_ERROR([User memory poisoning cannot be used without address sanitizer])]
  4923. )
  4924. enable_sanitizers="selected"
  4925. ]
  4926. )
  4927. AS_CASE([${enable_sanitizers}],
  4928. [selected], [AC_MSG_RESULT([selected])],
  4929. [auto], [AC_MSG_RESULT([yes, detect and use supported sanitizers])],
  4930. [auto-fallback], [AC_MSG_RESULT([yes, detect and use supported sanitizers even without run-time lib])],
  4931. [auto-optional], [AC_MSG_RESULT([yes, detect and use supported sanitizers if any])],
  4932. [AC_MSG_RESULT([no])]
  4933. )
  4934. AS_VAR_IF([enable_sanitizers], ["no"], [:],
  4935. [
  4936. AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS
  4937. AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS
  4938. AC_CACHE_CHECK([whether '-fsanitize=' works for $CC],
  4939. [mhd_cv_cc_sanitizer_works],
  4940. [
  4941. CFLAGS="${CFLAGS_ac} -fsanitize=wrongFeatureName ${user_CFLAGS}"
  4942. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  4943. [mhd_cv_cc_sanitizer_works=no], [mhd_cv_cc_sanitizer_works=yes])
  4944. ]
  4945. )
  4946. AS_VAR_IF([mhd_cv_cc_sanitizer_works], ["yes"],
  4947. [
  4948. AS_VAR_IF([enable_san_address], ["no"], [:],
  4949. [
  4950. AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address],
  4951. [
  4952. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address ${user_CFLAGS}"
  4953. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  4954. [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no])
  4955. ]
  4956. )
  4957. AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"],
  4958. [
  4959. AC_DEFINE([MHD_ASAN_ACTIVE], [1], [Define to '1' if you have address sanitizer enabled])
  4960. AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS])
  4961. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address"
  4962. AS_VAR_IF([enable_san_leak], ["no"], [:],
  4963. [
  4964. AC_CACHE_CHECK([whether leak detect is not rejected by address sanitizer], [mhd_cv_cc_sanitizer_address_leak],
  4965. [
  4966. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${user_CFLAGS}"
  4967. ASAN_OPTIONS="exitcode=88:detect_leaks=1:halt_on_error=1"
  4968. export ASAN_OPTIONS
  4969. AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])],
  4970. [mhd_cv_cc_sanitizer_address_leak=yes], [mhd_cv_cc_sanitizer_address_leak=no],
  4971. [
  4972. # Cross-compiling with sanitizers?
  4973. mhd_cv_cc_sanitizer_address_leak='assuming no'
  4974. ]
  4975. )
  4976. AS_UNSET([ASAN_OPTIONS])
  4977. ]
  4978. )
  4979. ]
  4980. )
  4981. AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare],
  4982. [
  4983. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare ${user_CFLAGS}"
  4984. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  4985. [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no])
  4986. ]
  4987. )
  4988. AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"],
  4989. [
  4990. AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS])
  4991. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare"
  4992. ]
  4993. )
  4994. AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract],
  4995. [
  4996. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract ${user_CFLAGS}"
  4997. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  4998. [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no])
  4999. ]
  5000. )
  5001. AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"],
  5002. [
  5003. AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS])
  5004. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract"
  5005. ]
  5006. )
  5007. AS_VAR_IF([enable_san_upoison], ["no"], [:],
  5008. [
  5009. AC_CHECK_HEADERS([sanitizer/asan_interface.h], [], [], [AC_INCLUDES_DEFAULT])
  5010. AS_VAR_IF([ac_cv_header_sanitizer_asan_interface_h],["yes"],
  5011. [
  5012. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
  5013. MHD_CHECK_FUNC([__asan_address_is_poisoned],[[#include <sanitizer/asan_interface.h>]],
  5014. [[int a_var=1; i][f(__asan_address_is_poisoned((void*) &a_var)) return 3;]]
  5015. )
  5016. MHD_CHECK_FUNC([__asan_region_is_poisoned],[[#include <sanitizer/asan_interface.h>]],
  5017. [[int a_var=1; i][f(((void*) 0) != __asan_region_is_poisoned((void*) &a_var, sizeof(a_var))) return 3;]]
  5018. )
  5019. AC_CACHE_CHECK([whether special function attribute is needed for user-poison], [mhd_cv_func_u_p_attribute_needed],
  5020. [
  5021. ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
  5022. export ASAN_OPTIONS
  5023. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
  5024. AC_RUN_IFELSE(
  5025. [
  5026. AC_LANG_SOURCE(
  5027. [[
  5028. #include <stdint.h>
  5029. #include <stdlib.h>
  5030. #include <sanitizer/asan_interface.h>
  5031. static const size_t first_pos = 0;
  5032. static const size_t mid_pos = 64;
  5033. static const size_t last_pos = 128;
  5034. static const size_t zone_size = 16;
  5035. static const size_t buf_size = 128 + 16;
  5036. static int ptr_compare(void *ptr1, uint8_t *ptr2)
  5037. {
  5038. if ((((uintptr_t) (uint8_t *)ptr1) >= ((uintptr_t)ptr2)))
  5039. return ((char *) ptr1)[0] < ((char *) ptr2)[0];
  5040. return ((char *) ptr1)[0] > ((char *) ptr2)[0];
  5041. }
  5042. static int ptr_subtract(void *ptr1, uint8_t *ptr2)
  5043. {
  5044. return ((size_t)(((uintptr_t)(uint8_t*)ptr1) - ((uintptr_t)ptr2))) <= last_pos;
  5045. }
  5046. int main(int argc, char *argv[])
  5047. {
  5048. char *buf = (char*) malloc (buf_size);
  5049. char *a;
  5050. char *b;
  5051. int ret;
  5052. (void) argv;
  5053. if (NULL == buf)
  5054. return 10;
  5055. ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
  5056. ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
  5057. if (0 < argc)
  5058. a = buf + last_pos;
  5059. else
  5060. a = buf + first_pos;
  5061. b = buf + mid_pos;
  5062. *a = '0';
  5063. *b = '9';
  5064. if (ptr_compare((void *)a, (uint8_t*) b))
  5065. {
  5066. if (ptr_subtract((void *)a, (uint8_t*) b))
  5067. ret = 0;
  5068. else
  5069. ret = 10;
  5070. }
  5071. else
  5072. ret = 5;
  5073. ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
  5074. free (buf);
  5075. return ret;
  5076. }
  5077. ]]
  5078. )
  5079. ],
  5080. [mhd_cv_func_u_p_attribute_needed="no"], [mhd_cv_func_u_p_attribute_needed="yes"],
  5081. [
  5082. # Cross-compiling with sanitizers??
  5083. mhd_cv_func_up_attribute_needed='assuming no'
  5084. ]
  5085. )
  5086. AS_UNSET([ASAN_OPTIONS])
  5087. ]
  5088. )
  5089. ]
  5090. )
  5091. AS_VAR_IF([mhd_cv_func_u_p_attribute_needed],["yes"],[:],
  5092. [
  5093. AC_DEFINE([FUNC_PTRCOMPARE_CAST_WORKAROUND_WORKS],[1],[Define to '1' if cast to 'uintptr_t' works for safely processing user-poisoned pointer])
  5094. ]
  5095. )
  5096. AS_IF([test "x${mhd_cv_func_u_p_attribute_needed}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes"],
  5097. [
  5098. AC_CACHE_CHECK([whether '__attribute__((no_sanitize("pointer-compare")))' and '__attribute__((no_sanitize("pointer-subtract")))' work],
  5099. [mhd_cv_func_attribute_nosanitize_ptr],
  5100. [
  5101. ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
  5102. export ASAN_OPTIONS
  5103. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
  5104. AC_RUN_IFELSE(
  5105. [
  5106. AC_LANG_SOURCE(
  5107. [[
  5108. #include <stdint.h>
  5109. #include <stdlib.h>
  5110. #include <sanitizer/asan_interface.h>
  5111. static const size_t first_pos = 0;
  5112. static const size_t mid_pos = 64;
  5113. static const size_t last_pos = 128;
  5114. static const size_t zone_size = 16;
  5115. static const size_t buf_size = 128 + 16;
  5116. __attribute__((no_sanitize("pointer-compare")))
  5117. static int ptr_compare(void *ptr1, uint8_t *ptr2)
  5118. {
  5119. if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2)))
  5120. return ((char *) ptr1)[0] < ((char *) ptr2)[0];
  5121. return ((char *) ptr1)[0] > ((char *) ptr2)[0];
  5122. }
  5123. __attribute__((no_sanitize("pointer-subtract")))
  5124. static int ptr_subtract(void *ptr1, uint8_t *ptr2)
  5125. {
  5126. return ((size_t)(((const uint8_t*)ptr1) - \
  5127. ((const uint8_t*)ptr2))) <= last_pos;
  5128. }
  5129. int main(int argc, char *argv[])
  5130. {
  5131. char *buf = (char*) malloc (buf_size);
  5132. char *a;
  5133. char *b;
  5134. int ret;
  5135. (void) argv;
  5136. if (NULL == buf)
  5137. return 10;
  5138. ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
  5139. ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
  5140. if (0 < argc)
  5141. a = buf + last_pos;
  5142. else
  5143. a = buf + first_pos;
  5144. b = buf + mid_pos;
  5145. *a = '0';
  5146. *b = '9';
  5147. if (ptr_compare((void *)a, (uint8_t*) b))
  5148. {
  5149. if (ptr_subtract((void *)a, (uint8_t*) b))
  5150. ret = 0;
  5151. else
  5152. ret = 10;
  5153. }
  5154. else
  5155. ret = 5;
  5156. ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
  5157. free (buf);
  5158. return ret;
  5159. }
  5160. ]]
  5161. )
  5162. ],
  5163. [mhd_cv_func_attribute_nosanitize_ptr=yes], [mhd_cv_func_attribute_nosanitize_ptr=no],
  5164. [
  5165. # Cross-compiling with sanitizers??
  5166. mhd_cv_func_attribute_nosanitize_ptr='assuming no'
  5167. ]
  5168. )
  5169. AS_UNSET([ASAN_OPTIONS])
  5170. ]
  5171. )
  5172. AS_VAR_IF([mhd_cv_func_attribute_nosanitize_ptr], ["yes"],
  5173. [
  5174. AC_DEFINE([FUNC_ATTR_PTRCOMPARE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-compare")))' works])
  5175. AC_DEFINE([FUNC_ATTR_PTRSUBTRACT_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-subtract")))' works])
  5176. ],
  5177. [
  5178. AC_CACHE_CHECK([whether '__attribute__((no_sanitize("address")))' works for pointers compare], [mhd_cv_func_attribute_nosanitize_addr],
  5179. [
  5180. ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
  5181. export ASAN_OPTIONS
  5182. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
  5183. AC_RUN_IFELSE(
  5184. [
  5185. AC_LANG_SOURCE(
  5186. [[
  5187. #include <stdint.h>
  5188. #include <stdlib.h>
  5189. #include <sanitizer/asan_interface.h>
  5190. static const size_t first_pos = 0;
  5191. static const size_t mid_pos = 64;
  5192. static const size_t last_pos = 128;
  5193. static const size_t zone_size = 16;
  5194. static const size_t buf_size = 128 + 16;
  5195. __attribute__((no_sanitize("address")))
  5196. static int ptr_compare(void *ptr1, uint8_t *ptr2)
  5197. {
  5198. if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2)))
  5199. return ((char *) ptr1)[0] < ((char *) ptr2)[0];
  5200. return ((char *) ptr1)[0] > ((char *) ptr2)[0];
  5201. }
  5202. __attribute__((no_sanitize("address")))
  5203. static int ptr_subtract(void *ptr1, uint8_t *ptr2)
  5204. {
  5205. return ((size_t)(((const uint8_t*)ptr1) - \
  5206. ((const uint8_t*)ptr2))) <= last_pos;
  5207. }
  5208. int main(int argc, char *argv[])
  5209. {
  5210. char *buf = (char*) malloc (buf_size);
  5211. char *a;
  5212. char *b;
  5213. int ret;
  5214. (void) argv;
  5215. if (NULL == buf)
  5216. return 10;
  5217. ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
  5218. ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
  5219. if (0 < argc)
  5220. a = buf + last_pos;
  5221. else
  5222. a = buf + first_pos;
  5223. b = buf + mid_pos;
  5224. *a = '0';
  5225. *b = '9';
  5226. if (ptr_compare((void *)a, (uint8_t*) b))
  5227. {
  5228. if (ptr_subtract((void *)a, (uint8_t*) b))
  5229. ret = 0;
  5230. else
  5231. ret = 10;
  5232. }
  5233. else
  5234. ret = 5;
  5235. ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
  5236. free (buf);
  5237. return ret;
  5238. }
  5239. ]]
  5240. )
  5241. ],
  5242. [mhd_cv_func_attribute_nosanitize_addr=yes], [mhd_cv_func_attribute_nosanitize_addr=no],
  5243. [
  5244. # Cross-compiling with sanitizers??
  5245. mhd_cv_func_attribute_nosanitize_addr='assuming no'
  5246. ]
  5247. )
  5248. AS_UNSET([ASAN_OPTIONS])
  5249. ]
  5250. )
  5251. AS_VAR_IF([mhd_cv_func_attribute_nosanitize_addr], ["yes"],
  5252. [AC_DEFINE([FUNC_ATTR_NOSANITIZE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("address")))' works for pointers compare])]
  5253. )
  5254. ]
  5255. )
  5256. ]
  5257. )
  5258. ]
  5259. )
  5260. ]
  5261. )
  5262. AS_IF([test "x${enable_san_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_address}" != "xyes"],
  5263. [AC_MSG_ERROR([Address sanitizer cannot be enabled])]
  5264. )
  5265. enable_san_address="${mhd_cv_cc_sanitizer_address}"
  5266. ]
  5267. )
  5268. AS_VAR_IF([enable_san_undef], ["no"], [:],
  5269. [
  5270. dnl Ensure that '#' will be processed correctly
  5271. [
  5272. test_undf_prog='
  5273. #include <stdio.h>
  5274. static void func_out_b(char *arr)
  5275. {
  5276. arr[0] = 0;
  5277. arr[16] = 2;
  5278. }
  5279. static unsigned int int_deref(void *ptr)
  5280. {
  5281. return (*((unsigned int*)ptr)) + 2;
  5282. }
  5283. static int func1(void)
  5284. {
  5285. char chr[16];
  5286. func_out_b (chr);
  5287. return (int) (int_deref(chr + 1) + int_deref(chr + 2));
  5288. }
  5289. int main(void)
  5290. {
  5291. unsigned long ulvar;
  5292. signed char ch1;
  5293. ulvar = -1 * func1();
  5294. ch1 = ulvar * 6UL;
  5295. printf("%lu\n", ulvar + ch1);
  5296. return 0;
  5297. }
  5298. '
  5299. ]
  5300. AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined],
  5301. [
  5302. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined ${user_CFLAGS}"
  5303. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  5304. [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no])
  5305. ]
  5306. )
  5307. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"],
  5308. [
  5309. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  5310. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  5311. ],
  5312. [
  5313. AS_CASE([${enable_san_undef}], [yes|auto-fallback],
  5314. [
  5315. AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap],
  5316. [
  5317. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error ${user_CFLAGS}"
  5318. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  5319. [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no])
  5320. ]
  5321. )
  5322. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"],
  5323. [
  5324. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  5325. AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS])
  5326. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  5327. AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited])
  5328. ],
  5329. [
  5330. AS_IF([test -z "${enabled_sanitizers}"],
  5331. [
  5332. # Last resort
  5333. AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all],
  5334. [
  5335. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}"
  5336. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  5337. [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no])
  5338. ]
  5339. )
  5340. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"],
  5341. [
  5342. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  5343. AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS])
  5344. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}"
  5345. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  5346. AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited])
  5347. ]
  5348. )
  5349. ]
  5350. )
  5351. ]
  5352. )
  5353. AS_CASE(["$enabled_sanitizers"], [*undefined],
  5354. [
  5355. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[],
  5356. [
  5357. # A workaround for broken clang which is trying to use UBSan lib
  5358. # even when instructed to not use it
  5359. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
  5360. AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion],
  5361. [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])])
  5362. ]
  5363. )
  5364. ]
  5365. )
  5366. ]
  5367. )
  5368. ]
  5369. )
  5370. AS_CASE(["$enabled_sanitizers"], [*undefined],
  5371. [
  5372. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
  5373. AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg],
  5374. [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])])
  5375. ]
  5376. )
  5377. AS_UNSET([test_undf_prog])
  5378. AS_CASE(["$enabled_sanitizers"],
  5379. [*undefined], [enable_san_undef="yes"],
  5380. [
  5381. AS_VAR_IF([enable_san_undef], [yes], [AC_MSG_ERROR([Undefined behavior sanitizer cannot be enabled])])
  5382. enable_san_undef="no"
  5383. ]
  5384. )
  5385. ]
  5386. )
  5387. AS_VAR_IF([enable_san_leak], ["no"], [:],
  5388. [
  5389. AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak],
  5390. [
  5391. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak ${user_CFLAGS}"
  5392. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  5393. [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no])
  5394. ]
  5395. )
  5396. AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"],
  5397. [
  5398. AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS])
  5399. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak"
  5400. ]
  5401. )
  5402. AS_IF([test "x${enable_san_leak}" = "xyes" && test "x${mhd_cv_cc_sanitizer_leak}" != "xyes"],
  5403. [AC_MSG_ERROR([User poison cannot be enabled])]
  5404. )
  5405. enable_san_leak="${mhd_cv_cc_sanitizer_leak}"
  5406. ]
  5407. )
  5408. AS_IF([test -z "${enabled_sanitizers}"],
  5409. [
  5410. AS_VAR_IF([enable_sanitizers], ["auto-optional"],
  5411. [
  5412. san_FLAGS=""
  5413. san_CFLAGS=""
  5414. ],
  5415. [
  5416. AC_MSG_ERROR([cannot find any sanitizer supported by $CC])
  5417. ]
  5418. )
  5419. ],
  5420. [
  5421. AS_VAR_IF([enable_san_upoison], ["no"], [:],
  5422. [
  5423. AC_MSG_CHECKING([whether to enable user memory poisoning])
  5424. AS_IF([test "x${mhd_cv_cc_sanitizer_address}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes" && \
  5425. (test "x${mhd_cv_func_u_p_attribute_needed}" != "xyes" || test "x${mhd_cv_func_attribute_nosanitize_ptr}" = "xyes" || \
  5426. test "x${mhd_cv_func_attribute_nosanitize_addr}" = "xyes")],
  5427. [
  5428. AC_DEFINE([MHD_ASAN_POISON_ACTIVE], [1], [Define to '1' if user memory poison is used])
  5429. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }user-poison"
  5430. enable_san_upoison="yes"
  5431. AC_MSG_RESULT([yes])
  5432. ],
  5433. [
  5434. AC_MSG_RESULT([no])
  5435. AS_VAR_IF([enable_san_upoison], ["yes"],
  5436. [AC_MSG_ERROR([User memory poisoning cannot be enabled])])
  5437. enable_san_upoison="no"
  5438. ]
  5439. )
  5440. ]
  5441. )
  5442. AS_VAR_IF([enable_san_address], ["yes"],
  5443. [
  5444. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
  5445. AC_CHECK_DECL([_FORTIFY_SOURCE],
  5446. [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])],
  5447. [],[/* no includes */])
  5448. AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS])
  5449. ],
  5450. [
  5451. AS_CASE([$enable_sanitizers], [auto|auto-fallback],
  5452. [AC_MSG_WARN([$CC does not support address sanitizer])])
  5453. ]
  5454. )
  5455. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
  5456. # Always stop on sanitizer error
  5457. AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS])
  5458. # Get a better output for sanitizers error reporting
  5459. AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-optimize-sibling-calls],
  5460. [san_CFLAGS])
  5461. AS_VAR_IF([enable_san_address], ["yes"],
  5462. [
  5463. AM_ASAN_OPTIONS="exitcode=88:strict_string_checks=1:detect_stack_use_after_return=1"
  5464. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64"
  5465. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3"
  5466. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:handle_ioctl=1:halt_on_error=1"
  5467. AS_VAR_IF([enable_san_upoison], ["yes"], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:allow_user_poisoning=1"])
  5468. AS_VAR_IF([enable_san_leak], ["yes"],
  5469. [AS_VAR_IF([mhd_cv_cc_sanitizer_address_leak], ["yes"],
  5470. [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=1"])
  5471. ], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=0"]
  5472. )
  5473. ]
  5474. )
  5475. AS_VAR_IF([enable_san_undef], [yes],
  5476. [AM_UBSAN_OPTIONS="exitcode=87:print_stacktrace=1:halt_on_error=1"])
  5477. AS_VAR_IF([enable_san_leak], ["yes"],
  5478. [AM_LSAN_OPTIONS="use_unaligned=1"]
  5479. )
  5480. TESTS_ENVIRONMENT_ac='\
  5481. ASAN_OPTIONS="$(AM_ASAN_OPTIONS)" ; export ASAN_OPTIONS ; \
  5482. UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \
  5483. LSAN_OPTIONS="$(AM_LSAN_OPTIONS)" ; export LSAN_OPTIONS ;'
  5484. ]
  5485. )
  5486. ]
  5487. )
  5488. CFLAGS_ac="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS}"
  5489. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  5490. ]
  5491. )
  5492. # fuzzing tests
  5493. run_zzuf_tests="no"
  5494. zzuf_socat_mandatory="no"
  5495. AS_VAR_IF([use_heavy_tests],["yes"],
  5496. [
  5497. AS_VAR_IF([enable_curl],["yes"],
  5498. [
  5499. AC_PATH_PROG([ZZUF],[zzuf],[no])
  5500. AS_VAR_IF([ZZUF],["no"],
  5501. [
  5502. run_zzuf_tests="no"
  5503. run_zzuf_tests_MSG="no, zzuf tool not found"
  5504. ],
  5505. [
  5506. AC_PATH_PROG([SOCAT],[socat],[no])
  5507. AS_IF([test "x${ac_cv_func_accept4}" = "xyes" && test "x${enable_asserts}" = "xno"],
  5508. [
  5509. zzuf_socat_mandatory="yes"
  5510. AS_VAR_IF([SOCAT],["no"],
  5511. [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests on this platform without asserts enabled"],
  5512. [
  5513. run_zzuf_tests="yes"
  5514. run_zzuf_tests_MSG="yes, with zzuf and socat tools"
  5515. ]
  5516. )
  5517. ],
  5518. [test -n "${enabled_sanitizers}"],
  5519. [
  5520. zzuf_socat_mandatory="yes"
  5521. AS_VAR_IF([SOCAT],["no"],
  5522. [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests when sanitizers enabled"],
  5523. [
  5524. run_zzuf_tests="yes"
  5525. run_zzuf_tests_MSG="yes, with zzuf and socat tools"
  5526. ]
  5527. )
  5528. ],
  5529. [
  5530. run_zzuf_tests="yes"
  5531. run_zzuf_tests_MSG="yes, with zzuf tool"
  5532. ]
  5533. )
  5534. ]
  5535. )
  5536. ],
  5537. [
  5538. run_zzuf_tests="no"
  5539. run_zzuf_tests_MSG="no, tests with libcurl are not enabled"
  5540. ]
  5541. )
  5542. ],
  5543. [
  5544. run_zzuf_tests="no"
  5545. run_zzuf_tests_MSG="no, heavy tests are not enabled"
  5546. ]
  5547. )
  5548. AM_CONDITIONAL([RUN_ZZUF_TESTS],[test "x$run_zzuf_tests" = "xyes"])
  5549. AM_CONDITIONAL([FORCE_USE_ZZUF_SOCAT],[test "x$zzuf_socat_mandatory" = "xyes"])
  5550. # Final flags that may interfere with autoconf detections
  5551. AS_CASE([${enable_build_type}],[debug|debugger],
  5552. [ # Debug build or build for walking with debugger
  5553. CFLAGS="${user_CFLAGS}"
  5554. MHD_CHECK_ADD_CC_CFLAGS([-Wextra-semi -Wextra-semi-stmt], [CFLAGS_ac])
  5555. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  5556. ]
  5557. )
  5558. AM_CONDITIONAL([USE_SANITIZERS],
  5559. [test -n "$enabled_sanitizers" && test "x$mhd_cv_cc_sanitizer_works" = "xyes"])
  5560. AC_SUBST([AM_ASAN_OPTIONS])
  5561. AC_SUBST([AM_UBSAN_OPTIONS])
  5562. AC_SUBST([AM_LSAN_OPTIONS])
  5563. AC_SUBST([TESTS_ENVIRONMENT_ac])
  5564. MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS"
  5565. AC_SUBST([CPU_COUNT])
  5566. AC_SUBST([HEAVY_TESTS_NOTPARALLEL])
  5567. AM_SUBST_NOTMAKE([HEAVY_TESTS_NOTPARALLEL])
  5568. AC_SUBST(MHD_LIB_CPPFLAGS)
  5569. AC_SUBST(MHD_LIB_CFLAGS)
  5570. AC_SUBST(MHD_LIB_LDFLAGS)
  5571. AC_SUBST(MHD_LIBDEPS)
  5572. AC_SUBST(MHD_TLS_LIB_CPPFLAGS)
  5573. AC_SUBST(MHD_TLS_LIB_CFLAGS)
  5574. AC_SUBST(MHD_TLS_LIB_LDFLAGS)
  5575. AC_SUBST(MHD_TLS_LIBDEPS)
  5576. # for pkg-config
  5577. AC_SUBST([MHD_REQ_PRIVATE])
  5578. AC_SUBST([MHD_LIBDEPS_PKGCFG])
  5579. # Restore flags as set by the user
  5580. CFLAGS="${user_CFLAGS}"
  5581. LDFLAGS="${user_LDFLAGS}"
  5582. CPPFLAGS="${user_CPPFLAGS}"
  5583. AC_SUBST([CFLAGS])
  5584. AC_SUBST([LDFLAGS])
  5585. AC_SUBST([CPPFLAGS])
  5586. AC_SUBST([LIBS])
  5587. # Configure-defined flags
  5588. AC_SUBST([CFLAGS_ac])
  5589. AC_SUBST([LDFLAGS_ac])
  5590. AC_SUBST([CPPFLAGS_ac])
  5591. # Used for 'po' directory staff
  5592. AC_SUBST([ac_configure_args])
  5593. AC_SUBST([EMPTY_VAR],[])
  5594. AC_SUBST([MHD_AUX_DIR])
  5595. AC_CONFIG_FILES([po/po-configure.ac])
  5596. AC_CONFIG_COMMANDS([po/Makefile.in],
  5597. [
  5598. echo "Skipping update of po/Makefile.in"
  5599. echo "Real update of po/Makefile.in for 'make dist' is performed by po-config.status"
  5600. ]
  5601. )
  5602. AC_CONFIG_COMMANDS([po-directories],
  5603. [
  5604. echo "Skipping po-directories command."
  5605. echo "Real po-directories command for 'make dist' is implemented in po-config.status"
  5606. ]
  5607. )
  5608. # We define the paths here, because MinGW/GCC expands paths
  5609. # passed through the command line ("-DDIR=..."). This would
  5610. # lead to hard-coded paths ("C:\mingw\mingw\bin...") that do
  5611. # not contain the actual installation.
  5612. AC_DEFINE_DIR([MHD_PLUGIN_INSTALL_PREFIX], [libdir/libmicrohttpd], [tls plugins])
  5613. AC_SUBST([ZZUF])
  5614. AC_SUBST([SOCAT])
  5615. # should experimental code be compiled (code that may not yet compile)?
  5616. AC_MSG_CHECKING(whether to compile experimental code)
  5617. AC_ARG_ENABLE([experimental],
  5618. [AS_HELP_STRING([--enable-experimental], [enable compiling experimental code])],
  5619. [enable_experimental=${enableval}],
  5620. [enable_experimental=no])
  5621. AC_MSG_RESULT($enable_experimental)
  5622. AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"])
  5623. AC_CONFIG_FILES([libmicrohttpd.pc
  5624. w32/common/microhttpd_dll_res_vc.rc
  5625. Makefile
  5626. contrib/Makefile
  5627. doc/Makefile
  5628. doc/doxygen/libmicrohttpd.doxy
  5629. doc/doxygen/Makefile
  5630. doc/examples/Makefile
  5631. m4/Makefile
  5632. src/Makefile
  5633. src/include/Makefile
  5634. src/microhttpd/Makefile
  5635. src/microhttpd_ws/Makefile
  5636. src/examples/Makefile
  5637. src/tools/Makefile
  5638. src/testcurl/Makefile
  5639. src/testcurl/https/Makefile
  5640. src/testzzuf/Makefile])
  5641. AC_OUTPUT
  5642. # Finally: summary
  5643. # Format flags without extra spaces for visual beauty
  5644. fin_CPPFLAGS="$user_CPPFLAGS"
  5645. fin_CFLAGS="$user_CFLAGS"
  5646. fin_LDFLAGS="$user_LDFLAGS"
  5647. MHD_PREPEND_FLAG_TO_VAR([fin_CPPFLAGS],[$CPPFLAGS_ac])
  5648. MHD_PREPEND_FLAG_TO_VAR([fin_CFLAGS],[$CFLAGS_ac])
  5649. MHD_PREPEND_FLAG_TO_VAR([fin_LDFLAGS],[$LDFLAGS_ac])
  5650. fin_lib_CPPFLAGS="$user_CPPFLAGS"
  5651. fin_lib_CFLAGS="$user_CFLAGS"
  5652. fin_lib_LDFLAGS="$user_LDFLAGS"
  5653. MHD_PREPEND_FLAG_TO_VAR([fin_lib_CPPFLAGS],[$MHD_LIB_CPPFLAGS])
  5654. MHD_PREPEND_FLAG_TO_VAR([fin_lib_CFLAGS],[$MHD_LIB_CFLAGS])
  5655. MHD_PREPEND_FLAG_TO_VAR([fin_lib_LDFLAGS],[$MHD_LIB_LDFLAGS])
  5656. MHD_PREPEND_FLAG_TO_VAR([fin_lib_CPPFLAGS],[$CPPFLAGS_ac])
  5657. MHD_PREPEND_FLAG_TO_VAR([fin_lib_CFLAGS],[$CFLAGS_ac])
  5658. MHD_PREPEND_FLAG_TO_VAR([fin_lib_LDFLAGS],[$LDFLAGS_ac])
  5659. AC_MSG_NOTICE([Toolchain settings:
  5660. CC=$CC
  5661. User/system/default flags:
  5662. CPPFLAGS="$user_CPPFLAGS"
  5663. CFLAGS= "$user_CFLAGS"
  5664. LDFLAGS= "$user_LDFLAGS"
  5665. Final set of the flags for tests and examples:
  5666. CPPFLAGS="$fin_CPPFLAGS"
  5667. CFLAGS= "$fin_CFLAGS"
  5668. LDFLAGS= "$fin_LDFLAGS"
  5669. Final set of the flags for ${PACKAGE_NAME} library:
  5670. CPPFLAGS="$fin_lib_CPPFLAGS"
  5671. CFLAGS= "$fin_lib_CFLAGS"
  5672. LDFLAGS= "$fin_lib_LDFLAGS"
  5673. ])
  5674. AS_UNSET([fin_CPPFLAGS])
  5675. AS_UNSET([fin_CFLAGS])
  5676. AS_UNSET([fin_LDFLAGS])
  5677. AS_UNSET([fin_lib_CPPFLAGS])
  5678. AS_UNSET([fin_lib_CFLAGS])
  5679. AS_UNSET([fin_lib_LDFLAGS])
  5680. AS_VAR_IF([os_is_windows], ["yes"],
  5681. [os_ver_msg="
  5682. Target W32 ver: ${mhd_w32_ver_msg}"], [AS_UNSET([[os_ver_msg]])])
  5683. AC_MSG_NOTICE([GNU libmicrohttpd ${PACKAGE_VERSION} Configuration Summary:
  5684. Target directory: ${prefix}
  5685. Cross-compiling: ${cross_compiling}
  5686. Operating System: ${mhd_host_os}${os_ver_msg}
  5687. Threading lib: ${USE_THREADS}
  5688. Inter-thread comm: ${use_itc}
  5689. Shutdown of listening socket triggers select: ${mhd_cv_host_shtdwn_trgr_select}
  5690. poll support: ${enable_poll=no}
  5691. epoll support: ${enable_epoll=no}
  5692. sendfile used: ${found_sendfile}
  5693. HTTPS support: ${MSG_HTTPS}
  5694. Messages: ${enable_messages}
  5695. Cookie parsing: ${enable_cookie}
  5696. Postproc: ${enable_postprocessor}
  5697. Basic auth.: ${enable_bauth}
  5698. Digest auth.: ${enable_dauth}
  5699. Digest auth. defaults: ${dauth_defs_MSG}
  5700. MD5: ${enable_md5_MSG}
  5701. SHA-256: ${enable_sha256_MSG}
  5702. SHA-512/256: ${enable_sha512_256_MSG}
  5703. HTTP "Upgrade": ${enable_httpupgrade}
  5704. Compact code: ${enable_compact_code} (${compact_code_MSG})
  5705. Use thread names: ${enable_thread_names}
  5706. Use debug asserts: ${use_asserts_MSG=no}
  5707. Use sanitizers: ${enabled_sanitizers:=no}
  5708. Build static lib: ${enable_static}
  5709. Build shared lib: ${enable_shared}
  5710. Build docs: ${enable_doc}
  5711. Build examples: ${enable_examples}
  5712. Build tools: ${enable_tools}
  5713. Test with libcurl: ${MSG_CURL}
  5714. Heavy tests: ${use_heavy_tests_MSG}
  5715. Fuzzing tests: ${run_zzuf_tests_MSG=no}
  5716. ])
  5717. AS_IF([test "x$enable_https" = "xyes"],
  5718. [AC_MSG_NOTICE([HTTPS subsystem configuration:
  5719. License : LGPL version 2.1 or any later version
  5720. ])],
  5721. [AC_MSG_NOTICE([
  5722. License : LGPLv2.1+ or eCos
  5723. ])])
  5724. AS_IF([test "x$enable_bauth" != "xyes" || \
  5725. test "x$enable_dauth" != "xyes" || \
  5726. test "x${enable_md5}" = "xno" || \
  5727. test "x${enable_sha256}" = "xno" || \
  5728. test "x${enable_sha512_256}" != "xyes" || \
  5729. test "x${USE_THREADS}" = "xnone" || \
  5730. test "x$enable_httpupgrade" != "xyes" || \
  5731. test "x$enable_cookie" != "xyes" || \
  5732. test "x$enable_httpupgrade" != "xyes" || \
  5733. test "x$enable_postprocessor" != "xyes"],
  5734. [AC_MSG_WARN([This will be a custom build with missing symbols. Do NOT use this build in a distribution. Building with these kinds of configure options is only for custom builds for embedded systems.])]
  5735. )
  5736. AS_IF([test -n "${CONF_FINAL_WARNS}"],[AC_MSG_WARN([${CONF_FINAL_WARNS}])])