#!/bin/bash

cd "$(dirname "$0")"
eval "$(
  sed -n '
    /^source=(/,/)/ p
  ' PKGBUILD
)"

makepkg --verifysource
git -C openttd-git fetch local
git -C openttd-git fetch --all -p
updpkgsums

printf '%s\n' "${source[@]}" \
| sed '
  s/\.patch$//
  /-pre$/d
  t
  d
' \
| while read -r patch; do
  git -C openttd-git diff $(git -C openttd-git merge-base master "remotes/local/${patch}") "remotes/local/${patch}" -- \
  > "${patch}.patch"
done
updpkgsums