Subject: bug#24507: noinst_PYTHON breaks uninstall of Python files

From: Karl Berry <[email-masked]>
Date: Wed, 5 Jul 2023 10:00:26 -0600

Hi Akim (hope all is well with you) and all,

Back on your report https://bugs.gnu.org/24507 from a mere seven years ago ...

    > $ cat Makefile.am
    > noinst_PYTHON = foo.py
    > python_PYTHON = bar.py
    ...
    > $ make uninstall-nodist_vcsn_tools_pythonPYTHON
    > make: Entering directory `_build/36s'
    > /bin/sh: command substitution: line 7: syntax error: unexpected end of file

Bogdan's patch (below) worked for me too, while not breaking any other
existing test, so I installed it.

    bd> I don't fully understand the cause, 

Me either.

    but I guess that the "if %?INSTALL%" block gets ignored when
    "noinst" is present, 

I guess so. Just based on the names. If there is any real explanation of
those weird %?FOO% and ?FOO? conditionals, I haven't found it.

    including the "?FIRST?" it contains, which
    defines the missing "am__pep3147_tweak".

Thank you very much for analyzing it and finding the patch.
Closing. --karl

2023-07-01  Bogdan  <[email-masked]>

python: support noinst_PYTHON preceding foo_PYTHON.

This change fixes https://bugs.gnu.org/24507.

* lib/am/python.am (am__pep3147_tweak): remove conditional
on %?INSTALL%.
* t/python-pr10995.sh: test with make uninstall.
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
+
 :

compile finished at Wed Jul  5 08:59:29 2023