#!/usr/bin/perl -w
#
#  getlibdir - Determine an appropriate library directory.
#
#  GNU MP3D - A portable(ish) MP3 server.
#
# Homepage:
#   http://www.gnump3d.org/
#
# Author:
#  Steve Kemp <steve@steve.org.uk>
#
# Version:
#  $Id: getlibdir,v 1.4 2004/11/23 09:32:52 skx Exp $
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
#
#  Steve Kemp
#  ---
#  http://www.steve.org.uk/
#
#


use strict;


#
#  Only examine directories beneath /usr or /Library
# (The latter is for Mac OS X).
#
my @dirs = grep( /^\/usr|^\/Library/, @INC );


#
# we prefer /share/ to /lib/ since this is arch-indep
#
if ( grep(m|/share/|, @dirs) ) {
    @dirs = grep(m|/share/|, @dirs);
}

#
#  Find the shortest one.
#
@dirs = sort { length( $a ) <=> length( $ b ) }  @dirs ;


#
#  Print it out - stripping the trailing '/' if present
#
if ( $dirs[0] =~ /(.*)\/$/ ) {
    $dirs[0] = $1;
}

print $dirs[0];
