27a45e87cf74947c5c349d944e1f1b116832caf5
[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 ("use-installed:s" => \$useinstalled);
18
19 $libfound = 0;
20 @libs = ();
21
22 my $cwd = cwd();
23 my $devkit = "$cwd/..";
24
25 if (defined $useinstalled) {
26     require ExtUtils::Liblist;
27     my $libspec = $useinstalled ? "-L$useinstalled/lib " : "";
28     $libspec .= "-lfcgi";
29     my @l = MM->ext($libspec);
30     if ($l[0] || $l[1] || $l[2]) {
31         $prefix = "$useinstalled/include" if $useinstalled;
32         $libfound = 1;
33         push @libs, $libspec;
34     }
35 }
36 if (!$libfound && -d "$devkit/libfcgi" && -d "$devkit/include") {
37     # devkit
38     if (grep { ! -f "$devkit/include/$_" } @dist3 
39         or grep { ! -f "$devkit/libfcgi/$_" } @dist2)
40     {
41         warn "This appears to be a FastCGI devkit distribution, " .
42             "but one or more FastCGI library files are missing. \n" .
43             "Please check the integrity of the distribution.\n";
44         exit -1;
45     }
46
47     my $extrarules = join "\n",
48         map { $b = $_; $b =~ s/\.c$//; my $s="$devkit/libfcgi/$b.c";
49             "$b\$(OBJ_EXT): $s\n\t".
50             '$(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) '."$s\n"; }
51             @dist2;
52     eval 'package MY; sub postamble { $extrarules; }';
53     $prefix = $devkit;
54 }
55
56
57 $sys = $^O eq 'MSWin32' ? 'win32' : 'unix';
58 push @o, "fcgiapp.o", "os_$sys.o" unless $libfound;
59 $inc = '-I.' unless $libfound;
60 $inc .= " -I$prefix/include" if $prefix;
61
62 push(@extras, CAPI => 'TRUE')
63      if ($] >= 5.005 and $^O eq 'MSWin32'
64         and $Config{archname} =~ /-object\b/i);
65
66 push(@extras,
67     ABSTRACT => 'Fast CGI module',
68     AUTHOR   => 'Sven Verdoolaege (skimo@kotnet.org)'
69 ) if ($ExtUtils::MakeMaker::VERSION >= 5.4301);
70
71 push @extras, META_MERGE => {
72     resources => {
73         repository => 'git://git.shadowcat.co.uk/catagits/fcgi2.git',
74     },
75 } if $ExtUtils::MakeMaker::VERSION >= 6.46;
76
77 $plfiles = {
78     'echo.PL' => 'echo.fpl',
79     'remote.PL' => 'remote.fpl',
80     'threaded.PL' => 'threaded.fpl',
81     'FCGI.PL' => 'FCGI.pm',
82 };
83
84 if ("$sys" eq "win32") {
85     push @libs, ":nosearch -lws2_32";
86     push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)';
87 }
88
89 push @extras,
90     'LIBS'    => [ "@libs" ],
91     'OBJECT'    => "@o",
92     'INC'    => $inc;
93
94 # See lib/ExtUtils/MakeMaker.pm for details of how to influence
95 # the contents of the Makefile that is written.
96
97 # Work around bug in previous versions of MakeMaker
98 WriteMakefile(
99     'NAME'        => 'FCGI',
100     'VERSION_FROM'    => 'version.pm',
101     'dist' => {
102         'COMPRESS' => 'gzip -9f',
103         'SUFFIX' => 'gz',
104         'PREOP' => '$(CP) '.join(' ',
105             map {"../$_"} @dist1,
106             (map {"libfcgi/$_"} @dist2),
107             map {"include/$_"} @dist3).' $(DISTVNAME);'.
108                 '$(CP) MANIFEST MANIFEST.old;'.
109                 '$(ECHO) '. join('\\\n',@dist1,@dist2,@dist3) .
110                 '>> $(DISTVNAME)/MANIFEST',
111                   'POSTOP' => 
112                 '$(MV) MANIFEST.old MANIFEST',
113     },
114     'clean'        => { FILES => 'config.cache fcgi_config.h' .
115                       ' FCGI.c ' .
116                       (join ' ', values %$plfiles)},
117     'PL_FILES'        => $plfiles,
118     PM            => {'FCGI.pm' => '$(INST_ARCHLIBDIR)/FCGI.pm'},
119     @extras,
120 );
121
122 exit if -f 'fcgi_config.h' or $libfound;
123
124 # CPAN and no installed lib found
125 if ($sys eq "win32") {
126     # configure will almost certainly not run on a normal NT install,
127     # use the pregenerated configuration file
128
129     print "Using prebuilt fcgi_config.h file for Windows\n";
130     unlink("fcgi_config.h");
131     my $confdir = $prefix ? "$prefix/include/" : '';
132     die $! unless copy("${confdir}fcgi_config_x86.h","fcgi_config.h");
133 } else {
134     print "Running ./configure for you\n";
135     print "Please read configure.readme for information on how to run it yourself\n";
136
137     $ENV{'CC'} = $Config{'cc'};
138     system("$Config{sh} configure");
139 }
140