範例 7

$4

automake 使用 Makefile.am 自動產生 Makefile.in,所以不需要再寫一個 Makefile.in 了;當程式碼檔案越來越多越來越複雜時,這可以幫助我們免去一些繁複的 routine。

Makefile.am

bin_PROGRAMS = acqua

acqua_SOURCES = acqua.cc

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

另外,Enrico 提到 autoconf 有良好的 UTF-8 支援,而 automake 目前並沒有良好的 UTF-8 支援,所以在這個例子裡已經不再使用中文的檔案名稱。

步驟

$ aclocal
$ autoheader
$ autoconf
$ automake --add-missing
$ ./configure
$ make
or
$ autoreconf -i
$ ./configure
$ make

前一頁 | 往上 | 後一頁

last edited 2006-01-18 11:26:23 by FourDollars