GNU Make meets file names with spaces in them


then the best thing to do is transform them by substituting space with some other
character and then change them back again.

For example, the s+ and +s functions here change escaped spaces to + signs and back
again.  You can then safely manipulate lists of file names using all the GNU Make
functions.  Just be sure to remove the +'s before using these names in a rule.

s+ = $(subst \\ ,+,$1)

+s = $(subst +,\\ ,$1)

Here's a fuller example where a list of source files that contain escaped spaces is
transformed into a list of object files and then the object files are used to define the
prerequisites of the all rule.

SRCS := a\\ b.c c\\ d.c e\\ f.c

SRCS := $(call s+,$(SRCS))

OBJS := $(SRCS:.c=.o)

all: $(call +s,$(OBJS))

About the author

AgileConnection is a TechWell community.

Through conferences, training, consulting, and online resources, TechWell helps you develop and deliver great software every day.