# Makefile for Oraperl and Coraperl

# Change these to your ORACLE installation directory and Perl source directory
#
ORACLE_HOME	= /usr/soft/oracle
SRC		= /usr/soft/public/perl

# Oracle Definitions, copied from $(ORACLE_HOME)/c/demo/proc.mk
# ALL_ORA_LIBS is the only entry that the Makefile actually uses;
# change it to whatever you need to link Pro*C programs
#
OTHERLIBS	= `cat $(ORACLE_HOME)/rdbms/lib/sysliblist`
CLIBS		= $(OTHERLIBS)
OCILIB		= $(ORACLE_HOME)/rdbms/lib/libocic.a
NETLIBS		= $(ORACLE_HOME)/rdbms/lib/osntab.o \
			$(ORACLE_HOME)/rdbms/lib/libsqlnet.a 
ORALIBS		= $(ORACLE_HOME)/rdbms/lib/libora.a

ALL_ORA_LIBS	= $(CLIBS) $(OCILIB) $(NETLIBS) $(ORALIBS)

# Perl Definitions, taken from $SRC/usub/Makefile
# Don't include the curses libraries here - they go in CURSELIB
#
GLOBINCS	= 
LOCINCS		= 
LIBS		= `. $(SRC)/config.sh; echo $$libs`

# Oraperl Definitions

# Set DEBUG to -DDEBUGGING, -DPERL_DEBUGGING or leave blank (see orafns.h)
# If it is not blank, uncomment the definition of DBUG_O
#
DEBUG		= -DPERL_DEBUGGING
DBUG_O		= dbug/dbug.o

# Curses libraries, only required if you want to build Coraperl
# You may also need -ltermlib or -ltermcap
#
CURSELIB	= -lcurses

# Row cache size for SELECT statements.
# If you want to change the default, uncomment this and set the value you want
#
#CACHE		= -DCACHE_SIZE=5

# Bind variable padding.
# If you want binding an empty string to provoke an error, uncomment this line.
#
#BIND		= -DNO_BIND_PADDING

# Some system-specific things
#
# If your system library does not include strtoul, uncomment the next line
STRTOUL	= strtoul.o
#
# If your malloc() returns anything other than a char *, set the appropriate
# type here (don't include the *)
# MALLOC_PTR_TYPE=void
#
# If you are using Perl v3 instead of v4, uncomment the next line
# STR_2MORTAL	= -Dstr_2mortal=str_2static

# Database, username and password to use for testing
#
TESTDATA	= t scott tiger


#
#	Leave these blank lines so that patches to what is below
#	won't be upset by your changes to the setups above.
#


# From here on, you shouldn't need to change anything. If you do, let me know.

SRCS		= oracle.mus orafns.c getcursor.c colons.c usersub.c \
		  debug.c strtoul.c
OBJS		= oracle.o orafns.o getcursor.o colons.o debug.o $(STRTOUL)
OOBJS		= $(OBJS) usersub.o $(DBUG_O)
COBJS		= $(OBJS) cusersub.o $(DBUG_O)
HDRS		= patchlevel.h orafns.h
DEFS		= $(STRTOL) $(PUTENV) $(STR_2MORTAL) $(DEBUG) $(CACHE) $(BIND)

CFLAGS		= -Idbug -I$(SRC) $(GLOBINCS) $(LOCINCS) $(DEFS)

oraperl: $(SRC)/uperl.o $(OOBJS)
	$(CC) -o oraperl $(SRC)/uperl.o $(OOBJS)			\
	      -lm $(ALL_ORA_LIBS) $(LIBS)

coraperl: $(SRC)/uperl.o $(COBJS) $(SRC)/usub/curses.o
	$(CC) -o coraperl $(SRC)/uperl.o $(COBJS) $(SRC)/usub/curses.o	\
	      -lm $(ALL_ORA_LIBS) $(LIBS) $(CURSELIB)

all:	oraperl coraperl

test:	oraperl
	@oraperl -e '&ora_version'
	@(cd testdir ;							      \
	  rm -f My-Results ;						      \
	  echo "Testing oraperl, please wait ..." ;			      \
	  for i in *.pl	; do ../oraperl $$i $(TESTDATA) ; done > My-Results ; \
	  if cmp -s Standard-Results My-Results ;			      \
	  then echo "Test successful" ;					      \
	  else echo "Test failed - compare My-Results with Standard-Results" ;\
	  fi; echo)

# We use oraperl although perl would suffice, because we know where it is!

install:	oraperl install.pl
	@./oraperl ./install.pl ${SRC}

cusersub.c:	usersub.c
	@rm -f cusersub.c
	ln usersub.c cusersub.c

cusersub.o:	cusersub.c
	$(CC) -c $(CFLAGS) -DCURSES cusersub.c

oracle.c: $(SRC)/usub/mus oracle.mus
	$(SRC)/usub/mus oracle.mus >oracle.c

$(OOBJS) $(COBJS):	$(HDRS)

dbug/dbug.o:
	(cd dbug ; $(MAKE) dbug.o)
	@echo "	(back to main directory)"

clean:
	(cd dbug ; $(MAKE) clean)
	@echo "	(back to main directory)"
	rm -f nohup.out *.o oracle.c cusersub.c
	rm -f testdir/My-Results listing tags core

realclean clobber:	clean
	(cd dbug ; $(MAKE) clobber)
	(cd doc ; $(MAKE) clobber)
	@echo "	(back to main directory)"
	rm -f oraperl coraperl

listing:
	pr -fn Makefile $(HDRS) $(SRCS) >listing

docs:
	(cd doc ; $(MAKE) docs)
	@echo "	(back to main directory)"

shar:	clean
	shar -n oraperl-v2 -a -s kstock@encore.com -F -o :Part -l 64	\
		Readme [C-Q]* Row* [S-z]*
