If automake doesn't recognise a line in a Makefile.am, it assumes that it is the continuation of a Makefile rule. In having a look at the code, I think there are a few problems with the way this is handled, particularly with regards to the handling of comments. 1. If an umatched line continues a rule, then the line should start with a leading tab. If it doesn't, it is probably a good idea to flag this as an error. The only place where I can see that this is an issue is if you get something like @SUBST_ME@ which is then substituted with a valid Makefile line which may or may not continue a rule. I think this should be handled as a special case. 2. The code as it stands seems to allow the following: target: dependencies # A comment here and some whitespace following <tab>echo do something While this is fine on GNU make, on BSD make you need to delete the comment and the blank line from the resulting Makefile to get it to work. 3. Because of a stupidity in Tru64 make, automake displays an error message if comments are found immediately after the tab (plus zero/more whitespace). I think perhaps a nicer approach would be for automake to allow comments in the .am and omit them from the Makefile.in output. The following suggested patch fixes these things and also fixes a couple of tests. IMO it also gives a lot better error messages for Makefile.am's that are bogus. It is quite possible that I have fundamentally misunderstood how the old code works, and the patch will cause problems, but it seems to pass the testsuite at least. I have to confess to not adding a test to make sure the patch now handles 1 and 2 correctly though. Comments anyone?
Index: automake.in =================================================================== RCS file: /cvs/automake/automake/automake.in,v retrieving revision 1.1173 diff -c -c -r1.1173 automake.in *** automake.in 2001/08/28 03:53:10 1.1173 --- automake.in 2001/09/20 02:12:22 *************** *** 6860,6875 **** } else { ! # This isn't an error; it is probably a continued rule. ! # In fact, this is what we assume. ! $was_rule = 1; ! $output_trailer .= $comment . $spacing; ! $output_trailer .= &make_condition (@cond_stack); ! $output_trailer .= $_; ! $comment = $spacing = ''; ! &am_line_error ($., "`#' comment at start of rule is unportable") ! if $_ =~ /^\t\s*\#/; ! } $saw_bk = $new_saw_bk; $_ = $am_file->getline; --- 6860,6901 ---- } else { ! # This line didn't match any patterns, so: ! ! # See if this is a continued Makefile rule ! if ($was_rule) { ! if (!/^\t/) { ! &am_line_error ($., ! "Expected a continued rule but no leading tab found"); ! } else { ! # Note if we saw a comment (starting in column 0) or a ! # blank line in the line preceding, then it will be omitted ! # from the output, as this doesn't work in BSD make ! ! # In addition, we ignore lines containing comments ! # immediately after a tab in a rule. This is because the ! # Tru64 Unix V5.1 system make will pass these to the ! # shell, which in turn can't find `#' as a command. ! if (!/^\t\s*\#/) { ! $output_trailer .= &make_condition (@cond_stack); ! $output_trailer .= $_; ! } ! } ! } elsif (/^\s*\@\w\@/) { ! # First token could be sustituted with something sensible lets ! # hope the user got it right ! $output_trailer .= $comment . $spacing; ! $output_trailer .= &make_condition (@cond_stack); ! $output_trailer .= $_; ! } else { ! #Can't think what else it should be ! chop $_ if (substr ($_, -1, 1) eq "\n"); ! &am_line_error ($., ! "Syntax error `$_' unexpected"); ! } ! ! $comment = $spacing = ''; ! } $saw_bk = $new_saw_bk; $_ = $am_file->getline; Index: tests/comment3.test =================================================================== RCS file: /cvs/automake/automake/tests/comment3.test,v retrieving revision 1.1 diff -c -c -r1.1 comment3.test *** comment3.test 2001/05/17 05:31:05 1.1 --- comment3.test 2001/09/20 02:12:24 *************** *** 1,6 **** #! /bin/sh ! # Make sure that `#' after a tab is a failure. # The Tru64 Unix V5.1 system make will pass these to the # shell, which in turn can't find `#' as a command. # Sigh. Some vendors must be destroyed. --- 1,7 ---- #! /bin/sh ! # Make sure that `#' after a tab succeeds, and the comment is stripped ! # from the resulting Makefile.in # The Tru64 Unix V5.1 system make will pass these to the # shell, which in turn can't find `#' as a command. # Sigh. Some vendors must be destroyed. *************** *** 10,16 **** cat > Makefile.am << 'END' install-data-local: # Tru64 Unix must die END ! $AUTOMAKE && exit 1 ! exit 0 --- 11,19 ---- cat > Makefile.am << 'END' install-data-local: # Tru64 Unix must die + @echo But putting a comment at the end # should be okay + # Tru64 Unix must die END ! $AUTOMAKE && test x"`grep '# Tru64 Unix must die' Makefile.in`" = x && exit 0 ! exit 1 Index: tests/dejagnu2.test =================================================================== RCS file: /cvs/automake/automake/tests/dejagnu2.test,v retrieving revision 1.1 diff -c -c -r1.1 dejagnu2.test *** dejagnu2.test 2001/08/05 22:02:33 1.1 --- dejagnu2.test 2001/09/20 02:12:24 *************** *** 8,14 **** AUTOMAKE_OPTIONS = dejagnu site.exp: ! echo foo END $AUTOMAKE || exit 1 --- 8,14 ---- AUTOMAKE_OPTIONS = dejagnu site.exp: ! echo foo END $AUTOMAKE || exit 1 Index: tests/else.test =================================================================== RCS file: /cvs/automake/automake/tests/else.test,v retrieving revision 1.1 diff -c -c -r1.1 else.test *** else.test 1998/09/27 21:29:44 1.1 --- else.test 2001/09/20 02:12:24 *************** *** 19,22 **** END $AUTOMAKE > out 2>&1 && exit 1 ! grep :7: out --- 19,22 ---- END $AUTOMAKE > out 2>&1 && exit 1 ! grep :5: out