範例 6
$4
此範例主要是在說明我們可以在 "configure.ac" 當中使用 shell script 。
AC_PATH_PROG(APTGET, apt-get, NOTFOUND) if test $APTGET != "NOTFOUND" then AC_DEFINE_UNQUOTED(APTGET, "$APTGET", "Location of apt-get") fi
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, NOTFOUND) if test $APTGET != "NOTFOUND" then AC_DEFINE_UNQUOTED(APTGET, "$APTGET", "Location of apt-get") fi 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() { #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 }
步驟
autoheader
autoconf
./configure
make
./水