Cleaned up recursion routine a bit

Signed-off-by: Galen Charlton <galen.charlton@liblime.com>
This commit is contained in:
Chris Nighswonger 2007-12-03 16:11:35 -05:00 committed by Galen Charlton
parent 5baba50aed
commit faaf13a6b3

140
Makefile.PL Executable file → Normal file
View file

@ -18,12 +18,17 @@
# Current maintainer MJR http://mjr.towers.org.uk/
# See http://www.koha.org/wiki/?page=KohaInstaller
#
# 2007-11-05 Corrected CGI copy to include entire 'installer' subdir structure. -fbcit
use ExtUtils::MakeMaker;
use POSIX;
die "perl 5.6.1 or later required" unless ($] >= 5.006001);
# Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
my $dirtree = hashdir('.');
my %result = ();
=head1 NAME
Makefile.PL - Koha packager and installer
@ -33,7 +38,6 @@ Makefile.PL - Koha packager and installer
=head2 BASIC INSTALLATION
perl Makefile.PL
or perl Makefile.PL INSTALL_BASE=/path/to/your/home/dir MARCFLAVOUR=marc21 LANGUAGE=en
make
sudo make install
@ -48,7 +52,7 @@ Makefile.PL - Koha packager and installer
=head1 DESCRIPTION
This is a packager and installer that uses
This is a Packager and installer that uses
ExtUtils::MakeMaker, which is fairly common
on perl systems.
As well as building tar or zip files
@ -105,13 +109,11 @@ WriteMakefile(
NAME => 'koha',
#VERSION => strftime('2.9.%Y%m%d%H',gmtime),
VERSION_FROM => 'kohaversion.pl',
VERSION_FROM => 'C4/Context.pm',
ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
AUTHOR => 'Koha Developers <koha-devel@nongnu.org>',
NO_META => 1,
INSTALLSITEBIN => '$(INSTALL_BASE)/lib',
PREREQ_PM => {
'Biblio::EndnoteStyle' => 0.05,
'CGI' => 3.15,
'CGI::Carp' => 1.29,
'CGI::Session' => '4.10',
@ -139,11 +141,9 @@ WriteMakefile(
'MARC::Crosswalk::DublinCore' => 0.03,
'MARC::File::XML' => 0.88,
'MARC::Record' => 2.00,
'MARC::Crosswalk::DublinCore' => 0.02,
'MIME::Base64' => 3.07,
'MIME::QuotedPrint' => 3.07,
'Mail::Sendmail' => 0.79,
'Net::Z3950::ZOOM' => 1.16,
'PDF::API2' => 2.000,
'PDF::API2::Page' => 2.000,
'PDF::API2::Util' => 2.000,
@ -163,14 +163,15 @@ WriteMakefile(
'Unicode::Normalize' => 0.32,
'XML::Dumper' => 0.81,
'XML::LibXML' => 1.59,
'XML::LibXSLT' => 1.63,
'XML::SAX::ParserFactory' => 1.01,
'XML::Simple' => 2.14,
'XML::RSS' => 1.31,
'ZOOM' => 1.16,
},
# File tree mapping
PM => map_tree(),
# PM => map_tree(),
PM => unhashdir($dirtree),
# disable tests
'test' => {TESTS => 't/dummy.t'},
@ -182,11 +183,11 @@ WriteMakefile(
PL_FILES => { # generator => target(s)
'rewrite-config.PL' => [
'$(INST_LIBDIR)/etc/koha-conf.xml',
'$(INST_LIBDIR)/etc/koha-httpd.conf',
'$(INST_LIBDIR)/etc/zebradb/etc/passwd',
'$(INST_LIBDIR)/etc/zebradb/zebra-biblios.cfg',
'$(INST_LIBDIR)/etc/zebradb/zebra-authorities.cfg'
'$(PREFIX)/share/koha/etc/koha-conf.xml',
'$(PREFIX)/share/koha/etc/koha-httpd.conf',
'$(PREFIX)/share/koha/etc/zebradb/etc/passwd',
'$(PREFIX)/share/koha/etc/zebradb/zebra-biblios.cfg',
'$(PREFIX)/share/koha/etc/zebradb/zebra-authorities.cfg'
]
}
# 'opac/getfromintranet.PL' => ['$(INST_LIBDIR)/opac/cgi-bin/detail.pl','$(INST_LIBDIR)/opac/cgi-bin/moredetail.pl','$(INST_LIBDIR)/opac/cgi-bin/search.pl','$(INST_LIBDIR)/opac/cgi-bin/subjectsearch.pl','$(INST_LIBDIR)/opac/cgi-bin/logout.pl'],
@ -197,8 +198,6 @@ WriteMakefile(
# # fake target to check permissions
# 'misc/chmod.PL' => '$(INST_LIBDIR)/fake-target'
# }
# need to set ownerships
# need to load koha.sql
# need to link koha-httpd.conf
@ -207,78 +206,69 @@ WriteMakefile(
=head1 FUNCTIONS
=head2 map_tree
=head2 hashdir
This function lists all files and where to install each one.
It returns a hash reference suitable for the PM variable above.
This function recurses through the directory structure and builds
a hash of hashes containing the structure with arrays holding filenames.
This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
=cut
sub map_tree {
my %result => ();
sub hashdir{
my $dir = shift;
opendir my $dh, $dir or die $!;
my $tree = {}->{$dir} = {};
while( my $file = readdir($dh) ) {
next if $file =~ m/^\.{1,2}/;
my $path = $dir .'/' . $file;
$tree->{$file} = hashdir($path), next if -d $path;
push @{$tree->{'.'}}, $file;
}
return $tree;
}
=pod
=head2 unhashdir
C4/*.pm is copied to perl's lib namespace.
This function unhashes the hash of hashes generated by hashdir().
This directory unhashing routine is the personal work of Chris Nighswonger (fbcit).
Modified here to build koha makefile. It lists all files and where to install each one.
It then returns a hash reference suitable for the PM variable above.
=cut
foreach my $src (glob("C4/*.pm")) {
$result{$src} = '$(INST_LIBDIR)/'.$src;
sub unhashdir{
my $dirhash = shift;
my $dirlevel = shift;
my $toplevel = $dirlevel;
for my $k1 ( sort keys %$dirhash ) {
if ($k1 ne '.' && $k1 ne '') {
$dirlevel = ( $dirlevel ? $dirlevel . '/' . $k1 : $k1 );
&unhashdir($dirhash->{ $k1 }, $dirlevel);
$dirlevel = $toplevel;
}
elsif ( $k1 eq '.' ) {
foreach $file ( @{$dirhash->{ $k1 }} ) {
# TODO: There are some hacks here that may be able to be improved... -fbcit
if ( $file =~ /^./ ) { next; } # skip hidden files and directories.
=pod
elsif ( $file =~ /\.pm/ && $dirlevel =~ /C4/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # C4/*.pm is copied to perl's lib namespace.
CGIs are copied to $(INSTALL_BASE)/lib/cgi-bin/koha/
and other scripts to koha/
elsif ( $dirlevel !~ /koha-tmpl/ && $dirlevel =~ /(installer|errors)/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(PREFIX)/lib/cgi-bin/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # error templates are copied to $(PREFIX)/lib/cgi-bin/koha/
elsif ( $dirlevel =~ /koha-tmpl/ && $dirlevel !~ /errors/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/koha/templates/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # error templates are copied to $(INST_LIBDIR)/koha/templates/
elsif ( $dirlevel =~ /(misc|rss)/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # misc & rss are copied to koha,
# elsif ( $dirlevel =~ /(intranet-tmpl|opac-tmpl)/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/koha/templates/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # Templates are copied to koha/templates,
elsif ( $file !~ /\.pl/ && $dirlevel =~ /etc/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(PREFIX)/share/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # Misc etc to koha/etc
elsif ( $file =~ /\.pl/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(PREFIX)/lib/cgi-bin/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # CGIs are copied to $(PREFIX)/lib/cgi-bin/koha/ print $result{ ($dirlevel ? $dirlevel . '/' . $file : $file)},"\n\n";
=cut
foreach my $src ("mainpage.pl","help.pl","kohaversion.pl",glob("*/*.pl"),glob("installer/*"),glob("installer/*/*/*/*"),glob("installer/*/*/*/*/*"),glob("*/*/*.pl"),glob("*/*/*/*.pl"),glob("installer/*/*/*.sql"))
{
if (-f $src) {
if ($src =~ /(misc|updater|rss)\//) {
$result{$src} = '$(INST_BIN)/koha/'.$src;
}
elsif ($src =~ /opac\//){
$result{$src} = '$(INST_BIN)/cgi-bin/'.$src;
} else {
$result{$src} = '$(INST_BIN)/cgi-bin/koha/'.$src;
next;
}
}
}
=pod
Templates are copied to koha/templates,
=cut
foreach my $src (glob("koha-tmpl/*"),glob("koha-tmpl/intranet-tmpl/*/*/*"),glob("koha-tmpl/intranet-tmpl/*/*/*/*"),glob("koha-tmpl/intranet-tmpl/*/*/*/*/*"),glob("koha-tmpl/opac-tmpl/*/*/*"),glob("koha-tmpl/opac-tmpl/*/*/*/*"),glob("koha-tmpl/opac-tmpl/*/*/*/*/*")) {
=pod
excluding non-files and whitespace in filenames.
=cut
if ((-f $src) && ($src !~ /(\s)/)) {
$result{$src} = '$(INST_LIBDIR)/koha/templates/'.$src;
}
}
=pod
etc files are copied to /usr/share/koha/etc/
=cut
# Misc etc to koha/etc
foreach my $src (glob("etc/zebradb/*/*/*"),glob("etc/zebradb/*/*"),glob("etc/zebradb/*"),glob("etc/*")) {
if (-f $src) {
$result{$src} = '$(INST_LIBDIR)/'.$src;
}
}
# set up zebra with the appropriate language and marc config
$result{"etc/zebradb/lang_defs/sort-string-$lang_value.chr"} = '$(INST_LIBDIR)/etc/zebradb/etc/sort-string-utf.chr';
$result{"etc/zebradb/marc_defs/biblios-$marc_value.abs"} = '$(INST_LIBDIR)/etc/zebradb/biblios/etc/record.abs';
$result{"etc/zebradb/marc_defs/authorities-$marc_value.abs"} = '$(INST_LIBDIR)/etc/zebradb/authorities/etc/record.abs';
return \%result;
}
@ -289,7 +279,7 @@ __END__
ExtUtils::MakeMaker(3)
=head1 AUTHOR
=head1 AUTHORS
MJ Ray mjr at phonecoop.coop