help-make
[Top][All Lists]
Advanced

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

Re: Inserting a '\' into a pattern rule command


From: Mike Shal
Subject: Re: Inserting a '\' into a pattern rule command
Date: Fri, 2 Nov 2007 21:22:01 -0400

On 11/2/07, Peter Johnson <address@hidden> wrote:
>
> On Nov 2, 2007, at 5:57 PM, Mike Shal wrote:
>
> > On 11/2/07, Martin Willers <address@hidden> wrote:
> >> Now, from time to time I'd like to see the exact compiler command-
> >> line,
> >> for example for inspecting certain CFLAGS entries which may not be
> >> given that
> >> obvious like in the example above.
> >> For this, I'd need to remove the '\' character in the middle line
> >> of the
> >> pattern rule, so that the $(CC) line is not hidden behind the '@'
> >> anymore.
> >
> > Another option is to remove the '@', instead (this is almost exactly
> > how it is specified in the Makefile for the Linux kernel) -
> >
> > ifeq ($(SHOW_CMD),1)
> >    Q =
> > else
> >    Q = @
> > endif
> >
> > all:
> >         $(Q)echo hey \
> >         blah blah blah...
> >
> > Then the $(Q) evaluates either to '@' (meaning the commands are
> > hidden), or nothing (meaning the commands are displayed). In your
> > example this would also cause the echo itself to be displayed. If
> > that's really an issue for you, you can probably work around it by
> > wrapping your echo commands in a function (like using $(call), for
> > example) that can return the text its given or nothing depending on
> > the value of SHOW_CMD. I typically use the $(Q) construct above and
> > don't worry about the extra echo...maybe someone else has a better
> > idea :)
> >
> > -Mike
>
> You could just do it like this...
>
> ifeq ($(SHOW_CMD),1)
>    Q =
> else
>    Q = @
> endif
>
> all:
>         @echo hey
>         $(Q)blah blah blah
>
> -Pete
>

Hmm - even easier than I thought! Though when writing commands like
that one has to be aware that the commands are executed in separate
shells, unlike a single shell with the backslash-newline construct
(can't seem to find an appropriate reference at the moment...). In
most cases (including the original example) that probably doesn't
matter. But if you're doing things like exporting variables in the
command list then it can change the behavior:

all:
        export foo=bar; \
        echo "foo = $$foo"

all2:
        export foo=bar
        echo "foo = $$foo"

In 'all' it would echo "foo = bar", but in all2 it shows "foo =". Just
a heads up, for anyone who tries it.

-Mike




reply via email to

[Prev in Thread] Current Thread [Next in Thread]