]> git.armaanb.net Git - opendoas.git/blobdiff - configure
configure: use LDLIBS instead of setting LDFLAGS
[opendoas.git] / configure
index bd1b94f57666b02e96c24fc6f9005a84ef5a03aa..9592a30f2b781d896652a975aecaa34ea7fcf6a7 100755 (executable)
--- a/configure
+++ b/configure
@@ -72,17 +72,14 @@ for x; do
 done
 
 CONFIG_MK=config.mk
-rm -f "$CONFIG_MK"
+CONFIG_H=config.h
+rm -f "$CONFIG_MK" "$CONFIG_H"
 
-cat <<EOF >>$CONFIG_MK
-PREFIX   ?=    ${PREFIX:="/usr"}
-EPREFIX  ?=    ${EPREFIX:="${PREFIX}"}
-BINDIR   ?=    ${BINDIR:="${PREFIX}/bin"}
-SHAREDIR ?=    ${SHAREDIR:="${PREFIX}/share"}
-MANDIR   ?=    ${MANDIR:="${SHAREDIR}/man"}
-SYSCONFDIR?=   ${SYSCONFDIR:="/etc"}
-PAMDIR   ?=    ${PAMDIR:="${SYSCONFDIR}/pam.d"}
-EOF
+cat <<! >$CONFIG_H
+#ifndef CONFIG_H
+#define CONFIG_H
+
+!
 
 if [ -z "$BUILD" ]; then
        BUILD="$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')"
@@ -111,13 +108,50 @@ OS_CFLAGS="-D__${OS}__"
 
 case "$OS" in
        linux)
-               OS_CFLAGS="$OS_CFLAGS -D_DEFAULT_SOURCE -D_GNU_SOURCE -DUID_MAX=${UID_MAX} -DGID_MAX=${GID_MAX}"
-               printf 'CURDIR   :=     .\n' >>$CONFIG_MK
-               [ -z "$WITHOUT_PAM" ] && \
-                       printf 'PAM_DOAS  =     pam.d__doas__linux\n' >>$CONFIG_MK
+               printf 'Setting UID_MAX\t\t\t\t%d.\n' "$UID_MAX" >&2
+               printf '#define UID_MAX %s\n' "$UID_MAX" >>$CONFIG_H
+               printf 'Setting GID_MAX\t\t\t\t%d.\n' "$GID_MAX" >&2
+               printf '#define GID_MAX %s\n' "$GID_MAX" >>$CONFIG_H
+               OS_CFLAGS="$OS_CFLAGS -D_DEFAULT_SOURCE -D_GNU_SOURCE"
+               ;;
+       netbsd)
+               OS_CFLAGS="$OS_CFLAGS -D_OPENBSD_SOURCE"
+               printf 'LDLIBS +=       -lutil\n' >>$CONFIG_MK
+               : ${BINGRP:=wheel}
+               ;;
+       freebsd)
+               printf 'LDLIBS +=       -lutil\n' >>$CONFIG_MK
+               : ${BINGRP:=wheel}
+               ;;
+       darwin)
+               : ${BINGRP:=wheel}
                ;;
 esac
 
+: ${PREFIX:=/usr/local}
+: ${EPREFIX:=${PREFIX}}
+: ${BINDIR:=${PREFIX}/bin}
+: ${SHAREDIR:=${PREFIX}/share}
+: ${MANDIR:=${SHAREDIR}/man}
+: ${SYSCONFDIR:=/etc}
+: ${PAMDIR:=${SYSCONFDIR}/pam.d}
+: ${BINMODE:=4755}
+: ${BINOWN:=root}
+: ${BINGRP:=root}
+
+cat <<EOF >>$CONFIG_MK
+PREFIX   ?=    ${PREFIX}
+EPREFIX  ?=    ${EPREFIX}
+BINDIR   ?=    ${BINDIR}
+SHAREDIR ?=    ${SHAREDIR}
+MANDIR   ?=    ${MANDIR}
+SYSCONFDIR?=   ${SYSCONFDIR}
+PAMDIR   ?=    ${PAMDIR}
+BINMODE  ?=    ${BINMODE}
+BINOWN  ?=     ${BINOWN}
+BINGRP  ?=     ${BINGRP}
+EOF
+
 [ -n "$OS_CFLAGS" ] && \
        printf 'CFLAGS   +=     %s\n' "$OS_CFLAGS" >>$CONFIG_MK
 
@@ -127,10 +161,14 @@ esac
 [ -n "$BUILD_STATIC" ] && \
        printf 'CFLAGS   +=     -static\n' >>$CONFIG_MK
 
-# Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features
-XCC="${CC:=cc} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS"
+# Add CPPFLAGS/CFLAGS/LDFLAGS/LDLIBS to CC for testing features
+XCC="${CC:=cc} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS $LDLIBS"
 # Make sure to disable --as-needed for CC tests.
-XCC="$XCC -Wl,--no-as-needed"
+
+case "$OS" in
+       darwin) ;;
+       *) XCC="$XCC -Wl,--no-as-needed" ;;
+esac
 
 check_func() {
        func="$1"; src="$2"; shift 2
@@ -139,12 +177,13 @@ check_func() {
        $XCC "_$func.c" -o "_$func" 2>/dev/null
        ret=$?
        rm -f "_$func.c" "_$func"
+       upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')"
        if [ $ret -eq 0 ]; then
                printf 'yes.\n' >&2
-               upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')"
-               printf 'CFLAGS   +=     -DHAVE_%s\n' "$upperfunc" >>$CONFIG_MK
+               printf '#define HAVE_%s\n' "$upperfunc" >>$CONFIG_H
                return 0
        else
+               printf '/* #define HAVE_%s */\n' "$upperfunc" >>$CONFIG_H
                printf 'no.\n' >&2
                return 1
        fi
@@ -161,9 +200,12 @@ int main(void) {
 }'
        [ -z "$WITHOUT_PAM" ] && check_func "pam_appl_h" "$src" && {
                printf 'SRCS     +=     pam.c\n' >>$CONFIG_MK
-               printf 'LDFLAGS  +=     -lpam\n' >>$CONFIG_MK
-               printf 'CPPFLAGS +=     -DUSE_PAM\n' >>$CONFIG_MK
+               printf 'LDLIBS +=       -lpam\n' >>$CONFIG_MK
+               printf '#define USE_PAM\n' >>$CONFIG_H
                printf 'pam\n'
+
+               pam_file="pam.d__doas__${OS}"
+               [ -e "$pam_file" ] && printf 'PAM_DOAS  =       %s\n' "$pam_file" >>$CONFIG_MK
                return 0
        }
 
@@ -177,8 +219,8 @@ int main(void) {
 }'
        [ -z "$WITHOUT_SHADOW" ] && check_func "shadow_h" "$src" && {
                printf 'SRCS     +=     shadow.c\n' >>$CONFIG_MK
-               printf 'LDFLAGS  +=     -lcrypt\n' >>$CONFIG_MK
-               printf 'CPPFLAGS +=     -DUSE_SHADOW\n' >>$CONFIG_MK
+               printf 'LDLIBS +=       -lcrypt\n' >>$CONFIG_MK
+               printf '#define USE_SHADOW\n' >>$CONFIG_H
                printf 'shadow\n'
                return 0
        }
@@ -188,7 +230,7 @@ int main(void) {
 
 persistmethod() {
        [ -z "$WITHOUT_TIMESTAMP" ] && {
-               printf 'CPPFLAGS += -DUSE_TIMESTAMP\n' >>$CONFIG_MK
+               printf '#define USE_TIMESTAMP\n' >>$CONFIG_H
                printf 'SRCS    += timestamp.c\n' >>$CONFIG_MK
                printf 'timestamp\n'
                return 0
@@ -206,7 +248,7 @@ int main(void) {
        return 0;
 }'
 check_func "explicit_bzero" "$src" || {
-       printf 'OPENBSD  +=     explicit_bzero.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/explicit_bzero.c\n' >>$CONFIG_MK
 }
 
 #
@@ -221,7 +263,7 @@ int main(void) {
        return 0;
 }'
 check_func "strlcat" "$src" || {
-       printf 'OPENBSD  +=     strlcat.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/strlcat.c\n' >>$CONFIG_MK
 }
 
 #
@@ -236,7 +278,7 @@ int main(void) {
        return 0;
 }'
 check_func "strlcpy" "$src" || {
-       printf 'OPENBSD  +=     strlcpy.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/strlcpy.c\n' >>$CONFIG_MK
 }
 
 #
@@ -249,20 +291,21 @@ int main(void) {
        return 0;
 }'
 check_func "errc" "$src" || {
-       printf 'OPENBSD  +=     errc.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/errc.c\n' >>$CONFIG_MK
 }
 
 #
 # Check for verrc().
 #
 src='
+#include <stddef.h>
 #include <err.h>
 int main(void) {
-       verrc(0, 0, "");
+       verrc(0, 0, "x", NULL);
        return 0;
 }'
 check_func "verrc" "$src" || {
-       printf 'OPENBSD  +=     verrc.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/verrc.c\n' >>$CONFIG_MK
 }
 
 #
@@ -275,7 +318,7 @@ int main(void) {
        return 0;
 }'
 check_func "setprogname" "$src" || {
-       printf 'OPENBSD  +=     progname.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/progname.c\n' >>$CONFIG_MK
 }
 
 #
@@ -289,7 +332,7 @@ int main(void) {
        return 0;
 }'
 check_func "readpassphrase" "$src" || {
-       printf 'OPENBSD  +=     readpassphrase.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/readpassphrase.c\n' >>$CONFIG_MK
 }
 
 #
@@ -303,7 +346,7 @@ int main(void) {
        return 0;
 }'
 check_func "strtonum" "$src" || {
-       printf 'OPENBSD  +=     strtonum.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/strtonum.c\n' >>$CONFIG_MK
 }
 
 #
@@ -316,7 +359,7 @@ int main(void) {
        return 0;
 }'
 check_func "reallocarray" "$src" || {
-       printf 'OPENBSD  +=     reallocarray.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/reallocarray.c\n' >>$CONFIG_MK
 }
 
 #
@@ -329,7 +372,9 @@ int main(void) {
        execvpe("", p, p);
        return 0;
 }'
-check_func "execvpe" "$src" || die "system has no execvpe(3): not supported"
+check_func "execvpe" "$src" || {
+       printf 'SRCS += libopenbsd/execvpe.c\n' >>$CONFIG_MK
+}
 
 #
 # Check for setresuid().
@@ -340,7 +385,47 @@ int main(void) {
        setresuid(0, 0, 0);
        return 0;
 }'
-check_func "setresuid" "$src" || die "system has no setresuid(2): not supported"
+check_func "setresuid" "$src"
+have_setresuid=$?
+
+#
+# Check for setresgid().
+#
+src='
+#include <unistd.h>
+int main(void) {
+       setresgid(0, 0, 0);
+       return 0;
+}'
+check_func "setresgid" "$src"
+have_setresgid=$?
+
+if [ $have_setresuid -eq 1 -o $have_setresgid -eq 1 ]; then
+       printf 'SRCS += libopenbsd/bsd-setres_id.c\n' >>$CONFIG_MK
+fi
+
+#
+# Check for setreuid().
+#
+src='
+#include <unistd.h>
+int main(void) {
+       setreuid(0, 0);
+       return 0;
+}'
+check_func "setreuid" "$src"
+
+
+#
+# Check for setregid().
+#
+src='
+#include <unistd.h>
+int main(void) {
+       setregid(0, 0);
+       return 0;
+}'
+check_func "setregid" "$src"
 
 #
 # Check for closefrom().
@@ -352,7 +437,7 @@ int main(void) {
        return 0;
 }'
 check_func "closefrom" "$src" || {
-       printf 'OPENBSD  +=     closefrom.o\n' >>$CONFIG_MK
+       printf 'SRCS += libopenbsd/closefrom.c\n' >>$CONFIG_MK
 }
 
 #
@@ -366,17 +451,6 @@ int main(void) {
 }'
 check_func "sysconf" "$src"
 
-#
-# Check for /proc/$PID.
-#
-printf 'Checking for %-14s\t\t' "/proc/\$PID ..." >&2
-if test -d /proc/$$; then
-       printf 'yes.\n' >&2
-       printf 'CFLAGS   +=     -DHAVE_%s\n' "PROC_PID" >>$CONFIG_MK
-else
-       printf 'no.\n' >&2
-fi
-
 #
 # Check for dirfd().
 #
@@ -488,5 +562,7 @@ if [ $? -eq 0 ]; then
 else
        printf 'Using persist method\t\t\tnone.\n' >&2
 fi
-printf 'Setting UID_MAX\t\t\t\t%d.\n' "$UID_MAX" >&2
-printf 'Setting GID_MAX\t\t\t\t%d.\n' "$GID_MAX" >&2
+
+printf '#define DOAS_CONF "%s/doas.conf"\n' "${SYSCONFDIR}" >>$CONFIG_H
+
+printf '\n#endif /* CONFIG_H */\n' >>$CONFIG_H