LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-03-2012, 01:19 PM   #1
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Rep: Reputation: 5
Talking 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.
 
Old 09-03-2012, 02:44 PM   #2
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

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

Last edited by sag47; 09-03-2012 at 02:51 PM.
 
4 members found this post helpful.
Old 09-03-2012, 07:37 PM   #3
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by sree_ec View Post
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
...
 
Old 09-05-2012, 02:02 PM   #4
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by sag47 View Post
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
 
Old 09-05-2012, 02:04 PM   #5
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by ntubski View Post
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?
 
Old 09-05-2012, 03:05 PM   #6
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by sree_ec View Post
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).
 
1 members found this post helpful.
Old 09-05-2012, 04:25 PM   #7
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
Thumbs up

Quote:
Originally Posted by ntubski View Post
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
 
Old 09-05-2012, 10:42 PM   #8
i_am_sorry
LQ Newbie
 
Registered: Sep 2012
Posts: 2

Rep: Reputation: Disabled
Quote:
Originally Posted by sag47 View Post
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?
 
1 members found this post helpful.
Old 09-06-2012, 12:59 AM   #9
sag47
Senior Member
 
Registered: Sep 2009
Location: Raleigh, NC
Distribution: Ubuntu, PopOS, Raspbian
Posts: 1,899
Blog Entries: 36

Rep: Reputation: 477Reputation: 477Reputation: 477Reputation: 477Reputation: 477
Quote:
Originally Posted by i_am_sorry View Post
why not the -l (lowercase L) option for grep?
Huh, would you look at that. I learn something new every day . Of course, I could say the same every time I re-read a man page.

Last edited by sag47; 09-06-2012 at 01:01 AM.
 
Old 09-06-2012, 01:01 AM   #10
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
ctags -R *.mk works
Thanks
 
Old 09-10-2012, 02:26 AM   #11
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by sag47 View Post
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?
 
Old 09-14-2012, 06:11 AM   #12
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
bumping up the thread.
 
Old 09-26-2012, 09:37 AM   #13
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
closing because no response is received yet
 
Old 09-26-2012, 09:56 AM   #14
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,781

Rep: Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081Reputation: 2081
Quote:
Originally Posted by sree_ec View Post
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.
 
Old 11-28-2012, 04:44 AM   #15
sree_ec
Member
 
Registered: Sep 2010
Location: world
Distribution: Ubuntu 12.04LTS
Posts: 76

Original Poster
Rep: Reputation: 5
Quote:
Originally Posted by ntubski View Post
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.
 
  


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
Navigate in terminal markf@no-exit-studio Linux - Newbie 2 10-13-2008 05:06 PM
Navigate shinobi59 LQ Suggestions & Feedback 6 01-17-2006 05:49 PM
How do you navigate Linux? Mudokin Linux - Newbie 8 03-10-2004 12:29 AM
How to navigate this forum??? BajaNick LQ Suggestions & Feedback 17 01-02-2004 01:46 PM
what's the best way to navigate around linux? chansky Linux - Newbie 3 09-25-2002 05:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:02 AM.

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