英文:
Apart from complexity, are there technical barriers to have a "crossplatform autotools"?
问题
I'm asking out of curiosity. 如果这种问题不受欢迎,请告诉我。
我了解 autotools 栈及其问题,但其中一个主要的,尽管是理论上的好处是,如果正确使用,将与所谓的 tarball 一起分发的 configure
脚本只需要一个 POSIX shell 来检测目标系统上的依赖关系并生成 Makefile。现在有 CMake 解决了许多问题,但要付出的代价是最终用户必须在他们的系统上安装它,这并不总是方便的(例如,当初始化尚未安装 CMake 但有一个 shell 时)。
是否有技术原因阻止创建一个“跨平台 autotools”?我指的是这样一个工具:
- 生成独立的脚本,执行与 CMake 相同的检查
- 这些脚本由目标 shell 语言编写
- 并生成目标的构建文件
(例如,结果是一个独立的 POSIX shell 脚本,生成 POSIX makefile,生成 Visual Studio 解决方案的 batch/PowerShell)。这些可以为项目的所有支持平台生成,用户只需告诉他们的操作系统和平台运行脚本,无需安装除编译器和依赖项之外的任何其他内容。
我怀疑这种东西不存在的原因不是技术性的,而是因为 1)复杂性和 2)CMake 已经解决了大部分问题。我是否漏掉了其他原因?
英文:
I'm asking out of curiosity. If this kind of question is not welcome, please let me know.
I am aware of the autotools stack and its problems, but one major, albeit theoretical benefit of them is that if used correctly, the resulting configure
script that will be distributed with a so-called tarball only needs a POSIX shell to detect dependencies on the target system itself and generate a Makefile. Nowadays, there exists CMake which solves many problems, but at the cost of the end user having to install it on their system, which is not always convenient. (e.g. when bootstrapping one doesn't yet have CMake but has a shell).
Is there a technical reason that prevents having a "cross-platform autotools"? By this I mean a tool that:
- generates standalone scripts which do the same checks that CMake does
- which are written in the target's shell language
- and generate the target's build files
(e.g. the result is standalone POSIX shell script that generates POSIX makefile, batch/PowerShell that generates Visual Studio solution). These could be generated for all supported platforms of a project, and one would tell the end user to run the script for their OS and platform, no need to install anything else than the compiler and dependencies.
My suspicion is that the reason something like this doesn't exist is not technical but rather due to 1) complexity and 2) CMake solves most of the problems already. Is there any other reason I'm missing?
答案1
得分: 2
"Is there a technical reason that prevents having a 'cross-platform autotools'? By this I mean a tool that:
- generates standalone scripts which do the same checks that CMake does
- which are written in the target's shell language
- and generate the target's build files"
TL;DR: Prevents, no. Disfavors, yes.
The Autotools are cross-platform. Their whole point is that Unix-like systems vary significantly on both per-arch/OS and per-system bases, and the Autotools provide an adaptive build system flexible enough in principle to support a diversity of platforms. That certainly includes MacOS, and to some extent it even includes Windows (with mingw / msys2, for example). Even if it were limited to just POSIX-conforming systems, these are sufficiently diverse that that would still be cross-platform.
Anyway, the first challenge here is to choose what commonalities to depend upon. The Autotools and CMake diverge here. The Autotools choose a POSIX shell and minimal set of command-line tools as the common components. CMake chooses a bespoke language. Other alternatives choose Python or Java or another general-purpose programming language. Any way around, these systems depend first and foremost on the needed language implementation to be provided by the build environments where they will be used. You say there's no cmake
binary for NewOS 23? Then no CMake for you on machines running that.
The second challenge is to express the needed configuration checks and the needed build rules in a way that can be adapted to the full diversity of systems that are to be supported. This is where CMake's choice of a bespoke language covering both of these areas shines most. In principle, however, any language with sufficient power could be chosen, and translated as needed to languages appropriate to various systems. Or one can choose a general-purpose language and limit build systems to those providing an implementation of that language.
But the crux of the matter may be timing. If you are going to generate scripts in the multiple native shell languages of a variety of targets, then when do you do that? If you wait until build time then why bother? Instead of writing a program that generates appropriately-targeted shell scripts at that point, wouldn't it be cleaner and simpler to write a program that directly manages the build? On the other hand, if you are going to build targeted scripts as a project maintenance activity then the maintainer or the tools need to make a decision at that time about what platforms are supported.
Overall, a tool such as you describe is possible in principle, but I don't see why anyone would choose to build something with that particular combination of design elements.
"My suspicion is that the reason something like this doesn't exist is not technical but rather due to 1) complexity and 2) CMake solves most of the problems already. Is there any other reason I'm missing?"
I agree that the reason is not technical. I suppose that complexity factors in, but I don't think we're looking at something with a different order of complexity than CMake. The main issue here is that combination of characteristics you describe makes for a bad design.
As an alternative, consider (just for the sake of argument) something like SCons.* It does or can do system configuration checks such as CMake and Autotools configure
scripts do, and it manages actual builds as CMake
-generated build systems and Autotools-generated makefiles do. It is cross-platform in the sense that it runs on any platform supporting new-enough Python (not a native shell script) and that additionally provides a toolchain it knows about, whether natively or through custom additional configuration.
*I despise SCons, but it fits into this discussion.
英文:
> Is there a technical reason that prevents having a "cross-platform
> autotools"? By this I mean a tool that:
>
> - generates standalone scripts which do the same checks that CMake does
> - which are written in the target's shell language
> - and generate the target's build files
TL;DR: Prevents, no. Disfavors, yes.
The Autotools are cross-platform. Their whole point is that Unix-like systems vary significantly on both per-arch/OS and per-system bases, and the Autotools provide an adaptive build system flexible enough in principle to support a diversity of platforms. That certainly includes MacOS, and to some extent it even includes Windows (with mingw / msys2, for example). Even if it were limited to just POSIX-conforming systems, these are sufficiently diverse that that would still be cross-platform.
Anyway, the first challenge here is to choose what commonalities to depend upon. The Autotools and CMake diverge here. The Autotools choose a POSIX shell and minimal set of command-line tools as the common components. CMake chooses a bespoke language. Other alternatives choose Python or Java or another general-purpose programming language. Any way around, these systems depend first and foremost on the needed language implementation to be provided by the build environments where they will be used. You say there's no cmake
binary for NewOS 23? Then no CMake for you on machines running that.
The second challenge is to express the needed configuration checks and the needed build rules in a way that can be adapted to the full diversity of systems that are to be supported. This is where CMake's choice of a bespoke language covering both of these areas shines most. In principle, however, any language with sufficient power could be chosen, and translated as needed to languages appropriate to various systems. Or one can choose a general-purpose language and limit build systems to those providing an implementation of that language.
But the crux of the matter may be timing. If you are going to generate scripts in the multiple native shell languages of a variety of targets, then when do you do that? If you wait until build time then why bother? Instead of writing a program that generates appropriately-targeted shell scripts at that point, wouldn't it be cleaner and simpler to write a program that directly manages the build? On the other hand, if you are going to build targeted scripts as a project maintenance activity then the maintainer or the tools need to make a decision at that time about what platforms are supported.
Overall, a tool such as you describe is possible in principle, but I don't see why anyone would choose to build something with that particular combination of design elements.
> My suspicion is that the reason something like this doesn't exist is not technical but rather due to 1) complexity and 2) CMake solves most of the problems already. Is there any other reason I'm missing?
I agree that the reason is not technical. I suppose that complexity factors in, but I don't think we're looking at something with a different order of complexity than CMake. The main issue here is that combination of characteristics you describe makes for a bad design.
As an alternative, consider (just for the sake of argument) something like SCons.<sup>*</sup> It does or can do system configuration checks such as CMake and Autotools configure
scripts do, and it manages actual builds as CMake
-generated build systems and Autotools-generated makefiles do. It is cross-platform in the sense that it runs on any platform supporting new-enough Python (not a native shell script) and that additionally provides a toolchain it knows about, whether natively or through custom additional configuration.
<sup>*</sup>I despise SCons, but it fits into this discussion.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论