+#! /bin/sh
+
+PROJECT=glenv
+PROJECT_BLURB="run an OpenGL program in a modified environment"
+
+srcdir=$(dirname "$0")
+
+# For a non-srcdir configure invocation (such as ../configure), create
+# the directory structure and copy Makefiles.
+if [ "$srcdir" != "." ]; then
+
+ for dir in . $(grep "^subdirs *=" "$srcdir"/Makefile | sed -e "s/subdirs *= *//"); do
+ mkdir -p "$dir"
+ cp "$srcdir"/"$dir"/Makefile.local "$dir"
+ cp "$srcdir"/"$dir"/Makefile "$dir"
+ done
+fi
+
+# Set several defaults (optionally specified by the user in
+# environment variables)
+CC=${CC:-gcc}
+CFLAGS=${CFLAGS:--O2}
+LDFLAGS=${LDFLAGS:-}
+
+# Set the defaults for values the user can specify with command-line
+# options.
+PREFIX=/usr/local
+
+usage ()
+{
+ cat <<EOF
+Usage: ./configure [options]...
+
+This script configures ${PROJECT} to build on your system.
+
+It verifies that dependencies are available, determines flags needed
+to compile and link against various required libraries, and identifies
+whether various system functions can be used or if locally-provided
+replacements will be built instead.
+
+Finally, it allows you to control various aspects of the build and
+installation process.
+
+First, some common variables can specified via environment variables:
+
+ CC The C compiler to use
+ CFLAGS Flags to pass to the C compiler
+ LDFLAGS Flags to pass when linking
+
+Each of these values can further be controlled by specifying them
+later on the "make" command line.
+
+Additionally, various options can be specified on the configure
+command line.
+
+ --prefix=PREFIX Install files in PREFIX [$PREFIX]
+
+By default, "make install" will install the resulting program to
+$PREFIX/bin, documentation to $PREFIX/man, etc. You can
+specify an installation prefix other than $PREFIX using
+--prefix, for instance:
+
+ ./configure --prefix=\$HOME
+
+Fine tuning of some installation directories is available:
+
+ --bindir=DIR Install executables to DIR [PREFIX/bin]
+ --libdir=DIR Install libraries to DIR [PREFIX/lib]
+ --mandir=DIR Install man pages to DIR [PREFIX/share/man]
+ --sysconfdir=DIR Read-only single-machine data [PREFIX/etc]
+
+Additional options are accepted for compatibility with other
+configure-script calling conventions, but don't do anything yet:
+
+ --build=<cpu>-<vendor>-<os> Currently ignored
+ --host=<cpu>-<vendor>-<os> Currently ignored
+ --infodir=DIR Currently ignored
+ --datadir=DIR Currently ignored
+ --localstatedir=DIR Currently ignored
+ --libexecdir=DIR Currently ignored
+ --disable-maintainer-mode Currently ignored
+ --disable-dependency-tracking Currently ignored
+
+EOF
+}
+
+# Parse command-line options
+for option; do
+ if [ "${option}" = '--help' ] ; then
+ usage
+ exit 0
+ elif [ "${option%%=*}" = '--prefix' ] ; then
+ PREFIX="${option#*=}"
+ elif [ "${option%%=*}" = '--bindir' ] ; then
+ BINDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--libdir' ] ; then
+ LIBDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--mandir' ] ; then
+ MANDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--sysconfdir' ] ; then
+ SYSCONFDIR="${option#*=}"
+ elif [ "${option%%=*}" = '--build' ] ; then
+ true
+ elif [ "${option%%=*}" = '--host' ] ; then
+ true
+ elif [ "${option%%=*}" = '--infodir' ] ; then
+ true
+ elif [ "${option%%=*}" = '--datadir' ] ; then
+ true
+ elif [ "${option%%=*}" = '--localstatedir' ] ; then
+ true
+ elif [ "${option%%=*}" = '--libexecdir' ] ; then
+ true
+ elif [ "${option}" = '--disable-maintainer-mode' ] ; then
+ true
+ elif [ "${option}" = '--disable-dependency-tracking' ] ; then
+ true
+ else
+ echo "Unrecognized option: ${option}"
+ echo "See:"
+ echo " $0 --help"
+ echo ""
+ exit 1
+ fi
+done
+
+printf "Checking for working C compiler (${CC})... "
+printf "int main(void){return 42;}\n" > minimal.c
+if ${CC} -o minimal minimal.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+else
+ printf "No.\n"
+ cat <<EOF
+
+*** Error: No functioning C compiler found. Either set the CC environment
+to a working C compiler, or else install gcc:
+
+ http://gcc.gnu.org/
+
+You may be able to install gcc with a command such as:
+
+ sudo apt-get install build-essential
+ or:
+ sudo yum install make automake gcc gcc-c++ kernel-devel
+
+EOF
+
+exit 1
+
+fi
+
+WARN_CFLAGS=""
+printf "Checking for available C compiler warning flags:\n"
+for flag in -Wall -Wextra -Wmissing-declarations -Werror=attributes; do
+ if ${CC} $flag -o minimal minimal.c > /dev/null 2>&1
+ then
+ WARN_CFLAGS="${WARN_CFLAGS}${WARN_CFLAGS:+ }${flag}"
+ fi
+done
+printf "\t${WARN_CFLAGS}\n"
+
+rm -f minimal minimal.c
+
+printf "#include <features.h>\nint main(void){return 0;}\n" > arch-minimal.c
+
+printf "Checking for machine-dependent compiler support:\n"
+
+printf " Compiler can create 32-bit binaries... "
+have_m32=Yes
+if ${CC} -m32 -o arch-minimal arch-minimal.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+else
+ printf "No.\n"
+ have_m32=No
+fi
+
+printf " Compiler can create 64-bit binaries... "
+have_m64=Yes
+if ${CC} -m64 -o arch-minimal arch-minimal.c > /dev/null 2>&1
+then
+ printf "Yes.\n"
+else
+ printf "No.\n"
+ have_m64=No
+fi
+
+if [ "$have_m32" = "No" ] || [ "$have_m64" = "No" ]; then
+ cat <<EOF
+
+* Warning: Cannot create both 32 and 64-bit glenv libraries. Glenv will not
+ support applications of the non-native size. Fixing this may be
+ as simple as running a command such as:
+
+ sudo apt-get install gcc-multilib
+EOF
+fi
+
+rm -f arch-minimal arch-minimal.c
+
+errors=0
+
+printf "Checking for pkg-config... "
+if pkg-config --version > /dev/null 2>&1; then
+ printf "Yes.\n"
+else
+ printf "No.\n"
+ cat <<EOF
+
+*** Error: This configure script requires pkg-config to find the
+compilation flags required to link against the various libraries
+needed by ${PROJECT}. The pkg-config program can be obtained from:
+
+ http://www.freedesktop.org/wiki/Software/pkg-config/
+
+Or you may be able install it with a command such as:
+
+ sudo apt-get install pkg-config
+ or:
+ sudo yum install pkgconfig
+
+EOF
+
+exit 1
+
+fi
+
+printf "Checking for glaze... "
+if pkg-config --exists glaze; then
+ printf "Yes.\n"
+ have_glazec=1
+ glaze_cflags=$(pkg-config --cflags glaze)
+ glaze_ldflags=$(pkg-config --libs glaze)
+else
+ printf "No.\n"
+ have_glaze=0
+ errors=$((errors + 1))
+fi
+
+if [ $errors -gt 0 ]; then
+ cat <<EOF
+
+*** Error: The dependencies of ${PROJECT} could not be satisfied. You will
+need to install the following packages before being able to compile
+${PROJECT}:
+
+EOF
+ if [ $have_glaze -eq 0 ]; then
+ echo " The glaze library"
+ echo " git://git.cworth.org/git/glaze/"
+ echo
+ fi
+
+ exit 1
+fi
+
+# construct the Makefile.config
+cat > Makefile.config <<EOF
+# This Makefile.config was automatically generated by the ./configure
+# script of ${PROJECT}. If the configure script identified anything
+# incorrectly, then you can edit this file to try to correct things,
+# but be warned that if configure is run again it will destroy your
+# changes, (and this could happen by simply calling "make" if the
+# configure script is updated).
+
+# The top-level directory for the source, (the directory containing
+# the configure script). This may be different than the build
+# directory (the current directory at the time configure was run).
+srcdir = ${srcdir}
+
+configure_options = $@
+
+# We use vpath directives (rather than the VPATH variable) since the
+# VPATH variable matches targets as well as prerequisites, (which is
+# not useful since then a target left-over from a srcdir build would
+# cause a target to not be built in the non-srcdir build).
+vpath % \$(srcdir)
+
+# The C compiler to use
+CC = ${CC}
+
+# Default FLAGS for C compiler (can be overridden by user such as "make CFLAGS=-g")
+CFLAGS = ${CFLAGS}
+
+# Default FLAGS for the linker (can be overridden by user such as "make LDFLAGS=-znow")
+LDFLAGS = ${LDFLAGS}
+
+# Flags to enable warnings when using the C compiler
+WARN_CFLAGS = ${WARN_CFLAGS}
+
+# The prefix to which ${PROJECT} should be installed
+PREFIX = ${PREFIX}
+
+# The directory to which executables should be installed
+BINDIR = ${BINDIR:-\$(PREFIX)/bin}
+
+# The directory to which libraries should be installed
+LIBDIR = ${LIBDIR:-\$(PREFIX)/lib}
+
+# The directory to which headers should be installed
+INCLUDEDIR = ${INCLUDEDIR:-\$(PREFIX)/include}
+
+# Whether compiler can create 32 or 64-bit binaries
+COMPILER_SUPPORTS_32 = ${have_m32}
+COMPILER_SUPPORTS_64 = ${have_m64}
+
+# Flags needed to compile and link against Glaze
+GLAZE_CFLAGS = ${glaze_cflags}
+GLAZE_LDFLAGS = ${glaze_ldflags}
+
+EOF
+
+cat <<EOF
+
+You may now run the following commands to compile and install ${PROJECT}:
+
+ make
+ sudo make install
+
+EOF