configure.ac 18 KB

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