1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

makefiles/utils: functions for lowercase and uppercase

Add make only function to convert strings to lowercase and uppercase.
This can replace the `$(shell echo $(var) | tr 'a-z-' 'A-Z_')` pattern.
Using the 'make' implementation results in being around 100 times faster.
This commit is contained in:
Gaëtan Harter 2019-08-29 13:42:52 +02:00
parent 4c56827508
commit 765f3e9327
No known key found for this signature in database
GPG Key ID: 76DF6BCF1B1F883B
4 changed files with 33 additions and 0 deletions

View File

@ -89,6 +89,7 @@ CLEAN = $(filter clean, $(MAKECMDGOALS))
# include makefiles utils tools
include $(RIOTMAKE)/utils/variables.mk
include $(RIOTMAKE)/utils/strings.mk
# get host operating system
OS := $(shell uname)

View File

@ -0,0 +1,8 @@
# Make only version of string functions
#
# This replaces the pattern of using ':= $(shell echo $(var) | tr 'a-z-' 'A-Z_)'
# On local tests the make version was ~100 times faster than the shell one
lowercase = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
uppercase = $(subst a,A,$(subst b,B,$(subst c,C,$(subst d,D,$(subst e,E,$(subst f,F,$(subst g,G,$(subst h,H,$(subst i,I,$(subst j,J,$(subst k,K,$(subst l,L,$(subst m,M,$(subst n,N,$(subst o,O,$(subst p,P,$(subst q,Q,$(subst r,R,$(subst s,S,$(subst t,T,$(subst u,U,$(subst v,V,$(subst w,W,$(subst x,X,$(subst y,Y,$(subst z,Z,$1))))))))))))))))))))))))))
uppercase_and_underscore = $(call uppercase,$(subst -,_,$1))

View File

@ -0,0 +1,14 @@
include strings.mk
STRING_LOWER = abcdefghijklmnopqrstuvwxyz-123456789
STRING_UPPER = ABCDEFGHIJKLMNOPQRSTUVWXYZ-123456789
STRING_MACRO = ABCDEFGHIJKLMNOPQRSTUVWXYZ_123456789
test-lowercase:
$(Q)bash -c 'test "$(STRING_LOWER)" = "$(call lowercase,$(STRING_UPPER))" || { echo ERROR: "$(STRING_LOWER)" != "$(call lowercase,$(STRING_UPPER))"; exit 1; }'
test-uppercase:
$(Q)bash -c 'test "$(STRING_UPPER)" = "$(call uppercase,$(STRING_LOWER))" || { echo ERROR: "$(STRING_UPPER)" != "$(call uppercase,$(STRING_LOWER))"; exit 1; }'
test-uppercase_and_underscore:
$(Q)bash -c 'test "$(STRING_MACRO)" = "$(call uppercase_and_underscore,$(STRING_LOWER))" || { echo ERROR: "$(STRING_MACRO)" != "$(call uppercase_and_underscore,$(STRING_LOWER))"; exit 1; }'

View File

@ -19,6 +19,9 @@ MAKEFILES_UTILS = $(RIOTMAKE)/utils
COMPILE_TESTS += test-ensure_value test-ensure_value-negative
COMPILE_TESTS += test-exported-variables
COMPILE_TESTS += test-memoized-variables
COMPILE_TESTS += test-lowercase
COMPILE_TESTS += test-uppercase
COMPILE_TESTS += test-uppercase_and_underscore
# Tests will be run both in the host machine and in `docker`
all: build-system-utils-tests
@ -39,3 +42,10 @@ test-exported-variables:
test-memoized-variables:
$(Q)$(call command_should_succeed,"$(MAKE)" -C $(MAKEFILES_UTILS) -f test-variables.mk test-memoized-variables)
test-lowercase:
$(Q)$(call command_should_succeed,"$(MAKE)" -C $(MAKEFILES_UTILS) -f test-strings.mk test-lowercase)
test-uppercase:
$(Q)$(call command_should_succeed,"$(MAKE)" -C $(MAKEFILES_UTILS) -f test-strings.mk test-uppercase)
test-uppercase_and_underscore:
$(Q)$(call command_should_succeed,"$(MAKE)" -C $(MAKEFILES_UTILS) -f test-strings.mk test-uppercase_and_underscore)