2

I am seeing a line of makefile as follows:

$(LAST_TARGET_DIR)/%: LFLAGS += -lpthread -lrt -Wl,-uevaluate

In my understanding, $(LAST_TARGET_DIR)/% is a target matching, and after the target should come its dependencies. Why are linking flags changed here?

1 Answer 1

5

This is a feature of GNU make that allows using a different value of a variable for one specific target or pattern.

For example,

LFLAGS = -lm
$(LAST_TARGET_DIR)/%: LFLAGS += -lpthread

%.exe: %.o common.o
    $(CC) -o $@ common.o $(@:%.exe=%.o) $(LFLAGS)

causes every .exe file to be linked with -lm, except that those in the directory $(LAST_TARGET_DIR) will be linked with -lm -lpthreads.

1
  • Great. Thanks. GNU make is not an easy system :(
    – Ziqi Fan
    Dec 10, 2021 at 22:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .