在 Emacs 上交叉编译

Cross compile on Emacs

如何在 Emacs 上 create/issue 编译命令,这样我就不需要在它和控制台之间来回切换?我希望看到的 Emacs 命令是我通常的编译过程:

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

我试图在 instructions 之后制作我自己的 M-x compile 命令版本,但失败了,因为我对 Lisp 和 Emacs 的内部结构不够熟悉。请注意,有问题的项目很大(即内核),具有多个目录和 Makefile,因此前面 link 中描述的方法(最近的 Makefile、默认目录等)不是解决方案。如果您可以将其绑定到单个键,例如现代 IDE 上的 Fx 键,则可加分。

P.S。我知道有 similar question,但它已经过时并且没有涵盖交叉编译问题,我希望现在有更好的解决方案。

Ctrl U Meta x compile应该问你用什么编译命令。你可以输入 make CROSS_COMPILE=arm-linux-gnueabi all

否则,配置您的 compilation-command Emacs 变量,也许在您的 ~/.emacs 中;您可以将其设为文件局部变量。

您可以在 ~/.emacs 中输入以下未经测试的行

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

顺便说一句,您的 export PATH=... 可以添加,例如在你的 ~/.bashrc 中,或者你可以有一个 shell 脚本 运行 精确地 make 和适当的 PATH 并且让那个脚本成为你的 Emacs compilation-command(甚至可能 "temporarily",即仅在您的 emacs 会话中)

您可以创建一个在特定目录中运行特定编译命令的自定义函数,如下所示:

(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")))

然后将它绑定到一些方便的键:

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