Makefile:变量未正确展开 [英] Makefile: variables don't get expanded correctly

查看:29
本文介绍了Makefile:变量未正确展开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此Makefile结构有问题。

make commit.install应创建foo.txt,然后将其放入某个文件夹。但是,make不会调用创建foo.text的目标。这意味着我必须调用make foo.txt来创建文件本身,然后调用make commit.install来复制它。我认为Make Not Expansion变量依赖项有问题。

./Common.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

./INTERNAL/NESTED/GNUmake文件

include ../common.mk

include Makefile

./INTERN/NESTED/Makefile

SRC=foo.txt

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

./INTER/Common.mk

include ../../common.mk

INSTALLSRC=${SRC}

Repository

推荐答案

问题是您在将其作为先决条件的规则之后定义INSTALLSRC。因此,当make计算先决条件列表时,该变量为空,因此make认为不需要构建foo.txt。如果您有simplified这个Make文件集合,这一点将非常明显。

修复很简单;将inner/common.mk中的两行互换:

INSTALLSRC=${SRC}

include ../../common.mk

和GNUMakefile:

include Makefile

include ../common.mk

这篇关于Makefile:变量未正确展开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆