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

John Graham-Cumming's picture John Graham-Cumming

John Graham-Cumming is Co-Founder at Electric Cloud, Inc . Prior to joining Electric Cloud, John was a Venture Consultant with Accel Partners, VP of Internet Technology at Interwoven, Inc. (IWOV), VP of Engineering at Scriptics Corporation (acquired by Interwoven), and Chief Architect at Optimal Networks, Inc. John holds BA and MA degrees in Mathematics and Computation and a Doctorate in Computer Security from Oxford University. John is the creator of the highly acclaimed open source POPFile project. He also holds two patents in network analysis and has others pending.

AgileConnection is one of the growing communities of the TechWell network.

Featuring fresh, insightful stories, is the place to go for what is happening in software development and delivery.  Join the conversation now!