【发布时间】:2017-12-14 03:09:46
【问题描述】:
我有一个 Makefile,它在自己的目录中管理多个 FPGA 构建。我有一个变量CS_FPGA_FETCH,它具有每个 fpga 的唯一名称。 (我项目中的许多子文件夹都是基于此名称)。
我想要一种干净的方式来处理为每个 FPGA 添加目标。我想出的是addprefix 并删除了前缀。
# Every FPGA
CS_FPGAS_FETCH := cs00 cs01 cs02 cs03 cs10 cs11 cs12 cs13 cs20 cs21 cs22 cs23 cs30 cs31 cs32 cs33
# this is a list of variables that has the words copy_official_ prefixed
# to all of the cs00, cs01
COPY_OFFICIAL_CS_TARGETS=$(addprefix copy_official_,$(CS_FPGAS_FETCH))
# because we use add prefix, we HAVE to strip it off
# this replases $(@) for guys with a prefix, so we can access the base variable inside the loop below
COPY_TARGET_FPGA_NAME=$(@:copy_official_%=%)
# this evaluates out to targets named:
# copy_official_cs00, copy_official_cs01 etc
$(COPY_OFFICIAL_CS_TARGETS):
@echo In $(@) target. Here i copy file $(COPY_TARGET_FPGA_NAME)
cp build/$(COPY_TARGET_FPGA_NAME)/file.bit install/$(COPY_TARGET_FPGA_NAME)
这种方法对我来说似乎是倒退的。我需要为我想使用的每个前缀创建一个COPY_TARGET_FPGA_NAME。这似乎非常令人困惑。我需要添加许多具有不同前缀的此类目标。
【问题讨论】: