Author: Sergei Golovan
Description: Patch enable dynamic linking to system-wide libjpeg.
 It is a Debian-specific hack and isn't supposed to be forwarded upstream.
Last-Modified: Wed, 31 Jan 2018 11:42:16 +0300

--- a/libjpeg/Makefile.in
+++ b/libjpeg/Makefile.in
@@ -158,9 +158,9 @@
 CONFIG_CLEAN_FILES = Makefile
 
 CPPFLAGS	= @CPPFLAGS@
-LIBS		= @PKG_LIBS@ @LIBS@
+LIBS		= @PKG_LIBS@ @LIBS@ -ljpeg
 AR		= @AR@
-CFLAGS		= @CFLAGS@ -DJPEGTCLAPI=MODULE_SCOPE -I$(srcdir)/../base
+CFLAGS		= @CFLAGS@ -DJPEGTCLAPI=MODULE_SCOPE -I$(srcdir)/../base -DMODULE_SCOPE=extern
 COMPILE		= $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 
 .SUFFIXES: .c .$(OBJEXT)
--- a/libjpeg/configure
+++ b/libjpeg/configure
@@ -5737,60 +5737,6 @@
 
 
 
-
-    vars="
-	../compat/libjpeg/jcapimin.c	../compat/libjpeg/jcapistd.c	../compat/libjpeg/jccoefct.c
-	../compat/libjpeg/jccolor.c	../compat/libjpeg/jcdctmgr.c	../compat/libjpeg/jchuff.c
-	../compat/libjpeg/jcinit.c	../compat/libjpeg/jcmainct.c	../compat/libjpeg/jcmarker.c
-	../compat/libjpeg/jcmaster.c	../compat/libjpeg/jcomapi.c	../compat/libjpeg/jcparam.c
-	../compat/libjpeg/jcarith.c	../compat/libjpeg/jcprepct.c	../compat/libjpeg/jcsample.c
-	../compat/libjpeg/jctrans.c	../compat/libjpeg/jdapimin.c	../compat/libjpeg/jdapistd.c
-	../compat/libjpeg/jdatadst.c	../compat/libjpeg/jdatasrc.c	../compat/libjpeg/jdcoefct.c
-	../compat/libjpeg/jdcolor.c	../compat/libjpeg/jddctmgr.c	../compat/libjpeg/jdhuff.c
-	../compat/libjpeg/jdinput.c	../compat/libjpeg/jdmainct.c	../compat/libjpeg/jdmarker.c
-	../compat/libjpeg/jdmaster.c	../compat/libjpeg/jdmerge.c	../compat/libjpeg/jdarith.c
-	../compat/libjpeg/jdpostct.c	../compat/libjpeg/jdsample.c	../compat/libjpeg/jdtrans.c
-	../compat/libjpeg/jerror.c	../compat/libjpeg/jfdctflt.c	../compat/libjpeg/jfdctfst.c
-	../compat/libjpeg/jfdctint.c	../compat/libjpeg/jidctflt.c	../compat/libjpeg/jidctfst.c
-	../compat/libjpeg/jidctint.c	../compat/libjpeg/jaricom.c	../compat/libjpeg/jquant1.c
-	../compat/libjpeg/jquant2.c	../compat/libjpeg/jutils.c	../compat/libjpeg/jmemmgr.c
-	../compat/libjpeg/jmemansi.c
-"
-    for i in $vars; do
-	case $i in
-	    \$*)
-		# allow $-var names
-		PKG_SOURCES="$PKG_SOURCES $i"
-		PKG_OBJECTS="$PKG_OBJECTS $i"
-		;;
-	    *)
-		# check for existence - allows for generic/win/unix VPATH
-		# To add more dirs here (like 'src'), you have to update VPATH
-		# in Makefile.in as well
-		if test ! -f "${srcdir}/$i" -a ! -f "${srcdir}/generic/$i" \
-		    -a ! -f "${srcdir}/win/$i" -a ! -f "${srcdir}/unix/$i" \
-		    -a ! -f "${srcdir}/macosx/$i" \
-		    ; then
-		    as_fn_error $? "could not find source file '$i'" "$LINENO" 5
-		fi
-		PKG_SOURCES="$PKG_SOURCES $i"
-		# this assumes it is in a VPATH dir
-		i=`basename $i`
-		# handle user calling this before or after TEA_SETUP_COMPILER
-		if test x"${OBJEXT}" != x ; then
-		    j="`echo $i | sed -e 's/\.[^.]*$//'`.${OBJEXT}"
-		else
-		    j="`echo $i | sed -e 's/\.[^.]*$//'`.\${OBJEXT}"
-		fi
-		PKG_OBJECTS="$PKG_OBJECTS $j"
-		;;
-	esac
-    done
-
-
-
-
-
     vars="jpegtcl.h jpegtclDecls.h"
     for i in $vars; do
 	# check for existence, be strict because it is installed
@@ -9650,28 +9596,6 @@
 
 
 #--------------------------------------------------------------------
-# We call the configure for the jpeg code on our own, without using
-# AC_CONFIG_SUBDIR ... Using that requires a symlink, thus making setup
-# difficult, and the transfer information ot it is busted, due to how
-# TEA handles CFLAGS.
-#--------------------------------------------------------------------
-
-case "$srcdir" in
-.) # No --srcdir option.  We are building in place.
-  jpegdir=../$srcdir/../compat/libjpeg ;;
-/*) # Absolute path.
-  jpegdir=$srcdir/../compat/libjpeg ;;
-*) # Relative path.
-  jpegdir=../$ac_dots$srcdir/../compat/libjpeg ;;
-esac
-
-mkdir -p libjpeg
-sleep 2        ; # Wait two seconds for the directory to actually appear (Windows).
-cd    libjpeg
-env CC="$JPEG_CC" CFLAGS="$JPEG_CFLAGS" $jpegdir/configure --enable-maxmem=500
-cd ..
-
-#--------------------------------------------------------------------
 # Finally, substitute all of the various values into the Makefile.
 # You may alternatively have a special pkgIndex.tcl.in or other files
 # which require substituting th AC variables in.  Include these here.
--- a/libjpeg/configure.ac
+++ b/libjpeg/configure.ac
@@ -53,24 +53,6 @@
 
 TEA_ADD_SOURCES([jpegtcl.c jpegtclStubInit.c])
 
-TEA_ADD_SOURCES([
-	../compat/libjpeg/jcapimin.c	../compat/libjpeg/jcapistd.c	../compat/libjpeg/jccoefct.c
-	../compat/libjpeg/jccolor.c	../compat/libjpeg/jcdctmgr.c	../compat/libjpeg/jchuff.c
-	../compat/libjpeg/jcinit.c	../compat/libjpeg/jcmainct.c	../compat/libjpeg/jcmarker.c
-	../compat/libjpeg/jcmaster.c	../compat/libjpeg/jcomapi.c	../compat/libjpeg/jcparam.c
-	../compat/libjpeg/jcarith.c	../compat/libjpeg/jcprepct.c	../compat/libjpeg/jcsample.c
-	../compat/libjpeg/jctrans.c	../compat/libjpeg/jdapimin.c	../compat/libjpeg/jdapistd.c
-	../compat/libjpeg/jdatadst.c	../compat/libjpeg/jdatasrc.c	../compat/libjpeg/jdcoefct.c
-	../compat/libjpeg/jdcolor.c	../compat/libjpeg/jddctmgr.c	../compat/libjpeg/jdhuff.c
-	../compat/libjpeg/jdinput.c	../compat/libjpeg/jdmainct.c	../compat/libjpeg/jdmarker.c
-	../compat/libjpeg/jdmaster.c	../compat/libjpeg/jdmerge.c	../compat/libjpeg/jdarith.c
-	../compat/libjpeg/jdpostct.c	../compat/libjpeg/jdsample.c	../compat/libjpeg/jdtrans.c
-	../compat/libjpeg/jerror.c	../compat/libjpeg/jfdctflt.c	../compat/libjpeg/jfdctfst.c
-	../compat/libjpeg/jfdctint.c	../compat/libjpeg/jidctflt.c	../compat/libjpeg/jidctfst.c
-	../compat/libjpeg/jidctint.c	../compat/libjpeg/jaricom.c	../compat/libjpeg/jquant1.c
-	../compat/libjpeg/jquant2.c	../compat/libjpeg/jutils.c	../compat/libjpeg/jmemmgr.c
-	../compat/libjpeg/jmemansi.c
-])
 
 TEA_ADD_HEADERS([jpegtcl.h jpegtclDecls.h])
 
@@ -186,28 +168,6 @@
 TEA_EXPORT_CONFIG(jpegtcl)
 
 #--------------------------------------------------------------------
-# We call the configure for the jpeg code on our own, without using
-# AC_CONFIG_SUBDIR ... Using that requires a symlink, thus making setup
-# difficult, and the transfer information ot it is busted, due to how
-# TEA handles CFLAGS.
-#--------------------------------------------------------------------
-
-case "$srcdir" in
-.) # No --srcdir option.  We are building in place.
-  jpegdir=../$srcdir/../compat/libjpeg ;;
-/*) # Absolute path.
-  jpegdir=$srcdir/../compat/libjpeg ;;
-*) # Relative path.
-  jpegdir=../$ac_dots$srcdir/../compat/libjpeg ;;
-esac
-
-mkdir -p libjpeg
-sleep 2        ; # Wait two seconds for the directory to actually appear (Windows).
-cd    libjpeg
-env CC="$JPEG_CC" CFLAGS="$JPEG_CFLAGS" $jpegdir/configure --enable-maxmem=500
-cd ..
-
-#--------------------------------------------------------------------
 # Finally, substitute all of the various values into the Makefile.
 # You may alternatively have a special pkgIndex.tcl.in or other files
 # which require substituting th AC variables in.  Include these here.
--- a/libjpeg/jpegtclDecls.h
+++ b/libjpeg/jpegtclDecls.h
@@ -31,8 +31,8 @@
 /* undef Tcl macros that conflict with libjpeg stuff (sigh) */
 #undef EXTERN
 
-#include "../compat/libjpeg/jpeglib.h"
-#include "../compat/libjpeg/jerror.h"
+#include "/usr/include/jpeglib.h"
+#include "/usr/include/jerror.h"
 
 /* !BEGIN!: Do not edit below this line. */
 
--- a/libjpeg/jpegtcl.decls
+++ b/libjpeg/jpegtcl.decls
@@ -175,7 +175,7 @@
 declare 47 {
     boolean jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired)
 }
-declare 48 {
+declare 48 generic {!JPEG_LIB_VERSION_GE_94} {
     JHUFF_TBL *jpeg_std_huff_table (j_common_ptr cinfo, boolean isDC, int tblno)
 }
 
--- a/libjpeg/jpegtcl.h
+++ b/libjpeg/jpegtcl.h
@@ -30,6 +30,12 @@
 #define JPEGTCL_VERSION         "9.6.0"
 #define JPEGTCL_PATCH_LEVEL     "9.6.0"
 
+#if defined(JPEG_LIB_VERSION_MAJOR) &&                                         \
+    (JPEG_LIB_VERSION_MAJOR > 9 ||                                             \
+     (JPEG_LIB_VERSION_MAJOR == 9 && JPEG_LIB_VERSION_MINOR >= 4))
+#   define JPEG_LIB_VERSION_GE_94
+#endif
+
 /*
  * Used to block the rest of this header file from resource compilers so
  * we can just get the version info.
--- a/libjpeg/jpegtclStubInit.c
+++ b/libjpeg/jpegtclStubInit.c
@@ -68,7 +68,11 @@
     jpeg_abort, /* 45 */
     jpeg_destroy, /* 46 */
     jpeg_resync_to_restart, /* 47 */
+#if !defined(JPEG_LIB_VERSION_GE_94)
+    0, /* 48 */
+#else  /* !JPEG_LIB_VERSION_GE_94 */
     jpeg_std_huff_table, /* 48 */
+#endif /* !JPEG_LIB_VERSION_GE_94 */
 };
 
 /* !END!: Do not edit above this line. */
