刚刚写了我的第一个 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/$@
) 中构建。