LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Tool to navigate makefiles (https://www.linuxquestions.org/questions/programming-9/tool-to-navigate-makefiles-4175425446/)

sree_ec 09-03-2012 01:19 PM

Tool to navigate makefiles
 
I have, may be, a 'strange' request.
Anyone here is familiar with any tool to navigate makefiles?(makefile, Makefile, .mk etc) .I have a huge build system for me to study and make some modifications . I am really finding it difficult to go through the makefiles. Any help is appreciated.

Note: what I need is something line ctags for .c files.

sag47 09-03-2012 02:44 PM

I usually use vim. Here's a couple of navigation tips.

Here are some good shortcuts. HINT: ^W means CTRL+W keyboard shortcut.

vim Terminology
buffer - a file loaded into memory (not always displayed in the current window)

key sequence - mode invoked - description
  • gf - normal "command" - when cursor is over a file name it will follow and open the file. It subsequently adds that file to your list of buffers to be accessed.
  • :ls - normal "command" - show a list of buffers
  • :b N - normal "command" - where N is an integer. Replaces the current window with the contents of the buffer. List buffers using :ls.
  • ^W n - normal "command" - open a blank window. You can load other buffers into the blank window.
  • ^W [hjkl] - normal "command" - navigates to other windows when screen is split. Use only one letter of the list [hjkl].
  • ^W f - split window and edit file name under the cursor

To learn more about vim and it's many uses run the following command to learn it.
Code:

vimtutor
To learn more about the commands I listed above see the following help documentation within vim. For the help documentation when you see ^W you literally type ^W.
  • :help ^W
  • :help sp
  • :help :ls
  • :help gf
  • :help :b
  • :help :sb
  • :help gt
  • :help gT

It's pretty useful for navigating any document which links other files due to its ability to follow linked files relative to the path of the working directory. In C programs, it correctly follows headers to their source files.

Lastly, find and grep are great utilities for figuring out where a function shows up in a source tree when paired with other files. Here's an example where I'm looking for which files contain the function tree() but don't necessarily care how many times the function is referenced (just which files it shows up in).
Code:

cd /path/to/src/code/
grep -ir 'tree(' * | cut -d: -f1 | sort -u

That is almost invaluable when reverse engineering code.

SAM

ntubski 09-03-2012 07:37 PM

Quote:

Originally Posted by sree_ec (Post 4771641)
Note: what I need is something line ctags for .c files.

The version of ctags I have supports Makefiles:
Code:

1% ctags --version
ctags (GNU Emacs 23.4)
Copyright (C) 2012 Free Software Foundation, Inc.
This program is distributed under the terms in ETAGS.README
% ctags --help
...
-l LANG, --language=LANG
        Force the following files to be considered as written in the
        named language up to the next --language=LANG option.
...
These are the currently supported languages, along with the
default file names and dot suffixes:
...
  makefile  Makefile makefile GNUMakefile Makefile.in Makefile.am
...


sree_ec 09-05-2012 02:02 PM

Quote:

Originally Posted by sag47 (Post 4771703)
I usually use vim. Here's a couple of navigation tips.

Here are some good shortcuts. HINT: ^W means CTRL+W keyboard shortcut.

vim Terminology
buffer - a file loaded into memory (not always displayed in the current window)

key sequence - mode invoked - description
  • gf - normal "command" - when cursor is over a file name it will follow and open the file. It subsequently adds that file to your list of buffers to be accessed.
  • :ls - normal "command" - show a list of buffers
  • :b N - normal "command" - where N is an integer. Replaces the current window with the contents of the buffer. List buffers using :ls.
  • ^W n - normal "command" - open a blank window. You can load other buffers into the blank window.
  • ^W [hjkl] - normal "command" - navigates to other windows when screen is split. Use only one letter of the list [hjkl].
  • ^W f - split window and edit file name under the cursor

To learn more about vim and it's many uses run the following command to learn it.
Code:

vimtutor
To learn more about the commands I listed above see the following help documentation within vim. For the help documentation when you see ^W you literally type ^W.
  • :help ^W
  • :help sp
  • :help :ls
  • :help gf
  • :help :b
  • :help :sb
  • :help gt
  • :help gT

It's pretty useful for navigating any document which links other files due to its ability to follow linked files relative to the path of the working directory. In C programs, it correctly follows headers to their source files.

Lastly, find and grep are great utilities for figuring out where a function shows up in a source tree when paired with other files. Here's an example where I'm looking for which files contain the function tree() but don't necessarily care how many times the function is referenced (just which files it shows up in).
Code:

cd /path/to/src/code/
grep -ir 'tree(' * | cut -d: -f1 | sort -u

That is almost invaluable when reverse engineering code.

SAM

I will try this out and let you know how it goes. Thanks

sree_ec 09-05-2012 02:04 PM

Quote:

Originally Posted by ntubski (Post 4771858)
The version of ctags I have supports Makefiles:
Code:

1% ctags --version
ctags (GNU Emacs 23.4)
Copyright (C) 2012 Free Software Foundation, Inc.
This program is distributed under the terms in ETAGS.README
% ctags --help
...
-l LANG, --language=LANG
        Force the following files to be considered as written in the
        named language up to the next --language=LANG option.
...
These are the currently supported languages, along with the
default file names and dot suffixes:
...
  makefile  Makefile makefile GNUMakefile Makefile.in Makefile.am
...


This means I can use this version of ctags and make the utility believe that .mk files are written in Makefile language. My understanding is correct?

ntubski 09-05-2012 03:05 PM

Quote:

Originally Posted by sree_ec (Post 4773483)
This means I can use this version of ctags and make the utility believe that .mk files are written in Makefile language. My understanding is correct?

Yes. linux.die.net seems to list a different version of ctags (associated with vi, rather than emacs like mine appears to be); it has slightly different options for this:
Quote:

--langmap=map[,map[...]]
...To map makefiles (e.g. files named either "Makefile", "makefile", or having the extension ".mak") to a language called "make", specify "--langmap=make:([Mm]akefile).mak".

Both versions also have options to find declarations using an arbitrary regex, so they could support any language (well, assuming regexes are suffcient to extract declarations for that language).

sree_ec 09-05-2012 04:25 PM

Quote:

Originally Posted by ntubski (Post 4773525)
Yes. linux.die.net seems to list a different version of ctags (associated with vi, rather than emacs like mine appears to be); it has slightly different options for this:


Both versions also have options to find declarations using an arbitrary regex, so they could support any language (well, assuming regexes are suffcient to extract declarations for that language).

I use Vim more.
Infact I found that ctags already supports .mk files. Here is what my ctags shows
Quote:

$>ctags --list-maps=Make
Make *.mak *.mk [Mm]akefile GNUmakefile

$>ctags --version
Exuberant Ctags 5.9~svn20110310, Copyright (C) 1996-2009 Darren Hiebert
Compiled: Nov 9 2011, 17:40:39
Addresses: <dhiebert@users.sourceforge.net>, http://ctags.sourceforge.net
Optional compiled features: +wildcards, +regex

i_am_sorry 09-05-2012 10:42 PM

Quote:

Originally Posted by sag47 (Post 4771703)
Lastly, find and grep are great utilities for figuring out where a function shows up in a source tree when paired with other files. Here's an example where I'm looking for which files contain the function tree() but don't necessarily care how many times the function is referenced (just which files it shows up in).
Code:

cd /path/to/src/code/
grep -ir 'tree(' * | cut -d: -f1 | sort -u

That is almost invaluable when reverse engineering code.

SAM

why not the -l (lowercase L) option for grep?

sag47 09-06-2012 12:59 AM

Quote:

Originally Posted by i_am_sorry (Post 4773762)
why not the -l (lowercase L) option for grep?

Huh, would you look at that. I learn something new every day :D. Of course, I could say the same every time I re-read a man page.

sree_ec 09-06-2012 01:01 AM

ctags -R *.mk works
Thanks:)

sree_ec 09-10-2012 02:26 AM

Quote:

Originally Posted by sag47 (Post 4771703)
I usually use vim. Here's a couple of navigation tips.
  • gf - normal "command" - when cursor is over a file name it will follow and open the file. It subsequently adds that file to your list of buffers to be accessed.
  • :ls - normal "command" - show a list of buffers
  • :b N - normal "command" - where N is an integer. Replaces the current window with the contents of the buffer. List buffers using :ls.
  • ^W n - normal "command" - open a blank window. You can load other buffers into the blank window.
  • ^W [hjkl] - normal "command" - navigates to other windows when screen is split. Use only one letter of the list [hjkl].
  • ^W f - split window and edit file name under the cursor

SAM

gf command does not expand the VARIABLES , isnt it?
suppose I have,
Quote:

include $(MY_ROOT)/jump.mk
when i try gf command, it tries to jump to /jump.mk and does not expand $(MY_ROOT) .. Is there anyway to include Variable expansion as well?

sree_ec 09-14-2012 06:11 AM

bumping up the thread.

sree_ec 09-26-2012 09:37 AM

closing because no response is received yet :(

ntubski 09-26-2012 09:56 AM

Quote:

Originally Posted by sree_ec (Post 4789826)
closing because no response is received yet :(

Well, you can't actually close the thread, but it looks like there is no easy answer for this. I guess you would have to parse the makefile in vimscript.

sree_ec 11-28-2012 04:44 AM

Quote:

Originally Posted by ntubski (Post 4789839)
Well, you can't actually close the thread, but it looks like there is no easy answer for this. I guess you would have to parse the makefile in vimscript.

Okay.I mean Solved.

I know there was no need to reply at this point of time..But my last question is still relevant.Its just that I am too optimistic to expect a reply. ;)


All times are GMT -5. The time now is 12:18 AM.