2014-10-29 18 views
3

讀完autotools mythbuster之後,我試着用子目標對象寫一個非遞歸makefile的小示例,以使我的二進制文件位於我的源文件。automake的subdir-objects選項不起作用

這裏是我的小測試的組織

/ 
    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 "[email protected]" 

configure.ac

AC_PREREQ([2.69]) 
AC_INIT([test], [0.0.1], [[email protected]]) 
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將與選項的src目錄已經創建子目錄對象但似乎這個選項沒有效果,並且toto二進制文件總是在根目錄中生成。

我也嘗試過在Makefile.am中傳遞這個選項,AUTOMAKE_OPTIONS = subdir-objects但是沒有成功。

+0

化妝會自動尋找一個Makefile文件名爲或Makefile的或Makefile.mak或makefile.mak。它不會查找文件名稱Makefile.am。所以使用make -f Makefile.am – user3629249 2014-10-30 02:41:10

+1

'make -f Makefile.am'將不工作。 'Makefile'由Automake和'configure'從'Makefile.am'中生成。 – ptomato 2014-10-30 05:49:02

回答

3

這不是subdir-objects選項的作用。它將中間的構建結果,尤其是*.o目標文件,放在與構建它們的源相同的目錄中。尤其是,您應該在0123那裏找到main.o,而不是在頂層目錄中。

另一方面,最終的編譯結果必須是您在Automake文件中指定的內容和位置。如果你想totosrc/目錄去得,然後用這個Makefile.am

MAINTAINERCLEANFILES = Makefile.in aclocal.m4 config.h.in configure depcomp install-sh missing compile 
bin_PROGRAMS=src/toto 
src_toto_SOURCES=src/main.c 
+0

我可以從經驗中證明,完全可以使用Automake進行非遞歸構建。但是,您可能會發現使用有限的遞歸進行文檔或頭文件*安裝*是有用的。 – 2014-10-29 20:51:16

+0

另外,我從來沒有找到'autogen.sh'這樣的需求,並且'MAINTAINERCLEANFILES'變量中列出的所有內容都被'make maintainer-clean'默認清除,否則可能根本不應該清理。我自己,我會擺脫這兩個。 – 2014-10-29 21:19:38

+0

我已經從[elementary](http://docs.enlightenment.org/auto/elementary/group__Start.html)庫(EFL,Enligthenment)的代碼示例中獲取了autogen.sh和MAINTAINERCLEANFILES的技巧。 – cedlemo 2014-10-30 17:01:59