[Qemu-devel] [PATCH 03/12] build-sys: add a rule to print a variable

Marc-André Lureau posted 12 patches 8 years, 2 months ago
There is a newer version of this series
[Qemu-devel] [PATCH 03/12] build-sys: add a rule to print a variable
Posted by Marc-André Lureau 8 years, 2 months ago
$ make print-CFLAGS
CFLAGS=-fsanitize=address -Og -g

Trick from various sources:
https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
https://www.cmcrossroads.com/article/printing-value-makefile-variable

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index ab0354c153..80683e8c8b 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,10 @@ BUILD_DIR=$(CURDIR)
 # Before including a proper config-host.mak, assume we are in the source tree
 SRC_PATH=.
 
-UNCHECKED_GOALS := %clean TAGS cscope ctags docker docker-% help
+UNCHECKED_GOALS := %clean TAGS cscope ctags docker docker-% help print-%
+
+print-%:
+	@echo '$*=$($*)'
 
 # All following code might depend on configuration variables
 ifneq ($(wildcard config-host.mak),)
-- 
2.15.1.355.g36791d7216


Re: [Qemu-devel] [PATCH 03/12] build-sys: add a rule to print a variable
Posted by Eric Blake 8 years, 2 months ago
On 12/07/2017 06:58 PM, Marc-André Lureau wrote:
> $ make print-CFLAGS
> CFLAGS=-fsanitize=address -Og -g
> 
> Trick from various sources:
> https://stackoverflow.com/questions/16467718/how-to-print-out-a-variable-in-makefile
> https://www.cmcrossroads.com/article/printing-value-makefile-variable
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  Makefile | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 

Slick!

Does it need to be documented anywhere that we have this useful
debugging aid in place?

Reviewed-by: Eric Blake <eblake@redhat.com>

> diff --git a/Makefile b/Makefile
> index ab0354c153..80683e8c8b 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -6,7 +6,10 @@ BUILD_DIR=$(CURDIR)
>  # Before including a proper config-host.mak, assume we are in the source tree
>  SRC_PATH=.
>  
> -UNCHECKED_GOALS := %clean TAGS cscope ctags docker docker-% help
> +UNCHECKED_GOALS := %clean TAGS cscope ctags docker docker-% help print-%
> +
> +print-%:
> +	@echo '$*=$($*)'
>  
>  # All following code might depend on configuration variables
>  ifneq ($(wildcard config-host.mak),)
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org