#  Copyright (c) 1997-2007
#  Ewgenij Gawrilow, Michael Joswig (Technische Universitaet Berlin, Germany)
#  http://www.math.tu-berlin.de/polymake,  mailto:polymake@math.tu-berlin.de
#
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the
#  Free Software Foundation; either version 2, or (at your option) any
#  later version: http://www.gnu.org/licenses/gpl.txt.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#-----------------------------------------------------------------------------
# $Project: polymake $$Id: Makefile.PL 7546 2007-01-08 16:34:56Z gawrilow $

my %broken;
if (-d "$ENV{TOP}/perl/ext/.svn") {
   local $/="\n";
   open SVN, "svn propget -R noexport $ENV{TOP}/perl/ext |";
   while (<SVN>) {
      if (m{([^/]+) - broken}) {
	 $broken{$1}=1;
      }
   }
   close SVN;
}

my @sources=grep { !$broken{$_} } map { m{([^/]+)$} } glob "$ENV{TOP}/perl/ext/*.{xs,h,PL}";

my $changed=!-f "Makefile";
opendir D, ".";
foreach (readdir D) {
   if (-l $_ and !-f $_ || $broken{$_}) {
      unlink $_ or die "can't remove obsolete link $_: $!\n";
      $changed=1;
   }
}
closedir D;
foreach (@sources) {
   unless (-l $_) {
      symlink "$ENV{TOP}/perl/ext/$_", $_  or  die "can't create link to $_: $!\n";
      $changed=1;
   }
}
exit 0 unless $changed;

open M, ">MANIFEST";
print M <<'.', map { "$_\n" } @sources;
MANIFEST
.
close M;

use ExtUtils::MakeMaker;

sub MY::makefile {
   package MY;
   my $text=shift->SUPER::makefile(@_);
   $text =~ s{^ .* ==> .* <== (?s: .* $ )}{}xmg;
   $text =~ s{(?= \$\(PERLRUN\) \s+ Makefile)}{TOP=$ENV{TOP} }x;
   $text .= <<'.';
	$(NOECHO) $(MAKE)
.
}

WriteMakefile(
    NAME	=> 'Poly::Ext',
    LDFROM	=> '$(O_FILES)',
    dynamic_lib => { INST_DYNAMIC_DEP => '$(O_FILES)' },
    LIBS	=> [''],   # e.g., '-lm'
    DEFINE	=> '',     # e.g., '-DHAVE_SOMETHING'
    INC		=> '',     # e.g., '-I/usr/include/other'
    macro	=> { InstallTop => $ENV{TOP} },
    LIB		=> "\$(InstallDir)/perlx/$Config::Config{version}",
    MAN3PODS	=> { },
);


# Local Variables:
# mode: perl
# c-basic-offset:3
# End:


syntax highlighted by Code2HTML, v. 0.9.1