help-make
[Top][All Lists]
Advanced

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

RE: make


From: Paul D. Smith
Subject: RE: make
Date: Fri, 5 May 2006 08:12:40 -0400

%% "Wong, Danny H." <address@hidden> writes:

  wdh> Right now, I have an issue when performing a "CD" command in a
  wdh> for loop. When there is no directory ( say qatest ), the loops
  wdh> goes back to the very top of the parent directory and keeps
  wdh> building (looping endlessly) until the machine runs out of
  wdh> memory! I want to perform a check if the CD failed, then ignore
  wdh> it and go onto the next one or failed the whole build and exit. I
  wdh> was hoping there is something like the if test statement below I
  wdh> used to check if the file built or not.

Just as I suspected: you are not thinking clearly about the very bright
line between the shell and make.  That line is a process boundary, and
cannot be crossed:

Make takes each entire line of the script and invokes a shell, passing
it the line to be run.  Make then waits for the script to finish and at
the end of it, retrieves the final exit status.


In NO WAY can make interfere with, influence, or obtain information
about the script WHILE IT IS RUNNING!  The script is run in a completely
separate process, the shell, and make is sitting doing nothing while the
shell runs it.

So, even if such a variable WERE to exist it wouldn't help you in any
way!  Make could only set it after the entire script finishes, and
there's no way the shell could query it, since the shell is already
finished by the time make would set it.

  wdh> build:
  wdh>  $(QUIET) for sd in $(SUBDIRS); do ( $(CD) "$$sd";       \
  wdh>  \

You have to use SHELL constructs to manage your shell script, not MAKE
constructs (like make variables).  The shell keeps the exit code of the
last command invoked in the "$?" variable.

Or you can use logic operators like && and ||.

You should change this to exit, like this:

    $(CD) "$$sd" || exit 1; \


You should read up on the shell: any good make user must also be a good
shell programmer.

HTH!

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