help-make
[Top][All Lists]
Advanced

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

Re: vpath w/implicit pattern rule, & non-basename target (GNU make)


From: gnu_make0
Subject: Re: vpath w/implicit pattern rule, & non-basename target (GNU make)
Date: Sun, 06 Jun 2010 08:13:10 -0500

On Sat 6/5/10 13:05 PDT Philip Guenther wrote:
> On Fri, Jun 4, 2010 at 11:17 PM,  <address@hidden> wrote:
> > Trying to use vpath w/implicit pattern rule.  Why does
> > case B fail?
> >
> >  # test makefile:
> >
> >    /tmp/test0 $ cat makefile    # simple test pattern rule
> >    %.foo: %.bar
> >            tac < $<    > $@
> >
> >    vpath %.bar /tmp/test0/src
> >
> >  # dependency/source file:
> >
> >    /tmp/test0 $ ls /tmp/test0/src
> >    x.bar
> >
> >  # case A: success w/vpath:
> ...
> >  # case B: why does this fail?:
> >
> >    /tmp/test0/tgt $ rm x.foo; cd ..
> >    /tmp/test0 $ make tgt/x.foo
> >    make: *** No rule to make target `tgt/x.foo'.  Stop.
> 
> Given the directive
>    vpath %.bar /tmp/test0/src
> 
> the prerequisite of tgt/x.bar will match and be searched for in
> "/tmp/test0/src/tgt/x.bar".  That is, the directory path from the
> prerequisite is kept.

Thanks much for your help.  It's making more sense now.

Summary below, corrections/edits welcome:

  passing make targets that are slash-containing pathnames

    The dependency that make will search for is derived from what
    make has matched the target's pattern rule '%' string to.
    Determine what string, % matches in the target pattern, then
    swap in that exact string for % in the dependency, to find the
    value of the *entire* dependency string - that string, which may
    end up as a "slash-containing pathname", will be searched for in
    vpath.  Searching for a "slash-containing pathname" below dirs
    in vpath is usually not what you want.

    Guideline: if you pass make a target string that is a
    slash-containing pathname, then the corresponding target pattern
    in the makefile should also be a slash-containing pathname
    matching the target string supplied to make, so % matches the
    basename before the suffix (.c, .o etc) - this means make will
    be looking through vpath for a *basename* not a slash-containing
    pathname.

    Tests suggest that the CWD of make by default is part of VPATH.

  CWD apparently always part of 'vpath' {

    /tmp/test0 $ cat makefile1
    tgt/%.foo: %.bar
            tac < $<    > $@

    vpath %.bar /tmp/test0/src
    /tmp/test0 $ ls x.bar src/ tgt/
    x.bar

    src/:

    tgt/:
    /tmp/test0 $ make -f makefile1 tgt/x.foo
    tac < x.bar    > tgt/x.foo

  }

  Specifying a target pattern in makefile with slash-containing pathname
  does NOT add the target dir to default VPATH (counter intuitive to me).

    ex {
      /tmp/test0 $ ls /tmp/test0/tgt /tmp/test0/src
      /tmp/test0/src:

      /tmp/test0/tgt:
      x.bar
      /tmp/test0 $ cat  makefile2
      /tmp/test0/tgt/%.foo: %.bar
              tac < $<    > $@

      vpath %.bar /tmp/test0/src:/tmp/test0/tgt
      /tmp/test0 $ make -f makefile2 /tmp/test0/tgt/x.foo
      tac < /tmp/test0/tgt/x.bar    > /tmp/test0/tgt/x.foo
      /tmp/test0 $ rm /tmp/test0/tgt/x.foo
      /tmp/test0 $ ed makefile2
      89
      # ed * /vpath
      vpath %.bar /tmp/test0/src:/tmp/test0/tgt
      # ed * s~:/tmp/test0/tgt~~
      # ed * wq
      74
      /tmp/test0 $ cat makefile2
      /tmp/test0/tgt/%.foo: %.bar
              tac < $<    > $@

      vpath %.bar /tmp/test0/src
      /tmp/test0 $ make -f makefile2 /tmp/test0/tgt/x.foo
      make: *** No rule to make target `/tmp/test0/tgt/x.foo'.  Stop.
      /tmp/test0 $ 
    }

  Cross post/related thread: 
    
http://groups.google.com/group/comp.unix.shell/browse_frm/thread/766dd3d104a5fec1#




reply via email to

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