Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle files with spaces in my Makefile?

Tags:

makefile

So some anonymous developers have decided to use a ridiculous convention of using spaces in their folder names that contain their source files. I would change these folders not to use spaces but sadly I don't make the rules around here so that's not an option (though I wish it were).

LUAC            = luac

SRC_DIR         = .
SOURCE          =                                                      \
stupid/naming\ convention/a.lua                                        \
stupid/naming\ convention/very\ annoying/b.lua                         \

vpath .lua $(SRC_DIR)

OUT_DIR         = ../out/
OUTPUT          = $(patsubst %.lua, $(OUT_DIR)/%.luac, $(SOURCE))


all: $(OUTPUT)

$(OUT_DIR)/%.luac: %.lua
    $(LUAC) "$<"
    mv luac.out "$@"

.PHONY: all

Simple Makefile. All it's meant to do is compile all the Lua files that I have and put them into an output directory.

No matter I do it keeps wanting to split the SOURCE string on the spaces in the folder, so I end with a beautiful error like this:

make: *** No rule to make target `stupid/naming ', needed by `all'.  Stop.

Is there a way to fix this without renaming the folders?

Thanks in advance.

like image 384
OLL Avatar asked Jul 31 '13 08:07

OLL


1 Answers

The very short, but IMO ultimately correct, answer is that make (not just GNU make, but all POSIX-style make implementations) does not support pathnames containing whitespace. If you want to use make, your "anonymous developers" simply cannot use them. If they insist that this is an absolute requirement you should switch to a different build tool altogether, that does support whitespace in filenames.

Yes, it's barely possible to create a makefile that will work with filenames containing whitespace, but you will essentially have to rewrite all your makefiles from scratch, and you will not be able to use many of the features of GNU make so your makefiles will be long, difficult to read, and difficult to maintain.

Just tell them to get over themselves. Or if they really can't, try having them create their workspace in a pathname without any whitespace in the names, then create a symbolic link containing whitespace pointing to the real workspace (the other way around won't work in all situations).

like image 179
MadScientist Avatar answered Sep 17 '22 13:09

MadScientist