Question on GNU make concerning vpath
I have a simple make file like this:
vpath %.c ${WPCP}:${CPCP} vpath %.pc ${WPGM}:${CPGM} vpath %.o $(WOBJ):$(COBJ) PCCFLAGS = maxopencursors=30 \ sqlcheck=semantics \ userid=$(USERID) \ code=ansi_c mode=oracle ltype=none \ include=$(WINC) include=$(CINC) \ include=$(ORACLE_HOME_DTB)/rdbms/public \ $(DEBUGPL) foo.c: foo.pc proc $(PCCFLAGS) oname=${WPCP}/$*.c iname=$<;\ CFLAG = $(DBG) $(DEBUG) \ $(ICIS_CC_OPT) \ -I $(WINC) -I $(CINC) \ -I$(ORACLE_HOME_DTB)/rdbms/demo \ -I$(ORACLE_HOME_DTB)/rdbms/public \ -I$(ORACLE_HOME_DTB)/precomp/public \ $(C64BIT:64=-q64) foo.o: foo.c $(CC) $(CFLAG) -fPIC -c $< -o ${WOBJ}/$*.o If I make foo.c, then make foo.o (in two separate steps), it works fine. But if I directly make foo.o, it says foo.c not found after foo.c is actually generated. And, if I am in the directory where .c should be, then, make foo.o also works. But if I am not in that directory, then cc complains that foo.c doesn't exist if I directly make foo.o. So it seems cc cannot search foo.c in vpath? ---------- Post added 11-15-11 at 04:04 AM ---------- [/COLOR]Forgot to mention I did this on Oracle Linux 5.7. make 3.81 and gcc 4.1.2. |
Pump for help!
|
Nobody has any idea?
|
please help
|
is it a right place for my post?
|
Quote:
|
Quote:
|
Okay, I think I figured it out. The problem is that make doesn't apply vpath to targets, only prerequisites. Furthermore when you put a rule that says foo.c: foo.pc, you're telling make that foo.c will be built in this directory not somewhere else. I put together a simpler example to understand this better. As you can see below make doesn't analyse the contents of the target building rules, so in the first case you get:
Code:
#Using Code:
#Using Code:
~/tmp/scratch$ ls -R |
I agree that vpath doesn't apply to targets, only apply to prerequests.
In my case, foo.c is both a target (in rule foo.c:foo.pc) and a prerequest (in rule foo.o:foo.c). Now, the first rule always works, that is, no matter which folder I'm in, I can make foo.c from foo.pc, so make uses vpath to find foo.pc. and if I then run make again to make foo.o, no matter which folder I'm in, it also works, so in second run of make it also uses vpath to find foo.c. But, if I remove foo.c and foo.o, then make foo.o directly, problem occurs. Only foo.c is made, then it complains foo.c cannot be found. So I don't understand why make cannot find foo.c that is just generated? In rule foo.o:foo.c, foo.c is a prerequest, why it doesn't use vpath to find it? |
Quote:
|
So isn't it better if make separates the two rules, and uses vpath on second rule as well? What could be the possible reason of doing so?
|
Quote:
|
So make somehow inherits? The first rule only says how to generate foo.c from foo.pc, it doesn't say foo.c must be in the current folder. If make restarts vpath search in second rule, it will find foo.c.
Besides, I suppose the performance loss is tiny |
Quote:
Quote:
Quote:
|
I meant, make 'inherits' the results from previous rule and assumes the previous target is built in the current folder. I cannot find a good reason to explain this. The reference you gave describes exactly the same case. I'd rather consider it a bug. And so far the solution is not to use vpath in such cases.
|
All times are GMT -5. The time now is 01:16 PM. |