help-make
[Top][All Lists]
Advanced

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

Re: Change directory problems


From: Paul D. Smith
Subject: Re: Change directory problems
Date: Mon, 18 Aug 2003 08:28:46 -0400

%% Kenny Mann <address@hidden> writes:

  km> Is it possible to have make change the cwd?

  km> For example:

  km> test:
  km>     tar -jxvf bash-2.05a.tar.bz2
  km>     cd bash-2.05a
  km>     ./configure
  km>     ...
  km>     ...
  km>     ...

In UNIX, the working directory is an attribute of each process.  So,
when make invokes a subshell which runs "cd ...", that directory change
is only in effect for the lifetime of that subshell.  When the subshell
exits, the change is gone.

So, if you want to cd within a rule you have to put all commands of the
rule that want the cd to be in effect into the same line, so all those
commands are sent to the same subshell.  Like this:

  test:
        tar -jxvf bash-2.05a.tar.bz2
        cd bash-2.05a \
          && ./configure \
          && ...
        echo done

I use "&&" to connect rules here so that if one fails the rule will
fail; you can use simple ";" if you don't want that.

-- 
-------------------------------------------------------------------------------
 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]