diff --git a/.gitignore b/.gitignore index 22720c6495272b60ad4ad1f4f147c9d1de7f1231..e961c5d6c90836469be4b6d47da15bab226f53dd 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,5 @@ missing openfortivpn .dirstamp doc/*.1 +config.sub +config.guess diff --git a/.travis.yml b/.travis.yml index bfcd4cf6c3464ad5cf15d2db986210837a9d32e6..3c79b62623599dd067871d4f523189ad47c115c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,6 @@ cache: script: - ./tests/lint/run.sh - > - aclocal && autoconf && automake --add-missing + ./autogen.sh && ./configure --prefix=/usr --sysconfdir=/etc && make diff --git a/README.md b/README.md index 819d50b2655f8757e0f401d27bedcfa5dc123a38..c3af5e36973a96b30b26895d2dce0f0ed95a0b8f 100644 --- a/README.md +++ b/README.md @@ -83,23 +83,15 @@ For other distros, you'll need to build and install from source: 2. Build and install. - On Linux: ```shell - aclocal && autoconf && automake --add-missing + ./autogen.sh ./configure --prefix=/usr/local --sysconfdir=/etc make sudo make install ``` - On macOS: - ```shell - export CPPFLAGS="-I/usr/local/opt/openssl/include" - export LDFLAGS="-L/usr/local/opt/openssl/lib" - aclocal && autoconf && automake --add-missing - ./configure --prefix=/usr/local --sysconfdir=/etc - make - sudo make install - ``` + If you need to specify the openssl location you can use the + `--with-openssl` option. diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 0000000000000000000000000000000000000000..47805a3303366d58b3c5ce608d6e782b4e0d9cb9 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,6 @@ +#!/bin/sh +set -exu + +aclocal +autoconf +automake --add-missing diff --git a/configure.ac b/configure.ac index 40c5dbcffecaf709e267fb136ceaca25fae146b8..3d35039820bf17ade7116e4d58fc175e9b57c8a5 100644 --- a/configure.ac +++ b/configure.ac @@ -10,8 +10,123 @@ AM_INIT_AUTOMAKE([foreign subdir-objects]) AC_PROG_CC AC_GNU_SOURCE +# Helps support multiarch by setting 'host_os' and 'host_cpu' +AC_CANONICAL_HOST + AM_SILENT_RULES([yes]) +AC_DEFUN([OPENSSL_DEVEL], +[ + dnl + dnl Set up configure script macros + dnl + AC_ARG_WITH(openssl, + [ --with-openssl=<path> path containing OpenSSL header and library subdirs], + [OPENSSL_lib_check="$with_openssl/lib64 $with_openssl/lib $with_openssl/lib64/openssl $with_openssl/lib/openssl" + OPENSSL_inc_check="$with_openssl/include $with_openssl/include/openssl"], + [OPENSSL_lib_check="/usr/local/openssl/lib64 /usr/local/openssl/lib /usr/local/lib64/openssl /usr/local/lib/openssl /opt/openssl/lib64 /opt/openssl/lib /usr/local/opt/openssl/lib64 /usr/local/opt/openssl/lib /usr/lib64/openssl /usr/lib/openssl /usr/local/lib64 /usr/local/lib /usr/lib64 /usr/lib /lib" + OPENSSL_inc_check="/usr/local/openssl/include /usr/local/include/openssl /opt/openssl/include /usr/local/opt/openssl/include /usr/local/include/openssl /usr/local/include /usr/include/openssl /usr/include"]) + AC_ARG_WITH(openssl-lib, + [ --with-openssl-lib=<path> directory path of OpenSSL library], + [OPENSSL_lib_check="$with_openssl_lib $with_openssl_lib/lib64 $with_openssl_lib/lib $with_openssl_lib/lib64/ssl $with_openssl_lib/lib/ssl"]) + AC_ARG_WITH(openssl-include, + [ --with-openssl-include=<path> directory path of OpenSSL headers], + [OPENSSL_inc_check="$with_openssl_include $with_openssl_include/include $with_openssl_include/include/ssl"]) + + dnl + dnl Look for OpenSSL library + dnl + AC_CACHE_CHECK([for OpenSSL library location], [ac_cv_openssl_lib], + [ + for dir in $OPENSSL_lib_check + do + if test -d "$dir" && \ + ( test -f "$dir/libssl.so" || + test -f "$dir/libssl.a" || + test -f "$dir/${host_cpu}-${host_os}/libssl.so" || + test -f "$dir/${host_cpu}-${host_os}/libssl.a" ) + then + ac_cv_openssl_lib=$dir + break + fi + done + + if test -z "$ac_cv_openssl_lib" + then + AC_MSG_ERROR([Didn't find the OpenSSL library dir in '$OPENSSL_lib_check']) + fi + + case "$ac_cv_openssl_lib" in + /* ) ;; + * ) AC_MSG_ERROR([The OpenSSL library directory ($ac_cv_openssl_lib) must be an absolute path.]) ;; + esac + ]) + AC_SUBST([OPENSSL_LIB_DIR],[$ac_cv_openssl_lib]) + + dnl + dnl Look for OpenSSL header file directory + dnl + AC_CACHE_CHECK([for OpenSSL include path], [ac_cv_openssl_inc], + [ + for dir in $OPENSSL_inc_check + do + if test -d "$dir" && test -f "$dir/openssl/ssl.h" + then + ac_cv_openssl_inc=$dir + break + fi + done + + if test -z "$ac_cv_openssl_inc" + then + AC_MSG_ERROR([Didn't find the OpenSSL header dir in '$OPENSSL_inc_check']) + fi + + case "$ac_cv_openssl_inc" in + /* ) ;; + * ) AC_MSG_ERROR([The OpenSSL header directory ($ac_cv_openssl_inc) must be an absolute path.]) ;; + esac + ]) + AC_SUBST([OPENSSL_INC_DIR],[$ac_cv_openssl_inc]) + + dnl + dnl Now check that the above checks resulted in -I and -L flags that + dnl let us build actual programs against OpenSSL. + dnl + case "$ac_cv_openssl_lib" in + /usr/lib) ;; + *) LDFLAGS="$LDFLAGS -L${ac_cv_openssl_lib}" ;; + esac + CPPFLAGS="$CPPFLAGS -I${ac_cv_openssl_inc}" + AC_MSG_CHECKING([that we can build OpenSSL programs]) + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([#include <openssl/ssl.h>], + [SSL_library_init()])], + AC_MSG_RESULT([yes]), + AC_MSG_ERROR([no])) +]) dnl End OPENSSL_DEVEL + + +# run it: +OPENSSL_DEVEL + +# Verify OpenSSL < 1.1.0 +AC_MSG_CHECKING([for OpenSSL version < 1.1.0]) +AC_EGREP_CPP(yes, + [#include <openssl/crypto.h> + #if (OPENSSL_VERSION_NUMBER < 0x10100000L) + yes + #endif + ], + [ + AC_MSG_RESULT(yes) + ], + [ + AC_MSG_RESULT(no) + AC_MSG_FAILURE([OpenSSL version too new]) + ] +) + # Checks for libraries. AC_CHECK_LIB([crypto], [ERR_peek_last_error], [], [AC_MSG_ERROR([Cannot find libcrypto.])]) AC_CHECK_LIB([pthread], [pthread_create], [], [AC_MSG_ERROR([Cannot find libpthread.])])