#!/bin/sh

set -e

print_usage_and_exit() {
  echo "USAGE: $0 path/to/fglrxko_pci_ids.h fglrx_module fglrx_package" >&2
  exit 1
}

[ -n "$3" ] || {
  print_usage_and_exit
}

filename="$1"
modname="$2"
pkgname="$3"

[ -e "$filename" ] || {
  print_usage_and_exit
}

echo "# Listing generated by $pkgname. Do not edit manually."

grep "0x" "$filename" | \
  sed -n "s/FGL_ASIC_ID(0x\([0-9A-F]\{4\}\)),$/alias pci:v00001002d0000\1sv*sd*bc03sc*i* $modname $pkgname/p" | \
  sort | uniq | sed -e 's/^[ \t]*//'
