#!/bin/sh

#
#  Usage:  build <archdir> <archprefix> <dest> <strip> <object>...
#

# Base of architecture-dependent directory
ARCHDIR=$1

# Prefix of architecture-dependent tools
ARCHPREFIX=$2

# Pathname of library file to generate
DEST=$3

# "strip" or "nostrip"
STRIP=$4

shift 4

if [ -r ${ARCHDIR}/target/lib/ld.so.1 ] ; then
    DYNLINKER="ld.so.1"
elif [ -r ${ARCHDIR}/target/lib/ld-linux.so.2 ] ; then
    DYNLINKER="ld-linux.so.2"
else
    echo "Dynamic linker not found; cannot build libm.so.6" >&2
    exit 1
fi
    
TOOLPREFIX=${ARCHDIR}/bin/${ARCHPREFIX}

${TOOLPREFIX}gcc -shared -Wl,-O1 -o ${DEST} \
    -Wl,-dynamic-linker=/lib/${DYNLINKER} \
    -Wl,--version-script=libm.map -Wl,-soname=libm.so.6 \
    -T libm.so.lds \
    abi-note.o $* interp.o \
    ${ARCHDIR}/target/lib/libc.so.6 libc_nonshared.a
if [ "$STRIP" = "strip" ] ; then
    ${TOOLPREFIX}strip -R .note -R .comment ${DEST}
fi
