#
# Sequoia: Database clustering technology.
# Copyright (C) 2005 Emic Networks
# Contact: sequoia@continuent.org
# 
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
# http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Initial developer(s): Gilles Rayrat
# Contributor(s): 
#

# Makefile for the Carob C++ API and tests
#



#Tools

RM                      = /bin/rm -f
RMDIR                   = /bin/rm -rf
LN                      = /bin/ln -s
DOXYGEN                 = /usr/bin/doxygen

ARFLAGS                 = rcs


#### PORTABILITY - CUSTOMIZATIOM

MKINCLUDES=make-includes

# gives default names like: carob, libcarob, libcarob.so.1,
# libcarob.1.dylib etc.
include ${MKINCLUDES}/defaults.mk

# customization
include ${MKINCLUDES}/main.mk



#Dirs
INCDIR                  = include
SRCDIR                  = src

#Carob C++ lib
OBJS                    = ${SRCDIR}/Common.o\
                          ${SRCDIR}/JavaSocket.o\
                          ${SRCDIR}/BufferedSocket.o\
                          ${SRCDIR}/DriverSocket.o\
                          ${SRCDIR}/CarobException.o\
                          ${SRCDIR}/SocketAddress.o\
                          ${SRCDIR}/ControllerInfo.o\
                          ${SRCDIR}/ConnectionParameters.o\
                          ${SRCDIR}/ControllerPool.o\
                          ${SRCDIR}/Connection.o\
                          ${SRCDIR}/Request.o\
                          ${SRCDIR}/RequestWithResultSetParameters.o\
                          ${SRCDIR}/ResultSetMetaData.o\
                          ${SRCDIR}/DriverResultSet.o\
                          ${SRCDIR}/Field.o\
                          ${SRCDIR}/Statement.o\
                          ${SRCDIR}/ParameterStatement.o\
                          ${SRCDIR}/BigDecimal.o\
                          ${SRCDIR}/SQLDataSerialization.o\
                          ${SRCDIR}/StringCodecs.o\
                          ${SRCDIR}/ControllerStateChangedCallback.o\
                          ${SRCDIR}/WatchedControllers.o\
                          ${SRCDIR}/ControllerPingSender.o\
                          ${SRCDIR}/ControllerWatcher.o
# _GLIBCXX_GTHREAD_USE_WEAK

override CPPFLAGS	+= -I${INCDIR}


# Uncomment this line to use select function instead of poll
# Or using the command line: make CXXFLAGS=-DCAROB_USE_SELECT
# override CXXFLAGS       += -DCAROB_USE_SELECT


# LDLIBS is not used to build static libcarob.a
override LDLIBS         +=  -lgmp







# Uncomment these 2 lines to use log4cxx instead of internal logger
#CXXFLAGS                += -DCAROB_LOG4CXX_NAME=CarobLogs
#LDFLAGS                 += -llog4cxx

#Doc
# DOC_DIR is duplicated in Doxyfile
DOC_DIR                 = doxygen
DOC_OUT                 = ${DOC_DIR}/html
DOXYFILE                = ${DOC_DIR}/Doxyfile
DOC_HTML                = ${DOC_OUT}/index.html

all: lib static
lib: ${LIB_CAROB_SONAME}
static: ${LIB_CAROB_STATIC}
test: all
	$(MAKE) -C test

${LIB_CAROB_SONAME}: ${OBJS}
	${CXX} ${CXXFLAGS} ${OBJS} ${SHARED_LDFLAGS} ${LDFLAGS} ${LDLIBS} -o ${LIB_CAROB_SONAME}
	- ${LN} -f ${LIB_CAROB_SONAME} ${LIB_CAROB_LINKNAME}

${LIB_CAROB_STATIC}: ${OBJS}
	${AR} ${ARFLAGS} ${LIB_CAROB_STATIC} ${OBJS}	

clean: clean-lib clean-test clean-doc clean-check
clean-lib:
	${RM} ${SRCDIR}/*.o ${LIB_CAROB_SONAME} ${LIB_CAROB_LINKNAME} ${LIB_CAROB_STATIC}
clean-test:
	$(MAKE) -C test clean
clean-doc:
	${RMDIR} ${DOC_OUT}

doc: ${DOC_HTML}
${DOC_HTML}: ${DOXYFILE}
	${DOXYGEN} ${DOXYFILE}


   ########## CHECKS ##############"

check: clean-doc doc checkheaders
	$(MAKE) -C test $@

clean-check:
	${RM} someheader.cpp someheader.o
	$(MAKE) -C test $@

# compile each include/*.hpp, isolated
# TODO: use a GNU make loop instead of a shell script one
checkheaders:
	for h in include/*.hpp; do ln -sf $$h someheader.cpp; \
	printf "compiling $$h\n"; \
	$(MAKE) someheader.o || break; $(RM) someheader.o; done


  ########### DIST ##################

# To create "carob-foo.tar.gz" from carob version tag r12_34,
# simply type this:
#
#   $  DIR_SUFFIX=foo CVS_TAG=r12_34 make dist
#
# alternatively, typing:
#
#   $  CVS_DATE=2055-09-22 make dist
#
# will create "carob-2055-09-22.tar.gz"
# Default value is the current YYYYMMDD date

dist:
	./publisher.sh buildsrctarball

publishdoc:
	./publisher.sh publishdoc
