From bf089e15cb7963d268b6fc3902030c4797b76f41 Mon Sep 17 00:00:00 2001
From: Ryan Carsten Schmidt <git@ryandesign.com>
Date: Apr 25 2024 04:09:43 +0000
Subject: [PATCH 1/5] don't use python-config --includes or --libs


Includes are unnecessary because they are part of CFLAGS. Similarly,
libs are unnecessary because they are part of LDFLAGS.

---

diff --git a/Makefile.in b/Makefile.in
index 366776f..6b44233 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -92,13 +92,11 @@ _snack.$(SOEXT):   snack.c $(LIBNEWTSH)
 		fi; \
 		mkdir -p $$ver; \
 		PCFLAGS=`$$pyconfig --cflags`; \
-		PIFLAGS=`$$pyconfig --includes`; \
 		PLDFLAGS=`$$pyconfig --ldflags`; \
-		PLFLAGS=`$$pyconfig --libs`; \
-		echo $(CC) $(SHCFLAGS) $(CFLAGS) $(CPPFLAGS) $$PIFLAGS $$PCFLAGS -c -o $$ver/snack.o snack.c; \
-		$(CC) $(SHCFLAGS) $(CFLAGS) $(CPPFLAGS) $$PIFLAGS $$PCFLAGS -c -o $$ver/snack.o snack.c; \
-		echo $(CC) --shared $(LDFLAGS) $$PLDFLAGS $$PLFLAGS -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L.  -lnewt $(LIBS); \
-		$(CC) --shared $(LDFLAGS) $$PLDFLAGS $$PLFLAGS -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L.  -lnewt $(LIBS); \
+		echo $(CC) $(SHCFLAGS) $(CFLAGS) $(CPPFLAGS) $$PCFLAGS -c -o $$ver/snack.o snack.c; \
+		$(CC) $(SHCFLAGS) $(CFLAGS) $(CPPFLAGS) $$PCFLAGS -c -o $$ver/snack.o snack.c; \
+		echo $(CC) --shared $(LDFLAGS) $$PLDFLAGS -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L. -lnewt $(LIBS); \
+		$(CC) --shared $(LDFLAGS) $$PLDFLAGS -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L. -lnewt $(LIBS); \
 	done || :
 	touch $@
 

From 0d7020ef1d1af32903fdd00830217ba94f1affc5 Mon Sep 17 00:00:00 2001
From: Ryan Carsten Schmidt <git@ryandesign.com>
Date: Apr 25 2024 05:35:08 +0000
Subject: [PATCH 2/5] try python-config --ldflags --embed first


As of python 3.8, output of "python-config --ldflags" no longer includes
the "-lpython" flag without which the python module fails to link due to
undefined symbols. Use "python-config --ldflags --embed" to get it back
and fall back to "python-config --ldflags" for python 3.7 and older.

https://docs.python.org/3.8/whatsnew/3.8.html#debug-build-uses-the-same-abi-as-release-build

---

diff --git a/Makefile.in b/Makefile.in
index 6b44233..2133c3f 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -92,7 +92,7 @@ _snack.$(SOEXT):   snack.c $(LIBNEWTSH)
 		fi; \
 		mkdir -p $$ver; \
 		PCFLAGS=`$$pyconfig --cflags`; \
-		PLDFLAGS=`$$pyconfig --ldflags`; \
+		PLDFLAGS=`$$pyconfig --ldflags --embed || $$pyconfig --ldflags`; \
 		echo $(CC) $(SHCFLAGS) $(CFLAGS) $(CPPFLAGS) $$PCFLAGS -c -o $$ver/snack.o snack.c; \
 		$(CC) $(SHCFLAGS) $(CFLAGS) $(CPPFLAGS) $$PCFLAGS -c -o $$ver/snack.o snack.c; \
 		echo $(CC) --shared $(LDFLAGS) $$PLDFLAGS -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L. -lnewt $(LIBS); \

From b4d874d14e9027495d572a00763116fc988f6eab Mon Sep 17 00:00:00 2001
From: Ryan Carsten Schmidt <git@ryandesign.com>
Date: Apr 25 2024 05:44:52 +0000
Subject: [PATCH 3/5] don't silently ignore build/install errors


---

diff --git a/Makefile.in b/Makefile.in
index 2133c3f..335e71e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -83,7 +83,8 @@ showkey:	showkey.o $(LIBNEWT)
 	$(CC) -g -o showkey showkey.o $(LIBNEWT) $(LDFLAGS) $(LIBS)
 
 _snack.$(SOEXT):   snack.c $(LIBNEWTSH)
-	@[ -n "$(PYTHONVERS)" ] && for ver in $(PYTHONVERS); do \
+ifneq ($(PYTHONVERS),)
+	@for ver in $(PYTHONVERS); do \
 		pyconfig=$$ver-config; \
 		if ! $$pyconfig --cflags > /dev/null 2>&1 && \
 				python-config --cflags > /dev/null 2>&1; then \
@@ -97,7 +98,8 @@ _snack.$(SOEXT):   snack.c $(LIBNEWTSH)
 		$(CC) $(SHCFLAGS) $(CFLAGS) $(CPPFLAGS) $$PCFLAGS -c -o $$ver/snack.o snack.c; \
 		echo $(CC) --shared $(LDFLAGS) $$PLDFLAGS -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L. -lnewt $(LIBS); \
 		$(CC) --shared $(LDFLAGS) $$PLDFLAGS -o $$ver/_snack.$(SOEXT) $$ver/snack.o -L. -lnewt $(LIBS); \
-	done || :
+	done
+endif
 	touch $@
 
 whiptail: $(NDIALOGOBJS) $(LIBNEWTSH)
@@ -149,12 +151,16 @@ install-sh: sharedlib $(WHIPTCLSO) _snack.$(SOEXT)
 	install -m 755 $(LIBNEWTSH) $(instroot)/$(libdir)
 	ln -sf $(LIBNEWTSONAME) $(instroot)/$(libdir)/libnewt.$(SOEXT)
 	ln -sf $(LIBNEWTSH) $(instroot)/$(libdir)/$(LIBNEWTSONAME)
-	[ -n "$(WHIPTCLSO)" ] && install -m 755 whiptcl.$(SOEXT) $(instroot)/$(libdir) || :
-	[ -n "$(PYTHONVERS)" ] && for ver in $(PYTHONVERS) ; do \
+ifneq ($(WHIPTCLSO),)
+	install -m 755 $(WHIPTCLSO) $(instroot)/$(libdir)
+endif
+ifneq ($(PYTHONVERS),)
+	for ver in $(PYTHONVERS); do \
 	   [ -d $(instroot)/$(libdir)/$$ver/site-packages ] || install -m 755 -d $(instroot)/$(libdir)/$$ver/site-packages ;\
 	   install -m 755 $$ver/_snack.$(SOEXT) $(instroot)/$(libdir)/$$ver/site-packages ;\
 	   install -m 644 snack.py $(instroot)/$(libdir)/$$ver/site-packages ;\
-	done || :
+	done
+endif
 	install -m 644 libnewt.pc $(instroot)/$(pkgconfigdir)
 
 Makefile: configure.ac

From fd0c706958fc0c27034b18e2baee5d7e061ae3f9 Mon Sep 17 00:00:00 2001
From: Ryan Carsten Schmidt <git@ryandesign.com>
Date: Apr 25 2024 06:18:48 +0000
Subject: [PATCH 4/5] create install-py and install-tcl targets


The install-py target can be used to install just the python modules and
the install-tcl target can be used to install just whiptcl.so. The
install-sh target can still be used to install both of those as well as
libnewt.so, newt.h, and libnewt.pc as before.

---

diff --git a/Makefile.in b/Makefile.in
index 335e71e..7534abe 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -143,7 +143,7 @@ install: $(LIBNEWT) install-sh whiptail
 	install -m 644 whiptail.1 $(instroot)/$(man1dir)
 	make -C po datadir=$(instroot)/$(datadir) install
 
-install-sh: sharedlib $(WHIPTCLSO) _snack.$(SOEXT)
+install-sh: sharedlib install-tcl install-py
 	[ -d $(instroot)/$(libdir) ] || install -m 755 -d $(instroot)/$(libdir)
 	[ -d $(instroot)/$(includedir) ] || install -m 755 -d $(instroot)/$(includedir)
 	[ -d $(instroot)/$(pkgconfigdir) ] || install -m 755 -d $(instroot)/$(pkgconfigdir)
@@ -151,9 +151,15 @@ install-sh: sharedlib $(WHIPTCLSO) _snack.$(SOEXT)
 	install -m 755 $(LIBNEWTSH) $(instroot)/$(libdir)
 	ln -sf $(LIBNEWTSONAME) $(instroot)/$(libdir)/libnewt.$(SOEXT)
 	ln -sf $(LIBNEWTSH) $(instroot)/$(libdir)/$(LIBNEWTSONAME)
+	install -m 644 libnewt.pc $(instroot)/$(pkgconfigdir)
+
+install-tcl: $(WHIPTCLSO)
 ifneq ($(WHIPTCLSO),)
+	[ -d $(instroot)/$(libdir) ] || install -m 755 -d $(instroot)/$(libdir)
 	install -m 755 $(WHIPTCLSO) $(instroot)/$(libdir)
 endif
+
+install-py: _snack.$(SOEXT)
 ifneq ($(PYTHONVERS),)
 	for ver in $(PYTHONVERS); do \
 	   [ -d $(instroot)/$(libdir)/$$ver/site-packages ] || install -m 755 -d $(instroot)/$(libdir)/$$ver/site-packages ;\
@@ -161,7 +167,6 @@ ifneq ($(PYTHONVERS),)
 	   install -m 644 snack.py $(instroot)/$(libdir)/$$ver/site-packages ;\
 	done
 endif
-	install -m 644 libnewt.pc $(instroot)/$(pkgconfigdir)
 
 Makefile: configure.ac
 	@echo "You need to rerun ./autogen.sh and ./configure before continuing"

From c03cdeb2b28e54fcce7112d0728159cf324acc99 Mon Sep 17 00:00:00 2001
From: Ryan Carsten Schmidt <git@ryandesign.com>
Date: Apr 26 2024 02:35:13 +0000
Subject: [PATCH 5/5] install python modules to purelib and platlib


Don't assume that python modules go into $(libdir)/$$ver/site-packages;
get the correct values by asking sysconfig for its platlib and purelib.
This requires python 2.7 or later or python 3.2 or later.

---

diff --git a/Makefile.in b/Makefile.in
index 7534abe..1741ee7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -161,10 +161,15 @@ endif
 
 install-py: _snack.$(SOEXT)
 ifneq ($(PYTHONVERS),)
-	for ver in $(PYTHONVERS); do \
-	   [ -d $(instroot)/$(libdir)/$$ver/site-packages ] || install -m 755 -d $(instroot)/$(libdir)/$$ver/site-packages ;\
-	   install -m 755 $$ver/_snack.$(SOEXT) $(instroot)/$(libdir)/$$ver/site-packages ;\
-	   install -m 644 snack.py $(instroot)/$(libdir)/$$ver/site-packages ;\
+	@for ver in $(PYTHONVERS); do \
+		PLATLIB=`$$ver -c "import sysconfig; print(sysconfig.get_path('platlib'))"`; \
+		PURELIB=`$$ver -c "import sysconfig; print(sysconfig.get_path('purelib'))"`; \
+		[ -d $(instroot)/$$PLATLIB ] || install -m 755 -d $(instroot)/$$PLATLIB ;\
+		[ -d $(instroot)/$$PURELIB ] || install -m 755 -d $(instroot)/$$PURELIB ;\
+		echo install -m 755 $$ver/_snack.$(SOEXT) $(instroot)/$$PLATLIB;\
+		install -m 755 $$ver/_snack.$(SOEXT) $(instroot)/$$PLATLIB;\
+		echo install -m 644 snack.py $(instroot)/$$PURELIB;\
+		install -m 644 snack.py $(instroot)/$$PURELIB;\
 	done
 endif
 

