GNOME Bugzilla – Bug 734630
make fails on OSX due to sed
Last modified: 2018-03-31 07:31:28 UTC
make fails on OSX on the following error: sed -e '1i\ #define GLIB_DISABLE_DEPRECATION_WARNINGS' \ -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \ temp-dbus-generated.c > secret-dbus-generated.c sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ temp-dbus-generated.h > secret-dbus-generated.h sed: 1: "1i#define GLIB_DISABLE_ ...": command i expects \ followed by text This is due to OSX using a BSD version of sed, which in this case seems to strip the backslash after i. The workaround I'm using is to use GNU sed instead, but ideally it would be better to change this to something compatible with both BSD and GNU sed.
*** This bug has been marked as a duplicate of bug 720087 ***
Oh sorry, I thought this was about 'sed -i' which is also non-portable. In any case a non-intrusive patch would be welcome.
I think the issue isn't that BSD sed itself is stripping the backslash. It's that the backslash and newline inside that '...' aren't there in the first place by the time it gets to sed. But the GNU version of sed is happy without them. $ echo foo | sed -e "1i#whatever" sed: 1: "1i#whatever ": command i expects \ followed by text $ echo foo | gsed -e "1i#whatever" #whatever foo The problem looks like that the backslashes at the end of the lines are being processed by the shell before it calls sed. I can't figure out how to get an arrangement of backslashes in the Makefile command such that the argument to that first -e will contain a literal backslash followed by a literal newline. Make needs the backslash to be the last thing on the line for a multi-line command, but it doesn't consume the backslash either. So I end up with too many or too few backslashes, or a quoting syntax error. Here's a workaround that just avoids the `i` issue. secret-dbus-generated.c: temp-dbus-generated.c Makefile.am $(AM_V_GEN) echo '#define GLIB_DISABLE_DEPRECATION_WARNINGS' > secret-dbus-generated.c \ && sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \ temp-dbus-generated.c >> secret-dbus-generated.c But look: your ./configure script is already detecting gsed. eilonwy% grep gsed config.log configure:5957: result: /usr/local/bin/gsed ac_cv_path_SED=/usr/local/bin/gsed SED='/usr/local/bin/gsed' eilonwy% Maybe you just need to use the detected "$(SED)" instead of literal plain "sed" in your Makefile.
Here's a patch. This was enough to get it building on OS X 10.9.5 for me. (You need to re-run automake and autoconf after applying this patch.) diff --git a/libsecret/Makefile.am b/libsecret/Makefile.am index 0601460..4f5a164 100644 --- a/libsecret/Makefile.am +++ b/libsecret/Makefile.am @@ -89,13 +89,13 @@ temp-dbus-generated.c: $(DBUS_XML_DEFINITIONS) Makefile.am $(AM_V_GEN) gdbus-codegen --interface-prefix org.freedesktop.Secret. \ --generate-c-code temp-dbus-generated --c-namespace SecretGen $< secret-dbus-generated.c: temp-dbus-generated.c Makefile.am - $(AM_V_GEN) sed -e '1i\ + $(AM_V_GEN) $(SED) -e '1i\ #define GLIB_DISABLE_DEPRECATION_WARNINGS' \ -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \ temp-dbus-generated.c > secret-dbus-generated.c secret-dbus-generated.h: temp-dbus-generated.c Makefile.am - $(AM_V_GEN) sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ + $(AM_V_GEN) $(SED) -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ temp-dbus-generated.h > secret-dbus-generated.h libsecret/secret-enum-types.h: libsecret/secret-enum-types.h.template $(libsecret_HEADS)
Using a $-quoted string makes BSD sed happy as well. Here's a patch.
Created attachment 321461 [details] [review] build: Use $-quoted string to escape newline BSD sed doesn't like escaping a literal newline character with a backslash. Instead, use a $-quoted string to escape the newline as \n.
Anyone have an objection to this patch? If not, I'd like to commit it.
Thanks. Merged into git master. Attachment 321461 [details] pushed as 4d7b190 - build: Use $-quoted string to escape newline
Hi. I am seeing a regression with this. Using GNU sed 4.2.2: gsed -e $'1i\\\n#define GLIB_DISABLE_DEPRECATION_WARNINGS' \ -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \ temp-dbus-generated.c > secret-dbus-generated.c gsed: -e expression #1, char 2: unknown command: `1' Using BSD sed (from OpenBSD): sed -e $'1i\\\n#define GLIB_DISABLE_DEPRECATION_WARNINGS' \ -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \ temp-dbus-generated.c > secret-dbus-generated.c sed: 1: "$1i\\\n#define GLIB_DIS ...: invalid command code 1
Could it be your shell does not understand $-quoted strings? It looks like the $ is getting passed into sed.
I thought that $-quoted strings were Bash extension for gettext integration: https://www.gnu.org/software/gettext/manual/html_node/bash.html Given that this is only used for inserting a single line, how about just calling echo, something like: $(AM_V_GEN) { echo '#define GLIB_DISABLE_DEPRECATION_WARNINGS'; \ sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \ temp-dbus-generated.c } > secret-dbus-generated.c
(In reply to Daiki Ueno from comment #11) > I thought that $-quoted strings were Bash extension for gettext integration: > https://www.gnu.org/software/gettext/manual/html_node/bash.html > > Given that this is only used for inserting a single line, how about just > calling echo, something like: > > $(AM_V_GEN) { echo '#define GLIB_DISABLE_DEPRECATION_WARNINGS'; \ > sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ > -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \ > temp-dbus-generated.c } > secret-dbus-generated.c Works for me :-) One typo though, there's a missing ';' after temp-dbus-generated.c. i.e. $(AM_V_GEN) { echo '#define GLIB_DISABLE_DEPRECATION_WARNINGS'; \ sed -e 's/secret_gen_/_secret_gen_/g' -e 's/type-/type/g' \ -e 's/temp-dbus-generated.h/secret-dbus-generated.h/g' \ temp-dbus-generated.c; } > secret-dbus-generated.c
Created attachment 370348 [details] [review] build: Make DBus code generation more portable The $'...' quoting syntax is a Bash extension and might not be available in other Bourne shell compatible shells: https://www.gnu.org/software/bash/manual/html_node/Major-Differences-From-The-Bourne-Shell.html#Major-Differences-From-The-Bourne-Shell
TIL that $'' and $"" are seemingly totally unrelated...
Yeah, my bad; although $'' is also listed in the link quoted in comment 13.
(In reply to Daiki Ueno from comment #13) > Created attachment 370348 [details] [review] [review] > build: Make DBus code generation more portable > > The $'...' quoting syntax is a Bash extension and might not be > available in other Bourne shell compatible shells: > https://www.gnu.org/software/bash/manual/html_node/Major-Differences-From- > The-Bourne-Shell.html#Major-Differences-From-The-Bourne-Shell Thanks, applied and working.
Anyway, I am pushing this. I am also wondering if this GLIB_DISABLE_DEPRECATION_WARNINGS setting is still needed; it seems a bit strange that the glib-generated code requires it to compile... Attachment 370348 [details] pushed as a7f2efc - build: Make DBus code generation more portable