#!/usr/bin/env bash
# reconfigure -- try to run ./configure with the last used options

if [[ configure.ac -nt configure ]] ||
   [[ configure.in -nt configure ]] ||
   [[ autogen.sh   -nt configure ]]; then
	if [[ -x autogen.sh ]]; then
		(NOCONFIGURE=1 ./autogen.sh)
	elif [[ -e autogen.sh ]]; then
		(NOCONFIGURE=1 sh ./autogen.sh)
	else
		(autoreconf -fi)
	fi
fi

if [[ -e config.log ]] && ! (( $# )); then
	sed -n '/^  \$ /{s///;p;q}' config.log | sh
else
	(./configure --prefix="$PREFIX" "$@")
fi
