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