PortSystem          1.0
PortGroup           github 1.0

github.setup        macports macports-base 2.6.2 v
name                MacPorts

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

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.

notes "This port cannot directly be used to upgrade MacPorts; use 'port\
selfupdate' for that."

homepage            https://www.macports.org
distname            ${name}-${version}
github.tarball_from releases
# testing subdir is for non-final releases only
#dist_subdir         ${name}/testing
use_bzip2           yes

checksums           rmd160 1400db2449d50e77d5d30e5f0820bb339dc3b080 \
                    sha256 1b58ccbb1cd6c6fab5e1f15b959208ef5233802fc9ac9585037d21c8e42e2b70

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 MacPorts' default flags don't play well when we're building MacPorts
# itself; nuke them.
configure.cppflags
configure.ldflags
configure.cc_archflags
configure.objc_archflags
configure.ld_archflags
compiler.cpath
compiler.library_path
configure.cxx_stdlib

# 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/archive_sites.conf
    delete ${destroot}${prefix}/etc/macports/macports.conf
    delete ${destroot}${prefix}/etc/macports/pubkeys.conf
    delete ${destroot}${prefix}/etc/macports/sources.conf
    delete ${destroot}${prefix}/etc/macports/variants.conf
}

if {!${package.flat}} {
    package.scripts   ${package.resources}
}
set resources_lang ${package.resources}/English.lproj

pre-pkg {
    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 ${package.scripts}
    file copy -force -- ${worksrcpath}/src/upgrade_sources_conf_default.tcl ${package.scripts}
    file copy -force -- ${worksrcpath}/src/images_to_archives.tcl ${package.scripts}
    file copy -force -- ${worksrcpath}/src/dedup_portfiles.tcl ${package.scripts}
    file copy -force -- ${worksrcpath}/src/cxx_stdlib_overridden.tcl ${package.scripts}

    file attributes ${package.scripts}/postflight -permissions 0755
    file attributes ${package.scripts}/upgrade_sources_conf_default.tcl -permissions 0755
    file attributes ${package.scripts}/images_to_archives.tcl -permissions 0755
    file attributes ${package.scripts}/dedup_portfiles.tcl -permissions 0755
    file attributes ${package.scripts}/cxx_stdlib_overridden.tcl -permissions 0755
    file attributes ${resources_lang}/ReadMe.rtf -permissions 0644
    file attributes ${resources_lang}/License.html -permissions 0644

    reinplace "s|__PREFIX__|${prefix}|g" \
              ${resources_lang}/ReadMe.rtf
    if {${os.major} < 11} {
        reinplace "s|is built|contains a Universal installer|" ${resources_lang}/ReadMe.rtf
    }
    reinplace "s|__XVERS__|${macosx_deployment_target}|" ${resources_lang}/ReadMe.rtf
    if {${package.flat}} {
        file copy -force -- ${worksrcpath}/portmgr/dmg/Distribution ${workpath}
        file attributes ${workpath}/Distribution -permissions 0644
        reinplace "s|__PREFIX__|${prefix}|g" ${workpath}/Distribution
        switch $macosx_deployment_target {
            10.4    {set xcode_cli "Command Line Support"}
            10.5    -
            10.6    {set xcode_cli "UNIX Development"}
            default {set xcode_cli "Command Line Tools or UNIX Development"}
        }
        reinplace "s|__XCODECLITOOLS__|${xcode_cli}|g" ${workpath}/Distribution
        reinplace "s|__XVERS__|${macosx_deployment_target}|" ${workpath}/Distribution
        set next_major [lindex [split $macosx_deployment_target .] 0].[expr [lindex [split $macosx_deployment_target .] 1] + 1]
        reinplace "s|__NEXT_XVERS__|$next_major|" ${workpath}/Distribution
        reinplace "s|__VERSION__|${version}|" ${workpath}/Distribution
        move ${package.scripts}/postflight ${package.scripts}/postinstall
    } else {
        file copy -force -- ${worksrcpath}/portmgr/dmg/InstallationCheck ${package.resources}
        file copy -force -- ${worksrcpath}/portmgr/dmg/InstallationCheck.strings ${resources_lang}
        file attributes ${package.resources}/InstallationCheck -permissions 0755
        file attributes ${resources_lang}/InstallationCheck.strings -permissions 0644
        reinplace "s|__PREFIX__|${prefix}|g" \
              ${package.resources}/InstallationCheck
        reinplace "s|__DARWINVERS__|${os.major}|" ${package.resources}/InstallationCheck
        reinplace "s|__XVERS__|${macosx_deployment_target}|" \
            ${resources_lang}/InstallationCheck.strings
    }

    reinplace "s|or newer ||" ${resources_lang}/Welcome.html
    if {${os.major} > 8} {
        reinplace "s|10\\.4|${macosx_deployment_target}|" ${resources_lang}/Welcome.html
    }
}

platform darwin 8 {
    # has ${prefix}/include ahead of /usr/include in default search path
    compiler.blacklist apple-gcc-4.2
}

platform darwin 8 powerpc {
    pre-configure {
        set sdkrootpath /Developer/SDKs/MacOSX10.4u.sdk
        if {[file exists ${sdkrootpath}]} {
            # User has 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 and sysroot flags to build MacPorts universal.
            configure.cflags-append -isysroot ${sdkrootpath} -arch ppc -arch i386
            if {[vercmp [macports_version] 2.5.99] >= 0} {
            configure.env-append "SHLIB_LDFLAGS=-Wl,-syslibroot,${sdkrootpath} -arch ppc -arch i386"
            } else {
            configure.env-append SHLIB_LDFLAGS='-Wl,-syslibroot,${sdkrootpath} -arch ppc -arch i386'
            }
        }
    }
}

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

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

platform darwin {
    if {${os.major} >= 11} {
        # Lion and above only run on x86_64.
        configure.cflags-append -arch x86_64
        configure.args-append SHLIB_LDFLAGS='-arch x86_64'
    } elseif {${os.major} == 10} {
        # Supply architecture flags to build MacPorts universal.
        configure.cflags-append -arch x86_64 -arch i386
        configure.args-append SHLIB_LDFLAGS='-arch x86_64 -arch i386'
    }

    # FIXME: "error: The specified item could not be found in the keychain."
    #if {${os.major} >= 18} {
    #    post-build {
    #        if {[getuid] == 0 && [info exists sudo_user]} {
    #            set codesign_cmd "/usr/bin/env SUDO_USER=${sudo_user} HOME=/Users/${sudo_user} ${build.cmd} codesign"
    #        } else {
    #            set codesign_cmd "${build.cmd} codesign"
    #        }
    #        system -W ${worksrcpath} ${codesign_cmd}
    #    }
    #}
}

destroot.violate_mtree yes
destroot.keepdirs    ${destroot}${prefix}/include \
                     ${destroot}${prefix}/lib \
                     ${destroot}${prefix}/libexec \
                     ${destroot}${prefix}/sbin \
                     ${destroot}${prefix}/share/doc \
                     ${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/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}/share/skel \
                     ${destroot}${prefix}/var/cache \
                     ${destroot}${prefix}/var/db \
                     ${destroot}${prefix}/var/macports/build \
                     ${destroot}${prefix}/var/macports/distfiles \
                     ${destroot}${prefix}/var/macports/registry \
                     ${destroot}${prefix}/var/macports/sip-workaround \
                     ${destroot}${prefix}/var/run \
                     ${destroot}${prefix}/var/spool

known_fail yes
pre-activate {
    ui_error ""
    ui_error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    ui_error "!! DO NOT INSTALL THE MACPORTS PORT !!"
    ui_error "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    ui_error "The MacPorts port is only used to build the installers you can download from"
    ui_error "macports.org It is not intended for installation by a user, and doing so will"
    ui_error "overwrite your MacPorts installation and render it unusable when removed."
    ui_error ""
    error "Installation aborted"
}

github.livecheck.regex  {([0-9.]+)}