[Top][All Lists]

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

Re: problems with directory in make

From: Paul D. Smith
Subject: Re: problems with directory in make
Date: Wed, 11 Jun 2003 10:36:11 -0400

%% Regarding problems with directory in make; you wrote:

  jj> I'm having problems with my makefile.  I want to descend into a
  jj> directory and issue shell commands to extract a list of files
  jj> using either `ls` or `echo` and store in a variable.

  jj> Here is the command:
  jj> install:
  jj>         cd LINUX/mod; mod2=$(shell echo *)

This can't work: you're confusing what is run by the shell with what is
run by make.  A command script is handled as follows:

 1) Make expands all variables and functions within the command script.

 2) Make takes the resulting string and invokes a shell with that string
    as the commands to run.

 3) Make waits until the shell exits and checks the exit code; if it
    succeeds (exits with a 0 exit code) then make proceeds with the next
    command.  If it fails (exits with a non-0 exit code) then make

I'm obviously ignoring special cases such as -i etc.

In your command, make runs the $(shell echo *) before it invokes the
shell (as part of step 1); since this is before the shell started the cd
command has not been done yet.  Also, you haven't quoted the results and
shell variables are only set to the first word.

This would work:

        cd LINUX/mod; mod2=`echo *`

  jj> I would like to descend to LINUX/mod directory from current
  jj> directory, echo the filenames and store in variable mod2 for later
  jj> use.

If by "later use" you mean within the same command line, that's fine.
If you mean anything else, you can't do that.  As above, you are setting
a _shell_ variable because it's the shell that's running the command.
Once that command is over and the shell exits, any shell variables you
set within the command are gone.
  jj> install:
  jj>         mod2=$(shell `ls LINUX/mod`)

  jj> In this case `ls` gives the right list of filenames but shell
  jj> attempts to execute the filenames as if it were commands.
  jj> install:
  jj>         mod2=$(`cd LINUX/mod`; $(shell echo *))
  jj>         mod2=$(`cd LINUX/mod`; `echo *`)
  jj>         mod2=$(`echo LINUX/mod/*`)
  jj> These don't work at all.

You're totally confused if you think any of these could possibly work.

Please either get a book on make, or read the very good GNU make user's
manual that comes with GNU make.  You're missing the basic concepts.

 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]