From c1e1dd6619faf4358ba7d6434dee95eaf6db2195 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Mon, 16 Dec 2019 19:45:22 -0700
Subject: [PATCH] automake: Ensure space after $(LISP) in tags dependencies.

This change fixes automake bug#38139.

* bin/automake.in (handle_tags): Concatenate with space in " @config".
* t/tags-lisp-space.sh: New test.
* t/list-of-tests.mk (handwritten_TESTS): Add it.
---
 NEWS                 |  4 ++++
 bin/automake.in      |  2 +-
 t/list-of-tests.mk   |  1 +
 t/tags-lisp-space.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 55 insertions(+), 1 deletion(-)
 create mode 100755 t/tags-lisp-space.sh

diff --git a/NEWS b/NEWS
index bb3fff83f..9bf332b06 100644
--- a/NEWS
+++ b/NEWS
@@ -79,6 +79,10 @@ New in ?.?.?:
     compatibility with the 'sed' implementation provided by macOS which
     considers '\n' as the 'n' character instead of a newline.
     (automake bug#31222)
+  
+  - For make tags, lisp_LISP is followed by the necessary space when
+    used with CONFIG_HEADERS.
+    (automake bug#38139)

 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

diff --git a/bin/automake.in b/bin/automake.in
index 67a7a9578..2e04bfb9a 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -3708,7 +3708,7 @@ sub handle_tags ()

     define_variable ('am__tagged_files',
                      '$(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP)'
-                     . "@config", INTERNAL);
+                     . " @config", INTERNAL);

     if (rvar('am__tagged_files')->value_as_list_recursive
           || var ('ETAGS_ARGS') || var ('SUBDIRS'))
diff --git a/t/list-of-tests.mk b/t/list-of-tests.mk
index be3b53077..445545e89 100644
--- a/t/list-of-tests.mk
+++ b/t/list-of-tests.mk
@@ -1188,6 +1188,7 @@ t/tap-summary-color.sh \
 t/tags.sh \
 t/tags2.sh \
 t/tagsub.sh \
+t/tags-lisp-space.sh \
 t/tags-pr12372.sh \
 t/tar-ustar.sh \
 t/tar-pax.sh \
diff --git a/t/tags-lisp-space.sh b/t/tags-lisp-space.sh
new file mode 100755
index 000000000..256a0f799
--- /dev/null
+++ b/t/tags-lisp-space.sh
@@ -0,0 +1,49 @@
+#! /bin/sh
+# Copyright (C) 2019 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <https://www.gnu.org/licenses/>.
+
+# Test to ensure the space after $(LISP) for make tags is present
+# if there are CONFIG_HEADERS.
+# See automake bug#38139.
+
+required=''
+. test-init.sh
+
+# some AC_CONFIG_FILES header is needed to trigger the bug.
+cat >> configure.ac <<'END'
+AC_CONFIG_HEADERS([config.h])
+AM_PATH_LISPDIR
+AC_OUTPUT
+END
+
+cat > Makefile.am <<'END'
+lisp_LISP = the-amtest-mode.el
+END
+
+touch config.h.in
+touch the-amtest-mode.el
+
+$ACLOCAL
+$AUTOCONF
+$AUTOMAKE
+
+./configure
+run_make -O -E tags
+
+# make tags should fail if the problem exists, but just in case, match:
+# make: *** No rule to make target 'the-amtest-mode.elconfig.h.in', needed by 'tags-am'.  Stop.
+grep 'No rule to make target' stderr && exit 1
+
+:
-- 
2.24.0.390.g083378cc35

