LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 11-18-2020, 01:38 AM   #1
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Rep: Reputation: 15
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.
 
Old 11-18-2020, 05:57 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I'd start by using the debug flag for make, -d.
 
Old 11-18-2020, 06:53 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
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
Code:
$(info this is a message)
anywhere too, to see what's happening.

What do you want to achieve at all?
 
Old 11-19-2020, 06:07 PM   #4
BudiKusasi
Member
 
Registered: Apr 2017
Distribution: Artix
Posts: 345

Original Poster
Rep: Reputation: 15
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
 
Old 11-20-2020, 12:47 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Quote:
Originally Posted by BudiKusasi View Post
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
 
Old 11-20-2020, 02:42 AM   #6
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=15, FreeBSD_12{.0|.1}
Posts: 6,264
Blog Entries: 24

Rep: Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194Reputation: 4194
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
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Removing All Syscall Invocations from Kernel Space LXer Syndicated Linux News 0 06-19-2018 08:06 PM
Why don't python scripts run unless I run them with explicit invocations of python? RandomTroll Linux - Newbie 23 10-06-2016 01:29 PM
[SOLVED] modifying variable containing compiler options as values in Makefile chakka.lokesh Programming 3 10-08-2015 11:45 PM
Measure I/O demands for method invocations bkk87 Linux - Kernel 3 05-31-2015 08:57 PM
APT get invocations for installing KDE theseer540 Debian 15 12-04-2004 08:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 02:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration