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