🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.misc
Article #2078

Re: re-setting VPATH in a GNU make action

#2078
From: Paul D. Smith
Date: Fri, 17 Nov 1995 00:00
71 lines
3369 bytes
%% Regarding re-setting VPATH in a GNU make action;
%% tzinck@bnr.ca (Thomas Zinck) writes:

    tz> I have a GNU makefile with a VPATH setting.  I would like to
    tz> re-set VPATH if a certain rule is met.

You can't [*].

    tz> fix_vpath:
    tz>         @echo Old Path is : ${VPATH}
    tz>         @set VPATH = ./one

This won't work in many ways:

  - First, GNU make always uses /bin/sh to run commands, not csh, so the
    syntax "set FOO = bar" is invalid.  You need to use "FOO=bar"
    (Bourne shell) syntax.

  - Second, even if you did that all it would do is set the environment
    variable VPATH in a subshell that GNU make invokes, which would of
    course have no effect on the make process itself.

You have to be very careful to remember which things make handles, and
which things it just passes to the shell to handle.  Anything in a build
script is just sent to the shell, it is _not_ interpreted by make in any
way.  So you _cannot_ effect the variables or processing of make from
with a build script in any way, you can only effect the shell it
invokes.

Further, note that make works in a two-step process: first it reads and
parses the entire makefile; second it evaluates all the targets and runs
the rules.  This is why something like this:

  VAR = 1
  all:
        echo $(VAR)
  VAR = 2

always prints "2", not "1": make reads the entire file before running
any rules.

    tz> I have also tried the "override" and "define" functions with no
    tz> success.

Exactly.

[*] Your only option is something like this:

      VPATH = ./one:/two

      all :   fix_vpath

      fix_vpath:
              @echo Old Path is : ${VPATH}
              @$(MAKE) VPATH=./one clean

      clean:
              @echo "New Path is ${VPATH}

    where make is re-invoked, overriding the setting of VPATH on the
    command line (command line always takes precedence over variable
    settings in the makefile itself, remember--barring the use of
    override or some such).
-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@baynetworks.com>         Network Management Development
 Senior Software Engineer                                   Bay Networks, Inc.
-----------------------------------------------==<http://www.baynetworks.com/>-
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
     These are my opinions--Bay Networks takes no responsibility for them.
Technical Details
Message-ID: <p5g2fmsrye.fsf@lemming.wellfleet.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <DI7394.qzn@CompStar.bnr.ca>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 11be23,d0fd7287b740963b,start
X-Google-Attributes: gid11be23,public
X-Google-Thread: 1025b4,d0fd7287b740963b,start
X-Google-Attributes: gid1025b4,public
X-Google-Thread: f72b0,d0fd7287b740963b,start
X-Google-Attributes: gidf72b0,public
From: psmith@lemming.wellfleet.com (Paul D. Smith)
Subject: Re: re-setting VPATH in a GNU make action
Date: 1995/11/17
Message-ID: <p5g2fmsrye.fsf@lemming.wellfleet.com>
X-Deja-AN: 119579171
sender: psmith@lemming.wellfleet.com
references: <DI7394.qzn@CompStar.bnr.ca>
to: tzinck@bnr.ca (Thomas Zinck)
organization: Bay Networks, Inc., Billerica, MA
reply-to: psmith@wellfleet.com
newsgroups: comp.unix.misc,gnu.misc.discuss,bnr.sys.unix