如何使用 make 进行构建,以便仅构建更改的文件

如何使用 make 进行构建,以便仅构建更改的文件

我的源代码位于 src 目录中,我的目标文件位于 AS5 目录中。

这是我的制作文件:

CC = g++
CFLAGS =-c -std=c99 -g -w -Wno-deprecated -D_FILE_OFFSET_BITS=64 -DATOMIC_BUILT_IN -DIB_USE_STD_STRING -Wall -Wno-switch
WORKING_DIR     = $(HOME)/JYOTI
PLATFORM        = AS5

BASICOBJS            = JYOTI.o OnixMDP3InputAdapter.o FixInputAdapter.o SGXInputAdapter.o SGXITCHProcess.o DGCXTBTInputAdapter.o DGCXMulticastInputAdapter.o NSECMDirectGateWay.o Profiler.o MCXXStreamInputAdapter.o MultipleConnectionReceiver.o EClientSocketBase.o EPosixClientSocket.o IBInputAdapter.o IDCInputAdapter.o NSEUdpInputAdapter.o InputAdapter.o BSEInputAdapter.o DGCXInputAdapter.o EmapiTagParser.o MCXInputAdapter.o OutputAdapter.o TBTProcess.o DataStructure.o NSETBTDataStructure.o LogQueue.o ServiceManager.o TCPSender.o PracticalSocket.o PriceMonitor.o Latency.o TCPInputAdapter.o AvgDiff.o MulticastInputAdapter.o MulticastOutputAdapter.o TBTInputAdapter.o LogStandard.o Common.o Event.o Utils.o MultipleIndexOutputAdapter.o DependendLib.o StringSplitter.o

OBJSWITHSYM     =SymExample.o SymFlusher.o SymInputAdapter.o

OBJWITHOADT     =  CFixGateWay.o DMA.o FixClient.o NSECMDirectGateWay.o MStrat2Way.o MStratOpt.o Basket.o IndexBasket.o RevBasket.o NSECDDirectGateWay.o BseGateWay.o Portfolio.o BasePortfolio.o MyPortfolio.o SLOFIX.o SLOFIXNEG.o SpreadBidding.o TwoLIOCSpd.o LatencyCheckPortfolio.o SLOSPR.o SLOSPRNEG.o SLO3WAY.o MStrat.o MulLegSynFut.o MAMR.o NSEFOGateWay.o NSECMGateWay.o SGXGateWay.o OrderAdapter.o OrderAdaptersInterface.o TCPListener.o FixGateWay.o DFixGateWay.o MAMRA.o FConBx.o

OBJMCXOADT      =MCXGateWay.o

OBJS    =$(BASICOBJS)

ifneq ($(AM),64)
        CC      +=-m32
        CFLAGS  += -march=i686
        SYME="::::      To Compile 64 bit binary, Usage: <make AM=64>"
endif


ifneq ($(SE),0)
        SE=1
        SYME+="::::      To Compile without flex, Usage: <make SE=0>"
else
        SE=0
endif

ifeq ($(SE),1)
        OBJS    += $(OBJSWITHSYM)
        CFLAGS  +=-DSYMAVAILABLE
endif

ifeq ($(ML),1)
        CFLAGS  +=-D_MESURE_LATENCY
else
        SYME+=" :::::  To Enable Latency Mesurement, Usage: <make ML=1>"
endif
ifeq ($(OADT),1)
        OBJS    +=$(OBJWITHOADT)
        CFLAGS +=-DISORDADPT
        LIB     += -lssl
else
        SYME+=" :::::  To Enable Order Adapter, Usage: <make OADT=1>"
endif

ifeq ($(MCXOADT),1)
        OBJS    +=$(OBJMCXOADT)
        CFLAGS  +=-DISMCXORDADPT
else
        SYME+=" :::::  To Enable MCX Order Adapter, Usage: <make MCXOADT=1>"
endif

ifeq ($(FIXADT),1)
        CFLAGS +=-DISFIXADPT
else
        SYME+=" :::::  To Enable Fix Adapter, Usage: <make OADT=1 FIXADT=1>"
endif

ifeq ($(COND),1)
        CFLAGS +=-DISCONDITION
else
        SYME+=" :::::  To Enable Condition variable, Usage: <make COND=1>"
endif

LDFLAGS =  -L"../../lib" -L"/usr/local/lib" -Wl,-rpath,../../lib  -Wl,-rpath=/usr/local/lib -Wl,-rpath=./lib -lboost_thread -lboost_system -lboost_atomic -L/usr/local/lib  -Wl,-rpath=/home/sys64/tbb2017_20161128oss/lib/intel64/gcc4.1/ -L/home/sys64/tbb2017_20161128oss/lib/intel64/gcc4.1/ #/usr/lib64/libonload_ext.so

INC      = -I$(FLEXSYS)/lzo-1.07/src
INC     += -I$(FLEXSYS)/lzo-1.07/include
INC     += -I$(FLEXAPP)/flex/apinew/include
INC     += -I$(WORKING_DIR)/inc
INC     += -I$(WORKING_DIR)/inc/IBinc
INC     += -I$(WORKING_DIR)/src
INC     += -I"/usr/include/"
INC     += -I"/usr/include/openssl/"
INC     += -I"../boost_1_55_0/"
INC     += -I"/usr/local/include"
INC     += -I"../tbb2017_20161128oss/include/"


LIB     += $(WORKING_DIR)/lib64/libsymproxy.a
LIB     += $(WORKING_DIR)/lib64/libflexapi.a
LIB     += $(WORKING_DIR)/lib/libACE.so
LIB     += $(WORKING_DIR)/lib/libOnixS.CmeMdp3HandlerCpp.so
LIB     += /usr/local/lib/libz.a
LIB     +=/usr/local/lib/liblzo.a
#LIB     +=$(WORKING_DIR)/lib/libqed.a
#LIB     +=$(WORKING_DIR)/lib/libconfig.a
LIB     += -lm -lstdc++ -z muldefs -lpthread -lrt -ltbb

DEF      = -DFOR_UNIX -DFOR_LINUX
DEF     += -D_REENTRANT
DEF     += -D_POSIX_PTHREAD_SEMANTICS
DEF     += -D__STL_PTHREADS

RM      = rm -rf

all: JYOTI

%.o : %.cpp

        -@if [ ! -d $(PLATFORM) ] ; then mkdir -p $(PLATFORM); fi;
        $(CC) $(CFLAGS) $(INC) $(DEF) $< -o $(PLATFORM)/$@

JYOTI: clean $(OBJS)
        cd $(PLATFORM);$(CC) $(LDFLAGS) $(OBJS) $(LIB) -o $@



clean:
        $(RM) log AS5/*
        @echo $(SYME)
        @echo

答案1

首先,您必须cleanJYOTI目标中删除依赖项。否则,一切总是从头开始。

接下来,您需要在模式规则中包含目标文件目录,例如:

$(PLATFORM)/%.o: %.cpp
        $(CC) $(CPPFLAGS) $(CFLAGS) -o $@ $<

最简单的事情是确保 $(PLATFORM) 目录本身始终存在并且不会被干净目标删除。

为此,您还需要$(PLATFORM)在对象列表中指定目录,例如:

OBJS = $(BASICOBJS:%=$(PLATFORM)/%)

相关内容