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.1],[libmicrohttpd@gnu.org])
  27. AC_CONFIG_AUX_DIR([build-aux])
  28. MHD_AUX_DIR='build-aux' # Must be set to the same value as in the previous line
  29. AC_CONFIG_HEADERS([MHD_config.h])
  30. AC_CONFIG_MACRO_DIR([m4])
  31. m4_pattern_forbid([^_?MHD_[A-Z_]+_CC_])dnl
  32. LIB_VERSION_CURRENT=74
  33. LIB_VERSION_REVISION=1
  34. LIB_VERSION_AGE=62
  35. AC_SUBST([LIB_VERSION_CURRENT])
  36. AC_SUBST([LIB_VERSION_REVISION])
  37. AC_SUBST([LIB_VERSION_AGE])
  38. PACKAGE_VERSION_MAJOR='m4_car(m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  39. PACKAGE_VERSION_MINOR='m4_argn(2, m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  40. PACKAGE_VERSION_SUBMINOR='m4_argn(3, m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  41. AS_VAR_ARITH([MHD_W32_DLL_SUFF],[[$LIB_VERSION_CURRENT - $LIB_VERSION_AGE]])
  42. AC_SUBST([PACKAGE_VERSION_MAJOR])
  43. AC_SUBST([PACKAGE_VERSION_MINOR])
  44. AC_SUBST([PACKAGE_VERSION_SUBMINOR])
  45. AC_SUBST([MHD_W32_DLL_SUFF])
  46. AC_CONFIG_FILES([src/microhttpd/microhttpd_dll_res.rc])
  47. 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. # Check for generic functions
  2347. MHD_CHECK_FUNC([random],
  2348. [
  2349. AC_INCLUDES_DEFAULT
  2350. [#include <stdlib.h>
  2351. ]],
  2352. [[long int r = random(); (void)r;]],
  2353. [],
  2354. [
  2355. MHD_CHECK_FUNC([rand],
  2356. [
  2357. AC_INCLUDES_DEFAULT
  2358. [#include <stdlib.h>
  2359. ]],
  2360. [[int r = rand(); (void)r;]],
  2361. )
  2362. ]
  2363. )
  2364. AC_CHECK_MEMBERS([struct sockaddr.sa_len, struct sockaddr_storage.ss_len,
  2365. struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len],
  2366. [], [],
  2367. [
  2368. #ifdef HAVE_SYS_TYPES_H
  2369. #include <sys/types.h>
  2370. #endif
  2371. #ifdef HAVE_SYS_SOCKET_H
  2372. #include <sys/socket.h>
  2373. #endif
  2374. #ifdef HAVE_NETINET_IN_H
  2375. #include <netinet/in.h>
  2376. #endif
  2377. #ifdef HAVE_WINSOCK2_H
  2378. #include <winsock2.h>
  2379. #endif
  2380. #ifdef HAVE_WS2TCPIP_H
  2381. #include <ws2tcpip.h>
  2382. #endif
  2383. ])
  2384. MHD_CHECK_FUNC_RUN([getsockname],
  2385. [[
  2386. #ifdef HAVE_SYS_TYPES_H
  2387. #include <sys/types.h>
  2388. #endif
  2389. #include <string.h>
  2390. #ifdef HAVE_SYS_SOCKET_H
  2391. #include <sys/socket.h>
  2392. #endif
  2393. #ifdef HAVE_UNISTD_H
  2394. #include <unistd.h>
  2395. #endif
  2396. #ifdef HAVE_WINSOCK2_H
  2397. #include <winsock2.h>
  2398. #endif
  2399. #ifdef HAVE_WS2TCPIP_H
  2400. #include <ws2tcpip.h>
  2401. #endif
  2402. #ifdef HAVE_NETINET_IN_H
  2403. #include <netinet/in.h>
  2404. #endif
  2405. #ifdef HAVE_NETINET_IP_H
  2406. #include <netinet/ip.h>
  2407. #endif
  2408. #ifdef HAVE_ARPA_INET_H
  2409. #include <arpa/inet.h>
  2410. #endif
  2411. ]],
  2412. [[
  2413. const socklen_t c_addr_size = (socklen_t)sizeof(struct sockaddr_in);
  2414. struct sockaddr_in sa;
  2415. socklen_t addr_size;
  2416. int ret = 1;
  2417. #if !defined(_WIN32) || defined(__CYGWIN__)
  2418. int sckt;
  2419. const int invld_sckt = -1;
  2420. #else
  2421. SOCKET sckt;
  2422. const SOCKET invld_sckt = INVALID_SOCKET;
  2423. WSADATA wsa_data;
  2424. i][f (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data) || MAKEWORD(2, 2) != wsa_data.wVersion)
  2425. return 20;
  2426. #endif
  2427. sckt = socket (PF_INET, SOCK_STREAM, 0);
  2428. i][f (invld_sckt != sckt)
  2429. {
  2430. memset(&sa, 0, c_addr_size);
  2431. sa.sin_family = AF_INET;
  2432. #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
  2433. sa.sin_len = c_addr_size;
  2434. #endif
  2435. i][f (0 == bind (sckt, (struct sockaddr *)&sa, c_addr_size))
  2436. {
  2437. i][f (0 == listen (sckt, 1))
  2438. {
  2439. addr_size = c_addr_size;
  2440. i][f (0 == getsockname (sckt, (struct sockaddr *)&sa, &addr_size))
  2441. {
  2442. i][f (c_addr_size >= addr_size)
  2443. {
  2444. i][f (0 != ntohs(sa.sin_port))
  2445. { ret = 0;
  2446. } el][se ret = 7;
  2447. } el][se ret = 6;
  2448. } el][se ret = 5;
  2449. } el][se ret = 4;
  2450. } el][se ret = 3;
  2451. } el][se ret = 2;
  2452. #if !defined(_WIN32) || defined(__CYGWIN__)
  2453. close (sckt);
  2454. #else
  2455. closesocket (sckt);
  2456. WSACleanup();
  2457. #endif
  2458. return ret;
  2459. ]],
  2460. [cacheVar='assuming yes'],
  2461. [AC_DEFINE([[MHD_USE_GETSOCKNAME]], [[1]], [Define if you have usable `getsockname' function.])]
  2462. )
  2463. AC_CACHE_CHECK([for usable PAGESIZE macro], [mhd_cv_macro_pagesize_usable],
  2464. [
  2465. AC_LINK_IFELSE(
  2466. [
  2467. AC_LANG_PROGRAM(
  2468. [[
  2469. #ifdef HAVE_UNISTD_H
  2470. #include <unistd.h>
  2471. #endif
  2472. #ifdef HAVE_LIMITS_H
  2473. #include <limits.h>
  2474. #endif
  2475. #ifdef HAVE_SYS_PARAM_H
  2476. #include <sys/param.h>
  2477. #endif
  2478. #ifndef PAGESIZE
  2479. #error No PAGESIZE macro defined
  2480. choke me now
  2481. #endif
  2482. ]],
  2483. [[
  2484. long pgsz = PAGESIZE + 0;
  2485. if (1 > pgsz) return 1;
  2486. ]]
  2487. )
  2488. ],
  2489. [[mhd_cv_macro_pagesize_usable="yes"]], [[mhd_cv_macro_pagesize_usable="no"]]
  2490. )
  2491. ]
  2492. )
  2493. AS_VAR_IF([[mhd_cv_macro_pagesize_usable]], [["yes"]],
  2494. [
  2495. AC_DEFINE([[MHD_USE_PAGESIZE_MACRO]],[[1]],[Define if you have usable PAGESIZE macro])
  2496. AC_CACHE_CHECK([whether PAGESIZE macro could be used for static init], [mhd_cv_macro_pagesize_usable_static],
  2497. [
  2498. AC_LINK_IFELSE(
  2499. [
  2500. AC_LANG_PROGRAM(
  2501. [[
  2502. #ifdef HAVE_UNISTD_H
  2503. #include <unistd.h>
  2504. #endif
  2505. #ifdef HAVE_LIMITS_H
  2506. #include <limits.h>
  2507. #endif
  2508. #ifdef HAVE_SYS_PARAM_H
  2509. #include <sys/param.h>
  2510. #endif
  2511. #ifndef PAGESIZE
  2512. #error No PAGESIZE macro defined
  2513. choke me now
  2514. #endif
  2515. static long ac_pgsz = PAGESIZE + 0;
  2516. ]],
  2517. [[
  2518. if (1 > ac_pgsz) return 1;
  2519. ]]
  2520. )
  2521. ],
  2522. [[mhd_cv_macro_pagesize_usable_static="yes"]], [[mhd_cv_macro_pagesize_usable_static="no"]]
  2523. )
  2524. ]
  2525. )
  2526. AS_VAR_IF([[mhd_cv_macro_pagesize_usable_static]], [["yes"]],
  2527. [AC_DEFINE([[MHD_USE_PAGESIZE_MACRO_STATIC]],[[1]],[Define if you have PAGESIZE macro usable for static init])]
  2528. )
  2529. ],
  2530. [
  2531. AC_CACHE_CHECK([for usable PAGE_SIZE macro], [mhd_cv_macro_page_size_usable],
  2532. [
  2533. AC_LINK_IFELSE(
  2534. [
  2535. AC_LANG_PROGRAM(
  2536. [[
  2537. #ifdef HAVE_UNISTD_H
  2538. #include <unistd.h>
  2539. #endif
  2540. #ifdef HAVE_LIMITS_H
  2541. #include <limits.h>
  2542. #endif
  2543. #ifdef HAVE_SYS_PARAM_H
  2544. #include <sys/param.h>
  2545. #endif
  2546. #ifndef PAGE_SIZE
  2547. #error No PAGE_SIZE macro defined
  2548. choke me now
  2549. #endif
  2550. ]],
  2551. [[
  2552. long pgsz = PAGE_SIZE + 0;
  2553. if (1 > pgsz) return 1;
  2554. ]]
  2555. )
  2556. ],
  2557. [[mhd_cv_macro_page_size_usable="yes"]], [[mhd_cv_macro_page_size_usable="no"]]
  2558. )
  2559. ]
  2560. )
  2561. AS_VAR_IF([[mhd_cv_macro_page_size_usable]], [["yes"]],
  2562. [
  2563. AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO]],[[1]],[Define if you have usable PAGE_SIZE macro])
  2564. AC_CACHE_CHECK([whether PAGE_SIZE macro could be used for static init], [mhd_cv_macro_page_size_usable_static],
  2565. [
  2566. AC_LINK_IFELSE(
  2567. [
  2568. AC_LANG_PROGRAM(
  2569. [[
  2570. #ifdef HAVE_UNISTD_H
  2571. #include <unistd.h>
  2572. #endif
  2573. #ifdef HAVE_LIMITS_H
  2574. #include <limits.h>
  2575. #endif
  2576. #ifdef HAVE_SYS_PARAM_H
  2577. #include <sys/param.h>
  2578. #endif
  2579. #ifndef PAGE_SIZE
  2580. #error No PAGE_SIZE macro defined
  2581. choke me now
  2582. #endif
  2583. static long ac_pgsz = PAGE_SIZE + 0;
  2584. ]],
  2585. [[
  2586. if (1 > ac_pgsz) return 1;
  2587. ]]
  2588. )
  2589. ],
  2590. [[mhd_cv_macro_page_size_usable_static="yes"]], [[mhd_cv_macro_page_size_usable_static="no"]]
  2591. )
  2592. ]
  2593. )
  2594. AS_VAR_IF([[mhd_cv_macro_page_size_usable_static]], [["yes"]],
  2595. [AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO_STATIC]],[[1]],[Define if you have PAGE_SIZE macro usable for static init])]
  2596. )
  2597. ]
  2598. )
  2599. ]
  2600. )
  2601. # Check for inter-thread signaling type
  2602. AC_ARG_ENABLE([[itc]],
  2603. [AS_HELP_STRING([[--enable-itc=TYPE]], [use TYPE of inter-thread communication (pipe, socketpair, eventfd) [auto]])], [],
  2604. [[enable_itc='auto']]
  2605. )
  2606. AS_CASE([[$enable_itc]],
  2607. [[pipe]], [[:]],
  2608. [[socketpair]], [[:]],
  2609. [[eventfd]], [[:]],
  2610. [[auto]], [AS_VAR_IF([[os_is_windows]], [["yes"]], [[enable_itc='socketpair']])],
  2611. [[eventFD]], [[enable_itc='eventfd']],
  2612. [[socket]], [[enable_itc='socketpair']],
  2613. [[no]], [AC_MSG_ERROR([[inter-thread communication cannot be disabled]])],
  2614. [AC_MSG_ERROR([[unrecognized type "$enable_itc" of inter-thread communication specified by "--enable-itc=$enable_itc"]])]
  2615. )
  2616. AS_UNSET([[use_itc]])
  2617. AS_IF([[test "x$enable_itc" = "xeventfd" || test "x$enable_itc" = "xauto"]],
  2618. [
  2619. MHD_CHECK_FUNC_RUN([eventfd],[[
  2620. #include <sys/eventfd.h>
  2621. #include <unistd.h>
  2622. ]],
  2623. [[
  2624. static unsigned char buf[8];
  2625. int ret;
  2626. int efd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
  2627. i][f (0 > efd)
  2628. return 2;
  2629. ret = 0;
  2630. buf[3] = 1;
  2631. i][f (8 != write(efd, buf, 8))
  2632. ret = 3;
  2633. el][se
  2634. {
  2635. i][f (8 != read(efd, buf, 8))
  2636. ret = 4;
  2637. }
  2638. close(efd);
  2639. return ret;
  2640. ]],
  2641. [
  2642. AS_VAR_IF([enable_itc],["eventfd"],
  2643. [cacheVar="assuming yes"],[cacheVar="assuming no"]
  2644. )
  2645. ],
  2646. [
  2647. use_itc='eventfd'
  2648. enable_itc="$use_itc"
  2649. AC_DEFINE([[_MHD_ITC_EVENTFD]], [[1]], [Define to use eventFD f][or inter-thread communication])
  2650. ]
  2651. )
  2652. AS_UNSET([warn_msg])
  2653. AS_VAR_IF([mhd_cv_works_func_eventfd],["assuming yes"],
  2654. [[warn_msg="When cross-compiling it is not possible to check whether 'eventfd()' really works on the host (final) platform.
  2655. 'eventfd' is enabled as requested by configure parameters.
  2656. Use './configure mhd_cv_works_func_eventfd=yes' to mute this warning."]]
  2657. )
  2658. AS_VAR_IF([mhd_cv_works_func_eventfd],["assuming no"],
  2659. [[warn_msg="When cross-compiling it is not possible to check whether 'eventfd()' really works on the host (final) platform.
  2660. 'eventfd()' is disabled. If it is available use './configure mhd_cv_works_func_eventfd=yes' to enable.
  2661. Use './configure mhd_cv_works_func_eventfd=no' to mute this warning."]]
  2662. )
  2663. AS_VAR_SET_IF([warn_msg],[AC_MSG_WARN([$warn_msg])
  2664. AS_IF([test -n "${CONF_FINAL_WARNS}" ],
  2665. [
  2666. CONF_FINAL_WARNS="${CONF_FINAL_WARNS}
  2667. WARNING: "
  2668. ]
  2669. )
  2670. CONF_FINAL_WARNS="${CONF_FINAL_WARNS}${warn_msg}"
  2671. ]
  2672. )
  2673. ]
  2674. )
  2675. AS_IF([[test "x$enable_itc" = "xpipe" || test "x$enable_itc" = "xauto"]], [
  2676. AS_VAR_IF([[os_is_native_w32]], [["yes"]], [], [
  2677. AC_CACHE_CHECK([[whether pipe(3) is usable]], [[mhd_cv_pipe_usable]], [
  2678. AC_LINK_IFELSE([
  2679. AC_LANG_PROGRAM([
  2680. AC_INCLUDES_DEFAULT
  2681. #ifdef HAVE_UNISTD_H
  2682. #include <unistd.h>
  2683. #endif
  2684. ], [[
  2685. int arr[2];
  2686. int res;
  2687. res = pipe(arr);
  2688. if (res != 0) return 33;
  2689. close (arr[0]);
  2690. close (arr[1]);
  2691. ]])
  2692. ], [[mhd_cv_pipe_usable='yes']], [[mhd_cv_pipe_usable='no']])
  2693. ])
  2694. AS_VAR_IF([[mhd_cv_pipe_usable]], [["yes"]], [
  2695. use_itc='pipe'
  2696. enable_itc="$use_itc"
  2697. AC_DEFINE([[_MHD_ITC_PIPE]], [[1]], [Define to use pipe for inter-thread communication])
  2698. MHD_CHECK_FUNC_RUN([pipe2],[
  2699. AC_INCLUDES_DEFAULT
  2700. [
  2701. #ifdef HAVE_FCNTL_H
  2702. #include <fcntl.h>
  2703. #endif
  2704. #ifdef HAVE_UNISTD_H
  2705. #include <unistd.h>
  2706. #endif
  2707. ]],[[
  2708. int arr[2];
  2709. int res;
  2710. res = pipe2(arr, O_CLOEXEC | O_NONBLOCK);
  2711. i][f (res != 0) return 33;
  2712. close (arr[0]);
  2713. close (arr[1]);
  2714. return 0;
  2715. ]],[
  2716. # Cross-compiling
  2717. AS_CASE([${host_os}], [kfreebsd*-gnu], [cacheVar='assuming no'],
  2718. [cacheVar='assuming yes'])
  2719. ],
  2720. [AC_DEFINE([[HAVE_PIPE2_FUNC]], [[1]], [Define i][f you have usable pipe2(2) function])],
  2721. )
  2722. ], [
  2723. AS_VAR_IF([[enable_itc]], [["pipe"]], [AC_MSG_ERROR([[pipe(3) is not usable, consider using other type of inter-thread communication]])])
  2724. ])
  2725. ])
  2726. ])
  2727. AS_IF([[test "x$enable_itc" = "xsocketpair" || test "x$enable_itc" = "xauto"]], [
  2728. AS_VAR_IF([[os_is_native_w32]], [["yes"]], [[mhd_cv_socketpair_usable='yes']], [
  2729. AC_CACHE_CHECK([[whether socketpair(3) is usable]], [[mhd_cv_socketpair_usable]], [
  2730. AC_LINK_IFELSE([
  2731. AC_LANG_PROGRAM([
  2732. AC_INCLUDES_DEFAULT
  2733. #ifdef HAVE_SYS_TYPES_H
  2734. #include <sys/types.h>
  2735. #endif
  2736. #ifdef HAVE_SYS_SOCKET_H
  2737. #include <sys/socket.h>
  2738. #endif
  2739. ], [[
  2740. int arr[2];
  2741. int res;
  2742. #if defined(AF_LOCAL)
  2743. res = socketpair(AF_LOCAL, SOCK_STREAM, 0, arr);
  2744. #elif defined(AF_UNIX)
  2745. res = socketpair(AF_UNIX, SOCK_STREAM, 0, arr);
  2746. #else
  2747. #error AF_LOCAL and AF_UNIX are both undefined
  2748. choke me now;
  2749. #endif
  2750. if (res != 0) return 1
  2751. ]])
  2752. ], [[mhd_cv_socketpair_usable='yes']], [[mhd_cv_socketpair_usable='no']])
  2753. ])
  2754. ])
  2755. AS_VAR_IF([[mhd_cv_socketpair_usable]], [["yes"]], [
  2756. use_itc='socketpair'
  2757. enable_itc="$use_itc"
  2758. AC_DEFINE([[_MHD_ITC_SOCKETPAIR]], [[1]], [Define to use socketpair for inter-thread communication])
  2759. ], [
  2760. AS_VAR_IF([[enable_itc]], [["socketpair"]], [AC_MSG_ERROR([[socketpair(3) is not usable, consider using other type of inter-thread communication]])])
  2761. ])
  2762. ])
  2763. AS_IF([[test -z "$use_itc"]], [AC_MSG_ERROR([[cannot find usable type of inter-thread communication]])])
  2764. MHD_CHECK_FUNC([accept4],
  2765. [[
  2766. #if defined(HAVE_SYS_TYPES_H)
  2767. # include <sys/types.h>
  2768. #endif
  2769. #include <sys/socket.h>
  2770. ]],
  2771. [[
  2772. struct sockaddr sk_addr;
  2773. socklen_t addr_size;
  2774. i][f (0 > accept4(0, &sk_addr, &addr_size, 0))
  2775. return 3;
  2776. ]]
  2777. )
  2778. MHD_CHECK_FUNC([gmtime_r],
  2779. [[
  2780. #if defined(HAVE_SYS_TYPES_H)
  2781. # include <sys/types.h>
  2782. #endif
  2783. #include <time.h>
  2784. ]],
  2785. [[
  2786. time_t timer = (time_t) 0;
  2787. struct tm res;
  2788. i][f (&res != gmtime_r(&timer, &res))
  2789. return 3;
  2790. ]]
  2791. )
  2792. MHD_CHECK_FUNC([memmem],
  2793. [[
  2794. #if defined(HAVE_STDDEF_H)
  2795. # include <stddef.h>
  2796. #elif defined(HAVE_STDLIB_H)
  2797. # include <stdlib.h>
  2798. #endif /* HAVE_STDLIB_H */
  2799. #include <string.h>
  2800. ]],
  2801. [[
  2802. const char *haystack = "abc";
  2803. size_t hslen = 3;
  2804. const char *needle = "b";
  2805. size_t needlelen = 1;
  2806. i][f ((haystack + 1) != memmem(haystack, hslen, needle, needlelen))
  2807. return 3;
  2808. ]]
  2809. )
  2810. MHD_CHECK_FUNC([snprintf],
  2811. [[
  2812. #include <stdio.h>
  2813. ]],
  2814. [[
  2815. char buf[2];
  2816. i][f (1 != snprintf(buf, 2, "a"))
  2817. return 3;
  2818. /* Do not use the next check to avoid compiler warning */
  2819. /* i][f (4 != snprintf(buf, 2, "abcd"))
  2820. return 4; */
  2821. ]]
  2822. )
  2823. AC_CHECK_DECL([gmtime_s],
  2824. [
  2825. AC_MSG_CHECKING([[whether gmtime_s is in C11 form]])
  2826. AC_LINK_IFELSE(
  2827. [ AC_LANG_PROGRAM(
  2828. [[
  2829. #define __STDC_WANT_LIB_EXT1__ 1
  2830. #include <time.h>
  2831. #ifdef __cplusplus
  2832. extern "C"
  2833. #endif
  2834. struct tm* gmtime_s(const time_t* time, struct tm* result);
  2835. ]], [[
  2836. static struct tm res;
  2837. static time_t t = 0;
  2838. gmtime_s (&t, &res);
  2839. ]])
  2840. ],
  2841. [
  2842. AC_DEFINE([HAVE_C11_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in C11 form.])
  2843. AC_MSG_RESULT([[yes]])
  2844. ],
  2845. [
  2846. AC_MSG_RESULT([[no]])
  2847. AC_MSG_CHECKING([[whether gmtime_s is in W32 form]])
  2848. AC_LINK_IFELSE(
  2849. [ AC_LANG_PROGRAM(
  2850. [[
  2851. #include <time.h>
  2852. #ifdef __cplusplus
  2853. extern "C"
  2854. #endif
  2855. errno_t gmtime_s(struct tm* _tm, const time_t* time);
  2856. ]], [[
  2857. static struct tm res;
  2858. static time_t t = 0;
  2859. gmtime_s (&res, &t);
  2860. ]])
  2861. ],
  2862. [
  2863. AC_DEFINE([HAVE_W32_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in W32 form.])
  2864. AC_MSG_RESULT([[yes]])
  2865. ],
  2866. [AC_MSG_RESULT([[no]])
  2867. ])
  2868. ])
  2869. ], [],
  2870. [[#define __STDC_WANT_LIB_EXT1__ 1
  2871. #include <time.h>]])
  2872. AC_CHECK_DECL([SOCK_NONBLOCK], [AC_DEFINE([HAVE_SOCK_NONBLOCK], [1], [SOCK_NONBLOCK is defined in a socket header])], [],
  2873. [[
  2874. #if defined(HAVE_SYS_TYPES_H)
  2875. # include <sys/types.h>
  2876. #endif
  2877. #if defined(HAVE_SYS_SOCKET_H)
  2878. # include <sys/socket.h>
  2879. #elif defined(HAVE_WINSOCK2_H)
  2880. # include <winsock2.h>
  2881. #endif
  2882. ]]
  2883. )
  2884. MHD_FIND_LIB([clock_gettime],[[#include <time.h>]],
  2885. [[
  2886. struct timespec tp;
  2887. i][f (0 > clock_gettime(CLOCK_REALTIME, &tp))
  2888. return 3;
  2889. ]],
  2890. [rt],
  2891. [
  2892. AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Define to '1' if you have clock_gettime() function])
  2893. AS_VAR_IF([[mhd_cv_find_lib_clock_gettime]],[["none required"]], [],
  2894. [
  2895. MHD_LIBDEPS_PKGCFG="${mhd_cv_find_lib_clock_gettime} $MHD_LIBDEPS_PKGCFG"
  2896. ]
  2897. )
  2898. ],[],
  2899. [MHD_LIBDEPS]
  2900. )
  2901. MHD_CHECK_FUNC([clock_get_time],
  2902. [[
  2903. #include <mach/clock.h>
  2904. #include <mach/mach.h>
  2905. ]],
  2906. [[
  2907. clock_serv_t cs;
  2908. mach_timespec_t mt;
  2909. host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cs);
  2910. clock_get_time(cs, &mt);
  2911. mach_port_deallocate(mach_task_self(), cs);
  2912. ]]
  2913. )
  2914. MHD_CHECK_FUNC([gethrtime],
  2915. [[
  2916. #ifdef HAVE_SYS_TIME_H
  2917. /* Solaris define gethrtime() in sys/time.h */
  2918. #include <sys/time.h>
  2919. #endif /* HAVE_SYS_TIME_H */
  2920. #ifdef HAVE_TIME_H
  2921. /* HP-UX define gethrtime() in time.h */
  2922. #include <time.h>
  2923. #endif /* HAVE_TIME_H */
  2924. ]],
  2925. [[
  2926. hrtime_t hrt = gethrtime();
  2927. i][f (0 == hrt)
  2928. return 3;
  2929. ]]
  2930. )
  2931. AS_VAR_IF([ac_cv_header_time_h], ["yes"],
  2932. [
  2933. MHD_CHECK_FUNC([timespec_get],
  2934. [[
  2935. #include <time.h>
  2936. #ifndef TIME_UTC
  2937. #error TIME_UTC must be defined to use timespec_get()
  2938. choke me now
  2939. #endif
  2940. ]],
  2941. [[
  2942. struct timespec ts;
  2943. i][f (TIME_UTC != timespec_get (&ts, TIME_UTC))
  2944. return 3;
  2945. ]]
  2946. )
  2947. ]
  2948. )
  2949. MHD_CHECK_FUNC_GETTIMEOFDAY
  2950. # IPv6
  2951. AC_CACHE_CHECK([for IPv6],[mhd_cv_have_inet6],
  2952. [
  2953. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  2954. #include <stdio.h>
  2955. #ifdef HAVE_NETINET_IN_H
  2956. #include <netinet/in.h>
  2957. #endif
  2958. #ifdef HAVE_SYS_SOCKET_H
  2959. #include <sys/socket.h>
  2960. #endif
  2961. #ifdef HAVE_WINSOCK2_H
  2962. #include <winsock2.h>
  2963. #endif
  2964. #ifdef HAVE_WS2TCPIP_H
  2965. #include <ws2tcpip.h>
  2966. #endif
  2967. ]], [[
  2968. int af=AF_INET6;
  2969. int pf=PF_INET6;
  2970. struct sockaddr_in6 sa;
  2971. printf("%d %d %p\n", af, pf, (void*) &sa);
  2972. ]]
  2973. )
  2974. ],
  2975. [AS_VAR_SET([mhd_cv_have_inet6],["yes"])],
  2976. [AS_VAR_SET([mhd_cv_have_inet6],["no"])]
  2977. )
  2978. ]
  2979. )
  2980. AS_VAR_IF([mhd_cv_have_inet6],["yes"],
  2981. [AC_DEFINE([HAVE_INET6], [1], [Define to '1' if you have IPv6 headers])]
  2982. )
  2983. MHD_CHECK_FUNC([[sysconf]], [[#include <unistd.h>]], [[long a = sysconf(0); if (a) return 1;]])
  2984. MHD_CHECK_FUNC([[sysctl]], [[
  2985. #ifdef HAVE_SYS_TYPES_H
  2986. #include <sys/types.h>
  2987. #endif
  2988. #ifdef HAVE_SYS_SYSCTL_H
  2989. #include <sys/sysctl.h>
  2990. #endif
  2991. #if defined(HAVE_STDDEF_H)
  2992. #include <stddef.h>
  2993. #elif defined(HAVE_STDLIB_H)
  2994. #include <stdlib.h>
  2995. #endif
  2996. ]], [[
  2997. int mib[2] = {0, 0}; /* Avoid any platform-specific values */
  2998. i][f (sysctl(mib, 2, NULL, NULL, NULL, 0)) return 1;
  2999. ]],
  3000. [
  3001. AC_CHECK_DECLS([CTL_NET,PF_INET,IPPROTO_ICMP,ICMPCTL_ICMPLIM],[],[],
  3002. [[
  3003. #ifdef HAVE_SYS_TYPES_H
  3004. #include <sys/types.h>
  3005. #endif /* HAVE_SYS_TYPES_H */
  3006. #ifdef HAVE_SYS_SYSCTL_H
  3007. #include <sys/sysctl.h>
  3008. #endif /* HAVE_SYS_SYSCTL_H */
  3009. #ifdef HAVE_SYS_SYSCTL_H
  3010. #include <sys/sysctl.h>
  3011. #endif /* HAVE_SYS_SYSCTL_H */
  3012. #ifdef HAVE_SYS_SOCKET_H
  3013. #include <sys/socket.h>
  3014. #endif /* HAVE_SYS_SOCKET_H */
  3015. #ifdef HAVE_NETINET_IN_SYSTM_H
  3016. #include <netinet/in_systm.h>
  3017. #endif /* HAVE_NETINET_IN_SYSTM_H */
  3018. #ifdef HAVE_NETINET_IN_H
  3019. #include <netinet/in.h>
  3020. #endif /* HAVE_NETINET_IN_H */
  3021. #ifdef HAVE_NETINET_IP_H
  3022. #include <netinet/ip.h>
  3023. #endif /* HAVE_NETINET_IP_H */
  3024. #ifdef HAVE_NETINET_IP_ICMP_H
  3025. #include <netinet/ip_icmp.h>
  3026. #endif /* HAVE_NETINET_IP_ICMP_H */
  3027. #ifdef HAVE_NETINET_ICMP_VAR_H
  3028. #include <netinet/icmp_var.h>
  3029. #endif /* HAVE_NETINET_ICMP_VAR_H */
  3030. ]]
  3031. )
  3032. ]
  3033. )
  3034. MHD_CHECK_FUNC([[sysctlbyname]], [[
  3035. #ifdef HAVE_SYS_TYPES_H
  3036. #include <sys/types.h>
  3037. #endif
  3038. #ifdef HAVE_SYS_SYSCTL_H
  3039. #include <sys/sysctl.h>
  3040. #endif
  3041. #if defined(HAVE_STDDEF_H)
  3042. #include <stddef.h>
  3043. #elif defined(HAVE_STDLIB_H)
  3044. #include <stdlib.h>
  3045. #endif
  3046. ]], [[sysctlbyname("test", NULL, NULL, NULL, 0);]]
  3047. )
  3048. MHD_CHECK_FUNC([[usleep]], [[#include <unistd.h>]], [[usleep(100000);]])
  3049. MHD_CHECK_FUNC([[nanosleep]], [[#include <time.h>]], [[struct timespec ts2, ts1 = {0, 0}; nanosleep(&ts1, &ts2);]])
  3050. HIDDEN_VISIBILITY_CFLAGS=""
  3051. AH_TEMPLATE([_MHD_EXTERN],[defines how to decorate public symbols w][hile building the library])
  3052. CFLAGS="${user_CFLAGS}"
  3053. MHD_CHECK_CC_CFLAG([-fvisibility=hidden],[CFLAGS_ac],
  3054. [
  3055. # NOTE: require setting of errattr_CFLAGS above
  3056. CFLAGS="${CFLAGS_ac} -fvisibility=hidden ${user_CFLAGS} ${errattr_CFLAGS}"
  3057. AC_CACHE_CHECK([whether $CC supports __attribute__((visibility("default")))],[mhd_cv_cc_attr_visibility],
  3058. [
  3059. AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
  3060. extern __attribute__((visibility("default"))) int test_extrn_func(void);
  3061. int test_extrn_func(void) {return 0;}
  3062. ]])
  3063. ],
  3064. [mhd_cv_cc_attr_visibility="yes"],[mhd_cv_cc_attr_visibility="no"]
  3065. )
  3066. ]
  3067. )
  3068. AS_VAR_IF([mhd_cv_cc_attr_visibility],["yes"],
  3069. [
  3070. HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"
  3071. AS_IF([test "x$os_is_native_w32" = "xyes" && test "x$enable_shared" = "xyes"],
  3072. [AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern])],
  3073. [AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) extern])]
  3074. )
  3075. ],
  3076. [
  3077. AC_MSG_WARN([$CC supports -fvisibility, but does not support __attribute__((visibility("default"))). Check compiler and compiler flags.])
  3078. AC_DEFINE([_MHD_EXTERN], [extern])
  3079. ]
  3080. )
  3081. ],[AC_DEFINE([_MHD_EXTERN], [extern])]
  3082. )
  3083. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3084. AC_SUBST([HIDDEN_VISIBILITY_CFLAGS])
  3085. # libcurl (required for testing)
  3086. AC_ARG_ENABLE([curl],
  3087. [AS_HELP_STRING([--disable-curl],[disable cURL based testcases])],
  3088. [enable_curl=${enableval}])
  3089. curl=0
  3090. AS_IF([test "$enable_curl" != "no"],
  3091. [LIBCURL_CHECK_CONFIG([yes],[7.16.4],[enable_curl=yes],
  3092. [
  3093. AS_IF([test "x$enable_curl" = "xyes"],
  3094. [AC_MSG_WARN([[cURL-based tests cannot be enabled because libcurl is missing]])])
  3095. enable_curl=no
  3096. ])
  3097. ])
  3098. AM_CONDITIONAL([RUN_LIBCURL_TESTS], [test "x$enable_curl" = "xyes"])
  3099. AS_IF([test "x$enable_curl" = "xyes"],
  3100. [MSG_CURL="yes"],
  3101. [MSG_CURL="no, many unit tests will not run"]
  3102. )
  3103. MHD_CHECK_FUNC([magic_open],
  3104. [[
  3105. #include <magic.h>
  3106. ]],
  3107. [[
  3108. char var_data[256];
  3109. const char *var_mime;
  3110. magic_t var_magic = magic_open (MAGIC_MIME_TYPE);
  3111. (void)magic_load (var_magic, "filename");
  3112. var_data[0] = 0;
  3113. var_mime = magic_buffer (var_magic, var_data, 1);
  3114. i][f (! var_mime)
  3115. return 1;
  3116. magic_close (var_magic);
  3117. ]],
  3118. [AC_DEFINE([MHD_HAVE_LIBMAGIC], [1], [Define to 1 if you have suitable libmagic.])],
  3119. [],
  3120. [-lmagic]
  3121. )
  3122. AM_CONDITIONAL([MHD_HAVE_LIBMAGIC], [[test "x$mhd_cv_have_func_magic_open" = "xyes"]])
  3123. # large file support (> 4 GB)
  3124. MHD_CHECK_FUNC([lseek64],
  3125. [[
  3126. #if defined(HAVE_SYS_TYPES_H)
  3127. # include <sys/types.h>
  3128. #endif
  3129. #include <unistd.h>
  3130. ]],
  3131. [[
  3132. i][f (((off64_t) -1) == lseek64(0, (off64_t) 0, SEEK_SET))
  3133. return 3;
  3134. ]]
  3135. )
  3136. MHD_CHECK_FUNC([pread64],
  3137. [[
  3138. #if defined(HAVE_SYS_TYPES_H)
  3139. # include <sys/types.h>
  3140. #endif
  3141. #include <unistd.h>
  3142. ]],
  3143. [[
  3144. char buf[5];
  3145. i][f (0 > pread64(0, (void *) buf, 1, (off64_t) 0))
  3146. return 3;
  3147. ]]
  3148. )
  3149. MHD_CHECK_FUNC([pread],
  3150. [[
  3151. #if defined(HAVE_SYS_TYPES_H)
  3152. # include <sys/types.h>
  3153. #endif
  3154. #include <unistd.h>
  3155. ]],
  3156. [[
  3157. char buf[5];
  3158. i][f (0 > pread(0, (void *) buf, 1, 0))
  3159. return 3;
  3160. ]]
  3161. )
  3162. # check for various sendfile functions
  3163. AC_ARG_ENABLE([sendfile],
  3164. [AS_HELP_STRING([--disable-sendfile],
  3165. [disable usage of sendfile() for HTTP connections [auto]])],
  3166. [],
  3167. [enable_sendfile="auto"])
  3168. AS_CASE([$enable_sendfile],
  3169. [[auto | yes]],[[found_sendfile="no"]],
  3170. [[no]],[[found_sendfile="disabled"]],
  3171. [AC_MSG_ERROR([[unknown value specified: --enable-sendfile=$enable_sendfile]])]
  3172. )
  3173. AS_VAR_IF([[found_sendfile]], [["no"]],
  3174. [
  3175. AC_MSG_CHECKING([[for Linux-style sendfile(2)]])
  3176. AC_LINK_IFELSE(
  3177. [AC_LANG_PROGRAM(
  3178. [[
  3179. #include <sys/sendfile.h>
  3180. static void empty_func(void)
  3181. {
  3182. /* Check for declaration */
  3183. (void)sendfile;
  3184. }
  3185. /* Declare again to check form match */
  3186. ssize_t sendfile(int, int, off_t*, size_t);
  3187. ]],
  3188. [[
  3189. int fd1=0, fd2=2;
  3190. off_t o = 0;
  3191. size_t s = 5;
  3192. ssize_t r;
  3193. r = sendfile (fd1, fd2, &o, s);
  3194. if (r)
  3195. empty_func();
  3196. ]]
  3197. )
  3198. ],
  3199. [
  3200. AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).])
  3201. found_sendfile="yes, Linux-style"
  3202. AC_MSG_RESULT([[yes]])
  3203. MHD_CHECK_FUNC([sendfile64],
  3204. [[
  3205. #include <sys/sendfile.h>
  3206. ]],
  3207. [[
  3208. off64_t f_offset = (off64_t) 0;
  3209. if (0 > sendfile64 (0, 1, &f_offset, 1))
  3210. return 3;
  3211. ]]
  3212. )
  3213. ],
  3214. [AC_MSG_RESULT([[no]])
  3215. ]
  3216. )
  3217. ]
  3218. )
  3219. AS_VAR_IF([[found_sendfile]], [["no"]],
  3220. [
  3221. AC_MSG_CHECKING([[for FreeBSD-style sendfile(2)]])
  3222. AC_LINK_IFELSE(
  3223. [AC_LANG_PROGRAM(
  3224. [[
  3225. #include <sys/types.h>
  3226. #include <sys/socket.h>
  3227. #include <sys/uio.h>
  3228. static void empty_func(void)
  3229. {
  3230. /* Check for declaration */
  3231. (void)sendfile;
  3232. }
  3233. /* Declare again to check form match */
  3234. int sendfile(int, int, off_t, size_t,
  3235. struct sf_hdtr*, off_t*, int);
  3236. ]],
  3237. [[
  3238. int fd1=0, fd2=1;
  3239. off_t o = 0;
  3240. size_t s = 5;
  3241. off_t r1;
  3242. int r2;
  3243. r2 = sendfile (fd1, fd2, o, s, (void*)0, &r1, 0);
  3244. if (r2)
  3245. empty_func();
  3246. ]]
  3247. )
  3248. ],
  3249. [
  3250. AC_DEFINE([HAVE_FREEBSD_SENDFILE], [1], [Define to 1 if you have FreeBSD-style sendfile(2).])
  3251. found_sendfile="yes, FreeBSD-style"
  3252. AC_MSG_RESULT([[yes]])
  3253. ],
  3254. [AC_MSG_RESULT([[no]])
  3255. ]
  3256. )
  3257. ]
  3258. )
  3259. AS_VAR_IF([[found_sendfile]], [["no"]],
  3260. [
  3261. AC_MSG_CHECKING([[for Darwin-style sendfile(2)]])
  3262. AC_LINK_IFELSE(
  3263. [AC_LANG_PROGRAM(
  3264. [[
  3265. #include <sys/types.h>
  3266. #include <sys/socket.h>
  3267. #include <sys/uio.h>
  3268. static void empty_func(void)
  3269. {
  3270. /* Check for declaration */
  3271. (void)sendfile;
  3272. }
  3273. /* Declare again to check form match */
  3274. int sendfile(int, int, off_t, off_t*,
  3275. struct sf_hdtr *, int);
  3276. ]],
  3277. [[
  3278. int fd=0, s=1;
  3279. off_t o = 0;
  3280. off_t l = 5;
  3281. int r;
  3282. r = sendfile (fd, s, o, &l, (void*)0, 0);
  3283. if (r)
  3284. empty_func();
  3285. ]]
  3286. )
  3287. ],
  3288. [
  3289. AC_DEFINE([HAVE_DARWIN_SENDFILE], [1], [Define to 1 if you have Darwin-style sendfile(2).])
  3290. found_sendfile="yes, Darwin-style"
  3291. AC_MSG_RESULT([[yes]])
  3292. ],
  3293. [AC_MSG_RESULT([[no]])
  3294. ]
  3295. )
  3296. ]
  3297. )
  3298. AS_VAR_IF([[found_sendfile]], [["no"]],
  3299. [
  3300. AC_MSG_CHECKING([[for Solaris-style sendfile(3)]])
  3301. SAVE_LIBS="$LIBS"
  3302. LIBS="-lsendfile $LIBS"
  3303. AC_LINK_IFELSE(
  3304. [AC_LANG_PROGRAM(
  3305. [[
  3306. #include <sys/types.h>
  3307. #include <sys/socket.h>
  3308. #include <sys/sendfile.h>
  3309. static void empty_func(void)
  3310. {
  3311. /* Check for declaration */
  3312. (void)sendfile;
  3313. }
  3314. /* Declare again to check form match */
  3315. ssize_t sendfile(int out_fd, int in_fd,
  3316. off_t *off, size_t len);
  3317. ]],
  3318. [[
  3319. int fd1=0, fd2=1;
  3320. off_t o = 0;
  3321. size_t l = 5;
  3322. ssize_t r;
  3323. r = sendfile (fd1, fd2, &o, l);
  3324. if (r)
  3325. empty_func();
  3326. ]]
  3327. )
  3328. ],
  3329. [
  3330. AC_DEFINE([HAVE_SOLARIS_SENDFILE], [1], [Define to 1 if you have Solaris-style sendfile(3).])
  3331. found_sendfile="yes, Solaris-style"
  3332. MHD_LIBDEPS="-lsendfile $MHD_LIBDEPS"
  3333. MHD_LIBDEPS_PKGCFG="-lsendfile $MHD_LIBDEPS_PKGCFG"
  3334. AC_MSG_RESULT([[yes]])
  3335. MHD_CHECK_FUNC([sendfile64],
  3336. [[
  3337. #include <sys/types.h>
  3338. #include <sys/socket.h>
  3339. #include <sys/sendfile.h>
  3340. ]],
  3341. [[
  3342. off64_t f_offset = (off64_t) 0;
  3343. if (0 > sendfile64 (0, 1, &f_offset, 1))
  3344. return 3;
  3345. ]]
  3346. )
  3347. ],
  3348. [AC_MSG_RESULT([[no]])
  3349. ]
  3350. )
  3351. LIBS="$SAVE_LIBS"
  3352. ]
  3353. )
  3354. AS_IF([[test "x$found_sendfile" = "xno" && test "x$enable_sendfile" = "xyes"]],
  3355. [AC_MSG_ERROR([[sendfile() usage was requested by configure parameter, but no usable sendfile() function is detected]])]
  3356. )
  3357. # optional: enable error and informational messages
  3358. AC_MSG_CHECKING([[whether to generate text messages]])
  3359. AC_ARG_ENABLE([messages],
  3360. [AS_HELP_STRING([--disable-messages],
  3361. [disable error, warning messages and text bodies for ]
  3362. [automatic HTTP responses (to reduce the binary size)])],
  3363. [enable_messages=${enableval}],
  3364. [enable_messages=yes])
  3365. AS_IF([[test "x$enable_messages" = "xyes"]],
  3366. [ AC_DEFINE([HAVE_MESSAGES],[1],[Define to 1 to enable support for text messages.]) ],
  3367. [[ enable_messages=no ]])
  3368. AC_MSG_RESULT([[$enable_messages]])
  3369. AM_CONDITIONAL([HAVE_MESSAGES], [test "x$enable_messages" != "xno"])
  3370. # optional: have postprocessor?
  3371. AC_MSG_CHECKING([[whether to enable postprocessor]])
  3372. AC_ARG_ENABLE([postprocessor],
  3373. [AS_HELP_STRING([--disable-postprocessor],
  3374. [disable MHD PostProcessor functionality])],
  3375. [enable_postprocessor=${enableval}],
  3376. [enable_postprocessor=yes])
  3377. AS_IF([[test "x$enable_postprocessor" != "xno"]],
  3378. [ enable_postprocessor=yes
  3379. AC_DEFINE([HAVE_POSTPROCESSOR],[1],[Define to 1 if libmicrohttpd is compiled with postprocessor support.]) ])
  3380. AM_CONDITIONAL([HAVE_POSTPROCESSOR], [test "x$enable_postprocessor" != "xno"])
  3381. AC_MSG_RESULT([[$enable_postprocessor]])
  3382. have_gnutls=no
  3383. have_gnutls_sni=no
  3384. have_gcrypt=no
  3385. AS_UNSET([GNUTLS_CPPFLAGS])
  3386. AS_UNSET([GNUTLS_LDFLAGS])
  3387. # optional: HTTPS support. Enabled by default
  3388. AC_ARG_ENABLE([https],
  3389. [AS_HELP_STRING([--enable-https],
  3390. [enable HTTPS support (yes, no, auto)[auto]])],
  3391. [enable_https=${enableval}])
  3392. AS_IF([test "x$enable_https" != "xno"],[
  3393. #
  3394. # Next block is large unindented block
  3395. #
  3396. # gnutls
  3397. have_gnutls_pkgcfg=no
  3398. AC_MSG_CHECKING([[how to find GnuTLS library]])
  3399. AC_ARG_WITH([[gnutls]],
  3400. [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)])],
  3401. [
  3402. AS_CASE([$with_gnutls],
  3403. [no],[
  3404. AC_MSG_RESULT([[GnuTLS disabled]])
  3405. AS_UNSET([GNUTLS_CPPFLAGS])
  3406. AS_UNSET([GNUTLS_CFLAGS])
  3407. AS_UNSET([GNUTLS_LDFLAGS])
  3408. AS_UNSET([GNUTLS_LIBS])
  3409. ],
  3410. [yes],[
  3411. AC_MSG_RESULT([[automatically, forced]])
  3412. ],
  3413. [
  3414. AC_MSG_RESULT([[-I$with_gnutls/include -L$with_gnutls/lib -lgnutls]])
  3415. SAVE_LIBS="$LIBS"
  3416. LDFLAGS="${LDFLAGS_ac} -L$with_gnutls/lib ${user_LDFLAGS}"
  3417. CPPFLAGS="${CPPFLAGS_ac} -I$with_gnutls/include ${user_CPPFLAGS}"
  3418. have_gnutls_pkgcfg=no
  3419. MHD_CHECK_FUNC([gnutls_check_version],[[#include <gnutls/gnutls.h>]],
  3420. [
  3421. if(!gnutls_check_version("2.0.0"))
  3422. return 3;
  3423. ],
  3424. [
  3425. GNUTLS_CPPFLAGS="-I$with_gnutls/include"
  3426. GNUTLS_LDFLAGS="-L$with_gnutls/lib"
  3427. GNUTLS_LIBS="-lgnutls"
  3428. have_gnutls=yes
  3429. ],
  3430. [AC_MSG_ERROR([can't find usable libgnutls at specified prefix $with_gnutls])],
  3431. [-lgnutls]
  3432. )
  3433. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3434. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3435. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3436. LIBS="$SAVE_LIBS"
  3437. ])
  3438. ],
  3439. [AC_MSG_RESULT([[automatically]])
  3440. ])
  3441. AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"],
  3442. [
  3443. PKG_CHECK_MODULES(GNUTLS, [[gnutls]],
  3444. [
  3445. have_gnutls_pkgcfg='yes'
  3446. SAVE_LIBS="$LIBS"
  3447. CFLAGS="${CFLAGS_ac} $GNUTLS_CFLAGS ${user_CFLAGS}"
  3448. LIBS="$GNUTLS_LIBS $LIBS"
  3449. AC_MSG_CHECKING([[whether GnuTLS is usable]])
  3450. AC_LINK_IFELSE([
  3451. AC_LANG_PROGRAM([[
  3452. #include <gnutls/gnutls.h>
  3453. ]], [[
  3454. gnutls_session_t session;
  3455. gnutls_priority_t priorities;
  3456. gnutls_global_init();
  3457. gnutls_priority_init(&priorities, "NORMAL", NULL);
  3458. gnutls_init(&session, GNUTLS_SERVER);
  3459. gnutls_priority_set(session, priorities);
  3460. ]])],
  3461. [
  3462. AC_MSG_RESULT([[yes]])
  3463. have_gnutls=yes
  3464. # GNUTLS_CFLAGS is actually CPPFLAGS
  3465. GNUTLS_CPPFLAGS="$GNUTLS_CFLAGS"
  3466. # GNUTLS_LDFLAGS is a combination of LDFLAGS and LIBS
  3467. GNUTLS_LDFLAGS="$GNUTLS_LIBS"
  3468. ],
  3469. [
  3470. AC_MSG_RESULT([[no]])
  3471. have_gnutls=no
  3472. ])
  3473. AS_IF([test "x$have_gnutls" != "xyes"],
  3474. [
  3475. AC_MSG_WARN([pkg-config reports that GnuTLS is present, but GnuTLS can't be used])
  3476. AS_UNSET([GNUTLS_CPPFLAGS])
  3477. AS_UNSET([GNUTLS_CFLAGS])
  3478. AS_UNSET([GNUTLS_LDFLAGS])
  3479. AS_UNSET([GNUTLS_LIBS])
  3480. ]
  3481. )
  3482. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3483. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3484. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3485. LIBS="$SAVE_LIBS"
  3486. ],
  3487. [
  3488. # check for GnuTLS at default paths
  3489. have_gnutls_pkgcfg='no'
  3490. AC_CHECK_HEADERS([gnutls/gnutls.h],
  3491. [AC_CHECK_LIB([gnutls], [gnutls_priority_set],
  3492. [
  3493. GNUTLS_LIBS="-lgnutls"
  3494. have_gnutls=yes
  3495. ])], [], [AC_INCLUDES_DEFAULT])
  3496. ])
  3497. ])
  3498. have_gcrypt='unknown'
  3499. AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"],
  3500. [
  3501. AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no])
  3502. AS_IF([[test "x$have_gcrypt" = "xyes"]],
  3503. [
  3504. SAVE_LIBS="$LIBS"
  3505. CFLAGS="${CFLAGS_ac} $LIBGCRYPT_CFLAGS ${user_CFLAGS}"
  3506. # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both
  3507. CPPFLAGS="${CPPFLAGS_ac} $LIBGCRYPT_CFLAGS ${user_CPPFLAGS}"
  3508. AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no], [AC_INCLUDES_DEFAULT])
  3509. # Check for GnuTLS with gcrypt flags
  3510. LDFLAGS="${LDFLAGS_ac} ${LIBGCRYPT_LIBS} ${user_LDFLAGS}"
  3511. # A bit of hack: unset cache variable to force recheck
  3512. AS_UNSET([ac_cv_header_gnutls_gnutls_h])
  3513. AC_CHECK_HEADERS([gnutls/gnutls.h],
  3514. [AS_UNSET([ac_cv_lib_gnutls_gnutls_priority_set]) # A bit of hack: unset cache variable to force recheck
  3515. AC_CHECK_LIB([gnutls], [gnutls_priority_set],
  3516. [
  3517. GNUTLS_CPPFLAGS="$LIBGCRYPT_CFLAGS"
  3518. GNUTLS_CFLAGS="$LIBGCRYPT_CFLAGS"
  3519. GNUTLS_LDFLAGS="$LIBGCRYPT_LIBS"
  3520. GNUTLS_LIBS="-lgnutls"
  3521. have_gnutls=yes
  3522. ])], [], [AC_INCLUDES_DEFAULT])
  3523. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3524. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3525. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3526. LIBS="$SAVE_LIBS"
  3527. ]
  3528. )
  3529. ]
  3530. )
  3531. AS_IF([test "x$have_gnutls" != "xyes" && test "x$with_gnutls" = "xyes"],
  3532. [AC_MSG_ERROR([[can't find usable libgnutls]])])
  3533. AS_IF([test "x$have_gnutls" = "xyes"],
  3534. [
  3535. SAVE_LIBS="$LIBS"
  3536. CPPFLAGS="${CPPFLAGS_ac} ${GNUTLS_CPPFLAGS} ${user_CPPFLAGS}"
  3537. CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}"
  3538. LDFLAGS="${LDFLAGS_ac} ${GNUTLS_LDFLAGS} ${user_LDFLAGS}"
  3539. LIBS="$GNUTLS_LIBS $LIBS"
  3540. AC_MSG_CHECKING([[for gnutls_privkey_import_x509_raw()]])
  3541. AC_LINK_IFELSE([
  3542. AC_LANG_PROGRAM([[
  3543. #include <gnutls/gnutls.h>
  3544. #include <gnutls/abstract.h>
  3545. ]], [[
  3546. gnutls_datum_t data;
  3547. gnutls_privkey_t key = 0;
  3548. #ifndef gnutls_load_file
  3549. (void)gnutls_load_file; /* Check for declaration. */
  3550. #endif
  3551. #ifndef gnutls_privkey_import_x509_raw
  3552. (void)gnutls_privkey_import_x509_raw; /* Check for declaration. */
  3553. #endif
  3554. gnutls_load_file("key.pem", &data);
  3555. gnutls_privkey_import_x509_raw(key, &data, GNUTLS_X509_FMT_PEM, NULL, 0);
  3556. gnutls_free(data.data);
  3557. ]])], [[have_gnutls_sni=yes]], [[have_gnutls_sni=no]])
  3558. AC_MSG_RESULT([[$have_gnutls_sni]])
  3559. AC_CACHE_CHECK([[whether GnuTLS require libgcrypt initialisation]], [mhd_cv_gcrypt_required],
  3560. [
  3561. AC_COMPILE_IFELSE(
  3562. [
  3563. AC_LANG_PROGRAM(
  3564. [
  3565. #include <gnutls/gnutls.h>
  3566. ],
  3567. [
  3568. #if !defined(GNUTLS_VERSION_NUMBER) || GNUTLS_VERSION_NUMBER+0 <= 0x020c14
  3569. #error Old versions of GnuTLS require libgcript initialisation
  3570. choke me now
  3571. #endif
  3572. ]
  3573. )
  3574. ],
  3575. [[mhd_cv_gcrypt_required='no']], [[mhd_cv_gcrypt_required='yes']]
  3576. )
  3577. ]
  3578. )
  3579. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3580. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3581. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3582. LIBS="$SAVE_LIBS"
  3583. ],
  3584. [
  3585. AS_UNSET([GNUTLS_CPPFLAGS])
  3586. AS_UNSET([GNUTLS_LDFLAGS])
  3587. ]
  3588. )
  3589. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes" && test "x$have_gcrypt" = "xunknown"]],
  3590. [
  3591. AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no])
  3592. AS_IF([[test "x$have_gcrypt" = "xyes"]],
  3593. [
  3594. CFLAGS="${CFLAGS_ac} ${LIBGCRYPT_CFLAGS} ${user_CFLAGS}"
  3595. # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both
  3596. CPPFLAGS="${CPPFLAGS_ac} ${LIBGCRYPT_CFLAGS} ${user_CPPFLAGS}"
  3597. AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no], [AC_INCLUDES_DEFAULT])
  3598. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3599. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3600. ]
  3601. )
  3602. ]
  3603. )
  3604. AS_UNSET([[crypt_missing]])
  3605. AS_IF([[test "x$have_gnutls" = "xyes"]],
  3606. [
  3607. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes" && test "x$have_gcrypt" != "xyes"]],
  3608. [
  3609. crypt_missing="required libgcrypt"
  3610. AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])])
  3611. enable_https=no
  3612. MSG_HTTPS="no (lacking $crypt_missing)"
  3613. AS_UNSET([LIBGCRYPT_CFLAGS])
  3614. AS_UNSET([LIBGCRYPT_LIBS])
  3615. AS_UNSET([GNUTLS_CPPFLAGS])
  3616. AS_UNSET([GNUTLS_CFLAGS])
  3617. AS_UNSET([GNUTLS_LDFLAGS])
  3618. AS_UNSET([GNUTLS_LIBS])
  3619. ],
  3620. [
  3621. AC_DEFINE([[HTTPS_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTPS support.])
  3622. enable_https=yes
  3623. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  3624. [
  3625. MSG_HTTPS="yes (using libgnutls and libgcrypt)"
  3626. MHD_TLS_LIB_CPPFLAGS="$LIBGCRYPT_CFLAGS $GNUTLS_CPPFLAGS"
  3627. MHD_TLS_LIB_CFLAGS="$LIBGCRYPT_CFLAGS $GNUTLS_CFLAGS"
  3628. MHD_TLS_LIB_LDFLAGS="$GNUTLS_LDFLAGS"
  3629. MHD_TLS_LIBDEPS="$GNUTLS_LIBS $LIBGCRYPT_LIBS"
  3630. AC_DEFINE([[MHD_HTTPS_REQUIRE_GCRYPT]], [[1]], [Define to `1' if HTTPS require initialisation of libgcrypt])
  3631. ],
  3632. [
  3633. MSG_HTTPS="yes (using libgnutls)"
  3634. AS_UNSET([LIBGCRYPT_CFLAGS])
  3635. AS_UNSET([LIBGCRYPT_LIBS])
  3636. MHD_TLS_LIB_CPPFLAGS="$GNUTLS_CPPFLAGS"
  3637. MHD_TLS_LIB_CFLAGS="$GNUTLS_CFLAGS"
  3638. MHD_TLS_LIB_LDFLAGS="$GNUTLS_LDFLAGS"
  3639. MHD_TLS_LIBDEPS="$GNUTLS_LIBS"
  3640. ]
  3641. )
  3642. AS_IF([[ test "x$have_gnutls_pkgcfg" = "xyes" ]],
  3643. [ # remove GnuTLS from private libs in .pc file as it defined in Requires.private
  3644. MHD_REQ_PRIVATE='gnutls'
  3645. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  3646. [[MHD_LIBDEPS_PKGCFG="$LIBGCRYPT_LIBS $MHD_LIBDEPS_PKGCFG"]]
  3647. )
  3648. ],
  3649. [
  3650. MHD_REQ_PRIVATE=''
  3651. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  3652. [[MHD_LIBDEPS_PKGCFG="$LIBGCRYPT_LIBS $MHD_LIBDEPS_PKGCFG"]]
  3653. )
  3654. MHD_LIBDEPS_PKGCFG="$GNUTLS_LIBS $MHD_LIBDEPS_PKGCFG"
  3655. ])
  3656. ]
  3657. )
  3658. ],
  3659. [
  3660. crypt_missing="libgnutls"
  3661. AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])])
  3662. enable_https=no
  3663. MSG_HTTPS="no (lacking $crypt_missing)"
  3664. AS_UNSET([LIBGCRYPT_CFLAGS])
  3665. AS_UNSET([LIBGCRYPT_LIBS])
  3666. AS_UNSET([GNUTLS_CPPFLAGS])
  3667. AS_UNSET([GNUTLS_CFLAGS])
  3668. AS_UNSET([GNUTLS_LDFLAGS])
  3669. AS_UNSET([GNUTLS_LIBS])
  3670. ]
  3671. )
  3672. ],[
  3673. MSG_HTTPS="no (disabled)"
  3674. ])
  3675. #
  3676. # End of large unindented block
  3677. #
  3678. AC_MSG_CHECKING(whether to support HTTPS)
  3679. AC_MSG_RESULT([$MSG_HTTPS])
  3680. AM_CONDITIONAL([HAVE_GNUTLS], [[test "x$have_gnutls" = "xyes"]])
  3681. AM_CONDITIONAL([HAVE_GNUTLS_SNI], [[test "x$have_gnutls_sni" = "xyes"]])
  3682. AM_CONDITIONAL([ENABLE_HTTPS], [test "x$enable_https" = "xyes"])
  3683. AM_CONDITIONAL([HTTPS_REQUIRE_GCRYPT], [[test "x$enable_https" = "xyes" && test "x$mhd_cv_gcrypt_required" = "xyes"]])
  3684. AC_SUBST([GNUTLS_CPPFLAGS])
  3685. AC_SUBST([GNUTLS_CFLAGS])
  3686. AC_SUBST([GNUTLS_LDFLAGS])
  3687. AC_SUBST([GNUTLS_LIBS])
  3688. AS_VAR_IF([have_gnutls], ["yes"],
  3689. [
  3690. AC_CACHE_CHECK([for GnuTLS quirks], [mhd_cv_gnutls_mthread_broken],
  3691. [
  3692. mhd_cv_gnutls_mthread_broken="no"
  3693. AS_IF([test -r /etc/redhat-release],
  3694. [
  3695. AS_IF([$FGREP ' release 6.' /etc/redhat-release >/dev/null || $FGREP '(Santiago)' /etc/redhat-release >/dev/null],
  3696. [mhd_cv_gnutls_mthread_broken="found"],
  3697. )
  3698. ]
  3699. )
  3700. AS_VAR_IF([mhd_cv_gnutls_mthread_broken], ["no"],
  3701. [
  3702. AS_IF([command -v rpm >/dev/null],
  3703. [
  3704. AS_IF([test "r`rpm -E '%{rhel}' 2>/dev/null`" = "r6"],
  3705. [mhd_cv_gnutls_mthread_broken="found"],
  3706. )
  3707. ]
  3708. )
  3709. ]
  3710. )
  3711. ]
  3712. )
  3713. AC_CACHE_CHECK([for gnutls-cli binary], [mhd_cv_gnutls_cli],
  3714. [
  3715. mhd_cv_gnutls_cli="no"
  3716. AS_IF([command -v gnutls-cli >/dev/null 2>&1],
  3717. [AS_IF([AC_RUN_LOG([gnutls-cli --version >&2])], [mhd_cv_gnutls_cli="yes"])]
  3718. )
  3719. ]
  3720. )
  3721. ]
  3722. )
  3723. AM_CONDITIONAL([HAVE_GNUTLS_MTHREAD_BROKEN], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xfound"]])
  3724. AM_CONDITIONAL([USE_UPGRADE_TLS_TESTS], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xno" || test "x${mhd_cv_gnutls_cli}" = "xyes"]])
  3725. # optional: HTTP Basic Auth support. Enabled by default
  3726. AC_MSG_CHECKING([[whether to support HTTP Basic authentication]])
  3727. AC_ARG_ENABLE([bauth],
  3728. [AS_HELP_STRING([--disable-bauth],[disable HTTP Basic Authentication support])],
  3729. [enable_bauth=${enableval}],
  3730. [enable_bauth=yes])
  3731. AS_IF([[test "x$enable_bauth" != "xno"]],
  3732. [ enable_bauth=yes
  3733. AC_DEFINE([BAUTH_SUPPORT],[1],[Define to 1 if libmicrohttpd is compiled with Basic Auth support.]) ])
  3734. AM_CONDITIONAL([ENABLE_BAUTH], [test "x$enable_bauth" != "xno"])
  3735. AC_MSG_RESULT([[$enable_bauth]])
  3736. # optional: HTTP Digest Auth support. Enabled by default
  3737. AC_MSG_CHECKING([[whether to support HTTP Digest authentication]])
  3738. AC_ARG_ENABLE([dauth],
  3739. [AS_HELP_STRING([--disable-dauth], [disable HTTP Digest Authentication support])],
  3740. [enable_dauth="${enableval}"],
  3741. [enable_dauth="yes"])
  3742. AS_IF([[test "x$enable_dauth" != "xno"]],
  3743. [ enable_dauth=yes
  3744. AC_DEFINE([DAUTH_SUPPORT],[1],[Define to 1 if libmicrohttpd is compiled with Digest Auth support.]) ])
  3745. AM_CONDITIONAL([ENABLE_DAUTH], [test "x$enable_dauth" != "xno"])
  3746. AC_MSG_RESULT([[$enable_dauth]])
  3747. AS_VAR_IF([enable_dauth], ["yes"],
  3748. [
  3749. AC_MSG_CHECKING([[for Digest Authentication default nonce timeout value]])
  3750. AC_ARG_ENABLE([dauth-def-timeout],
  3751. [AS_HELP_STRING([--enable-dauth-def-timeout=NNN],
  3752. [set default Digest Auth nonce validity time to NNN seconds [90]])],
  3753. [enable_dauth_def_timeout="${enableval}"],
  3754. [enable_dauth_def_timeout=""]
  3755. )
  3756. AS_VAR_IF([enable_dauth_def_timeout], ["no"],
  3757. [
  3758. AC_MSG_WARN([Default Diget Auth nonce validity time cannot be disabled, --disable-dauth-def-timeout parameter is ignored])
  3759. enable_dauth_def_timeout=""
  3760. ]
  3761. )
  3762. AS_IF([test -z "${enable_dauth_def_timeout}"],
  3763. [
  3764. enable_dauth_def_timeout="90"
  3765. enable_dauth_def_timeout_MSG="${enable_dauth_def_timeout} seconds (default)"
  3766. ],
  3767. [
  3768. AS_IF([[test "x${enable_dauth_def_timeout}" = "x`echo ${enable_dauth_def_timeout}|${SED-sed} 's/[^0-9]//g'`" && \
  3769. test "${enable_dauth_def_timeout}" -ge "0" 2>/dev/null ]],[:],
  3770. [AC_MSG_ERROR([Invalid parameter --enable-dauth-def-timeout=${enable_dauth_def_timeout}. Timeout value must be a positive integer.])
  3771. ]
  3772. )
  3773. AC_COMPILE_IFELSE(
  3774. [
  3775. AC_LANG_PROGRAM([],
  3776. [[
  3777. static int arr[((int) 2) - 4 * (int)(${enable_dauth_def_timeout} != ((unsigned int)${enable_dauth_def_timeout}))];
  3778. (void) arr;
  3779. ]]
  3780. )
  3781. ],
  3782. [],
  3783. [AC_MSG_ERROR([The value specified by --enable-dauth-def-timeout=${enable_dauth_def_timeout} is too large.])]
  3784. )
  3785. enable_dauth_def_timeout_MSG="${enable_dauth_def_timeout} seconds (set by parameter)"
  3786. ]
  3787. )
  3788. AC_DEFINE_UNQUOTED([MHD_DAUTH_DEF_TIMEOUT_],[${enable_dauth_def_timeout}],
  3789. [The default HTTP Digest Auth default nonce timeout value (in seconds)])
  3790. AC_MSG_RESULT([[${enable_dauth_def_timeout_MSG}]])
  3791. AC_MSG_CHECKING([[for Digest Authentication default maximum nc value]])
  3792. AC_ARG_ENABLE([dauth-def-max-nc],
  3793. [AS_HELP_STRING([--enable-dauth-def-max-nc=NNN],
  3794. [set default Digest Auth maximum nc (nonce count) value to NNN [1000]])],
  3795. [enable_dauth_def_max_nc="${enableval}"],
  3796. [enable_dauth_def_max_nc=""]
  3797. )
  3798. AS_VAR_IF([enable_dauth_def_max_nc], ["no"],
  3799. [
  3800. AC_MSG_WARN([Default Diget Auth maximum nc cannot be disabled, --disable-dauth-def-max-nc parameter is ignored])
  3801. enable_dauth_def_max_nc=""
  3802. ]
  3803. )
  3804. AS_IF([test -z "${enable_dauth_def_max_nc}"],
  3805. [
  3806. enable_dauth_def_max_nc="1000"
  3807. enable_dauth_def_max_nc_MSG="${enable_dauth_def_max_nc} (default)"
  3808. ],
  3809. [
  3810. AS_IF([[test "x${enable_dauth_def_max_nc}" = "x`echo ${enable_dauth_def_max_nc}|${SED-sed} 's/[^0-9]//g'`" && \
  3811. test "${enable_dauth_def_max_nc}" -ge "0" 2>/dev/null ]],[:],
  3812. [AC_MSG_ERROR([Invalid parameter --enable-dauth-def-max-nc=${enable_dauth_def_max_nc}. The value must be a positive integer.])
  3813. ]
  3814. )
  3815. AC_COMPILE_IFELSE(
  3816. [
  3817. AC_LANG_PROGRAM(
  3818. [[
  3819. #include <stdint.h>
  3820. ]],
  3821. [[
  3822. static int arr[((int) 2) - 4 * (int)(${enable_dauth_def_max_nc} != ((uint32_t)${enable_dauth_def_max_nc}))];
  3823. (void) arr;
  3824. ]]
  3825. )
  3826. ],
  3827. [],
  3828. [AC_MSG_ERROR([The value specified by --enable-dauth-def-max-nc=${enable_dauth_def_max_nc} is too large.])]
  3829. )
  3830. enable_dauth_def_max_nc_MSG="${enable_dauth_def_max_nc} (set by parameter)"
  3831. ]
  3832. )
  3833. AC_DEFINE_UNQUOTED([MHD_DAUTH_DEF_MAX_NC_],[${enable_dauth_def_max_nc}],
  3834. [The default HTTP Digest Auth default maximum nc (nonce count) value])
  3835. AC_MSG_RESULT([[${enable_dauth_def_max_nc_MSG}]])
  3836. dauth_defs_MSG="timeout: ${enable_dauth_def_timeout_MSG}, max nc: ${enable_dauth_def_max_nc_MSG}"
  3837. ],
  3838. [
  3839. dauth_defs_MSG="N/A"
  3840. ]
  3841. )
  3842. AM_CONDITIONAL([HAVE_ANYAUTH],[test "x$enable_bauth" != "xno" || test "x$enable_dauth" != "xno"])
  3843. # optional: HTTP "Upgrade" support. Enabled by default
  3844. AC_MSG_CHECKING([[whether to support HTTP "Upgrade"]])
  3845. AC_ARG_ENABLE([[httpupgrade]],
  3846. [AS_HELP_STRING([[--disable-httpupgrade]], [disable HTTP "Upgrade" support])],
  3847. [AS_VAR_IF([[enable_httpupgrade]],[["no"]],[],[[enable_httpupgrade='yes']])],
  3848. [[enable_httpupgrade='yes']])
  3849. AS_VAR_IF([[enable_httpupgrade]],[["yes"]],
  3850. [
  3851. AC_DEFINE([[UPGRADE_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP Upgrade support.]) ])
  3852. AM_CONDITIONAL([ENABLE_UPGRADE], [[test "x$enable_httpupgrade" = "xyes"]])
  3853. AC_MSG_RESULT([[$enable_httpupgrade]])
  3854. # optional: HTTP cookie parsing support. Enabled by default
  3855. AC_MSG_CHECKING([[whether to support HTTP cookie parsing]])
  3856. AC_ARG_ENABLE([[cookie]],
  3857. [AS_HELP_STRING([[--disable-cookie]], [disable HTTP cookie parsing support])],
  3858. [AS_VAR_IF([[enable_cookie]],[["no"]],[],[[enable_cookie='yes']])],
  3859. [[enable_cookie='yes']])
  3860. AS_VAR_IF([[enable_cookie]],[["yes"]],
  3861. [
  3862. AC_DEFINE([[COOKIE_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP cookie parsing support.]) ])
  3863. AM_CONDITIONAL([ENABLE_COOKIE], [[test "x$enable_cookie" = "xyes"]])
  3864. AC_MSG_RESULT([[$enable_cookie]])
  3865. # optional: MD5 support for Digest Auth. Enabled by default.
  3866. AC_ARG_ENABLE([[md5]],
  3867. [AS_HELP_STRING([[--enable-md5=TYPE]],
  3868. [enable TYPE of MD5 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])],
  3869. [
  3870. AS_VAR_IF([enable_md5],["internal"],[enable_md5='builtin'])
  3871. AS_VAR_IF([enable_md5],["built-in"],[enable_md5='builtin'])
  3872. AS_VAR_IF([enable_dauth],["yes"],[],
  3873. [
  3874. AS_VAR_IF([enable_md5],["no"],[],
  3875. [
  3876. AC_MSG_WARN([The parameter --enable-md5=${enable_md5} is ignored as Digest Authentication is disabled])
  3877. enable_md5='no'
  3878. ]
  3879. )
  3880. ]
  3881. )
  3882. ], [[enable_md5="${enable_dauth}"]]
  3883. )
  3884. AS_CASE([${enable_md5}],[yes|tlslib],
  3885. [
  3886. AS_IF([test "x${enable_compact_code}" != "xno" || test "x$enable_md5" = "xtlslib"],
  3887. [
  3888. AS_IF([test "x$enable_https" = "xyes"],
  3889. [
  3890. AC_CACHE_CHECK([whether GnuTLS supports MD5 hashing],[mhd_cv_gnutls_md5],
  3891. [
  3892. CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}"
  3893. CPPFLAGS="${CPPFLAGS_ac} ${MHD_TLS_LIB_CPPFLAGS} ${user_CPPFLAGS}"
  3894. CFLAGS="${CFLAGS_ac} ${MHD_TLS_LIB_CFLAGS} ${user_CFLAGS}"
  3895. LDFLAGS="${LDFLAGS_ac} ${MHD_TLS_LIB_LDFLAGS} ${user_LDFLAGS}"
  3896. save_LIBS="$LIBS"
  3897. LIBS="${MHD_TLS_LIBDEPS} ${LIBS}"
  3898. AC_LINK_IFELSE(
  3899. [
  3900. AC_LANG_PROGRAM(
  3901. [[
  3902. #include <gnutls/crypto.h>
  3903. ]],
  3904. [[
  3905. gnutls_hash_hd_t hash_handle;
  3906. unsigned char digest[16];
  3907. int exit_code;
  3908. if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_MD5))
  3909. {
  3910. if (0 == gnutls_hash(hash_handle, "", 1))
  3911. {
  3912. gnutls_hash_output(hash_handle, digest);
  3913. if (0x93 == digest[0])
  3914. exit_code = 0;
  3915. else
  3916. exit_code = 7;
  3917. }
  3918. else
  3919. exit_code = 5;
  3920. gnutls_hash_deinit(hash_handle, (void *)0);
  3921. }
  3922. else
  3923. exit_code = 2;
  3924. if (exit_code)
  3925. return exit_code;
  3926. ]]
  3927. )
  3928. ],
  3929. [mhd_cv_gnutls_md5='yes'],[mhd_cv_gnutls_md5='no']
  3930. )
  3931. LIBS="${save_LIBS}"
  3932. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3933. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  3934. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  3935. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  3936. ]
  3937. )
  3938. AS_VAR_IF([mhd_cv_gnutls_md5],["no"],
  3939. [
  3940. AS_VAR_IF([enable_md5],["tlslib"],
  3941. [AC_MSG_FAILURE([TLS library MD5 implementation is not available])]
  3942. )
  3943. enable_md5="builtin"
  3944. ],
  3945. [enable_md5="tlslib"]
  3946. )
  3947. ],
  3948. [
  3949. AS_VAR_IF([enable_md5],["tlslib"],
  3950. [AC_MSG_ERROR([HTTPS is not enabled, TLS library MD5 implementation cannot be used])]
  3951. )
  3952. enable_md5="builtin"
  3953. ]
  3954. )
  3955. ],
  3956. [
  3957. enable_md5="builtin"
  3958. ]
  3959. )
  3960. ]
  3961. )
  3962. AC_MSG_CHECKING([[whether to support MD5]])
  3963. AS_UNSET([enable_md5_MSG])
  3964. AS_CASE([${enable_md5}],
  3965. [builtin],[enable_md5_MSG='yes, built-in'],
  3966. [tlslib],[enable_md5_MSG='yes, external (TLS library)'],
  3967. [no],[enable_md5_MSG='no'],
  3968. [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])],
  3969. [AC_MSG_ERROR([Unrecognized parameter --enable-md5=${enable_md5}])]
  3970. )
  3971. AS_IF([test "x${enable_md5}" = "xbuiltin" || test "x${enable_md5}" = "xtlslib" ],
  3972. [
  3973. AC_DEFINE([[MHD_MD5_SUPPORT]],[[1]],
  3974. [Define to 1 if libmicrohttpd is compiled with MD5 hashing support.])
  3975. ]
  3976. )
  3977. AS_IF([test "x${enable_md5}" = "xtlslib" ],
  3978. [
  3979. AC_DEFINE([[MHD_MD5_TLSLIB]],[[1]],
  3980. [Define to 1 if libmicrohttpd is compiled with MD5 hashing by TLS library.])
  3981. ]
  3982. )
  3983. AM_CONDITIONAL([ENABLE_MD5], [[test "x${enable_md5}" = "xbuiltin" || test "x${enable_md5}" = "xtlslib" ]])
  3984. AM_CONDITIONAL([ENABLE_MD5_EXT], [[test "x${enable_md5}" = "xtlslib" ]])
  3985. AC_MSG_RESULT([[${enable_md5_MSG}]])
  3986. # optional: SHA-256 support for Digest Auth. Enabled by default.
  3987. AC_ARG_ENABLE([[sha256]],
  3988. [AS_HELP_STRING([[--enable-sha256=TYPE]],
  3989. [enable TYPE of SHA-256 hashing code (yes, no, builtin, tlslib) [yes if dauth enabled]])],
  3990. [
  3991. AS_VAR_IF([enable_sha256],["internal"],[enable_sha256='builtin'])
  3992. AS_VAR_IF([enable_sha256],["built-in"],[enable_sha256='builtin'])
  3993. AS_VAR_IF([enable_dauth],["yes"],[],
  3994. [
  3995. AS_VAR_IF([enable_sha256],["no"],[],
  3996. [
  3997. AC_MSG_WARN([The parameter --enable-sha256=${enable_sha256} is ignored as Digest Authentication is disabled])
  3998. enable_sha256='no'
  3999. ]
  4000. )
  4001. ]
  4002. )
  4003. ], [[enable_sha256="${enable_dauth}"]]
  4004. )
  4005. AS_CASE([${enable_sha256}],[yes|tlslib],
  4006. [
  4007. AS_IF([test "x${enable_compact_code}" != "xno" || test "x$enable_sha256" = "xtlslib"],
  4008. [
  4009. AS_IF([test "x$enable_https" = "xyes"],
  4010. [
  4011. AC_CACHE_CHECK([whether GnuTLS supports sha256 hashing],[mhd_cv_gnutls_sha256],
  4012. [
  4013. CFLAGS="${CFLAGS_ac} ${GNUTLS_CFLAGS} ${user_CFLAGS}"
  4014. CPPFLAGS="${CPPFLAGS_ac} ${MHD_TLS_LIB_CPPFLAGS} ${user_CPPFLAGS}"
  4015. CFLAGS="${CFLAGS_ac} ${MHD_TLS_LIB_CFLAGS} ${user_CFLAGS}"
  4016. LDFLAGS="${LDFLAGS_ac} ${MHD_TLS_LIB_LDFLAGS} ${user_LDFLAGS}"
  4017. save_LIBS="$LIBS"
  4018. LIBS="${MHD_TLS_LIBDEPS} ${LIBS}"
  4019. AC_LINK_IFELSE(
  4020. [
  4021. AC_LANG_PROGRAM(
  4022. [[
  4023. #include <gnutls/crypto.h>
  4024. ]],
  4025. [[
  4026. gnutls_hash_hd_t hash_handle;
  4027. unsigned char digest[32];
  4028. int exit_code;
  4029. if (0 == gnutls_hash_init(&hash_handle, GNUTLS_DIG_SHA256))
  4030. {
  4031. if (0 == gnutls_hash(hash_handle, "", 1))
  4032. {
  4033. gnutls_hash_output(hash_handle, digest);
  4034. if (0x6e == digest[0])
  4035. exit_code = 0;
  4036. else
  4037. exit_code = 7;
  4038. }
  4039. else
  4040. exit_code = 5;
  4041. gnutls_hash_deinit(hash_handle, (void *)0);
  4042. }
  4043. else
  4044. exit_code = 2;
  4045. if (exit_code)
  4046. return exit_code;
  4047. ]]
  4048. )
  4049. ],
  4050. [mhd_cv_gnutls_sha256='yes'],[mhd_cv_gnutls_sha256='no']
  4051. )
  4052. LIBS="${save_LIBS}"
  4053. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  4054. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  4055. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  4056. LDFLAGS="${LDFLAGS_ac} ${user_LDFLAGS}"
  4057. ]
  4058. )
  4059. AS_VAR_IF([mhd_cv_gnutls_sha256],["no"],
  4060. [
  4061. AS_VAR_IF([enable_sha256],["tlslib"],
  4062. [AC_MSG_FAILURE([TLS library SHA-256 implementation is not available])]
  4063. )
  4064. enable_sha256="builtin"
  4065. ],
  4066. [enable_sha256="tlslib"]
  4067. )
  4068. ],
  4069. [
  4070. AS_VAR_IF([enable_sha256],["tlslib"],
  4071. [AC_MSG_ERROR([HTTPS is not enabled, TLS library SHA-256 implementation cannot be used])]
  4072. )
  4073. enable_sha256="builtin"
  4074. ]
  4075. )
  4076. ],
  4077. [
  4078. enable_sha256="builtin"
  4079. ]
  4080. )
  4081. ]
  4082. )
  4083. AC_MSG_CHECKING([[whether to support SHA-256]])
  4084. AS_UNSET([enable_sha256_MSG])
  4085. AS_CASE([${enable_sha256}],
  4086. [builtin],[enable_sha256_MSG='yes, built-in'],
  4087. [tlslib],[enable_sha256_MSG='yes, external (TLS library)'],
  4088. [no],[enable_sha256_MSG='no'],
  4089. [yes],[AC_MSG_ERROR([configure internal error: unexpected variable value])],
  4090. [AC_MSG_ERROR([Unrecognized parameter --enable-sha256=${enable_sha256}])]
  4091. )
  4092. AS_IF([test "x${enable_sha256}" = "xbuiltin" || test "x${enable_sha256}" = "xtlslib" ],
  4093. [
  4094. AC_DEFINE([[MHD_SHA256_SUPPORT]],[[1]],
  4095. [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing support.])
  4096. ]
  4097. )
  4098. AS_IF([test "x${enable_sha256}" = "xtlslib" ],
  4099. [
  4100. AC_DEFINE([[MHD_SHA256_TLSLIB]],[[1]],
  4101. [Define to 1 if libmicrohttpd is compiled with SHA-256 hashing by TLS library.])
  4102. ]
  4103. )
  4104. AM_CONDITIONAL([ENABLE_SHA256], [[test "x${enable_sha256}" = "xbuiltin" || test "x${enable_sha256}" = "xtlslib" ]])
  4105. AM_CONDITIONAL([ENABLE_SHA256_EXT], [[test "x${enable_sha256}" = "xtlslib" ]])
  4106. AC_MSG_RESULT([[${enable_sha256_MSG}]])
  4107. # optional: SHA-512/256 support for Digest Auth. Enabled by default.
  4108. AC_ARG_ENABLE([[sha512-256]],
  4109. [AS_HELP_STRING([[--disable-sha512-256]],
  4110. [disable SHA-512/256 hashing support for Digest Authentication])],
  4111. [
  4112. AS_VAR_IF([[enable_sha512_256]],[["yes"]],
  4113. [
  4114. AS_VAR_IF([enable_dauth],["yes"],[],
  4115. [
  4116. AC_MSG_WARN([The parameter --enable-sha512-256 is ignored as Digest Authentication is disabled])
  4117. enable_sha512_256='no'
  4118. ]
  4119. )
  4120. ],[[enable_sha512_256='no']]
  4121. )
  4122. ], [[enable_sha512_256="${enable_dauth}"]]
  4123. )
  4124. AC_MSG_CHECKING([[whether to support SHA-512/256]])
  4125. AS_UNSET([enable_sha512_256_MSG])
  4126. AS_CASE([${enable_sha512_256}],
  4127. [yes],[enable_sha512_256_MSG='yes, built-in'],
  4128. [no],[enable_sha512_256_MSG='no'],
  4129. [AC_MSG_ERROR([Unrecognized parameter --enable-sha512-256=${enable_sha512_256}])]
  4130. )
  4131. AS_VAR_IF([[enable_sha512_256]],[["yes"]],
  4132. [
  4133. AC_DEFINE([[MHD_SHA512_256_SUPPORT]],[[1]],
  4134. [Define to 1 if libmicrohttpd is compiled with SHA-512/256 hashing support.])
  4135. ]
  4136. )
  4137. AM_CONDITIONAL([ENABLE_SHA512_256], [[test "x${enable_sha512_256}" = "xyes"]])
  4138. AC_MSG_RESULT([[${enable_sha512_256_MSG}]])
  4139. AS_IF([test "x$enable_dauth" != "xno"],
  4140. [
  4141. AS_IF([test "x${enable_md5}" = "xno" && test "x${enable_sha256}" = "xno" && test "x${enable_sha512_256}" != "xyes"],
  4142. [AC_MSG_ERROR([At least one hashing algorithm must be enabled if Digest Auth is enabled])]
  4143. )
  4144. ]
  4145. )
  4146. AC_CACHE_CHECK([[for calloc()]], [[mhd_cv_have_func_calloc]],
  4147. [
  4148. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  4149. #include <stdlib.h>
  4150. ]],[[void * ptr = calloc(1, 2); if (ptr) return 1;]])
  4151. ],
  4152. [[mhd_cv_have_func_calloc='yes']],
  4153. [[mhd_cv_have_func_calloc='no']]
  4154. )
  4155. ]
  4156. )
  4157. AS_VAR_IF([[mhd_cv_have_func_calloc]], [["yes"]],
  4158. [AC_DEFINE([[HAVE_CALLOC]], [[1]], [Define to 1 if you have the usable `calloc' function.])])
  4159. # Some systems have IPv6 disabled in kernel at run-time
  4160. AS_IF([[test "x${mhd_cv_have_inet6}" = "xyes" && test "x${cross_compiling}" = "xno"]],
  4161. [
  4162. AC_CACHE_CHECK([whether IPv6 could be used for testing],[mhd_cv_ipv6_for_testing],
  4163. [
  4164. AC_RUN_IFELSE(
  4165. [
  4166. AC_LANG_SOURCE([[
  4167. #ifdef HAVE_UNISTD_H
  4168. #include <unistd.h>
  4169. #endif
  4170. #ifdef HAVE_SYS_TYPES_H
  4171. #include <sys/types.h>
  4172. #endif
  4173. #ifdef HAVE_SYS_SOCKET_H
  4174. #include <sys/socket.h>
  4175. #endif
  4176. #ifdef HAVE_WINSOCK2_H
  4177. #include <winsock2.h>
  4178. #endif
  4179. #ifdef HAVE_WS2TCPIP_H
  4180. #include <ws2tcpip.h>
  4181. #endif
  4182. #ifdef HAVE_NETINET_IN_H
  4183. #include <netinet/in.h>
  4184. #endif
  4185. #ifdef HAVE_NETINET_IP_H
  4186. #include <netinet/ip.h>
  4187. #endif
  4188. #ifdef HAVE_ARPA_INET_H
  4189. #include <arpa/inet.h>
  4190. #endif
  4191. #ifdef HAVE_NETINET_TCP_H
  4192. #include <netinet/tcp.h>
  4193. #endif
  4194. static void zr_mem(void *ptr, socklen_t size)
  4195. { char *mem = ptr; while(size--) {mem[0] = 0; mem++;} }
  4196. int main(void)
  4197. {
  4198. int ret = 30;
  4199. struct sockaddr_in6 sa;
  4200. #if !defined(_WIN32) || defined(__CYGWIN__)
  4201. int sckt;
  4202. const int invld_sckt = -1;
  4203. #else
  4204. SOCKET sckt;
  4205. const SOCKET invld_sckt = INVALID_SOCKET;
  4206. WSADATA wsa_data;
  4207. WSAStartup(MAKEWORD(2, 2), &wsa_data);
  4208. #endif
  4209. zr_mem(&sa, sizeof(sa));
  4210. sa.sin6_family = AF_INET6;
  4211. sa.sin6_port = 0;
  4212. sa.sin6_addr = in6addr_loopback;
  4213. #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
  4214. sa.sin6_len = sizeof(sa);
  4215. #endif
  4216. sckt = socket (PF_INET6, SOCK_STREAM, 0);
  4217. if (invld_sckt != sckt)
  4218. {
  4219. if (0 == bind (sckt, (struct sockaddr *)&sa, sizeof(sa)))
  4220. {
  4221. if (0 == listen (sckt, 1))
  4222. ret = 0;
  4223. else
  4224. ret = 1; /* listen() failed */
  4225. } else ret = 2; /* bind() failed */
  4226. #if !defined(_WIN32) || defined(__CYGWIN__)
  4227. close (sckt);
  4228. #else
  4229. closesocket (sckt);
  4230. #endif
  4231. } else ret = 3; /* socket() failed */
  4232. #if defined(_WIN32) && !defined(__CYGWIN__)
  4233. WSACleanup();
  4234. #endif
  4235. return ret;
  4236. }
  4237. ]])
  4238. ], [[mhd_cv_ipv6_for_testing="yes"]], [[mhd_cv_ipv6_for_testing="no"]], [[mhd_cv_ipv6_for_testing="no"]]
  4239. )
  4240. ]
  4241. )
  4242. ]
  4243. )
  4244. AS_VAR_IF([mhd_cv_ipv6_for_testing],["yes"],
  4245. [AC_DEFINE([[USE_IPV6_TESTING]], [[1]], [Define to 1 if your kernel supports IPv6 and IPv6 is enabled and useful for testing.])]
  4246. )
  4247. AS_VAR_IF([enable_tools],["yes"],
  4248. [
  4249. AC_CHECK_HEADERS([features.h sys/pstat.h vxCpuLib.h],[],[],[AC_INCLUDES_DEFAULT])
  4250. AC_CHECK_DECLS(
  4251. [_SC_NPROCESSORS_ONLN,_SC_NPROC_ONLN,_SC_CRAY_NCPU,_SC_NPROCESSORS_CONF,CTL_HW,HW_NCPUONLINE,HW_NCPU,HW_AVAILCPU],
  4252. [],[],
  4253. [[
  4254. #ifdef HAVE_SYS_TYPES_H
  4255. #include <sys/types.h>
  4256. #endif /* HAVE_SYS_TYPES_H */
  4257. #ifdef HAVE_SYS_PARAM_H
  4258. #include <sys/param.h>
  4259. #endif /* HAVE_SYS_PARAM_H */
  4260. #ifdef HAVE_SYS_SYSCTL_H
  4261. #include <sys/sysctl.h>
  4262. #endif /* HAVE_SYS_SYSCTL_H */
  4263. #ifdef HAVE_UNISTD_H
  4264. #include <unistd.h>
  4265. #endif /* HAVE_UNISTD_H */
  4266. ]]
  4267. )
  4268. MHD_CHECK_FUNC([pstat_getdynamic],[[
  4269. #include <sys/param.h>
  4270. #include <sys/pstat.h>
  4271. ]],
  4272. [[
  4273. struct pst_dynamic psd_data;
  4274. i][f (1 != pstat_getdynamic(&psd_data, sizeof(psd_data), (size_t)1, 0))
  4275. return 2;
  4276. i][f (0 >= psd_data.psd_proc_cnt)
  4277. return 3;
  4278. ]]
  4279. )
  4280. MHD_CHECK_FUNC([vxCpuEnabledGet],[[#include <vxCpuLib.h>]],
  4281. [[
  4282. cpuset_t enb_set;
  4283. enb_set = vxCpuEnabledGet();
  4284. (void) enb_set;
  4285. ]]
  4286. )
  4287. AC_CHECK_HEADERS([sched.h sys/_cpuset.h sys/cpuset.h],[],[],[AC_INCLUDES_DEFAULT])
  4288. # glibc / Linux kernel
  4289. MHD_CHECK_FUNC([getpid],[[
  4290. #ifdef HAVE_SYS_TYPES_H
  4291. #include <sys/types.h>
  4292. #endif /* HAVE_SYS_TYPES_H */
  4293. #include <unistd.h>
  4294. ]],
  4295. [[
  4296. pid_t cur_pid;
  4297. cur_pid = getpid();
  4298. (void) &cur_pid; /* Mute possible warning */
  4299. ]],
  4300. [
  4301. MHD_CHECK_FUNC([sched_getaffinity],[[
  4302. #ifdef HAVE_SYS_TYPES_H
  4303. #include <sys/types.h>
  4304. #endif /* HAVE_SYS_TYPES_H */
  4305. #include <unistd.h>
  4306. #include <sched.h>
  4307. ]],
  4308. [[
  4309. cpu_set_t cur_set;
  4310. i][f (0 != sched_getaffinity(getpid(), sizeof(cur_set), &cur_set))
  4311. return 2;
  4312. i][f (0 == CPU_SET (0, &cur_set))
  4313. return 3; /* Actually this could be a valid result */
  4314. ]],
  4315. [
  4316. MHD_CHECK_FUNC([CPU_COUNT],[[
  4317. #include <stddef.h>
  4318. #include <sched.h>
  4319. ]],
  4320. [[
  4321. cpu_set_t cur_set;
  4322. CPU_ZERO(&cur_set);
  4323. i][f (0 != CPU_COUNT(&cur_set))
  4324. return 2;
  4325. ]],
  4326. [
  4327. MHD_CHECK_FUNC([CPU_COUNT_S],[[
  4328. #include <stddef.h>
  4329. #include <sched.h>
  4330. ]],
  4331. [[
  4332. static const unsigned int set_size_cpus = 2048u;
  4333. const size_t set_size_bytes = (size_t) CPU_ALLOC_SIZE(set_size_cpus);
  4334. cpu_set_t *p_set;
  4335. p_set = CPU_ALLOC(set_size_cpus);
  4336. i][f (!p_set)
  4337. return 2;
  4338. CPU_ZERO_S(set_size_bytes, p_set);
  4339. i][f (0 != CPU_COUNT_S(set_size_bytes, p_set))
  4340. {
  4341. CPU_FREE(p_set);
  4342. return 3;
  4343. }
  4344. CPU_FREE(p_set);
  4345. ]],
  4346. [AC_CHECK_DECLS([CPU_SETSIZE],[],[],[#include <sched.h>])]
  4347. )
  4348. ]
  4349. )
  4350. ]
  4351. )
  4352. # NetBSD
  4353. # Should work only with -lrt, but actually works without it.
  4354. MHD_CHECK_FUNC([sched_getaffinity_np],[[
  4355. #ifdef HAVE_SYS_TYPES_H
  4356. #include <sys/types.h>
  4357. #endif /* HAVE_SYS_TYPES_H */
  4358. #include <unistd.h>
  4359. #include <sched.h>
  4360. ]],
  4361. [[
  4362. cpuset_t *cpuset_ptr;
  4363. cpuid_t cpu_num = 0;
  4364. cpuset_ptr = cpuset_create();
  4365. i][f (!cpuset_ptr)
  4366. return 2;
  4367. i][f (0 != sched_getaffinity_np(getpid(), cpuset_size(cpuset_ptr), cpuset_ptr))
  4368. {
  4369. cpuset_destroy(cpuset_ptr);
  4370. return 3;
  4371. }
  4372. i][f (0 >= cpuset_isset(cpu_num, cpuset_ptr))
  4373. {
  4374. cpuset_destroy(cpuset_ptr);
  4375. return 4; /* Actually this could be a valid result */
  4376. }
  4377. cpuset_destroy(cpuset_ptr);
  4378. ]]
  4379. )
  4380. ]
  4381. )
  4382. # FreeBSD
  4383. MHD_CHECK_FUNC([cpuset_getaffinity],[[
  4384. #ifdef HAVE_SYS_PARAM_H
  4385. #include <sys/param.h>
  4386. #endif /* HAVE_SYS_PARAM_H */
  4387. #include <sys/cpuset.h>
  4388. ]],
  4389. [[
  4390. cpuset_t cur_mask;
  4391. i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1, sizeof(cur_mask), &cur_mask))
  4392. return 2;
  4393. ]],
  4394. [
  4395. MHD_CHECK_FUNC([CPU_COUNT],[[
  4396. #ifdef HAVE_SYS_PARAM_H
  4397. #include <sys/param.h>
  4398. #endif /* HAVE_SYS_PARAM_H */
  4399. #ifdef HAVE_SYS__CPUSET_H
  4400. #include <sys/_cpuset.h>
  4401. #endif /* HAVE_SYS_PARAM_H */
  4402. #include <sys/cpuset.h>
  4403. ]],
  4404. [[
  4405. cpuset_t test_mask;
  4406. CPU_ZERO(&test_mask);
  4407. i][f (0 != CPU_COUNT(&test_mask))
  4408. return 2;
  4409. ]],
  4410. [
  4411. MHD_CHECK_FUNC([CPU_COUNT_S],[[
  4412. #ifdef HAVE_SYS_PARAM_H
  4413. #include <sys/param.h>
  4414. #endif /* HAVE_SYS_PARAM_H */
  4415. #ifdef HAVE_SYS__CPUSET_H
  4416. #include <sys/_cpuset.h>
  4417. #endif /* HAVE_SYS_PARAM_H */
  4418. #include <sys/cpuset.h>
  4419. ]],
  4420. [[
  4421. static const unsigned int max_cpu_num = 2048u;
  4422. cpuset_t *mask_ptr;
  4423. mask_ptr = CPU_ALLOC(max_cpu_num);
  4424. i][f (! mask_ptr)
  4425. return 2;
  4426. i][f (0 != cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, (id_t) -1,
  4427. CPU_ALLOC_SIZE(max_cpu_num), mask_ptr))
  4428. {
  4429. CPU_FREE(mask_ptr);
  4430. return 3;
  4431. }
  4432. i][f (0 == CPU_COUNT_S(CPU_ALLOC_SIZE(max_cpu_num), &test_mask))
  4433. {
  4434. CPU_FREE(mask_ptr);
  4435. return 4;
  4436. }
  4437. CPU_FREE(mask_ptr);
  4438. ]]
  4439. )
  4440. ]
  4441. )
  4442. ]
  4443. )
  4444. AS_VAR_IF([mhd_cv_have_func_CPU_COUNT_S],["yes"],
  4445. [
  4446. AC_CACHE_CHECK([whether CPU_COUNT_S() expects max CPU number as 'size' parameter],[mhd_cv_func_cpu_count_s_cpus],
  4447. [
  4448. AS_VAR_IF([cross-compiling],["yes"],[mhd_cv_func_cpu_count_s_cpus="assuming no"],
  4449. [
  4450. AC_LINK_IFELSE(
  4451. [
  4452. AC_LANG_PROGRAM([[
  4453. #ifdef HAVE_SYS_TYPES_H
  4454. #include <sys/types.h>
  4455. #endif /* HAVE_SYS_TYPES_H */
  4456. #ifdef HAVE_SYS_PARAM_H
  4457. #include <sys/param.h>
  4458. #endif /* HAVE_SYS_PARAM_H */
  4459. #ifdef HAVE_SYS__CPUSET_H
  4460. #include <sys/_cpuset.h>
  4461. #endif /* HAVE_SYS_PARAM_H */
  4462. #ifdef HAVE_SYS_CPUSET_H
  4463. #include <sys/cpuset.h>
  4464. #endif /* HAVE_SYS_CPUSET_H */
  4465. #ifdef HAVE_STDDEF_H
  4466. #include <stddef.h>
  4467. #endif /* HAVE_STDDEF_H */
  4468. #ifdef HAVE_UNISTD_H
  4469. #include <unistd.h>
  4470. #endif /* HAVE_UNISTD_H */
  4471. #ifdef HAVE_SCHED_H
  4472. #include <sched.h>
  4473. #endif /* HAVE_SCHED_H */
  4474. #include <stdio.h>
  4475. #ifdef HAVE_SCHED_GETAFFINITY
  4476. #define TEST_CPUSET_TYPE cpu_set_t
  4477. #else /* ! HAVE_SCHED_GETAFFINITY */
  4478. #define TEST_CPUSET_TYPE cpuset_t
  4479. #endif /* ! HAVE_SCHED_GETAFFINITY */
  4480. ]],
  4481. [[
  4482. TEST_CPUSET_TYPE *p_testset;
  4483. /* The size of the cpuset that is larger then the test cpuset (in CPUs) */
  4484. static const unsigned int testset_size_oversized_cpus = (8 * sizeof(long)) * 1024;
  4485. const size_t testset_size_oversized_bytes = CPU_ALLOC_SIZE(testset_size_oversized_cpus);
  4486. /* The size of the test cpuset in number of CPUs */
  4487. const unsigned int testset_size_cpus = (unsigned int) testset_size_oversized_bytes;
  4488. /* The size of the test cpuset in bytes */
  4489. const size_t testset_size_bytes = CPU_ALLOC_SIZE(testset_size_cpus);
  4490. /* The last one CPU in the test set */
  4491. const unsigned int test_cpu_num1 = testset_size_cpus - 1;
  4492. /* The penultimate CPU in the test set */
  4493. const unsigned int test_cpu_num2 = testset_size_cpus - 2;
  4494. /* The CPU numbers that should be cleared */
  4495. const unsigned int test_cpu_clear1 = testset_size_cpus - 3;
  4496. const unsigned int test_cpu_clear2 = testset_size_cpus - 4;
  4497. unsigned int count_res;
  4498. int ret = 0;
  4499. /* Allocate oversize area to ensure that memory outside the buffer is not used */
  4500. p_testset = CPU_ALLOC(testset_size_oversized_cpus);
  4501. if (! p_testset)
  4502. {
  4503. fprintf (stderr, "Error allocating memory.\n");
  4504. return 99;
  4505. }
  4506. /* Set the some CPU numbers and then clear them */
  4507. CPU_SET_S(test_cpu_clear1, testset_size_bytes, p_testset);
  4508. CPU_SET_S(test_cpu_clear2, testset_size_bytes, p_testset);
  4509. CPU_ZERO_S(testset_size_bytes, p_testset);
  4510. /* Set two CPUs on */
  4511. CPU_SET_S(test_cpu_num1, testset_size_bytes, p_testset);
  4512. CPU_SET_S(test_cpu_num2, testset_size_bytes, p_testset);
  4513. count_res = (unsigned int) CPU_COUNT_S(testset_size_bytes, p_testset);
  4514. if (0 == count_res)
  4515. {
  4516. fprintf (stderr, "Full cpuset cannot be read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
  4517. /* Set the some CPU numbers and then clear them */
  4518. CPU_SET_S(test_cpu_clear1, testset_size_cpus, p_testset);
  4519. CPU_SET_S(test_cpu_clear2, testset_size_cpus, p_testset);
  4520. CPU_ZERO_S(testset_size_cpus, p_testset);
  4521. /* Set two CPUs on */
  4522. CPU_SET_S(test_cpu_num1, testset_size_cpus, p_testset);
  4523. CPU_SET_S(test_cpu_num2, testset_size_cpus, p_testset);
  4524. count_res = (unsigned int) CPU_COUNT_S(testset_size_cpus, p_testset);
  4525. if (2 == count_res)
  4526. {
  4527. fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() only when using the maximum CPU number as the size parameter.\n");
  4528. ret = 3;
  4529. }
  4530. else
  4531. {
  4532. fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the maximum CPU number as the size parameter.\n");
  4533. fprintf (stderr, "Number of 'enabled' CPUs: 2\n");
  4534. fprintf (stderr, "Number of counted CPUs: %u\n", count_res);
  4535. fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n");
  4536. ret = 70;
  4537. }
  4538. }
  4539. else if (2 == count_res)
  4540. {
  4541. fprintf (stderr, "Full cpuset is read by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
  4542. }
  4543. else
  4544. {
  4545. fprintf (stderr, "Wrong result returned by CPU_COUNT_S() when using the number of bytes as the size parameter.\n");
  4546. fprintf (stderr, "Number of 'enabled' CPUs: 2\n");
  4547. fprintf (stderr, "Number of counted CPUs: %u\n", count_res);
  4548. fprintf (stderr, "CPU_COUNT_S() could be unreliable.\n");
  4549. ret = 71;
  4550. }
  4551. CPU_FREE(p_testset);
  4552. if (0 != ret)
  4553. return ret;
  4554. ]]
  4555. )
  4556. ],
  4557. [
  4558. AM_RUN_LOG([./conftest$EXEEXT])
  4559. count_test_res=$?
  4560. AS_IF([test $count_test_res -eq 0],[mhd_cv_func_cpu_count_s_cpus="no"],
  4561. [test $count_test_res -eq 3],[mhd_cv_func_cpu_count_s_cpus="yes"],
  4562. [
  4563. AC_MSG_WARN([Unexpected value returned by CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}])
  4564. mhd_cv_func_cpu_count_s_cpus="assuming no"
  4565. ]
  4566. )
  4567. ],
  4568. [
  4569. AC_MSG_WARN([Cannot build CPU_COUNT_S() test program. Please report to ${PACKAGE_BUGREPORT}])
  4570. mhd_cv_func_cpu_count_s_cpus="assuming no"
  4571. ]
  4572. )
  4573. ]
  4574. )
  4575. ]
  4576. )
  4577. AS_VAR_IF([mhd_cv_func_cpu_count_s_cpus],["yes"],
  4578. [AC_DEFINE([MHD_FUNC_CPU_COUNT_S_GETS_CPUS],[1],
  4579. [Define to '1' if CPU_COUNT_S() function expects max CPU number as 'size' parameter])
  4580. ]
  4581. )
  4582. ]
  4583. )
  4584. ]
  4585. )
  4586. # Check for fork() and waitpid(). They are used for tests.
  4587. AC_MSG_CHECKING([[for fork()]])
  4588. mhd_have_fork_waitpid='no'
  4589. AC_LINK_IFELSE(
  4590. [
  4591. AC_LANG_PROGRAM(
  4592. [[
  4593. #ifdef HAVE_SYS_TYPES_H
  4594. #include <sys/types.h>
  4595. #endif
  4596. #ifdef HAVE_UNISTD_H
  4597. #include <unistd.h>
  4598. #endif
  4599. ]], [[
  4600. pid_t p = fork ();
  4601. if (0 == p)
  4602. return 1;
  4603. ]])
  4604. ], [
  4605. AC_DEFINE([[HAVE_FORK]], [[1]], [Define to 1 if you have the usable `fork' function.])
  4606. AC_MSG_RESULT([[yes]])
  4607. AC_MSG_CHECKING([[for waitpid()]])
  4608. AC_LINK_IFELSE(
  4609. [
  4610. AC_LANG_PROGRAM(
  4611. [[
  4612. #ifdef HAVE_SYS_TYPES_H
  4613. #include <sys/types.h>
  4614. #endif
  4615. #ifdef HAVE_UNISTD_H
  4616. #include <unistd.h>
  4617. #endif
  4618. #include <sys/wait.h>
  4619. ]], [[
  4620. pid_t p = fork ();
  4621. if (0 == p)
  4622. return 1;
  4623. waitpid (p, (void*)0, 0)
  4624. ]])
  4625. ], [
  4626. AC_DEFINE([[HAVE_WAITPID]], [[1]], [Define to 1 if you have the usable `waitpid' function.])
  4627. AC_MSG_RESULT([[yes]])
  4628. mhd_have_fork_waitpid='yes'
  4629. ],[
  4630. AC_MSG_RESULT([[no]])
  4631. ])
  4632. ],[
  4633. AC_MSG_RESULT([[no]])
  4634. ])
  4635. AM_CONDITIONAL([HAVE_FORK_WAITPID], [test "x$mhd_have_fork_waitpid" = "xyes"])
  4636. # gcov compilation
  4637. AC_MSG_CHECKING(whether to compile with support for code coverage analysis)
  4638. AC_ARG_ENABLE([coverage],
  4639. AS_HELP_STRING([--enable-coverage],
  4640. [compile the library with code coverage support]),
  4641. [use_gcov=${enableval}],
  4642. [use_gcov=no])
  4643. AC_MSG_RESULT($use_gcov)
  4644. AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"])
  4645. AX_COUNT_CPUS
  4646. AC_SUBST([MHD_REAL_CPU_COUNT],[${CPU_COUNT}])
  4647. AM_SUBST_NOTMAKE([MHD_REAL_CPU_COUNT])
  4648. AC_MSG_CHECKING([for number of CPU cores to use in tests])
  4649. AS_VAR_IF([use_heavy_tests], ["yes"],
  4650. [
  4651. # Enable usage of many core if heavy tests are enabled
  4652. AS_IF([[test "$CPU_COUNT" -gt "32"]], [[CPU_COUNT="32"]])dnl Limit resource usage
  4653. ],
  4654. [
  4655. # Limit usage to just a few cores if heavy tests are not enabled
  4656. AS_IF([[test "$CPU_COUNT" -gt "6"]], [[CPU_COUNT="6"]])
  4657. AS_IF([[test "$CPU_COUNT" -lt "2"]], [[CPU_COUNT="2"]])
  4658. ]
  4659. )
  4660. AC_MSG_RESULT([$CPU_COUNT])
  4661. AC_ARG_ENABLE([[asserts]],
  4662. [AS_HELP_STRING([[--enable-asserts]],
  4663. [enable test build with debug asserts])],
  4664. [],
  4665. [enable_asserts='auto']
  4666. )
  4667. AS_UNSET([use_asserts_MSG])
  4668. AC_CACHE_CHECK([[whether NDEBUG macro is defined]], [mhd_cv_macro_ndebug_def],
  4669. [
  4670. AC_LINK_IFELSE(
  4671. [
  4672. AC_LANG_SOURCE([[
  4673. #ifndef NDEBUG
  4674. #error NDEBUG is NOT defined
  4675. chome me now
  4676. #endif
  4677. int main(void)
  4678. {
  4679. return 0;
  4680. }
  4681. ]]
  4682. )
  4683. ],
  4684. [[mhd_cv_macro_ndebug_def='yes']],
  4685. [[mhd_cv_macro_ndebug_def='no']]
  4686. )
  4687. ]
  4688. )
  4689. AS_VAR_IF([enable_asserts],["yes"],
  4690. [
  4691. AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"],
  4692. [
  4693. AC_MSG_FAILURE([Parameter --enable-asserts is specified, but NDEBUG macro is defined as well])
  4694. ]
  4695. )
  4696. use_asserts_MSG="yes, enabled by configure parameter"
  4697. ]
  4698. )
  4699. AC_CACHE_CHECK([[whether _DEBUG macro is defined]], [mhd_cv_macro__debug_def],
  4700. [
  4701. AC_LINK_IFELSE(
  4702. [
  4703. AC_LANG_SOURCE([[
  4704. #ifndef _DEBUG
  4705. #error _DEBUG is NOT defined
  4706. chome me now
  4707. #endif
  4708. int main(void)
  4709. {
  4710. return 0;
  4711. }
  4712. ]]
  4713. )
  4714. ],
  4715. [[mhd_cv_macro__debug_def='yes']],
  4716. [[mhd_cv_macro__debug_def='no']]
  4717. )
  4718. ]
  4719. )
  4720. AS_VAR_IF([enable_asserts],["no"],
  4721. [
  4722. AS_VAR_IF([mhd_cv_macro__debug_def],["yes"],
  4723. [
  4724. AC_MSG_FAILURE([Parameter --disable-asserts is specified, but _DEBUG macro is defined as well])
  4725. ]
  4726. )
  4727. use_asserts_MSG="no, set by configure parameter"
  4728. ]
  4729. )
  4730. AS_IF([test "x${mhd_cv_macro_ndebug_def}" = "xyes" && test "x${mhd_cv_macro__debug_def}" = "xyes"],
  4731. [AC_MSG_FAILURE([Both NDEBUG and _DEBUG macros are defined])]
  4732. )
  4733. AS_VAR_IF([enable_asserts],["auto"],
  4734. [
  4735. AS_VAR_IF([mhd_cv_macro_ndebug_def],["yes"],
  4736. [
  4737. enable_asserts="no"
  4738. use_asserts_MSG="no, set by NDEBUG preprocessor macro"
  4739. ]
  4740. )
  4741. ]
  4742. )
  4743. AS_VAR_IF([enable_asserts],["auto"],
  4744. [
  4745. AS_VAR_IF([mhd_cv_macro__debug_def],["yes"],
  4746. [
  4747. enable_asserts="yes"
  4748. use_asserts_MSG="yes, enabled by _DEBUG preprocessor macro"
  4749. ]
  4750. )
  4751. ]
  4752. )
  4753. AS_VAR_IF([enable_asserts],["auto"],
  4754. [
  4755. AC_CACHE_CHECK([[whether DEBUG macro is defined]], [mhd_cv_macro_debug_def],
  4756. [
  4757. AC_LINK_IFELSE(
  4758. [
  4759. AC_LANG_SOURCE([[
  4760. #ifndef DEBUG
  4761. #error DEBUG is NOT defined
  4762. chome me now
  4763. #endif
  4764. int main(void)
  4765. {
  4766. return 0;
  4767. }
  4768. ]]
  4769. )
  4770. ],
  4771. [[mhd_cv_macro_debug_def='yes']],
  4772. [[mhd_cv_macro_debug_def='no']]
  4773. )
  4774. ]
  4775. )
  4776. AS_VAR_IF([mhd_cv_macro_debug_def],["yes"],
  4777. [
  4778. enable_asserts="yes"
  4779. use_asserts_MSG="yes, enabled by DEBUG preprocessor macro"
  4780. ]
  4781. )
  4782. ]
  4783. )
  4784. AC_MSG_CHECKING([[whether to enable debug asserts]])
  4785. AS_VAR_IF([enable_asserts],["auto"],
  4786. [
  4787. AS_CASE([${enable_build_type}],
  4788. [debug|debugger],
  4789. [
  4790. enable_asserts="yes"
  4791. use_asserts_MSG="yes, enabled by --enable-bulid-type=${enable_build_type}"
  4792. ],
  4793. [
  4794. enable_asserts="no"
  4795. use_asserts_MSG="no"
  4796. ]
  4797. )
  4798. ]
  4799. )
  4800. AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']])
  4801. AC_MSG_RESULT([[${use_asserts_MSG=no}]])
  4802. AS_VAR_IF([[enable_asserts]], [["yes"]],
  4803. [
  4804. AS_VAR_IF([[mhd_cv_macro__debug_def]], [["yes"]], [:],
  4805. [
  4806. MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-D_DEBUG=1])
  4807. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  4808. ]
  4809. )
  4810. AC_CACHE_CHECK([[whether system assert() is available]], [mhd_cv_sys_assert_avail],
  4811. [
  4812. AC_LINK_IFELSE(
  4813. [
  4814. AC_LANG_SOURCE([[
  4815. #include <assert.h>
  4816. static int pos_val(void) {return 5;}
  4817. static int neg_val(void) {return -5;}
  4818. int main(void)
  4819. {
  4820. int pos_var = pos_val(), neg_var = neg_val();
  4821. assert(neg_var > pos_var); /* Must trigger assert. */
  4822. return pos_var + neg_var;
  4823. }
  4824. ]])
  4825. ],
  4826. [[mhd_cv_sys_assert_avail='yes']],
  4827. [[mhd_cv_sys_assert_avail='no']]
  4828. )
  4829. ]
  4830. )
  4831. AS_VAR_IF([[mhd_cv_sys_assert_avail]], [["no"]], [],
  4832. [AC_DEFINE([[HAVE_ASSERT]], [[1]], [Define if you have usable assert() and assert.h])])
  4833. ],
  4834. [
  4835. AS_VAR_IF([[mhd_cv_macro_ndebug_def]], [["yes"]], [:],
  4836. [
  4837. MHD_PREPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-DNDEBUG=1])
  4838. CPPFLAGS="${CPPFLAGS_ac} ${user_CPPFLAGS}"
  4839. ]
  4840. )
  4841. ]
  4842. )
  4843. AS_UNSET([enabled_sanitizers])
  4844. TESTS_ENVIRONMENT_ac=""
  4845. AM_ASAN_OPTIONS=""
  4846. AM_UBSAN_OPTIONS=""
  4847. AM_LSAN_OPTIONS=""
  4848. AS_UNSET([ASAN_OPTIONS])
  4849. AS_UNSET([UBSAN_OPTIONS])
  4850. AS_UNSET([LSAN_OPTIONS])
  4851. AC_MSG_CHECKING([whether to enable run-time sanitizers])
  4852. AC_ARG_ENABLE([sanitizers],
  4853. [AS_HELP_STRING([[--enable-sanitizers[=address,undefined,leak,user-poison]]],
  4854. [enable run-time sanitizers, specify the list of types of sanitizers to enable, ]
  4855. [leave the list empty (or set to "auto") to enable all supported and available ]
  4856. [sanitizers, or specify "auto-fallback" to use sanitizers even without ]
  4857. [installed sanitizer run-time library])],
  4858. [], [AS_CASE([${enable_build_type}],[debug],
  4859. [enable_sanitizers='auto-optional'],[enable_sanitizers='no'])]
  4860. )
  4861. AS_IF([test "x${enable_sanitizers}" = "x"], [enable_sanitizers="auto"])
  4862. AS_VAR_IF([enable_sanitizers], ["yes"], [enable_sanitizers="auto"])
  4863. AS_VAR_IF([enable_sanitizers], ["autofallback"], [enable_sanitizers="auto-fallback"])
  4864. AS_VAR_IF([enable_sanitizers], ["autooptional"], [enable_sanitizers="auto-optional"])
  4865. AS_IF([test "x${enable_sanitizers}" = "xno"],
  4866. [
  4867. enable_sanitizers="no"
  4868. enable_san_address="no"
  4869. enable_san_undef="no"
  4870. enable_san_leak="no"
  4871. enable_san_upoison="no"
  4872. ],
  4873. [test "x${enable_sanitizers}" = "xauto" || test "x${enable_sanitizers}" = "xauto-optional"],
  4874. [
  4875. AS_VAR_IF([enable_compiler_hardening],["yes"],
  4876. [
  4877. AS_VAR_IF([enable_sanitizers],["auto"],
  4878. [AC_MSG_ERROR([sanitizers cannot be enabled with compiler hardnening])],
  4879. [AC_MSG_WARN([sanitizers cannot be enabled with compiler hardnening])]
  4880. )
  4881. enable_sanitizers="no"
  4882. enable_san_address="no"
  4883. enable_san_undef="no"
  4884. enable_san_leak="no"
  4885. enable_san_upoison="no"
  4886. ],
  4887. [
  4888. enable_san_address="auto"
  4889. enable_san_undef="auto"
  4890. enable_san_leak="auto"
  4891. enable_san_upoison="auto"
  4892. ]
  4893. )
  4894. ],
  4895. [test "x${enable_sanitizers}" = "xauto-fallback"],
  4896. [
  4897. enable_san_address="auto"
  4898. enable_san_undef="auto-fallback"
  4899. enable_san_leak="auto"
  4900. enable_san_upoison="auto"
  4901. ],
  4902. [
  4903. AS_UNSET([san])
  4904. enable_san_address="no"
  4905. enable_san_undef="no"
  4906. enable_san_leak="no"
  4907. enable_san_upoison="no"
  4908. f][or san in `AS_ECHO([${enable_sanitizers}]) | tr ',' ' '`
  4909. do
  4910. AS_CASE([$san],
  4911. [address], [enable_san_address="yes"],
  4912. [undefined], [enable_san_undef="yes"],
  4913. [leak], [enable_san_leak="yes"],
  4914. [user-poison|user_poison], [enable_san_upoison="yes"],
  4915. [no|yes|auto|auto-fallback|autofallback], [AC_MSG_ERROR(["$san" cannot be used with other options for --enable-sanitizers=])],
  4916. [AC_MSG_ERROR([Unknown parameter "$san" for --enable-sanitizers=])]
  4917. )
  4918. done
  4919. AS_IF([test "x${enable_san_upoison}" = "xyes" && test "x${enable_san_address}" = "xno"],
  4920. [AC_MSG_ERROR([User memory poisoning cannot be used without address sanitizer])]
  4921. )
  4922. enable_sanitizers="selected"
  4923. ]
  4924. )
  4925. AS_CASE([${enable_sanitizers}],
  4926. [selected], [AC_MSG_RESULT([selected])],
  4927. [auto], [AC_MSG_RESULT([yes, detect and use supported sanitizers])],
  4928. [auto-fallback], [AC_MSG_RESULT([yes, detect and use supported sanitizers even without run-time lib])],
  4929. [auto-optional], [AC_MSG_RESULT([yes, detect and use supported sanitizers if any])],
  4930. [AC_MSG_RESULT([no])]
  4931. )
  4932. AS_VAR_IF([enable_sanitizers], ["no"], [:],
  4933. [
  4934. AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS
  4935. AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS
  4936. AC_CACHE_CHECK([whether '-fsanitize=' works for $CC],
  4937. [mhd_cv_cc_sanitizer_works],
  4938. [
  4939. CFLAGS="${CFLAGS_ac} -fsanitize=wrongFeatureName ${user_CFLAGS}"
  4940. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  4941. [mhd_cv_cc_sanitizer_works=no], [mhd_cv_cc_sanitizer_works=yes])
  4942. ]
  4943. )
  4944. AS_VAR_IF([mhd_cv_cc_sanitizer_works], ["yes"],
  4945. [
  4946. AS_VAR_IF([enable_san_address], ["no"], [:],
  4947. [
  4948. AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address],
  4949. [
  4950. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address ${user_CFLAGS}"
  4951. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  4952. [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no])
  4953. ]
  4954. )
  4955. AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"],
  4956. [
  4957. AC_DEFINE([MHD_ASAN_ACTIVE], [1], [Define to '1' if you have address sanitizer enabled])
  4958. AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS])
  4959. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address"
  4960. AS_VAR_IF([enable_san_leak], ["no"], [:],
  4961. [
  4962. AC_CACHE_CHECK([whether leak detect is not rejected by address sanitizer], [mhd_cv_cc_sanitizer_address_leak],
  4963. [
  4964. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${user_CFLAGS}"
  4965. ASAN_OPTIONS="exitcode=88:detect_leaks=1:halt_on_error=1"
  4966. export ASAN_OPTIONS
  4967. AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])],
  4968. [mhd_cv_cc_sanitizer_address_leak=yes], [mhd_cv_cc_sanitizer_address_leak=no],
  4969. [
  4970. # Cross-compiling with sanitizers?
  4971. mhd_cv_cc_sanitizer_address_leak='assuming no'
  4972. ]
  4973. )
  4974. AS_UNSET([ASAN_OPTIONS])
  4975. ]
  4976. )
  4977. ]
  4978. )
  4979. AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare],
  4980. [
  4981. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare ${user_CFLAGS}"
  4982. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  4983. [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no])
  4984. ]
  4985. )
  4986. AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"],
  4987. [
  4988. AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS])
  4989. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare"
  4990. ]
  4991. )
  4992. AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract],
  4993. [
  4994. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract ${user_CFLAGS}"
  4995. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  4996. [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no])
  4997. ]
  4998. )
  4999. AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"],
  5000. [
  5001. AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS])
  5002. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract"
  5003. ]
  5004. )
  5005. AS_VAR_IF([enable_san_upoison], ["no"], [:],
  5006. [
  5007. AC_CHECK_HEADERS([sanitizer/asan_interface.h], [], [], [AC_INCLUDES_DEFAULT])
  5008. AS_VAR_IF([ac_cv_header_sanitizer_asan_interface_h],["yes"],
  5009. [
  5010. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
  5011. MHD_CHECK_FUNC([__asan_address_is_poisoned],[[#include <sanitizer/asan_interface.h>]],
  5012. [[int a_var=1; i][f(__asan_address_is_poisoned((void*) &a_var)) return 3;]]
  5013. )
  5014. MHD_CHECK_FUNC([__asan_region_is_poisoned],[[#include <sanitizer/asan_interface.h>]],
  5015. [[int a_var=1; i][f(((void*) 0) != __asan_region_is_poisoned((void*) &a_var, sizeof(a_var))) return 3;]]
  5016. )
  5017. AC_CACHE_CHECK([whether special function attribute is needed for user-poison], [mhd_cv_func_u_p_attribute_needed],
  5018. [
  5019. ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
  5020. export ASAN_OPTIONS
  5021. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
  5022. AC_RUN_IFELSE(
  5023. [
  5024. AC_LANG_SOURCE(
  5025. [[
  5026. #include <stdint.h>
  5027. #include <stdlib.h>
  5028. #include <sanitizer/asan_interface.h>
  5029. static const size_t first_pos = 0;
  5030. static const size_t mid_pos = 64;
  5031. static const size_t last_pos = 128;
  5032. static const size_t zone_size = 16;
  5033. static const size_t buf_size = 128 + 16;
  5034. static int ptr_compare(void *ptr1, uint8_t *ptr2)
  5035. {
  5036. if ((((uintptr_t) (uint8_t *)ptr1) >= ((uintptr_t)ptr2)))
  5037. return ((char *) ptr1)[0] < ((char *) ptr2)[0];
  5038. return ((char *) ptr1)[0] > ((char *) ptr2)[0];
  5039. }
  5040. static int ptr_subtract(void *ptr1, uint8_t *ptr2)
  5041. {
  5042. return ((size_t)(((uintptr_t)(uint8_t*)ptr1) - ((uintptr_t)ptr2))) <= last_pos;
  5043. }
  5044. int main(int argc, char *argv[])
  5045. {
  5046. char *buf = (char*) malloc (buf_size);
  5047. char *a;
  5048. char *b;
  5049. int ret;
  5050. (void) argv;
  5051. if (NULL == buf)
  5052. return 10;
  5053. ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
  5054. ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
  5055. if (0 < argc)
  5056. a = buf + last_pos;
  5057. else
  5058. a = buf + first_pos;
  5059. b = buf + mid_pos;
  5060. *a = '0';
  5061. *b = '9';
  5062. if (ptr_compare((void *)a, (uint8_t*) b))
  5063. {
  5064. if (ptr_subtract((void *)a, (uint8_t*) b))
  5065. ret = 0;
  5066. else
  5067. ret = 10;
  5068. }
  5069. else
  5070. ret = 5;
  5071. ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
  5072. free (buf);
  5073. return ret;
  5074. }
  5075. ]]
  5076. )
  5077. ],
  5078. [mhd_cv_func_u_p_attribute_needed="no"], [mhd_cv_func_u_p_attribute_needed="yes"],
  5079. [
  5080. # Cross-compiling with sanitizers??
  5081. mhd_cv_func_up_attribute_needed='assuming no'
  5082. ]
  5083. )
  5084. AS_UNSET([ASAN_OPTIONS])
  5085. ]
  5086. )
  5087. ]
  5088. )
  5089. AS_VAR_IF([mhd_cv_func_u_p_attribute_needed],["yes"],[:],
  5090. [
  5091. AC_DEFINE([FUNC_PTRCOMPARE_CAST_WORKAROUND_WORKS],[1],[Define to '1' if cast to 'uintptr_t' works for safely processing user-poisoned pointer])
  5092. ]
  5093. )
  5094. AS_IF([test "x${mhd_cv_func_u_p_attribute_needed}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes"],
  5095. [
  5096. AC_CACHE_CHECK([whether '__attribute__((no_sanitize("pointer-compare")))' and '__attribute__((no_sanitize("pointer-subtract")))' work],
  5097. [mhd_cv_func_attribute_nosanitize_ptr],
  5098. [
  5099. ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
  5100. export ASAN_OPTIONS
  5101. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
  5102. AC_RUN_IFELSE(
  5103. [
  5104. AC_LANG_SOURCE(
  5105. [[
  5106. #include <stdint.h>
  5107. #include <stdlib.h>
  5108. #include <sanitizer/asan_interface.h>
  5109. static const size_t first_pos = 0;
  5110. static const size_t mid_pos = 64;
  5111. static const size_t last_pos = 128;
  5112. static const size_t zone_size = 16;
  5113. static const size_t buf_size = 128 + 16;
  5114. __attribute__((no_sanitize("pointer-compare")))
  5115. static int ptr_compare(void *ptr1, uint8_t *ptr2)
  5116. {
  5117. if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2)))
  5118. return ((char *) ptr1)[0] < ((char *) ptr2)[0];
  5119. return ((char *) ptr1)[0] > ((char *) ptr2)[0];
  5120. }
  5121. __attribute__((no_sanitize("pointer-subtract")))
  5122. static int ptr_subtract(void *ptr1, uint8_t *ptr2)
  5123. {
  5124. return ((size_t)(((const uint8_t*)ptr1) - \
  5125. ((const uint8_t*)ptr2))) <= last_pos;
  5126. }
  5127. int main(int argc, char *argv[])
  5128. {
  5129. char *buf = (char*) malloc (buf_size);
  5130. char *a;
  5131. char *b;
  5132. int ret;
  5133. (void) argv;
  5134. if (NULL == buf)
  5135. return 10;
  5136. ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
  5137. ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
  5138. if (0 < argc)
  5139. a = buf + last_pos;
  5140. else
  5141. a = buf + first_pos;
  5142. b = buf + mid_pos;
  5143. *a = '0';
  5144. *b = '9';
  5145. if (ptr_compare((void *)a, (uint8_t*) b))
  5146. {
  5147. if (ptr_subtract((void *)a, (uint8_t*) b))
  5148. ret = 0;
  5149. else
  5150. ret = 10;
  5151. }
  5152. else
  5153. ret = 5;
  5154. ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
  5155. free (buf);
  5156. return ret;
  5157. }
  5158. ]]
  5159. )
  5160. ],
  5161. [mhd_cv_func_attribute_nosanitize_ptr=yes], [mhd_cv_func_attribute_nosanitize_ptr=no],
  5162. [
  5163. # Cross-compiling with sanitizers??
  5164. mhd_cv_func_attribute_nosanitize_ptr='assuming no'
  5165. ]
  5166. )
  5167. AS_UNSET([ASAN_OPTIONS])
  5168. ]
  5169. )
  5170. AS_VAR_IF([mhd_cv_func_attribute_nosanitize_ptr], ["yes"],
  5171. [
  5172. AC_DEFINE([FUNC_ATTR_PTRCOMPARE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-compare")))' works])
  5173. AC_DEFINE([FUNC_ATTR_PTRSUBTRACT_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-subtract")))' works])
  5174. ],
  5175. [
  5176. AC_CACHE_CHECK([whether '__attribute__((no_sanitize("address")))' works for pointers compare], [mhd_cv_func_attribute_nosanitize_addr],
  5177. [
  5178. ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
  5179. export ASAN_OPTIONS
  5180. CFLAGS="${CFLAGS_ac} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS} ${user_CFLAGS}"
  5181. AC_RUN_IFELSE(
  5182. [
  5183. AC_LANG_SOURCE(
  5184. [[
  5185. #include <stdint.h>
  5186. #include <stdlib.h>
  5187. #include <sanitizer/asan_interface.h>
  5188. static const size_t first_pos = 0;
  5189. static const size_t mid_pos = 64;
  5190. static const size_t last_pos = 128;
  5191. static const size_t zone_size = 16;
  5192. static const size_t buf_size = 128 + 16;
  5193. __attribute__((no_sanitize("address")))
  5194. static int ptr_compare(void *ptr1, uint8_t *ptr2)
  5195. {
  5196. if ((((const uint8_t*)ptr1) >= ((const uint8_t*)ptr2)))
  5197. return ((char *) ptr1)[0] < ((char *) ptr2)[0];
  5198. return ((char *) ptr1)[0] > ((char *) ptr2)[0];
  5199. }
  5200. __attribute__((no_sanitize("address")))
  5201. static int ptr_subtract(void *ptr1, uint8_t *ptr2)
  5202. {
  5203. return ((size_t)(((const uint8_t*)ptr1) - \
  5204. ((const uint8_t*)ptr2))) <= last_pos;
  5205. }
  5206. int main(int argc, char *argv[])
  5207. {
  5208. char *buf = (char*) malloc (buf_size);
  5209. char *a;
  5210. char *b;
  5211. int ret;
  5212. (void) argv;
  5213. if (NULL == buf)
  5214. return 10;
  5215. ASAN_POISON_MEMORY_REGION (buf + first_pos + zone_size, mid_pos - first_pos - zone_size);
  5216. ASAN_POISON_MEMORY_REGION (buf + mid_pos + zone_size, last_pos - mid_pos - zone_size);
  5217. if (0 < argc)
  5218. a = buf + last_pos;
  5219. else
  5220. a = buf + first_pos;
  5221. b = buf + mid_pos;
  5222. *a = '0';
  5223. *b = '9';
  5224. if (ptr_compare((void *)a, (uint8_t*) b))
  5225. {
  5226. if (ptr_subtract((void *)a, (uint8_t*) b))
  5227. ret = 0;
  5228. else
  5229. ret = 10;
  5230. }
  5231. else
  5232. ret = 5;
  5233. ASAN_UNPOISON_MEMORY_REGION (buf, buf_size);
  5234. free (buf);
  5235. return ret;
  5236. }
  5237. ]]
  5238. )
  5239. ],
  5240. [mhd_cv_func_attribute_nosanitize_addr=yes], [mhd_cv_func_attribute_nosanitize_addr=no],
  5241. [
  5242. # Cross-compiling with sanitizers??
  5243. mhd_cv_func_attribute_nosanitize_addr='assuming no'
  5244. ]
  5245. )
  5246. AS_UNSET([ASAN_OPTIONS])
  5247. ]
  5248. )
  5249. AS_VAR_IF([mhd_cv_func_attribute_nosanitize_addr], ["yes"],
  5250. [AC_DEFINE([FUNC_ATTR_NOSANITIZE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("address")))' works for pointers compare])]
  5251. )
  5252. ]
  5253. )
  5254. ]
  5255. )
  5256. ]
  5257. )
  5258. ]
  5259. )
  5260. AS_IF([test "x${enable_san_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_address}" != "xyes"],
  5261. [AC_MSG_ERROR([Address sanitizer cannot be enabled])]
  5262. )
  5263. enable_san_address="${mhd_cv_cc_sanitizer_address}"
  5264. ]
  5265. )
  5266. AS_VAR_IF([enable_san_undef], ["no"], [:],
  5267. [
  5268. dnl Ensure that '#' will be processed correctly
  5269. [
  5270. test_undf_prog='
  5271. #include <stdio.h>
  5272. static void func_out_b(char *arr)
  5273. {
  5274. arr[0] = 0;
  5275. arr[16] = 2;
  5276. }
  5277. static unsigned int int_deref(void *ptr)
  5278. {
  5279. return (*((unsigned int*)ptr)) + 2;
  5280. }
  5281. static int func1(void)
  5282. {
  5283. char chr[16];
  5284. func_out_b (chr);
  5285. return (int) (int_deref(chr + 1) + int_deref(chr + 2));
  5286. }
  5287. int main(void)
  5288. {
  5289. unsigned long ulvar;
  5290. signed char ch1;
  5291. ulvar = -1 * func1();
  5292. ch1 = ulvar * 6UL;
  5293. printf("%lu\n", ulvar + ch1);
  5294. return 0;
  5295. }
  5296. '
  5297. ]
  5298. AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined],
  5299. [
  5300. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined ${user_CFLAGS}"
  5301. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  5302. [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no])
  5303. ]
  5304. )
  5305. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"],
  5306. [
  5307. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  5308. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  5309. ],
  5310. [
  5311. AS_CASE([${enable_san_undef}], [yes|auto-fallback],
  5312. [
  5313. AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap],
  5314. [
  5315. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error ${user_CFLAGS}"
  5316. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  5317. [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no])
  5318. ]
  5319. )
  5320. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"],
  5321. [
  5322. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  5323. AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS])
  5324. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  5325. AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited])
  5326. ],
  5327. [
  5328. AS_IF([test -z "${enabled_sanitizers}"],
  5329. [
  5330. # Last resort
  5331. AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all],
  5332. [
  5333. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}"
  5334. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  5335. [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no])
  5336. ]
  5337. )
  5338. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"],
  5339. [
  5340. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  5341. AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS])
  5342. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all ${user_CFLAGS}"
  5343. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  5344. AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited])
  5345. ]
  5346. )
  5347. ]
  5348. )
  5349. ]
  5350. )
  5351. AS_CASE(["$enabled_sanitizers"], [*undefined],
  5352. [
  5353. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[],
  5354. [
  5355. # A workaround for broken clang which is trying to use UBSan lib
  5356. # even when instructed to not use it
  5357. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
  5358. AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion],
  5359. [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])])
  5360. ]
  5361. )
  5362. ]
  5363. )
  5364. ]
  5365. )
  5366. ]
  5367. )
  5368. AS_CASE(["$enabled_sanitizers"], [*undefined],
  5369. [
  5370. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
  5371. AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg],
  5372. [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])])
  5373. ]
  5374. )
  5375. AS_UNSET([test_undf_prog])
  5376. AS_CASE(["$enabled_sanitizers"],
  5377. [*undefined], [enable_san_undef="yes"],
  5378. [
  5379. AS_VAR_IF([enable_san_undef], [yes], [AC_MSG_ERROR([Undefined behavior sanitizer cannot be enabled])])
  5380. enable_san_undef="no"
  5381. ]
  5382. )
  5383. ]
  5384. )
  5385. AS_VAR_IF([enable_san_leak], ["no"], [:],
  5386. [
  5387. AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak],
  5388. [
  5389. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak ${user_CFLAGS}"
  5390. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  5391. [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no])
  5392. ]
  5393. )
  5394. AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"],
  5395. [
  5396. AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS])
  5397. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak"
  5398. ]
  5399. )
  5400. AS_IF([test "x${enable_san_leak}" = "xyes" && test "x${mhd_cv_cc_sanitizer_leak}" != "xyes"],
  5401. [AC_MSG_ERROR([User poison cannot be enabled])]
  5402. )
  5403. enable_san_leak="${mhd_cv_cc_sanitizer_leak}"
  5404. ]
  5405. )
  5406. AS_IF([test -z "${enabled_sanitizers}"],
  5407. [
  5408. AS_VAR_IF([enable_sanitizers], ["auto-optional"],
  5409. [
  5410. san_FLAGS=""
  5411. san_CFLAGS=""
  5412. ],
  5413. [
  5414. AC_MSG_ERROR([cannot find any sanitizer supported by $CC])
  5415. ]
  5416. )
  5417. ],
  5418. [
  5419. AS_VAR_IF([enable_san_upoison], ["no"], [:],
  5420. [
  5421. AC_MSG_CHECKING([whether to enable user memory poisoning])
  5422. AS_IF([test "x${mhd_cv_cc_sanitizer_address}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes" && \
  5423. (test "x${mhd_cv_func_u_p_attribute_needed}" != "xyes" || test "x${mhd_cv_func_attribute_nosanitize_ptr}" = "xyes" || \
  5424. test "x${mhd_cv_func_attribute_nosanitize_addr}" = "xyes")],
  5425. [
  5426. AC_DEFINE([MHD_ASAN_POISON_ACTIVE], [1], [Define to '1' if user memory poison is used])
  5427. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }user-poison"
  5428. enable_san_upoison="yes"
  5429. AC_MSG_RESULT([yes])
  5430. ],
  5431. [
  5432. AC_MSG_RESULT([no])
  5433. AS_VAR_IF([enable_san_upoison], ["yes"],
  5434. [AC_MSG_ERROR([User memory poisoning cannot be enabled])])
  5435. enable_san_upoison="no"
  5436. ]
  5437. )
  5438. ]
  5439. )
  5440. AS_VAR_IF([enable_san_address], ["yes"],
  5441. [
  5442. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
  5443. AC_CHECK_DECL([_FORTIFY_SOURCE],
  5444. [MHD_APPEND_FLAG_TO_VAR([CPPFLAGS_ac],[-U_FORTIFY_SOURCE])],
  5445. [],[/* no includes */])
  5446. AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS])
  5447. ],
  5448. [
  5449. AS_CASE([$enable_sanitizers], [auto|auto-fallback],
  5450. [AC_MSG_WARN([$CC does not support address sanitizer])])
  5451. ]
  5452. )
  5453. CFLAGS="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS} ${user_CFLAGS}"
  5454. # Always stop on sanitizer error
  5455. AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS])
  5456. # Get a better output for sanitizers error reporting
  5457. AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-optimize-sibling-calls],
  5458. [san_CFLAGS])
  5459. AS_VAR_IF([enable_san_address], ["yes"],
  5460. [
  5461. AM_ASAN_OPTIONS="exitcode=88:strict_string_checks=1:detect_stack_use_after_return=1"
  5462. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64"
  5463. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3"
  5464. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:handle_ioctl=1:halt_on_error=1"
  5465. AS_VAR_IF([enable_san_upoison], ["yes"], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:allow_user_poisoning=1"])
  5466. AS_VAR_IF([enable_san_leak], ["yes"],
  5467. [AS_VAR_IF([mhd_cv_cc_sanitizer_address_leak], ["yes"],
  5468. [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=1"])
  5469. ], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=0"]
  5470. )
  5471. ]
  5472. )
  5473. AS_VAR_IF([enable_san_undef], [yes],
  5474. [AM_UBSAN_OPTIONS="exitcode=87:print_stacktrace=1:halt_on_error=1"])
  5475. AS_VAR_IF([enable_san_leak], ["yes"],
  5476. [AM_LSAN_OPTIONS="use_unaligned=1"]
  5477. )
  5478. TESTS_ENVIRONMENT_ac='\
  5479. ASAN_OPTIONS="$(AM_ASAN_OPTIONS)" ; export ASAN_OPTIONS ; \
  5480. UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \
  5481. LSAN_OPTIONS="$(AM_LSAN_OPTIONS)" ; export LSAN_OPTIONS ;'
  5482. ]
  5483. )
  5484. ]
  5485. )
  5486. CFLAGS_ac="${CFLAGS_ac} ${san_FLAGS} ${san_CFLAGS}"
  5487. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  5488. ]
  5489. )
  5490. # fuzzing tests
  5491. run_zzuf_tests="no"
  5492. zzuf_socat_mandatory="no"
  5493. AS_VAR_IF([use_heavy_tests],["yes"],
  5494. [
  5495. AS_VAR_IF([enable_curl],["yes"],
  5496. [
  5497. AC_PATH_PROG([ZZUF],[zzuf],[no])
  5498. AS_VAR_IF([ZZUF],["no"],
  5499. [
  5500. run_zzuf_tests="no"
  5501. run_zzuf_tests_MSG="no, zzuf tool not found"
  5502. ],
  5503. [
  5504. AC_PATH_PROG([SOCAT],[socat],[no])
  5505. AS_IF([test "x${ac_cv_func_accept4}" = "xyes" && test "x${enable_asserts}" = "xno"],
  5506. [
  5507. zzuf_socat_mandatory="yes"
  5508. AS_VAR_IF([SOCAT],["no"],
  5509. [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests on this platform without asserts enabled"],
  5510. [
  5511. run_zzuf_tests="yes"
  5512. run_zzuf_tests_MSG="yes, with zzuf and socat tools"
  5513. ]
  5514. )
  5515. ],
  5516. [test -n "${enabled_sanitizers}"],
  5517. [
  5518. zzuf_socat_mandatory="yes"
  5519. AS_VAR_IF([SOCAT],["no"],
  5520. [run_zzuf_tests_MSG="no, socat not found, but required for fuzzing tests when sanitizers enabled"],
  5521. [
  5522. run_zzuf_tests="yes"
  5523. run_zzuf_tests_MSG="yes, with zzuf and socat tools"
  5524. ]
  5525. )
  5526. ],
  5527. [
  5528. run_zzuf_tests="yes"
  5529. run_zzuf_tests_MSG="yes, with zzuf tool"
  5530. ]
  5531. )
  5532. ]
  5533. )
  5534. ],
  5535. [
  5536. run_zzuf_tests="no"
  5537. run_zzuf_tests_MSG="no, tests with libcurl are not enabled"
  5538. ]
  5539. )
  5540. ],
  5541. [
  5542. run_zzuf_tests="no"
  5543. run_zzuf_tests_MSG="no, heavy tests are not enabled"
  5544. ]
  5545. )
  5546. AM_CONDITIONAL([RUN_ZZUF_TESTS],[test "x$run_zzuf_tests" = "xyes"])
  5547. AM_CONDITIONAL([FORCE_USE_ZZUF_SOCAT],[test "x$zzuf_socat_mandatory" = "xyes"])
  5548. # Final flags that may interfere with autoconf detections
  5549. AS_CASE([${enable_build_type}],[debug|debugger],
  5550. [ # Debug build or build for walking with debugger
  5551. CFLAGS="${user_CFLAGS}"
  5552. MHD_CHECK_ADD_CC_CFLAGS([-Wextra-semi -Wextra-semi-stmt], [CFLAGS_ac])
  5553. CFLAGS="${CFLAGS_ac} ${user_CFLAGS}"
  5554. ]
  5555. )
  5556. AM_CONDITIONAL([USE_SANITIZERS],
  5557. [test -n "$enabled_sanitizers" && test "x$mhd_cv_cc_sanitizer_works" = "xyes"])
  5558. AC_SUBST([AM_ASAN_OPTIONS])
  5559. AC_SUBST([AM_UBSAN_OPTIONS])
  5560. AC_SUBST([AM_LSAN_OPTIONS])
  5561. AC_SUBST([TESTS_ENVIRONMENT_ac])
  5562. MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS"
  5563. AC_SUBST([CPU_COUNT])
  5564. AC_SUBST([HEAVY_TESTS_NOTPARALLEL])
  5565. AM_SUBST_NOTMAKE([HEAVY_TESTS_NOTPARALLEL])
  5566. AC_SUBST(MHD_LIB_CPPFLAGS)
  5567. AC_SUBST(MHD_LIB_CFLAGS)
  5568. AC_SUBST(MHD_LIB_LDFLAGS)
  5569. AC_SUBST(MHD_LIBDEPS)
  5570. AC_SUBST(MHD_TLS_LIB_CPPFLAGS)
  5571. AC_SUBST(MHD_TLS_LIB_CFLAGS)
  5572. AC_SUBST(MHD_TLS_LIB_LDFLAGS)
  5573. AC_SUBST(MHD_TLS_LIBDEPS)
  5574. # for pkg-config
  5575. AC_SUBST([MHD_REQ_PRIVATE])
  5576. AC_SUBST([MHD_LIBDEPS_PKGCFG])
  5577. # Restore flags as set by the user
  5578. CFLAGS="${user_CFLAGS}"
  5579. LDFLAGS="${user_LDFLAGS}"
  5580. CPPFLAGS="${user_CPPFLAGS}"
  5581. AC_SUBST([CFLAGS])
  5582. AC_SUBST([LDFLAGS])
  5583. AC_SUBST([CPPFLAGS])
  5584. AC_SUBST([LIBS])
  5585. # Configure-defined flags
  5586. AC_SUBST([CFLAGS_ac])
  5587. AC_SUBST([LDFLAGS_ac])
  5588. AC_SUBST([CPPFLAGS_ac])
  5589. # Used for 'po' directory staff
  5590. AC_SUBST([ac_configure_args])
  5591. AC_SUBST([EMPTY_VAR],[])
  5592. AC_SUBST([MHD_AUX_DIR])
  5593. AC_CONFIG_FILES([po/po-configure.ac])
  5594. AC_CONFIG_COMMANDS([po/Makefile.in],
  5595. [
  5596. echo "Skipping update of po/Makefile.in"
  5597. echo "Real update of po/Makefile.in for 'make dist' is performed by po-config.status"
  5598. ]
  5599. )
  5600. AC_CONFIG_COMMANDS([po-directories],
  5601. [
  5602. echo "Skipping po-directories command."
  5603. echo "Real po-directories command for 'make dist' is implemented in po-config.status"
  5604. ]
  5605. )
  5606. # We define the paths here, because MinGW/GCC expands paths
  5607. # passed through the command line ("-DDIR=..."). This would
  5608. # lead to hard-coded paths ("C:\mingw\mingw\bin...") that do
  5609. # not contain the actual installation.
  5610. AC_DEFINE_DIR([MHD_PLUGIN_INSTALL_PREFIX], [libdir/libmicrohttpd], [tls plugins])
  5611. AC_SUBST([ZZUF])
  5612. AC_SUBST([SOCAT])
  5613. # should experimental code be compiled (code that may not yet compile)?
  5614. AC_MSG_CHECKING(whether to compile experimental code)
  5615. AC_ARG_ENABLE([experimental],
  5616. [AS_HELP_STRING([--enable-experimental], [enable compiling experimental code])],
  5617. [enable_experimental=${enableval}],
  5618. [enable_experimental=no])
  5619. AC_MSG_RESULT($enable_experimental)
  5620. AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"])
  5621. AC_CONFIG_FILES([libmicrohttpd.pc
  5622. w32/common/microhttpd_dll_res_vc.rc
  5623. Makefile
  5624. contrib/Makefile
  5625. doc/Makefile
  5626. doc/doxygen/libmicrohttpd.doxy
  5627. doc/doxygen/Makefile
  5628. doc/examples/Makefile
  5629. m4/Makefile
  5630. src/Makefile
  5631. src/include/Makefile
  5632. src/lib/Makefile
  5633. src/microhttpd/Makefile
  5634. src/microhttpd_ws/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}])])