summaryrefslogtreecommitdiffabout
path: root/varnishapi.m4
blob: 147230c642932e5a77c9616875d4c2a48c2d30b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
## Autoconf macros for writing Varnish modules
## Copyright (C) 2016,2017 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 2

## 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 m4_if([$2],,0,[$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 m4_if([$3],,0,[$3]); then
      varnishapi_version_diff=newer
  else
      varnishapi_version_diff=same
  fi
])])

## AM_VARNISHAPI([MIN-VERSION],[MAX-VERSION])
## Tests if the programs and libraries needed for compiling a varnish
## module are present. If MIN-VERSION argument is supplied, checks if
## varnish API version is the same or newer than that. If it is older,
## emits error message and aborts. Otherwise, if MAX-VERSION is specified
## checks varnish API version against that. If the version is newer than
## both MAX-VERSION, a warning message to that effect will be emitted at
## the end of configure.
##
## If no arguments are given, and the package version string ends in -N.N.N,
## (where N stands for a decimal digit), the macro behaves as if it were
## called as AM_VARNISHAPI([N.N.N]).
##
## Sets the following configuration variables:
##
##   VMODDIR         the path of the varnish module directory.
##   VARNISH_MAJOR, VARNISH_MINOR, and VARNISH_PATCH
##                   the corresponding numbers of the varnish API version.
##   VARNISHD        full pathname of the varnishd binary
##   VARNISHTEST     full pathname of the varnishtest binary
##   VARNISHAPI_PKGDATADIR
##                   varnish API package data directory
##   VARNISHAPI_VMODTOOL
##                   full pathname of the vmodtool.py script 
##
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 (deprecated)
  AC_ARG_WITH([varnish-source],
     [],
     [AC_MSG_ERROR([the --with-varnish-source option has been withdrawn])])

  # pkg-config
  PKG_PROG_PKG_CONFIG
  PKG_CHECK_MODULES([VARNISHAPI], [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

    m4_pushdef([ver],[m4_bpatsubst(AC_PACKAGE_VERSION,[.*-\([0-9]\.[0-9]\.[0-9]\)$],[\1])])

    VAPI_CHECK_VER(m4_unquote(m4_split(m4_if([ver],AC_PACKAGE_VERSION,[$1],[$1],,[ver],[$1]),\.)))
    if test $varnishapi_version_diff = older; then
      AC_MSG_ERROR([varnishapi version too old: $VARNISHAPI_MAJOR.$VARNISHAPI_MINOR.$VARNISHAPI_PATCH; required at least $1])
    fi

    m4_if([$2],,[m4_if(ver,AC_PACKAGE_VERSION,[# Suppress the warning message
    varnishapi_version_diff=same])],dnl
    [if test "$varnishapi_version_diff" = newer; then
       VAPI_CHECK_VER(m4_unquote(m4_split([$2],\.)))
     fi])
    m4_popdef([ver])
  else
    AC_MSG_ERROR([unknown varnishapi version])
  fi
  
  # 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_ARG_VAR([VARNISH_BINDIR],[Varnish bin directory])
  VARNISH_BINDIR=$($PKG_CONFIG --variable=bindir varnishapi)

  AC_ARG_VAR([VARNISH_SBINDIR],[Varnish sbin directory])
  VARNISH_SBINDIR=$($PKG_CONFIG --variable=sbindir varnishapi)
  
  AC_ARG_VAR([VARNISHD],[full pathname of the varnishd binary])
  AC_PATH_PROG([VARNISHD],
               [varnishd],[\$(abs_top_srcdir)/build-aux/missing varnishd],
               [$VARNISH_SBINDIR:$PATH])
  AC_ARG_VAR([VARNISHTEST],[full pathname of the varnishtest binary])
  AC_PATH_PROG([VARNISHTEST],
               [varnishtest],[\$(abs_top_srcdir)/build-aux/missing varnishtest],
               [$VARNISH_BINDIR:$PATH])

  AC_ARG_VAR([VARNISHAPI_PKGDATADIR],[full pathname of the varnish lib directory])
  VARNISHAPI_PKGDATADIR=$($PKG_CONFIG --variable=pkgdatadir varnishapi)
  AC_ARG_VAR([VARNISHAPI_VMODTOOL],[full pathname of the vmodtool.py script])
  VARNISHAPI_VMODTOOL='$(VARNISHAPI_PKGDATADIR)/vmodtool.py'
  
  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 ($2).  If it doesn't compile, please report it 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.