Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In GNU Make, how do I convert a variable to lower case?

Tags:

makefile

This is a silly question, but.... with GNU Make:

VAR = MixedCaseText LOWER_VAR = $(VAR,lc)  default:         @echo $(VAR)         @echo $(LOWER_VAR) 

In the above example, what's the correct syntax for converting VAR's contents to lower case? The syntax shown (and everything else I've run across) result in LOWER_VAR being an empty string.

like image 491
DonGar Avatar asked Mar 20 '09 00:03

DonGar


People also ask

How do you convert a set of string variable to lowercase?

The toLowerCase method converts a string to lowercase letters. The toLowerCase() method doesn't take in any parameters. Strings in JavaScript are immutable. The toLowerCase() method converts the string specified into a new one that consists of only lowercase letters and returns that value.

How do I convert a string to lowercase in shell script?

To convert a string to lowercase in Bash, use tr command. tr stands for translate or transliterate. With tr command we can translate uppercase characters, if any, in the input string to lowercase characters.

How do you make a uppercase variable?

'^' symbol is used to convert the first character of any string to uppercase and '^^' symbol is used to convert the whole string to the uppercase.

How do you make a lowercase variable in Python?

The lower() method converts all uppercase characters in a string into lowercase characters and returns it.


2 Answers

you can always spawn off tr

LOWER_VAR = `echo $(VAR) | tr A-Z a-z` 

or

LOWER_VAR  = $(shell echo $(VAR) | tr A-Z a-z) 

The 'lc' functions you trying to call is from GNU Make Standard Library

Assuming that is installed , the proper syntax would be

LOWER_VAR  = $(call lc,$(VAR)) 
like image 159
3 revs, 2 users 86% Avatar answered Sep 24 '22 21:09

3 revs, 2 users 86%


You can do this directly in gmake, without using the GNU Make Standard Library:

lc = $(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))))))))))))))))))))))))))  VAR = MixedCaseText LOWER_VAR = $(call lc,$(VAR))  all:         @echo $(VAR)         @echo $(LOWER_VAR) 

It looks a little clunky, but it gets the job done.

If you do go with the $(shell) variety, please do use := instead of just =, as in LOWER_VAR := $(shell echo $VAR | tr A-Z a-z). That way, you only invoke the shell one time, when the variable is declared, instead of every time the variable is referenced!

Hope that helps.

like image 37
Eric Melski Avatar answered Sep 20 '22 21:09

Eric Melski