From: Helmut Grohne <helmut@subdivi.de>
Date: Tue, 9 Aug 2016 18:11:49 +0200
Subject: Debian: Build mantohtml with the build architecture compiler

mantohtml is run during build. Thus it needs to be built with the build
architecture compiler (or execution fails). The obvious part is switching to
CC_FOR_BUILD. That also depends on it not requiring any other cups components.
In particular, removing uses of strlcpy and replacing host architecture-
specific includes is thus needed.

Bug-Debian: https://bugs.debian.org/837936
Forwarded: not-needed
---
 Makedefs.in     |  1 +
 configure.ac    |  9 +++++++++
 man/Makefile    |  5 ++---
 man/mantohtml.c | 15 ++++++++++-----
 4 files changed, 22 insertions(+), 8 deletions(-)

Index: cups/Makedefs.in
===================================================================
--- cups.orig/Makedefs.in	2022-02-21 04:35:06.386971790 +0000
+++ cups/Makedefs.in	2022-02-21 04:35:06.378971241 +0000
@@ -23,6 +23,7 @@
 AR		=	@AR@
 AWK		=	@AWK@
 CC		=	@LIBTOOL_CC@ @CC@
+CC_FOR_BUILD	=	@CC_FOR_BUILD@
 CHMOD		=	@CHMOD@
 CXX		=	@LIBTOOL_CXX@ @CXX@
 DSO		=	@DSO@
Index: cups/configure.ac
===================================================================
--- cups.orig/configure.ac	2022-02-21 04:35:06.386971790 +0000
+++ cups/configure.ac	2022-02-21 04:37:52.754384935 +0000
@@ -25,6 +25,16 @@
 sinclude(config-scripts/cups-common.m4)
 sinclude(config-scripts/cups-directories.m4)
 sinclude(config-scripts/cups-manpages.m4)
+
+AC_MSG_CHECKING([for build system compiler])
+if test "$cross_compiling" = yes; then
+       CC_FOR_BUILD=${CC_FOR_BUILD-cc}
+else
+       CC_FOR_BUILD=${CC}
+fi
+AC_MSG_RESULT(${CC_FOR_BUILD})
+AC_SUBST(CC_FOR_BUILD)
+
 sinclude(config-scripts/cups-sharedlibs.m4)
 sinclude(config-scripts/cups-libtool.m4)
 sinclude(config-scripts/cups-compiler.m4)
Index: cups/man/Makefile
===================================================================
--- cups.orig/man/Makefile	2022-02-21 04:35:06.386971790 +0000
+++ cups/man/Makefile	2022-02-21 04:35:06.378971241 +0000
@@ -222,6 +222,5 @@
 		./mantohtml $$file >../doc/help/man-`basename $$file .8`.html; \
 	done
 
-mantohtml:	mantohtml.o ../cups/$(LIBCUPSSTATIC)
-	$(LD_CC) $(ARCHFLAGS) $(ALL_LDFLAGS) -o $@ mantohtml.o $(LINKCUPSSTATIC)
-	$(CODE_SIGN) -s "$(CODE_SIGN_IDENTITY)" $@
+mantohtml:	mantohtml.c
+	$(CC_FOR_BUILD) -o $@ $<
Index: cups/man/mantohtml.c
===================================================================
--- cups.orig/man/mantohtml.c	2022-02-21 04:35:06.386971790 +0000
+++ cups/man/mantohtml.c	2022-02-21 04:35:06.378971241 +0000
@@ -11,8 +11,10 @@
  * Include necessary headers.
  */
 
-#include <cups/string-private.h>
-#include <cups/array-private.h>
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 
 
@@ -811,7 +813,8 @@
         * Anchor for HTML output...
         */
 
-        strlcpy(anchor, line + 4, sizeof(anchor));
+        strncpy(anchor, line + 4, sizeof(anchor) - 1);
+        anchor[sizeof(anchor) - 1] = '\0';
       }
       else if (strncmp(line, ".\\\"", 3))
       {
@@ -944,7 +947,8 @@
 		manfile[1024],		// Man page filename
 		manurl[1024];		// Man page URL
 
-        strlcpy(name, s, sizeof(name));
+        strncpy(name, s, sizeof(name) - 1);
+        name[sizeof(name) - 1] = '\0';
         if ((size_t)(end - s) < sizeof(name))
           name[end - s] = '\0';
 
