#!/bin/sh
#
# Use this when doing code development

SRCDIR=${SRCDIR:-$(dirname "$0")}

set -ex

make -k distclean > /dev/null 2>&1 || true

# Prefer CLANG if we have it, and have not given preferences
if command -v clang >/dev/null && test -z "$CC" ; then
	CC=clang
	export CC
fi

if [ "x$DST" != "x" ] ; then
	:
elif [ "x`uname -o`" = "xFreeBSD" ] ; then
	DST="--prefix=/usr/local --mandir=/usr/local/man"
else
	DST="--prefix=/opt/varnish --mandir=/opt/varnish/man"
fi

PERSISTENT=--with-persistent-storage

if [ `uname -m` = "s390x" ] ; then
	# ASLR makes this impossible
	PERSISTENT=
fi

rm -f $SRCDIR/configure
autoreconf -i -v $SRCDIR

# NB: Workaround for make distcheck not working with
# NB: FreeBSD's make on -current
# env MAKE=gmake \
$SRCDIR/configure \
    $DST \
    --enable-maintainer-mode \
    --enable-developer-warnings \
    --enable-debugging-symbols \
    --enable-dependency-tracking \
    ${PERSISTENT} \
    --with-contrib \
    "$@"
