installer (part 1): started major changes
[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 ExtUtils::MakeMaker;
23 use POSIX;
24 use File::Spec;
25
26 die "perl 5.6.1 or later required" unless ($] >= 5.006001);
27
28 # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
29
30 my $dirtree = hashdir('.');
31 my %result = ();
32
33 =head1 NAME
34
35 Makefile.PL - Koha packager and installer
36
37 =head1 SYNOPSIS
38
39 =head2 BASIC INSTALLATION
40
41         perl Makefile.PL
42         make
43         sudo make install
44
45 =head2 PACKAGING RELEASE TARBALLS
46
47         make manifest tardist
48         make manifest zipdist
49
50 =head2 CLEANING UP
51
52         make clean
53
54 =head1 DESCRIPTION
55
56 This is a packager and installer that uses
57 ExtUtils::MakeMaker, which is fairly common
58 on perl systems.
59 As well as building tar or zip files
60 and installing with the above commands,
61 it allows us to check pre-requisites
62 and generate configuration files.
63
64 =head1 VARIABLES
65
66 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
67
68 Basic metadata about this software.
69
70 =head2 NO_META
71
72 Suppress generation of META.yml file.
73
74 =head2 PREREQ_PM
75
76 Hash of perl modules and versions required.
77
78 =head2 PM
79
80 Hash of file mappings
81
82 =head2 CONFIGURE
83
84 Maybe use prompt() here in future to get configuration values 
85 interactively at installation time.
86
87 =head2 PL_FILES
88
89 This is a hash of PL scripts to run after installation and
90 the files to ask them to generate.
91 Maybe use the values from CONFIGURE
92 to generate initial configuration files in future.
93
94 =cut
95
96 =head2 target_map
97
98 This is a hash mapping directories and files in the
99 source tree to installation target directories.  The rules
100 for this mapping are:
101
102 =over 4
103
104 =item If a directory or file is specified, it and its
105 contents will be copied to the installation target directory.
106
107 =item If a subdirectory of a mapped directory is specified,
108 its target overrides the parent's target for that subdirectory.
109
110 =item The value of each map entry may either be a scalar containing 
111 one target or a reference to an array of targets, in which case
112 the directory or file is copied to each target.
113
114 =item Any files at the top level of the source tree that are
115 not included in the map will not be installed.
116
117 =item Any directories at the top level of the source tree
118 that are not included in the map will be installed in
119 INTRANET_CGI_DIR.  This is a sensible default given the
120 current organization of the source tree, but (FIXME) it
121 would be better to reorganize the source tree to better
122 match the installation system, to allow adding new directories
123 without having to adjust Makefile.PL each time.  The idea
124 is to make the C<%target_map> hash as minimal as possible.
125
126 =back
127
128 The permitted installation targets are:
129
130 =over 4
131
132 =item INTRANET_CGI_DIR 
133
134 CGI scripts for intranet (staff) interface.
135
136 =item INTRANET_TMPL_DIR
137
138 HTML templates for the intranet interface.
139
140 =item INTRANET_WWW_DIR
141
142 HTML files, images, etc. for DocumentRoot for the intranet interface.
143
144 =item OPAC_CGI_DIR
145
146 CGI scripts for OPAC (public) interface.
147
148 =item OPAC_TMPL_DIR
149
150 HTML templates for the OPAC interface.
151
152 =item OPAC_WWW_DIR
153
154 HTML files, images, etc. for DocumentRoot for the OPAC interface.
155
156 =item PERL_MODULE_DIR
157
158 Perl modules (at present just the C4 modules) that are intimately
159 tied to Koha.  Depending on the installation options, these
160 may or may not be installed one of the standard directories
161 in Perl's default @LIB.
162
163 =item KOHA_CONF_DIR
164
165 Directory for Koha configuration files.
166
167 =item ZEBRA_CONF_DIR
168
169 Directory for Zebra configuration files.
170
171 =item NONE
172
173 This is a dummy target used to explicitly state
174 that a given file or directory is not to be installed.
175 This is used either for parts of the installer itself
176 or for development tools that are not applicable to a
177 production installation.
178
179 =back
180
181 =cut
182
183 my %target_map = (
184   'about.pl'                  => 'INTRANET_CGI_DIR',
185   'acqui'                     => 'INTRANET_CGI_DIR',
186   'admin'                     => 'INTRANET_CGI_DIR',
187   'authorities'               => 'INTRANET_CGI_DIR',
188   'C4'                        => 'PERL_MODULE_DIR',
189   'catalogue'                 => 'INTRANET_CGI_DIR',
190   'cataloguing'               => 'INTRANET_CGI_DIR',
191   'changelanguage.pl'         => [ 'INTRANET_CGI_DIR', 'OPAC_CGI_DIR' ],
192   'check_sysprefs.pl'         => 'NONE',
193   'circ'                      => 'INTRANET_CGI_DIR',
194   'edithelp.pl'               => 'INTRANET_CGI_DIR',
195   'etc'                       => 'KOHA_CONF_DIR',
196   'etc/zebradb'               => 'ZEBRA_CONF_DIR',
197   'installer-CPAN.pl'         => 'NONE',
198   'installer'                 => 'INTRANET_CGI_DIR',
199   'koha-tmpl'                 => 'NONE',
200   'koha-tmpl/intranet-tmpl'   => 'INTRANET_TMPL_DIR',
201   'koha-tmpl/opac-tmpl'       => 'OPAC_TMPL_DIR',
202   'koha-version.pl'           => 'INTRANET_CGI_DIR', # FIXME this may need to be in OPAC_CGI_DIR as well, with an update to C4::Context
203   'labels'                    => 'INTRANET_CGI_DIR',
204   'mainpage.pl'               => 'INTRANET_CGI_DIR',
205   'Makefile.PL'               => 'NONE',
206   'MANIFEST.SKIP'             => 'NONE',
207   'members'                   => 'INTRANET_CGI_DIR',
208   'misc'                      => 'NONE', # FIXME deal with a little later
209   'opac'                      => 'OPAC_CGI_DIR',
210   'README.txt'                => 'NONE',
211   'reports'                   => 'INTRANET_CGI_DIR',
212   'reserve'                   => 'INTRANET_CGI_DIR',
213   'reviews'                   => 'INTRANET_CGI_DIR',
214   'rewrite-config.PL'         => 'NONE',
215   'reviews'                   => 'INTRANET_CGI_DIR',
216   'rss'                       => 'NONE', # FIXME deal with a little later
217   'serials'                   => 'INTRANET_CGI_DIR',
218   'sms'                       => 'INTRANET_CGI_DIR',
219   'suggestion'                => 'INTRANET_CGI_DIR',
220   'svc'                       => 'INTRANET_CGI_DIR',
221   't'                         => 'NONE',
222   'tmp'                       => 'NONE', # FIXME deal with later
223   'tools'                     => 'INTRANET_CGI_DIR',
224   'virtualshelves'            => 'INTRANET_CGI_DIR',
225 );
226
227 =head1 CONFIGURATION OPTIONS
228
229 The following configuration options are used by the installer.
230
231 =over 4
232
233 =item INSTALL_MODE
234
235 Specifies whether installation will be FHS-compliant (default,
236 assumes user has root), put everything under
237 a single directory (for users installing on a web host
238 that allows CGI scripts and a MySQL database but not root 
239 access), or development (for a developer who wants to run
240 Koha from a git clone with no fuss).
241
242 =item INSTALL_BASE
243
244 Directory under which most components will go.  Default
245 value will vary depending on INSTALL_MODE.
246
247 =item INSTALL_ZEBRA
248
249 Whether to install Zebra configuration files and data
250 directories.
251
252 =item ZEBRA_MARC_FORMAT
253
254 Specifies format of MARC records to be indexed by Zebra.
255
256 =item ZEBRA_LANGUAGE
257
258 Specifies primary language of records that will be 
259 indexed by Zebra.
260
261 =back
262
263 =cut
264
265 # default configuration options
266 my %config_defaults = (
267   'INSTALL_MODE'      => 'standard',
268   'INSTALL_BASE'      => '/usr/share/koha',
269   'INSTALL_ZEBRA'     => 'yes',
270   'ZEBRA_MARC_FORMAT' => 'marc21',
271   'ZEBRA_LANGUAGE'    => 'en',
272 );
273
274 # valid values for certain configuration options
275 my %valid_config_values = (
276   'INSTALL_MODE'  => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
277   'INSTALL_ZEBRA' => { 'yes' => 1, 'no' => 1 },
278   'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
279   'ZEBRA_LANGUAGE'    => { 'en' => 1, 'fr' => 1 }, # FIXME should generate from contents of distribution
280 );
281
282 my %config = get_configuration(\%config_defaults, \%valid_config_values);
283 my %target_directories = get_target_directories(\%config);
284
285 WriteMakefile(
286     NAME => 'koha',
287     #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
288     VERSION_FROM => 'C4/Context.pm',
289     ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
290     AUTHOR => 'Koha Developers <koha-devel@nongnu.org>',
291     NO_META => 1,
292     PREREQ_PM => {
293 'CGI' => 3.15,
294 'CGI::Carp' => 1.29,
295 'CGI::Session' => '4.10',
296 'Class::Factory::Util' => 1.7,
297 'Class::Accessor' => 0.30,
298 'DBD::mysql' => 3.0008,
299 'DBI' => 1.53,
300 'Data::Dumper' => 2.121_08,
301 'Date::Calc' => 5.4,
302 'Date::Manip' => 5.44,
303 'Digest::MD5' => 2.36,
304 'File::Temp' => 0.16,
305 'GD::Barcode::UPCE' => 1.1,
306 'Getopt::Long' => 2.35,
307 'Getopt::Std' => 1.05,
308 'HTML::Template::Pro' => 0.65,
309 'HTTP::Cookies' => 1.39,
310 'HTTP::Request::Common' => 1.26,
311 'LWP::Simple' => 1.41,
312 'LWP::UserAgent' => 2.033,
313 'Lingua::Stem' => 0.82,
314 'List::Util' => 1.18,
315 'Locale::Language' => 2.07,
316 'MARC::Charset' => 0.98,
317 'MARC::Crosswalk::DublinCore' => 0.03,
318 'MARC::File::XML' => 0.88,
319 'MARC::Record' => 2.00,
320 'MIME::Base64' => 3.07,
321 'MIME::QuotedPrint' => 3.07,
322 'Mail::Sendmail' => 0.79,
323 'PDF::API2' => 2.000,
324 'PDF::API2::Page' => 2.000,
325 'PDF::API2::Util' => 2.000,
326 'PDF::Reuse' => 0.33,
327 'PDF::Reuse::Barcode' => 0.05,
328 'POSIX' => 1.09,
329 'Schedule::At' => 1.06,
330 'Term::ANSIColor' => 1.10,
331 'Test' => 1.25,
332 'Test::Harness' => 2.56,
333 'Test::More' => 0.62,
334 'Text::CSV' => 0.01,
335 'Text::CSV_XS' => 0.32,
336 'Text::Wrap' => 2005.082401,
337 'Time::HiRes' => 1.86,
338 'Time::localtime' => 1.02,
339 'Unicode::Normalize' => 0.32,
340 'XML::Dumper' => 0.81,
341 'XML::LibXML' => 1.59,
342 'XML::SAX::ParserFactory' => 1.01,
343 'XML::Simple' => 2.14,
344 'XML::RSS' => 1.31,
345 'ZOOM' => 1.16,
346         },
347
348         # File tree mapping
349 #       PM => map_tree(),
350         PM => unhashdir($dirtree),
351
352         # disable tests
353         'test' => {TESTS => 't/dummy.t'},
354
355 #   CONFIGURE => sub {
356 #     # Ask for options with prompt($question,$default) calls here?
357 #     return { macro => { 'export TEST' => '755' } }
358 #     },
359
360    PL_FILES => { # generator => target(s)
361       'rewrite-config.PL' => [
362          '$(PREFIX)/share/koha/etc/koha-conf.xml',
363          '$(PREFIX)/share/koha/etc/koha-httpd.conf',
364          '$(PREFIX)/share/koha/etc/zebradb/etc/passwd',
365          '$(PREFIX)/share/koha/etc/zebradb/zebra-biblios.cfg',
366          '$(PREFIX)/share/koha/etc/zebradb/zebra-authorities.cfg'
367          ]
368    }
369 #     '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'],
370 #     'misc/koha.conf.PL' => '$(INST_LIBDIR)/../etc/koha.conf',
371 #     'misc/apache-koha.conf.PL' => '$(INST_LIBDIR)/../etc/apache-koha.conf',
372 #     'misc/koha.sql.PL' => '$(INST_LIBDIR)/intranet/scripts/koha.sql',
373 #     'z3950/z3950-daemon-options.PL' => '$(INST_LIBDIR)/intranet/scripts/z3950daemon/z3950-daemon-options',
374 #     # fake target to check permissions
375 #     'misc/chmod.PL' => '$(INST_LIBDIR)/fake-target'
376 #     }
377    # need to set ownerships
378    # need to load koha.sql
379    # need to link koha-httpd.conf
380    # need to start z3950-daemon
381 );
382
383 =head1 FUNCTIONS
384
385 =head2 hashdir
386
387 This function recurses through the directory structure and builds
388 a hash of hashes containing the structure with arrays holding filenames.
389 This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
390
391 =cut
392
393 sub hashdir{
394     my $dir = shift;
395     opendir my $dh, $dir or die $!;
396     my $tree = {}->{$dir} = {};
397     while( my $file = readdir($dh) ) {
398         next if $file =~ m/^\.{1,2}/;
399         my $path = $dir .'/' . $file;
400         $tree->{$file} = hashdir($path), next if -d $path;
401         push @{$tree->{'.'}}, $file;
402     }
403     return $tree;
404 }
405
406 =head2 unhashdir
407
408 This function unhashes the hash of hashes generated by hashdir().
409 This directory unhashing routine is the personal work of Chris Nighswonger (fbcit).
410 Modified here to build koha makefile. It lists all files and where to install each one.
411 It then returns a hash reference suitable for the PM variable above.
412
413 =cut
414
415 sub unhashdir{
416         my $dirhash = shift;
417         my $dirlevel = shift;
418         my $toplevel = $dirlevel;
419         for my $k1 ( sort keys %$dirhash ) {
420                 if ($k1 ne '.' && $k1 ne '') {
421                         $dirlevel = ( $dirlevel ? $dirlevel . '/' . $k1 : $k1 );
422                         &unhashdir($dirhash->{ $k1 }, $dirlevel);
423                         $dirlevel = $toplevel;
424                 }
425                 elsif ( $k1 eq '.' ) {
426                         foreach $file ( @{$dirhash->{ $k1 }} ) {
427 #                               TODO: There are some hacks here that may be able to be improved... -fbcit
428                                 if ( $file =~ /^./ ) { next; } # skip hidden files and directories.
429
430                                 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.
431
432                                 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/
433
434                                 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/
435
436                                 elsif ( $dirlevel =~ /(misc|rss)/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # misc & rss are copied to koha,
437
438 #                               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,
439
440                                 elsif ( $file !~ /\.pl/ && $dirlevel =~ /etc/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(PREFIX)/share/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # Misc etc to koha/etc
441
442                                 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"; 
443
444                         }
445                         next;
446                 }
447         }
448         return \%result;
449 }
450
451 =head2 get_configuration_options
452
453 This prompts the user for various configuration options.
454
455 =cut
456
457 sub get_configuration {
458   my $defaults = shift;
459   my $valid_values = shift;
460   my %config = ();
461
462   my $msg = q(
463 By default, Koha can be installed in one of three ways:
464
465 standard: Install files in conformance with the Filesystem
466           Hierarchy Standard (FHS).  This is the default mode
467           and should be used when installing a production
468           Koha system.  On Unix systems, root access is 
469           needed to complete a standard installation.
470
471 single:   Install files under a single directory.  This option
472           is useful for installing Koha without root access, e.g.,
473           on a web host that allows CGI scripts and MySQL databases
474           but requires the user to keep all files under the user's
475           HOME directory.
476
477 dev:      Create a set of symbolic links and configuration files to
478           allow Koha to run directly from the source distribution.
479           This mode is useful for developers who want to run
480           Koha from a git clone.
481
482 Please choose the installation mode);
483     $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
484     $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values);
485
486     # set message and default value for INSTALL_BASE
487     # depending on value of INSTALL_MODE
488     my $install_base_default = $defaults->{'INSTALL_BASE'};
489     if ($config{'INSTALL_MODE'} eq 'dev') {
490         $msg = q(
491 Please specify the directory in which to install Koha's
492 active configuration files and (if applicable) the
493 Zebra database.  Koha's CGI scripts and templates will
494 be run from the current directory.);
495         # FIXME - home directory portability consideration apply
496         $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha-dev" : "/usr/share/koha-dev";
497     } elsif ($config{'INSTALL_MODE'} eq 'single') {
498         $msg = "\nPlease specify the directory in which to install Koha";
499         # FIXME -- we're assuming under a 'single' mode install
500         # that user will likely want to install under the home
501         # directory.  This is OK in and of itself, but we should
502         # use File::HomeDir to locate the home directory portably.  
503         # This is deferred for now because File::HomeDir is not yet
504         # core.
505         $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : "/usr/share/koha";
506     } else {
507         # must be standard
508         $msg = q(
509 Please specify the directory under which most Koha files 
510 will be installed.
511
512 Note that if you are planning in installing more than 
513 one instance of Koha, you may want to modify the last
514 component of the directory path, which will be used
515 as the package name in the FHS layout.);
516     }
517     $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values);
518
519     $msg = q(
520 Koha can use the Zebra search engine for high-performance
521 searching of bibliographic and authority records.  If you
522 have installed the Zebra software and would like to use it,
523 please answer 'yes' to the following question.  Otherwise, 
524 Koha will default to using its internal search engine.
525
526 Please specify whether to install the Zebra configuration files);
527     $msg .= _add_valid_values_disp('INSTALL_ZEBRA', $valid_values);
528     $config{'INSTALL_ZEBRA'} = _get_value('INSTALL_ZEBRA', $msg, $defaults->{'INSTALL_ZEBRA'}, $valid_values);
529
530     if ($config{'INSTALL_ZEBRA'} eq 'yes') {
531         $msg = q(
532 Since you've chosen to use Zebra with Koha,
533 you must specify the primary MARC format of the
534 records to be indexed by Zebra.
535
536 Koha provides Zebra configuration files for MARC 21
537 and UNIMARC.
538
539 Please specify the MARC format);
540         $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
541         $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values);
542         $msg = q(
543 Koha supplies Zebra configuration files tuned for
544 searching either English (en) or French (fr) MARC
545 records.
546
547 Please specify the primary language of the MARC records);
548         $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
549         $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values);
550     }
551     return %config;
552 }
553
554 sub _add_valid_values_disp {
555     my $key = shift;
556     my $valid_values = shift;
557    
558     my $disp = "";
559     if (exists $valid_values->{$key}) {
560         $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
561     }
562     return $disp;
563 }
564
565 sub _get_value {
566     my $key = shift;
567     my $msg = shift;
568     my $default = shift;
569     my $valid_values = shift;
570
571     my $val = prompt($msg, $default);
572     while (exists $valid_values->{$key} and not exists $valid_values->{$key}->{$val}) {
573         my $retry_msg = "Value '$val' is not a valid option.\n";
574         $retry_msg .= "Please enter a value";
575         $retry_msg .= _add_valid_values_disp($key, $valid_values);
576         $val = prompt($retry_msg, $default);
577     }
578     return $val;
579 }
580
581 =head2 get_target_directories 
582
583 Creates a hash mapping from symbols for installation target
584 directories to actual directory paths.
585
586 =cut
587
588 sub get_target_directories {
589     my $config = shift;
590
591     my $base = $config->{'INSTALL_BASE'};
592     my $mode = $config->{'INSTALL_MODE'};
593
594     # get last component of install base directory
595     # to treat as package name
596     my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
597     my @basedir = File::Spec->splitdir($directories);
598     my $package = pop @basedir;
599
600     my %dirmap = ();
601     if ($mode eq 'single') {
602         # mode is standard, i.e., 'fhs'
603         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
604         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'templates');
605         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'www');
606         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
607         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'templates');
608         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'www');
609         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
610         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
611         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
612         $dirmap{'EXAMPLE_DIR'} = File::Spec->catdir(@basedir, $package, 'example');
613         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
614         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
615         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
616         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
617         $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
618         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
619     } elsif ($mode eq 'dev') {
620         my $curdir = File::Spec->rel2abs(File::Spec->curdir());
621         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
622         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
623         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
624         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir, 'opac');
625         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
626         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
627         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
628         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
629         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
630         $dirmap{'EXAMPLE_DIR'} = File::Spec->catdir(@basedir, $package, 'example');
631         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
632         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
633         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
634         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
635         $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
636         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
637     } else {
638         # mode is standard, i.e., 'fhs'
639         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
640         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'templates');
641         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'www');
642         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
643         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'templates');
644         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'www');
645         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
646         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
647         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
648         $dirmap{'EXAMPLE_DIR'} = File::Spec->catdir(@basedir, $package, 'example');
649         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
650         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
651         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
652         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
653         $dirmap{'LOG_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
654         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
655     }
656
657     foreach my $key (sort keys %dirmap) {
658         print sprintf("%-25.25s%s\n", $key, $dirmap{$key});
659     }
660     return %dirmap;
661 }
662
663 #package MY;
664 #sub install {
665     #warn "\n\n\noverride\n\n\n";
666     #return "";
667 #}
668
669 __END__
670
671
672 =head1 SEE ALSO
673
674 ExtUtils::MakeMaker(3)
675
676 =head1 AUTHORS
677
678 MJ Ray mjr at phonecoop.coop
679
680 =cut
681