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