Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using vim's make command with a makefile that runs make on subdirectories

Tags:

vim

makefile

I have a project setup that has multiple sub-projects all with their own make files. There is a master make file in the main directory that cd's into each project and runs make in the proper order.

The makefile command looks like this:

sub-project/sub-project.a:
    cd sub-project ; make

The problem I have is that when I run make in vim and an error is reported, vim tries to open the file based on the relative path from inside whatever project had the error. Is there any way to have vim get the relative path from the root directory instead of the sub-project directory?

like image 488
drewag Avatar asked Feb 24 '23 20:02

drewag


2 Answers

Make sure your makefile is reporting when it enters and leaves the subdirectories, as follows:

make[1]: Entering directory `/home/username/projects/projectname/subdir1'
[... compile commands ...]
make[1]: Leaving directory `/home/username/projects/projectname/subdir1'

In my experience, vim will parse this portion of the output to find the correct paths for the files with errors. Also in my (frustrated) experience as of a few years ago, without the messages vim has no idea where to look for the files referenced by the error messages.

Note that this works even with recursive subdirectory building, as in this example:

make[1]: Entering directory `/home/username/projects/projectname/subdir1'
make[2]: Entering directory `/home/username/projects/projectname/subdir1/blah'
[... compile commands ...]
make[2]: Leaving directory `/home/username/projects/projectname/subdir1/blah'
make[1]: Leaving directory `/home/username/projects/projectname/subdir1'
like image 109
Caleb Huitt - cjhuitt Avatar answered Feb 26 '23 10:02

Caleb Huitt - cjhuitt


:make -w is good enough to generate the directory listing that is important for vim to understand the current directory being compiled.

like image 22
Nikhils Avatar answered Feb 26 '23 09:02

Nikhils