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

Community
  • 1
  • 1
user3494614
  • 603
  • 1
  • 7
  • 20
  • 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? – Some programmer dude Dec 02 '16 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. – user3494614 Dec 02 '16 at 11:22

1 Answers1

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.

blackpen
  • 2,339
  • 13
  • 15