2015-01-15 37 views
0

我的Makefile文件包含以下規則:如何在Makefile中使用算術進行模式規則?

result-n1 : inputs 
     foo $^ 

result-n2 : result-n1 
     hashandmash $^ > [email protected] 

result-n3 : result-n2 
     hashandmash $^ > [email protected] 

# ... [~ 50 more lines omitted for clarity] 

result-n20 : result-n19 
     hashandmash $^ > [email protected] 

我很想有隻有一個模式規則。這將更加清晰,並將避免20的硬編碼限制。

但你會如何做到這一點? How do you say result-nx取決於result-nx-1?我只看到不雅的解決方案(比如命名我的文件在基礎1,例如,result-nIIIIIIII)。

PS & FWIW,我用GNU Make 3.81

回答

0

你不能做到這一點,直接。您可以爲result-%創建沒有先決條件的模式規則,然後您可以分別聲明先決條件:

result-n1: inputs 
     foo $^ 

result-%: 
     hashandmash $^ > [email protected] 

result-n2: result-n1 
result-n3: result-n2 
    ... 
result-n20: result-n19 
+0

謝謝!這已經比我的示例Makefile更清晰簡單了。 – phs 2015-01-15 17:38:55