configure.ac 161 KB

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