-#!/bin/sh
+#! /bin/sh -e
+
+have_ext=$(if test -e ext/automake.mk; then echo yes; else echo no; fi)
+for opt
+do
+ case $opt in
+ (--enable-ext) have_ext=yes ;;
+ (--disable-ext) have_ext=no ;;
+ (--help) cat <<EOF
+$0: bootstrap OpenFlow from a Git repository
+usage: $0 [OPTIONS]
+The recognized options are:
+ --enable-ext include openflowext
+ --disable-ext exclude openflowext
+By default, openflowext is included if it is present.
+EOF
+ exit 0
+ ;;
+ (*) echo "unknown option $opt; use --help for help"; exit 1 ;;
+ esac
+done
+
# Generate list of files in debian/ to distribute.
(echo '# Automatically generated by boot.sh (from Git tree).' &&
- echo 'EXTRA_DIST = \' &&
- cd debian && git ls-files | grep -v '^\.gitignore$' |
- sed -e 's/\(.*\)/ \1 \\/' -e '$s/ \\//') > debian/Makefile.am
+ echo 'EXTRA_DIST += \' &&
+ git ls-files debian | grep -v '^debian/\.gitignore$' |
+ sed -e 's/\(.*\)/ \1 \\/' -e '$s/ \\//') > debian/automake.mk
+
+# Find the "include ext/automake.mk" line in Makefile.am and comment
+# it out or in according to whether ext is available, and similarly
+# for "m4_include(ext/configure.m4)" in configure.ac.
+if test "$have_ext" = yes; then
+ echo 'Enabling openflowext...'
+ perl -i.bak -pe 's|^#(include ext/automake\.mk)$|$1|' Makefile.am
+ perl -i.bak -pe 's|^#(m4_include\(ext/configure\.m4\))$|$1|' configure.ac
+else
+ echo 'Disabling openflowext...'
+ perl -i.bak -pe 's|^(include ext/automake\.mk)$|#$1|' Makefile.am
+ perl -i.bak -pe 's|^(m4_include\(ext/configure\.m4\))$|#$1|' configure.ac
+fi
# Bootstrap configure system from .ac/.am files
autoreconf --install -I config --force