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

name                    MacOSX.sdk
categories              devel
platforms               macosx
maintainers             {ryandesign @ryandesign}
license                 Restrictive Nomirror
installs_libs           no

switch ${os.arch} {
    powerpc {
        version         10.6
        revision        0
    }
    arm64 -
    i386 -
    default {
        if {${build_arch} eq "i386"} {
            version     10.13
            revision    0
        } else {
            version     12
            revision    0
        }
    }
}

homepage                https://developer.apple.com/macos/

options cdn_path
default cdn_path        {}

default distname        {[expr {${cdn_path} eq {} ? "${name}-${version}" : [file rootname [file tail ${cdn_path}]]}]}

default dist_subdir     {[expr {${cdn_path} eq {} ? ${name} : "${name}/${version}"}]}

options extract_paths
default extract_paths   {[expr {${cdn_path} eq {}
                            ? "Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX${sdk_major}.sdk"
                            : "Library/Developer/CommandLineTools/SDKs/MacOSX${sdk_major}.sdk"
                        }]}

default extract.suffix  {[expr {${cdn_path} eq {} ? ".dmg" : [file extension ${cdn_path}]}]}

default master_sites    {[expr {${cdn_path} eq {}
                            ? "https://download.developer.apple.com/Developer_Tools/${master_sites.mirror_subdir}"
                            : "https://swcdn.apple.com/content/downloads/${master_sites.mirror_subdir}"
                        }]}

default master_sites.mirror_subdir \
                        {[expr {${cdn_path} eq {} ? ${distname} : [file dirname ${cdn_path}]}]}

options xar_file
default xar_file        {}

options xar_pbzx
default xar_pbzx        yes

options xar_payload
default xar_payload     {}

subport MacOSX12.sdk {
#   SDK                   Size  Date        File                                                                                        Notes
#   12.0-21A5294d     49516205  2021-07-23  43/52/071-71319-A_2PNZ1H03T9/yorgkv27w1zgfvebolkypz7kd69zi7ykhm/CLTools_macOSNMOS_SDK.pkg
#   12.1-21C46        49815732  2021-12-21  52/17/002-41708-A_E8MFK7B2PK/6p55tbmh0qttgbt4cy94uuvnacy6tkw435/CLTools_macOSNMOS_SDK.pkg
#   12.3-21E226       49686708  2022-02-25  28/19/071-82714-A_HUFJRGID6Y/nnmlg28zs93jdbrsqtk6krr4mmaize40hb/CLTools_macOSNMOS_SDK.pkg   newest smallest
    set macos_name      {macOS Monterey}
    version             12.3-21E226
    revision            0
    checksums           rmd160  e25c1c3f471ff1ecd1d8b33af10c8670f6137556 \
                        sha256  be771479c51c0367eafb83c2a54d9a3ca840b34250097e810042b59aab9517cd \
                        size    49686708
    cdn_path            28/19/071-82714-A_HUFJRGID6Y/nnmlg28zs93jdbrsqtk6krr4mmaize40hb/CLTools_macOSNMOS_SDK.pkg

    homepage            https://developer.apple.com/documentation/macos-release-notes/macos-12_0_1-release-notes
}

subport MacOSX11.sdk {
#   SDK                   Size  Date        File                                                                                        Notes
#   11.1-20C63        52634181  2021-01-08  46/21/001-89745-A_56FM390IW5/v1um2qppgfdnam2e9cdqcqu2r6k8aa3lis/CLTools_macOSNMOS_SDK.pkg
#   11.3-20E214       54901737  2021-04-20  50/51/071-29699-A_YC8SX0OHH3/7479xojqghsvgtnt3dxjpnxuz9sjpmbmds/CLTools_macOSNMOS_SDK.pkg
#   11.3-20E214       54904673  2021-06-08  02/62/071-54303-A_EU2CL1YVT7/943i95dpeyi2ghlnj2mgyq3t202t5gf18b/CLTools_macOSNMOS_SDK.pkg
#   11.3.1-20E241     54906565  2021-07-23  43/52/071-71319-A_2PNZ1H03T9/yorgkv27w1zgfvebolkypz7kd69zi7ykhm/CLTools_macOSLMOS_SDK.pkg
#   11.3.1-20E241     54920394  2021-12-02  52/17/002-41708-A_E8MFK7B2PK/6p55tbmh0qttgbt4cy94uuvnacy6tkw435/CLTools_macOSLMOS_SDK.pkg
#   11.3.1-20E241     54904075  2022-02-25  28/19/071-82714-A_HUFJRGID6Y/nnmlg28zs93jdbrsqtk6krr4mmaize40hb/CLTools_macOSLMOS_SDK.pkg   newest smallest
    set macos_name      {macOS Big Sur}
    version             11.3.1-20E241
    revision            0
    checksums           rmd160  5d1de1fd578c595f99869ef6ff878079d9f92ca5 \
                        sha256  2256993894725f9996c4f0f7490b7183493d3b1545e45cf17f36dc4b4761102a \
                        size    54904075
    cdn_path            28/19/071-82714-A_HUFJRGID6Y/nnmlg28zs93jdbrsqtk6krr4mmaize40hb/CLTools_macOSLMOS_SDK.pkg

    homepage            https://developer.apple.com/documentation/macos-release-notes/macos-big-sur-11_0_1-release-notes
}

subport MacOSX10.15.sdk {
#   SDK                   Size  Date        File                                                                                        Notes
#   10.15-19A547      43286143  2019-09-05  45/28/061-26566-A_R7LP2VO5QF/svs27at6zihaghh3wj0av4y3wdcriu4n2j/CLTools_macOS1015_SDK.pkg
#   10.15-19A547     230422479  2019-10-01  Command_Line_Tools_for_Xcode_11.dmg
#   10.15-19A547    7612937462  2019-10-01  Xcode_11.xip
#   10.15-19A547    7675842712  2019-10-07  Xcode_11.1.xip
#   10.15.1-19B81    230414314  2019-11-07  Command_Line_Tools_for_Xcode_11.2.dmg
#   10.15.1-19B81   7821856919  2019-10-31  Xcode_11.2.xip
#   10.15.1-19B89   7821856908  2019-11-12  Xcode_11.2.1.xip
#   10.15.1-19B90    230414303  2019-12-10  Command_Line_Tools_for_Xcode_11.3.dmg
#   10.15.1-19B90   7845187734  2019-12-10  Xcode_11.3.xip
#   10.15.1-19B90    230414298  2020-01-13  Command_Line_Tools_for_Xcode_11.3.1.dmg
#   10.15.1-19B90   7843352719  2020-01-13  Xcode_11.3.1.xip
#   10.15.4-19E258   260497052  2020-03-24  Command_Line_Tools_for_Xcode_11.4.dmg
#   10.15.4-19E258  8111919274  2020-03-24  Xcode_11.4.xip
#   10.15.4-19E258   260365974  2020-04-15  Command_Line_Tools_for_Xcode_11.4.1.dmg
#   10.15.4-19E258  8108773540  2020-04-16  Xcode_11.4.1.xip
#   10.15.4-19E258   260431508  2020-05-20  Command_Line_Tools_for_Xcode_11.5.dmg
#   10.15.4-19E258  8124240037  2020-05-20  Xcode_11.5.xip
#   10.15.6-19G68   8148095139  2020-07-15  Xcode_11.6.xip
#   10.15.6-19G68   8150585507  2020-09-01  Xcode_11.7.xip
#   10.15.6-19G68    440575587  2020-09-17  Command_Line_Tools_for_Xcode_12.dmg
#   10.15.6-19G68  11209653545  2020-09-17  Xcode_12.xip
#   10.15.6-19G68     43292373  2021-01-08  46/21/001-89745-A_56FM390IW5/v1um2qppgfdnam2e9cdqcqu2r6k8aa3lis/CLTools_macOSLMOS_SDK.pkg
#   10.15.6-19G68     43293884  2021-04-20  50/51/071-29699-A_YC8SX0OHH3/7479xojqghsvgtnt3dxjpnxuz9sjpmbmds/CLTools_macOSLMOS_SDK.pkg
#   10.15.6-19G68     43136357  2021-06-08  02/62/071-54303-A_EU2CL1YVT7/943i95dpeyi2ghlnj2mgyq3t202t5gf18b/CLTools_macOSLMOS_SDK.pkg   newest smallest
    set macos_name      {macOS Catalina}
    version             10.15.6-19G68
    revision            0
    checksums           rmd160  ea57f9c48b800380cbdf7fd3b1611667b52504a8 \
                        sha256  d459ae8498deb77f290f7f3adc99a98fb488441818a90042091ee7bb78c817c3 \
                        size    43293884
    cdn_path            02/62/071-54303-A_EU2CL1YVT7/943i95dpeyi2ghlnj2mgyq3t202t5gf18b/CLTools_macOSLMOS_SDK.pkg

    homepage            https://developer.apple.com/documentation/macos-release-notes/macos-catalina-10_15-release-notes
}

subport MacOSX10.14.sdk {
#   SDK                   Size  Date        File                                                                                        Notes
#   10.14-18A384     195780760  2019-10-23  Command_Line_Tools_macOS_10.13_for_Xcode_10.dmg
#   10.14-18A384     192475091  2019-10-23  Command_Line_Tools_macOS_10.14_for_Xcode_10.dmg
#   10.14-18A384    5876954359  2019-10-23  Xcode_10.xip
#   10.14.1-18B71     25605433  2018-10-19  50/15/041-91747-A_WICZE7RNVZ/rayjnqf847xflt3tan8o8agod67eq88cav/CLTools_SDK_macOS1014.pkg
#   10.14.1-18B71    195846261  2019-10-23  Command_Line_Tools_macOS_10.13_for_Xcode_10.1.dmg
#   10.14.1-18B71    192997780  2019-10-23  Command_Line_Tools_macOS_10.14_for_Xcode_10.1.dmg
#   10.14.1-18B71   6047806709  2019-10-23  Xcode_10.1.xip
#   10.14.4-18E219   203813482  2019-10-23  Command_Line_Tools_macOS_10.14_for_Xcode_10.2.dmg
#   10.14.4-18E219  6055736566  2019-10-23  Xcode_10.2.xip
#   10.14.4-18E219   203813456  2019-10-23  Command_Line_Tools_macOS_10.14_for_Xcode_10.2.1.dmg
#   10.14.4-18E219  6055671032  2019-10-23  Xcode_10.2.1.xip
#   10.14.5-18F132    31929696  2019-09-05  45/28/061-26566-A_R7LP2VO5QF/svs27at6zihaghh3wj0av4y3wdcriu4n2j/CLTools_macOS1014_SDK.pkg
#   10.14.5-18F132   230422479  2019-10-01  Command_Line_Tools_for_Xcode_11.dmg
#   10.14.5-18F132   230414314  2019-11-07  Command_Line_Tools_for_Xcode_11.2.dmg
#   10.14.5-18F132   230414303  2019-12-10  Command_Line_Tools_for_Xcode_11.3.dmg
#   10.14.5-18F132   230414298  2020-01-13  Command_Line_Tools_for_Xcode_11.3.1.dmg
#   10.14.5-18F132   260497052  2020-03-24  Command_Line_Tools_for_Xcode_11.4.dmg
#   10.14.5-18F132   260365974  2020-04-15  Command_Line_Tools_for_Xcode_11.4.1.dmg
#   10.14.5-18F132   260431508  2020-05-20  Command_Line_Tools_for_Xcode_11.5.dmg
#   10.14.6-18G74     25703733  2019-07-13  41/57/061-26573-A_JMOA8GZGDR/lj8yrtu8dgs40fw9k8f5fkoviwkp0og6vs/CLTools_SDK_macOS1014.pkg   newest smallest
#   10.14.6-18G74    203944529  2019-10-23  Command_Line_Tools_macOS_10.14_for_Xcode_10.3.dmg
#   10.14.6-18G74   6044005625  2019-10-23  Xcode_10.3.xip
    set macos_name      {macOS Mojave}
    version             10.14.6-18G74
    revision            1
    checksums           rmd160  6bf687a426624b83a5694220e5294e697fb73426 \
                        sha256  3b65c623e29ad74a3cd4f4eaf8e7fa6fc4b887b07bdf7b83f9217caa5fd67f51 \
                        size    25703733
    cdn_path            41/57/061-26573-A_JMOA8GZGDR/lj8yrtu8dgs40fw9k8f5fkoviwkp0og6vs/CLTools_SDK_macOS1014.pkg
    extract_paths       Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

    homepage            https://developer.apple.com/documentation/macos-release-notes/macos-mojave-10_14-release-notes
}

subport MacOSX10.13.sdk {
#   SDK                   Size  Date        File                                                Notes
#   10.13-17A360     186889025  2019-11-01  Command_Line_Tools_macOS_10.12_for_Xcode_9.dmg
#   10.13-17A360     181553114  2019-11-01  Command_Line_Tools_macOS_10.13_for_Xcode_9.dmg
#   10.13-17A360    5370295544  2019-11-01  Xcode_9.xip
#   10.13-17A360     187403942  2019-11-01  Command_Line_Tools_macOS_10.12_for_Xcode_9.0.1.dmg
#   10.13-17A360     182087050  2019-11-01  Command_Line_Tools_macOS_10.13_for_Xcode_9.0.1.dmg
#   10.13-17A360    5442843891  2019-11-01  Xcode_9.0.1.xip
#   10.13.1-17B41    187514526  2019-11-01  Command_Line_Tools_macOS_10.12_for_Xcode_9.1.dmg
#   10.13.1-17B41    182201735  2019-11-01  Command_Line_Tools_macOS_10.13_for_Xcode_9.1.dmg
#   10.13.1-17B41   5442909430  2019-11-01  Xcode_9.1.xip
#   10.13.2-17C76     28071275  2017-11-17  33/36/041-90419-A_7JJ4H9ZHO2/xs88ob5wjz6riz7g6764twblnvksusg4ps/CLTools_SDK_macOS1013.pkg
#   10.13.2-17C76    187629224  2019-11-01  Command_Line_Tools_macOS_10.12_for_Xcode_9.2.dmg
#   10.13.2-17C76    182316425  2019-11-01  Command_Line_Tools_macOS_10.13_for_Xcode_9.2.dmg
#   10.13.2-17C76   5478692088  2019-11-01  Xcode_9.2.xip
#   10.13.4-17E189   192491483  2019-11-01  Command_Line_Tools_macOS_10.13_for_Xcode_9.3.dmg    newest smallest
#   10.13.4-17E189  5235094775  2019-11-01  Xcode_9.3.xip
#   10.13.4-17E189  5235160313  2019-11-01  Xcode_9.3.1.xip
#   10.13.4-17E189   192565208  2019-11-01  Command_Line_Tools_macOS_10.13_for_Xcode_9.4.dmg
#   10.13.4-17E189  5271139574  2019-11-01  Xcode_9.4.xip
#   10.13.4-17E189   192548827  2019-11-01  Command_Line_Tools_macOS_10.13_for_Xcode_9.4.1.dmg
#   10.13.4-17E189  5271270648  2019-11-01  Xcode_9.4.1.xip
    set macos_name      {macOS High Sierra}
    version             10.13.4-17E189
    revision            0
    checksums           rmd160  29c5a9ad27bf3ccf4ca1aceda973654071b89235 \
                        sha256  bb99dd83b359b6e85e870f231ee31ee0681b1b7477787b4ddf5b8f0da5ea987d \
                        size    192491483
    distname            Command_Line_Tools_macOS_10.13_for_Xcode_9.3
    xar_file            Command Line Tools (macOS High Sierra version 10.13).pkg
    xar_payload         CLTools_SDK_macOS1013.pkg/Payload
    extract_paths       Library/Developer/CommandLineTools/SDKs/MacOSX.sdk

    homepage            https://developer.apple.com/library/archive/releasenotes/General/RN-macOSSDK-10.13/
}

subport MacOSX10.12.sdk {
#   SDK                   Size  Date        File                                                Notes
#   10.12-16A300    4415370488  2019-11-08  Xcode_8.xip
#   10.12.1-16B2649 4446762222  2019-11-08  Xcode_8.1.xip
#   10.12.2-16C58     27030882  2016-12-05  22/62/041-88607/wg8avdk0jo75k9a13gentz9stwqgrqmcv6/CLTools_SDK_OSX1012.pkg
#   10.12.2-16C58    154679192  2019-11-08  Command_Line_Tools_macOS_10.11_for_Xcode_8.2.dmg
#   10.12.2-16C58    154863510  2019-11-08  Command_Line_Tools_macOS_10.12_for_Xcode_8.2.dmg
#   10.12.2-16C58   4526912760  2019-11-08  Xcode_8.2.xip
#   10.12.2-16C58   4527043832  2019-11-08  Xcode_8.2.1.xip
#   10.12.4-16E185   166119977  2019-11-08  Command_Line_Tools_macOS_10.12_for_Xcode_8.3.dmg    newest smallest
#   10.12.4-16E185  4505613560  2019-11-08  Xcode_8.3.xip
#   10.12.4-16E185  4495662305  2017-04-06  Xcode_8.3.1.xip                                     removed in 2019
#   10.12.4-16E185   166128165  2019-11-08  Command_Line_Tools_macOS_10.12_for_Xcode_8.3.2.dmg
#   10.12.4-16E185  4494079225  2019-11-08  Xcode_8.3.2.xip
#   10.12.4-16E185  4522587381  2019-11-08  Xcode_8.3.3.xip
    set macos_name      {macOS Sierra}
    version             10.12.4-16E185
    revision            0
    checksums           rmd160  f11bd2fc98b7b7ab81779da94673f7649df1eeed \
                        sha256  80f34f206562a10dc8dc14269ab744c16a58134f2bcd26933234fe06ca594683 \
                        size    166119977
    distname            Command_Line_Tools_macOS_10.12_for_Xcode_8.3
    xar_file            Command Line Tools (macOS Sierra version 10.12).pkg
    xar_payload         CLTools_SDK_OSX1012.pkg/Payload
    extract_paths       Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
}

subport MacOSX10.11.sdk {
#   SDK                   Size  Date        File                                                Notes
#   10.11-15A278    3731744540  2019-11-13  Xcode_7.dmg
#   10.11-15A278    3733068903  2019-11-13  Xcode_7.0.1.dmg
#   10.11-15A278    4474328556  2019-11-13  Xcode_7.1.dmg
#   10.11-15A278    4474204264  2019-11-13  Xcode_7.1.1.dmg
#   10.11.2-15C43   4591512140  2019-11-13  Xcode_7.2.dmg
#   10.11.2-15C43   4591829253  2019-11-13  Xcode_7.2.1.dmg
#   10.11.4-15E60   5047652942  2019-11-13  Xcode_7.3.dmg                                       newest smallest
#   10.11.4-15E60   5050193754  2019-11-13  Xcode_7.3.1.dmg
    set macos_name      {OS X El Capitan}
    version             10.11.4-15E60
    revision            0
    checksums           rmd160  c15f1f966be258a60cbabdc95cc0085b007fa7df \
                        sha256  5db90607c1f4f7222b40664c160b033be37433d29ed639f335b5d01545e3bb9c \
                        size    5047652942
    distname            Xcode_7.3
}

subport MacOSX10.10.sdk {
#   SDK                   Size  Date        File                                                Notes
#   10.10-14A382    2611748750  2019-12-11  Xcode_6.1.dmg
#   10.10-14A382    2612045447  2019-12-11  Xcode_6.1.1.dmg
#   10.10-14A383    2699970727  2019-12-11  Xcode_6.2.dmg
#   10.10.3-14D125  2685818165  2019-12-11  Xcode_6.3.dmg
#   10.10.3-14D125  2685577832  2019-12-11  Xcode_6.3.1.dmg                                     newest smallest
#   10.10.3-14D125  2687136616  2019-12-11  Xcode_6.3.2.dmg
#   10.10.3-14D125  2804514980  2019-12-11  Xcode_6.4.dmg                                       not reissued in 2019
    set macos_name      {OS X Yosemite}
    version             10.10.3-14D125
    revision            0
    checksums           rmd160  fab391862be2d7fbd78ba69dcf01b283d2bde7c7 \
                        sha256  205830f485200252b2d7c34b15c8037ce06de6cee95f6f4ab23f856016057df5 \
                        size    2685577832
    distname            Xcode_6.3.1
}

subport MacOSX10.9.sdk {
#   SDK                   Size  Date        File                                                Notes
#   10.9-13A595     2171659981  2019-12-11  Xcode_5.0.1.dmg
#   10.9-13A595     2173178480  2019-12-11  Xcode_5.0.2.dmg
#   10.9.2-13C64    2261628363  2019-12-11  Xcode_5.1.dmg
#   10.9.2-13C64    2260656898  2019-12-11  Xcode_5.1.1.dmg
#   10.9.5-13F26    2542512797  2019-12-05  Xcode_6.0.1.dmg
#   10.9.5-13F26    2611748750  2019-12-11  Xcode_6.1.dmg
#   10.9.5-13F26    2612045447  2019-12-11  Xcode_6.1.1.dmg
#   10.9.5-13F26    2699970727  2019-12-11  Xcode_6.2.dmg
#   10.9.5-13F34    2685818165  2019-12-11  Xcode_6.3.dmg
#   10.9.5-13F34    2685577832  2019-12-11  Xcode_6.3.1.dmg                                     newest smallest
#   10.9.5-13F34    2687136616  2019-12-11  Xcode_6.3.2.dmg
#   10.9.5-13F34    2804514980  2019-12-11  Xcode_6.4.dmg                                       not reissued in 2019
    set macos_name      {OS X Mavericks}
    version             10.9.5-13F34
    revision            0
    checksums           rmd160  fab391862be2d7fbd78ba69dcf01b283d2bde7c7 \
                        sha256  205830f485200252b2d7c34b15c8037ce06de6cee95f6f4ab23f856016057df5 \
                        size    2685577832
    distname            Xcode_6.3.1
}

subport MacOSX10.8.sdk {
#   SDK                   Size  Date        File                                                Notes
#   10.8-12A264     1941984563  2019-12-20  Xcode_4.4.dmg
#   10.8-12A264     1941992755  2019-12-20  Xcode_4.4.1.dmg
#   10.8.2-12C37    1662589104  2019-12-20  Xcode_4.5.dmg
#   10.8.2-12C37    1662484314  2019-12-20  Xcode_4.5.1.dmg
#   10.8.2-12C37    1663452382  2019-12-20  Xcode_4.5.2.dmg
#   10.8.2-12C37    1723665548  2013-01-25  xcode460417218a.dmg                                 not reissued in 2019
#   10.8.3-12D75    1712373581  2019-12-20  Xcode_4.6.1.dmg
#   10.8.3-12D75    1712053690  2019-12-20  Xcode_4.6.2.dmg
#   10.8.3-12D75    1712074184  2019-12-20  Xcode_4.6.3.dmg
#   10.8.3-12D75    2024415296  2019-12-11  Xcode_5.dmg
#   10.8.5-12F37    2171659981  2019-12-11  Xcode_5.0.1.dmg                                     newest smallest
#   10.8.5-12F37    2173178480  2019-12-11  Xcode_5.0.2.dmg
#   10.8.5-12F37    2261628363  2019-12-11  Xcode_5.1.dmg
#   10.8.5-12F37    2260656898  2019-12-11  Xcode_5.1.1.dmg
    set macos_name      {OS X Mountain Lion}
    version             10.8.5-12F37
    revision            0
    checksums           rmd160  275e6cf1ca701792933ec9b7cb59eceb0663deb3 \
                        sha256  92a38fc37e6928a5b4b4066796dc402bcb8dbbb0070a5c64c3b48c8487901b1a \
                        size    2171659981
    master_sites.mirror_subdir \
                        xcode_5.0.1
    distname            Xcode_5.0.1
}

subport MacOSX10.7.sdk {
#   SDK                   Size  Date        File                                                Notes
#   10.7-11A511a    3175033467  2012-03-21  installxcode_41_lion.dmg
#   10.7.2-11C63    1807251365  2012-03-21  installxcode_42_lion.dmg
#   10.7.2-11C63    1807220808  2012-03-21  installxcode_421_lion.dmg
#   10.7.3-11D50a   1493268524  2019-12-20  Xcode_4.3_for_Lion.dmg
#   10.7.3-11D50a   1575888770  2019-12-20  Xcode_4.3.1_for_Lion.dmg
#   10.7.3-11D50a   1981952725  2019-12-20  Xcode_4.3.2_for_Lion.dmg
#   10.7.4-11E52    1975435989  2019-12-20  Xcode_4.3.3_for_Lion.dmg
#   10.7.4-11E52    1941984563  2019-12-20  Xcode_4.4.dmg
#   10.7.4-11E52    1941992755  2019-12-20  Xcode_4.4.1.dmg
#   10.7.4-11E52    1662589104  2019-12-20  Xcode_4.5.dmg
#   10.7.4-11E52    1662484314  2019-12-20  Xcode_4.5.1.dmg                                     newest smallest
#   10.7.4-11E52    1663452382  2019-12-20  Xcode_4.5.2.dmg
#   10.7.4-11E52    1723665548  2013-01-25  xcode460417218a.dmg                                 not reissued in 2019
#   10.7.4-11E52    1712373581  2019-12-20  Xcode_4.6.1.dmg
#   10.7.4-11E52    1712053690  2019-12-20  Xcode_4.6.2.dmg
#   10.7.4-11E52    1712074184  2019-12-20  Xcode_4.6.3.dmg
    set macos_name      {Mac OS X Lion}
    version             10.7.4-11E52
    revision            0
    checksums           rmd160  687b76d45c132485489ff59930cbe96dc64fbf2d \
                        sha256  aaffbc3949548259e2c05aa40dddff6ed3215ec37733a15cfef888f95b938575 \
                        size    1662484314
    master_sites.mirror_subdir \
                        xcode_4.5.1
    distname            Xcode_4.5.1
}

subport MacOSX10.6.sdk {
#   SDK                   Size  Date        File                                                Notes
#   10.6-10A432      785073678  2009-08-27  xcode3210a432.dmg
#   10.6-10M2003     787658017  2009-10-08  xcode321_10m2003_developerdvd.dmg
#   10.6-10M2148     780887329  2010-03-30  xcode322_2148_developerdvd.dmg
#   10.6-10M2262    2446068106  2010-07-07  xcode_3.2.3_and_ios_sdk_4.0.1.dmg
#   10.6-10M2262    2675189630  2010-08-11  xcode_3.2.3_and_ios_sdk_4.0.2.dmg
#   10.6-10M2309    3154281265  2010-09-07  xcode_3.2.4_and_ios_sdk_4.1.dmg
#   10.6-10M2423    3782241266  2010-11-19  xcode_3.2.5_and_ios_sdk_4.2_final.dmg
#   10.6-10M2518    4443150993  2011-03-07  xcode_3.2.6_and_ios_sdk_4.3.dmg
#   10.6-4A304a     4597154754  2011-03-09  xcode_4_and_ios_sdk_4.3__final.dmg
#   10.6-4A1006     4607939522  2011-03-23  xcode_4.0.1_and_ios_sdk_4.3.dmg
#   10.6-4A2002a    4608009154  2011-04-12  xcode_4.0.2_and_ios_sdk_4.3.dmg
#   10.6-4B110f     4645556106  2011-08-29  xcode_4.1_for_snow_leopard.dmg
#   10.6.6-10J567   3175033467  2012-03-21  installxcode_41_lion.dmg
#   10.6.8-10K549   1761397888  2011-10-12  xcode_4.2_for_snow_leopard.dmg
#   10.6.8-10K549   1807251365  2012-03-21  installxcode_42_lion.dmg
#   10.6.8-10K549   1807220808  2012-03-21  installxcode_421_lion.dmg
#   10.6.8-10K549   1493268524  2019-12-20  Xcode_4.3_for_Lion.dmg                              newest smallest
#   10.6.8-10K549   1575888770  2019-12-20  Xcode_4.3.1_for_Lion.dmg
#   10.6.8-10K549   1981952725  2019-12-20  Xcode_4.3.2_for_Lion.dmg
#   10.6.8-10K549   1975435989  2019-12-20  Xcode_4.3.3_for_Lion.dmg
    set macos_name      {Mac OS X Snow Leopard}
    version             10.6.8-10K549
    revision            0
    checksums           rmd160  1c4cf2f7b384840655b24aef57a21fbcca4349c4 \
                        sha256  51ad4ad86be70532bec5ba29da1cec9aedfdd040eb14b6b7e15a4d886c2be330 \
                        size    1493268524
    master_sites.mirror_subdir \
                        xcode_4.3_for_lion_21266
    distname            Xcode_4.3_for_Lion
}

pre-fetch {
    foreach distfile ${distfiles} {
        if {${cdn_path} eq {} && ![file isfile ${distpath}/${distfile}]} {
            ui_error "This port cannot download the needed files automatically."
            ui_error "Please log in to your Apple Developer account at:"
            ui_error ""
            ui_error "https://developer.apple.com/download/"
            ui_error ""
            ui_error "Then paste this URL into your browser:"
            ui_error ""
            ui_error "[lindex ${master_sites} 0]/${distfile}"
            ui_error ""
            ui_error "Place the downloaded file in this directory:"
            ui_error ""
            ui_error "${distpath}"
            ui_error ""
            ui_error "Then retry installing this port."
            return -code error "distfiles missing"
        }
    }
}

# You'd think this would be in Tcl or MacPorts base already.
# http://wiki.tcl.tk/4884
proc map {prefix list} {
    set result {}
    foreach item ${list} {
        lappend result [{*}${prefix} ${item}]
    }
    return ${result}
}

set sdk_dir             ${prefix}/Developer/SDKs

use_configure           no

if {${os.platform} eq "darwin" && ${os.major} < 11} {
    # Having the stdlib set to libc++ on 10.6 causes a dependency on a
    # macports-clang compiler to be added, which is unnecessary.
    configure.cxx_stdlib
}

pre-destroot {
    xinstall -d ${destroot}${sdk_dir}
}

if {${subport} eq ${name}} {
    description         latest macOS SDK

    long_description    This port installs a link to the latest macOS SDK.

    distfiles
    supported_archs     noarch

    depends_run-append  port:MacOSX${version}.sdk

    build {}

    destroot {
        ln -s MacOSX${version}.sdk ${destroot}${sdk_dir}/MacOSX.sdk
    }
} else {
    set sdk_version     [lindex [split ${version} -] 0]
    set sdk_build       [lindex [split ${version} -] 1]
    set sdk_major       [join [lrange [split ${sdk_version} .] 0 1] .]

    description         ${macos_name} v${sdk_version} (${sdk_build}) SDK

    long_description    This port installs the ${macos_name} v${sdk_version} \
                        (${sdk_build}) SDK.

    # /usr/bin/cpio does not like to deal with some dmg contents:
    # cpio: Cannot restore xattr:com.apple.decmpfs: Permission denied
    depends_extract     port:libarchive

    set distfile        [lindex ${extract.only} 0]
    set ext             [file extension ${distfile}]
    switch ${ext} {
        .pkg {
            xar_file    ${distfile}
            xar_payload Payload
        }
        .xip {
            xar_file    ${distfile}
            xar_payload Content
        }
    }
    if {${xar_file} ne ""} {
        # /usr/bin/xar does not support -O / --to-stdout
        depends_extract-append \
                        port:xar
        if {${xar_pbzx}} {
            depends_extract-append \
                        port:xz
        }
    }

    set plist           /System/Library/CoreServices/SystemVersion.plist

    extract {
        set dmg [expr {${ext} eq ".dmg"}]
        set source_dir ${distpath}
        if {${xar_file} ne ""} {
            if {${xar_pbzx}} {
                set payload_decompress ${workpath}/pbzx
                system "${configure.cc} ${configure.cflags} ${configure.cppflags} ${configure.ldflags} [shellescape ${filespath}/pbzx.c] -llzma -o [shellescape ${payload_decompress}]"
            } else {
                set payload_decompress bzcat
            }
        }
        if {${dmg}} {
            set source_dir [mkdtemp "/tmp/mports.XXXXXX"]
            set hdiutil [findBinary hdiutil ${portutil::autoconf::hdiutil_path}]
            system "${hdiutil} attach [shellescape ${distpath}/${distfile}] -private -readonly -nobrowse -mountpoint [shellescape ${source_dir}]"
        }
        set escaped_extract_paths [join [map {shellescape} ${extract_paths}] { }]
        xinstall -d ${worksrcpath}
        if {${xar_file} ne ""} {
            system -W ${worksrcpath} "${prefix}/bin/xar -xOf [shellescape ${source_dir}/${xar_file}] [shellescape ${xar_payload}] | ${payload_decompress} | ${prefix}/bin/bsdcpio -idmu --quiet ${escaped_extract_paths}"
        } elseif {[llength ${extract_paths}] > 0} {
            system -W ${source_dir} "[findBinary find ${portutil::autoconf::find_path}] ${escaped_extract_paths} -depth -perm -+r | ${prefix}/bin/bsdcpio -pdmu --quiet [shellescape ${worksrcpath}]"
        }
        if {${dmg}} {
            system "${hdiutil} detach [shellescape ${source_dir}]"
            delete ${source_dir}
        }
        if {![file exists ${worksrcpath}/[lindex ${extract_paths} 0]${plist}]} {
            ui_error "we don't appear to have extracted everything properly"
            return -code error "extract problem"
        }
    }

    build {
        if {${os.major} < 9} {
            set plistbuddy {}
            fs-traverse item [list /Library/Receipts] {
                if {[file tail ${item}] eq "PlistBuddy" && [file isfile ${item}] && [file executable ${item}]} {
                    set plistbuddy ${item}
                    break
                }
            }
            if {${plistbuddy} eq {}} {
                ui_error "can't find PlistBuddy in /Library/Receipts"
                return -code error "PlistBuddy not found"
            }
        } else {
            set plistbuddy /usr/libexec/PlistBuddy
        }
        set extracted_version [join [split [exec ${plistbuddy} -c Print:ProductVersion -c Print:ProductBuildVersion ${worksrcpath}/[lindex ${extract_paths} 0]${plist}] "\n"] "-"]
        if {${version} ne ${extracted_version}} {
            ui_error "port version is ${version} but SDK version is ${extracted_version}"
            return -code error "version mismatch"
        }
    }

    destroot {
        move ${worksrcpath}/[lindex ${extract_paths} 0] ${destroot}${sdk_dir}/${subport}
    }

    if {[vercmp ${sdk_version} 11.0] >= 0} {
        supported_archs arm64 x86_64
    } elseif {[vercmp ${sdk_version} 10.14] >= 0} {
        supported_archs x86_64
    } elseif {[vercmp ${sdk_version} 10.7] >= 0} {
        supported_archs i386 x86_64
    } elseif {[vercmp ${sdk_version} 10.6] >= 0} {
        supported_archs i386 ppc x86_64
    }

    if {[llength ${supported_archs}] > 1} {
        configure.universal_archs {*}${supported_archs}
        variant universal {}
        default_variants +universal
        variant_set universal
    }
}

livecheck.type          none
