Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can GNU make handle filenames with spaces?

I have a directory containing several files, some of which have spaces in their names:

Test workspace/ Another directory/ file1.ext file2.ext demo 2012-03-23.odp 

I use GNU's $(wildcard) command on this directory, and then iterate over the result using $(foreach), printing everything out. Here's the code:

FOO := $(wildcard *) $(info FOO = $(FOO)) $(foreach PLACE,$(FOO),$(info PLACE = $(PLACE))) 

Here's what I would expect to see printed out:

Test workspace Another directory file1.ext file2.ext demo 2012-03-23.odp 

Here's what I would actually get:

Test workspace Another directory file1.ext file2.ext demo 2012-03-23.odp 

The latter is obviously of no use to me. The documentation for $(wildcard) flat-out states that it returns a "space-separated list of names" but completely fails to acknowledge the huge problems this raises. Nor does the documentation for $(foreach).

Is it possible to work around this? If so, how? Renaming every file and directory to remove the spaces is not an option.

like image 295
qntm Avatar asked Mar 23 '12 11:03

qntm


1 Answers

The bug #712 suggests that make does not handle names with spaces. Nowhere, never.

I found a blog post saying it's partially implemented by escaping the spaces with \ (\\ seems to be typo or formatting artefact), but:

  • It does not work in any functions except $(wildcard).
  • It does not work when expanding lists of names from variables, which includes the special variables $?, $^ and $+ as well as any user-defined variable. Which in turn means that while $(wildcard) will match correct files, you won't be able to interpret the result anyway.

So with explicit or very simple pattern rules you can get it to work, but beyond that you are out of luck. You'll have to look for some other build system that does support spaces. I am not sure whether jam/bjam does, scons, waf, ant, nant and msbuild all should work.

like image 157
Jan Hudec Avatar answered Oct 20 '22 14:10

Jan Hudec