From c3efdd482e171bd8a6d6c8a1125c4f757ebdf2e4 Mon Sep 17 00:00:00 2001
From: Anders Roxell <anders.roxell@linaro.org>
Date: Wed, 6 Feb 2019 13:40:58 +0100
Subject: [PATCH] install-tests to bindir test

Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
---
 configure.ac      | 14 ++++++++++++++
 libgpiod.pc.in    |  1 +
 tests/Makefile.am |  8 +++++++-
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/configure.ac b/configure.ac
index 49bedf4d2410..e767dc46ae75 100644
--- a/configure.ac
+++ b/configure.ac
@@ -127,6 +127,20 @@ AC_ARG_ENABLE([tests],
 	[with_tests=false])
 AM_CONDITIONAL([WITH_TESTS], [test "x$with_tests" = xtrue])
 
+AC_ARG_ENABLE([install-tests],
+	[AC_HELP_STRING([--enable-install-tests],
+		[enable install tests [default=no]])],
+	[
+		if test "x$enableval" = xyes
+		then
+			with_install_tests=true
+		else
+			with_install_tests=false
+		fi
+	],
+	[with_install_tests=false])
+AM_CONDITIONAL([WITH_INSTALL_TESTS], [test "x$with_install_tests" = xtrue])
+
 AC_DEFUN([FUNC_NOT_FOUND_TESTS],
 	[ERR_NOT_FOUND([$1()], [tests])])
 
diff --git a/libgpiod.pc.in b/libgpiod.pc.in
index 48ff11392ae4..96d1111324e5 100644
--- a/libgpiod.pc.in
+++ b/libgpiod.pc.in
@@ -1,5 +1,6 @@
 prefix=@prefix@
 exec_prefix=@exec_prefix@
+bindir=@bindir@
 libdir=@libdir@
 includedir=@includedir@
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a9319a725f0d..683ab54db5a0 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -9,10 +9,16 @@
 AM_CFLAGS = -I$(top_srcdir)/include/ -include $(top_builddir)/config.h
 AM_CFLAGS += -Wall -Wextra -g $(KMOD_CFLAGS) $(UDEV_CFLAGS)
 AM_LDFLAGS = -pthread
-LDADD = ../src/lib/libgpiod.la $(KMOD_LIBS) $(UDEV_LIBS)
+LDADD = $(top_builddir)/src/lib/libgpiod.la $(KMOD_LIBS) $(UDEV_LIBS)
 
 check_PROGRAMS = gpiod-test
 
+if WITH_INSTALL_TESTS
+bin_PROGRAMS = $(check_PROGRAMS)
+else
+noinst_PROGRAMS = $(check_PROGRAMS)
+endif
+
 gpiod_test_SOURCES =	gpiod-test.c \
 			gpiod-test.h \
 			tests-chip.c \
-- 
2.20.1

