2010-01-23 78 views
10

我的第一個問題(yay!)是關於gnumake和並行構建的。這裏有一個簡單的例子文件:使用gnumake和先決條件的並行構建

.PHONY: tool_1 tool_2 tool_3 tool_4 all tools 

all: | tools 

tools: | tool_2 tool_3 tool_4 

tool_1: 
    # commands for tool 1 

tool_2: | tool_1 
    # commands for tool 2 

tool_3: | tool_1 
    # commands for tool 3 

tool_4: | tool_1 
    # commands for tool 4 

如果我對這個傢伙做make -j,是我在這裏正確的,以確保爲tool_1的命令只執行一次,並make之前嘗試構建任何tool_[234]

我在找的是make -j原因tool_1先構建,然後tool_[234]並行構建,但沒有執行三次tool_1命令。我希望這是有道理的。感謝您的任何建議或想法!

+0

它看起來像我想要的那樣工作,但是這種並行構建的東西有一種基於系統負載或機器到機器等方式來改變行爲的方式。 – 2010-01-23 01:22:09

回答

8

make -j的行爲與您在問題中所期望的完全相同。它不會多次依賴。

該管道(|)字符在您的依賴列表中做了什麼?

+10

訂單前提條件:http:// www.gnu.org/software/make/manual/make.html#Prerequisite-Types – Amro 2010-01-23 01:38:46

+0

太好了,謝謝@Alex。我找不到任何出現在文檔中的內容,並表示這一點。 – 2010-01-23 02:14:02

+0

我以爲我知道GNU做得很好,但這是我錯過的功能。 – JesperE 2010-01-23 08:54:30