2010-10-14 24 views
123

這是我的Makefile:爲什麼認爲目標是最新的?

REBAR=./rebar 
REBAR_COMPILE=$(REBAR) get-deps compile 

all: compile 

compile: 
    $(REBAR_COMPILE) 

test: 
    $(REBAR_COMPILE) skip_deps=true eunit 

clean: 
    -rm -rf deps ebin priv doc/* 

docs: 
    $(REBAR_COMPILE) doc 

ifeq ($(wildcard dialyzer/sqlite3.plt),) 
static: 
    $(REBAR_COMPILE) build_plt analyze 
else 
static: 
    $(REBAR_COMPILE) analyze 
endif 

我可以運行make compile多次,得到

[email protected]:~/workspace/gm-controller/lib/erlang-sqlite$ make compile 
./rebar get-deps compile 
==> erlang-sqlite (get-deps) 
==> erlang-sqlite (compile) 

然而,對於運行make test某種原因總是給人

[email protected]:~/workspace/gm-controller/lib/erlang-sqlite$ make test 
make: `test' is up to date. 

即使文件未編譯。問題是,爲什麼?

運行相同的命令直接作用:

[email protected]:~/workspace/gm-controller/lib/erlang-sqlite$ ./rebar get-deps compile skip_deps=true eunit 
==> erlang-sqlite (get-deps) 
==> erlang-sqlite (compile) 
Compiled src/sqlite3_lib.erl 
Compiled src/sqlite3.erl 
==> erlang-sqlite (eunit) 
... 

回答

265

也許你在目錄中有一個名爲test一個文件/目錄。如果此目錄存在,並且沒有更新的依賴關係,則該目標不會重建。

要強制重建這幾樣不是文件相關的目標,你應該讓他們假如下:

.PHONY: all test clean 

請注意,你可以聲明所有的僞目標在那裏。

+0

我有一個名爲build的目錄,另一個名爲lib。事後看來,這些並不是完美的目標名稱。唉.....做。 – MattD 2013-10-15 20:35:28

+1

*其中'all','test'和'clear'是您的生成文件目標名稱 – ThorSummoner 2015-04-27 17:05:17

+0

另一種解決方案是更改標籤。在你的情況下,將'test'改爲'test_rule'或者其他的東西。 – auraham 2015-11-12 16:42:49

8

編輯:這隻適用於make的某些版本 - 你應該檢查你的手冊頁。

您還可以將-B標誌傳遞給make。根據手冊頁,這是:

-B, --always-make無條件地制定所有目標。

,如果你是在一個情況下,你不想編輯Makefile或更改你的測試文件夾的名稱,以便將make -B test解決您的問題。

+0

'-B'是向後兼容模式對我來說...(FreeBSD,OS/GNU工具包似乎沒有被指定有問題) – 2016-08-15 13:25:45

+0

哦,有趣的是......「--always-make」是否適合你? – jamesc 2016-08-15 13:28:39

+0

沒有。 '.PHONY'目標似乎是一種可移植的,儘管...(至少對FreeBSD來說,並不確定Solaris這樣的東西) – 2016-08-15 16:53:33

相關問題