web-dev-qa-db-ja.com

makefile変数値をbashコマンドの結果に割り当てますか?

次のコード行のように、このコマンドの出力(私のmakefileにある)をmakefile HEADER varに割り当てようとしています。

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

問題は、次を使用してメイクファイルにHEADERを出力すると:

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

そして、このコマンドをコンソールで直接実行し、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
....

だから私はすべてのヘッダーファイルを取得します。これは、メイクファイルですべての.hファイルを手動で指定することを避けるためです。

何か案は ?

40
Goles

Shellコマンド内で$文字を二重エスケープする必要があります。

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

ここでの問題は、makeが$fを変数として展開しようとしますが、何も見つからないため、単純に ""に置き換えられることです。これにより、Shellコマンドはecho ileのみを残し、忠実に実行します。

$$を追加すると、その位置に単一の$を配置するようにmakeに指示します。これにより、シェルコマンドは希望どおりに表示されます。

72
e.James

なぜ単純にしないのですか

HEADER = $(Shell find . -name '*.h')
14
Sorpigal

makefile tutorial は、wildcardを使用してディレクトリ内のファイルのリストを取得することを推奨します。あなたの場合、これはこれを意味します:

HEADERS=$(wildcard *.h)
7
BЈовић