configure.ac 193 KB

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