Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow space in target of GCC makefile

Is there a way to get spaces inside target names working when using make.exe? It seems to be impossible if this really ancient bug report is correct: http://savannah.gnu.org/bugs/?712

For reference, the big problem is that pieces of makefile commands like:

"foo bar baz": $(OBJ)
    $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

... seem to get treated as three separate commands: one to build "foo (note the included "), one to build bar, and lastly, one to build baz" (again, including "). This is because make.exe seems to be using space as a delimiter.

However, it's reasonable to assume that one might want to build "Hello World.exe" for example. This doesn't seem to be possible. Double quotes don't work, and neither does escaping the separate words (I've read that somewhere, don't remember the link):

"foo\\ bar\\ baz": $(OBJ)
    $(CPP) $(LINKOBJ) -o $(BIN) $(LIBS)

Is there any other way to fix this? The official manual only confirms the tokenize-by-spaces stuff, but doesn't provide a way to use space for any other purpose: http://www.gnu.org/software/make/manual/make.html#Rule-Syntax

Edit: as suggested, I've tried single slashes too, but these have the exact same effect as double slashes. Make complains it can't find rules for the first word:

mingw32-make.exe: *** No rule to make target `foo', needed by `all'.  Stop.

The executable "foo bar baz.exe" is correctly produced though, but linking is done each time per word.

like image 659
Orwell Avatar asked Feb 21 '13 14:02

Orwell


People also ask

Does whitespace matter makefile?

Whitespace and indentation in makefiles are more problematic than for other languages. Even while most of the time whitespace is not significant, sometimes it is. This might be considered a design flaw in make, but that's not something we can do anything about.

How do you resolve No rule to make target?

No rule to make target generally means simply that you have a compiler version that does not match the original compiler used in the project. You only need to go to the project properties and change the compiler to use the one you installed. Another reason could be that you moved the project or files to another folder.

What is a target and a rule in makefile?

A rule appears in the makefile and says when and how to remake certain files, called the rule's targets (most often only one per rule). It lists the other files that are the prerequisites of the target, and the recipe to use to create or update the target.


1 Answers

Instead of double backslash use single ones. The following Makefile works (at least for gnu make):

goal:   foo\ bar

foo\ bar:
    gcc -o "foo bar" "foo bar.c"
like image 89
Matthias Avatar answered Oct 16 '22 03:10

Matthias