#!/bin/sh -e
#
# $Id: install-freeamp,v 1.5 1999/07/29 21:11:39 robert Exp $
#

prefix=/usr/local

bindir="$prefix/bin"
libdir="$prefix/lib"
fadir="$libdir/freeamp"
plugdir="$fadir/plugins"
ldconf="/sbin/ldconfig"

# We could use mkdir -p, but not all unix systems' mkdir's support -p
for dir in "$bindir" "$libdir" "$fadir" "$plugdir"; do
    if [ \! -d "$dir" ]; then
	echo "mkdir $dir"
	mkdir "$dir"
	echo "chown root $dir"
	chown root "$dir"
	echo "chmod 755 $dir"
	chmod 755 "$dir"
    fi
done

install -c -m 755 freeamp "$bindir"
for file in plugins/*.*; do
    enable=f
    case "$file" in
    	*/alsa-*.pmo)
	      if $ldconf -p | grep 'libasound\.so' > /dev/null; then
	      	enable=t
	      else
	      	enable=f
		      echo "rm -f $fadir/$file"
		      rm -f "$fadir/$file"
	      fi
	   ;;
    	*/esound-*.pmo)
	      if $ldconf -p | grep 'libesd\.so' > /dev/null; then
	      	enable=t
	      else
	      	enable=f
		      echo "rm -f $fadir/$file"
		      rm -f "$fadir/$file"
	      fi
	   ;;
      */ncurses-*.ui)
         if $ldconf -p | grep 'libncurses\.so' > /dev/null; then
            enable=t
         else
            enable=f
            rm -f "$fadir/$file"
         fi
      ;; 
	   *)
	   enable=t
	   ;;
    esac
    if [ "$enable" = t ]; then
        echo "install -c -o root -m 644 $file $plugdir"
        install -c -o root -m 644 "$file" "$plugdir"
    fi
done
