help-make
[Top][All Lists]
Advanced

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

Re: Probably a v.small doubt


From: Paul D. Smith
Subject: Re: Probably a v.small doubt
Date: Mon, 16 Sep 2002 21:46:28 -0400

%% Karthikesh Raju <address@hidden> writes:

  kr> define make-final
  kr> @${ECHO} "  "
  kr> @${ECHO} "---- Running TEX System for $<" 
  kr> -@(${EGREP} -qi '*foil*' $<  && \
  kr>               ${ECHO} "---- Slides : Running PdfLaTeX on $<" && \
  kr>               TEXSYSTEM=pdflatex) || \
  kr>               (${ECHO} "---- Paper  : Running LaTeX on $<" && \
  kr>         TEXSYSTEM=latex)
  kr> TEXSYSTEM $<

I assume here you mean something like:

  $$TEXSYSTEM $<

?

  kr> endef

  kr> Now the variable TEXSYSTEM doesnot seem to contain the preferred
  kr> processor, and so the final command for processing fails. i want
  kr> to know methods by which this variable can be accessed within the
  kr> define and also exported to (maybe) other defines.

The former is possible, the latter is not.

Please remember that (a) in UNIX every process has its own environment,
initially inherited from its parent process, and no process can _ever_
modify the environment of another one including its parent, and that (b)
every command that make invokes to build a target is invoked in a
sub-process.

In fact, make invokes every _line_ of a command to build a target in a
_different_ sub-process.

That means that your third line above (the EGREP line) is invoked in one
shell: it does the egrep, echos, and sets the value for TEXSYSTEM.  This
is a shell variable set in the sub-process, _NOT_ a make variable set in
the make process.  Then, that shell exits and all local environment
changes including the setting of TEXSYSTEM are lost.

Then make invokes another shell for the next line and here, the variable
TEXSYSTEM is not set to anything.

The answer to your first question, then, is to combine the third and
fourth lines so they're executed in the same shell:

  -@(${EGREP} ... \
        ... \
        ... \
        ... \
    TEXSYSTEM=latex; \
  $$TEXSYSTEM $<


As you can see from the above, there's no way to "keep" the value of a
variable set in the commands for one target for use in another target,
because they are always done in different shells.

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