###################################################################################################
## Very generic Makefile:
## It generates the object files from all cpp or cc files in a directory and links them together. 
## You only have to supply it with your TARGET, LIBS, FLAGS, PATHS etc.
###################################################################################################

CC		:=	gcc
CXX		:=	g++
CFLAGS		:=	-pipe -W -Wall -g -mcpu=i686 -march=i686 -O3 -fomit-frame-pointer -DDEBUG -D_REENTRANT 
CXXFLAGS	:=	-pipe -W -Wall -g -mcpu=i686 -march=i686 -O3  -DDEBUG -D_REENTRANT
INCPATH		:=  

LINK		:=	g++
LFLAGS		:=	

LIBS		:=
LIBPATH		:=	

TAR		:=	tar -cf
GZIP		:=	gzip -9f
BZIP		:=	bzip2
RM		:=	rm -vf
TAGS		:=	ctags
DOXYGEN		:=	doxygen

# FILE THAT STORES THE DEPENDENCIES AND IS INCLUDED IN THE MAKEFILE AUTOMATICALLY
DEPS		:= Makefile.dep
# FLAG HOW TO GENERATE THE DEPENDENCIES 
# ( '-M' generates all dependencies '-MM' generates only dependencies of user created source files
DEP_FLAG	:= -MM
HEADERS		:= $(wildcard *.h)
SOURCES 	:= $(wildcard *.c) $(wildcard *.cc)
OBJECTS 	:= $(patsubst %.c,%.o,$(patsubst %.cc,%.o,$(SOURCES)))

TARGET		:= MSG

####### Implicit rules

.SUFFIXES: .cpp .cxx .cc .C .c

.cpp.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cxx.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.cc.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.C.o:
	$(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<

.c.o:
	$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<

####### Build rules

.PHONY : all depend objects clean proper world docs


all : $(TARGET)

$(TARGET): $(OBJECTS) 
	$(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(LIBPATH) $(LIBS)

depend :
	$(CXX) $(INCPATH) $(DEP_FLAG) $(SOURCES) > $(DEPS)

objects : $(OBJECTS)

clean :
	$(RM) $(TARGET)
	$(RM) $(OBJECTS)
	$(RM) *.d
	$(RM) *~ core

proper: clean
	$(RM) *.a
	$(RM) *.bak
	$(RM) *.old
	$(RM) *.rpo
	$(RM) $(DEPS)
	$(RM) tags
	$(RM) *~

tags:
	$(TAGS) *
	
docs:
	$(DOXYGEN) Doxyfile

world: proper tags depend all docs

-include $(DEPS)