
# Actions to rebuild an out-of-date shared library
#   The library basename is given by LIBNAME
SLSUFFIX = so

# configure generated targets:
shared_irix6: shared_irix

shared_osf5: shared_alpha

shared_solaris2: shared_solaris

shared_freebsd5: shared_freebsd
shared_freebsd4: shared_freebsd
shared_freebsd3: shared_freebsd

shared_aix3:
shared_aix4:
shared_aix5:
shared_aix6:

shared_darwin6: 
shared_darwin7: 

shared_hpux11: shared_hpux

# rules for building different shared libraries
shared_none:

shared_cygwin:

shared_linux_intel:
	-@cd ${SHARED_LIBRARY_TMPDIR}; \
	${AR} x ${INSTALL_LIB_DIR}/${LIBNAME}.${LIB_SUFFIX}; \
	${CLINKER} -shared -o ${INSTALL_LIB_DIR}/$$LIBNAME.${SLSUFFIX} *.o ${PETSC_EXTERNAL_LIB_BASIC}; \
	${RM} -f *

shared_irix:
	-@${C_CC} -elf -no_library_replacement -shared -rdata_shared -all ${INSTALL_LIB_DIR}/${LIBNAME}.${LIB_SUFFIX} -o ${INSTALL_LIB_DIR}/${LIBNAME}.${SLSUFFIX}

shared_alpha:
	-@${LD} -shared -all ${INSTALL_LIB_DIR}/${LIBNAME}.${LIB_SUFFIX} -o ${INSTALL_LIB_DIR}/${LIBNAME}.${SLSUFFIX} >/dev/null 2>&1

shared_freebsd:
	-@${LD} -Bshareable --whole-archive ${INSTALL_LIB_DIR}/${LIBNAME}.${LIB_SUFFIX} -o ${INSTALL_LIB_DIR}/${LIBNAME}.${SLSUFFIX}

shared_hpux:
	-@cd ${SHARED_LIBRARY_TMPDIR}; \
	${AR} x ${INSTALL_LIB_DIR}/${LIBNAME}.${LIB_SUFFIX}; \
	${LD} -b *.o -o ${INSTALL_LIB_DIR}/${LIBNAME}.${SLSUFFIX}; \
	${RM} -f *

#${CLINKER} -fPIC -shared *.o -o ${INSTALL_LIB_DIR}/${LIBNAME}.${SLSUFFIX};
shared_linux:
	-@cd ${SHARED_LIBRARY_TMPDIR}; \
	${AR} x ${INSTALL_LIB_DIR}/${LIBNAME}.${LIB_SUFFIX}; \
	${CLINKER} -shared -Wl,-soname,${LIBNAME}.${SLSUFFIX} -o ${INSTALL_LIB_DIR}/$$LIBNAME.${SLSUFFIX} *.o ${PETSC_EXTERNAL_LIB_BASIC}; \
	${RM} -f *

shared_solaris:
	-@cd ${SHARED_LIBRARY_TMPDIR}; \
	${AR} x ${INSTALL_LIB_DIR}/${LIBNAME}.${LIB_SUFFIX}; \
	sys_lib=`echo "${SYS_LIB}" | sed s?-Wl,-rpath?-L?g`; external_lib=`echo "${PETSC_EXTERNAL_LIB_BASIC}" | sed s?-Wl,-rpath?-L?g`;\
	${LD}  -G -h ${LIBNAME}.${SLSUFFIX} *.o -o ${INSTALL_LIB_DIR}/${LIBNAME}.${SLSUFFIX} $${sys_lib} $${external_lib}; \
	${RM} -f *

# Actions taken by libtool to rebuild an out-of-date shared library
#   The library basename is given by LIBNAME
shared_libtool:
	-@cd ${SHARED_LIBRARY_TMPDIR}; \
	${AR} x ${INSTALL_LIB_DIR}/${LIBNAME}.${LIB_SUFFIX}; \
	${AR} x ${INSTALL_LIB_DIR}/lt_${LIBNAME}.${LIB_SUFFIX}; \
	${LIBTOOL} --mode=link ${CLINKER} ${CFLAGS} ${CCPPFLAGS} -rpath ${INSTALL_LIB_DIR} -o ${LIBNAME}.la *.lo; \
	${LIBTOOL} --mode=install ${PETSC_DIR}/bin/config/install-sh ${LIBNAME}.la ${INSTALL_LIB_DIR}; \
	${RM} -f *

# This is the main target for building shared libraries. It takes the following actions
#   a) Create 'tmp' in the library directory
#   b) Loops over the shared libraries in $SHLIBS
#   c) Checks that the corresponding archive or its libtool counterpart exists
#   d) Checks whether an existing archive is newer than the shared library
#   e) Executes target 'shared_arch' for any out-of-date library (The library basename is passed as LIBNAME)
#   c) Removes 'tmp'
# The 'shared_arch' target is passed
#   a) BOPT
#   b) LIBNAME (the library basename)
#   c) SHARED_LIBRARY_TMPDIR (where .o files should be manipulated)
# and both the archive and shared library reside in INSTALL_LIB_DIR.
shared: chkopts_basic
	-@echo making shared libraries in ${INSTALL_LIB_DIR}; \
	${RM} -rf ${INSTALL_LIB_DIR}/tmp; \
	mkdir ${INSTALL_LIB_DIR}/tmp; \
	for LIBNAME in ${SHLIBS}; \
	do \
	  if test -f ${INSTALL_LIB_DIR}/$$LIBNAME.${LIB_SUFFIX} -o -f ${INSTALL_LIB_DIR}/lt_$$LIBNAME.${LIB_SUFFIX}; then \
	    if test -f ${INSTALL_LIB_DIR}/$$LIBNAME.${SLSUFFIX}; then \
	      flag=`find ${INSTALL_LIB_DIR} -type f -name $$LIBNAME.${LIB_SUFFIX} -newer ${INSTALL_LIB_DIR}/$$LIBNAME.${SLSUFFIX} -print`; \
	      if [ "$$flag" = "" ]; then \
	        flag=`find ${INSTALL_LIB_DIR} -type f -name lt_$$LIBNAME.${LIB_SUFFIX} -newer ${INSTALL_LIB_DIR}/$$LIBNAME.${SLSUFFIX} -print`; \
	      fi; \
	    else \
	      flag="build"; \
	    fi; \
	    if [ "$$flag" != "" ]; then \
            echo "building $$LIBNAME.${SLSUFFIX}"; \
	      ${OMAKE} BOPT=${BOPT} LIBNAME=$$LIBNAME SHARED_LIBRARY_TMPDIR=${INSTALL_LIB_DIR}/tmp shared_arch; \
	    fi; \
	  fi; \
	done; \
	${RM} -rf ${INSTALL_LIB_DIR}/tmp


