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

name                bash
set bash_version    5.2
set bash_patchlevel 37
subport bash50 {
    # used by bashdb port
    set bash_version    5.0
    set bash_patchlevel 18
}
version             ${bash_version}.${bash_patchlevel}
subport bash-devel {
    version             20241126
    set bash_patchlevel 0

    fetch.type          git
    git.url             git://git.savannah.gnu.org/bash.git
    git.branch          49c2670226b045746d66765b23af37c1c7ba5597
}
distname            ${name}-${bash_version}
categories          shells
platforms           darwin freebsd
license             GPL-3+
maintainers         {raimue @raimue}
description         Bash (bourne-again shell) is a UNIX command interpreter
long_description    \
    Bash is an sh-compatible shell that incorporates useful     \
    features from the Korn shell (ksh) and C shell (csh). It is     \
    intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell  \
    and Tools standard. It offers functional improvements over sh   \
    for both programming and interactive use. In addition, most     \
    sh scripts can be run by Bash without modification.
homepage            https://www.gnu.org/software/bash/bash.html
if {${subport} eq ${name}} {
   conflicts        bash50 bash-devel
} elseif {${subport} eq "bash50"} {
   conflicts        bash bash-devel
} elseif {${subport} eq "bash-devel"} {
   conflicts        bash bash50
}

if {${subport} eq "bash50"} {
    # https://www.mail-archive.com/bug-bash@gnu.org/msg25109.html
    # bash 5.0 lacks fixes needed to build on arm
    supported_archs     x86_64
}

master_sites        gnu
patch_sites         gnu:${name}/${distname}-patches
dist_subdir         ${name}/${bash_version}_1

# Generate patchfiles
for {set i 1} {$i <= $bash_patchlevel} {incr i} {
    patchfiles-append \
        [format "%s%s-%03d" $name [strsed ${bash_version} {g/\.//}] $i]
}

if {${subport} eq ${name}} {
    checksums           ${distname}${extract.suffix} \
                        rmd160  03d6cad0dce2c1bf6682afb88376feb0636cbc16 \
                        sha256  a139c166df7ff4471c5e0733051642ee5556c1cc8a4a78f145583c5c81ab32fb \
                        size    10950833

    checksums-append    bash52-001 \
                        rmd160  323c6de804d6c492c8df55f9e65222f5ae76e224 \
                        sha256  f42f2fee923bc2209f406a1892772121c467f44533bedfe00a176139da5d310a \
                        size    1381 \
                        bash52-002 \
                        rmd160  9340accbdbbcd25e22c0bc88e9c4f6a7a9075215 \
                        sha256  45cc5e1b876550eee96f95bffb36c41b6cb7c07d33f671db5634405cd00fd7b8 \
                        size    1328 \
                        bash52-003 \
                        rmd160  be06c915def9608d5dc19e735719792c3f8077d3 \
                        sha256  6a090cdbd334306fceacd0e4a1b9e0b0678efdbbdedbd1f5842035990c8abaff \
                        size    2157 \
                        bash52-004 \
                        rmd160  784a7e1fd83d0f438dee7ba87de48289cff6992c \
                        sha256  38827724bba908cf5721bd8d4e595d80f02c05c35f3dd7dbc4cd3c5678a42512 \
                        size    2016 \
                        bash52-005 \
                        rmd160  b0072da7328a3c2b0b9316c5e4465839415be5b3 \
                        sha256  ece0eb544368b3b4359fb8464caa9d89c7a6743c8ed070be1c7d599c3675d357 \
                        size    1515 \
                        bash52-006 \
                        rmd160  a95de86478b30457c4cc5682fa79e7b273a9e7d6 \
                        sha256  d1e0566a257d149a0d99d450ce2885123f9995e9c01d0a5ef6df7044a72a468c \
                        size    8790 \
                        bash52-007 \
                        rmd160  022a28c6daccd271ce6ea8e4f92c0500bef8c173 \
                        sha256  2500a3fc21cb08133f06648a017cebfa27f30ea19c8cbe8dfefdf16227cfd490 \
                        size    9072 \
                        bash52-008 \
                        rmd160  a23ea17ed4d97955c6f8505ff2c4e4a222111a0f \
                        sha256  6b4bd92fd0099d1bab436b941875e99e0cb3c320997587182d6267af1844b1e8 \
                        size    1771 \
                        bash52-009 \
                        rmd160  3e9e427247ca34ecf95e6d5674ed6471cb73be0a \
                        sha256  f95a817882eaeb0cb78bce82859a86bbb297a308ced730ebe449cd504211d3cd \
                        size    1316 \
                        bash52-010 \
                        rmd160  20808bd0d6a3f6bf6fad9afabf86f92ab137d7dc \
                        sha256  c7705e029f752507310ecd7270aef437e8043a9959e4d0c6065a82517996c1cd \
                        size    2045 \
                        bash52-011 \
                        rmd160  f14caeae72a607d4d334ff10fea2275550851a9a \
                        sha256  831b5f25bf3e88625f3ab315043be7498907c551f86041fa3b914123d79eb6f4 \
                        size    1229 \
                        bash52-012 \
                        rmd160  f605d65b520d8c92bbe4640511ff0940fb95d4fb \
                        sha256  2fb107ce1fb8e93f36997c8b0b2743fc1ca98a454c7cc5a3fcabec533f67d42c \
                        size    9107 \
                        bash52-013 \
                        rmd160  261e3b88a1905316fef2cc657883d0523c25818c \
                        sha256  094b4fd81bc488a26febba5d799689b64d52a5505b63e8ee854f48d356bc7ce6 \
                        size    1503 \
                        bash52-014 \
                        rmd160  0639d98227ebd71c2a252348ae23522862af2427 \
                        sha256  3ef9246f2906ef1e487a0a3f4c647ae1c289cbd8459caa7db5ce118ef136e624 \
                        size    3245 \
                        bash52-015 \
                        rmd160  4b96fdd43e1fea45fb69c3418d40199a581e7dfb \
                        sha256  ef73905169db67399a728e238a9413e0d689462cb9b72ab17a05dba51221358a \
                        size    8088 \
                        bash52-016 \
                        rmd160  04013fbe5d21a8c583395c0c6b1efe960a44526b \
                        sha256  155853bc5bd10e40a9bea369fb6f50a203a7d0358e9e32321be0d9fa21585915 \
                        size    1225 \
                        bash52-017 \
                        rmd160  6438d9ab91b46e9d2949c595162eb5007b5e9f9c \
                        sha256  1c48cecbc9b7b4217990580203b7e1de19c4979d0bd2c0e310167df748df2c89 \
                        size    1396 \
                        bash52-018 \
                        rmd160  6569790215d8c1d140a5f3a9082980f194bd6f18 \
                        sha256  4641dd49dd923b454dd0a346277907090410f5d60a29a2de3b82c98e49aaaa80 \
                        size    151467 \
                        bash52-019 \
                        rmd160  51be97047a006d15b14c81a25b2d65f10f6f0b3f \
                        sha256  325c26860ad4bba8558356c4ab914ac57e7b415dac6f5aae86b9b05ccb7ed282 \
                        size    2548 \
                        bash52-020 \
                        rmd160  b1de66a2edf18a5a0070986f119b3e191199cf39 \
                        sha256  b6fc252aeb95ce67c9b017d29d81e8a5e285db4bf20d4ec8cdca35892be5c01d \
                        size    1459 \
                        bash52-021 \
                        rmd160  afa6fea5edd7d253a49b5cfca67293d37e064adb \
                        sha256  8334b88117ad047598f23581aeb0c66c0248cdd77abc3b4e259133aa307650cd \
                        size    1890 \
                        bash52-022 \
                        rmd160  458bf889fc9d3fea00558deaf4e0d119badc1d7c \
                        sha256  78b5230a49594ec30811e72dcd0f56d1089710ec7828621022d08507aa57e470 \
                        size    1305 \
                        bash52-023 \
                        rmd160  38f12fc2e5486afff99259592ca68f88717fb6c4 \
                        sha256  af905502e2106c8510ba2085aa2b56e64830fc0fdf6ee67ebb459ac11696dcd3 \
                        size    1817 \
                        bash52-024 \
                        rmd160  64770d95e7d974160115b524b661ab8e06ee960c \
                        sha256  971534490117eb05d97d7fd81f5f9d8daf927b4d581231844ffae485651b02c3 \
                        size    2298 \
                        bash52-025 \
                        rmd160  ea44747bf5642655d0452ebbfc5d3a1bd706afd2 \
                        sha256  5138f487e7cf71a6323dc81d22419906f1535b89835cc2ff68847e1a35613075 \
                        size    1454 \
                        bash52-026 \
                        rmd160  9a4710c808def2c4d1337c81bd761936be0d9bc5 \
                        sha256  96ee1f549aa0b530521e36bdc0ba7661602cfaee409f7023cac744dd42852eac \
                        size    1372 \
                        bash52-027 \
                        rmd160  fa30b5e39ac2c6bd310ba77b1817aa2243ce8367 \
                        sha256  e12a890a2e4f0d9c6ec1ce65b73da4fe116c8e4209bac8ac9dc4cd96f486ab39 \
                        size    1881 \
                        bash52-028 \
                        rmd160  d63afa9945c1ffae75151e688cd756d2dbee758f \
                        sha256  6042780ba2893daca4a3f0f9b65728592cd7bb6d4cebe073855a6aad4d63aac1 \
                        size    1571 \
                        bash52-029 \
                        rmd160  e7d5b1f14eef4c1b7d55d2f1d17610957e5d02c7 \
                        sha256  125cacb37e625471924b3ee06c54cb1bf21b3b7fe0e569d24a681b0ec4a29987 \
                        size    3619 \
                        bash52-030 \
                        rmd160  afe33531734a9b157c5d15eb62590f80c012a2cd \
                        sha256  c3ff73230e123acdb5ac216921a386df8f74340459533d776d02811a1f76698f \
                        size    4111 \
                        bash52-031 \
                        rmd160  66dbb9443510b7bc2752c5916ef57e9a129fe4da \
                        sha256  c2d1b7be2df771126105020af7fafa00fffd4deff4a4e45d60fc6a235bcba795 \
                        size    1159 \
                        bash52-032 \
                        rmd160  2ec870b706258160f24334b82faf264dbcd2633a \
                        sha256  7b9c77daeca93ff711781d7537234166e83ed9835ce1ee7dcd5742319c372a16 \
                        size    1529 \
                        bash52-033 \
                        rmd160  4897a12d2ff129c2bb9d42d14cf74533bbb15882 \
                        sha256  013ec6cc10ad98060a7c34ed5c11187bcc5bf4510f32de0d545db89a9a52a2e2 \
                        size    2131 \
                        bash52-034 \
                        rmd160  0f1b8abb53d1318a9b2ee26bd118718c30324772 \
                        sha256  899fbb3b338048fe52a9c8252bf65ef1194cdff4f7a3fb3316f5f2396143232e \
                        size    4134 \
                        bash52-035 \
                        rmd160  c28e4f772d5486f4e60fe16d6e71bdb08efcfd7f \
                        sha256  821a0a47fa692bb0a39482728b1b396bf951e2912768fea6f3026c813c1913e5 \
                        size    3413 \
                        bash52-036 \
                        rmd160  af62b1bf1d062d5ef016b89d91c0c227d31fc070 \
                        sha256  15c93f4936a5e5b88301f3ede767a23d3dd19635af2f3a91fb4cc0e560ca9057 \
                        size    5941 \
                        bash52-037 \
                        rmd160  137255087bccdc8eb4eae5791383c35a758078e1 \
                        sha256  8a2c1c3b5125d9ae5b47882f7d2ddf9648805f8c67c13aa5ea7efeac475cda94 \
                        size    2835
} elseif {${subport} eq "bash50"} {
   checksums           ${distname}${extract.suffix} \
                       rmd160  a081428a896d617855499376b670eca3433a27c1 \
                       sha256  b4a80f2ac66170b2913efbfb9f2594f1f76c7b1afd11f799e22035d63077fb4d \
                       size    10135110

   checksums-append    bash50-001 \
                       rmd160  20cde6fea8fb371d1d00d10496c1f5b1d9c71182 \
                       sha256  f2fe9e1f0faddf14ab9bfa88d450a75e5d028fedafad23b88716bd657c737289 \
                       size    4133 \
                       bash50-002 \
                       rmd160  a1eb7734493903e9eb25b3c1b48d69ee7a01da5e \
                       sha256  87e87d3542e598799adb3e7e01c8165bc743e136a400ed0de015845f7ff68707 \
                       size    4380 \
                       bash50-003 \
                       rmd160  c964aa0deb96a5efe5e0d9cf123d0e5345c77efc \
                       sha256  4eebcdc37b13793a232c5f2f498a5fcbf7da0ecb3da2059391c096db620ec85b \
                       size    6434 \
                       bash50-004 \
                       rmd160  90417dbb08702281201614df0518d1534dcf6f48 \
                       sha256  14447ad832add8ecfafdce5384badd933697b559c4688d6b9e3d36ff36c62f08 \
                       size    1664 \
                       bash50-005 \
                       rmd160  9662d5e3ed43a14b80845ecb6a5916733113a126 \
                       sha256  5bf54dd9bd2c211d2bfb34a49e2c741f2ed5e338767e9ce9f4d41254bf9f8276 \
                       size    3732 \
                       bash50-006 \
                       rmd160  702429f2e21e61cb39f7ecc579fc61bfaa5f4991 \
                       sha256  d68529a6ff201b6ff5915318ab12fc16b8a0ebb77fda3308303fcc1e13398420 \
                       size    1275 \
                       bash50-007 \
                       rmd160  75f55a086cb11db8fb0faa001a7fe8d77b17b30f \
                       sha256  17b41e7ee3673d8887dd25992417a398677533ab8827938aa41fad70df19af9b \
                       size    1640 \
                       bash50-008 \
                       rmd160  e4076df3d86bb750c2fd72766fcdf855a92b9269 \
                       sha256  eec64588622a82a5029b2776e218a75a3640bef4953f09d6ee1f4199670ad7e3 \
                       size    2622 \
                       bash50-009 \
                       rmd160  55a8d44d5ef731d4996bdf69dcf6a80105ca168e \
                       sha256  ed3ca21767303fc3de93934aa524c2e920787c506b601cc40a4897d4b094d903 \
                       size    1095 \
                       bash50-010 \
                       rmd160  40599f5fe2f5a9cfa9324cd31c0487166ff68f5a \
                       sha256  d6fbc325f0b5dc54ddbe8ee43020bced8bd589ddffea59d128db14b2e52a8a11 \
                       size    6407 \
                       bash50-011 \
                       rmd160  d2866cbdf4f5a8e1f79ff4795b6045a45bea4627 \
                       sha256  2c4de332b91eaf797abbbd6c79709690b5cbd48b12e8dfe748096dbd7bf474ea \
                       size    1870 \
                       bash50-012 \
                       rmd160  3c08d0e8a96645112fe86c407637f2d030319a7a \
                       sha256  2943ee19688018296f2a04dbfe30b7138b889700efa8ff1c0524af271e0ee233 \
                       size    1571 \
                       bash50-013 \
                       rmd160  824d45c5779bf238b2891a4906a38d7e49f71ea8 \
                       sha256  f5d7178d8da30799e01b83a0802018d913d6aa972dd2ddad3b927f3f3eb7099a \
                       size    2328 \
                       bash50-014 \
                       rmd160  1f36acc05688999814a8932ac87fcbd8f2f71b4c \
                       sha256  5d6eee6514ee6e22a87bba8d22be0a8621a0ae119246f1c5a9a35db1f72af589 \
                       size    1747 \
                       bash50-015 \
                       rmd160  540db9eff2543184e504f2de9bff3c07642c2ce5 \
                       sha256  a517df2dda93b26d5cbf00effefea93e3a4ccd6652f152f4109170544ebfa05e \
                       size    2565 \
                       bash50-016 \
                       rmd160  19d5f631e0181e2671f9bcb8ee7419a46f99008e \
                       sha256  ffd1d7a54a99fa7f5b1825e4f7e95d8c8876bc2ca151f150e751d429c650b06d \
                       size    1534 \
                       bash50-017 \
                       rmd160  a46602c2186a902f20f3260da2bbde825b7a8ad9 \
                       sha256  4cf3b9fafb8a66d411dd5fc9120032533a4012df1dc6ee024c7833373e2ddc31 \
                       size    6517 \
                       bash50-018 \
                       rmd160  f3c61856439972d3a5b51c8140bb6899c259816e \
                       sha256  7c314e375a105a6642e8ed44f3808b9def89d15f7492fe2029a21ba9c0de81d3 \
                       size    1242

    patchfiles-append  patch-configure.diff
}

depends_build           port:bison \
                        port:gettext
# ar: internal ranlib command failed
depends_build-append    port:cctools

depends_lib             port:gettext-runtime \
                        port:ncurses

variant universal {}

compiler.blacklist-append *gcc-4.* {clang < 400}

configure.ldflags-append \
    "-Wl,-search_paths_first -lncurses"
configure.args          --mandir=${prefix}/share/man \
                        --infodir=${prefix}/share/info \
                        --without-installed-readline \
                        CFLAGS_FOR_BUILD="[get_canonical_archflags]"

# Always source .bashrc when connecting remotely with ssh, #40603
configure.cflags-append -DSSH_SOURCE_BASHRC

configure.checks.implicit_function_declaration.whitelist-append strchr

livecheck.type          regex
livecheck.url           https://ftp.gnu.org/gnu/${name}/${name}-${bash_version}-patches/?C=M&O=D
livecheck.version       [format %03d ${bash_patchlevel}]
livecheck.regex         ${name}[strsed ${bash_version} {g/\.//}]-(\\d\\d\\d)