Skip to contentSkip to conversation

Makefile: add variable print capabilities

PATCH New Emeric Vigier 3 participants 8 messages Jul 19, 2012 – May 26, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Makefile: add variable print capabilities

Hi all,

I just got started with buildroot yesterday, and like it :-).
I am no Makefile expert, then often I turn into wanting to check Makefile variables. This patch adds a capability to do so by issuing:

$ make print-<myvariable>

e.g.

$ make print-DL_DIR
DL_DIR = /home/evigier/buildroot/dl

The implementation is perhaps clumsy, I am open to advices. Thanks, keep on the good work.

Emeric

#1 lore raw

PATCH 1/1 Makefile: add variable print capabilities

Taken from http://www.cmcrossroads.com/ask-mr-make/
6521-dumping-every-makefile-variable

---
 Makefile |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
Makefile +10 -1
index d55b136..901c3c3 100644
@@ -369,7 +369,8 @@ world: prepare dirs dependencies $(BASE_TARGETS) $(TARGETS_ALL)
 	$(BASE_TARGETS) $(TARGETS) $(TARGETS_ALL) \
 	$(TARGETS_CLEAN) $(TARGETS_DIRCLEAN) $(TARGETS_SOURCE) $(TARGETS_LEGAL_INFO) \
 	$(DL_DIR) $(TOOLCHAIN_DIR) $(BUILD_DIR) $(STAGING_DIR) $(TARGET_DIR) \
-	$(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR)
+	$(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR) \
+	printvars
 
 #############################################################
 #
@@ -377,6 +378,14 @@ world: prepare dirs dependencies $(BASE_TARGETS) $(TARGETS_ALL)
 # dependencies anywhere else
 #
 #############################################################
+printvars:
+	@$(foreach V,$(sort $(.VARIABLES)), \
+	$(if $(filter-out environment% default automatic, \
+	$(origin $V)),$(warning $V=$($V) ($(value $V)))))
+
+print-%:
+	@echo $* = $($*)
+
 $(DL_DIR) $(TOOLCHAIN_DIR) $(BUILD_DIR) $(HOST_DIR) $(BINARIES_DIR) $(STAMP_DIR) $(LEGAL_INFO_DIR) $(REDIST_SOURCES_DIR):
 	@mkdir -p $@
 
Signature · 1 line
1.7.5.4
#2 lore raw

cover Makefile: add variable print capabilities

In reply to Emeric Vigier

Le Thu, 19 Jul 2012 15:01:17 -0400,
Emeric Vigier <[email protected]> a ?crit :

Quoted 10 lines

I just got started with buildroot yesterday, and like it :-).
I am no Makefile expert, then often I turn into wanting to check Makefile variables. This patch adds a capability to do so by issuing:

$ make print-<myvariable>

e.g.

$ make print-DL_DIR
DL_DIR = /home/evigier/buildroot/dl

Hum, is this really useful? What are the use cases? What do other thinks about this?

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#3 lore raw

cover Makefile: add variable print capabilities

----- Mail original -----

Quoted 10 lines

Le Thu, 19 Jul 2012 15:01:17 -0400,
Emeric Vigier <[email protected]> a ?crit :

Quoted 7 lines

I just got started with buildroot yesterday, and like it :-). I am no Makefile expert, then often I turn into wanting to check Makefile variables.
This patch adds a capability to do so by issuing:

$ make print-<myvariable>
Quoted 7 lines
Quoted 4 lines

e.g.

$ make print-DL_DIR
DL_DIR = /home/evigier/buildroot/dl

Hum, is this really useful? What are the use cases? What do other thinks about this?

It is somehow similar to Android's "get_build_var" which is very useful to me.

$ get_build_var TARGET_OUT
out/target/product/panda/system

But maybe there are other convenient ways to retrieve those INKTV (I never know the value) variables without grepping or reading Makefile and included ones?

Quoted 8 lines

Thomas
--
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com

Signature · 1 line
Emeric
#4 lore raw

cover Makefile: add variable print capabilities

In reply to Thomas Petazzoni

Emeric, All,

On 2012-07-19 22:08 +0200, Thomas Petazzoni spake thusly:

Quoted 9 lines

Le Thu, 19 Jul 2012 15:01:17 -0400,
Emeric Vigier <[email protected]> a ?crit :

Quoted 6 lines

I just got started with buildroot yesterday, and like it :-).
I am no Makefile expert, then often I turn into wanting to check Makefile variables. This patch adds a capability to do so by issuing:

$ make print-<myvariable>
Quoted 7 lines
Quoted 4 lines

e.g.

$ make print-DL_DIR
DL_DIR = /home/evigier/buildroot/dl

Hum, is this really useful? What are the use cases? What do other thinks about this?

I like the overall idea, but only for printing all variables. It's then possible to grep the result to find the one variable one is interested in.

I've taken that patch in my tree (dropped the per-variable print, and adapted the printvars a bit), and will send a pull request to Peter later tonight.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#5 lore raw

cover Makefile: add variable print capabilities

Dear Yann E. MORIN,

Quoted 10 lines · Yann E. MORIN
Quoted 2 lines

Hum, is this really useful? What are the use cases? What do other thinks about this?

I like the overall idea, but only for printing all variables. It's then possible to grep the result to find the one variable one is interested in.

I've taken that patch in my tree (dropped the per-variable print, and adapted the printvars a bit), and will send a pull request to Peter later tonight.

I would suggest to not send patches touching the core infrastructure as part of a pull request that also has many usually uncontroversial package changes/updates.

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com
#6 lore raw

cover Makefile: add variable print capabilities

Thomas, All,

On 2013-05-26 21:44 +0200, Thomas Petazzoni spake thusly:

Quoted 11 lines

Dear Yann E. MORIN,

Quoted 7 lines · Yann E. MORIN
Quoted 2 lines

Hum, is this really useful? What are the use cases? What do other thinks about this?

I like the overall idea, but only for printing all variables. It's then possible to grep the result to find the one variable one is interested in.

Quoted 7 lines
Quoted 3 lines

I've taken that patch in my tree (dropped the per-variable print, and adapted the printvars a bit), and will send a pull request to Peter later tonight.

I would suggest to not send patches touching the core infrastructure as part of a pull request that also has many usually uncontroversial package changes/updates.

Yes, it's in a separate branch. I have three branches:
- fixes
- features
- tentative

That one is on the tentative branch.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#7 lore raw

cover Makefile: add variable print capabilities

Dear Yann E. MORIN,

Quoted 6 lines · Yann E. MORIN

Yes, it's in a separate branch. I have three branches:
- fixes
- features
- tentative

That one is on the tentative branch.

Excellent, thanks!

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com