Joe
Joe

Reputation: 3796

In a makefile, how can I paste a directory path to every file in a list of files?

If I define the following variables in my makefile

REPORT_DIR = ./reports

REPORT_TARGETS = my_report.html another_report.html

clean: 
    rm -f $(REPORT_DIR)/$(REPORT_TARGETS)

When I execute make clean the report directory is only pasted to the first report target.

rm -f ./reports/my_report.html another_report.html

My goal is that executing make clean would produce

rm -f ./reports/my_report.html ./reports/another_report.html

How can I paste ./reports/ to all elements of REPORT_TARGETS?

Upvotes: 0

Views: 58

Answers (1)

Beta
Beta

Reputation: 99094

Use the addprefix function:

TARGETS_WITH_PATHS := $(addprefix $(REPORT_DIR)/, $(REPORT_TARGETS))

Upvotes: 1

Related Questions