1

我的 Makefile 中有这条规则,它响应我通过的标志:

$(BUILD_DIR)/disable_%:
    mkdir -p $(BUILD_DIR)
    touch $(BUILD_DIR)/disable_$*
    rm -f $(BUILD_DIR)/enable_$*
    cd $(BUILD_DIR) && rm -f Makefile   

$(BUILD_DIR)/enable_%:
    mkdir -p $(BUILD_DIR)
    touch $(BUILD_DIR)/enable_$*
    rm -f $(BUILD_DIR)/disable_$*
    cd $(BUILD_DIR) && rm -f Makefile

这意味着当我更改调用 makefile 的标志时,我可以触发一些可能依赖于这些标志的重新编译。
上面的代码有点多余:你看到我删除了一个文件,触摸了另一个文件,然后在这两种情况下删除了一个 Makefile。唯一改变的是我触摸/删除的​​文件的名称,它们是相关的。

例如,

make clean
make enable_debug=yes enable_video=no # will compile from zero
make enable_debug=no enable_video=no  # flag change detected -> recompile some submodules that depend on this flag

假设两个规则之间唯一的变化([en|dis]able),我想要的是只有 1 个通用规则,如下所示:

# match 2 parts in the rule
$(BUILD_DIR)/%ble_%: 
    mkdir -p $(BUILD_DIR)
    touch $(BUILD_DIR)/(???)ble_$*  # should be $@
    rm -f $(BUILD_DIR)/(???)able_$* # should be disable if $@ is enable and inverse
    cd $(BUILD_DIR) && rm -f Makefile

这可能吗 ?

PS:对不起,如果我没有正确理解标题,我想不出如何更好地解释它。

4

1 回答 1

1
$(BUILD_DIR)/enable_% $(BUILD_DIR)/disable_%:
    mkdir -p $(BUILD_DIR)
    rm -f $(BUILD_DIR)/*able_$*
    touch $@
    cd $(BUILD_DIR) && rm -f Makefile

不是字面上你想要的(在make中禁止使用多通配符),但做的完全一样。

于 2013-10-14T08:52:27.347 回答