0

For a large project that can benefit from some refactoring one of my goals is to reduce coupling. I'm looking at coupling here as the ability to break up the code into very small/logical compile units much like how coupling is explained in This document 3.1.

So I'm writing a makefile to test the source files as I go alone. The intent is that all object files compile to the .object/ directory. The idea is that when these large source files fail to be assembled I've found a place that needs attention.

The issue is that the makefile compiles every source every time and I can't find the rule that is causing it.

In using a makefile like this am I wrong in my approach? Is there a better way for doing this kind of refactoring - short of using an IDE with those tools built in?

CC       = g++
CC_FLAGS = -std=c++0x -pthread
LI_FLAGS = 
EXEC     = UAVapp.o
OUT      = .object/

#Types/
T = Arming.hpp JCommand.hpp
TYPES  = $(T:%=Types/%)

#Extensions
HPP     = Defines.hpp $(TYPES)
CPP     = 

#Groups
COBJ    = $(CPP:.cpp=.o)
HOBJ    = $(HPP:.hpp=.o) 

all: PRE $(EXEC)

# Main target
$(EXEC): $(HOBJ)
    touch $(EXEC)
#$(CC) $(LI_FLAGS) $(CC_FLAGS) $(OUT)$(COBJ) -o $(EXEC)


%.o:%.hpp
    $(CC) -c $< $(CC_FLAGS) -o $(OUT)$(notdir $@)
%.o:%.cpp 
    $(CC) -c $< $(CC_FLAGS) -o $(OUT)$(notdir $@)

# Do work before compilation
PRE:
    @mkdir -p $(OUT)
clean:
    rm -rf ./*.o $(EXEC) ./$(OUT)*
Aage Torleif
  • 1,907
  • 1
  • 20
  • 37

1 Answers1

1

From a cursory look, it seems that your problem is that your "%.o:%.hpp" and "%o:%.cpp" rules don't actually produce the file listed on the left-hand side. Typically make determines that there is no work to do by examining the file listed on the left hand side and determining if it is newer than the files listed as its dependencies, but since the file on the left never comes into existence as a result of the rule, the rule must always be executed. Try specifying ".object/foo.o" on the left-hand side rather than hijacking the builtin rule (I'd also strongly advise against clobbering commands such as "CC" that should be provided by Make).

Michael Aaron Safyan
  • 93,612
  • 16
  • 138
  • 200