#!/bin/sh
set -e

tmp=src/amw-$$

rm -rf $tmp
mkdir $tmp
trap 'status=$?; rm -rf $tmp; exit $status' 0 1 2 3 15

automake "$@" --output-dir=$tmp

# Transform the automake-generated rule that runs `rm -f rm'.
# On some systems, that command would fail with a diagnostic like
# `rm: cannot unlink `rm': Text file busy' when `.' appears so early
# in the shell's search path that running `rm' would run the `rm'
# executable in the current directory.
# Similarly, adjust the clean-binPROGRAMS rule.
sed \
    -e 's!rm -f rm$!& > /dev/null 2>\&1 || /bin/&!' \
    -e 's!rm -f \$(bin_PROGRAMS)$!& > /dev/null 2>\&1 || /bin/&!' \
    $tmp/src/Makefile.in \
  > src/Makefile.int

rm -rf $tmp

mv src/Makefile.int src/Makefile.in

exit 0
