aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/clean_driver.bat
diff options
context:
space:
mode:
Diffstat (limited to 'clean_driver.bat')
-rw-r--r--clean_driver.bat69
1 files changed, 38 insertions, 31 deletions
diff --git a/clean_driver.bat b/clean_driver.bat
index a74a1a6..68bb3d3 100644
--- a/clean_driver.bat
+++ b/clean_driver.bat
@@ -6,31 +6,31 @@
@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_ddk.bat || exit /b !errorlevel!
call check_env.bat || exit /b !errorlevel!
-set driver_src_root=%~f1
-cd "%driver_src_root%"
+set "driver_src_root=%~f1"
+cd "%driver_src_root%" || exit /b !errorlevel!
for /f %%i in ("%driver_src_root%") do (
- set driver_name=%%~ni
- set driver_dist_root=%%~dpi
+ set "driver_name=%%~ni"
+ set "driver_dist_root=%%~dpi"
)
call :make_relative driver_dist_root "%src_root%"
-set sys_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%dist_root%
-set pdb_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%dist_root%
-set lib_dist_dir=%lib_root%\%target_platform%\%target_configuration%\%dist_root%
+set "sys_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_root%"
+set "pdb_dist_dir=%bin_root%\%target_platform%\%target_configuration%\%driver_dist_root%"
+set "lib_dist_dir=%lib_root%\%target_platform%\%target_configuration%\%driver_dist_root%"
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 ============================== CLEAN ==============================
@@ -42,7 +42,7 @@ call :clean_del "%sys_dist_dir%%driver_name%.sys" || goto :clean_failure
call :clean_del "%pdb_dist_dir%%driver_name%.pdb" || goto :clean_failure
call :clean_del "%lib_dist_dir%%driver_name%.lib" || goto :clean_failure
echo ========================== CLEAN SUCCESS ==========================
-exit /b
+exit /b 0
:clean_rmdir
if exist "%~1\" (
@@ -50,7 +50,7 @@ if exist "%~1\" (
rmdir /s /q "%~1" >nul
exit /b !errorlevel!
)
-exit /b
+exit /b 0
:clean_del
if exist "%~1" (
@@ -58,7 +58,7 @@ if exist "%~1" (
del "%~1" >nul
exit /b !errorlevel!
)
-exit /b
+exit /b 0
:clean_failure
echo ========================== CLEAN FAILURE ==========================
@@ -66,24 +66,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