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