#
# Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org and TWiki Contributors
# Copyright (C) 2008-2009 Foswiki Contributors.
# All Rights Reserved. TWiki Contributors and Foswiki Contributors
# are listed in the AUTHORS file in the root of this distribution.
# NOTE: Please extend that file, not this notice.
#
# 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. For
# more details read LICENSE in the root of this distribution.
#
# 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.
#
# setlib.cfg: determines the defaults for Foswiki and Perl library paths
#

###########################################################################
# DO NOT CHANGE THIS FILE - instead, create a file called LocalLib.cfg    #
# using the LocalLib.cfg.txt template file and customise your settings in #
# there. They will override any settings in this file.                    #
###########################################################################

# for development, you can enable ASSERTS by adding
# $ENV{FOSWIKI_ASSERTS} = 1;
# to your bin/LocalLib.cfg

use vars qw( $foswikiLibPath @localPerlLibPath );

my $LocalLib = __FILE__;    # the dir where this setlib.cfg resides
$LocalLib =~ s/setlib.cfg$/LocalLib.cfg/;
require $LocalLib if -r $LocalLib;
# if foswikiLibPath isn't defined, then see if $twikiLibPath is
# for compatibility
$foswikiLibPath = $twikiLibPath unless defined( $foswikiLibPath );

unless (( defined ($foswikiLibPath) ) and (-e $foswikiLibPath)) {
	use Cwd qw( abs_path );
    my $bindir = __FILE__;
    $bindir =~ s/setlib.cfg$//;
	( $foswikiLibPath ) = ($foswikiLibPath = Cwd::abs_path( "$bindir../lib" )) =~ /(.*)/;
}
if ($foswikiLibPath eq "") {
    $foswikiLibPath = "../lib";
    warn "using relative path for libs - some plugins may break";
}

#    Path to local Perl modules
my $defaultingCPANBASE = !defined($CPANBASE);
$CPANBASE = "$foswikiLibPath/CPAN/lib/" unless $CPANBASE;
if ( -e $CPANBASE ) {
	require Config;
	my $VER = $Config::Config{version};
	my $SITEARCH = $Config::Config{archname};
	push @localPerlLibPath, ( "$CPANBASE/arch", "$CPANBASE/$VER/$SITEARCH", "$CPANBASE/$VER", "$CPANBASE" );
}

# Prepend to @INC, the Perl search path for modules
unshift @INC, $foswikiLibPath;
if ($defaultingCPANBASE) {
	push @INC, @localPerlLibPath if @localPerlLibPath;
} else {
	unshift @INC, @localPerlLibPath if @localPerlLibPath;
}

1;			    	# Return success for module loading

