+
+sub get_target_directories {
+ my $config = shift;
+
+ my $base = $config->{'INSTALL_BASE'};
+ my $mode = $config->{'INSTALL_MODE'};
+
+ # get last component of install base directory
+ # to treat as package name
+ my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
+
+ my @basedir = File::Spec->splitdir($directories);
+
+ # for Win32 we need to prepend the volume to the directory path
+ if ( $^O eq 'MSWin32' ) { shift @basedir; unshift @basedir, $volume; }
+ elsif ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; } # in a cygwin environment, $volume is returned empty
+
+ my $package = pop @basedir;
+
+
+ my %dirmap = ();
+ my %skipdirs = ();
+ if ($mode eq 'single') {
+ $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
+ $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
+ $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
+ $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
+ $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
+ $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
+ $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
+ $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
+ $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
+ $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'pazpar2');
+ $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
+ $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
+ $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
+ $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
+ $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
+ $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
+ $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
+ $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
+ $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
+ } elsif ($mode eq 'dev') {
+ my $curdir = File::Spec->rel2abs(File::Spec->curdir());
+ $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
+ $skipdirs{'INTRANET_CGI_DIR'} = 1;
+ $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
+ $skipdirs{'INTRANET_TMPL_DIR'} = 1;
+ $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
+ $skipdirs{'INTRANET_WWW_DIR'} = 1;
+ $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir);
+ $skipdirs{'OPAC_CGI_DIR'} = 1;
+ $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
+ $skipdirs{'OPAC_TMPL_DIR'} = 1;
+ $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
+ $skipdirs{'OPAC_WWW_DIR'} = 1;
+ $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
+ $skipdirs{'PERL_MODULE_DIR'} = 1;
+ $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
+ $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
+ $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'pazpar2');
+ $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
+ $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
+ $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
+ $skipdirs{'SCRIPT_NONDEV_DIR'} = 1;
+ $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
+ $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
+ $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
+ $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
+ $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
+ $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
+ } else {
+ # mode is standard, i.e., 'fhs'
+ $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
+ $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
+ $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
+ $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
+ $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
+ $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
+ $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
+ $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
+ $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
+ $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'pazpar2');
+ $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
+ $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
+ $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
+ $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
+ $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
+ $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
+ $dirmap{'LOG_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
+ $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
+ $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
+ }
+
+ _get_env_overrides(\%dirmap);
+ _get_argv_overrides(\%dirmap);
+ _add_destdir(\%dirmap);
+
+ return \%dirmap, \%skipdirs;
+}
+
+=head2 get_test_dir
+
+Map a directory target to the corresponding path for
+the test suite.
+
+=cut
+
+sub get_test_dir {
+ my ($dirname) = @_;
+
+ my @basedir = (File::Spec->rel2abs(File::Spec->curdir()), 't', 'run');
+ if (exists $test_suite_override_dirs{$dirname}) {
+ return File::Spec->catdir(@basedir, @{ $test_suite_override_dirs{$dirname} });
+ } else {
+ return;
+ }
+
+}
+
+sub _get_env_overrides {
+ my $dirmap = shift;
+
+ foreach my $key (keys %$dirmap) {
+ if (exists $ENV{$key}) {
+ $dirmap->{$key} = $ENV{$key};
+ print "Setting $key from environment\n";
+ }
+ }
+}
+
+sub _get_argv_overrides {
+ my $dirmap = shift;
+
+ my @new_argv = ();
+ for (my $i = 0; $i <= $#ARGV; $i++) {
+ if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
+ $dirmap->{$1} = $2;
+ } else {
+ push @new_argv, $ARGV[$i];
+ }
+ }
+ @ARGV = @new_argv;
+}
+
+sub _strip_destdir {
+ my $dir = shift;
+ $dir =~ s/^\$\(DESTDIR\)//;
+ return $dir;
+}
+
+sub _add_destdir {
+ my $dirmap = shift;
+
+ foreach my $key (keys %$dirmap) {
+ $dirmap->{$key} = '$(DESTDIR)'.$dirmap->{$key};
+ }
+}
+
+sub display_configuration {
+ my $config = shift;
+ my $dirmap = shift;
+ print "\n\nKoha will be installed with the following configuration parameters:\n\n";
+ foreach my $key (sort keys %$config) {
+ print sprintf("%-25.25s%s\n", $key, $config->{$key});
+ }
+
+ print "\nand in the following directories:\n\n";
+ foreach my $key (sort keys %$dirmap) {
+ print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
+ }
+ print "\n\nTo change any configuration setting, please run\n";
+ print "perl Makefile.PL again. To override one of the target\n";
+ print "directories, you can do so on the command line like this:\n";
+ print "\nperl Makefile.PL PERL_MODULE_DIR=/usr/share/perl/5.8\n\n";
+ print "You can also set different default values for parameters\n";
+ print "or override directory locations by using environment variables.\n";
+ print "\nFor example:\n\n";
+ print "export DB_USER=my_koha\n";
+ print "perl Makefile.PL\n";
+ print "\nor\n\n";
+ print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
+ print "If installing on a Win32 platform, be sure to use:\n";
+ print "'dmake -x MAXLINELENGTH=300000'\n\n";
+}
+
+=head2 find_zebra
+
+Attempt to find Zebra - check user's PATH and
+a few other directories for zebrasrv and zebraidx.
+
+FIXME: doesn't handle Win32
+
+=cut
+
+sub find_zebra {
+ my @search_dirs = map {
+ my $abs = File::Spec->rel2abs($_);
+ my ($toss, $directories);
+ ($toss, $directories, $toss) = File::Spec->splitpath($abs, 1);
+ $directories;
+ } split /:/, $ENV{PATH};
+ push @search_dirs, qw(/usr/local/bin /opt/local/bin /usr/bin);
+ my @zebrasrv_dirs = grep { -x File::Spec->catpath('', $_, 'zebrasrv') } @search_dirs;
+ return unless @zebrasrv_dirs;
+ # verify that directory that contains zebrasrv also contains zebraidx
+ foreach my $dir (@zebrasrv_dirs) {
+ return $dir if -x File::Spec->catpath('', $dir, 'zebraidx');
+ }
+ return;
+}
+
+package MY;
+
+# This will have to be reworked in order to accommodate Win32...
+
+sub test {
+ my $self = shift;
+ my $test = $self->SUPER::test(@_);
+ $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
+
+ # set KOHA_CONF
+ $test =~ s!\$\(FULLPERLRUN\)!KOHA_CONF=blib/KOHA_CONF_DIR/koha-conf.xml \$(FULLPERLRUN)!g;
+ return $test;
+}
+
+sub install {
+ my $self = shift;
+ my $install = "";
+ # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
+ # This means that we're completely overriding EU::MM's default
+ # installation and uninstallation targets.
+
+# If installation is on Win32, we need to do permissions different from *nix
+ if ( $^O =~ /darwin|linux|cygwin|freebsd|solaris/ ) { # this value needs to be verified for each platform and modified accordingly
+ foreach my $key (sort keys %$target_directories) {
+ $install .= qq(
+KOHA_INST_$key = blib/$key
+KOHA_DEST_$key = $target_directories->{$key}
+) unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ $install .= qq(
+install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
+\t\$(NOECHO) \$(NOOP)
+);
+ $install .= "install_koha ::\n";
+ $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
+ foreach my $key (sort keys %$target_directories) {
+ $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
+ $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
+
+ $install .= "\n";
+ $install .= "set_koha_ownership ::\n";
+# Do not try to change ownership if DESTDIR is set
+ if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
+ foreach my $key (sort keys %$target_directories) {
+ $install .= "\t\$(NOECHO) if test -z \"\$(DESTDIR)\"; then chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key); fi\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ } else {
+ $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
+ }
+
+ $install .= "\n";
+ $install .= "set_koha_permissions ::\n";
+ # This is necessary because EU::MM installs files
+ # as either 0444 or 0555, and we want the owner
+ # of Koha's files to have write permission by default.
+ foreach my $key (sort keys %$target_directories) {
+ $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ }
+ elsif ($^O eq 'MSWin32' ) { # On Win32, the install probably needs to be done under the user account koha will be running as...
+ # We can attempt some creative things with command line utils such as CACLS which allows permission
+ # management from Win32 cmd.exe, but permissions really only apply to NTFS.
+ foreach my $key (sort keys %$target_directories) {
+ $install .= qq(
+KOHA_INST_$key = blib/$key
+KOHA_DEST_$key = $target_directories->{$key}
+) unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ $install .= qq(
+install :: all install_koha warn_koha_env_vars
+\t\$(NOECHO) \$(NOOP)
+);
+ $install .= "install_koha ::\n";
+ $install .= "\t\$(MOD_INSTALL) \\\n";
+ foreach my $key (sort keys %$target_directories) {
+ $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};