Commit | Line | Data |
aff18d25 |
1 | # $Id: Makefile.PL,v 1.33 2002/12/15 19:40:19 skimo Exp $ |
1b64d24d |
2 | |
3 | use ExtUtils::MakeMaker; |
4 | use IO::File; |
5 | use Config; |
6 | use Cwd 'cwd'; |
7bb01969 |
7 | use Getopt::Long; |
1e48c05a |
8 | use File::Copy qw(copy); |
1b64d24d |
9 | |
ffaa0e42 |
10 | @h1 = qw(fastcgi.h fcgiapp.h fcgimisc.h fcgios.h); |
1b64d24d |
11 | @h = (@h1, 'fcgi_config.h'); |
12 | @o = qw(FCGI.o); |
e12d4fb3 |
13 | @dist1 = qw(LICENSE.TERMS); |
1b64d24d |
14 | @dist2 = qw(fcgiapp.c os_unix.c os_win32.c); |
7ef79c64 |
15 | @dist3 = (@h1, qw(fcgi_config_x86.h)); |
1b64d24d |
16 | |
c737f293 |
17 | GetOptions ("pure-perl!" => \$pure, |
1e48c05a |
18 | "use-installed:s" => \$useinstalled); |
cd834ed1 |
19 | $pure = "0" unless defined $pure; |
0833402a |
20 | open(CFG,">FCGI.cfg"); |
21 | print CFG "\$pure = $pure;1;\n"; |
22 | close CFG; |
23 | |
e12d4fb3 |
24 | $libfound = 0; |
c737f293 |
25 | @libs = (); |
e12d4fb3 |
26 | |
e87ca2dd |
27 | if (! $pure) { |
e12d4fb3 |
28 | my $cwd = cwd(); |
29 | my $devkit = "$cwd/.."; |
30 | |
c737f293 |
31 | if (defined $useinstalled) { |
1e48c05a |
32 | require ExtUtils::Liblist; |
33 | my $libspec = $useinstalled ? "-L$useinstalled/lib " : ""; |
34 | $libspec .= "-lfcgi"; |
35 | my @l = MM->ext($libspec); |
36 | if ($l[0] || $l[1] || $l[2]) { |
37 | $prefix = "$useinstalled/include" if $useinstalled; |
38 | $libfound = 1; |
39 | push @libs, $libspec; |
40 | } |
c737f293 |
41 | } |
42 | if (!$libfound && -d "$devkit/libfcgi" && -d "$devkit/include") { |
1e48c05a |
43 | # devkit |
44 | if (grep { ! -f "$devkit/include/$_" } @dist3 |
45 | or grep { ! -f "$devkit/libfcgi/$_" } @dist2) |
46 | { |
47 | warn "This appears to be a FastCGI devkit distribution, " . |
48 | "but one or more FastCGI library files are missing. \n" . |
49 | "Please check the integrity of the distribution.\n"; |
50 | exit -1; |
51 | } |
52 | |
53 | my $extrarules = join "\n", |
54 | map { $b = $_; $b =~ s/\.c$//; my $s="$devkit/libfcgi/$b.c"; |
55 | "$b\$(OBJ_EXT): $s\n\t". |
56 | '$(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) '."$s\n"; } |
57 | @dist2; |
58 | eval 'package MY; sub postamble { $extrarules; }'; |
59 | $prefix = $devkit; |
e12d4fb3 |
60 | } |
1b64d24d |
61 | } |
62 | |
63 | $sys = $^O eq 'MSWin32' ? 'win32' : 'unix'; |
e12d4fb3 |
64 | push @o, "fcgiapp.o", "os_$sys.o" unless $libfound; |
92079298 |
65 | $inc = '-I.' unless $libfound; |
66 | $inc .= " -I$prefix/include" if $prefix; |
1b64d24d |
67 | |
0074e702 |
68 | push(@extras, CAPI => 'TRUE') |
69 | if ($] >= 5.005 and $^O eq 'MSWin32' |
70 | and $Config{archname} =~ /-object\b/i); |
71 | |
72 | push(@extras, |
73 | ABSTRACT => 'Fast CGI module', |
1e48c05a |
74 | AUTHOR => 'Sven Verdoolaege (skimo@kotnet.org)' |
75 | ) |
76 | if ($ExtUtils::MakeMaker::VERSION >= 5.4301); |
77 | |
78 | $plfiles = { |
79 | 'echo.PL' => 'echo.fpl', |
80 | 'remote.PL' => 'remote.fpl', |
81 | 'threaded.PL' => 'threaded.fpl', |
82 | 'FCGI.PL' => 'FCGI.pm', |
83 | }; |
0833402a |
84 | $plfiles->{'FCGI.XL'} = 'FCGI.xs' unless $pure; |
236be38d |
85 | if ($pure) { |
86 | push @extras, |
1e48c05a |
87 | LINKTYPE => ' '; |
236be38d |
88 | } else { |
e87ca2dd |
89 | |
1e48c05a |
90 | if ("$sys" eq "win32") { |
91 | push @libs, ":nosearch -lws2_32"; |
92 | push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)'; |
93 | } |
e87ca2dd |
94 | |
0833402a |
95 | push @extras, |
1e48c05a |
96 | 'LIBS' => [ "@libs" ], |
97 | 'OBJECT' => "@o", |
98 | 'INC' => $inc; |
0833402a |
99 | } |
1e48c05a |
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 |
d81643d2 |
105 | WriteMakefile( |
1e48c05a |
106 | 'NAME' => 'FCGI', |
107 | 'VERSION_FROM' => 'version.pm', |
108 | 'dist' => { |
109 | 'COMPRESS' => 'gzip -9f', |
110 | 'SUFFIX' => 'gz', |
111 | 'PREOP' => '$(CP) '.join(' ', |
112 | map {"../$_"} @dist1, |
113 | (map {"libfcgi/$_"} @dist2), |
114 | map {"include/$_"} @dist3).' $(DISTVNAME);'. |
115 | '$(CP) MANIFEST MANIFEST.old;'. |
116 | 'echo -e '. join('\\\n',@dist1,@dist2,@dist3) . |
117 | '>> $(DISTVNAME)/MANIFEST', |
118 | 'POSTOP' => |
119 | '$(MV) MANIFEST.old MANIFEST', |
120 | }, |
121 | 'clean' => { FILES => 'config.cache fcgi_config.h' . |
122 | ' FCGI.xs FCGI.c FCGI.cfg ' . |
123 | (join ' ', values %$plfiles)}, |
124 | 'PL_FILES' => $plfiles, |
125 | PM => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'}, |
0074e702 |
126 | @extras, |
d81643d2 |
127 | ); |
1b64d24d |
128 | |
e12d4fb3 |
129 | exit if -f 'fcgi_config.h' or $libfound or $pure; |
1b64d24d |
130 | |
131 | # CPAN and no installed lib found |
132 | if ($sys eq "win32") { |
133 | # configure will almost certainly not run on a normal NT install, |
134 | # use the pregenerated configuration file |
135 | |
136 | print "Using prebuilt fcgi_config.h file for Windows\n"; |
137 | unlink("fcgi_config.h"); |
18c10cb1 |
138 | my $confdir = $prefix ? "$prefix/include/" : ''; |
aff18d25 |
139 | die $! unless copy("${confdir}fcgi_config_x86.h","fcgi_config.h"); |
e87ca2dd |
140 | |
141 | # Win can't deal with existence of FCGI.xs or absence of FCGI.c |
142 | unlink("FCGI.xs"); |
143 | open(F, ">FCGI.c"); close(F); |
144 | $now = time; $before = $now - 600; |
145 | utime $before, $before, "FCGI.c"; |
146 | utime $now, $now, "FCGI.PL"; |
1b64d24d |
147 | } else { |
148 | print "Running ./configure for you\n"; |
6ef7789b |
149 | print "Please read configure.readme for information on how to run it yourself\n"; |
1b64d24d |
150 | |
151 | $ENV{'CC'} = $Config{'cc'}; |
d4b5dccc |
152 | system("$Config{sh} configure"); |
1b64d24d |
153 | } |
1e48c05a |
154 | |