]> git.armaanb.net Git - opendoas.git/blobdiff - configure
bump version to 0.2
[opendoas.git] / configure
index 73d56cd111caffbabed30125835e29ad49f8a4ce..cc23132af55b28df8f411a9574ecfacc87dda662 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,45 +1,72 @@
 #!/bin/sh
 
+die() {
+       printf "$1\n" >&2
+       exit 1
+}
+
+usage() {
+       cat <<EOF
+usage: configure [options]
+
+  --prefix=PREFIX        installation prefix [/usr]
+  --exec-prefix=EPREFIX  installation prefix for executable files [PREFIX]
+  --bindir=DIR           user executables [PREFIX/bin]
+  --datadir=DIR          architecture-independent data files [PREFIX/share]
+  --mandir=DIR           manual pages [DATADIR/man]
+  --sysconfdir=DIR       directory for configuration files [/etc]
+  --pamdir=DIR           PAM directory [SYSCONFDIR/pam.d]
+
+  --build=build-alias    a cpu-vendor-opsys for the system where the application will be built
+  --host=host-alias      a cpu-vendor-opsys for the system where the application will run
+  --target=target-alias  the machine that CC will produce code for
+
+  --enable-debug         enable debugging
+  --enable-seccomp       enable seccomp
+  --enable-static        prepare for static build
+
+  --help, -h             display this help and exit
+EOF
+       exit 0
+}
+
 for x; do
        opt=${x%%=*}
        var=${x#*=}
        case "$opt" in
-       --enable-debug) DEBUG=yes;;
        --prefix) PREFIX=$var;;
        --exec-prefix) EPREFIX=$var;;
        --bindir) BINDIR=$var;;
-       --mandir) MANDIR=$var;;
        --datadir) SHAREDIR=$var;;
+       --mandir) MANDIR=$var;;
+       --sysconfdir) SYSCONFDIR=$var;;
+       --pamdir) PAMDIR=$var;;
        --build) BUILD=$var;;
        --host) HOST=$var;;
        --target) TARGET=$var;;
-       --includedir) INCLUDEDIR=$var;;
-       --sysconfdir) SYSCONFDIR=$var;;
-       --pamdir) PAMDIR=$var;;
-       --localstatedir) LOCALSTATEDIR=$var;;
-       --libdir) LIBDIR=$var;;
-       --datadir|--infodir) ;; # ignore autotools
-       --verbose) unset SILENT;;
-       --pkgconfigdir) PKGCONFIGDIR=$var;;
-       --enable-static) BUILD_STATIC=yes;;
+       --enable-debug) DEBUG=yes;;
        --enable-seccomp) BUILD_SECCOMP=yes;;
-       --help) usage;;
-       *) echo "$0: WARNING: unknown option $opt" >&2;;
+       --enable-static) BUILD_STATIC=yes;;
+       --help|-h) usage;;
+       *) die "Error: unknown option $opt";;
        esac
 done
 
 CONFIG_MK=config.mk
 rm -f "$CONFIG_MK"
 
+# : ${VERSION:="$(git describe --dirty --tags --long --always)"}
+: ${VERSION:="0.2"}
+
 cat <<EOF >>$CONFIG_MK
-DESTDIR  ?=    /
 PREFIX   ?=    ${PREFIX:="/usr"}
 EPREFIX  ?=    ${EPREFIX:="${PREFIX}"}
-SHAREDIR ?=    ${SHAREDIR:="${PREFIX}/share"}
 BINDIR   ?=    ${BINDIR:="${PREFIX}/bin"}
+SHAREDIR ?=    ${SHAREDIR:="${PREFIX}/share"}
 MANDIR   ?=    ${MANDIR:="${SHAREDIR}/man"}
 SYSCONFDIR?=   ${SYSCONFDIR:="/etc"}
 PAMDIR   ?=    ${PAMDIR:="${SYSCONFDIR}/pam.d"}
+CFLAGS   +=    -DVERSION="\"${VERSION}\""
 EOF
 
 if [ -z "$BUILD" ]; then
@@ -65,9 +92,11 @@ if [ -z "$OS" ]; then
        KERNEL=${REST%%-*}
 fi
 
+OS_CFLAGS="-D__${OS}__"
+
 case "$OS" in
        linux)
-               OS_CFLAGS="-D_DEFAULT_SOURCE -D_GNU_SOURCE -DUID_MAX=60000 -DGID_MAX=60000"
+               OS_CFLAGS="$OS_CFLAGS -D_DEFAULT_SOURCE -D_GNU_SOURCE -DUID_MAX=60000 -DGID_MAX=60000"
                printf 'CURDIR   :=     .\n' >>$CONFIG_MK
                printf 'PAM_DOAS  =     pam.d__doas__linux\n' >>$CONFIG_MK
                ;;
@@ -76,6 +105,12 @@ esac
 [ -n "$OS_CFLAGS" ] && \
        printf 'CFLAGS   +=     %s\n' "$OS_CFLAGS" >>$CONFIG_MK
 
+[ -n "$DEBUG" ] && \
+       printf 'CFLAGS   +=     -O0 -g\n' >>$CONFIG_MK
+
+[ -n "$BUILD_STATIC" ] && \
+       printf 'CFLAGS   +=     -static\n' >>$CONFIG_MK
+
 # Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features
 XCC="${CC:=clang} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS"
 # Make sure to disable --as-needed for CC tests.
@@ -85,14 +120,18 @@ check_func() {
        func="$1"; src="$2"; shift 2
        printf 'Checking for %-14s\t\t' "$func ..."
        printf '%s\n' "$src" >"_$func.c"
-       if $XCC "_$func.c" -o "_$func" 2>/dev/null; then
+       $XCC "_$func.c" -o "_$func" 2>/dev/null
+       ret=$?
+       rm -f "_$func.c" "_$func"
+       if [ $ret -eq 0 ]; then
                printf 'yes.\n'
                upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')"
                printf 'CFLAGS   +=     -DHAVE_%s\n' "$upperfunc" >>$CONFIG_MK
+               return 0
        else
                printf 'no.\n'
+               return 1
        fi
-       rm -f "_$func.c" "_$func"
 }
 
 src='
@@ -102,7 +141,7 @@ int main(void) {
        return 0;
 }'
 check_func "explicit_bzero" "$src" || {
-       printf 'OPENBSD  +=     explicit_bzero.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     explicit_bzero.o\n' >>$CONFIG_MK
 }
 
 
@@ -114,11 +153,11 @@ src='
 int main(void) {
        const char s1[] = "foo";
        char s2[10];
-       strlccat(s2, s1, sizeof(s2));
+       strlcat(s2, s1, sizeof(s2));
        return 0;
 }'
 check_func "strlcat" "$src" || {
-       printf 'OPENBSD  +=     strlcat.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     strlcat.o\n' >>$CONFIG_MK
 }
 
 #
@@ -133,7 +172,7 @@ int main(void) {
        return 0;
 }'
 check_func "strlcpy" "$src" || {
-       printf 'OPENBSD  +=     strlcpy.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     strlcpy.o\n' >>$CONFIG_MK
 }
 
 #
@@ -146,7 +185,7 @@ int main(void) {
        return 0;
 }'
 check_func "errc" "$src" || {
-       printf 'OPENBSD  +=     errc.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     errc.o\n' >>$CONFIG_MK
 }
 
 #
@@ -159,7 +198,7 @@ int main(void) {
        return 0;
 }'
 check_func "verrc" "$src" || {
-       printf 'OPENBSD  +=     verrc.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     verrc.o\n' >>$CONFIG_MK
 }
 
 #
@@ -172,7 +211,7 @@ int main(void) {
        return 0;
 }'
 check_func "setprogname" "$src" || {
-       printf 'OPENBSD  +=     progname.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     progname.o\n' >>$CONFIG_MK
 }
 
 #
@@ -186,7 +225,7 @@ int main(void) {
        return 0;
 }'
 check_func "readpassphrase" "$src" || {
-       printf 'OPENBSD  +=     readpassphrase.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     readpassphrase.o\n' >>$CONFIG_MK
 }
 
 #
@@ -200,7 +239,7 @@ int main(void) {
        return 0;
 }'
 check_func "strtonum" "$src" || {
-       printf 'OPENBSD  +=     strtonum.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     strtonum.o\n' >>$CONFIG_MK
 }
 
 #
@@ -213,7 +252,7 @@ int main(void) {
        return 0;
 }'
 check_func "reallocarray" "$src" || {
-       printf 'OPENBSD  +=     reallocarray.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     reallocarray.o\n' >>$CONFIG_MK
 }
 
 #
@@ -224,9 +263,22 @@ src='
 int main(void) {
        return 0;
 }'
-check_func "bsd_auth_h" "$src" || {
-       printf 'OPENBSD  +=     auth_userokay.c\n' >>$CONFIG_MK
-}
+check_func "bsd_auth_h" "$src" && \
+       have_bsd_auth_h=1
+
+#
+# Check for pam_appl.h.
+#
+src='
+#include <security/pam_appl.h>
+int main(void) {
+       return 0;
+}'
+[ -z "$have_bsd_auth_h" ] && \
+       check_func "pam_appl_h" "$src" && {
+               printf 'SRCS     +=     doas_pam.c\n' >>$CONFIG_MK
+               printf 'LDFLAGS  +=     -lpam\n' >>$CONFIG_MK
+       }
 
 #
 # Check for login_cap.h.
@@ -237,7 +289,7 @@ int main(void) {
        return 0;
 }'
 check_func "login_cap_h" "$src" || {
-       printf 'OPENBSD  +=     setusercontext.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     setusercontext.o\n' >>$CONFIG_MK
 }
 
 #
@@ -251,7 +303,7 @@ int main(void) {
        return 0;
 }'
 check_func "execvpe" "$src" || {
-       printf 'OPENBSD  +=     execvpe.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     execvpe.o\n' >>$CONFIG_MK
 }
 
 #
@@ -264,7 +316,7 @@ int main(void) {
        return 0;
 }'
 check_func "setresuid" "$src" || {
-       printf 'OPENBSD  +=     setresuid.c\n' >>$CONFIG_MK
+       printf 'OPENBSD  +=     setresuid.o\n' >>$CONFIG_MK
 }
 
 #
@@ -291,10 +343,12 @@ int main(void) {
        prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, NULL);
        return 0;
 }'
-if [ -n "$have_pledge" -a -n "$BUILD_SECCOMP" ]; then
-       check_func "seccomp_h" "$src" && {
-               printf 'OPENBSD  +=     pledge-seccomp.c\n' >>$CONFIG_MK
+[ -z "$have_pledge" -a -n "$BUILD_SECCOMP" ] && \
+       check_func "seccomp_h" "$src" && \
+       {
+               have_pledge=1
+               printf 'OPENBSD  +=     pledge-seccomp.o\n' >>$CONFIG_MK
        }
-elif [ -n "$have_pledge" ]; then
-       printf 'OPENBSD  +=     pledge-noop.c\n' >>$CONFIG_MK
-fi
+
+[ -z "$have_pledge" ] && \
+       printf 'OPENBSD  +=     pledge-noop.o\n' >>$CONFIG_MK