#!/bin/sh
+#
+# Copyright © 2011-2012, 2015 Nick Bowler
+#
+# Simple script to get started from a fresh git checkout.
+#
+# License WTFPL2: Do What The Fuck You Want To Public License, version 2.
+# This is free software: you are free to do what the fuck you want to.
+# There is NO WARRANTY, to the extent permitted by law.
-die()
-{
- echo $@ 1>&2
+scriptname=$0
+
+err() {
+ printf '%s: %s\n' "$scriptname" "$@" 1>&2
+}
+
+die() {
+ err "$@"
exit 1
}
-test -d m4 || mkdir m4
-test -d lib || mkdir lib
+: ${LIBTOOLIZE=libtoolize}
+: ${AUTORECONF=autoreconf}
+: ${GNULIB=gnulib}
+: ${GIT=git}
+: ${PERL=perl}
+
+$GIT submodule update --init || err "Failed to update submodules from git."
-git submodule update --init || echo "Failed to update Gnulib sources from git."
-if test -x gnulib/gnulib-tool; then
- gnulib/gnulib-tool --update || die "Failed to update gnulib."
+if test -x $GNULIB/gnulib-tool; then
+ $GNULIB/gnulib-tool --update -S || die "Failed to update Gnulib."
else
- die "Gnulib sources are not properly installed in gnulib/"
+ die "Gnulib sources are not properly installed in gnulib/."
fi
-autoreconf -fis
+$PERL common/scripts/fix-gnulib.pl -o lib/gnulib.mk -i lib/gnulib.mk.in \
+ || die "Failed to fixup Gnulib makefile fragment."
+
+# Frustratingly, libtoolize has changed the name of its nonrecursive ltdl
+# makefile output, which broke all packages depending on previous documented
+# behaviour. Work around the issue by renaming the output.
+rm -f libltdl/ltdl.mk
+$LIBTOOLIZE -f || die "Failed to run libtoolize."
+test ! -f libltdl/Makefile.inc || mv -f libltdl/Makefile.inc libltdl/ltdl.mk.in
+test ! -f libltdl/ltdl.mk || mv -f libltdl/ltdl.mk libltdl/ltdl.mk.in
+
+$PERL common/scripts/fix-ltdl.pl -o libltdl/ltdl.mk -i libltdl/ltdl.mk.in \
+ || die "Failed to fixup libltdl makefile fragment."
+
+# Punt some automake-generated files so that Gentoo's wrapper script doesn't
+# try to detect the automake version in use.
+rm -f Makefile.in aclocal.m4
+LIBTOOLIZE=true $AUTORECONF -fis