# -*- 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

PortSystem          1.0
PortGroup           select 1.0

name                python_select
version             0.3
revision            10
categories          sysutils
supported_archs     noarch
configure.cxx_stdlib
license             BSD
maintainers         nomaintainer
description         Common files for selecting default Python version
long_description    This port installs files that allow 'port select' \
                    to create links to the preferred default version \
                    of Python.
homepage            https://www.macports.org/

distfiles
use_configure       no
build               {}
destroot            {}

# Documentation for Python ports:
#   PortGroup       select 1.0
#   select.group    python
#   select.file     ${filespath}/python[string map {. {}} ${branch}]

if {$subport eq $name} {
    # install all files
    select.entries      {python base} \
                        {python none}

    platform darwin {
        set apple_pythons [
            if {${os.major} == 8} {
                list python23-apple
            } elseif {${os.major} == 9} {
                list python25-apple
            } elseif {${os.major} == 10} {
                list python25-apple \
                     python26-apple
            } elseif {${os.major} == 11} {
                list python25-apple \
                     python26-apple \
                     python27-apple
            } elseif {${os.major} == 12 || ${os.major} == 13} {
                list {python25-apple.mtln python25-apple} \
                     {python26-apple.mtln python26-apple} \
                     {python27-apple.mtln python27-apple}
            } elseif {${os.major} == 14 || ${os.major} == 15 || ${os.major} == 16} {
                list {python26-apple.mtln python26-apple} \
                     {python27-apple.mtln python27-apple}
            } elseif {${os.major} == 17 || ${os.major} == 18} {
                list {python27-apple.mtln python27-apple}
            } elseif {${os.major} == 19} {
                list {python27-apple.mtln python27-apple} \
                     python37-apple \
                     python38-apple
            } elseif {${os.major} == 20} {
                list {python27-apple.mtln python27-apple} \
                     python38-apple
            }
        ]
        foreach python $apple_pythons {
            select.entries-append [list python {*}$python]
        }
    }
}

foreach p {38 39 310 311 312 313 314 315} {
    subport python_select-${p} {
        set pyver $p
    }
}
if {$subport ne $name} {
    revision    1
    platforms   any
    depends_run port:python_select
    select.entries  [list python python${pyver} python${pyver}]
    pre-activate {
        if {[file exists ${prefix}/etc/select/python/python${pyver}]} {
            set owner [registry_file_registered ${prefix}/etc/select/python/python${pyver}]
            if {[string match python${pyver}* $owner]} {
                registry_deactivate_composite $owner "" [list ports_nodepcheck 1]
            }
        }
    }
}

livecheck.type     none
