Hello Andy, and thanks for the report. I can confirm the bug with latest automake (from git master), with a much-reduced minimal testcase (see attachment).
I still haven't looked for an explanation or a fix, though. Regards, Stefano
foo.test
Description: application/shellscript