configure.ac 192 KB

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