Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Out-of-tree vmod skeleton

  • Loading branch information...
commit 9ad8b8bb5251b0082011774d8904329a4582628c 0 parents
@mbgrydeland mbgrydeland authored
3  Makefile.am
@@ -0,0 +1,3 @@
+ACLOCAL_AMFLAGS = -I m4
+
+SUBDIRS = src
6 README
@@ -0,0 +1,6 @@
+This is an example skeleton for developing out-of-tree Varnish vmods.
+
+When running configure, specify the location of your Varnish source tree like this:
+./configure VARNISHSRC=DIR
+
+Optionally you can also set the vmod install dir by adding VMODDIR=DIR (defaults to LIBDIR/varnish/vmods, which would become /usr/local/lib/varnish/vmods on most platforms).
44 autogen.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+warn() {
+ echo "WARNING: $@" 1>&2
+}
+
+case `uname -s` in
+Darwin)
+ LIBTOOLIZE=glibtoolize
+ ;;
+FreeBSD)
+ LIBTOOLIZE=libtoolize
+ ;;
+Linux)
+ LIBTOOLIZE=libtoolize
+ ;;
+SunOS)
+ LIBTOOLIZE=libtoolize
+ ;;
+*)
+ warn "unrecognized platform:" `uname -s`
+ LIBTOOLIZE=libtoolize
+esac
+
+automake_version=`automake --version | tr ' ' '\n' | egrep '^[0-9]\.[0-9a-z.-]+'`
+if [ -z "$automake_version" ] ; then
+ warn "unable to determine automake version"
+else
+ case $automake_version in
+ 0.*|1.[0-8]|1.[0-8][.-]*)
+ warn "automake ($automake_version) detected; 1.9 or newer recommended"
+ ;;
+ *)
+ ;;
+ esac
+fi
+
+set -ex
+
+aclocal -I m4
+$LIBTOOLIZE --copy --force
+autoheader
+automake --add-missing --copy --foreign
+autoconf
52 configure.ac
@@ -0,0 +1,52 @@
+AC_PREREQ(2.59)
+AC_COPYRIGHT([Copyright (c) 2011 Varnish Software AS])
+AC_INIT([libvmod_example], [0.1])
+AC_CONFIG_MACRO_DIR([m4])
+AC_CONFIG_SRCDIR(src/vmod.vcc)
+AM_CONFIG_HEADER(config.h)
+
+AC_CANONICAL_SYSTEM
+AC_LANG(C)
+
+AM_INIT_AUTOMAKE([foreign])
+
+AC_GNU_SOURCE
+AC_PROG_CC
+AC_PROG_CC_STDC
+if test "x$ac_cv_prog_cc_c99" = xno; then
+ AC_MSG_ERROR([Could not find a C99 compatible compiler])
+fi
+AC_PROG_CPP
+
+AC_PROG_INSTALL
+AC_PROG_LIBTOOL
+AC_PROG_MAKE_SET
+
+# Checks for header files.
+AC_HEADER_STDC
+AC_CHECK_HEADERS([sys/stdlib.h])
+
+# Check for python
+AC_CHECK_PROGS(PYTHON, [python3 python3.1 python3.2 python2.7 python2.6 python2.5 python2 python], [AC_MSG_ERROR([Python is needed to build this vmod, please install python.])])
+
+# Varnish source tree
+AC_ARG_VAR([VARNISHSRC], [path to Varnish source tree (mandatory)])
+if test "x$VARNISHSRC" = x; then
+ AC_MSG_ERROR([No Varnish source tree specified])
+fi
+AC_CHECK_FILE([$VARNISHSRC/include/varnishapi.h],
+ [],
+ [AC_MSG_FAILURE(["$VARNISHSRC" is not a Varnish source directory])]
+)
+
+# vmod installation dir
+AC_ARG_VAR([VMODDIR], [vmod installation directory @<:@LIBDIR/varnish/vmods@:>@])
+if test "x$VMODDIR" = x; then
+ VMODDIR=$libdir/varnish/vmods
+fi
+
+AC_CONFIG_FILES([
+ Makefile
+ src/Makefile
+])
+AC_OUTPUT
18 src/Makefile.am
@@ -0,0 +1,18 @@
+INCLUDES = -I$(VARNISHSRC)/include -I$(VARNISHSRC)
+
+vmoddir = $(VMODDIR)
+vmod_LTLIBRARIES = libvmod_example.la
+
+libvmod_example_la_LDFLAGS = -version-info 1:0:0
+
+libvmod_example_la_SOURCES = \
+ vcc_if.c \
+ vcc_if.h \
+ vmod.c
+
+vcc_if.c vcc_if.h: $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc
+ @PYTHON@ $(VARNISHSRC)/lib/libvmod_std/vmod.py $(top_srcdir)/src/vmod.vcc
+
+EXTRA_DIST = vmod.vcc
+
+CLEANFILES = $(builddir)vcc_if.c $(builddir)/vcc_if.h
18 src/vmod.c
@@ -0,0 +1,18 @@
+#include <stdlib.h>
+
+#include "vrt.h"
+#include "bin/varnishd/cache.h"
+
+#include "vcc_if.h"
+
+int
+init_function(struct vmod_priv *priv, const struct VCL_conf *conf)
+{
+ return (0);
+}
+
+int
+vmod_abs(struct sess *sp, int val)
+{
+ return (abs(val));
+}
3  src/vmod.vcc
@@ -0,0 +1,3 @@
+Module example
+Init init_function
+Function INT abs(INT)
Please sign in to comment.
Something went wrong with that request. Please try again.