# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
# $Id: Portfile 105677 2013-05-01 17:05:36Z macsforever2000@macports.org $

PortSystem          1.0
PortGroup           perl5 1.0

perl5.branches      5.12 5.14 5.16
perl5.setup         Ifeffit 1.0
set ifeffit_version 1.2.11c

platforms           darwin
license             Permissive
maintainers         macsforever2000

description         perl interface to ifeffit

long_description    ${description}

master_sites        http://sourceforge.net/projects/ifeffit/files/ifeffit/${ifeffit_version}/

distname            ifeffit-${ifeffit_version}
dist_subdir         ifeffit

checksums           rmd160  f4eb038193f65570dcbad65b43520291899d5372 \
                    sha256  dbeac0485b42edb2f23d45500b08ce8db8ba80c8ec17540ff8717203d23422c0

worksrcdir          ${distname}/wrappers/perl

if {${perl5.major} != ""} {
    depends_lib-append  port:ifeffit

    post-extract {
        # Copy ifeffit Makefile.PL because it is closer to correct than the default one
        file copy -force ${prefix}/share/ifeffit/config/Makefile.PL \
            ${worksrcpath}/Makefile.PL
    }

    post-patch {
        # Fix the location of the ifeffit library
        #             -lifeffit /opt/local/var/macports/build/_opt_mports_trunk_dports_science_ifeffit/ifeffit/work/ifeffit-1.2.11c/src/pgstub/libnopgplot.a
        reinplace -E "s|-lifeffit .+libnopgplot\.a|-lifeffit -lnopgplot|g" ${worksrcpath}/Makefile.PL
    }
    
    post-configure {
        # Need to patch the generated Makefile due to strange bug
        reinplace "s|^PERL_ARCHIVE *= *$|PERL_ARCHIVE = \$(PERL_INC)/libperl.dylib|" ${worksrcpath}/Makefile
    }
}
