Commit | Line | Data |
f5e40fb4 |
1 | # $Id: Makefile.PL,v 1.18 2001/09/01 00:55:26 robs Exp $ |
1b64d24d |
2 | |
3 | use ExtUtils::MakeMaker; |
4 | use IO::File; |
5 | use Config; |
6 | use Cwd 'cwd'; |
7bb01969 |
7 | use 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); |
f5e40fb4 |
12 | @dist1 = qw(LICENSE.TERMS configure configure.in); |
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 |
16 | GetOptions ("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 |
20 | open(CFG,">FCGI.cfg"); |
21 | print CFG "\$pure = $pure;1;\n"; |
22 | close CFG; |
23 | |
e87ca2dd |
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 (@dist3, @dist2) { unlink }; |
45 | foreach (@dist3) { copy("$devkit/include/$_", ".") || die $! }; |
46 | foreach (@dist2) { copy("$devkit/libfcgi/$_", ".") || die $! }; |
47 | } |
48 | else { |
49 | # CPAN |
50 | for $dir ("/usr", "/usr/local") { |
51 | if (-d "$dir/lib/" && -f "$dir/lib/libfcgi.a" |
52 | && -d "$dir/include" && !grep {!-f "$dir/include/$_"} (@h)) |
53 | { |
54 | print "Found fcgi library and include files in $dir\n"; |
55 | print "Will be using those instead of the included files\n"; |
56 | print "Edit Makefile.PL if you don't like it\n"; |
57 | |
58 | $prefix = $dir; |
59 | push @libs, "-L$dir/lib -lfcgi"; |
60 | last; |
61 | } |
62 | } |
63 | } |
1b64d24d |
64 | } |
65 | |
66 | $sys = $^O eq 'MSWin32' ? 'win32' : 'unix'; |
67 | push @o, "fcgiapp.o", "os_$sys.o" unless $prefix; |
68 | $inc = $prefix ? "-I$prefix/include" : '-I.'; |
69 | |
0074e702 |
70 | push(@extras, CAPI => 'TRUE') |
71 | if ($] >= 5.005 and $^O eq 'MSWin32' |
72 | and $Config{archname} =~ /-object\b/i); |
73 | |
74 | push(@extras, |
75 | ABSTRACT => 'Fast CGI module', |
76 | AUTHOR => 'Sven Verdoolaege (skimo@kotnet.org)') |
77 | if ($ExtUtils::MakeMaker::VERSION >= 5.4301); |
0833402a |
78 | |
79 | $plfiles = { 'echo.PL' => 'echo.fpl', |
80 | 'remote.PL' => 'remote.fpl', |
81 | 'threaded.PL' => 'threaded.fpl', |
82 | 'FCGI.PL' => 'FCGI.pm', |
83 | }; |
84 | $plfiles->{'FCGI.XL'} = 'FCGI.xs' unless $pure; |
236be38d |
85 | if ($pure) { |
86 | push @extras, |
87 | LINKTYPE => ' '; |
88 | } else { |
e87ca2dd |
89 | |
90 | if ("$sys" eq "win32") { |
91 | @libs = (@libs) ? map { "$_ ws2_32.lib" } @libs : ('ws2_32.lib'); |
92 | push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)'; |
93 | } |
94 | |
0833402a |
95 | push @extras, |
96 | 'LIBS' => [ @libs ], |
97 | 'OBJECT' => "@o", |
98 | 'INC' => $inc; |
99 | } |
0074e702 |
100 | |
1b64d24d |
101 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence |
102 | # the contents of the Makefile that is written. |
00cbdd93 |
103 | |
104 | # Work around bug in previous versions of MakeMaker |
105 | WriteMakefile(NAME => 'FCGI') |
106 | if $ExtUtils::MakeMaker::VERSION <= 5.4302; |
107 | |
0833402a |
108 | $mm = MM->new({ |
1b64d24d |
109 | 'NAME' => 'FCGI', |
0833402a |
110 | 'VERSION_FROM' => 'FCGI.PL', |
1b64d24d |
111 | 'dist' => { 'COMPRESS' => 'gzip -9f', |
112 | 'SUFFIX' => 'gz', |
113 | 'PREOP' => '$(CP) '.join(' ', |
114 | map {"../$_"} @dist1, |
115 | (map {"libfcgi/$_"} @dist2), |
116 | map {"include/$_"} @dist3).' $(DISTVNAME);'. |
117 | '$(CP) MANIFEST MANIFEST.old;'. |
118 | 'echo -e '. join('\\\n',@dist1,@dist2,@dist3) . |
119 | '>> $(DISTVNAME)/MANIFEST', |
120 | 'POSTOP' => |
121 | '$(MV) MANIFEST.old MANIFEST', |
122 | }, |
236be38d |
123 | 'clean' => { FILES => 'config.cache fcgi_config.h' . |
124 | ' FCGI.xs FCGI.c FCGI.cfg ' . |
125 | (join ' ', values %$plfiles)}, |
0833402a |
126 | 'PL_FILES' => $plfiles, |
127 | PM => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'}, |
0074e702 |
128 | @extras, |
0833402a |
129 | }); |
130 | # don't install oldinterface pod |
131 | delete $mm->{MAN3PODS}{oldinterface.pod}; |
132 | $mm->flush; |
1b64d24d |
133 | |
236be38d |
134 | exit if -f 'fcgi_config.h' or $prefix or $pure; |
1b64d24d |
135 | |
136 | # CPAN and no installed lib found |
137 | if ($sys eq "win32") { |
138 | # configure will almost certainly not run on a normal NT install, |
139 | # use the pregenerated configuration file |
140 | |
09c3bca2 |
141 | use File::Copy qw(copy); |
1b64d24d |
142 | print "Using prebuilt fcgi_config.h file for Windows\n"; |
143 | unlink("fcgi_config.h"); |
09c3bca2 |
144 | die $! unless copy("fcgi_config_x86.h","fcgi_config.h"); |
e87ca2dd |
145 | |
146 | # Win can't deal with existence of FCGI.xs or absence of FCGI.c |
147 | unlink("FCGI.xs"); |
148 | open(F, ">FCGI.c"); close(F); |
149 | $now = time; $before = $now - 600; |
150 | utime $before, $before, "FCGI.c"; |
151 | utime $now, $now, "FCGI.PL"; |
1b64d24d |
152 | } else { |
153 | print "Running ./configure for you\n"; |
6ef7789b |
154 | print "Please read configure.readme for information on how to run it yourself\n"; |
1b64d24d |
155 | |
156 | $ENV{'CC'} = $Config{'cc'}; |
157 | system("./configure"); |
158 | } |