#!/usr/bin/env bash
set -euo pipefail
unset MAKEFLAGS MFLAGS GNUMAKEFLAGS
make_bin=$(command -v gmake || command -v make)
m() { "$make_bin" --no-print-directory -rR "$@"; }
work_dir=$(mktemp -d)
if [ "${KEEP_WORK:-0}" = 1 ]; then
  trap 'printf "Artifacts: %s\n" "$work_dir"' EXIT
else
  trap 'rm -rf -- "$work_dir"' EXIT
fi
cd "$work_dir"
export TMPDIR="$work_dir"
cat > input.txt <<'INPUT_75_1'
Ada
Grace
INPUT_75_1
cat > Makefile <<'MAKEFILE'
all: summary.txt count.txt
summary.txt count.txt &: input.txt
	@printf "one grouped recipe\n"
	@cp input.txt summary.txt
	@wc -l < input.txt | tr -d " " > count.txt
MAKEFILE
m -s -j2 all
cat summary.txt count.txt
