用于可移植代码的独立,最小配置脚本

时间:2014-12-21 21:29:44

标签: c++ makefile configure autoconf automake

我遇到了我希望分发的代码可移植性问题,但并非如此。我发送的Makefile需要大量编辑才能用户编译和优化他们的系统代码,这是我想要避免的(显然)。我最近一直在研究automake和autoconf,我已经能够成功生成配置脚本来为我的系统生成Makefile。问题是,我似乎无法在没有安装autoconf或automake的机器上工作,或只是使用不同的版本。所以我不必把它全部放在这里,我已经能够通过一个更简单的“你好世界”来复制这些结果。程序

的hello.c

#include <iostream>
using namespace std;
int main(){
  cout << "Hello World" << endl;
  return 0;
}

Makefile.am

bin_PROGRAMS=hello
hello_SOURCES=hello.c

然后我运行autoscan。我并不特别关心这里的版本,因此我只需将configure.scan移至configure.ac。然后我运行automake。仅仅为了完整起见,我得到了这些错误:

configure.ac: error: no proper invocation of AM_INIT_AUTOMAKE was found.
configure.ac: You should verify that configure.ac invokes AM_INIT_AUTOMAKE,
configure.ac: that aclocal.m4 is present in the top-level directory,
configure.ac: and that aclocal.m4 was recently regenerated (using aclocal)
Makefile.am: error: required file './INSTALL' not found
Makefile.am:   'automake --add-missing' can install 'INSTALL'
Makefile.am: error: required file './NEWS' not found
Makefile.am: error: required file './README' not found
Makefile.am: error: required file './AUTHORS' not found
Makefile.am: error: required file './ChangeLog' not found
Makefile.am: error: required file './COPYING' not found
Makefile.am:   'automake --add-missing' can install 'COPYING'
configure.ac:7: error: required file 'config.h.in' not found
Makefile.am: error: required file './depcomp' not found
Makefile.am:   'automake --add-missing' can install 'depcomp'
/usr/share/automake-1.13/am/depend2.am: error: am__fastdepCC does not appear in AM_CONDITIONAL
/usr/share/automake-1.13/am/depend2.am:   The usual way to define 'am__fastdepCC' is to add 'AC_PROG_CC'
/usr/share/automake-1.13/am/depend2.am:   to 'configure.ac' and run 'aclocal' and 'autoconf' again
/usr/share/automake-1.13/am/depend2.am: error: AMDEP does not appear in AM_CONDITIONAL
/usr/share/automake-1.13/am/depend2.am:   The usual way to define 'AMDEP' is to add one of the compiler tests
/usr/share/automake-1.13/am/depend2.am:     AC_PROG_CC, AC_PROG_CXX, AC_PROG_OBJC, AC_PROG_OBJCXX,
/usr/share/automake-1.13/am/depend2.am:     AM_PROG_AS, AM_PROG_GCJ, AM_PROG_UPC
/usr/share/automake-1.13/am/depend2.am:   to 'configure.ac' and run 'aclocal' and 'autoconf' again 

所以我修正了错误:

touch NEWS README AUTHORS ChangeLog
automake --add-missing
add `AM_INIT_AUTOMAKE(hello, 1.0)` to configure.ac
aclocal
autoheader
automake

然后我得到的唯一错误就是automake不喜欢我传入AM_INIT_AUTOMAKE的参数数量。然后我运行autoconfconfigure。 configure脚本执行它并生成可用的makefile。现在的问题是当我尝试将其移动到另一个系统时。

我可以让configure脚本运行,但是当我尝试make

时出现以下错误
cd . && /bin/sh /home/dbwy/autohell/missing automake-1.13 --gnu
/home/dbwy/autohell/missing: line 81: automake-1.13: command not found
WARNING: 'automake-1.13' is missing on your system.
         You should only need it if you modified 'Makefile.am' or
         'configure.ac' or m4 files included by 'configure.ac'.
         The 'automake' program is part of the GNU Automake package:
         <http://www.gnu.org/software/automake>
         It also requires GNU Autoconf, GNU m4 and Perl in order to run:
         <http://www.gnu.org/software/autoconf>
         <http://www.gnu.org/software/m4/>
         <http://www.perl.org/>
make: *** [Makefile.in] Error 1

因此,似乎我的问题在于configure生成的Makefile隐式依赖于automake。我知道在过去使用配置文件的经验中,这并不总是需要的(因为我刚安装了autotools套件来生成这个项目),所以我想知道如何做到这一点?即如何创建一个配置文件,我可以给任何UNIX类型的机器,并让他们能够安装它而无需使用automake或autoconf(我在Mac上遇到autoconf问题)。我的最终目标是能够为某人提供源代码树并配置脚本,让他们能够自定义他们使用的编译器等等。

1 个答案:

答案 0 :(得分:0)

启用维护者模式时会发生此问题。默认情况下,autotools会自动启用此模式,因此必须将AM_MAINTAINER_MODE添加到其configure.ac。调用AM_MAINTAINER_MODE会自动禁用该模式,并允许选项在配置时将其重新打开:

./configure --enable-maintainer-mode

默认情况下,可以通过将AM_MAINTATINER_MODE([enable])行添加到configure.ac

来启用它