1### This -*- perl -*- script writes the Makefile by ukai
2###
3### Author:  Internet Message Group <img@mew.org>
4### Created: Apr 23, 1997
5### Revised: Dec 20, 2002
6###
7### perl Makefile.PL
8### make
9### make install or make install_rpop
10###
11
12require 5.004;
13use Config;
14
15BEGIN {
16    $VERSION = '100';
17    $im_db_type = "DB";
18
19    # this should be in BEGIN section.
20    if ($im_db_type) {
21	@AnyDBM_File::ISA = qw(DB_File GDBM_File NDBM_File SDBM_File ODBM_File);
22	unshift(@AnyDBM_File::ISA, "${im_db_type}_File");
23	print "try DB type: @AnyDBM_File::ISA\n";
24    } else {
25	print "ignore DB type\n";
26    }
27}
28
29if (open(CONFIN, "configure.in")) {
30    while (<CONFIN>) {
31	/^im_/ && eval "\$$_";
32    }
33    close(CONFIN);
34}
35
36if ($Config{'osname'} ne 'MSWin32') {
37$prefix = "/usr/local";
38$libdir = "\$exec_prefix/lib";
39} else {
40  $prefix = $Config{'prefix'};
41  $prefix =~ s:\\:/:g;
42  $libdir = $Config{'sitelib'};
43  $libdir =~ s:\\:/:g;
44}
45chomp($im_hostname);
46if ($Config{osname} eq "solaris") {
47    $im_usecl='yes';
48} else {
49    $im_usecl='no';
50}
51$im_nosync='no';
52
53# checking DB type
54if ($im_db_type) {
55    use AnyDBM_File;
56    $im_db_type="$AnyDBM_File::ISA[0]";
57    $im_db_type =~ s/_File$//;
58    print "Your DB type is $im_db_type\n";
59}
60
61# generate im*.in -> im*.PL
62opendir(DIR, ".") or die "cannot opendir .: $!";
63@programs_to_install = @pl_files = ();
64foreach (grep(/\.in$/ && !/^(configure|Makefile|IM)/, readdir DIR)) {
65    open(IN, "$_") or die "cannot open $_.in: $!";
66    s/.in$//;
67    push(@programs_to_install, "$_");
68    open(PL, ">$_.PL") or die "cannot open $_.PL: $!";
69    push(@pl_files, "$_.PL");
70    print PL <<"!SUBST!";
71use Config;
72(\$file = \$0) =~ s/\\.PL\$//i;
73open(OUT, ">\$file") or die "Cannot create \$file: $!";
74chmod(0755, \$file);
75print "Extracting \$file (with variable substitutions)\n";
76print OUT << \"!GROK!THIS\";
77\$Config{'startperl'}
78
79!GROK!THIS
80while (<DATA>) {
81    /^#! \\\@im_path_perl\\\@/ && next;
82    s/\\\@im_my_siteperl\\\@//;
83    s/\\\@im_src_siteperl\\\@//;
84    print OUT;
85}
86close(OUT);
87exit 0;
88__END__
89!SUBST!
90    while (<IN>) {
91	print PL $_;
92    }
93    close(IN);
94    close(PL);
95}
96closedir(DIR);
97
98# generate IM/Config.pm.in -> IM/Config.pm
99#          cnf.im/SiteConfig.in -> cnf.im/SiteConfig
100@generate_files = ('IM/Config.pm', 'cnf.im/SiteConfig');
101foreach (@generate_files) {
102    open(IN, "$_.in") or die "cannot open $_.in: $!";
103    open(PM, ">$_") or die "cannot open $_: $!";
104    print "Extracting $_ (with variable substitutions)\n";
105    while (<IN>) {
106	s/\@prefix\@/$prefix/;	# Config.pm.in
107	s/\@exec_prefix\@/$prefix/;
108	s/\@libdir\@/$libdir/;
109	s/\@im_db_type\@/$im_db_type/;
110	s/\@im_file_attr\@/$im_file_attr/;
111	s/\@im_hostname\@/$im_hostname/;
112	s/\@im_usecl\@/$im_usecl/;
113	s/\@im_nosync\@/$im_nosync/;
114	print PM;
115    }
116    close(IN);
117    close(PM);
118}
119closedir(DIR);
120
121# write Makefile
122use ExtUtils::MakeMaker;
123WriteMakefile(
124    'NAME' => 'IM',
125    'VERSION' => $VERSION,
126    'EXE_FILES' => \@programs_to_install,
127    'MAN1PODS' => {},
128    'MAN3PODS' => {},
129    'PREFIX' => $prefix,
130    'clean' => { FILES => join(' ', '$(EXE_FILES)',
131			       @pl_files, @generate_files) },
132    'dist' => { COMPRESS => 'gzip -9f', SUFFIX => 'gz' }
133);
134
135# special rules
136sub MY::postamble {
137    my($self) = shift;
138    my(@m);
139    if ($Config{'osname'} ne 'MSWin32') {
140    push (@m, qq{
141prefix=$prefix
142exec_prefix=$prefix
143libdir=\$(exec_prefix)/lib
144IM_SITECONFIG_DIR=\$(libdir)/im
145
146install:: install_config
147
148install_config: cnf.im/SiteConfig
149	\$(MKPATH) \$(IM_SITECONFIG_DIR)
150	for cnf_im in SiteConfig ; do \\
151	    if \$(TEST_F) \$(IM_SITECONFIG_DIR)/\$\$cnf_im; then \\
152		(\$(CP) cnf.im/\$\$cnf_im \$(IM_SITECONFIG_DIR)/\$\$cnf_im.new;) \\
153	    else \\
154		(\$(CP) cnf.im/\$\$cnf_im \$(IM_SITECONFIG_DIR);) \\
155	    fi \\
156	done
157	\$(CHMOD) -R 0644 \$(IM_SITECONFIG_DIR)/*
158	\$(CHMOD) 755 \$(IM_SITECONFIG_DIR)
159
160uninstall:: uninstall_config
161
162uninstall_config::
163	\$(RM_F) \$(IM_SITECONFIG_DIR)/SiteConfig
164
165install_rpop: install
166	\$(PERL) -e 'chown(0, (getgrnam("mail"))[2], \@ARGV) and chmod(04755, \@ARGV);' \$(INSTALLSCRIPT)/imget
167    });
168  } else {
169    push (@m, qq{
170install:: install_progs
171
172install_progs:
173    \$(CP) Win32\*.exe \$(INSTALLBIN)
174  });
175    join "", @m;
176  }
177}
178
179### Copyright (C) 1997, 1998, 1999 IM developing team
180### All rights reserved.
181###
182### Redistribution and use in source and binary forms, with or without
183### modification, are permitted provided that the following conditions
184### are met:
185###
186### 1. Redistributions of source code must retain the above copyright
187###    notice, this list of conditions and the following disclaimer.
188### 2. Redistributions in binary form must reproduce the above copyright
189###    notice, this list of conditions and the following disclaimer in the
190###    documentation and/or other materials provided with the distribution.
191### 3. Neither the name of the team nor the names of its contributors
192###    may be used to endorse or promote products derived from this software
193###    without specific prior written permission.
194###
195### THIS SOFTWARE IS PROVIDED BY THE TEAM AND CONTRIBUTORS ``AS IS'' AND
196### ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
197### IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
198### PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE TEAM OR CONTRIBUTORS BE
199### LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
200### CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
201### SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
202### BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
203### WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
204### OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
205### IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
206