############################################################################
#
# UNIX Makefile for the Client-Library example programs. To use this 
# makefile, you need to set the following environment variables:
#
#	SYBASE		Set to the Sybase installation directory.
#	SYBPLATFORM 	Set to the Sybase abbreviation for your platform.
#
# The shell script sybopts.sh is used to create a platform-specific 
# options for compile-and-link command line, Sybase and system libraries. 
# The SYBPLATFORM environment variable must be set in order for this 
# script to work correctly.
# 
#   Possible values for the SYBPLATFORM environment variable are:
#
#	sun4		SunOS Release 4.x
#	sun_svr4	SunOS Release 5.x (SVR4)
#	dce_sun_svr4    SunOS Release 5.x (SVR4) with DCE
#	sgi		SGI (compiled with -n32 option)
#	sgi64		SGI (compiled with -64 option)
#	dce_sgi		SGI (compiled with -n32 option for DCE environment)
#	dce_sgi64	SGI (compiled with -64 option for DCE environment)
#	hp800		HP9000 HP-UX
#	dce_hp800	HP9000 HP-UX with DCE
# 	rs6000		IBM RISC System 6000
#	nthread_rs6000	IBM RISC System 6000 with native threads
# 	dce_rs6000	IBM RISC System 6000 with DCE
#	axposf		Digital Unix 4.x
#	dce_axposf	Digital Unix 4.x with DCE
#
#############################################################################

#############################################################################
#
# Directories and search paths.
#
#############################################################################

SHELL     = /bin/sh

INCDIR    = $(SYBASE)/include   # Sybase include directory

#
# Modify the following line to use debug/nondebug libraries
#
#LIBDIR   = $(SYBASE)/devlib     # for debug library versions
LIBDIR    = $(SYBASE)/lib       # Sybase library directory

# Specify the include and library search paths for the compiler
INCLUDE   = -I. -I$(INCDIR)
LIBPATH   = -L$(LIBDIR) 

##############################################################################
#
# Macros for compile/link lines
#
##############################################################################

#
# Specify the compile-time defines.
#
DEFS 	=	-DDEBUG -D$(SYBPLATFORM)=1 

#
# Define the compiler command and compile flags.
#
# `sybopts.sh compile` echoes a platform-specific command to invoke the C 
# compiler. You can replace this invocation with the comand to invoke your 
# preferred compiler if you like.
#
COMPILE =	`sybopts.sh compile` $(INCLUDE) $(DEFS)

#
# Define the list of libraries that must be linked with in order to call 
# Client-Library and Bulk-Library routines.
#
# `sybopts.sh comlibs` echoes a platform-specific list of lower-layer 
#   Sybase libraries to link with. These are required in order to link with 
#   CS-Libary, Client-Library, Bulk-Library, or Server-Library.
# `sybopts.sh syslibs` echoes a platform-specific list of system libraries 
#   that are required.
#
CTLIBS	= 	`sybopts.sh ct cs` `sybopts.sh comlibs` 
BLKLIBS	= 	`sybopts.sh blk` $(CTLIBS) 
SYSLIBS	= 	`sybopts.sh syslibs`
KRBLIBS =	`sybopts.sh krblibs`

##############################################################################
#
# The targets and how to build them.
#
##############################################################################

# 
# 'make all' does not build the multthrd or secct samples, since they
# are not supported on all platforms.
#
all: compute csr_disp rpc getsend i18n usedir exasync blktxt exconfig firstapp

exutils.o: exutils.c example.h exutils.h
	sh sybopts.sh verify; \
	$(COMPILE) -c exutils.c -o exutils.o

ex_alib.o: ex_alib.c example.h exasync.h
	sh sybopts.sh verify; \
	$(COMPILE) -c ex_alib.c -o ex_alib.o


#
# The file generic/thrdfunc.c has the interfaces for pthreads API
# and the file dce_sun_svr4/thrdfunc.c has the interfaces for solaris 
# native threads.
#

thrdfunc.o: thrdfunc.c thrdfunc.h
	sh sybopts.sh verify_threaded; \
	sh sybopts.sh verify; \
	$(COMPILE) -c thrdfunc.c -o thrdfunc.o

thrdutil.o: thrdutil.c thrdutil.h
	sh sybopts.sh verify_threaded; \
	sh sybopts.sh verify; \
	$(COMPILE) -c thrdutil.c -o thrdutil.o

compute: compute.c exutils.o
	sh sybopts.sh verify; \
	$(COMPILE) compute.c exutils.o $(LIBPATH) $(CTLIBS) $(SYSLIBS) -o $@

rpc: rpc.c exutils.o
	sh sybopts.sh verify; \
	$(COMPILE) rpc.c exutils.o $(LIBPATH) $(CTLIBS) $(SYSLIBS)  -o $@

csr_disp: csr_disp.c exutils.o
	sh sybopts.sh verify; \
	$(COMPILE) csr_disp.c exutils.o $(LIBPATH) $(CTLIBS) $(SYSLIBS) -o $@

getsend: getsend.c exutils.o
	sh sybopts.sh verify; \
	$(COMPILE) getsend.c exutils.o $(LIBPATH) $(CTLIBS) $(SYSLIBS) -o $@

i18n: i18n.c exutils.o
	sh sybopts.sh verify; \
	$(COMPILE) i18n.c exutils.o $(LIBPATH) $(CTLIBS) $(SYSLIBS) -o $@

exasync: ex_amain.c exutils.o ex_alib.o
	sh sybopts.sh verify; \
	$(COMPILE) ex_amain.c exutils.o ex_alib.o $(LIBPATH) $(CTLIBS) \
		$(SYSLIBS) -o $@

blktxt: blktxt.c exutils.o
	sh sybopts.sh verify; \
	$(COMPILE) blktxt.c exutils.o $(LIBPATH) $(BLKLIBS) $(SYSLIBS) -o $@

usedir: usedir.c exutils.o
	sh sybopts.sh verify; \
	$(COMPILE) usedir.c exutils.o $(LIBPATH) $(CTLIBS) $(SYSLIBS) -o $@

#
# multthrd requires the DCE pthread or solaris thread interface. 
# sybopts.sh verifies that SYBPLATFORM is set to a "dce_" variant.
# The files: generic/thrdfunc.c has interface for pthreads and 
# dce_sun_svr4/thrdfunc.c has an interfaces for solaris native threads

multthrd: multthrd.c thrdutil.o thrdfunc.o example.h
	sh sybopts.sh verify_threaded; \
	sh sybopts.sh verify; \
	$(COMPILE) multthrd.c thrdutil.o thrdfunc.o $(LIBPATH) $(CTLIBS) \
		$(SYSLIBS) -o $@

exconfig: exconfig.c exutils.o
	sh sybopts.sh verify; \
	$(COMPILE) exconfig.c exutils.o $(LIBPATH) $(CTLIBS) $(SYSLIBS) -o $@

firstapp: firstapp.c
	sh sybopts.sh verify; \
	$(COMPILE) firstapp.c $(LIBPATH) $(CTLIBS) $(SYSLIBS) -o $@

# 
# There are two targets for the network-based security example:
#   secct_dce -- for DCE security driver
#   secct_krb -- for CyberSAFE Kerberos security driver
#
secct_krb: secct.c exutils.o
	sh sybopts.sh verify_krb; \
	sh sybopts.sh verify; \
	$(COMPILE) secct.c exutils.o $(LIBPATH) $(CTLIBS) $(KRBLIBS) $(SYSLIBS) -o $@
secct_dce: secct.c exutils.o
	sh sybopts.sh verify_dce; \
	sh sybopts.sh verify; \
	$(COMPILE) secct.c exutils.o $(LIBPATH) $(CTLIBS) $(SYSLIBS) -o $@


clean: 
	rm compute csr_disp rpc getsend i18n usedir exasync \
	blktxt exconfig firstapp *.o

