build libtiff

Change-Id: Id9b6e1355147c3f68b9922db14f1b4904a05c686
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134650
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
diff --git a/Makefile.fetch b/Makefile.fetch
index 1064195..ccb3860 100644
--- a/Makefile.fetch
+++ b/Makefile.fetch
@@ -159,6 +159,7 @@ $(WORKDIR)/download: $(BUILDDIR)/config_$(gb_Side).mk $(SRCDIR)/download.lst $(S
		$(call fetch_Optional,LIBLANGTAG,LIBLANGTAG_TARBALL) \
		$(call fetch_Optional,LIBNUMBERTEXT,LIBNUMBERTEXT_TARBALL) \
		$(call fetch_Optional,LIBPNG,LIBPNG_TARBALL) \
		$(call fetch_Optional,LIBTIFF,LIBTIFF_TARBALL) \
		$(call fetch_Optional,LIBTOMMATH,LIBTOMMATH_TARBALL) \
		$(call fetch_Optional,LIBWEBP,LIBWEBP_TARBALL) \
		$(call fetch_Optional,LIBXML2,LIBXML_TARBALL) \
diff --git a/RepositoryExternal.mk b/RepositoryExternal.mk
index 590a609..fa97dc3 100644
--- a/RepositoryExternal.mk
+++ b/RepositoryExternal.mk
@@ -2607,6 +2607,55 @@ endef

endif # !SYSTEM_LIBPNG

ifneq ($(SYSTEM_LIBTIFF),)

define gb_LinkTarget__use_libtiff
$(call gb_LinkTarget_set_include,$(1),\
	$$(INCLUDE) \
	$(LIBTIFF_CFLAGS) \
)

$(call gb_LinkTarget_add_libs,$(1),\
	$(LIBTIFF_LIBS) \
)

endef

gb_ExternalProject__use_libtiff :=

else # !SYSTEM_LIBTIFF

define gb_LinkTarget__use_libtiff
$(call gb_LinkTarget_set_include,$(1),\
	$(LIBTIFF_CFLAGS) \
	$$(INCLUDE) \
)

$(call gb_LinkTarget_set_include,$(1),\
	-I$(call gb_UnpackedTarball_get_dir,libtiff)/src \
	$$(INCLUDE) \
)
ifeq ($(OS),WNT)
$(call gb_LinkTarget_add_libs,$(1),\
	$(call gb_UnpackedTarball_get_dir,libtiff)/libtiff/.libs/libtiff$(gb_StaticLibrary_PLAINEXT) \
)
else
$(call gb_LinkTarget_add_libs,$(1),\
	-L$(call gb_UnpackedTarball_get_dir,libtiff)/libtiff/.libs -ltiff \
)
endif
$(call gb_LinkTarget_use_external_project,$(1),libtiff)

endef

define gb_ExternalProject__use_libtiff
$(call gb_ExternalProject_use_external_project,$(1),\
	libtiff \
)

endef

endif # !SYSTEM_LIBTIFF

ifneq ($(SYSTEM_LIBWEBP),)

diff --git a/bin/lo-all-static-libs b/bin/lo-all-static-libs
index fbe6d70..af4ff25 100755
--- a/bin/lo-all-static-libs
+++ b/bin/lo-all-static-libs
@@ -123,6 +123,7 @@ echo $INSTDIR/$LIBO_LIB_FOLDER/lib*.a \
     $WORKDIR/UnpackedTarball/liborcus/src/*/.libs/*.a \
     $WORKDIR/UnpackedTarball/librevenge/src/*/.libs/*.a \
     $WORKDIR/UnpackedTarball/libvisio/src/lib/.libs/*.a \
     $WORKDIR/UnpackedTarball/libtiff/libtiff/.libs/*.a \
     $WORKDIR/UnpackedTarball/libwebp/src/.libs/*.a \
     $WORKDIR/UnpackedTarball/libwp?/src/lib/.libs/*.a \
     $WORKDIR/UnpackedTarball/raptor/src/.libs/*.a \
diff --git a/config_host.mk.in b/config_host.mk.in
index df8205e8..4d45a94 100644
--- a/config_host.mk.in
+++ b/config_host.mk.in
@@ -417,6 +417,8 @@ export LIBPNG_CFLAGS=$(gb_SPACE)@LIBPNG_CFLAGS@
export LIBPNG_LIBS=$(gb_SPACE)@LIBPNG_LIBS@
export LIBREPOSITORY_JAR=@LIBREPOSITORY_JAR@
export LIBSERIALIZER_JAR=@LIBSERIALIZER_JAR@
export LIBTIFF_CFLAGS=$(gb_SPACE)@LIBTIFF_CFLAGS@
export LIBTIFF_LIBS=$(gb_SPACE)@LIBTIFF_LIBS@
export LIBTOMMATH_CFLAGS=@LIBTOMMATH_CFLAGS@
export LIBTOMMATH_LIBS=@LIBTOMMATH_LIBS@
export LIBTOOL=@LIBTOOL@
@@ -644,6 +646,7 @@ export SYSTEM_LIBNUMBERTEXT=@SYSTEM_LIBNUMBERTEXT@
export SYSTEM_LIBNUMBERTEXT_DATA=@SYSTEM_LIBNUMBERTEXT_DATA@
export SYSTEM_LIBORCUS=@SYSTEM_LIBORCUS@
export SYSTEM_LIBPNG=@SYSTEM_LIBPNG@
export SYSTEM_LIBTIFF=@SYSTEM_LIBTIFF@
export SYSTEM_LIBTOMMATH=@SYSTEM_LIBTOMMATH@
export SYSTEM_LIBWEBP=@SYSTEM_LIBWEBP@
export SYSTEM_LIBXML=@SYSTEM_LIBXML@
diff --git a/configure.ac b/configure.ac
index 34ba3f7..186c472 100644
--- a/configure.ac
+++ b/configure.ac
@@ -13556,6 +13556,12 @@ LIBPNG_LIBS_internal="-L${WORKDIR}/LinkTarget/StaticLibrary -llibpng"
libo_CHECK_SYSTEM_MODULE([libpng],[LIBPNG],[libpng])

dnl ===================================================================
dnl Test whether to build libtiff or rely on the system version
dnl ===================================================================

libo_CHECK_SYSTEM_MODULE([libtiff],[LIBTIFF],[libtiff])

dnl ===================================================================
dnl Test whether to build libwebp or rely on the system version
dnl ===================================================================

diff --git a/download.lst b/download.lst
index e57bce7..be1eaa4 100644
--- a/download.lst
+++ b/download.lst
@@ -208,6 +208,8 @@ export PIXMAN_SHA256SUM := 6d200dec3740d9ec4ec8d1180e25779c00bc749f94278c8b9021f
export PIXMAN_TARBALL := pixman-0.40.0.tar.gz
export LIBPNG_SHA256SUM := 505e70834d35383537b6491e7ae8641f1a4bed1876dbfe361201fc80868d88ca
export LIBPNG_TARBALL := libpng-1.6.37.tar.xz
export LIBTIFF_SHA256SUM := 0e46e5acb087ce7d1ac53cf4f56a09b221537fc86dfc5daaad1c2e89e1b37ac8
export LIBTIFF_TARBALL := tiff-4.3.0.tar.gz
export POPPLER_SHA256SUM := 7d3493056b5b86413e5c693c2cae02c5c06cd8e618d14c2c31e2c84b67b2313e
export POPPLER_TARBALL := poppler-22.01.0.tar.xz
export POPPLER_DATA_SHA256SUM := 2cec05cd1bb03af98a8b06a1e22f6e6e1a65b1e2f3816cb3069bb0874825f08c
diff --git a/external/Module_external.mk b/external/Module_external.mk
index 4f97609..c8ad9ae 100644
--- a/external/Module_external.mk
+++ b/external/Module_external.mk
@@ -61,6 +61,7 @@ $(eval $(call gb_Module_add_moduledirs,external,\
	$(call gb_Helper_optional,LIBLANGTAG,liblangtag) \
	$(call gb_Helper_optional,LIBNUMBERTEXT,libnumbertext) \
	$(call gb_Helper_optional,LIBPNG,libpng) \
	$(call gb_Helper_optional,LIBTIFF,libtiff) \
	$(call gb_Helper_optional,LIBWEBP,libwebp) \
	$(call gb_Helper_optional,LIBXML2,libxml2) \
	$(call gb_Helper_optional,LIBXSLT,libxslt) \
diff --git a/external/libtiff/ExternalProject_libtiff.mk b/external/libtiff/ExternalProject_libtiff.mk
new file mode 100644
index 0000000..9933a4c
--- /dev/null
+++ b/external/libtiff/ExternalProject_libtiff.mk
@@ -0,0 +1,44 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

$(eval $(call gb_ExternalProject_ExternalProject,libtiff))

$(eval $(call gb_ExternalProject_register_targets,libtiff,\
	build \
))

$(eval $(call gb_ExternalProject_use_autoconf,libtiff,build))

$(call gb_ExternalProject_get_state_target,libtiff,build) :
	$(call gb_Trace_StartRange,libtiff,EXTERNAL)
	$(call gb_ExternalProject_run,build,\
		export PKG_CONFIG="" \
		&& MAKE=$(MAKE) $(gb_RUN_CONFIGURE) ./configure \
			--enable-static \
			--with-pic \
			--disable-shared \
			--disable-cxx \
			--disable-jbig \
			--disable-jpeg \
			--disable-lzma \
			--disable-mdi \
			--disable-webp \
			--disable-win32-io \
			--disable-zstd \
			--without-x \
			$(if $(verbose),--disable-silent-rules,--enable-silent-rules) \
			CFLAGS="$(CFLAGS) $(call gb_ExternalProject_get_build_flags,libtiff)" \
			CPPFLAGS="$(CPPFLAGS) $(BOOST_CPPFLAGS)" \
			LDFLAGS="$(call gb_ExternalProject_get_link_flags,libtiff)" \
			$(gb_CONFIGURE_PLATFORMS) \
		&& $(MAKE) \
	)
	$(call gb_Trace_EndRange,libtiff,EXTERNAL)

# vim: set noet sw=4 ts=4:
diff --git a/external/libtiff/Makefile b/external/libtiff/Makefile
new file mode 100644
index 0000000..e4968cf8
--- /dev/null
+++ b/external/libtiff/Makefile
@@ -0,0 +1,7 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-

module_directory:=$(dir $(realpath $(firstword $(MAKEFILE_LIST))))

include $(module_directory)/../../solenv/gbuild/partial_build.mk

# vim: set noet sw=4 ts=4:
diff --git a/external/libtiff/Module_libtiff.mk b/external/libtiff/Module_libtiff.mk
new file mode 100644
index 0000000..adf8114
--- /dev/null
+++ b/external/libtiff/Module_libtiff.mk
@@ -0,0 +1,17 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

$(eval $(call gb_Module_Module,libtiff))

$(eval $(call gb_Module_add_targets,libtiff,\
	ExternalProject_libtiff \
	UnpackedTarball_libtiff \
))

# vim: set noet sw=4 ts=4:
diff --git a/external/libtiff/UnpackedTarball_libtiff.mk b/external/libtiff/UnpackedTarball_libtiff.mk
new file mode 100644
index 0000000..30701ed
--- /dev/null
+++ b/external/libtiff/UnpackedTarball_libtiff.mk
@@ -0,0 +1,16 @@
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

$(eval $(call gb_UnpackedTarball_UnpackedTarball,libtiff))

$(eval $(call gb_UnpackedTarball_set_tarball,libtiff,$(LIBTIFF_TARBALL)))

$(eval $(call gb_UnpackedTarball_set_patchlevel,libtiff,0))

# vim: set noet sw=4 ts=4:
diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index a141e22..5828084 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -91,6 +91,7 @@ $(eval $(call gb_Library_use_externals,vcl,\
    libeot \
    libjpeg \
    libpng \
    libtiff \
    libwebp \
    mdds_headers \
))