範例 7
$4
automake 使用 Makefile.am 自動產生 Makefile.in,所以不需要再寫一個 Makefile.in 了;當程式碼檔案越來越多越來越複雜時,這可以幫助我們免去一些繁複的 routine。
Makefile.am
bin_PROGRAMS = acqua acqua_SOURCES = acqua.cc
簡短的兩行敘述就可以自動生成 Makefile.in 出來
acqua 是執行檔的名稱
acqua_SOURCES 放的是編譯時所需要的原始碼檔案
acqua.cc
#include "config.h" #include <unistd.h> #include <errno.h> #include <string.h> #include <iostream> using namespace std; int main() { #ifdef APTGET execl(APTGET, APTGET, "install", "xdesktopwaves", (char*)NULL); cerr << "execl failed: " << strerror(errno) << endl; return 1; #else cout << "I would like to install the package xdesktopwaves," " but apt-get is not available in your system." << endl; cout << "Please install xdesktopwaves manually." << endl; return 0; #endif }
同前例。
configure.ac
AC_INIT(hello, 0.1, [email protected]) AC_CONFIG_SRCDIR([acqua.cc]) AM_CONFIG_HEADER(config.h) AM_INIT_AUTOMAKE([foreign]) AC_PROG_CXX AC_PATH_PROG(APTGET, apt-get, NOTFOUND) if test $APTGET != "NOTFOUND" then AC_DEFINE_UNQUOTED(APTGET, "$APTGET", "Location of apt-get") fi AC_CONFIG_FILES([ Makefile ]) AC_OUTPUT
這邊新增了一行巨集
AM_INIT_AUTOMAKE([foreign])
主要是要讓 autoconf 跟 automake 搭配起來使用。
另外,Enrico 提到 autoconf 有良好的 UTF-8 支援,而 automake 目前並沒有良好的 UTF-8 支援,所以在這個例子裡已經不再使用中文的檔案名稱。
步驟
$ aclocal $ autoheader $ autoconf $ automake --add-missing $ ./configure $ make or $ autoreconf -i $ ./configure $ make
autoreconf 可以自動執行 autoheader, aclocal, automake, libtoolize 另外還有 autopoint (假如需要的話),節省掉許多的指令。