build: add check for clock_gettime() in librt

zuctest is another clock_gettime() user that fails to link against librt when
necessary.

Instead of adding another -lrt LDADD entry i've opted for the saner way and
converted the check to a configure test that will set CLOCK_GETTIME_LIBS
appropiately and replaced all instances of -lrt with it.
Built-tested against old and new glibc.

Signed-off-by: Gustavo Zacarias <gustavo@zacarias.com.ar>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
diff --git a/Makefile.am b/Makefile.am
index d3c3f71..c042c68 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -65,7 +65,7 @@
 weston_CPPFLAGS = $(AM_CPPFLAGS) -DIN_WESTON
 weston_CFLAGS = $(AM_CFLAGS) $(COMPOSITOR_CFLAGS) $(LIBUNWIND_CFLAGS)
 weston_LDADD = $(COMPOSITOR_LIBS) $(LIBUNWIND_LIBS) \
-	$(DLOPEN_LIBS) -lm -lrt libshared.la
+	$(DLOPEN_LIBS) -lm $(CLOCK_GETTIME_LIBS) libshared.la
 
 weston_SOURCES =					\
 	src/git-version.h				\
@@ -270,7 +270,8 @@
 	$(COMPOSITOR_LIBS)			\
 	$(DRM_COMPOSITOR_LIBS)			\
 	$(INPUT_BACKEND_LIBS)			\
-	libshared.la -lrt			\
+	libshared.la				\
+	$(CLOCK_GETTIME_LIBS)			\
 	libsession-helper.la
 drm_backend_la_CFLAGS =				\
 	$(COMPOSITOR_CFLAGS)			\
@@ -508,11 +509,11 @@
 	protocol/presentation-time-protocol.c		\
 	protocol/presentation-time-client-protocol.h
 weston_presentation_shm_CFLAGS = $(AM_CFLAGS) $(SIMPLE_CLIENT_CFLAGS)
-weston_presentation_shm_LDADD = $(SIMPLE_CLIENT_LIBS) libshared.la -lm -lrt
+weston_presentation_shm_LDADD = $(SIMPLE_CLIENT_LIBS) libshared.la -lm $(CLOCK_GETTIME_LIBS)
 
 weston_multi_resource_SOURCES = clients/multi-resource.c
 weston_multi_resource_CFLAGS = $(AM_CFLAGS) $(SIMPLE_CLIENT_CFLAGS)
-weston_multi_resource_LDADD = $(SIMPLE_CLIENT_LIBS) libshared.la -lrt -lm
+weston_multi_resource_LDADD = $(SIMPLE_CLIENT_LIBS) libshared.la $(CLOCK_GETTIME_LIBS) -lm
 endif
 
 if BUILD_SIMPLE_EGL_CLIENTS
@@ -580,7 +581,7 @@
 libtoytoolkit_la_LIBADD =			\
 	$(CLIENT_LIBS)				\
 	$(CAIRO_EGL_LIBS)			\
-	libshared-cairo.la -lrt -lm
+	libshared-cairo.la $(CLOCK_GETTIME_LIBS) -lm
 libtoytoolkit_la_CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS) $(CAIRO_EGL_CFLAGS)
 
 weston_flower_SOURCES = clients/flower.c
@@ -1181,7 +1182,7 @@
 	shared/helpers.h			\
 	src/vertex-clipping.c			\
 	src/vertex-clipping.h
-vertex_clip_test_LDADD = libtest-runner.la -lm -lrt
+vertex_clip_test_LDADD = libtest-runner.la -lm $(CLOCK_GETTIME_LIBS)
 
 libtest_client_la_SOURCES =			\
 	tests/weston-test-client-helper.c	\
@@ -1269,7 +1270,7 @@
 	shared/matrix.c				\
 	shared/matrix.h
 matrix_test_CPPFLAGS = -DUNIT_TEST
-matrix_test_LDADD = -lm -lrt
+matrix_test_LDADD = -lm $(CLOCK_GETTIME_LIBS)
 
 if ENABLE_IVI_SHELL
 module_tests += 				\