Substitution of extensions in the list of file names separated by spaces is a general requirement, and there are built-in functions for this. If you want to add x at the end of each name in the list:
FILES_OUT = $(FILES_IN:=x)
General view of $(VARIABLE:OLD_SUFFIX=NEW_SUFFIX) . This takes the value VARIABLE and replaces OLD_SUFFIX at the end of each word that ends with this suffix with NEW_SUFFIX (inconsistent words remain unchanged). GNU calls this function (which exists in every make implementation) of the replacement reference .
If you just want to change .doc to .docx and .xls to .xlsx using this function, you need to use an intermediate variable.
FILES_OUT_1 = $(FILES_IN:.doc=.docx) FILES_OUT = $(FILES_OUT_1:.xls=.xlsx)
You can also use a slightly more general $(VARIABLE:OLD_PREFIX%OLD_SUFFIX=NEW_PREFIX%NEW_SUFFIX) syntax $(VARIABLE:OLD_PREFIX%OLD_SUFFIX=NEW_PREFIX%NEW_SUFFIX) . This feature is not unique to GNU make, but not as portable as a simple suffix replacement.
There is also a GNU make function that allows you to chain multiple substitutions on a single line: the patsubst function .
FILES_OUT = $(patsubst %.xls,%.xlsx,$(patsubst %.doc,%.docx,$(FILES_IN)))
Gilles Aug 22 '12 at 11:18 2012-08-22 11:18
source share