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

Thomas De Schampheleire patrickdepinguin at gmail.com
Sun Nov 10 20:33:32 UTC 2013


Hi Thierry,

On Sun, Nov 10, 2013 at 6:32 PM, Thierry Bultel
<thierry.bultel at wanadoo.fr> wrote:
> 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
>

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

>
> Signed-off-by: Thierry Bultel <thierry.bultel at wanadoo.fr>
> ---
>  Makefile             |    2 +-
>  package/pkg-utils.mk |    8 ++++++++
>  2 files changed, 9 insertions(+), 1 deletions(-)
>
> diff --git a/Makefile b/Makefile
> index 1496bd7..a006615 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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
> diff --git a/package/pkg-utils.mk b/package/pkg-utils.mk
> index 5930f2c..0ef433d 100644
> --- a/package/pkg-utils.mk
> +++ b/package/pkg-utils.mk
> @@ -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
> +

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

Reviewed-by: Thomas De Schampheleire <thomas.de.schampheleire at gmail.com>


More information about the buildroot mailing list