tags:

views:

1300

answers:

2

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.

+3  A: 

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))
Vardhan Varma
In my case, the $(call lc,$VAR) syntax is also resulting in an empty string. I guess that library isn't installed, and it would be non-optimal for me to require all of our developers to install it. However, the spawn out is working.
DonGar
Make sure you put curly braces or parentheses around any variable name longer than one character. $VAR will be evaluated by make to AR unless $V is set to something, so use ${VAR} instead.
Jason Catena
@Jason, thanx for telling. I've fixed the answer.
Vardhan Varma
+1  A: 

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,

Eric Melski

Eric Melski