# $Id: Portfile 52577 2009-06-19 04:31:40Z eridius@macports.org $

PortSystem 1.0
PortGroup select 1.0

name                    python24
version                 2.4.6
revision                4
set major               [lindex [split $version .] 0]
set branch              [join [lrange [split ${version} .] 0 1] .]
categories              lang
platforms               darwin
maintainers             nomaintainer

description             An interpreted, object-oriented programming language
long_description        Python is an interpreted, interactive, object-oriented \
                        programming language.

homepage                http://www.python.org/
master_sites            ${homepage}/ftp/python/${version}/ \
                        ftp://ftp.python.org/pub/python/${version}/ \
                        ftp://ftp.fastorama.com/mirrors/ftp.python.org/pub/python/${version}/ \
                        ftp://ftp.python.jp/pub/python/${version}/

distname                Python-${version}
use_bzip2               yes

checksums               md5     76083277f6c7e4d78992f36d7ad9018d \
                        sha1    cb1972a554a458f6a26d3e047b359251865d7c96 \
                        rmd160  0687989193dec2ac108142759281be7ddcf7f31e

patchfiles              patch-configure \
                        patch-Makefile.pre.in \
                        patch-Lib-cgi.py \
                        patch-Lib-site.py \
                        patch-setup.py \
                        patch-Include-pyport.h \
                        patch-Mac-OSX-Makefile.in \
                        patch-Mac-OSX-IDLE-Makefile.in \
                        patch-Mac-OSX-PythonLauncher-Makefile.in

depends_lib             port:gettext

configure.compiler gcc-4.0

configure.args          --with-cxx=${configure.cxx} \
                        --enable-shared \
                        --enable-framework=${frameworks_dir} \
                        --mandir=${prefix}/share/man \
                        --without-readline \
                        --disable-tk \
                        --enable-ipv6

use_parallel_build      no

post-patch {
    reinplace "s|__PREFIX__|${prefix}|g" ${worksrcpath}/Lib/cgi.py \
        ${worksrcpath}/Lib/site.py ${worksrcpath}/setup.py
    reinplace "s|__FRAMEWORKS_DIR__|${frameworks_dir}|g" \
        ${worksrcpath}/Mac/OSX/Makefile.in
    reinplace "s|__APPLICATIONS_DIR__|${applications_dir}|g" \
        ${worksrcpath}/Mac/OSX/IDLE/Makefile.in \
        ${worksrcpath}/Mac/OSX/Makefile.in \
        ${worksrcpath}/Mac/OSX/PythonLauncher/Makefile.in
}

build.target            all

# Workaround for case-sensitive file systems
post-build {
    if { ![file exists ${worksrcpath}/python.exe] } {
        ln -s python ${worksrcpath}/python.exe
    }
}

test.run                yes
test.target             test

destroot.target         frameworkinstall maninstall

select.group            python
select.file             ${filespath}/python[string map {. {}} ${branch}]

platform macosx {
    post-destroot {
        set framewpath ${frameworks_dir}/Python.framework
        set framewdir  ${framewpath}/Versions/${branch}

        foreach dir { lib include } {
            file rename ${destroot}${framewdir}/${dir}/python${branch} ${destroot}${prefix}/${dir}
            ln -s ${prefix}/${dir}/python${branch} ${destroot}${framewdir}/${dir}/python${branch}
        }
        # Since the lib/python${branch} dir was just moved above and
        # libpython2.4.a in lib/python${branch}/config is relative, we need
        # to repoint it here
        file delete ${destroot}${prefix}/lib/python${branch}/config/libpython${branch}.a
        ln -s ${framewdir}/Python ${destroot}${prefix}/lib/python${branch}/config/libpython${branch}.a

        ln -s ${framewdir}/Python ${destroot}${prefix}/lib/libpython${branch}.dylib

        file rename ${destroot}${prefix}/share/man/man1/python.1 ${destroot}${prefix}/share/man/man1/python${branch}.1

        # delete symlinks without version suffix, use python_select instead to choose version
        foreach bin { python pythonw idle pydoc smtpd.py } {
            file delete ${destroot}${prefix}/bin/${bin}
        }
        foreach bin [list python${branch} pythonw${branch} idle${branch} pydoc${branch} smtpd${branch}.py] {
            file rename -force ${destroot}${framewdir}/bin/${bin} ${destroot}${prefix}/bin
            ln -s ${prefix}/bin/${bin} ${destroot}${framewdir}/bin/${bin}
        }

        foreach dir { Headers Resources Python Versions/Current } {
            file delete ${destroot}${framewpath}/${dir}
        }

        # Without this, LINKFORSHARED is set to
        # ... $(PYTHONFRAMEWORKDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)
        # (this becomes Python.framework/Versions/2.4/Python) which doesn't
        # quite work (see ticket #15099); instead specifically list the
        # full path to the proper Python framework file (which becomes
        # ${prefix}/Library/Frameworks/Python.framework/Versions/2.4/Python)
        reinplace {s|^\(LINKFORSHARED=.*\)$(PYTHONFRAMEWORKDIR).*$|\1 $(PYTHONFRAMEWORKINSTALLDIR)/Versions/$(VERSION)/$(PYTHONFRAMEWORK)|} ${destroot}${prefix}/lib/python${branch}/config/Makefile
    }
}

post-activate {
    ui_msg "\nTo fully complete your installation and make python $branch the default, please run
\n\tsudo port install python_select \
\n\tsudo python_select $name\n"
}

platform darwin {
    post-configure {
        # See http://trac.macports.org/ticket/18376
        system "cd ${worksrcpath} && ed - pyconfig.h < ${filespath}/pyconfig.ed"
    }
}

platform darwin 9 {
    configure.cppflags-append       -D__DARWIN_UNIX03
}

platform darwin 10 {
    configure.cppflags-append       -D__DARWIN_UNIX03
}

platform puredarwin {
    configure.args-delete   --enable-framework=${frameworks_dir}
    configure.args-append   --disable-toolbox-glue --disable-framework
    destroot.target         install maninstall

    post-destroot {
        # delete symlinks without version suffix, use python_select instead to choose version
        foreach bin { python pythonw idle pydoc smtpd.py python-config } {
            file delete ${destroot}${prefix}/bin/${bin}
        }

        file rename ${destroot}${prefix}/share/man/man1/python.1 ${destroot}${prefix}/share/man/man1/python${branch}.1

        # install select file for python_select
        xinstall -m 755 -d ${destroot}${prefix}/etc/select/python
        xinstall -m 644 ${filespath}/python[string map {. {}} ${branch}] ${destroot}${prefix}/etc/select/python/
    }
}

variant universal {
   if {[info exists universal_sysroot]} {
      configure.args-append   --enable-universalsdk=${universal_sysroot}
   } else {
      if {${macosx_version} == "10.4"} {
         configure.args-append   --enable-universalsdk=/Developer/SDKs/MacOSX${macosx_version}u.sdk
      } else {
         configure.args-append   --enable-universalsdk=/Developer/SDKs/MacOSX${macosx_version}.sdk
      }
   }
}

livecheck.check         regex
livecheck.url           ${homepage}download/releases/
livecheck.regex         Python (${branch}.\[0-9\]+)

