2

Makefile の環境変数 PATH を変更しても、CLT の make では効果がありません。元のソースからコンパイルした make util では問題ありません。

シンプルなメイクファイル

PATH := $(PATH):/opt/bin

export PATH

all:
      @cscope --version

私のテスト

/tmp $ echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin
/tmp $ ls /opt/bin/cscope
/opt/bin/cscope
/tmp $ which make
/usr/bin/make
/tmp $ make
make: cscope: No such file or directory
make: *** [all] Error 1
/tmp $ ./_install/bin/make
cscope: version 15.7a
/tmp $ make --version
GNU Make 3.81
Copyright (C) 2006  Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.


This program built for i386-apple-darwin11.3.0
/tmp $ ./_install/bin/make --version
GNU Make 3.82
Built for x86_64-apple-darwin12.0.0
Copyright (C) 2010  Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

誰でも助けることができますか?

4

1 に答える 1

2

make変数と変数を混同していshellます。makeセットアップでは、呼び出されるシェル コマンドは、設定した変数の影響を受けませんPATH

PATH次のように、レシピ内に変数を設定する必要があります

all:
    @PATH=$(PATH):/opt/bin; cscope --version

PATHレシピのすべての行が別のシェルで実行され、行った設定が事実上失われるため、1 行で両方を実行する必要があります。\または、各行の最後にバックスラッシュを追加して、複数の行に分割できます。

all:
    @PATH=$(PATH):/opt/bin; \
    cscope --version

アップデート

申し訳ありませんが、あなたの makefile を使用することの重要性を見逃していましたmake 3.82。私は両方のバージョンと実際に試してみましたが3.813.82この場合は動作が異なります。

次のよう3.81に呼び出すことで、これを機能させることができました。make

make SHELL="/bin/sh -c"

また

make SHELL=/bin/bash
于 2012-07-31T17:45:36.000 に答える