diff mbox series

[v2,03/13] build-sys: add a rule to print a variable

Message ID 20171215150659.1811-4-marcandre.lureau@redhat.com
State New
Headers show
Series Various build-sys and ASAN related fixes | expand

Commit Message

Marc-André Lureau Dec. 15, 2017, 3:06 p.m. UTC
$ 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>
Reviewed-by: Eric Blake <eblake@redhat.com>
---
 Makefile                    |  5 ++++-
 docs/devel/build-system.txt | 13 +++++++++++++
 2 files changed, 17 insertions(+), 1 deletion(-)

Comments

Eric Blake Dec. 15, 2017, 6:28 p.m. UTC | #1
On 12/15/2017 09:06 AM, 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>
> Reviewed-by: Eric Blake <eblake@redhat.com>
> ---
>  Makefile                    |  5 ++++-
>  docs/devel/build-system.txt | 13 +++++++++++++
>  2 files changed, 17 insertions(+), 1 deletion(-)

> +++ b/docs/devel/build-system.txt
> @@ -510,3 +510,16 @@ default-configs/$TARGET-NAME file as input.
>  This is the entrypoint used when make recurses to build a single system
>  or userspace emulator target. It is merely a symlink back to the
>  Makefile.target in the top level.
> +
> +
> +Useful make targets
> +===================
> +
> +- help
> +
> +  Print a help message for the most common build targets.

Except that this patch forgot to tweak 'make help' to mention 'make
print-VAR' ;)

> +
> +- print-VAR
> +
> +  Print the value of the variable VAR. Useful for debugging the build
> +  system.
>
Marc-André Lureau Dec. 19, 2017, 3:45 p.m. UTC | #2
Hi

On Fri, Dec 15, 2017 at 7:28 PM, Eric Blake <eblake@redhat.com> wrote:
> On 12/15/2017 09:06 AM, 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>
>> Reviewed-by: Eric Blake <eblake@redhat.com>
>> ---
>>  Makefile                    |  5 ++++-
>>  docs/devel/build-system.txt | 13 +++++++++++++
>>  2 files changed, 17 insertions(+), 1 deletion(-)
>
>> +++ b/docs/devel/build-system.txt
>> @@ -510,3 +510,16 @@ default-configs/$TARGET-NAME file as input.
>>  This is the entrypoint used when make recurses to build a single system
>>  or userspace emulator target. It is merely a symlink back to the
>>  Makefile.target in the top level.
>> +
>> +
>> +Useful make targets
>> +===================
>> +
>> +- help
>> +
>> +  Print a help message for the most common build targets.
>
> Except that this patch forgot to tweak 'make help' to mention 'make
> print-VAR' ;)

Well, I don't think print-VAR is a common build target, it's a
build-sys hack/debug imho, so having it described in build-system.txt
only make sense.

Do you agree?

thanks
Eric Blake Dec. 19, 2017, 4:31 p.m. UTC | #3
On 12/19/2017 09:45 AM, Marc-André Lureau wrote:

>>> +Useful make targets
>>> +===================
>>> +
>>> +- help
>>> +
>>> +  Print a help message for the most common build targets.
>>
>> Except that this patch forgot to tweak 'make help' to mention 'make
>> print-VAR' ;)
> 
> Well, I don't think print-VAR is a common build target, it's a
> build-sys hack/debug imho, so having it described in build-system.txt
> only make sense.
> 
> Do you agree?

With the bash-completion library installed, performing tab-completion on 
'make ' produces a large list of targets, which includes 'help', but 
even with your patch does NOT include 'print-CFLAGS' or any variant of 
print-.  If I use just tab-completion and 'make help', then having 
'print-FOO' listed under the "Generic targets:" section of the help 
output would let me discover it without me having to read build-system.txt.

Does anyone else have a strong opinion for or against the additional 
output in 'make help'?
diff mbox series

Patch

diff --git a/Makefile b/Makefile
index 199f39fde1..46bc61004d 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),)
diff --git a/docs/devel/build-system.txt b/docs/devel/build-system.txt
index 386ef36ee3..52501f2ad9 100644
--- a/docs/devel/build-system.txt
+++ b/docs/devel/build-system.txt
@@ -510,3 +510,16 @@  default-configs/$TARGET-NAME file as input.
 This is the entrypoint used when make recurses to build a single system
 or userspace emulator target. It is merely a symlink back to the
 Makefile.target in the top level.
+
+
+Useful make targets
+===================
+
+- help
+
+  Print a help message for the most common build targets.
+
+- print-VAR
+
+  Print the value of the variable VAR. Useful for debugging the build
+  system.