#!/bin/sh

target_file=debian/targets

awk '/^[a-z0-9]/{print $2}' ${target_file} | sort -u | while read subarch ; do
    case ${subarch} in
        -) package=u-boot ;;
        *) package=u-boot-${subarch} ;;
    esac
    overrides=debian/${package}.lintian-overrides

    cat >${overrides}<<EOF

# There are no file conflicts across architectures for u-boot, as each
# target is only installed on a single architecture. In theory, some
# targets could be built on multiple architectures, but could instead install
# the package for the architecture needed.
EOF

    sed -n "/^[a-z0-9].*[[:space:]]$subarch[[:space:]]/p" ${target_file} | while read arch subarch2 platform targets ; do
        echo "${package} binary: arch-dependent-file-not-in-arch-specific-directory usr/lib/u-boot/*/uboot.elf"
    done | LC_ALL=C sort -u >> ${overrides}

    cat >>${overrides}<<EOF

# These bootloaders need to be statically linked.
EOF

    sed -n "/^[a-z0-9].*[[:space:]]$subarch[[:space:]]/p" ${target_file} | while read arch subarch2 platform targets ; do
        echo "${package} binary: statically-linked-binary usr/lib/u-boot/*/uboot.elf"
    done | LC_ALL=C sort -u >> ${overrides}

    cat >>${overrides}<<EOF

# These are bootloader binaries, and have no external dependency information
EOF

    sed -n "/^[a-z0-9].*[[:space:]]$subarch[[:space:]]/p" ${target_file} | while read arch subarch2 platform targets ; do
        echo "${package} binary: shared-lib-without-dependency-information usr/lib/u-boot/*/uboot.elf"
    done | LC_ALL=C sort -u >> ${overrides}

    cat >>${overrides}<<EOF

${package}: description-synopsis-starts-with-article

EOF
done

package=u-boot-qemu
overrides=debian/${package}.lintian-overrides
cat >>${overrides}<<EOF

# These are binary firmware blobs
EOF

sed -n "/^all:.*[[:space:]]qemu[[:space:]]/p" ${target_file} | while read arch subarch2 platform targets ; do
        echo "${package} binary: arch-independent-package-contains-binary-or-object usr/lib/u-boot/*/uboot.elf"
done | LC_ALL=C sort -u >> ${overrides}
