summaryrefslogtreecommitdiffstats
path: root/configure
diff options
context:
space:
mode:
authorP. J. McDermott <pjm@nac.net>2012-08-02 05:45:46 (EDT)
committer P. J. McDermott <pjm@nac.net>2012-08-02 06:20:52 (EDT)
commitc6dbf4726d3cd4a98fe24929a28c78e880b39024 (patch)
tree8365c9ef219a06f78d25a501c717c5ab65ced04f /configure
parent6b31e57b664970bc6caeef0c840403862b3c7172 (diff)
Start rewriting build system.
Diffstat (limited to 'configure')
-rwxr-xr-xconfigure311
1 files changed, 171 insertions, 140 deletions
diff --git a/configure b/configure
index 26c658a..ea0e98c 100755
--- a/configure
+++ b/configure
@@ -19,12 +19,71 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-PACKAGE='opkhelper'
-VERSION='1.0.0'
+package_name='opkhelper'
+package_version='2.0.0'
+
+srcdir=$(dirname "${0}")
+srcdir=$(cd ${srcdir} && pwd)
+prefix='/usr/local'
+bindir='$(prefix)/bin'
+libdir='$(prefix)/lib/opkhelper'
+datadir='$(prefix)/share'
+mandir='$(datadir)/man'
+localedir='$(datadir)/locale'
+
+quiet=false
+missing_deps=false
+dep_cmds='
+install
+sh
+'
+
+long_opts_with_args='
+srcdir
+prefix
+bindir
+libdir
+datadir
+mandir
+localedir
+'
+
+features="${dep_cmds}"
+
+subst_vars="package_name
+package_version
+${long_opts_with_args}
+${dep_cmds}"
+
+main()
+{
+ parse_options "${@}"
+
+ for dep in ${dep_cmds}; do
+ dep_val=$(eval echo \$\{"${dep}"\})
+ if [ -z "${dep_val}" ]; then
+ find_dep_cmd "${dep}"
+ fi
+ done
+
+ if ${missing_deps}; then
+ cat <<EOF
+
+Some dependencies could not be found.
+Please make sure all dependencies are installed and try again.
+
+EOF
+ exit 1
+ fi
+
+ write_makefiles
+
+ printf '\nConfiguration complete!\n\n'
+}
print_usage()
{
- printf 'Usage: %s [OPTION]...\n' "$1"
+ printf 'Usage: %s [OPTION]...\n' "${0}"
}
print_help()
@@ -32,7 +91,7 @@ print_help()
cat <<EOF
\`configure' configures ${PACKAGE} ${VERSION} to adapt to many kinds of systems.
-$(print_usage "${1}")
+$(print_usage)
Configuration:
-h, --help display this help and exit
@@ -51,14 +110,16 @@ Installation directories:
--datadir=DATADIR expect to find data in DATADIR
default: PREFIX/share
--mandir=MANDIR install manual pages in MANDIR
- default: PREFIX/share/man
+ default: DATADIR/man
+ --localedir=LOCALEDIR install locales in LOCALEDIR
+ default: DATADIR/man
EOF
}
print_version()
{
cat <<EOF
-${PACKAGE} ${VERSION} configure
+${package_name} ${package_version} configure
Not generated by GNU Autoconf
Copyright (C) 2011-2012 Patrick "P. J." McDermott
@@ -68,148 +129,118 @@ There is NO WARRANTY, to the extent permitted by law.
EOF
}
-opts=$(getopt -n "${0}" -o 'hVq' -l 'help,version,quiet' \
- -l 'srcdir:,prefix:,bindir:,libdir:,mandir:' -- "${@}")
-if [ ${?} -ne 0 ]; then
- print_usage "${0}" >&2
- exit 1;
-fi
-eval set -- "${opts}"
-while true; do
- case "${1}" in
- -h|--help)
- print_help "${0}"
- exit 0
- ;;
- -V|--version)
- print_version
- exit 0
- ;;
- -q|--quiet)
- QUIET=true
- shift
- ;;
- --srcdir)
- SRCDIR="${2}"
- shift 2
- ;;
- --prefix)
- PREFIX="${2}"
- shift 2
- ;;
- --bindir)
- # Leave PREFIX unexpanded for now, in case it isn't set yet.
- BINDIR="\${PREFIX}/${2}"
- shift 2
- ;;
- --libdir)
- # Leave PREFIX unexpanded for now, in case it isn't set yet.
- LIBDIR="\${PREFIX}/${2}"
- shift 2
- ;;
- --datadir)
- # Leave PREFIX unexpanded for now, in case it isn't set yet.
- DATADIR="\${PREFIX}/${2}"
- shift 2
- ;;
- --mandir)
- # Leave PREFIX unexpanded for now, in case it isn't set yet.
- MANDIR="\${PREFIX}/${2}"
- shift 2
- ;;
- --)
- shift
- break
- ;;
- *)
- print_usage "${0}" >&2
+parse_options()
+{
+ for _opt; do
+
+ # Handle arguments of "--opt arg" options.
+ if [ -n "${_prev}" ]; then
+ eval "${_prev}=\$\{_opt\}"
+ _prev=
+ continue
+ fi
+
+ # Detect "--opt=arg" and "--opt arg" options.
+ case "${_opt}" in
+ *=*)
+ _optarg="${_opt#*=}"
+ _opt="${_opt%=*}"
+ _optarg_set=true
+ ;;
+ *)
+ _optarg_set=false
+ ;;
+ esac
+
+ # Handle short and long options.
+ case "${_opt}" in
+ --)
+ break
+ ;;
+ -h|--help)
+ print_help
+ exit 0
+ ;;
+ -V|--version)
+ print_version
+ exit 0
+ ;;
+ -q|--quiet)
+ quiet=true
+ continue
+ ;;
+ esac
+
+ # Anything beyond this point should be a long option.
+ case "${_opt}" in
+ --with-*)
+ _opt="${_opt#--with-}"
+ _opts="${features}"
+ _type=package
+ ;;
+ --*)
+ _opt="${_opt#--}"
+ _opts="${long_opts_with_args}"
+ _type=option
+ ;;
+ *)
+ printf 'unrecognized option: %s\n' "${_opt}" >&2
+ exit 1
+ ;;
+ esac
+
+ grep "^${_opt}\$" >/dev/null 2>&1 <<EOF
+"${_opts}"
+EOF
+ if [ ${?} -ne 0 ]; then
+ printf 'invalid %s name: %s\n' "${_type}" "${_opt}" >&2
exit 1
- ;;
- esac
-done
-
-if [ -z "${QUIET}" ]; then
- QUIET=false
-fi
-
-if [ -z "${SRCDIR}" ]; then
- SRCDIR=$(dirname "${0}")
-fi
-# Make SRCDIR an absolute path if it isn't already.
-SRCDIR=$(cd ${SRCDIR} && pwd)
-if [ -z "${PREFIX}" ]; then
- PREFIX=/usr/local
-fi
-if [ -z "${BINDIR}" ]; then
- BINDIR=${PREFIX}/bin
-fi
-if [ -z "${LIBDIR}" ]; then
- LIBDIR=${PREFIX}/lib
-fi
-if [ -z "${DATADIR}" ]; then
- DATADIR=${PREFIX}/share
-fi
-if [ -z "${MANDIR}" ]; then
- MANDIR=${PREFIX}/share/man
-fi
-# Expand PREFIX if it's there.
-eval "BINDIR=${BINDIR}"
-eval "LIBDIR=${LIBDIR}"
-eval "DATADIR=${DATADIR}"
-eval "MANDIR=${MANDIR}"
-
-find_dependency()
+ fi
+ if ${_optarg_set}; then
+ eval ${_opt}=\$\{_optarg\}
+ else
+ _prev="${_opt}"
+ fi
+
+ done
+}
+
+find_dep_cmd()
{
- dep=${1}
- var=${2}
- shift 2
+ _dep="${1}"
- ${QUIET} || printf 'checking for %s... ' "${dep}"
+ ${quiet} || printf 'checking for %s... ' "${dep}"
- while [ ${#} -gt 0 ]; do
- if [ -f "${1}/${dep}" ]; then
- ${QUIET} || printf '%s/%s\n' "${1}" "${dep}"
- eval "${var}=${1}/${dep}"
+ _old_ifs="${IFS}"
+ IFS=:
+
+ for _element in ${PATH}; do
+ : ${_element=-.}
+ if [ -f "${_element}/${_dep}" -a -x "${_element}/${_dep}" ]; then
+ ${quiet} || printf '%s/%s\n' "${_element}" "${_dep}"
+ eval "${_dep}=${_element}/${_dep}"
+ IFS="${_old_ifs}"
return 0
fi
- shift
done
- ${QUIET} || printf 'not found\n'
- missing_dependencies=true
+ IFS="${_old_ifs}"
+ ${quiet} || printf 'not found\n'
+ missing_deps=true
return 1
}
-missing_dependencies=false
-
-find_dependency sh SHELL /bin
-find_dependency install INSTALL /usr/bin
-find_dependency make MAKE /usr/bin
-
-if ${missing_dependencies}; then
- printf '\nSome dependencies could not be found.\n'
- printf 'Please make sure all dependencies are installed and try again.\n\n'
- exit 1
-fi
-
-sed_script="
-s&@shell@&${SHELL}&
-s&@install@&${INSTALL} -c&
-s&@make@&${MAKE}&
-s&@srcdir@&${SRCDIR}&
-s&@prefix@&${PREFIX}&
-s&@bindir@&${BINDIR}&
-s&@libdir@&${LIBDIR}&
-s&@datadir@&${DATADIR}&
-s&@mandir@&${MANDIR}&
-s&@package@&${PACKAGE}&
-s&@version@&${VERSION}&"
-
-# Replace configuration variables in Makefile.in
-mkdir -p src lib man
-sed "$sed_script" ${SRCDIR}/Makefile.in > Makefile
-sed "$sed_script" ${SRCDIR}/src/Makefile.in > src/Makefile
-sed "$sed_script" ${SRCDIR}/lib/Makefile.in > lib/Makefile
-sed "$sed_script" ${SRCDIR}/man/Makefile.in > man/Makefile
-
-printf '\nConfiguration complete!\n\n'
+write_makefiles()
+{
+ # Make a script to edit input makefiles.
+ _sed_script=
+ for _var in ${subst_vars}; do
+ _sed_script="${_sed_script}s&@${_var}@&$(eval echo \$\{"${_var}"\})&g;"
+ done
+
+ for _dir in . src lib locale man; do
+ sed "${_sed_script}" "${srcdir}/${_dir}/Makefile.in" >"${_dir}/Makefile"
+ done
+}
+
+main "${@}"