configure.ac 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. dnl
  2. dnl Configuration script for Mini-XML, a small XML file parsing library.
  3. dnl
  4. dnl https://www.msweet.org/mxml
  5. dnl
  6. dnl Copyright © 2003-2022 by Michael R Sweet.
  7. dnl
  8. dnl Licensed under Apache License v2.0. See the file "LICENSE" for more
  9. dnl information.
  10. dnl
  11. dnl We need at least autoconf 2.70 for --runstatedir...
  12. AC_PREREQ([2.70])
  13. dnl Package name and version...
  14. AC_INIT([Mini-XML], [3.3.1], [https://github.com/michaelrsweet/mxml/issues], [mxml], [https://www.msweet.org/mxml])
  15. dnl This line is provided to ensure that you don't run the autoheader program
  16. dnl against this project. Doing so is completely unsupported and WILL cause
  17. dnl problems!
  18. AH_TOP([#error "Somebody ran autoheader on this project which is unsupported and WILL cause problems."])
  19. dnl Get the build and host platforms and split the host_os value
  20. AC_CANONICAL_BUILD
  21. AC_CANONICAL_HOST
  22. [host_os_name=`echo $host_os | sed -e '1,$s/[0-9.]*$//g'`]
  23. [host_os_version="$(echo $host_os | sed -e '1,$s/^[^0-9.]*//g' | awk -F. '{print $1 $2}')"]
  24. # Linux often does not yield an OS version we can use...
  25. AS_IF([test "x$host_os_version" = x], [
  26. host_os_version="0"
  27. ])
  28. dnl Set the name of the config header file...
  29. AC_CONFIG_HEADERS([config.h])
  30. dnl Version number...
  31. VERSION="AC_PACKAGE_VERSION"
  32. AC_SUBST(VERSION)
  33. AC_DEFINE_UNQUOTED(MXML_VERSION, "Mini-XML v$VERSION")
  34. dnl Clear default debugging options and set normal optimization by
  35. dnl default unless the user asks for debugging specifically.
  36. CFLAGS="${CFLAGS:=}"
  37. CPPFLAGS="${CPPFLAGS:=}"
  38. LDFLAGS="${LDFLAGS:=}"
  39. AC_SUBST([LDFLAGS])
  40. LIBS="${LIBS:=}"
  41. dnl Options...
  42. AC_ARG_WITH([ansi], AS_HELP_STRING([--with-ansi], [set full ANSI C mode, default=no]), [
  43. use_ansi="$withval"
  44. ], [
  45. use_ansi="no"
  46. ])
  47. AC_ARG_WITH([archflags], AS_HELP_STRING([--with-archflags], [set additional architecture flags, default=none]), [
  48. ARCHFLAGS="$withval"
  49. ], [
  50. AS_CASE(["$host_os_name"], [darwin*], [
  51. AS_IF([test "$host_os_version" -ge 200 -a x$enable_debug != xyes], [
  52. # macOS 11.0 and higher support the Apple Silicon (arm64) CPUs
  53. ARCHFLAGS="-mmacosx-version-min=10.14 -arch x86_64 -arch arm64"
  54. ], [test x$enable_debug != xyes], [
  55. ARCHFLAGS="-mmacosx-version-min=10.14 -arch x86_64"
  56. ])
  57. ], [*], [
  58. ARCHFLAGS=""
  59. ])
  60. ])
  61. AC_SUBST([ARCHFLAGS])
  62. AC_ARG_WITH([optim], AS_HELP_STRING([--with-optim], [set additional optimization flags, default=none]), [
  63. OPTIM="$withval"
  64. ], [
  65. OPTIM=""
  66. ])
  67. AC_SUBST([OPTIM])
  68. AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [turn on debugging, default=no]))
  69. AC_ARG_ENABLE([maintainer], AS_HELP_STRING([--enable-maintainer], [turn on maintainer mode, default=no]))
  70. AC_ARG_ENABLE([sanitizer], AS_HELP_STRING([--enable-sanitizer], [build with AddressSanitizer, default=no]))
  71. AC_ARG_WITH([docdir], AS_HELP_STRING([--with-docdir], [set directory for documentation, default=${prefix}/share/doc/mxml]), [
  72. docdir="$withval"
  73. ], [
  74. docdir="NONE"
  75. ])
  76. AC_SUBST(docdir)
  77. AC_ARG_WITH([vsnprintf], AS_HELP_STRING([--with-vsnprintf], [use vsnprintf emulation functions, default=auto]), [
  78. use_vsnprintf="$withval"
  79. ], [
  80. use_vsnprintf="no"
  81. ])
  82. dnl Checks for programs...
  83. AC_PROG_CC
  84. AC_PROG_CXX
  85. AC_PROG_INSTALL
  86. AS_IF([test "$INSTALL" = "$ac_install_sh"], [
  87. # Use full path to install-sh script...
  88. INSTALL="`pwd`/install-sh -c"
  89. ])
  90. AC_PROG_RANLIB
  91. AC_CHECK_TOOL(AR,ar)
  92. AC_PATH_PROG(CP,cp)
  93. AC_PATH_PROGS(LDCONFIG,ldconfig false)
  94. AC_PATH_PROG(LN,ln)
  95. AC_PATH_PROG(MKDIR,mkdir)
  96. AC_PATH_PROG(RM,rm)
  97. dnl Flags for "ar" command...
  98. AS_CASE(["$host_os_name"], [darwin* | *bsd], [
  99. ARFLAGS="-rcv"
  100. ], [*], [
  101. ARFLAGS="crvs"
  102. ])
  103. AC_SUBST(ARFLAGS)
  104. dnl Inline functions...
  105. AC_C_INLINE
  106. dnl Checks for string functions.
  107. AS_IF([test "x$use_ansi" != xyes], [
  108. AC_CHECK_FUNCS([strdup strlcat strlcpy])
  109. ])
  110. AS_IF([test "x$use_vsnprintf" != xyes], [
  111. AC_CHECK_FUNCS([snprintf vasprintf vsnprintf])
  112. ])
  113. dnl Check for "long long" support...
  114. AC_TYPE_LONG_LONG_INT
  115. dnl Threading support
  116. AC_ARG_ENABLE([threads], AS_HELP_STRING([--disable-threads], [disable multi-threading support, default=no]))
  117. have_pthread=no
  118. AS_IF([test "x$enable_threads" != xno], [
  119. AC_CHECK_HEADER([pthread.h], [
  120. AC_DEFINE([HAVE_PTHREAD_H], [Have <pthread.h>?])
  121. ])
  122. AS_IF([test x$ac_cv_header_pthread_h = xyes], [
  123. dnl Check various threading options for the platforms we support
  124. for flag in -lpthreads -lpthread -pthread; do
  125. AC_MSG_CHECKING([for pthread_create using $flag])
  126. SAVELIBS="$LIBS"
  127. LIBS="$flag $LIBS"
  128. AC_LANG([C])
  129. AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],[pthread_create(0, 0, 0, 0);])], [
  130. have_pthread=yes
  131. ], [
  132. LIBS="$SAVELIBS"
  133. ])
  134. AS_IF([test x$have_pthread = xyes], [
  135. AC_MSG_RESULT([yes])
  136. CPPFLAGS="$CPPFLAGS -D_THREAD_SAFE -D_REENTRANT"
  137. break
  138. ], [
  139. AC_MSG_RESULT([no])
  140. ])
  141. done
  142. ])
  143. ])
  144. dnl Shared library support...
  145. DSO="${DSO:=:}"
  146. DSOFLAGS="${DSOFLAGS:=}"
  147. AC_ARG_ENABLE([shared], AS_HELP_STRING([--disable-shared], [turn off shared libraries, default=no]))
  148. AS_IF([test x$enable_shared != xno], [
  149. AC_MSG_CHECKING([for shared library support])
  150. PICFLAG=1
  151. AS_CASE(["$host_os_name"], [sunos | unix_s], [
  152. AC_MSG_RESULT([yes])
  153. LIBMXML="libmxml.so.1.6"
  154. DSO="\$(CC)"
  155. DSOFLAGS="$DSOFLAGS -Wl,-h,libmxml.so.1 -G -R\$(libdir) \$(OPTIM)"
  156. LDFLAGS="$LDFLAGS -R\$(libdir)"
  157. ], [linux*], [
  158. AC_MSG_RESULT([yes])
  159. LIBMXML="libmxml.so.1.6"
  160. DSO="\$(CC)"
  161. DSOFLAGS="$DSOFLAGS -Wl,-soname,libmxml.so.1 -shared \$(OPTIM)"
  162. ], [osf | gnu], [
  163. AC_MSG_RESULT([yes])
  164. LIBMXML="libmxml.so.1.6"
  165. DSO="\$(CC)"
  166. DSOFLAGS="$DSOFLAGS -Wl,-soname,libmxml.so.1,-rpath,\$(libdir) -shared \$(OPTIM)"
  167. LDFLAGS="$LDFLAGS -Wl,-rpath,\$(libdir)"
  168. ], [*bsd | haiku*], [
  169. AC_MSG_RESULT([yes])
  170. LIBMXML="libmxml.so.1.6"
  171. DSO="\$(CC)"
  172. DSOFLAGS="$DSOFLAGS -Wl,-soname,libmxml.so.1,-R\$(libdir) -shared \$(OPTIM)"
  173. LDFLAGS="$LDFLAGS -Wl,-R\$(libdir)"
  174. ], [darwin], [
  175. AC_MSG_RESULT([yes])
  176. LIBMXML="libmxml.1.dylib"
  177. DSO="\$(CC)"
  178. DSOFLAGS="$DSOFLAGS \$(RC_CFLAGS) -dynamiclib -lc"
  179. ], [mingw], [
  180. AC_MSG_RESULT([yes])
  181. LIBMXML="mxml1.dll"
  182. DSO="\$(CC)"
  183. DSOFLAGS="$DSOFLAGS -shared -Wl,--out-implib,libmxml1.a,--no-undefined,--enable-runtime-pseudo-reloc"
  184. ], [*], [
  185. AC_MSG_RESULT([no])
  186. AC_MSG_WARN([shared libraries not supported on this platform.])
  187. PICFLAG=0
  188. LIBMXML="libmxml.a"
  189. ])
  190. ], [
  191. PICFLAG=0
  192. LIBMXML="libmxml.a"
  193. ])
  194. AC_SUBST([DSO])
  195. AC_SUBST([DSOFLAGS])
  196. AC_SUBST([LIBMXML])
  197. AC_SUBST([PICFLAG])
  198. dnl Compiler options...
  199. WARNINGS=""
  200. AC_SUBST([WARNINGS])
  201. AS_IF([test -n "$GCC"], [
  202. CFLAGS="-D_GNU_SOURCE $CFLAGS"
  203. AS_IF([test "x$OPTIM" = x], [
  204. AS_IF([test x$enable_debug = xyes], [
  205. OPTIM="-g"
  206. ], [
  207. OPTIM="-g -Os"
  208. ])
  209. ], [test x$enable_debug = xyes], [
  210. OPTIM="$OPTIM -g"
  211. ])
  212. AS_IF([test x$enable_sanitizer = xyes], [
  213. # Use -fsanitize=address with debugging...
  214. OPTIM="$OPTIM -fsanitize=address"
  215. ], [
  216. # Otherwise use the Fortify enhancements to catch any unbounded
  217. # string operations...
  218. CPPFLAGS="$CPPFLAGS -D_FORTIFY_SOURCE=2"
  219. ])
  220. AS_IF([test "x$use_ansi" = xyes], [
  221. CFLAGS="-ansi -pedantic $CFLAGS"
  222. ])
  223. dnl Show all standard warnings + unused variables when compiling...
  224. WARNINGS="-Wall -Wunused"
  225. dnl Drop some not-useful/unreliable warnings...
  226. for warning in char-subscripts format-truncation format-y2k switch unused-result; do
  227. AC_MSG_CHECKING([whether compiler supports -Wno-$warning])
  228. OLDCFLAGS="$CFLAGS"
  229. CFLAGS="$CFLAGS -Wno-$warning -Werror"
  230. AC_COMPILE_IFELSE([AC_LANG_PROGRAM()], [
  231. AC_MSG_RESULT(yes)
  232. WARNINGS="$WARNINGS -Wno-$warning"
  233. ], [
  234. AC_MSG_RESULT(no)
  235. ])
  236. CFLAGS="$OLDCFLAGS"
  237. done
  238. dnl Maintainer mode enables -Werror...
  239. AS_IF([test x$enable_maintainer = xyes], [
  240. WARNINGS="$WARNINGS -Werror"
  241. ])
  242. AS_IF([test $PICFLAG = 1 -a "$host_os_name" != aix], [
  243. OPTIM="-fPIC $OPTIM"
  244. ])
  245. ], [
  246. AS_IF([test "x$OPTIM" = x], [
  247. AS_IF([test x$enable_debug = xyes], [
  248. OPTIM="-g"
  249. ], [
  250. OPTIM="-O"
  251. ])
  252. ])
  253. AS_CASE(["$host_os_name"], [hp-ux], [
  254. CFLAGS="-Ae $CFLAGS"
  255. OPTIM="+DAportable $OPTIM"
  256. AS_IF([test $PICFLAG = 1], [
  257. OPTIM="+z $OPTIM"
  258. ])
  259. ], [unix_svr | sunos], [
  260. AS_IF([test $PICFLAG = 1], [
  261. OPTIM="-KPIC $OPTIM"
  262. ])
  263. ])
  264. ])
  265. dnl Determine whether we are cross-compiling...
  266. AS_IF([test "$build" = "$host"], [
  267. TARGETS="ALLTARGETS"
  268. ], [
  269. TARGETS="CROSSTARGETS"
  270. ])
  271. AC_SUBST([TARGETS])
  272. dnl Fix installation directories...
  273. AS_IF([test "$prefix" = "NONE"], [
  274. prefix="/usr/local"
  275. ])
  276. AS_IF([test "$exec_prefix" = "NONE"], [
  277. exec_prefix="$prefix"
  278. ])
  279. AS_IF([test "$docdir" = "NONE"], [
  280. docdir="$datadir/doc/mxml"
  281. ])
  282. AS_IF([test "$mandir" = "\${prefix}/man" -a "$prefix" = "/usr"], [
  283. mandir="/usr/share/man"
  284. ])
  285. dnl pkg-config stuff...
  286. AS_IF([test "$includedir" != /usr/include], [
  287. PC_CFLAGS="-I$includedir"
  288. ], [
  289. PC_CFLAGS=""
  290. ])
  291. AC_SUBST([PC_CFLAGS])
  292. AS_IF([test "$libdir" != /usr/lib], [
  293. PC_LIBS="-L$libdir -lmxml"
  294. ], [
  295. PC_LIBS="-lmxml"
  296. ])
  297. AC_SUBST([PC_LIBS])
  298. dnl Output the makefile, etc...
  299. AC_CONFIG_FILES([Makefile mxml.pc])
  300. AC_OUTPUT