List Info

Thread: Inserting a '' into a pattern rule command




Inserting a '' into a pattern rule command
country flaguser name
Germany
2007-11-02 19:24:18
Hello,

in my Makefiles, the pattern rule for compiling C sources
has the exact 
compiler command hidden behind a clean custom output like
"[CC] main.o..."
to reduce visual clutter.
This is a stripped-down Makefile:

========================

CFLAGS += -DFOO -DBAR

%.o : %.c
	echo "[CC] $..."; 
	$(CC) -c -o $ $(CFLAGS) $<

test: test.o
	echo "[LD] $..."
	#actually link target here

========================

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.

Now my question is: Can I achieve this without having to
find that '' 
character and remove it inbetween the pattern rule? I'd like
to be able to 
activate this feature by some environment variable, like:
  $ SHOW_CMD=1 make

I was trying to define some variable with a '' in it and
place it there 
programmatically, but I couldn't get it to work:

## tried both with and without a trailing space in this
var,
## and with one as well as two '' chars
BS:= 

%.o : %.c
	echo "[CC] $..."; $(BS)
	$(CC) -c -o $ $(CFLAGS) $<

$ make
[CC] test.o...
/bin/sh:  : command not found
make: *** [test.o] Fehler 127


Surely this must be possible?

-- 
 Martin Willers


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Inserting a '\' into a pattern rule command
user name
2007-11-02 19:57:10
On 11/2/07, Martin Willers <willersxm-arts.de> 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


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Inserting a '\' into a pattern rule command
country flaguser name
United States
2007-11-02 20:06:24
On Nov 2, 2007, at 5:57 PM, Mike Shal wrote:

> On 11/2/07, Martin Willers <willersxm-arts.de> 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


  


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Inserting a '\' into a pattern rule command
user name
2007-11-02 20:22:01
On 11/2/07, Peter Johnson <petecoho.org> wrote:
>
> On Nov 2, 2007, at 5:57 PM, Mike Shal wrote:
>
> > On 11/2/07, Martin Willers <willersxm-arts.de> 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


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

Re: Inserting a '\' into a pattern rule command
country flaguser name
Germany
2007-11-04 05:26:04
> > Another option is to remove the '',
instead (this is almost exactly
> > how it is specified in the Makefile for the Linux
kernel) -
> >
> > [...]
> You could just do it like this...
>
> ifeq ($(SHOW_CMD),1)
>    Q =
> else
>    Q = 
> endif
>
> all:
> 	echo hey
> 	$(Q)blah blah blah

Well, that was indeed simple. Thank you very much!

-- 
 Martin Willers


_______________________________________________
Help-make mailing list
Help-makegnu.org
http:
//lists.gnu.org/mailman/listinfo/help-make

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )