简体   繁体   English

在Emacs上交叉编译

[英]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? 我如何在Emacs上创建/发出编译命令,所以不需要在它与控制台之间来回切换? My usual compilation procedure I'd like to see as Emacs command: 我通常希望使用Emacs命令查看编译过程:

$ 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. 我按照说明尝试制作自己的Mx compile命令版本,但由于我对Lisp和Emacs的内部知识不够熟悉而失败了。 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. 请注意,所涉及的项目很大(即内核),具有多个目录和Makefile,因此上一个链接中描述的方法(最近的Makefile,默认目录等)不是解决方案。 Bonus points if you could bind it to a single key, like Fx key on modern IDEs. 如果您可以将其绑定到单个键(例如现代IDE上的Fx键),则可以得到加分。

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. PS我知道有一个类似的问题 ,但是它已经过时并且不涉及交叉编译问题,我希望现在有一个更好的解决方案。

Ctrl U Meta x compile should ask you what compilation command to use. Ctrl U Meta x编译应询问您要使用的编译命令。 You could type make CROSS_COMPILE=arm-linux-gnueabi all 您可以输入make CROSS_COMPILE=arm-linux-gnueabi all

Otherwise, configure your compilation-command Emacs variable, perhaps in your ~/.emacs ; 否则,可以在~/.emacs配置compilation-command Emacs变量。 and you might make that a file-local variable. 并且您可以将其设为文件本地变量。

You could put in your ~/.emacs the following untested lines 您可以在~/.emacs放入以下未经测试的行

 (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) 顺便说一句,你的export PATH= ...可以添加,例如在你~/.bashrc ,或者你可以有一个shell脚本运行的,准确的make与适当的PATH ,并让该脚本是您的Emacs compilation-command (甚至可能是“暂时”,即仅在您的emacs会话中)

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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