#!/bin/sh
#
# =========================================================================
#
# PHENIX installation script to check library installation
#
# Author: Paul Adams, March 2003
#
# Copyright: Lawrence Berkeley National Laboratory, 2003
# =========================================================================
#
if [ ! "$1" -o ! "$2" ]; then
  echo usage: check_lib directory library
  exit 1
fi
#
dir=$1
if [ ! -d "$dir" ]; then
  echo check_lib: directory $dir does not exist
  exit 1
fi
#
search_lib=$2
#
found=0
#
# process possible dynamic library files
# 
lib_list=""
if /bin/ls $dir/*$search_lib*.so >/dev/null 2>&1 ; then
  lib_list="`/bin/ls $dir/*$search_lib*.so 2>&1 | awk 'BEGIN{FS="/"}{print $NF}' | sed -e 's/\.so$//'`"
fi
if [ -n "$lib_list" ]; then
  for lib in $lib_list ; do
     libbase="`echo $lib | sed -e 's/-*[0-9]*\.*[0-9]*//g'`"
     if [ "lib$search_lib" = "$libbase" ]; then
       found=1
     elif [ "$search_lib" = "$libbase" ]; then
       found=1
     fi
  done
fi
#
# process possible static library files
# 
lib_list=""
if /bin/ls $dir/*$search_lib*.a >/dev/null 2>&1 ; then
  lib_list="`/bin/ls $dir/*$search_lib*.a 2>&1 | awk 'BEGIN{FS="/"}{print $NF}' | sed -e 's/\.a$//'`"
fi
if [ -n "$lib_list" ]; then
  for lib in $lib_list ; do
     libbase="`echo $lib | sed -e 's/-*[0-9]*\.*[0-9]*//g'`"
     if [ "lib$search_lib" = "$libbase" ]; then
       found=1
     elif [ "$search_lib" = "$libbase" ]; then
       found=1
     fi
  done
fi
#
echo $found
#
