Skip to content

Instantly share code, notes, and snippets.

@sham1
Last active August 9, 2021 20:45
Show Gist options
  • Save sham1/4c31a7e38593aea8dad50ec1085d5dbb to your computer and use it in GitHub Desktop.
Save sham1/4c31a7e38593aea8dad50ec1085d5dbb to your computer and use it in GitHub Desktop.
Template for ./configure-scripts in (hopefully) POSIX shell
#!/bin/sh
usage() {
printf "Usage: %s [options]\n" "${0}"
echo ""
echo "Options: "
printf " --help or -h "
echo "Display this help message"
printf " --prefix=PREFIX "
echo "Top level install directory is PREFIX [default /usr/local]"
printf " --bindir=BINDIR "
echo "Install executables to BINDIR [default /usr/local/bin]"
printf " --sbindir=SBINDIR "
echo "Install system administrator executables to SBINDIR [default /usr/local/sbin]"
printf " --libexecdir=LIBEXECDIR "
echo "Install program executables to LIBEXECDIR [default /usr/local/libexec]"
printf " --sysconfdir=SYSCONFDIR "
echo "Install configurations to SYSCONFDIR [default /usr/local/etc]"
printf " --sharedstatedir=SHAREDSTATEDIR "
echo "Modifiable architecture-independent data goes to SHAREDSTATEDIR [default /usr/local/com]"
printf " --localstatedir=LOCALSTATEDIR "
echo "Modifiable data of the program goes to LOCALSTATEDIR [default /usr/local/var]"
printf " --libdir=LIBDIR "
echo "Install program libraries to LIBDIR [default /usr/local/lib]"
printf " --includedir=INCLUDEDIR "
echo "Install program headers to INCLUDEDIR [default /usr/local/include]"
printf " --datarootdir=DATAROOTDIR "
echo "Install read-only program data to DATAROOTDIR [default /usr/local/share]"
printf " --datadir=DATADIR "
echo "Install read-only program data to DATADIR [default /usr/local/share]"
printf " --mandir=MANDIR "
echo "Install manuals to MANDIR [default /usr/local/share/man]"
}
for arg in "$@"; do
case "$arg" in
--prefix=*)
PREFIX="${arg#*=}"
;;
--bindir=*)
BINDIR="${arg#*=}"
;;
--sbindir=*)
SBINDIR="${arg#*=}"
;;
--libexecdir=*)
LIBEXECDIR="${arg#*=}"
;;
--sysconfdir=*)
SYSCONFDIR="${arg#*=}"
;;
--sharedstatedir=*)
SHAREDSTATEDIR="${arg#*=}"
;;
--localstatedir=*)
LOCALSTATEDIR="${arg#*=}"
;;
--libdir=*)
LIBDIR="${arg#*=}"
;;
--includedir=*)
INCLUDEDIR="${arg#*=}"
;;
--datarootdir=*)
DATAROOTDIR="${arg#*=}"
;;
--datadir=*)
DATADIR="${arg#*=}"
;;
--mandir=*)
MANDIR="${arg#*=}"
;;
--help|-h)
usage
exit 1
;;
*)
;;
esac
done
PREFIX="${PREFIX:-/usr/local}"
BINDIR="${BINDIR:-${PREFIX}/bin}"
SBINDIR="${BINDIR:-${PREFIX}/sbin}"
LIBEXECDIR="${LIBEXECDIR:-${PREFIX}/libexec}"
SYSCONFDIR="${SYSCONFDIR:-${PREFIX}/etc}"
SHAREDSTATEDIR="${SHAREDSTATEDIR:-${PREFIX}/com}"
LOCALSTATEDIR="${LOCALSTATEDIR:-${PREFIX}/var}"
LIBDIR="${LIBDIR:-${PREFIX}/lib}"
INCLUDEDIR="${INCLUDEDIR:-${PREFIX}/include}"
DATAROOTDIR="${DATAROOTDIR:-${PREFIX}/share}"
DATADIR="${DATADIR:-${DATAROOTDIR}}"
MANDIR="${MANDIR:-${DATAROOTDIR}/man}"
CC="${CC:-cc}"
CFLAGS="${CFLAGS:--Og -g}"
LDFLAGS="${LDFLAGS:-}"
# Add checks for things like pkg-config and such here, since this is as
# convenient a place as any.
cat << EOF > config.vars
PREFIX="${PREFIX}"
BINDIR="${BINDIR}"
SBINDIR="${SBINDIR}"
LIBEXECDIR="${LIBEXECDIR}"
SYSCONFDIR="${SYSCONFDIR}"
SHAREDSTATEDIR="${SHAREDSTATEDIR}"
LOCALSTATEDIR="${LOCALSTATEDIR}"
LIBDIR="${LIBDIR}"
INCLUDEDIR="${INCLUDEDIR}"
DATAROOTDIR="${DATAROOTDIR}"
DATADIR="${DATADIR}"
MANDIR="${MANDIR}"
CC="${CC}"
CFLAGS="${CFLAGS}"
LDFLAGS="${LDFLAGS}"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment