LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 11-15-2011, 03:03 AM   #1
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Rep: Reputation: Disabled
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.

Last edited by olivexer; 11-15-2011 at 03:08 AM.
 
Old 11-16-2011, 08:13 PM   #2
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
Pump for help!
 
Old 11-18-2011, 02:33 AM   #3
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
Nobody has any idea?
 
Old 11-19-2011, 04:33 PM   #4
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
please help
 
Old 11-21-2011, 11:47 PM   #5
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
is it a right place for my post?
 
Old 11-25-2011, 12:34 AM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by olivexer View Post
So it seems cc cannot search foo.c in vpath?
Yes, vpath is only known to make, the compiler has no idea about it.
 
Old 11-25-2011, 01:24 AM   #7
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by ntubski View Post
Yes, vpath is only known to make, the compiler has no idea about it.
Yes but make should somehow feed vpath to cc, otherwise how to make use of vpath?
 
Old 12-03-2011, 11:53 AM   #8
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
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
#%.c : %.pc
#	cp $< $(CDIR)/$@
cp pcfiles/foo.pc cfiles/foo.c
  Successfully remade target file `foo.c'. # make is confused
But you can fix it by telling make where foo.c will be created:
Code:
#Using
#$(CDIR)/%.c : %.pc
#	cp $< $@
cp pcfiles/foo.pc cfiles/foo.c
  Successfully remade target file `cfiles/foo.c'. # now make has the right idea
Code:
~/tmp/scratch$ ls -R
.:
cfiles  Makefile.broken  Makefile.fixed  ofiles  pcfiles

./cfiles:

./ofiles:

./pcfiles:
foo.pc
~/tmp/scratch$ cat Makefile.broken
CDIR=cfiles
PCDIR=pcfiles
ODIR=ofiles

vpath %.c $(CDIR)
vpath %.pc $(PCDIR)
vpath %.o $(ODIR)

%.c : %.pc
	cp $< $(CDIR)/$@

%.o : %.c
	cp $< $(ODIR)/$@

foo.c : foo.pc
foo.o : foo.c

clean :
	rm -f $(CDIR)/*.c $(ODIR)/*.o
~/tmp/scratch$ make --no-builtin-rules --no-builtin-variables --makefile=Makefile.broken --debug=implicit foo.o
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `foo.o' does not exist.
 Looking for an implicit rule for `foo.o'.
 Trying pattern rule with stem `foo'.
 Trying implicit prerequisite `foo.c'.
 Found an implicit rule for `foo.o'.
   File `foo.c' does not exist.
   Looking for an implicit rule for `foo.c'.
   Trying pattern rule with stem `foo'.
   Trying implicit prerequisite `foo.pc'.
   Found an implicit rule for `foo.c'.
     Looking for an implicit rule for `foo.pc'.
     No implicit rule found for `foo.pc'.
  Must remake target `foo.c'.
cp pcfiles/foo.pc cfiles/foo.c
  Successfully remade target file `foo.c'.
Must remake target `foo.o'.
cp foo.c ofiles/foo.o
cp: cannot stat `foo.c': No such file or directory
make: *** [foo.o] Error 1
~/tmp/scratch$ cat Makefile.fixed
CDIR=cfiles
PCDIR=pcfiles
ODIR=ofiles

vpath %.c $(CDIR)
vpath %.pc $(PCDIR)
vpath %.o $(ODIR)

$(CDIR)/%.c : %.pc
	cp $< $@

%.o : %.c
	cp $< $(ODIR)/$@

$(CDIR)/foo.c : foo.pc
foo.o : foo.c

clean :
	rm -f $(CDIR)/*.c $(ODIR)/*.o
~/tmp/scratch$ make -f Makefile.fixed clean
rm -f cfiles/*.c ofiles/*.o
~/tmp/scratch$ make --no-builtin-rules --no-builtin-variables --makefile=Makefile.fixed --debug=implicit foo.o
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.

This program built for x86_64-pc-linux-gnu
Reading makefiles...
Updating goal targets....
 File `foo.o' does not exist.
 Looking for an implicit rule for `foo.o'.
 Trying pattern rule with stem `foo'.
 Trying implicit prerequisite `foo.c'.
 Found an implicit rule for `foo.o'.
   File `cfiles/foo.c' does not exist.
   Looking for an implicit rule for `cfiles/foo.c'.
   Trying pattern rule with stem `foo'.
   Trying implicit prerequisite `foo.pc'.
   Found an implicit rule for `cfiles/foo.c'.
     Looking for an implicit rule for `foo.pc'.
     No implicit rule found for `foo.pc'.
  Must remake target `cfiles/foo.c'.
cp pcfiles/foo.pc cfiles/foo.c
  Successfully remade target file `cfiles/foo.c'.
Must remake target `foo.o'.
cp cfiles/foo.c ofiles/foo.o
Successfully remade target file `foo.o'.
 
Old 12-03-2011, 04:57 PM   #9
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
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?
 
Old 12-03-2011, 07:51 PM   #10
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by olivexer View Post
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?
The problem is the rule foo.c : foo.pc, make will apply it and then assume that foo.c has been generated (rather than the ${WPCP}/foo.c that is actually generated) so it won't look for it in vpath.
 
Old 12-03-2011, 11:45 PM   #11
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
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?

Last edited by olivexer; 12-04-2011 at 12:17 AM.
 
Old 12-04-2011, 09:19 AM   #12
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by olivexer View Post
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?
It does use vpath in the second rule, but it doesn't try to find foo.c in vpath after applying foo.c : foo.pc, because that rule (wrongly) claims to already create foo.c in the current directory. If you wonder why make doesn't check that rules actually generate what they are supposed to, I would say it's likely for performance reasons.
 
Old 12-04-2011, 04:08 PM   #13
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
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
 
Old 12-04-2011, 10:34 PM   #14
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,774

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by olivexer View Post
So make somehow inherits?
What? I don't understand this question.

Quote:
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.
You might think foo.c means foo.c anywhere, but really it means the same as ./foo.c, ie in the current directory. You are breaking Paul's Second Rule of Makefiles.

Quote:
If make restarts vpath search in second rule, it will find foo.c.
Besides, I suppose the performance loss is tiny
Well, the performance thing is only my guess, you can ask the GNU make developers about it for a definitive answer. I think this person had a similar problem.
 
Old 12-05-2011, 04:50 AM   #15
olivexer
LQ Newbie
 
Registered: Nov 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
GNU Make and GNU GCC DEBUG vs RELEASE compiler options aryan1 Programming 1 01-12-2010 12:29 PM
VPATH mechanism in make file sonu kumar Linux - Newbie 1 01-11-2010 11:42 AM
regarding VPATH in makefiles utkarshrawat Linux - General 5 10-02-2007 12:03 PM
newb question on GNU glibc-2.3.1 upgrade to GNU glibc-2.3.2 clindy528 Slackware 1 11-10-2005 06:49 AM
specfying vpath in make files help gauravsahni Programming 0 11-10-2004 04:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration