Need help with vpath command in make

olive's picture
olive asked on November 15, 2011 - 8:50am | Replies (3).

Hello, I got stuck in a make file which I doubt I didn't use vpath correctly. I came across your article here and I can figure that you are knowledgable about this. Is it possible you do me a favor?
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 \

foo.c: foo.pc
proc $(PCCFLAGS) oname=${WPCP}/$*.c iname=$<;\

-I $(WINC) -I $(CINC) \
-I$(ORACLE_HOME_DTB)/rdbms/demo \
-I$(ORACLE_HOME_DTB)/rdbms/public \
-I$(ORACLE_HOME_DTB)/precomp/public \
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?

Thank you in advance.

3 Answers

Ginger Kid's picture
Ginger Kid replied on December 6, 2011 - 7:41am.

You break the second Paul's rule (

foo.c: foo.pc
proc $(PCCFLAGS) oname=${WPCP}/$*.c iname=$<

change that to

%.c: %.pc
proc $(PCCFLAGS) [email protected] iname=$<

You may try

$(WPCP)/%.c: %.pc

as well, but I cannot tell off the top of my head if that produces the desired result.

CMCrossroads is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.