configure.ac 18 KB

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