【发布时间】:2014-12-25 17:08:01
【问题描述】:
阅读autotools mythbuster 之后,我尝试使用subdir-objects 编写一个非递归makefile 的小示例,以便将我的二进制文件放在我的源文件目录中.
这是我的小测试的组织:
/
autogen.sh
configure.ac
Makefile.am
src/
main.c
autogen.sh:
#!/bin/sh
echo "Running aclocal..." ; aclocal $ACLOCAL_FLAGS || exit 1
echo "Running autoheader..." ; autoheader || exit 1
echo "Running autoconf..." ; autoconf || exit 1
echo "Running automake..." ; automake --add-missing --copy --gnu || exit 1
./configure "$@"
configure.ac:
AC_PREREQ([2.69])
AC_INIT([test], [0.0.1], [devel@hell.org])
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([config.h])
# Checks for programs.
AC_PROG_CC
AM_INIT_AUTOMAKE([1.14 foreign subdir-objects])
AM_MAINTAINER_MODE([enable])
AC_OUTPUT(Makefile)
Makefile.am:
MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.h.in configure depcomp install-sh missing compile
bin_PROGRAMS=toto
toto_SOURCES=src/main.c
我用 :
编译所有内容./autogen.sh
make
我以为二进制 toto 会使用选项 subdir-objects 在 src 目录中创建,但似乎此选项无效,并且 toto 二进制文件始终在根目录中生成.
我也尝试在 Makefile.am 中使用 AUTOMAKE_OPTIONS = subdir-objects 传递此选项,但没有成功。
【问题讨论】:
-
make 将自动查找名为 Makefile 或 makefile 或 Makefile.mak 或 makefile.mak 的文件。它不会寻找文件名 Makefile.am。所以使用 make -f Makefile.am
-
make -f Makefile.am将不工作。Makefile是由 Automake 和configure从Makefile.am生成的。