#!/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 > source.txt <<'INPUT_69_1'
record
INPUT_69_1
cat > Makefile <<'MAKEFILE'
copy.txt: source.txt
	@cp source.txt copy.txt
MAKEFILE
cp source.txt copy.txt
touch -t 202001010101 copy.txt
touch -t 202101010101 source.txt
m --trace copy.txt | sed -E "s/Makefile:[0-9]+:/Makefile:LINE:/g"
