#!/bin/sh
# Fail if mult.o .data section or factor64.o _TEXT32 section
# are not aligned on a 32 byte boundary.

MAP=source23/linux/mapfile
MULT=mult.o
FACTOR64=factor64.o

MULT_ADDR=`grep ".data" $MAP | grep $MULT | tr -s \  | cut -d\  -f3`
FACTOR64_ADDR=`grep "_TEXT32" $MAP | grep $FACTOR64 | tr -s \   | cut -d\  -f3`

MULT_MATCHES=`expr $MULT_ADDR : '0x..............[02468aAcCeE]0'`
FACTOR64_MATCHES=`expr $FACTOR64_ADDR : '0x..............[02468aAcCeE]0'`

SUCCESS=true

echo -n "#" $MULT
case $MULT_MATCHES in
    18) echo -n " is ";;
    *) echo -n " is not "; SUCCESS=false;;
esac
echo 32 byte aligned.

echo -n "#" $FACTOR64
case $FACTOR64_MATCHES in
    18) echo -n " is ";;
    *) echo -n " is not "; SUCCESS=false;;
esac
echo 32 byte aligned.

if $SUCCESS; then
    exit 0;
else
    echo "# mprime is not correctly aligned. Edit source23/linux/makefile"
    echo "# to set DUMMY3 and DUMMY4 to the correct values for your system"
    echo "# (or use the binary package instead)."
    exit 1;
fi