From: Ole Streicher <debian@liska.ath.cx>
Date: Sat, 15 Oct 2016 14:49:02 +0200
Subject: Install the tcl interface to /usr/lib/tcltk/xpa according to
 Debian's policy.

Also use Tcl stubs.
---
 Makefile.in | 35 +++++++++++++++++++++++------------
 1 file changed, 23 insertions(+), 12 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index b77f2fa..bf29bdc 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -38,6 +38,7 @@ INSTALL_ROOT = $(DESTDIR)
 
 # Directory in which to install the .a or .so binary for the XPA library:
 LIB_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/lib/${DEB_HOST_MULTIARCH}
+TCL_LIB_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/lib/tcltk/${DEB_HOST_MULTIARCH}/xpa
 
 # Directory in which to install the program wish:
 BIN_INSTALL_DIR =	$(INSTALL_ROOT)$(exec_prefix)/bin
@@ -142,7 +143,7 @@ GTK_OBJS =	gtkloop.o
 INCL	=	xpa.h xpap.h
 
 # these are all the modules going into the "normal" xpa library
-LIBOBJS =	${BASE_OBJS} ${TCL_OBJS} ${XT_OBJS} ${GTK_OBJS}
+LIBOBJS =	${BASE_OBJS} ${XT_OBJS} ${GTK_OBJS}
 LIB =	libxpa.a
 
 # used in link line
@@ -169,6 +170,8 @@ install::	install-share
 
 install::	install-data
 
+install::	tclxpa_install
+
 lib:		$(LIB) $(DOSHARED)
 
 $(LIB):		$(LIBOBJS)
@@ -192,14 +195,17 @@ mingw-dll:	$(LIBOBJS)
 		-Wl,--output-def,libxpa.def,--out-implib,libxpa_dll.a,-no-undefined,--enable-runtime-pseudo-reloc -o libxpa.dll \
 		-lwsock32
 
-tclxpa:		$(LIB)
-		@(rm -rf libtclxpa.tmp; mkdir libtclxpa.tmp; \
-		(cd libtclxpa.tmp && ar x ../lib$(PACKAGE).a); \
-		rm -f libtclxpa.tmp/xt*.o; \
-		CC='$(CC)' CXX=$(CXX) \
-		./mklib -o tclxpa libtclxpa.tmp/*.o $(TCL_LIBS); \
-		test -r libtclxpa.dylib && cp -p libtclxpa.dylib libtclxpa.so && echo "copying libtclxpa.dylib to libtclxpa.so"; \
-		rm -rf libtclxpa.tmp)
+
+tclxpa:		$(TCL_OBJS)
+		ar cruv libtclxpa.a $(TCL_OBJS)
+		$(RANLIB) libtclxpa.a
+
+shtclxpa:	tclxpa
+		@(rm -rf $(PACKAGE)tmp; mkdir $(PACKAGE)tmp; \
+		(cd $(PACKAGE)tmp && ar x ../libtclxpa.a); \
+		CC='$(CC)' CXX='$(CXX)' \
+		./mklib -o tclxpa -L. -lxpa $(PACKAGE)tmp/*.o -ltclstub; \
+		rm -rf $(PACKAGE)tmp; )
 
 diff:
 		-(for f in `ls *.c`;					\
@@ -258,7 +264,7 @@ smoke:  ctest stest
 _install:
 
 shlib_install:
-	@-(for i in `ls *.so* *.dylib *.sl 2>/dev/null` ; \
+	@-(for i in `ls libxpa.so* *.dylib *.sl 2>/dev/null` ; \
 	   do \
 	   if [ -h $$i ] ; then \
 		echo "Installing link $$i" ; \
@@ -270,6 +276,11 @@ shlib_install:
 	   fi; \
 	   done;)
 
+tclxpa_install: shtclxpa
+	mkdir -p $(TCL_LIB_INSTALL_DIR)
+	$(INSTALL_DATA) libtclxpa.so $(TCL_LIB_INSTALL_DIR)
+	$(INSTALL_DATA) pkgIndex.tcl $(TCL_LIB_INSTALL_DIR)
+
 install-binaries: $(LIB) $(PROGS)
 	@for i in $(LIB_INSTALL_DIR) $(INCLUDE_INSTALL_DIR) $(BIN_INSTALL_DIR) ; \
 	    do \
@@ -388,10 +399,10 @@ port.o:		port.c $(INCL)
 		$(CC) -c $(CC_SWITCHES) port.c
 
 tcl.o:		tcl.c $(INCL)
-		$(CC) -c $(CC_SWITCHES) $(TCL_CFLAGS) tcl.c
+		$(CC) -c $(CC_SWITCHES) $(TCL_CFLAGS) -DUSE_TCL_STUBS=1 tcl.c
 
 tclloop.o:	tclloop.c $(INCL)
-		$(CC) -c $(CC_SWITCHES) $(TCL_CFLAGS) tclloop.c
+		$(CC) -c $(CC_SWITCHES) $(TCL_CFLAGS) -DUSE_TCL_STUBS=1 tclloop.c
 
 gtkloop.o:	gtkloop.c $(INCL)
 		$(CC) -c $(CC_SWITCHES) $(GTK_CFLAGS) gtkloop.c
