1dnl 2dnl Configuration script for Mini-XML, a small XML-like file parsing library. 3dnl 4dnl https://www.msweet.org/mxml 5dnl 6dnl Copyright © 2003-2019 by Michael R Sweet. 7dnl 8dnl Licensed under Apache License v2.0. See the file "LICENSE" for more 9dnl information. 10dnl 11 12dnl Package name and version... 13AC_INIT([Mini-XML], [3.1], [https://github.com/michaelrsweet/mxml/issues], [mxml], [https://michaelrsweet.github.io/mxml]) 14 15dnl This line is provided to ensure that you don't run the autoheader program 16dnl against this project. Doing so is completely unsupported and WILL cause 17dnl problems! 18AH_TOP([#error "Somebody ran autoheader on this project which is unsupported and WILL cause problems."]) 19 20dnl Get the build and host platforms and split the host_os value 21AC_CANONICAL_BUILD 22AC_CANONICAL_HOST 23 24[host_os_name=`echo $host_os | sed -e '1,$s/[0-9.]*$//g'`] 25[host_os_version=`echo $host_os | sed -e '1,$s/^[^0-9.]*//g'`] 26 27dnl Set the name of the config header file... 28AC_CONFIG_HEADER(config.h) 29 30dnl Version number... 31VERSION="AC_PACKAGE_VERSION" 32AC_SUBST(VERSION) 33AC_DEFINE_UNQUOTED(MXML_VERSION, "Mini-XML v$VERSION") 34 35dnl Clear default debugging options and set normal optimization by 36dnl default unless the user asks for debugging specifically. 37CFLAGS="${CFLAGS:=}" 38CXXFLAGS="${CXXFLAGS:=}" 39LDFLAGS="${LDFLAGS:=}" 40AC_SUBST(LDFLAGS) 41 42AC_ARG_WITH(ansi, [ --with-ansi set full ANSI C mode, default=no], 43 use_ansi="$withval", 44 use_ansi="no") 45 46AC_ARG_WITH(archflags, [ --with-archflags set additional architecture flags, default=none], 47 ARCHFLAGS="$withval", 48 ARCHFLAGS="") 49AC_SUBST(ARCHFLAGS) 50 51AC_ARG_WITH(optim, [ --with-optim set additional optimization flags, default=none], 52 OPTIM="$withval", 53 OPTIM="") 54AC_SUBST(OPTIM) 55 56AC_ARG_ENABLE(debug, [ --enable-debug turn on debugging, default=no], 57if eval "test x$enable_debug = xyes"; then 58 OPTIM="$OPTIM -g" 59fi) 60 61AC_ARG_WITH(docdir, [ --with-docdir set directory for documentation, default=${prefix}/share/doc/mxml], 62 docdir="$withval", 63 docdir="NONE") 64 65AC_SUBST(docdir) 66 67AC_ARG_WITH(vsnprintf, [ --with-vsnprintf use vsnprintf emulation functions, default=auto], 68 use_vsnprintf="$withval", 69 use_vsnprintf="no") 70 71dnl Checks for programs... 72AC_PROG_CC 73AC_PROG_CXX 74AC_PROG_INSTALL 75if test "$INSTALL" = "$ac_install_sh"; then 76 # Use full path to install-sh script... 77 INSTALL="`pwd`/install-sh -c" 78fi 79AC_PROG_RANLIB 80AC_CHECK_TOOL(AR,ar) 81AC_PATH_PROG(CP,cp) 82AC_PATH_PROGS(LDCONFIG,ldconfig false) 83AC_PATH_PROG(LN,ln) 84AC_PATH_PROG(MKDIR,mkdir) 85AC_PATH_PROG(RM,rm) 86 87dnl Flags for "ar" command... 88case "$host_os_name" in 89 darwin* | *bsd) 90 ARFLAGS="-rcv" 91 ;; 92 *) 93 ARFLAGS="crvs" 94 ;; 95esac 96 97AC_SUBST(ARFLAGS) 98 99dnl Inline functions... 100AC_C_INLINE 101 102dnl Checks for string functions. 103if test "x$use_ansi" != xyes; then 104 AC_CHECK_FUNCS(strdup strlcat strlcpy) 105fi 106 107if test "x$use_vsnprintf" != xyes; then 108 AC_CHECK_FUNCS(snprintf vasprintf vsnprintf) 109fi 110 111dnl Check for "long long" support... 112AC_CACHE_CHECK(for long long int, ac_cv_c_long_long, 113 [if test "$GCC" = yes; then 114 ac_cv_c_long_long=yes 115 else 116 AC_TRY_COMPILE(,[long long int i;], 117 ac_cv_c_long_long=yes, 118 ac_cv_c_long_long=no) 119 fi]) 120 121if test $ac_cv_c_long_long = yes; then 122 AC_DEFINE(HAVE_LONG_LONG) 123fi 124 125dnl Threading support 126AC_ARG_ENABLE(threads, [ --enable-threads enable multi-threading support]) 127 128have_pthread=no 129PTHREAD_FLAGS="" 130PTHREAD_LIBS="" 131 132if test "x$enable_threads" != xno; then 133 AC_CHECK_HEADER(pthread.h, AC_DEFINE(HAVE_PTHREAD_H)) 134 135 if test x$ac_cv_header_pthread_h = xyes; then 136 dnl Check various threading options for the platforms we support 137 for flag in -lpthreads -lpthread -pthread; do 138 AC_MSG_CHECKING([for pthread_create using $flag]) 139 SAVELIBS="$LIBS" 140 LIBS="$flag $LIBS" 141 AC_TRY_LINK([#include <pthread.h>], 142 [pthread_create(0, 0, 0, 0);], 143 have_pthread=yes) 144 AC_MSG_RESULT([$have_pthread]) 145 LIBS="$SAVELIBS" 146 147 if test $have_pthread = yes; then 148 PTHREAD_FLAGS="-D_THREAD_SAFE -D_REENTRANT" 149 PTHREAD_LIBS="$flag" 150 151 # Solaris requires -D_POSIX_PTHREAD_SEMANTICS to 152 # be POSIX-compliant... :( 153 case "$host_os_name" in 154 sunos) 155 PTHREAD_FLAGS="$PTHREAD_FLAGS -D_POSIX_PTHREAD_SEMANTICS" 156 ;; 157 esac 158 break 159 fi 160 done 161 fi 162fi 163 164AC_SUBST(PTHREAD_FLAGS) 165AC_SUBST(PTHREAD_LIBS) 166 167dnl Shared library support... 168DSO="${DSO:=:}" 169DSOFLAGS="${DSOFLAGS:=}" 170 171AC_ARG_ENABLE(shared, [ --enable-shared turn on shared libraries, default=no]) 172 173if test x$enable_shared != xno; then 174 AC_MSG_CHECKING(for shared library support) 175 PICFLAG=1 176 177 case "$host_os_name" in 178 sunos | unix_s) 179 AC_MSG_RESULT(yes) 180 LIBMXML="libmxml.so.1.6" 181 DSO="\$(CC)" 182 DSOFLAGS="$DSOFLAGS -Wl,-h,libmxml.so.1 -G -R\$(libdir) \$(OPTIM)" 183 LDFLAGS="$LDFLAGS -R\$(libdir)" 184 ;; 185 186 linux*) 187 AC_MSG_RESULT(yes) 188 LIBMXML="libmxml.so.1.6" 189 DSO="\$(CC)" 190 DSOFLAGS="$DSOFLAGS -Wl,-soname,libmxml.so.1 -shared \$(OPTIM)" 191 ;; 192 193 osf | gnu) 194 AC_MSG_RESULT(yes) 195 LIBMXML="libmxml.so.1.6" 196 DSO="\$(CC)" 197 DSOFLAGS="$DSOFLAGS -Wl,-soname,libmxml.so.1,-rpath,\$(libdir) -shared \$(OPTIM)" 198 LDFLAGS="$LDFLAGS -Wl,-rpath,\$(libdir)" 199 ;; 200 201 *bsd) 202 AC_MSG_RESULT(yes) 203 LIBMXML="libmxml.so.1.6" 204 DSO="\$(CC)" 205 DSOFLAGS="$DSOFLAGS -Wl,-soname,libmxml.so.1,-R\$(libdir) -shared \$(OPTIM)" 206 LDFLAGS="$LDFLAGS -Wl,-R\$(libdir)" 207 ;; 208 209 darwin) 210 AC_MSG_RESULT(yes) 211 LIBMXML="libmxml.1.dylib" 212 DSO="\$(CC)" 213 DSOFLAGS="$DSOFLAGS \$(RC_CFLAGS) -dynamiclib -lc" 214 ;; 215 216 mingw) 217 AC_MSG_RESULT(yes) 218 LIBMXML="mxml1.dll" 219 DSO="\$(CC)" 220 DSOFLAGS="$DSOFLAGS -shared -Wl,--out-implib,libmxml1.a,--no-undefined,--enable-runtime-pseudo-reloc" 221 ;; 222 223 *) 224 AC_MSG_RESULT(no) 225 AC_MSG_WARN(shared libraries not supported on this platform.) 226 PICFLAG=0 227 LIBMXML="libmxml.a" 228 ;; 229 esac 230else 231 PICFLAG=0 232 LIBMXML="libmxml.a" 233fi 234 235AC_SUBST(DSO) 236AC_SUBST(DSOFLAGS) 237AC_SUBST(LIBMXML) 238AC_SUBST(PICFLAG) 239 240dnl Add -Wall for GCC... 241if test -n "$GCC"; then 242 CFLAGS="-Wall -D_GNU_SOURCE $CFLAGS" 243 244 if test "x$OPTIM" = x; then 245 OPTIM="-Os -g" 246 fi 247 248 if test "x$use_ansi" = xyes; then 249 CFLAGS="-ansi -pedantic $CFLAGS" 250 fi 251 252 if test $PICFLAG = 1 -a "$host_os_name" != aix; then 253 OPTIM="-fPIC $OPTIM" 254 fi 255else 256 case "$host_os_name" in 257 hp-ux) 258 CFLAGS="-Ae $CFLAGS" 259 260 if test "x$OPTIM" = x; then 261 OPTIM="-O" 262 fi 263 264 OPTIM="+DAportable $OPTIM" 265 266 if test $PICFLAG = 1; then 267 OPTIM="+z $OPTIM" 268 fi 269 ;; 270 271 unix_svr | sunos) 272 if test "x$OPTIM" = x; then 273 OPTIM="-O" 274 fi 275 276 if test $PICFLAG = 1; then 277 OPTIM="-KPIC $OPTIM" 278 fi 279 ;; 280 281 *) 282 if test "x$OPTIM" = x; then 283 OPTIM="-O" 284 fi 285 ;; 286 esac 287fi 288 289dnl Determine whether we are cross-compiling... 290if test "$build" = "$host"; then 291 TARGETS="ALLTARGETS" 292else 293 TARGETS="CROSSTARGETS" 294fi 295AC_SUBST(TARGETS) 296 297dnl Fix "prefix" variable if it hasn't been specified... 298if test "$prefix" = "NONE"; then 299 prefix="/usr/local" 300fi 301 302dnl Fix "exec_prefix" variable if it hasn't been specified... 303if test "$exec_prefix" = "NONE"; then 304 exec_prefix="$prefix" 305fi 306 307dnl Fix "docdir" variable if it hasn't been specified... 308if test "$docdir" = "NONE"; then 309 docdir="$datadir/doc/mxml" 310fi 311 312dnl Fix "mandir" variable if it hasn't been specified... 313if test "$mandir" = "\${prefix}/man" -a "$prefix" = "/usr"; then 314 case "$host_os_name" in 315 *bsd | darwin | linux*) 316 # *BSD, Darwin (macOS), and Linux 317 mandir="/usr/share/man" 318 ;; 319 irix) 320 # SGI IRIX 321 mandir="/usr/share/catman/u_man" 322 ;; 323 *) 324 # All others 325 mandir="/usr/man" 326 ;; 327 esac 328fi 329 330dnl pkg-config stuff... 331if test "$includedir" != /usr/include; then 332 PC_CFLAGS="-I$includedir" 333else 334 PC_CFLAGS="" 335fi 336 337if test "$libdir" != /usr/lib; then 338 PC_LIBS="-L$libdir -lmxml" 339else 340 PC_LIBS="-lmxml" 341fi 342 343AC_SUBST(PC_CFLAGS) 344AC_SUBST(PC_LIBS) 345 346dnl Output the makefile, etc... 347AC_OUTPUT(Makefile mxml.pc) 348