#  Copyright (c) 1997-2004
#  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,v 1.11 2004/12/09 21:54:57 gawrilow Exp $

my @sources=map { m|([^/]+)$| } glob "$ENV{TOP}/perl/ext/*.{xs,h,PL}";
my $changed=!-f "Makefile";
opendir D, ".";
foreach (readdir D) {
   if (-l $_ && !-f $_) {
      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		=> '$(InstallTop)/perlx',
    MAN3PODS	=> { },
);


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