# $Id: Portfile 68432 2010-06-03 13:17:40Z jmr@macports.org $

PortSystem          1.0

name                MacPorts
version             1.9.0-rc2

categories          sysutils
platforms           darwin freebsd
maintainers         lists.macosforge.org:macports-mgr

description         The MacPorts Infrastructure
long_description \
   MacPorts provides the infrastructure that allows easy installation and \
   management of freely available software on Mac OS X 10.4 or newer systems.

homepage            http://www.macports.org/
master_sites        macports_distfiles
# testing subdir is for non-final releases only
dist_subdir         ${name}/testing
use_bzip2           yes

checksums           md5     5c90f52a7d8338a1dc6e6450c3340619 \
                    sha1    7707503e141140519a25a2e873df46e43dac1e9c \
                    rmd160  19a2bc179b3997f04b24d973affc5995f0711fa9

variant keep_prefix description "Use configured prefix instead of enforcing /opt/local" {}
if {![variant_isset keep_prefix]} {
    prefix          /opt/local
}

# Readline is disabled by default to avoid support issues with people who
# have a readline in /usr/local. Since this portfile is presumably used in a
# clean environment, enable it here.
configure.args      --enable-readline

# we don't want to use anything supplied by ports when building macports itself
configure.env       PATH=/usr/bin:/bin:/usr/sbin:/sbin

# Some of MacPort's default flags don't play well when we're building
# MacPorts itself: nuke them
configure.cppflags
configure.ldflags

if {[info exists configure.cc_archflags]} {
    configure.cc_archflags
    configure.objc_archflags
}
if {[info exists configure.ld_archflags]} {
    configure.ld_archflags
}
if {[info exists compiler.cpath]} {
    compiler.cpath
    compiler.library_path
}

# MacPorts' configure removes ${prefix}/bin from $PATH,
# so better do not use ccache to avoid problems
configure.ccache no

post-destroot {
    # only install .default versions of config files
    delete ${destroot}${prefix}/etc/macports/macports.conf
    delete ${destroot}${prefix}/etc/macports/sources.conf
    delete ${destroot}${prefix}/etc/macports/variants.conf
}

set resources_scripts ${workpath}/${name}-${version}.pkg/Contents/Resources
set resources_lang ${workpath}/${name}-${version}.pkg/Contents/Resources

post-pkg {
    global resources_scripts resources_lang
    if {[file exists ${resources_scripts}/English.lproj]} {
        set resources_lang ${resources_scripts}/English.lproj
    }
    file copy -force -- ${worksrcpath}/portmgr/dmg/ReadMe.rtf ${resources_lang}
    file copy -force -- ${worksrcpath}/portmgr/dmg/License.html ${resources_lang}
    file copy -force -- ${worksrcpath}/portmgr/dmg/postflight ${resources_scripts}
    file copy -force -- ${worksrcpath}/portmgr/dmg/InstallationCheck ${resources_scripts}
    file copy -force -- ${worksrcpath}/portmgr/dmg/InstallationCheck.strings ${resources_lang}
    file copy -force -- ${worksrcpath}/src/dep_map_clean.tcl ${resources_scripts}
    file copy -force -- ${worksrcpath}/src/upgrade_sources_conf_default.tcl ${resources_scripts}
    
    reinplace "s|__PREFIX__|${prefix}|g" \
              ${resources_scripts}/InstallationCheck \
              ${resources_scripts}/postflight \
              ${resources_lang}/ReadMe.rtf
}

platform darwin 7 {
    pre-fetch {
        return -code error "$name $version does not work on Panther."
    }
}

platform darwin 8 {
    post-pkg {
        global resources_scripts resources_lang
        reinplace "s|is built|contains a Universal installer|" ${resources_lang}/ReadMe.rtf
        reinplace "s|__XVERS__|10.4|" ${resources_lang}/ReadMe.rtf \
            ${resources_lang}/InstallationCheck.strings
        reinplace "s|or newer ||" ${resources_lang}/Welcome.html
        reinplace "s|__DARWINVERS__|8|" ${resources_scripts}/InstallationCheck
    }
}

platform darwin 8 powerpc {
    pre-configure {
        set sdkrootpath /Developer/SDKs/MacOSX10.4u.sdk
        if {[file exists ${sdkrootpath}]} {
            # User has Universal SDK installed.
            set tclstubpath /System/Library/Frameworks/Tcl.framework/Versions/8.4/libtclstub8.4.a
            if {![file exists ${sdkrootpath}${tclstubpath}]} {
                ui_msg "Fixing your MacOSX10.4u installation by copying libtclstub8.4.a to ${sdkrootpath}${tclstubpath}"
                xinstall -p ${tclstubpath} ${sdkrootpath}${tclstubpath}
            }
            # Supply architecture flags to build MacPorts Universal
            configure.cflags-append -isysroot ${sdkrootpath} -arch ppc -arch i386
            configure.env-append SHLIB_LDFLAGS='-Wl,-syslibroot,${sdkrootpath} -arch ppc -arch i386'
        }
    }
}

platform darwin 8 i386 {
    # Supply architecture flags to build MacPorts Universal on an Intel Mac
    configure.cflags-append -arch ppc -arch i386
    configure.args-append SHLIB_LDFLAGS='-arch ppc -arch i386'
}

platform darwin 9 {
    post-pkg {
        global resources_scripts resources_lang
        reinplace "s|is built|contains a Universal installer|" ${resources_lang}/ReadMe.rtf
        reinplace "s|__XVERS__|10.5|" ${resources_lang}/ReadMe.rtf \
            ${resources_lang}/InstallationCheck.strings
        reinplace "s|10.4|10.5|" ${resources_lang}/Welcome.html
        reinplace "s|or newer ||" ${resources_lang}/Welcome.html
        reinplace "s|__DARWINVERS__|9|" ${resources_scripts}/InstallationCheck
    }
}

platform darwin 9 powerpc {
    pre-configure {
        set sdkrootpath /Developer/SDKs/MacOSX10.5.sdk
        if {[file exists ${sdkrootpath}]} {
            # User has Universal SDK installed.
            set tclstubpath /System/Library/Frameworks/Tcl.framework/Versions/8.4/libtclstub8.4.a
            if {![file exists ${sdkrootpath}${tclstubpath}]} {
                ui_msg "Fixing your MacOSX10.5 installation by copying libtclstub8.4.a to ${sdkrootpath}${tclstubpath}"
                xinstall -p ${tclstubpath} ${sdkrootpath}${tclstubpath}
            }
            # Supply architecture flags to build MacPorts Universal
            configure.cflags-append -isysroot ${sdkrootpath} -arch ppc -arch i386
            configure.env-append SHLIB_LDFLAGS='-Wl,-syslibroot,${sdkrootpath} -arch ppc -arch i386'
        }
    }
}

platform darwin 9 i386 {
    # Supply architecture flags to build MacPorts Universal on an Intel Mac
    configure.cflags-append -arch ppc -arch i386
    configure.args-append SHLIB_LDFLAGS='-arch ppc -arch i386'
}

platform darwin 10 {
    # Supply architecture flags to build MacPorts Universal on an Intel Mac
    configure.cflags-append -arch x86_64 -arch i386
    configure.args-append SHLIB_LDFLAGS='-arch x86_64 -arch i386'
    post-pkg {
        global resources_scripts resources_lang
        reinplace "s|is built|contains a Universal installer|" ${resources_lang}/ReadMe.rtf
        reinplace "s|__XVERS__|10.6|" ${resources_lang}/ReadMe.rtf \
            ${resources_lang}/InstallationCheck.strings
        reinplace "s|10.4|10.6|" ${resources_lang}/Welcome.html
        reinplace "s|or newer ||" ${resources_lang}/Welcome.html
        reinplace "s|__DARWINVERS__|10|" ${resources_scripts}/InstallationCheck
    }
}

destroot.violate_mtree yes
destroot.keepdirs    ${destroot}${prefix}/include \
                     ${destroot}${prefix}/lib \
                     ${destroot}${prefix}/libexec \
                     ${destroot}${prefix}/sbin \
                     ${destroot}${prefix}/share/info \
                     ${destroot}${prefix}/share/man/cat1 \
                     ${destroot}${prefix}/share/man/cat2 \
                     ${destroot}${prefix}/share/man/cat3 \
                     ${destroot}${prefix}/share/man/cat4 \
                     ${destroot}${prefix}/share/man/cat5 \
                     ${destroot}${prefix}/share/man/cat6 \
                     ${destroot}${prefix}/share/man/cat7 \
                     ${destroot}${prefix}/share/man/cat8 \
                     ${destroot}${prefix}/share/man/cat9 \
                     ${destroot}${prefix}/share/man/catl \
                     ${destroot}${prefix}/share/man/catn \
                     ${destroot}${prefix}/share/man/man1 \
                     ${destroot}${prefix}/share/man/man2 \
                     ${destroot}${prefix}/share/man/man3 \
                     ${destroot}${prefix}/share/man/man4 \
                     ${destroot}${prefix}/share/man/man5 \
                     ${destroot}${prefix}/share/man/man6 \
                     ${destroot}${prefix}/share/man/man7 \
                     ${destroot}${prefix}/share/man/man8 \
                     ${destroot}${prefix}/share/man/man9 \
                     ${destroot}${prefix}/share/man/manl \
                     ${destroot}${prefix}/share/man/mann \
                     ${destroot}${prefix}/share/nls/C \
                     ${destroot}${prefix}/share/nls/skel \
                     ${destroot}${prefix}/share/nls/af_ZA.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/af_ZA.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/bg_BG.CP1251 \
                     ${destroot}${prefix}/share/nls/cs_CZ.ISO8859-2 \
                     ${destroot}${prefix}/share/nls/da_DK.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/da_DK.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/de_AT.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/de_AT.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/de_CH.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/de_CH.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/de_DE.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/de_DE.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/el_GR.ISO8859-7 \
                     ${destroot}${prefix}/share/nls/en_AU.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/en_AU.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/en_AU.US-ASCII \
                     ${destroot}${prefix}/share/nls/en_CA.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/en_CA.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/en_CA.US-ASCII \
                     ${destroot}${prefix}/share/nls/en_GB.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/en_GB.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/en_GB.US-ASCII \
                     ${destroot}${prefix}/share/nls/en_NZ.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/en_NZ.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/en_NZ.US-ASCII \
                     ${destroot}${prefix}/share/nls/en_US.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/en_US.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/es_ES.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/es_ES.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/et_EE.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/fi_FI.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/fi_FI.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/fr_BE.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/fr_BE.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/fr_CA.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/fr_CA.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/fr_CH.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/fr_CH.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/fr_FR.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/fr_FR.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/hi_IN.ISCII-DEV \
                     ${destroot}${prefix}/share/nls/hr_HR.ISO8859-2 \
                     ${destroot}${prefix}/share/nls/hu_HU.ISO8859-2 \
                     ${destroot}${prefix}/share/nls/is_IS.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/is_IS.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/it_CH.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/it_CH.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/it_IT.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/it_IT.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/ja_JP.SJIS \
                     ${destroot}${prefix}/share/nls/ja_JP.eucJP \
                     ${destroot}${prefix}/share/nls/ko_KR.eucKR \
                     ${destroot}${prefix}/share/nls/la_LN.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/la_LN.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/la_LN.ISO8859-2 \
                     ${destroot}${prefix}/share/nls/la_LN.ISO8859-4 \
                     ${destroot}${prefix}/share/nls/la_LN.US-ASCII \
                     ${destroot}${prefix}/share/nls/lt_LT.ISO8859-4 \
                     ${destroot}${prefix}/share/nls/nl_BE.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/nl_BE.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/nl_NL.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/nl_NL.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/no_NO.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/no_NO.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/pl_PL.ISO8859-2 \
                     ${destroot}${prefix}/share/nls/pt_BR.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/pt_PT.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/pt_PT.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/ro_RO.ISO8859-2 \
                     ${destroot}${prefix}/share/nls/ru_RU.CP866 \
                     ${destroot}${prefix}/share/nls/ru_RU.ISO8859-5 \
                     ${destroot}${prefix}/share/nls/ru_RU.KOI8-R \
                     ${destroot}${prefix}/share/nls/sk_SK.ISO8859-2 \
                     ${destroot}${prefix}/share/nls/sl_SI.ISO8859-2 \
                     ${destroot}${prefix}/share/nls/sv_SE.ISO8859-1 \
                     ${destroot}${prefix}/share/nls/sv_SE.ISO8859-15 \
                     ${destroot}${prefix}/share/nls/tr_TR.ISO8859-9 \
                     ${destroot}${prefix}/share/nls/uk_UA.ISO8859-5 \
                     ${destroot}${prefix}/share/nls/uk_UA.KOI8-U \
                     ${destroot}${prefix}/share/nls/zh_CN.eucCN \
                     ${destroot}${prefix}/share/nls/zh_TW.Big5 \
                     ${destroot}${prefix}/var/macports/build \
                     ${destroot}${prefix}/var/macports/distfiles \
                     ${destroot}${prefix}/var/macports/receipts \
                     ${destroot}${prefix}/var/macports/registry \
                     ${destroot}${prefix}/var/macports/packages
