Escaping colons in filenames in a Makefile

The answers here all seemed too complex to be helpful. I finally found a solution here:

colon := :
$(colon) := :

and then used the macro in the filename as:

filename$(:)

which successfully translated to "filename:" upon evaluation.


The following hack worked for me, though it unfortunately relies on $(shell).

# modify file names immediately
PRE := $(shell rename : @COLON@ *)
# example variables that I need
XDLS = $(wildcard *.xdl)
YYYS = $(patsubst %.xdl,%.yyy,$(XDLS))
# restore file names later
POST = $(shell rename @COLON@ : *)

wrapper: $(YYYS)
    @# restore file names
    $(POST)

$(YYYS):
    @# show file names after $(PRE) renaming but before $(POST) renaming
    @ls

Because PRE is assigned with :=, its associated shell command is run before the XDLS variable is evaluated. The key is to then put the colons back in place after the fact by explicitly invoking $(POST).


I doubt it's possible: see this discussion about colons in Makefiles. In summary, GNU make has never worked well with filenames that contain whitespace or colons. The maintainer, Paul D. Smith, says that adding support for escaping would tend to break existing makefiles. Furthermore, adding such support would require significant changes to the code.

You might be able to work around with some sort of nasty temporary file arrangement.

Good luck!