You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Makefile技巧:执行make target1时如何强制跳过target0依赖?

如何在执行make target1时跳过依赖target0?

问题背景

用户提供的Makefile内容如下:

.PHONY: target0 target1

target0:
    <command>

target1: target0
    <command>

需要实现:执行make target1时,强制跳过依赖目标target0。

解决方法

  • 方法1:用-t标记更新目标时间戳
    先执行make -t target1更新target1的时间戳,让make判定它已处于最新状态,之后再执行make target1就不会触发target0的执行:

    make -t target1 && make target1
    
  • 方法2:用-o选项忽略指定依赖
    直接在命令行添加-o target0参数,告诉maketarget0始终是最新的,无需处理:

    make -o target0 target1
    
  • 方法3:临时覆盖依赖定义
    通过命令行参数直接清空target1的依赖,临时修改Makefile的生效逻辑:

    make target1 target0=
    

内容的提问来源于stack exchange,提问作者user1334858

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.15 22:50:40