#! /bin/sh
# Generate parallel-tests.am.
#
# For each test in the TESTS list in this Makefile.am file, that itself
# tests features of the TESTS automake interface, generate a sibling
# test that does likewise, but with the option `parallel-tests' enabled.

set -e

tests=`sed -n '/^TESTS =/,/^$/s/\(.*\.test\).*/\1/p' Makefile.am`
{
  grep -l '^TESTS ' $tests
  grep -l ' TESTS ' $tests
} |
grep -v '.-p\.test' |
LC_ALL=C sort -u |
while read tst; do
  if grep '^[^#]*parallel-tests' $tst >/dev/null \
     || grep '^\. \./defs-p' $tst >/dev/null
  then :; else echo $tst; fi;
done |
{
  echo "## Generated by gen-parallel-tests.  Edit Makefile.am instead of this."
  echo "parallel_tests = \\"
  sed 's,\.test$,-p.test,; $!s,$, \\,'
}
