#!/bin/sh

rm -f hisocli_64
rm -f hisocli_32
rm -f hisocli_aa64
rm -f hisocli_m64e

SRCS="hisocli.c hisofat.c hisogpt.c crc32.c partresize.c"

gcc -specs "/usr/local/musl/lib/musl-gcc.specs" -Os -static -D_FILE_OFFSET_BITS=64 $SRCS -Ifat_io_lib/include fat_io_lib/lib/libfat_io_64.a -o hisocli_64

/opt/diet32/bin/diet -Os gcc -D_FILE_OFFSET_BITS=64 -m32 $SRCS -Ifat_io_lib/include fat_io_lib/lib/libfat_io_32.a -o hisocli_32


#gcc -O2 -D_FILE_OFFSET_BITS=64 $SRCS -Ifat_io_lib/include fat_io_lib/lib/libfat_io_64.a -o hisocli_64
#gcc -m32 -O2 -D_FILE_OFFSET_BITS=64 $SRCS -Ifat_io_lib/include fat_io_lib/lib/libfat_io_32.a -o hisocli_32

aarch64-buildroot-linux-uclibc-gcc -static -O2 -D_FILE_OFFSET_BITS=64 $SRCS -Ifat_io_lib/include fat_io_lib/lib/libfat_io_aa64.a -o hisocli_aa64
mips64el-linux-musl-gcc -mips64r2 -mabi=64 -static -O2 -D_FILE_OFFSET_BITS=64 $SRCS -Ifat_io_lib/include fat_io_lib/lib/libfat_io_m64e.a -o hisocli_m64e


if [ -e hisocli_64 ] && [ -e hisocli_32 ] && [ -e hisocli_aa64 ] && [ -e hisocli_m64e ]; then
    echo -e "\n===== success $name =======\n"
    
    strip --strip-all hisocli_32
    strip --strip-all hisocli_64
    aarch64-buildroot-linux-uclibc-strip --strip-all hisocli_aa64
    mips64el-linux-musl-strip --strip-all hisocli_m64e
    
    [ -d ../INSTALL/tool/i386/ ] && mv hisocli_32 ../INSTALL/tool/i386/hisocli
    [ -d ../INSTALL/tool/x86_64/ ] && mv hisocli_64 ../INSTALL/tool/x86_64/hisocli
    [ -d ../INSTALL/tool/aarch64/ ] && mv hisocli_aa64 ../INSTALL/tool/aarch64/hisocli
    [ -d ../INSTALL/tool/mips64el/ ] && mv hisocli_m64e ../INSTALL/tool/mips64el/hisocli
else
    echo -e "\n===== failed =======\n"
    exit 1
fi
