変更されていないファイルを再コンパイルする

変更されていないファイルを再コンパイルする

初めての 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 は現在の dir 内のファイル名を期待していますが、 dir ( )currentPlot 内でビルドしています。bin-o bin/$@

関連情報