19

GNU make マニュアルによると

複数のパターン ルールがこれらの基準を満たす可能性があります。その場合、make はステムが最も短いルール (つまり、最も具体的に一致するパターン) を選択します。

ですから、次のことに驚きました。

$ touch make_specific.cpp

$ cat Makefile.general_first
%.o: %.cpp
@echo using general rule
$(CXX) -c $< -o $@

%_specific.o: %_specific.cpp
@echo using specific rule
$(CXX) -c $< -o $@

$ make -B -f Makefile.general_first make_specific.o
using general rule
g++44 -c make_specific.cpp -o make_specific.o

複数のパターン ルールがターゲットに一致し、%_specific.o : %_specific.cppルールのステム (この場合は「make」) がルールのステムよりも短いため%.o : %.cpp、特定のルールが選択されることを期待していましたが、そうではありません。

私は何が欠けていますか?

4

1 に答える 1

19

より低いバージョンの make を使用している可能性があり3.82ます。

バージョン3.81以下では、選択基準が異なりました。makeパターンに一致した最初のルールを選択します。あなたが参照しているドキュメントはバージョン用3.82です。そのバージョンでは、期待どおりの、最も具体的な語幹を持つルールが選択されます。

ソース ツリーNEWSのファイルから:make

Version 3.82
...
* WARNING: Backward-incompatibility!
  The pattern-specific variables and pattern rules are now applied in the
  shortest stem first order instead of the definition order (variables
  and rules with the same stem length are still applied in the definition
  order). This produces the usually-desired behavior where more specific
  patterns are preferred. To detect this feature search for 'shortest-stem'
  in the .FEATURES special variable.
于 2012-07-13T04:25:05.653 に答える