configure.ac 111 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482
  1. # This file is part of libmicrohttpd.
  2. # (C) 2006-2021 Christian Grothoff (and other contributing authors)
  3. # (C) 2014-2021 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. AM_INIT_AUTOMAKE([silent-rules] [subdir-objects])
  29. AC_CONFIG_HEADERS([MHD_config.h])
  30. AC_CONFIG_MACRO_DIR([m4])
  31. LIB_VERSION_CURRENT=72
  32. LIB_VERSION_REVISION=0
  33. LIB_VERSION_AGE=60
  34. AC_SUBST(LIB_VERSION_CURRENT)
  35. AC_SUBST(LIB_VERSION_REVISION)
  36. AC_SUBST(LIB_VERSION_AGE)
  37. AC_MSG_CHECKING([[whether z/OS special settings are required]])
  38. AS_IF([test `uname -s` = "OS/390"],
  39. [
  40. # configure binaries for z/OS
  41. AS_IF([test -z "$CC"],
  42. [CC=`pwd`"/contrib/xcc"
  43. chmod +x $CC || true])
  44. AS_IF([test -z "$CPP"],
  45. CPP="c89 -E")
  46. AS_IF([test -z "$CXXCPP"],
  47. CXXCPP="c++ -E -+")
  48. AC_MSG_RESULT([[yes]])
  49. # _CCC_CCMODE=1
  50. # _C89_CCMODE=1
  51. ],
  52. AC_MSG_RESULT([[no]])
  53. )
  54. # Checks for programs.
  55. AC_PROG_AWK
  56. AC_PROG_GREP
  57. AC_PROG_FGREP
  58. AC_PROG_INSTALL
  59. AC_PROG_LN_S
  60. AC_PROG_MAKE_SET
  61. AC_CANONICAL_HOST
  62. m4_version_prereq([2.70],
  63. [
  64. # Find C compiler and compiler options to support
  65. # the latest C standard (C11). Fallback to C99 and C89
  66. # if later C versions are not supported.
  67. AC_PROG_CC
  68. ],
  69. [
  70. # Find C compiler and compiler options to support
  71. # the latest C standard (C99). Fallback to C89
  72. # if later C versions are not supported.
  73. AC_PROG_CC_STDC
  74. ]
  75. )
  76. MHD_SYS_EXT
  77. LT_INIT([win32-dll])
  78. LT_LANG([Windows Resource])
  79. # Check for headers that are ALWAYS required
  80. AC_CHECK_HEADERS_ONCE([stdio.h string.h stdint.h errno.h limits.h fcntl.h], [],
  81. [AC_MSG_ERROR([Compiling libmicrohttpd requires standard POSIX headers files])], [AC_INCLUDES_DEFAULT])
  82. # Check for basic optional headers
  83. AC_CHECK_HEADERS([stddef.h stdlib.h inttypes.h sys/types.h sys/stat.h unistd.h], [], [], [AC_INCLUDES_DEFAULT])
  84. # Check for clock-specific optional headers
  85. AC_CHECK_HEADERS([sys/time.h time.h], [], [], [AC_INCLUDES_DEFAULT])
  86. # Check for system information and parameters optional headers
  87. AC_CHECK_HEADERS([endian.h machine/endian.h sys/endian.h sys/byteorder.h \
  88. sys/machine.h machine/param.h sys/param.h sys/isa_defs.h \
  89. sys/ioctl.h], [], [], [AC_INCLUDES_DEFAULT])
  90. # Check for network and sockets optional headers
  91. AC_CHECK_HEADERS([sys/socket.h sys/select.h netinet/in.h arpa/inet.h \
  92. netinet/ip.h netinet/tcp.h net/if.h \
  93. netdb.h sockLib.h inetLib.h], [], [],
  94. [AC_INCLUDES_DEFAULT
  95. [
  96. #ifdef HAVE_SYS_TYPES_H
  97. #include <sys/types.h>
  98. #endif /* HAVE_SYS_TYPES_H */
  99. #ifdef HAVE_INTTYPES_H
  100. #include <inttypes.h>
  101. #endif /* HAVE_INTTYPES_H */
  102. #ifdef HAVE_SYS_SOCKET_H
  103. #include <sys/socket.h>
  104. #endif /* HAVE_SYS_SOCKET_H */
  105. #ifdef HAVE_NETINET_IN_H
  106. #include <netinet/in.h>
  107. #endif /* HAVE_NETINET_IN_H */
  108. #ifdef HAVE_NETINET_IP_H
  109. #include <netinet/ip.h>
  110. #endif /* HAVE_NETINET_IP_H */
  111. #ifdef HAVE_NETINET_TCP_H
  112. #include <netinet/tcp.h>
  113. #endif /* HAVE_NETINET_TCP_H */
  114. ]]
  115. )
  116. # Check for other optional headers
  117. AC_CHECK_HEADERS([sys/msg.h sys/mman.h signal.h], [], [], [AC_INCLUDES_DEFAULT])
  118. AC_CHECK_HEADER([[search.h]],
  119. [
  120. gl_FUNC_TSEARCH
  121. AS_IF([[test "x$HAVE_TSEARCH" = "x1" && test "x$REPLACE_TSEARCH" != "x1"]],
  122. [AC_DEFINE([[HAVE_SEARCH_H]], [[1]],
  123. [Define to 1 if you have the <search.h> header file and your system have properly functioning tsearch(), tfind() and tdelete() functions])])
  124. ],
  125. [], [AC_INCLUDES_DEFAULT])
  126. AM_CONDITIONAL([MHD_HAVE_TSEARCH], [[test "x$ac_cv_header_search_h" = xyes && test "x$HAVE_TSEARCH" = "x1" && test "x$REPLACE_TSEARCH" != "x1"]])
  127. # Optional headers used for tests
  128. AC_CHECK_HEADERS([sys/sysctl.h netinet/ip_icmp.h netinet/icmp_var.h], [], [],
  129. [[
  130. #ifdef HAVE_SYS_TYPES_H
  131. #include <sys/types.h>
  132. #endif /* HAVE_SYS_TYPES_H */
  133. #ifdef HAVE_SYS_SYSCTL_H
  134. #include <sys/sysctl.h>
  135. #endif /* HAVE_SYS_SYSCTL_H */
  136. #ifdef HAVE_SYS_SOCKET_H
  137. #include <sys/socket.h>
  138. #endif /* HAVE_SYS_SOCKET_H */
  139. #ifdef HAVE_NETINET_IN_H
  140. #include <netinet/in.h>
  141. #endif /* HAVE_NETINET_IN_H */
  142. #ifdef HAVE_NETINET_IP_H
  143. #include <netinet/ip.h>
  144. #endif /* HAVE_NETINET_IP_H */
  145. #ifdef HAVE_NETINET_IP_ICMP_H
  146. #include <netinet/ip_icmp.h>
  147. #endif /* HAVE_NETINET_IP_ICMP_H */
  148. ]]
  149. )
  150. # Checks for gettext.
  151. m4_ifdef([AM_GNU_GETTEXT], [
  152. AS_VAR_SET_IF([enable_nls], [], [[enable_nls=no]])
  153. AM_GNU_GETTEXT([external],[need-ngettext])
  154. AC_CONFIG_FILES([po/Makefile.in])
  155. have_po=yes
  156. ], [
  157. have_po=no
  158. ])
  159. m4_ifdef([AM_GNU_GETTEXT_VERSION], [
  160. #do not indent here
  161. AM_GNU_GETTEXT_VERSION([0.20.2])
  162. ])
  163. AM_CONDITIONAL([HAVE_PO], [ test "$have_po" = yes ])
  164. # Adam shostack suggests the following for Windows:
  165. # -D_FORTIFY_SOURCE=2 -fstack-protector-all
  166. AC_ARG_ENABLE([gcc-hardening],
  167. [AS_HELP_STRING([--enable-gcc-hardening], [enable compiler security checks])],
  168. [AS_IF([test x$enableval = xyes],[
  169. CFLAGS="$CFLAGS -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fstack-protector-all"
  170. CFLAGS="$CFLAGS -fwrapv -fPIE -Wstack-protector"
  171. CFLAGS="$CFLAGS --param ssp-buffer-size=1"
  172. LDFLAGS="$LDFLAGS -pie"
  173. ])])
  174. # Linker hardening options
  175. # Currently these options are ELF specific - you can't use this with MacOSX
  176. AC_ARG_ENABLE([linker-hardening],
  177. [AS_HELP_STRING([--enable-linker-hardening], [enable linker security fixups])],
  178. [AS_IF([test x$enableval = xyes],
  179. [LDFLAGS="$LDFLAGS -z relro -z now"])])
  180. # Workaround for libgcrypt
  181. AS_IF([[test "x$lt_sysroot" != "x" && test "x$SYSROOT" = "x"]], [[SYSROOT="$lt_sysroot"]])
  182. PACKAGE_VERSION_MAJOR='m4_car(m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  183. PACKAGE_VERSION_MINOR='m4_argn(2, m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  184. PACKAGE_VERSION_SUBMINOR='m4_argn(3, m4_unquote(m4_split(AC_PACKAGE_VERSION, [\.])))'
  185. AS_VAR_ARITH([MHD_W32_DLL_SUFF],[[$LIB_VERSION_CURRENT - $LIB_VERSION_AGE]])
  186. AC_SUBST([PACKAGE_VERSION_MAJOR])
  187. AC_SUBST([PACKAGE_VERSION_MINOR])
  188. AC_SUBST([PACKAGE_VERSION_SUBMINOR])
  189. AC_SUBST([MHD_W32_DLL_SUFF])
  190. AC_CONFIG_FILES([src/microhttpd/microhttpd_dll_res.rc])
  191. MHD_LIB_CPPFLAGS=""
  192. MHD_LIB_CFLAGS=""
  193. MHD_LIB_LDFLAGS=""
  194. MHD_LIBDEPS=""
  195. # for pkg-config
  196. MHD_REQ_PRIVATE=''
  197. MHD_LIBDEPS_PKGCFG=''
  198. AH_TEMPLATE([[HAVE_STDBOOL_H]], [Define to 1 if you have the <stdbool.h> header file and <stdbool.h> defines 'bool' type.])
  199. AH_TEMPLATE([[HAVE_REAL_BOOL]], [Define to 1 if you have the real boolean type.])
  200. AH_TEMPLATE([[bool]], [Define to type name which will be used as boolean type.])
  201. AC_CHECK_HEADER([stdbool.h],
  202. [
  203. AC_CHECK_TYPE([bool],
  204. [
  205. AC_DEFINE([[HAVE_STDBOOL_H]], [[1]])
  206. AC_DEFINE([[HAVE_REAL_BOOL]], [[1]])
  207. ],
  208. [
  209. AC_MSG_WARN([[Header <stdbool.h> is present, but "bool" type cannot be detected. Check compiler flags.]])
  210. AC_DEFINE([[bool]], [[int]])
  211. ], [
  212. #include <stdbool.h>
  213. ]
  214. )
  215. ],
  216. [
  217. AC_CHECK_TYPE([bool],
  218. [AC_DEFINE([[HAVE_REAL_BOOL]], [[1]])],
  219. [
  220. AC_CHECK_TYPE([_Bool],
  221. [
  222. AC_DEFINE([[HAVE_REAL_BOOL]], [[1]])
  223. AC_DEFINE([[bool]], [[_Bool]])
  224. ],
  225. [
  226. AC_DEFINE([[bool]], [[int]])
  227. ], []
  228. )
  229. ], []
  230. )
  231. ],
  232. [AC_INCLUDES_DEFAULT]
  233. )
  234. AC_CACHE_CHECK([[whether "true" is defined or builtin]], [[mhd_cv_macro_true_defined]],
  235. [AC_COMPILE_IFELSE(
  236. [AC_LANG_PROGRAM(
  237. [[
  238. #ifdef HAVE_STDBOOL_H
  239. #include <stdbool.h>
  240. #endif
  241. ]], [[
  242. #if defined(true)
  243. /* dummy */
  244. #else
  245. (void)true;
  246. #endif
  247. ]])
  248. ], [[mhd_cv_macro_true_defined='yes']], [[mhd_cv_macro_true_defined='no']])
  249. ])
  250. AS_VAR_IF([[mhd_cv_macro_true_defined]], [["yes"]], [[:]],
  251. [AC_DEFINE([[true]],[[(!0)]], [Define to value interpreted by compiler as boolean "true", if "true" is not defined by system headers.])])
  252. AC_CACHE_CHECK([[whether "false" is defined or builtin]], [[mhd_cv_macro_false_defined]],
  253. [AC_COMPILE_IFELSE(
  254. [AC_LANG_PROGRAM(
  255. [[
  256. #ifdef HAVE_STDBOOL_H
  257. #include <stdbool.h>
  258. #endif
  259. ]], [[
  260. #if !defined(false)
  261. (void)false;
  262. #else
  263. /* dummy */
  264. #endif
  265. ]])
  266. ], [[mhd_cv_macro_false_defined='yes']], [[mhd_cv_macro_false_defined='no']])
  267. ])
  268. AS_VAR_IF([[mhd_cv_macro_false_defined]], [["yes"]], [[:]],
  269. [AC_DEFINE([[false]],[[0]], [Define to value interpreted by compiler as boolean "false", if "false" is not defined by system headers.])])
  270. AC_CACHE_CHECK([[whether "true" and "false" could be used]], [[mhd_cv_macro_true_false_valid]],
  271. [AC_COMPILE_IFELSE(
  272. [AC_LANG_PROGRAM(
  273. [[
  274. #ifdef HAVE_STDBOOL_H
  275. #include <stdbool.h>
  276. #endif
  277. ]], [[
  278. int var1[true ? 1 : -1] = { 1 };
  279. int var2[false ? -1 : 1] = { 2 };
  280. int var3[!true ? -1 : 1] = { 3 };
  281. int var4[!false ? 1 : -1] = { 4 };
  282. if (var1[0] == var2[0] || var3[0] == var4[0])
  283. return 1;
  284. ]])
  285. ], [[mhd_cv_macro_true_false_valid='yes']], [[mhd_cv_macro_true_false_valid='no']])
  286. ])
  287. AS_VAR_IF([[mhd_cv_macro_true_false_valid]], [["yes"]], [[:]],
  288. [AC_MSG_ERROR([[Value of "true" or value of "false" is not valid. Check config.log for details.]])])
  289. AX_CHECK_COMPILE_FLAG([[-Werror=attributes]],
  290. [
  291. save_CFLAGS="$CFLAGS"
  292. CFLAGS="$CFLAGS -Werror=attributes"
  293. AC_MSG_CHECKING([[whether -Werror=attributes actually works]])
  294. AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
  295. [[__attribute__((non_existing_attrb_dummy)) int SimpleFunc(void) {return 3;}]], [[int r = SimpleFunc(); if (r) return r;]])],
  296. [
  297. AC_MSG_RESULT([[no]])
  298. errattr_CFLAGS=""
  299. ], [
  300. AC_MSG_RESULT([[yes]])
  301. errattr_CFLAGS="-Werror=attributes"
  302. ])
  303. CFLAGS="$save_CFLAGS"
  304. ],
  305. [[errattr_CFLAGS=""]], [], [])
  306. AC_MSG_CHECKING([[for function inline keywords supported by $CC]])
  307. save_CFLAGS="$CFLAGS"
  308. CFLAGS="$CFLAGS $errattr_CFLAGS"
  309. inln_prfx="none"
  310. # Prefer always inline functions
  311. for inln_prfx_chk in InlineWithAttr __forceinline inline __inline__ __inline _inline _Inline
  312. do
  313. # Try to link to avoid "symbol undefined" problems at build time
  314. AS_IF([[test "x$inln_prfx_chk" = "xInlineWithAttr"]],
  315. [
  316. AS_IF([[test "x$errattr_CFLAGS" = "x"]],
  317. [[ # Skip test with attribute as negative result can't be detected
  318. inln_prfx_chk="__forceinline" # use next value
  319. ]],[[inln_prfx_chk="inline __attribute__((always_inline))"]])
  320. ])
  321. AC_LINK_IFELSE(
  322. [
  323. AC_LANG_PROGRAM(
  324. [[
  325. #ifdef __cplusplus
  326. #error This test is only for C.
  327. choke me
  328. #endif
  329. #ifdef HAVE_STDBOOL_H
  330. #include <stdbool.h>
  331. #endif
  332. static $inln_prfx_chk bool cmpfn(int x, int y)
  333. { return x > y; }
  334. static $inln_prfx_chk int sumfn(int x, int y)
  335. { return x + y; }
  336. ]],[[
  337. int a = 1, b = 100, c;
  338. if (cmpfn(a, b))
  339. c = sumfn(a, b);
  340. else
  341. c = 0 - sumfn(a, b);
  342. if (c)
  343. return 0;
  344. ]])
  345. ],
  346. [[ inln_prfx="$inln_prfx_chk" ]])
  347. test "x$inln_prfx" != "xnone" && break
  348. done
  349. AS_IF([[test "x$inln_prfx" != "xnone"]],
  350. [
  351. AC_DEFINE([INLINE_FUNC],[1],[Define to 1 if your C compiler supports inline functions.])
  352. AC_DEFINE_UNQUOTED([_MHD_static_inline],[static $inln_prfx],[Define to prefix which will be used with MHD static inline functions.])
  353. ], [
  354. AC_DEFINE([_MHD_static_inline],[static],[Define to prefix which will be used with MHD static inline functions.])
  355. ])
  356. AC_MSG_RESULT([[$inln_prfx]])
  357. CFLAGS="$save_CFLAGS"
  358. AC_CHECK_HEADERS([stdalign.h], [], [], [AC_INCLUDES_DEFAULT])
  359. AC_CACHE_CHECK([[for C11 'alignof()' support]], [[mhd_cv_c_alignof]],
  360. [AC_COMPILE_IFELSE(
  361. [AC_LANG_PROGRAM(
  362. [[
  363. #ifdef HAVE_STDALIGN_H
  364. #include <stdalign.h>
  365. #endif
  366. ]], [[
  367. int var1[(alignof(int) >= 2) ? 1 : -1];
  368. int var2[alignof(unsigned int) - 1];
  369. int var3[(alignof(char) > 0) ? 1 : -1];
  370. int var4[(alignof(long) >= 4) ? 1 : -1];
  371. /* Mute compiler warnings */
  372. var1[0] = var2[0] = var3[0] = 0;
  373. var4[0] = 1;
  374. if (var1[0] + var2[0] + var3[0] == var4[0])
  375. return 1;
  376. ]])
  377. ], [
  378. AC_COMPILE_IFELSE(
  379. [AC_LANG_PROGRAM(
  380. [[
  381. #ifdef HAVE_STDALIGN_H
  382. #include <stdalign.h>
  383. #endif
  384. ]], [[
  385. /* Should fail if 'alignof()' works */
  386. int var1[alignof(nonexisting_type) - 1];
  387. /* Mute compiler warnings */
  388. var1[0] = 1;
  389. if (var1[0] + 1 == 1)
  390. return 1;
  391. ]])
  392. ], [[mhd_cv_c_alignof='no']], [[mhd_cv_c_alignof='yes']])
  393. ], [[mhd_cv_c_alignof='no']])
  394. ])
  395. AS_VAR_IF([mhd_cv_c_alignof], ["yes"],
  396. [AC_DEFINE([[HAVE_C_ALIGNOF]], [1], [Define to 1 if your compiler supports 'alignof()'])])
  397. # Check system type
  398. shutdown_trig_select='no'
  399. AC_MSG_CHECKING([[for target host OS]])
  400. AS_CASE(["$host_os"],
  401. [*darwin* | *rhapsody* | *macosx*],
  402. [AC_DEFINE_UNQUOTED(OSX,1,[This is an OS X system])
  403. CFLAGS="-no-cpp-precomp -fno-common $CFLAGS"
  404. mhd_host_os='Darwin'
  405. AC_MSG_RESULT([[$mhd_host_os]])],
  406. [freebsd*],
  407. [AC_DEFINE_UNQUOTED(SOMEBSD,1,[This is a BSD system])
  408. AC_DEFINE_UNQUOTED(FREEBSD,1,[This is a FreeBSD system])
  409. mhd_host_os='FreeBSD'
  410. AC_MSG_RESULT([[$mhd_host_os]])],
  411. [openbsd*],
  412. [AC_DEFINE_UNQUOTED(SOMEBSD,1,[This is a BSD system])
  413. AC_DEFINE_UNQUOTED(OPENBSD,1,[This is an OpenBSD system])
  414. mhd_host_os='OpenBSD'
  415. AC_MSG_RESULT([[$mhd_host_os]])],
  416. [netbsd*],
  417. [AC_DEFINE_UNQUOTED(SOMEBSD,1,[This is a BSD system])
  418. AC_DEFINE_UNQUOTED(NETBSD,1,[This is a NetBSD system])
  419. mhd_host_os='NetBSD'
  420. AC_MSG_RESULT([[$mhd_host_os]])],
  421. [*solaris*],
  422. [AC_DEFINE_UNQUOTED(SOLARIS,1,[This is a Solaris system])
  423. AC_DEFINE_UNQUOTED(_REENTRANT,1,[Need with solaris or errno does not work])
  424. mhd_host_os='Solaris'
  425. AC_MSG_RESULT([[$mhd_host_os]])
  426. AC_SEARCH_LIBS(gethostbyname, nsl)
  427. AC_SEARCH_LIBS(socket, socket)],
  428. [*arm-linux*],
  429. [AC_DEFINE_UNQUOTED(LINUX,1,[This is a Linux kernel])
  430. mhd_host_os='ARM Linux'
  431. AC_MSG_RESULT([[$mhd_host_os]])
  432. CFLAGS="-fPIC -pipe $CFLAGS"],
  433. [*linux*],
  434. [AC_DEFINE_UNQUOTED(LINUX,1,[This is a Linux kernel])
  435. mhd_host_os='Linux'
  436. AC_MSG_RESULT([[$mhd_host_os]])],
  437. [*cygwin*],
  438. [AC_DEFINE_UNQUOTED(CYGWIN,1,[This is a Cygwin system])
  439. mhd_host_os='Windows/Cygwin'
  440. AC_MSG_RESULT([[$mhd_host_os]])
  441. os_is_windows=yes],
  442. [*mingw*],
  443. [
  444. AC_DEFINE([MINGW],[1],[This is a MinGW system])
  445. AC_DEFINE([WINDOWS],[1],[This is a Windows system])
  446. mhd_host_os='Windows/MinGW'
  447. AC_MSG_RESULT([[$mhd_host_os]])
  448. LIBS="$LIBS -lws2_32"
  449. AC_CHECK_HEADERS([winsock2.h ws2tcpip.h], [], [AC_MSG_ERROR([[Winsock2 headers are required for W32]])], [AC_INCLUDES_DEFAULT])
  450. AC_CACHE_CHECK([for MS lib utility], [ac_cv_use_ms_lib_tool],
  451. [mslibcheck=`lib 2>&1`
  452. AS_IF([echo "$mslibcheck" | $GREP -e '^Microsoft (R) Library Manager' - >/dev/null],
  453. [ac_cv_use_ms_lib_tool=yes],
  454. [ac_cv_use_ms_lib_tool=no])
  455. ])
  456. AS_IF([test "x$ac_cv_use_ms_lib_tool" = "xyes"],
  457. [AC_SUBST([MS_LIB_TOOL], [[lib]])])
  458. AC_SUBST([lt_cv_objdir])
  459. os_is_windows=yes
  460. os_is_native_w32=yes
  461. ],
  462. [*openedition*],
  463. [AC_DEFINE_UNQUOTED(OS390,1,[This is a OS/390 system])
  464. mhd_host_os='OS/390'
  465. AC_MSG_RESULT([[$mhd_host_os]])],
  466. [gnu*],
  467. [AC_DEFINE([[GNU_HURD]], [[1]], [Define to `1' if host machine runs on GNU Hurd.])
  468. mhd_host_os='GNU Hurd'
  469. AC_MSG_RESULT([[$mhd_host_os]])
  470. ],
  471. [
  472. AC_MSG_RESULT([unrecognised OS])
  473. mhd_host_os="${host_os}"
  474. AC_MSG_WARN([Unrecognised OS $host_os])
  475. AC_DEFINE_UNQUOTED(OTHEROS,1,[Some strange OS])
  476. ])
  477. AM_CONDITIONAL([CYGWIN_TARGET], [[test "x$os_is_windows" = "xyes" && \
  478. test "x${os_is_native_w32}" != "xyes"]])
  479. AS_VAR_IF([os_is_windows], ["yes"],
  480. [
  481. AC_MSG_CHECKING([[whether target W32 version is specified by precompiler defines]])
  482. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  483. /* Note: check logic is reversed for easy log reading */
  484. #ifdef WINVER
  485. #error WINVER is defined
  486. choke me now;
  487. #endif
  488. #ifdef _WIN32_WINNT
  489. #error _WIN32_WINNT is defined
  490. choke me now;
  491. #endif
  492. #ifdef NTDDI
  493. #error NTDDI is defined
  494. choke me now;
  495. #endif
  496. ]],[[(void)0]])
  497. ], [[mhd_w32_ver_preselect=no]], [[mhd_w32_ver_preselect=yes]]
  498. )
  499. AC_MSG_RESULT([[${mhd_w32_ver_preselect}]])
  500. AC_CHECK_HEADERS([windows.h sdkddkver.h], [], [], [AC_INCLUDES_DEFAULT])
  501. AS_VAR_IF([mhd_w32_ver_preselect],["yes"],
  502. [
  503. AC_MSG_CHECKING([[for specified target W32 version]])
  504. AS_UNSET([[mhd_w32_ver]])
  505. AS_UNSET([[mhd_w32_ver_msg]])
  506. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  507. #if _WIN32_WINNT+0 < 0x0501
  508. /* Check before headers inclusion */
  509. #error _WIN32_WINNT is less than 0x0501
  510. choke me now;
  511. #endif
  512. #ifdef HAVE_SDKDDKVER_H
  513. #include <sdkddkver.h>
  514. #endif
  515. #ifdef HAVE_WINDOWS_H
  516. #include <windows.h>
  517. #endif
  518. #if _WIN32_WINNT+0 < 0x0501
  519. #error _WIN32_WINNT is less than 0x0501
  520. choke me now;
  521. #endif
  522. ]],[[(void)0]])
  523. ], [], [
  524. AC_MSG_RESULT([[pre-WinXP]])
  525. AC_MSG_ERROR([[libmicrohttpd cannot be compiled for Windows version before Windows XP]])
  526. ]
  527. )
  528. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  529. #ifdef HAVE_SDKDDKVER_H
  530. #include <sdkddkver.h>
  531. #endif
  532. #ifdef HAVE_WINDOWS_H
  533. #include <windows.h>
  534. #endif
  535. #if _WIN32_WINNT+0 == 0x0501
  536. #error _WIN32_WINNT is 0x0501
  537. choke me now;
  538. #endif
  539. #if _WIN32_WINNT+0 == 0x0502
  540. #error _WIN32_WINNT is 0x0502
  541. choke me now;
  542. #endif
  543. ]],[[(void)0]])
  544. ], [], [
  545. mhd_w32_ver="WinXP"
  546. mhd_w32_ver_msg="WinXP (selected by precompiler flags)"
  547. ]
  548. )
  549. AS_VAR_SET_IF([mhd_w32_ver], [],
  550. [
  551. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  552. #ifdef HAVE_SDKDDKVER_H
  553. #include <sdkddkver.h>
  554. #endif
  555. #ifdef HAVE_WINDOWS_H
  556. #include <windows.h>
  557. #endif
  558. #if _WIN32_WINNT+0 < 0x0600
  559. #error _WIN32_WINNT is less than 0x0600 but greater than 0x0502
  560. choke me now;
  561. #endif
  562. ]],[[(void)0]])
  563. ], [], [
  564. AC_MSG_ERROR([[_WIN32_WINNT value is wrong (less than 0x0600 but greater than 0x0502)]])
  565. ]
  566. )
  567. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  568. #ifdef HAVE_SDKDDKVER_H
  569. #include <sdkddkver.h>
  570. #endif
  571. #ifdef HAVE_WINDOWS_H
  572. #include <windows.h>
  573. #endif
  574. #if _WIN32_WINNT+0 == 0x0600
  575. #error _WIN32_WINNT is 0x0600
  576. choke me now;
  577. #endif
  578. ]],[[(void)0]])
  579. ], [], [
  580. mhd_w32_ver="Vista"
  581. mhd_w32_ver_msg="Vista (selected by precompiler flags)"
  582. ]
  583. )
  584. ]
  585. )
  586. AS_VAR_SET_IF([mhd_w32_ver], [],
  587. [
  588. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  589. #ifdef HAVE_SDKDDKVER_H
  590. #include <sdkddkver.h>
  591. #endif
  592. #ifdef HAVE_WINDOWS_H
  593. #include <windows.h>
  594. #endif
  595. #if _WIN32_WINNT+0 > 0x0600
  596. #error _WIN32_WINNT is greater than 0x0600
  597. choke me now;
  598. #endif
  599. ]],[[(void)0]])
  600. ], [
  601. mhd_w32_ver="unknown"
  602. mhd_w32_ver_msg="unknown (cannot be detected)"
  603. ], [
  604. mhd_w32_ver="newer than Vista"
  605. mhd_w32_ver_msg="newer than Vista (selected by precompiler flags)"
  606. ]
  607. )
  608. ]
  609. )
  610. AC_MSG_RESULT([[${mhd_w32_ver}]])
  611. ], [
  612. mhd_w32_ver="Vista"
  613. mhd_w32_ver_msg="Vista (default, override by CPPFLAGS=-D_WIN32_WINNT=0xNNNN)"
  614. CPPFLAGS="$CPPFLAGS -D_WIN32_WINNT=0x0600"
  615. AC_MSG_CHECKING([[whether headers accept _WIN32_WINNT=0x0600]])
  616. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  617. #ifdef HAVE_SDKDDKVER_H
  618. #include <sdkddkver.h>
  619. #endif
  620. #ifdef HAVE_WINDOWS_H
  621. #include <windows.h>
  622. #endif
  623. #include <stdio.h>
  624. ]],[[(void)0]])
  625. ], [
  626. AC_MSG_RESULT([[yes]])
  627. ], [
  628. AC_MSG_RESULT([[no]])
  629. AC_MSG_ERROR([Headers do not accept _WIN32_WINNT=0x0600. Consider override target W32 version by CPPFLAGS=-D_WIN32_WINNT=0xNNNN])
  630. ]
  631. )
  632. ]
  633. )
  634. ]
  635. )
  636. AS_IF([test "x${os_is_windows}" = "xyes" && test "x${os_is_native_w32}" = "xyes"],
  637. [
  638. AC_CACHE_CHECK([W32 run-time library type], [mhd_cv_wctr_type],
  639. [
  640. AC_EGREP_CPP([MHDMARKER: UCRT run-time library in use!], [
  641. #include <stdio.h>
  642. #if defined(_UCRT)
  643. #define CRT_STR "MHDMARKER: UCRT run-time library in use!"
  644. #endif
  645. #if defined(__MSVCRT_VERSION__)
  646. #if (__MSVCRT_VERSION__ >= 0xE00) && (__MSVCRT_VERSION__ < 0x1000)
  647. #define CRT_STR "MHDMARKER: UCRT run-time library in use!"
  648. #endif
  649. #if (__MSVCRT_VERSION__ > 0x1400)
  650. #define CRT_STR "MHDMARKER: UCRT run-time library in use!"
  651. #endif
  652. #endif
  653. #ifndef CRT_STR
  654. #define CRT_STR "MHDMARKER: MSVCRT run-time library in use!"
  655. #endif
  656. int main(void)
  657. {
  658. printf ("%\n", CRT_STR);
  659. return 0;
  660. }
  661. ],
  662. [mhd_cv_wctr_type="ucrt"], [mhd_cv_wctr_type="msvcrt"])
  663. ]
  664. )
  665. mhd_host_os="${mhd_host_os}-${mhd_cv_wctr_type}"
  666. AS_VAR_IF([mhd_cv_wctr_type], ["msvcrt"],
  667. [
  668. AX_APPEND_COMPILE_FLAGS([-U__USE_MINGW_ANSI_STDIO -D__USE_MINGW_ANSI_STDIO=0], [CPPFLAGS])
  669. AC_SUBST([W32CRT], [MSVCRT])
  670. ], [AC_SUBST([W32CRT], [UCRT])]
  671. )
  672. ]
  673. )
  674. AC_ARG_WITH([threads],
  675. [AS_HELP_STRING([--with-threads=LIB],[choose threading library (posix, w32, auto, none) [auto]])],
  676. [], [with_threads='auto'])
  677. AS_CASE([[$with_threads]],
  678. [[win32]], [[with_threads='w32']],
  679. [[pthreads]], [[with_threads='posix']],
  680. [[posix]], [[:]],
  681. [[w32]], [[:]],
  682. [[none]], [[with_threads='none']],
  683. [[no]], [[with_threads='none']],
  684. [[auto]], [[:]],
  685. [AC_MSG_ERROR([[incorrect parameter "$with_threads" specified for --with-threads]])]
  686. )
  687. # Check for posix threads support, regardless of configure parameters as
  688. # testsuite uses only posix threads.
  689. AX_PTHREAD(
  690. [
  691. mhd_have_posix_threads='yes'
  692. AC_DEFINE([[HAVE_PTHREAD_H]],[[1]],[Define to 1 if you have the <pthread.h> header file.])
  693. AC_CACHE_CHECK([[whether pthread_sigmask(3) is available]],
  694. [[mhd_cv_func_pthread_sigmask]], [dnl
  695. save_LIBS="$LIBS"
  696. save_CFLAGS="$CFLAGS"
  697. LIBS="$PTHREAD_LIBS $LIBS"
  698. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  699. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <signal.h>]],
  700. [[
  701. sigset_t nset, oset;
  702. sigemptyset (&nset);
  703. sigaddset (&nset, SIGPIPE);
  704. if (0 != pthread_sigmask(SIG_BLOCK, &nset, &oset)) return 1;
  705. ]])],
  706. [[mhd_cv_func_pthread_sigmask="yes"]],[[mhd_cv_func_pthread_sigmask="no"]])
  707. LIBS="${save_LIBS}"
  708. CFLAGS="${save_CFLAGS}"
  709. ])
  710. AS_VAR_IF([mhd_cv_func_pthread_sigmask],["yes"],
  711. [AC_DEFINE([[HAVE_PTHREAD_SIGMASK]],[[1]],[Define to 1 if you have the pthread_sigmask(3) function.])])
  712. ],[[mhd_have_posix_threads='no']])
  713. AM_CONDITIONAL([HAVE_POSIX_THREADS],[test "x$mhd_have_posix_threads" = "xyes"])
  714. mhd_have_w32_threads='no'
  715. AS_IF([[test "x$with_threads" = "xauto"]],
  716. [
  717. AS_IF([[test "x$os_is_windows" = "xyes"]],
  718. [
  719. AC_MSG_CHECKING([[for W32 threads]])
  720. AC_LINK_IFELSE(
  721. [AC_LANG_PROGRAM([[
  722. #include <windows.h>
  723. ]], [ HANDLE h = CreateThread(NULL, 0, NULL, NULL, 0, NULL);])]
  724. , [[mhd_have_w32_threads='yes']], [[mhd_have_w32_threads='no']]
  725. )
  726. AC_MSG_RESULT([[$mhd_have_w32_threads]])
  727. ])
  728. ]
  729. )
  730. AC_MSG_CHECKING([[for threading lib to use with libmicrohttpd ($with_threads)]])
  731. AS_IF([test "x$with_threads" = "xposix"],
  732. [ # forced posix threads
  733. AS_IF([test "x$mhd_have_posix_threads" = "xyes"], [USE_THREADS='posix'],
  734. [ AS_IF([[test "x$os_is_windows" = "xyes"]] ,
  735. [ AC_MSG_ERROR([[Posix threads are not available. Try to configure --with-threads=auto]])],
  736. [ AC_MSG_ERROR([[No threading lib is available. Consider installing pthreads]])] )
  737. ])
  738. ])
  739. AS_IF([test "x$with_threads" = "xw32"],
  740. [ # forced w32 threads
  741. AS_IF([[test "x$mhd_have_w32_threads" = "xyes"]],
  742. [[ USE_THREADS='w32' ]],
  743. [ AC_MSG_ERROR([[W32 threads are not available. Try to configure --with-threads=auto]])])
  744. ])
  745. AS_IF([test "x$with_threads" = "xauto"],
  746. [# automatic threads lib selection
  747. AS_IF([[test "x$os_is_native_w32" = "xyes" && test "x$mhd_have_w32_threads" = "xyes"]] ,
  748. [[ USE_THREADS='w32' ]] ,
  749. [[ test "x$mhd_have_posix_threads" = "xyes" ]], [[ USE_THREADS='posix' ]],
  750. [[ test "x$mhd_have_w32_threads" = "xyes" ]], [[ USE_THREADS='w32' ]],
  751. [ AC_MSG_ERROR([[No threading lib is available. Consider installing pthreads]]) ]
  752. )])
  753. AS_IF([test "x$with_threads" = "xnone"],
  754. [USE_THREADS='none'])
  755. AS_IF([test "x$USE_THREADS" = "xposix"],
  756. [CC="$PTHREAD_CC"
  757. AC_DEFINE([MHD_USE_POSIX_THREADS],[1],[define to use pthreads])
  758. MHD_LIB_CFLAGS="$MHD_LIB_CFLAGS $PTHREAD_CFLAGS"
  759. MHD_LIBDEPS="$PTHREAD_LIBS $MHD_LIBDEPS"
  760. MHD_LIBDEPS_PKGCFG="$PTHREAD_LIBS $MHD_LIBDEPS_PKGCFG"],
  761. [AS_IF([test "x$USE_THREADS" = "xw32"],
  762. [AC_DEFINE([MHD_USE_W32_THREADS],[1],[define to use W32 threads])])])
  763. AM_CONDITIONAL([USE_POSIX_THREADS], [test "x$USE_THREADS" = "xposix"])
  764. AM_CONDITIONAL([USE_W32_THREADS], [test "x$USE_THREADS" = "xw32"])
  765. AM_CONDITIONAL([USE_THREADS], [test "x$USE_THREADS" != "xnone"])
  766. AM_CONDITIONAL([DISABLE_THREADS], [test "x$USE_THREADS" = "xnone"])
  767. AC_MSG_RESULT([$USE_THREADS])
  768. AC_ARG_ENABLE([[thread-names]],
  769. [AS_HELP_STRING([--disable-thread-names],[do not set names on MHD generated threads [auto]])],
  770. [], [enable_thread_names='auto'])
  771. AS_IF([test "x$enable_thread_names" != "xno" && test "x$USE_THREADS" = "xposix"],[
  772. # Check for thread name function
  773. HAVE_THREAD_NAME_FUNC="no"
  774. SAVE_LIBS="$LIBS"
  775. SAVE_CFLAGS="$CFLAGS"
  776. LIBS="$PTHREAD_LIBS $LIBS"
  777. CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
  778. AC_CHECK_HEADERS([pthread_np.h],[],[],
  779. [
  780. AC_INCLUDES_DEFAULT
  781. [
  782. #include <pthread.h>
  783. ]
  784. ])
  785. # Try to find how to set thread name by thread attributes.
  786. # If pthread_attr_setname_np(3) is not declared, it's not possible to detect
  787. # form of pthread_attr_setname_np(3) due to C "feature" "implicit declaration".
  788. AC_CHECK_DECL([[pthread_attr_setname_np]],[],[],[[
  789. #include <pthread.h>
  790. #ifdef HAVE_PTHREAD_NP_H
  791. #include <pthread_np.h>
  792. #endif
  793. ]])
  794. AS_IF([[test "x$ac_cv_have_decl_pthread_attr_setname_np" = "xyes"]],
  795. [AC_MSG_CHECKING([[for pthread_attr_setname_np(3) in NetBSD or OSF1 form]])
  796. AC_LINK_IFELSE(
  797. [AC_LANG_PROGRAM([[
  798. #include <pthread.h>
  799. #ifdef HAVE_PTHREAD_NP_H
  800. #include <pthread_np.h>
  801. #endif
  802. ]], [[
  803. pthread_attr_t thr_attr;
  804. pthread_attr_init(&thr_attr);
  805. pthread_attr_setname_np(&thr_attr, "name", 0);
  806. pthread_attr_destroy(&thr_attr);
  807. ]])],
  808. [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.])
  809. HAVE_THREAD_NAME_FUNC="yes"
  810. AC_MSG_RESULT([[yes]])],
  811. [AC_MSG_RESULT([[no]])]
  812. )
  813. ])
  814. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_attr_setname_np" = "xyes"]],
  815. [AC_MSG_CHECKING([[for pthread_attr_setname_np(3) in IBM i or Solaris form]])
  816. AC_LINK_IFELSE(
  817. [AC_LANG_PROGRAM([[
  818. #include <pthread.h>
  819. #ifdef HAVE_PTHREAD_NP_H
  820. #include <pthread_np.h>
  821. #endif
  822. ]], [[
  823. pthread_attr_t thr_attr;
  824. pthread_attr_init(&thr_attr);
  825. pthread_attr_setname_np(&thr_attr, "name");
  826. pthread_attr_destroy(&thr_attr);
  827. ]])],
  828. [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.])
  829. HAVE_THREAD_NAME_FUNC="yes"
  830. AC_MSG_RESULT([[yes]])],
  831. [AC_MSG_RESULT([[no]])]
  832. )
  833. ])
  834. # Try to find how to set thread name for started thread - less convenient
  835. # than setting name by attributes.
  836. # If pthread_setname_np(3) is not declared, it's not possible to detect
  837. # form of pthread_setname_np(3) due to C "feature" "implicit declaration".
  838. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes"]],
  839. [AC_CHECK_DECL([[pthread_setname_np]],[],[],[[
  840. #include <pthread.h>
  841. #ifdef HAVE_PTHREAD_NP_H
  842. #include <pthread_np.h>
  843. #endif
  844. ]])
  845. ])
  846. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]],
  847. [AC_MSG_CHECKING([[for pthread_setname_np(3) in NetBSD or OSF1 form]])
  848. AC_LINK_IFELSE(
  849. [AC_LANG_PROGRAM([[
  850. #include <pthread.h>
  851. #ifdef HAVE_PTHREAD_NP_H
  852. #include <pthread_np.h>
  853. #endif
  854. ]], [[int res = pthread_setname_np(pthread_self(), "name", 0); if (res) return res;]])],
  855. [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_NETBSD]], [[1]], [Define if you have NetBSD form (or OSF1 form) of pthread_setname_np(3) function.])
  856. HAVE_THREAD_NAME_FUNC="yes"
  857. AC_MSG_RESULT([[yes]])],
  858. [AC_MSG_RESULT([[no]])]
  859. )
  860. ])
  861. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]],
  862. [AC_MSG_CHECKING([[for pthread_setname_np(3) in GNU/Linux form]])
  863. AC_LINK_IFELSE(
  864. [AC_LANG_PROGRAM([[
  865. #include <pthread.h>
  866. #ifdef HAVE_PTHREAD_NP_H
  867. #include <pthread_np.h>
  868. #endif
  869. ]], [[int res = pthread_setname_np(pthread_self(), "name"); if (res) return res;]])],
  870. [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_GNU]], [[1]], [Define if you have GNU/Linux form of pthread_setname_np(3) function.])
  871. HAVE_THREAD_NAME_FUNC="yes"
  872. AC_MSG_RESULT([[yes]])],
  873. [AC_MSG_RESULT([[no]])]
  874. )
  875. ])
  876. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes" && test "x$ac_cv_have_decl_pthread_setname_np" = "xyes"]],
  877. [AC_MSG_CHECKING([[for pthread_setname_np(3) in Darwin form]])
  878. AC_LINK_IFELSE(
  879. [AC_LANG_PROGRAM([[
  880. #include <pthread.h>
  881. #ifdef HAVE_PTHREAD_NP_H
  882. #include <pthread_np.h>
  883. #endif
  884. ]], [[int res = pthread_setname_np("name"); if (res) return res;]])],
  885. [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_DARWIN]], [[1]], [Define if you have Darwin form of pthread_setname_np(3) function.])
  886. HAVE_THREAD_NAME_FUNC="yes"
  887. AC_MSG_RESULT([[yes]])],
  888. [AC_MSG_RESULT([[no]])]
  889. )
  890. ])
  891. AS_IF([[test "x$HAVE_THREAD_NAME_FUNC" != "xyes"]],
  892. [
  893. AC_CHECK_DECL([[pthread_set_name_np]],
  894. [
  895. AC_MSG_CHECKING([[for pthread_set_name_np(3) in FreeBSD form]])
  896. AC_LINK_IFELSE(
  897. [AC_LANG_PROGRAM([[
  898. #include <pthread.h>
  899. #ifdef HAVE_PTHREAD_NP_H
  900. #include <pthread_np.h>
  901. #endif
  902. ]], [[pthread_set_name_np(pthread_self(), "name");]])],
  903. [AC_DEFINE([[HAVE_PTHREAD_SET_NAME_NP_FREEBSD]], [[1]], [Define if you have FreeBSD form of pthread_set_name_np(3) function.])
  904. HAVE_THREAD_NAME_FUNC="yes"
  905. AC_MSG_RESULT([[yes]])],
  906. [AC_MSG_RESULT([[no]])]
  907. )
  908. ],[],[[
  909. #include <pthread.h>
  910. #ifdef HAVE_PTHREAD_NP_H
  911. #include <pthread_np.h>
  912. #endif
  913. ]]
  914. )
  915. ])
  916. LIBS="$SAVE_LIBS"
  917. CFLAGS="$SAVE_CFLAGS"
  918. ])
  919. AS_IF([[test "x$enable_thread_names" != "xno"]],
  920. [
  921. AC_MSG_CHECKING([[whether to enable thread names]])
  922. AC_COMPILE_IFELSE(
  923. [AC_LANG_PROGRAM([], [[
  924. #ifdef MHD_NO_THREAD_NAMES
  925. #error Thread names are disabled.
  926. choke me
  927. #endif
  928. /* Keep in sync with mhd_threads.h */
  929. #if defined(MHD_USE_POSIX_THREADS) && (defined(HAVE_PTHREAD_ATTR_SETNAME_NP_NETBSD) || defined(HAVE_PTHREAD_ATTR_SETNAME_NP_IBMI) || \
  930. defined(HAVE_PTHREAD_SETNAME_NP_GNU) || defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) || defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || \
  931. defined(HAVE_PTHREAD_SETNAME_NP_NETBSD) )
  932. (void) 0; /* no-op */
  933. #elif defined(MHD_USE_W32_THREADS) && defined(_MSC_FULL_VER)
  934. (void) 0; /* no-op */
  935. #else
  936. #error No thread name function is available.
  937. choke me
  938. #endif
  939. ]])
  940. ], [
  941. enable_thread_names='yes'
  942. ], [
  943. AS_IF([[test "x$enable_thread_names" = "xyes"]],
  944. [
  945. AC_MSG_RESULT([[no]])
  946. AC_MSG_ERROR([[thread names was explicitly requested, but thread name function is not available]])
  947. ])
  948. enable_thread_names='no'
  949. ])
  950. AC_MSG_RESULT([[$enable_thread_names]])
  951. ])
  952. AS_IF([[test "x$enable_thread_names" = "xno"]],
  953. [AC_DEFINE([[MHD_NO_THREAD_NAMES]], [[1]], [Define to 1 to disable setting name on generated threads])])
  954. AM_CONDITIONAL(HAVE_W32, [test "x$os_is_native_w32" = "xyes"])
  955. w32_shared_lib_exp=no
  956. AS_IF([test "x$enable_shared" = "xyes" && test "x$os_is_native_w32" = "xyes"],
  957. [
  958. AS_IF([test "x$ac_cv_use_ms_lib_tool" = "xyes" || test -n "$DLLTOOL"],
  959. [
  960. w32_shared_lib_exp=yes
  961. use_expfile="no"
  962. AS_VAR_IF([ac_cv_use_ms_lib_tool], ["yes"], [use_expfile="yes"],
  963. [
  964. AC_CACHE_CHECK([whether $DLLTOOL supports export file generation], [mhd_cv_dlltool_expfile],
  965. [
  966. AS_IF([AC_RUN_LOG([$DLLTOOL -e conftest.exp >&2 ])],
  967. [
  968. AS_IF([test -f conftest.exp], [mhd_cv_dlltool_expfile="yes"], [mhd_cv_dlltool_expfile="no"])
  969. ], [mhd_cv_dlltool_expfile="no"]
  970. )
  971. rm -f conftest.exp
  972. ]
  973. )
  974. use_expfile="${mhd_cv_dlltool_expfile}"
  975. ]
  976. )
  977. ],
  978. [
  979. AC_MSG_WARN([[GNU dlltool or MS lib.exe is required for creating shared library export on W32]])
  980. AC_MSG_WARN([[Export library libmicrohttpd.lib will not be created]])
  981. ]
  982. )
  983. ]
  984. )
  985. AM_CONDITIONAL([W32_SHARED_LIB_EXP], [test "x$w32_shared_lib_exp" = "xyes"])
  986. AM_CONDITIONAL([USE_MS_LIB_TOOL], [test "x$ac_cv_use_ms_lib_tool" = "xyes"])
  987. AM_CONDITIONAL([USE_EXPORT_FILE], [test "x$use_expfile" = "xyes"])
  988. MHD_CHECK_SOCKET_SHUTDOWN_TRIGGER([AC_DEFINE([HAVE_LISTEN_SHUTDOWN],[1],[can use shutdown on listen sockets])])
  989. AM_CONDITIONAL([HAVE_LISTEN_SHUTDOWN], [test "x$mhd_cv_host_shtdwn_trgr_select" = "xyes"])
  990. # SENDMSG. Should we check for SCM_RIGHTS instead?
  991. # https://lists.x.org/archives/xorg-devel/2013-November/038687.html
  992. AC_SEARCH_LIBS([sendmsg], [socket], [AC_DEFINE([HAVE_SENDMSG],[1],[Define if your platform supports sendmsg])])
  993. AC_CHECK_FUNCS([writev])
  994. # set GCC options
  995. # use '-fno-strict-aliasing', but only if the compiler
  996. # and linker can take it
  997. AX_CHECK_LINK_FLAG([-fno-strict-aliasing],
  998. [AX_APPEND_COMPILE_FLAGS([-fno-strict-aliasing])])
  999. AC_C_BIGENDIAN
  1000. AC_C_VARARRAYS
  1001. AC_CACHE_CHECK([[whether __func__ magic-macro is available]],
  1002. [[mhd_cv_macro___func___avail]], [dnl
  1003. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>]],[[const char *funcname = __func__ ; if (NULL == funcname) return 1;]])],
  1004. [[mhd_cv_macro___func___avail="yes"]],[[mhd_cv_macro___func___avail="no"]])
  1005. ])
  1006. AS_VAR_IF([mhd_cv_macro___func___avail], ["yes"],
  1007. [AC_DEFINE([HAVE___FUNC__], [1], [Define to 1 if your compiler supports __func__ magic-macro.])],
  1008. [
  1009. AC_CACHE_CHECK([[whether __FUNCTION__ magic-macro is available]],
  1010. [[mhd_cv_macro___function___avail]], [dnl
  1011. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stddef.h>]],[[const char *funcname = __FUNCTION__ ; if (NULL == funcname) return 1;]])],
  1012. [[mhd_cv_macro___function___avail="yes"]],[[mhd_cv_macro___function___avail="no"]])
  1013. ])
  1014. AC_DEFINE([HAVE___FUNCTION__], [1], [Define to 1 if your compiler supports __FUNCTION__ magic-macro.])
  1015. ]
  1016. )
  1017. AC_CACHE_CHECK([[whether __builtin_bswap32() is available]],
  1018. [[mhd_cv_func___builtin_bswap32_avail]], [dnl
  1019. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint32_t a = 1; uint32_t b = __builtin_bswap32(a); a = b;]])],
  1020. [[mhd_cv_func___builtin_bswap32_avail="yes"]],[[mhd_cv_func___builtin_bswap32_avail="no"]])
  1021. ])
  1022. AS_IF([[test "x$mhd_cv_func___builtin_bswap32_avail" = "xyes"]],
  1023. [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP32]], [[1]], [Define to 1 if you have __builtin_bswap32() builtin function])])
  1024. AC_CACHE_CHECK([[whether __builtin_bswap64() is available]],
  1025. [[mhd_cv_func___builtin_bswap64_avail]], [dnl
  1026. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include<stdint.h>]], [[uint64_t a = 1; uint32_t b = __builtin_bswap64(a); a = b;]])],
  1027. [[mhd_cv_func___builtin_bswap64_avail="yes"]], [[mhd_cv_func___builtin_bswap64_avail="no"]])
  1028. ])
  1029. AS_IF([[test "x$mhd_cv_func___builtin_bswap64_avail" = "xyes"]],
  1030. [AC_DEFINE([[MHD_HAVE___BUILTIN_BSWAP64]], [[1]], [Define to 1 if you have __builtin_bswap64() builtin function])])
  1031. AC_CHECK_PROG([HAVE_CURL_BINARY],[curl],[yes],[no])
  1032. AM_CONDITIONAL([HAVE_CURL_BINARY],[test "x$HAVE_CURL_BINARY" = "xyes"])
  1033. AC_CHECK_PROG([HAVE_MAKEINFO_BINARY],[makeinfo],[yes],[no])
  1034. AM_CONDITIONAL([HAVE_MAKEINFO_BINARY],[test "x$HAVE_MAKEINFO_BINARY" = "xyes"])
  1035. AM_CONDITIONAL(W32_STATIC_LIB, [test "x$os_is_native_w32" = "xyes" && test "x$enable_static" = "xyes"])
  1036. AC_ARG_ENABLE([[doc]],
  1037. [AS_HELP_STRING([[--disable-doc]], [do not build any documentation])], ,
  1038. [enable_doc=yes])
  1039. test "x$enable_doc" = "xno" || enable_doc=yes
  1040. AM_CONDITIONAL([BUILD_DOC], [test "x$enable_doc" = "xyes"])
  1041. AC_ARG_ENABLE([[examples]],
  1042. [AS_HELP_STRING([[--disable-examples]], [do not build any examples])], ,
  1043. [enable_examples=yes])
  1044. test "x$enable_examples" = "xno" || enable_examples=yes
  1045. AM_CONDITIONAL([BUILD_EXAMPLES], [test "x$enable_examples" = "xyes"])
  1046. AC_ARG_ENABLE([[heavy-tests]],
  1047. [AS_HELP_STRING([[--enable-heavy-tests]], [use heavy tests in test-suite. WARNING:]
  1048. [a dedicated host with minimal number of background processes and no network]
  1049. [activity is recommended to enable.])], [],
  1050. [enable_heavy_tests=no])
  1051. AS_VAR_IF([enable_heavy_tests], ["yes"],
  1052. [
  1053. HEAVY_TESTS_NOTPARALLEL='.NOTPARALLEL:'
  1054. AC_DEFINE([_MHD_HEAVY_TESTS], [1], [Define to 1 to enable "heavy" test paths.])
  1055. ],
  1056. [
  1057. enable_heavy_tests=no
  1058. HEAVY_TESTS_NOTPARALLEL=" "
  1059. ]
  1060. )
  1061. AM_CONDITIONAL([HEAVY_TESTS],[test "x$enable_heavy_tests" = "xyes"])
  1062. AC_ARG_ENABLE([[poll]],
  1063. [AS_HELP_STRING([[--enable-poll[=ARG]]], [enable poll support (yes, no, auto) [auto]])],
  1064. [enable_poll=${enableval}],
  1065. [enable_poll='auto']
  1066. )
  1067. AS_IF([test "$enable_poll" != "no"],
  1068. [AS_IF([test "$os_is_native_w32" != "yes"],
  1069. AC_CHECK_HEADERS([poll.h],
  1070. [AC_CHECK_FUNCS([poll], [have_poll='yes'], [have_poll='no'])],
  1071. [],
  1072. [AC_INCLUDES_DEFAULT]),
  1073. [AC_MSG_CHECKING([for WSAPoll()])
  1074. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  1075. #include <winsock2.h>
  1076. ]],[[
  1077. WSAPOLLFD fda[2];
  1078. WSAPoll(fda, 2, 0);]])],
  1079. [have_poll='yes'
  1080. AC_DEFINE([HAVE_POLL],[1])
  1081. ],[have_poll='no'])
  1082. AC_MSG_RESULT([$have_poll])])
  1083. AS_IF([test "$enable_poll" = "yes" && test "$have_poll" != "yes"],
  1084. [AC_MSG_ERROR([[Support for poll was explicitly requested but cannot be enabled on this platform.]])])
  1085. enable_poll="$have_poll"])
  1086. AC_ARG_ENABLE([[epoll]],
  1087. [AS_HELP_STRING([[--enable-epoll[=ARG]]], [enable epoll support (yes, no, auto) [auto]])],
  1088. [enable_epoll=${enableval}],
  1089. [enable_epoll='auto']
  1090. )
  1091. AS_IF([test "$enable_epoll" != "no"],
  1092. [
  1093. AX_HAVE_EPOLL
  1094. AS_IF([test "${ax_cv_have_epoll}" = "yes"],
  1095. [
  1096. AC_DEFINE([[EPOLL_SUPPORT]],[[1]],[Define to 1 to enable epoll support])
  1097. enable_epoll='yes'
  1098. ],
  1099. [
  1100. AS_IF([test "$enable_epoll" = "yes"],
  1101. [AC_MSG_ERROR([[Support for epoll was explicitly requested but cannot be enabled on this platform.]])]
  1102. )
  1103. enable_epoll='no'
  1104. ]
  1105. )
  1106. ]
  1107. )
  1108. AM_CONDITIONAL([MHD_HAVE_EPOLL], [[test "x$enable_epoll" = xyes]])
  1109. AS_IF([test "x$enable_epoll" = "xyes"],
  1110. AC_CACHE_CHECK([for epoll_create1()],
  1111. [mhd_cv_have_epoll_create1], [
  1112. AC_LINK_IFELSE([
  1113. AC_LANG_PROGRAM([[
  1114. #include <sys/epoll.h>
  1115. ]], [[
  1116. int fd;
  1117. fd = epoll_create1(EPOLL_CLOEXEC);]])],
  1118. [mhd_cv_have_epoll_create1=yes],
  1119. [mhd_cv_have_epoll_create1=no])])
  1120. AS_IF([test "x$mhd_cv_have_epoll_create1" = "xyes"],[
  1121. AC_DEFINE([[HAVE_EPOLL_CREATE1]], [[1]], [Define if you have epoll_create1 function.])]))
  1122. AC_CACHE_CHECK([for suported 'noreturn' keyword], [mhd_cv_decl_noreturn],
  1123. [
  1124. mhd_cv_decl_noreturn="none"
  1125. save_CFLAGS="${CFLAGS}"
  1126. CFLAGS="${CFLAGS} ${errattr_CFLAGS}"
  1127. for decl_noret in '_Noreturn' '__attribute__((__noreturn__))' '__declspec(noreturn)'
  1128. do
  1129. AC_LINK_IFELSE([AC_LANG_SOURCE(
  1130. [[
  1131. #ifdef HAVE_STDLIB_H
  1132. #include <stdlib.h>
  1133. #endif
  1134. ${decl_noret} void myexitfunc(int code)
  1135. {
  1136. #ifdef HAVE_STDLIB_H
  1137. exit (code);
  1138. #else
  1139. (void)code;
  1140. #endif
  1141. }
  1142. int main (int argc, char *const *argv)
  1143. {
  1144. (void) argv;
  1145. if (argc > 2)
  1146. myexitfunc (2);
  1147. return 0;
  1148. }
  1149. ]]
  1150. )], [mhd_cv_decl_noreturn="${decl_noret}"]
  1151. )
  1152. AS_IF([test "x${mhd_cv_decl_noreturn}" != "xnone"], [break])
  1153. done
  1154. CFLAGS="${save_CFLAGS}"
  1155. ]
  1156. )
  1157. AS_VAR_IF([mhd_cv_decl_noreturn], ["none"],
  1158. [AC_DEFINE([_MHD_NORETURN], [], [Define to supported 'noreturn' function declaration])],
  1159. [AC_DEFINE_UNQUOTED([_MHD_NORETURN], [${mhd_cv_decl_noreturn}], [Define to supported 'noreturn' function declaration])]
  1160. )
  1161. # Check for types sizes
  1162. # Types sizes are used as an indirect indication of maximum allowed values for types
  1163. # which is used to exclude by preprocessor some compiler checks for values clips
  1164. # Assuming no staffing or uniform staffing for integer types
  1165. AC_CACHE_CHECK([size of tv_sec member of struct timeval], [mhd_cv_size_timeval_tv_sec],
  1166. [
  1167. AC_COMPUTE_INT([mhd_cv_size_timeval_tv_sec], [((long int)sizeof(test_var.tv_sec))],
  1168. [[
  1169. #ifdef HAVE_SYS_TIME_H
  1170. #include <sys/time.h>
  1171. #endif /* HAVE_SYS_TIME_H */
  1172. #ifdef HAVE_TIME_H
  1173. #include <time.h>
  1174. #endif /* HAVE_TIME_H */
  1175. #if HAVE_SYS_TYPES_H
  1176. #include <sys/types.h>
  1177. #endif /* HAVE_SYS_TYPES_H */
  1178. struct timeval test_var;
  1179. ]],
  1180. [
  1181. # The size is used only to exclude additional checks/comparison in code
  1182. # to avoid compiler warnings. With larger size MHD code will use
  1183. # additional checks which ensure that value will fit but it may produce
  1184. # a harmless compiler warning.
  1185. AC_MSG_WARN([The size cannot be determined, assuming 8.])
  1186. mhd_cv_size_timeval_tv_sec=8
  1187. ]
  1188. )
  1189. ]
  1190. )
  1191. AC_DEFINE_UNQUOTED([SIZEOF_STRUCT_TIMEVAL_TV_SEC], [$mhd_cv_size_timeval_tv_sec],
  1192. [The size of `tv_sec' member of `struct timeval', as computed by sizeof])
  1193. AC_CHECK_SIZEOF([uint64_t], [], [[#include <stdint.h>]])
  1194. AC_CHECK_SIZEOF([unsigned int], [], [[#include <stdint.h>]])
  1195. AC_CHECK_SIZEOF([size_t], [],
  1196. [[
  1197. #ifdef HAVE_STDLIB_H
  1198. #include <stdlib.h>
  1199. #endif /* HAVE_STDLIB_H */
  1200. #ifdef HAVE_STDDEF_H
  1201. #include <stddef.h>
  1202. #endif /* HAVE_STDDEF_H */
  1203. #include <stdio.h>
  1204. ]]
  1205. )
  1206. AC_CHECK_SIZEOF([unsigned long long], [], [[#include <stdint.h>]])
  1207. AC_CHECK_HEADERS([dlfcn.h],[have_tlsplugin=yes],[have_tlsplugin=no], [AC_INCLUDES_DEFAULT])
  1208. AM_CONDITIONAL([MHD_HAVE_TLS_PLUGIN], [[test "x$have_tlsplugin" = xyes]])
  1209. AC_CHECK_HEADERS([zlib.h],[have_zlib=yes],[have_zlib=no], [AC_INCLUDES_DEFAULT])
  1210. AM_CONDITIONAL([HAVE_ZLIB], [[test "x$have_zlib" = xyes]])
  1211. # Check for generic functions
  1212. MHD_CHECK_FUNC([random],
  1213. [
  1214. AC_INCLUDES_DEFAULT
  1215. [#include <stdlib.h>
  1216. ]],
  1217. [[long int r = random(); (void)r;]],
  1218. [],
  1219. [
  1220. MHD_CHECK_FUNC([rand],
  1221. [
  1222. AC_INCLUDES_DEFAULT
  1223. [#include <stdlib.h>
  1224. ]],
  1225. [[int r = rand(); (void)r;]],
  1226. )
  1227. ]
  1228. )
  1229. AC_CHECK_MEMBERS([struct sockaddr_in.sin_len, struct sockaddr_in6.sin6_len,
  1230. struct sockaddr_storage.ss_len],
  1231. [], [],
  1232. [
  1233. #ifdef HAVE_SYS_TYPES_H
  1234. #include <sys/types.h>
  1235. #endif
  1236. #ifdef HAVE_SYS_SOCKET_H
  1237. #include <sys/socket.h>
  1238. #endif
  1239. #ifdef HAVE_NETINET_IN_H
  1240. #include <netinet/in.h>
  1241. #endif
  1242. ])
  1243. MHD_CHECK_FUNC([getsockname],
  1244. [[
  1245. #ifdef HAVE_SYS_TYPES_H
  1246. #include <sys/types.h>
  1247. #endif
  1248. #ifdef HAVE_SYS_SOCKET_H
  1249. #include <sys/socket.h>
  1250. #endif
  1251. #ifdef HAVE_WINSOCK2_H
  1252. #include <winsock2.h>
  1253. #endif
  1254. ]],
  1255. [
  1256. struct sockaddr_storage ss;
  1257. (void)getsockname(socket(0,0,0),(struct sockaddr *)&ss,(void*)0);
  1258. ],
  1259. [
  1260. AC_CACHE_CHECK([[whether getsockname() is usable]], [[mhd_cv_getsockname_usable]],
  1261. [
  1262. AC_RUN_IFELSE(
  1263. [
  1264. AC_LANG_SOURCE(
  1265. [[
  1266. #ifdef HAVE_SYS_TYPES_H
  1267. #include <sys/types.h>
  1268. #endif
  1269. #ifdef HAVE_SYS_SOCKET_H
  1270. #include <sys/socket.h>
  1271. #endif
  1272. #ifdef HAVE_UNISTD_H
  1273. #include <unistd.h>
  1274. #endif
  1275. #ifdef HAVE_WINSOCK2_H
  1276. #include <winsock2.h>
  1277. #endif
  1278. #ifdef HAVE_WS2TCPIP_H
  1279. #include <ws2tcpip.h>
  1280. #endif
  1281. #ifdef HAVE_NETINET_IN_H
  1282. #include <netinet/in.h>
  1283. #endif
  1284. #ifdef HAVE_NETINET_IP_H
  1285. #include <netinet/ip.h>
  1286. #endif
  1287. #ifdef HAVE_ARPA_INET_H
  1288. #include <arpa/inet.h>
  1289. #endif
  1290. static void zr_mem(void *ptr, socklen_t size)
  1291. { char *mem = ptr; while(size--) {mem[0] = 0; mem++;} }
  1292. int main(void)
  1293. {
  1294. const socklen_t c_addr_size = (socklen_t)sizeof(struct sockaddr_in);
  1295. struct sockaddr_in sa;
  1296. socklen_t addr_size;
  1297. int ret = 1;
  1298. #if !defined(_WIN32) || defined(__CYGWIN__)
  1299. int sckt;
  1300. const int invld_sckt = -1;
  1301. #else
  1302. SOCKET sckt;
  1303. const SOCKET invld_sckt = INVALID_SOCKET;
  1304. WSADATA wsa_data;
  1305. if (0 != WSAStartup(MAKEWORD(2, 2), &wsa_data) || MAKEWORD(2, 2) != wsa_data.wVersion)
  1306. return 20;
  1307. #endif
  1308. sckt = socket (PF_INET, SOCK_STREAM, 0);
  1309. if (invld_sckt != sckt)
  1310. {
  1311. zr_mem(&sa, c_addr_size);
  1312. sa.sin_family = AF_INET;
  1313. #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
  1314. sa.sin_len = c_addr_size;
  1315. #endif
  1316. if (0 == bind (sckt, (struct sockaddr *)&sa, c_addr_size))
  1317. {
  1318. if (0 == listen (sckt, 1))
  1319. {
  1320. addr_size = c_addr_size;
  1321. if (0 == getsockname (sckt, (struct sockaddr *)&sa, &addr_size))
  1322. {
  1323. if (c_addr_size >= addr_size)
  1324. {
  1325. if (0 != ntohs(sa.sin_port))
  1326. { ret = 0;
  1327. } else ret = 7;
  1328. } else ret = 6;
  1329. } else ret = 5;
  1330. } else ret = 4;
  1331. } else ret = 3;
  1332. } else ret = 2;
  1333. #if !defined(_WIN32) || defined(__CYGWIN__)
  1334. close (sckt);
  1335. #else
  1336. closesocket (sckt);
  1337. WSACleanup();
  1338. #endif
  1339. return ret;
  1340. }
  1341. ]]
  1342. )
  1343. ],
  1344. [[mhd_cv_getsockname_usable='yes']],
  1345. [[mhd_cv_getsockname_usable='no']],
  1346. [[mhd_cv_getsockname_usable='assuming yes']]
  1347. )
  1348. ]
  1349. )
  1350. AS_VAR_IF([[mhd_cv_getsockname_usable]], [["no"]], [:],
  1351. [AC_DEFINE([[MHD_USE_GETSOCKNAME]], [[1]], [Define if you have usable `getsockname' function.])])
  1352. ]
  1353. )
  1354. AC_CACHE_CHECK([for usable PAGESIZE macro], [mhd_cv_macro_pagesize_usable],
  1355. [
  1356. AC_LINK_IFELSE(
  1357. [
  1358. AC_LANG_PROGRAM(
  1359. [[
  1360. #ifdef HAVE_UNISTD_H
  1361. #include <unistd.h>
  1362. #endif
  1363. #ifdef HAVE_LIMITS_H
  1364. #include <limits.h>
  1365. #endif
  1366. #ifdef HAVE_SYS_PARAM_H
  1367. #include <sys/param.h>
  1368. #endif
  1369. #ifndef PAGESIZE
  1370. #error No PAGESIZE macro defined
  1371. choke me now
  1372. #endif
  1373. ]],
  1374. [[
  1375. long pgsz = PAGESIZE + 0;
  1376. if (1 > pgsz) return 1;
  1377. ]]
  1378. )
  1379. ],
  1380. [[mhd_cv_macro_pagesize_usable="yes"]], [[mhd_cv_macro_pagesize_usable="no"]]
  1381. )
  1382. ]
  1383. )
  1384. AS_VAR_IF([[mhd_cv_macro_pagesize_usable]], [["yes"]],
  1385. [
  1386. AC_DEFINE([[MHD_USE_PAGESIZE_MACRO]],[[1]],[Define if you have usable PAGESIZE macro])
  1387. AC_CACHE_CHECK([whether PAGESIZE macro could be used for static init], [mhd_cv_macro_pagesize_usable_static],
  1388. [
  1389. AC_LINK_IFELSE(
  1390. [
  1391. AC_LANG_PROGRAM(
  1392. [[
  1393. #ifdef HAVE_UNISTD_H
  1394. #include <unistd.h>
  1395. #endif
  1396. #ifdef HAVE_LIMITS_H
  1397. #include <limits.h>
  1398. #endif
  1399. #ifdef HAVE_SYS_PARAM_H
  1400. #include <sys/param.h>
  1401. #endif
  1402. #ifndef PAGESIZE
  1403. #error No PAGESIZE macro defined
  1404. choke me now
  1405. #endif
  1406. static long ac_pgsz = PAGESIZE + 0;
  1407. ]],
  1408. [[
  1409. if (1 > ac_pgsz) return 1;
  1410. ]]
  1411. )
  1412. ],
  1413. [[mhd_cv_macro_pagesize_usable_static="yes"]], [[mhd_cv_macro_pagesize_usable_static="no"]]
  1414. )
  1415. ]
  1416. )
  1417. AS_VAR_IF([[mhd_cv_macro_pagesize_usable_static]], [["yes"]],
  1418. [AC_DEFINE([[MHD_USE_PAGESIZE_MACRO_STATIC]],[[1]],[Define if you have PAGESIZE macro usable for static init])]
  1419. )
  1420. ],
  1421. [
  1422. AC_CACHE_CHECK([for usable PAGE_SIZE macro], [mhd_cv_macro_page_size_usable],
  1423. [
  1424. AC_LINK_IFELSE(
  1425. [
  1426. AC_LANG_PROGRAM(
  1427. [[
  1428. #ifdef HAVE_UNISTD_H
  1429. #include <unistd.h>
  1430. #endif
  1431. #ifdef HAVE_LIMITS_H
  1432. #include <limits.h>
  1433. #endif
  1434. #ifdef HAVE_SYS_PARAM_H
  1435. #include <sys/param.h>
  1436. #endif
  1437. #ifndef PAGE_SIZE
  1438. #error No PAGE_SIZE macro defined
  1439. choke me now
  1440. #endif
  1441. ]],
  1442. [[
  1443. long pgsz = PAGE_SIZE + 0;
  1444. if (1 > pgsz) return 1;
  1445. ]]
  1446. )
  1447. ],
  1448. [[mhd_cv_macro_page_size_usable="yes"]], [[mhd_cv_macro_page_size_usable="no"]]
  1449. )
  1450. ]
  1451. )
  1452. AS_VAR_IF([[mhd_cv_macro_page_size_usable]], [["yes"]],
  1453. [
  1454. AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO]],[[1]],[Define if you have usable PAGE_SIZE macro])
  1455. AC_CACHE_CHECK([whether PAGE_SIZE macro could be used for static init], [mhd_cv_macro_page_size_usable_static],
  1456. [
  1457. AC_LINK_IFELSE(
  1458. [
  1459. AC_LANG_PROGRAM(
  1460. [[
  1461. #ifdef HAVE_UNISTD_H
  1462. #include <unistd.h>
  1463. #endif
  1464. #ifdef HAVE_LIMITS_H
  1465. #include <limits.h>
  1466. #endif
  1467. #ifdef HAVE_SYS_PARAM_H
  1468. #include <sys/param.h>
  1469. #endif
  1470. #ifndef PAGE_SIZE
  1471. #error No PAGE_SIZE macro defined
  1472. choke me now
  1473. #endif
  1474. static long ac_pgsz = PAGE_SIZE + 0;
  1475. ]],
  1476. [[
  1477. if (1 > ac_pgsz) return 1;
  1478. ]]
  1479. )
  1480. ],
  1481. [[mhd_cv_macro_page_size_usable_static="yes"]], [[mhd_cv_macro_page_size_usable_static="no"]]
  1482. )
  1483. ]
  1484. )
  1485. AS_VAR_IF([[mhd_cv_macro_page_size_usable_static]], [["yes"]],
  1486. [AC_DEFINE([[MHD_USE_PAGE_SIZE_MACRO_STATIC]],[[1]],[Define if you have PAGE_SIZE macro usable for static init])]
  1487. )
  1488. ]
  1489. )
  1490. ]
  1491. )
  1492. # Check for inter-thread signaling type
  1493. AC_ARG_ENABLE([[itc]],
  1494. [AS_HELP_STRING([[--enable-itc=TYPE]], [use TYPE of inter-thread communication (pipe, socketpair, eventfd) [auto]])], [],
  1495. [[enable_itc='auto']]
  1496. )
  1497. AS_CASE([[$enable_itc]],
  1498. [[pipe]], [[:]],
  1499. [[socketpair]], [[:]],
  1500. [[eventfd]], [[:]],
  1501. [[auto]], [AS_VAR_IF([[os_is_windows]], [["yes"]], [[enable_itc='socketpair']])],
  1502. [[eventFD]], [[enable_itc='eventfd']],
  1503. [[socket]], [[enable_itc='socketpair']],
  1504. [[no]], [AC_MSG_ERROR([[inter-thread communication cannot be disabled]])],
  1505. [AC_MSG_ERROR([[unrecognized type "$enable_itc" of inter-thread communication specified by "--enable-itc=$enable_itc"]])]
  1506. )
  1507. # AS_UNSET([[use_itc]])
  1508. AS_IF([[test "x$enable_itc" = "xeventfd" || test "x$enable_itc" = "xauto"]], [
  1509. AS_VAR_IF([[os_is_native_w32]], [["yes"]], [], [
  1510. AC_CHECK_HEADERS([sys/eventfd.h], [], [], [AC_INCLUDES_DEFAULT])
  1511. AS_VAR_IF([[ac_cv_header_sys_eventfd_h]], [["yes"]], [
  1512. AC_CACHE_CHECK([whether eventfd(2) is usable], [[mhd_cv_eventfd_usable]], [
  1513. AC_LINK_IFELSE([
  1514. AC_LANG_PROGRAM([[
  1515. #include <sys/eventfd.h>
  1516. ]], [[
  1517. int ef = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
  1518. if (ef) return ef - 1;
  1519. ]])
  1520. ], [[mhd_cv_eventfd_usable='yes']], [[mhd_cv_eventfd_usable='no']])
  1521. ])
  1522. ])
  1523. ])
  1524. AS_VAR_IF([[mhd_cv_eventfd_usable]], [["yes"]], [
  1525. use_itc='eventfd'
  1526. enable_itc="$use_itc"
  1527. AC_DEFINE([[_MHD_ITC_EVENTFD]], [[1]], [Define to use eventFD for inter-thread communication])
  1528. ], [
  1529. AS_VAR_IF([[enable_itc]], [["eventfd"]], [AC_MSG_ERROR([[eventfd(2) is not usable, consider using other type of inter-thread communication]])])
  1530. ])
  1531. ])
  1532. AS_IF([[test "x$enable_itc" = "xpipe" || test "x$enable_itc" = "xauto"]], [
  1533. AS_VAR_IF([[os_is_native_w32]], [["yes"]], [], [
  1534. AC_CACHE_CHECK([[whether pipe(3) is usable]], [[mhd_cv_pipe_usable]], [
  1535. AC_LINK_IFELSE([
  1536. AC_LANG_PROGRAM([
  1537. AC_INCLUDES_DEFAULT
  1538. #ifdef HAVE_UNISTD_H
  1539. #include <unistd.h>
  1540. #endif
  1541. ], [[
  1542. int arr[2];
  1543. int res;
  1544. res = pipe(arr)
  1545. ]])
  1546. ], [[mhd_cv_pipe_usable='yes']], [[mhd_cv_pipe_usable='no']])
  1547. ])
  1548. ])
  1549. AS_VAR_IF([[mhd_cv_pipe_usable]], [["yes"]], [
  1550. use_itc='pipe'
  1551. enable_itc="$use_itc"
  1552. AC_DEFINE([[_MHD_ITC_PIPE]], [[1]], [Define to use pipe for inter-thread communication])
  1553. AC_CACHE_CHECK([[whether pipe2(2) is usable]], [[mhd_cv_pipe2_usable]], [
  1554. AC_LINK_IFELSE([
  1555. AC_LANG_PROGRAM([
  1556. AC_INCLUDES_DEFAULT
  1557. #ifdef HAVE_FCNTL_H
  1558. #include <fcntl.h>
  1559. #endif
  1560. #ifdef HAVE_UNISTD_H
  1561. #include <unistd.h>
  1562. #endif
  1563. ], [[
  1564. int arr[2];
  1565. int res;
  1566. res = pipe2(arr, O_CLOEXEC | O_NONBLOCK)
  1567. ]])
  1568. ], [[mhd_cv_pipe2_usable='yes']], [[mhd_cv_pipe2_usable='no']])
  1569. ])
  1570. AS_VAR_IF([[mhd_cv_pipe2_usable]], [["yes"]],
  1571. [AC_DEFINE([[HAVE_PIPE2_FUNC]], [[1]], [Define if you have usable pipe2(2) function])])
  1572. ], [
  1573. AS_VAR_IF([[enable_itc]], [["pipe"]], [AC_MSG_ERROR([[pipe(3) is not usable, consider using other type of inter-thread communication]])])
  1574. ])
  1575. ])
  1576. AS_IF([[test "x$enable_itc" = "xsocketpair" || test "x$enable_itc" = "xauto"]], [
  1577. AS_VAR_IF([[os_is_native_w32]], [["yes"]], [[mhd_cv_socketpair_usable='yes']], [
  1578. AC_CACHE_CHECK([[whether socketpair(3) is usable]], [[mhd_cv_socketpair_usable]], [
  1579. AC_LINK_IFELSE([
  1580. AC_LANG_PROGRAM([
  1581. AC_INCLUDES_DEFAULT
  1582. #ifdef HAVE_SYS_TYPES_H
  1583. #include <sys/types.h>
  1584. #endif
  1585. #ifdef HAVE_SYS_SOCKET_H
  1586. #include <sys/socket.h>
  1587. #endif
  1588. ], [[
  1589. int arr[2];
  1590. int res;
  1591. #if defined(AF_LOCAL)
  1592. res = socketpair(AF_LOCAL, SOCK_STREAM, 0, arr);
  1593. #elif defined(AF_UNIX)
  1594. res = socketpair(AF_UNIX, SOCK_STREAM, 0, arr);
  1595. #else
  1596. #error AF_LOCAL and AF_UNIX are both undefined
  1597. choke me now;
  1598. #endif
  1599. if (res != 0) return 1
  1600. ]])
  1601. ], [[mhd_cv_socketpair_usable='yes']], [[mhd_cv_socketpair_usable='no']])
  1602. ])
  1603. ])
  1604. AS_VAR_IF([[mhd_cv_socketpair_usable]], [["yes"]], [
  1605. use_itc='socketpair'
  1606. enable_itc="$use_itc"
  1607. AC_DEFINE([[_MHD_ITC_SOCKETPAIR]], [[1]], [Define to use socketpair for inter-thread communication])
  1608. ], [
  1609. AS_VAR_IF([[enable_itc]], [["socketpair"]], [AC_MSG_ERROR([[socketpair(3) is not usable, consider using other type of inter-thread communication]])])
  1610. ])
  1611. ])
  1612. AS_IF([[test -z "$use_itc"]], [AC_MSG_ERROR([[cannot find usable type of inter-thread communication]])])
  1613. AC_CHECK_FUNCS_ONCE([accept4 gmtime_r memmem snprintf])
  1614. AC_CHECK_DECL([gmtime_s],
  1615. [
  1616. AC_MSG_CHECKING([[whether gmtime_s is in C11 form]])
  1617. AC_LINK_IFELSE(
  1618. [ AC_LANG_PROGRAM(
  1619. [[
  1620. #define __STDC_WANT_LIB_EXT1__ 1
  1621. #include <time.h>
  1622. #ifdef __cplusplus
  1623. extern "C"
  1624. #endif
  1625. struct tm* gmtime_s(const time_t* time, struct tm* result);
  1626. ]], [[
  1627. struct tm res;
  1628. time_t t;
  1629. gmtime_s (&t, &res);
  1630. ]])
  1631. ],
  1632. [
  1633. AC_DEFINE([HAVE_C11_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in C11 form.])
  1634. AC_MSG_RESULT([[yes]])
  1635. ],
  1636. [
  1637. AC_MSG_RESULT([[no]])
  1638. AC_MSG_CHECKING([[whether gmtime_s is in W32 form]])
  1639. AC_LINK_IFELSE(
  1640. [ AC_LANG_PROGRAM(
  1641. [[
  1642. #include <time.h>
  1643. #ifdef __cplusplus
  1644. extern "C"
  1645. #endif
  1646. errno_t gmtime_s(struct tm* _tm, const time_t* time);
  1647. ]], [[
  1648. struct tm res;
  1649. time_t t;
  1650. gmtime_s (&res, &t);
  1651. ]])
  1652. ],
  1653. [
  1654. AC_DEFINE([HAVE_W32_GMTIME_S], [1], [Define to 1 if you have the `gmtime_s' function in W32 form.])
  1655. AC_MSG_RESULT([[yes]])
  1656. ],
  1657. [AC_MSG_RESULT([[no]])
  1658. ])
  1659. ])
  1660. ], [],
  1661. [[#define __STDC_WANT_LIB_EXT1__ 1
  1662. #include <time.h>]])
  1663. AC_CHECK_DECL([SOCK_NONBLOCK], [AC_DEFINE([HAVE_SOCK_NONBLOCK], [1], [SOCK_NONBLOCK is defined in a socket header])], [],
  1664. [[
  1665. #if defined(HAVE_SYS_TYPES_H)
  1666. # include <sys/types.h>
  1667. #endif
  1668. #if defined(HAVE_SYS_SOCKET_H)
  1669. # include <sys/socket.h>
  1670. #elif defined(HAVE_WINSOCK2_H)
  1671. # include <winsock2.h>
  1672. #endif
  1673. ]]
  1674. )
  1675. AC_CHECK_DECL([[clock_gettime]],
  1676. [
  1677. SAVE_LIBS="$LIBS"
  1678. AC_SEARCH_LIBS([clock_gettime], [rt],
  1679. [
  1680. AC_DEFINE([HAVE_CLOCK_GETTIME], [1], [Have clock_gettime])
  1681. AS_VAR_IF([[ac_cv_search_clock_gettime]],[["none required"]], [],
  1682. [
  1683. MHD_LIBDEPS="$ac_cv_search_clock_gettime $MHD_LIBDEPS"
  1684. MHD_LIBDEPS_PKGCFG="$ac_cv_search_clock_gettime $MHD_LIBDEPS_PKGCFG"
  1685. ])
  1686. ], [], [$MHD_LIBDEPS])
  1687. LIBS="$SAVE_LIBS"
  1688. ], [], [[
  1689. #include <time.h>
  1690. ]])
  1691. AC_MSG_CHECKING([[for clock_get_time]])
  1692. AC_LINK_IFELSE(
  1693. [AC_LANG_PROGRAM(
  1694. [[
  1695. #include <mach/clock.h>
  1696. #include <mach/mach.h>
  1697. ]],
  1698. [[
  1699. clock_serv_t cs;
  1700. mach_timespec_t mt;
  1701. host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cs);
  1702. clock_get_time(cs, &mt);
  1703. mach_port_deallocate(mach_task_self(), cs);
  1704. ]])
  1705. ],
  1706. [
  1707. AC_DEFINE([HAVE_CLOCK_GET_TIME], [1], [Define to 1 if you have `clock_get_time', `host_get_clock_service' and `mach_port_deallocate' functions.])
  1708. AC_MSG_RESULT([[yes]])
  1709. ],
  1710. [AC_MSG_RESULT([[no]])
  1711. ])
  1712. AC_MSG_CHECKING([[for gethrtime]])
  1713. AC_LINK_IFELSE(
  1714. [AC_LANG_PROGRAM(
  1715. [[
  1716. #ifdef HAVE_SYS_TIME_H
  1717. /* Solaris define gethrtime() in sys/time.h */
  1718. #include <sys/time.h>
  1719. #endif /* HAVE_SYS_TIME_H */
  1720. #ifdef HAVE_TIME_H
  1721. /* HP-UX define gethrtime() in time.h */
  1722. #include <time.h>
  1723. #endif /* HAVE_TIME_H */
  1724. ]], [[hrtime_t hrt = gethrtime(); ]])
  1725. ],
  1726. [
  1727. AC_DEFINE([HAVE_GETHRTIME], [1], [Define to 1 if you have `gethrtime' function.])
  1728. AC_MSG_RESULT([[yes]])
  1729. ],
  1730. [AC_MSG_RESULT([[no]])
  1731. ])
  1732. AS_VAR_IF([ac_cv_header_time_h], ["yes"],
  1733. [
  1734. AC_CACHE_CHECK([[for C11 timespec_get()]], [mhd_cv_func_timespec_get],
  1735. [
  1736. AC_LINK_IFELSE(
  1737. [
  1738. AC_LANG_PROGRAM(
  1739. [[
  1740. #include <time.h>
  1741. #ifndef TIME_UTC
  1742. #error TIME_UTC must be defined to use timespec_get()
  1743. choke me now
  1744. #endif
  1745. ]],
  1746. [[
  1747. struct timespec ts;
  1748. if (TIME_UTC != timespec_get (&ts, TIME_UTC))
  1749. return 1;
  1750. ]]
  1751. )
  1752. ], [[mhd_cv_func_timespec_get="yes"]], [[mhd_cv_func_timespec_get="no"]]
  1753. )
  1754. ]
  1755. )
  1756. AS_VAR_IF([mhd_cv_func_timespec_get], ["yes"],
  1757. [AC_DEFINE([HAVE_TIMESPEC_GET], [1], [Define to 1 if you have C11 `mhd_cv_func_timespec_get' function and TIME_UTC macro.])]
  1758. )
  1759. ]
  1760. )
  1761. AS_VAR_SET_IF([ac_cv_func_gettimeofday], [mhd_cv_func_gettimeofday="${ac_cv_func_gettimeofday}"])
  1762. AC_CACHE_CHECK([[for gettimeofday(2)]], [mhd_cv_func_gettimeofday], [
  1763. AC_LINK_IFELSE(
  1764. [
  1765. AC_LANG_PROGRAM(
  1766. [[
  1767. #ifdef HAVE_SYS_TIME_H
  1768. #include <sys/time.h>
  1769. #endif /* HAVE_SYS_TIME_H */
  1770. #ifdef HAVE_TIME_H
  1771. #include <time.h>
  1772. #endif /* HAVE_TIME_H */
  1773. ]],
  1774. [[
  1775. struct timeval tv;
  1776. if (0 != gettimeofday (&tv, (void*) 0))
  1777. return 1;
  1778. ]]
  1779. )
  1780. ], [[mhd_cv_func_gettimeofday="yes"]], [[mhd_cv_func_gettimeofday="no"]]
  1781. )
  1782. ])
  1783. AS_VAR_IF([mhd_cv_func_gettimeofday], ["yes"],
  1784. [AC_DEFINE([HAVE_GETTIMEOFDAY], [1], [Define to 1 if you have `gettimeofday' function.])]
  1785. )
  1786. # IPv6
  1787. AC_MSG_CHECKING(for IPv6)
  1788. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  1789. #include <stdio.h>
  1790. #if HAVE_NETINET_IN_H
  1791. #include <netinet/in.h>
  1792. #endif
  1793. #if HAVE_SYS_SOCKET_H
  1794. #include <sys/socket.h>
  1795. #endif
  1796. #if HAVE_WINSOCK2_H
  1797. #include <winsock2.h>
  1798. #endif
  1799. #if HAVE_WS2TCPIP_H
  1800. #include <ws2tcpip.h>
  1801. #endif
  1802. ]], [[
  1803. int af=AF_INET6;
  1804. int pf=PF_INET6;
  1805. struct sockaddr_in6 sa;
  1806. printf("%d %d %p\n", af, pf, &sa);
  1807. ]])],[
  1808. have_inet6=yes;
  1809. AC_DEFINE([HAVE_INET6], [1], [Provides IPv6 headers])
  1810. ],[
  1811. have_inet6=no
  1812. ])
  1813. AC_MSG_RESULT($have_inet6)
  1814. MHD_CHECK_FUNC([[sysconf]], [[#include <unistd.h>]], [[long a = sysconf(0); if (a) return 1;]])
  1815. MHD_CHECK_FUNC([[sysctl]], [[
  1816. #ifdef HAVE_SYS_TYPES_H
  1817. #include <sys/types.h>
  1818. #endif
  1819. #ifdef HAVE_SYS_SYSCTL_H
  1820. #include <sys/sysctl.h>
  1821. #endif
  1822. #ifdef HAVE_STDDEF_H
  1823. #include <stddef.h>
  1824. #endif
  1825. ]], [[int mib[2] = {CTL_KERN, KERN_MAXPROC}; if (sysctl(mib, 2, NULL, NULL, NULL, 0)) return 1;]]
  1826. )
  1827. MHD_CHECK_FUNC([[sysctlbyname]], [[
  1828. #ifdef HAVE_SYS_TYPES_H
  1829. #include <sys/types.h>
  1830. #endif
  1831. #ifdef HAVE_SYS_SYSCTL_H
  1832. #include <sys/sysctl.h>
  1833. #endif
  1834. #ifdef HAVE_STDDEF_H
  1835. #include <stddef.h>
  1836. #endif
  1837. ]], [[sysctlbyname("test", NULL, NULL, NULL, 0);]]
  1838. )
  1839. MHD_CHECK_FUNC([[usleep]], [[#include <unistd.h>]], [[usleep(100000);]])
  1840. MHD_CHECK_FUNC([[nanosleep]], [[#include <time.h>]], [[struct timespec ts2, ts1 = {0, 0}; nanosleep(&ts1, &ts2);]])
  1841. HIDDEN_VISIBILITY_CFLAGS=""
  1842. AS_CASE(["$host"],
  1843. [*-*-mingw*],[
  1844. dnl on mingw32 we do -fvisibility=hidden and __declspec(dllexport)
  1845. AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) __declspec(dllexport) extern],
  1846. [defines how to decorate public symbols while building])
  1847. HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"
  1848. ],[
  1849. dnl on other compilers, check if we can do -fvisibility=hidden
  1850. AX_CHECK_LINK_FLAG([-fvisibility=hidden],
  1851. [AX_CHECK_COMPILE_FLAG([-fvisibility=hidden],
  1852. [AC_DEFINE([_MHD_EXTERN], [__attribute__((visibility("default"))) extern],
  1853. [defines how to decorate public symbols while building])
  1854. HIDDEN_VISIBILITY_CFLAGS="-fvisibility=hidden"])])
  1855. ])
  1856. AC_SUBST(HIDDEN_VISIBILITY_CFLAGS)
  1857. # libcurl (required for testing)
  1858. AC_ARG_ENABLE([curl],
  1859. [AS_HELP_STRING([--disable-curl],[disable cURL based testcases])],
  1860. [enable_curl=${enableval}])
  1861. curl=0
  1862. AS_IF([test "$enable_curl" != "no"],
  1863. [LIBCURL_CHECK_CONFIG([yes],[7.16.4],[enable_curl=yes],
  1864. [
  1865. AS_IF([test "x$enable_curl" = "xyes"],
  1866. [AC_MSG_WARN([[cURL-based tests cannot be enabled because libcurl is missing]])])
  1867. enable_curl=no
  1868. ])
  1869. ])
  1870. AS_IF([test "$enable_curl" != "no"],
  1871. [
  1872. # Lib cURL & cURL - OpenSSL versions
  1873. AC_DEFINE([MHD_REQ_CURL_VERSION], ["7.16.4"], [required cURL version to run tests])
  1874. AC_DEFINE([MHD_REQ_CURL_OPENSSL_VERSION], ["0.9.8"], [required cURL SSL version to run tests])
  1875. AC_DEFINE([MHD_REQ_CURL_GNUTLS_VERSION], ["2.8.6"], [gnuTLS lib version - used in conjunction with cURL])
  1876. AC_DEFINE([MHD_REQ_CURL_NSS_VERSION], ["3.12.0"], [NSS lib version - used in conjunction with cURL])
  1877. ])
  1878. AM_CONDITIONAL([HAVE_CURL], [test "x$enable_curl" = "xyes"])
  1879. mhd_have_libmagic="no"
  1880. SAVE_LIBS="$LIBS"
  1881. LIBS="$LIBS -lmagic"
  1882. AC_MSG_CHECKING([[for suitable libmagic]])
  1883. AC_LINK_IFELSE(
  1884. [AC_LANG_PROGRAM(
  1885. [AC_INCLUDES_DEFAULT
  1886. [
  1887. #include <magic.h>
  1888. ]],
  1889. [[
  1890. char var_data[256];
  1891. const char *var_mime;
  1892. magic_t var_magic = magic_open (MAGIC_MIME_TYPE);
  1893. (void)magic_load (var_magic, NULL);
  1894. var_data[0] = 0;
  1895. var_mime = magic_buffer (var_magic, var_data, 1);
  1896. magic_close (var_magic);
  1897. ]]
  1898. )
  1899. ],
  1900. [
  1901. AC_DEFINE([MHD_HAVE_LIBMAGIC], [1], [Define to 1 if you have suitable libmagic.])
  1902. mhd_have_libmagic="yes"
  1903. AC_MSG_RESULT([[yes]])
  1904. ],
  1905. [AC_MSG_RESULT([[no]])
  1906. ]
  1907. )
  1908. LIBS="$SAVE_LIBS"
  1909. AM_CONDITIONAL([MHD_HAVE_LIBMAGIC], [[test "x$mhd_have_libmagic" = "xyes"]])
  1910. # large file support (> 4 GB)
  1911. AC_SYS_LARGEFILE
  1912. AC_FUNC_FSEEKO
  1913. AC_CHECK_FUNCS([lseek64 pread64 pread])
  1914. # check for various sendfile functions
  1915. AC_ARG_ENABLE([sendfile],
  1916. [AS_HELP_STRING([--disable-sendfile],
  1917. [disable usage of sendfile() for HTTP connections [auto]])],
  1918. [],
  1919. [enable_sendfile="auto"])
  1920. AS_CASE([$enable_sendfile],
  1921. [[auto | yes]],[[found_sendfile="no"]],
  1922. [[no]],[[found_sendfile="disabled"]],
  1923. [AC_MSG_ERROR([[unknown value specified: --enable-sendfile=$enable_sendfile]])]
  1924. )
  1925. AS_VAR_IF([[found_sendfile]], [["no"]],
  1926. [
  1927. AC_MSG_CHECKING([[for Linux-style sendfile(2)]])
  1928. AC_LINK_IFELSE(
  1929. [AC_LANG_PROGRAM(
  1930. [[
  1931. #include <sys/sendfile.h>
  1932. static void empty_func(void)
  1933. {
  1934. /* Check for declaration */
  1935. (void)sendfile;
  1936. }
  1937. /* Declare again to check form match */
  1938. ssize_t sendfile(int, int, off_t*, size_t);
  1939. ]],
  1940. [[
  1941. int fd1=0, fd2=2;
  1942. off_t o = 0;
  1943. size_t s = 5;
  1944. ssize_t r;
  1945. r = sendfile (fd1, fd2, &o, s);
  1946. if (r)
  1947. empty_func();
  1948. ]]
  1949. )
  1950. ],
  1951. [
  1952. AC_DEFINE([HAVE_LINUX_SENDFILE], [1], [Define to 1 if you have linux-style sendfile(2).])
  1953. found_sendfile="yes, Linux-style"
  1954. AC_MSG_RESULT([[yes]])
  1955. AC_CHECK_FUNCS([sendfile64])
  1956. ],
  1957. [AC_MSG_RESULT([[no]])
  1958. ]
  1959. )
  1960. ]
  1961. )
  1962. AS_VAR_IF([[found_sendfile]], [["no"]],
  1963. [
  1964. AC_MSG_CHECKING([[for FreeBSD-style sendfile(2)]])
  1965. AC_LINK_IFELSE(
  1966. [AC_LANG_PROGRAM(
  1967. [[
  1968. #include <sys/types.h>
  1969. #include <sys/socket.h>
  1970. #include <sys/uio.h>
  1971. static void empty_func(void)
  1972. {
  1973. /* Check for declaration */
  1974. (void)sendfile;
  1975. }
  1976. /* Declare again to check form match */
  1977. int sendfile(int, int, off_t, size_t,
  1978. struct sf_hdtr*, off_t*, int);
  1979. ]],
  1980. [[
  1981. int fd1=0, fd2=1;
  1982. off_t o = 0;
  1983. size_t s = 5;
  1984. off_t r1;
  1985. int r2;
  1986. r2 = sendfile (fd1, fd2, o, s, (void*)0, &r1, 0);
  1987. if (r2)
  1988. empty_func();
  1989. ]]
  1990. )
  1991. ],
  1992. [
  1993. AC_DEFINE([HAVE_FREEBSD_SENDFILE], [1], [Define to 1 if you have FreeBSD-style sendfile(2).])
  1994. found_sendfile="yes, FreeBSD-style"
  1995. AC_MSG_RESULT([[yes]])
  1996. ],
  1997. [AC_MSG_RESULT([[no]])
  1998. ]
  1999. )
  2000. ]
  2001. )
  2002. AS_VAR_IF([[found_sendfile]], [["no"]],
  2003. [
  2004. AC_MSG_CHECKING([[for Darwin-style sendfile(2)]])
  2005. AC_LINK_IFELSE(
  2006. [AC_LANG_PROGRAM(
  2007. [[
  2008. #include <sys/types.h>
  2009. #include <sys/socket.h>
  2010. #include <sys/uio.h>
  2011. static void empty_func(void)
  2012. {
  2013. /* Check for declaration */
  2014. (void)sendfile;
  2015. }
  2016. /* Declare again to check form match */
  2017. int sendfile(int, int, off_t, off_t*,
  2018. struct sf_hdtr *, int);
  2019. ]],
  2020. [[
  2021. int fd=0, s=1;
  2022. off_t o = 0;
  2023. off_t l = 5;
  2024. int r;
  2025. r = sendfile (fd, s, o, &l, (void*)0, 0);
  2026. if (r)
  2027. empty_func();
  2028. ]]
  2029. )
  2030. ],
  2031. [
  2032. AC_DEFINE([HAVE_DARWIN_SENDFILE], [1], [Define to 1 if you have Darwin-style sendfile(2).])
  2033. found_sendfile="yes, Darwin-style"
  2034. AC_MSG_RESULT([[yes]])
  2035. ],
  2036. [AC_MSG_RESULT([[no]])
  2037. ]
  2038. )
  2039. ]
  2040. )
  2041. AS_VAR_IF([[found_sendfile]], [["no"]],
  2042. [
  2043. AC_MSG_CHECKING([[for Solaris-style sendfile(3)]])
  2044. SAVE_LIBS="$LIBS"
  2045. LIBS="$LIBS -lsendfile"
  2046. AC_LINK_IFELSE(
  2047. [AC_LANG_PROGRAM(
  2048. [[
  2049. #include <sys/types.h>
  2050. #include <sys/socket.h>
  2051. #include <sys/sendfile.h>
  2052. static void empty_func(void)
  2053. {
  2054. /* Check for declaration */
  2055. (void)sendfile;
  2056. }
  2057. /* Declare again to check form match */
  2058. ssize_t sendfile(int out_fd, int in_fd,
  2059. off_t *off, size_t len);
  2060. ]],
  2061. [[
  2062. int fd1=0, fd2=1;
  2063. off_t o = 0;
  2064. size_t l = 5;
  2065. ssize_t r;
  2066. r = sendfile (fd1, fd2, &o, l);
  2067. if (r)
  2068. empty_func();
  2069. ]]
  2070. )
  2071. ],
  2072. [
  2073. AC_DEFINE([HAVE_SOLARIS_SENDFILE], [1], [Define to 1 if you have Solaris-style sendfile(3).])
  2074. found_sendfile="yes, Solaris-style"
  2075. MHD_LIBDEPS="-lsendfile $MHD_LIBDEPS"
  2076. MHD_LIBDEPS_PKGCFG="-lsendfile $MHD_LIBDEPS_PKGCFG"
  2077. AC_MSG_RESULT([[yes]])
  2078. AC_CHECK_FUNCS([sendfile64])
  2079. ],
  2080. [AC_MSG_RESULT([[no]])
  2081. ]
  2082. )
  2083. LIBS="$SAVE_LIBS"
  2084. ]
  2085. )
  2086. AS_IF([[test "x$found_sendfile" = "xno" && test "x$enable_sendfile" = "xyes"]],
  2087. [AC_MSG_ERROR([[sendfile() usage was requested by configure parameter, but no usable sendfile() function is detected]])]
  2088. )
  2089. # optional: have error messages ?
  2090. AC_MSG_CHECKING([[whether to generate error messages]])
  2091. AC_ARG_ENABLE([messages],
  2092. [AS_HELP_STRING([--disable-messages],
  2093. [disable MHD error messages])],
  2094. [enable_messages=${enableval}],
  2095. [enable_messages=yes])
  2096. AS_IF([[test "x$enable_messages" = "xyes"]],
  2097. [ AC_DEFINE([HAVE_MESSAGES],[1],[Define to 1 to enable support for error messages.]) ],
  2098. [[ enable_messages=no ]])
  2099. AC_MSG_RESULT([[$enable_messages]])
  2100. # optional: have postprocessor?
  2101. AC_MSG_CHECKING([[whether to enable postprocessor]])
  2102. AC_ARG_ENABLE([postprocessor],
  2103. [AS_HELP_STRING([--disable-postprocessor],
  2104. [disable MHD PostProcessor functionality])],
  2105. [enable_postprocessor=${enableval}],
  2106. [enable_postprocessor=yes])
  2107. AS_IF([[test "x$enable_postprocessor" != "xno"]],
  2108. [ enable_postprocessor=yes
  2109. AC_DEFINE([HAVE_POSTPROCESSOR],[1],[Define to 1 if libmicrohttpd is compiled with postprocessor support.]) ])
  2110. AM_CONDITIONAL([HAVE_POSTPROCESSOR], [test "x$enable_postprocessor" != "xno"])
  2111. AC_MSG_RESULT([[$enable_postprocessor]])
  2112. # optional: have zzuf, socat?
  2113. AC_CHECK_PROG([have_zzuf],[zzuf], [yes], [no])
  2114. AC_CHECK_PROG([have_socat],[socat], [yes], [no])
  2115. AM_CONDITIONAL([HAVE_ZZUF], [test "x$have_zzuf" = "xyes"])
  2116. AM_CONDITIONAL([HAVE_SOCAT], [test "x$have_socat" = "xyes"])
  2117. have_gnutls=no
  2118. have_gnutls_sni=no
  2119. have_gcrypt=no
  2120. AS_UNSET([GNUTLS_CPPFLAGS])
  2121. AS_UNSET([GNUTLS_LDFLAGS])
  2122. # optional: HTTPS support. Enabled by default
  2123. AC_ARG_ENABLE([https],
  2124. [AS_HELP_STRING([--enable-https],
  2125. [enable HTTPS support (yes, no, auto)[auto]])],
  2126. [enable_https=${enableval}])
  2127. AS_IF([test "x$enable_https" != "xno"],[
  2128. #
  2129. # Next block is large unindented block
  2130. #
  2131. # gnutls
  2132. have_gnutls_pkgcfg=no
  2133. AC_MSG_CHECKING([[how to find GnuTLS library]])
  2134. AC_ARG_WITH([[gnutls]],
  2135. [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)])],
  2136. [
  2137. AS_CASE([$with_gnutls],
  2138. [no],[
  2139. AC_MSG_RESULT([[GnuTLS disabled]])
  2140. AS_UNSET([GNUTLS_CPPFLAGS])
  2141. AS_UNSET([GNUTLS_CFLAGS])
  2142. AS_UNSET([GNUTLS_LDFLAGS])
  2143. AS_UNSET([GNUTLS_LIBS])
  2144. ],
  2145. [yes],[
  2146. AC_MSG_RESULT([[automatically, forced]])
  2147. ],
  2148. [
  2149. AC_MSG_RESULT([[-I$with_gnutls/include -L$with_gnutls/lib -lgnutls]])
  2150. SAVE_LDFLAGS="$LDFLAGS"
  2151. SAVE_CPPFLAGS="$CPPFLAGS"
  2152. SAVE_CFLAGS="$CFLAGS"
  2153. SAVE_LIBS="$LIBS"
  2154. LDFLAGS="-L$with_gnutls/lib $LDFLAGS"
  2155. CPPFLAGS="-I$with_gnutls/include $CPPFLAGS"
  2156. have_gnutls_pkgcfg=no
  2157. AC_CHECK_HEADERS([gnutls/gnutls.h],
  2158. [AC_CHECK_LIB([gnutls], [gnutls_priority_set],
  2159. [
  2160. GNUTLS_CPPFLAGS="-I$with_gnutls/include"
  2161. GNUTLS_LDFLAGS="-L$with_gnutls/lib"
  2162. GNUTLS_LIBS="-lgnutls"
  2163. have_gnutls=yes
  2164. ])], [], [AC_INCLUDES_DEFAULT])
  2165. AS_IF([test "x$have_gnutls" != "xyes"], [AC_MSG_ERROR([can't find usable libgnutls at specified prefix $with_gnutls])])
  2166. CPPFLAGS="$SAVE_CPPFLAGS"
  2167. CFLAGS="$SAVE_CFLAGS"
  2168. LDFLAGS="$SAVE_LDFLAGS"
  2169. LIBS="$SAVE_LIBS"
  2170. ])
  2171. ],
  2172. [AC_MSG_RESULT([[automatically]])
  2173. ])
  2174. AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"],
  2175. [
  2176. AC_CACHE_CHECK([[whether to add pkg-config special search directories]], [mhd_cv_pkgconf_add_dirs],
  2177. [
  2178. AS_IF([[test "x$host_os" = "xsolaris2.11" && test "x$cross_compiling" = "xno"]],
  2179. [
  2180. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
  2181. char size_chk[7-sizeof(char*)];
  2182. #if defined(_LP64) || defined(__LP64__) || defined(__x86_64) || defined(__x86_64__)
  2183. #error This is 64-bit target.
  2184. choke me now
  2185. #endif
  2186. #if defined(__amd64) || defined(__amd64__) || defined(__sparcv9) || defined(__sparc_v9__)
  2187. #error This is 64-bit target.
  2188. choke me now
  2189. #endif
  2190. ]], [[]]
  2191. )
  2192. ],
  2193. [
  2194. mhd_cv_pkgconf_add_dirs='/usr/lib/pkgconfig/gnutls-3'
  2195. ],
  2196. [
  2197. AS_IF([[test "x$host_cpu" = "xx86_64" || test "x$host_cpu" = "xi386"]],
  2198. [[mhd_cv_pkgconf_add_dirs='/usr/lib/amd64/pkgconfig/gnutls-3:/usr/lib/amd64/pkgconfig']],
  2199. [[test "x$host_cpu" = "xsparc"]],
  2200. [[mhd_cv_pkgconf_add_dirs='/usr/lib/sparkv9/pkgconfig/gnutls-3:/usr/lib/sparkv9/pkgconfig']],
  2201. [[mhd_cv_pkgconf_add_dirs='/usr/lib/64/pkgconfig/gnutls-3:/usr/lib/64/pkgconfig']]
  2202. )
  2203. ]
  2204. )
  2205. ],
  2206. [[ mhd_cv_pkgconf_add_dirs='no' ]]
  2207. )
  2208. ]
  2209. )
  2210. AS_IF([[test "x$mhd_cv_pkgconf_add_dirs" != "xno"]],
  2211. [
  2212. test "x$PKG_CONFIG_PATH" = "x" || PKG_CONFIG_PATH="${PKG_CONFIG_PATH}${PATH_SEPARATOR}"
  2213. PKG_CONFIG_PATH="${PKG_CONFIG_PATH}${mhd_cv_pkgconf_add_dirs}"
  2214. export PKG_CONFIG_PATH
  2215. ]
  2216. )
  2217. PKG_CHECK_MODULES(GNUTLS, [[gnutls]],
  2218. [
  2219. have_gnutls_pkgcfg='yes'
  2220. SAVE_CPPFLAGS="$CPPFLAGS"
  2221. SAVE_CFLAGS="$CFLAGS"
  2222. SAVE_LDFLAGS="$LDFLAGS"
  2223. SAVE_LIBS="$LIBS"
  2224. CFLAGS="$GNUTLS_CFLAGS $CFLAGS"
  2225. LIBS="$LIBS $GNUTLS_LIBS"
  2226. AC_MSG_CHECKING([[whether GnuTLS is usable]])
  2227. AC_LINK_IFELSE([
  2228. AC_LANG_PROGRAM([[
  2229. #include <gnutls/gnutls.h>
  2230. ]], [[
  2231. gnutls_session_t session;
  2232. gnutls_priority_t priorities;
  2233. gnutls_global_init();
  2234. gnutls_priority_init(&priorities, "NORMAL", NULL);
  2235. gnutls_init(&session, GNUTLS_SERVER);
  2236. gnutls_priority_set(session, priorities);
  2237. ]])],
  2238. [
  2239. AC_MSG_RESULT([[yes]])
  2240. have_gnutls=yes
  2241. # GNUTLS_CFLAGS is actually CPPFLAGS
  2242. GNUTLS_CPPFLAGS="$GNUTLS_CFLAGS"
  2243. # GNUTLS_CFLAGS is combination of LDFLAGS and LIBS
  2244. GNUTLS_LDFLAGS="$GNUTLS_LIBS"
  2245. ],
  2246. [
  2247. AC_MSG_RESULT([[no]])
  2248. have_gnutls=no
  2249. ])
  2250. AS_IF([test "x$have_gnutls" != "xyes"],
  2251. [
  2252. AC_MSG_WARN([pkg-config reports that GnuTLS is present, but GnuTLS can't be used])
  2253. AS_UNSET([GNUTLS_CPPFLAGS])
  2254. AS_UNSET([GNUTLS_CFLAGS])
  2255. AS_UNSET([GNUTLS_LDFLAGS])
  2256. AS_UNSET([GNUTLS_LIBS])
  2257. ]
  2258. )
  2259. CPPFLAGS="$SAVE_CPPFLAGS"
  2260. CFLAGS="$SAVE_CFLAGS"
  2261. LDFLAGS="$SAVE_LDFLAGS"
  2262. LIBS="$SAVE_LIBS"
  2263. ],
  2264. [
  2265. # check for GnuTLS at default paths
  2266. have_gnutls_pkgcfg='no'
  2267. AC_CHECK_HEADERS([gnutls/gnutls.h],
  2268. [AC_CHECK_LIB([gnutls], [gnutls_priority_set],
  2269. [
  2270. GNUTLS_LIBS="-lgnutls"
  2271. have_gnutls=yes
  2272. ])], [], [AC_INCLUDES_DEFAULT])
  2273. ])
  2274. ])
  2275. have_gcrypt='unknown'
  2276. AS_IF([test "x$with_gnutls" != "xno" && test "x$have_gnutls" != "xyes"],
  2277. [
  2278. AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no])
  2279. AS_IF([[test "x$have_gcrypt" = "xyes"]],
  2280. [
  2281. SAVE_CPPFLAGS="$CPPFLAGS"
  2282. SAVE_CFLAGS="$CFLAGS"
  2283. SAVE_LIBS="$LIBS"
  2284. SAVE_LDFLAGS="$LDFLAGS"
  2285. CFLAGS="$CFLAGS $LIBGCRYPT_CFLAGS"
  2286. # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both
  2287. CPPFLAGS="$CPPFLAGS $LIBGCRYPT_CFLAGS"
  2288. AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no], [AC_INCLUDES_DEFAULT])
  2289. # Check for GnuTLS with gcrypt flags
  2290. LDFLAGS="$LDFLAGS $LIBGCRYPT_LIBS"
  2291. # A bit of hack: unset cache variable to force recheck
  2292. AS_UNSET([ac_cv_header_gnutls_gnutls_h])
  2293. AC_CHECK_HEADERS([gnutls/gnutls.h],
  2294. [AS_UNSET([ac_cv_lib_gnutls_gnutls_priority_set]) # A bit of hack: unset cache variable to force recheck
  2295. AC_CHECK_LIB([gnutls], [gnutls_priority_set],
  2296. [
  2297. GNUTLS_CPPFLAGS="$LIBGCRYPT_CFLAGS"
  2298. GNUTLS_CFLAGS="$LIBGCRYPT_CFLAGS"
  2299. GNUTLS_LDFLAGS="$LIBGCRYPT_LIBS"
  2300. GNUTLS_LIBS="-lgnutls"
  2301. have_gnutls=yes
  2302. ])], [], [AC_INCLUDES_DEFAULT])
  2303. CPPFLAGS="$SAVE_CPPFLAGS"
  2304. CFLAGS="$SAVE_CFLAGS"
  2305. LDFLAGS="$SAVE_LDFLAGS"
  2306. LIBS="$SAVE_LIBS"
  2307. ]
  2308. )
  2309. ]
  2310. )
  2311. AS_IF([test "x$have_gnutls" != "xyes" && test "x$with_gnutls" = "xyes"],
  2312. [AC_MSG_ERROR([[can't find usable libgnutls]])])
  2313. AS_IF([test "x$have_gnutls" = "xyes"],
  2314. [
  2315. SAVE_CPPFLAGS="$CPPFLAGS"
  2316. SAVE_CFLAGS="$CFLAGS"
  2317. SAVE_LDFLAGS="$LDFLAGS"
  2318. SAVE_LIBS="$LIBS"
  2319. CPPFLAGS="$GNUTLS_CPPFLAGS $CPPFLAGS"
  2320. CFLAGS="$GNUTLS_CFLAGS $CFLAGS"
  2321. LDFLAGS="$GNUTLS_LDFLAGS $LDFLAGS"
  2322. LIBS="$LIBS $GNUTLS_LIBS"
  2323. AC_MSG_CHECKING([[for gnutls_privkey_import_x509_raw()]])
  2324. AC_LINK_IFELSE([
  2325. AC_LANG_PROGRAM([[
  2326. #include <gnutls/gnutls.h>
  2327. #include <gnutls/abstract.h>
  2328. ]], [[
  2329. gnutls_datum_t data;
  2330. gnutls_privkey_t key = 0;
  2331. #ifndef gnutls_load_file
  2332. (void)gnutls_load_file; /* Check for declaration. */
  2333. #endif
  2334. #ifndef gnutls_privkey_import_x509_raw
  2335. (void)gnutls_privkey_import_x509_raw; /* Check for declaration. */
  2336. #endif
  2337. gnutls_load_file("key.pem", &data);
  2338. gnutls_privkey_import_x509_raw(key, &data, GNUTLS_X509_FMT_PEM, NULL, 0);
  2339. gnutls_free(data.data);
  2340. ]])], [[have_gnutls_sni=yes]], [[have_gnutls_sni=no]])
  2341. AC_MSG_RESULT([[$have_gnutls_sni]])
  2342. AC_CACHE_CHECK([[whether GnuTLS require libgcrypt initialisaion]], [mhd_cv_gcrypt_required],
  2343. [
  2344. AC_COMPILE_IFELSE(
  2345. [
  2346. AC_LANG_PROGRAM(
  2347. [
  2348. #include <gnutls/gnutls.h>
  2349. ],
  2350. [
  2351. #if !defined(GNUTLS_VERSION_NUMBER) || GNUTLS_VERSION_NUMBER+0 <= 0x020c14
  2352. #error Old versions of GnuTLS require libgcript initialisaion
  2353. choke me now
  2354. #endif
  2355. ]
  2356. )
  2357. ],
  2358. [[mhd_cv_gcrypt_required='no']], [[mhd_cv_gcrypt_required='yes']]
  2359. )
  2360. ]
  2361. )
  2362. CPPFLAGS="$SAVE_CPPFLAGS"
  2363. CFLAGS="$SAVE_CFLAGS"
  2364. LDFLAGS="$SAVE_LDFLAGS"
  2365. LIBS="$SAVE_LIBS"
  2366. ],
  2367. [
  2368. AS_UNSET([GNUTLS_CPPFLAGS])
  2369. AS_UNSET([GNUTLS_LDFLAGS])
  2370. ]
  2371. )
  2372. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes" && test "x$have_gcrypt" = "xunknown"]],
  2373. [
  2374. AM_PATH_LIBGCRYPT([1.2.2], [have_gcrypt=yes], [have_gcrypt=no])
  2375. AS_IF([[test "x$have_gcrypt" = "xyes"]],
  2376. [
  2377. SAVE_CPPFLAGS="$CPPFLAGS"
  2378. SAVE_CFLAGS="$CFLAGS"
  2379. CFLAGS="$CFLAGS $LIBGCRYPT_CFLAGS"
  2380. # LIBGCRYPT_CFLAGS can be actually a CPPFLAGS, so check them both
  2381. CPPFLAGS="$CPPFLAGS $LIBGCRYPT_CFLAGS"
  2382. AC_CHECK_HEADERS([gcrypt.h], [], [have_gcrypt=no], [AC_INCLUDES_DEFAULT])
  2383. CPPFLAGS="$SAVE_CPPFLAGS"
  2384. CFLAGS="$SAVE_CFLAGS"
  2385. ]
  2386. )
  2387. ]
  2388. )
  2389. AS_UNSET([[crypt_missing]])
  2390. AS_IF([[test "x$have_gnutls" = "xyes"]],
  2391. [
  2392. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes" && test "x$have_gcrypt" != "xyes"]],
  2393. [
  2394. crypt_missing="required libgcrypt"
  2395. AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])])
  2396. enable_https=no
  2397. MSG_HTTPS="no (lacking $crypt_missing)"
  2398. AS_UNSET([LIBGCRYPT_CFLAGS])
  2399. AS_UNSET([LIBGCRYPT_LIBS])
  2400. AS_UNSET([GNUTLS_CPPFLAGS])
  2401. AS_UNSET([GNUTLS_CFLAGS])
  2402. AS_UNSET([GNUTLS_LDFLAGS])
  2403. AS_UNSET([GNUTLS_LIBS])
  2404. ],
  2405. [
  2406. AC_DEFINE([[HTTPS_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTPS support.])
  2407. enable_https=yes
  2408. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  2409. [
  2410. MSG_HTTPS="yes (using libgnutls and libgcrypt)"
  2411. MHD_TLS_LIB_CPPFLAGS="$LIBGCRYPT_CFLAGS $GNUTLS_CPPFLAGS"
  2412. MHD_TLS_LIB_CFLAGS="$LIBGCRYPT_CFLAGS $GNUTLS_CFLAGS"
  2413. MHD_TLS_LIB_LDFLAGS="$GNUTLS_LDFLAGS"
  2414. MHD_TLS_LIBDEPS="$GNUTLS_LIBS $LIBGCRYPT_LIBS"
  2415. AC_DEFINE([[MHD_HTTPS_REQUIRE_GCRYPT]], [[1]], [Define to `1' if HTTPS require initialisation of libgcrypt])
  2416. ],
  2417. [
  2418. MSG_HTTPS="yes (using libgnutls)"
  2419. AS_UNSET([LIBGCRYPT_CFLAGS])
  2420. AS_UNSET([LIBGCRYPT_LIBS])
  2421. MHD_TLS_LIB_CPPFLAGS="$GNUTLS_CPPFLAGS"
  2422. MHD_TLS_LIB_CFLAGS="$GNUTLS_CFLAGS"
  2423. MHD_TLS_LIB_LDFLAGS="$GNUTLS_LDFLAGS"
  2424. MHD_TLS_LIBDEPS="$GNUTLS_LIBS"
  2425. ]
  2426. )
  2427. AS_IF([[ test "x$have_gnutls_pkgcfg" = "xyes" ]],
  2428. [ # remove GnuTLS from private libs in .pc file as it defined in Requires.private
  2429. MHD_REQ_PRIVATE='gnutls'
  2430. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  2431. [[MHD_LIBDEPS_PKGCFG="$LIBGCRYPT_LIBS $MHD_LIBDEPS_PKGCFG"]]
  2432. )
  2433. ],
  2434. [
  2435. MHD_REQ_PRIVATE=''
  2436. AS_IF([[test "x$mhd_cv_gcrypt_required" = "xyes"]],
  2437. [[MHD_LIBDEPS_PKGCFG="$LIBGCRYPT_LIBS $MHD_LIBDEPS_PKGCFG"]]
  2438. )
  2439. MHD_LIBDEPS_PKGCFG="$GNUTLS_LIBS $MHD_LIBDEPS_PKGCFG"
  2440. ])
  2441. ]
  2442. )
  2443. ],
  2444. [
  2445. crypt_missing="libgnutls"
  2446. AS_IF([[test "x$enable_https" = "xyes" ]], [AC_MSG_ERROR([[HTTPS support cannot be enabled without $crypt_missing.]])])
  2447. enable_https=no
  2448. MSG_HTTPS="no (lacking $crypt_missing)"
  2449. AS_UNSET([LIBGCRYPT_CFLAGS])
  2450. AS_UNSET([LIBGCRYPT_LIBS])
  2451. AS_UNSET([GNUTLS_CPPFLAGS])
  2452. AS_UNSET([GNUTLS_CFLAGS])
  2453. AS_UNSET([GNUTLS_LDFLAGS])
  2454. AS_UNSET([GNUTLS_LIBS])
  2455. ]
  2456. )
  2457. ],[
  2458. MSG_HTTPS="no (disabled)"
  2459. ])
  2460. #
  2461. # End of large unindented block
  2462. #
  2463. AC_MSG_CHECKING(whether to support HTTPS)
  2464. AC_MSG_RESULT([$MSG_HTTPS])
  2465. AM_CONDITIONAL([HAVE_GNUTLS], [[test "x$have_gnutls" = "xyes"]])
  2466. AM_CONDITIONAL([HAVE_GNUTLS_SNI], [[test "x$have_gnutls_sni" = "xyes"]])
  2467. AM_CONDITIONAL([ENABLE_HTTPS], [test "x$enable_https" = "xyes"])
  2468. AM_CONDITIONAL([HTTPS_REQUIRE_GCRYPT], [[test "x$enable_https" = "xyes" && test "x$mhd_cv_gcrypt_required" = "xyes"]])
  2469. AC_SUBST([GNUTLS_CPPFLAGS])
  2470. AC_SUBST([GNUTLS_CFLAGS])
  2471. AC_SUBST([GNUTLS_LDFLAGS])
  2472. AC_SUBST([GNUTLS_LIBS])
  2473. AS_VAR_IF([have_gnutls], ["yes"],
  2474. [
  2475. AC_CACHE_CHECK([for GnuTLS quirks], [mhd_cv_gnutls_mthread_broken],
  2476. [
  2477. mhd_cv_gnutls_mthread_broken="no"
  2478. AS_IF([test -r /etc/redhat-release],
  2479. [
  2480. AS_IF([$FGREP ' release 6.' /etc/redhat-release >/dev/null || $FGREP '(Santiago)' /etc/redhat-release >/dev/null],
  2481. [mhd_cv_gnutls_mthread_broken="found"],
  2482. )
  2483. ]
  2484. )
  2485. AS_VAR_IF([mhd_cv_gnutls_mthread_broken], ["no"],
  2486. [
  2487. AS_IF([command -v rpm >/dev/null],
  2488. [
  2489. AS_IF([test r`rpm -E '%{rhel} 2>/dev/null'` = "r6"],
  2490. [mhd_cv_gnutls_mthread_broken="found"],
  2491. )
  2492. ]
  2493. )
  2494. ]
  2495. )
  2496. ]
  2497. )
  2498. AC_CACHE_CHECK([for gnutls-cli binary], [mhd_cv_gnutls_cli],
  2499. [
  2500. mhd_cv_gnutls_cli="no"
  2501. AS_IF([command -v gnutls-cli >/dev/null 2>&1],
  2502. [AS_IF([AC_RUN_LOG([gnutls-cli --version >&2])], [mhd_cv_gnutls_cli="yes"])]
  2503. )
  2504. ]
  2505. )
  2506. ]
  2507. )
  2508. AM_CONDITIONAL([HAVE_GNUTLS_MTHREAD_BROKEN], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xfound"]])
  2509. AM_CONDITIONAL([USE_UPGRADE_TLS_TESTS], [[test "x${mhd_cv_gnutls_mthread_broken}" = "xno" || test "x${mhd_cv_gnutls_cli}" = "xyes"]])
  2510. # optional: HTTP Basic Auth support. Enabled by default
  2511. AC_MSG_CHECKING([[whether to support HTTP basic authentication]])
  2512. AC_ARG_ENABLE([bauth],
  2513. AS_HELP_STRING([--disable-bauth],
  2514. [disable HTTP basic Auth support]),
  2515. [enable_bauth=${enableval}],
  2516. [enable_bauth=yes])
  2517. AS_IF([[test "x$enable_bauth" != "xno"]],
  2518. [ enable_bauth=yes
  2519. AC_DEFINE([BAUTH_SUPPORT],[1],[Define to 1 if libmicrohttpd is compiled with basic Auth support.]) ])
  2520. AM_CONDITIONAL([ENABLE_BAUTH], [test "x$enable_bauth" != "xno"])
  2521. AC_MSG_RESULT([[$enable_bauth]])
  2522. # optional: HTTP Digest Auth support. Enabled by default
  2523. AC_MSG_CHECKING([[whether to support HTTP digest authentication]])
  2524. AC_ARG_ENABLE([dauth],
  2525. AS_HELP_STRING([--disable-dauth],
  2526. [disable HTTP basic and digest Auth support]),
  2527. [enable_dauth=${enableval}],
  2528. [enable_dauth=yes])
  2529. AS_IF([[test "x$enable_dauth" != "xno"]],
  2530. [ enable_dauth=yes
  2531. AC_DEFINE([DAUTH_SUPPORT],[1],[Define to 1 if libmicrohttpd is compiled with digest Auth support.]) ])
  2532. AM_CONDITIONAL([ENABLE_DAUTH], [test "x$enable_dauth" != "xno"])
  2533. AC_MSG_RESULT([[$enable_dauth]])
  2534. # optional: HTTP "Upgrade" support. Enabled by default
  2535. AC_MSG_CHECKING([[whether to support HTTP "Upgrade"]])
  2536. AC_ARG_ENABLE([[httpupgrade]],
  2537. AS_HELP_STRING([[--disable-httpupgrade]],
  2538. [disable HTTP "Upgrade" support]),
  2539. [AS_VAR_IF([[enable_httpupgrade]],[["no"]],[],[[enable_httpupgrade='yes']])],
  2540. [[enable_httpupgrade='yes']])
  2541. AS_VAR_IF([[enable_httpupgrade]],[["yes"]],
  2542. [
  2543. AC_DEFINE([[UPGRADE_SUPPORT]],[[1]],[Define to 1 if libmicrohttpd is compiled with HTTP Upgrade support.]) ])
  2544. AM_CONDITIONAL([ENABLE_UPGRADE], [[test "x$enable_httpupgrade" = "xyes"]])
  2545. AC_MSG_RESULT([[$enable_httpupgrade]])
  2546. AC_CACHE_CHECK([[for calloc()]], [[mhd_cv_have_func_calloc]],
  2547. [
  2548. AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  2549. #include <stdlib.h>
  2550. ]],[[void * ptr = calloc(1, 2); if (ptr) return 1;]])
  2551. ],
  2552. [[mhd_cv_have_func_calloc='yes']],
  2553. [[mhd_cv_have_func_calloc='no']]
  2554. )
  2555. ]
  2556. )
  2557. AS_VAR_IF([[mhd_cv_have_func_calloc]], [["yes"]],
  2558. [AC_DEFINE([[HAVE_CALLOC]], [[1]], [Define to 1 if you have the usable `calloc' function.])])
  2559. # Some systems have IPv6 disabled in kernel at run-time
  2560. AS_IF([[test "x${have_inet6}" = "xyes" && test "x${cross_compiling}" = "xno"]],
  2561. [
  2562. AC_CACHE_CHECK([whether IPv6 could be used for testing],[mhd_cv_ipv6_for_testing],
  2563. [
  2564. AC_RUN_IFELSE(
  2565. [
  2566. AC_LANG_SOURCE([[
  2567. #ifdef HAVE_UNISTD_H
  2568. #include <unistd.h>
  2569. #endif
  2570. #ifdef HAVE_SYS_TYPES_H
  2571. #include <sys/types.h>
  2572. #endif
  2573. #ifdef HAVE_SYS_SOCKET_H
  2574. #include <sys/socket.h>
  2575. #endif
  2576. #ifdef HAVE_WINSOCK2_H
  2577. #include <winsock2.h>
  2578. #endif
  2579. #ifdef HAVE_WS2TCPIP_H
  2580. #include <ws2tcpip.h>
  2581. #endif
  2582. #ifdef HAVE_NETINET_IN_H
  2583. #include <netinet/in.h>
  2584. #endif
  2585. #ifdef HAVE_NETINET_IP_H
  2586. #include <netinet/ip.h>
  2587. #endif
  2588. #ifdef HAVE_ARPA_INET_H
  2589. #include <arpa/inet.h>
  2590. #endif
  2591. #ifdef HAVE_NETINET_TCP_H
  2592. #include <netinet/tcp.h>
  2593. #endif
  2594. static void zr_mem(void *ptr, socklen_t size)
  2595. { char *mem = ptr; while(size--) {mem[0] = 0; mem++;} }
  2596. int main(void)
  2597. {
  2598. int ret = 30;
  2599. struct sockaddr_in6 sa;
  2600. #if !defined(_WIN32) || defined(__CYGWIN__)
  2601. int sckt;
  2602. const int invld_sckt = -1;
  2603. #else
  2604. SOCKET sckt;
  2605. const SOCKET invld_sckt = INVALID_SOCKET;
  2606. WSADATA wsa_data;
  2607. WSAStartup(MAKEWORD(2, 2), &wsa_data);
  2608. #endif
  2609. zr_mem(&sa, sizeof(sa));
  2610. sa.sin6_family = AF_INET6;
  2611. sa.sin6_port = 0;
  2612. sa.sin6_addr = in6addr_loopback;
  2613. #ifdef HAVE_STRUCT_SOCKADDR_IN6_SIN6_LEN
  2614. sa.sin6_len = sizeof(sa);
  2615. #endif
  2616. sckt = socket (PF_INET6, SOCK_STREAM, 0);
  2617. if (invld_sckt != sckt)
  2618. {
  2619. if (0 == bind (sckt, (struct sockaddr *)&sa, sizeof(sa)))
  2620. {
  2621. if (0 == listen (sckt, 1))
  2622. ret = 0;
  2623. else
  2624. ret = 1; /* listen() failed */
  2625. } else ret = 2; /* bind() failed */
  2626. #if !defined(_WIN32) || defined(__CYGWIN__)
  2627. close (sckt);
  2628. #else
  2629. closesocket (sckt);
  2630. #endif
  2631. } else ret = 3; /* socket() failed */
  2632. #if defined(_WIN32) && !defined(__CYGWIN__)
  2633. WSACleanup();
  2634. #endif
  2635. return ret;
  2636. }
  2637. ]])
  2638. ], [[mhd_cv_ipv6_for_testing="yes"]], [[mhd_cv_ipv6_for_testing="no"]], [[mhd_cv_ipv6_for_testing="no"]]
  2639. )
  2640. ]
  2641. )
  2642. ]
  2643. )
  2644. AS_VAR_IF([mhd_cv_ipv6_for_testing],["yes"],
  2645. [AC_DEFINE([[USE_IPV6_TESTING]], [[1]], [Define to 1 if your kernel supports IPv6 and IPv6 is enabled and useful for testing.])]
  2646. )
  2647. # Check for fork() and waitpid(). They are used for tests.
  2648. AC_MSG_CHECKING([[for fork()]])
  2649. mhd_have_fork_waitpid='no'
  2650. AC_LINK_IFELSE(
  2651. [
  2652. AC_LANG_PROGRAM(
  2653. [[
  2654. #ifdef HAVE_SYS_TYPES_H
  2655. #include <sys/types.h>
  2656. #endif
  2657. #ifdef HAVE_UNISTD_H
  2658. #include <unistd.h>
  2659. #endif
  2660. ]], [[
  2661. pid_t p = fork ();
  2662. if (0 == p)
  2663. return 1;
  2664. ]])
  2665. ], [
  2666. AC_DEFINE([[HAVE_FORK]], [[1]], [Define to 1 if you have the usable `fork' function.])
  2667. AC_MSG_RESULT([[yes]])
  2668. AC_MSG_CHECKING([[for waitpid()]])
  2669. AC_LINK_IFELSE(
  2670. [
  2671. AC_LANG_PROGRAM(
  2672. [[
  2673. #include <sys/wait.h>
  2674. ]], [[
  2675. pid_t p = fork ();
  2676. if (0 == p)
  2677. return 1;
  2678. waitpid (p, (void*)0, 0)
  2679. ]])
  2680. ], [
  2681. AC_DEFINE([[HAVE_WAITPID]], [[1]], [Define to 1 if you have the usable `waitpid' function.])
  2682. AC_MSG_RESULT([[yes]])
  2683. mhd_have_fork_waitpid='yes'
  2684. ],[
  2685. AC_MSG_RESULT([[no]])
  2686. ])
  2687. ],[
  2688. AC_MSG_RESULT([[no]])
  2689. ])
  2690. AM_CONDITIONAL([HAVE_FORK_WAITPID], [test "x$mhd_have_fork_waitpid" = "xyes"])
  2691. # gcov compilation
  2692. AC_MSG_CHECKING(whether to compile with support for code coverage analysis)
  2693. AC_ARG_ENABLE([coverage],
  2694. AS_HELP_STRING([--enable-coverage],
  2695. [compile the library with code coverage support]),
  2696. [use_gcov=${enableval}],
  2697. [use_gcov=no])
  2698. AC_MSG_RESULT($use_gcov)
  2699. AM_CONDITIONAL([USE_COVERAGE], [test "x$use_gcov" = "xyes"])
  2700. AX_COUNT_CPUS
  2701. AC_MSG_CHECKING([for number of CPU cores to use in tests])
  2702. AS_VAR_IF([enable_heavy_tests], ["yes"],
  2703. [
  2704. # Enable usage of many core if heavy tests are enabled
  2705. AS_IF([[test "$CPU_COUNT" -gt "32"]], [[CPU_COUNT="32"]])dnl Limit resource usage
  2706. ],
  2707. [
  2708. # Limit usage to just a few cores if heavy tests are not enabled
  2709. AS_IF([[test "$CPU_COUNT" -gt "6"]], [[CPU_COUNT="6"]])
  2710. AS_IF([[test "$CPU_COUNT" -lt "2"]], [[CPU_COUNT="2"]])
  2711. ]
  2712. )
  2713. AC_MSG_RESULT([$CPU_COUNT])
  2714. AC_MSG_CHECKING([[whether to enable debug asserts]])
  2715. AC_ARG_ENABLE([[asserts]],
  2716. AS_HELP_STRING([[--enable-asserts]],
  2717. [enable test build with debug asserts]),
  2718. [], [[enable_asserts='no']])
  2719. AS_CASE([[$enable_asserts]], [[yes]], [[:]], [[no]], [[:]], [[enable_asserts='no']])
  2720. AC_MSG_RESULT([[$enable_asserts]])
  2721. AS_VAR_IF([[enable_asserts]], [["yes"]],
  2722. [
  2723. AC_DEFINE([[_DEBUG]], [[1]], [Define to use debug asserts.])
  2724. [mhd_assert_test_prg="#include <assert.h>
  2725. int pos_val(void) {return 5;}
  2726. int neg_val(void) {return -5;}
  2727. int main(void)
  2728. { int pos_var = pos_val(), neg_var = neg_val();
  2729. assert(neg_var > pos_var); /* Must trigger assert. */
  2730. (void)pos_var; (void)neg_var;
  2731. return 0; }
  2732. "]
  2733. AC_CACHE_CHECK([[whether system assert() is available]], [mhd_cv_sys_assert_avail],
  2734. [
  2735. AC_LINK_IFELSE([AC_LANG_SOURCE([[$mhd_assert_test_prg]])],
  2736. [[mhd_cv_sys_assert_avail='yes']],
  2737. [[mhd_cv_sys_assert_avail='no']])
  2738. ]
  2739. )
  2740. AS_VAR_IF([[mhd_cv_sys_assert_avail]], [["no"]], [],
  2741. [AC_DEFINE([[HAVE_ASSERT]], [[1]], [Define if you have usable assert() and assert.h])])
  2742. AS_UNSET([mhd_assert_test_prg])
  2743. ],
  2744. [AC_DEFINE([[NDEBUG]], [[1]], [Define to disable usage of debug asserts.])]
  2745. )
  2746. AS_UNSET([enabled_sanitizers])
  2747. AM_TESTS_ENVIRONMENT=""
  2748. AM_ASAN_OPTIONS=""
  2749. AM_UBSAN_OPTIONS=""
  2750. AM_LSAN_OPTIONS=""
  2751. AS_UNSET([ASAN_OPTIONS])
  2752. AS_UNSET([UBSAN_OPTIONS])
  2753. AS_UNSET([LSAN_OPTIONS])
  2754. AC_MSG_CHECKING([whether to enable run-time sanitizers])
  2755. AC_ARG_ENABLE([sanitizers],
  2756. [AS_HELP_STRING([[--enable-sanitizers[=address,undefined,leak,user-poison]]],
  2757. [enable run-time sanitizers, specify the list of types of sanitizers to enable or ]
  2758. [leave the list empty to enable all suppoted and availabe sanitizers])],
  2759. [], [enable_sanitizers=no])
  2760. AS_IF([test "x${enable_sanitizers}" = "x"], [enable_sanitizers="auto"])
  2761. AS_VAR_IF([enable_sanitizers], ["yes"], [enable_sanitizers="auto"])
  2762. AS_IF([test "x${enable_sanitizers}" = "xno"],
  2763. [
  2764. enable_sanitizers="no"
  2765. enable_san_address="no"
  2766. enable_san_undef="no"
  2767. enable_san_leak="no"
  2768. enable_san_upoison="no"
  2769. ],
  2770. [test "x${enable_sanitizers}" = "xauto"],
  2771. [
  2772. enable_san_address="auto"
  2773. enable_san_undef="auto"
  2774. enable_san_leak="auto"
  2775. enable_san_upoison="auto"
  2776. ],
  2777. [
  2778. AS_UNSET([san])
  2779. enable_san_address="no"
  2780. enable_san_undef="no"
  2781. enable_san_leak="no"
  2782. enable_san_upoison="no"
  2783. for san in `AS_ECHO([${enable_sanitizers}]) | tr ',' ' '`
  2784. do
  2785. AS_CASE([$san],
  2786. [address], [enable_san_address="yes"],
  2787. [undefined], [enable_san_undef="yes"],
  2788. [leak], [enable_san_leak="yes"],
  2789. [user-poison|user_poison], [enable_san_upoison="yes"],
  2790. [no|yes|auto], [AC_MSG_ERROR(["$san" cannot be used with other options for --enable-sanitizers=])],
  2791. [AC_MSG_ERROR([Unknown parameter "$san" for --enable-sanitizers=])]
  2792. )
  2793. done
  2794. AS_IF([test "x${enable_san_upoison}" = "xyes" && test "x${enable_san_address}" = "xno"],
  2795. [AC_MSG_ERROR([User memory poisoning cannot be used without address sanitizer])]
  2796. )
  2797. enable_sanitizers="selected"
  2798. ]
  2799. )
  2800. AS_CASE([${enable_sanitizers}],
  2801. [selected], [AC_MSG_RESULT([selected])],
  2802. [auto], [AC_MSG_RESULT([yes, detect and use supported sanitizers])],
  2803. [AC_MSG_RESULT([no])]
  2804. )
  2805. AS_VAR_IF([enable_sanitizers], ["no"], [:],
  2806. [
  2807. AS_UNSET([san_FLAGS]) # the sanitizer flags to be added to both CFLAGS and LDFLAGS
  2808. AS_UNSET([san_CFLAGS]) # the sanitizer flags to be added to CFLAGS
  2809. saved_CFLAGS="$CFLAGS"
  2810. AC_CACHE_CHECK([whether '-fsanitize=' works for $CC],
  2811. [mhd_cv_cc_sanitizer_works],
  2812. [
  2813. CFLAGS="${saved_CFLAGS} -fsanitize=wrongFeatureName"
  2814. AC_COMPILE_IFELSE([AC_LANG_PROGRAM([],[])],
  2815. [mhd_cv_cc_sanitizer_works=no], [mhd_cv_cc_sanitizer_works=yes])
  2816. ]
  2817. )
  2818. AS_VAR_IF([mhd_cv_cc_sanitizer_works], ["yes"],
  2819. [
  2820. AS_VAR_IF([enable_san_address], ["no"], [:],
  2821. [
  2822. AC_CACHE_CHECK([for address sanitizer], [mhd_cv_cc_sanitizer_address],
  2823. [
  2824. CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=address"
  2825. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  2826. [mhd_cv_cc_sanitizer_address=yes], [mhd_cv_cc_sanitizer_address=no])
  2827. ]
  2828. )
  2829. AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"],
  2830. [
  2831. AC_DEFINE([MHD_ASAN_ACTIVE], [1], [Define to '1' if you have address sanitizer enabled])
  2832. AX_APPEND_FLAG([-fsanitize=address], [san_FLAGS])
  2833. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }address"
  2834. AS_VAR_IF([enable_san_leak], ["no"], [:],
  2835. [
  2836. AC_CACHE_CHECK([whether leak detect is not rejected by address sanitizer], [mhd_cv_cc_sanitizer_address_leak],
  2837. [
  2838. CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS}"
  2839. ASAN_OPTIONS="exitcode=88:detect_leaks=1:halt_on_error=1"
  2840. export ASAN_OPTIONS
  2841. AC_RUN_IFELSE([AC_LANG_PROGRAM([],[])],
  2842. [mhd_cv_cc_sanitizer_address_leak=yes], [mhd_cv_cc_sanitizer_address_leak=no],
  2843. [
  2844. # Cross-compiling with sanitizers?
  2845. mhd_cv_cc_sanitizer_address_leak='assuming no'
  2846. ]
  2847. )
  2848. AS_UNSET([ASAN_OPTIONS])
  2849. ]
  2850. )
  2851. ]
  2852. )
  2853. AC_CACHE_CHECK([for pointer compare sanitizer], [mhd_cv_cc_sanitizer_pointer_compare],
  2854. [
  2855. CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-compare"
  2856. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  2857. [mhd_cv_cc_sanitizer_pointer_compare=yes], [mhd_cv_cc_sanitizer_pointer_compare=no])
  2858. ]
  2859. )
  2860. AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_compare],["yes"],
  2861. [
  2862. AX_APPEND_FLAG([-fsanitize=pointer-compare], [san_FLAGS])
  2863. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer compare"
  2864. ]
  2865. )
  2866. AC_CACHE_CHECK([for pointer subtract sanitizer], [mhd_cv_cc_sanitizer_pointer_subtract],
  2867. [
  2868. CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} -fsanitize=pointer-subtract"
  2869. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  2870. [mhd_cv_cc_sanitizer_pointer_subtract=yes], [mhd_cv_cc_sanitizer_pointer_subtract=no])
  2871. ]
  2872. )
  2873. AS_VAR_IF([mhd_cv_cc_sanitizer_pointer_subtract],["yes"],
  2874. [
  2875. AX_APPEND_FLAG([-fsanitize=pointer-subtract], [san_FLAGS])
  2876. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }pointer subtract"
  2877. ]
  2878. )
  2879. AS_VAR_IF([enable_san_upoison], ["no"], [:],
  2880. [
  2881. AC_CHECK_HEADERS([sanitizer/asan_interface.h], [], [], [AC_INCLUDES_DEFAULT])
  2882. AS_IF([test "x${mhd_cv_cc_sanitizer_pointer_compare}" = "xyes" && test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes"],
  2883. [
  2884. AC_CACHE_CHECK([whether '__attribute__((no_sanitize("pointer-compare","pointer-subtract")))' works], [mhd_cv_func_attribute_nosanitize_ptr],
  2885. [
  2886. ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
  2887. export ASAN_OPTIONS
  2888. CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS}"
  2889. AC_RUN_IFELSE(
  2890. [
  2891. AC_LANG_PROGRAM(
  2892. [[
  2893. #include <stdlib.h>
  2894. __attribute__((no_sanitize("pointer-compare","pointer-subtract")))
  2895. int ptr_process(void *ptr1, void *ptr2)
  2896. {
  2897. if ((char*)ptr1 <= (char*)ptr2)
  2898. return (int) ((char*)ptr2 - (char*)ptr1);
  2899. return (int) ((char*)ptr1 - (char*)ptr2);
  2900. }
  2901. ]],
  2902. [[
  2903. int *a = (int*) malloc (sizeof(int)*4);
  2904. int *b = (int*) malloc (sizeof(long)*6);
  2905. int c = ptr_process(a, b);
  2906. if (c)
  2907. {
  2908. free (b);
  2909. free (a);
  2910. return 0;
  2911. }
  2912. free (a);
  2913. free (b);
  2914. ]]
  2915. )
  2916. ],
  2917. [mhd_cv_func_attribute_nosanitize_ptr=yes], [mhd_cv_func_attribute_nosanitize_ptr=no],
  2918. [
  2919. # Cross-compiling with sanitizers??
  2920. mhd_cv_func_attribute_nosanitize_ptr='assuming no'
  2921. ]
  2922. )
  2923. AS_UNSET([ASAN_OPTIONS])
  2924. ]
  2925. )
  2926. AS_VAR_IF([mhd_cv_func_attribute_nosanitize_ptr], ["yes"],
  2927. [AC_DEFINE([FUNC_ATTR_PTRCOMPARE_WOKRS],[1],[Define to '1' if '__attribute__((no_sanitize("pointer-compare","pointer-subtract")))' works])],
  2928. [
  2929. AC_CACHE_CHECK([whether '__attribute__((no_sanitize("address")))' works for pointers compare], [mhd_cv_func_attribute_nosanitize_addr],
  2930. [
  2931. ASAN_OPTIONS="exitcode=88:detect_invalid_pointer_pairs=3:halt_on_error=1"
  2932. export ASAN_OPTIONS
  2933. CFLAGS="${saved_CFLAGS} ${san_CFLAGS} ${san_FLAGS} ${errattr_CFLAGS}"
  2934. AC_RUN_IFELSE(
  2935. [
  2936. AC_LANG_PROGRAM(
  2937. [[
  2938. #include <stdlib.h>
  2939. __attribute__((no_sanitize("address")))
  2940. int ptr_process(void *ptr1, void *ptr2)
  2941. {
  2942. if ((char*)ptr1 <= (char*)ptr2)
  2943. return (int) ((char*)ptr2 - (char*)ptr1);
  2944. return (int) ((char*)ptr1 - (char*)ptr2);
  2945. }
  2946. ]],
  2947. [[
  2948. int *a = (int*) malloc (sizeof(int)*4);
  2949. int *b = (int*) malloc (sizeof(long)*6);
  2950. int c = ptr_process(a, b);
  2951. if (c)
  2952. {
  2953. free (b);
  2954. free (a);
  2955. return 0;
  2956. }
  2957. free (a);
  2958. free (b);
  2959. ]]
  2960. )
  2961. ],
  2962. [mhd_cv_func_attribute_nosanitize_addr=yes], [mhd_cv_func_attribute_nosanitize_addr=no],
  2963. [
  2964. # Cross-compiling with sanitizers??
  2965. mhd_cv_func_attribute_nosanitize_addr='assuming no'
  2966. ]
  2967. )
  2968. AS_UNSET([ASAN_OPTIONS])
  2969. ]
  2970. )
  2971. AS_VAR_IF([mhd_cv_func_attribute_nosanitize_addr], ["yes"],
  2972. [AC_DEFINE([FUNC_ATTR_NOSANITIZE_WORKS],[1],[Define to '1' if '__attribute__((no_sanitize("address")))' works for pointers compare])]
  2973. )
  2974. ]
  2975. )
  2976. ]
  2977. )
  2978. ]
  2979. )
  2980. ]
  2981. )
  2982. AS_IF([test "x${enable_san_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_address}" != "xyes"],
  2983. [AC_MSG_ERROR([Address sanitizer cannot be enabled])]
  2984. )
  2985. enable_san_address="${mhd_cv_cc_sanitizer_address}"
  2986. ]
  2987. )
  2988. AS_VAR_IF([enable_san_undef], ["no"], [:],
  2989. [
  2990. dnl Ensure that '#' will be processed correctly
  2991. [
  2992. test_undf_prog='
  2993. #include <stdio.h>
  2994. void func_out_b(char *arr)
  2995. {
  2996. arr[0] = 0;
  2997. arr[16] = 2;
  2998. }
  2999. unsigned int int_deref(void *ptr)
  3000. {
  3001. return (*((int*)ptr)) + 2;
  3002. }
  3003. int func1(void)
  3004. {
  3005. char chr[16];
  3006. func_out_b (chr);
  3007. return int_deref(chr + 1) + int_deref(chr + 2);
  3008. }
  3009. int main(void)
  3010. {
  3011. unsigned long ulvar;
  3012. signed char ch1;
  3013. ulvar = -1 * func1();
  3014. ch1 = ulvar * 6UL;
  3015. printf("%lu\n", ulvar + ch1);
  3016. return 0;
  3017. }
  3018. '
  3019. ]
  3020. AC_CACHE_CHECK([for undefined behavior sanitizer], [mhd_cv_cc_sanitizer_undefined],
  3021. [
  3022. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined"
  3023. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  3024. [mhd_cv_cc_sanitizer_undefined=yes], [mhd_cv_cc_sanitizer_undefined=no])
  3025. ]
  3026. )
  3027. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined],["yes"],
  3028. [
  3029. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  3030. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  3031. ],
  3032. [
  3033. AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-undefined-trap-on-error'], [mhd_cv_cc_sanitizer_undefined_trap],
  3034. [
  3035. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-undefined-trap-on-error"
  3036. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  3037. [mhd_cv_cc_sanitizer_undefined_trap=yes], [mhd_cv_cc_sanitizer_undefined_trap=no])
  3038. ]
  3039. )
  3040. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap], ["yes"],
  3041. [
  3042. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  3043. AX_APPEND_FLAG([-fsanitize-undefined-trap-on-error], [san_FLAGS])
  3044. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  3045. AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited])
  3046. ],
  3047. [
  3048. AS_IF([test -z "${enabled_sanitizers}"],
  3049. [
  3050. # Last resort
  3051. AC_CACHE_CHECK([for undefined behavior sanitizer with '-fsanitize-trap=all'], [mhd_cv_cc_sanitizer_undefined_trap_all],
  3052. [
  3053. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all"
  3054. AC_LINK_IFELSE([AC_LANG_SOURCE([${test_undf_prog}])],
  3055. [mhd_cv_cc_sanitizer_undefined_trap_all=yes], [mhd_cv_cc_sanitizer_undefined_trap_all=no])
  3056. ]
  3057. )
  3058. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined_trap_all],["yes"],
  3059. [
  3060. AX_APPEND_FLAG([-fsanitize=undefined], [san_FLAGS])
  3061. AX_APPEND_FLAG([-fsanitize-trap=all], [san_FLAGS])
  3062. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=undefined -fsanitize-trap=all"
  3063. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }undefined"
  3064. AC_MSG_WARN([Enabled sanitizer without run-time library, error reporting will be limited])
  3065. ]
  3066. )
  3067. ]
  3068. )
  3069. ]
  3070. )
  3071. ]
  3072. )
  3073. AS_CASE(["$enabled_sanitizers"], [*undefined],
  3074. [
  3075. AS_VAR_IF([mhd_cv_cc_sanitizer_undefined], ["yes"],[],
  3076. [
  3077. # A workaround for broken clang which is trying to use UBSan lib
  3078. # even when instructed to not use it
  3079. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}"
  3080. AX_APPEND_LINK_FLAGS([-fsanitize-trap=implicit-conversion],
  3081. [san_FLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])])
  3082. ]
  3083. )
  3084. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}"
  3085. AX_APPEND_LINK_FLAGS([-fsanitize=bounds-strict -fsanitize=local-bounds -fsanitize=implicit-conversion -fsanitize=nullability-arg],
  3086. [san_CFLAGS], [], [AC_LANG_SOURCE([${test_undf_prog}])])
  3087. ]
  3088. )
  3089. AS_UNSET([test_undf_prog])
  3090. AS_CASE(["$enabled_sanitizers"],
  3091. [*undefined], [enable_san_undef="yes"],
  3092. [
  3093. AS_VAR_IF([enable_san_undef], [yes], [AC_MSG_ERROR([Undefined behavior sanitizer cannot be enabled])])
  3094. enable_san_undef="no"
  3095. ]
  3096. )
  3097. ]
  3098. )
  3099. AS_VAR_IF([enable_san_leak], ["no"], [:],
  3100. [
  3101. AC_CACHE_CHECK([for leak sanitizer], [mhd_cv_cc_sanitizer_leak],
  3102. [
  3103. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS} -fsanitize=leak"
  3104. AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
  3105. [mhd_cv_cc_sanitizer_leak=yes], [mhd_cv_cc_sanitizer_leak=no])
  3106. ]
  3107. )
  3108. AS_VAR_IF([mhd_cv_cc_sanitizer_leak],["yes"],
  3109. [
  3110. AX_APPEND_FLAG([-fsanitize=leak], [san_FLAGS])
  3111. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }leak"
  3112. ]
  3113. )
  3114. AS_IF([test "x${enable_san_leak}" = "xyes" && test "x${mhd_cv_cc_sanitizer_leak}" != "xyes"],
  3115. [AC_MSG_ERROR([User poison cannot be enabled])]
  3116. )
  3117. enable_san_leak="${mhd_cv_cc_sanitizer_leak}"
  3118. ]
  3119. )
  3120. AS_IF([test -z "${enabled_sanitizers}"],
  3121. [AC_MSG_ERROR([cannot find any sanitizer supported by $CC])])
  3122. AS_VAR_IF([enable_san_upoison], ["no"], [:],
  3123. [
  3124. AC_MSG_CHECKING([whether to enable user memory poisoning])
  3125. AS_IF([test "x${mhd_cv_cc_sanitizer_address}" = "xyes" && test "x${mhd_cv_cc_sanitizer_pointer_compare}" = "xyes" && \
  3126. test "x${ac_cv_header_sanitizer_asan_interface_h}" = "xyes" && \
  3127. (test "x${mhd_cv_func_attribute_nosanitize_ptr}" = "xyes" || test "x${mhd_cv_func_attribute_nosanitize_addr}" = "xyes")],
  3128. [
  3129. AC_DEFINE([MHD_ASAN_POISON_ACTIVE], [1], [Define to '1' if user memory poison is used])
  3130. enabled_sanitizers="${enabled_sanitizers}${enabled_sanitizers:+, }user-poison"
  3131. enable_san_upoison="yes"
  3132. AC_MSG_RESULT([yes])
  3133. ],
  3134. [
  3135. AC_MSG_RESULT([no])
  3136. AS_VAR_IF([enable_san_upoison], ["yes"],
  3137. [AC_MSG_ERROR([User memory poisoning cannot be enabled])])
  3138. enable_san_upoison="no"
  3139. ]
  3140. )
  3141. ]
  3142. )
  3143. AS_VAR_IF([enable_san_address], ["yes"],
  3144. [
  3145. AS_VAR_IF([mhd_cv_cc_sanitizer_address],["yes"],
  3146. [
  3147. AX_APPEND_FLAG([-D_FORTIFY_SOURCE=0], [san_CFLAGS])
  3148. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}"
  3149. AX_APPEND_COMPILE_FLAGS([-Wp,-U_FORTIFY_SOURCE], [san_CFLAGS])
  3150. ],
  3151. [AC_MSG_WARN([$CC does not support address sanitizer])]
  3152. )
  3153. ]
  3154. )
  3155. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}"
  3156. # Always stop on sanitizer error
  3157. AX_APPEND_COMPILE_FLAGS([-fno-sanitize-recover=all], [san_CFLAGS])
  3158. # Get a better output for sanitizers error reporting
  3159. AX_APPEND_COMPILE_FLAGS([-fno-omit-frame-pointer -fno-optimize-sibling-calls],
  3160. [san_CFLAGS])
  3161. AS_VAR_IF([enable_san_address], ["yes"],
  3162. [
  3163. AM_ASAN_OPTIONS="exitcode=88:strict_string_checks=1:detect_stack_use_after_return=1"
  3164. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:check_initialization_order=1:strict_init_order=1:redzone=64"
  3165. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:max_free_fill_size=1024:detect_invalid_pointer_pairs=3"
  3166. AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:handle_ioctl=1:halt_on_error=1"
  3167. AS_VAR_IF([enable_san_upoison], ["yes"], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:allow_user_poisoning=1"])
  3168. AS_VAR_IF([enable_san_leak], ["yes"],
  3169. [AS_VAR_IF([mhd_cv_cc_sanitizer_address_leak], ["yes"],
  3170. [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=1"])
  3171. ], [AM_ASAN_OPTIONS="${AM_ASAN_OPTIONS}:detect_leaks=0"]
  3172. )
  3173. ]
  3174. )
  3175. AS_VAR_IF([enable_san_undef], [yes],
  3176. [AM_UBSAN_OPTIONS="exitcode=87:print_stacktrace=1:halt_on_error=1"])
  3177. AS_VAR_IF([enable_san_leak], ["yes"],
  3178. [AM_LSAN_OPTIONS="use_unaligned=1"]
  3179. )
  3180. AM_TESTS_ENVIRONMENT='\
  3181. ASAN_OPTIONS="$(AM_ASAN_OPTIONS)" ; export ASAN_OPTIONS ; \
  3182. UBSAN_OPTIONS="$(AM_UBSAN_OPTIONS)" ; export UBSAN_OPTIONS ; \
  3183. LSAN_OPTIONS="$(AM_LSAN_OPTIONS)" ; export LSAN_OPTIONS ;'
  3184. ]
  3185. )
  3186. CFLAGS="${saved_CFLAGS} ${san_FLAGS} ${san_CFLAGS}"
  3187. AS_UNSET([saved_CFLAGS])
  3188. ]
  3189. )
  3190. AM_CONDITIONAL([USE_SANITIZERS],
  3191. [test -n "$enabled_sanitizers" && test "x$mhd_cv_cc_sanitizer_works" = "xyes"])
  3192. AC_SUBST([AM_ASAN_OPTIONS])
  3193. AC_SUBST([AM_UBSAN_OPTIONS])
  3194. AC_SUBST([AM_LSAN_OPTIONS])
  3195. AC_SUBST([AM_TESTS_ENVIRONMENT])
  3196. MHD_LIB_LDFLAGS="$MHD_LIB_LDFLAGS -export-dynamic -no-undefined"
  3197. AC_SUBST([CPU_COUNT])
  3198. AC_SUBST([HEAVY_TESTS_NOTPARALLEL])
  3199. AC_SUBST(MHD_LIB_CPPFLAGS)
  3200. AC_SUBST(MHD_LIB_CFLAGS)
  3201. AC_SUBST(MHD_LIB_LDFLAGS)
  3202. AC_SUBST(MHD_LIBDEPS)
  3203. AC_SUBST(MHD_TLS_LIB_CPPFLAGS)
  3204. AC_SUBST(MHD_TLS_LIB_CFLAGS)
  3205. AC_SUBST(MHD_TLS_LIB_LDFLAGS)
  3206. AC_SUBST(MHD_TLS_LIBDEPS)
  3207. # for pkg-config
  3208. AC_SUBST([MHD_REQ_PRIVATE])
  3209. AC_SUBST([MHD_LIBDEPS_PKGCFG])
  3210. AC_SUBST(CPPFLAGS)
  3211. AC_SUBST(LIBS)
  3212. AC_SUBST(LDFLAGS)
  3213. # Used for 'po' directory staff
  3214. AC_SUBST([ac_configure_args])
  3215. AC_SUBST([EMPTY_VAR], [[]])
  3216. # We define the paths here, because MinGW/GCC expands paths
  3217. # passed through the command line ("-DDIR=..."). This would
  3218. # lead to hard-coded paths ("C:\mingw\mingw\bin...") that do
  3219. # not contain the actual installation.
  3220. AC_DEFINE_DIR([MHD_PLUGIN_INSTALL_PREFIX], [libdir/libmicrohttpd], [tls plugins])
  3221. # should experimental code be compiled (code that may not yet compile)?
  3222. AC_MSG_CHECKING(whether to compile experimental code)
  3223. AC_ARG_ENABLE([experimental],
  3224. [AS_HELP_STRING([--enable-experimental], [enable compiling experimental code])],
  3225. [enable_experimental=${enableval}],
  3226. [enable_experimental=no])
  3227. AC_MSG_RESULT($enable_experimental)
  3228. AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test "x$enable_experimental" = "xyes"])
  3229. AC_CONFIG_FILES([libmicrohttpd.pc
  3230. w32/common/microhttpd_dll_res_vc.rc
  3231. Makefile
  3232. contrib/Makefile
  3233. doc/Makefile
  3234. doc/doxygen/libmicrohttpd.doxy
  3235. doc/doxygen/Makefile
  3236. doc/examples/Makefile
  3237. m4/Makefile
  3238. src/Makefile
  3239. src/include/Makefile
  3240. src/lib/Makefile
  3241. src/microhttpd/Makefile
  3242. src/microhttpd_ws/Makefile
  3243. src/examples/Makefile
  3244. src/testcurl/Makefile
  3245. src/testcurl/https/Makefile
  3246. src/testzzuf/Makefile])
  3247. AC_OUTPUT
  3248. # Finally: summary
  3249. AS_IF([test "x$enable_curl" != "xyes"],
  3250. [MSG_CURL="no, many unit tests will not run"],
  3251. [MSG_CURL="yes"])
  3252. AS_VAR_IF([os_is_windows], ["yes"],
  3253. [os_ver_msg="
  3254. Target W32 ver: ${mhd_w32_ver_msg}"], [AS_UNSET([[os_ver_msg]])])
  3255. AC_MSG_NOTICE([GNU libmicrohttpd ${PACKAGE_VERSION} Configuration Summary:
  3256. Target directory: ${prefix}
  3257. Cross-compiling: ${cross_compiling}
  3258. Operating System: ${mhd_host_os}${os_ver_msg}
  3259. Shutdown of listening socket triggers select: ${mhd_cv_host_shtdwn_trgr_select}
  3260. Inter-thread comm: ${use_itc}
  3261. poll support: ${enable_poll=no}
  3262. epoll support: ${enable_epoll=no}
  3263. sendfile used: ${found_sendfile}
  3264. HTTPS support: ${MSG_HTTPS}
  3265. Threading lib: ${USE_THREADS}
  3266. Use thread names: ${enable_thread_names}
  3267. Use debug asserts: ${enable_asserts}
  3268. Use sanitizers: ${enabled_sanitizers:=no}
  3269. Messages: ${enable_messages}
  3270. Gettext: ${have_po}
  3271. Basic auth.: ${enable_bauth}
  3272. Digest auth.: ${enable_dauth}
  3273. HTTP "Upgrade": ${enable_httpupgrade}
  3274. Postproc: ${enable_postprocessor}
  3275. Build docs: ${enable_doc}
  3276. Build examples: ${enable_examples}
  3277. Test with libcurl: ${MSG_CURL}
  3278. ])
  3279. AS_IF([test "x$enable_https" = "xyes"],
  3280. [AC_MSG_NOTICE([HTTPS subsystem configuration:
  3281. License : LGPLv2.1+ only
  3282. ])],
  3283. [AC_MSG_NOTICE([
  3284. License : LGPLv2.1+ or eCos
  3285. ])])
  3286. AS_IF([test "x$enable_bauth" != "xyes" || \
  3287. test "x$enable_dauth" != "xyes" || \
  3288. test "x$enable_httpupgrade" != "xyes" || \
  3289. test "x$enable_postprocessor" != "xyes"],
  3290. [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.])])