diff options
Diffstat (limited to 'build_driver.bat')
-rw-r--r-- | build_driver.bat | 77 |
1 files changed, 42 insertions, 35 deletions
diff --git a/build_driver.bat b/build_driver.bat index 283cde8..76d9659 100644 --- a/build_driver.bat +++ b/build_driver.bat @@ -6,54 +6,54 @@ @setlocal enabledelayedexpansion @echo off -if [%1] == [] ( - echo Usage: %~0 DRIVER_SRC_ROOT +if "%~1" == "" ( + echo Usage: %~nx0 DRIVER_SRC_ROOT exit /b 1 ) call check_env.bat || exit /b !errorlevel! call check_ddk.bat || exit /b !errorlevel! -set driver_src_root=%~f1 +set "driver_src_root=%~f1" for /f %%i in ("%driver_src_root%") do ( - set driver_name=%%~ni - set driver_dist_subdir=%%~dpi + set "driver_name=%%~ni" + set "driver_dist_subdir=%%~dpi" ) call :make_relative driver_dist_subdir "%src_root%" -set sys_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_subdir% -set pdb_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_subdir% -set lib_dist_dir=%lib_root%\%target_platform%\%target_configuration%\%driver_dist_subdir% +set "sys_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" +set "pdb_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" +set "lib_dist_dir=%lib_root%\%target_platform%\%target_configuration%\%driver_dist_subdir%" echo =========================== DRIVER INFO =========================== -echo Driver source directory: "%driver_src_root%" -echo Driver name: "%driver_name%" +echo Driver source directory: %driver_src_root% +echo Driver name: %driver_name% echo ========================= END DRIVER INFO ========================= echo. echo ============================== BUILD ============================== -set LIBDISTDIR=%lib_dist_dir% +set "LIBDISTDIR=%lib_dist_dir%" pushd "%driver_src_root%" && ( build.exe /cegwZ popd ) -if %errorlevel% equ 0 ( +if errorlevel 0 ( echo ========================== BUILD SUCCESS ========================== ) else ( echo ========================== BUILD FAILURE ========================== exit /b %errorlevel% ) -if [%_BUILDARCH%] == [x86] ( +if "%_BUILDARCH%" == "x86" ( set buildarch_directory=i386 ) else ( - set buildarch_directory=%_BUILDARCH% + set "buildarch_directory=%_BUILDARCH%" ) -set sys_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.sys -set pdb_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.pdb -set lib_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.lib +set "sys_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.sys" +set "pdb_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.pdb" +set "lib_path=%driver_src_root%\obj%BUILD_ALT_DIR%\%buildarch_directory%\%driver_name%.lib" if exist "%sys_path%" ( echo. @@ -84,7 +84,7 @@ exit /b 0 call :distr_mkdir "%~2" || exit /b !errorlevel! echo copy "%~1" "%~2" copy "%~1" "%~2" >nul -exit /b !errorlevel! +exit /b %errorlevel% :distr_failure echo ========================== DISTR FAILURE ========================== @@ -92,24 +92,31 @@ exit /b %errorlevel% :make_relative @setlocal enabledelayedexpansion -set src=%~1 -if defined %1 set src=!%~1! -set base=%~2 -if not defined base set base=%cd% -for /f "tokens=*" %%a in ("%src%") do set src=%%~fa -for /f "tokens=*" %%a in ("%base%") do set base=%%~fa + +set "abs=%~1" +if defined %~1 set "abs=!%~1!" + +set "base=%~2" +if not defined base set "base=%CD%" + +for /f "tokens=*" %%i in ("%abs%") do set "abs=%%~fi" +for /f "tokens=*" %%i in ("%base%") do set "base=%%~fi" + set match= -set c= -for /f "tokens=*" %%a in ('echo.%base:\=^&echo.%') do ( - set sub=!sub!%%a\ - call set tmp=%%src:!sub!=%% - if "!tmp!" neq "!src!" ( - set match=!sub! +set upper= + +for /f "tokens=*" %%i in ('echo.%base:\=^&echo.%') do ( + set "sub=!sub!%%i\" + call set "tmp=%%abs:!sub!=%%" + if "!tmp!" == "!abs!" ( + set "upper=!upper!..\" ) else ( - set upper=!upper!..\ + set "match=!sub!" ) ) -set src=%upper%!src:%match%=! -(endlocal -if defined %1 (set %~1=%src%) else (echo.%src%)) -exit /b + +set "rel=%upper%!abs:%match%=!" + +(endlocal & if defined %~1 (set "%~1=%rel%") else (echo.%rel%)) + +exit /b 0 |