我明白,「顯式」模式規則在其先決條件可以生效時將優先於其隱式對應模式。確保存在模式規則的先決條件
all: src/foo.o
src/%.o: makefile my_haeder.h src/%.c
echo Do something with those source files
如果存在「my_header.h」的拼寫錯誤,則%.o的隱式規則優先。不僅我的食譜不會被執行,而且觸摸先決條件也不會觸發規則。其實這是我感興趣的第二點。
SET_OF_FILES=src/foo.o
all: src/foo.o
$(SET_OF_FILES): src/%.o: makefile my_haeder.h src/%.c
echo Do something with those source files
這導致:
該補充文件使用靜態模式規則提供了一個驗證
gmake: *** No rule to make target `src/my_haeder.h', needed by `src/foo.o'. Stop.
雖然較大的規則,該解決方案是好的,只要我不必須添加一個可以重疊的規則:
SET_OF_FILES=src/foo.o src/subsrc/bar.o
all: src/foo.o
$(SET_OF_FILES): src/%.o: makefile my_header.h src/%.c
echo Do something with those source files
$(SET_OF_FILES): src/subsrc/%.o: makefile my_header.h src/subsrc/%.c
echo Do something with those other source files
其中結果爲:
makefile:8: target `src/foo.o' doesn't match the target pattern
makefile:9: warning: overriding commands for target `src/foo.o'
makefile:6: warning: ignoring old commands for target `src/foo.o'
makefile:9: warning: overriding commands for target `src/subsrc/bar.o'
makefile:6: warning: ignoring old commands for target `src/subsrc/bar.o'
第一條消息是在這裏,因爲我沒有打擾$(filter)ing SET_OF_FILES。我不知道如何解決接下來的警告,對於任何評論者來說,這意味着「有些事情是錯誤的」。
是否有另一種(更優雅的)方法來驗證先決條件實際上是否可行,以避免丟棄顯式模式規則?
(使用GNU使3.79.1的win32)
你的 「重疊」 例如沒有按對我來說沒有意義,因爲第一個子句應該指定模式規則適用的目標文件。 你將兩個目標結合在一起:這就是說每個目標都應該使用兩個規則。 – ewindes 2017-07-12 22:16:12