views:

38

answers:

2

Using GNU's make, I'd like to extract the first character of a variable. Currently I'm using the shell function to have bash perform the substring. I'm wanting to know if there is a way using gmake's built-ins to do the same.

DIR=/user/$(shell echo "$${USER:0:1}")/$(USER)/
+1  A: 

http://www.gnu.org/software/make/manual/make.html#Functions is a comprehensive list of everything you can do with gmake builtins.

It does not appear to be possible to extract the first character without $(shell), unfortunately.

Zack
+1  A: 

It's not very satisfying, and you'd have to add to $(INITIALS) until you were happy, but:

INITIALS := 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
U := $(strip $(foreach a,$(INITIALS),$(if $(USER:$a%=),,$a)))

DIR = /user/$(U)/$(USER)/

Perhaps the sensible approach would be to take note of the := usages in the above, and amend your simple version to DIR := ...$(shell ...)... so that the shell command is only invoked once.

John Marshall