gpt4 book ai didi

Makefile变量扩展/评估

转载 作者:行者123 更新时间:2023-12-04 05:04:43 30 4
gpt4 key购买 nike

目前,由于生成变量的评估,我的Makefile遇到了问题。我降低了复杂性,仅保留了导致问题的基本要素。

读取Makefile时,

  • $(LIST)被评估为文件列表。
  • 在步骤1中,其中一个文件被删除。
  • 在步骤2中使用变量时,不会再次对其求值,因此不再有效,这会导致在复制命令期间出错。
  • 如果在使用变量时在步骤2中对变量进行了评估,那就太好了。

  • 有任何解决或解决此问题的想法吗?

    Makefile:
    LIST=$(wildcard src/*.txt)

    all: step1 step2

    step1:
    @echo "---------- step1 ----------"
    @echo $(LIST)
    rm src/q1.txt
    ls src

    step2:
    @echo "---------- step2 ----------"
    @echo $(LIST)
    cp $(LIST) ./dst

    执行日志:
    $ make
    ---------- step1 ----------
    src/q1.txt src/q2.txt
    rm src/q1.txt
    ls src
    q2.txt
    ---------- step2 ----------
    src/q1.txt src/q2.txt
    cp src/q1.txt src/q2.txt ./dst
    cp: cannot stat `src/q1.txt': No such file or directory
    make: *** [step2] Error 1

    最佳答案

    不要使用通配符功能。

    LIST = src/*.txt

    all: step1 step2

    step1:
    @echo "---------- step1 ----------"
    @echo $(LIST)
    rm src/q1.txt
    ls src

    step2:
    @echo "---------- step2 ----------"
    @echo $(LIST)
    cp $(LIST) ./dst

    关于Makefile变量扩展/评估,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9030129/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com