tags:

views:

18

answers:

1

I had a simple variable definition in my makefile:

THIS         := ~/edan 

and it had trailing spaces in the line.

Later, when I defined another variable in terms of this one:

WARES       := $(THIS)/wares

the actual variable defined was /home/directory/edan wares

and then the make clean rule removed /home/directory/edan instead of what I wanted it to.

How can I prevent a makefile from executing if a line has trailing spaces?

+1  A: 

Although you could write the Makefile so that it checks the variable for trailing whitespace and exits if it finds some, there are better ways of dealing with this situation.

In this instance, I would recommend using the addsuffix function to catenate $(THIS) and /wares instead of doing it manually. The addsuffix function will strip the trailing whitespace for you. In other words:

WARES := $(addsuffix /wares,$(THIS))

If you really want it to exit if it discovers trailing whitespace, you could do this:

THIS := ~/edan
ifneq "$(THIS)" "$(strip $(THIS))"
    $(error Found trailing whitespace)
endif
Dan Moulding