# Initialise autoconf
AC_PREREQ([2.65])
AC_LANG([C])
AC_INIT([ACOPM], [0.99], [], [acopm], [https://packages.alphachat.net/projects/ACOPM.git/])
AC_CONFIG_MACRO_DIR([m4])
AC_CONFIG_SRCDIR([src/acopm.c])
AC_PREFIX_DEFAULT([$HOME/ACOPM])
# Initialise automake
AM_INIT_AUTOMAKE([subdir-objects])
# Optional features
AC_ARG_ENABLE([debug], AS_HELP_STRING([--enable-debug], [build with debugging information and runtime checks]), [], [enable_debug="no"])
AC_ARG_WITH([mbedtls], AS_HELP_STRING([--with-mbedtls], [build with support for ARM mbedTLS, =internal to build internal copy]), [], [with_mbedtls="no"])
# Test for required toolchain utilities or features
CFLAGS_GIVEN="${CFLAGS}"
CFLAGS=""
AC_PROG_CC_C99
AM_PROG_CC_C_O
AM_PROG_AR
AC_PROG_RANLIB
AC_PROG_INSTALL
AC_PROG_MKDIR_P
# Test for required compiler keywords, header includes, functions, or data types (and members)
AC_C_CONST
AC_C_INLINE
AC_C_RESTRICT
AC_CHECK_HEADERS(
[arpa/inet.h errno.h fcntl.h getopt.h limits.h netdb.h netinet/in.h regex.h signal.h stdarg.h stdbool.h],
[], AC_MSG_ERROR([required header not found])
)
AC_CHECK_HEADERS(
[stddef.h stdio.h sys/socket.h sys/wait.h time.h],
[], AC_MSG_ERROR([required header not found])
)
AC_CHECK_FUNCS(
[calloc close dup2 execve exit fclose fcntl fileno fflush fopen fork fprintf free malloc memchr memmove],
[], AC_MSG_ERROR([required function not found])
)
AC_CHECK_FUNCS(
[memset open realloc socket strcasecmp strchr strcmp strdup strerror strstr strtoul vfprintf vsprintf],
[], AC_MSG_ERROR([required function not found])
)
AC_CHECK_FUNCS(
[vsnprintf],
[], AC_MSG_ERROR([required function not found])
)
AC_CHECK_FUNCS(
[regcomp regerror regexec regfree],
[], AC_MSG_ERROR([required function not found]), [[#include <regex.h>]]
)
AC_CHECK_FUNCS(
[localtime strftime time],
[], AC_MSG_ERROR([required function not found]), [[#include <time.h>]]
)
AC_CHECK_TYPES(
[pid_t, size_t, ssize_t, uid_t, uint8_t, uint16_t, uint32_t, uint64_t, long long int],
[], AC_MSG_ERROR([required type not found])
)
AC_CHECK_TYPES(
[sa_family_t, socklen_t],
[], AC_MSG_ERROR([required type not found]), [[#include <sys/socket.h>]]
)
AC_CHECK_MEMBERS(
[regex_t.re_nsub, regmatch_t.rm_so, regmatch_t.rm_eo],
[], AC_MSG_ERROR([required 'regex_t' or 'regmatch_t' member not found]), [[#include <regex.h>]]
)
AC_CHECK_MEMBERS(
[struct addrinfo.ai_flags, struct addrinfo.ai_family, struct addrinfo.ai_socktype],
[], AC_MSG_ERROR([required 'struct addrinfo' member not found]), [[#include <netdb.h>]]
)
AC_CHECK_MEMBERS(
[struct addrinfo.ai_protocol, struct addrinfo.ai_addrlen, struct addrinfo.ai_addr, struct addrinfo.ai_next],
[], AC_MSG_ERROR([required 'struct addrinfo' member not found]), [[#include <netdb.h>]]
)
# Test for libconfig
LIBCONFIG_ERRSTR="your libconfig is missing, broken or too old"
AC_CHECK_HEADERS([libconfig.h], [], AC_MSG_ERROR([$LIBCONFIG_ERRSTR]))
AC_SEARCH_LIBS([config_init], [config], [], AC_MSG_ERROR([$LIBCONFIG_ERRSTR]))
# Test for libevent
LIBEVENT_ERRSTR="your libevent is missing, broken or too old"
AC_CHECK_HEADERS([event2/dns.h event2/event.h], [], AC_MSG_ERROR([$LIBEVENT_ERRSTR]))
AC_SEARCH_LIBS([event_base_dispatch], [event], [], AC_MSG_ERROR([$LIBEVENT_ERRSTR]))
# Test for MbedTLS
AM_CONDITIONAL([WITH_MBEDTLS_INTERNAL], [test "x${with_mbedtls}" = "xinternal"])
if test "x${with_mbedtls}" = "xyes"
then
AC_DEFINE([BUILD_WITH_MBEDTLS], [1], [build with support for ARM mbedTLS])
LIBMBEDTLS_ERRSTR="your ARM mbedTLS libraries are missing, broken or too old"
AC_CHECK_HEADERS(
[mbedtls/ctr_drbg.h mbedtls/entropy.h mbedtls/error.h mbedtls/md.h],
[], AC_MSG_ERROR([$LIBMBEDTLS_ERRSTR])
)
AC_CHECK_HEADERS(
[mbedtls/pk.h mbedtls/ssl.h mbedtls/version.h mbedtls/x509_crt.h],
[], AC_MSG_ERROR([$LIBMBEDTLS_ERRSTR])
)
AC_SEARCH_LIBS([mbedtls_ctr_drbg_init], [mbedcrypto], [], AC_MSG_ERROR($LIBMBEDTLS_ERRSTR))
AC_SEARCH_LIBS([mbedtls_x509_crt_init], [mbedx509], [], AC_MSG_ERROR($LIBMBEDTLS_ERRSTR))
AC_SEARCH_LIBS([mbedtls_ssl_init], [mbedtls], [], AC_MSG_ERROR($LIBMBEDTLS_ERRSTR))
test_cflags_mbedtls="yes"
with_mbedtls="Yes"
else
if test "x${with_mbedtls}" = "xinternal"
then
AC_DEFINE([BUILD_WITH_MBEDTLS], [1], [build with support for ARM mbedTLS])
git_submodule_update_remote="yes"
test_cflags_mbedtls="yes"
with_mbedtls="Yes (Building Internal Copy)"
else
if test "x${with_mbedtls}" = "xno"
then
with_mbedtls="No"
else
with_mbedtls="No (unrecognised argument '${with_mbedtls}')"
fi
fi
fi
# If we were instructed to build with debugging support, check assert(3) works correctly
if test "x${enable_debug}" = "xyes"
then
AC_DEFINE([BUILD_WITH_DEBUG], [1], [build with debugging information and runtime checks])
AC_CHECK_HEADERS([assert.h], [], AC_MSG_ERROR([assert.h not found or unusable]))
ACOPM_TEST_ASSERT
fi
# Test for C compiler diagnostic flags
ACOPM_TEST_CFLAGS_DIAGNOSTICS
if test "x${test_cflags_mbedtls}" = "xyes"
then
ACOPM_TEST_CFLAGS([-Wno-redundant-decls])
ACOPM_TEST_CFLAGS([-Wno-switch-enum])
fi
# If no CFLAGS were given to the configure script, check for optimisation flags
if test "x${CFLAGS_GIVEN}" = "x"
then
ACOPM_TEST_CFLAGS_EXTRA
if test "x${enable_debug}" = "xno"
then
ACOPM_TEST_CFLAGS_NODEBUG
enable_debug="No"
fi
else
CFLAGS="${CFLAGS} ${CFLAGS_GIVEN}"
fi
if test "x${enable_debug}" = "xyes"
then
ACOPM_TEST_CFLAGS_DEBUG
enable_debug="Yes"
fi
# Define some compile-time directories
AC_DEFINE_PATH([BINDIR], ["${bindir}"], [Binary installation directory])
AC_DEFINE_PATH([SYSCONFDIR], ["${sysconfdir}"], [System configuration directory])
# Generate the output files
if test "x${git_submodule_update_remote}" = "xyes"
then
AC_MSG_NOTICE([checking out ARM mbedTLS repository])
if ! git submodule update --init --remote --recursive
then
AC_MSG_ERROR([failed])
fi
fi
AC_CONFIG_FILES([Makefile dist/acopm-dronebl-submit.py])
AC_CONFIG_HEADERS([lib/acopm-config.h])
AC_OUTPUT
# Give some information to the user
echo " "
echo " Configuration of ${PACKAGE_NAME} version ${PACKAGE_VERSION}"
echo " "
echo " Installation prefix .......: $(eval echo ${prefix})"
echo " Binary directory ..........: $(eval echo ${bindir})"
echo " Configuration directory ...: $(eval echo ${sysconfdir})"
echo " "
echo " Debugging Support .........: ${enable_debug}"
echo " ARM mbedTLS Support .......: ${with_mbedtls}"
echo " "