2017-06-13 12 views
1

私のすべてのサービス用のベースメイクファイルがあります。デフォルトの「テスト」ターゲットを使用したい場合もあれば、それを上書きしたい場合もあります。これらは私がこれまでに持っていたファイルです(明らかに期待通りに動作しません)。メイクファイルの追加とオーバーライドの両方を許可する

MakefileBase

test: 
    ./.../run-tests.sh 

Makefileの

BASE_FILE := /path/to/MakefileBase 
include ${BASE_FILE} 
test: 
    @$(MAKE) -f $(BASE_FILE) test # un/comment this line in order to run the default tests. 
# echo "custom test" 

期待どおりに動作します警告を除いて、私は私が

Makefile:10: warning: overriding commands for target `test' 
/.../MakefileBase:63: warning: ignoring old commands for target `test' 
echo "no tests" 
no tests 

次取得コメントアウト最初の行でテストを実行問題は親関数を使用しようとすると次のエラーが発生することです。

Makefile:9: warning: overriding commands for target `test' 
/.../MakefileBase:63: warning: ignoring old commands for target `test' 
make[1]: test: No such file or directory 
make[1]: *** No rule to make target `test'. Stop. 
make: *** [test] Error 2 

答えて

0

これはdouble-colon rulesはのためのものです:これは、既存のターゲット "に追加" します

BASE_FILE := /path/to/MakefileBase 
include ${BASE_FILE} 

test:: 
     @$(MAKE) -f $(BASE_FILE) test 

test:: 
     ./.../run-tests.sh 

と。別のレシピでターゲットをオーバーライドする方法はありませんが、警告は発生しません。

唯一の方法は、変数を使用してレシピを保持し、変数値を上書きすることです。

test_recipe = ./.../run-tests.sh 

test: 
     $(test_recipe) 

と::たとえば、私は `テストを追加しようとした場合

BASE_FILE := /path/to/MakefileBase 
include ${BASE_FILE} 

test_recipe = @$(MAKE) -f $(BASE_FILE) test 
+0

それだけで、コマンドを追加します:: は '「私はまったく何もしないようにしたい」エコーそれが実行されますベースファイルからのコマンドとエコーよりも –

関連する問題