Return to Snippet

Revision: 22294
at January 7, 2010 20:21 by michaelaskew


Initial Code
NOTHING:=
SPACE:=$(NOTHING) $(NOTHING)

Initial URL
http://braindumpery.com

Initial Description
Make (and GMake) ignore spaces in many constructs, making it difficult to use a single space as a search string or a replacement string, for example. This trick works around the problem by assigning the space to a variable named SPACE and using that instead. So given this makefile:

    NOTHING:=
    SPACE:=$(NOTHING) $(NOTHING)
    NAME_WITH_UNDERSCORES:=$(subst $(SPACE),_,$(NAME))
    print : ; @echo $(NAME_WITH_UNDERSCORES)

The command

    gmake NAME="Professor Hubert Farnsworth"

would print

    Professor_Hubert_Farnsworth

Initial Title
Search For or Replace Spaces

Initial Tags
search, replace, filter

Initial Language
Makefile