Subject: [bug#24507][PATCH] noinst_PYTHON breaks uninstall of Python files

From: Bogdan <[email-masked]>
Date: Wed, 22 Mar 2023 17:56:28 +0100

Hi, Automakers.

  The attached patch fixes bug#24507.

  I don't fully understand the cause, but I guess that the "if 
%?INSTALL%" block gets ignored when "noinst" is present, including the 
"?FIRST?" it contains, which defines the missing "am__pep3147_tweak".

  Anyway, moving the "?FIRST?" block with the declaration of 
"am__pep3147_tweak" outside the "if %?INSTALL%" block fixes the issue. 
All tests with "py" in the name pass.

  This isn't the first time either. The test I've updated was for a 
similar case - bug#10995 ("am__py_compile doesn't get correctly 
defined when there a 'noinst_PYTHON' declaration precedes a 
'foo_PYTHON' declaration"), that's probably why "am__py_compile" is in 
its own "?FIRST?" block at the top now.

  No other language XX.am files seem to have "?FIRST?" inside an "if" 
block.

-- 
Regards - Bogdan ('bogdro') D.                 (GNU/Linux & FreeDOS)
X86 assembly (DOS, GNU/Linux):    http://bogdro.evai.pl/index-en.php
Soft(EN): http://bogdro.evai.pl/soft  http://bogdro.evai.pl/soft4asm
www.Xiph.org  www.TorProject.org  www.LibreOffice.org  www.GnuPG.org

From bf0a60a61c1413185a982890b30046f46cf9cd1d Mon Sep 17 00:00:00 2001
From: Bogdan Drozdowski <>
Date: Wed, 22 Mar 2023 17:10:58 +0100
Subject: [PATCH] Fix Python tweak missing when noinst is present

---
 lib/am/python.am    | 4 ++--
 t/python-pr10995.sh | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/am/python.am b/lib/am/python.am
index 98f95af1b..19f268efc 100644
--- a/lib/am/python.am
+++ b/lib/am/python.am
@@ -94,11 +94,11 @@ endif %?INSTALL%
 ## Uninstalling.  ##
 ## -------------- ##
 
-if %?INSTALL%
-
 ?FIRST?am__pep3147_tweak = \
 ?FIRST?  sed -e 's|\.py$$||' -e 's|[^/]*$$|__pycache__/&.*.pyc __pycache__/&.*.pyo|'
 
+if %?INSTALL%
+
 .PHONY uninstall-am: uninstall-%DIR%PYTHON
 uninstall-%DIR%PYTHON:
 	@$(NORMAL_UNINSTALL)
diff --git a/t/python-pr10995.sh b/t/python-pr10995.sh
index 324be916e..abeb8a124 100644
--- a/t/python-pr10995.sh
+++ b/t/python-pr10995.sh
@@ -17,6 +17,9 @@
 # Test automake bug#10995: am__py_compile doesn't get correctly defined
 # when there a 'noinst_PYTHON' declaration precedes a 'foo_PYTHON'
 # declaration.
+# Test also automake bug#24507: am__pep3147_tweak doesn't get correctly
+# defined when there a 'noinst_PYTHON' declaration precedes a 'foo_PYTHON'
+# declaration and 'make uninstall' fails functionally (just shows errors).
 
 required=python
 . test-init.sh
@@ -53,4 +56,7 @@ py_installed --not inst/py/no.pyc
 
 $MAKE disttest
 
+LC_ALL=C run_make -M uninstall
+grep 'command substitution' output && exit 1
+
 :
-- 
2.35.1