configure.ac 16 KB

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