# $Id: Portfile 28540 2007-09-03 11:42:45Z mww@macports.org $

PortSystem 1.0
name            g95
version         0.90
revision        2
platforms       darwin
categories      lang
maintainers     takeshi@mac.com
description     Another GNU Fortran 95 compiler
long_description \
                G95 is a stable, production Fortran 95 compiler \
                available for multiple cpu architectures and operating systems. \
                Innovations and optimizations continue to be worked on. \
                Parts of the F2003 standard have been implemented in g95.
homepage        http://g95.org/
master_sites    ftp://gcc.gnu.org/pub/gcc/releases/gcc-4.0.3/:gcc \
                ftp://anonymous%%40g95%%2Eorg:none@ftp.g95.org/v0.9/:g95

set version_gcc 4.0.3
set dcore       gcc-core-${version_gcc}.tar.gz
set dg95        ${name}_source.tgz
set gcclib      lib/gcc-lib/${os.arch}-apple-${os.platform}${os.version}/${version_gcc}
distfiles       ${dcore}:gcc ${dg95}:g95

checksums       ${dcore} sha1 2694281fa05ae0e39cd871fcc52745e35a2dfefc \
                ${dg95}  sha1 1f8d30fd39f8f23a71030802405e23abcc8a00b4

depends_lib     port:odcctools

patchfiles      patch-Makefile.in

universal_variant no

pre-configure {
    file mkdir ${workpath}/gcc-${version_gcc}/${name}
    if {[variant_isset darwin_9]} {
        set gcc_configargs "--with-as=/usr/bin/as --with-ld=/usr/bin/ld --with-nm=/usr/bin/nm"
		} else {
        reinplace "s|/usr/bin/libtool|${prefix}/bin/odlibtool|" ${workpath}/gcc-${version_gcc}/gcc/config/darwin.h
        set gcc_configargs "--with-as=${prefix}/bin/odas --with-ld=${prefix}/bin/odld --with-nm=${prefix}/bin/odnm"
	  }
    system "unset CPPFLAGS; unset LDFLAGS; \
            cd ${workpath}/gcc-${version_gcc}/${name}; \
            ../configure --prefix=${prefix}/${gcclib} \
            --enable-languages=c ${gcc_configargs} --with-included-gettext; \
            make"
}

configure.cppflags	""
configure.ldflags	""
configure.args  --with-gcc-dir=${workpath}/gcc-${version_gcc}

post-build {
    system "cd ${worksrcpath}; tar zxvf libf95.a-${version}.tar.gz; \
           cd libf95.a-${version}; \
           ./configure --prefix=${prefix}; \
           make"
}

pre-destroot {
    reinplace "s|${prefix}/${gcclib}|${destroot}${prefix}/${gcclib}|g" ${worksrcpath}/Makefile
    reinplace "s|${prefix}/${gcclib}|${destroot}${prefix}/${gcclib}|g" ${worksrcpath}/libf95.a-${version}/Makefile
}

destroot {
    system "cd ${worksrcpath}; \
           make install prefix=${destroot}${prefix}; \
           cd libf95.a-${version}; \
           make install prefix=${destroot}${prefix}; \
           ranlib ${destroot}${prefix}/${gcclib}/libf95.a; \
           ranlib ${destroot}${prefix}/${gcclib}/libgcc.a; \
           ranlib ${destroot}${prefix}/${gcclib}/libgcc_eh.a"
    file mkdir ${destroot}${prefix}/share/doc/${name}
    file rename ${destroot}${prefix}/G95Manual.pdf ${destroot}${prefix}/share/doc/${name}
    system "ln -sf ${prefix}/${gcclib}/libf95.a ${destroot}${prefix}/lib/libf95.a"
    file mkdir ${destroot}${prefix}/${gcclib}/lib
    system "ln -sf ${prefix}/${gcclib}/libgcc_s.1.0.dylib ${destroot}${prefix}/${gcclib}/lib/libgcc_s.1.0.dylib"
    system "ln -sf ${prefix}/${gcclib}/libgcc_s.1.0.dylib ${destroot}${prefix}/${gcclib}/lib/libgcc_s.dylib"
}

platform darwin 9 {
    patchfiles-append patch-host-darwin.c patch-darwin-fallback.c
    depends_lib-delete port:odcctools
}
