4 ms·
This should accept exactly "me a sandwich" or "ME A SANDWICH" on the GNU Make command line and do what's expected. And has the advantage of no repetition. But i
by jgrahamc 5y ago
This should accept exactly "me a sandwich" or "ME A SANDWICH" on the GNU Make command line and do what's expected. And has the advantage of no repetition. But it is a tad more complex.
[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
tr = $(if $1$2,$(call tr,$(wordlist 2,$(words $1),$1),$(wordlist 2,\
$(words $2),$2),$(subst $(firstword $1),$(firstword $2),$3)),$3)
toupper = $(call tr,$([a-z]),$([A-Z]),$1)
COMMAND := me a sandwich
ifeq ($(MAKECMDGOALS),$(COMMAND))
fixcase = $1
endif
ifeq ($(MAKECMDGOALS),$(call toupper,$(COMMAND)))
fixcase = $(call toupper,$1)
endif
ifdef fixcase
.PHONY: $(MAKECMDGOALS)
UID := $(subst 0,,$(shell id -u))
$(wordlist 1,2,$(MAKECMDGOALS)): ; @true
$(lastword $(MAKECMDGOALS)): ; @echo "$(call fixcase,$(if $(UID),\
What? Make it yourself,Okay))."
endif
- chrismorgan 5y agoI think my favourite part of this is the inclusion of square brackets in the variable names [A-Z] and [a-z]. And possibly your description of this as “a tad more complex”. I love makefiles!
- jgrahamc 5y agoI have been messing with GNU Make syntax for... a while. https://gmsl.sourceforge.io/ https://gmsl.sourceforge.io/
- chrismorgan 5y agoI’ve enjoyed reading a lot of your stuff pertaining to Make. You chimed in last year when I wrote something about Make too: https://news.ycombinator.com/item?id=23268911 https://news.ycombinator.com/item?id=23268911. Thanks :-)