+# BZIP2
+AC_ARG_ENABLE(bzip2, AC_HELP_STRING([--enable-bzip2],
+ [enable bzip2 Support (default is enable).]),
+ [ac_cv_enable_bzip2=$enableval],
+ [ac_cv_enable_bzip2=yes])
+AC_CACHE_CHECK([whether to enable bzip2 Support],
+ [ac_cv_enable_bzip2], [ac_cv_enable_bzip2=yes])
+case $ac_cv_enable_bzip2 in
+ yes)
+ AC_CHECK_HEADERS([bzlib.h],[],[AC_MSG_ERROR([bzlib.h is needed but not found - you will need to install package 'libbz2-dev' or similar. The feature can be disabled with --disable-bzip2])])
+ if test "$ac_mingw32" = "yes"; then
+ # Using the cross compiler it bizarrely fails to detect BZ2_bzRead during the configure stage
+ # I SWEAR THIS WORKED AT SOME POINT - BUT ON A DIFFERENT DAY IT DOESN'T = MORE SWEARING
+ BZ2FUNC=main
+ AC_CHECK_LIB(bz2, [$BZ2FUNC], [], [LIBS="-lbz2 $LIBS"
+ AC_MSG_WARN([libbz2 not found! Forcing it anyway!])])
+ else
+ BZ2FUNC=BZ2_bzRead
+ AC_CHECK_LIB(bz2, [$BZ2FUNC], [], [AC_MSG_ERROR([libbz2 is needed but not found.])])
+ fi
+ ;;
+esac
+AM_CONDITIONAL([BZIP2], [test x$ac_cv_enable_bzip2 = xyes])
+
+# FILE MAGIC
+AC_ARG_ENABLE(magic, AC_HELP_STRING([--enable-magic],
+ [enable File Magic support via libmagic (default is enable).]),
+ [ac_cv_enable_magic=$enableval],
+ [ac_cv_enable_magic=yes])
+AC_CACHE_CHECK([whether to enable Magic Support],
+ [ac_cv_enable_magic], [ac_cv_enable_magic=yes])
+case $ac_cv_enable_magic in
+ yes)
+ AC_CHECK_HEADERS([magic.h],[],[AC_MSG_ERROR([magic.h is needed but not found - you will need to install package 'libmagic-dev' or similar. The feature can be disabled with --disable-magic])])
+ AC_CHECK_LIB(magic, magic_open, [], [AC_MSG_ERROR([libmagic is needed but not found.])])
+ ;;
+esac
+AM_CONDITIONAL([MAGIC], [test x$ac_cv_enable_magic = xyes])
+
+# SQL for MBTiles
+AC_ARG_ENABLE(mbtiles, AC_HELP_STRING([--enable-mbtiles],
+ [enable MBTiles support via libsqlite3 (default is enable).]),
+ [ac_cv_enable_mbtiles=$enableval],
+ [ac_cv_enable_mbtiles=yes])
+AC_CACHE_CHECK([whether to enable MBTiles Support],
+ [ac_cv_enable_mbtiles], [ac_cv_enable_mbtiles=yes])
+case $ac_cv_enable_mbtiles in
+ yes)
+ AC_CHECK_HEADERS([sqlite3.h],[],[AC_MSG_ERROR([sqlite3.h is needed but not found - you will need to install package 'libsqlite3-dev' or similar. The feature can be disabled with --disable-mbtiles])])
+ AC_CHECK_LIB(sqlite3, sqlite3_open, [], [AC_MSG_ERROR([libsqlite3 is needed but not found.])])
+ ;;
+esac
+AM_CONDITIONAL([SQLITE], [test x$ac_cv_enable_mbtiles = xyes])
+
+# Standard compression is handled by libz
+# libzip enables a friendlier file based interface
+# libzip itself depends on libz (which is required in the Viking build ATM)
+# ZIP
+AC_ARG_ENABLE(zip, AC_HELP_STRING([--enable-zip],
+ [enable zip support (default is enable).]),
+ [ac_cv_enable_zip=$enableval],
+ [ac_cv_enable_zip=yes])
+AC_CACHE_CHECK([whether to enable zip Support],
+ [ac_cv_enable_zip], [ac_cv_enable_zip=yes])
+case $ac_cv_enable_zip in
+ yes)
+ # NB As far as I can tell libzip doesn't provide any versioning info within the header code itself
+ # Thus supporting old versions via simple #if #else #endif directives is seemingly not possible
+ # Resort to checking versioning only via pkgconfig
+ PKG_CHECK_MODULES([LIBZIP], [libzip >= 0.11],
+ [ AC_CHECK_HEADERS([zip.h],[],[AC_MSG_ERROR([zip.h is needed but not found - you will need to install package 'libzip-dev' or similar. The feature can be disabled with --disable-zip])])
+ AC_CHECK_LIB(zip, [main], [], [AC_MSG_ERROR([libzip is needed but not found.])]) ],
+ [ AC_MSG_WARN([libzip version needs to be at least 0.11, use of libzip is disabled])
+ ac_cv_enable_zip=no ]
+ )
+ ;;
+esac
+AM_CONDITIONAL([ZIP], [test x$ac_cv_enable_zip = xyes])
+
+# ATM only for MD5 Hashing which is currently only used for filename of image thumbnails
+AC_ARG_ENABLE(nettle, AC_HELP_STRING([--enable-nettle],
+ [enable MD5 Hash support (default is enable)]),
+ [ac_cv_enable_nettle=$enableval],
+ [ac_cv_enable_nettle=yes])
+AC_CACHE_CHECK([whether to enable MD5 Hash support],
+ [ac_cv_enable_nettle], [ac_cv_enable_nettle=yes])
+case $ac_cv_enable_nettle in
+ yes)
+ AC_CHECK_HEADER([nettle/md5-compat.h],[],[AC_MSG_ERROR([nettle/md5-compat.h is needed but not found - you will need to install package 'nettle-dev' or similar. The feature can be disabled with --disable-nettle])])
+ AC_CHECK_LIB([nettle], [main], [], [AC_MSG_ERROR([libnettle is needed but not found.])])
+ ;;
+esac
+AM_CONDITIONAL([MD5_HASH], [test x$ac_cv_enable_nettle = xyes])
+
+# Mapnik rendering layer
+AC_ARG_ENABLE(mapnik, AC_HELP_STRING([--enable-mapnik],
+ [enable Mapnik (default is enable)]),
+ [ac_cv_enable_mapnik=$enableval],
+ [ac_cv_enable_mapnik=yes])
+AC_CACHE_CHECK([whether to enable Mapnik],
+ [ac_cv_enable_mapnik], [ac_cv_enable_mapnik=yes])
+case $ac_cv_enable_mapnik in
+ yes)
+ # C++
+ AC_LANG_CPLUSPLUS
+ AC_LANG_SAVE
+ AC_PROG_CXX
+ # Mapnik3 requires C++11. Viking will use C++11 as well.
+ CXXFLAGS="$CXXFLAGS -std=c++11"
+ # Too difficult to get check working under Windows (extra dependencies needed probably Boost)- so just skip it
+ if test "x$ac_cv_enable_windows" = "xno"; then
+ AC_CHECK_HEADER([mapnik/map.hpp],[],[AC_MSG_ERROR([mapnik/map.hpp is needed but not found - you will need to install package 'libmapnik-dev' or similar. The feature can be disabled with --disable-mapnik])])
+ fi
+ AC_CHECK_LIB([mapnik], [main], [], [AC_MSG_ERROR([libmapnik is needed but not found.])])
+ AC_CHECK_LIB([stdc++], [main], [], [AC_MSG_ERROR([libstdc++ is needed but not found.])])
+ # Required for Mapnik3 build (it's also in Mapnik2 but does not need to be specified for some reason)
+ # it's part of libmapnik install dependencies
+ AC_CHECK_LIB([icuuc], [main], [], [AC_MSG_ERROR([libicuuc is needed but not found.])])
+ AC_LANG_RESTORE
+ ;;
+esac
+AM_CONDITIONAL([MAPNIK], [test x$ac_cv_enable_mapnik = xyes])
+###
+
+## WORK AROUND BROKEN autoconf - see http://lists.gnu.org/archive/html/bug-automake/2002-11/msg00020.html
+m4_pushdef([AC_MSG_ERROR])
+AC_PROG_CXX
+m4_popdef([AC_MSG_ERROR])
+##