help-make
[Top][All Lists]
Advanced

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

Re: using MAKEFLAGS in compiling C code as a shared library for R


From: Paul D. Smith
Subject: Re: using MAKEFLAGS in compiling C code as a shared library for R
Date: Fri, 14 Jun 2002 00:42:17 -0400

%% Faheem Mitha <address@hidden> writes:

  fm> On Thu, 13 Jun 2002, Paul D. Smith wrote:

  >> The simplest solution is to use backslashes to quote the spaces:
  >> 
  >> MAKEFLAGS='CC=gcc-3.0 PKG_CFLAGS=\ -Wall\ -pedantic' R CMD SHLIB rc.c -o 
rc.so
  >> 
  >> will work (note the change to single quotes: if you must use double
  >> quotes you'll have to type two backslashes to get one--see the
  >> documentation for your shell).

  fm> Thanks. This works. Am I correct in thinking this a shell issue?
  fm> I am using bash, of course.

Not really.

The contents of the MAKEFLAGS variable are interpreted by make, not by
the shell.

However, make uses virtually the same rules for breaking the string up
into words as the one employed by the Bourne shell, except make leaves
out some of the "edge cases".

  fm> I am not completely clear on why it works, though. The Bash manual
  fm> says:

  fm> Single Quotes
  fm> .............

  fm>    Enclosing characters in single quotes (`'') preserves the literal
  fm> value of each character within the quotes.  A single quote may not occur
  fm> between single quotes, even when preceded by a backslash.

  fm> Also

  fm> Escape Character
  fm> ................

  fm>    A non-quoted backslash `\' is the Bash escape character.  It
  fm> preserves the literal value of the next character that follows, with
  fm> the exception of `newline'.  If a `\newline' pair appears, and the
  fm> backslash itself is not quoted, the `\newline' is treated as a line
  fm> continuation (that is, it is removed from the input stream and
  fm> effectively ignored).

  fm> So, if single quotes are preserving the literal value of each
  fm> character within the quotes, why is it necessary to include a
  fm> backslash before each space within single quotes, when a backslash
  fm> also "preserves the literal value of the next character that
  fm> follows"?

The single quotes are used so that the shell doesn't do away with your
backslashes.  It's easy to see what happens, just do this:

  $ echo "foo bar"
  foo bar

  $ echo "foo\ bar"
  foo bar

  $ echo 'foo\ bar'
  foo\ bar

Note how the single quotes preserved the backslash in the last example.

You need to get those literal backslashes included in the value that
_make_ sees, because _make_ is going to be chopping up the value of the
MAKEFLAGS variable into words (again, using much the same algorithm as
the shell).

If make sees the value of MAKEFLAGS is:

  foo=bar biz= baz boz= -n

how can it know whether "baz" is supposed to be the value for "biz", or
whether "biz" is being set to the empty value and "baz" is a target to
be built.  How can make know whether the "-n" is the make -n option, or
if it was intended to be the value for the variable "boz"?

For that matter, you could want to assign the whole string
"bar biz= baz boz= -n" to the variable "foo"!

A string like that is inherently ambiguous, so make follows the behavior
of the shell and chops it up using spaces as delimiters.

So, if you don't want a space to be treated as a word delimiter, you
have to use a backslash and you have to ensure that _make_ sees the
backslash and that it's not removed by the shell first.


HTH!

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://www.paulandlesley.org/gmake/
 "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]