makefile - 配置编译选项和编译器 autoconf

标签 makefile rust autotools

我正在使用 Rust 和 tcl 进行个人项目,但我仍然想使用经典的 makefile 结构。
我知道要编译多文件我只需要声明 mod second在 main.rs 和 rustc 上自动连接模块。所以我用

$ rustc main.rs -o output -C debuginfo=2
现在我尝试集成 autoconf 和 automake,因为我想制作一个配置脚本来检查 tcl、rustup 等...但我不知道如何编辑以使用 rustc 及其选项而不是 cc 和 c 选项进行编译(比如尝试一个无法编译的 .o,因为它们没有 main 函数)。
对于配置.ac 我用了:
AC_CONFIG_SRCDIR([source/main.rs])
AC_CONFIG_AUX_DIR(config)

# I manually checked for rustup and tclsh

AM_INIT_AUTOMAKE
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
对于 Makefile.am :
AUTOMAKE_OPTIONS = foreign
bin_PROGRAMS = output

SUBDIRS = sources
output_SOURCES = sources/main.rs
我有 configure.ac 和 Makefile.am 的主目录和所有东西的源目录(还有 autoconf 的配置目录)

最佳答案

Now I tried to integrate autoconf and automake because I want to make a configure script to check for tcl, rustup etc...


配置脚本由 Autoconf 负责。将 Automake 与 Autoconf 一起使用不是强制性的,您应该考虑单独使用 Autoconf 是否明智。这将使您完全控制生成的 Makefile ,就像你会写一个 Makefile.in直接而不是依靠 Automake 为您做这件事。大概,你会写一个更简单的 Makefile.in比 Automake 生成的,这很好。

Automake不一定是不可能的,而是its manual has this to say关于语言支持:

Automake currently only includes full support for C, C++ (see C++ Support), Objective C (see Objective C Support), Objective C++ (see Objective C++ Support), Fortran 77 (see Fortran 77 Support), Fortran 9x (see Fortran 9x Support), and Java (see Java Support with gcj). There is only rudimentary support for other languages, support for which will be improved based on user demand.

Some limited support for adding your own languages is available via the suffix rule handling (see Suffixes).


referenced section about suffix rules展示了如何使用这样的规则来教 Automake 如何构建 Rust 程序。它可能看起来像这样:
.rs:
    $(RUSTC) $< -o $@ $(AM_RUSTFLAGS) $(RUSTFLAGS)

SUFFIXES = .rs
假设 configure将识别 Rust 编译器并将其名称导出为 RUSTC . AM_RUSTFLAGS用于在项目内部定义编译标志(通常在 Makefile.am 中)和 RUSTFLAGS供构建器在构建时添加或覆盖编译标志。
但是由于编译器不生成中间目标文件(或者我收集到),我希望在 output_SOURCES 中定义源文件。不会产生工作的 Makefile,并且您可能需要顶级 Rust 源的名称来匹配所需二进制文件的名称(即 output.rs 而不是 main.rs )。那么,单后缀规则应该在没有明确指定任何源的情况下构建您的二进制文件。您还想在 EXTRA_SOURCES 中命名所有贡献的 Rust 源。变量,否则它们将从通过 make dist 构建的分发包中省略.
还要注意,如果您正在构建多文件程序,上述内容并未定义实际存在的所有构建依赖项。我建议通过添加适当的仅先决条件规则来做到这一点,例如
output: $(output_extra_sources)
(没有配方)在多文件情况下。这将确保 make将在 output 时识别由于对 output.rs 以外的其中一个来源进行了修改,需要重建.

关于makefile - 配置编译选项和编译器 autoconf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64593081/

相关文章:

rust - '移动发生是因为值具有类型' Rust 错误

enums - 将Rust枚举转换为子枚举

autotools - 我可以在 distcheck 期间使用 $dc_install_base 安装 systemd 文件吗?

Autotools:应该将 config.guess、depcomp 或 ltmain.sh 存储在 SVN 存储库中吗?

ruby-on-rails - 在 ruby​​-1.8.7-p334 [ x86_64 ] 上使用 rvm 安装 nokogiri gem 时出错

rust - 在 `loop` 中使用 Rust 的错误会导致廉价的阻塞,但为什么呢?

python - 如何使bash和make install使用虚拟环境

linux - 使用 configure 识别 Raspberry Pi 主机

c++ - 官方 C++/11 Makefile 标准/替代品?

c++ - 如何扩展先决条件列表中的 makefile 变量?