re-adding the list in cc.

-- 
Guillaume Quintard

On Mon, Sep 21, 2015 at 1:54 PM, Guillaume Quintard <
guilla...@varnish-software.com> wrote:

> Sure, here you go. Please note I haven't integrated new changes since I
> first posted (was waiting for the 4.1 release)
>
> --
> Guillaume Quintard
>
> On Mon, Sep 21, 2015 at 1:49 PM, Poul-Henning Kamp <p...@phk.freebsd.dk>
> wrote:
>
>> --------
>> In message <CAJ6ZYQwNUeyOYE5tmLmfDXCxWPR3wHq8dmEHP-J-Oc=
>> m44c...@mail.gmail.com>
>> , Guillaume Quintard writes:
>>
>> >Here's a big patch for the (autotools) build system. It has been one of
>> my
>> >pet peeves, so I took some time during evenings to make it non-recursive.
>> >I'm not sure everybody will be okay with it, but my OCD compelled me to
>> try
>> >:-)
>>
>> I have not been able to get the patch out of the email and the copy
>> in patchwork seems to have the same problem.
>>
>> Can you try again with the patch as an actual attachment ?
>>
>> --
>> Poul-Henning Kamp       | UNIX since Zilog Zeus 3.20
>> p...@freebsd.org         | TCP/IP since RFC 956
>> FreeBSD committer       | BSD since 4.3-tahoe
>> Never attribute to malice what can adequately be explained by
>> incompetence.
>>
>
>
From 7f7f5593faac1523b32fa03534c0d8c8495339a4 Mon Sep 17 00:00:00 2001
From: Guillaume Quintard <guilla...@varnish-software.com>
Date: Tue, 1 Sep 2015 10:37:41 +0200
Subject: [PATCH] Make the build system non-recursive

---
 Makefile.am                       |  75 +++++++++--
 bin/Makefile.am                   |  14 --
 bin/varnishadm/Makefile.am        |  24 ++--
 bin/varnishd/Makefile.am          | 276 +++++++++++++++++++++-----------------
 bin/varnishhist/Makefile.am       |  41 +++---
 bin/varnishlog/Makefile.am        |  45 ++++---
 bin/varnishncsa/Makefile.am       |  53 ++++----
 bin/varnishreplay/Makefile.am     |   8 +-
 bin/varnishstat/Makefile.am       |  20 +--
 bin/varnishtest/Makefile.am       |  57 ++++----
 bin/varnishtop/Makefile.am        |  43 +++---
 configure.ac                      |  29 +---
 doc/Makefile.am                   |   9 +-
 doc/graphviz/Makefile.am          |  41 +++---
 doc/sphinx/Makefile.am            | 148 +++++++++++---------
 etc/Makefile.am                   |  12 +-
 include/Makefile.am               | 244 ++++++++++++++++++---------------
 lib/Makefile.am                   |  23 ----
 lib/libvarnish/Makefile.am        |  87 ++++++------
 lib/libvarnishapi/Makefile.am     | 146 ++++++++++----------
 lib/libvarnishcompat/Makefile.am  |  14 +-
 lib/libvarnishtools/Makefile.am   |   6 +-
 lib/libvcc/Makefile.am            |  75 ++++++-----
 lib/libvgz/Makefile.am            |  54 ++++----
 lib/libvmod_debug/Makefile.am     |  49 +++----
 lib/libvmod_directors/Makefile.am |  57 ++++----
 lib/libvmod_std/Makefile.am       |  55 ++++----
 man/Makefile.am                   |  82 ++++++-----
 28 files changed, 945 insertions(+), 842 deletions(-)
 delete mode 100644 bin/Makefile.am
 delete mode 100644 lib/Makefile.am

diff --git a/Makefile.am b/Makefile.am
index e49505f..a1d1019 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,6 +1,66 @@
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS = include lib bin etc doc man
+CLEANFILES =
+DISTCLEANFILES =
+MAINTAINERCLEANFILES =
+EXTRA_DIST =
+bin_PROGRAMS =
+sbin_PROGRAMS =
+noinst_PROGRAMS =
+noinst_HEADERS =
+vmod_LTLIBRARIES =
+pkglib_LTLIBRARIES =
+dist_pkgdata_SCRIPTS =
+check_LTLIBRARIES =
+lib_LTLIBRARIES =
+noinst_LTLIBRARIES =
+BUILT_SOURCES =
+pkginclude_HEADERS =
+nobase_pkginclude_HEADERS =
+nobase_noinst_HEADERS =
+
+# etc
+include etc/Makefile.am
+
+# include
+include include/Makefile.am
+
+# bin
+include bin/varnishd/Makefile.am
+include bin/varnishlog/Makefile.am
+include bin/varnishncsa/Makefile.am
+include bin/varnishadm/Makefile.am
+include bin/varnishhist/Makefile.am
+include bin/varnishstat/Makefile.am
+include bin/varnishtop/Makefile.am
+include bin/varnishtest/Makefile.am
+# Disabling building of the tools while api is in flux
+#include bin/varnishreplay/Makefile.am
+
+# lib
+vmoddir = $(pkglibdir)/vmods
+vmodtool = $(top_srcdir)/lib/libvcc/vmodtool.py
+vmodtoolargs = --strict
+lib/libvmod_%.lo : include/vmod_abi.h
+
+include lib/libvarnish/Makefile.am
+include lib/libvarnishcompat/Makefile.am
+include lib/libvarnishtools/Makefile.am
+include lib/libvarnishapi/Makefile.am
+include lib/libvcc/Makefile.am
+include lib/libvgz/Makefile.am
+include lib/libvmod_debug/Makefile.am
+include lib/libvmod_std/Makefile.am
+include lib/libvmod_directors/Makefile.am
+
+RST2ANY_FLAGS = --halt=2
+# doc
+include doc/Makefile.am
+include doc/graphviz/Makefile.am
+include doc/sphinx/Makefile.am
+
+# man
+include man/Makefile.am
 
 pkgconfigdir = $(libdir)/pkgconfig
 pkgconfig_DATA = varnishapi.pc
@@ -8,8 +68,8 @@ pkgconfig_DATA = varnishapi.pc
 m4dir = $(datadir)/aclocal
 m4_DATA = varnish.m4
 
-CLEANFILES = cscope.in.out cscope.out cscope.po.out
-EXTRA_DIST = LICENSE autogen.sh varnishapi.pc.in varnish.m4
+CLEANFILES += cscope.in.out cscope.out cscope.po.out
+EXTRA_DIST += LICENSE autogen.sh varnishapi.pc.in varnish.m4
 
 DISTCHECK_CONFIGURE_FLAGS = \
     --enable-developer-warnings \
@@ -17,19 +77,10 @@ DISTCHECK_CONFIGURE_FLAGS = \
     --enable-dependency-tracking \
     --enable-tests
 
-install-data-local:
-	$(install_sh) -d -m 0755 $(DESTDIR)$(localstatedir)/varnish
-
-
 distcleancheck_listfiles = \
 	find . -type f -exec sh -c 'test -f $(srcdir)/$$1 || echo $$1' \
 		sh '{}' ';'
 
-# XXX: This is a hack to ensure we have a built source tree when
-# running make dist If we had used non-recursive make we could have
-# solved it better, but we don't, so use this at least for now.
-LICENSE: all
-
 cscope:
 	-rm -f cscope*
 	find . -name '*.[hcS]' > cscope.files
diff --git a/bin/Makefile.am b/bin/Makefile.am
deleted file mode 100644
index 8aa2ef9..0000000
--- a/bin/Makefile.am
+++ /dev/null
@@ -1,14 +0,0 @@
-#
-
-# Disabling building of the tools while api is in flux
-
-#SUBDIRS = varnishreplay
-SUBDIRS = \
-	varnishadm \
-	varnishd \
-	varnishhist \
-	varnishlog \
-	varnishncsa \
-	varnishstat \
-	varnishtest \
-	varnishtop
diff --git a/bin/varnishadm/Makefile.am b/bin/varnishadm/Makefile.am
index 9033e08..e372502 100644
--- a/bin/varnishadm/Makefile.am
+++ b/bin/varnishadm/Makefile.am
@@ -1,21 +1,21 @@
 #
 
-AM_CPPFLAGS = \
+bin_varnishadm_varnishadm_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include
 
-bin_PROGRAMS = varnishadm
+bin_PROGRAMS += bin/varnishadm/varnishadm
 
-varnishadm_SOURCES = \
-	varnishadm.c \
-	$(top_srcdir)/lib/libvarnish/vas.c \
-	$(top_srcdir)/lib/libvarnish/vsa.c \
-	$(top_srcdir)/lib/libvarnish/vtcp.c \
-	$(top_srcdir)/lib/libvarnish/vss.c
+bin_varnishadm_varnishadm_SOURCES = \
+	bin/varnishadm/varnishadm.c \
+	lib/libvarnish/vas.c \
+	lib/libvarnish/vsa.c \
+	lib/libvarnish/vtcp.c \
+	lib/libvarnish/vss.c
 
-varnishadm_CFLAGS = @LIBEDIT_CFLAGS@
+bin_varnishadm_varnishadm_CFLAGS = @LIBEDIT_CFLAGS@
 
-varnishadm_LDADD = \
-	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
-	$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
+bin_varnishadm_varnishadm_LDADD = \
+	lib/libvarnishapi/libvarnishapi.la \
+	lib/libvarnishcompat/libvarnishcompat.la \
 	${PTHREAD_LIBS} ${RT_LIBS} ${NET_LIBS} @LIBEDIT_LIBS@ ${LIBM}
diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index e4d2ab5..df84905 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -1,138 +1,164 @@
 #
 
-AM_CPPFLAGS = \
+bin_varnishd_varnishd_CPPFLAGS = \
+	-I$(top_srcdir)/bin/varnishd \
 	-I$(top_srcdir)/include \
 	-I$(top_srcdir)/lib/libvgz \
 	-I$(top_builddir)/bin/varnishd \
 	-I$(top_builddir)/include
 
-sbin_PROGRAMS = varnishd
-
-varnishd_SOURCES = \
-	cache/cache_acceptor.c \
-	cache/cache_backend.c \
-	cache/cache_backend_cfg.c \
-	cache/cache_backend_probe.c \
-	cache/cache_backend_tcp.c \
-	cache/cache_ban.c \
-	cache/cache_busyobj.c \
-	cache/cache_cli.c \
-	cache/cache_deliver_proc.c \
-	cache/cache_director.c \
-	cache/cache_esi_deliver.c \
-	cache/cache_esi_fetch.c \
-	cache/cache_esi_parse.c \
-	cache/cache_expire.c \
-	cache/cache_fetch.c \
-	cache/cache_fetch_proc.c \
-	cache/cache_gzip.c \
-	cache/cache_hash.c \
-	cache/cache_http.c \
-	cache/cache_lck.c \
-	cache/cache_main.c \
-	cache/cache_mempool.c \
-	cache/cache_obj.c \
-	cache/cache_panic.c \
-	cache/cache_pool.c \
-	cache/cache_req.c \
-	cache/cache_req_body.c \
-	cache/cache_req_fsm.c \
-	cache/cache_rfc2616.c \
-	cache/cache_range.c \
-	cache/cache_session.c \
-	cache/cache_shmlog.c \
-	cache/cache_vary.c \
-	cache/cache_vcl.c \
-	cache/cache_vrt.c \
-	cache/cache_vrt_priv.c \
-	cache/cache_vrt_re.c \
-	cache/cache_vrt_var.c \
-	cache/cache_vrt_vmod.c \
-	cache/cache_wrk.c \
-	cache/cache_ws.c \
-	common/common_vsm.c \
-	common/common_vsc.c \
-	hash/hash_classic.c \
-	hash/hash_critbit.c \
-	hash/mgt_hash.c \
-	hash/hash_simple_list.c \
-	http1/cache_http1_deliver.c \
-	http1/cache_http1_fetch.c \
-	http1/cache_http1_fsm.c \
-	http1/cache_http1_line.c \
-	http1/cache_http1_pipe.c \
-	http1/cache_http1_proto.c \
-	http1/cache_http1_vfp.c \
-	mgt/mgt_acceptor.c \
-	mgt/mgt_child.c \
-	mgt/mgt_cli.c \
-	mgt/mgt_jail.c \
-	mgt/mgt_jail_unix.c \
-	mgt/mgt_jail_solaris.c \
-	mgt/mgt_main.c \
-	mgt/mgt_param.c \
-	mgt/mgt_param_tbl.c \
-	mgt/mgt_param_bits.c \
-	mgt/mgt_param_tcp.c \
-	mgt/mgt_param_tweak.c \
-	mgt/mgt_pool.c \
-	mgt/mgt_shmem.c \
-	mgt/mgt_vcc.c \
-	mgt/mgt_vcl.c \
-	proxy/cache_proxy_proto.c \
-	storage/stevedore.c \
-	storage/mgt_stevedore.c \
-	storage/stevedore_utils.c \
-	storage/storage_file.c \
-	storage/storage_malloc.c \
-	storage/storage_persistent.c \
-	storage/mgt_storage_persistent.c \
-	storage/storage_persistent_silo.c \
-	storage/storage_persistent_subr.c \
-	storage/storage_umem.c \
-	waiter/mgt_waiter.c \
-	waiter/cache_waiter.c \
-	waiter/cache_waiter_epoll.c \
-	waiter/cache_waiter_kqueue.c \
-	waiter/cache_waiter_poll.c \
-	waiter/cache_waiter_ports.c 
-
-noinst_HEADERS = \
-	builtin_vcl.h \
-	cache/cache_esi.h \
-	cache/cache_pool.h \
-	cache/cache_priv.h \
-	common/heritage.h \
-	hash/hash_slinger.h \
-	http1/cache_http1.h \
-	mgt/mgt.h \
-	mgt/mgt_cli.h \
-	mgt/mgt_param.h \
-	storage/storage.h \
-	storage/storage_persistent.h \
-	waiter/waiter_priv.h \
-	waiter/mgt_waiter.h
+sbin_PROGRAMS += bin/varnishd/varnishd
+
+bin_varnishd_varnishd_SOURCES = \
+	bin/varnishd/cache/cache_acceptor.c \
+	bin/varnishd/cache/cache_backend.c \
+	bin/varnishd/cache/cache_backend_cfg.c \
+	bin/varnishd/cache/cache_backend_probe.c \
+	bin/varnishd/cache/cache_backend_tcp.c \
+	bin/varnishd/cache/cache_ban.c \
+	bin/varnishd/cache/cache_busyobj.c \
+	bin/varnishd/cache/cache_cli.c \
+	bin/varnishd/cache/cache_deliver_proc.c \
+	bin/varnishd/cache/cache_director.c \
+	bin/varnishd/cache/cache_esi_deliver.c \
+	bin/varnishd/cache/cache_esi_fetch.c \
+	bin/varnishd/cache/cache_esi_parse.c \
+	bin/varnishd/cache/cache_expire.c \
+	bin/varnishd/cache/cache_fetch.c \
+	bin/varnishd/cache/cache_fetch_proc.c \
+	bin/varnishd/cache/cache_gzip.c \
+	bin/varnishd/cache/cache_hash.c \
+	bin/varnishd/cache/cache_http.c \
+	bin/varnishd/cache/cache_lck.c \
+	bin/varnishd/cache/cache_main.c \
+	bin/varnishd/cache/cache_mempool.c \
+	bin/varnishd/cache/cache_obj.c \
+	bin/varnishd/cache/cache_panic.c \
+	bin/varnishd/cache/cache_pool.c \
+	bin/varnishd/cache/cache_req.c \
+	bin/varnishd/cache/cache_req_body.c \
+	bin/varnishd/cache/cache_req_fsm.c \
+	bin/varnishd/cache/cache_rfc2616.c \
+	bin/varnishd/cache/cache_range.c \
+	bin/varnishd/cache/cache_session.c \
+	bin/varnishd/cache/cache_shmlog.c \
+	bin/varnishd/cache/cache_vary.c \
+	bin/varnishd/cache/cache_vcl.c \
+	bin/varnishd/cache/cache_vrt.c \
+	bin/varnishd/cache/cache_vrt_priv.c \
+	bin/varnishd/cache/cache_vrt_re.c \
+	bin/varnishd/cache/cache_vrt_var.c \
+	bin/varnishd/cache/cache_vrt_vmod.c \
+	bin/varnishd/cache/cache_wrk.c \
+	bin/varnishd/cache/cache_ws.c \
+	bin/varnishd/common/common_vsm.c \
+	bin/varnishd/common/common_vsc.c \
+	bin/varnishd/hash/hash_classic.c \
+	bin/varnishd/hash/hash_critbit.c \
+	bin/varnishd/hash/mgt_hash.c \
+	bin/varnishd/hash/hash_simple_list.c \
+	bin/varnishd/http1/cache_http1_deliver.c \
+	bin/varnishd/http1/cache_http1_fetch.c \
+	bin/varnishd/http1/cache_http1_fsm.c \
+	bin/varnishd/http1/cache_http1_line.c \
+	bin/varnishd/http1/cache_http1_pipe.c \
+	bin/varnishd/http1/cache_http1_proto.c \
+	bin/varnishd/http1/cache_http1_vfp.c \
+	bin/varnishd/mgt/mgt_acceptor.c \
+	bin/varnishd/mgt/mgt_child.c \
+	bin/varnishd/mgt/mgt_cli.c \
+	bin/varnishd/mgt/mgt_jail.c \
+	bin/varnishd/mgt/mgt_jail_unix.c \
+	bin/varnishd/mgt/mgt_jail_solaris.c \
+	bin/varnishd/mgt/mgt_main.c \
+	bin/varnishd/mgt/mgt_param.c \
+	bin/varnishd/mgt/mgt_param_tbl.c \
+	bin/varnishd/mgt/mgt_param_bits.c \
+	bin/varnishd/mgt/mgt_param_tcp.c \
+	bin/varnishd/mgt/mgt_param_tweak.c \
+	bin/varnishd/mgt/mgt_pool.c \
+	bin/varnishd/mgt/mgt_shmem.c \
+	bin/varnishd/mgt/mgt_vcc.c \
+	bin/varnishd/mgt/mgt_vcl.c \
+	bin/varnishd/proxy/cache_proxy_proto.c \
+	bin/varnishd/storage/stevedore.c \
+	bin/varnishd/storage/mgt_stevedore.c \
+	bin/varnishd/storage/stevedore_utils.c \
+	bin/varnishd/storage/storage_file.c \
+	bin/varnishd/storage/storage_malloc.c \
+	bin/varnishd/storage/storage_persistent.c \
+	bin/varnishd/storage/mgt_storage_persistent.c \
+	bin/varnishd/storage/storage_persistent_silo.c \
+	bin/varnishd/storage/storage_persistent_subr.c \
+	bin/varnishd/storage/storage_umem.c \
+	bin/varnishd/waiter/mgt_waiter.c \
+	bin/varnishd/waiter/cache_waiter.c \
+	bin/varnishd/waiter/cache_waiter_epoll.c \
+	bin/varnishd/waiter/cache_waiter_kqueue.c \
+	bin/varnishd/waiter/cache_waiter_poll.c \
+	bin/varnishd/waiter/cache_waiter_ports.c 
+
+noinst_HEADERS += \
+	bin/varnishd/builtin_vcl.h \
+	bin/varnishd/cache/cache_esi.h \
+	bin/varnishd/cache/cache_pool.h \
+	bin/varnishd/cache/cache_priv.h \
+	bin/varnishd/common/heritage.h \
+	bin/varnishd/hash/hash_slinger.h \
+	bin/varnishd/http1/cache_http1.h \
+	bin/varnishd/mgt/mgt.h \
+	bin/varnishd/mgt/mgt_cli.h \
+	bin/varnishd/mgt/mgt_param.h \
+	bin/varnishd/storage/storage.h \
+	bin/varnishd/storage/storage_persistent.h \
+	bin/varnishd/waiter/waiter_priv.h \
+	bin/varnishd/waiter/mgt_waiter.h
 
 # Headers for use with vmods
-nobase_pkginclude_HEADERS = \
-	cache/cache.h \
-	cache/cache_filter.h \
-	cache/cache_backend.h \
-	cache/cache_director.h \
-	common/common.h \
-	common/params.h \
-	waiter/waiter.h
-
-varnishd_CFLAGS = \
+public_varnishd_headers = \
+	bin/varnishd/cache/cache.h \
+	bin/varnishd/cache/cache_filter.h \
+	bin/varnishd/cache/cache_backend.h \
+	bin/varnishd/cache/cache_director.h \
+	bin/varnishd/common/common.h \
+	bin/varnishd/common/params.h \
+	bin/varnishd/waiter/waiter.h
+
+# This saddens me, but nobase will strip the path completely
+# and we want to change 'bin/varnishd/' to 'varnish/cache/'
+# XXX one mkdir per file is wasteful, but we won't risk
+# forgetting subdirs
+install-data-local: install-public-varnishd-headers
+install-public-varnishd-headers:
+	for i in $(public_varnishd_headers); do \
+		h_dir="$$(dirname $(DESTDIR)$(includedir)/varnish`echo $$i |sed s@bin/varnishd@@`)"; \
+		$(install_sh) -d -m 0755 $$h_dir; \
+		$(INSTALL_HEADER) $(srcdir)/$$i $$h_dir; \
+	done
+
+#		chmod +w $$(dirname $(includedir)/`echo $$i |
+#		            sed s@bin/varnishd@varnish@`);
+uninstall-hook: uninstall-public-varnishd-headers 
+uninstall-public-varnishd-headers :
+	for i in $(public_varnishd_headers); do \
+		rm -f $(DESTDIR)$(includedir)/`echo $$i | \
+			sed s@bin/varnishd@varnish@`; \
+	done
+
+.PHONY: install-public-varnishd-headers uninstall-public-varnishd-headers
+
+EXTRA_DIST += $(public_varnishd_headers)
+
+bin_varnishd_varnishd_CFLAGS = \
 	@PCRE_CFLAGS@ \
 	-DVARNISHD_IS_NOT_A_VMOD \
         -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' \
 	-DVARNISH_VMOD_DIR='"${pkglibdir}/vmods"' \
 	-DVARNISH_VCL_DIR='"${varnishconfdir}"'
 
-varnishd_LDFLAGS = -export-dynamic
+bin_varnishd_varnishd_LDFLAGS = -export-dynamic
 
-varnishd_LDADD = \
+bin_varnishd_varnishd_LDADD = \
 	$(top_builddir)/lib/libvarnish/libvarnish.la \
 	$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
 	$(top_builddir)/lib/libvcc/libvcc.la \
@@ -141,13 +167,15 @@ varnishd_LDADD = \
 	@PCRE_LIBS@ \
 	${DL_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${LIBM} ${LIBUMEM}
 
-EXTRA_DIST = builtin.vcl
-DISTCLEANFILES = builtin_vcl.h
+$(bin_varnishd_varnishd_OBJECTS) : include/tbl/vcl_returns.h
+
+EXTRA_DIST += bin/varnishd/builtin.vcl
+DISTCLEANFILES += bin/varnishd/builtin_vcl.h
 
 #
 # Turn the builtin.vcl file into a C-string we can include in the program.
 #
-builtin_vcl.h:	builtin.vcl
+bin/varnishd/builtin_vcl.h:	bin/varnishd/builtin.vcl
 	echo '/*' > $@
 	echo ' * NB:  This file is machine generated, DO NOT EDIT!' >> $@
 	echo ' *' >> $@
@@ -157,7 +185,7 @@ builtin_vcl.h:	builtin.vcl
 	echo '' >> $@
 	sed -e 's/"/\\"/g' \
 	    -e 's/$$/\\n"/' \
-	    -e 's/^/ "/' $(srcdir)/builtin.vcl >> $@
+	    -e 's/^/ "/' $(srcdir)/bin/varnishd/builtin.vcl >> $@
 
 # Explicitly record dependency
-mgt/mgt_vcc.c:	builtin_vcl.h
+bin/varnishd/mgt/mgt_vcc.c:	bin/varnishd/builtin_vcl.h
diff --git a/bin/varnishhist/Makefile.am b/bin/varnishhist/Makefile.am
index 5904430..eeaa1a2 100644
--- a/bin/varnishhist/Makefile.am
+++ b/bin/varnishhist/Makefile.am
@@ -1,29 +1,36 @@
 #
 
-AM_CPPFLAGS = \
+bin_varnishhist_varnishhist_CPPFLAGS = \
 	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishhist/ \
 	-I$(top_builddir)/include
 
-bin_PROGRAMS = varnishhist
+bin_PROGRAMS += bin/varnishhist/varnishhist
 
-varnishhist_SOURCES = varnishhist.c \
-	varnishhist_options.h \
-	varnishhist_options.c \
-	$(top_srcdir)/lib/libvarnish/vas.c \
-	$(top_srcdir)/lib/libvarnish/version.c \
-	$(top_srcdir)/lib/libvarnish/vpf.c \
-	$(top_srcdir)/lib/libvarnish/vtim.c \
-	$(top_srcdir)/lib/libvarnish/flopen.c \
-	$(top_srcdir)/lib/libvarnishtools/vut.c
+bin_varnishhist_varnishhist_SOURCES = bin/varnishhist/varnishhist.c \
+	bin/varnishhist/varnishhist_options.h \
+	bin/varnishhist/varnishhist_options.c \
+	lib/libvarnish/vas.c \
+	lib/libvarnish/version.c \
+	lib/libvarnish/vpf.c \
+	lib/libvarnish/vtim.c \
+	lib/libvarnish/flopen.c \
+	lib/libvarnishtools/vut.c
 
-varnishhist_LDADD = \
+bin_varnishhist_varnishhist_LDADD = \
 	$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	-lm \
 	@CURSES_LIB@ ${RT_LIBS} ${PTHREAD_LIBS}
 
-noinst_PROGRAMS = varnishhist_opt2rst
-varnishhist_opt2rst_SOURCES = \
-	varnishhist_options.h \
-	varnishhist_options.c \
-	$(top_srcdir)/lib/libvarnishtools/opt2rst.c
+noinst_PROGRAMS += bin/varnishhist/varnishhist_opt2rst
+
+bin_varnishhist_varnishhist_opt2rst_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishhist/ \
+	-I$(top_builddir)/include
+
+bin_varnishhist_varnishhist_opt2rst_SOURCES = \
+	bin/varnishhist/varnishhist_options.h \
+	bin/varnishhist/varnishhist_options.c \
+	lib/libvarnishtools/opt2rst.c
diff --git a/bin/varnishlog/Makefile.am b/bin/varnishlog/Makefile.am
index 2df9415..4e04540 100644
--- a/bin/varnishlog/Makefile.am
+++ b/bin/varnishlog/Makefile.am
@@ -1,30 +1,37 @@
 #
 
-AM_CPPFLAGS = \
+bin_varnishlog_varnishlog_CPPFLAGS = \
 	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishlog \
 	-I$(top_builddir)/include
 
-bin_PROGRAMS = varnishlog
+bin_PROGRAMS += bin/varnishlog/varnishlog
 
-varnishlog_SOURCES = \
-	varnishlog.c \
-	varnishlog_options.h \
-	varnishlog_options.c \
-	$(top_srcdir)/lib/libvarnishtools/vut.c \
-	$(top_srcdir)/lib/libvarnish/vas.c \
-	$(top_srcdir)/lib/libvarnish/flopen.c \
-	$(top_srcdir)/lib/libvarnish/version.c \
-	$(top_srcdir)/lib/libvarnish/vsb.c \
-	$(top_srcdir)/lib/libvarnish/vpf.c \
-	$(top_srcdir)/lib/libvarnish/vtim.c
+bin_varnishlog_varnishlog_SOURCES = \
+	bin/varnishlog/varnishlog.c \
+	bin/varnishlog/varnishlog_options.h \
+	bin/varnishlog/varnishlog_options.c \
+	lib/libvarnishtools/vut.c \
+	lib/libvarnish/vas.c \
+	lib/libvarnish/flopen.c \
+	lib/libvarnish/version.c \
+	lib/libvarnish/vsb.c \
+	lib/libvarnish/vpf.c \
+	lib/libvarnish/vtim.c
 
-varnishlog_LDADD = \
+bin_varnishlog_varnishlog_LDADD = \
 	$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
 
-noinst_PROGRAMS = varnishlog_opt2rst
-varnishlog_opt2rst_SOURCES = \
-	varnishlog_options.h \
-	varnishlog_options.c \
-	$(top_srcdir)/lib/libvarnishtools/opt2rst.c
+noinst_PROGRAMS += bin/varnishlog/varnishlog_opt2rst
+
+bin_varnishlog_varnishlog_opt2rst_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishlog \
+	-I$(top_builddir)/include
+
+bin_varnishlog_varnishlog_opt2rst_SOURCES = \
+	bin/varnishlog/varnishlog_options.h \
+	bin/varnishlog/varnishlog_options.c \
+	lib/libvarnishtools/opt2rst.c
diff --git a/bin/varnishncsa/Makefile.am b/bin/varnishncsa/Makefile.am
index d63df61..c8f7925 100644
--- a/bin/varnishncsa/Makefile.am
+++ b/bin/varnishncsa/Makefile.am
@@ -1,32 +1,39 @@
 #
 
-AM_CPPFLAGS = \
+bin_varnishncsa_varnishncsa_CPPFLAGS = \
 	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishncsa \
 	-I$(top_builddir)/include
 
-bin_PROGRAMS = varnishncsa
+bin_PROGRAMS += bin/varnishncsa/varnishncsa
 
-varnishncsa_SOURCES = \
-	varnishncsa.c \
-	varnishncsa_options.h \
-	varnishncsa_options.c \
-	base64.h \
-	base64.c \
-	$(top_srcdir)/lib/libvarnishtools/vut.c \
-	$(top_srcdir)/lib/libvarnish/vas.c \
-	$(top_srcdir)/lib/libvarnish/flopen.c \
-	$(top_srcdir)/lib/libvarnish/version.c \
-	$(top_srcdir)/lib/libvarnish/vpf.c \
-	$(top_srcdir)/lib/libvarnish/vtim.c \
-	$(top_srcdir)/lib/libvarnish/vsb.c
+bin_varnishncsa_varnishncsa_SOURCES = \
+	bin/varnishncsa/varnishncsa.c \
+	bin/varnishncsa/varnishncsa_options.h \
+	bin/varnishncsa/varnishncsa_options.c \
+	bin/varnishncsa/base64.h \
+	bin/varnishncsa/base64.c \
+	lib/libvarnishtools/vut.c \
+	lib/libvarnish/vas.c \
+	lib/libvarnish/flopen.c \
+	lib/libvarnish/version.c \
+	lib/libvarnish/vpf.c \
+	lib/libvarnish/vtim.c \
+	lib/libvarnish/vsb.c
 
-varnishncsa_LDADD = \
-	$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
-	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
+bin_varnishncsa_varnishncsa_LDADD = \
+	lib/libvarnishcompat/libvarnishcompat.la \
+	lib/libvarnishapi/libvarnishapi.la \
 	${RT_LIBS} ${LIBM}
 
-noinst_PROGRAMS = varnishncsa_opt2rst
-varnishncsa_opt2rst_SOURCES = \
-	varnishncsa_options.h \
-	varnishncsa_options.c \
-	$(top_srcdir)/lib/libvarnishtools/opt2rst.c
+noinst_PROGRAMS += bin/varnishncsa/varnishncsa_opt2rst
+
+bin_varnishncsa_varnishncsa_opt2rst_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishncsa \
+	-I$(top_builddir)/include
+
+bin_varnishncsa_varnishncsa_opt2rst_SOURCES = \
+	bin/varnishncsa/varnishncsa_options.h \
+	bin/varnishncsa/varnishncsa_options.c \
+	lib/libvarnishtools/opt2rst.c
diff --git a/bin/varnishreplay/Makefile.am b/bin/varnishreplay/Makefile.am
index 38d1c30..4610bc5 100644
--- a/bin/varnishreplay/Makefile.am
+++ b/bin/varnishreplay/Makefile.am
@@ -1,18 +1,18 @@
 #
 
-AM_CPPFLAGS = \
+bin_varnishreplay_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include
 
-bin_PROGRAMS = varnishreplay
+bin_PROGRAMS += bin/varnishreplay/varnishreplay
 
-varnishreplay_SOURCES = \
+bin_varnishreplay_varnishreplay_SOURCES = \
 	varnishreplay.c \
 	$(top_srcdir)/lib/libvarnish/vas.c \
 	$(top_srcdir)/lib/libvarnish/vtcp.c \
 	$(top_srcdir)/lib/libvarnish/vss.c
 
-varnishreplay_LDADD = \
+bin_varnishreplay_varnishreplay_LDADD = \
 	$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	${RT_LIBS} ${PTHREAD_LIBS} ${NET_LIBS} ${LIBM}
diff --git a/bin/varnishstat/Makefile.am b/bin/varnishstat/Makefile.am
index 664131d..891569f 100644
--- a/bin/varnishstat/Makefile.am
+++ b/bin/varnishstat/Makefile.am
@@ -1,21 +1,21 @@
 #
 
-AM_CPPFLAGS = \
+bin_varnishstat_varnishstat_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include
 
-bin_PROGRAMS = varnishstat
+bin_PROGRAMS += bin/varnishstat/varnishstat
 
-varnishstat_SOURCES = \
-	varnishstat.h \
+bin_varnishstat_varnishstat_SOURCES = \
+	bin/varnishstat/varnishstat.h \
 	\
-	varnishstat.c \
-	varnishstat_curses.c \
-	$(top_srcdir)/lib/libvarnish/vas.c \
-	$(top_srcdir)/lib/libvarnish/version.c \
-	$(top_srcdir)/lib/libvarnish/vtim.c
+	bin/varnishstat/varnishstat.c \
+	bin/varnishstat/varnishstat_curses.c \
+	lib/libvarnish/vas.c \
+	lib/libvarnish/version.c \
+	lib/libvarnish/vtim.c
 
-varnishstat_LDADD = \
+bin_varnishstat_varnishstat_LDADD = \
 	$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	@CURSES_LIB@ ${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
diff --git a/bin/varnishtest/Makefile.am b/bin/varnishtest/Makefile.am
index 2506a8a..58a48d3 100644
--- a/bin/varnishtest/Makefile.am
+++ b/bin/varnishtest/Makefile.am
@@ -1,51 +1,50 @@
 #
 
-VTC_LOG_COMPILER = ./varnishtest -v -i
+VTC_LOG_COMPILER = bin/varnishtest/varnishtest -v -i
 TEST_EXTENSIONS = .vtc
 TESTS = @VTC_TESTS@
 
-# Make sure we run check-local first
-check: check-am check-local
-check-am: check-local
+check: lib/libvmod_debug/libvmod_debug.la verify-tests-list
 # See if list of checks have changed, recheck
-check-local:
-	if [ "$$(cd $(srcdir) && echo tests/*.vtc)" != "@VTC_TESTS@" ]; then \
-		cd $(top_builddir) && ./config.status --recheck ; \
+verify-tests-list :
+	if [ "$$(cd $(top_srcdir) && echo bin/varnishtest/tests/*.vtc)" != "@VTC_TESTS@" ]; then \
+		./config.status --recheck ; \
 	fi
 
-DISTCLEANFILES = _.ok
+DISTCLEANFILES += bin/varnishtest/_.ok
 
-AM_CPPFLAGS = \
+
+bin_varnishtest_varnishtest_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include \
 	-I$(top_srcdir)/lib/libvgz
 
-bin_PROGRAMS =	varnishtest
-
-varnishtest_SOURCES = \
-		vtc.c \
-		vtc.h \
-		vmods.h \
-		programs.h \
-		vtc_client.c \
-		vtc_http.c \
-		vtc_main.c \
-		vtc_log.c \
-		vtc_sema.c \
-		vtc_server.c \
-		vtc_varnish.c \
-		vtc_logexp.c \
-		vtc_process.c
-
-varnishtest_LDADD = \
+bin_PROGRAMS +=	bin/varnishtest/varnishtest
+
+bin_varnishtest_varnishtest_SOURCES = \
+		bin/varnishtest/vtc.c \
+		bin/varnishtest/vtc.h \
+		bin/varnishtest/vmods.h \
+		bin/varnishtest/programs.h \
+		bin/varnishtest/vtc_client.c \
+		bin/varnishtest/vtc_http.c \
+		bin/varnishtest/vtc_main.c \
+		bin/varnishtest/vtc_log.c \
+		bin/varnishtest/vtc_sema.c \
+		bin/varnishtest/vtc_server.c \
+		bin/varnishtest/vtc_varnish.c \
+		bin/varnishtest/vtc_logexp.c \
+		bin/varnishtest/vtc_process.c
+
+bin_varnishtest_varnishtest_LDADD = \
 		$(top_builddir)/lib/libvarnish/libvarnish.la \
 		$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
 		$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 		$(top_builddir)/lib/libvgz/libvgz.la \
 		${LIBM} ${PTHREAD_LIBS}
 
-varnishtest_CFLAGS = \
+bin_varnishtest_varnishtest_CFLAGS = \
 		-DTOP_BUILDDIR='"${top_builddir}"'
 
-EXTRA_DIST = $(top_srcdir)/bin/varnishtest/tests/*.vtc \
+EXTRA_DIST += @VTC_TESTS@ \
 	$(top_srcdir)/bin/varnishtest/tests/README
diff --git a/bin/varnishtop/Makefile.am b/bin/varnishtop/Makefile.am
index f48e972..82d3d6c 100644
--- a/bin/varnishtop/Makefile.am
+++ b/bin/varnishtop/Makefile.am
@@ -1,30 +1,35 @@
 #
 
-AM_CPPFLAGS = \
+bin_varnishtop_varnishtop_CPPFLAGS = \
 	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishtop \
 	-I$(top_builddir)/include
 
-bin_PROGRAMS = varnishtop
+bin_PROGRAMS += bin/varnishtop/varnishtop
 
-varnishtop_SOURCES = varnishtop.c \
-	varnishtop_options.h \
-	varnishtop_options.c \
-	$(top_srcdir)/lib/libvarnishtools/vut.c \
-	$(top_srcdir)/lib/libvarnish/vas.c \
-	$(top_srcdir)/lib/libvarnish/flopen.c \
-	$(top_srcdir)/lib/libvarnish/version.c \
-	$(top_srcdir)/lib/libvarnish/vpf.c \
-	$(top_srcdir)/lib/libvarnish/vtim.c \
-	$(top_srcdir)/lib/libvarnish/vsb.c
+bin_varnishtop_varnishtop_SOURCES = bin/varnishtop/varnishtop.c \
+	bin/varnishtop/varnishtop_options.h \
+	bin/varnishtop/varnishtop_options.c \
+	lib/libvarnishtools/vut.c \
+	lib/libvarnish/vas.c \
+	lib/libvarnish/flopen.c \
+	lib/libvarnish/version.c \
+	lib/libvarnish/vpf.c \
+	lib/libvarnish/vtim.c \
+	lib/libvarnish/vsb.c
 
-
-varnishtop_LDADD = \
+bin_varnishtop_varnishtop_LDADD = \
 	$(top_builddir)/lib/libvarnishcompat/libvarnishcompat.la \
 	$(top_builddir)/lib/libvarnishapi/libvarnishapi.la \
 	@CURSES_LIB@ ${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
 
-noinst_PROGRAMS = varnishtop_opt2rst
-varnishtop_opt2rst_SOURCES = \
-	varnishtop_options.h \
-	varnishtop_options.c \
-	$(top_srcdir)/lib/libvarnishtools/opt2rst.c
+noinst_PROGRAMS += bin/varnishtop/varnishtop_opt2rst
+bin_varnishtop_varnishtop_opt2rst_SOURCES = \
+	bin/varnishtop/varnishtop_options.h \
+	bin/varnishtop/varnishtop_options.c \
+	lib/libvarnishtools/opt2rst.c
+
+bin_varnishtop_varnishtop_opt2rst_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_srcdir)/bin/varnishtop \
+	-I$(top_builddir)/include
\ No newline at end of file
diff --git a/configure.ac b/configure.ac
index 48af690..7eb57b5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -16,7 +16,7 @@ AC_CANONICAL_SYSTEM
 AC_LANG(C)
 
 AM_MAINTAINER_MODE([disable])
-AM_INIT_AUTOMAKE([1.11 foreign color-tests parallel-tests])
+AM_INIT_AUTOMAKE([1.11 foreign color-tests parallel-tests subdir-objects])
 AM_SILENT_RULES([yes])
 AC_DISABLE_STATIC
 AC_PROG_LIBTOOL
@@ -623,7 +623,7 @@ if test "$enable_pcre_jit" = yes; then
 fi
 
 # Stupid automake needs this
-VTC_TESTS="$(cd $srcdir/bin/varnishtest && echo tests/*.vtc)"
+VTC_TESTS="$(cd ${srcdir} && echo bin/varnishtest/tests/*.vtc)"
 AC_SUBST(VTC_TESTS)
 
 # Make sure this include dir exists
@@ -632,32 +632,7 @@ AC_CONFIG_COMMANDS([mkdir], [$MKDIR_P doc/sphinx/include])
 # Generate output
 AC_CONFIG_FILES([
     Makefile
-    bin/Makefile
-    bin/varnishadm/Makefile
-    bin/varnishd/Makefile
-    bin/varnishlog/Makefile
-    bin/varnishstat/Makefile
-    bin/varnishtop/Makefile
-    bin/varnishhist/Makefile
-    bin/varnishtest/Makefile
-    bin/varnishncsa/Makefile
-    doc/Makefile
-    doc/graphviz/Makefile
-    doc/sphinx/Makefile
     doc/sphinx/conf.py
-    etc/Makefile
-    include/Makefile
-    lib/Makefile
-    lib/libvarnish/Makefile
-    lib/libvarnishapi/Makefile
-    lib/libvarnishtools/Makefile
-    lib/libvarnishcompat/Makefile
-    lib/libvcc/Makefile
-    lib/libvgz/Makefile
-    lib/libvmod_debug/Makefile
-    lib/libvmod_std/Makefile
-    lib/libvmod_directors/Makefile
-    man/Makefile
     varnishapi.pc
     varnishapi-uninstalled.pc
 ])
diff --git a/doc/Makefile.am b/doc/Makefile.am
index e420a99..1279135 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,10 +1,8 @@
 #
 #
-RST2ANY_FLAGS = --halt=2
+EXTRA_DIST += doc/changes.rst doc/changes.html
 
-EXTRA_DIST = changes.rst changes.html
-
-changes.html: changes.rst
+doc/changes.html: doc/changes.rst
 if HAVE_RST2HTML
 	${RST2HTML} ${RST2ANY_FLAGS} $? $@
 else
@@ -13,6 +11,3 @@ else
 	@echo "========================================"
 	@false
 endif
-
-# build graphviz before sphinx, so sphinx docs can use svg output
-SUBDIRS = graphviz sphinx
diff --git a/doc/graphviz/Makefile.am b/doc/graphviz/Makefile.am
index acbe4fe..fc5b685 100644
--- a/doc/graphviz/Makefile.am
+++ b/doc/graphviz/Makefile.am
@@ -2,38 +2,32 @@
 
 # for an out-of-tree build, sphinx needs the output in builddir
 # XXX is there a better way to do this?
+# .PHONY is required as VPATH will happily register the files in
+# buildi
 
-.PHONY: link_srcdir
-
-link_srcdir:
-	if test "x$(srcdir)" != "x$(builddir)" && \
-	   test ! -f $(builddir)/cache_http1_fsm.svg ; then \
-		d=`pwd`/$(builddir) ; \
-		cd $(srcdir) && find . -name \*.svg -type f | \
-		cpio -ldmp $${d} ; \
-	fi
-
-dist-hook:
-	$(MAKE) html
+dist: html
 
 # You can set these variables from the command line.
 # this is a4, letter is 8.5,11
 SIZE	      = 8.4,11.7
 
-EXTRA_DIST = $(srcdir)/*.dot
+EXTRA_DIST += \
+	doc/graphviz/cache_http1_fsm.dot \
+	doc/graphviz/cache_req_fsm.dot \
+	doc/graphviz/cache_fetch.dot
 
 if HAVE_DOT
 PDFS = \
-	cache_http1_fsm.pdf \
-	cache_req_fsm.pdf \
-	cache_fetch.pdf
+	doc/graphviz/cache_http1_fsm.pdf \
+	doc/graphviz/cache_req_fsm.pdf \
+	doc/graphviz/cache_fetch.pdf
 
 SVGS = \
-	cache_http1_fsm.svg \
-	cache_req_fsm.svg \
-	cache_fetch.svg
+	doc/graphviz/cache_http1_fsm.svg \
+	doc/graphviz/cache_req_fsm.svg \
+	doc/graphviz/cache_fetch.svg
 
-CLEANFILES = \
+CLEANFILES += \
 	$(PDFS)	\
 	$(SVGS)
 endif
@@ -46,7 +40,7 @@ if ! HAVE_DOT
 	@false
 endif
 
-html: $(SVGS) link_srcdir
+graphviz: $(SVGS)
 if ! HAVE_DOT
 	@echo ===================================================
 	@echo You need graphviz installed to generate html output
@@ -55,11 +49,14 @@ if ! HAVE_DOT
 endif
 
 # XXX does not fit onto a4 unless in landscape
-cache_fetch.pdf: cache_fetch.dot
+doc/graphviz/cache_fetch.pdf: doc/graphviz/cache_fetch.dot
+	mkdir -p $(top_builddir)/doc/graphviz
 	@DOT@ -Tpdf -Gsize=$(SIZE) -Grotate=90 $< >$@
 
 %.pdf: %.dot
+	mkdir -p $(top_builddir)/doc/graphviz
 	@DOT@ -Tpdf -Gsize=$(SIZE) $< >$@
 
 %.svg: %.dot
+	mkdir -p $(top_builddir)/doc/graphviz
 	@DOT@ -Tsvg $< >$@
diff --git a/doc/sphinx/Makefile.am b/doc/sphinx/Makefile.am
index 6d71c14..01114cb 100644
--- a/doc/sphinx/Makefile.am
+++ b/doc/sphinx/Makefile.am
@@ -5,12 +5,12 @@
 SPHINXOPTS    =
 SPHINXBUILD   = sphinx-build -W -q -N
 PAPER         = a4
-BUILDDIR      = build
+BUILDDIR      = $(builddir)/doc/sphinx/build
 
 # Internal variables.
 PAPEROPT_a4     = -D latex_paper_size=a4
 PAPEROPT_letter = -D latex_paper_size=letter
-ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(builddir)
+ALLSPHINXOPTS   = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) $(builddir)/doc/sphinx
 
 .PHONY: help clean html dirhtml pickle json htmlhelp qthelp latex changes linkcheck doctest
 
@@ -27,23 +27,18 @@ help:
 	@echo "  linkcheck to check all external links for integrity"
 	@echo "  doctest   to run all doctests embedded in the documentation (if enabled)"
 
-clean:
-	-rm -rf $(BUILDDIR)/*
+clean-local: sphinx-clean
 
 # use index.rst as an indicator if we have copied already
 .PHONY: link_srcdir
 link_srcdir:
 	if test "x$(srcdir)" != "x$(builddir)" && test ! -f index.rst ; then \
-		d=`pwd`/$(builddir) ; \
-		cd $(srcdir) && find . -type f | cpio -ldmp $${d} ; \
+		d=`pwd`/$(builddir)/doc/sphinx ; \
+		cd $(srcdir)/doc/sphinx/ && find . -type f | cpio -ldmp $${d} ; \
+		chmod -R +w $${d} ;\
 	fi
 
-# work around for make html called within doc/sphinx
-.PHONY: graphviz
-graphviz:
-	cd ../graphviz && $(MAKE) html
-
-sphinx_prereq: link_srcdir graphviz conf.py
+sphinx_prereq: link_srcdir graphviz doc/sphinx/conf.py
 
 html: sphinx_prereq
 	$(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
@@ -103,71 +98,100 @@ doctest: sphinx_prereq
 	@echo "Testing of doctests in the sources finished, look at the " \
 	      "results in $(BUILDDIR)/doctest/output.txt."
 
-EXTRA_DIST = \
-	conf.py \
-	index.rst \
-	include \
-	glossary \
-	installation \
-	phk \
-	tutorial \
-	users-guide \
-	whats-new
-
-dist-hook:
-	$(MAKE) html
+EXTRA_DIST += \
+	doc/sphinx/conf.py \
+	doc/sphinx/index.rst \
+	doc/sphinx/include \
+	doc/sphinx/glossary \
+	doc/sphinx/installation \
+	doc/sphinx/phk \
+	doc/sphinx/tutorial \
+	doc/sphinx/users-guide \
+	doc/sphinx/whats-new
+
+dist-hook: sphinx-dist
+.PHONY: sphinx-dist
+sphinx-dist:
 	rm -rf $(BUILDDIR)/doctrees
-	cp -r $(BUILDDIR)/html $(distdir)/../
+	cp -r $(BUILDDIR)/html $(distdir)/doc/html
 
-distclean-local:
+distclean-local: sphinx-clean
+sphinx-clean:
 	rm -rf $(BUILDDIR)
 
-include/params.rst: $(top_builddir)/bin/varnishd/varnishd
-	$(top_builddir)/bin/varnishd/varnishd -x dumprstparam > include/params.rst
-BUILT_SOURCES = include/params.rst
+doc/sphinx/include:
+	test -d $@ || mkdir -m0755 $@
+
+SPHINXFIRSTS = $(top_builddir)/lib/libvarnishapi/vsl-tags.rst
+
+$(top_builddir)/doc/sphinx/include/params.rst: $(top_builddir)/bin/varnishd/varnishd $(top_builddir)/doc/sphinx/include
+	$(top_builddir)/bin/varnishd/varnishd -x dumprstparam > $@
+SPHINXFIRSTS += $(top_builddir)/doc/sphinx/include/params.rst
 
 # XXX add varnishstat here when it's been _opt2rst'ed
 
-include/varnishncsa_options.rst: $(top_builddir)/bin/varnishncsa/varnishncsa_opt2rst
+$(top_builddir)/doc/sphinx/include/varnishncsa_options.rst: $(top_builddir)/bin/varnishncsa/varnishncsa_opt2rst
 	$(top_builddir)/bin/varnishncsa/varnishncsa_opt2rst options > $@
-include/varnishncsa_synopsis.rst: $(top_builddir)/bin/varnishncsa/varnishncsa_opt2rst
+$(top_builddir)/doc/sphinx/include/varnishncsa_synopsis.rst: $(top_builddir)/bin/varnishncsa/varnishncsa_opt2rst
 	$(top_builddir)/bin/varnishncsa/varnishncsa_opt2rst synopsis > $@
-BUILT_SOURCES += include/varnishncsa_options.rst \
-	include/varnishncsa_synopsis.rst
+SPHINXFIRSTS += $(top_builddir)/doc/sphinx/include/varnishncsa_options.rst \
+	$(top_builddir)/doc/sphinx/include/varnishncsa_synopsis.rst
 
-include/varnishlog_options.rst: $(top_builddir)/bin/varnishlog/varnishlog_opt2rst
+$(top_builddir)/doc/sphinx/include/varnishlog_options.rst: $(top_builddir)/bin/varnishlog/varnishlog_opt2rst
 	$(top_builddir)/bin/varnishlog/varnishlog_opt2rst options > $@
-include/varnishlog_synopsis.rst: $(top_builddir)/bin/varnishlog/varnishlog_opt2rst
+$(top_builddir)/doc/sphinx/include/varnishlog_synopsis.rst: $(top_builddir)/bin/varnishlog/varnishlog_opt2rst
 	$(top_builddir)/bin/varnishlog/varnishlog_opt2rst synopsis > $@
-BUILT_SOURCES += include/varnishlog_options.rst \
-	include/varnishlog_synopsis.rst
+SPHINXFIRSTS += $(top_builddir)/doc/sphinx/include/varnishlog_options.rst \
+	$(top_builddir)/doc/sphinx/include/varnishlog_synopsis.rst
 
-include/varnishtop_options.rst: $(top_builddir)/bin/varnishtop/varnishtop_opt2rst
+$(top_builddir)/doc/sphinx/include/varnishtop_options.rst: $(top_builddir)/bin/varnishtop/varnishtop_opt2rst
 	$(top_builddir)/bin/varnishtop/varnishtop_opt2rst options > $@
-include/varnishtop_synopsis.rst: $(top_builddir)/bin/varnishtop/varnishtop_opt2rst
+$(top_builddir)/doc/sphinx/include/varnishtop_synopsis.rst: $(top_builddir)/bin/varnishtop/varnishtop_opt2rst
 	$(top_builddir)/bin/varnishtop/varnishtop_opt2rst synopsis > $@
-BUILT_SOURCES += include/varnishtop_options.rst \
-	 include/varnishtop_synopsis.rst
+SPHINXFIRSTS += $(top_builddir)/doc/sphinx/include/varnishtop_options.rst \
+	 $(top_builddir)/doc/sphinx/include/varnishtop_synopsis.rst
 
-include/varnishhist_options.rst: $(top_builddir)/bin/varnishhist/varnishhist_opt2rst
+$(top_builddir)/doc/sphinx/include/varnishhist_options.rst: $(top_builddir)/bin/varnishhist/varnishhist_opt2rst
 	$(top_builddir)/bin/varnishhist/varnishhist_opt2rst options > $@
-include/varnishhist_synopsis.rst: $(top_builddir)/bin/varnishhist/varnishhist_opt2rst
+$(top_builddir)/doc/sphinx/include/varnishhist_synopsis.rst: $(top_builddir)/bin/varnishhist/varnishhist_opt2rst
 	$(top_builddir)/bin/varnishhist/varnishhist_opt2rst synopsis > $@
-BUILT_SOURCES += include/varnishhist_options.rst \
-	 include/varnishhist_synopsis.rst
-
-.PHONY: reference
-reference:
-	test -d $@ || mkdir $@
-BUILT_SOURCES += reference
-
-reference/vmod_std.generated.rst: reference $(top_builddir)/lib/libvmod_std/vmod_std.rst
-	cp $(top_builddir)/lib/libvmod_std/vmod_std.rst $@
-BUILT_SOURCES += reference/vmod_std.generated.rst
-
-reference/vmod_directors.generated.rst: reference $(top_builddir)/lib/libvmod_directors/vmod_directors.rst
-	cp $(top_builddir)/lib/libvmod_directors/vmod_directors.rst $@
-BUILT_SOURCES += reference/vmod_directors.generated.rst
-
-EXTRA_DIST += $(BUILT_SOURCES)
-MAINTAINERCLEANFILES = $(EXTRA_DIST)
+SPHINXFIRSTS += $(top_builddir)/doc/sphinx/include/varnishhist_options.rst \
+	 $(top_builddir)/doc/sphinx/include/varnishhist_synopsis.rst
+
+$(top_builddir)/doc/sphinx/reference/vmod_std.generated.rst: \
+		$(top_builddir)/lib/libvmod_std/vmod_std.rst
+	mkdir -p $(top_builddir)/doc/sphinx/reference
+	cp -f $(top_builddir)/lib/libvmod_std/vmod_std.rst $@
+SPHINXFIRSTS += $(top_builddir)/doc/sphinx/reference/vmod_std.generated.rst
+
+$(top_builddir)/doc/sphinx/reference/vmod_directors.generated.rst: \
+		$(top_builddir)/lib/libvmod_directors/vmod_directors.rst 
+	mkdir -p $(top_builddir)/doc/sphinx/reference
+	cp -f $(top_builddir)/lib/libvmod_directors/vmod_directors.rst $@
+SPHINXFIRSTS += $(top_builddir)/doc/sphinx/reference/vmod_directors.generated.rst
+
+sphinx_prereq: $(SPHINXFIRSTS)
+
+$(SPHINXFIRSTS): doc/sphinx/include
+
+EXTRA_DIST += $(SPHINXFIRSTS) \
+			  doc/sphinx/reference/directors.rst \
+			  doc/sphinx/reference/index.rst \
+			  doc/sphinx/reference/states.rst \
+			  doc/sphinx/reference/varnishadm.rst \
+			  doc/sphinx/reference/varnish-cli.rst \
+			  doc/sphinx/reference/varnishd.rst \
+			  doc/sphinx/reference/varnishhist.rst \
+			  doc/sphinx/reference/varnishlog.rst \
+			  doc/sphinx/reference/varnishncsa.rst \
+			  doc/sphinx/reference/varnishstat.rst \
+			  doc/sphinx/reference/varnishtest.rst \
+			  doc/sphinx/reference/varnishtop.rst \
+			  doc/sphinx/reference/vcl.rst \
+			  $(top_builddir)/doc/sphinx/reference/vmod_directors.generated.rst \
+			  doc/sphinx/reference/vmod.rst \
+			  $(top_builddir)/doc/sphinx/reference/vmod_std.generated.rst \
+			  doc/sphinx/reference/vsl-query.rst \
+			  doc/sphinx/reference/vsl.rst \
+			  doc/sphinx/reference/vsm.rst
+MAINTAINERCLEANFILES += $(SPHINXFIRSTS)
diff --git a/etc/Makefile.am b/etc/Makefile.am
index d02d710..5efeec6 100644
--- a/etc/Makefile.am
+++ b/etc/Makefile.am
@@ -1,12 +1,12 @@
 #
 
-DISTCLEANFILES = builtin.vcl
+DISTCLEANFILES += etc/builtin.vcl
 
-dist_doc_DATA = builtin.vcl \
-		example.vcl
+dist_doc_DATA = etc/builtin.vcl \
+		etc/example.vcl
 
-builtin.vcl:	$(top_srcdir)/bin/varnishd/builtin.vcl
+etc/builtin.vcl:	bin/varnishd/builtin.vcl
 	( printf "This is the VCL configuration Varnish will automatically append to your VCL\nfile during compilation/loading. See the vcl(7) man page for details on syntax\nand semantics.\n\
 New users is recommended to use the example.vcl file as a starting point.\n\n";\
-	sed -n '/vcl_recv/,$$p' $(top_srcdir)/bin/varnishd/builtin.vcl ) | \
-	sed 's/^\(.*\)$$/# \1/' > builtin.vcl
+	sed -n '/vcl_recv/,$$p' bin/varnishd/builtin.vcl ) | \
+	sed 's/^\(.*\)$$/# \1/' > etc/builtin.vcl
diff --git a/include/Makefile.am b/include/Makefile.am
index 7088579..c615ede 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -1,109 +1,141 @@
 #
 
 # API headers
-nobase_pkginclude_HEADERS = \
-	tbl/acct_fields_req.h \
-	tbl/acct_fields_bereq.h \
-	tbl/backend_poll.h \
-	tbl/ban_vars.h \
-	tbl/bo_flags.h \
-	tbl/body_status.h \
-	tbl/debug_bits.h \
-	tbl/feature_bits.h \
-	tbl/http_headers.h \
-	tbl/http_response.h \
-	tbl/locks.h \
-	tbl/obj_attr.h \
-	tbl/params.h \
-	tbl/req_body.h \
-	tbl/req_flags.h \
-	tbl/sess_attr.h \
-	tbl/sess_close.h \
-	tbl/steps.h \
-	tbl/symbol_kind.h \
-	tbl/vcc_types.h \
-	tbl/vcl_returns.h \
-	tbl/vrt_stv_var.h \
-	tbl/vsc_types.h \
-	tbl/vsc_all.h \
-	tbl/vsc_fields.h \
-	tbl/vsc_levels.h \
-	tbl/vsc_f_main.h \
-	tbl/vsl_tags.h \
-	tbl/vsl_tags_http.h \
-	vapi/vsm.h \
-	vapi/vsm_int.h \
-	vapi/vsc.h \
-	vapi/vsc_int.h \
-	vapi/vsl.h \
-	vapi/vsl_int.h \
-	vapi/voptget.h \
-	vapi/vapi_options.h \
-	vcli.h
+
+public_include_headers = \
+	include/tbl/acct_fields_req.h \
+	include/tbl/acct_fields_bereq.h \
+	include/tbl/backend_poll.h \
+	include/tbl/ban_vars.h \
+	include/tbl/bo_flags.h \
+	include/tbl/body_status.h \
+	include/tbl/debug_bits.h \
+	include/tbl/feature_bits.h \
+	include/tbl/http_headers.h \
+	include/tbl/http_response.h \
+	include/tbl/locks.h \
+	include/tbl/obj_attr.h \
+	include/tbl/params.h \
+	include/tbl/req_body.h \
+	include/tbl/req_flags.h \
+	include/tbl/sess_attr.h \
+	include/tbl/sess_close.h \
+	include/tbl/steps.h \
+	include/tbl/symbol_kind.h \
+	include/tbl/vcc_types.h \
+	include/tbl/vcl_returns.h \
+	include/tbl/vrt_stv_var.h \
+	include/tbl/vsc_types.h \
+	include/tbl/vsc_all.h \
+	include/tbl/vsc_fields.h \
+	include/tbl/vsc_levels.h \
+	include/tbl/vsc_f_main.h \
+	include/tbl/vsl_tags.h \
+	include/tbl/vsl_tags_http.h \
+	include/vapi/vsm.h \
+	include/vapi/vsm_int.h \
+	include/vapi/vsc.h \
+	include/vapi/vsc_int.h \
+	include/vapi/vsl.h \
+	include/vapi/vsl_int.h \
+	include/vapi/voptget.h \
+	include/vapi/vapi_options.h \
+	include/vcli.h
+
+# This saddens me, but nobase will strip the path completely
+# and we want to keep everything after 'include/'
+# XXX one mkdir per file is wasteful, but we won't risk
+# forgetting subdirs
+install-data-local: install-public-include-headers
+install-public-include-headers:
+	for i in $(public_include_headers); do \
+		h_dir="$$(dirname $(DESTDIR)$(includedir)/varnish`echo $$i | sed s@include@@`)"; \
+		$(install_sh) -d -m 0755 $$h_dir; \
+		$(INSTALL_HEADER) $(srcdir)/$$i $$h_dir; \
+	done
+
+#		chmod +w $$(dirname $(includedir)/`echo $$i |
+#			sed s@include@varnish@`);
+uninstall-hook: uninstall-public-include-headers 
+uninstall-public-include-headers :
+	for i in $(public_include_headers); do \
+		rm -f $(DESTDIR)$(includedir)/`echo $$i | sed s@include@varnish@`; \
+	done
+	
+.PHONY : install-public-include-headers uninstall-public-include-headers
+EXTRA_DIST += $(public_include_headers)
 
 # Headers for use with vmods
-nobase_pkginclude_HEADERS += \
-	miniobj.h \
-	vas.h \
-	vav.h \
-	vbm.h \
-	vcl.h \
-	vcs.h \
-	vmod_abi.h \
-	vqueue.h \
-	vre.h \
-	vdef.h \
-	vrt.h \
-	vrt_obj.h \
-	vsa.h \
-	vsb.h \
-	vsha256.h \
-	vtcp.h \
-	vtim.h
+pkginclude_HEADERS += \
+	include/miniobj.h \
+	include/vas.h \
+	include/vav.h \
+	include/vbm.h \
+	include/vcl.h \
+	include/vcs.h \
+	include/vmod_abi.h \
+	include/vqueue.h \
+	include/vre.h \
+	include/vdef.h \
+	include/vrt.h \
+	include/vrt_obj.h \
+	include/vsa.h \
+	include/vsb.h \
+	include/vsha256.h \
+	include/vtcp.h \
+	include/vtim.h
 
 # Private headers
-nobase_noinst_HEADERS = \
-	binary_heap.h \
-	compat/daemon.h \
-	compat/execinfo.h \
-	flopen.h \
-	libvcc.h \
-	vcli_common.h \
-	vcli_priv.h \
-	vcli_serve.h \
-	vcs_version.h \
-	vct.h \
-	vcurses.h \
-	vend.h \
-	vev.h \
-	vfil.h \
-	vin.h \
-	vlu.h \
-	vmb.h \
-	vnum.h \
-	vpf.h \
-	vrnd.h \
-	vsl_priv.h \
-	vsm_priv.h \
-	vsub.h \
-	vss.h \
-	vtcp.h \
-	vtree.h \
-	vut.h \
-	vut_options.h
+nobase_noinst_HEADERS += \
+	include/binary_heap.h \
+	include/compat/daemon.h \
+	include/compat/execinfo.h \
+	include/flopen.h \
+	include/libvcc.h \
+	include/vcli_common.h \
+	include/vcli_priv.h \
+	include/vcli_serve.h \
+	include/vcs_version.h \
+	include/vct.h \
+	include/vcurses.h \
+	include/vend.h \
+	include/vev.h \
+	include/vfil.h \
+	include/vin.h \
+	include/vlu.h \
+	include/vmb.h \
+	include/vnum.h \
+	include/vpf.h \
+	include/vrnd.h \
+	include/vsl_priv.h \
+	include/vsm_priv.h \
+	include/vsub.h \
+	include/vss.h \
+	include/vtcp.h \
+	include/vtree.h \
+	include/vut.h \
+	include/vut_options.h
+
+include/tbl/vrt_stv_var.h \
+	include/tbl/vcl_returns.h \
+	include/tbl/vcc_types.h \
+	include/vrt_obj.h \
+	lib/libvcc/vcc_fixed_token.c \
+	lib/libvcc/vcc_obj.c \
+	lib/libvcc/vcc_token_defs.h: \
+		include/vcl.h
+include/vcl.h: lib/libvcc/generate.py include/vrt.h 
+	mkdir -p include/tbl
+	@PYTHON@ $(top_srcdir)/lib/libvcc/generate.py . .
 
-tbl/vrt_stv_var.h tbl/vcl_returns.h tbl/vcc_types.h vrt_obj.h: vcl.h
-vcl.h: $(top_srcdir)/lib/libvcc/generate.py $(top_srcdir)/include/vrt.h
-	mkdir -p tbl
-	@PYTHON@ $(top_srcdir)/lib/libvcc/generate.py $(top_srcdir) $(top_builddir)
+MAINTAINERCLEANFILES += $(top_builddir)/include/vcs_version.h
 
-BUILT_SOURCES = vcs_version.h vmod_abi.h
-MAINTAINERCLEANFILES = vcs_version.h 
-vcs_version.h: FORCE
+include/vcs_version.h:
+	@mkdir -p include
 	@if [ -d "$(top_srcdir)/.git" ]; then \
 		V="$$(git show -s --pretty=format:%h)" \
 		B="$$(git rev-parse --abbrev-ref HEAD)" \
-		H="$$(head -n 1 vcs_version.h 2>/dev/null || true)"; \
+		H="$$(head -n 1 include/vcs_version.h 2>/dev/null || true)"; \
 		if [ "/* $$V */" != "$$H" ]; then \
 		( \
 		  echo "/* $$V */" ;\
@@ -117,16 +149,16 @@ vcs_version.h: FORCE
 		  echo '' ;\
 		  echo "#define VCS_Version \"$$V\"" ; \
 		  echo "#define VCS_Branch \"$$B\"" \
-		) > vcs_version.h ; \
+		) > include/vcs_version.h ; \
 		fi \
 	else \
-		if [ ! -f vcs_version.h ]; then \
+		if [ ! -f include/vcs_version.h ]; then \
 		( \
 		  echo "/* NOGIT */" ; \
 		  echo '/* No git commit ID available, see include/Makefile.am for explanation */' ; \
 		  echo '#define VCS_Version "NOGIT"' ; \
 		  echo '#define VCS_Branch "NOGIT"' \
-		) >  vcs_version.h ; \
+		) >  include/vcs_version.h ; \
 		fi \
 	fi
 FORCE:
@@ -139,16 +171,16 @@ FORCE:
 # The way to fix this is to either build Varnish from a tarball made
 # with `make dist` or a git checkout.
 
-vmod_abi.h: vcs_version.h
-	@GITID=$$(sed 's/[^0-9a-f]//g;q' vcs_version.h) ; \
+include/vmod_abi.h: include/vcs_version.h
+	@GITID=$$(sed 's/[^0-9a-f]//g;q' include/vcs_version.h) ; \
 	if [ -z "$$GITID" ]; then \
 		echo "warning: weak VMOD ABI checking, see include/Makefile.am" ; \
 	fi ; \
-	echo "#define VMOD_ABI_Version \"@PACKAGE_STRING@ $$GITID\"" > vmod_abi.h
+	echo "#define VMOD_ABI_Version \"@PACKAGE_STRING@ $$GITID\"" > $(top_builddir)/include/vmod_abi.h
 
-CLEANFILES = \
-	tbl/vcl_returns.h \
-	tbl/vrt_stv_var.h \
-	vcl.h \
-	vrt_obj.h \
-	vmod_abi.h
+CLEANFILES += \
+	include/tbl/vcl_returns.h \
+	include/tbl/vrt_stv_var.h \
+	include/vcl.h \
+	include/vrt_obj.h \
+	include/vmod_abi.h
diff --git a/lib/Makefile.am b/lib/Makefile.am
deleted file mode 100644
index c0c0e60..0000000
--- a/lib/Makefile.am
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-
-SUBDIRS = \
-	libvarnishcompat \
-	libvarnish \
-	libvarnishapi \
-	libvarnishtools \
-	libvcc \
-	libvgz \
-	libvmod_debug \
-	libvmod_std \
-	libvmod_directors
-
-DIST_SUBDIRS = 	\
-	libvarnishcompat \
-	libvarnish \
-	libvarnishapi \
-	libvarnishtools \
-	libvcc \
-	libvgz \
-	libvmod_debug \
-	libvmod_std \
-	libvmod_directors
diff --git a/lib/libvarnish/Makefile.am b/lib/libvarnish/Makefile.am
index b592cff..f24b894 100644
--- a/lib/libvarnish/Makefile.am
+++ b/lib/libvarnish/Makefile.am
@@ -1,53 +1,56 @@
-AM_CPPFLAGS = \
+lib_libvarnish_libvarnish_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include \
 	@PCRE_CFLAGS@
 
-AM_LDFLAGS  = $(AM_LT_LDFLAGS)
-
-pkglib_LTLIBRARIES = libvarnish.la
-
-libvarnish_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
-
-libvarnish_la_SOURCES = \
-	vav.c \
-	vas.c \
-	binary_heap.c \
-	vsub.c \
-	cli_auth.c \
-	cli_common.c \
-	cli_serve.c \
-	flopen.c \
-	vnum.c \
-	vtim.c \
-	vtcp.c \
-	vct.c \
-	version.c \
-	vev.c \
-	vfil.c \
-	vin.c \
-	vlu.c \
-	vmb.c \
-	vpf.c \
-	vre.c \
-	vrnd.c \
-	vsa.c \
-	vsb.c \
-	vsha256.c \
-	vss.c
-
-libvarnish_la_CFLAGS = -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"'
-libvarnish_la_LIBADD = ${RT_LIBS} ${NET_LIBS} ${LIBM} @PCRE_LIBS@
+pkglib_LTLIBRARIES += lib/libvarnish/libvarnish.la
+
+lib_libvarnish_libvarnish_la_LDFLAGS = $(AM_LT_LDFLAGS) -avoid-version
+
+lib_libvarnish_libvarnish_la_SOURCES = \
+	lib/libvarnish/vav.c \
+	lib/libvarnish/vas.c \
+	lib/libvarnish/binary_heap.c \
+	lib/libvarnish/vsub.c \
+	lib/libvarnish/cli_auth.c \
+	lib/libvarnish/cli_common.c \
+	lib/libvarnish/cli_serve.c \
+	lib/libvarnish/flopen.c \
+	lib/libvarnish/vnum.c \
+	lib/libvarnish/vtim.c \
+	lib/libvarnish/vtcp.c \
+	lib/libvarnish/vct.c \
+	lib/libvarnish/version.c \
+	lib/libvarnish/vev.c \
+	lib/libvarnish/vfil.c \
+	lib/libvarnish/vin.c \
+	lib/libvarnish/vlu.c \
+	lib/libvarnish/vmb.c \
+	lib/libvarnish/vpf.c \
+	lib/libvarnish/vre.c \
+	lib/libvarnish/vrnd.c \
+	lib/libvarnish/vsa.c \
+	lib/libvarnish/vsb.c \
+	lib/libvarnish/vsha256.c \
+	lib/libvarnish/vss.c
+
+lib_libvarnish_libvarnish_la_CFLAGS = -DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"'
+lib_libvarnish_libvarnish_la_LIBADD = ${RT_LIBS} ${NET_LIBS} ${LIBM} @PCRE_LIBS@
 
 if ENABLE_TESTS
-TESTS = vnum_c_test
+TESTS += lib/libvarnish/vnum_c_test
 
-noinst_PROGRAMS = ${TESTS}
+noinst_PROGRAMS += lib/libvarnish/vnum_c_test
 
-vnum_c_test_SOURCES = vnum.c vas.c
-vnum_c_test_CFLAGS = -DNUM_C_TEST -include config.h
-vnum_c_test_LDADD = ${LIBM}
+lib_libvarnish_vnum_c_test_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
+	@PCRE_CFLAGS@
+
+lib_libvarnish_vnum_c_test_SOURCES = lib/libvarnish/vnum.c lib/libvarnish/vas.c
+lib_libvarnish_vnum_c_test_CFLAGS = -DNUM_C_TEST -include config.h
+lib_libvarnish_vnum_c_test_LDADD = ${LIBM}
 
-test: ${TESTS}
+test: lib/libvarnish/vnum_c_test
 	@for test in ${TESTS} ; do ./$${test} ; done
 endif
diff --git a/lib/libvarnishapi/Makefile.am b/lib/libvarnishapi/Makefile.am
index 68a89bd..5e00829 100644
--- a/lib/libvarnishapi/Makefile.am
+++ b/lib/libvarnishapi/Makefile.am
@@ -1,105 +1,113 @@
 #
 
-AM_LDFLAGS  = $(AM_LT_LDFLAGS)
-
-AM_CPPFLAGS = \
+lib_libvarnishapi_libvarnishapi_la_CPPFLAGS = \
+	-I$(top_srcdir)/lib/libvarnishapi \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include \
 	@PCRE_CFLAGS@
 
-lib_LTLIBRARIES = libvarnishapi.la
+lib_LTLIBRARIES += lib/libvarnishapi/libvarnishapi.la
 
-libvarnishapi_la_LDFLAGS = $(AM_LDFLAGS) -version-info 1:0:0
+lib_libvarnishapi_libvarnishapi_la_LDFLAGS = $(AM_LT_LDFLAGS) -version-info 1:0:0
 
-libvarnishapi_la_SOURCES = \
-	vsm_api.h \
-	vsl_api.h \
-	vxp.h \
-	vxp_tokens.h \
+lib_libvarnishapi_libvarnishapi_la_SOURCES = \
+	lib/libvarnishapi/vsm_api.h \
+	lib/libvarnishapi/vsl_api.h \
+	lib/libvarnishapi/vxp.h \
+	lib/libvarnishapi/vxp_tokens.h \
+	\
+	lib/libvarnish/vas.c \
+	lib/libvarnish/vav.c \
+	include/vcs_version.h \
+	lib/libvarnish/version.c \
+	lib/libvarnish/cli_common.c \
+	lib/libvarnish/cli_auth.c \
+	lib/libvarnish/vin.c \
+	lib/libvarnish/vmb.c \
+	lib/libvarnish/vre.c \
+	lib/libvarnish/vsb.c \
+	lib/libvarnish/vtim.c \
+	lib/libvarnish/vnum.c \
+	lib/libvarnish/vsha256.c \
 	\
-	../libvarnish/vas.c \
-	../libvarnish/vav.c \
-	../../include/vcs_version.h \
-	../libvarnish/version.c \
-	../libvarnish/cli_common.c \
-	../libvarnish/cli_auth.c \
-	../libvarnish/vin.c \
-	../libvarnish/vmb.c \
-	../libvarnish/vre.c \
-	../libvarnish/vsb.c \
-	../libvarnish/vtim.c \
-	../libvarnish/vnum.c \
-	../libvarnish/vsha256.c \
-	vsm.c \
-	vsl_arg.c \
-	vsl_cursor.c \
-	vsl_dispatch.c \
-	vsl_query.c \
-	vsl.c \
-	vsc.c \
-	vxp.c \
-	vxp_parse.c \
-	vxp_lexer.c \
-	vxp_fixed_token.c \
-	libvarnishapi.map
-
-libvarnishapi_la_CFLAGS = \
+	lib/libvarnishapi/vxp_fixed_token.c \
+	lib/libvarnishapi/vsm.c \
+	lib/libvarnishapi/vsl_arg.c \
+	lib/libvarnishapi/vsl_cursor.c \
+	lib/libvarnishapi/vsl_dispatch.c \
+	lib/libvarnishapi/vsl_query.c \
+	lib/libvarnishapi/vsl.c \
+	lib/libvarnishapi/vsc.c \
+	lib/libvarnishapi/vxp.c \
+	lib/libvarnishapi/vxp_parse.c \
+	lib/libvarnishapi/vxp_lexer.c \
+	lib/libvarnishapi/libvarnishapi.map
+
+lib/libvarnish/lib_libvarnish_libvarnish_la-version.lo FORCE: include/vcs_version.h
+
+lib_libvarnishapi_libvarnishapi_la_CFLAGS = \
 	-DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"'
 
-libvarnishapi_la_LIBADD = @PCRE_LIBS@ @RT_LIBS@
+lib_libvarnishapi_libvarnishapi_la_LIBADD = @PCRE_LIBS@ @RT_LIBS@
 
 if HAVE_LD_VERSION_SCRIPT
-libvarnishapi_la_LDFLAGS += -Wl,--version-script=$(srcdir)/libvarnishapi.map
+lib_libvarnishapi_libvarnishapi_la_LDFLAGS += -Wl,--version-script=$(top_srcdir)/lib/libvarnishapi/libvarnishapi.map
 else
-libvarnishapi_la_LDFLAGS += -export-symbols-regex '^V'
+lib_libvarnishapi_libvarnishapi_la_LDFLAGS += -export-symbols-regex '^V'
 endif
 
-EXTRA_DIST = \
-	generate.py \
-	vsl-tags.rst
+EXTRA_DIST += \
+	lib/libvarnishapi/generate.py \
+	lib/libvarnishapi/vsl-tags.rst
 
-BUILT_SOURCES = \
-	vxp_fixed_token.c \
-	vxp_tokens.h \
-	vsl-tags.rst
+#BUILT_SOURCES += \
+#	lib/libvarnishapi/vxp_fixed_token.c \
+#	lib/libvarnishapi/vxp_tokens.h
 
-CLEANFILES = \
-	$(builddir)/vxp_fixed_token.c \
-	$(builddir)/vxp_tokens.h
+CLEANFILES += \
+	$(top_builddir)/lib/libvarnishapi/vxp_fixed_token.c \
+	$(top_builddir)/lib/libvarnishapi/vxp_tokens.h
 
-MAINTAINERCLEANFILES = \
-	vsl-tags.rst
+MAINTAINERCLEANFILES += \
+	lib/libvarnishapi/vsl-tags.rst
 
-noinst_PROGRAMS = vsl2rst
+noinst_PROGRAMS += lib/libvarnishapi/vsl2rst
 
-vsl2rst_SOURCES = \
-	vsl2rst.c \
+lib_libvarnishapi_vsl2rst_CPPFLAGS = \
+	-I$(top_srcdir)/include \
+	-I$(top_builddir)/include \
+	@PCRE_CFLAGS@
+
+lib_libvarnishapi_vsl2rst_SOURCES = \
+	lib/libvarnishapi/vsl2rst.c \
 	$(top_srcdir)/include/tbl/vsl_tags.h \
 	$(top_srcdir)/include/tbl/vsl_tags_http.h
 
-vsl-tags.rst: vsl2rst
-	./vsl2rst > $@
+$(top_builddir)/lib/libvarnishapi/vsl-tags.rst: lib/libvarnishapi/vsl2rst
+	lib/libvarnishapi/vsl2rst > lib/libvarnishapi/vsl-tags.rst
+
+lib/libvarnishapi/vxp_fixed_token.c : lib/libvarnishapi/vxp_tokens.h
 
-vxp_fixed_token.c vxp_tokens.h: \
-	$(srcdir)/generate.py
-	@PYTHON@ $(srcdir)/generate.py $(srcdir) $(top_builddir)
+lib/libvarnishapi/vxp_tokens.h: \
+		lib/libvarnishapi/generate.py
+	@PYTHON@ $(top_srcdir)/lib/libvarnishapi/generate.py lib/libvarnishapi/ .
 
-EXTRA_PROGRAMS = vxp_test vsl_glob_test
+EXTRA_PROGRAMS = lib/libvarnishapi/vxp_test lib/libvarnishapi/vsl_glob_test
 
-vxp_test_LDADD = @PCRE_LIBS@ \
+lib_libvarnishapi_vxp_test_LDADD = @PCRE_LIBS@ \
 	${RT_LIBS} ${LIBM} ${PTHREAD_LIBS}
 
-vxp_test_CFLAGS = \
+lib_libvarnishapi_vxp_test_CFLAGS = \
 	-DVARNISH_STATE_DIR='"${VARNISH_STATE_DIR}"' \
 	-DVXP_DEBUG
 
-vxp_test_SOURCES = \
+lib_libvarnishapi_vxp_test_SOURCES = \
 	$(libvarnishapi_la_SOURCES) \
-	vxp_test.c
+	lib/libvarnishapi/vxp_test.c
 
-vsl_glob_test_SOURCES = \
-	vsl_glob_test.c
+lib_libvarnishapi_vsl_glob_test_SOURCES = \
+	lib/libvarnishapi/vsl_glob_test.c
 
-vsl_glob_test_LDADD = @PCRE_LIBS@ ${RT_LIBS} ${LIBM} libvarnishapi.la
+lib_libvarnishapi_vsl_glob_test_LDADD = @PCRE_LIBS@ ${RT_LIBS} ${LIBM} libvarnishapi.la
 
-vsl_glob_test_CFLAGS = -I$(top_srcdir)/include
+lib_libvarnishapi_vsl_glob_test_CFLAGS = -I$(top_srcdir)/include
diff --git a/lib/libvarnishcompat/Makefile.am b/lib/libvarnishcompat/Makefile.am
index 78683c0..120e955 100644
--- a/lib/libvarnishcompat/Makefile.am
+++ b/lib/libvarnishcompat/Makefile.am
@@ -1,15 +1,13 @@
 #
 
-AM_CPPFLAGS = \
+lib_libvarnishcompat_libvarnishcompat_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include
 
-AM_LDFLAGS  = $(AM_LT_LDFLAGS)
+pkglib_LTLIBRARIES += lib/libvarnishcompat/libvarnishcompat.la
 
-pkglib_LTLIBRARIES = libvarnishcompat.la
+lib_libvarnishcompat_libvarnishcompat_la_LDFLAGS = $(AM_LT_LDFLAGS) -avoid-version
 
-libvarnishcompat_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
-
-libvarnishcompat_la_SOURCES = \
-	daemon.c \
-	execinfo.c
+lib_libvarnishcompat_libvarnishcompat_la_SOURCES = \
+	lib/libvarnishcompat/daemon.c \
+	lib/libvarnishcompat/execinfo.c
diff --git a/lib/libvarnishtools/Makefile.am b/lib/libvarnishtools/Makefile.am
index 1a14212..910b6ff 100644
--- a/lib/libvarnishtools/Makefile.am
+++ b/lib/libvarnishtools/Makefile.am
@@ -1,5 +1,5 @@
 #
 
-EXTRA_DIST = \
-	vut.c \
-	opt2rst.c
+EXTRA_DIST += \
+	lib/libvarnishtools/vut.c \
+	lib/libvarnishtools/opt2rst.c
diff --git a/lib/libvcc/Makefile.am b/lib/libvcc/Makefile.am
index b5a6574..d49d55a 100644
--- a/lib/libvcc/Makefile.am
+++ b/lib/libvcc/Makefile.am
@@ -1,45 +1,46 @@
 #
 
-AM_LDFLAGS  = $(AM_LT_LDFLAGS)
-
-AM_CPPFLAGS = \
+lib_libvcc_libvcc_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include
 
-pkglib_LTLIBRARIES = libvcc.la
+pkglib_LTLIBRARIES += lib/libvcc/libvcc.la
 
-libvcc_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
+lib_libvcc_libvcc_la_LDFLAGS = $(AM__LT_LDFLAGS) -avoid-version
 
-libvcc_la_SOURCES = \
-	vcc_compile.h \
-	vcc_token_defs.h \
+lib_libvcc_libvcc_la_SOURCES = \
+	lib/libvcc/vcc_compile.h \
+	lib/libvcc/vcc_token_defs.h \
 	\
-	vcc_acl.c \
-	vcc_action.c \
-	vcc_backend.c \
-	vcc_backend_util.c \
-	vcc_compile.c \
-	vcc_expr.c \
-	vcc_parse.c \
-	vcc_fixed_token.c \
-	vcc_obj.c \
-	vcc_storage.c \
-	vcc_utils.c \
-	vcc_symb.c \
-	vcc_token.c \
-	vcc_var.c \
-	vcc_vmod.c \
-	vcc_xref.c
-
-EXTRA_DIST = \
-	generate.py
-
-dist_pkgdata_SCRIPTS = \
-	vmodtool.py
-
-vcc_obj.c vcc_fixed_token.c vcc_token_defs.h: \
-	$(top_builddir)/include/vcl.h
-
-CLEANFILES = $(builddir)/vcc_token_defs.h \
-	$(builddir)/vcc_fixed_token.c \
-	$(builddir)/vcc_obj.c
+	lib/libvcc/vcc_acl.c \
+	lib/libvcc/vcc_action.c \
+	lib/libvcc/vcc_backend.c \
+	lib/libvcc/vcc_backend_util.c \
+	lib/libvcc/vcc_compile.c \
+	lib/libvcc/vcc_expr.c \
+	lib/libvcc/vcc_parse.c \
+	lib/libvcc/vcc_fixed_token.c \
+	lib/libvcc/vcc_obj.c \
+	lib/libvcc/vcc_storage.c \
+	lib/libvcc/vcc_utils.c \
+	lib/libvcc/vcc_symb.c \
+	lib/libvcc/vcc_token.c \
+	lib/libvcc/vcc_var.c \
+	lib/libvcc/vcc_vmod.c \
+	lib/libvcc/vcc_xref.c
+
+EXTRA_DIST += \
+	lib/libvcc/generate.py
+
+dist_pkgdata_SCRIPTS += \
+	lib/libvcc/vmodtool.py
+
+lib/libvcc/lib_libvcc_libvcc_la-vcc_vmod.lo FORCE: include/vmod_abi.h include/vcl.h
+
+lib/libvcc/lib_libvcc_libvcc_la-vcc_obj.$(OBJEXT) \
+	lib/libvcc/lib_libvcc_libvcc_la-vcc_fixed_token.$(OBJEXT) \
+	lib/libvcc/lib_libvcc_libvcc_la-vcc_token_defs.$(OBJEXT) : include/vcl.h
+
+CLEANFILES += $(builddir)/lib/libvcc/vcc_token_defs.h \
+	$(builddir)/lib/libvcc/vcc_fixed_token.c \
+	$(builddir)/lib/libvcc/vcc_obj.c
diff --git a/lib/libvgz/Makefile.am b/lib/libvgz/Makefile.am
index d9c0dae..be7b9b2 100644
--- a/lib/libvgz/Makefile.am
+++ b/lib/libvgz/Makefile.am
@@ -1,31 +1,31 @@
 #
-AM_LDFLAGS  = $(AM_LT_LDFLAGS)
+pkglib_LTLIBRARIES += lib/libvgz/libvgz.la
 
-pkglib_LTLIBRARIES = libvgz.la
+lib_libvgz_libvgz_la_LDFLAGS = $(AM__LTLDFLAGS) -avoid-version
+lib_libvgz_libvgz_la_CFLAGS = -D_LARGEFILE64_SOURCE=1 -DZLIB_CONST $(libvgz_extra_cflags)
 
-libvgz_la_LDFLAGS = $(AM_LDFLAGS) -avoid-version
-libvgz_la_CFLAGS = -D_LARGEFILE64_SOURCE=1 -DZLIB_CONST $(libvgz_extra_cflags)
+lib_libvgz_libvgz_la_SOURCES = \
+	lib/libvgz/adler32.c \
+	lib/libvgz/compress.c \
+	lib/libvgz/crc32.c \
+	lib/libvgz/crc32.h \
+	lib/libvgz/deflate.c \
+	lib/libvgz/deflate.h \
+	lib/libvgz/gzguts.h \
+	lib/libvgz/infback.c \
+	lib/libvgz/inffast.c \
+	lib/libvgz/inffast.h \
+	lib/libvgz/inffixed.h \
+	lib/libvgz/inflate.c \
+	lib/libvgz/inflate.h \
+	lib/libvgz/inftrees.c \
+	lib/libvgz/inftrees.h \
+	lib/libvgz/trees.c \
+	lib/libvgz/trees.h \
+	lib/libvgz/uncompr.c \
+	lib/libvgz/zconf.h \
+	lib/libvgz/vgz.h \
+	lib/libvgz/zutil.c \
+	lib/libvgz/zutil.h
 
-libvgz_la_SOURCES = \
-	adler32.c \
-	compress.c \
-	crc32.c \
-	crc32.h \
-	deflate.c \
-	deflate.h \
-	gzguts.h \
-	infback.c \
-	inffast.c \
-	inffast.h \
-	inffixed.h \
-	inflate.c \
-	inflate.h \
-	inftrees.c \
-	inftrees.h \
-	trees.c \
-	trees.h \
-	uncompr.c \
-	zconf.h \
-	vgz.h \
-	zutil.c \
-	zutil.h
+EXTRA_DIST += lib/libvgz/README
diff --git a/lib/libvmod_debug/Makefile.am b/lib/libvmod_debug/Makefile.am
index 9115713..1c8d02a 100644
--- a/lib/libvmod_debug/Makefile.am
+++ b/lib/libvmod_debug/Makefile.am
@@ -1,37 +1,38 @@
 #
-AM_LDFLAGS  = $(AM_LT_LDFLAGS)
 
-AM_CPPFLAGS = \
+
+lib_libvmod_debug_libvmod_debug_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_srcdir)/bin/varnishd \
-	-I$(top_builddir)/include
+	-I$(top_builddir)/include \
+	-I$(top_builddir)/lib/libvmod_debug
 
-vmoddir = $(pkglibdir)/vmods
-vmod_srcdir = $(top_srcdir)/lib/libvmod_debug
-vmodtool = $(top_srcdir)/lib/libvcc/vmodtool.py
-vmodtoolargs = --strict
+noinst_LTLIBRARIES += lib/libvmod_debug/libvmod_debug.la
 
-noinst_LTLIBRARIES = libvmod_debug.la
+lib_libvmod_debug_libvmod_debug_la_LDFLAGS = $(AM_LT_LDFLAGS) -module -export-dynamic -avoid-version -shared -rpath $(abs_builddir)
 
-libvmod_debug_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared -rpath /nowhere
+lib_libvmod_debug_libvmod_debug_la_SOURCES = \
+	lib/libvmod_debug/vmod_debug.c \
+	lib/libvmod_debug/vmod_debug_obj.c \
+	lib/libvmod_debug/vmod_debug_dyn.c
 
-libvmod_debug_la_SOURCES = \
-	vmod_debug.c \
-	vmod_debug_obj.c \
-	vmod_debug_dyn.c
+nodist_lib_libvmod_debug_libvmod_debug_la_SOURCES = \
+	lib/libvmod_debug/vcc_if.c \
+	lib/libvmod_debug/vcc_if.h
 
-nodist_libvmod_debug_la_SOURCES = \
-	vcc_if.c \
-	vcc_if.h
+$(lib_libvmod_debug_libvmod_debug_la_OBJECTS) : lib/libvmod_debug/vcc_if.h include/tbl/vcl_returns.h
 
-# BUILT_SOURCES is only a hack and dependency tracking does not help for the first build
-vmod_debug.lo vmod_debug_obj.lo vmod_debug_dyn.lo: vcc_if.h
+# stupid hack to run vmodtool only once
+lib/libvmod_debug/vcc_if.c \
+	lib/libvmod_debug/vmod_debug.rst \
+	lib/libvmod_debug/vmod_debug.man.rst : lib/libvmod_debug/vcc_if.h
+	@#
 
-vcc_if.c vcc_if.h vmod_debug.rst vmod_debug.man.rst: $(vmodtool) $(vmod_srcdir)/vmod.vcc
-	@PYTHON@ $(vmodtool) $(vmodtoolargs) $(vmod_srcdir)/vmod.vcc
+lib/libvmod_debug/vcc_if.h: $(vmodtool) lib/libvmod_debug/vmod.vcc
+	cd lib/libvmod_debug/ && @PYTHON@ ../../$(vmodtool) $(vmodtoolargs) $(abs_top_srcdir)/lib/libvmod_debug/vmod.vcc
 
-EXTRA_DIST = vmod.vcc
+EXTRA_DIST += lib/libvmod_debug/vmod.vcc
 
-CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h \
-	$(builddir)/vmod_debug.rst \
-	$(builddir)/vmod_debug.man.rst
+CLEANFILES +=  $(builddir)/lib/libvmod_debug/vcc_if.c  $(builddir)/lib/libvmod_debug/vcc_if.h \
+	$(builddir)/lib/libvmod_debug/vmod_debug.rst \
+	$(builddir)/lib/libvmod_debug/vmod_debug.man.rst
diff --git a/lib/libvmod_directors/Makefile.am b/lib/libvmod_directors/Makefile.am
index 64b72a8..f2465d8 100644
--- a/lib/libvmod_directors/Makefile.am
+++ b/lib/libvmod_directors/Makefile.am
@@ -1,40 +1,41 @@
 #
-AM_LDFLAGS  = $(AM_LT_LDFLAGS)
-
-AM_CPPFLAGS = \
+lib_libvmod_directors_libvmod_directors_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_srcdir)/bin/varnishd \
-	-I$(top_builddir)/include
+	-I$(top_builddir)/include \
+	-I$(top_builddir)/lib/libvmod_directors
+
+vmod_LTLIBRARIES += lib/libvmod_directors/libvmod_directors.la
 
-vmoddir = $(pkglibdir)/vmods
-vmod_srcdir = $(top_srcdir)/lib/libvmod_directors
-vmodtool = $(top_srcdir)/lib/libvcc/vmodtool.py
-vmodtoolargs = --strict
-vmod_LTLIBRARIES = libvmod_directors.la
+lib_libvmod_directors_libvmod_directors_la_LDFLAGS = $(AM_LT_LDFLAGS) -module -export-dynamic -avoid-version -shared
 
-libvmod_directors_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared
+lib_libvmod_directors_libvmod_directors_la_SOURCES = \
+	lib/libvmod_directors/vdir.c \
+	lib/libvmod_directors/vdir.h \
+	lib/libvmod_directors/fall_back.c \
+	lib/libvmod_directors/hash.c \
+	lib/libvmod_directors/random.c \
+	lib/libvmod_directors/round_robin.c
 
-libvmod_directors_la_SOURCES = \
-	vdir.c \
-	vdir.h \
-	fall_back.c \
-	hash.c \
-	random.c \
-	round_robin.c
+nodist_lib_libvmod_directors_libvmod_directors_la_SOURCES = \
+	lib/libvmod_directors/vcc_if.c \
+	lib/libvmod_directors/vcc_if.h
 
-nodist_libvmod_directors_la_SOURCES = \
-	vcc_if.c \
-	vcc_if.h
+lib/libvmod_std/lib_libvmod_std_libvmod_std_la-vmod_vcc_if.lo : include/vmod_abi.h
 
-# BUILT_SOURCES is only a hack and dependency tracking does not help for the first build
-vdir.lo fall_back.lo hash.lo random.lo round_robin.lo: vcc_if.h
+$(lib_libvmod_directors_libvmod_directors_la_OBJECTS) : lib/libvmod_directors/vcc_if.h include/tbl/vcl_returns.h
 
-vcc_if.c vcc_if.h vmod_directors.rst vmod_directors.man.rst: $(vmodtool) $(vmod_srcdir)/vmod.vcc
-	@PYTHON@ $(vmodtool) $(vmodtoolargs) $(vmod_srcdir)/vmod.vcc
+# stupid hack to run vmodtool only once
+lib/libvmod_directors/vcc_if.c \
+	lib/libvmod_directors/vmod_directors.rst \
+	lib/libvmod_directors/vmod_directors.man.rst : lib/libvmod_directors/vcc_if.h
+	@#
 
+lib/libvmod_directors/vcc_if.h: $(vmodtool) lib/libvmod_directors/vmod.vcc
+	cd lib/libvmod_directors/ && @PYTHON@ ../../$(vmodtool) $(vmodtoolargs) $(abs_top_srcdir)/lib/libvmod_directors/vmod.vcc
 
-EXTRA_DIST = vmod.vcc
+EXTRA_DIST += lib/libvmod_directors/vmod.vcc
 
-CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h \
-	$(builddir)/vmod_directors.rst \
-	$(builddir)/vmod_directors.man.rst
+CLEANFILES +=  $(top_builddir)/lib/libvmod_directors/vcc_if.c  $(top_builddir)/lib/libvmod_directors/vcc_if.h \
+	$(top_builddir)/lib/libvmod_directors/vmod_directors.rst \
+	$(top_builddir)/lib/libvmod_directors/vmod_directors.man.rst
diff --git a/lib/libvmod_std/Makefile.am b/lib/libvmod_std/Makefile.am
index 47dd5dc..1cb5636 100644
--- a/lib/libvmod_std/Makefile.am
+++ b/lib/libvmod_std/Makefile.am
@@ -1,38 +1,41 @@
 #
 
-AM_LDFLAGS  = $(AM_LT_LDFLAGS)
-
-AM_CPPFLAGS = \
+lib_libvmod_std_libvmod_std_la_CPPFLAGS = \
 	-I$(top_srcdir)/include \
 	-I$(top_srcdir)/bin/varnishd \
-	-I$(top_builddir)/include
+	-I$(top_builddir)/include \
+	-I$(top_builddir)/lib/libvmod_std
+
+vmod_LTLIBRARIES += lib/libvmod_std/libvmod_std.la
+
+lib_libvmod_std_libvmod_std_la_LDFLAGS = $(AM_LT_LDFLAGS) -module -export-dynamic -avoid-version -shared
 
-vmoddir = $(pkglibdir)/vmods
-vmod_srcdir = $(top_srcdir)/lib/libvmod_std
-vmodtool = $(top_srcdir)/lib/libvcc/vmodtool.py
-vmodtoolargs = --strict
-vmod_LTLIBRARIES = libvmod_std.la
+lib_libvmod_std_libvmod_std_la_SOURCES = \
+	lib/libvmod_std/vmod_std.c \
+	lib/libvmod_std/vmod_std_conversions.c \
+	lib/libvmod_std/vmod_std_fileread.c \
+	lib/libvmod_std/vmod_std_querysort.c
 
-libvmod_std_la_LDFLAGS = $(AM_LDFLAGS) -module -export-dynamic -avoid-version -shared
+nodist_lib_libvmod_std_libvmod_std_la_SOURCES = \
+	lib/libvmod_std/vcc_if.c \
+	lib/libvmod_std/vcc_if.h
 
-libvmod_std_la_SOURCES = \
-	vmod_std.c \
-	vmod_std_conversions.c \
-	vmod_std_fileread.c \
-	vmod_std_querysort.c
+lib/libvmod_std/lib_libvmod_std_libvmod_std_la-vmod_vcc_if.$(OBJEXT) : include/vmod_abi.h
 
-nodist_libvmod_std_la_SOURCES = \
-	vcc_if.c \
-	vcc_if.h
+$(lib_libvmod_std_libvmod_std_la_OBJECTS) : lib/libvmod_std/vcc_if.h include/tbl/vcl_returns.h
 
-# BUILT_SOURCES is only a hack and dependency tracking does not help for the first build
-$(libvmod_std_la_OBJECTS): vcc_if.h
+# stupid hack to run vmodtool only once
+lib/libvmod_std/vcc_if.c \
+	lib/libvmod_std/vmod_std.rst \
+	lib/libvmod_std/vmod_std.man.rst : lib/libvmod_std/vcc_if.h
+	@#
 
-vcc_if.c vcc_if.h vmod_std.rst vmod_std.man.rst: $(vmodtool) $(vmod_srcdir)/vmod.vcc
-	@PYTHON@ $(vmodtool) $(vmodtoolargs) $(vmod_srcdir)/vmod.vcc
+lib/libvmod_std/vcc_if.h: $(vmodtool) lib/libvmod_std/vmod.vcc
+	cd lib/libvmod_std/ && @PYTHON@ ../../$(vmodtool) $(vmodtoolargs) $(abs_top_srcdir)/lib/libvmod_std/vmod.vcc
 
-EXTRA_DIST = vmod.vcc
+EXTRA_DIST += lib/libvmod_std/vmod.vcc
 
-CLEANFILES = $(builddir)/vcc_if.c $(builddir)/vcc_if.h \
-	$(builddir)/vmod_std.rst \
-	$(builddir)/vmod_std.man.rst
+CLEANFILES +=  lib/libvmod_std/vcc_if.c  lib/libvmod_std/vcc_if.h \
+	lib/libvmod_std/vmod_std.rst \
+	lib/libvmod_std/vmod_std.man.rst
+	
diff --git a/man/Makefile.am b/man/Makefile.am
index d791d1f..5ad9f48 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -1,93 +1,91 @@
 #
 
-noinst_PROGRAMS = vsc2rst
-vsc2rst_SOURCES = vsc2rst.c \
-	$(top_srcdir)/include/tbl/vsc_fields.h
+noinst_PROGRAMS += man/vsc2rst
+man_vsc2rst_SOURCES = man/vsc2rst.c \
+	include/tbl/vsc_fields.h
 
-AM_CPPFLAGS = -I$(top_srcdir)/include
+man_vsc2rst_CPPFLAGS = -I$(top_srcdir)/include
 
 dist_man_MANS = \
-	varnish-cli.7 \
-	varnish-counters.7 \
-	vcl.7 \
-	vsl.7 \
-	vsl-query.7 \
-	varnishadm.1 \
-	varnishd.1 \
-	varnishhist.1 \
-	varnishlog.1 \
-	varnishncsa.1 \
-	varnishstat.1 \
-	varnishtest.1 \
-	varnishtop.1 \
-	vmod_directors.3 \
-	vmod_std.3
-
-MAINTAINERCLEANFILES = $(dist_man_MANS)
-
-RST2ANY_FLAGS = --halt=2
-
-varnish-cli.7: $(top_srcdir)/doc/sphinx/reference/varnish-cli.rst
+	man/varnish-cli.7 \
+	man/varnish-counters.7 \
+	man/vcl.7 \
+	man/vsl.7 \
+	man/vsl-query.7 \
+	man/varnishadm.1 \
+	man/varnishd.1 \
+	man/varnishhist.1 \
+	man/varnishlog.1 \
+	man/varnishncsa.1 \
+	man/varnishstat.1 \
+	man/varnishtest.1 \
+	man/varnishtop.1 \
+	man/vmod_directors.3 \
+	man/vmod_std.3
+
+MAINTAINERCLEANFILES += $(dist_man_MANS)
+
+man/varnish-cli.7: $(top_srcdir)/doc/sphinx/reference/varnish-cli.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnish-cli.rst $@
 
-varnish-counters.7: vsc2rst
-	./vsc2rst | ${RST2MAN} $(RST2ANY_FLAGS) - $@
+man/varnish-counters.7: $(top_builddir)/man/vsc2rst
+	$^ | ${RST2MAN} $(RST2ANY_FLAGS) - $@
 
-vcl.7: $(top_srcdir)/doc/sphinx/reference/vcl.rst \
-	$(top_srcdir)/bin/varnishd/builtin.vcl
+man/vcl.7: $(top_srcdir)/doc/sphinx/reference/vcl.rst \
+	bin/varnishd/builtin.vcl
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/vcl.rst $@
 
-vsl.7: $(top_srcdir)/doc/sphinx/reference/vsl.rst \
+man/vsl.7: $(top_srcdir)/doc/sphinx/reference/vsl.rst \
 	$(top_srcdir)/lib/libvarnishapi/vsl-tags.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/vsl.rst $@
 
-vsl-query.7: $(top_srcdir)/doc/sphinx/reference/vsl-query.rst
+man/vsl-query.7: $(top_srcdir)/doc/sphinx/reference/vsl-query.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/vsl-query.rst $@
 
-varnishadm.1: $(top_srcdir)/doc/sphinx/reference/varnishadm.rst
+man/varnishadm.1: $(top_srcdir)/doc/sphinx/reference/varnishadm.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishadm.rst $@
 
-varnishd.1: \
+man/varnishd.1: \
 	$(top_srcdir)/doc/sphinx/reference/varnishd.rst \
 	$(top_srcdir)/doc/sphinx/include/params.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishd.rst $@
 
-varnishncsa.1: \
+man/varnishncsa.1: \
 	$(top_srcdir)/doc/sphinx/reference/varnishncsa.rst \
 	$(top_srcdir)/doc/sphinx/include/varnishncsa_options.rst \
 	$(top_srcdir)/doc/sphinx/include/varnishncsa_synopsis.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishncsa.rst $@
 
-varnishlog.1: \
+man/varnishlog.1: \
 	$(top_srcdir)/doc/sphinx/reference/varnishlog.rst \
 	$(top_srcdir)/doc/sphinx/include/varnishlog_options.rst \
 	$(top_srcdir)/doc/sphinx/include/varnishlog_synopsis.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishlog.rst $@
 
-varnishreplay.1: $(top_srcdir)/doc/sphinx/reference/varnishreplay.rst
+man/varnishreplay.1: $(top_srcdir)/doc/sphinx/reference/varnishreplay.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishreplay.rst $@
 
 # XXX add _options.rst and _synopsis.rst here when it's been _opt2rst'ed
-varnishstat.1: $(top_srcdir)/doc/sphinx/reference/varnishstat.rst
+man/varnishstat.1: $(top_srcdir)/doc/sphinx/reference/varnishstat.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishstat.rst $@
 
-varnishtest.1: $(top_srcdir)/doc/sphinx/reference/varnishtest.rst
+man/varnishtest.1: $(top_srcdir)/doc/sphinx/reference/varnishtest.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishtest.rst $@
 
-varnishtop.1: \
+man/varnishtop.1: \
 	$(top_srcdir)/doc/sphinx/reference/varnishtop.rst \
 	$(top_srcdir)/doc/sphinx/include/varnishtop_options.rst \
 	$(top_srcdir)/doc/sphinx/include/varnishtop_synopsis.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishtop.rst $@
 
-varnishhist.1: \
+man/varnishhist.1: \
 	$(top_srcdir)/doc/sphinx/reference/varnishhist.rst \
 	$(top_srcdir)/doc/sphinx/include/varnishhist_options.rst \
 	$(top_srcdir)/doc/sphinx/include/varnishhist_synopsis.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $(top_srcdir)/doc/sphinx/reference/varnishhist.rst $@
 
-vmod_std.3: $(top_builddir)/lib/libvmod_std/vmod_std.man.rst
+man/vmod_std.3: $(top_builddir)/lib/libvmod_std/vmod_std.man.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $? $@
 
-vmod_directors.3: $(top_builddir)/lib/libvmod_directors/vmod_directors.man.rst
+man/vmod_directors.3: $(top_builddir)/lib/libvmod_directors/vmod_directors.man.rst
 	${RST2MAN} $(RST2ANY_FLAGS) $? $@
_______________________________________________
varnish-dev mailing list
varnish-dev@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev

Reply via email to