@echo off
cls

if "%DDKBUILDENV%"=="" (
    goto NoEnv
) else (
    echo.
    echo This window already has the DDK build environment set.
    echo Script is now opening another windows to run build commands...
    echo.
    start "OxSemi Drivers Build Utility" /i %~s0
)
goto :eof

:NoEnv
set OXBASEDIR=C:\WinDDK\6001.18000
if not exist %OXBASEDIR% (
    echo.
    echo ERROR:
    echo At least WDK 6001.18001 is required. C:\WinDDK\6001.18001 was not found!
    echo.
    pause & goto :eof
)
if not exist "%OXBASEDIR%\redist\wdf\x86\WdfCoInstaller01007.dll" (
    echo.
    echo ERROR:
    echo %OXBASEDIR%\redist\wdf\x86\WdfCoInstaller01007.dll was not found!
    echo If your WDK installation is up-to-date, you should manually copy the file
    echo from C:\WinDDK\WDFREDIST1.7\redist\WDF\x86\.
    echo.
    pause & goto :eof
)
if not exist "%OXBASEDIR%\redist\wdf\amd64\WdfCoInstaller01007.dll" (
    echo.
    echo ERROR:
    echo %OXBASEDIR%\redist\wdf\amd64\WdfCoInstaller01007.dll was not found!
    echo If your WDK installation is up-to-date, you should manually copy the file
    echo from C:\WinDDK\WDFREDIST1.7\redist\WDF\amd64\.
    echo.
    pause & goto :eof
)

setlocal ENABLEEXTENSIONS
cls
echo.
echo Building 32-bit driver.
echo.
pause
call %OXBASEDIR%\bin\setenv.bat %OXBASEDIR% fre WXP
pushd %~sdp0\source
call cu.bat
call bu.bat
pause
cls
call iu.bat
pause
popd
endlocal

setlocal ENABLEEXTENSIONS
cls
echo.
echo Building 64-bit driver.
echo.
pause
call %OXBASEDIR%\bin\setenv.bat %OXBASEDIR% fre x64 WNET
pushd %~sdp0\source
call cu.bat
call bu.bat
pause
cls
call iu.bat
pause
popd
endlocal

cls
echo.
echo If drivers are built and installed successfully, they can be located
echo under %~dp0\install\MfUart\wdf.
echo.
echo You can now run Oxford Semiconductor's OXide utilities to further
echo customise the drivers.
echo.
set OXBASEDIR=
pause
goto :eof
