Cleaned up recursion routine a bit
[koha-equinox.git] / Makefile.PL
1 # Copyright 2007 MJ Ray
2 #
3 # This file is part of Koha.
4 #
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
9 #
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
17 #
18 # Current maintainer MJR http://mjr.towers.org.uk/
19 # See http://www.koha.org/wiki/?page=KohaInstaller
20 #
21
22 use ExtUtils::MakeMaker;
23 use POSIX;
24
25 die "perl 5.6.1 or later required" unless ($] >= 5.006001);
26
27 # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
28
29 my $dirtree = hashdir('.');
30 my %result = ();
31
32 =head1 NAME
33
34 Makefile.PL - Koha packager and installer
35
36 =head1 SYNOPSIS
37
38 =head2 BASIC INSTALLATION
39
40         perl Makefile.PL
41         make
42         sudo make install
43
44 =head2 PACKAGING RELEASE TARBALLS
45
46         make manifest tardist
47         make manifest zipdist
48
49 =head2 CLEANING UP
50
51         make clean
52
53 =head1 DESCRIPTION
54
55 This is a Packager and installer that uses
56 ExtUtils::MakeMaker, which is fairly common
57 on perl systems.
58 As well as building tar or zip files
59 and installing with the above commands,
60 it allows us to check pre-requisites
61 and generate configuration files.
62
63 =head1 VARIABLES
64
65 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
66
67 Basic metadata about this software.
68
69 =head2 NO_META
70
71 Suppress generation of META.yml file.
72
73 =head2 PREREQ_PM
74
75 Hash of perl modules and versions required.
76
77 =head2 PM
78
79 Hash of file mappings
80
81 =head2 CONFIGURE
82
83 Maybe use prompt() here in future to get configuration values 
84 interactively at installation time.
85
86 =head2 PL_FILES
87
88 This is a hash of PL scripts to run after installation and
89 the files to ask them to generate.
90 Maybe use the values from CONFIGURE
91 to generate initial configuration files in future.
92
93 =cut
94
95 my $marc_value;
96 my $lang_value;
97
98
99 while ($marc_value ne 'marc21' && $marc_value ne 'unimarc'){
100    my $message= "Chose your flavour of MARC, unimarc or marc21 [marc21]";
101    $marc_value=prompt($message) || 'marc21';
102 }
103 while ($lang_value ne 'en' && $lang_value ne 'fr'){
104    my $message= "Choose your language, en or fr [en]";
105    $lang_value=prompt($message) || 'en';
106 }
107
108 WriteMakefile(
109
110     NAME => 'koha',
111     #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
112     VERSION_FROM => 'C4/Context.pm',
113     ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
114     AUTHOR => 'Koha Developers <koha-devel@nongnu.org>',
115     NO_META => 1,
116     PREREQ_PM => {
117 'CGI' => 3.15,
118 'CGI::Carp' => 1.29,
119 'CGI::Session' => '4.10',
120 'Class::Factory::Util' => 1.7,
121 'Class::Accessor' => 0.30,
122 'DBD::mysql' => 3.0008,
123 'DBI' => 1.53,
124 'Data::Dumper' => 2.121_08,
125 'Date::Calc' => 5.4,
126 'Date::Manip' => 5.44,
127 'Digest::MD5' => 2.36,
128 'File::Temp' => 0.16,
129 'GD::Barcode::UPCE' => 1.1,
130 'Getopt::Long' => 2.35,
131 'Getopt::Std' => 1.05,
132 'HTML::Template::Pro' => 0.65,
133 'HTTP::Cookies' => 1.39,
134 'HTTP::Request::Common' => 1.26,
135 'LWP::Simple' => 1.41,
136 'LWP::UserAgent' => 2.033,
137 'Lingua::Stem' => 0.82,
138 'List::Util' => 1.18,
139 'Locale::Language' => 2.07,
140 'MARC::Charset' => 0.98,
141 'MARC::Crosswalk::DublinCore' => 0.03,
142 'MARC::File::XML' => 0.88,
143 'MARC::Record' => 2.00,
144 'MIME::Base64' => 3.07,
145 'MIME::QuotedPrint' => 3.07,
146 'Mail::Sendmail' => 0.79,
147 'PDF::API2' => 2.000,
148 'PDF::API2::Page' => 2.000,
149 'PDF::API2::Util' => 2.000,
150 'PDF::Reuse' => 0.33,
151 'PDF::Reuse::Barcode' => 0.05,
152 'POSIX' => 1.09,
153 'Schedule::At' => 1.06,
154 'Term::ANSIColor' => 1.10,
155 'Test' => 1.25,
156 'Test::Harness' => 2.56,
157 'Test::More' => 0.62,
158 'Text::CSV' => 0.01,
159 'Text::CSV_XS' => 0.32,
160 'Text::Wrap' => 2005.082401,
161 'Time::HiRes' => 1.86,
162 'Time::localtime' => 1.02,
163 'Unicode::Normalize' => 0.32,
164 'XML::Dumper' => 0.81,
165 'XML::LibXML' => 1.59,
166 'XML::SAX::ParserFactory' => 1.01,
167 'XML::Simple' => 2.14,
168 'XML::RSS' => 1.31,
169 'ZOOM' => 1.16,
170         },
171
172         # File tree mapping
173 #       PM => map_tree(),
174         PM => unhashdir($dirtree),
175
176         # disable tests
177         'test' => {TESTS => 't/dummy.t'},
178
179 #   CONFIGURE => sub {
180 #     # Ask for options with prompt($question,$default) calls here?
181 #     return { macro => { 'export TEST' => '755' } }
182 #     },
183
184    PL_FILES => { # generator => target(s)
185       'rewrite-config.PL' => [
186          '$(PREFIX)/share/koha/etc/koha-conf.xml',
187          '$(PREFIX)/share/koha/etc/koha-httpd.conf',
188          '$(PREFIX)/share/koha/etc/zebradb/etc/passwd',
189          '$(PREFIX)/share/koha/etc/zebradb/zebra-biblios.cfg',
190          '$(PREFIX)/share/koha/etc/zebradb/zebra-authorities.cfg'
191          ]
192    }
193 #     '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'],
194 #     'misc/koha.conf.PL' => '$(INST_LIBDIR)/../etc/koha.conf',
195 #     'misc/apache-koha.conf.PL' => '$(INST_LIBDIR)/../etc/apache-koha.conf',
196 #     'misc/koha.sql.PL' => '$(INST_LIBDIR)/intranet/scripts/koha.sql',
197 #     'z3950/z3950-daemon-options.PL' => '$(INST_LIBDIR)/intranet/scripts/z3950daemon/z3950-daemon-options',
198 #     # fake target to check permissions
199 #     'misc/chmod.PL' => '$(INST_LIBDIR)/fake-target'
200 #     }
201    # need to set ownerships
202    # need to load koha.sql
203    # need to link koha-httpd.conf
204    # need to start z3950-daemon
205 );
206
207 =head1 FUNCTIONS
208
209 =head2 hashdir
210
211 This function recurses through the directory structure and builds
212 a hash of hashes containing the structure with arrays holding filenames.
213 This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
214
215 =cut
216
217 sub hashdir{
218     my $dir = shift;
219     opendir my $dh, $dir or die $!;
220     my $tree = {}->{$dir} = {};
221     while( my $file = readdir($dh) ) {
222         next if $file =~ m/^\.{1,2}/;
223         my $path = $dir .'/' . $file;
224         $tree->{$file} = hashdir($path), next if -d $path;
225         push @{$tree->{'.'}}, $file;
226     }
227     return $tree;
228 }
229
230 =head2 unhashdir
231
232 This function unhashes the hash of hashes generated by hashdir().
233 This directory unhashing routine is the personal work of Chris Nighswonger (fbcit).
234 Modified here to build koha makefile. It lists all files and where to install each one.
235 It then returns a hash reference suitable for the PM variable above.
236
237 =cut
238
239 sub unhashdir{
240         my $dirhash = shift;
241         my $dirlevel = shift;
242         my $toplevel = $dirlevel;
243         for my $k1 ( sort keys %$dirhash ) {
244                 if ($k1 ne '.' && $k1 ne '') {
245                         $dirlevel = ( $dirlevel ? $dirlevel . '/' . $k1 : $k1 );
246                         &unhashdir($dirhash->{ $k1 }, $dirlevel);
247                         $dirlevel = $toplevel;
248                 }
249                 elsif ( $k1 eq '.' ) {
250                         foreach $file ( @{$dirhash->{ $k1 }} ) {
251 #                               TODO: There are some hacks here that may be able to be improved... -fbcit
252                                 if ( $file =~ /^./ ) { next; } # skip hidden files and directories.
253
254                                 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.
255
256                                 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/
257
258                                 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/
259
260                                 elsif ( $dirlevel =~ /(misc|rss)/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # misc & rss are copied to koha,
261
262 #                               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,
263
264                                 elsif ( $file !~ /\.pl/ && $dirlevel =~ /etc/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(PREFIX)/share/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # Misc etc to koha/etc
265
266                                 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"; 
267
268                         }
269                         next;
270                 }
271         }
272         return \%result;
273 }
274
275 __END__
276
277
278 =head1 SEE ALSO
279
280 ExtUtils::MakeMaker(3)
281
282 =head1 AUTHORS
283
284 MJ Ray mjr at phonecoop.coop
285
286 =cut
287