#!/bin/sh
# $Id$

prefix=/opt/local
bindir=${prefix}/bin
mandir=${prefix}/share/man
version=$(grep 'set VERSION' port_cutleaves.in | awk '{print $3}')

for i; do
    opt=$(echo ${i}|sed 's|=.*||g')
    val=$(echo ${i}|sed 's|.*=||g')

    if [ "--help" = "${opt}" ]; then
        echo "Options:"
        echo "  --prefix=PREFIX <${prefix}>"
        echo "  --bindir=BINDIR <${bindir}>"
        echo "  --mandir=MANDIR <${mandir}>"
        exit 0
    elif [ "--prefix" = "${opt}" ]; then
        prefix=${val}
        bindir=${prefix}/bin
        mandir=${prefix}/share/man
    elif [ "--bindir" = "${opt}" ]; then
        bindir=${val}
    elif [ "--mandir" = "${opt}" ]; then
        mandir=${val}
    fi
done

< Makefile.in \
    sed -e "s|@prefix@|${prefix}|g" \
    -e "s|@bindir@|${bindir}|g" \
    -e "s|@mandir@|${mandir}|g" \
    -e "s|@version@|${version}|g" > Makefile

sed "s|@prefix@|${prefix}|g" \
    < port_cutleaves.in > port_cutleaves
chmod +x port_cutleaves

sed "s|@prefix@|${prefix}|g" \
    < port_cutleaves.8.in > port_cutleaves.8
