+echo =+=+=\r
+echo Checking libbz2 header...\r
+echo =+=+=\r
+set BZ2_TAR=bzip2-1.0.6-4-mingw32-dev.tar\r
+set BZ2_LZ=%BZ2_TAR%.lzma\r
+if not exist "%MINGW%\include\bzlib.h" (\r
+ if not exist %BZ2_LZ% (\r
+ wget "http://sourceforge.net/projects/mingw/files/MinGW/Extension/bzip2/bzip2-1.0.6-4/%BZ2_LZ%"\r
+ )\r
+ echo Extracting libbz2 header...\r
+ 7z e %BZ2_LZ%\r
+ 7z x %BZ2_TAR% -o"%MinGW%"\r
+ if ERRORLEVEL 1 goto Error\r
+ del %BZ2_TAR%\r
+)\r
+\r
+echo =+=+=\r
+echo Checking libbz2...\r
+echo =+=+=\r
+set BZ2DLL_TAR=libbz2-1.0.6-4-mingw32-dll-2.tar\r
+set BZ2DLL_LZ=%BZ2DLL_TAR%.lzma\r
+if not exist "%MINGW_BIN%\libbz2-2.dll" (\r
+ if not exist %BZ2DLL_LZ% (\r
+ wget "http://sourceforge.net/projects/mingw/files/MinGW/Extension/bzip2/bzip2-1.0.6-4/%BZ2DLL_LZ%"\r
+ )\r
+ echo Extracting libbz2...\r
+ 7z e %BZ2DLL_LZ%\r
+ 7z x %BZ2DLL_TAR% -o"%MinGW%"\r
+ if ERRORLEVEL 1 goto Error\r
+ del %BZ2DLL_TAR%\r
+)\r
+\r
+echo =+=+=\r
+echo Checking magic dev...\r
+echo =+=+=\r
+set MAGIC_ZIP=file-5.03-lib.zip\r
+if not exist "%MINGW%\include\magic.h" (\r
+ if not exist %MAGIC_ZIP% (\r
+ wget http://downloads.sourceforge.net/gnuwin32/%MAGIC_ZIP%\r
+ )\r
+ 7z x %MAGIC_ZIP% -o"%MinGW%"\r
+ if ERRORLEVEL 1 goto Error\r
+)\r
+\r
+echo =+=+=\r
+echo Checking magic DLL...\r
+echo =+=+=\r
+set MAGICDLL_ZIP=file-5.03-bin.zip\r
+if not exist "%MINGW_BIN%\magic1.dll" (\r
+ if not exist %MAGICDLL_ZIP% (\r
+ wget http://downloads.sourceforge.net/gnuwin32/%MAGICDLL_ZIP%\r
+ )\r
+ 7z x %MAGICDLL_ZIP% -o"%MinGW%"\r
+ if ERRORLEVEL 1 goto Error\r
+)\r
+\r
+echo =+=+=\r
+echo Checking regex DLL (required by magic)...\r
+echo =+=+=\r
+set REGDLL_ZIP=regex-2.7-bin.zip\r
+if not exist "%MINGW_BIN%\regex2.dll" (\r
+ if not exist %REGDLL_ZIP% (\r
+ wget http://downloads.sourceforge.net/gnuwin32/%REGDLL_ZIP%\r
+ )\r
+ 7z x %REGDLL_ZIP% -o"%MinGW%"\r
+ if ERRORLEVEL 1 goto Error\r
+)\r
+\r
+echo =+=+=\r
+echo Checking SQLite dev...\r
+echo =+=+=\r
+set SQL_ZIP=sqlite-amalgamation-3080002.zip\r
+if not exist "%MINGW%\include\sqlite3.h" (\r
+ if not exist %SQL_ZIP% (\r
+ wget http://www.sqlite.org/2013/%SQL_ZIP%\r
+ )\r
+ 7z x %SQL_ZIP%\r
+ if ERRORLEVEL 1 goto Error\r
+ copy /Y sqlite-amalgamation-3080002\s* "%MinGW%\include"\r
+ rmdir /S /Q sqlite-amalgamation-3080002\r
+)\r
+\r
+echo =+=+=\r
+echo Checking SQL DLL...\r
+echo =+=+=\r
+set SQLDLL_ZIP=sqlite-dll-win32-x86-3080002.zip\r
+if not exist "%MINGW_BIN%\sqlite3.dll" (\r
+ if not exist %SQLDLL_ZIP% (\r
+ wget http://www.sqlite.org/2013/%SQLDLL_ZIP%\r
+ )\r
+ 7z x %SQLDLL_ZIP% -o"%MinGW_BIN%"\r
+ if ERRORLEVEL 1 goto Error\r
+ REM Annoyingly SQL doesn't come with a .lib file so have to generate it ourselves:\r
+ REM Possibly need to insert the line 'LIBRARY sqlite3.dll' at the beginning of the def file?\r
+ REM but this may not be needed as the --dllname option may suffice\r
+ popd %MinGW_BIN%\r
+ dlltool -d sqlite3.def --dllname sqlite3.dll -l ..\lib\sqlite3.lib\r
+ pushd\r
+)\r
+\r