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. --- diff --git a/Makefile.in b/Makefile.in index 9dbd4f0..218a0ff 100644 --- a/Makefile.in +++ b/Makefile.in @@ -17,48 +17,35 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -SHELL = @shell@ -INSTALL = @install@ -MAKE = @make@ +package_name = @package_name@ +package_version= @package_version@ + +srcdir = @srcdir@ +prefix = @prefix@ +bindir = @bindir@ +libdir = @libdir@ +datadir = @datadir@ +mandir = @mandir@ -SRCDIR = @srcdir@ -PREFIX = @prefix@ -BINDIR = @bindir@ -LIBDIR = @libdir@ -DATADIR = @datadir@ -MANDIR = @mandir@ +sh = @sh@ -PACKAGE = @package@ -VERSION = @version@ +INSTALL = @install@ -distdir = $(PACKAGE)-$(VERSION) +distdir = $(package_name)-$(package_version) distfiles = configure Makefile.in COPYING README INSTALL ChangeLog TODO \ genopkg.sh .SUFFIXES: -.PHONY: all -all: sedscript +all: @printf 'Making executable files...\n' @cd src && $(MAKE) all - @printf 'Making library files...\n' - @cd lib && $(MAKE) all - @printf 'Making manual pages...\n' - @cd man && $(MAKE) all +# @printf 'Making library files...\n' +# @cd lib && $(MAKE) all +# @printf 'Making manual pages...\n' +# @cd man && $(MAKE) all -sedscript: - @printf 'Writing sed script...\n' - @echo 's&@@PACKAGE@@&$(PACKAGE)&' > sedscript - @echo 's&@@VERSION@@&$(VERSION)&' >> sedscript - @echo 's&@@BINDIR@@&$(BINDIR)&' >> sedscript - @echo 's&@@DATADIR@@&$(DATADIR)&' >> sedscript - @echo 's&@@LIBDIR@@&$(LIBDIR)&' >> sedscript - @echo 's&@@SHELL@@&$(SHELL)&' >> sedscript - -.PHONY: clean clean: - @printf 'Deleting sed script...\n' - @rm -f sedscript @printf 'Cleaning executable files...\n' @cd src && $(MAKE) clean @printf 'Cleaning library files...\n' @@ -66,7 +53,6 @@ clean: @printf 'Cleaning manual pages...\n' @cd man && $(MAKE) clean -.PHONY: install install: all @printf 'Generating installation configuration...\n' @if [ -n '$(DESTDIR)' ]; then \ @@ -83,7 +69,6 @@ install: all @printf 'Installing manual pages...\n' @cd man && $(MAKE) $$(cat ../install.config) install -.PHONY: uninstall uninstall: @printf 'Uninstalling executable files...\n' @cd src && $(MAKE) $$(cat ../install.config) uninstall @@ -92,19 +77,17 @@ uninstall: @printf 'Uninstalling manual pages...\n' @cd man && $(MAKE) $$(cat ../install.config) uninstall -.PHONY: distdir dist dist-gzip dist-bzip2 - -distdir: - @[ -d '$(distdir)' ] || mkdir '$(distdir)' - @cp -pR $(distfiles) $(distdir) - @cd src && $(MAKE) distdir - @cd lib && $(MAKE) distdir - @cd man && $(MAKE) distdir +$(distdir): + @mkdir -p '$(distdir)' + @cp -pR $(distfiles) '$(distdir)' + @cd src && $(MAKE) '../$(distdir)/src' + @cd lib && $(MAKE) '../$(distdir)/lib' + @cd man && $(MAKE) '../$(distdir)/man' -dist dist-gzip: distdir +dist dist-gzip: $(distdir) @tar -cf - '$(distdir)' | gzip -9c > '$(distdir).tar.gz' @rm -Rf '$(distdir)' -dist-bzip2: distdir +dist-bzip2: $(distdir) @tar -cf - '$(distdir)' | bzip2 -9c > '$(distdir).tar.bz2' @rm -Rf '$(distdir)' diff --git a/TODO b/TODO index 1f947bf..883fc9a 100644 --- a/TODO +++ b/TODO @@ -13,10 +13,6 @@ For 2.0.0: - Document standard output and error stream usage. * Document new utility interfaces. * Update build system. - - Update lists of source files. - - Change libdir macros/parameters. - - Add localedir macros/parameters. - - Search for executable dependencies in PATH. - Add a DATE macro for manual pages. Future Plans: @@ -26,7 +22,6 @@ Future Plans: * Compress documentation files. [2] * Write an 'opkcreate' script like dh_make to create a new source package. * Build platform-specific binary packages only when really necessary. [3] - * Maybe support "--with-PACKAGE" options, e.g. "--with-shell=/bin/bash" * Write a tool similar to debhelper's dh_auto_configure. Notes: 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 "${@}" diff --git a/lib/messages.sh b/lib/messages.sh index 68b08f9..597ceaf 100644 --- a/lib/messages.sh +++ b/lib/messages.sh @@ -70,5 +70,6 @@ oh_help() oh_version() { - printf "${oh_str_version}\n" "${0##*/}" '@@PACKAGE@@' '@@VERSION@@' + printf "${oh_str_version}\n" \ + "${0##*/}" '@@package_name@@' '@@package_version@@' } diff --git a/src/Makefile.in b/src/Makefile.in index bc4a362..22c115c 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -17,58 +17,61 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -SHELL = @shell@ -INSTALL = @install@ -MAKE = @make@ +package_name = @package_name@ +package_version= @package_version@ + +srcdir = @srcdir@ +prefix = @prefix@ +bindir = @bindir@ +libdir = @libdir@ + +sh = @sh@ -SRCDIR = @srcdir@ -PREFIX = @prefix@ -BINDIR = @bindir@ +sed_script = s&@@PACKAGE_NAME@@&$(package_name)&;\ + s&@@PACKAGE_VERSION@@&$(package_version)&;\ + s&@@LIBDIR@@&$(libdir)&;\ + s&@@SH@@&$(sh)&; + +INSTALL = @install@ .SUFFIXES: .SUFFIXES: .sh SRCS = opkbuild.sh \ - oh-checkbuilddeps.sh oh-applypatches.sh oh-copyconfig.sh \ - oh-strip.sh oh-installfiles.sh oh-installdocs.sh \ - oh-gencontrol.sh oh-buildopk.sh oh-parsechangelog.sh + oh-unpacksource.sh \ + oh-applypatches.sh \ + oh-copyconfig.sh \ + oh-gencontrol.sh \ + oh-parsechangelog.sh OBJS = $(SRCS:.sh=) -PACKAGE = @package@ -VERSION = @version@ - -distdir = ../$(PACKAGE)-$(VERSION)/src +distdir = ../$(package_name)-$(package_version)/src distfiles = Makefile.in $(SRCS) -.PHONY: all all: $(OBJS) $(OBJS): @printf ' SED %s\n' '$@' - @sed -f ../sedscript $(SRCDIR)/src/$@.sh > $@ + @sed '$(sed_script)' '$(srcdir)/src/$@.sh' >'$@' -.PHONY: clean clean: @for obj in $(OBJS); do \ printf ' RM src/%s\n' "$${obj}"; \ - rm -f $${obj}; \ + rm -f "$${obj}"; \ done -.PHONY: install install: all @for obj in $(OBJS); do \ printf ' INSTALL src/%s\n' "$${obj}"; \ - $(INSTALL) -D $${obj} "$(DESTDIR)/$(BINDIR)/$${obj}"; \ + $(INSTALL) -D "$${obj}" "$(DESTDIR)/$(bindir)/$${obj}"; \ done -.PHONY: uninstall uninstall: @for obj in $(OBJS); do \ printf ' RM %s\n' "$${obj}"; \ - rm -f "$(DESTDIR)/$(BINDIR)/$${obj}"; \ + rm -f "$(DESTDIR)/$(bindir)/$${obj}"; \ done -.PHONY: distdir -distdir: - @[ -d '$(distdir)' ] || mkdir '$(distdir)' - @cp -pR $(distfiles) $(distdir) +$(distdir): + @mkdir -p '$(distdir)' + @cp -pR $(distfiles) '$(distdir)' diff --git a/src/opkbuild.sh b/src/opkbuild.sh index eac3bef..bcb148e 100644 --- a/src/opkbuild.sh +++ b/src/opkbuild.sh @@ -1,4 +1,4 @@ -#!@@SHELL@@ +#!@@SH@@ # # opkhelper # src/opkbuild -- cgit v0.9.1