Sometimes it's handy to be able to 'tr' inside GNU Make without wasting
time going to the shell. Here's an implementation that works with GNU
Make 3.80:
# The tr function. Has three arguments:
#
# $1 The list of characters to translate from
# $2 The list of characters to translate to
# $3 The text to translate
#
# For example, $(call tr,A B C,1 2 3,CAPITAL) becomes 21PIT1L.
tr = $(eval __t := $3) \
$(foreach c, \
$(join $(addsuffix :,$1),$2), \
$(eval __t := \
$(subst $(word 1,$(subst :, ,$c)),$(word 2,$(subst :, ,$c)), \
$(__t))))$(__t)
# Common character classes for use with the tr function. Each of
# these is actually a variable declaration and must be wrapped with
# $() or ${} to be used.
[A-Z] := A B C D E F G H I J K L M N O P Q R S T U V W X Y Z #
[a-z] := a b c d e f g h i j k l m n o p q r s t u v w x y z #
[0-9] := 0 1 2 3 4 5 6 7 8 9 #
[A-F] := A B C D E F #
# Upper case and lower case functions. Each function has a single
# argument which is the text to alter
uc = $(call tr,$([a-z]),$([A-Z]),$1)
lc = $(call tr,$([A-Z]),$([a-z]),$1)
.PHONY: all
all:
@echo $(call lc,The Quick Brown Fox)
@echo $(call uc,The Quick Brown Fox)
John.
--
John Graham-Cumming
Home: http://www.jgc.org/
Work: http://www.electric-cloud.com/
POPFile: http://getpopfile.org/
_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make