10 usage: configure [options]
12 --prefix=PREFIX installation prefix [/usr]
13 --exec-prefix=EPREFIX installation prefix for executable files [PREFIX]
14 --bindir=DIR user executables [PREFIX/bin]
15 --datadir=DIR architecture-independent data files [PREFIX/share]
16 --mandir=DIR manual pages [DATADIR/man]
17 --sysconfdir=DIR directory for configuration files [/etc]
18 --pamdir=DIR PAM directory [SYSCONFDIR/pam.d]
20 --build=build-alias a cpu-vendor-opsys for the system where the application will be built
21 --host=host-alias a cpu-vendor-opsys for the system where the application will run
22 --target=target-alias the machine that CC will produce code for
24 --enable-debug enable debugging
25 --enable-static prepare for static build
27 --without-pam disable pam support
28 --without-shadow disable shadow support
30 --with-timestamp enable timestamp support
32 --uid-max=NUM set UID_MAX (default 65535)
33 --gid-max=NUM set GID_MAX (default 65535)
35 --help, -h display this help and exit
49 --prefix) PREFIX=$var ;;
50 --exec-prefix) EPREFIX=$var ;;
51 --bindir) BINDIR=$var ;;
52 --datadir) SHAREDIR=$var ;;
53 --mandir) MANDIR=$var ;;
54 --sysconfdir) SYSCONFDIR=$var ;;
55 --pamdir) PAMDIR=$var ;;
56 --build) BUILD=$var ;;
58 --target) TARGET=$var ;;
59 --enable-debug) DEBUG=yes ;;
60 --enable-static) BUILD_STATIC=yes ;;
61 --with-pam) WITHOUT_PAM=; WITHOUT_SHADOW=yes ;;
62 --with-shadow) WITHOUT_SHADOW=; WITHOUT_PAM=yes ;;
63 --without-pam) WITHOUT_PAM=yes ;;
64 --without-shadow) WITHOUT_SHADOW=yes ;;
65 --with-timestamp) WITHOUT_TIMESTAMP= ;;
66 --without-timestamp) WITHOUT_TIMESTAMP=yes ;;
67 --uid-max) UID_MAX=$var ;;
68 --gid-max) UID_MAX=$var ;;
70 *) die "Error: unknown option $opt" ;;
76 rm -f "$CONFIG_MK" "$CONFIG_H"
84 cat <<EOF >>$CONFIG_MK
85 PREFIX ?= ${PREFIX:="/usr"}
86 EPREFIX ?= ${EPREFIX:="${PREFIX}"}
87 BINDIR ?= ${BINDIR:="${PREFIX}/bin"}
88 SHAREDIR ?= ${SHAREDIR:="${PREFIX}/share"}
89 MANDIR ?= ${MANDIR:="${SHAREDIR}/man"}
90 SYSCONFDIR?= ${SYSCONFDIR:="/etc"}
91 PAMDIR ?= ${PAMDIR:="${SYSCONFDIR}/pam.d"}
94 if [ -z "$BUILD" ]; then
95 BUILD="$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')"
97 if [ -z "$HOST" ]; then
98 [ -z "$TARGET" ] && TARGET=$BUILD
101 if [ -z "$TARGET" ]; then
102 [ -z "$HOST" ] && HOST=$BUILD
106 if [ -z "$OS" ]; then
107 # Derive OS from cpu-manufacturer-os-kernel
117 OS_CFLAGS="-D__${OS}__"
121 printf 'Setting UID_MAX\t\t\t\t%d.\n' "$UID_MAX" >&2
122 printf '#define UID_MAX %s\n' "$UID_MAX" >>$CONFIG_H
123 printf 'Setting GID_MAX\t\t\t\t%d.\n' "$GID_MAX" >&2
124 printf '#define GID_MAX %s\n' "$GID_MAX" >>$CONFIG_H
125 OS_CFLAGS="$OS_CFLAGS -D_DEFAULT_SOURCE -D_GNU_SOURCE"
126 printf 'CURDIR := .\n' >>$CONFIG_MK
129 OS_CFLAGS="$OS_CFLAGS -D_OPENBSD_SOURCE"
133 [ -n "$OS_CFLAGS" ] && \
134 printf 'CFLAGS += %s\n' "$OS_CFLAGS" >>$CONFIG_MK
137 printf 'CFLAGS += -O0 -g\n' >>$CONFIG_MK
139 [ -n "$BUILD_STATIC" ] && \
140 printf 'CFLAGS += -static\n' >>$CONFIG_MK
142 # Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features
143 XCC="${CC:=cc} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS"
144 # Make sure to disable --as-needed for CC tests.
145 XCC="$XCC -Wl,--no-as-needed"
148 func="$1"; src="$2"; shift 2
149 printf 'Checking for %-14s\t\t' "$func ..." >&2
150 printf '%s\n' "$src" >"_$func.c"
151 $XCC "_$func.c" -o "_$func" 2>/dev/null
153 rm -f "_$func.c" "_$func"
154 upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')"
155 if [ $ret -eq 0 ]; then
157 printf '#define HAVE_%s\n' "$upperfunc" >>$CONFIG_H
160 printf '/* #define HAVE_%s */\n' "$upperfunc" >>$CONFIG_H
168 # Check for pam_appl.h.
171 #include <security/pam_appl.h>
175 [ -z "$WITHOUT_PAM" ] && check_func "pam_appl_h" "$src" && {
176 printf 'SRCS += pam.c\n' >>$CONFIG_MK
177 printf 'LDFLAGS += -lpam\n' >>$CONFIG_MK
178 printf '#define USE_PAM\n' >>$CONFIG_H
181 pam_file="pam.d__doas__${OS}"
182 [ -e "$pam_file" ] && printf 'PAM_DOAS = %s\n' "$pam_file" >>$CONFIG_MK
187 # Check for shadow.h.
194 [ -z "$WITHOUT_SHADOW" ] && check_func "shadow_h" "$src" && {
195 printf 'SRCS += shadow.c\n' >>$CONFIG_MK
196 printf 'LDFLAGS += -lcrypt\n' >>$CONFIG_MK
197 printf '#define USE_SHADOW\n' >>$CONFIG_H
206 [ -z "$WITHOUT_TIMESTAMP" ] && {
207 printf '#define USE_TIMESTAMP\n' >>$CONFIG_H
208 printf 'SRCS += timestamp.c\n' >>$CONFIG_MK
216 # Check for explicit_bzero().
221 explicit_bzero(NULL, 0);
224 check_func "explicit_bzero" "$src" || {
225 printf 'SRCS += libopenbsd/explicit_bzero.c\n' >>$CONFIG_MK
229 # Check for strlcat().
234 const char s1[] = "foo";
236 strlcat(s2, s1, sizeof(s2));
239 check_func "strlcat" "$src" || {
240 printf 'SRCS += libopenbsd/strlcat.c\n' >>$CONFIG_MK
244 # Check for strlcpy().
249 const char s1[] = "foo";
251 strlcpy(s2, s1, sizeof(s2));
254 check_func "strlcpy" "$src" || {
255 printf 'SRCS += libopenbsd/strlcpy.c\n' >>$CONFIG_MK
267 check_func "errc" "$src" || {
268 printf 'SRCS += libopenbsd/errc.c\n' >>$CONFIG_MK
280 check_func "verrc" "$src" || {
281 printf 'SRCS += libopenbsd/verrc.c\n' >>$CONFIG_MK
285 # Check for setprogname().
293 check_func "setprogname" "$src" || {
294 printf 'SRCS += libopenbsd/progname.c\n' >>$CONFIG_MK
298 # Check for readpassphrase().
301 #include <readpassphrase.h>
304 readpassphrase("", buf, sizeof(buf), 0);
307 check_func "readpassphrase" "$src" || {
308 printf 'SRCS += libopenbsd/readpassphrase.c\n' >>$CONFIG_MK
312 # Check for strtonum().
318 strtonum("", 1, 64, &errstr);
321 check_func "strtonum" "$src" || {
322 printf 'SRCS += libopenbsd/strtonum.c\n' >>$CONFIG_MK
326 # Check for reallocarray().
331 reallocarray(NULL, 0, 0);
334 check_func "reallocarray" "$src" || {
335 printf 'SRCS += libopenbsd/reallocarray.c\n' >>$CONFIG_MK
339 # Check for execvpe().
344 const char *p = { "", NULL };
348 check_func "execvpe" "$src" || die "system has no execvpe(3): not supported"
351 # Check for setresuid().
359 check_func "setresuid" "$src" || {
360 printf 'SRCS += libopenbsd/bsd-setres_id.c\n' >>$CONFIG_MK
364 # Check for closefrom().
372 check_func "closefrom" "$src" || {
373 printf 'SRCS += libopenbsd/closefrom.c\n' >>$CONFIG_MK
377 # Check for sysconf().
385 check_func "sysconf" "$src"
396 check_func "dirfd" "$src"
406 check_func "fcntl_h" "$src"
409 # Check for F_CLOSEM.
419 check_func "F_CLOSEM" "$src"
422 # Check for dirent.h.
429 check_func "dirent_h" "$src"
432 # Check for sys/ndir.h.
435 #include <sys/ndir.h>
439 check_func "sys_ndir_h" "$src"
442 # Check for sys/dir.h.
449 check_func "sys_dir_h" "$src"
459 check_func "ndir_h" "$src"
462 # Check for login_cap.h.
465 #include <sys/types.h>
466 #include <login_cap.h>
470 check_func "login_cap_h" "$src"
477 int main(void){return 0;}
478 __attribute__((__unused__)) static void foo(void){return;}
480 check_func "__attribute__" "$src" || {
481 printf 'CFLAGS += -DNO_ATTRIBUTE_ON_RETURN_TYPE=1\n' >>$CONFIG_MK
485 if [ $? -eq 0 ]; then
486 printf 'Using auth method\t\t\t%s.\n' "$auth" >&2
488 printf 'Error auth method\t\t\n' >&2
492 persist=$(persistmethod)
493 if [ $? -eq 0 ]; then
494 printf 'Using persist method\t\t\t%s.\n' "$persist" >&2
496 printf 'Using persist method\t\t\tnone.\n' >&2
499 printf '#define DOAS_CONF "%s/doas.conf"\n' "${SYSCONFDIR}" >>$CONFIG_H
501 printf '\n#endif /* CONFIG_H */\n' >>$CONFIG_H