configure.ac 17 KB

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