[GRASS-dev] Indented comments in Makefile not compatible with make-3.82

Glynn Clements glynn at gclements.plus.com
Fri Jun 1 00:28:02 PDT 2012


Daniel Macks wrote:

> The problem appears to be just after the above "sed" command, where
> macosx/modbuild/Makefile has:
> 
>     @# until I figure out how to get sed to replace with multiple lines in a
>     @# makefile, GRASS_APP required for modbuild, ie no default to /Applications
>     @#-e 's#^GISBASE.*#ifdef GRASS_APP\
>     @#GISBASE = $$(GRASS_APP)/Contents/MacOS\
>     @#else\
>     @#GISBASE = $(INST_DIR_MACOSX)\
>     @#endif#g'
>     @# html.make needs a little change
> 
> Why is it even looking at the syntax of a comment? The commented-out
> section is confusing because it's a hybrid of makefile-recipe quiet
> tags (@), makefile commenting (#), and makefile and shell
> line-continuations (). The new make is known to be stricter about
> several types of makefile syntax, so maybe you've triggered one of
> those? The use of the apparently non-standard "@#" in general does
> not seem to be the problem, or else the modbuild recipe would have
> crashed even earlier, so it must be related to the multilining in
> them. Changing the commented-out sed chunk to use standard
> commenting (non-indented leading #) works for me:

Make parses the above as four shell commands:

# until I figure out how to get sed to replace with multiple lines in a

# makefile, GRASS_APP required for modbuild, ie no default to /Applications

#-e 's#^GISBASE.*#ifdef GRASS_APP\
@#GISBASE = $$(GRASS_APP)/Contents/MacOS\
@#else\
@#GISBASE = $(INST_DIR_MACOSX)\
@#endif#g'

@# html.make needs a little change

For the third one (which is causing the problem), the entire block is
executed as a single command, including the backslash-newline pairs
and the @ at the start of each line other than the first.

It's the leading @ which causes the problem; a # only begins a comment
when it appears at the beginning of a word:

	$ pwd #asdfasdf
	/home/glynn
	$ pwd#asdfasdf
	bash: pwd#asdfasdf: command not found

Also, backslash-newline elimination isn't performed within comments.

Consequently, the shell parses the string as two commands:

	#-e 's#^GISBASE.*#ifdef GRASS_APP\

	@#GISBASE = $$(GRASS_APP)/Contents/MacOS @#else @#GISBASE = $(INST_DIR_MACOSX) @#endif#g'

The first is a comment, the second isn't. The comment swallows the
opening single quote, so what should be the closing quote is actually
the opening quote. The fact that the actual command is gibberish
doesn't matter, because the shell never gets beyond the first phases
of parsing, due to the mismatched quote.

Removing the leading '@' from each continuation line should suffice,
i.e.:

	@# until I figure out how to get sed to replace with multiple lines in a
	@# makefile, GRASS_APP required for modbuild, ie no default to /Applications
	@#-e 's#^GISBASE.*#ifdef GRASS_APP\
	#GISBASE = $$(GRASS_APP)/Contents/MacOS\
	#else\
	#GISBASE = $(INST_DIR_MACOSX)\
	#endif#g'
	# html.make needs a little change

BTW, I'm not sure why this is commented out; the sed expression should
actually work as-is, i.e.:

	-e 's#^GISBASE.*#ifdef GRASS_APP\
	GISBASE = $$(GRASS_APP)/Contents/MacOS\
	else\
	GISBASE = $(INST_DIR_MACOSX)\
	endif#g'

Make should pass backslash-newline through to the shell, the shell
should pass it through to sed (being in a single-quoted string), and
sed recognises backslash-newline as a literal newline in the
replacement of an 's' command.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list