#
# Example for linking demo OCI programs:
#
# deferred mode (default):
#	make -f oracle.mk cdemo1
#
# non-deferred mode:
#	make -f oracle.mk NONDEFER=true cdemo1
#
#
# NOTE:   ORACLE_HOME must be either:
#		. set in the user's environment
#		. passed in on the command line
#		. defined in a modified version of this makefile
#
# Following macro contains ORACLE libraries that are linked to create:
# OCILDLIBS	: OCI application executables
#

include $(ORACLE_HOME)/rdbms/lib/env_rdbms.mk

LDFLAGS=-L$(LIBHOME) -L$(ORACLE_HOME)/rdbms/lib
ECHO=$(ORACLE_HOME)/bin/echodo
LLIBPSO=`cat $(ORACLE_HOME)/rdbms/lib/psoliblist`

FC=f77
COB=cob
COBFLAGS=-C IBMCOMP -x
COBGNTFLAGS=-C IBMCOMP -u

# directory that contain oratypes.h and other oci demo program header files
INCLUDE= -I$(ORACLE_HOME)/rdbms/demo -I$(ORACLE_HOME)/rdbms/public

#
CONFIG = $(ORACLE_HOME)/rdbms/lib/config.o

# module to be used for linking with non-deferred option
NDFOPT= $(ORACLE_HOME)/rdbms/lib/kpundf.o

# flag for linking with non-deferred option (default is deferred mode)
NONDEFER=false

# libraries for linking oci programs
OCILDLIBS= $(LIBCLIENT) $(DEVTTLIBS) $(LLIBCORE)

PSOLIBLIST=$(ORACLE_HOME)/rdbms/lib/psoliblist
CLEANPSO=rm -f $(PSOLIBLIST); $(GENPSOLIB)

DOLIB=$(ORACLE_HOME)/lib/liborcaccel.a
DUMSDOLIB=$(ORACLE_HOME)/lib/liborcaccel_stub.a
REALSDOLIB=/usr/lpp/orcaccel/liborcaccel.a

ORALIBS=$(LLIBORA) -lknlopt $(LLIBPLSQL)
ORALIBD=$(LIBORA) $(LIBKNLOPT) $(LIBPLS) $(LIBKNL)

PROC=$(ORACLE_HOME)/bin/proc
PCCINCLUDE= include=$(ORACLE_HOME)/precomp/public
PCCI=-I$(ORACLE_HOME)/precomp/public
USERID=scott/tiger
PCCPLSFLAGS= $(PCCINCLUDE) ireclen=132 oreclen=132 sqlcheck=full \
ltype=none user=$(USERID)
LLIBSQL= -lsql
PROLDLIBS= $(LLIBSQL) $(TTLIBS)

DEMO_MAKEFILE = oracle.mk
 
DEMOS = cdemo1 cdemo2 cdemo3 cdemo4 cdemo5 obndra oci01 oci02 oci03 \
        oci04 oci05 oci06 oci07 oci08 oci09 oci10 oci11 oci12 oci13 \
        oci14 oci15 oci16 oci17 oci18 oci19 oci20 oci21 oci22 oci23 \
        oci24 oci25 readpipe 
COBDEMOS = cbdem1 cbdem2 cbdem3
FORDEMOS = fdemo1 fdemo2 fdemo3
C++DEMOS = cdemo6


.SUFFIXES: .o .cob .for

MAKEDEMO= \
	@if [ "$(NONDEFER)" = "true" -o "$(NONDEFER)" = "TRUE" ] ; then \
	$(ECHO) $(CC) $(LDFLAGS) -o $(EXE) $? $(NDFOPT) $(OCILDLIBS) $(CLIBS); \
	else \
	$(ECHO) $(CC) $(LDFLAGS) -o $(EXE) $? $(OCILDLIBS) $(CLIBS); \
	fi

demos: $(DEMOS)

$(DEMOS):
	$(MAKE) -f $(DEMO_MAKEFILE) build EXE=$@ OBJS=$@.o

build: $(OBJS)
	$(MAKEDEMO)


MAKECOBDEMO= \
	@if [ "$(NONDEFER)" = "true" -o "$(NONDEFER)" = "TRUE" ] ; then \
	$(ECHO) $(COB) $(COBFLAGS) $(LDFLAGS) -o $(EXE) $? $(NDFOPT) $(OCILDLIBS) $(CLIBS); \
	else \
	$(ECHO) $(COB) $(COBFLAGS) $(LDFLAGS) -o $(EXE) $? $(OCILDLIBS) $(CLIBS); \
	fi


cobdemos: $(COBDEMOS)
 
$(COBDEMOS):
	$(MAKE) -f $(DEMO_MAKEFILE) buildcob EXE=$@ OBJS=$@.o
 
buildcob: $(OBJS)
	$(MAKECOBDEMO)
 


MAKEFORDEMO= \
	@if [ "$(NONDEFER)" = "true" -o "$(NONDEFER)" = "TRUE" ] ; then \
	$(ECHO) $(FC) $(LDFLAGS) -o $(EXE) $? $(NDFOPT) $(OCILDLIBS) $(CLIBS); \
	else \
	$(ECHO) $(FC) $(LDFLAGS) -o $(EXE) $? $(OCILDLIBS) $(CLIBS); \
	fi

fordemos:  $(FORDEMOS)
 
$(FORDEMOS):
	$(MAKE) -f $(DEMO_MAKEFILE) buildfor EXE=$@ OBJS=$@.o
 
buildfor:  $(OBJS)
	$(MAKEFORDEMO)


.for.o:
	$(FC) $(LDFLAGS) $(CFLAGS) $*.for $(OCILDLIBS)

.cob.o:
	$(COB) $(COBFLAGS) $(LDFLAGS) $*.cob $(OCILDLIBS)

