Commit | Line | Data |
18c10cb1 |
1 | # $Id: Makefile.PL,v 1.32 2001/09/27 12:11:40 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); |
e12d4fb3 |
12 | @dist1 = qw(LICENSE.TERMS); |
1b64d24d |
13 | @dist2 = qw(fcgiapp.c os_unix.c os_win32.c); |
7ef79c64 |
14 | @dist3 = (@h1, qw(fcgi_config_x86.h)); |
1b64d24d |
15 | |
c737f293 |
16 | GetOptions ("pure-perl!" => \$pure, |
17 | "use-installed:s" => \$useinstalled); |
cd834ed1 |
18 | $pure = "0" unless defined $pure; |
0833402a |
19 | open(CFG,">FCGI.cfg"); |
20 | print CFG "\$pure = $pure;1;\n"; |
21 | close CFG; |
22 | |
e12d4fb3 |
23 | $libfound = 0; |
c737f293 |
24 | @libs = (); |
e12d4fb3 |
25 | |
e87ca2dd |
26 | if (! $pure) { |
e12d4fb3 |
27 | my $cwd = cwd(); |
28 | my $devkit = "$cwd/.."; |
29 | |
c737f293 |
30 | if (defined $useinstalled) { |
31 | require ExtUtils::Liblist; |
c737f293 |
32 | my $libspec = $useinstalled ? "-L$useinstalled/lib " : ""; |
33 | $libspec .= "-lfcgi"; |
fa01dc1c |
34 | my @l = MM->ext($libspec); |
c737f293 |
35 | if ($l[0] || $l[1] || $l[2]) { |
36 | $prefix = "$useinstalled/include" if $useinstalled; |
37 | $libfound = 1; |
38 | push @libs, $libspec; |
39 | } |
c737f293 |
40 | } |
41 | if (!$libfound && -d "$devkit/libfcgi" && -d "$devkit/include") { |
e12d4fb3 |
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; |
e87ca2dd |
50 | } |
e12d4fb3 |
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 | } |
1b64d24d |
60 | } |
61 | |
62 | $sys = $^O eq 'MSWin32' ? 'win32' : 'unix'; |
e12d4fb3 |
63 | push @o, "fcgiapp.o", "os_$sys.o" unless $libfound; |
92079298 |
64 | $inc = '-I.' unless $libfound; |
65 | $inc .= " -I$prefix/include" if $prefix; |
1b64d24d |
66 | |
0074e702 |
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); |
0833402a |
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; |
236be38d |
82 | if ($pure) { |
83 | push @extras, |
84 | LINKTYPE => ' '; |
85 | } else { |
e87ca2dd |
86 | |
87 | if ("$sys" eq "win32") { |
c737f293 |
88 | push @libs, ":nosearch -lws2_32"; |
e87ca2dd |
89 | push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)'; |
90 | } |
91 | |
0833402a |
92 | push @extras, |
c737f293 |
93 | 'LIBS' => [ "@libs" ], |
0833402a |
94 | 'OBJECT' => "@o", |
95 | 'INC' => $inc; |
96 | } |
0074e702 |
97 | |
1b64d24d |
98 | # See lib/ExtUtils/MakeMaker.pm for details of how to influence |
99 | # the contents of the Makefile that is written. |
00cbdd93 |
100 | |
101 | # Work around bug in previous versions of MakeMaker |
102 | WriteMakefile(NAME => 'FCGI') |
103 | if $ExtUtils::MakeMaker::VERSION <= 5.4302; |
104 | |
0833402a |
105 | $mm = MM->new({ |
1b64d24d |
106 | 'NAME' => 'FCGI', |
4945bfbe |
107 | 'VERSION_FROM' => 'version.pm', |
1b64d24d |
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 | }, |
236be38d |
120 | 'clean' => { FILES => 'config.cache fcgi_config.h' . |
121 | ' FCGI.xs FCGI.c FCGI.cfg ' . |
122 | (join ' ', values %$plfiles)}, |
0833402a |
123 | 'PL_FILES' => $plfiles, |
124 | PM => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'}, |
0074e702 |
125 | @extras, |
0833402a |
126 | }); |
127 | # don't install oldinterface pod |
128 | delete $mm->{MAN3PODS}{oldinterface.pod}; |
129 | $mm->flush; |
1b64d24d |
130 | |
e12d4fb3 |
131 | exit if -f 'fcgi_config.h' or $libfound or $pure; |
1b64d24d |
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 | |
09c3bca2 |
138 | use File::Copy qw(copy); |
1b64d24d |
139 | print "Using prebuilt fcgi_config.h file for Windows\n"; |
140 | unlink("fcgi_config.h"); |
18c10cb1 |
141 | my $confdir = $prefix ? "$prefix/include/" : ''; |
142 | die $! unless copy("$confdir/fcgi_config_x86.h","fcgi_config.h"); |
e87ca2dd |
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"; |
1b64d24d |
150 | } else { |
151 | print "Running ./configure for you\n"; |
6ef7789b |
152 | print "Please read configure.readme for information on how to run it yourself\n"; |
1b64d24d |
153 | |
154 | $ENV{'CC'} = $Config{'cc'}; |
d4b5dccc |
155 | system("$Config{sh} configure"); |
1b64d24d |
156 | } |