[Makefile] String Replacement Example
First example: replace . with -
i.e.,
mn.004.contrast-reading.html => mn-004-contrast-reading-html
Second example: replace ending .html with %zh.rst
i.e.,
mn.004.contrast-reading.html => mn.004.contrast-reading%zh.rst
Source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | FILENAME:= mn.004.contrast-reading.html DOT:= . DASH:= - # replace . with - RESULT= $(subst $(DOT),$(DASH),$(FILENAME)) HTML_SUFFIX:= .html RST_SUFFIX:= \%zh.rst # replace .html with %zh.rst RESULT2= $(subst $(HTML_SUFFIX),$(RST_SUFFIX),$(FILENAME)) default: @echo $(RESULT) @echo $(RESULT2) |
Output:
mn-004-contrast-reading-html
mn.004.contrast-reading%zh.rst
Tested on Ubuntu Linux 15.10, GNU make 4.0-8.2.
References:
[3] | makefile file name manipulation · twnanda/twnanda@0323a19 · GitHub |