Skip to contentSkip to conversation

Makefile: remove bashism

PATCH Applied Michael Tokarev 3 participants 5 messages Apr 5, 2014 – Apr 7, 2014 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: remove bashism

When installing modules (when --enable-modules is specified for ./configure), Makefile uses the following construct to replace all slashes with dashes in module name:

${s//\//-}

This is a bash-specific substitution mechanism. POSIX does not have it, and some operating systems (for example Debian) does not implement this construct in default shell (for example dash).

Use more traditional way to perform the substitution: use `tr' tool.

Makefile +1 -1
index ec74039..d622799 100644
@@ -376,7 +376,7 @@ endif
 ifneq ($(CONFIG_MODULES),)
 	$(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)"
 	for s in $(patsubst %.mo,%$(DSOSUF),$(modules-m)); do \
-		$(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$${s//\//-}"; \
+		$(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$$(echo $$s | tr / -)"; \
 	done
 endif
 ifneq ($(HELPERS-y),)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 20 lines · Michael Tokarev

When installing modules (when --enable-modules is specified for ./configure), Makefile uses the following construct to replace all slashes with dashes in module name:

${s//\//-}

This is a bash-specific substitution mechanism. POSIX does not have it, and some operating systems (for example Debian) does not implement this construct in default shell (for example dash).

Use more traditional way to perform the substitution: use `tr' tool.

Makefile +0 -0
index ec74039..d622799 100644

Makefile endif · line 382

Quoted 8 lines
Makefile +1 -1
@@ -376,7 +376,7 @@ endif
 ifneq ($(CONFIG_MODULES),)
        $(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)"
        for s in $(patsubst %.mo,%$(DSOSUF),$(modules-m)); do \
-               $(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$${s//\//-}"; \
+               $(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$$(echo $$s | tr / -)"; \
        done
 endif
 ifneq ($(HELPERS-y),)

Paolo, Fam: does this patch look ok to you? I propose to apply it for 2.0...

thanks
-- PMM

#2 lore raw
Quoted 32 lines · Peter Maydell
Quoted 20 lines · Michael Tokarev

When installing modules (when --enable-modules is specified for ./configure), Makefile uses the following construct to replace all slashes with dashes in module name:

${s//\//-}

This is a bash-specific substitution mechanism. POSIX does not have it, and some operating systems (for example Debian) does not implement this construct in default shell (for example dash).

Use more traditional way to perform the substitution: use `tr' tool.

Makefile +0 -0
index ec74039..d622799 100644

Makefile endif · line 382

Quoted 8 lines
Makefile +1 -1
@@ -376,7 +376,7 @@ endif
 ifneq ($(CONFIG_MODULES),)
        $(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)"
        for s in $(patsubst %.mo,%$(DSOSUF),$(modules-m)); do \
-               $(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$${s//\//-}"; \
+               $(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$$(echo $$s | tr / -)"; \
        done
 endif
 ifneq ($(HELPERS-y),)
Quoted 2 lines

Paolo, Fam: does this patch look ok to you? I propose to apply it for 2.0...

I don't understand the quoting in the old version offhand (leaning toothpick syndrome). The new version looks good to me.

#3 lore raw
Quoted 12 lines · Markus Armbruster
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Michael Tokarev

ifneq ($(CONFIG_MODULES),)

        $(INSTALL_DIR) "$(DESTDIR)$(qemu_moddir)"
        for s in $(patsubst %.mo,%$(DSOSUF),$(modules-m)); do \
Makefile +1 -1
-               $(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$${s//\//-}"; \
+               $(INSTALL_PROG) $(STRIP_OPT) $$s "$(DESTDIR)$(qemu_moddir)/$$(echo $$s | tr / -)"; \
        done
 endif
 ifneq ($(HELPERS-y),)
Quoted 7 lines
Quoted 4 lines

Paolo, Fam: does this patch look ok to you? I propose to apply it for 2.0...

I don't understand the quoting in the old version offhand (leaning toothpick syndrome)

Yeah, it took me a while to figure out too, but:
$${s//\//-}
$$ is quoting a '$' for Make, so the shell sees:
${s//\//-}
and the bash syntax for this substitution is:
${parameter/pattern/string}
where if 'pattern' starts with a '/' it means 'replace all matches', like sed's 'g' modifier
So we have:
parameter: s
pattern: /\/
string: -
and the pattern is the 'global replace' modifier plus an escaped forward slash. So it's $s (the shell variable) with all the forward slashes converted to hyphens.

thanks
-- PMM

#4 lore raw
In reply to Michael Tokarev
Quoted 6 lines · Michael Tokarev

When installing modules (when --enable-modules is specified for ./configure), Makefile uses the following construct to replace all slashes with dashes in module name:

${s//\//-}

Quoted 8 lines

This is a bash-specific substitution mechanism. POSIX does not have it, and some operating systems (for example Debian) does not implement this construct in default shell (for example dash).

Use more traditional way to perform the substitution: use `tr' tool.

Applied to master, thanks.

-- PMM