#!/bin/bash
# SPDX-FileCopyrightText: 2025 Torsten Keßler <tpkessler@archlinux.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

function help() {
    local -r COMMAND=${BASH_SOURCE[0]##*/}
    cat <<- __EOF__
        Usage: ${COMMAND} [OPTIONS]

        Print supported GPU targets for ROCm packages on Arch Linux

        OPTIONS
        -d        Delimiter for GPU architecture list
        -h        Show this help
__EOF__
}

function die() {
    >2 echo $1
    exit ${2:-1}
}

function supported() {
    local gfx=(
        gfx900
        gfx906:xnack-
        gfx908:xnack-
        gfx90a
        gfx942
        gfx950
        gfx1010
        gfx1012
        gfx1030
        gfx1100
        gfx1101
        gfx1102
        gfx1151
        gfx1152
        gfx1200
        gfx1201
    )
    local output
    printf -v output "%s$DELIM" "${gfx[@]}"
    echo "${output%${DELIM}}"
}

DELIM=";"
while getopts "d:h" opt; do
    case $opt in
        h)
            help
            exit 0
            ;;
        d)
            DELIM=$OPTARG
            ;;
        *)
            help
            die "Invalid option -- '${OPTARG:-${!OPTIND:-${opt:-}}}'" 1
            ;;
    esac
done

supported DELIM
