help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: VPATH, GPATH and implicit rules


From: Paul D. Smith
Subject: Re: VPATH, GPATH and implicit rules
Date: Sat, 26 Feb 2005 17:44:34 -0500

%% "Collins, Paul" <address@hidden> writes:

  cp> I'm experimenting with some makefiles on HPUX and Linux and I
  cp> would like to ask a question about the impact of GPATH. I've got a
  cp> setup something like the following:

  cp> ./Makefile.OK
  cp> ./src/test_floor.c
  cp> ./obj/

  cp> where test_floor.c is just a short C program and I want the object
  cp> file and executable 'test_floor' to go in obj/. I realise this is
  cp> breaking "Paul's Third Rule of Makefiles"
  cp> (http://make.paulandlesley.org/rules.html#rule3), but I'm finding
  cp> that a bit restrictive.

I'm not sure what you mean here... whether you think it's restrictive or
not doesn't change the fact that it's the way make works... so you're
pretty much stuck with it :-/ :-).

  cp> .SUFFIXES: 
  cp> .SUFFIXES: .o .c

  cp> # compile source and put object file in $(OBJDIR)
  cp> .c.o:
  cp>           @echo $(CC) $(CCFLAGS) -c $(<F)
  cp>           @$(CC) $(CCFLAGS) -c $< -o $(OBJDIR)/$(@F)

By the time make invokes your rule it already KNOWS what target it wants
to build, including the full path.  That target is placed into the $@
variable, and make expects your script to build that target.  Make does
NOT go looking through VPATH _again_, after the rule completes, to find
out what file your script actually did create.

  cp> Note that with GPATH=$(VPATH) the new prerequisite
  cp> src/test_floor.c is 'found', but that there are:

  cp> No commands for `obj/test_floor.o' and no prerequisites actually changed.

  cp> My question is: Is this correct?

Yes, because once src/test_floor.c is found, make matches the rule and
asks your script to build src/test_floor.o.  Your script doesn't do
that, but that's what make thinks it did.

Similarly, make finds obj/test_floor.o and, because of GPATH, it keeps
the pathname.  Now it wants to find a rule to build that target, and
the only rule that will match has a prerequisite of obj/test_floor.c.
Since there is no obj/test_floor.c file, that rule doesn't match either,
and you get the message about no commands found, and no prerequisites
changed.


I think it will help if you read the "How _not_ to use VPATH" article on
my web site; it will give you insight into how make searches for rules
and targets and how VPATH impacts that search.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist




reply via email to

[Prev in Thread] Current Thread [Next in Thread]