代码之家  ›  专栏  ›  技术社区  ›  Node.JS

Makefile:变量无法正确展开

  •  0
  • Node.JS  · 技术社区  · 4 年前

    我的Makefile结构有问题。

    make commit.install 应该创造 foo.txt 然后把它放进某个文件夹。但是,make不会调用创建 foo.text .这意味着我得打电话 make foo.txt 创建文件本身,然后调用 做出承诺。安装 把这个复制过来。我认为make不扩展变量依赖性存在问题。

    /普通。mk

    src.install: ${INSTALLSRC}
            mkdir -p result
            for f in ${INSTALLSRC}; do \
                    cp -a $$f result/.; \
            done
    
    commit.install: src.install
            echo "finished"
    
    clean:
            rm -rf result
    

    ./inner/nested/GNUmakefile

    include ../common.mk
    
    include Makefile
    

    ./inner/nested/Makefile

    SRC=foo.txt
    
    foo.txt:
            echo "hello world" > foo.txt
    

    /内部/普通。mk

    include ../../common.mk
    
    INSTALLSRC=${SRC}
    

    Repository

    0 回复  |  直到 4 年前
        1
  •  1
  •   Beta    4 年前

    问题是你定义了 INSTALLSRC 之后 以它为前提的规则。因此,当Make评估前提条件列表时,变量为空,因此Make认为不需要构建 foo.txt .如果你有 simplified 这是makefiles的集合。

    解决办法很简单;把这两行换成一行 inner/common.mk :

    INSTALLSRC=${SRC}
    
    include ../../common.mk
    

    和GNUMakefile:

    include Makefile
    
    include ../common.mk