# See bottom of file for license and copyright information
#
# 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

#   Declare package Foswiki, so globals end up in $Foswiki space
package Foswiki;

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";
}

# Prepend to @INC, the Perl search path for modules
unshift @INC, $foswikiLibPath;
unshift @INC, @localPerlLibPath if @localPerlLibPath;
# Append lib/CPAN/lib for absolutely needed dependencies
push @INC, "$foswikiLibPath/CPAN/lib";

# Foswiki won't run at all without these:
my %missing;

foreach (qw( JSON Error CGI CGI::Session File::Copy::Recursive Crypt::PasswdMD5 )) {
    eval "require $_";
    $missing{$_} = $@ if $@;
}

if ( scalar %missing ) {
    print "Content-type: text/plain\n\n";
    print
"**** ERROR ****\nThe following critical dependencies are missing from your installation:\n";
    foreach my $key ( sort keys %missing ) {
        $missing{$key} =~ m/^(.*?(?:\@INC|CPAN\.))/;
        print " ... $key: $1 \n";
    }
    print <<REPORT;

Please install these modules and then ensure all dependencies are installed by either:
 -  viewing the System.PerlDependencyReport in your local Foswki,  or
 -  running the CLI shell script tools/dependencies from your server's command line.
You can get a complete list of Perl module dependencies by viewing System.SystemRequirements
on your local system or at http://foswiki.org/System/SystemRequirements.

Foswiki will not operate correctly unless the required dependencies are installed.

Your current library search path \@INC contains:

REPORT

    print "   " . join( "\n   ", @INC ) . "\n";

    print "\nYou can adjust the search path by editing bin/LocalLib.cfg\n";
    exit;
}

1;			    	# Return success for module loading

__END__
Foswiki - The Free and Open Source Wiki, http://foswiki.org/

Copyright (C) 2008-2010 Foswiki Contributors. Foswiki Contributors
are listed in the AUTHORS file in the root of this distribution.
NOTE: Please extend that file, not this notice.

Additional copyrights apply to some or all of the code in this
file as follows:

Copyright (C) 1999-2007 Peter Thoeny, peter@thoeny.org
and TWiki Contributors. All Rights Reserved. TWiki Contributors
are listed in the AUTHORS file in the root of this distribution.

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.

As per the GPL, removal of this notice is prohibited.
