linbianxiaocao
linbianxiaocao

Reputation: 930

What does two percent % symbols mean in this Makefile sentence?

I encountered this line of code in Makefile. I have tried so hard to find an explanation but not able to. Can someone pass a hint if you have a clue? In particular, what does symbol %= mean in this Makefile sentence.

ifndef VARA
    VARB := $(CURDIR:/Dev/home/ajhome/%=/home/%)
    export VARA:= $(VARB)
endif

Appreciate a lot in advance.

Upvotes: 2

Views: 1271

Answers (1)

Wintermute
Wintermute

Reputation: 44023

That shouldn't be read as a %=, the % and = have different functions. It's a pattern substitution:

$(VARNAME:pattern1=pattern2)

And % is a placeholder in the pattern. This is often used (for example) to get the name of object files from source files, for example

SRCS = foo.c bar.c
OBJS = $(SRCS:%.c=%.o)

# $(OBJS) is foo.o bar.o

In your case, it will take the directory in $(CURDIR) and replace the /Dev/home/ajhome/ at its beginning with /home/. Well, if $(CURDIR) is a list of directories, it will do so for each one of them, but the variable name suggests that there's only one in them, so I'm going with that.

Upvotes: 8

Related Questions