Debug a Makefile containing many Makefile scripts invocations, for a variable
Linux - DesktopThis forum is for the discussion of all Linux Software used in a desktop context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Debug a Makefile containing many Makefile scripts invocations, for a variable
How to debug a make Makefile containing many Makefile scripts invocations, to trace where a variable/identifier name is actually declared/defined with debug log of all tracked ways to finding that, when that variable is being used at RHS
Last edited by BudiKusasi; 11-18-2020 at 04:28 AM.
I'm afraid there is no tool which can give you direct answer to this question:
Quote:
when that variable is being used at RHS
make -p can be useful too, but anyway, makefile[s] are not shell scripts where the commands are executed line by line. The execution of any line of code may depend on the target[s] specified, the evaluation of the actual dependency tree, existence of dependent targets, environment and also the status of the commands already executed.
If you want you can insert lines like
I got workaround by this 'angel of savior' command:
$(error v = $v...... )
just put variable name to find out and move this line up/down to intercept curious, suspected part, although clearly laborious it's working awesome...
at least for me
I got workaround by this 'angel of savior' command:
$(error v = $v...... )
just put variable name to find out and move this line up/down to intercept curious, suspected part, although clearly laborious it's working awesome...
at least for me
That's what I suggested too (I think using info is a bit better than error). Anyway, if you think it is now solved please mark the thread solved.
Last edited by pan64; 11-20-2020 at 03:04 AM.
Reason: typo
You could also use the $(warning) function inside an $(if ...) instead of $(error) if you want to log some condition without terminating make, or $(info) as suggested by pan64.
You could also define an assert style macro which you could use throughout your Makefile to report and/or terminate when a variable is or is not defined.
Here is an example which tests that a variable is defined shamelessly adapted from Managing Projects With GNU Make, 3rd Edition, pages 63-80.
Code:
#First define a common assert style macro
define assert
$(if $1,,$(error Assertion failed: $2))
endef
Then use it to define your test macro:
Code:
define assert-defined
$(call assert,$(filter-out undefined,$(origin $1)),"$1" is undefined)
endef
Then $(assert-defined,varname) wherever you want to test that some variable is defined, and exit with error if not defined.
Your desired test appears to be the opposite case, print message if the variable is defined, so I will leave that and other adaptations as an exercise!
Last edited by astrogeek; 11-20-2020 at 02:51 AM.
Reason: grammar, typos
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.