首页 > 解决方案 > 递归 Makefile 总是重新制作目标

问题描述

我正在尝试创建一个 Makefile 目标,该目标将使用不同的选项调用自身。

# Include config.mk which sets design-specific variables
`include $(CONFIG)

# This command runs the script once with current options
$(LOG_DIR)/compare.log: $(RESULTS_DIR)/final.bin
  tclsh $(UTILS_DIR)/script.tcl | tee $@

# Alias for above command
compare: $(LOG_DIR)/compare.log

# This command runs make once for each config file
.PHONY: compare_all
compare_all:
  for config in designs/*/config.mk; do \
    $(MAKE) CONFIG=$$config compare; \
  done
  $(UTILS_DIR)/compare_all.py

问题是compare_all目标按预期工作,但它总是认为 sub-make 目标已过时。

例如,当我跑步时

make CONFIG=designs/a/config.mk compare
make CONFIG=designs/b/config.mk compare
make CONFIG=designs/c/config.mk compare

我得到:

make: Nothing to be done for 'compare'.
make: Nothing to be done for 'compare'.
make: Nothing to be done for 'compare'.

但是当我跑步时make compare_all -n,我得到

tclsh utils/script.tcl | tee logs/a/compare.log
tclsh utils/script.tcl | tee logs/b/compare.log
tclsh utils/script.tcl | tee logs/c/compare.log

表明它将重建所有设计,即使它们已经是最新的。

标签: makefile

解决方案


推荐阅读