Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: there is a stray {note} in the AC_DEFUN example. I didn't move it because I didn't want to guess how it ended.

...

Section
Column
width50%
Code Block
# ================ NET SNMP ================
AC_DEFUN([CHECK_FOO],
[
    AC_MSG_CHECKING([for foo includes ])
    include_path="$includedir $prefix/include /usr/include /usr/local/include"
    include_check="foo/foo.h"

    foundpath=""
    for dir in $include_path ; do
        if test -f "$dir/$include_check";
        then
            foundpath=$dir;
            break;
{note}
You *must* check to make sure that an
         fi;
    done
    if test x_$foundpath = x_; then
       AC_MSG_ERROR('$include_check' not found)
    else
       AC_MSG_RESULT($foundpath/$include_check)
    fi
])
Column
width50%

This code defines the CHECK_FOO test macro; it is written in the m4 macro language, which when processed generates a shell script code fragment that is incorporated into the configure script.

The AC_MSG_CHECKING macro causes configure to print a progress message about what it is looking for - this message does not get a newline at the end.

The for loop checks in a series of directories for the foo/foo.h include file. The search list should be chosen to look in all the places the target file might be on different platforms, including those installed from rpm (or equivalent) packages or from source. In this case, all the choices were ones that will be in the default search path for include files, so no manipulation of the path is needed. There are a number of examples in config/general.m4 that do more elaborate searches and set variables used by other parts of the build.

The AC_MSG_RESULT macro causes configure to print a success message about where it found the file.

The AC_MSG_ERROR macro causes configure to print a failure message, and aborts configure.

...

Info

There are exceptions - for example, if all that's needed is a library that is linked (either statically or dynamiclydynamically) into an executable installed by the component RPM, then you don't need to declare that - the build system detects and includes those dependencies automatically. However, it never hurts to add them manually, especially if a particular version is needed.

...