user1245262
user1245262

Reputation: 7505

Confusion with Makefile

I'm trying to learn about makefile, mainly to understand a makefile that I'm using, but am getting thrown by what are probably simple things. The section of my makefile that confuses me looks like this:

SUBS = dir1 dir2 dir3

depend clean:
         @-X=`pwd`;\
         for i in $(SUBS);\
         cd $$X/$$i;\
         done

What does "@-X=pwd do? I gather that it somehow assigns the value of the present directory to X, but I have no idea how to read the "@-" syntax.

Also, why do X & i need to be prepended with '$$' instead of just '$'? I've experimentally verified that both $'s are necessary, but would've thought that only one should be needed to replace each with their value

Upvotes: 2

Views: 245

Answers (1)

Christian Stieber
Christian Stieber

Reputation: 12496

I have no idea how to read the "@-" syntax.

Just read it from left to right :-) Kidding aside, "@" at the beginning of a line tells make not to echo the line before executing it; "-" tells it to ignore errors

X & i need to be prepended with '$$' instead of just '$'?

Because make itself has variables that are accessed via $, but in this case the rule uses shell variables, which are also accessed by $. The $$ is just an escape, so the shell command that gets executed contains $X, instead of the content of the makefile variable X which is probably empty.

Upvotes: 3

Related Questions