Skip to content

Autoconf

How to install

apt-get install autoconf

Macros

AC_PREREQ([VERSION])
사용할 autoconf의 버전을 지정한다. (e.g. AC_PREREQ([2.59]))
AC_INIT (package, version, [bug-report], [tarname], [url])
https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Initializing-configure.html
만들고자 하는 Package의 정보. (e.g. AC_INIT([hello], [1.0.0], [aaa@google.com]))
The following M4 macros (e.g., AC_PACKAGE_NAME), output variables (e.g., PACKAGE_NAME), and preprocessor symbols (e.g., PACKAGE_NAME), are defined by AC_INIT:
  • AC_PACKAGE_NAME, PACKAGE_NAME
  • AC_PACKAGE_TARNAME, PACKAGE_TARNAME
  • AC_PACKAGE_VERSION, PACKAGE_VERSION
  • AC_PACKAGE_STRING, PACKAGE_STRING
  • AC_PACKAGE_BUGREPORT, PACKAGE_BUGREPORT
  • AC_PACKAGE_URL, PACKAGE_URL
AC_SUBST (variable, [value])
Create an output variable from a shell variable.
AC_CHECK_TYPES (types, [action-if-found], [action-if-not-found], [includes = ‘AC_INCLUDES_DEFAULT’])
https://www.gnu.org/software/autoconf/manual/autoconf-2.64/html_node/Generic-Types.html
For each type of the types that is defined, define HAVE_type (in all capitals).
AC_LANG_PROGRAM (prologue, body)
https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Generating-Sources.html
Expands into a source file which consists of the prologue, and then body as body of the main function (e.g., main in C). Since it uses AC_LANG_SOURCE, the features of the latter are available.
AC_COMPILE_IFELSE (input, [action-if-true], [action-if-false])
https://www.gnu.org/software/autoconf/manual/autoconf-2.66/html_node/Running-the-Compiler.html
Run the compiler and compilation flags of the current language (see Language Choice) on the input, run the shell commands action-if-true on success, action-if-false otherwise. The input can be made by AC_LANG_PROGRAM and friends.

Library Files

AC_CHECK_LIBAC_SEARCH_LIBS를 사용하면 된다.

Example

Change output variables

Makefile에 @OPENSSL_LIBS@와 같은 형태의 문자열이 치환되는 형태를 원한다면 AC_SUBST을 사용하면 된다. 아래의 코드를 configure.ac에 입력하면 된다.

# Check for usable OpenSSL
have_openssl=yes
OPENSSL_INCLUDES="/usr/local/c2core/include"
OPENSSL_LDFLAGS="/usr/local/c2core/lib/libssl.so /usr/local/c2core/lib/libcrypto.so"
OPENSSL_LIBS=""
AC_SUBST([OPENSSL_INCLUDES])
AC_SUBST([OPENSSL_LIBS])
AC_SUBST([OPENSSL_LDFLAGS])

이후 아래의 명령으로 configure파일을 수정하면 된다.

$ autoconf

zlib example

# Check for zlib.
HAVE_ZLIB=0
AS_IF([test "$with_zlib" != no], [
  AC_MSG_CHECKING([zlib version])

  # First check the zlib header version.
  AC_COMPILE_IFELSE(
    [AC_LANG_PROGRAM([[
        #include <zlib.h>
        #if !defined(ZLIB_VERNUM) || (ZLIB_VERNUM < 0x1204)
        # error zlib version too old
        #endif
        ]], [])], [
    AC_MSG_RESULT([ok (1.2.0.4 or later)])

    # Also need to add -lz to the linker flags and make sure this succeeds.
    AC_SEARCH_LIBS([zlibVersion], [z], [
      AC_DEFINE([HAVE_ZLIB], [1], [Enable classes using zlib compression.])
      HAVE_ZLIB=1
    ], [
      AS_IF([test "$with_zlib" != check], [
        AC_MSG_FAILURE([--with-zlib was given, but no working zlib library was found])
      ])
    ])
  ], [
    AS_IF([test "$with_zlib" = check], [
      AC_MSG_RESULT([headers missing or too old (requires 1.2.0.4)])
    ], [
      AC_MSG_FAILURE([--with-zlib was given, but zlib headers were not present or were too old (requires 1.2.0.4)])
    ])
  ])
])
AM_CONDITIONAL([HAVE_ZLIB], [test $HAVE_ZLIB = 1])

Troubleshooting

undefined AC_PROG_LIBTOOL

configure 또는 autoreconf등을 사용할 경우 아래와 같은 에러가 발생될 수 있다.

configure.in:14: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation.
autoreconf: /usr/bin/autoconf failed with exit status: 1

이 경우 libtool를 설치해야 한다.

$ sudo apt-get install libtool

Favorite site