aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.fossil-settings/ignore-glob1
-rw-r--r--Makefile19
-rw-r--r--config.mk18
-rwxr-xr-xconfigure112
-rw-r--r--docs/Makefile10
5 files changed, 128 insertions, 32 deletions
diff --git a/.fossil-settings/ignore-glob b/.fossil-settings/ignore-glob
index d4cc917..98cdf27 100644
--- a/.fossil-settings/ignore-glob
+++ b/.fossil-settings/ignore-glob
@@ -17,3 +17,4 @@ tests/etc/cpt-hook
.shellspec-quick.log
report
coverage
+config.mk
diff --git a/Makefile b/Makefile
index 3b49aaf..5cb62c1 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
# Carbs Packaging Tools
-include config.mk
+-include config.mk
INSTALL_SH = ./tools/install.sh
CONTRIB = `find contrib -name 'cpt*' ! -name '*.*'`
@@ -9,7 +9,8 @@ LIB = src/cpt-lib
LIB_IN = ${LIB:=.in}
all: src/cpt-lib
- test "${DOCS}" != yes || ${MAKE} -C docs all
+ @if ! [ -e config.mk ]; then echo "Please run './configure'"; exit 1; fi
+ @test "${DOCS}" != yes || ${MAKE} -C docs all
src/cpt-lib: src/cpt-lib.in
sed -e "s|@VERSION@|${VERSION}|g" \
@@ -32,6 +33,10 @@ dist: docs/cpt.info
install: all
test "${DOCS}" != yes || ${MAKE} -C docs install
+ [ -f docs/cpt.info ] && \
+ ${INSTALL_SH} -Dm644 docs/cpt.info -t ${DESTDIR}${INFODIR}
+ [ -f docs/cpt.txt ] && \
+ ${INSTALL_SH} -Dm644 docs/cpt.txt -t ${DESTDIR}${DOCDIR}
${INSTALL_SH} -Dm755 -t ${DESTDIR}${BINDIR} ${BIN}
${INSTALL_SH} -Dm644 -t ${DESTDIR}${MAN1} man/*.1
for man in ${CONTRIB}; do \
@@ -40,15 +45,19 @@ install: all
done
uninstall:
- test "${DOCS}" != yes || ${MAKE} -C docs uninstall
for bin in ${BIN}; do \
rm -f ${DESTDIR}${BINDIR}/$${bin##*/}; done
for man in man/*.1; do rm -f ${DESTDIR}${MAN1}/$${man##*/}; done
for man in ${CONTRIB}; do rm -f ${DESTDIR}${MAN1}/$${man##*/}.1; done
+ rm -rf ${DESTDIR}${DOCDIR}
+ rm -f ${DESTDIR}${INFODIR}/cpt.info
clean:
- test "${DOCS}" != yes || ${MAKE} -C docs clean
+ ${MAKE} -C docs clean
rm -rf src/cpt-lib "cpt-${VERSION}.tar.xz" coverage report
rm -f tests/etc/cpt-hook
-.PHONY: all dist clean install uninstall shellspec shellcheck test
+allclean: clean
+ rm -f config.mk
+
+.PHONY: all dist allclean clean install uninstall shellspec shellcheck test
diff --git a/config.mk b/config.mk
deleted file mode 100644
index 1bc27fe..0000000
--- a/config.mk
+++ /dev/null
@@ -1,18 +0,0 @@
-# Carbs Packaging Tools
-VERSION = dev
-
-# Installation paths
-PREFIX = /usr/local
-BINDIR = ${PREFIX}/bin
-SHAREDIR = ${PREFIX}/share
-INFODIR = ${SHAREDIR}/info
-DOCDIR = ${SHAREDIR}/doc
-CPTDOC = ${DOCDIR}/cpt
-MANPREFIX = ${SHAREDIR}/man
-MAN1 = ${MANPREFIX}/man1
-
-EMACS = emacs
-MAKEINFO = makeinfo
-
-# Comment or change if you don't want to build/install the documentation
-DOCS = yes
diff --git a/configure b/configure
new file mode 100755
index 0000000..d57e48c
--- /dev/null
+++ b/configure
@@ -0,0 +1,112 @@
+#!/bin/sh -e
+
+version=dev
+
+die() {
+ printf '%s: %s\n' "${0##*/}" "$*" >&2
+ exit 1
+}
+
+out() { printf '%s\n' "$@" ;}
+
+_check() {
+ for arg; do
+ printf 'checking for %s... ' "$arg"
+ command -v "$arg" || { out no; die "'$arg' not found" ;}
+ done
+}
+
+_check_multi() {
+ c=$1; shift
+ printf 'checking for %s... ' "$c"
+ for arg; do command -v "$arg" && return 0; done
+ out no; die "no $c was found"
+}
+
+usage() {
+ out "usage: $0 [options]" \
+ "Options:" \
+ " --prefix=dir Set prefix directory" \
+ " --bindir=dir User executables [PREFIX/bin]" \
+ " --datarootdir=dir Data root directory [PREFIX/share]" \
+ " --mandir=dir Manual pages [DATAROOTDIR/man]" \
+ " --infodir=dir info documentation [DATAROOTDIR/info]" \
+ " --docdir=dir Documentation directory [DATAROOTDIR/doc/cpt]" \
+ " --with-docs=opt Whether to build the texinfo documentation [auto]" "" \
+ " MAKEINFO Name of the 'makeinfo' executable" \
+ " EMACS Name of the 'emacs' executable" "" \
+ "Use these variables to override the behaviour of '$0'."
+ exit 1
+}
+
+prefix=/usr/local
+# We don't want expansion
+# shellcheck disable=2016
+{
+bindir='$(PREFIX)/bin'
+datarootdir='$(PREFIX)/share'
+mandir='$(DATAROOTDIR)/man'
+infodir='$(DATAROOTDIR)/info'
+docdir='$(DATAROOTDIR)/doc/cpt'
+}
+docs=auto
+
+for arg; do
+ case $arg in
+ -h|--help) usage ;;
+ --prefix=*) prefix=${arg#*=} ;;
+ --bindir=*) bindir=${arg#*=} ;;
+ --mandir=*) mandir=${arg#*=} ;;
+ --infodir=*) infodir=${arg#*=} ;;
+ --docdir=*) docdir=${arg#*=} ;;
+ --without-docs) docs=no ;;
+ --with-docs) docs=yes ;;
+ --with-docs=*) docs=${arg#*=} ;;
+ *-*) die "Unknown option: '$arg'" ;;
+ *=*) export "${arg:?}" ;;
+ *) die "Unknown argument: '$arg'"
+ esac
+done
+
+trap 'rm -f config.mk' EXIT
+trap 'rm -f config.mk; exit 1' INT
+
+: "${EMACS:=emacs}" "${MAKEINFO:=makeinfo}"
+
+out "starting configuration..."
+
+cat <<EOF > config.mk
+PREFIX = $prefix
+BINDIR = $bindir
+DATAROOTDIR = $datarootdir
+MANDIR = $mandir
+INFODIR = $infodir
+DOCDIR = $docdir
+MAN1 = \$(MANDIR)/man1
+
+VERSION = $version
+EMACS = $EMACS
+EOF
+
+case $docs in
+ auto|yes)
+ printf 'checking for makeinfo... '
+ if makeinfo=$(command -v "$MAKEINFO"); then
+ out "$makeinfo"
+ docs=yes
+ out "MAKEINFO = $makeinfo" >>config.mk
+ else
+ out no
+ [ "$docs" = yes ] && die "'$MAKEINFO' not found"
+ docs=no
+ fi
+esac
+[ "$docs" = no ] && out "not building documentation"
+out "DOCS = $docs" >>config.mk
+
+out "checking runtime dependencies"
+_check pax rsync sed awk grep
+_check_multi "sha256 provider" sha256sum sha256 openssl
+
+trap - EXIT INT
+out "written config.mk" "Run 'make' to build cpt"
diff --git a/docs/Makefile b/docs/Makefile
index 344bd70..3a7dbf0 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -1,5 +1,5 @@
# Carbs Packaging Tools Documentation
-include ../config.mk
+-include ../config.mk
INSTALL_SH = ../tools/install.sh
all: cpt.txt cpt.texi cpt.info
@@ -22,12 +22,4 @@ clean:
all-clean: clean
rm -f cpt.texi cpt.txt
-install: all
- ${INSTALL_SH} -Dm644 cpt.txt ${DESTDIR}${CPTDOC}/cpt.txt
- ${INSTALL_SH} -Dm644 cpt.info ${DESTDIR}${INFODIR}/cpt.info
-
-uninstall:
- rm -rf ${DESTDIR}${CPTDOC}
- rm -f ${DESTDIR}${INFODIR}/cpt.info
-
.PHONY: all clean all-clean install uninstall