我寫了一個小的Makefile文件,編譯它們,然後幾個簡單的C程序測試它們的執行時間:奇怪的化妝隱含規則
CC = gcc
CFLAGS = -Wall
PTEST = /usr/bin/time -f "%Us"
ARCH=-march=native
OPTIMIZATION=
NOPTIMIZATION=
%comp : %.c
$(CC) $(CFLAGS) $(NOPTIMIZATION) -o $* $<
$(CC) $(CFLAGS) $(OPTIMIZATION) -o $*_opt $<
$(CC) $(CFLAGS) $(NOPTIMIZATION) $(ARCH) -o $*_arch $<
$(CC) $(CFLAGS) $(OPTIMIZATION) $(ARCH) -o $*_opt_arch $<
%test:
@echo ---$<---
@echo Bez optymalizacji, bez podowania architektury
@$(PTEST) ./$*
@echo Bez optymalizacji, uwzgledniana architektura
@$(PTEST) ./$*_arch
@echo Opcja $(OPTIMIZATION), bez podawania architektury
@$(PTEST) ./$*_opt
@echo Opcja $(OPTIMIZATION), uwzgledniania architektura
@$(PTEST) ./$*_opt_arch
loop%:OPTIMIZATION=-O2
logic%:OPTIMIZATION=-O1
math%:OPTIMIZATION=-O1 -ffast-math
recursive%:OPTIMIZATION=-O2 -foptimize-sibling-calls
recursive%:NOPTIMIZATION=-O2 -fno-optimize-sibling-calls
#all: loopcomp logiccomp mathcomp recursivecomp looptest logictest mathtest recursivetest
loop:loopcomp looptest
clean:
rm -rf loop loop_opt loop_arch loop_opt_arch \
logic logic_opt logic_arch logic_opt_arch \
math math_opt math_arch math_opt_arch \
recursive recursive_opt recursive_arch recursive_opt_arch
當我鍵入使循環它編譯和測試他們,但隨後調用奇怪的隱含規則,這是否:
gcc -Wall loop.c loopcomp looptest -o loop
gcc: error: loopcomp: No such file or directory
gcc: error: looptest: No such file or directory
我知道,這是使隱性規則,因爲當調用make -r loop
一切都OK。我無法弄清楚:哪個內置隱式規則是試圖調用的,我怎樣才能覆蓋它,最好是在調用make
時最好不要添加-r
選項?如果可能的話,我想重寫它或以某種方式可以使makefile中的隱式規則可以使用。
.PHONY工作,謝謝 – Andna 2012-03-18 15:56:51