include rpath.mk

OSCC		=	gcc 
OSCPP		=	g++ 
OSCFLAGS	= 	-D_MT -D_PTHREADS 
OSCPPFLAGS	= 	-w -fPIC -pipe 
OSCDBGFLAGS	=	-g
OSCPPDBGFLAGS	=	-g
OSPURIFYOPTIONS	=	
OSSHLIBFLAGS	=       -shared	-Wl,-Bsymbolic
OSSHLIBSUFFIX	=	so
DBG_FLAG        =       
TEMPLATE_FLAG	=	-D__unix -D_REENTRANT -D_PTHREADS \
                        -DSTRING_CONVERSION \
			-D_GNU_SOURCE \
                        -DSTL_STRING_LENGTH_ORIG -DSGI_STL \
                        -D__STL -DSYNC_IS_PUBLIC -DNATIVE_64BIT
THREADLIBS	=	-lpthread
DYNLIBS		=	-ldl
LIBGCC		=	-lgcc

# Clear out default suffixes and set our own.
.SUFFIXES:
.SUFFIXES: .o .cpp .c .S 

# name of component, used for naming output
COMPNAME = SampleSo
COMPVER =

# component build flags, used for naming output
dynamicdebug : COMPFLAGS = ${ST}D
dynamicrelease : COMPFLAGS = ${ST}
dynamicdebugunicode : COMPFLAGS = ${ST}DU
dynamicreleaseunicode : COMPFLAGS = ${ST}U

# output file name
dynamicdebug : TARGETNAME = lib${COMPNAME}${COMPVER}${COMPFLAGS}.${OSSHLIBSUFFIX}
dynamicrelease : TARGETNAME = lib${COMPNAME}${COMPVER}${COMPFLAGS}.${OSSHLIBSUFFIX}
dynamicdebugunicode : TARGETNAME = lib${COMPNAME}${COMPVER}${COMPFLAGS}.${OSSHLIBSUFFIX}
dynamicreleaseunicode : TARGETNAME = lib${COMPNAME}${COMPVER}${COMPFLAGS}.${OSSHLIBSUFFIX}

# output directories
dynamicdebug : CPOUT = ./.
dynamicrelease : CPOUT = ./.
dynamicdebugunicode : CPOUT = ./.
dynamicreleaseunicode : CPOUT = ./.

# build directory
%debug : BUILDDIR = ./obj${ST}/debug
%release : BUILDDIR = ./obj${ST}/release
%debugunicode : BUILDDIR = ./obj${ST}/debugU
%releaseunicode : BUILDDIR = ./obj${ST}/releaseU

# CFLAGS
%debug : CFLAGS = ${DEFINES} ${DBGDEFINES} ${OSCFLAGS} ${OSCDBGFLAGS}
%release : CFLAGS = ${DEFINES} ${RELDEFINES} ${OSCFLAGS}
%debugunicode : CFLAGS = ${DEFINES} ${DBGDEFINES} ${OSCFLAGS} ${OSCDBGFLAGS} -D_UNICODE
%releaseunicode : CFLAGS = ${DEFINES} ${RELDEFINES} ${OSCFLAGS} -D_UNICODE

# CPPFLAGS
%debug : CPPFLAGS = ${TEMPLATE_FLAG} ${DEFINES} ${DBGDEFINES} \
	${OSCPPFLAGS} ${OSCPPDBGFLAGS}
%release : CPPFLAGS = ${TEMPLATE_FLAG}  ${DEFINES} ${RELDEFINES} ${OSCPPFLAGS}
%debugunicode : CPPFLAGS = ${TEMPLATE_FLAG} ${DEFINES} ${DBGDEFINES} \
	${OSCPPFLAGS} ${OSCPPDBGFLAGS} -D_UNICODE
%releaseunicode : CPPFLAGS = ${TEMPLATE_FLAG}  ${DEFINES} ${RELDEFINES} ${OSCPPFLAGS} -D_UNICODE

# libraries to link against
dynamicdebug : LIBS = ${OTHERLIBS} ${SOCKETLIBS} ${DYNLIBS} ${THREADLIBS} ${LIBGCC}
dynamicrelease : LIBS = ${OTHERLIBS} ${SOCKETLIBS} ${DYNLIBS} ${THREADLIBS} ${LIBGCC}
dynamicdebugunicode : LIBS = ${OTHERLIBS} ${SOCKETLIBS} ${DYNLIBS} ${THREADLIBS} ${LIBGCC}
dynamicreleaseunicode : LIBS = ${OTHERLIBS} ${SOCKETLIBS} ${DYNLIBS} ${THREADLIBS} ${LIBGCC}

# library path
dynamicdebug : LIBPATH =
dynamicrelease : LIBPATH =
dynamicdebugunicode : LIBPATH =
dynamicreleaseunicode : LIBPATH =

# command used to build the target
dynamicdebug : MAKETARGET = ${OSCPP} ${USESHLIBPATH} \
	-o ${CPOUT}/${TARGETNAME} \
	${OSSHLIBFLAGS} ${LINKFLAGS} $(RPATHFLAG_PREFIX)'$(RPATHFLAG)$(RPATHFLAG_EXTRAS)' ${OBJS} ${LIBPATH} ${LIBS}
dynamicrelease : MAKETARGET = ${OSCPP} ${USESHLIBPATH} \
	-o ${CPOUT}/${TARGETNAME} \
	${OSSHLIBFLAGS} ${LINKFLAGS} $(RPATHFLAG_PREFIX)'$(RPATHFLAG)$(RPATHFLAG_EXTRAS)' ${OBJS} ${LIBPATH} ${LIBS}
dynamicdebugunicode : MAKETARGET = ${OSCPP} ${USESHLIBPATH} \
	-o ${CPOUT}/${TARGETNAME} \
	${OSSHLIBFLAGS} $(RPATHFLAG_PREFIX)'$(RPATHFLAG)$(RPATHFLAG_EXTRAS)' ${OBJS} ${LIBPATH} ${LIBS}
dynamicreleaseunicode : MAKETARGET = ${OSCPP} ${USESHLIBPATH} \
	-o ${CPOUT}/${TARGETNAME} \
	${OSSHLIBFLAGS} $(RPATHFLAG_PREFIX)'$(RPATHFLAG)$(RPATHFLAG_EXTRAS)' ${OBJS} ${LIBPATH} ${LIBS}

# PURIFY NOTES:
# If you want to build a Purified build, you must define
# PUREFLAGS in your environment or pass it into make, define explicit
# targets for the purify targets, or alternatively,
# set the PUREFLAGS var below to be the location of the purify command.
# The default compilation rule for .c and .cpp files will pick up the
# PUREFLAGS setting and build against the purify libs correctly.
# If you want to do this via the below macros, define PUREFLAGS to
# be ${PURIFY} ${PURIFYOPTIONS}
# NOTE ON Pure Coverage:  To enable this as well, just change the
# PUREFLAGS to ${PURIFY} ${PURIFYOPTIONS} purecov and enable for builds
# as described in this Makefile.  This should run BOTH purify and enable
# Pure Coverage.
PURIFYOPTIONS=-exit-status=yes -leaks-at-exit=yes ${OSPURIFYOPTIONS}
PDIR            =       `purify -print-home-dir`
PURIFY          =       purify ${PFLAGS}
PSTUBS          =       ${PDIR}/purify_stubs.a
#PUREFLAGS=${PURIFY} ${PURIFYOPTIONS}

# NOTE: To compile under Linux, use the GNU supplied STL and comment out the includes/stl
#	dir below.
INCLUDE = 


# Defines for debug builds
DBGDEFINES	=	-D_DEBUG \
			-D__UNIX_DEBUG__ \
			${DBG_FLAG}

RELDEFINES	=	-DNDEBUG

# Fill in the source files for SRCS, OBJS will use macro substitution to
# replace .cpp extensions with a .o extension.
CSRCS =

CPPSRCS	= sample.cpp

VPATH	=	./.

# Build object names from source names.
CPPOBJS=${CPPSRCS:%.cpp=${BUILDDIR}/%.o}
COBJS=${CSRCS:%.c=${BUILDDIR}/%.o}
OBJS=${COBJS} ${CPPOBJS}

# Build	all of the libraries and executables.  This should rarely if ever need
# to be changed.  The dirs target MUST be left as a dependency.

.PHONY : debug
debug : dynamicdebug

.PHONY : release
release : dynamicrelease

.PHONY : all
all : debug release

.PHONY : unicode
unicode : dynamicdebugunicode dynamicreleaseunicode

define makedirs
	@if [ -d ${CPOUT} ]  ; then	\
		echo "System Output ${CPOUT} Dir Exists."; \
	else	\
		echo "Creating Build output dir: ${CPOUT}\n"; \
		mkdir -p ${CPOUT};			\
	fi				
	@if [ -d ${BUILDDIR} ]  ; then	\
		echo "System Output ${BUILDDIR} Dir Exists."; \
	else	\
		echo "Creating Platform specific output dir: ${BUILDDIR}\n"; \
		mkdir -p ${BUILDDIR};			\
	fi				
endef

.PHONY : dynamicdebug
.PHONY : dynamicrelease
.PHONY : dynamicdebugunicode
.PHONY : dynamicreleaseunicode
dynamicdebug dynamicrelease dynamicdebugunicode dynamicreleaseunicode :
	$(makedirs)
	VPATH="${VPATH}" OBJS="${OBJS}" BUILDDIR="${BUILDDIR}" \
	TARGETNAME="${TARGETNAME}" MAKETARGET="${MAKETARGET}" \
	MAKECPPOBJS="${PUREFLAGS} ${OSCPP} ${CPPFLAGS} ${INCLUDE}" \
	MAKECOBJS="${PUREFLAGS} ${OSCC} -c ${CFLAGS} ${INCLUDE}" \
	$(MAKE) -f Make.mk 
	@echo "$@ version built."

# cleanup
.PHONY : clean
clean :
	-rm -fr obj libSampleSo.so

# End Makefile

