user163159
user163159

Reputation: 71

Why does this regular expression for sed break inside Makefile?

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?

Upvotes: 3

Views: 1948

Answers (1)

P Shved
P Shved

Reputation: 99264

\+ 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,\}.

Upvotes: 2

Related Questions