build: Move tests/Makefile.am into toplevel Makefile.am
diff --git a/Makefile.am b/Makefile.am
index 6c56f97..6c5fd85 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -7,8 +7,7 @@
 
 SUBDIRS =					\
 	shared					\
-	clients					\
-	tests
+	clients
 
 DISTCHECK_CONFIGURE_FLAGS = --disable-setuid-install
 
@@ -23,8 +22,12 @@
 
 all-local : weston.ini validate-protocol-xml
 
+AM_CFLAGS = $(GCC_CFLAGS)
+
 AM_CPPFLAGS = 					\
+	-I$(top_srcdir)/src			\
 	-I$(top_builddir)/src			\
+	-I$(top_builddir)/tests			\
 	-I$(top_srcdir)/shared			\
 	-DDATADIR='"$(datadir)"'		\
 	-DMODULEDIR='"$(moduledir)"'		\
@@ -442,6 +445,157 @@
 endif
 
 
+#
+# tests subdirectory
+#
+
+TESTS = $(shared_tests) $(module_tests) $(weston_tests)
+
+shared_tests =					\
+	config-parser.test			\
+	vertex-clip.test
+
+module_tests =					\
+	surface-test.la				\
+	surface-global-test.la
+
+weston_tests =					\
+	bad_buffer.weston			\
+	keyboard.weston				\
+	event.weston				\
+	button.weston				\
+	text.weston				\
+	subsurface.weston
+
+
+AM_TESTS_ENVIRONMENT = \
+	abs_builddir='$(abs_builddir)'; export abs_builddir;
+
+TEST_EXTENSIONS = .la .weston
+LA_LOG_COMPILER = $(srcdir)/tests/weston-tests-env
+WESTON_LOG_COMPILER = $(srcdir)/tests/weston-tests-env
+
+clean-local:
+	-rm -rf tests/logs
+
+# To remove when automake 1.11 support is dropped
+export abs_builddir
+
+noinst_LTLIBRARIES +=			\
+	weston-test.la			\
+	$(module_tests)			\
+	libtest-runner.la		\
+	libtest-client.la
+
+noinst_PROGRAMS +=			\
+	$(setbacklight)			\
+	$(shared_tests)			\
+	$(weston_tests)			\
+	matrix-test
+
+test_module_ldflags = \
+	-module -avoid-version -rpath $(libdir) $(COMPOSITOR_LIBS)
+
+surface_global_test_la_SOURCES = tests/surface-global-test.c
+surface_global_test_la_LDFLAGS = $(test_module_ldflags)
+surface_global_test_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
+
+surface_test_la_SOURCES = tests/surface-test.c
+surface_test_la_LDFLAGS = $(test_module_ldflags)
+surface_test_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
+
+weston_test_la_LIBADD = $(COMPOSITOR_LIBS) shared/libshared.la
+weston_test_la_LDFLAGS = $(test_module_ldflags)
+weston_test_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
+weston_test_la_SOURCES =			\
+	tests/weston-test.c			\
+	tests/wayland-test-protocol.c		\
+	tests/wayland-test-server-protocol.h
+
+if ENABLE_EGL
+weston_test_la_CFLAGS += $(EGL_TESTS_CFLAGS)
+weston_test_la_LDFLAGS += $(EGL_TESTS_LIBS)
+endif
+
+libtest_runner_la_SOURCES =			\
+	tests/weston-test-runner.c		\
+	tests/weston-test-runner.h
+libtest_runner_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
+
+config_parser_test_SOURCES = tests/config-parser-test.c
+config_parser_test_LDADD = shared/libshared.la libtest-runner.la $(COMPOSITOR_LIBS)
+
+vertex_clip_test_SOURCES =			\
+	tests/vertex-clip-test.c		\
+	src/vertex-clipping.c			\
+	src/vertex-clipping.h
+vertex_clip_test_LDADD = libtest-runner.la -lm -lrt
+
+libtest_client_la_SOURCES =		\
+	tests/weston-test-client-helper.c	\
+	tests/weston-test-client-helper.h	\
+	tests/wayland-test-protocol.c		\
+	tests/wayland-test-client-protocol.h
+libtest_client_la_LIBADD = $(TEST_CLIENT_LIBS) shared/libshared.la libtest-runner.la
+
+bad_buffer_weston_SOURCES = tests/bad-buffer-test.c
+bad_buffer_weston_LDADD = libtest-client.la
+
+keyboard_weston_SOURCES = tests/keyboard-test.c
+keyboard_weston_LDADD = libtest-client.la
+
+event_weston_SOURCES = tests/event-test.c
+event_weston_LDADD = libtest-client.la
+
+button_weston_SOURCES = tests/button-test.c
+button_weston_LDADD = libtest-client.la
+
+text_weston_SOURCES = tests/text-test.c tests/text-protocol.c
+text_weston_LDADD = libtest-client.la
+
+subsurface_weston_SOURCES = tests/subsurface-test.c
+subsurface_weston_LDADD = libtest-client.la
+
+if ENABLE_EGL
+weston_tests += buffer-count.weston
+buffer_count_weston_SOURCES = tests/buffer-count-test.c
+buffer_count_weston_CFLAGS = $(GCC_CFLAGS) $(EGL_TESTS_CFLAGS)
+buffer_count_weston_LDADD = libtest-client.la $(EGL_TESTS_LIBS)
+endif
+
+if ENABLE_XWAYLAND_TEST
+weston_tests +=	xwayland.weston
+xwayland_weston_SOURCES = tests/xwayland-test.c
+xwayland_weston_CFLAGS = $(GCC_CFLAGS) $(XWAYLAND_TEST_CFLAGS)
+xwayland_weston_LDADD = libtest-client.la $(XWAYLAND_TEST_LIBS)
+endif
+
+matrix_test_SOURCES =				\
+	tests/matrix-test.c			\
+	shared/matrix.c				\
+	shared/matrix.h
+matrix_test_CPPFLAGS = -DUNIT_TEST
+matrix_test_LDADD = -lm -lrt
+
+if BUILD_SETBACKLIGHT
+noinst_PROGRAMS += setbacklight
+setbacklight_SOURCES =				\
+	tests/setbacklight.c			\
+	src/libbacklight.c			\
+	src/libbacklight.h
+setbacklight_CFLAGS = $(AM_CFLAGS) $(SETBACKLIGHT_CFLAGS)
+setbacklight_LDADD = $(SETBACKLIGHT_LIBS)
+endif
+
+EXTRA_DIST += tests/weston-tests-env
+
+BUILT_SOURCES +=				\
+	tests/wayland-test-protocol.c		\
+	tests/wayland-test-server-protocol.h	\
+	tests/wayland-test-client-protocol.h	\
+	tests/text-protocol.c			\
+	tests/text-client-protocol.h
+
 protocol_sources =				\
 	protocol/desktop-shell.xml		\
 	protocol/screenshooter.xml		\
diff --git a/configure.ac b/configure.ac
index 2144f85..b960618 100644
--- a/configure.ac
+++ b/configure.ac
@@ -488,8 +488,7 @@
 		 shared/Makefile
 		 src/version.h
 		 src/weston.pc
-		 clients/Makefile
-		 tests/Makefile])
+		 clients/Makefile])
 AC_OUTPUT
 
 AC_MSG_RESULT([
diff --git a/tests/Makefile.am b/tests/Makefile.am
deleted file mode 100644
index 1286514..0000000
--- a/tests/Makefile.am
+++ /dev/null
@@ -1,166 +0,0 @@
-TESTS = $(shared_tests) $(module_tests) $(weston_tests)
-
-shared_tests = \
-	config-parser.test		\
-	vertex-clip.test
-
-module_tests =				\
-	surface-test.la			\
-	surface-global-test.la
-
-weston_tests =				\
-	bad_buffer.weston		\
-	keyboard.weston			\
-	event.weston			\
-	button.weston			\
-	text.weston			\
-	subsurface.weston		\
-	$(xwayland_test)
-
-if ENABLE_EGL
-weston_tests +=				\
-	buffer-count.weston
-endif
-
-AM_TESTS_ENVIRONMENT = \
-	abs_builddir='$(abs_builddir)'; export abs_builddir;
-
-TEST_EXTENSIONS = .la .weston
-LA_LOG_COMPILER = $(srcdir)/weston-tests-env
-WESTON_LOG_COMPILER = $(srcdir)/weston-tests-env
-
-clean-local:
-	-rm -rf logs
-
-# To remove when automake 1.11 support is dropped
-export abs_builddir
-
-noinst_LTLIBRARIES =			\
-	weston-test.la			\
-	$(module_tests)			\
-	libtest-runner.la		\
-	libtest-client.la
-
-noinst_PROGRAMS =			\
-	$(setbacklight)			\
-	$(shared_tests)			\
-	$(weston_tests)			\
-	matrix-test
-
-AM_CFLAGS = $(GCC_CFLAGS)
-AM_CPPFLAGS =					\
-	-I$(top_srcdir)/src			\
-	-I$(top_srcdir)/shared			\
-	-I$(top_builddir)/src			\
-	$(COMPOSITOR_CFLAGS)
-
-surface_global_test_la_SOURCES = surface-global-test.c
-surface_global_test_la_LDFLAGS = -module -avoid-version -rpath $(libdir)
-surface_test_la_SOURCES = surface-test.c
-surface_test_la_LDFLAGS = -module -avoid-version -rpath $(libdir)
-
-weston_test_la_LIBADD = $(COMPOSITOR_LIBS) ../shared/libshared.la
-weston_test_la_LDFLAGS = -module -avoid-version -rpath $(libdir)
-weston_test_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
-weston_test_la_SOURCES =		\
-	weston-test.c			\
-	wayland-test-protocol.c		\
-	wayland-test-server-protocol.h
-
-if ENABLE_EGL
-weston_test_la_CFLAGS += $(EGL_TESTS_CFLAGS)
-weston_test_la_LDFLAGS += $(EGL_TESTS_LIBS)
-endif
-
-libtest_runner_la_SOURCES =	\
-	weston-test-runner.c	\
-	weston-test-runner.h
-libtest_runner_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
-
-config_parser_test_LDADD =	\
-	../shared/libshared.la	\
-	libtest-runner.la	\
-	$(COMPOSITOR_LIBS)
-config_parser_test_SOURCES =	\
-	config-parser-test.c
-
-vertex_clip_test_SOURCES =		\
-	vertex-clip-test.c		\
-	../src/vertex-clipping.c	\
-	../src/vertex-clipping.h
-vertex_clip_test_LDADD =	\
-	libtest-runner.la	\
-	-lm -lrt
-
-libtest_client_la_SOURCES =		\
-	weston-test-client-helper.c	\
-	weston-test-client-helper.h	\
-	wayland-test-protocol.c		\
-	wayland-test-client-protocol.h
-libtest_client_la_LIBADD =		\
-	$(TEST_CLIENT_LIBS)		\
-	../shared/libshared.la		\
-	libtest-runner.la
-
-bad_buffer_weston_SOURCES = bad-buffer-test.c
-bad_buffer_weston_LDADD = libtest-client.la
-
-keyboard_weston_SOURCES = keyboard-test.c
-keyboard_weston_LDADD = libtest-client.la
-
-event_weston_SOURCES = event-test.c
-event_weston_LDADD = libtest-client.la
-
-button_weston_SOURCES = button-test.c
-button_weston_LDADD = libtest-client.la
-
-text_weston_SOURCES = text-test.c text-protocol.c
-text_weston_LDADD = libtest-client.la
-
-subsurface_weston_SOURCES = subsurface-test.c
-subsurface_weston_LDADD = libtest-client.la
-
-buffer_count_weston_SOURCES = buffer-count-test.c
-buffer_count_weston_CFLAGS = $(GCC_CFLAGS) $(EGL_TESTS_CFLAGS)
-buffer_count_weston_LDADD = libtest-client.la $(EGL_TESTS_LIBS)
-
-xwayland_weston_SOURCES = xwayland-test.c
-xwayland_weston_CFLAGS = $(GCC_CFLAGS) $(XWAYLAND_TEST_CFLAGS)
-xwayland_weston_LDADD = libtest-client.la $(XWAYLAND_TEST_LIBS)
-
-if ENABLE_XWAYLAND_TEST
-xwayland_test = xwayland.weston
-endif
-
-matrix_test_CPPFLAGS = -DUNIT_TEST
-matrix_test_SOURCES =				\
-	matrix-test.c				\
-	../shared/matrix.c			\
-	../shared/matrix.h
-matrix_test_LDADD = -lm -lrt
-
-setbacklight_SOURCES =				\
-	setbacklight.c				\
-	../src/libbacklight.c			\
-	..//src/libbacklight.h
-
-setbacklight_CFLAGS = $(AM_CFLAGS) $(SETBACKLIGHT_CFLAGS)
-setbacklight_LDADD = $(SETBACKLIGHT_LIBS)
-
-if BUILD_SETBACKLIGHT
-setbacklight = setbacklight
-endif
-
-EXTRA_DIST = weston-tests-env
-
-BUILT_SOURCES =					\
-	wayland-test-protocol.c			\
-	wayland-test-server-protocol.h		\
-	wayland-test-client-protocol.h		\
-	text-protocol.c				\
-	text-client-protocol.h
-
-CLEANFILES = $(BUILT_SOURCES)
-
-wayland_protocoldir = $(top_srcdir)/protocol
-include $(top_srcdir)/wayland-scanner.mk
diff --git a/tests/weston-tests-env b/tests/weston-tests-env
index b732250..04b91a9 100755
--- a/tests/weston-tests-env
+++ b/tests/weston-tests-env
@@ -7,7 +7,7 @@
 	exit 1;
 fi
 
-WESTON=$abs_builddir/../src/weston
+WESTON=$abs_builddir/weston
 LOGDIR=$abs_builddir/logs
 
 mkdir -p "$LOGDIR"
@@ -18,11 +18,11 @@
 rm -f "$SERVERLOG"
 
 if test x$WAYLAND_DISPLAY != x; then
-	BACKEND=$abs_builddir/../src/.libs/wayland-backend.so
+	BACKEND=$abs_builddir/.libs/wayland-backend.so
 elif test x$DISPLAY != x; then
-	BACKEND=$abs_builddir/../src/.libs/x11-backend.so
+	BACKEND=$abs_builddir/.libs/x11-backend.so
 else
-	BACKEND=$abs_builddir/../src/.libs/wayland-backend.so
+	BACKEND=$abs_builddir/.libs/wayland-backend.so
 fi
 
 case $TESTNAME in