Add LIBFCGI_EXPORTS to defines
[catagits/fcgi2.git] / perl / Makefile.PL
index 5c5beed..a7deac4 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: Makefile.PL,v 1.16 2001/08/30 02:52:22 robs Exp $
+# $Id: Makefile.PL,v 1.32 2001/09/27 12:11:40 skimo Exp $
 
 use ExtUtils::MakeMaker;
 use IO::File;
@@ -9,63 +9,60 @@ use Getopt::Long;
 @h1 = qw(fastcgi.h fcgiapp.h fcgimisc.h fcgios.h);
 @h = (@h1, 'fcgi_config.h');
 @o = qw(FCGI.o);
-@dist1 = qw(LICENSE.TERMS acconfig.h);
+@dist1 = qw(LICENSE.TERMS);
 @dist2 = qw(fcgiapp.c os_unix.c os_win32.c);
-@dist3 = (@h1, qw(fcgi_config.h.in fcgi_config_x86.h));
+@dist3 = (@h1, qw(fcgi_config_x86.h));
 
-GetOptions ("pure-perl!" => \$pure);
-$pure = 
-    (prompt("Do you want to use the pure perl implementation", "no") =~ /^y/) 
-    ? "1" : "0" unless defined $pure;
+GetOptions ("pure-perl!" => \$pure,
+           "use-installed:s" => \$useinstalled);
+$pure = "0" unless defined $pure;
 open(CFG,">FCGI.cfg");
 print CFG "\$pure = $pure;1;\n";
 close CFG;
 
+$libfound = 0;
+@libs = ();
+
 if (! $pure) {
-       my $cwd = cwd();
-       my $devkit = "$cwd/..";
-
-       if (-d "$devkit/libfcgi" && -d "$devkit/include") {
-               # devkit
-               if (grep { ! -f "$devkit/include/$_" } @dist3 
-                       or grep { ! -f "$devkit/libfcgi/$_" } @dist2)
-               {
-                       warn "This appears to be a FastCGI devkit distribution, " .
-                                "but one or more FastCGI library files are missing. \n" .
-                                "Please check the integrity of the distribution.\n";
-                       exit -1;
-               }
-
-               # Copy the C lib files down to ensure a compatible build.
-               print "Copying C library files from the devkit distribution\n";
-           use File::Copy qw(copy);
-
-               # TODO: stop or save if a local file has been modified
-               foreach (@dist3, @dist2) { unlink };
-               foreach (@dist3) { copy("$devkit/include/$_", ".") || die $! };
-               foreach (@dist2)  { copy("$devkit/libfcgi/$_", ".") || die $! };
+    my $cwd = cwd();
+    my $devkit = "$cwd/..";
+
+    if (defined $useinstalled) {
+       require ExtUtils::Liblist;
+       my $libspec = $useinstalled ? "-L$useinstalled/lib " : "";
+       $libspec .= "-lfcgi";
+       my @l = MM->ext($libspec);
+       if ($l[0] || $l[1] || $l[2]) {
+           $prefix = "$useinstalled/include" if $useinstalled;
+           $libfound = 1;
+           push @libs, $libspec;
        }
-       else {
-           # CPAN  
-           for $dir ("/usr", "/usr/local") {
-               if (-d "$dir/lib/" && -f "$dir/lib/libfcgi.a" 
-                       && -d "$dir/include" && !grep {!-f "$dir/include/$_"} (@h)) 
-               {
-                   print "Found fcgi library and include files in $dir\n";
-                   print "Will be using those instead of the included files\n";
-                   print "Edit Makefile.PL if you don't like it\n";
-                   
-                   $prefix = $dir;
-                   push @libs, "-L$dir/lib -lfcgi"; 
-                   last;
-               }
-           }
+    }
+    if (!$libfound && -d "$devkit/libfcgi" && -d "$devkit/include") {
+       # devkit
+       if (grep { ! -f "$devkit/include/$_" } @dist3 
+               or grep { ! -f "$devkit/libfcgi/$_" } @dist2)
+       {
+               warn "This appears to be a FastCGI devkit distribution, " .
+                    "but one or more FastCGI library files are missing. \n" .
+                    "Please check the integrity of the distribution.\n";
+               exit -1;
        }
+
+       my $extrarules = join "\n", 
+           map { $b = $_; $b =~ s/\.c$//; my $s="$devkit/libfcgi/$b.c"; 
+                 "$b\$(OBJ_EXT): $s\n\t".
+                 '$(CCCMD) $(CCCDLFLAGS) -I$(PERL_INC) $(DEFINE) '."$s\n"; }
+               @dist2;
+       eval 'package MY; sub postamble { $extrarules; }';
+       $prefix = $devkit;
+    }
 }
 
 $sys = $^O eq 'MSWin32' ? 'win32' : 'unix';
-push @o, "fcgiapp.o", "os_$sys.o" unless $prefix;
-$inc = $prefix ? "-I$prefix/include" : '-I.';
+push @o, "fcgiapp.o", "os_$sys.o" unless $libfound;
+$inc = '-I.' unless $libfound;
+$inc .= " -I$prefix/include" if $prefix;
 
 push(@extras, CAPI => 'TRUE')
      if ($] >= 5.005 and $^O eq 'MSWin32'
@@ -88,12 +85,12 @@ if ($pure) {
 } else {
 
        if ("$sys" eq "win32") {
-               @libs = (@libs) ? map { "$_ ws2_32.lib" } @libs : ('ws2_32.lib');
+               push @libs, ":nosearch -lws2_32";
                push @extras, 'DEFINE' => '-DDLLAPI=__declspec(dllexport)';
        }
 
     push @extras,
-       'LIBS'  => [ @libs ],
+       'LIBS'  => [ "@libs" ],
        'OBJECT'        => "@o",
        'INC'   => $inc;
 }
@@ -107,7 +104,7 @@ WriteMakefile(NAME => 'FCGI')
 
 $mm = MM->new({
     'NAME'             => 'FCGI',
-    'VERSION_FROM'     => 'FCGI.PL',
+    'VERSION_FROM'     => 'version.pm',
     'dist'             => { 'COMPRESS' => 'gzip -9f', 
                             'SUFFIX' => 'gz',
                             'PREOP' => '$(CP) '.join(' ',
@@ -131,7 +128,7 @@ $mm = MM->new({
 delete $mm->{MAN3PODS}{oldinterface.pod};
 $mm->flush;
 
-exit if -f 'fcgi_config.h' or $prefix or $pure;
+exit if -f 'fcgi_config.h' or $libfound or $pure;
 
 # CPAN and no installed lib found
 if ($sys eq "win32") {
@@ -141,7 +138,8 @@ if ($sys eq "win32") {
     use File::Copy qw(copy);
     print "Using prebuilt fcgi_config.h file for Windows\n";
     unlink("fcgi_config.h");
-    die $! unless copy("fcgi_config_x86.h","fcgi_config.h");
+    my $confdir = $prefix ? "$prefix/include/" : '';
+    die $! unless copy("$confdir/fcgi_config_x86.h","fcgi_config.h");
 
     # Win can't deal with existence of FCGI.xs or absence of FCGI.c
     unlink("FCGI.xs");
@@ -154,5 +152,5 @@ if ($sys eq "win32") {
     print "Please read configure.readme for information on how to run it yourself\n";
 
     $ENV{'CC'} = $Config{'cc'};
-    system("./configure");
+    system("$Config{sh} configure");
 }