範例 5
$4
原本是沒有 "config.h" 這個檔案的,等一下要利用 autoheader 以及 autoconf 自動產生 "config.h"。
configure.ac
AC_INIT(hello, 0.1, [email protected]) AC_CONFIG_SRCDIR([水.cc]) AC_CONFIG_HEADERS(config.h) AC_PROG_CXX AC_PATH_PROG(APTGET, apt-get, /usr/bin/apt-get) AC_DEFINE_UNQUOTED(APTGET, "$APTGET", "Location of apt-get") AC_CONFIG_FILES([ Makefile ]) AC_OUTPUT
Makefile.in
CXX = @CXX@ APTGET = @APTGET@ 水: 水.cc $(CXX) -o $@ $?
水.cc
#include "config.h" #include <unistd.h> #include <errno.h> #include <string.h> #include <iostream> using namespace std; int main() { execl(APTGET, APTGET, "install", "xdesktopwaves", (char*)NULL); cerr << "execl failed: " << strerror(errno) << endl; return 1; }
步驟
執行 autoheader 判斷 "configure.ac" 中的 AC_CONFIG_HEADERS(config.h) 產生 config.h.in
/* config.h.in. Generated from configure.ac by autoheader. */ /* "Location of apt-get" */ #undef APTGET /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the version of this package. */ #undef PACKAGE_VERSION
其中的/* "Location of apt-get" */ #undef APTGET
是由 "configure.ac" 中的 AC_DEFINE_UNQUOTED(APTGET, "$APTGET", "Location of apt-get") 所產生的 執行 autoconf 產生 configure 執行 ./configure 產生 Makefile 及 config.h 執行 make 開始編譯程式