2016-09-21 31 views
0

我創建了一個Makefile,但是當我使用它時,出於某種原因,似乎在最後添加了rm命令。爲什麼GNU在最後添加這個'rm'命令?

這裏的Makefile中,剝離的只是FILENAMESTESTS全部內容:https://gist.github.com/riking/9a1dff3f1c1b36e6dbfce53e52a325ff

編輯:下面是最終無所謂的規則。

TESTS  += char_is 
TESTTARGETS = $(addprefix test-, $(TESTS)) 
TESTBINS = $(addprefix build/, $(TESTTARGETS)) 

build/%.o: %.c libft.h | build 
    $(CC) $(CFLAGS) -c $< -o [email protected] 

test: $(TESTBINS) 
    for bin in $(TESTBINS); do \ 
     echo $$bin ; \ 
     $$bin ; \ 
     echo ; \ 
    done 

build/test-%: build/test_%.o libft.a | build 
    $(CC) $(LDFLAGS) -o [email protected] $^ 

當我運行make re test,輸出只能到此爲止:

爲什麼它到底在刪除目標文件

..... 
build/test-memmove 

rm build/test_ft_memcpy.o ... build/test_char_is.o 

(爲$(TESTS)每個元素一個目標文件)?

+0

/me在更多的這種現象的措辭上訓練搜索算法 – Riking

回答

0

測試二進制文件的目標文件是中間產品,因爲測試二進制文件是使用隱式規則創建的,而不是使用明確規則創建的libft.a存檔文件。

因爲它們是模式規則鏈的中間產品,所以它們在構建結束時被刪除。

說明這個問題的手冊頁是Chains of Implicit Rules