aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2016-01-23 22:07:14 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2016-01-23 22:07:14 +0200
commitf064cf4d7aa1ead1f8607b8b72baf883f015ffc8 (patch)
treeb9bffc8d01a735a511389397bede224fe741e948
downloadacvmod-f064cf4d7aa1ead1f8607b8b72baf883f015ffc8.tar.gz
acvmod-f064cf4d7aa1ead1f8607b8b72baf883f015ffc8.tar.bz2
Initial commit
-rw-r--r--varnishapi.m4161
1 files changed, 161 insertions, 0 deletions
diff --git a/varnishapi.m4 b/varnishapi.m4
new file mode 100644
index 0000000..b3ef75d
--- /dev/null
+++ b/varnishapi.m4
@@ -0,0 +1,161 @@
+## Autoconf macros for writing Varnish modules
+## Copyright (C) 2016 Sergey Poznyakoff
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 3, or (at your option)
+## any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+## serial 1
+
+## VAPI_CHECK_VER([MAJOR], [MINOR], [PATCH]) - Check version
+##
+## Arguments are literal numbers. All of them are optional, but at least
+## MAJOR must be present, otherwise the macro will produce empty expansion.
+## The macro expands to shell code that compares the supplied numbers with
+## the Varnish API version stored in environment variables VARNISHAPI_MAJOR,
+## VARNISHAPI_MINOR, and VARNISHAPI_PATCH. Depending on the comparison,
+## the code sets variable varnishapi_version_diff to one of: "older", "newer",
+## or "same".
+##
+m4_define([VAPI_CHECK_VER],[
+ m4_if([$1],,,[if test $VARNISHAPI_MAJOR -lt $1; then
+ varnishapi_version_diff=older
+ elif test $VARNISHAPI_MAJOR -gt $1; then
+ varnishapi_version_diff=newer
+ m4_if([$2],,,[elif test $VARNISHAPI_MINOR -lt $2; then
+ varnishapi_version_diff=older
+ elif test $VARNISHAPI_MINOR -gt $2; then
+ varnishapi_version_diff=newer
+ ])m4_if([$3],,,[elif test $VARNISHAPI_PATCH -lt $3; then
+ varnishapi_version_diff=older
+ elif test $VARNISHAPI_PATCH -gt $3; then
+ varnishapi_version_diff=newer
+ ])else
+ varnishapi_version_diff=same
+ fi
+ if test $varnishapi_version_diff = older; then
+ AC_MSG_ERROR([unsupported varnishapi version $VARNISHAPI_MAJOR.$VARNISHAPI_MINOR.$VARNISHAPI_PATCH])
+ fi
+])])
+
+## AM_VARNISHAPI([VERSION])
+## Test if the programs and libraries needed for compiling a varnish
+## module are present. If VERSION argument is supplied, check if varnish API
+## version is the same or newer than that. Otherwise, if package version
+## string ends in -N.N.N, where N stands for a decimal digit, check if varnish
+## API version is at least N.N.N. If API is older, emit error message and
+## abort. If it is newer, emit a warning message at the end of configure.
+##
+## Set configuration variable VMODDIR to the path of the varnish module
+## directory.
+## Set VARNISHSRC to the pathname of the varnish source directory.
+## Set variables VARNISH_MAJOR, VARNISH_MINOR, and VARNISH_PATCH to the
+## corresponding numbers of the varnish API version.
+##
+AC_DEFUN([AM_VARNISHAPI],
+[ # Check for pkg-config
+ PKG_PROG_PKG_CONFIG
+
+ # Check for python
+ AC_CHECK_PROGS(PYTHON, [python], [AC_MSG_ERROR([python is not found.])])
+
+ # Varnish source tree
+ AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree])
+ AC_ARG_WITH([varnish-source],
+ AC_HELP_STRING([--with-varnish-source=DIR],
+ [Varnish sources are located in DIR]),
+ [VARNISHSRC=$withval])
+
+ if test -z "$VARNISHSRC"; then
+ AC_MSG_ERROR([no Varnish source tree specified])
+ fi
+ case "$VARNISHSRC" in
+ /*) ;;
+ *) AC_MSG_ERROR([varnish source path must be absolute pathname])
+ esac
+
+ VARNISHSRC=$(cd $VARNISHSRC && pwd)
+
+ # pkg-config
+ PKG_PROG_PKG_CONFIG
+ PKG_CHECK_MODULES([libvarnishapi], [varnishapi])
+
+ varnishapi_version() {
+ VARNISHAPI_MAJOR=$[]1
+ VARNISHAPI_MINOR=$[]2
+ VARNISHAPI_PATCH=$[]3
+ }
+
+ v=$($PKG_CONFIG --modversion varnishapi)
+
+ if test -n "$v"; then
+ save_IFS=$IFS
+ IFS='.'
+ varnishapi_version $v
+ IFS=$save_IFS
+ VAPI_CHECK_VER(m4_if([$1],,
+ [m4_pushdef([ver],[m4_bpatsubst(AC_PACKAGE_VERSION,[.*-\([0-9]\)\.\([0-9]\)\.\([0-9]\)$],[m4_quote(\1,\2,\3)])])dnl
+m4_if(ver,AC_PACKAGE_VERSION,,[m4_unquote(ver)])dnl
+m4_popdef([ver])],
+ [m4_unquote(m4_split([$1],\.))]))
+ else
+ AC_MSG_ERROR([unknown varnishapi version])
+ fi
+
+ # Check that varnishtest is built in the varnish source directory
+ AC_CHECK_FILE([$VARNISHSRC/bin/varnishtest/varnishtest],
+ [],
+ [AC_MSG_FAILURE([cannot find "$VARNISHSRC/bin/varnishtest/varnishtest". Please build your varnish source directory])])
+
+ # vmod installation dir
+ AC_ARG_VAR([VMODDIR], [vmod installation directory])
+ AC_ARG_WITH([vmoddir],
+ AC_HELP_STRING([--with-vmoddir=DIR],
+ [install modules to DIR]),
+ [case "$withval" in
+ /*) VMODDIR=$withval;;
+ no) unset VMODDIR;;
+ *) AC_MSG_ERROR([argument to --with-vmoddir must be absolute pathname])
+ esac],[VMODDIR=$($PKG_CONFIG --variable=vmoddir varnishapi)
+ if test -z "$VMODDIR"; then
+ AC_MSG_FAILURE([cannot determine vmod installation directory])
+ fi])
+
+ if test -z "$VMODDIR"; then
+ VMODDIR='$(libdir)/varnish/mods'
+ fi
+
+ AC_CONFIG_COMMANDS([status],[
+delim="---------------------------------------------------------------------------"
+echo ""
+echo $delim
+echo "Building for Varnish version $version"
+if test "$varnishapi_version_diff" = newer; then
+ fmt <<EOT
+WARNING: This version is newer than the latest version for which
+$PACKAGE_STRING was tested. If it doesn't compile, please send a mail to
+<$PACKAGE_BUGREPORT>.
+EOT
+fi
+echo $delim
+echo ""
+],
+[version="$VARNISHAPI_MAJOR.$VARNISHAPI_MINOR"
+if test -n "$VARNISHAPI_PATCH"; then
+ version="\$version.$VARNISHAPI_PATCH"
+fi
+varnishapi_version_diff=$varnishapi_version_diff
+PACKAGE_STRING="$PACKAGE_STRING"
+PACKAGE_BUGREPORT=$PACKAGE_BUGREPORT
+])])
+
+## varnishapi.m4 ends

Return to:

Send suggestions and report system problems to the System administrator.