mk: don't escape '#' for `grep`
PATCH 1/1 mk: don't escape '#' for `grep`
Without the change build process complains
$ LANG=C make -R help
grep: warning: stray \ before #
grep: warning: stray \ before #--- share/mk/configure/build-depends/cpp/cpp.mk | 2 +- share/mk/src/sh.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
share/mk/configure/build-depends/cpp/cpp.mk +1 -1
@@ -21,7 +21,7 @@ endif CPP_HAS_ALREADY_D_FORTIFY_SOURCE := \ $(shell \ $(CPP) -dM - -Wno-error </dev/null \ - | $(GREP) '\#define _FORTIFY_SOURCE ' >/dev/null \ + | $(GREP) '#define _FORTIFY_SOURCE ' >/dev/null \ && $(ECHO) yes \ || $(ECHO) no; \ )
share/mk/src/sh.mk +1 -1
@@ -14,7 +14,7 @@ include $(MAKEFILEDIR)/configure/directory_variables/src.mk BIN_sh := $(shell $(FIND) $(SRCBINDIR) -type f \ - | $(XARGS) $(GREP) -l '^\#!/bin/\(sh\|bash\)\>' \ + | $(XARGS) $(GREP) -l '^#!/bin/\(sh\|bash\)\>' \ | $(SORT))
Signature · 1 line
2.48.1
Alejandro Colomar
maintainerHi Sergei,
I'm CCing Boris, since he had the opposite problem, which triggered adding the stray '\'.
Quoted 5 lines · Sergei Trofimovich
Without the change build process complains
$ LANG=C make -R help grep: warning: stray \ before # grep: warning: stray \ before #
I can't reproduce. What's your version of grep(1) and your version of make(1)?
alx@debian:~/src/linux/man-pages/man-pages/contrib$ make -R help make: warning: undefined variable 'GNUMAKEFLAGS' To see a list of targets, run: $ make -R -p nothing \ | grep '^\.PHONY:' \ | tr ' ' '\n' \ | grep -v '^\.PHONY:' \ | sort;
To see a list of variables, run: $ find GNUmakefile share/mk/configure -type f \ | sort \ | xargs grep '^[^[:space:]].*?=' \ | sed 's/=.*/=/'; To see a list of dependencies (package/program), run: $ find share/mk/configure/build-depends -type f \ | sed 's,share/mk/configure/build-depends/,,' \ | sed 's,\.mk,,' \ | sort; alx@debian:~/src/linux/man-pages/man-pages/contrib$ LANG=C make -R help make: warning: undefined variable 'GNUMAKEFLAGS' To see a list of targets, run: $ make -R -p nothing \ | grep '^\.PHONY:' \ | tr ' ' '\n' \ | grep -v '^\.PHONY:' \ | sort; To see a list of variables, run: $ find GNUmakefile share/mk/configure -type f \ | sort \ | xargs grep '^[^[:space:]].*?=' \ | sed 's/=.*/=/'; To see a list of dependencies (package/program), run: $ find share/mk/configure/build-depends -type f \ | sed 's,share/mk/configure/build-depends/,,' \ | sed 's,\.mk,,' \ | sort; alx@debian:~/src/linux/man-pages/man-pages/contrib$ make --version GNU Make 4.4.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. alx@debian:~/src/linux/man-pages/man-pages/contrib$ grep --version grep (GNU grep) 3.11 Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Mike Haertel and others; see <https://git.savannah.gnu.org/cgit/grep.git/tree/AUTHORS>. grep -P uses PCRE2 10.45 2025-02-05
Quoted 2 lines
Signed-off-by Sergei Trofimovich <[email protected]>
Please add a tag mentioning that it reverts a certain commit:
Fixes: 76f12e3fd3ea (2025-02-10; "share/mk/: Escape '#' in regexes")
Have a lovely day!
Alex
Quoted 34 lines
--- share/mk/configure/build-depends/cpp/cpp.mk | 2 +- share/mk/src/sh.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)share/mk/configure/build-depends/cpp/cpp.mk +1
-1@@ -21,7 +21,7 @@ endif CPP_HAS_ALREADY_D_FORTIFY_SOURCE := \ $(shell \ $(CPP) -dM - -Wno-error </dev/null \ - | $(GREP) '\#define _FORTIFY_SOURCE ' >/dev/null \ + | $(GREP) '#define _FORTIFY_SOURCE ' >/dev/null \ && $(ECHO) yes \ || $(ECHO) no; \ )share/mk/src/sh.mk +1
-1@@ -14,7 +14,7 @@ include $(MAKEFILEDIR)/configure/directory_variables/src.mk BIN_sh := $(shell $(FIND) $(SRCBINDIR) -type f \ - | $(XARGS) $(GREP) -l '^\#!/bin/\(sh\|bash\)\>' \ + | $(XARGS) $(GREP) -l '^#!/bin/\(sh\|bash\)\>' \ | $(SORT))Signature · 1 line
2.48.1
Signature · 1 line
<https://www.alejandro-colomar.es/>
Quoted 67 lines · Alejandro Colomar
Hi Sergei,
I'm CCing Boris, since he had the opposite problem, which triggered adding the stray '\'.
Quoted 5 lines · Sergei Trofimovich
Without the change build process complains
$ LANG=C make -R help grep: warning: stray \ before # grep: warning: stray \ before #I can't reproduce. What's your version of grep(1) and your version of make(1)?
alx@debian:~/src/linux/man-pages/man-pages/contrib$ make -R help make: warning: undefined variable 'GNUMAKEFLAGS' To see a list of targets, run: $ make -R -p nothing \ | grep '^\.PHONY:' \ | tr ' ' '\n' \ | grep -v '^\.PHONY:' \ | sort;To see a list of variables, run: $ find GNUmakefile share/mk/configure -type f \ | sort \ | xargs grep '^[^[:space:]].*?=' \ | sed 's/=.*/=/'; To see a list of dependencies (package/program), run: $ find share/mk/configure/build-depends -type f \ | sed 's,share/mk/configure/build-depends/,,' \ | sed 's,\.mk,,' \ | sort; alx@debian:~/src/linux/man-pages/man-pages/contrib$ LANG=C make -R help make: warning: undefined variable 'GNUMAKEFLAGS' To see a list of targets, run: $ make -R -p nothing \ | grep '^\.PHONY:' \ | tr ' ' '\n' \ | grep -v '^\.PHONY:' \ | sort; To see a list of variables, run: $ find GNUmakefile share/mk/configure -type f \ | sort \ | xargs grep '^[^[:space:]].*?=' \ | sed 's/=.*/=/'; To see a list of dependencies (package/program), run: $ find share/mk/configure/build-depends -type f \ | sed 's,share/mk/configure/build-depends/,,' \ | sed 's,\.mk,,' \ | sort; alx@debian:~/src/linux/man-pages/man-pages/contrib$ make --version GNU Make 4.4.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. alx@debian:~/src/linux/man-pages/man-pages/contrib$ grep --version grep (GNU grep) 3.11 Copyright (C) 2023 Free Software Foundation, Inc.
Quoted 9 lines
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Mike Haertel and others; see <https://git.savannah.gnu.org/cgit/grep.git/tree/AUTHORS>. grep -P uses PCRE2 10.45 2025-02-05
Aha, I wonder if it's also related to the escaping behaviour of sh and `bash. Here are my tool versions:
$ make --version
GNU Make 4.4.1
Built for x86_64-pc-linux-gnu
Copyright (C) 1988-2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. $ grep --version
grep (GNU grep) 3.11
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Written by Mike Haertel and others; see
<https://git.savannah.gnu.org/cgit/grep.git/tree/AUTHORS>.
grep -P uses PCRE2 10.44 2024-06-07
$ sh --version
GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
$ bash --version
GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2022 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
Quoted 47 lines
Quoted 1 line
Signed-off-by Sergei Trofimovich <[email protected]>Please add a tag mentioning that it reverts a certain commit:
Fixes: 76f12e3fd3ea (2025-02-10; "share/mk/: Escape '#' in regexes")Have a lovely day!
AlexQuoted 34 lines
--- share/mk/configure/build-depends/cpp/cpp.mk | 2 +- share/mk/src/sh.mk | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)share/mk/configure/build-depends/cpp/cpp.mk +1
-1@@ -21,7 +21,7 @@ endif CPP_HAS_ALREADY_D_FORTIFY_SOURCE := \ $(shell \ $(CPP) -dM - -Wno-error </dev/null \ - | $(GREP) '\#define _FORTIFY_SOURCE ' >/dev/null \ + | $(GREP) '#define _FORTIFY_SOURCE ' >/dev/null \ && $(ECHO) yes \ || $(ECHO) no; \ )share/mk/src/sh.mk +1
-1@@ -14,7 +14,7 @@ include $(MAKEFILEDIR)/configure/directory_variables/src.mk BIN_sh := $(shell $(FIND) $(SRCBINDIR) -type f \ - | $(XARGS) $(GREP) -l '^\#!/bin/\(sh\|bash\)\>' \ + | $(XARGS) $(GREP) -l '^#!/bin/\(sh\|bash\)\>' \ | $(SORT))Signature · 1 line
2.48.1Signature · 1 line
<https://www.alejandro-colomar.es/>
Signature · 1 line
Sergei
Alejandro Colomar
maintainerHi Sergei,
Quoted 1 line · Sergei Trofimovich
Aha, I wonder if it's also related to the escaping behaviour of
shand `bash.
sh(1) shouldn't matter, because the I explicitly request bash(1) in the makefiles.
$ grep -rn SHELL GNUmakefile 5:SHELL := bash 6:.SHELLFLAGS := -Eeuo pipefail -c
Quoted 9 lines
Here are my tool versions:
$ sh --version GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
alx@debian:~$ which sh /usr/bin/sh alx@debian:~$ which sh | xargs dpkg -S dash: /usr/bin/sh alx@debian:~$ which sh | xargs dpkg -S | cut -f1 -d: | xargs dpkg -l | tail -n1 ii dash 0.5.12-12 amd64 POSIX-compliant shell
(But as said, this shouldn't matter.)
Quoted 8 lines
$ bash --version GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
$ bash --version GNU bash, version 5.2.37(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
Could you please try to find out the cause of the actual problem? Maybe there's a fix that doesn't involve reverting that patch. Or maybe there's a bug in some tool, and we can report it.
Cheers,
Alex
Signature · 1 line
<https://www.alejandro-colomar.es/>
* Alejandro Colomar:
Quoted 3 lines
Could you please try to find out the cause of the actual problem? Maybe there's a fix that doesn't involve reverting that patch. Or maybe there's a bug in some tool, and we can report it.
NEWS in GNU make explains this:
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation no longer introduce comments and should not be escaped with backslashes:
thus a call such as:
foo := $(shell echo '#')
is legal. Previously the number sign needed to be escaped, for example:
foo := $(shell echo '\#')
Now this latter will resolve to "\#". If you want to write makefiles
portable to both versions, assign the number sign to a variable:
H := \#
foo := $(shell echo '$H')This was claimed to be fixed in 3.81, but wasn't, for some reason. To detect this change search for 'nocomment' in the .FEATURES variable.
Applying the $H suggestion seems harmless enough, although this make change seems to be fairly problematic in general.
Alejandro Colomar
maintainerHi Florian,
Quoted 19 lines · Florian Weimer
* Alejandro Colomar:
Quoted 3 lines
Could you please try to find out the cause of the actual problem? Maybe there's a fix that doesn't involve reverting that patch. Or maybe there's a bug in some tool, and we can report it.
NEWS in GNU make explains this:
* WARNING: Backward-incompatibility!
Number signs (#) appearing inside a macro reference or function invocation no longer introduce comments and should not be escaped with backslashes:
thus a call such as:foo := $(shell echo '#') is legal. Previously the number sign needed to be escaped, for example: foo := $(shell echo '\#') Now this latter will resolve to "\#". If you want to write makefiles portable to both versions, assign the number sign to a variable: H := \# foo := $(shell echo '$H')
Quoted 2 lines
This was claimed to be fixed in 3.81, but wasn't, for some reason. To detect this change search for 'nocomment' in the .FEATURES variable.
Thanks for pasting the relevant NEWS entry.
Quoted 3 lines
Applying the $H suggestion seems harmless enough, although this make change seems to be fairly problematic in general.
However, I learned about that change last month (after Boris's report), and I think it's not our problem here. The thing is, on my system, grep(1) is just fine with that escaped hash:
$ echo '#foo' | grep '\#foo' #foo
While Sergei seems to be getting a warning from grep(1). So, something in our systems differs, even if our make(1) version is the same.
Our bash(1) version is also the same (sh(1) is not, but we're not using sh(1), AFAIK). So something other than make(1) seems to be treating the \# differently.
Have a lovely day!
Alex
Signature · 1 line
<https://www.alejandro-colomar.es/>
* Alejandro Colomar <[email protected]>, 2025-02-27 16:20:
Quoted 4 lines
Quoted 4 lines
Now this latter will resolve to "\#". If you want to write makefiles portable to both versions, assign the number sign to a variable:
H := \# foo := $(shell echo '$H')
Alternatively, you could take advantage of the fact that in some shell contexts # and \# mean the same thing:
foo := $(shell echo ''\#)
Quoted 4 lines
The thing is, on my system, grep(1) is just fine with that escaped hash:
$ echo '#foo' | grep '\#foo' #foo
The warning comes from GNU grep (>= 3.8): "Regular expressions with stray backslashes now cause warnings, as their unspecified behavior can lead to unexpected results."
You're probably not seeing the warnings because Debian patched them out:
https://bugs.debian.org/1019724
Signature · 1 line
Jakub Wilk
Alejandro Colomar
maintainerHi Jakub,
Quoted 10 lines · Jakub Wilk
* Alejandro Colomar <[email protected]>, 2025-02-27 16:20:
Quoted 4 lines
Quoted 4 lines
Now this latter will resolve to "\#". If you want to write makefiles portable to both versions, assign the number sign to a variable:
H := \# foo := $(shell echo '$H')Alternatively, you could take advantage of the fact that in some shell contexts # and \# mean the same thing:
foo := $(shell echo ''\#)
Hmmm, sounds reasonable, since a # not preceeded by a space is not a comment.
alx@debian:~$ echo ''\# # alx@debian:~$ echo ''# #
I'll take this workaround. I'll put this on the commit:
Quoted 6 lines
Quoted 5 lines
The thing is, on my system, grep(1) is just fine with that escaped hash:
$ echo '#foo' | grep '\#foo' #foo
Quoted 6 lines
The warning comes from GNU grep (>= 3.8): "Regular expressions with stray backslashes now cause warnings, as their unspecified behavior can lead to unexpected results."
You're probably not seeing the warnings because Debian patched them out:
https://bugs.debian.org/1019724
Ahhh, that makes sense. Thanks!
Have a lovely night!
Alex
Signature · 1 line
<https://www.alejandro-colomar.es/>
Alejandro Colomar
maintainerHi all,
Quoted 13 lines · Alejandro Colomar
Quoted 4 lines
Alternatively, you could take advantage of the fact that in some shell contexts # and \# mean the same thing:
foo := $(shell echo ''\#)Hmmm, sounds reasonable, since a # not preceeded by a space is not a comment.
alx@debian:~$ echo ''\# # alx@debian:~$ echo ''# #
Quoted 6 lines
I'll take this workaround. I'll put this on the commit:
Reported-by Sergei Trofimovich <[email protected]>Cc Florian Weimer <[email protected]>Cc Boris Pigin <[email protected]>Suggested-by Jakub Wilk <[email protected]>
I've applied the suggestion by Jakub, which you can find here:
<https://www.alejandro-colomar.es/src/alx/linux/man-pages/man-pages.git/commit/?h=contrib&id=46b7bcaae3cbd18b3022caa3ddd52e7be66bb21a>
Tomorrow I'll push that to the master branch, if there are no concerns.
Since this probably affects packagers, I'll issue a new release in a few days.
Cheers,
Alex
Signature · 1 line
<https://www.alejandro-colomar.es/>