Gol*_*les 42 bash shell makefile
我正在尝试将此命令的输出(即在我的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
./engine/helper/crypto/tomcrypt/headers/tomcrypt_hash.h
./engine/helper/crypto/tomcrypt/headers/tomcrypt_mac.h
....
Run Code Online (Sandbox Code Playgroud)
所以我得到了所有的头文件.我这样做是为了避免在makefile中手动指定所有我的.h文件.
有任何想法吗 ?
e.J*_*mes 74
您需要$在shell命令中双重转义字符:
HEADER = $(shell for file in `find . -name *.h`;do echo $$file; done)
Run Code Online (Sandbox Code Playgroud)
这里的问题是make会尝试扩展$f为变量,因为它没有找到任何东西,它只是用""替换它.这使得你的shell命令什么都没有,但echo ile它忠实地做了.
添加$$tell make会$在该位置放置一个,这会导致shell命令完全按照您希望的方式查找.
Sor*_*gal 14
为什么不简单呢
HEADER = $(shell find . -name '*.h')
Run Code Online (Sandbox Code Playgroud)
在生成文件教程建议使用wildcard来获得目录中的文件列表.在你的情况下,它意味着:
HEADERS=$(wildcard *.h)
Run Code Online (Sandbox Code Playgroud)