Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke Makefile in different directory without exiting Vim

Tags:

vim

makefile

Referring to the structure below, suppose that I am in /test directory and I opened vim main.cpp. Running :make would invoke /test/Makefile. Now I do :edit ../src/foo.cpp and made changes here, too. I want to run make on /Makefile to create a shared library in /lib. How can I run make on /Makefile without exiting Vim?

project
|  Makefile
|+ lib
|+ include
|- src
    |  foo.cpp
|- test
    |  main.cpp
    |  Makefile
like image 719
Shibli Avatar asked Aug 26 '16 18:08

Shibli


People also ask

How do I change the directory in makefile?

In a Makefile, each line is run in a different shell. If you want to run something in a different directory, you need to cd /dir && something .

Does CD work in makefile?

Yes because variable and function expansion are done before executing the commands by make, whereas pwd and `pwd` is executed by the shell itself.

How do I add a header file path in makefile?

Including Header file from Different Directories This can be done using -I option in makefile. Assuming that functions. h file is available in /home/tutorialspoint/header folder and rest of the files are available in /home/tutorialspoint/src/ folder, then the make file would be written as follows.

Where are makefiles stored?

some projects put their makefile in src/ subdirectory of the root directories of the projects, some projects put their makefiles in the root directory of the project.


1 Answers

Just run:

:make -C path_to_dir_with_your_makefile

Where -C:

-C dir, --directory=dir
        Change to directory dir before reading the makefiles or doing anything else.  If multiple -C options are specified, each is interpreted relative to the previous one: -C / -C etc  is
        equivalent to -C /etc.  This is typically used with recursive invocations of make.
like image 67
Dave Grabowski Avatar answered Nov 15 '22 08:11

Dave Grabowski