@echo off
SETLOCAL

set CURRENT=%~dp0
echo %CURRENT%
set PKGPATH=%CURRENT%

echo.
echo =============================================
echo = HDF5 library                              =
echo =============================================

REM sepcial settings for HDF5
set PKG_ZLIB=zlib-1.2.1
set HDF5_EXT_ZLIB=zdll.lib
set PKG_SZIP=szip-2.0
set HDF5_EXT_SZIP=szlibdll.lib

rmdir /S /Q hdf5-1.8.9
del /F ..\RadarVolumeExplorer\lib\hdf5.lib
del /F ..\RadarVolumeExplorer\lib\hdf5_cpp.lib
del /F ..\RadarVolumeExplorer\lib\hdf5_hl.lib
7za.exe x -y hdf5-1.8.9.tar.gz
7za.exe x -y hdf5-1.8.9.tar
del /F hdf5-1.8.9.tar

REM On Windows x64 the following lines must not be in a IF statement.
REM The Closing brace of "Program Files (x86)" is treated as a closing IF brace
REM and causes the error "\Microsoft was unexpected at this time"
set include=%PKGPATH%\%PKG_ZLIB%;%PKGPATH%\%PKG_SZIP%\src;%include%
set lib=%PKGPATH%\%PKG_ZLIB%;%PKGPATH%\%PKG_SZIP%\all\libdll\Release;%lib%

copy /Y hdf5-1.8.9.pro .\hdf5-1.8.9\src\
copy /Y hdf5-1.8.9-cpp.pro ".\hdf5-1.8.9\c++\src\"
copy /Y hdf5-1.8.9-hl.pro .\hdf5-1.8.9\hl\src\
copy /Y hdf5-1.8.9-H5detect.pro .\hdf5-1.8.9\src\
copy /Y hdf5-1.8.9-H5make_libsettings.pro .\hdf5-1.8.9\src\

cd hdf5-1.8.9

echo ===== Compiling hdf5 tools
   
echo ..... Compiling hdf5_H5detect
cd src
qmake hdf5-1.8.9-H5detect.pro
nmake
if %ERRORLEVEL% neq 0 goto ERROR
   
echo ..... Running H5detect
H5detect.exe > h5tinit.c
   
echo ..... Compiling hdf5_H5make_libsettings
qmake hdf5-1.8.9-H5make_libsettings.pro
nmake
if %ERRORLEVEL% neq 0 goto ERROR
   
echo ..... Running H5make_libsettings
H5make_libsettings.exe > H5libsettings.c

echo ===== Compiling hf5

REM MSVC++ 14.0 _MSC_VER == 1900 (Visual Studio 2015)
rem IF %MSVC% geq 19 (
   echo #define timezone _timezone >> H5Opkg.h
rem )
qmake hdf5-1.8.9.pro

nmake

echo ..... Compiling hdf5_cpp
cd ..
cd c++\src
qmake hdf5-1.8.9-cpp.pro
nmake
if %ERRORLEVEL% neq 0 goto ERROR

echo ..... Compiling hdf5_hl
cd ..
cd ..
cd hl\src
qmake hdf5-1.8.9-hl.pro
nmake
if %ERRORLEVEL% neq 0 goto ERROR

cd ..
cd ..
cd ..

echo ===== Finished hdf5
