#
# 
# 

VDB_SRCS=msqlacc.c mysqlacc.c Vdb.c

# there are a number of build targets to choose from depending on the
# functionality you want
#
# msql & mysql
#
# default behaviour is to build  with support for
# both msql & mysql

# msql builds an msql only version

# mysql builds a mysql only version

#BUILD_TYPE=-DVDB_MSQL
#BUILD_TYPE=-DVDB_MYSQL


# define these values based on your system

LN = ln
RM = rm -f
INSTALL = install

AR = ar rcu

VCLEAN = true
#VCLEAN = rcsclean

# do 'man ranlib' to find out
# linux
RANLIB=ranlib

# Sunos 4.1.4
#RANLIB=ranlib

# no ranlib
#RANLIB=touch

##################
TESTSRCS = test.c

LIBS = -lVdb -ldflts -lV -lmsql -lmysqlclient -lm
DEFS =

MSQLLIB=/usr/local/Minerva/lib
MSQLINC=/usr/local/Minerva/include
# this could in one or the other depending on the version of mysql
MYSQLLIB=/usr/local/mysql/lib -L/usr/local/lib/mysql
MYSQLINC=/usr/local/mysql/include -I/usr/local/include/mysql

LIBPATH= -L. -L../lib -L../../lib -L$(MSQLLIB) -L$(MYSQLLIB) -L/usr/local/lib

LIST    = Vdb 

default: libVdb.a

all: ${LIST:%=all-%}


#################
#
# where things go when built
#
# a local lib directory
BUILD_DIR=../../lib

# installation directory
INSTALL_DIR=../../lib

# use a sensible compiler
CC = gcc
CFLAGS= -c -g -O2 -Wall $(BUILD_TYPE)
INCLUDES= -I. -I../include -I../../include -I$(MSQLINC) -I$(MYSQLINC) -I/usr/local/include -D${VSYSTEM}

##########
# if you have a memory checking system i.e. purify
# PRELINKER=purify
#

VdbOBJECTS = ${VDB_SRCS:%.c=%.o}
all-Vdb: libVdb.a

VlibOBJECTS = ${VLIB_SRCS:%.c=%.o}
all-Vlib: libVlib.a

%.o : %.c
	$(CC) $(CFLAGS) $(INCLUDES) -o $*.o $*.c

##############
#
#  Vdb rules

libVdb.a: ${VdbOBJECTS} 
	${AR} libVdb.a ${VdbOBJECTS}
	${RANLIB} libVdb.a

install-Vdb: ${INSTALL_DIR}/libVdb.a

${INSTALL_DIR}/libVdb.a: libVdb.a
	${INSTALL} libVdb.a ${INSTALL_DIR}
	${RANLIB} ${INSTALL_DIR}/libVdb.a
	chmod 644 ${INSTALL_DIR}/libVdb.a

lib-Vdb: ${BUILD_DIR}/libVdb.a

debug-Vdb: libVdb.a
	${INSTALL} libVdb.a ${BUILD_DIR}/${DEBUGLIBDIR}
	${RANLIB} ${BUILD_DIR}/${DEBUGLIBDIR}/libVdb.a
	chmod 644 ${BUILD_DIR}/libVdb.a

dbi-Vdb: libVdb.a
	${INSTALL} libVdb.a ${INSTALL_DIR}/${DEBUGLIBDIR}
	${RANLIB} ${INSTALL_DIR}/${DEBUGLIBDIR}/libVdb.a
	chmod 644 ${INSTALL_DIR}/libVdb.a

cpp-Vdb: ${VDB_SRCS} ${VDB_SRCS:%.c=%.i} ${VDB_SRCS:%.cc=%.i} ${VDB_SRCS:%.C=%.i}

touch-Vdb:
	touch libVdb.a

Vdb: libVdb.a

relink-Vdb: Vdb

clean-Vdb:
	${RM} libVdb.a *.o *~ *.bak *.dep core test
	-${VCLEAN}



###############
#
# test program rules


testOBJECTS = ${TESTSRCS:%.c=%.o} ${CCSRCS:%.cc=%.o}
all-test: test

test: ${testOBJECTS} 
	${PRELINKER} ${CC} -o test ${testOBJECTS} ${LIBPATH} ${LIBS} ${LINKFLAGS} 

install-test: ${INSTALL_DIR}/test

lib-test: test

${INSTALL_DIR}/test: test
	${INSTALL} -c -s -m 755 test ${INSTALL_DIR}

debug-test: test
	${INSTALL} test ${BUILD_DIR}/${DEBUGBINDIR}

dbi-test: test
	${INSTALL} test ${INSTALL_DIR}/${DEBUGBINDIR}/

local-test: test
	${INSTALL} test /usr/local/bin/

remove-test:
	${RM} test

relink-test: remove-test test

pure-test: remove-test test

cpp-test: ${SRCS:%.c=%.i} ${SRCS:%.cc=%.i} ${SRCS:%.C=%.i}

touch-test:
	touch test

clean-test:
	${RM} test ${testOBJECTS} *~ *.bak *.dep core
	-${VCLEAN}

install:: ${LIST:%=install-%}

lib:: ${LIST:%=lib-%}

bin:: ${LIST:%=bin-%}

debug:: ${LIST:%=debug-%}

dbi:: ${LIST:%=dbi-%}

local:: ${LIST:%=local-%}

relink:: ${LIST:%=relink-%}

pure:: ${LIST:%=pure-%}

clean:: ${LIST:%=clean-%}

touch:: ${LIST:%=touch-%}

cpp:: ${LIST:%=cpp-%}

