configure.ac 18 KB

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