Skip to contentSkip to conversation

Generation of locales: made call to tr more robust and added LOWERCASE macro

PATCH New Thierry Bultel 3 participants 3 messages Nov 10, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Generation of locales: made call to tr more robust and added LOWERCASE macro

When calling 'tr' without quoting braces, bash can make really weird things if there are existing 'single-letter-named' directories
eg:
thierry at thierry-desktop:~$ echo AAA | tr [A-Z] [a-z]
aaa
thierry at thierry-desktop:~$ mkdir m
thierry at thierry-desktop:~$ echo AAA | tr [A-Z] [a-z]
AAA

The (quick) analysis is that the callee (tr) argvs then contain 'm' thus the translation does not work

Using quotes works around it:
thierry at thierry-desktop:~$ echo AAA | tr '[A-Z]' '[a-z]' aaa

Changes v1->v2
- Added the LOWERCASE macro, following Thomas De Schampheleire's advice

---
 Makefile             |    2 +-
 package/pkg-utils.mk |    8 ++++++++
 2 files changed, 9 insertions(+), 1 deletions(-)
Makefile +1 -1
index 1496bd7..a006615 100644
@@ -548,7 +548,7 @@ target-generatelocales: host-localedef
 		I18NPATH=$(STAGING_DIR)/usr/share/i18n:/usr/share/i18n \
 		$(HOST_DIR)/usr/bin/localedef \
 			--prefix=$(TARGET_DIR) \
-			--`echo $(BR2_ENDIAN) | tr [A-Z] [a-z]`-endian \
+			--$(call LOWERCASE,$(BR2_ENDIAN))-endian \
 			-i $${inputfile} -f $${charmap} \
 			$${locale} ; \
 	done
package/pkg-utils.mk +8 -0
index 5930f2c..0ef433d 100644
@@ -23,6 +23,14 @@ UPPERCASE = $(strip $(eval __tmp := $1) \
 	$(__tmp)))) \
 	$(__tmp))
 
+# LOWERCASE macro -- transforms its arguments to lowercase
+# The above non-tr implementation is not needed, because LOWERCASE is not
+# called very often
+
+define LOWERCASE
+$(shell echo $1 | tr '[:upper:]' '[:lower:]')
+endef
+
 #
 # Manipulation of .config files based on the Kconfig
 # infrastructure. Used by the Busybox package, the Linux kernel
Signature · 1 line
1.7.1
#1 lore raw

PATCH 1/1 Generation of locales: made call to tr more robust and added LOWERCASE macro

Hi Thierry,

Quoted 13 lines · Thierry Bultel

When calling 'tr' without quoting braces, bash can make really weird things if there are existing 'single-letter-named' directories
eg:
thierry at thierry-desktop:~$ echo AAA | tr [A-Z] [a-z]
aaa
thierry at thierry-desktop:~$ mkdir m
thierry at thierry-desktop:~$ echo AAA | tr [A-Z] [a-z]
AAA

The (quick) analysis is that the callee (tr) argvs then contain 'm' thus the translation does not work

Quoted 8 lines

Using quotes works around it:
thierry at thierry-desktop:~$ echo AAA | tr '[A-Z]' '[a-z]' aaa

Changes v1->v2
- Added the LOWERCASE macro, following Thomas De Schampheleire's advice

This 'Changes' text should be below the --- line, otherwise it ends up in the commit log which is not supposed to happen.

Quoted 26 lines
---
 Makefile             |    2 +-
 package/pkg-utils.mk |    8 ++++++++
 2 files changed, 9 insertions(+), 1 deletions(-)
Makefile +1 -1
index 1496bd7..a006615 100644
@@ -548,7 +548,7 @@ target-generatelocales: host-localedef
                I18NPATH=$(STAGING_DIR)/usr/share/i18n:/usr/share/i18n \
                $(HOST_DIR)/usr/bin/localedef \
                        --prefix=$(TARGET_DIR) \
-                       --`echo $(BR2_ENDIAN) | tr [A-Z] [a-z]`-endian \
+                       --$(call LOWERCASE,$(BR2_ENDIAN))-endian \
                        -i $${inputfile} -f $${charmap} \
                        $${locale} ; \
        done
package/pkg-utils.mk +0 -0
index 5930f2c..0ef433d 100644
@@ -23,6 +23,14 @@ UPPERCASE = $(strip $(eval __tmp := $1) \
        $(__tmp)))) \

package/pkg-utils.mk UPPERCASE = $(strip $(eval __tmp := $1) \ · line 33

Quoted 10 lines
package/pkg-utils.mk +8 -0
        $(__tmp))
 
+# LOWERCASE macro -- transforms its arguments to lowercase
+# The above non-tr implementation is not needed, because LOWERCASE is not
+# called very often
+
+define LOWERCASE
+$(shell echo $1 | tr '[:upper:]' '[:lower:]')
+endef
+

Not sure if a 'define' was needed here (compared to a simple assignment), but I have no strong feelings about that.

#2 lore raw

PATCH 1/1 Generation of locales: made call to tr more robust and added LOWERCASE macro

In reply to Thierry Bultel
Quoted 15 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Thierry" == Thierry Bultel <[email protected]> writes:

When calling 'tr' without quoting braces, bash can make really weird things if there are existing 'single-letter-named' directories
eg:
thierry at thierry-desktop:~$ echo AAA | tr [A-Z] [a-z]
aaa
thierry at thierry-desktop:~$ mkdir m
thierry at thierry-desktop:~$ echo AAA | tr [A-Z] [a-z]
AAA

The (quick) analysis is that the callee (tr) argvs then contain 'm' thus the translation does not work

Quoted 7 lines

Using quotes works around it:
thierry at thierry-desktop:~$ echo AAA | tr '[A-Z]' '[a-z]' aaa

Changes v1->v2
- Added the LOWERCASE macro, following Thomas De Schampheleire's advice

Committed, thanks.

Signature · 1 line
Bye, Peter Korsgaard