简体   繁体   中英

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 Mx 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 (ie 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.

PS 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.

Ctrl U Meta x compile should ask you what compilation command to use. You could type make CROSS_COMPILE=arm-linux-gnueabi all

Otherwise, configure your compilation-command Emacs variable, perhaps in your ~/.emacs ; and you might make that a file-local variable.

You could put in your ~/.emacs the following untested lines

 (load-library "compile")
 (global-set-key [f12] 'recompile)
 (setq compilation-command "make CROSS_COMPILE=arm-linux-gnueabihf all")

BTW, your export PATH= ... could be added eg in your ~/.bashrc , or you could have a shell script running that exact make with the appropriate PATH and have that script be your Emacs compilation-command (perhaps even "temporarily", ie just in your emacs session)

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM