Escaping the $title in the regexes with \Q and \E to handle nested quantifiers, cheer...
[koha.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 strict;
23 use warnings;
24 use ExtUtils::MakeMaker;
25 use POSIX;
26 use File::Spec;
27
28 my $DEBUG = 0;
29 die "perl 5.6.1 or later required" unless ($] >= 5.006001);
30
31 # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
32
33 my $dirtree = hashdir('.');
34 my %result = ();
35
36 =head1 NAME
37
38 Makefile.PL - Koha packager and installer
39
40 =head1 SYNOPSIS
41
42 =head2 BASIC INSTALLATION
43
44         perl Makefile.PL
45         make
46         sudo make install
47
48 =head2 PACKAGING RELEASE TARBALLS
49
50         make manifest tardist
51         make manifest zipdist
52
53 =head2 CLEANING UP
54
55         make clean
56
57 =head1 DESCRIPTION
58
59 This is a packager and installer that uses
60 ExtUtils::MakeMaker, which is fairly common
61 on perl systems.
62 As well as building tar or zip files
63 and installing with the above commands,
64 it allows us to check pre-requisites
65 and generate configuration files.
66
67 =head1 VARIABLES
68
69 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
70
71 Basic metadata about this software.
72
73 =head2 NO_META
74
75 Suppress generation of META.yml file.
76
77 =head2 PREREQ_PM
78
79 Hash of perl modules and versions required.
80
81 =head2 PM
82
83 Hash of file mappings
84
85 =head2 PL_FILES
86
87 This is a hash of PL scripts to run after installation and
88 the files to ask them to generate.
89 Maybe use the values from CONFIGURE
90 to generate initial configuration files in future.
91
92 =cut
93
94 =head2 target_map
95
96 This is a hash mapping directories and files in the
97 source tree to installation target directories.  The rules
98 for this mapping are:
99
100 =over 4
101
102 =item If a directory or file is specified, it and its
103 contents will be copied to the installation target directory.
104
105 =item If a subdirectory of a mapped directory is specified,
106 its target overrides the parent's target for that subdirectory.
107
108 =item The value of each map entry may either be a scalar containing 
109 one target or a reference to a hash containing 'target' and 'trimdir'
110 keys.
111
112 =item Any files at the top level of the source tree that are
113 not included in the map will not be installed.
114
115 =item Any directories at the top level of the source tree
116 that are not included in the map will be installed in
117 INTRANET_CGI_DIR.  This is a sensible default given the
118 current organization of the source tree, but (FIXME) it
119 would be better to reorganize the source tree to better
120 match the installation system, to allow adding new directories
121 without having to adjust Makefile.PL each time.  The idea
122 is to make the C<$target_map> hash as minimal as possible.
123
124 =back
125
126 The permitted installation targets are:
127
128 =over 4
129
130 =item INTRANET_CGI_DIR 
131
132 CGI scripts for intranet (staff) interface.
133
134 =item INTRANET_TMPL_DIR
135
136 HTML templates for the intranet interface.
137
138 =item INTRANET_WWW_DIR
139
140 HTML files, images, etc. for DocumentRoot for the intranet interface.
141
142 =item OPAC_CGI_DIR
143
144 CGI scripts for OPAC (public) interface.
145
146 =item OPAC_TMPL_DIR
147
148 HTML templates for the OPAC interface.
149
150 =item OPAC_WWW_DIR
151
152 HTML files, images, etc. for DocumentRoot for the OPAC interface.
153
154 =item PERL_MODULE_DIR
155
156 Perl modules (at present just the C4 modules) that are intimately
157 tied to Koha.  Depending on the installation options, these
158 may or may not be installed one of the standard directories
159 in Perl's default @LIB.
160
161 =item KOHA_CONF_DIR
162
163 Directory for Koha configuration files.
164
165 =item ZEBRA_CONF_DIR
166
167 Directory for Zebra configuration files.
168
169 =item ZEBRA_LOCK_DIR
170
171 Directory for Zebra's lock files.
172
173 =item ZEBRA_DATA_DIR
174
175 Directory for Zebra's data files.
176
177 =item ZEBRA_RUN_DIR
178
179 Directory for Zebra's UNIX-domain sockets.
180
181 =item MISC_DIR
182
183 Directory for for miscellaenous scripts, among other
184 things the translation toolkit and RSS feed tools.
185
186 =item SCRIPT_DIR
187
188 Directory for command-line scripts and daemons.
189
190 =item MAN_DIR
191
192 Directory for man pages created from POD -- will mostly
193 contain information of interest to Koha developers.
194
195 =item DOC_DIR
196
197 Directory for Koha documentation accessed from the 
198 command-line, e.g., READMEs.
199
200 =item LOG_DIR
201
202 Directory for Apache and Zebra logs produced by Koha.
203
204 =item NONE
205
206 This is a dummy target used to explicitly state
207 that a given file or directory is not to be installed.
208 This is used either for parts of the installer itself
209 or for development tools that are not applicable to a
210 production installation.
211
212 =back
213
214 =cut
215
216 my $target_map = {
217   './about.pl'                  => 'INTRANET_CGI_DIR',
218   './acqui'                     => 'INTRANET_CGI_DIR',
219   './admin'                     => 'INTRANET_CGI_DIR',
220   './authorities'               => 'INTRANET_CGI_DIR',
221   './C4'                        => 'PERL_MODULE_DIR',
222   './C4/SIP/t'                  => 'NONE',
223   './C4/SIP/koha_test'          => 'NONE',
224   './C4/tests'                  => 'NONE',
225   './catalogue'                 => 'INTRANET_CGI_DIR',
226   './cataloguing'               => 'INTRANET_CGI_DIR',
227   './changelanguage.pl'         => 'INTRANET_CGI_DIR',
228   './check_sysprefs.pl'         => 'NONE',
229   './circ'                      => 'INTRANET_CGI_DIR',
230   './edithelp.pl'               => 'INTRANET_CGI_DIR',
231   './etc'                       => { target => 'KOHA_CONF_DIR', trimdir => -1 },
232   './etc/zebradb'               => { target => 'ZEBRA_CONF_DIR', trimdir => -1 },
233   './help.pl'                   => 'INTRANET_CGI_DIR', 
234   './installer-CPAN.pl'         => 'NONE',
235   './installer'                 => 'INTRANET_CGI_DIR',
236   './koha-tmpl/errors'          => {target => 'INTRANET_CGI_DIR', trimdir => 2},
237   './koha-tmpl/intranet-tmpl'   => {target => 'INTRANET_TMPL_DIR', trimdir => -1},
238   './koha-tmpl/opac-tmpl'       => {target => 'OPAC_TMPL_DIR', trimdir => -1},
239   './kohaversion.pl'            => 'INTRANET_CGI_DIR', 
240   './labels'                    => 'INTRANET_CGI_DIR',
241   './mainpage.pl'               => 'INTRANET_CGI_DIR',
242   './Makefile.PL'               => 'NONE',
243   './MANIFEST.SKIP'             => 'NONE',
244   './members'                   => 'INTRANET_CGI_DIR',
245   './misc'                      => { target => 'SCRIPT_DIR', trimdir => -1 }, 
246   './misc/bin'                  => { target => 'SCRIPT_DIR', trimdir => -1 }, 
247   './misc/release_notes'        => { target => 'DOC_DIR', trimdir => 2 },
248   './misc/translator'           => { target => 'MISC_DIR', trimdir => 2 }, 
249   './misc/installer_devel_notes' => 'NONE',
250   './opac'                      => 'OPAC_CGI_DIR',
251   './README.txt'                => 'NONE',
252   './reports'                   => 'INTRANET_CGI_DIR',
253   './reserve'                   => 'INTRANET_CGI_DIR',
254   './reviews'                   => 'INTRANET_CGI_DIR',
255   './rewrite-config.PL'         => 'NONE',
256   './reviews'                   => 'INTRANET_CGI_DIR',
257   './rss'                       => 'MISC_DIR', 
258   './serials'                   => 'INTRANET_CGI_DIR',
259   './skel'                      => 'NONE',
260   './skel/var/log/koha'         => { target => 'LOG_DIR', trimdir => -1 },
261   './skel/var/run/koha/zebradb' => { target => 'ZEBRA_RUN_DIR', trimdir => -1 },
262   './skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
263   './skel/var/lib/koha/zebradb/authorities/key'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
264   './skel/var/lib/koha/zebradb/authorities/register'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
265   './skel/var/lib/koha/zebradb/authorities/shadow'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
266   './skel/var/lib/koha/zebradb/authorities/tmp'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
267   './skel/var/lock/koha/zebradb/biblios' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
268   './skel/var/lib/koha/zebradb/biblios/key'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
269   './skel/var/lib/koha/zebradb/biblios/register'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
270   './skel/var/lib/koha/zebradb/biblios/shadow'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
271   './skel/var/lib/koha/zebradb/biblios/tmp'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
272   './sms'                       => 'INTRANET_CGI_DIR',
273   './suggestion'                => 'INTRANET_CGI_DIR',
274   './svc'                       => 'INTRANET_CGI_DIR',
275   './t'                         => 'NONE',
276   './tmp'                       => 'NONE', # FIXME need to determine whether 
277                                            # Koha generates any persistent temp files
278                                            # that should go in /var/tmp/koha
279   './tools'                     => 'INTRANET_CGI_DIR',
280   './virtualshelves'            => 'INTRANET_CGI_DIR',
281   # ignore files and directories created by the install itself
282   './pm_to_blib'                => 'NONE',
283   './blib'                      => 'NONE',
284 };
285
286 =head1 CONFIGURATION OPTIONS
287
288 The following configuration options are used by the installer.
289
290 =over 4
291
292 =item INSTALL_MODE
293
294 Specifies whether installation will be FHS-compliant (default,
295 assumes user has root), put everything under
296 a single directory (for users installing on a web host
297 that allows CGI scripts and a MySQL database but not root 
298 access), or development (for a developer who wants to run
299 Koha from a git clone with no fuss).
300
301 =item INSTALL_BASE
302
303 Directory under which most components will go.  Default
304 value will vary depending on INSTALL_MODE.
305
306 =item DB_TYPE
307
308 Type of DBMS (e.g., mysql or Pg).
309
310 =item DB_HOST
311
312 Name of DBMS server.
313
314 =item DB_PORT
315
316 Port that DBMS server is listening on.
317
318 =item DB_NAME
319
320 Name of the DBMS database for Koha.
321
322 =item DB_USER
323
324 Name of DBMS user account for Koha's database.
325
326 =item DB_PASS
327
328 Pasword of DMBS user account for Koha's database.
329
330 =item INSTALL_ZEBRA
331
332 Whether to install Zebra configuration files and data
333 directories.
334
335 =item ZEBRA_MARC_FORMAT
336
337 Specifies format of MARC records to be indexed by Zebra.
338
339 =item ZEBRA_LANGUAGE
340
341 Specifies primary language of records that will be 
342 indexed by Zebra.
343
344 =item ZEBRA_USER
345
346 Internal Zebra user account for the index.
347
348 =item ZEBRA_PASS
349
350 Internal Zebra user account's password.
351
352 =item KOHA_USER
353
354 System user account that will own Koha's files.
355
356 =item KOHA_GROUP
357
358 System group that will own Koha's files.
359
360 =back
361
362 =cut
363
364 # default configuration options
365 my %config_defaults = (
366   'DB_TYPE'           => 'mysql',
367   'DB_HOST'           => 'localhost',
368   'DB_NAME'           => 'koha',    
369   'DB_USER'           => 'kohaadmin',
370   'DB_PASS'           => 'katikoan',
371   'INSTALL_ZEBRA'     => 'yes',
372   'INSTALL_SRU'       => 'yes',
373   'ZEBRA_MARC_FORMAT' => 'marc21',
374   'ZEBRA_LANGUAGE'    => 'en',
375   'ZEBRA_USER'        => 'kohauser',
376   'ZEBRA_PASS'        => 'zebrastripes',
377   'ZEBRA_SRU_HOST'    => 'localhost',
378   'ZEBRA_SRU_BIBLIOS_PORT'    => '9998',
379   'ZEBRA_SRU_AUTHORITIES_PORT'    => '9999',
380   'KOHA_USER'         => 'koha',
381   'KOHA_GROUP'        => 'koha',
382 );
383
384 # set some default configuratio options based on OS
385 # more conditions need to be added for other OS's
386 # this should probably also incorporate usage of Win32::GetOSName() and/or Win32::GetOSVersion()
387 # to allow for more granular decisions based on which Win32 platform
388
389 warn "Your platform appears to be $^O.\n" if $DEBUG;
390
391 if ( $^O eq 'MSWin32' ) {
392         # Most Unix2Win32 ports seem to poke everything into the Program Files directory
393         # this could be changed to put some files (ie. libraries) into system32, etc.
394         $config_defaults{'INSTALL_MODE'} = 'single';
395         $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha';  # Use 8.3 names to be safe...
396 }
397 elsif ( $^O eq 'cygwin' ) {
398         # Most Unix2Win32 ports seem to poke everything into the Program Files directory
399         # this could be changed to put some files (ie. libraries) into system32, etc.
400         $config_defaults{'INSTALL_MODE'} = 'single';
401         $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha';  # Use 8.3 names to be safe...
402 }
403 else {
404         $config_defaults{'INSTALL_MODE'} = 'standard';
405         $config_defaults{'INSTALL_BASE'} = '/usr/share/koha';
406 }
407
408 # valid values for certain configuration options
409 my %valid_config_values = (
410   'INSTALL_MODE'  => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
411   'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 },
412   'INSTALL_ZEBRA' => { 'yes' => 1, 'no' => 1 },
413   'INSTALL_SRU' => { 'yes' => 1, 'no' => 1 },
414   'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
415   'ZEBRA_LANGUAGE'    => { 'en' => 1, 'fr' => 1 }, # FIXME should generate from contents of distribution
416 );
417
418 my %config = get_configuration(\%config_defaults, \%valid_config_values);
419 my ($target_directories, $skip_directories) = get_target_directories(\%config);
420 display_configuration(\%config, $target_directories);
421 my $file_map = {};
422 get_file_map($target_map, $dirtree, $file_map, $config{'INSTALL_ZEBRA'} eq "yes" ? 1: 0);
423
424 my $pl_files = {
425       'rewrite-config.PL' => [
426          'blib/KOHA_CONF_DIR/koha-conf.xml',
427          'blib/KOHA_CONF_DIR/koha-httpd.conf'
428          ],
429           'fix-perl-path.PL' => [       # this script ensures the correct shebang line for the platform installed on...
430                  'blib'
431                  ]
432 };
433
434 if ($config{'INSTALL_ZEBRA'} eq "yes") {
435     push @{ $pl_files->{'rewrite-config.PL'} }, (
436         'blib/ZEBRA_CONF_DIR/etc/passwd',
437         'blib/ZEBRA_CONF_DIR/zebra-biblios.cfg',
438         'blib/ZEBRA_CONF_DIR/zebra-authorities.cfg',
439         'blib/ZEBRA_CONF_DIR/explain-authorities.xml',
440         'blib/ZEBRA_CONF_DIR/explain-biblios.xml'
441     );
442     if ($config{'INSTALL_MODE'} ne 'dev') {
443         push @{ $pl_files->{'rewrite-config.PL'} }, (
444             'blib/SCRIPT_DIR/koha-zebra-ctl.sh',
445             'blib/SCRIPT_DIR/koha-zebraqueue-ctl.sh',
446         );
447     }
448 }
449
450 if ($config{'INSTALL_MODE'} ne "dev") {
451     push @{ $pl_files->{'rewrite-config.PL'} }, (
452         'blib/PERL_MODULE_DIR/C4/Context.pm',
453         'blib/SCRIPT_DIR/kohalib.pl'
454     );
455 }
456
457 WriteMakefile(
458     NAME => 'koha',
459     #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
460     VERSION_FROM => 'kohaversion.pl',
461     ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
462     AUTHOR => 'Koha Developers <koha-devel@nongnu.org>',
463     NO_META => 1,
464     PREREQ_PM => {
465 # awaiting package maintainer's use of $VERSION
466 #'Algorithm::CheckDigits' => 0.48,
467 #'Algorithm::CheckDigits::M43_001' => 0.48,
468 'Biblio::EndnoteStyle' => 0.05,
469 'CGI' => 3.15,
470 'CGI::Carp' => 1.29,
471 'CGI::Session' => '4.10',
472 'Class::Factory::Util' => 1.6,
473 'Class::Accessor' => 0.30,
474 'DBD::mysql' => 4.004,
475 'DBI' => 1.53,
476 'Data::ICal' => 0.13,
477 'Data::Dumper' => 2.121_08,
478 'Date::Calc' => 5.4,
479 'Date::ICal' => 1.72,
480 'Date::Manip' => 5.44,
481 'Digest::MD5' => 2.36,
482 'File::Temp' => 0.16,
483 'GD::Barcode::UPCE' => 1.1,
484 'Getopt::Long' => 2.35,
485 'Getopt::Std' => 1.05,
486 'HTML::Template::Pro' => 0.65,
487 'HTTP::Cookies' => 1.39,
488 'HTTP::Request::Common' => 1.26,
489 'LWP::Simple' => 1.41,
490 'LWP::UserAgent' => 2.033,
491 'Lingua::Stem' => 0.82,
492 'List::Util' => 1.18,
493 'List::MoreUtils' => 0.21,
494 'Locale::Language' => 2.07,
495 'MARC::Charset' => 0.98,
496 'MARC::Crosswalk::DublinCore' => 0.02,
497 'MARC::File::XML' => 0.88,
498 'MARC::Record' => 2.00,
499 'MIME::Base64' => 3.07,
500 'MIME::QuotedPrint' => 3.07,
501 'Mail::Sendmail' => 0.79,
502 'Net::LDAP' => 0.33,
503 'Net::LDAP::Filter' => 0.14,
504 'Net::Z3950::ZOOM' => 1.16,
505 'PDF::API2' => 2.000,
506 'PDF::API2::Page' => 2.000,
507 'PDF::API2::Util' => 2.000,
508 'PDF::Reuse' => 0.33,
509 'PDF::Reuse::Barcode' => 0.05,
510 'POE' => 0.9999,
511 'POSIX' => 1.09,
512 'Schedule::At' => 1.06,
513 'Term::ANSIColor' => 1.10,
514 'Test' => 1.25,
515 'Test::Harness' => 2.56,
516 'Test::More' => 0.62,
517 'Text::CSV' => 0.01,
518 'Text::CSV_XS' => 0.32,
519 'Text::Wrap' => 2005.082401,
520 'Time::HiRes' => 1.86,
521 'Time::localtime' => 1.02,
522 'Unicode::Normalize' => 0.32,
523 'XML::Dumper' => 0.81,
524 'XML::LibXML' => 1.59,
525 'XML::LibXSLT' => 1.59,
526 'XML::SAX::ParserFactory' => 1.01,
527 'XML::Simple' => 2.14,
528 'XML::RSS' => 1.31,
529 'YAML::Syck' => 0.71,
530         },
531
532         # File tree mapping
533         PM => $file_map,
534
535     # Man pages generated from POD
536     INSTALLMAN1DIR => File::Spec->catdir($target_directories->{'MAN_DIR'}, 'man1'),
537     INSTALLMAN3DIR => File::Spec->catdir($target_directories->{'MAN_DIR'}, 'man3'),
538
539     PL_FILES => $pl_files,
540
541 );
542
543 =head1 FUNCTIONS
544
545 =head2 hashdir
546
547 This function recurses through the directory structure and builds
548 a hash of hashes containing the structure with arrays holding filenames.
549 This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
550
551 =cut
552
553 sub hashdir{
554     my $dir = shift;
555     opendir my $dh, $dir or die $!;
556     my $tree = {}->{$dir} = {};
557     while( my $file = readdir($dh) ) {
558         next if $file =~ m/^\.{1,2}/ and $file !~ /^\.htaccess/; # .htaccess is a special case
559         my $path = $dir .'/' . $file;
560         $tree->{$file} = hashdir($path), next if -d $path;
561         push @{$tree->{'.'}}, $file;
562     }
563     return $tree;
564 }
565
566 =head2 get_file_map 
567
568 This function combines the target_map and file hash to
569 map each source file to its destination relative to
570 the set of installation targets.
571
572 Output will be a hash mapping from each source file
573 to its destination value, like this:
574
575 'mainpage.pl' => '$(INTRANET_CGI_DIR)/mainpage.pl'
576
577 =cut
578
579 sub get_file_map {
580     my $target_map = shift;
581     my $dirtree = shift;
582     my $file_map = shift;
583     my $install_zebra = shift;
584     my $curr_path = @_ ? shift : ['.'];
585
586     # Traverse the directory tree.
587     # For each file or directory, identify the
588     # most specific match in the target_map
589     foreach my $dir (sort keys %{ $dirtree }) {
590         if ($dir eq '.') {
591             # deal with files in directory
592             foreach my $file (sort @{ $dirtree->{$dir} }) {
593                 my $targetdir = undef;
594                 my $matchlevel = undef;
595                 # first, see if there is a match on this specific
596                 # file in the target map
597                 my $filepath = join("/", @$curr_path, $file);
598                 if (exists $target_map->{$filepath}) {
599                     $targetdir = $target_map->{$filepath};
600                     $matchlevel = scalar(@$curr_path) + 1;
601                 } else {
602                     # no match on the specific file; look for
603                     # a directory match
604                     for (my $i = scalar(@$curr_path) - 1; $i >= 0; $i--)  {
605                         my $dirpath = join("/", @$curr_path[0..$i]);
606                         if (exists $target_map->{$dirpath}) {
607                             $targetdir = $target_map->{$dirpath};
608                             $matchlevel = $i + 1;
609                             last;
610                         }
611                     }
612                 }
613                 if (defined $targetdir) {
614                      _add_to_file_map($file_map, $targetdir, $curr_path, $file, $matchlevel, $install_zebra);
615                 } else {
616                     my $path = join("/", @$curr_path);
617                     print "failed to map: $path/$file\n" if $DEBUG;
618                 }
619             }
620         } else {
621             # dealing with subdirectory
622             push @$curr_path, $dir;
623             get_file_map($target_map, $dirtree->{$dir}, $file_map, $install_zebra, $curr_path);
624             pop @$curr_path;
625         }
626     }
627 }
628
629 sub _add_to_file_map {
630     my $file_map = shift;
631     my $targetdir = shift;
632     my $curr_path = shift;
633     my $file = shift;
634     my $matchlevel = shift;
635     my $install_zebra = shift;
636     my $dest_path = @_ ? shift : $curr_path;
637
638     # The target can be one of the following:
639     # 1. scalar representing target symbol
640     # 2. hash ref containing target and trimdir keys
641     #
642     # Consequently, this routine traverses this structure,
643     # calling itself recursively, until it deals with
644     # all of the scalar target symbols.
645     if (ref $targetdir eq 'HASH') {
646         my $subtarget = $targetdir->{target};
647         if (exists $targetdir->{trimdir}) {
648             # if we get here, we've specified that
649             # rather than installing the file to
650             # $(TARGET)/matching/dirs/subdirs/file,
651             # we want to install it to
652             # $(TARGET)/subdirs/file
653             #
654             # Note that this the only place where
655             # $matchlevel is used.
656             my @new_dest_path = @$dest_path;
657             if ($targetdir->{trimdir} == -1)  {
658                 splice @new_dest_path, 0, $matchlevel;
659             } else {
660                 splice @new_dest_path, 0, $targetdir->{trimdir};
661             }
662             _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra, \@new_dest_path);
663         } else {
664             # actually getting here means that the
665             # target was unnecessarily listed
666             # as a hash, but we'll forgive that
667             _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra);
668         }
669     } elsif ($targetdir ne 'NONE' and $targetdir ne '') {
670         my $source = File::Spec->catfile(@$curr_path, $file);
671         my $destination = File::Spec->catfile('blib', $targetdir, @$dest_path, $file);
672         #print "$source => $destination\n"; # DEBUG
673         # quote spaces in file names
674         # FIXME: this is of questionable portability and
675         # probably depends on user's make recognizing this
676         # quoting syntax -- probably better to remove
677         # spaces and shell metacharacters from all file names
678         $source =~ s/ /\\ /g;
679         $destination =~ s/ /\\ /g;
680       
681         $file_map->{$source} = $destination unless (!$install_zebra and $targetdir =~ /ZEBRA/);
682     }
683 }
684
685 =head2 get_configuration_options
686
687 This prompts the user for various configuration options.
688
689 =cut
690
691 sub get_configuration {
692   my $defaults = shift;
693   my $valid_values = shift;
694   my %config = ();
695
696   my $msg = q(
697 By default, Koha can be installed in one of three ways:
698
699 standard: Install files in conformance with the Filesystem
700           Hierarchy Standard (FHS).  This is the default mode
701           and should be used when installing a production
702           Koha system.  On Unix systems, root access is 
703           needed to complete a standard installation.
704
705 single:   Install files under a single directory.  This option
706           is useful for installing Koha without root access, e.g.,
707           on a web host that allows CGI scripts and MySQL databases
708           but requires the user to keep all files under the user's
709           HOME directory.
710
711 dev:      Create a set of symbolic links and configuration files to
712           allow Koha to run directly from the source distribution.
713           This mode is useful for developers who want to run
714           Koha from a git clone.
715
716 Installation mode);
717     $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
718     $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values);
719
720     # set message and default value for INSTALL_BASE
721     # depending on value of INSTALL_MODE
722     my $install_base_default = $defaults->{'INSTALL_BASE'};
723     if ($config{'INSTALL_MODE'} eq 'dev') {
724         $msg = q(
725 Please specify the directory in which to install Koha's
726 active configuration files and (if applicable) the
727 Zebra database.  Koha's CGI scripts and templates will
728 be run from the current directory.
729
730 Configuration directory:);
731         # FIXME - home directory portability consideration apply
732         $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev";
733     } elsif ($config{'INSTALL_MODE'} eq 'single') {
734         $msg = "\nPlease specify the directory in which to install Koha";
735         # FIXME -- we're assuming under a 'single' mode install
736         # that user will likely want to install under the home
737         # directory.  This is OK in and of itself, but we should
738         # use File::HomeDir to locate the home directory portably.  
739         # This is deferred for now because File::HomeDir is not yet
740         # core.
741                 # --we must also keep this portable to the major OS's -fbcit
742         $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
743     } else {
744         # must be standard
745         $msg = q(
746 Please specify the directory under which most Koha files 
747 will be installed.
748
749 Note that if you are planning in installing more than 
750 one instance of Koha, you may want to modify the last
751 component of the directory path, which will be used
752 as the package name in the FHS layout.
753
754 Base installation directory);
755     }
756     $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values);
757
758     $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
759         print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
760     if ($config{'INSTALL_MODE'} eq "standard") {
761         $msg = q(
762 Since you are using the 'standard' install
763 mode, you should run 'make install' as root.
764 However, it is recommended that a non-root
765 user (on Unix and Linux platforms) have 
766 ownership of Koha's files, including the
767 Zebra indexes if applicable.
768
769 Please specify a user account.  This
770 user account does not need to exist
771 right now, but it needs to exist
772 before you run 'make install'.  Please
773 note that for security reasons, this
774 user should not be the same as the user
775 account Apache runs under.
776
777 User account);
778         $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values);
779
780         $msg = q(
781 Please specify the group that should own
782 Koha's files.  As above, this group need
783 not exist right now, but should be created
784 before you run 'make install'.
785
786 Group);
787         $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values);
788     }
789
790     $msg = q(
791 Please specify which database engine you will use
792 to store data in Koha.  The choices are MySQL and
793 PostgreSQL; please note that at the moment
794 PostgreSQL support is highly experimental.
795
796 DBMS to use);
797     $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
798     $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values);
799
800     $msg = q(
801 Please specify the name or address of your 
802 database server.  Note that the database 
803 does not have to exist at this point, it
804 can be created after running 'make install'
805 and before you try using Koha for the first time.
806
807 Database server);
808     $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values);
809
810     $msg = q(
811 Please specify the port used to connect to the
812 DMBS);
813     my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
814     $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values);
815
816     $msg = q(
817 Please specify the name of the database to be
818 used by Koha);
819     $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values);
820
821     $msg = q(
822 Please specify the user that owns the database to be
823 used by Koha);
824     $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values);
825
826     $msg = q(
827 Please specify the password of the user that owns the 
828 database to be used by Koha);
829     $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values);
830
831     $msg = q(
832 Koha can use the Zebra search engine for high-performance
833 searching of bibliographic and authority records.  If you
834 have installed the Zebra software and would like to use it,
835 please answer 'yes' to the following question.  Otherwise, 
836 Koha will default to using its internal search engine.
837
838 Please note that if you choose *NOT* to install Zebra,
839 koha-conf.xml will still contain some references to Zebra
840 settings.  Those references will be ignored by Koha.
841
842 Install the Zebra configuration files?);
843     $msg .= _add_valid_values_disp('INSTALL_ZEBRA', $valid_values);
844     $config{'INSTALL_ZEBRA'} = _get_value('INSTALL_ZEBRA', $msg, $defaults->{'INSTALL_ZEBRA'}, $valid_values);
845
846     if ($config{'INSTALL_ZEBRA'} eq 'yes') {
847         $msg = q(
848 Since you've chosen to use Zebra with Koha,
849 you must specify the primary MARC format of the
850 records to be indexed by Zebra.
851
852 Koha provides Zebra configuration files for MARC 21
853 and UNIMARC.
854
855 MARC format for Zebra indexing);
856         $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
857         $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values);
858         $msg = q(
859 Koha supplies Zebra configuration files tuned for
860 searching either English (en) or French (fr) MARC
861 records.
862
863 Primary language for Zebra indexing);
864         $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
865         $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values);
866
867         $msg = q(
868 Please specify Zebra database user);
869         $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values);
870
871         $msg = q(
872 Please specify the Zebra database password);
873         $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values);
874
875         $msg = q(
876 Since you've chosen to use Zebra, you can enable the SRU/
877 Z39.50 Server if you so choose, but you must specify a
878 few configuration options for it.
879
880 Please note that if you choose *NOT* to configure SRU,
881 koha-conf.xml will still contain some references to SRU
882 settings.  Those references will be ignored by Koha.
883
884 Install the SRU configuration files?);
885         $msg .= _add_valid_values_disp('INSTALL_SRU', $valid_values);
886         $config{'INSTALL_SRU'} = _get_value('INSTALL_SRU', $msg, $defaults->{'INSTALL_SRU'}, $valid_values);
887
888         if ($config{'INSTALL_SRU'} eq 'yes') {
889             $msg = q(
890 Since you've chosen to configure SRU, you must
891 specify the host and port(s) that the SRU
892 Servers (bibliographic and authority) should run on.
893 );
894             $msg = q(
895 SRU Database host?);
896             $config{'ZEBRA_SRU_HOST'} = _get_value('ZEBRA_SRU_HOST', $msg, $defaults->{'ZEBRA_SRU_HOST'}, $valid_values);
897
898             $msg = q(
899 SRU port for bibliographic data?);
900             $config{'ZEBRA_SRU_BIBLIOS_PORT'} = _get_value('ZEBRA_SRU_BIBLIOS_PORT', $msg, $defaults->{'ZEBRA_SRU_BIBLIOS_PORT'}, $valid_values);
901
902             $msg = q(
903 SRU port for authority data?);
904             $config{'ZEBRA_SRU_AUTHORITIES_PORT'} = _get_value('ZEBRA_SRU_AUTHORITIES_PORT', $msg, $defaults->{'ZEBRA_SRU_AUTHORITIES_PORT'}, $valid_values);
905
906         }
907     }
908
909     print "\n\n";
910     return %config;
911 }
912
913 sub _add_valid_values_disp {
914     my $key = shift;
915     my $valid_values = shift;
916    
917     my $disp = "";
918     if (exists $valid_values->{$key}) {
919         $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
920     }
921     return $disp;
922 }
923
924 sub _get_value {
925     my $key = shift;
926     my $msg = shift;
927     my $default = shift;
928     my $valid_values = shift;
929
930     # override default value from environment
931     if (exists $ENV{$key}) {
932         $default = $ENV{$key};
933         $msg .= " (default from environment)";
934     }
935
936     my $val = prompt($msg, $default);
937
938     while (exists $valid_values->{$key} and 
939            $val ne $default and
940            not exists $valid_values->{$key}->{$val}) {
941         my $retry_msg = "Value '$val' is not a valid option.\n";
942         $retry_msg .= "Please enter a value";
943         $retry_msg .= _add_valid_values_disp($key, $valid_values);
944         $val = prompt($retry_msg, $default);
945     }
946     return $val;
947 }
948
949 =head2 get_target_directories 
950
951 Creates a hash mapping from symbols for installation target
952 directories to actual directory paths.
953
954 Also returns a hash indicating targets for which 
955 files need not be copied -- this is used for the 'dev'
956 mode installation, where some files are installed in place.
957
958 =cut
959
960 sub get_target_directories {
961     my $config = shift;
962
963     my $base = $config->{'INSTALL_BASE'};
964     my $mode = $config->{'INSTALL_MODE'};
965
966     # get last component of install base directory
967     # to treat as package name
968     my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
969
970     my @basedir = File::Spec->splitdir($directories);
971
972         # for Win32 we need to prepend the volume to the directory path
973         if ( $^O eq 'MSWin32' ) { shift @basedir; unshift @basedir, $volume; }
974         elsif ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; }   # in a cygwin environment, $volume is returned empty
975
976     my $package = pop @basedir;
977
978
979     my %dirmap = ();
980     my %skipdirs = ();
981     if ($mode eq 'single') {
982         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
983         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
984         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
985         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
986         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
987         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
988         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
989         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
990         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
991         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
992         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
993         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
994         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
995         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
996         $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
997         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
998         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
999     } elsif ($mode eq 'dev') {
1000         my $curdir = File::Spec->rel2abs(File::Spec->curdir());
1001         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
1002         $skipdirs{'INTRANET_CGI_DIR'} = 1;
1003         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
1004         $skipdirs{'INTRANET_TMPL_DIR'} = 1;
1005         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
1006         $skipdirs{'INTRANET_WWW_DIR'} = 1;
1007         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir);
1008         $skipdirs{'OPAC_CGI_DIR'} = 1;
1009         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
1010         $skipdirs{'OPAC_TMPL_DIR'} = 1;
1011         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
1012         $skipdirs{'OPAC_WWW_DIR'} = 1;
1013         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
1014         $skipdirs{'PERL_MODULE_DIR'} = 1;
1015         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
1016         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
1017         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1018         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1019         $skipdirs{'SCRIPT_DIR'} = 1;
1020         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1021         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1022         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1023         $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1024         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1025         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1026     } else {
1027         # mode is standard, i.e., 'fhs'
1028         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
1029         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
1030         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
1031         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
1032         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
1033         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
1034         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
1035         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
1036         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
1037         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1038         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1039         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1040         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1041         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
1042         $dirmap{'LOG_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
1043         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
1044         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
1045     }
1046
1047     _get_env_overrides(\%dirmap);
1048     _get_argv_overrides(\%dirmap);
1049
1050     return \%dirmap, \%skipdirs;
1051 }
1052
1053 sub _get_env_overrides {
1054     my $dirmap = shift;
1055
1056     foreach my $key (keys %$dirmap) {
1057         if (exists $ENV{$key}) {
1058             $dirmap->{$key} = $ENV{$key};
1059             print "Setting $key from environment\n";
1060         }
1061     }
1062 }
1063
1064 sub _get_argv_overrides {
1065     my $dirmap = shift;
1066     
1067     my @new_argv = ();
1068     for (my $i = 0; $i <= $#ARGV; $i++) {
1069         if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
1070             $dirmap->{$1} = $2;
1071         } else {
1072             push @new_argv, $ARGV[$i];
1073         }
1074     }
1075     @ARGV = @new_argv;
1076 }
1077
1078 sub display_configuration {
1079     my $config = shift;
1080     my $dirmap = shift;
1081     print "\n\nKoha will be installed with the following configuration parameters:\n\n";
1082     foreach my $key (sort keys %$config) {
1083         print sprintf("%-25.25s%s\n", $key, $config->{$key});
1084     }
1085
1086     print "\nand in the following directories:\n\n";
1087     foreach my $key (sort keys %$dirmap) {
1088         print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
1089     }
1090     print "\n\nTo change any configuration setting, please run\n";
1091     print "perl Makefile.PL again.  To override one of the target\n";
1092     print "directories, you can do so on the command line like this:\n";
1093     print "\nperl Makefile.PL PERL_MODULE_DIR=/usr/share/perl/5.8\n\n";
1094     print "You can also set different default values for parameters\n";
1095     print "or override directory locations by using environment variables.\n";
1096     print "\nFor example:\n\n";
1097     print "export DB_USER=my_koha\n";
1098     print "perl Makefile.PL\n";
1099     print "\nor\n\n";
1100     print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
1101 }
1102
1103 package MY;
1104
1105 # This will have to be reworked in order to accommodate Win32...
1106
1107 sub test {
1108     my $self = shift;
1109     my $test = $self->SUPER::test(@_);
1110     $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
1111
1112     # set KOHA_CONF 
1113     $test =~ s!\$\(FULLPERLRUN\)!KOHA_CONF=blib/KOHA_CONF_DIR/koha-conf.xml \$(FULLPERLRUN)!g;
1114     return $test;
1115 }
1116
1117 sub install {
1118     my $self = shift;
1119     my $install = ""; 
1120     # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
1121     # This means that we're completely overriding EU::MM's default
1122     # installation and uninstallation targets.
1123
1124 # If installation is on Win32, we need to do permissions different from *nix
1125     if ( $^O =~ /darwin|linux|cygwin/ ) { # this value needs to be verified for each platform and modified accordingly
1126             foreach my $key (sort keys %$target_directories) {
1127                     $install .= qq(
1128 KOHA_INST_$key = blib/$key
1129 KOHA_DEST_$key = $target_directories->{$key}
1130 )                       unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1131                 }
1132                 $install .= qq(
1133 install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
1134 \t\$(NOECHO) \$(NOOP)
1135 );
1136                         $install .= "install_koha ::\n";      
1137                         $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
1138                         foreach my $key (sort keys %$target_directories) {
1139                                 $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n" 
1140                                         unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1141                         }
1142                         $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
1143                         $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
1144
1145                         $install .= "\n";
1146                         $install .= "set_koha_ownership ::\n";
1147                         if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
1148                                 foreach my $key (sort keys %$target_directories) {
1149                                         $install .= "\t\$(NOECHO) chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key)\n"
1150                                                 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1151                                 }
1152                         } else {
1153                                 $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
1154                         }
1155
1156                         $install .= "\n";
1157                         $install .= "set_koha_permissions ::\n";
1158                         # This is necessary because EU::MM installs files
1159                         # as either 0444 or 0555, and we want the owner
1160                         # of Koha's files to have write permission by default.
1161                         foreach my $key (sort keys %$target_directories) {
1162                                 $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
1163                                         unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1164                         }
1165         }
1166         elsif ($^O eq 'MSWin32' ) {     # On Win32, the install probably needs to be done under the user account koha will be running as...
1167                                                                 # We can attempt some creative things with command line utils such as CACLS which allows permission
1168                                                                 # management from Win32 cmd.exe, but permissions really only apply to NTFS.
1169             foreach my $key (sort keys %$target_directories) {
1170                     $install .= qq(
1171 KOHA_INST_$key = blib/$key
1172 KOHA_DEST_$key = $target_directories->{$key}
1173 )                       unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1174                 }
1175                 $install .= qq(
1176 install :: all install_koha warn_koha_env_vars
1177 \t\$(NOECHO) \$(NOOP)
1178 );
1179                 $install .= "install_koha ::\n";
1180                 $install .= "\t\$(MOD_INSTALL) \\\n";
1181                 foreach my $key (sort keys %$target_directories) {
1182                         $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n" 
1183                                 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1184                 }
1185         }
1186         $install .= "\n";
1187
1188     $install .= "warn_koha_env_vars ::\n";
1189     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1190     $install .= "\t\$(NOECHO) \$(ECHO) Koha\\'s files have now been installed. \n";
1191     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1192     $install .= "\t\$(NOECHO) \$(ECHO) In order to use Koha\\'s command-line batch jobs,\n";
1193     $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n";
1194     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1195     $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
1196     $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n";
1197     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1198     $install .= "\t\$(NOECHO) \$(ECHO) If installing on a Win32 platform, be sure to use:\n";
1199     $install .= "\t\$(NOECHO) \$(ECHO) 'dmake -x MAXLINELENGTH=300000'\n";
1200     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1201     $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
1202     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1203
1204     if ($config{'INSTALL_ZEBRA'} eq "yes") {
1205         $install .= _update_zebra_conf_target();
1206     }
1207
1208     return $install;
1209 }
1210
1211 =head 2 _update_zebra_conf_target
1212
1213 Add an installation target for updating
1214 Zebra's configuration files.
1215
1216 =cut
1217
1218 sub _update_zebra_conf_target {
1219
1220     my $target = "\nupdate_zebra_conf ::\n";
1221     $target   .= "\tumask 022; \$(MOD_INSTALL) \\\n";
1222     $target .= "\t\t\$(KOHA_INST_ZEBRA_CONF_DIR) \$(KOHA_DEST_ZEBRA_CONF_DIR) \n";
1223
1224     return $target;
1225 }
1226
1227 sub postamble {
1228     # put directory mappings into Makefile
1229     # so that Make will export as environment
1230     # variables -- this is for the use of
1231     # rewrite-confg.PL
1232
1233     # quote '$' in the two password parameters
1234     my %config = %config;
1235     $config{'DB_PASS'} =~ s/\$/\$\$/g;
1236     if ($config{'INSTALL_ZEBRA'} eq "yes") {
1237         $config{'ZEBRA_PASS'} =~ s/\$/\$\$/g;
1238     }
1239
1240         # Hereagain, we must alter syntax per platform...
1241         if ( $^O eq 'MSWin32' ) {
1242                 # NOTE: it is imperative that there be no whitespaces in ENV=value...
1243                 my $env = join("\n", map { "__${_}__=$target_directories->{$_}" } keys %$target_directories); 
1244                 $env .= "\n\n";
1245                 $env .= join("\n", map { "__${_}__=$config{$_}" } keys %config);
1246                 return "$env\n";
1247         }
1248     else {
1249                 my $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories); 
1250                 $env .= "\n\n";
1251                 $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
1252                 return "$env\n";
1253         }
1254 }
1255
1256
1257 __END__
1258
1259
1260 =head1 SEE ALSO
1261
1262 ExtUtils::MakeMaker(3)
1263
1264 =head1 AUTHORS
1265
1266 MJ Ray mjr at phonecoop.coop
1267 Galen Charlton galen.charlton at liblime.com
1268
1269 =cut
1270 FIXME: deal with .htaccess