I am trying to fix a problem with a makefile. If you see below, I am setting the value of SUBDIR inside the rule, but it is not set when it gets to the next line. I have verified that the subst command is correct using output warnings, but it seems that the command on the next line is generated before the line above is executed. Is this possible? What am I doing wrong?
$(CppObj):$(OBJPATH)/%.$(OBJ_EXT): $(CPPPATH)/%.cpp
@$(MKDIR) $(OBJPATH)
@$(RM) $@
SUBDIR = $(subst $(OBJPATH),,$(@D))
$(CC) $(C++FLAGS) $(CCOMP_ONLY_FLAG) $< $(COBJ_NAME_FLAG)$(OBJPATH)$(SUBDIR)$(@F)