views:

253

answers:

1

I'm using GNU Make 3.81, and I have the following rule in my Makefile:

jslint :
    java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
    | sed 's/Lint at line \([0-9]\+\) character \([0-9]\+\)/mango.js:\1:\2/'

This works fine if I enter it directly on the command line, but the regular expression does not match if I run it with "make jslint". However, it works if I replace \+ with \{1,\} in the Makefile:

jslint :
    java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
    | sed 's/Lint at line \([0-9]\{1,\}\) character \([0-9]\{1,\}\)/mango.js:\1:\2/'

Is there some special meaning to \+ in Makefiles, or is this a bug?

+1  A: 

\+ doesn't have any special meaning. Also, there's nothing wrong with GNU Make, I suppose.

The expressions probably does match even in the first case, but the thing is probably that either

  • you call make jslnit when a file jslint already exists in the current directory. In this case it won't be considered as a target, for which the proper commands should be invoked. To be sure, try inserting echo statement in your commands, just to tell Make got to executing them:

    jslint :
        echo I got here
        java org.mozilla.javascript.tools.shell.Main jslint.js mango.js \
        | sed 's/Lint at line \([0-9]\+\) character \([0-9]\+\)/mango.js:\1:\2/'
    
  • your call to java yields different results (perhaps, it has changed?)

  • (this is the problem, see comments below ) the shell used by Make (it is /bin/sh by default, and can be changed as shown here) and the shell you enter commands to (to check if both versions match) differ, and it in some way affects what you're doing. For example, different default versions of sed are called in these shells, and in one of them \+ is not equivalent to \{1,\}.
Pavel Shved
Thanks for your help, but java is the same and there is no file named jslint. If I make two separate targets in the Makefile and call them jsplus and jscurly, then jscurly works and jsplus fails.
@jcrochol, I made some edits, did it help?
Pavel Shved
@pavel, The output from java is always the same, and I can always see it, only the `sed` replacement doesn't match with `\+` inside the Makefile. Different shell sounds most plausible so far, but I'm passing a string to `sed` which should not be mangled by the shell.
The `SHELL` variable on my command line contains `/bin/bash`, but inside `make` it's `/bin/sh`, which is different on my system. I tried setting `SHELL` to `/bin/bash` both inside Makefile and in the environment, but that didn't solve the problem with `\+`.
@jcrocholl, I might have been wrong about how to set shell. Check here to be sure: http://www.gnu.org/software/make/manual/make.html#Choosing-the-Shell
Pavel Shved
Okay, I found the problem: I had `alias sed=gsed` in my command line bash, and `/usr/bin/sed` is the one that comes with Mac OS X, and is broken. I'm marking your answer as correct because you mentioned different shell environments.