1package
2        setup;
3
4use strict;
5use warnings;
6use parent qw(Exporter);
7
8use File::Spec;
9use Cwd qw(abs_path);
10
11our @EXPORT = ('%setup');
12
13our %setup = (
14    datadir => './share',
15    libdir  => './lib',
16    vardir  => './var',
17);
18
19# Compute directly libdir from this setup file as it should be installed
20# in expected directory
21eval {
22    $setup{libdir} = abs_path(File::Spec->rel2abs('..', __FILE__))
23        unless ($setup{libdir} && File::Spec->file_name_is_absolute($setup{libdir}));
24
25    # If run from sources, we can try to rebase setup keys to absolute folders related to libdir
26    if (File::Spec->file_name_is_absolute($setup{libdir})) {
27        foreach my $key (qw(datadir vardir)) {
28            # Anyway don't update if target still absolute
29            next if ($setup{$key} && File::Spec->file_name_is_absolute($setup{$key}));
30
31            my $folder = abs_path(File::Spec->rel2abs('../'.$setup{$key}, $setup{libdir}));
32            $setup{$key} = $folder if $folder && -d $folder;
33        }
34    }
35};
36
371;
38