#!/bin/sh -e
# -*- mode: Shell-script; tab-width: 8; fill-column: 70; -*-

PROG="${0##*/}"
#this path should match %docs_modules_prefix macro expansion
docs_modules_prefix="/usr/share/doc/alt-docs/modules"

Fatal() {
  printf "$PROG: Warning: %s\n" "$*" >&2
  exit 1
}

[ "$#" -gt 0 ] || Fatal "more argumets required"

requires=
# we must replace . with - in ModuleID to get a package name
for n in `sed -ne 's,^.* href="adt:\([^" ]\+\)".*$,\1,ip' $* `; do
    # Check for common error: author name is forgotten
    echo "$n" | grep -q '\.' || Fatal "forgotten author in adt link \"$n\""
    echo "$n" | grep -q '\.$' && Fatal "forgotten author in adt link \"$n\""
    NAME=${n%.*}
    AUTHOR=${n##*.}
    # Spaces will break build, it's normal. Correct html links not contain spaces
    requires="$requires docs-$NAME-$AUTHOR"
done

[ -n "$requires" ] || exit 0
 
echo "Requires:$requires"
