summaryrefslogtreecommitdiff
path: root/wrapper
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2015-07-01 23:22:00 -0600
committerLuke Shumaker <lukeshu@sbcglobal.net>2015-07-01 23:22:00 -0600
commit504d11ded8c1e9a0757332f2a10ed7d86dd5fc70 (patch)
treea3bba73ac491feaaecddca3345d8a54c5673bf72 /wrapper
parent04b12bbea2be03a988e773afcd014a74d37ddca5 (diff)
A whole bunch of stuff
Diffstat (limited to 'wrapper')
-rw-r--r--wrapper/.gitignore3
-rw-r--r--wrapper/Makefile17
-rw-r--r--wrapper/inner.sh.m4 (renamed from wrapper/inner.sh)65
-rw-r--r--wrapper/runcmd.mk15
4 files changed, 64 insertions, 36 deletions
diff --git a/wrapper/.gitignore b/wrapper/.gitignore
index 6141a28..0c3c90a 100644
--- a/wrapper/.gitignore
+++ b/wrapper/.gitignore
@@ -1,2 +1,3 @@
/outer
-/inner \ No newline at end of file
+/inner
+/inner.sh
diff --git a/wrapper/Makefile b/wrapper/Makefile
index f316cc0..54047d2 100644
--- a/wrapper/Makefile
+++ b/wrapper/Makefile
@@ -17,16 +17,19 @@
include $(dir $(lastword $(MAKEFILE_LIST)))/../config.mk
include $(topsrcdir)/common.top.mk
-src_files += Makefile outer.c inner.sh
-obj_files += outer inner
-install_files += $(bindir)/$(PACKAGE) $(pkglibexecdir)/$(PACKAGE)
+src_files += Makefile outer.c inner.sh.m4 runcmd.mk
+out_files += outer inner
+clean_files += inner.sh
+sys_files += $(bindir)/$(PACKAGE) $(pkglibexecdir)/$(PACKAGE) $(pkglibexecdir)/runcmd.mk
-$(objdir)/outer.o: $(topobjdir)/config.h
-$(objdir)/inner: $(topobjdir)/config.sh
+$(outdir)/outer.o: $(topoutdir)/config.h
+$(outdir)/inner: $(topoutdir)/config.sh
-$(DESTDIR)$(bindir)/$(PACKAGE) : $(objdir)/outer | $(DESTDIR)$(bindir)
+$(DESTDIR)$(bindir)/$(PACKAGE) : $(outdir)/outer | $(DESTDIR)$(bindir)
$(INSTALL_PROGRAM) $< $@
-$(DESTDIR)$(pkglibexecdir)/$(PACKAGE) : $(objdir)/inner | $(DESTDIR)$(bindir)
+$(DESTDIR)$(pkglibexecdir)/$(PACKAGE) : $(outdir)/inner | $(DESTDIR)$(pkglibexecdir)
+ $(INSTALL_PROGRAM) $< $@
+$(DESTDIR)$(pkglibexecdir)/runcmd.mk : $(srcdir)/runcmd.mk | $(DESTDIR)$(pkglibexecdir)
$(INSTALL_PROGRAM) $< $@
include $(topsrcdir)/common.bottom.mk
diff --git a/wrapper/inner.sh b/wrapper/inner.sh.m4
index b1dc718..8444bd6 100644
--- a/wrapper/inner.sh
+++ b/wrapper/inner.sh.m4
@@ -54,44 +54,53 @@ install_sighandlers() {
# Like GLibC's error(3), but call gettext on the format string
error() {
- >&2 printf "%s: $(_ "$2")\n" "$RVS" "${@:3}"
+ >&2 printf "%s: $(_ "$2")\n" "$program_name" "${@:3}"
+ [[ $1 -eq 0 ]] || exit $1
+}
+
+errusage() {
+ >&2 printf "$(_ "$2")\n" "$program_name" "${@:3}"
[[ $1 -eq 0 ]] || exit $1
}
_runcmd() {
- [[ $# -ge 1 ]] || error 1 'Usage: %s <command> [<args>]' "$program_name"
- local cmd=$1
-
+ [[ $# -ge 1 ]] || errusage 1 'Usage: %q <command> [<args>]'
+ local cmd=$1; shift
+ local args_str=''
+ [[ $# -eq 0 ]] || printf -v args_str '%q ' "$@"
+
local exec_path="${!varname_EXEC_PATH:-$pkglibexecdir}"
- if [ ! -e "$exec_path/$cmd" ] || [ "$cmd" = "${PACKAGE}" ]; then
+ shopt -s nullglob
+ local files=("${exec_path}"/modules/*/"$cmd")
+ if [[ ${#files[@]} -eq 0 ]]; then
error 127 '%s: Not a %s command' "$cmd" "$PACKAGE"
- else
- trap '[ -z "${TMPDIR:-}" ] || rm -rf -- "$TMPDIR"' EXIT
- export TMPDIR="$(mktemp -dt "${PACKAGE}.XXXXXXXXXX")"
-
- repo="$(_repo)"
- export "$varname_REPO=$repo"
-
- set -o pipefail
-
- if [ -f "$exec_path/$cmd" ]; then
- "$exec_path/$cmd" "$@" | tee -- "$TMPDIR/$cmd"
- elif [ -d "$exec_path/$cmd" ]; then
- mkdir -p -- "$TMPDIR/$cmd"
- local file
- for file in "$exec_path/$command"/*; do
- "$file" "$@" | tee -- "$TMPDIR/$command/${file##*/}" ||
- error 127 'Aborting: error encountered while running: %s' "$file"
- done
- else
- error 127 '%s: Could not execute' "$exec_path/$cmd"
- fi
fi
+ files=("${files[@]#"${exec_path/modules/}"}")
+
+ local output_dir
+ trap '[ -z "${output_dir:-}" ] || rm -rf -- "$TMPDIR"' EXIT
+ output_dir="$(mktemp -dt "${PACKAGE}.XXXXXXXXXX")"
+
+ local repo
+ repo="$(_repo)"
+ export "${varname_REPO}=${repo}"
+
+ local cwd
+ printf -v cwd '%q' "$PWD"
+
+ make -j1 \
+ -f "$exec_path/runcmd.mk" \
+ -C "$output_dir" \
+ ARGS="$args_str" \
+ EXEC_PATH="$exec_path" \
+ CWD="$cwd" \
+ -- "${files[@]}"
+ exit $?
}
_repo() {
- [[ $# -ne 0 ]] || error 1 'Usage: %s repo' "$program_name"
+ [[ $# -ne 0 ]] || errusage 1 'Usage: %q repo'
if [ -z "${!varname_REPO:-}" ]; then # we aren't getting a value from then env
local repo=".${PACKAGE,,}"
@@ -113,7 +122,7 @@ _repo() {
}
_init() {
- [[ $# -gt 1 ]] || error 1 'Usage: %s init [directory]' "$program_name"
+ [[ $# -gt 1 ]] || errusage 1 'Usage: %q init [directory]'
local dir="${1:-$PWD}"
mkdir -p -- "$dir"
cd "$dir"
diff --git a/wrapper/runcmd.mk b/wrapper/runcmd.mk
new file mode 100644
index 0000000..7cadb43
--- /dev/null
+++ b/wrapper/runcmd.mk
@@ -0,0 +1,15 @@
+#!/usr/bin/make -f
+
+# Environment/command line variables:
+# - ARGS
+# - EXEC_DIR
+# - CWD
+
+SHELL = bash -o pipefail
+
+export OUTPUT_DIR := $(realpath .)
+
+% : $(EXEC_PATH)/modules/%
+ cd $(CWD) && '$<' $(ARGS) | tee -- '$@'
+
+include $(wildcard $(EXEC_PATH)/modules/*.mk)