#!/bin/sh

configure_prefix=''

for a in "$@"; do
    case $a in
	--prefix=*)	prefix="${a#--prefix=}";;
	?)		echo "Warning: Ignoring argument $a" 1>&2;;
    esac
done

if [ -z "$prefix" ]; then
    echo "Error: Prefix was not set" 1>&2
    exit 64
fi

#
# GNU Make does not have a -V flag,
#  so we have to hardwire these values instead of asking the makefile for them
#

libdir="${prefix}/libexec/noweb"
texinputs="${prefix}/share/texmf/tex/generic/noweb"

sed -i .bk \
    -e "s@|TEXINPUTS|@${texinputs}@g" \
    -e "s@|LIBDIR|@${libdir}@g" \
    xdoc/cpif.1 \
    xdoc/nodefs.1 \
    xdoc/noroots.1 \
    xdoc/noweb.1 \
    xdoc/noindex.1 \
    xdoc/nuweb2noweb.1 \
    xdoc/notangle.1 \
    xdoc/noroff.1 \
    xdoc/sl2h.1 \
    xdoc/htmltoc.1 \
    xdoc/nowebstyle.7 \
    xdoc/nowebfilters.7 \
    shell/noweb \
    shell/notangle \
    shell/$(WEAVE) \
    shell/nountangle \
    shell/nodefs \
    shell/noroots \
    shell/nuweb2noweb \
    shell/cpif \
    shell/htmltoc \
    shell/noroff \
    shell/toroff
