#! /usr/bin/env bash

make=${1:-make}
makefile=${TMPDIR:-/tmp}/maketest.$$.mk

cat >> $makefile <<'EOF'

things = thing1 thing2
all: $(things)
$(things):; @echo '$@ start'; sleep 1; echo '$@ end'
-include inc.mk
inc.mk: ; @touch $@
EOF

try=0
while true
do
	(( try=try+1 ))
	strace -s512 -f -o strace.$try ${make} -f ${makefile} -j2 > out.$try 2>&1 || break
	lines=$(wc -l < out.$try)
	[[ $lines == 4 ]] || break
	echo -n .
done

echo try $try failed
