Make and CMake


At aKademy, David Faure presented a script for calling make from emacs when you write code in a different directory from the one you build in. Since I use vim and bash, I had to adapt it to work for me. One important aspect for vim users is that if you call ‘:make’ from vim, it calls the first ‘make’ it finds in the path. This call is associated with niceness like jumping to the right error lines after calling ‘:make’. The script I paste here should occur in your path before the real make (usually /usr/bin/make) and it should be called ‘make’. When called, it will move up in the directory hierarchy until it finds a directory called ‘build’. It enters there and calls the real ‘make’ with the arguments you passed.

Update: I just discovered that makeobj by Coolo does almost the same.


set makeprg

If you don't want to fiddle with PATH order, you can use:
:set makeprg=bla

Next time you run :make, it will start the bla command.

You can even pass arguments, as long as you escape spaces with backslashes. For example:
:set makeprg=unsermake\ -p