From 241c51e2974ad0423bfb7ee2ad7844e846c246fc Mon Sep 17 00:00:00 2001
From: Luke Dashjr <luke-jr+git@utopios.org>
Date: Mon, 12 Jan 2015 19:32:38 +0000
Subject: [PATCH] Added configure option --disable-tools

---
 Makefile.am              |  7 ++++-
 configure.ac             | 67 ++++++++++++++++++++++++++++++------------------
 doc/manpages/Makefile.am |  7 +++--
 3 files changed, 53 insertions(+), 28 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 3ca67f3..9f6b199 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -27,10 +27,15 @@ if ENABLE_DANE
 SUBDIRS += libdane
 endif
 
-SUBDIRS += po src
+SUBDIRS += po
 if ENABLE_DOC
 SUBDIRS += doc
 endif
+if ENABLE_TOOLS
+SUBDIRS += src
+else
+SUBDIRS += src/gl
+endif
 if ENABLE_TESTS
 SUBDIRS += tests
 endif
diff --git a/configure.ac b/configure.ac
index a08d6f3..5cdb02f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -45,14 +45,27 @@ AC_PROG_CXX
 AM_PROG_CC_C_O
 AC_PROG_YACC
 AC_PROG_SED
-AC_CHECK_PROG([AUTOGEN], [autogen], [autogen], [/bin/true])
 
-if test x"$AUTOGEN" = "x/bin/true"; then
-  AC_MSG_WARN([[
+AC_ARG_ENABLE(doc,
+  AS_HELP_STRING([--disable-doc], [don't generate any documentation]),
+    enable_doc=$enableval, enable_doc=yes)
+AM_CONDITIONAL(ENABLE_DOC, test "$enable_doc" != "no")
+
+AC_ARG_ENABLE(tools,
+  AS_HELP_STRING([--disable-tools], [don't compile any tools]),
+    enable_tools=$enableval, enable_tools=yes)
+AM_CONDITIONAL(ENABLE_TOOLS, test "$enable_tools" != "no")
+
+if test "$enable_tools$enable_doc" != "nono"; then
+  AC_CHECK_PROG([AUTOGEN], [autogen], [autogen], [/bin/true])
+
+  if test x"$AUTOGEN" = "x/bin/true"; then
+    AC_MSG_WARN([[
 ***
 *** autogen not found. Will not link against libopts.
 *** ]])
-enable_local_libopts=yes
+    enable_local_libopts=yes
+  fi
 fi
 
 # For includes/gnutls/gnutls.h.in.
@@ -174,14 +187,12 @@ dnl Try the hooks.m4
 LIBGNUTLS_HOOKS
 LIBGNUTLS_EXTRA_HOOKS
 
-AC_ARG_ENABLE(doc,
-  AS_HELP_STRING([--disable-doc], [don't generate any documentation]),
-    enable_doc=$enableval, enable_doc=yes)
-AM_CONDITIONAL(ENABLE_DOC, test "$enable_doc" != "no")
-
 AC_ARG_ENABLE(tests,
   AS_HELP_STRING([--disable-tests], [don't compile or run any tests]),
-    enable_tests=$enableval, enable_tests=yes)
+    enable_tests=$enableval, enable_tests=$enable_tools)
+if test "$enable_tests$enable_tools" = "yesno"; then
+  true #AC_MSG_ERROR([Cannot enable tests while disabling tools])
+fi
 AM_CONDITIONAL(ENABLE_TESTS, test "$enable_tests" != "no")
 
 GTK_DOC_CHECK(1.1)
@@ -508,24 +519,30 @@ fi
 
 AM_CONDITIONAL(ENABLE_TROUSERS, test "$with_tpm" != "no")
 
-LIBOPTS_CHECK([src/libopts])
-if test "$NEED_LIBOPTS_DIR" = "true";then
-	dnl replace libopts-generated files with distributed backups, if present
-	missing_baks=
-	for i in ${srcdir}/src/*-args.c.bak ${srcdir}/src/*-args.h.bak; do
-		nam=`echo $i|sed 's/.bak//g'`
-		if test -f $i;then
-			cp -f $i $nam
-		else
-			missing_baks=true
+enable_local_libopts=no
+if test "$enable_tools$enable_doc" != "no"; then
+	LIBOPTS_CHECK([src/libopts])
+	if test "$NEED_LIBOPTS_DIR" = "true";then
+		dnl replace libopts-generated files with distributed backups, if present
+		missing_baks=
+		for i in ${srcdir}/src/*-args.c.bak ${srcdir}/src/*-args.h.bak; do
+			nam=`echo $i|sed 's/.bak//g'`
+			if test -f $i;then
+				cp -f $i $nam
+			else
+				missing_baks=true
+			fi
+		done
+		if test -z "$missing_baks"; then
+			AC_SUBST([AUTOGEN], [/bin/true])
 		fi
-	done
-	if test -z "$missing_baks"; then
-		AC_SUBST([AUTOGEN], [/bin/true])
+		enable_local_libopts=yes
 	fi
-	enable_local_libopts=yes
 else
-	enable_local_libopts=no
+	# Need to ensure the relevant conditionals get set
+	gl_STDNORETURN_H
+	AM_CONDITIONAL([INSTALL_LIBOPTS],[false])
+	AM_CONDITIONAL([NEED_LIBOPTS], [false])
 fi
 AM_CONDITIONAL(NEED_LIBOPTS, test "$enable_local_libopts" = "yes")
 
diff --git a/doc/manpages/Makefile.am b/doc/manpages/Makefile.am
index bba05ee..1f5019a 100644
--- a/doc/manpages/Makefile.am
+++ b/doc/manpages/Makefile.am
@@ -21,17 +21,20 @@
 
 EXTRA_DIST = stamp_mans
 
-dist_man_MANS = gnutls-cli.1 gnutls-cli-debug.1 gnutls-serv.1	\
-	certtool.1 psktool.1 p11tool.1 ocsptool.1 tpmtool.1
+dist_man_MANS =
 
 -include $(top_srcdir)/doc/doc.mk
 
+if ENABLE_TOOLS
+dist_man_MANS += gnutls-cli.1 gnutls-cli-debug.1 gnutls-serv.1	\
+	certtool.1 psktool.1 p11tool.1 ocsptool.1 tpmtool.1
 if ENABLE_SRP
 dist_man_MANS += srptool.1
 endif
 if ENABLE_DANE
 dist_man_MANS += danetool.1
 endif
+endif
 
 # Note that our .def files depend on autogen
 # supporting the @subheading texi keyword. This
-- 
2.0.5

