1c80424b6e3296aeb12d0900162d8cfefae7967f
[catagits/fcgi2.git] / perl / Makefile.PL
1 # $Id: Makefile.PL,v 1.20 2001/09/01 13:09:20 skimo Exp $
2
3 use ExtUtils::MakeMaker;
4 use IO::File;
5 use Config;
6 use Cwd 'cwd';
7 use Getopt::Long;
8
9 @h1 = qw(fastcgi.h fcgiapp.h fcgimisc.h fcgios.h);
10 @h = (@h1, 'fcgi_config.h');
11 @o = qw(FCGI.o);
12 @dist1 = qw(LICENSE.TERMS configure configure.in install.sh);
13 @dist2 = qw(fcgiapp.c os_unix.c os_win32.c);
14 @dist3 = (@h1, qw(fcgi_config.h.in fcgi_config_x86.h));
15
16 GetOptions ("pure-perl!" => \$pure);
17 $pure = 
18     (prompt("Do you want to use the pure perl implementation", "no") =~ /^y/) 
19     ? "1" : "0" unless defined $pure;
20 open(CFG,">FCGI.cfg");
21 print CFG "\$pure = $pure;1;\n";
22 close CFG;
23
24 if (! $pure) {
25         my $cwd = cwd();
26         my $devkit = "$cwd/..";
27
28         if (-d "$devkit/libfcgi" && -d "$devkit/include") {
29                 # devkit
30                 if (grep { ! -f "$devkit/include/$_" } @dist3 
31                         or grep { ! -f "$devkit/libfcgi/$_" } @dist2)
32                 {
33                         warn "This appears to be a FastCGI devkit distribution, " .
34                                  "but one or more FastCGI library files are missing. \n" .
35                                  "Please check the integrity of the distribution.\n";
36                         exit -1;
37                 }
38
39                 # Copy the C lib files down to ensure a compatible build.
40                 print "Copying C library files from the devkit distribution\n";
41             use File::Copy qw(copy);
42
43                 # TODO: stop or save if a local file has been modified
44                 foreach (@dist1, @dist2, @dist3) { unlink };
45                 foreach (@dist1) { copy("$devkit/$_", ".") || die $! };
46                 foreach (@dist2) { copy("$devkit/libfcgi/$_", ".") || die $! };
47                 foreach (@dist3) { copy("$devkit/include/$_", ".") || die $! };
48         }
49         else {
50             # CPAN  
51             for $dir ("/usr", "/usr/local") {
52                 if (-d "$dir/lib/" && -f "$dir/lib/libfcgi.a" 
53                         && -d "$dir/include" && !grep {!-f "$dir/include/$_"} (@h)) 
54                 {
55                     print "Found fcgi library and include files in $dir\n";
56                     print "Will be using those instead of the included files\n";
57                     print "Edit Makefile.PL if you don't like it\n";
58                     
59                     $prefix = $dir;
60                     push @libs, "-L$dir/lib -lfcgi"; 
61                     last;
62                 }
63             }
64         }
65 }
66
67 $sys = $^O eq 'MSWin32' ? 'win32' : 'unix';
68 push @o, "fcgiapp.o", "os_$sys.o" unless $prefix;
69 $inc = $prefix ? "-I$prefix/include" : '-I.';
70
71 push(@extras, CAPI => 'TRUE')
72      if ($] >= 5.005 and $^O eq 'MSWin32'
73         and $Config{archname} =~ /-object\b/i);
74
75 push(@extras,
76     ABSTRACT => 'Fast CGI module',
77     AUTHOR   => 'Sven Verdoolaege (skimo@kotnet.org)')
78         if ($ExtUtils::MakeMaker::VERSION >= 5.4301); 
79
80 $plfiles = { 'echo.PL' => 'echo.fpl', 
81              'remote.PL' => 'remote.fpl',
82              'threaded.PL' => 'threaded.fpl',
83              'FCGI.PL' => 'FCGI.pm',
84            };
85 $plfiles->{'FCGI.XL'} = 'FCGI.xs' unless $pure;
86 if ($pure) {
87     push @extras,
88         LINKTYPE => ' ';
89 } else {
90
91         if ("$sys" eq "win32") {
92                 @libs = (@libs) ? map { "$_ ws2_32.lib" } @libs : ('ws2_32.lib');
93                 push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)';
94         }
95
96     push @extras,
97         'LIBS'  => [ @libs ],
98         'OBJECT'        => "@o",
99         'INC'   => $inc;
100 }
101         
102 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
103 # the contents of the Makefile that is written.
104
105 # Work around bug in previous versions of MakeMaker
106 WriteMakefile(NAME => 'FCGI') 
107     if $ExtUtils::MakeMaker::VERSION <= 5.4302;
108
109 $mm = MM->new({
110     'NAME'              => 'FCGI',
111     'VERSION_FROM'      => 'FCGI.PL',
112     'dist'              => { 'COMPRESS' => 'gzip -9f', 
113                              'SUFFIX' => 'gz',
114                              'PREOP' => '$(CP) '.join(' ',
115                                 map {"../$_"} @dist1,
116                                 (map {"libfcgi/$_"} @dist2),
117                                 map {"include/$_"} @dist3).' $(DISTVNAME);'.
118                                 '$(CP) MANIFEST MANIFEST.old;'.
119                                 'echo -e '. join('\\\n',@dist1,@dist2,@dist3) .
120                                 '>> $(DISTVNAME)/MANIFEST',
121                               'POSTOP' => 
122                                 '$(MV) MANIFEST.old MANIFEST',
123                             },
124     'clean'             => { FILES => 'config.cache fcgi_config.h' . 
125                                       ' FCGI.xs FCGI.c FCGI.cfg ' .
126                                       (join ' ', values %$plfiles)},
127     'PL_FILES'          => $plfiles,
128     PM                  => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'},
129     @extras,
130 });
131 # don't install oldinterface pod
132 delete $mm->{MAN3PODS}{oldinterface.pod};
133 $mm->flush;
134
135 exit if -f 'fcgi_config.h' or $prefix or $pure;
136
137 # CPAN and no installed lib found
138 if ($sys eq "win32") {
139     # configure will almost certainly not run on a normal NT install,
140     # use the pregenerated configuration file
141
142     use File::Copy qw(copy);
143     print "Using prebuilt fcgi_config.h file for Windows\n";
144     unlink("fcgi_config.h");
145     die $! unless copy("fcgi_config_x86.h","fcgi_config.h");
146
147     # Win can't deal with existence of FCGI.xs or absence of FCGI.c
148     unlink("FCGI.xs");
149     open(F, ">FCGI.c"); close(F);
150     $now = time; $before = $now - 600;
151     utime $before, $before, "FCGI.c";
152     utime $now, $now, "FCGI.PL";
153 } else {
154     print "Running ./configure for you\n";
155     print "Please read configure.readme for information on how to run it yourself\n";
156
157     $ENV{'CC'} = $Config{'cc'};
158     system("sh configure");
159 }