Welcome to little lamb

Code » limb » master » tree

[master] / tools / mkendian

#!/bin/sh

dief()
{
    echo "$0: fatal: $@" >&2
    exit 1
}

isle=0
isbe=0
ispdp=0

if ! test -e config.tmp/endian; then dief "missing config.tmp/endian"; fi
endian="$(cat config.tmp/endian 2>/dev/null)"
case "$endian" in
    LITTLE) isle=1 ;;
    BIG) isbe=1 ;;
    PDP) ispdp=1 ;;
    *) dief "invalid endian: $endian" ;;
esac

cat <<EOF
#ifndef LIMB_ENDIAN_H
#define LIMB_ENDIAN_H

#define LIMB_LITTLE    1234
#define LIMB_BIG       4321
#define LIMB_PDP       3412
#define LIMB_ENDIAN    LIMB_$endian

#define LIMB_IS_LE    $isle
#define LIMB_IS_BE    $isbe
#define LIMB_IS_PDP   $ispdp

#endif /* LIMB_ENDIAN_H */
EOF