0

I have written below Makefile and as per answer to this question added rules for header file dependencies but it is not working. I did a clean and then build. After that I modified Parse.h using touch command and ran "make all" it says Test.exe is up to date. I got same output with just "make" command too.

Can anyone please let me know where am I gone wrong.

RM := rm -rf
MKDIR := mkdir -p
FIND := find
CPIO := cpio
CD := cd
MV := mv
# Set compiler flags
ifeq ($(BUILD_TYPE),DEBUG)
 COMPILE_FLAGS= -c -fpic -DDBG=1 -g -DUSE_UTLPATMAT=1 -Wall
else ifeq ($(BUILD_TYPE),RELEASE)
 COMPILE_FLAGS= -c -fpic -O3 -DUSE_UTLPATMAT=1 -Wall
else ifeq ($(BUILD_TYPE),PERF)
 COMPILE_FLAGS= -c -fpic -O3 -DUSE_UTLPATMAT=1 -DPERF_COMPONENT -Wall
else
 COMPILE_FLAGS= -c -fpic -O3 -DUSE_UTLPATMAT=1 -Wall
endif
export STFP_HOME = $(shell cd "$(CURDIR)/.."; pwd)
STFP_LIB = $(STFP_HOME)/lib
STFP_BIN = $(STFP_HOME)/bin
$(shell mkdir -p ${STFP_LIB})
$(shell mkdir -p ${STFP_BIN})
STFP_INC = $(CURDIR)/SP
SPTEST_SRC = $(CURDIR)/SPTest
SPTEST_INC = $(CURDIR)/SPTest
STFP_SRC = $(CURDIR)/SP
STFP_INC = $(CURDIR)/SP
UTILITIES_SRC_DIR = $(CURDIR)/../utilities
LIBS= -L${CLIENT_LIB} 
INCS_DIRS= -I${CLIENT_INC} 
#Subdivision Publisher Test
SPTESTSRCS=\
$(SPTEST_SRC)/Parse.cpp \
$(SPTEST_SRC)/Main.cpp 
SPTESTOBJS=$(patsubst %.c,%.o,$(patsubst %.cpp,%.o,$(SPTESTSRCS)))
all := $(STFP_BIN)/Test.exe 
#################### Main targets #####################################
all:$(all)
clean:
 find $(STFP_SRC)/ -name "*.o" | xargs rm -rf
 find $(SPTEST_SRC)/ -name "*.o" | xargs rm -rf
 rm -rf $(STFP_LIB)
 rm -rf $(STFP_BIN)
#######################################################################
$(STFP_BIN)/Test.exe: $(SPTESTOBJS)
 $(CXX) -g $(INCS_DIRS) \
 $(SPTESTOBJS) -o $@ \
 $(LIBS) -lmodpbase64 -lboost_regex -lboost_filesystem -lboost_system -lboost_serialization \
 -lutility
%.o : %.cpp
 $(CXX) -DPROVIDE_LOG_UTILITIES $(COMPILE_FLAGS) $(INCS_DIRS) -o $@ $<
%.o : %.c
 $(CC) -DPROVIDE_LOG_UTILITIES $(COMPILE_FLAGS) $(INCS_DIRS) -o $@ $<
################# Dependencies #########################
depend: .depend
.depend: $(SPTESTSRCS)
 rm -f .depend
 $(CXX) -DPROVIDE_LOG_UTILITIES $(COMPILE_FLAGS) $(INCS_DIRS) -MM -$(SPTESTSRCS) > .depend
-include .depend
########################################################

Thanks

asked Dec 2, 2016 at 11:13
2
  • Try using make -d to see a lot of debugging information about what make does. Also, are you sure that SPTESTOBJS is correct? Try making a dummy target that prints it. Are the dependencies in .depend correct? Have you checked it? Commented Dec 2, 2016 at 11:16
  • I have checked .depend file and it looks correct. Also since normal build is working ok like if I modify Parse.cpp then only Parse.cpp gets recompiled and link so SPTESTOBJS should be correct. Commented Dec 2, 2016 at 11:22

1 Answer 1

1

You seem to expect .o files in SPTest. You could do so by using:

SPTest/%.o: SPTest/%.cpp
 $(CXX) -DPROVIDE_LOG_UTILITIES $(COMPILE_FLAGS) $(INCS_DIRS) -o $@ $<

OR by using (where @D is directory and @F is filename):

%.o : %.cpp
 $(CXX) -DPROVIDE_LOG_UTILITIES $(COMPILE_FLAGS) $(INCS_DIRS) -o $(@D)/$(@F) $<

Let me know if you still get errors.

answered Dec 2, 2016 at 12:31
Sign up to request clarification or add additional context in comments.

1 Comment

@Beta, Noted. Tx.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.