#!/bin/sh

rm -f hisofat_64
rm -f hisofat_32
rm -f hisofat_aa64
rm -f hisofat_m64e


gcc -O2 -D_FILE_OFFSET_BITS=64 hisofat_linux.c -Ifat_io_lib/include fat_io_lib/lib/libfat_io_64.a -o hisofat_64
gcc -m32 -O2 -D_FILE_OFFSET_BITS=64 hisofat_linux.c -Ifat_io_lib/include fat_io_lib/lib/libfat_io_32.a -o hisofat_32
aarch64-buildroot-linux-uclibc-gcc -static -O2 -D_FILE_OFFSET_BITS=64 hisofat_linux.c -Ifat_io_lib/include fat_io_lib/lib/libfat_io_aa64.a -o hisofat_aa64
mips64el-linux-musl-gcc -mips64r2 -mabi=64 -static -O2 -D_FILE_OFFSET_BITS=64 hisofat_linux.c -Ifat_io_lib/include fat_io_lib/lib/libfat_io_m64e.a -o hisofat_m64e


if [ -e hisofat_64 ] && [ -e hisofat_32 ] && [ -e hisofat_aa64 ] && [ -e hisofat_m64e ]; then
    echo -e "\n===== success $name =======\n"
    
    strip --strip-all hisofat_32
    strip --strip-all hisofat_64
    aarch64-buildroot-linux-uclibc-strip --strip-all hisofat_aa64
    mips64el-linux-musl-strip --strip-all hisofat_m64e
    
    [ -d ../INSTALL/tool/i386/ ] && mv hisofat_32 ../INSTALL/tool/i386/hisofat
    [ -d ../INSTALL/tool/x86_64/ ] && mv hisofat_64 ../INSTALL/tool/x86_64/hisofat
    [ -d ../INSTALL/tool/aarch64/ ] && mv hisofat_aa64 ../INSTALL/tool/aarch64/hisofat
    [ -d ../INSTALL/tool/mips64el/ ] && mv hisofat_m64e ../INSTALL/tool/mips64el/hisofat
else
    echo -e "\n===== failed =======\n"
    exit 1
fi
