handle int to pointer conversion properly
[catagits/fcgi2.git] / perl / Makefile.PL
CommitLineData
58191f5e 1# $Id: Makefile.PL,v 1.21 2001/09/04 12:34:10 robs Exp $
1b64d24d 2
3use ExtUtils::MakeMaker;
4use IO::File;
5use Config;
6use Cwd 'cwd';
7bb01969 7use Getopt::Long;
1b64d24d 8
ffaa0e42 9@h1 = qw(fastcgi.h fcgiapp.h fcgimisc.h fcgios.h);
1b64d24d 10@h = (@h1, 'fcgi_config.h');
11@o = qw(FCGI.o);
c5be828e 12@dist1 = qw(LICENSE.TERMS configure configure.in install.sh);
1b64d24d 13@dist2 = qw(fcgiapp.c os_unix.c os_win32.c);
14@dist3 = (@h1, qw(fcgi_config.h.in fcgi_config_x86.h));
15
7bb01969 16GetOptions ("pure-perl!" => \$pure);
0833402a 17$pure =
18 (prompt("Do you want to use the pure perl implementation", "no") =~ /^y/)
7bb01969 19 ? "1" : "0" unless defined $pure;
0833402a 20open(CFG,">FCGI.cfg");
21print CFG "\$pure = $pure;1;\n";
22close CFG;
23
e87ca2dd 24if (! $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
108e1cc2 44 foreach (@dist1, @dist2, @dist3) { unlink };
45 foreach (@dist1) { copy("$devkit/$_", ".") || die $! };
46 foreach (@dist2) { copy("$devkit/libfcgi/$_", ".") || die $! };
e87ca2dd 47 foreach (@dist3) { copy("$devkit/include/$_", ".") || die $! };
e87ca2dd 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 }
1b64d24d 65}
66
67$sys = $^O eq 'MSWin32' ? 'win32' : 'unix';
68push @o, "fcgiapp.o", "os_$sys.o" unless $prefix;
69$inc = $prefix ? "-I$prefix/include" : '-I.';
70
0074e702 71push(@extras, CAPI => 'TRUE')
72 if ($] >= 5.005 and $^O eq 'MSWin32'
73 and $Config{archname} =~ /-object\b/i);
74
75push(@extras,
76 ABSTRACT => 'Fast CGI module',
77 AUTHOR => 'Sven Verdoolaege (skimo@kotnet.org)')
78 if ($ExtUtils::MakeMaker::VERSION >= 5.4301);
0833402a 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;
236be38d 86if ($pure) {
87 push @extras,
88 LINKTYPE => ' ';
89} else {
e87ca2dd 90
91 if ("$sys" eq "win32") {
58191f5e 92 @libs = (scalar @libs)
93 ? map { "$_ :nosearch -lws2_32" } @libs
94 : (':nosearch -lws2_32');
e87ca2dd 95 push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)';
96 }
97
0833402a 98 push @extras,
99 'LIBS' => [ @libs ],
100 'OBJECT' => "@o",
101 'INC' => $inc;
102}
0074e702 103
1b64d24d 104# See lib/ExtUtils/MakeMaker.pm for details of how to influence
105# the contents of the Makefile that is written.
00cbdd93 106
107# Work around bug in previous versions of MakeMaker
108WriteMakefile(NAME => 'FCGI')
109 if $ExtUtils::MakeMaker::VERSION <= 5.4302;
110
0833402a 111$mm = MM->new({
1b64d24d 112 'NAME' => 'FCGI',
0833402a 113 'VERSION_FROM' => 'FCGI.PL',
1b64d24d 114 'dist' => { 'COMPRESS' => 'gzip -9f',
115 'SUFFIX' => 'gz',
116 'PREOP' => '$(CP) '.join(' ',
117 map {"../$_"} @dist1,
118 (map {"libfcgi/$_"} @dist2),
119 map {"include/$_"} @dist3).' $(DISTVNAME);'.
120 '$(CP) MANIFEST MANIFEST.old;'.
121 'echo -e '. join('\\\n',@dist1,@dist2,@dist3) .
122 '>> $(DISTVNAME)/MANIFEST',
123 'POSTOP' =>
124 '$(MV) MANIFEST.old MANIFEST',
125 },
236be38d 126 'clean' => { FILES => 'config.cache fcgi_config.h' .
127 ' FCGI.xs FCGI.c FCGI.cfg ' .
128 (join ' ', values %$plfiles)},
0833402a 129 'PL_FILES' => $plfiles,
130 PM => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'},
0074e702 131 @extras,
0833402a 132});
133# don't install oldinterface pod
134delete $mm->{MAN3PODS}{oldinterface.pod};
135$mm->flush;
1b64d24d 136
236be38d 137exit if -f 'fcgi_config.h' or $prefix or $pure;
1b64d24d 138
139# CPAN and no installed lib found
140if ($sys eq "win32") {
141 # configure will almost certainly not run on a normal NT install,
142 # use the pregenerated configuration file
143
09c3bca2 144 use File::Copy qw(copy);
1b64d24d 145 print "Using prebuilt fcgi_config.h file for Windows\n";
146 unlink("fcgi_config.h");
09c3bca2 147 die $! unless copy("fcgi_config_x86.h","fcgi_config.h");
e87ca2dd 148
149 # Win can't deal with existence of FCGI.xs or absence of FCGI.c
150 unlink("FCGI.xs");
151 open(F, ">FCGI.c"); close(F);
152 $now = time; $before = $now - 600;
153 utime $before, $before, "FCGI.c";
154 utime $now, $now, "FCGI.PL";
1b64d24d 155} else {
156 print "Running ./configure for you\n";
6ef7789b 157 print "Please read configure.readme for information on how to run it yourself\n";
1b64d24d 158
159 $ENV{'CC'} = $Config{'cc'};
c5be828e 160 system("sh configure");
1b64d24d 161}