aboutsummaryrefslogtreecommitdiff
path: root/varnishapi.m4
blob: 895b9227a44ea42848cdbca2099e8f2a44c3ad0b (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
## 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 $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])
## Tests if the programs and libraries needed for compiling a varnish
## module are present. If VERSION argument is supplied, checks 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, checks if varnish
## API version is at least N.N.N. If API is older, emits error message and
## aborts. If it is newer, emits a warning message at the end of configure.
##
## 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
    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
  
  # 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.  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.