相关疑难解决方法(0)

如何将命令的输出分配给Makefile变量

我需要有条件地执行一些make规则,只要安装的Python大于某个版本(比如2.5).

我以为我可以做一些像执行:

python -c 'import sys; print int(sys.version_info >= (2,5))'
Run Code Online (Sandbox Code Playgroud)

然后在ifeqmake语句中使用输出(如果正常则为"1",否则为"0").

在一个简单的bash shell脚本中,它只是:

MY_VAR=`python -c 'import sys; print int(sys.version_info >= (2,5))'`
Run Code Online (Sandbox Code Playgroud)

但这在Makefile中不起作用.

有什么建议?我可以使用任何其他合理的解决方法来实现这一目标.

shell makefile

196
推荐指数
6
解决办法
14万
查看次数

在规则执行时定义make变量

在我的GNUmakefile中,我希望有一个使用临时目录的规则.例如:

out.tar: TMP := $(shell mktemp -d)
        echo hi $(TMP)/hi.txt
        tar -C $(TMP) cf $@ .
        rm -rf $(TMP)
Run Code Online (Sandbox Code Playgroud)

如上所述,上述规则在解析规则时创建临时目录.这意味着,即使我没有直接创建.tar,也会创建许多临时目录.我想避免我的/ tmp被未使用的临时目录弄乱.

是否有办法使该变量仅在触发规则时定义,而不是在定义时定义?

我的主要想法是将mktemp和tar转储到shell脚本中,但这看起来有点难看.

makefile gnu-make

186
推荐指数
4
解决办法
14万
查看次数

将makefile变量值分配给bash命令结果?

我正在尝试将此命令的输出(即在我的makefile中)分配给makefile HEADER var,如下面的代码行所示:

HEADER = $(shell for file in `find . -name *.h`;do echo $file; done)
Run Code Online (Sandbox Code Playgroud)

问题是,如果我使用以下命令在makefile中打印HEADER:

print:
    @echo $(HEADER)
Run Code Online (Sandbox Code Playgroud)

我明白了

ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile ile
Run Code Online (Sandbox Code Playgroud)

如果我直接在控制台中运行此命令,并直接在我的makefile所在的位置:

myaccount$ for file in `find . -name *.h`;do echo $file; done
./engine/helper/crypto/tomcrypt/headers/._tomcrypt_pk.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_argchk.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_cfg.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_cipher.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_custom.h …
Run Code Online (Sandbox Code Playgroud)

bash shell makefile

42
推荐指数
3
解决办法
6万
查看次数

标签 统计

makefile ×3

shell ×2

bash ×1

gnu-make ×1