###################################################################################################
## 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 -mcpu=i686 -march=i686 -O3 -fomit-frame-pointer -Wall -W -g -DDEBUG -D_REENTRANT
CXXFLAGS    :=	-pipe -mcpu=i686 -march=i686 -O3 -fno-rtti -Wall -W -g -frepo -DDEBUG -D_REENTRANT
INCPATH     :=
LINK        :=	g++
LFLAGS      :=	-frepo
LIBS        :=	-lpthread
LIBPATH     :=

TAR         :=	tar -cf
GZIP        :=	gzip -9f
BZIP        :=	bzip2
RM          :=	rm -vf
TAGS        :=	ctags
# 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 *.cpp) $(wildcard *.cc)
OBJECTS     := $(patsubst %.cpp,%.o,$(patsubst %.cc,%.o,$(SOURCES)))

TARGET      := MY_SINGLETON

####### 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


all : $(TARGET)

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

depend :
    $(CXX) $(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) *

world: proper tags depend all

-include $(DEPS)