Search code examples
emacsemacs23

Cross compile on Emacs


How do I create/issue compilation command on Emacs, so I don't need to switch back and forth between it and console? My usual compilation procedure I'd like to see as Emacs command:

$ export PATH=/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7/bin:$PATH
$ cd my/project 
$ make CROSS_COMPILE=arm-linux-gnueabihf- all

I tried to make my own version of M-x compile command following instructions, but failed as I'm not familiar with Lisp and Emacs internals enough. Please note, that projects in question are big (i.e. kernel) with multi directories and Makefiles, so the approaches (closest Makefile, default directory etc.) described in the previous link are not a solution. Bonus points if you could bind it to a single key, like Fx key on modern IDEs.

P.S. I'm aware that there's similar question, but it's outdated and doesn't cover cross compile issue, I hope there's a better solution nowadays.


Solution

  • You can create a custom function that runs a specific compile command in a specific directory, like this:

    (defun my-compile ()
      (interactive)
      (let ((default-directory "~/my/project"))
        (compile "export PATH=/toolchain/gcc-linaro-arm-linux-gnueabihf-4.7/bin:$PATH && make CROSS_COMPILE=arm-linux-gnueabihf- all")))
    

    And then bind it to some convenient key:

    (global-set-key [f12] 'my-compile)