Squid Web Cache wiki

Squid Web Cache documentation

🔗 Autoconf Library Detection guideline

This page is a work in progress. The autoconf template documented here is still evolving and when stable will be turned into a macro.

🔗 Overview of Behaviour

Each library depended on by Squid should have an AC_WITH() macro defined to permit user disabling, requirement, or replacement of the library. Squid should be capable of quicky detecting the libraries absence and

🔗 Piece 1: AC_ARG_WITH()

Use this autoconf provided macro to setup path locations and with_* variables for the library.

    AC_ARG_WITH(foo,
      AS_HELP_STRING([--without-foo],
                     [Do not use Foo. Default: auto-detect]), [
    case "$with_foo" in
      yes|no)
        : # Nothing special to do here
        ;;
      *)
        if test ! -d "$withval" ; then
          AC_MSG_ERROR([--with-foo path does not point to a directory])
        fi
        LIBFOO_PATH="-L$with_foo/lib"
        CXXFLAGS="-I$with_foo/include $CXXFLAGS"
      esac
    ])
    AH_TEMPLATE(USE_FOO,[Foo support is available])

🔗 Piece 2: Library need check

    if test "x$with_foo" != "xno"; then
      SQUID_STATE_SAVE(squid_foo_state)
      LIBS="$LIBS $LIBFOO_PATH"

Piece #3 and #4 goes in here

  SQUID_STATE_ROLLBACK(squid_foo_state)

  if test "x$with_foo" = "xyes" -a "x$LIBFOO_LIBS" = "x"; then
    AC_MSG_ERROR([Required Foo library not found])
  fi
  if test "x$LIBFOO_LIBS" != "x" ; then
    CXXFLAGS="$LIBFOO_CFLAGS $CXXFLAGS"
    FOOLIB="$LIBFOO_PATH $LIBFOO_LIBS"
    AC_DEFINE(USE_FOO,1,[Foo support is available])
    with_foo=yes
  else
    with_foo=no
  fi
fi
AC_MSG_NOTICE([Foo library support: ${with_foo:=auto} ${LIBFOO_PATH} ${LIBFOO_LIBS}])
AC_SUBST(FOOLIB)

🔗 Piece 3: pkg-config and file detections

Prefer the use of pkg-config to locate library parameters. When provided by the library author they are updated automatically if the build parameters change, and can also do library version detection more accurately.

The PKG_CHECK_MODULES macro creates the local variables LIBFOO_CFLAGS and LIBFOO_LIBS necessary to build against the library.

An example of how to use PKG_CHECK_MODULES:

  # auto-detect using pkg-config
  PKG_CHECK_MODULES([LIBFOO],[foo >= 1.0.0],,[

    ## something went wrong.
    ## try to find the package without pkg-config

    ## check that the library is actually new enough.
    ## by testing for a 1.0.0+ function which we use
    AC_CHECK_LIB(foo,foo_10_function,[LIBFOO_LIBS="-lfoo"])
  ])

🔗 Piece 4: header detection

Check for the library header includes separately.

This is required as a side effect of the Squid requiremet for HAVE_FOO_H wrapper definitions. The pkg-config tool does not check for them automatically and it makes no sense to do them twice for both its success and failure actions.

  if test "x$LIBFOO_LIBS" != "x" ; then
    AC_CHECK_HEADERS(foo.h)
  fi

🔗 Makefile.am

Each binary that uses library Foo should include ` $(FOOLIB) ` in its LDADD declaration following the libcompat.la entry and will be linked when relevant.

:information_source: for ease of maintenance these FOOLIB LDADD entries should be alphabetical.

Navigation: Site Search, Site Pages, Categories, 🔼 go up