1# Initialize configuration 2# ---------------------------------------------------------------------------------------------------------------------------------- 3AC_PREREQ([2.69]) 4AC_INIT([pgBackRest], [2.35]) 5AC_CONFIG_SRCDIR([version.h]) 6AC_CONFIG_AUX_DIR(build) 7 8# Don't add any CFLAGS by default (otherwise -g -O2 will be added) 9# ---------------------------------------------------------------------------------------------------------------------------------- 10: ${CFLAGS=""} 11 12# Check compiler supports C99 standard 13# ---------------------------------------------------------------------------------------------------------------------------------- 14AC_PROG_CC_C99 15 16# Build C standard based on the host type. C99 is required and other flags are added depending on the host. 17# ---------------------------------------------------------------------------------------------------------------------------------- 18AC_CANONICAL_HOST 19AC_SUBST(CFLAGS, "${CFLAGS} -std=c99") 20 21case $host_os in 22 darwin*) 23 AC_SUBST(CPPFLAGS, "${CPPFLAGS} -D_DARWIN_C_SOURCE") 24 ;; 25 26 linux*) 27 AC_SUBST(CPPFLAGS, "${CPPFLAGS} -D_POSIX_C_SOURCE=200809L") 28 ;; 29esac 30 31# Check if the C compiler supports _Static_assert() 32# 33# Test the syntax ({_Static_assert(...)}) because gcc-style compound expressions are needed to wrap it into macros. 34# ---------------------------------------------------------------------------------------------------------------------------------- 35AC_LINK_IFELSE([AC_LANG_PROGRAM([], [({_Static_assert(1, "foo");})])], [AC_DEFINE(HAVE_STATIC_ASSERT)]) 36 37# Check if the C compiler supports __builtin_types_compatible_p() 38# ---------------------------------------------------------------------------------------------------------------------------------- 39AC_LINK_IFELSE( 40 [AC_LANG_PROGRAM([], [[int x; static int y[__builtin_types_compatible_p(__typeof__(x), int)];]])], 41 [AC_DEFINE(HAVE_BUILTIN_TYPES_COMPATIBLE_P)]) 42 43# Set warnings and optimizations based on build type (i.e. production or test) 44# ---------------------------------------------------------------------------------------------------------------------------------- 45AC_SUBST(CFLAGS, "${CFLAGS} -Wall -Wextra -Wno-missing-field-initializers -Wno-implicit-fallthrough") 46 47# -Wno-clobbered is not supported on all compilers 48AX_CHECK_COMPILE_FLAG([-Wno-clobbered], [AC_SUBST(CFLAGS, "${CFLAGS} -Wno-clobbered")], [], [-Werror]) 49 50AC_ARG_ENABLE( 51 test, [AS_HELP_STRING([--enable-test], [enable internal test code and assertions for debugging])]) 52 53if test "$enable_test" != yes 54then 55 AC_DEFINE(NDEBUG) 56 57 # Enable optimizations if not testing and they have not been disabled 58 AC_ARG_ENABLE(optimize, [AS_HELP_STRING([--disable-optimize], [disable compiler optimizations])]) 59 60 if test "$enable_optimize" != no 61 then 62 AC_SUBST(CFLAGS, "${CFLAGS} -O2") 63 AC_SUBST(CFLAGS_PAGE_CHECKSUM, "-funroll-loops -ftree-vectorize") 64 fi 65else 66 # Check for optional warnings (note that these must be checked before the additional warnings below are added) 67 AX_CHECK_COMPILE_FLAG([-Wformat-signedness], [AC_SUBST(CFLAGS, "${CFLAGS} -Wformat-signedness")], [], [-Werror]) 68 AX_CHECK_COMPILE_FLAG([-Wduplicated-branches], [AC_SUBST(CFLAGS, "${CFLAGS} -Wduplicated-branches")], [], [-Werror]) 69 AX_CHECK_COMPILE_FLAG([-Wduplicated-cond], [AC_SUBST(CFLAGS, "${CFLAGS} -Wduplicated-cond")], [], [-Werror]) 70 71 # Add additional warnings 72 AC_SUBST(CFLAGS, "${CFLAGS} -Wwrite-strings -Wconversion -Wformat=2 -Wformat-nonliteral -Wstrict-prototypes -Wpointer-arith") 73 AC_SUBST(CFLAGS, "${CFLAGS} -Wvla") 74fi 75 76# Include the build directory 77# ---------------------------------------------------------------------------------------------------------------------------------- 78AC_SUBST(CPPFLAGS, "${CPPFLAGS} -I.") 79 80# Check required pq library 81# ---------------------------------------------------------------------------------------------------------------------------------- 82AC_ARG_VAR(PG_CONFIG, [path to pg_config utility])dnl 83 84if test -z "$PG_CONFIG"; then 85 PG_CONFIG="pg_config" 86fi 87 88AC_CHECK_PROG(PG_CONFIG_EXISTS, [${PG_CONFIG?}], ["yes"], ["no"]) 89 90if test ${PG_CONFIG_EXISTS?} == yes 91then 92 AC_SUBST(CPPFLAGS, "${CPPFLAGS} -I`${PG_CONFIG?} --includedir`") 93 AC_SUBST(LDFLAGS, "${LDFLAGS} -L`${PG_CONFIG?} --libdir`") 94fi 95 96AC_CHECK_LIB([pq], [PQconnectdb], [], [AC_MSG_ERROR([library 'pq' is required])]) 97AC_CHECK_HEADER(libpq-fe.h, [], [AC_MSG_ERROR([header file <libpq-fe.h> is required])]) 98 99# Check required openssl libraries 100# ---------------------------------------------------------------------------------------------------------------------------------- 101AC_CHECK_LIB([crypto], [EVP_get_digestbyname], [], [AC_MSG_ERROR([library 'crypto' is required])]) 102AC_CHECK_LIB([ssl], [SSL_new], [], [AC_MSG_ERROR([library 'ssl' is required])]) 103 104# Check required xml library 105# ---------------------------------------------------------------------------------------------------------------------------------- 106AC_ARG_VAR(XML2_CONFIG, [path to xml2 config utility])dnl 107 108if test -z "$XML2_CONFIG"; then 109 XML2_CONFIG="pkg-config libxml-2.0" 110fi 111 112AC_CHECK_PROG(XML2_CONFIG_EXISTS, [${XML2_CONFIG?}], ["yes"], ["no"]) 113 114if test ${XML2_CONFIG_EXISTS?} == yes 115then 116 AC_SUBST(CPPFLAGS, "$CPPFLAGS `${XML2_CONFIG?} --cflags`") 117fi 118 119AC_CHECK_LIB([xml2], [xmlSaveToBuffer], [], [AC_MSG_ERROR([library 'xml2' is required])]) 120AC_CHECK_HEADER(libxml/parser.h, [], [AC_MSG_ERROR([header file <libxml/parser.h> is required])]) 121 122# Check required yaml library (only required for build) 123# ---------------------------------------------------------------------------------------------------------------------------------- 124AC_CHECK_LIB( 125 [yaml], [yaml_parser_initialize], [AC_SUBST(LIBS_BUILD, "${LIBS_BUILD} -lyaml")], [AC_MSG_ERROR([library 'yaml' is required])]) 126AC_CHECK_HEADER(zlib.h, [], [AC_MSG_ERROR([header file <yaml.h> is required])]) 127 128# Check required gz library 129# ---------------------------------------------------------------------------------------------------------------------------------- 130AC_CHECK_LIB([z], [deflate], [], [AC_MSG_ERROR([library 'z' is required])]) 131AC_CHECK_HEADER(zlib.h, [], [AC_MSG_ERROR([header file <zlib.h> is required])]) 132 133# Check required bzip2 library 134# ---------------------------------------------------------------------------------------------------------------------------------- 135AC_CHECK_LIB([bz2], [BZ2_bzCompress], [], [AC_MSG_ERROR([library 'bz2' is required])]) 136AC_CHECK_HEADER(bzlib.h, [], [AC_MSG_ERROR([header file <bzlib.h> is required])]) 137 138# Check optional lz4 library 139# ---------------------------------------------------------------------------------------------------------------------------------- 140AC_CHECK_LIB( 141 [lz4], [LZ4F_isError], 142 [AC_CHECK_HEADER(lz4frame.h, [AC_DEFINE(HAVE_LIBLZ4) AC_SUBST(LIBS, "${LIBS} -llz4")], 143 [AC_MSG_ERROR([header file <lz4frame.h> is required])])]) 144 145# Check optional zst library. Ignore any versions below 1.0. 146# ---------------------------------------------------------------------------------------------------------------------------------- 147AC_CHECK_LIB( 148 [zstd], [ZSTD_isError], 149 [AC_CHECK_HEADER(zstd.h, 150 [AC_LINK_IFELSE( 151 [AC_LANG_PROGRAM( 152 [#include <zstd.h>], 153 [#if ZSTD_VERSION_MAJOR < 1 154 #error "ZSTD_VERSION_MAJOR must be >= 1" 155 #endif])], 156 [AC_DEFINE(HAVE_LIBZST) AC_SUBST(LIBS, "${LIBS} -lzstd")])], 157 [AC_MSG_ERROR([header file <zstd.h> is required])])]) 158 159# Set configuration path 160# ---------------------------------------------------------------------------------------------------------------------------------- 161AC_ARG_WITH( 162 [configdir], [AS_HELP_STRING([--with-configdir=DIR], [default configuration path])], 163 [AC_DEFINE_UNQUOTED([CFGOPTDEF_CONFIG_PATH], ["${withval}"])], 164 [AC_DEFINE_UNQUOTED([CFGOPTDEF_CONFIG_PATH], ["/etc/" PROJECT_BIN])]) 165 166# Write output 167# ---------------------------------------------------------------------------------------------------------------------------------- 168AC_CONFIG_HEADERS([build.auto.h]) 169AC_CONFIG_FILES([Makefile]) 170AC_OUTPUT 171