configure.ac 161 KB

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