Commit | Line | Data |
7ef79c64 |
1 | # $Id: Makefile.PL,v 1.26 2001/09/21 22:38:59 skimo 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); |
7ef79c64 |
12 | @dist1 = qw(LICENSE.TERMS install-sh config.sub config.guess); |
1b64d24d |
13 | @dist2 = qw(fcgiapp.c os_unix.c os_win32.c); |
7ef79c64 |
14 | @dist3 = (@h1, qw(fcgi_config_x86.h)); |
1b64d24d |
15 | |
7bb01969 |
16 | GetOptions ("pure-perl!" => \$pure); |
cd834ed1 |
17 | $pure = "0" unless defined $pure; |
0833402a |
18 | open(CFG,">FCGI.cfg"); |
19 | print CFG "\$pure = $pure;1;\n"; |
20 | close CFG; |
21 | |
e87ca2dd |
22 | if (! $pure) { |
23 | my $cwd = cwd(); |
24 | my $devkit = "$cwd/.."; |
25 | |
26 | if (-d "$devkit/libfcgi" && -d "$devkit/include") { |
27 | # devkit |
28 | if (grep { ! -f "$devkit/include/$_" } @dist3 |
29 | or grep { ! -f "$devkit/libfcgi/$_" } @dist2) |
30 | { |
31 | warn "This appears to be a FastCGI devkit distribution, " . |
32 | "but one or more FastCGI library files are missing. \n" . |
33 | "Please check the integrity of the distribution.\n"; |
34 | exit -1; |
35 | } |
36 | |
37 | # Copy the C lib files down to ensure a compatible build. |
38 | print "Copying C library files from the devkit distribution\n"; |
39 | use File::Copy qw(copy); |
40 | |
41 | # TODO: stop or save if a local file has been modified |
108e1cc2 |
42 | foreach (@dist1, @dist2, @dist3) { unlink }; |
43 | foreach (@dist1) { copy("$devkit/$_", ".") || die $! }; |
44 | foreach (@dist2) { copy("$devkit/libfcgi/$_", ".") || die $! }; |
e87ca2dd |
45 | foreach (@dist3) { copy("$devkit/include/$_", ".") || die $! }; |
e87ca2dd |
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 those instead of the 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 | } |
1b64d24d |
63 | } |
64 | |
65 | $sys = $^O eq 'MSWin32' ? 'win32' : 'unix'; |
66 | push @o, "fcgiapp.o", "os_$sys.o" unless $prefix; |
67 | $inc = $prefix ? "-I$prefix/include" : '-I.'; |
68 | |
0074e702 |
69 | push(@extras, CAPI => 'TRUE') |
70 | if ($] >= 5.005 and $^O eq 'MSWin32' |
71 | and $Config{archname} =~ /-object\b/i); |
72 | |
73 | push(@extras, |
74 | ABSTRACT => 'Fast CGI module', |
75 | AUTHOR => 'Sven Verdoolaege (skimo@kotnet.org)') |
76 | if ($ExtUtils::MakeMaker::VERSION >= 5.4301); |
0833402a |
77 | |
78 | $plfiles = { 'echo.PL' => 'echo.fpl', |
79 | 'remote.PL' => 'remote.fpl', |
80 | 'threaded.PL' => 'threaded.fpl', |
81 | 'FCGI.PL' => 'FCGI.pm', |
82 | }; |
83 | $plfiles->{'FCGI.XL'} = 'FCGI.xs' unless $pure; |
236be38d |
84 | if ($pure) { |
85 | push @extras, |
86 | LINKTYPE => ' '; |
87 | } else { |
e87ca2dd |
88 | |
89 | if ("$sys" eq "win32") { |
58191f5e |
90 | @libs = (scalar @libs) |
91 | ? map { "$_ :nosearch -lws2_32" } @libs |
92 | : (':nosearch -lws2_32'); |
e87ca2dd |
93 | push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)'; |
94 | } |
95 | |
0833402a |
96 | push @extras, |
97 | 'LIBS' => [ @libs ], |
98 | 'OBJECT' => "@o", |
99 | 'INC' => $inc; |
100 | } |
0074e702 |
101 | |
1b64d24d |
102 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence |
103 | # the contents of the Makefile that is written. |
00cbdd93 |
104 | |
105 | # Work around bug in previous versions of MakeMaker |
106 | WriteMakefile(NAME => 'FCGI') |
107 | if $ExtUtils::MakeMaker::VERSION <= 5.4302; |
108 | |
0833402a |
109 | $mm = MM->new({ |
1b64d24d |
110 | 'NAME' => 'FCGI', |
4945bfbe |
111 | 'VERSION_FROM' => 'version.pm', |
1b64d24d |
112 | 'dist' => { 'COMPRESS' => 'gzip -9f', |
113 | 'SUFFIX' => 'gz', |
114 | 'PREOP' => '$(CP) '.join(' ', |
115 | map {"../$_"} @dist1, |
116 | (map {"libfcgi/$_"} @dist2), |
117 | map {"include/$_"} @dist3).' $(DISTVNAME);'. |
118 | '$(CP) MANIFEST MANIFEST.old;'. |
119 | 'echo -e '. join('\\\n',@dist1,@dist2,@dist3) . |
120 | '>> $(DISTVNAME)/MANIFEST', |
121 | 'POSTOP' => |
122 | '$(MV) MANIFEST.old MANIFEST', |
123 | }, |
236be38d |
124 | 'clean' => { FILES => 'config.cache fcgi_config.h' . |
125 | ' FCGI.xs FCGI.c FCGI.cfg ' . |
126 | (join ' ', values %$plfiles)}, |
0833402a |
127 | 'PL_FILES' => $plfiles, |
128 | PM => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'}, |
0074e702 |
129 | @extras, |
0833402a |
130 | }); |
131 | # don't install oldinterface pod |
132 | delete $mm->{MAN3PODS}{oldinterface.pod}; |
133 | $mm->flush; |
1b64d24d |
134 | |
236be38d |
135 | exit if -f 'fcgi_config.h' or $prefix or $pure; |
1b64d24d |
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 | |
09c3bca2 |
142 | use File::Copy qw(copy); |
1b64d24d |
143 | print "Using prebuilt fcgi_config.h file for Windows\n"; |
144 | unlink("fcgi_config.h"); |
09c3bca2 |
145 | die $! unless copy("fcgi_config_x86.h","fcgi_config.h"); |
e87ca2dd |
146 | |
147 | # Win can't deal with existence of FCGI.xs or absence of FCGI.c |
148 | unlink("FCGI.xs"); |
149 | open(F, ">FCGI.c"); close(F); |
150 | $now = time; $before = $now - 600; |
151 | utime $before, $before, "FCGI.c"; |
152 | utime $now, $now, "FCGI.PL"; |
1b64d24d |
153 | } else { |
154 | print "Running ./configure for you\n"; |
6ef7789b |
155 | print "Please read configure.readme for information on how to run it yourself\n"; |
1b64d24d |
156 | |
157 | $ENV{'CC'} = $Config{'cc'}; |
d4b5dccc |
158 | system("$Config{sh} configure"); |
1b64d24d |
159 | } |