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)"}
60 cat <<EOF >>$CONFIG_MK
61 PREFIX ?= ${PREFIX:="/usr"}
62 EPREFIX ?= ${EPREFIX:="${PREFIX}"}
63 BINDIR ?= ${BINDIR:="${PREFIX}/bin"}
64 SHAREDIR ?= ${SHAREDIR:="${PREFIX}/share"}
65 MANDIR ?= ${MANDIR:="${SHAREDIR}/man"}
66 SYSCONFDIR?= ${SYSCONFDIR:="/etc"}
67 PAMDIR ?= ${PAMDIR:="${SYSCONFDIR}/pam.d"}
68 CFLAGS += -DVERSION="\"${VERSION}\""
71 if [ -z "$BUILD" ]; then
72 BUILD="$(uname -m)-unknown-$(uname -s | tr '[:upper:]' '[:lower:]')"
74 if [ -z "$HOST" ]; then
75 [ -z "$TARGET" ] && TARGET=$BUILD
78 if [ -z "$TARGET" ]; then
79 [ -z "$HOST" ] && HOST=$BUILD
84 # Derive OS from cpu-manufacturer-os-kernel
94 OS_CFLAGS="-D__${OS}__"
98 OS_CFLAGS="$OS_CFLAGS -D_DEFAULT_SOURCE -D_GNU_SOURCE -DUID_MAX=60000 -DGID_MAX=60000"
99 printf 'CURDIR := .\n' >>$CONFIG_MK
100 printf 'PAM_DOAS = pam.d__doas__linux\n' >>$CONFIG_MK
104 [ -n "$OS_CFLAGS" ] && \
105 printf 'CFLAGS += %s\n' "$OS_CFLAGS" >>$CONFIG_MK
108 printf 'CFLAGS += -O0 -g\n' >>$CONFIG_MK
110 [ -n "$BUILD_STATIC" ] && \
111 printf 'CFLAGS += -static\n' >>$CONFIG_MK
113 # Add CPPFLAGS/CFLAGS/LDFLAGS to CC for testing features
114 XCC="${CC:=clang} $CFLAGS $OS_CFLAGS $CPPFLAGS $LDFLAGS"
115 # Make sure to disable --as-needed for CC tests.
116 XCC="$XCC -Wl,--no-as-needed"
119 func="$1"; src="$2"; shift 2
120 printf 'Checking for %-14s\t\t' "$func ..."
121 printf '%s\n' "$src" >"_$func.c"
122 $XCC "_$func.c" -o "_$func" 2>/dev/null
124 rm -f "_$func.c" "_$func"
125 if [ $ret -eq 0 ]; then
127 upperfunc="$(printf '%s\n' "$func" | tr '[[:lower:]]' '[[:upper:]]')"
128 printf 'CFLAGS += -DHAVE_%s\n' "$upperfunc" >>$CONFIG_MK
139 explicit_bzero(NULL, 0);
142 check_func "explicit_bzero" "$src" || {
143 printf 'OPENBSD += explicit_bzero.o\n' >>$CONFIG_MK
148 # Check for strlcat().
153 const char s1[] = "foo";
155 strlcat(s2, s1, sizeof(s2));
158 check_func "strlcat" "$src" || {
159 printf 'OPENBSD += strlcat.o\n' >>$CONFIG_MK
163 # Check for strlcpy().
168 const char s1[] = "foo";
170 strlcpy(s2, s1, sizeof(s2));
173 check_func "strlcpy" "$src" || {
174 printf 'OPENBSD += strlcpy.o\n' >>$CONFIG_MK
186 check_func "errc" "$src" || {
187 printf 'OPENBSD += errc.o\n' >>$CONFIG_MK
199 check_func "verrc" "$src" || {
200 printf 'OPENBSD += verrc.o\n' >>$CONFIG_MK
204 # Check for setprogname().
212 check_func "setprogname" "$src" || {
213 printf 'OPENBSD += progname.o\n' >>$CONFIG_MK
217 # Check for readpassphrase().
220 #include <readpassphrase.h>
223 readpassphrase("", buf, sizeof(buf), 0);
226 check_func "readpassphrase" "$src" || {
227 printf 'OPENBSD += readpassphrase.o\n' >>$CONFIG_MK
231 # Check for strtonum().
237 strtonum("", 1, 64, &errstr);
240 check_func "strtonum" "$src" || {
241 printf 'OPENBSD += strtonum.o\n' >>$CONFIG_MK
245 # Check for reallocarray().
250 reallocarray(NULL, 0, 0);
253 check_func "reallocarray" "$src" || {
254 printf 'OPENBSD += reallocarray.o\n' >>$CONFIG_MK
258 # Check for bsd_auth.h.
261 #include <bsd_auth.h>
265 check_func "bsd_auth_h" "$src" && \
269 # Check for pam_appl.h.
272 #include <security/pam_appl.h>
276 [ -z "$have_bsd_auth_h" ] && \
277 check_func "pam_appl_h" "$src" && {
278 printf 'SRCS += doas_pam.c\n' >>$CONFIG_MK
279 printf 'LDFLAGS += -lpam\n' >>$CONFIG_MK
283 # Check for login_cap.h.
286 #include <login_cap.h>
290 check_func "login_cap_h" "$src" || {
291 printf 'OPENBSD += setusercontext.o\n' >>$CONFIG_MK
295 # Check for execvpe().
300 const char *p = { "", NULL };
304 check_func "execvpe" "$src" || {
305 printf 'OPENBSD += execvpe.o\n' >>$CONFIG_MK
309 # Check for setresuid().
317 check_func "setresuid" "$src" || {
318 printf 'OPENBSD += setresuid.o\n' >>$CONFIG_MK
322 # Check for pledge().
330 check_func "pledge" "$src" && {
335 # Check for seccomp.h
338 #include <linux/seccomp.h>
339 #include <sys/prctl.h>
342 prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, NULL);
345 [ -z "$have_pledge" -a -n "$BUILD_SECCOMP" ] && \
346 check_func "seccomp_h" "$src" && \
349 printf 'OPENBSD += pledge-seccomp.o\n' >>$CONFIG_MK
352 [ -z "$have_pledge" ] && \
353 printf 'OPENBSD += pledge-noop.o\n' >>$CONFIG_MK