I’m trying to write a makefile snippet to compile .el files to .elc files. I have the following snippet:
.el.elc:
$(EMACS) -q -Q --batch \
--eval "(progn
(setq load-path (cons \"$(abs_srcdir)\" load-path))
(setq load-path (cons nil load-path))
(defun byte-compile-dest-file (f) \"$@\")
(condition-case nil
(byte-compile-file \"$<\")
(error (kill-emacs 1))))"
(I have formatted the snippet for presentation, make probably won’t like it laid out this way.)
$(abs_srcdir) is being defined correctly, but I have two problems:
Firstly: With a directory layout like the following:
+- foo.el <- foo.el lives in $(abs_srcdir)
+- _build/
++- bar.el
++- Makefile
(That is, a VPATH build where foo.el lives in srcdir and I’m trying to build in _build.)
If bar.el depends on foo.el (via (require 'foo) and (provide 'foo)), attempts to compile bar.elc fail with the error:
In toplevel form:
../bar.el:1:1:Error: Cannot open load file: foo
This strikes me as odd because thought I was consing $(abs_srcdir) onto load-path. What’s happened?
The second problem is that even if this happens, emacs is exiting with status 0, despite my efforts to wrap the (byte-compile-file) call in a (condition-case). What has happened here?
The first problem I had was that with a VPATH build, files in the build directory weren’t being found (by calls to
(require), for example). For some reason, consingnilontoload-pathdoesn’t work, but consing$(abs_srcdir)works.The second problem was that I couldn’t catch the error raised by
(byte-compile). This was solved by wvxvw:(byte-compile)doesn’t raise errors, but returnstif the compilation succeeds. Therefore, something like:works nicely.