Add repository to meta resources
[catagits/fcgi2.git] / perl / Makefile.PL
1 # $Id: Makefile.PL,v 1.33 2002/12/15 19:40:19 skimo Exp $
2
3 use ExtUtils::MakeMaker;
4 use IO::File;
5 use Config;
6 use Cwd 'cwd';
7 use Getopt::Long;
8 use File::Copy qw(copy);
9
10 @h1 = qw(fastcgi.h fcgiapp.h fcgimisc.h fcgios.h);
11 @h = (@h1, 'fcgi_config.h');
12 @o = qw(FCGI.o);
13 @dist1 = qw(LICENSE.TERMS);
14 @dist2 = qw(fcgiapp.c os_unix.c os_win32.c);
15 @dist3 = (@h1, qw(fcgi_config_x86.h));
16
17 GetOptions ("pure-perl!" => \$pure,
18         "use-installed:s" => \$useinstalled);
19 $pure = "0" unless defined $pure;
20 open(CFG,">FCGI.cfg");
21 print CFG "\$pure = $pure;1;\n";
22 close CFG;
23
24 $libfound = 0;
25 @libs = ();
26
27 if (! $pure) {
28     my $cwd = cwd();
29     my $devkit = "$cwd/..";
30
31     if (defined $useinstalled) {
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     }
41     }
42     if (!$libfound && -d "$devkit/libfcgi" && -d "$devkit/include") {
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;
60     }
61 }
62
63 $sys = $^O eq 'MSWin32' ? 'win32' : 'unix';
64 push @o, "fcgiapp.o", "os_$sys.o" unless $libfound;
65 $inc = '-I.' unless $libfound;
66 $inc .= " -I$prefix/include" if $prefix;
67
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',
74     AUTHOR   => 'Sven Verdoolaege (skimo@kotnet.org)'
75 )
76     if ($ExtUtils::MakeMaker::VERSION >= 5.4301);
77
78 push @extras, META_MERGE => {
79     resources => {
80         repository => 'git://git.shadowcat.co.uk/catagits/fcgi2.git',
81     },
82 } if $ExtUtils::MakeMaker::VERSION >= 6.46;
83
84 $plfiles = {
85     'echo.PL' => 'echo.fpl',
86     'remote.PL' => 'remote.fpl',
87     'threaded.PL' => 'threaded.fpl',
88     'FCGI.PL' => 'FCGI.pm',
89 };
90 $plfiles->{'FCGI.XL'} = 'FCGI.xs' unless $pure;
91 if ($pure) {
92     push @extras,
93     LINKTYPE => ' ';
94 } else {
95
96     if ("$sys" eq "win32") {
97         push @libs, ":nosearch -lws2_32";
98         push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)';
99     }
100
101     push @extras,
102         'LIBS'    => [ "@libs" ],
103         'OBJECT'    => "@o",
104         'INC'    => $inc;
105 }
106
107 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
108 # the contents of the Makefile that is written.
109
110 # Work around bug in previous versions of MakeMaker
111 WriteMakefile(
112     'NAME'        => 'FCGI',
113     'VERSION_FROM'    => 'version.pm',
114     'dist' => {
115         'COMPRESS' => 'gzip -9f',
116         'SUFFIX' => 'gz',
117         'PREOP' => '$(CP) '.join(' ',
118             map {"../$_"} @dist1,
119             (map {"libfcgi/$_"} @dist2),
120             map {"include/$_"} @dist3).' $(DISTVNAME);'.
121                 '$(CP) MANIFEST MANIFEST.old;'.
122                 'echo -e '. join('\\\n',@dist1,@dist2,@dist3) .
123                 '>> $(DISTVNAME)/MANIFEST',
124                   'POSTOP' => 
125                 '$(MV) MANIFEST.old MANIFEST',
126     },
127     'clean'        => { FILES => 'config.cache fcgi_config.h' .
128                       ' FCGI.xs FCGI.c FCGI.cfg ' .
129                       (join ' ', values %$plfiles)},
130     'PL_FILES'        => $plfiles,
131     PM            => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'},
132     @extras,
133 );
134
135 exit if -f 'fcgi_config.h' or $libfound or $pure;
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
142     print "Using prebuilt fcgi_config.h file for Windows\n";
143     unlink("fcgi_config.h");
144     my $confdir = $prefix ? "$prefix/include/" : '';
145     die $! unless copy("${confdir}fcgi_config_x86.h","fcgi_config.h");
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";
153 } else {
154     print "Running ./configure for you\n";
155     print "Please read configure.readme for information on how to run it yourself\n";
156
157     $ENV{'CC'} = $Config{'cc'};
158     system("$Config{sh} configure");
159 }
160