#! /bin/sh
#
# $FreeBSD: ports/lang/modula-3-lib/scripts/configure,v 1.5 1999/08/30 12:01:10 peter Exp $

umask 022

temp_prefix=${WRKSRC}/installed
plist_src=${PKGDIR}/${PLIST##*/}
template_src=${FILESDIR}/FreeBSD2.${PORTOBJFORMAT}
template="${WRKSRC}/m3/m3build/templates/FreeBSD2"

if [ "${PORTOBJFORMAT}" = aout -a -f /usr/lib/aout/crt0.o ]; then
    crt0=/usr/lib/aout/crt0.o
else
    crt0=/usr/lib/crt0.o
fi
if [ "${PORTOBJFORMAT}" = aout -a -f /usr/lib/aout/libgcc.a ]; then
    libgcc=/usr/lib/aout/libgcc.a
else
    libgcc=/usr/lib/libgcc.a
fi

# Copy the appropriate m3build template file into place, patching up
# various pathnames in the process.
rm -f ${template}
sed -e "s|/usr/local/|${temp_prefix}/|g" \
    -e "s|!PREFIX!|${PREFIX}|g" \
    -e "s|/usr/lib/crt0\.o|${crt0}|g" \
    -e "s|/usr/lib/libgcc\.a|${libgcc}|g" \
    ${template_src} >${template}

# Our PLIST templates contain only the "libfoo.so" names for shared
# libraries.  Here we add the "libfoo.so.${MAJOR}" names.  This saves
# us from having to fix the PLIST every time we bump the version number.
sed -e "/\.so\$/p" \
    -e "s/\.so\$/&.${MAJOR}/" \
    ${plist_src} > ${PLIST}

# Also generate a "PLIST.real" file which includes the minor version
# numbers on shared library names if the object format is a.out.
if [ "${PORTOBJFORMAT}" = aout ]; then
    sed -e "s/\.so\.${MAJOR}\$/&.0/" ${PLIST} > ${PLIST}.real
else
    cp ${PLIST} ${PLIST}.real
fi
