help-make
[Top][All Lists]
Advanced

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

Re: Function to display a command without expanding variables


From: Ken Smith
Subject: Re: Function to display a command without expanding variables
Date: Fri, 5 Oct 2007 15:07:11 -0700

Hi Michael,

Here is a self contained example that achieves what you're trying to
do.  Note, that we have to escape the dollar signs when printing them
in the shell or else things get really strange.

---GNUmakefile BEGIN
cc := gcc
cflags := -DWHATEVER
#verbose := t
objs := a.o

.PHONY: all
all: $(objs)

show-vars = \
$(strip \
  $(foreach .tmp,$(1), \
    $(warning $(.tmp)="$($(.tmp))") \
   ) \
 )

$(if $(strip $(verbose)), \
  $(do nothing), \
  $(eval q := @) \
  $(call show-vars,cc cflags) \
 )

escape-dollar-signs = $(subst $$,\$$,$(1))

c-compile-rule = $(cc) $(cflags) -c $< -o $@

%.o : %.c ; $(strip $(q)$(c-compile-rule) \
$(if $(strip $(verbose)),$(do nothing), \
  && echo "$(call escape-dollar-signs,$(value c-compile-rule))" \
 ) \
)

.PHONY: clean
clean: ; rm -f $(objs)

a.c : ; echo "void foo(){}" > $@
---GNUmakefile END

Example usage:

$ make
GNUmakefile:16: cc="gcc"
GNUmakefile:16: cflags="-DWHATEVER"
$(cc) $(cflags) -c $< -o $@

$ make clean
GNUmakefile:16: cc="gcc"
GNUmakefile:16: cflags="-DWHATEVER"
rm -f a.o

$ make verbose=t
gcc -DWHATEVER -c a.c -o a.o

$ make verbose=t clean
rm -f a.o

   Ken

On 10/5/07, Michael Morrell <address@hidden> wrote:
> John,
>
> My goal is to have a "nicer" verbose output.
>
> Currently, if I have a Makefile with:
>
> CC = gcc
> CFLAGS = -DWHATEVER
>
> foo.o: foo.c
>    $(Q)$(CC) $(CFLAGS) -c $<
>
> Then, when I call make with "Q=@", I will get just the output from the
> compile, and when I call make with "Q=", I will get the output
>
>   gcc -DWHATEVER -c foo.c
>
> printed before the compiler output.
>
> I want a way to have the verbose mode show me this instead:
>
> CC = gcc
> CFLAGS = -DWHATEVER
> $(CC) $(CFLAGS) -c $<
>
> before the compiler output (I'm not sure how I want to see $< handled).
>
> That way, if I were to compare two such outputs from make with hundreds
> of such compiles and where all I changed was the value of CFLAGS, I would
> see just one line of difference.
>
> Does that explain things better?
>
>    Michael
>
> --- John Graham-Cumming <address@hidden> wrote:
>
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > Michael Morrell wrote:
> > > I'm trying to write a function that will let me display a command
> > without
> > > expanding the variables.
> > >
> > > This way, I can write:
> > >
> > > x = 1
> > > y = 2
> > >
> > > all:
> > >      $(call show-cmd, echo $(x) $(y))
> > >
> > > and have the output be:
> > >
> > > echo $(x) $(y)
> > > 1 2
> > >
> > > That is, I want to see the command I am executing but I want it in a
> > > "symbolic" form.
> >
> >
> > You can't do that directly with a $(call) because $(call) expands it's
> > arguments before they are passed to the function.   You could do
> > something like
> >
> > a = echo $(x) $(y)
> >
> > and then use $(value a) to get the unexpanded string.   What are you
> > actually trying to achieve?
> >
> > John.
> > -----BEGIN PGP SIGNATURE-----
> > Version: GnuPG v1.4.2.2 (Darwin)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> >
> > iD8DBQFHBpYRLphrp73n/hARArAjAKDW/DnuobFCdJQVn+ULECLxW5HuOgCgyVsC
> > 9zFtnT7eoPGhgwWvpBpZeH4=
> > =23Kz
> > -----END PGP SIGNATURE-----
> >
> >
> > _______________________________________________
> > Help-make mailing list
> > address@hidden
> > http://lists.gnu.org/mailman/listinfo/help-make
> >
>
>
>
>
> ____________________________________________________________________________________
> Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for 
> today's economy) at Yahoo! Games.
> http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow
>
>
> _______________________________________________
> Help-make mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/help-make
>




reply via email to

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