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-seccomp enable seccomp
26 --enable-static prepare for static build
28 --help, -h display this help and exit
37 --prefix) PREFIX=$var;;
38 --exec-prefix) EPREFIX=$var;;
39 --bindir) BINDIR=$var;;
40 --datadir) SHAREDIR=$var;;
41 --mandir) MANDIR=$var;;
42 --sysconfdir) SYSCONFDIR=$var;;
43 --pamdir) PAMDIR=$var;;
46 --target) TARGET=$var;;
47 --enable-debug) DEBUG=yes;;
48 --enable-seccomp) BUILD_SECCOMP=yes;;
49 --enable-static) BUILD_STATIC=yes;;
51 *) die "Error: unknown option $opt";;
58 # : ${VERSION:="$(git describe --dirty --tags --long --always)"}
61 cat <<EOF >>$CONFIG_MK
62 PREFIX ?= ${PREFIX:="/usr"}
63 EPREFIX ?= ${EPREFIX:="${PREFIX}"}
64 BINDIR ?= ${BINDIR:="${PREFIX}/bin"}
65 SHAREDIR ?= ${SHAREDIR:="${PREFIX}/share"}
66 MANDIR ?= ${MANDIR:="${SHAREDIR}/man"}
67 SYSCONFDIR?= ${SYSCONFDIR:="/etc"}
68 PAMDIR ?= ${PAMDIR:="${SYSCONFDIR}/pam.d"}
69 CFLAGS += -DVERSION="\"${VERSION}\""
72 if [ -z "$BUILD" ]; then
73 BUILD="$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')"
75 if [ -z "$HOST" ]; then
76 [ -z "$TARGET" ] && TARGET=$BUILD
79 if [ -z "$TARGET" ]; then
80 [ -z "$HOST" ] && HOST=$BUILD
85 # Derive OS from cpu-manufacturer-os-kernel
95 OS_CFLAGS="-D__${OS}__"
99 OS_CFLAGS="$OS_CFLAGS -D_DEFAULT_SOURCE -D_GNU_SOURCE -DUID_MAX=60000 -DGID_MAX=60000"
100 printf 'CURDIR := .\n' >>$CONFIG_MK
101 printf 'PAM_DOAS = pam.d__doas__linux\n' >>$CONFIG_MK
105 [ -n "$OS_CFLAGS" ] && \
106 printf 'CFLAGS += %s\n' "$OS_CFLAGS" >>$CONFIG_MK
109 printf 'CFLAGS += -O0 -g\n' >>$CONFIG_MK
111 [ -n "$BUILD_STATIC" ] && \
112 printf 'CFLAGS += -static\n' >>$CONFIG_MK
114 # Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features
115 XCC="${CC:=clang} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS"
116 # Make sure to disable --as-needed for CC tests.
117 XCC="$XCC -Wl,--no-as-needed"
120 func="$1"; src="$2"; shift 2
121 printf 'Checking for %-14s\t\t' "$func ..."
122 printf '%s\n' "$src" >"_$func.c"
123 $XCC "_$func.c" -o "_$func" 2>/dev/null
125 rm -f "_$func.c" "_$func"
126 if [ $ret -eq 0 ]; then
128 upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')"
129 printf 'CFLAGS += -DHAVE_%s\n' "$upperfunc" >>$CONFIG_MK
140 explicit_bzero(NULL, 0);
143 check_func "explicit_bzero" "$src" || {
144 printf 'OPENBSD += explicit_bzero.o\n' >>$CONFIG_MK
149 # Check for strlcat().
154 const char s1[] = "foo";
156 strlcat(s2, s1, sizeof(s2));
159 check_func "strlcat" "$src" || {
160 printf 'OPENBSD += strlcat.o\n' >>$CONFIG_MK
164 # Check for strlcpy().
169 const char s1[] = "foo";
171 strlcpy(s2, s1, sizeof(s2));
174 check_func "strlcpy" "$src" || {
175 printf 'OPENBSD += strlcpy.o\n' >>$CONFIG_MK
187 check_func "errc" "$src" || {
188 printf 'OPENBSD += errc.o\n' >>$CONFIG_MK
200 check_func "verrc" "$src" || {
201 printf 'OPENBSD += verrc.o\n' >>$CONFIG_MK
205 # Check for setprogname().
213 check_func "setprogname" "$src" || {
214 printf 'OPENBSD += progname.o\n' >>$CONFIG_MK
218 # Check for readpassphrase().
221 #include <readpassphrase.h>
224 readpassphrase("", buf, sizeof(buf), 0);
227 check_func "readpassphrase" "$src" || {
228 printf 'OPENBSD += readpassphrase.o\n' >>$CONFIG_MK
232 # Check for strtonum().
238 strtonum("", 1, 64, &errstr);
241 check_func "strtonum" "$src" || {
242 printf 'OPENBSD += strtonum.o\n' >>$CONFIG_MK
246 # Check for reallocarray().
251 reallocarray(NULL, 0, 0);
254 check_func "reallocarray" "$src" || {
255 printf 'OPENBSD += reallocarray.o\n' >>$CONFIG_MK
259 # Check for bsd_auth.h.
262 #include <bsd_auth.h>
266 check_func "bsd_auth_h" "$src" && \
270 # Check for pam_appl.h.
273 #include <security/pam_appl.h>
277 [ -z "$have_bsd_auth_h" ] && \
278 check_func "pam_appl_h" "$src" && {
279 printf 'SRCS += doas_pam.c\n' >>$CONFIG_MK
280 printf 'LDFLAGS += -lpam\n' >>$CONFIG_MK
284 # Check for login_cap.h.
287 #include <login_cap.h>
291 check_func "login_cap_h" "$src" || {
292 printf 'OPENBSD += setusercontext.o\n' >>$CONFIG_MK
296 # Check for execvpe().
301 const char *p = { "", NULL };
305 check_func "execvpe" "$src" || {
306 printf 'OPENBSD += execvpe.o\n' >>$CONFIG_MK
310 # Check for setresuid().
318 check_func "setresuid" "$src" || {
319 printf 'OPENBSD += setresuid.o\n' >>$CONFIG_MK
323 # Check for pledge().
331 check_func "pledge" "$src" && {
336 # Check for seccomp.h
339 #include <linux/seccomp.h>
340 #include <sys/prctl.h>
343 prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, NULL);
346 [ -z "$have_pledge" -a -n "$BUILD_SECCOMP" ] && \
347 check_func "seccomp_h" "$src" && \
350 printf 'OPENBSD += pledge-seccomp.o\n' >>$CONFIG_MK
353 [ -z "$have_pledge" ] && \
354 printf 'OPENBSD += pledge-noop.o\n' >>$CONFIG_MK