How to set the default-directory of compilation in Emacs?

SoftTimur picture SoftTimur · Jan 27, 2012 · Viewed 8.3k times · Source

I am coding OCaml under Emacs, I have one makefile in the working folder, and several sub-folders containing .ml files. If I launch M-x compile and make works fine on a buffer of makefile, but does not work on a buffer of a .ml file, it gives me an error:

-*- mode: compilation; default-directory: "..." -*-
Compilation started at Fri Jan 27 18:51:35

make -k
make: *** No targets specified and no makefile found.  Stop.

Compilation exited abnormally with code 2 at Fri Jan 27 18:51:35

It is understandable because the default-directory is sub-folder which does not contain makefile. Does anyone know how to set the folder of makefile always as the default-directory of compilation?

Answer

Thomas picture Thomas · Jan 27, 2012

You can call make with the right arguments:

make -C .. -k

where .. is the path to your Makefile