From c6dbf4726d3cd4a98fe24929a28c78e880b39024 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Thu, 02 Aug 2012 05:45:46 -0400 Subject: Start rewriting build system. --- (limited to 'configure') 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 . -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 <&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 <&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 "${@}" -- cgit v0.9.1