Makefile

常用的Makefile模板

SHELL = /bin/sh

# Define the searching path(s) of make
VPATH    = ./windows ./LinuxLayer ./Communication

# Define object file(s)
OBJS    = Afe.o Asic.o CanonApi.o DevADF.o DevCalib.o \
    Device.o DevInit.o DevLCD.o DevMap.o DevMove.o DevScan.o \
    Interface.o Motor.o Profile.o Queue.o Register.o \
    Setting.o StagImg.o Usb.o WinApiDef.o
    
# Define compiler    
CXX        = g++

# Define the -l library name(s)
LIBS    = -lpthread -lusb  -lrt  -lsanei

# Define the output file of compile
OUTPUT    = CNDH1220.so

# Define the include path(s)
INCPATH    = -I. -I./Windows -I./LinuxLayer -I./Communication -I./include -I./include/sane -I./include/sanei

# Define compile parameter(s)
CXXFLAGS=-W -Wall  -Wno-trigraphs  -Wno-write-strings

# Define rule for compipling .cpp file
.cpp.o:
    @echo Compiling $<
    @$(CXX) -c $(CXXFLAGS) $(INCPATH) $<
# Define rule for compiling .c file
.c.o:
    @echo Compiling $<
    @$(CXX) -c $(CXXFLAGS) $(INCPATH) $<

.PHONY: all clean
    
all: $(OBJS)
    $(CXX) -fPIC -O2 -shared $(OBJS) -o $(OUTPUT)

clean:
    rm $(OBJS)

问题: 怎么样能够使当某个.o文件依赖的头文件改变时,重新编译生成相应的.o文件呢?

你可能感兴趣的:(makefile)