[source]
git = "https://gitlab.redox-os.org/redox-os/drivers.git"

[build]
template = "custom"
script = """
# Drivers that are built on all architectures, and NOT in drivers-initfs
BINS=(
    alxd
    e1000d
    ihdad
    ixgbed
    pcid
    rtl8139d
    rtl8168d
    usbctl
    usbhidd
    usbhubd
    usbscsid
    virtio-netd
    xhcid
    inputd
)

# Add additional drivers to the list to build, that are not in drivers-initfs
# depending on the target architecture
case "${TARGET}" in
    i686-unknown-redox | x86_64-unknown-redox)
        BINS+=(ac97d bgad pcspkrd sb16d vboxd)
        ;;
    *)
        ;;
esac

#Build each driver in the list
mkdir -pv "${COOKBOOK_STAGE}/usr/bin" "${COOKBOOK_STAGE}/usr/lib/drivers"
export CARGO_PROFILE_RELEASE_OPT_LEVEL=s
export CARGO_PROFILE_RELEASE_PANIC=abort
"${COOKBOOK_CARGO}" build --release \
    --manifest-path "${COOKBOOK_SOURCE}/Cargo.toml" \
    $(for bin in "${BINS[@]}"; do echo "-p" "${bin}"; done)
for bin in "${BINS[@]}"
do
    if [[ "${bin}" == "inputd" || "${bin}" == "pcid" ]]; then
        cp -v "target/${TARGET}/release/${bin}" "${COOKBOOK_STAGE}/usr/bin"
    else
        cp -v "target/${TARGET}/release/${bin}" "${COOKBOOK_STAGE}/usr/lib/drivers"
    fi
done

mkdir -pv "${COOKBOOK_STAGE}/etc/pcid"
cp -v "${COOKBOOK_SOURCE}/initfs.toml" "${COOKBOOK_STAGE}/etc/pcid/initfs.toml"

mkdir -pv "${COOKBOOK_STAGE}/etc/pcid.d"
${FIND} "${COOKBOOK_SOURCE}" -maxdepth 3 -type f -name 'config.toml' | while read conf
do
    driver="$(basename "$(dirname "$conf")")"
    cp -v "$conf" "${COOKBOOK_STAGE}/etc/pcid.d/$driver.toml"
done
"""
