ScrollerBlaster
ScrollerBlaster

Reputation: 1598

Recursive makefiles within vim

My c++ project consists of multiple directories each with their own makefile. One level up I also have a top level makefile which calls the other ones in order.

From within vim I want to make either the top level makefile or one the sub ones. I want to see my errors within vim, pressing ENTER on a line to jump to a source code line.

This works using

make | copen

but only one directory at a time. The file name listed in the error window is just a name, no path. If you try to build the top level makefile and press ENTER on a file name / line number, it does't know the path to the file.

Is there a way around this? I would like to build the top level makefile from within vim and no matter what directory the errors are in to jump to the correct file. The problem may be that g++ only outputs the name of the file, not the path.

Upvotes: 1

Views: 595

Answers (3)

snobb
snobb

Reputation: 1074

You can create a map in your vim to the following

!find .. -type d -exec make -C {} \;

something like:

map  <F12>    <esc>:!find .. -type d -exec make -C {} \;<cr>

I believe you should still see the errors in the :clist.

If you want to run the upper level make file you can do something like:

:make -C .. | copen

Upvotes: 0

Ingo Karkat
Ingo Karkat

Reputation: 172540

The 'errorformat' has a mechanism built in for that; from :help errorformat:

Some compilers produce messages that consist of directory names that have to be prepended to each file name read by %f (example: GNU make). The following codes can be used to scan these directory names; they will be stored in an internal directory stack. E379 %D "enter directory" format string; expects a following %f that finds the directory name %X "leave directory" format string; expects following %f

When defining an "enter directory" or "leave directory" format, the "%D" or "%X" has to be given at the start of that substring. Vim tracks the directory changes and prepends the current directory to each erroneous file found with a relative path. See |quickfix-directory-stack| for details, tips and limitations.

So, you need to get your Makefile to output these "change directory" messages, and make sure they are parsed correctly via your 'errorformat' setting.

Upvotes: 2

romainl
romainl

Reputation: 196546

You could give Vim a custom command to execute with :make:

:set makeprg=make\ -f\ /path/to/your/toplevel/makefile

Upvotes: 0

Related Questions