Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 929
user163159 Avatar asked Dec 07 '25 04:12

user163159


1 Answers

\+ 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,\}.
like image 177
P Shved Avatar answered Dec 08 '25 17:12

P Shved