# cus_rdbms.mk - "make" command file to reload 'oracle'.
#
# Used to reload oracle after changing the SGA base address or adding a
# new network driver.
#
# The base address of the sga is specified by the symbol "sgabeg"
# or the symbol "sgadef" in the file ksms.s
#
#
# 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
#


CONFIG = $(ORACLE_HOME)/rdbms/lib/config.o
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`

#

# 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

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)

SDOLIBS = `if $(AR) tv ${LIBKNLOPT} | grep ${NO_SDOPT} > /dev/null 2>&1;then echo " ";else echo "-lmdknl -lmdhh -lm";fi`
OSNTABST= `if [ -f $(ORACLE_HOME)/lib/osntabst.o ]; then \
		echo '$(ORACLE_HOME)/lib/osntabst.o'; \
	   else \
		echo '$(ORACLE_HOME)/network/lib/osntabst.o'; \
	   fi `

$(PSOLIBLIST):
	$(GENPSOLIB)

GENPSOLIB=\
	rm -f $(PSOLIBLIST); \
	if $(AR) t $(LIBKNLOPT) $(NO_PARROPT) > /dev/null 2>&1; then \
	 echo $(DUMPSOLIBS) > $(PSOLIBLIST) ; \
	else \
	 echo $(PSOLIBS) > $(PSOLIBLIST); \
	fi

setsdolib:
	rm -f $(SDOLIB); \
	if $(AR) t $(LIBKNLOPT) $(NO_SCAFOPT) > /dev/null 2>&1; then \
	 ln -s $(DUMSDOLIB) $(SDOLIB) ; \
	else \
		if [ -f $(REALSDOLIB) ] ; then \
		 ln -s $(REALSDOLIB)  $(SDOLIB) ; \
		else \
		 ln -s $(DUMSDOLIB) $(SDOLIB) ; \
		fi \
	fi

INSTALL_TARGS=clean ioracle iexp iimp isqlldr

default: oracle
  
#
# targets for adding/removing oracle7 kernel options
#
pqopt: $(PQOPT) $(BMIOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(NO_PQOPT) > /dev/null 2>&1; then \
		$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(NO_PQOPT); \
	fi
	@if $(AR) t $(LIBKNLOPT) | grep $(NO_BMIOPT) > /dev/null 2>&1; then \
                $(ECHO) $(ARDELETE) $(LIBKNLOPT) $(NO_BMIOPT); \
        fi
	$(ARCREATE) $(LIBKNLOPT) $(PQOPT) $(BMIOPT)
	$(RANLIBKNLOPT)

no_pqopt: $(NO_PQOPT) $(NO_BMIOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(PQOPT) > /dev/null 2>&1; then \
		$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(PQOPT); \
	fi
	@if $(AR) t $(LIBKNLOPT) | grep $(BMIOPT) > /dev/null 2>&1; then \
                $(ECHO) $(ARDELETE) $(LIBKNLOPT) $(BMIOPT); \
        fi
	$(ARCREATE) $(LIBKNLOPT) $(NO_PQOPT) $(NO_BMIOPT)
	$(RANLIBKNLOPT)

repopt:	$(REPOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(NO_REPOPT) > /dev/null 2>&1; then \
	$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(NO_REPOPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(REPOPT)
	$(RANLIBKNLOPT)
no_repopt:	$(NO_REPOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(REPOPT) > /dev/null 2>&1; then \
	$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(REPOPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(NO_REPOPT)
	$(RANLIBKNLOPT)
procopt: $(PROCOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(NO_PROCOPT) > /dev/null 2>&1; then \
		$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(NO_PROCOPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(PROCOPT) 
	$(RANLIBKNLOPT)

no_procopt: $(NO_PROCOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(PROCOPT) > /dev/null 2>&1; then \
		$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(PROCOPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(NO_PROCOPT) 
	$(RANLIBKNLOPT)

parropt: $(PARROPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(NO_PARROPT) > /dev/null 2>&1; then \
	$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(NO_PARROPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(PARROPT)
	$(CLEANPSO)
	$(RANLIBKNLOPT)

no_parropt: $(NO_PARROPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(PARROPT) > /dev/null 2>&1; then \
	$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(PARROPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(NO_PARROPT)
	$(CLEANPSO)
	$(RANLIBKNLOPT)

ddbopt: $(DDBOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(NO_DDBOPT) > /dev/null 2>&1; then \
		$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(NO_DDBOPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(DDBOPT) 
	$(RANLIBKNLOPT)

no_ddbopt: $(NO_DDBOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(DDBOPT) > /dev/null 2>&1; then \
		$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(DDBOPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(NO_DDBOPT) 
	$(RANLIBKNLOPT)

sdopt: $(SDOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(NO_SDOPT) > /dev/null 2>&1; then \
		$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(NO_SDOPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(SDOPT) 
	$(RANLIBKNLOPT)

no_sdopt: $(NO_SDOPT)
	@if $(AR) t $(LIBKNLOPT) | grep $(SDOPT) > /dev/null 2>&1; then \
		$(ECHO) $(ARDELETE) $(LIBKNLOPT) $(SDOPT); \
	fi
	$(ARCREATE) $(LIBKNLOPT) $(NO_SDOPT) 
	$(RANLIBKNLOPT)

oracle: $(ORALIBD) $(CORELIBD) $(NETLIBD) $(KSMS) $(CONFIG) $(PSOLIBLIST) opimai.o
	@$(ECHO) $(LINK) -o $@ $(LDFLAGS) $(LDFLAGS_ORA) opimai.o $(CONFIG) \
	$(LLIBSERVER) $(LLIBORA) $(LLIBKNLOPT) $(LLIBSLAX) $(LLIBPLSQL) \
	$(LLIBSICX) $(LLIBSOWSUTL) \
	$(LLIBSERVER) $(LLIBORA) $(LLIBKNLOPT) $(LLIBSLAX) $(LLIBPLSQL) \
	$(LLIBSERVER) $(LLIBORA) $(LLIBSLAX) $(LLIBPLSQL) $(LLIBSERVER) \
	$(TTLIBS) $(SDOLIBS) $(LLIBPSO) $(LIBLISTRDBMS) $(CLIBS) -lc -lm

ioracle: oracle
	-mv -f $(ORACLE_HOME)/bin/oracle $(ORACLE_HOME)/bin/oracleO
	-mv oracle $(ORACLE_HOME)/bin/oracle
	-chmod 6751 $(ORACLE_HOME)/bin/oracle

exp: exudrv.o $(LIBEXP) $(TTLIBD) $(LIBCORE)
	@$(ECHO) $(LINK) -o $@ $(LDFLAGS) exudrv.o -lexp $(TTLIBS) -lc

iexp: exp
	-mv -f $(ORACLE_HOME)/bin/exp $(ORACLE_HOME)/bin/expO
	-mv exp $(ORACLE_HOME)/bin/exp
	-chmod 751 $(ORACLE_HOME)/bin/exp

imp: impdrv.o $(LIBIMP) $(TTLIBD) $(LIBCORE)
	@$(ECHO) $(LINK) -o $@ $(LDFLAGS) impdrv.o -limp $(TTLIBS) -lc

iimp: imp
	-mv -f $(ORACLE_HOME)/bin/imp $(ORACLE_HOME)/bin/impO
	-mv imp $(ORACLE_HOME)/bin/imp
	-chmod 751 $(ORACLE_HOME)/bin/imp

sqlldr: ulmai.o $(LIBUL) $(TTLIBD) $(LIBCLIENT) $(LIBKNL) $(LIBCORE)
	@$(ECHO) $(LINK) -o $@ $(LDFLAGS) ulmai.o $(TTLIBS) -lc

isqlldr: sqlldr
	-mv -f $(ORACLE_HOME)/bin/sqlldr $(ORACLE_HOME)/bin/sqlldrO
	-mv sqlldr $(ORACLE_HOME)/bin/sqlldr
	-chmod 751 $(ORACLE_HOME)/bin/sqlldr
	-rm -f $(ORACLE_HOME)/bin/sqlload
	-ln $(ORACLE_HOME)/bin/sqlldr  $(ORACLE_HOME)/bin/sqlload

tkprof:	
	@$(ECHO) $(LINK) -o $@ $(LDFLAGS) tkprof.o $(TTLIBS) -lc

itkprof: tkprof
	-mv -f $(ORACLE_HOME)/bin/tkprof $(ORACLE_HOME)/bin/tkprofO
	-mv tkprof $(ORACLE_HOME)/bin/tkprof
	-chmod 751 $(ORACLE_HOME)/bin/tkprof

expst: exudrv.o $(LIBEXP) $(LIBORASTD) $(CONFIG) $(PSOLIBLIST)
	@$(ECHO) $(LINK) -o $@ $(LDFLAGS) exudrv.o -lexp $(STLIBS) -lc

impst: impdrv.o $(LIBIMP) $(LIBORASTD) $(CONFIG) $(PSOLIBLIST)
	@$(ECHO) $(LINK) -o $@ $(LDFLAGS) impdrv.o -limp $(STLIBS) -lc

sqlldrst: ulmai.o $(LIBUL) $(LIBORASTD) $(LIBCLIENT) $(CONFIG) $(PSOLIBLIST)
	@$(ECHO) $(LINK) -o $@ $(LDFLAGS) ulmai.o $(LIBCLIENT) $(STLIBS) -lc

preinstall:
	-chmod 755 $(ORACLE_HOME)/bin

install: preinstall $(INSTALL_TARGS)

singletask: expst impst sqlldrst
	chmod 755 $(ORACLE_HOME)/bin
	-mv -f $(ORACLE_HOME)/bin/expst $(ORACLE_HOME)/bin/expstO
	-mv -f $(ORACLE_HOME)/bin/impst $(ORACLE_HOME)/bin/impstO
	-mv -f $(ORACLE_HOME)/bin/sqlldrst $(ORACLE_HOME)/bin/sqlldrstO
	mv expst $(ORACLE_HOME)/bin/expst
	mv impst $(ORACLE_HOME)/bin/impst
	mv sqlldrst $(ORACLE_HOME)/bin/sqlldrst
	chmod 751 $(ORACLE_HOME)/bin/expst
	chmod 751 $(ORACLE_HOME)/bin/impst
	chmod 751 $(ORACLE_HOME)/bin/sqlldrst

clean:
	-rm -f ksms.s ksms.o
	-rm -f oracle imp exp sqlldr
