@ECHO OFF
rem Nnecessary ext. tools (lib.exe link.exe msvcr100.dll)
SET ORGPATH=%PATH%
SET GCCBIN=""

if not exist %GCCBIN% FOR /F "usebackq" %%t IN (`83 "%ProgramFiles%\BestTech\GCC Developer Lite\GCC\"`) DO SET GCCBIN=%%t
if not exist %GCCBIN% FOR /F "usebackq" %%t IN (`83 "%ProgramFiles(x86)%\BestTech\GCC Developer Lite\GCC\"`) DO SET GCCBIN=%%t
if not exist %GCCBIN% goto err

echo #### 32bit ####
SET PATH=%GCCBIN%x86\bin;%ORGPATH%
del dx2lib_x32.dll
gcc -shared -static-libgcc -static-libstdc++ -D__MAKE_LIB__ -o dx2lib_x32.dll dx2lib_intuitive.cpp dx2lib.cpp -O3 -Wall -Wno-main -Wno-sign-compare -Wshadow -Wcast-align -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wunused -Wl,--add-stdcall-alias,--output-def,dx2lib_x32.def,--out-implib,libdx2lib_x32.a
if not exist dx2lib_x32.dll goto err
if not exist lib.exe goto err
lib /DEF:dx2lib_x32.def /MACHINE:X86 /out:dx2lib_x32.lib
strip dx2lib_x32.dll

echo #### 64bit ####
SET PATH=%GCCBIN%x64\bin;%ORGPATH%
del dx2lib_x64.dll
gcc -shared -static-libgcc -static-libstdc++ -D__MAKE_LIB__ -o dx2lib_x64.dll dx2lib_intuitive.cpp dx2lib.cpp -O3 -Wall -Wno-main -Wno-sign-compare -Wshadow -Wcast-align -Wpointer-arith -Wswitch -Wredundant-decls -Wreturn-type -Wshadow -Wunused -Wl,--add-stdcall-alias,--output-def,dx2lib_x64.def,--out-implib,libdx2lib_x64.a
if not exist dx2lib_x64.dll goto err
if not exist lib.exe goto err
lib /DEF:dx2lib_x64.def /MACHINE:X64 /out:dx2lib_x64.lib
strip dx2lib_x64.dll
goto ok

:err
echo ---------------------------
echo !! create lib error !!
echo ---------------------------
pause
goto fin

:ok
echo ---------------------------
echo !! create lib success !!
echo ---------------------------
goto fin

:fin
SET PATH=%ORGPATH%
