make 重新編譯未更改的文件

make 重新編譯未更改的文件

剛剛寫了我的第一個 Makefile,我不明白為什麼 GNUmake 每次呼叫時都會重新編譯所有內容make。這裡是:

# Makefile
CC         = c++

ROOTFLAGS  = $(shell root-config --cflags)
MGDOFLAGS  = $(shell mgdo-config --cflags)
CLHEPFLAGS = $(shell clhep-config --include)
ALLFLAGS   = $(ROOTFLAGS) $(MGDOFLAGS) $(CLHEPFLAGS)

ROOTLIBS  = $(shell root-config --glibs) -lSpectrum
MGDOLIBS  = $(shell mgdo-config --libs)
CLHEPLIBS = $(shell clhep-config --libs)
ALLLIBS   = $(ROOTLIBS) $(MGDOLIBS) $(CLHEPLIBS)

EXEC = tier1browser selectEvents currentPlot

all : $(EXEC)

selectEvents : selectEvents.cc
    mkdir -p bin && \
    $(CC) $(ALLFLAGS) -o bin/$@ $< $(ALLLIBS)

currentPlot : currentPlot.cc
    mkdir -p bin && \
    $(CC) $(ROOTFLAGS) -o bin/$@ $< $(ROOTLIBS) -fopenmp -Ofast

tier1browser : tier1Browser.cxx tier1BrowserDict.cxx
    mkdir -p bin && \
    $(CC)-4.9 $(ALLFLAGS) -I. -o bin/$@ $< lib/tier1BrowserDict.cxx $(ALLLIBS)   

tier1BrowserDict.cxx : tier1Browser.h tier1BrowserLinkDef.h
    mkdir -p lib && \
    cd lib && \
    rootcling -f $@ $(MGDOFLAGS) $(CLHEPFLAGS) -c ../tier1Browser.h ../tier1BrowserLinkDef.h; \
    cd ..

.PHONY : all clean

clean : 
    rm -rf bin/* lib/*

怎麼了?最終的資料夾層次結構:

bin/currentPlot
bin/selectEvents
bin/tier1browser
lib/tier1BrowserDict.cxx
lib/tier1BrowserDict_rdict.pcm
Makefile
currentPlot.cc
selectEvents.cc
tier1Browser.cxx
tier1Browser.h
tier1BrowserLinkDef.h

對於新手來說,還有什麼其他提示可以使其更有效率和優雅嗎?

答案1

您向 Makefile 詢問對目前目錄的依賴關係

currentPlot : currentPlot.cc

make 需要currentPlot 目前目錄中的檔案名,而您正在bin目錄 ( -o bin/$@) 中建置。

相關內容