# -*- 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 21
subport bash50 {
    # used by bashdb port
    set bash_version    5.0
    set bash_patchlevel 18
}
version             ${bash_version}.${bash_patchlevel}
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
} elseif {${subport} eq "bash50"} {
   conflicts        bash
}

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
} 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           bin:bison:bison
# ar: internal ranlib command failed
depends_build-append    port:cctools

depends_lib             port:gettext \
                        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)
