Quantcast
Channel: User HolyBlackCat - Stack Overflow
Viewing all articles
Browse latest Browse all 1278

Answer by HolyBlackCat for Makefile Pattern recipe for filename copying and renaming as temporary file

$
0
0

Alright... Here's the function to convert a string to uppercase:

override alphabet := \    A-a B-b C-c D-d E-e \    F-f G-g H-h I-i J-j \    K-k L-l M-m N-n O-o \    P-p Q-q R-r S-s T-t \    U-u V-v W-w X-x Y-y \    Z-zoverride var = $(eval override $(subst #,\#,$(subst $,$$$$,$1)))override uppercase = $(call,$(call var,_ret := $1)$(foreach x,$(alphabet),$(call var,_ret := $(subst $(lastword $(subst -, ,$x)),$(firstword $(subst -, ,$x)),$(_ret)))))$(_ret)

This is way faster than using $(shell ) as @RenaudPacalet does in his answer (made a little benchmark processing 10 strings; this code takes ~6ms, while their takes ~56ms).

Here, var is a helper function that safely assigns to a variable, without tripping on special characters. $(call, ...) is a hack to evaluate the argument and destroy the string it expands to.

And here's how you use it to copy files: (this isn't too different from @RenaudPacalet's answer)

.PHONY: alloverride define rename_rule =all: $(call uppercase,$(basename $1))$(call uppercase,$(basename $1)): $1    cp $$< $$@endef$(foreach f,$(wildcard *.irx),$(eval $(call rename_rule,$f)))

Viewing all articles
Browse latest Browse all 1278

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>