libtiff: Add options for disabling tools, tests, contrib and docs

From 1ab0e2696a368a556b793a0941b5365e4d9f56ef Mon Sep 17 00:00:00 2001
From: Roger Leigh <[EMAIL REDACTED]>
Date: Sun, 29 May 2022 11:18:42 +0100
Subject: [PATCH] Add options for disabling tools, tests, contrib and docs

---
 CMakeLists.txt               | 33 +++++++++++++++++++++------
 Makefile.am                  |  2 ++
 configure.ac                 | 44 ++++++++++++++++++++++++++++++++++--
 contrib/addtiffo/Makefile.am |  2 ++
 contrib/dbs/Makefile.am      |  2 ++
 contrib/iptcutil/Makefile.am |  2 ++
 html/Makefile.am             |  5 +++-
 html/images/Makefile.am      |  5 +++-
 html/man/Makefile.am         |  6 ++++-
 man/Makefile.am              | 12 ++++++++--
 test/Makefile.am             |  4 ++++
 tools/Makefile.am            |  4 ++++
 12 files changed, 107 insertions(+), 14 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 770b0fac..d1dd275e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -42,10 +42,16 @@ message(STATUS "libtiff build date: ${BUILD_DATE}")
 
 set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries")
 
+option(tiff-tools "build TIFF tools" ON)
+option(tiff-tests "build TIFF tests" ON)
+option(tiff-contrib "build TIFF contrib" ON)
+option(tiff-docs "build TIFF documentation" ON)
+option(tiff-deprecated "build TIFF deprecated features" OFF)
 
 # Disable deprecated features to ensure clean build
-add_definitions(-DTIFF_DISABLE_DEPRECATED)
-
+if (tiff-deprecated)
+  add_definitions(-DTIFF_DISABLE_DEPRECATED)
+endif()
 
 # Project definition
 set(CMAKE_C_STANDARD 99)
@@ -135,12 +141,20 @@ include(Release)
 # Process subdirectories
 add_subdirectory(port)
 add_subdirectory(libtiff)
-add_subdirectory(tools)
-add_subdirectory(test)
-add_subdirectory(contrib)
+if(tiff-tools)
+  add_subdirectory(tools)
+endif()
+if(tiff-tests)
+  add_subdirectory(test)
+endif()
+if(tiff-contrib)
+  add_subdirectory(contrib)
+endif()
 add_subdirectory(build)
-add_subdirectory(man)
-add_subdirectory(html)
+if(tiff-docs)
+  add_subdirectory(man)
+  add_subdirectory(html)
+endif()
 
 # pkg-config support
 include(PkgConfig)
@@ -153,6 +167,11 @@ message(STATUS "  Documentation directory:            ${LIBTIFF_DOCDIR}")
 message(STATUS "  C compiler:                         ${CMAKE_C_COMPILER}")
 message(STATUS "  C++ compiler:                       ${CMAKE_CXX_COMPILER}")
 message(STATUS "  Build shared libraries:             ${BUILD_SHARED_LIBS}")
+message(STATUS "  Build tools:                        ${tiff-tools}")
+message(STATUS "  Build tests:                        ${tiff-tests}")
+message(STATUS "  Build contrib:                      ${tiff-contrib}")
+message(STATUS "  Build docs:                         ${tiff-docs}")
+message(STATUS "  Build deprecated features:          ${tiff-deprecated}")
 message(STATUS "  Enable linker symbol versioning:    ${HAVE_LD_VERSION_SCRIPT}")
 message(STATUS "  Support Microsoft Document Imaging: ${mdi}")
 message(STATUS "  Use win32 IO:                       ${USE_WIN32_FILEIO}")
diff --git a/Makefile.am b/Makefile.am
index aaabf4d1..0d939e1e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -44,7 +44,9 @@ EXTRA_DIST = \
 	autogen.sh \
 	libtiff-4.pc.in
 
+if TIFF_DOCS
 dist_doc_DATA = $(docfiles)
+endif
 
 distcheck-hook:
 	if [ -x "$(CMAKE)" ]; then \
diff --git a/configure.ac b/configure.ac
index 23e834a2..891e8cbb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -198,8 +198,15 @@ dnl ---------------------------------------------------------------------------
 dnl Deprecated features and backward compatibilty
 dnl ---------------------------------------------------------------------------
 
-# Disable deprecated features to ensure clean build
-CPPFLAGS="-DTIFF_DISABLE_DEPRECATED $CPPFLAGS"
+AC_ARG_ENABLE([deprecated],
+  AS_HELP_STRING([--enable-deprecated],
+      [enable deprecated features (default is disabled)]),
+      [enable_deprecated=$enableval], [enable_deprecated=no])
+
+if test "$enable_deprecated" = "yes"; then
+  # Disable deprecated features to ensure clean build
+  CPPFLAGS="-DTIFF_DISABLE_DEPRECATED $CPPFLAGS"
+fi
 
 dnl ---------------------------------------------------------------------------
 dnl Compute sized types for current CPU and compiler options
@@ -316,6 +323,34 @@ fi
 AC_SUBST(LIBTIFF_DOCDIR)
 
 
+dnl ---------------------------------------------------------------------------
+dnl Enable or disable parts of the build
+dnl ---------------------------------------------------------------------------
+
+AC_ARG_ENABLE(tools,
+              AS_HELP_STRING([--disable-tools],
+                             [Disable building of tools]),
+                             [TIFF_TOOLS=$enableval], [TIFF_TOOLS=yes])
+AM_CONDITIONAL(TIFF_TOOLS, test "$TIFF_TOOLS" = "yes")
+
+AC_ARG_ENABLE(tests,
+              AS_HELP_STRING([--disable-tests],
+                             [Disable building of tests]),
+                             [TIFF_TESTS=$enableval], [TIFF_TESTS=yes])
+AM_CONDITIONAL(TIFF_TESTS, test "$TIFF_TESTS" = "yes")
+
+AC_ARG_ENABLE(contrib,
+              AS_HELP_STRING([--disable-contrib],
+                             [Disable building of contrib]),
+                             [TIFF_CONTRIB=$enableval], [TIFF_CONTRIB=yes])
+AM_CONDITIONAL(TIFF_CONTRIB, test "$TIFF_CONTRIB" = "yes")
+
+AC_ARG_ENABLE(docs,
+              AS_HELP_STRING([--disable-docs],
+                             [Disable building of docs]),
+                             [TIFF_DOCS=$enableval], [TIFF_DOCS=yes])
+AM_CONDITIONAL(TIFF_DOCS, test "$TIFF_DOCS" = "yes")
+
 
 dnl ---------------------------------------------------------------------------
 dnl Switch on/off internal codecs.
@@ -1128,6 +1163,11 @@ LOC_MSG([  Installation directory:             ${prefix}])
 LOC_MSG([  Documentation directory:            ${LIBTIFF_DOCDIR}])
 LOC_MSG([  C compiler:                         ${CC} ${CFLAGS}])
 LOC_MSG([  C++ compiler:                       ${CXX} ${CXXFLAGS}])
+LOC_MSG([  Build tools:                        ${TIFF_TOOLS}])
+LOC_MSG([  Build tests:                        ${TIFF_TESTS}])
+LOC_MSG([  Build contrib:                      ${TIFF_CONTRIB}])
+LOC_MSG([  Build docs:                         ${TIFF_DOCS}])
+LOC_MSG([  Build deprecated features:          ${enable_deprecated}])
 LOC_MSG([  Enable runtime linker paths:        ${HAVE_RPATH}])
 LOC_MSG([  Enable linker symbol versioning:    ${have_ld_version_script}])
 LOC_MSG([  Support Microsoft Document Imaging: ${HAVE_MDI}])
diff --git a/contrib/addtiffo/Makefile.am b/contrib/addtiffo/Makefile.am
index 3f817c6f..f8f15fcd 100644
--- a/contrib/addtiffo/Makefile.am
+++ b/contrib/addtiffo/Makefile.am
@@ -29,7 +29,9 @@ EXTRA_DIST = \
 	CMakeLists.txt \
 	README
 
+if TIFF_CONTRIB
 noinst_PROGRAMS = addtiffo
+endif
 
 addtiffo_SOURCES = addtiffo.c tif_overview.c tif_ovrcache.c tif_ovrcache.h
 addtiffo_LDADD = $(LIBTIFF)
diff --git a/contrib/dbs/Makefile.am b/contrib/dbs/Makefile.am
index 90697eed..191d9346 100644
--- a/contrib/dbs/Makefile.am
+++ b/contrib/dbs/Makefile.am
@@ -31,7 +31,9 @@ EXTRA_DIST = \
 	CMakeLists.txt \
 	README
 
+if TIFF_CONTRIB
 noinst_PROGRAMS = tiff-bi tiff-grayscale tiff-palette tiff-rgb
+endif
 
 tiff_bi_SOURCES = tiff-bi.c
 tiff_bi_LDADD = $(LIBTIFF)
diff --git a/contrib/iptcutil/Makefile.am b/contrib/iptcutil/Makefile.am
index 4aabe2e9..ca79306a 100644
--- a/contrib/iptcutil/Makefile.am
+++ b/contrib/iptcutil/Makefile.am
@@ -31,7 +31,9 @@ EXTRA_DIST = \
 	test.iptc \
 	test.txt
 
+if TIFF_CONTRIB
 noinst_PROGRAMS = iptcutil
+endif
 
 iptcutil_SOURCES = iptcutil.c
 iptcutil_LDADD = $(LIBTIFF)
diff --git a/html/Makefile.am b/html/Makefile.am
index cd1483bd..383e3faa 100644
--- a/html/Makefile.am
+++ b/html/Makefile.am
@@ -93,9 +93,12 @@ docfiles = \
 	v4.3.0.html \
 	v4.4.0.html
 
-dist_doc_DATA = $(docfiles)
+if TIFF_DOCS
+doc_DATA = $(docfiles)
+endif
 
 SUBDIRS = images man
 
 EXTRA_DIST = \
+	$(docfiles) \
 	CMakeLists.txt
diff --git a/html/images/Makefile.am b/html/images/Makefile.am
index 979c8582..15755391 100644
--- a/html/images/Makefile.am
+++ b/html/images/Makefile.am
@@ -43,7 +43,10 @@ docfiles = \
 	strike.gif \
 	warning.gif
 
-dist_doc_DATA = $(docfiles)
+if TIFF_DOCS
+doc_DATA = $(docfiles)
+endif
 
 EXTRA_DIST = \
+	$(docfiles) \
 	CMakeLists.txt
diff --git a/html/man/Makefile.am b/html/man/Makefile.am
index 3ed00d44..8c4e9056 100644
--- a/html/man/Makefile.am
+++ b/html/man/Makefile.am
@@ -96,7 +96,9 @@ docfiles = \
 	tiffset.1.html \
 	tiffsplit.1.html
 
-dist_doc_DATA = $(indexfile) $(docfiles)
+if TIFF_DOCS
+doc_DATA = $(indexfile) $(docfiles)
+endif
 
 INDEXSTART = '<HTML><HEAD><TITLE>Libtiff HTML manpage index</TITLE></HEAD><BODY BGCOLOR=white><ul><H2>Man Pages</h2><p>'
 INDEXEND = '</ul></BODY></HTML>'
@@ -118,5 +120,7 @@ htmldoc:
 	done
 
 EXTRA_DIST = \
+	$(indexfile) \
+	$(docfiles) \
 	CMakeLists.txt \
 	HtmlDoc.cmake
diff --git a/man/Makefile.am b/man/Makefile.am
index 0fe9e4d0..7cc14608 100644
--- a/man/Makefile.am
+++ b/man/Makefile.am
@@ -23,7 +23,7 @@
 
 # Process this file with automake to produce Makefile.in.
 
-dist_man1_MANS = \
+man1_pages = \
 	fax2ps.1 \
 	fax2tiff.1 \
 	pal2rgb.1 \
@@ -44,7 +44,7 @@ dist_man1_MANS = \
 	tiffset.1 \
 	tiffsplit.1
 
-dist_man3_MANS = \
+man3_pages = \
 	libtiff.3tiff \
 	TIFFbuffer.3tiff \
 	TIFFClose.3tiff \
@@ -90,5 +90,13 @@ dist_man3_MANS = \
 	TIFFWriteScanline.3tiff \
 	TIFFWriteTile.3tiff
 
+if TIFF_DOCS
+man1_MANS = $(man1_pages)
+man3_MANS = $(man3_pages)
+endif
+
+
 EXTRA_DIST = \
+	$(man1_pages) \
+	$(man3_pages) \
 	CMakeLists.txt
diff --git a/test/Makefile.am b/test/Makefile.am
index b5823198..6df12122 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -44,7 +44,9 @@ EXTRA_DIST = \
 	TiffTest.cmake
 
 # All of the tests to execute via 'make check'
+if TIFF_TESTS
 TESTS = $(check_PROGRAMS) $(TESTSCRIPTS)
+endif
 
 # Tests which are expected to fail
 XFAIL_TESTS =
@@ -66,10 +68,12 @@ JPEG_DEPENDENT_TESTSCRIPTS=
 endif
 
 # Executable programs which need to be built in order to support tests
+if TIFF_TESTS
 check_PROGRAMS = \
 	ascii_tag long_tag short_tag strip_rw rewrite custom_dir custom_dir_EXIF_231 \
 	rational_precision2double defer_strile_loading defer_strile_writing test_directory \
 	testtypes test_signed_tags $(JPEG_DEPENDENT_CHECK_PROG)
+endif
 
 # Test scripts to execute
 TESTSCRIPTS = \
diff --git a/tools/Makefile.am b/tools/Makefile.am
index c8142b05..c6c4c8af 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -29,6 +29,7 @@ LIBTIFF = $(top_builddir)/libtiff/libtiff.la
 EXTRA_DIST = \
 	CMakeLists.txt
 
+if TIFF_TOOLS
 bin_PROGRAMS = \
 	fax2ps \
 	fax2tiff \
@@ -51,13 +52,16 @@ bin_PROGRAMS = \
 if HAVE_OPENGL
 bin_PROGRAMS += tiffgt
 endif
+endif
 
 EXTRA_PROGRAMS = rgb2ycbcr thumbnail
 
 # Executable programs which need to be built in order to support tests
+if TIFF_TESTS
 check_PROGRAMS = \
 	rgb2ycbcr \
 	thumbnail
+endif
 
 if HAVE_RPATH
 AM_LDFLAGS = $(LIBDIR)