configure.ac 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. # -*- Autoconf -*-
  2. # Process this file with autoconf to produce a configure script.
  3. m4_define([MAJOR_VERSION], 1)
  4. m4_define([MINOR_VERSION], 7)
  5. m4_define([MICRO_VERSION], 0)
  6. AC_PREREQ(2.59)
  7. AC_INIT([klish],
  8. [MAJOR_VERSION.MINOR_VERSION.MICRO_VERSION],
  9. [serj.kalichev at gmail dot com])
  10. AC_CONFIG_AUX_DIR(aux_scripts)
  11. AC_CONFIG_MACRO_DIR([m4])
  12. # Check for system extensions (_POSIX_THREAD_SEMANTICS for Solaris)
  13. AC_USE_SYSTEM_EXTENSIONS
  14. # Checks for programs.
  15. AC_PROG_CC
  16. AC_LIBTOOL_WIN32_DLL
  17. AC_PROG_LIBTOOL
  18. AC_CONFIG_HEADERS([config.h])
  19. AM_INIT_AUTOMAKE(subdir-objects)
  20. AM_PROG_CC_C_O
  21. # needed to handle 64-bit architecture
  22. AC_CHECK_SIZEOF(int)
  23. AC_CHECK_SIZEOF(long)
  24. AC_CHECK_SIZEOF(size_t)
  25. #########################################
  26. # See if linker supports version scripts
  27. #########################################
  28. # Check if LD supports linker scripts,
  29. # and define automake conditional HAVE_LD_VERSION_SCRIPT if so.
  30. AC_ARG_ENABLE([ld-version-script],
  31. AS_HELP_STRING([--enable-ld-version-script],
  32. [enable linker version script (default is enabled when possible)]),
  33. [have_ld_version_script=$enableval], [])
  34. if test -z "$have_ld_version_script"; then
  35. AC_MSG_CHECKING([if LD -Wl,--version-script works])
  36. save_LDFLAGS="$LDFLAGS"
  37. LDFLAGS="$LDFLAGS -Wl,--version-script=conftest.map"
  38. cat > conftest.map <<EOF
  39. VERS_1 {
  40. global: sym;
  41. };
  42. VERS_2 {
  43. global: sym;
  44. } VERS_1;
  45. EOF
  46. AC_LINK_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])],
  47. [have_ld_version_script=yes], [have_ld_version_script=no])
  48. rm -f conftest.map
  49. LDFLAGS="$save_LDFLAGS"
  50. AC_MSG_RESULT($have_ld_version_script)
  51. fi
  52. AM_CONDITIONAL(HAVE_LD_VERSION_SCRIPT, test "$have_ld_version_script" = "yes")
  53. ################################
  54. # Deal with debugging options
  55. ################################
  56. AC_ARG_ENABLE(debug,
  57. [AS_HELP_STRING([--enable-debug],
  58. [Turn on debugging including asserts [default=no]])],
  59. [],
  60. [enable_debug=no])
  61. AM_CONDITIONAL(DEBUG,test x$enable_debug = xyes)
  62. ################################
  63. # Check for Lua support
  64. ################################
  65. AC_ARG_WITH(lua,
  66. [AS_HELP_STRING([--with-lua=DIR],
  67. [Build Lua ACTION plugin [default=no]])],
  68. [use_lua=$withval],
  69. [use_lua=no])
  70. AM_CONDITIONAL(WITH_LUA,test x$use_lua != xno)
  71. if test x$use_lua != xno; then
  72. if test x$use_lua != xyes; then
  73. CPPFLAGS="${CPPFLAGS} -I$use_lua/include"
  74. LDFLAGS="${LDFLAGS} -L$use_lua/lib"
  75. fi
  76. LUA_VERSION="5.1"
  77. AX_LUA_HEADERS()
  78. AX_LUA_LIBS()
  79. fi
  80. ################################
  81. # Check for the roxml library
  82. ################################
  83. AC_ARG_WITH(libroxml,
  84. [AS_HELP_STRING([--with-libroxml=DIR],
  85. [Use roxml as the XML parser implementation [default=no]])],
  86. [use_roxml=$withval],
  87. [use_roxml=no])
  88. AC_ARG_WITH(libexpat,
  89. [AS_HELP_STRING([--with-libexpat=DIR],
  90. [Use expat as the XML parser implementation [default=no]])],
  91. [use_expat=$withval],
  92. [use_expat=no])
  93. AC_ARG_WITH(libxml2,
  94. [AS_HELP_STRING([--with-libxml2=DIR],
  95. [Use libxml2 as the XML parser implementation [default=no]])],
  96. [use_libxml2=$withval],
  97. [use_libxml2=no])
  98. # select the default xml backend
  99. sel_xml_backends=""
  100. xml_backend=""
  101. found_xml_backend=""
  102. count_xml_backends=0
  103. if test "x$use_libxml2" != "xno"; then
  104. sel_xml_backends="$sel_xml_backends libxml2"
  105. xml_backend="libxml2"
  106. count_xml_backends=$((count_xml_backends + 1))
  107. fi
  108. if test "x$use_roxml" != "xno"; then
  109. sel_xml_backends="$sel_xml_backends roxml"
  110. xml_backend="roxml"
  111. count_xml_backends=$((count_xml_backends + 1))
  112. fi
  113. if test "x$use_expat" != "xno"; then
  114. sel_xml_backends="$sel_xml_backends expat"
  115. xml_backend="expat"
  116. count_xml_backends=$((count_xml_backends + 1))
  117. fi
  118. if test $count_xml_backends -gt 1; then
  119. AC_MSG_WARN([Multiple XML backend has been selected ($sel_xml_backends). I choose $xml_backend])
  120. fi
  121. if test "x$xml_backend" = "x"; then
  122. xml_backend="auto"
  123. AC_MSG_WARN([No XML backend has been selected: auto check])
  124. fi
  125. case x$xml_backend in
  126. xroxml)
  127. use_libxml2="no"
  128. use_expat="no"
  129. ;;
  130. xlibxml2)
  131. use_roxml="no"
  132. use_expat="no"
  133. ;;
  134. xexpat)
  135. use_libxml2="no"
  136. use_roxml="no"
  137. ;;
  138. esac
  139. XML_LDFLAGS=""
  140. XML_CFLAGS=""
  141. XML_LIBS=""
  142. if test "$xml_backend" = "expat" -o "$xml_backend" = "auto"; then
  143. if test "$xml_backend" = "auto"; then
  144. # on auto select, we try to detect the library
  145. use_expat="yes"
  146. fi
  147. case x$use_expat in
  148. xyes)
  149. # we choose to NOT rely on pkg-config on this one. Instead, we
  150. # check for the library and the header file - that should be
  151. # enough.
  152. AC_CHECK_HEADER([expat.h],
  153. [expat_h_found=yes],
  154. [expat_h_found=no],
  155. [/* force include check */])
  156. if test "x$expat_h_found" != "xyes"; then
  157. AC_CHECK_HEADER([bsdxml.h],
  158. [expat_h_found=yes],
  159. [expat_h_found=no],
  160. [/* force include check */])
  161. if test "x$expat_h_found" != "xyes"; then
  162. if test "$xml_backend" = "auto"; then
  163. AC_MSG_WARN([cannot find <expat.h> header file])
  164. else
  165. AC_MSG_ERROR([cannot find <expat.h> header file])
  166. fi
  167. fi
  168. fi
  169. XML_CFLAGS=""
  170. AC_CHECK_LIB([expat],
  171. [XML_ParserCreate],
  172. [expat_lib_found=yes],
  173. [expat_lib_found=no],
  174. [])
  175. if test "x$expat_lib_found" != "xyes"; then
  176. AC_CHECK_LIB([bsdxml],
  177. [XML_ParserCreate],
  178. [expat_lib_found=yes],
  179. [expat_lib_found=no],
  180. [])
  181. if test "x$expat_lib_found" != "xno"; then
  182. XML_LIBS="-lbsdxml"
  183. AC_DEFINE([HAVE_LIB_BSDXML],
  184. [],
  185. [libbsdxml-based XML backend])
  186. else
  187. if test "$xml_backend" = "auto"; then
  188. AC_MSG_WARN([cannot find expat library])
  189. else
  190. AC_MSG_ERROR([cannot find expat library])
  191. fi
  192. fi
  193. else
  194. XML_LIBS="-lexpat"
  195. fi
  196. XML_LDFLAGS=""
  197. AC_DEFINE([HAVE_LIB_EXPAT],
  198. [],
  199. [libexpat-based XML backend])
  200. xml_backend="found"
  201. found_xml_backend="expat"
  202. ;;
  203. *)
  204. # this is probably broken. We consider that the user supplied path is
  205. # a non-standard path. But we're not going to check anything.
  206. AC_MSG_WARN([--with-expat=DIR is probably broken, just trying])
  207. XML_LDFLAGS="-L${use_expat}/lib"
  208. XML_CFLAGS="-I${use_expat}/include"
  209. XML_LIBS="-lexpat"
  210. AC_MSG_CHECKING([for expat support])
  211. AC_MSG_RESULT([yes])
  212. AC_MSG_NOTICE([headers for expat hopefully in ${use_expat}/include])
  213. AC_MSG_NOTICE([library expat hopefully in ${use_expat}/lib])
  214. AC_DEFINE([HAVE_LIB_EXPAT],
  215. [],
  216. [expat-based XML backend])
  217. xml_backend="found"
  218. found_xml_backend="expat"
  219. ;;
  220. esac
  221. else
  222. AC_MSG_CHECKING([for libexpat support])
  223. AC_MSG_RESULT([no])
  224. fi
  225. if test "$xml_backend" = "roxml" -o "$xml_backend" = "auto"; then
  226. if test "$xml_backend" = "auto"; then
  227. # on auto select, we try to detect the library
  228. use_roxml="yes"
  229. fi
  230. case x$use_roxml in
  231. xyes)
  232. # we choose to NOT rely on pkg-config on this one. We may do it as
  233. # libroxml provides a .pc file but some environment (both cross-compile
  234. # or native environment) may lack this support. The good thing is that
  235. # it doesn't add much complexity to the configure.ac file (and we
  236. # may move these tests to another m4 file later).
  237. # the header is installed in the standard path
  238. AC_CHECK_HEADER([roxml.h],
  239. [roxml_h_found=yes],
  240. [roxml_h_found=no],
  241. [/* force include check */])
  242. if test "x$roxml_h_found" != "xyes"; then
  243. if test "$xml_backend" = "auto"; then
  244. AC_MSG_WARN([cannot find <roxml.h> header file])
  245. else
  246. AC_MSG_ERROR([cannot find <roxml.h> header file])
  247. fi
  248. fi
  249. XML_CFLAGS=""
  250. # the library is installed in the standard path
  251. AC_CHECK_LIB([roxml],
  252. [roxml_load_doc],
  253. [roxml_lib_found=yes],
  254. [roxml_lib_found=no],
  255. [])
  256. if test "x$roxml_lib_found" != "xyes"; then
  257. if test "$xml_backend" = "auto"; then
  258. AC_MSG_WARN([cannot find roxml library])
  259. else
  260. AC_MSG_ERROR([cannot find roxml library])
  261. fi
  262. fi
  263. XML_LDFLAGS=""
  264. XML_LIBS="-lroxml"
  265. AC_DEFINE([HAVE_LIB_ROXML],
  266. [],
  267. [libroxml-based XML backend])
  268. xml_backend="found"
  269. found_xml_backend="roxml"
  270. ;;
  271. *)
  272. # first, we check if we're not looking for an alternate include
  273. # directory -for example, if the user feeds the script with the
  274. # option --with-roxml=/usr/local
  275. # NOTE: we search for include/roxml.h and inc/roxml.h to defeat
  276. # the caching algorithm of the configure script. If someone knows
  277. # a better way, please do not hesitate
  278. roxml_CFLAGS="$CFLAGS"
  279. CFLAGS="$CFLAGS -I${use_roxml}"
  280. AC_CHECK_HEADER([include/roxml.h],
  281. [roxml_h_found=yes],
  282. [roxml_h_found=no],
  283. [/* force include check */])
  284. if test "x$roxml_h_found" = "xno"; then
  285. # the directory might be a source directory, so check
  286. # if the include file is to be found here
  287. AC_CHECK_HEADER([inc/roxml.h],
  288. [roxml_h_found=yes],
  289. [roxml_h_found=no],
  290. [/* force include check */])
  291. if test "x$roxml_h_found" = "xno"; then
  292. if test "$xml_backend" = "auto"; then
  293. AC_MSG_WARN([cannot find <roxml.h> header file])
  294. else
  295. AC_MSG_ERROR([cannot find <roxml.h> header file])
  296. fi
  297. fi
  298. XML_CFLAGS="-I${use_roxml}/inc"
  299. AC_MSG_NOTICE([header file <roxml.h> found in ${use_roxml}/inc])
  300. else
  301. XML_CFLAGS="-I${use_roxml}/include"
  302. AC_MSG_NOTICE([header file <roxml.h> found in ${use_roxml}/include])
  303. fi
  304. CFLAGS="$roxml_CFLAGS"
  305. # we're doing both previous checks, but we are trying to find a library
  306. # now, so the check themselves are a bit different
  307. # NOTE: we search for roxml_load_doc and roxml_close to defeat
  308. # the caching algorithm of the configure script. If someone knows
  309. # a better way, please do not hesitate.
  310. roxml_LDFLAGS="$LDFLAGS"
  311. LDFLAGS="$LDFLAGS -L${use_roxml}/lib"
  312. AC_CHECK_LIB([roxml],
  313. [roxml_load_doc],
  314. [roxml_lib_found=yes],
  315. [roxml_lib_found=no],
  316. [])
  317. LDFLAGS=$roxml_LDFLAGS
  318. if test "x$roxml_lib_found" = "xno"; then
  319. LDFLAGS="$LDFLAGS -L${use_roxml}"
  320. AC_CHECK_LIB([roxml],
  321. [roxml_close],
  322. [roxml_lib_found=yes],
  323. [roxml_lib_found=no],
  324. [])
  325. LDFLAGS=$roxml_LDFLAGS
  326. if test "x$roxml_lib_found" = "xno"; then
  327. if test "$xml_backend" = "auto"; then
  328. AC_MSG_WARN([cannot find roxml library])
  329. else
  330. AC_MSG_ERROR([cannot find roxml library])
  331. fi
  332. fi
  333. XML_LDFLAGS="-L${use_roxml}"
  334. XML_LIBS="-lroxml"
  335. AC_MSG_NOTICE([library libroxml found in ${use_roxml}])
  336. else
  337. XML_LDFLAGS="-L${use_roxml}/lib"
  338. XML_LIBS="-lroxml"
  339. AC_MSG_NOTICE([library libroxml found in ${use_roxml}/lib])
  340. fi
  341. AC_DEFINE([HAVE_LIB_ROXML],
  342. [],
  343. [libroxml-based XML backend])
  344. xml_backend="found"
  345. found_xml_backend="roxml"
  346. ;;
  347. esac
  348. else
  349. AC_MSG_CHECKING([for libroxml support])
  350. AC_MSG_RESULT([no])
  351. fi
  352. if test "$xml_backend" = "libxml2" -o "$xml_backend" = "auto"; then
  353. if test "$xml_backend" = "auto"; then
  354. # on auto select, we try to detect the library
  355. use_libxml2="yes"
  356. fi
  357. case x$use_libxml2 in
  358. xyes)
  359. # I would love to avoid using pkg-config (which may not be available on
  360. # some compilation environment) but doing so really add a lot of
  361. # complexity to the system, as the headers don't lie in a standard
  362. # directory (they lie in a subdirectory of a standard include directory;
  363. # not the same thing for configure scripts).
  364. XML_CFLAGS="`pkg-config libxml-2.0 --cflags`"
  365. XML_LDFLAGS="`pkg-config libxml-2.0 --libs-only-L`"
  366. XML_LIBS="`pkg-config libxml-2.0 --libs-only-l`"
  367. AC_CHECK_LIB([xml2],
  368. [xmlNewDoc],
  369. [libxml2_lib_found=yes],
  370. [libxml2_lib_found=no],
  371. [-lz])
  372. if test "x$libxml2_lib_found" != "xyes"; then
  373. if test "$xml_backend" = "auto"; then
  374. AC_MSG_WARN([cannot find libxml2 library])
  375. else
  376. AC_MSG_ERROR([cannot find libxml2 library])
  377. fi
  378. fi
  379. # the header file is installed in a subdirectory of one of the standard
  380. # include directory. This might prove to be a problem if the cross-
  381. # compile environment is not complete enough (i.e. if it misses
  382. # pkg-config, or if pkg-config returns wrong values). In most cases, the
  383. # environment is likely to be OK so we will never hit any issue.
  384. xml2_CFLAGS="$CFLAGS"
  385. CFLAGS="$CFLAGS $XML_CFLAGS"
  386. AC_CHECK_HEADER([libxml/tree.h],
  387. [libxml2_h_found=yes],
  388. [libxml2_h_found=no],
  389. [/* force include check */])
  390. CFLAGS="$xml2_CFLAGS"
  391. if test "x$libxml2_h_found" != "xyes"; then
  392. if test "$xml_backend" = "auto"; then
  393. AC_MSG_WARN([cannot find libxml2 headers])
  394. else
  395. AC_MSG_ERROR([cannot find libxml2 headers])
  396. fi
  397. fi
  398. AC_DEFINE([HAVE_LIB_LIBXML2],
  399. [],
  400. [libxml2-based XML backend])
  401. xml_backend="found"
  402. found_xml_backend="libxml2"
  403. ;;
  404. *)
  405. # this is probably broken. We consider that the user supplied path is
  406. # a non-standard path. But we're not going to check anything.
  407. AC_MSG_WARN([--with-libxml2=DIR is probably broken, just trying])
  408. XML_LDFLAGS="-L${use_libxml2}/lib"
  409. XML_CFLAGS="-I${use_libxml2}/include/libxml2"
  410. XML_LIBS="-lxml2"
  411. AC_MSG_CHECKING([for libxml2 support])
  412. AC_MSG_RESULT([yes])
  413. AC_MSG_NOTICE([headers for libxml2 hopefully in ${use_libxml2}/include/libxml2])
  414. AC_MSG_NOTICE([library libxml2 hopefully in ${use_libxml2}/lib])
  415. AC_DEFINE([HAVE_LIB_LIBXML2],
  416. [],
  417. [libxml2-based XML backend])
  418. xml_backend="found"
  419. found_xml_backend="libxml2"
  420. ;;
  421. esac
  422. else
  423. # not selected? We print a small message
  424. AC_MSG_CHECKING([for libxml2 support])
  425. AC_MSG_RESULT([no])
  426. fi
  427. if test "$xml_backend" != "found"; then
  428. AC_MSG_ERROR([Failed to find a suitable XML backend])
  429. fi
  430. if test $count_xml_backends -eq 0; then
  431. AC_MSG_NOTICE([I found a suitable XML backend: $found_xml_backend])
  432. fi
  433. AC_SUBST(XML_LIBS)
  434. AC_SUBST(XML_LDFLAGS)
  435. AC_SUBST(XML_CFLAGS)
  436. ################################
  437. # Search for network functions (like connect())
  438. ################################
  439. AC_SEARCH_LIBS([socket], [socket])
  440. ################################
  441. # Check for regex.h
  442. ################################
  443. AC_CHECK_HEADERS(regex.h, [],
  444. AC_MSG_ERROR([regex.h not found: regular expressions are not supported]))
  445. ################################
  446. # Check for getopt_long()
  447. ################################
  448. AC_CHECK_HEADERS(getopt.h, [],
  449. AC_MSG_WARN([getopt.h not found: only short parameters can be used on command line]))
  450. ################################
  451. # Check for locale.h
  452. ################################
  453. AC_CHECK_HEADERS(locale.h, [],
  454. AC_MSG_WARN([locale.h not found: the locales is not supported]))
  455. ################################
  456. # Check for CODESET within nl_langinfo
  457. ################################
  458. AM_LANGINFO_CODESET
  459. ################################
  460. # Check for pwd.h and grp.h
  461. ################################
  462. AC_CHECK_HEADERS(pwd.h, [],
  463. AC_MSG_WARN([pwd.h not found: the pwd operations is not supported]))
  464. AC_CHECK_HEADERS(grp.h, [],
  465. AC_MSG_WARN([grp.h not found: the grp operations is not supported]))
  466. ################################
  467. # Check for chroot
  468. ################################
  469. AC_CHECK_FUNCS(chroot, [],
  470. AC_MSG_WARN([chroot() not found: the choot is not supported]))
  471. ################################
  472. # Check for dlopen
  473. ################################
  474. AC_CHECK_HEADERS(dlfcn.h, [
  475. AC_SEARCH_LIBS([dlopen], [dl dld], [], [
  476. AC_MSG_WARN([unable to find the dlopen() function])
  477. ])
  478. ],
  479. AC_MSG_WARN([dlfcn.h not found: the dl operations is not supported]))
  480. AC_CONFIG_FILES(Makefile)
  481. AC_OUTPUT