0

I have this Makefile

CC=g++
CFLAGS=-g -c -Wall -o standalone
MYSQLINCLUDE = -I/usr/local/include/mysql
MYSQLINCLUDESP = -I/usr/local/include/
LDFLAGS =-L/usr/local/lib
LDFLAGSSP =-L/usr/local/lib/mysql  -lmysqlclient -lmysqlcppconn
SOURCES= /usr/eval/demo 1/user/demo1/p2/main.cpp 
OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=p2
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
    $(CC) $(LDFLAGS) $(LDFLAGSSP) $(OBJECTS) -o $@
.cpp.o:
    $(CC) $(MYSQLINCLUDESP) $(CFLAGS) $< -o $@
clean:
    rm -rf $(OBJECTS) $(EXECUTABLE) *.core

The problem are to this line

SOURCES= /usr/eval/demo 1/user/demo1/p2/main.cpp 

with the space between demo and 1 and I get this error

`make: don't know how to make /usr/eval/demo Stop`

this Makefile is auto generate from other program

xnl96
  • 189
  • 2
  • 11
  • 1
    In general you cannot use filenames containing whitespace (or colons) in make. – MadScientist May 28 '12 at 19:58
  • Yeah it seams very messy at least, maybe this http://stackoverflow.com/questions/668322/what-is-the-most-reliable-way-of-using-gnumake-with-filenames-containing-spaces question can help – Mattias Wadman May 28 '12 at 20:46

2 Answers2

0

Try to escape:

SOURCES=/usr/eval/demo\ 1/user/demo1/p2/main.cpp

Or use quotes:

SOURCES="/usr/eval/demo 1/user/demo1/p2/main.cpp"
Mattias Wadman
  • 11,172
  • 2
  • 42
  • 57
  • I try this `SOURCES=/usr/eval/demo\ 1/user/demo1/p2/main.cpp ; SOURCES="/usr/eval/demo 1/user/demo1/p2/main.cpp" ; SOURCES="/usr/eval/demo\ 1/user/demo1/p2/main.cpp"` but is not working – xnl96 May 28 '12 at 18:22
0

Working under MSYS on Windows (GNU make 3.79.1) I battled this problem for a while, and came up with:

ifndef ESCAPE_PATH
ESCAPE_SPACE = $(subst _,,_ _)
ESCAPE_PATH = $(subst $(ESCAPE_SPACE),\$(ESCAPE_SPACE),$(1))
endif

Then, for example:

PROBLEM = ../problem with spaces.txt

PROBLEM_ESCAPED = $(call ESCAPE_PATH,$(PROBLEM))

$(PROBLEM_ESCAPED):
    date >$(PROBLEM_ESCAPED)

md5: $(PROBLEM_ESCAPED)
    md5sum $(PROBLEM_ESCAPED) >$(PROBLEM_ESCAPED).md5sum

This works in a simple make file, and even in more complex circumstances, but I have a real project where it does not work, and it is not simple to reproduce in a generic example to demonstrate. A number of include files bring in data, reusable make resources, targets, etc. The value assigned to PROBLEM is derived from other variables also in an include file, includes a path computed relative to $(CURDIR), though ultimately at the file name resolves to a simple constant string. What the precise circumstances are that cause the breakage is not known and at least one attempt to create and example for this post did not reproduce the problem (GNU make could not detect that the $(PROBLEM) file already existed and did not need to be rebuilt).

It seems clear (to me) that spaces in file names pose a challenge for GNU make for which there is no obvious one-size-fits-all solution.

kbulgrien
  • 4,384
  • 2
  • 26
  • 43