2014-11-08 56 views
2

我想使用的autoconf/automake的工具链,以创建一个非常简单的构建脚本空make文件(主要是作为一个学习的过程。)的Autoconf/Automake的生成

大多数例子似乎表明,你需要一个将每个源目录中的Makefile.am分开,并且项目根目录中的Makefile.am文件应包含SUBDIRS指令,该指令告诉autoconf在哪里查找其他Makefile。

我认为对于一个非常简单的项目,在项目根目录中可能只有一个Makefile.am。但是,当我尝试执行此操作并运行生成的configure脚本时,它将在项目根目录中创建一个空的Makefile(0字节)。

我不确定我在做什么错误。

所以,我的目录结构非常简单:

MyProject 
---src 
------myproject.cpp 
---Makefile.am 
---configure.ac 

configure.ac文件是最小的:

AC_INIT(myproject, 1.0) 
AC_MSG_NOTICE([My Project]) 
AC_PROG_CXX 
AC_LANG(C++) 
AC_CHECK_HEADERS(iostream) 
AC_CONFIG_SRCDIR(src/myproject.cpp) 
AM_INIT_AUTOMAKE(MyProject, 1.0) 
AC_OUTPUT(Makefile) 

而且Makefile.am也很简单:

bin_PROGRAMS = myproject 
myproject_SOURCES = src/myproject.cpp 
myproject_CPPFLAGS = --std=c++11 

我跑:

autoconf configure.ac > configure 

当我运行configure脚本时,没有错误。

然后我看到它产生在项目根目录Makefile

# ls -lh | grep Make 
-rw-r--r-- 1 root root 0 Nov 8 16:13 Makefile 
-rw-r--r-- 1 root root 98 Nov 8 15:53 Makefile.am 
-rw-r--r-- 1 root root 0 Nov 8 15:00 Makefile.in 

而且你可以看到,它产生的Makefile文件完全是空的。

所以我显然误解了autoconf/automake应该如何工作的根本原因。我在这里做错了什么?

+1

你运行过'automake'吗? – reinierpost 2014-11-09 22:43:47

回答

0

我有同样的问题 - automake会生成空的Makefiles。我不知道它为什么会发生,但我通过删除autoconf生成的所有文件来修复它,例如Makefile.in(零字节Makefile.in绝对不好)。

您也可以尝试autoreconf -if

0

这很有意思,我试图复制你的情况和我不同,虽然预期的结果。

  • AM_INIT_AUTOMAKE调用是obsolete,你应该写AM_INIT_AUTOMAKE([foreign])foreign告诉automake不要抱怨丢失README,ChangeLog
  • 你有你的Makefile.am在与源文件不同的文件夹。虽然是好的,新的automake应该抱怨,这是一个正向的不兼容性,我得到这个在输出(automake的1.15):

    Makefile.am:2: warning: source file 'src/myproject.cpp' is in a subdirectory, 
    Makefile.am:2: but option 'subdir-objects' is disabled 
    automake: warning: possible forward-incompatibility. 
    automake: At least a source file is in a subdirectory, but the 'subdir-objects' 
    automake: automake option hasn't been enabled. For now, the corresponding output 
    ... 
    

    这些仅仅是警告,虽然。

  • 不管怎么说,而不是只运行autoconf,我已经跑了autoreconf -i(或-i -f可以肯定的---在-f选项将覆盖所有文件,这些工具生成)。 Autoreconf以正确的顺序为您运行autoconfautomake和其他工具。

  • autoreconf完成后,我得到了一个按预期工作的配置脚本,在运行它之后,我也得到了一个正确的Makefile。