Support building from the devkit on Win32 when the libfcgi was built into Release...
[catagits/fcgi2.git] / perl / Makefile.PL
1 # $Id: Makefile.PL,v 1.13 2001/08/28 19:14:21 robs 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 acconfig.h);
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 $devkit = cwd() . "/..";
25
26 if (-d "$devkit/libfcgi/" 
27     && -d "$devkit/include" && !grep {!-f "$devkit/include/$_"} (@h)) 
28 {
29     # devkit
30     $prefix = $devkit;
31
32     if (-f "$devkit/libfcgi/libfcgi.a") {
33                 push @libs, "-L$devkit/libfcgi -lfcgi";
34     }
35     elsif (-f "$devkit/libfcgi/Release/libfcgi.dll") {
36                 push @libs, "-L$devkit/libfcgi/Release -lfcgi";
37     }
38     elsif (-f "$devkit/libfcgi/Debug/libfcgi.dll") {
39                 push @libs, "-L$devkit/libfcgi/Debug -lfcgi";
40     }
41     else {
42                 warn "Please compile the library before attempting " .
43                  "to compile the perl module.\n";
44                 exit -1;
45     }
46
47 else {
48     # CPAN  
49     for $dir ("/usr", "/usr/local") {
50         if (-d "$dir/lib/" && -f "$dir/lib/libfcgi.a" 
51                 && -d "$dir/include" && !grep {!-f "$dir/include/$_"} (@h)) 
52         {
53             print "Found fcgi library and include files in $dir\n";
54             print "Will be using that instead of included files\n";
55             print "Edit Makefile.PL if you don't like it\n";
56             
57             $prefix = $dir;
58             push @libs, "-L$dir/lib -lfcgi"; 
59             last;
60         }
61     }
62 }
63
64 $sys = $^O eq 'MSWin32' ? 'win32' : 'unix';
65 push @o, "fcgiapp.o", "os_$sys.o" unless $prefix;
66 $inc = $prefix ? "-I$prefix/include" : '-I.';
67
68 push(@extras, CAPI => 'TRUE')
69      if ($] >= 5.005 and $^O eq 'MSWin32'
70         and $Config{archname} =~ /-object\b/i);
71
72 push(@extras,
73     ABSTRACT => 'Fast CGI module',
74     AUTHOR   => 'Sven Verdoolaege (skimo@kotnet.org)')
75         if ($ExtUtils::MakeMaker::VERSION >= 5.4301); 
76
77 $plfiles = { 'echo.PL' => 'echo.fpl', 
78              'remote.PL' => 'remote.fpl',
79              'threaded.PL' => 'threaded.fpl',
80              'FCGI.PL' => 'FCGI.pm',
81            };
82 $plfiles->{'FCGI.XL'} = 'FCGI.xs' unless $pure;
83 if ($pure) {
84     push @extras,
85         LINKTYPE => ' ';
86 } else {
87     push @extras,
88         'LIBS'  => [ @libs ],
89         'OBJECT'        => "@o",
90         'INC'   => $inc;
91 }
92         
93 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
94 # the contents of the Makefile that is written.
95
96 # Work around bug in previous versions of MakeMaker
97 WriteMakefile(NAME => 'FCGI') 
98     if $ExtUtils::MakeMaker::VERSION <= 5.4302;
99
100 $mm = MM->new({
101     'NAME'              => 'FCGI',
102     'VERSION_FROM'      => 'FCGI.PL',
103     'dist'              => { 'COMPRESS' => 'gzip -9f', 
104                              'SUFFIX' => 'gz',
105                              'PREOP' => '$(CP) '.join(' ',
106                                 map {"../$_"} @dist1,
107                                 (map {"libfcgi/$_"} @dist2),
108                                 map {"include/$_"} @dist3).' $(DISTVNAME);'.
109                                 '$(CP) MANIFEST MANIFEST.old;'.
110                                 'echo -e '. join('\\\n',@dist1,@dist2,@dist3) .
111                                 '>> $(DISTVNAME)/MANIFEST',
112                               'POSTOP' => 
113                                 '$(MV) MANIFEST.old MANIFEST',
114                             },
115     'clean'             => { FILES => 'config.cache fcgi_config.h' . 
116                                       ' FCGI.xs FCGI.c FCGI.cfg ' .
117                                       (join ' ', values %$plfiles)},
118     'PL_FILES'          => $plfiles,
119     PM                  => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'},
120     @extras,
121 });
122 # don't install oldinterface pod
123 delete $mm->{MAN3PODS}{oldinterface.pod};
124 $mm->flush;
125
126 if ($sys eq "win32") {
127     # Win can't deal with existence of FCGI.xs or absence of FCGI.c
128     unlink("FCGI.xs");
129     open(F, ">FCGI.c"); close(F);
130     $now = time; $before = $now - 600;
131     utime $before, $before, "FCGI.c";
132     utime $now, $now, "FCGI.PL";
133 }
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 } else {
147     print "Running ./configure for you\n";
148     print "Please read configure.readme for information on how to run it yourself\n";
149
150     $ENV{'CC'} = $Config{'cc'};
151     system("./configure");
152 }