#!/bin/sh

PKG_NAME=sin_msdos_sse_latest.7z
rm -f $PKG_NAME

./cleanall.sh

. ./cross_defs.dj

mkdir -p _build || exit 1

make CC=$TARGET-gcc CXX=$TARGET-g++ -f Makefile.dj clean $*     || exit 1
make CC=$TARGET-gcc CXX=$TARGET-g++ AR=$TARGET-ar RANLIB=$TARGET-ranlib -f Makefile.dj USE_ASM=1 USE_SSE=1 DEBUG=0 $*     || exit 1
upx -9 sin_sse.exe || exit 1

make CC=$TARGET-gcc CXX=$TARGET-g++ -f Makefile.dj clean $*     || exit 1
make CC=$TARGET-gcc CXX=$TARGET-g++ -f Makefile.dj USE_ASM=1 USE_SSE=1 DEBUG=0 REF_DXE=0 REF_STATIC_GL=1 REFGL_DRIVER=sage $*     || exit 1
mv sin_fx.exe sin_sage.exe
upx -9 sin_sage.exe || exit 1

make CC=$TARGET-gcc CXX=$TARGET-g++ -f Makefile.dj clean $*     || exit 1
make CC=$TARGET-gcc CXX=$TARGET-g++ -f Makefile.dj USE_ASM=1 USE_SSE=1 DEBUG=0 REF_DXE=0 REF_STATIC_GL=1 REFGL_DRIVER=mesa $*     || exit 1
upx -9 sin_fx.exe || exit 1

make CC=$TARGET-gcc CXX=$TARGET-g++ -C ref_gl -f Makefile.dj clean $* || exit 1
make CC=$TARGET-gcc CXX=$TARGET-g++ -C ref_gl -f Makefile.dj USE_ASM=1 USE_SSE=1 DEBUG=0 $* || exit 1

make CC=$TARGET-gcc CXX=$TARGET-g++ -C ref_soft -f Makefile.dj clean $* || exit 1
make CC=$TARGET-gcc CXX=$TARGET-g++ -C ref_soft -f Makefile.dj USE_ASM=1 USE_SSE=1 DEBUG=0 $* || exit 1

make CC=$TARGET-gcc CXX=$TARGET-g++ -C game -f Makefile.dj clean $* || exit 1
make CC=$TARGET-gcc CXX=$TARGET-g++ -C game -f Makefile.dj USE_ASM=1 USE_SSE=1 DEBUG=0 $* || exit 1

make CC=$TARGET-gcc CXX=$TARGET-g++ -C 2015 -f Makefile.dj clean $* || exit 1
make CC=$TARGET-gcc CXX=$TARGET-g++ -C 2015 -f Makefile.dj USE_ASM=1 USE_SSE=1 DEBUG=0 $* || exit 1

cp -p sin_sse.exe _build
cp -p sin_fx.exe _build
cp -p sin_sage.exe _build
cp -p ref_gl/ref_gl.dxe _build
cp -p ref_soft/ref_soft.dxe _build
cp -p readme.txt _build
cp -p readme.fx _build
cp -p status-djgpp.txt _build

mkdir -p _build/base
cp -p game/gamex86.dxe _build/base
mkdir -p _build/ctf
cp -p game/gamex86.dxe _build/ctf
mkdir -p _build/2015
cp -p 2015/gamex86.dxe _build/2015

cd _build || exit 1
echo "These SSE builds are entirely UNSUPPORTED and provided only as a convenience!  Please do not send us bug reports from them, Thanks!" > !READ_SSE.txt
unix2dos -k !READ_SSE.txt
unix2dos -k readme.txt
unix2dos -k readme.fx
unix2dos -k status-djgpp.txt
find * -type d|xargs chmod 755
find * -type f|xargs chmod 644
7z a -mx9 -mmt ../$PKG_NAME *
