指定一个makefile变量值bash命令的结果? [英] Assign a makefile variable value to a bash command result?

查看:132
本文介绍了指定一个makefile变量值bash命令的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在这下面一行code这个命令的输出(也就是在我的makefile)来生成文件HEADER VAR分配如下:

I'm trying to assign the output of this command ( that is in my makefile ) to the makefile HEADER var like in this following line of code:

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

问题是,如果我用打印前面在我的Makefile:

The problem is that if I print HEADER in my makefile using:

print:
    @echo $(HEADER)

我得到

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

如果我直接在控制台运行此命令,并直接在我的生成文件是:

And if I run this command directly in the console, and directly where my makefile is:

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
./engine/helper/crypto/tomcrypt/headers/tomcrypt_hash.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_mac.h
....

所以,我把我所有的头文件。我这样做是为了避免手动指定在我的makefile我所有的.h文件手动。

So I get all my header files. I'm doing this to avoid manually specifying all my .h files manually in my makefile.

任何想法?

推荐答案

您需要将shell命令中仔细逃避 $ 人物:

You will need to double-escape the $ character within the shell command:

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

这里的问题是,使将试图展开 $ F 作为一个变量,因为它没有发现任何东西,它只是用来替换它。这使得你的shell命令什么,但回声ILE ,它忠实地做。

The problem here is that make will try to expand $f as a variable, and since it doesn't find anything, it simply replaces it with "". That leaves your shell command with nothing but echo ile, which it faithfully does.

添加 $ 告诉make放置一个 $ 在那个位置,这会导致shell命令寻找正是这样,你想让它。

Adding $$ tells make to place a single $ at that position, which results in the shell command looking exactly the way you want it to.

这篇关于指定一个makefile变量值bash命令的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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