2013-10-28 22:50:05 +01:00
# -*-sh-*-
2013-11-04 17:43:22 +01:00
#
# This file is part of Pretty Curved Privacy (pcp1).
#
2014-12-22 16:22:52 +01:00
# Copyright (C) 2013-2015 T.Linden.
2013-11-04 17:43:22 +01:00
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# You can contact me by mail: <tlinden AT cpan DOT org>.
#
2013-10-28 22:50:05 +01:00
AC_PREREQ(2.61)
2013-11-12 09:05:55 +01:00
define([pcpversion], esyscmd([sh -c "cat VERSION"]))dnl
AC_INIT([pcp], [pcpversion], [pcp@daemon.de])
#AC_INIT(pcp, `cat VERSION`)
2013-10-28 22:50:05 +01:00
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_MACRO_DIR(config)
2013-11-12 09:05:55 +01:00
AC_CONFIG_HEADER(include/pcp/config.h)
2015-03-31 17:26:59 +02:00
AM_INIT_AUTOMAKE([subdir-objects])
2013-10-29 22:14:34 +01:00
LT_INIT
2013-10-28 22:50:05 +01:00
ORIG_CFLAGS="${CFLAGS:-none}"
2015-01-07 12:31:21 +01:00
2013-10-28 22:50:05 +01:00
# Checks for programs
2013-11-28 19:36:50 +01:00
AC_PROG_CXX
AC_PROG_CXXCPP
2013-10-28 22:50:05 +01:00
AC_PROG_CC
AM_PROG_CC_C_O
AC_PROG_LIBTOOL
AC_PROG_SED
AC_PROG_AWK
AC_PROG_INSTALL
2015-01-07 12:31:21 +01:00
# remove flags set by AC_PROG_CC (duplicates and/or invalid for clang)
2015-05-11 20:44:47 +02:00
# FIXME: why did I do this?!
#CFLAGS=""
#CXXFLAGS=""
2013-10-28 22:50:05 +01:00
# Host speciffic checks
AC_CANONICAL_HOST
# Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(errno.h err.h stdlib.h string.h unistd.h stdio.h getopt.h\
2013-10-29 22:54:07 +01:00
limits.h stddef.h stdint.h sys/types.h sys/stat.h endian.h \
2013-11-03 14:50:03 +01:00
sys/endian.h termios.h arpa/inet.h netinet/in.h wctype.h)
2013-10-28 22:50:05 +01:00
AC_TYPE_SIZE_T
# Checks for library functions.
AC_CHECK_FUNCS( \
arc4random_buf \
2014-03-08 19:27:52 +01:00
arc4random \
2013-10-28 22:50:05 +01:00
fread \
fopen \
free \
fwrite \
fseek \
ftruncate \
fprintf \
isatty \
malloc \
memset \
memcpy \
2015-04-17 14:14:38 +02:00
mmap \
2013-10-28 22:50:05 +01:00
perror \
2015-04-17 14:14:38 +02:00
posix_memalign \
2015-01-13 13:06:20 +01:00
setrlimit \
2013-10-28 22:50:05 +01:00
strnlen \
2014-03-10 16:58:48 +01:00
strnstr \
2013-10-28 22:50:05 +01:00
strlen \
strtol \
sizeof \
tcgetattr \
2013-11-03 14:50:03 +01:00
umask \
2013-11-17 16:53:20 +01:00
towlower \
getopt_long \
vasprintf
2013-10-28 22:50:05 +01:00
)
2014-01-16 15:25:09 +01:00
AC_MSG_CHECKING([for be32toh])
AC_TRY_LINK([
#include "libpcp/pcp/config.h"
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
], [
(void)be32toh(0);
], [AC_MSG_RESULT([no])], [
AC_DEFINE(HAVE_BE32TOH,, Define if be32toh() is available)
AC_MSG_RESULT([yes])
])
AC_MSG_CHECKING([for htobe32])
AC_TRY_LINK([
#include "libpcp/pcp/config.h"
#ifdef HAVE_ENDIAN_H
#include <endian.h>
#endif
#ifdef HAVE_SYS_ENDIAN_H
#include <sys/endian.h>
#endif
], [
(void)htobe32(0);
], [AC_MSG_RESULT([no])], [
AC_DEFINE(HAVE_HTOBE32,, Define if htobe32() is available)
AC_MSG_RESULT([yes])
])
2014-09-17 10:02:06 +02:00
cross_compile="no"
2013-10-28 22:50:05 +01:00
AC_MSG_CHECKING([compiler and flags for sanity])
AC_RUN_IFELSE([AC_LANG_PROGRAM([[ #include <stdio.h> ]], [[ exit(0); ]])],
2014-09-17 10:02:06 +02:00
[ AC_MSG_RESULT([yes]) ],
2013-10-28 22:50:05 +01:00
[
2014-09-17 10:02:06 +02:00
AC_MSG_RESULT([no])
AC_MSG_ERROR([*** compiler cannot create working executables, check config.log ***])
2013-10-28 22:50:05 +01:00
],
2014-09-17 10:02:06 +02:00
[
AC_MSG_WARN([cross compiling: not checking compiler sanity])
[cross_compile="yes"]
]
2013-10-28 22:50:05 +01:00
)
2013-10-29 22:14:34 +01:00
_havenacl=no
_ldlib=""
AC_ARG_WITH([libsodium],
[AS_HELP_STRING([--with-libsodium],
[Specify libsodium prefix])],
[search_libsodium="yes"],
[])
if test "x$search_libsodium" = "xyes"; then
if test -r "${with_libsodium}/include/sodium.h"; then
CFLAGS="-I${with_libsodium}/include ${CFLAGS}"
LDFLAGS="-L${with_libsodium}/lib ${LDFLAGS}"
_havenacl=yes
_ldlib="${with_libsodium}/lib"
fi
fi
AC_ARG_WITH([libsodium-include-dir],
[AS_HELP_STRING([--with-libsodium-include-dir],
[Specify libsodium include prefix])],
[search_libsodium_include="yes"],
[])
if test "x$search_libsodium_include" = "xyes"; then
if test -r "${with_libsodium_include_dir}/sodium.h"; then
2015-04-17 16:01:56 +02:00
CFLAGS="-I${with_libsodium_include_dir} ${CFLAGS}"
2013-10-29 22:14:34 +01:00
_havenacl=yes
fi
fi
AC_ARG_WITH([libsodium_lib_dir],
[AS_HELP_STRING([--with-libsodium-lib-dir],
[Specify libsodium library prefix])],
[search_libsodium_lib="yes"],
[])
if test "x$search_libsodium_lib" = "xyes"; then
2015-04-17 16:01:56 +02:00
if test -r "${with_libsodium_lib_dir}/libsodium.dylib" -o -r "${with_libsodium_lib_dir}/libsodium.so" -o -r "${with_libsodium_lib_dir}/libsodium.a"; then
LDFLAGS="-L${with_libsodium_lib_dir} ${LDFLAGS}"
2013-10-29 22:14:34 +01:00
_havenacl=yes
2015-04-17 16:01:56 +02:00
_ldlib="${with_libsodium_lib_dir}"
2013-10-29 22:14:34 +01:00
fi
fi
if test "x${_havenacl}" = "xno"; then
AC_MSG_CHECKING([pkg-config for libsodium])
if pkg-config --exists libsodium; then
# found it
LDFLAGS=`pkg-config --libs libsodium`
CFLAGS=`pkg-config --cflags libsodium`
_ldlib=`pkg-config --libs libsodium | cut -d ' ' -f 1 | cut -d L -f 2`
2015-01-13 13:06:20 +01:00
_havenacl=yes
2013-10-29 22:14:34 +01:00
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
fi
2015-01-13 13:06:20 +01:00
if test "x${_havenacl}" != "xno" -a "x$cross_compile" = "xno"; then
2015-04-17 12:06:25 +02:00
LIBS="-lsodium" # gcc
2015-04-17 16:01:56 +02:00
export LDFLAGS="$LDFLAGS"
export CFLAGS="$CFLAGS"
export LIBS="$LIBS"
2015-01-13 13:06:20 +01:00
AC_MSG_CHECKING([libsodium version compatible])
AC_RUN_IFELSE([
AC_LANG_PROGRAM([[
#include <sodium.h>
]],[[
if (sodium_library_version_major() >= 7) { exit(0); }
else { exit(1); }
]])],
[
AC_MSG_RESULT([yes])
],
[
2015-04-16 21:20:38 +02:00
AC_MSG_ERROR([no, libsodium too old. please update your libsodium installation. or maybe the path in "$LDFLAGS" is not in LD_LIBRARY_PATH?])
2015-01-13 13:06:20 +01:00
]
)
fi
2013-10-29 22:14:34 +01:00
2013-10-28 22:50:05 +01:00
# Check for some target-specific stuff
case "$host" in
2013-11-17 16:53:20 +01:00
*aix*)
2013-11-17 12:30:34 +01:00
# libm is required as well
2013-11-17 16:53:20 +01:00
CFLAGS="$CFLAGS -D_AIX_SOURCE=1"
2013-11-17 12:30:34 +01:00
LDFLAGS="$LDFLAGS -lm"
;;
2013-10-28 22:50:05 +01:00
*-*-android*) ;;
*-*-cygwin*) ;;
*-*-dgux*) ;;
*-*-darwin*) ;;
*-*-dragonfly*) ;;
*-*-haiku*) ;;
*-*-hpux*) ;;
*-*-irix5*) ;;
*-*-irix6*) ;;
*-*-k*bsd*-gnu | *-*-kopensolaris*-gnu) ;;
*-*-linux*) ;;
*-*-netbsd*) ;;
*-*-freebsd*)
# ports install to /usr/local by default, check
if test -d "/usr/local/lib" -a -d "/usr/local/include"; then
CFLAGS="$CFLAGS -I/usr/local/include"
LDFLAGS="$LDFLAGS -L/usr/local/lib"
fi
;;
*-*-bsdi*) ;;
*-next-*) ;;
*-*-openbsd*) ;;
*-*-solaris*) ;;
*-*-sunos4*) ;;
*-ncr-sysv*) ;;
*-sni-sysv*) ;;
*-*-sysv4.2*) ;;
*-*-sysv5*) ;;
*-*-sysv*) ;;
*-*-sco*) ;;
*-*-unicos*) ;;
*-dec-osf*) ;;
*-*-nto-qnx*) ;;
*-*-ultrix*) ;;
*-*-lynxos) ;;
esac
AC_CHECK_LIB(sodium, sodium_init, , [AC_MSG_ERROR([cannot link with -lsodium, install libsodium.])])
2013-10-29 22:14:34 +01:00
if test -n "$_ldlib"; then
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${_ldlib}"
fi
2013-10-29 22:51:06 +01:00
2014-09-17 10:02:06 +02:00
if test "$cross_compile" = "no"; then
2013-10-28 22:50:05 +01:00
AC_MSG_CHECKING([is libsodium compiled correctly])
AC_RUN_IFELSE([
AC_LANG_PROGRAM([[
#include <sodium.h>
2015-01-13 13:06:20 +01:00
#include <stdlib.h>
2013-10-28 22:50:05 +01:00
#if crypto_box_PUBLICKEYBYTES != 32 || crypto_box_SECRETKEYBYTES != 32 || crypto_sign_PUBLICKEYBYTES != 32 || crypto_sign_PUBLICKEYBYTES != 32
# error "libsodium not built correctly"
#endif
]],[[exit(0);]])],
[
AC_MSG_RESULT([yes])
],
[
AC_MSG_ERROR([no. please check your libsodium installation, consider re-installing])
]
)
2014-09-17 10:02:06 +02:00
fi
2013-10-28 22:50:05 +01:00
2014-09-17 10:02:06 +02:00
if test "$cross_compile" = "no"; then
2013-10-29 22:51:06 +01:00
# check endianess
# program returns 0 on little and 1 on big endian systems
AC_MSG_CHECKING([are we on a big endian system])
AC_RUN_IFELSE([
AC_LANG_PROGRAM([[]],[[long one= 1; exit(!(*((char *)(&one)))); ]])],
[
AC_MSG_RESULT([no])
2015-01-01 15:52:58 +01:00
bigendian="no"
2013-10-29 22:51:06 +01:00
],
[
AC_MSG_RESULT([yes])
2015-01-01 15:52:58 +01:00
bigendian="yes"
2013-10-29 22:51:06 +01:00
]
)
2014-09-17 10:02:06 +02:00
fi
2013-10-29 22:51:06 +01:00
2015-01-01 15:52:58 +01:00
if test "x$bigendian" = "xyes"; then
2013-11-19 21:04:14 +01:00
CFLAGS="$CFLAGS -D__CPU_IS_BIG_ENDIAN=1"
2013-10-29 22:51:06 +01:00
fi
2015-01-07 12:31:21 +01:00
# prepare FLAGS
CFLAGS="$CFLAGS -Werror -Wextra -Wall"
AC_ARG_ENABLE([debug],
AS_HELP_STRING([--disable-debug], [Disable debugging]))
AS_IF([test "x$enable_debug" != "xno"], [
2015-01-13 13:06:20 +01:00
CFLAGS="$CFLAGS -g -DDEBUG"
2015-01-07 12:31:21 +01:00
enable_debug="yes"
])
AC_ARG_ENABLE([optimize],
AS_HELP_STRING([--disable-optimize], [Disable optimization]))
AS_IF([test "x$enable_optimize" != "xno"], [
case $enable_optimize in
-O*)
CFLAGS="$CFLAGS $enable_optimize"
enable_optimize="$enable_optimize"
;;
*)
CFLAGS="$CFLAGS -O2"
enable_optimize="-O2"
;;
esac
])
2013-11-28 19:36:50 +01:00
CXXFLAGS="$CFLAGS"
2015-01-07 12:31:21 +01:00
2014-12-22 16:22:52 +01:00
# conditionals for bindings and stuff
2014-12-14 14:39:10 +01:00
2014-12-22 16:22:52 +01:00
# c++
AC_ARG_ENABLE([cpp-binding],
[AS_HELP_STRING([--disable-cpp-binding],
[Disable C++ binding])],
)
2014-12-14 14:39:10 +01:00
2015-01-07 12:31:21 +01:00
AS_IF([test "x$enable_cpp_binding" != "xno"], [
enable_cpp_binding=yes
])
2014-12-22 16:22:52 +01:00
AM_CONDITIONAL([BUILDCPP], [test "x$enable_cpp_binding" != "xno"])
2014-12-14 14:39:10 +01:00
2014-12-22 16:22:52 +01:00
# py
AC_ARG_ENABLE([python-binding],
[AS_HELP_STRING([--enable-python-binding],
2015-01-07 12:31:21 +01:00
[Enable python binding])
],
2014-12-22 16:22:52 +01:00
[python="yes"],
[])
2014-12-14 14:39:10 +01:00
if test "x$python" = "xyes"; then
2014-12-22 16:22:52 +01:00
if ! python -c "import cffi" > /dev/null 2>&1; then
python="no"
2014-12-14 14:39:10 +01:00
AC_MSG_ERROR([python or cffi is not installed])
fi
2015-01-01 15:52:58 +01:00
else
python="no"
2014-12-14 14:39:10 +01:00
fi
2014-12-22 16:22:52 +01:00
AM_CONDITIONAL([BUILDPY], [test "x$python" = "xyes"])
AC_SUBST(PACKAGE_VERSION)
# Specify output files
2015-04-17 17:40:10 +02:00
AC_CONFIG_FILES([Makefile include/Makefile libpcp/Makefile src/Makefile man/Makefile \
2014-12-22 16:22:52 +01:00
tests/Makefile libpcp/libpcp1.pc bindings/cpp/Makefile bindings/py/Makefile])
2013-10-28 22:50:05 +01:00
AC_OUTPUT
2015-01-01 15:52:58 +01:00
AC_MSG_RESULT([
2015-01-07 12:31:21 +01:00
Build configured for $PACKAGE $VERSION:
2015-01-01 15:52:58 +01:00
CC: ${CC}
CFLAGS: ${CFLAGS}
CXX: ${CXX}
CXXFLAGS: ${CXXFLAGS}
LDFLAGS: ${LDFLAGS}
LIBS: ${LIBS}
2015-01-07 12:31:21 +01:00
debug: ${enable_debug}
optimize: ${enable_optimize}
2015-01-01 15:52:58 +01:00
prefix: ${prefix}
libdir: ${libdir}
includedir: ${includedir}
2015-01-07 12:31:21 +01:00
target platform: ${host}
big endian cpu: ${bigendian}
2015-01-13 13:06:20 +01:00
cross compile: ${cross_compile}
2015-01-01 15:52:58 +01:00
build python binding: ${python}
2015-01-07 12:31:21 +01:00
build c++ binding: ${enable_cpp_binding}
Type 'make' to build, 'make install' to install.
To execute unit tests, type 'make test'.
2015-01-01 15:52:58 +01:00
])