aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--add_cert.bat2
-rw-r--r--build_driver.bat77
-rw-r--r--build_drivers.bat2
-rw-r--r--check_ddk.bat16
-rw-r--r--check_env.bat10
-rw-r--r--clean_driver.bat69
-rw-r--r--clean_drivers.bat2
-rw-r--r--setenv.bat34
-rw-r--r--sign.bat8
9 files changed, 120 insertions, 100 deletions
diff --git a/add_cert.bat b/add_cert.bat
index fa457a8..7223a2a 100644
--- a/add_cert.bat
+++ b/add_cert.bat
@@ -9,7 +9,7 @@
set cert_name=windows7_drivers
echo ============================ CERT INFO ============================
-echo Certificate name: "%cert_name%"
+echo Certificate name: %cert_name%
echo ========================== END CERT INFO ==========================
echo.
echo ======================= ADDING CERTIFICATE ========================
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
diff --git a/build_drivers.bat b/build_drivers.bat
index fd6f9b6..8bec487 100644
--- a/build_drivers.bat
+++ b/build_drivers.bat
@@ -7,7 +7,7 @@
@echo off
for /f "delims=" %%i in ('dir /s sources /b') do (
- set driver_src_root=%%~dpi
+ set "driver_src_root=%%~dpi"
echo.
call build_driver.bat "!driver_src_root:~0,-1!" || exit /b !errorlevel!
)
diff --git a/check_ddk.bat b/check_ddk.bat
index a57a7fb..0c4d414 100644
--- a/check_ddk.bat
+++ b/check_ddk.bat
@@ -8,11 +8,11 @@
call check_env.bat || exit /b !errorlevel!
-if [%BUILD_ALT_DIR%] == [] goto :ddk_not_set
-if [%_BUILDARCH%] == [] goto :ddk_not_set
+if not defined BUILD_ALT_DIR goto :ddk_not_set
+if not defined _BUILDARCH goto :ddk_not_set
-if not exist %root%\sign.bat (
- echo Error: %root%\sign.bat is missing ^(don^'t know how to sign drivers^)
+if not exist "%root%\sign.bat" (
+ echo Error: %root%\sign.bat was not found ^(don^'t know how to sign drivers otherwise^) >&2
exit /b 1
)
@@ -22,17 +22,17 @@ where makecert.exe >nul 2>&1 || goto :makecert_not_found
exit /b 0
:ddk_not_set
-echo Error: either %%BUILD_ALT_DIR%% or %%_BUILDARCH%% are not set ^(perhaps you forgot to set up the WinDDK environment^)
+echo Error: either %%BUILD_ALT_DIR%% or %%_BUILDARCH%% are not set ^(have you set up the WinDDK environment?^) >&2
exit /b 1
:build_not_found
-echo Error: build.exe not found ^(perhaps you forgot to set up the WinDDK environment^)
+echo Error: build.exe was not found ^(have you set up the WinDDK environment?^) >&2
exit /b 1
:signtool_not_found
-echo Error: signtool.exe not found ^(perhaps you forgot to set up the WinDDK environment^)
+echo Error: signtool.exe was not found ^(have you set up the WinDDK environment?^) >&2
exit /b 1
:makecert_not_found
-echo Error: makecert.exe not found ^(perhaps you forgot to set up the WinDDK environment^)
+echo Error: makecert.exe was not found ^(have you set up the WinDDK environment?^) >&2
exit /b 1
diff --git a/check_env.bat b/check_env.bat
index be19909..f3cb382 100644
--- a/check_env.bat
+++ b/check_env.bat
@@ -6,13 +6,13 @@
@setlocal enabledelayedexpansion
@echo off
-if [%root%] == [] goto :env_not_set
-if [%bin_root%] == [] goto :env_not_set
-if [%lib_root%] == [] goto :env_not_set
-if [%src_root%] == [] goto :env_not_set
+if not defined root goto :env_not_set
+if not defined bin_root goto :env_not_set
+if not defined lib_root goto :env_not_set
+if not defined src_root goto :env_not_set
exit /b 0
:env_not_set
-echo Error: either %%root%%, %%bin_root%%, %%lib_root%% or %%src_root%% are not set ^(perhaps you forgot to call setenv.bat^)
+echo Error: either %%root%%, %%bin_root%%, %%lib_root%% or %%src_root%% are not set ^(have you set up the build environment using setenv.bat?^) >&2
exit /b 1
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
diff --git a/clean_drivers.bat b/clean_drivers.bat
index 76dabe0..ca2e48e 100644
--- a/clean_drivers.bat
+++ b/clean_drivers.bat
@@ -7,7 +7,7 @@
@echo off
for /f "delims=" %%i in ('dir /s sources /b') do (
- set driver_src_root=%%~dpi
+ set "driver_src_root=%%~dpi"
echo.
call clean_driver.bat "!driver_src_root:~0,-1!" || exit /b !errorlevel!
)
diff --git a/setenv.bat b/setenv.bat
index f8e5073..ee164df 100644
--- a/setenv.bat
+++ b/setenv.bat
@@ -5,21 +5,27 @@
@echo off
-set root=%~dp0%
-set src_root=%root%src
-set bin_root=%root%bin
-set lib_root=%root%lib
+set "root=%~dp0%"
+set "src_root=%root%src"
+set "bin_root=%root%bin"
+set "lib_root=%root%lib"
set target_configuration=Release
-if [%_BUILDARCH%] == [AMD64] goto :target_platform_x64
-if [%_BUILDARCH%] == [x86] goto :target_platform_x86
-echo Unsupported %%_BUILDARCH%% (supported build architectures: AMD64, x86)
-exit /b -1
+if not defined _BUILDARCH (
+ echo Error: %%_BUILDARCH%% is not defined ^(have you set up the WinDDK environment?^) >&2
+ exit /b 1
+)
-:target_platform_x64
-set target_platform=x64
-exit /b 0
-:target_platform_x86
-set target_platform=x86
-exit /b 0
+if "%_BUILDARCH%" == "AMD64" (
+ set target_platform=x64
+ exit /b 0
+)
+
+if "%_BUILDARCH%" == "x86" (
+ set target_platform=x86
+ exit /b 0
+)
+
+echo Error: invalid %%_BUILDARCH%% value "%_BUILDARCH%" ^(the only supported architecture is x86^(-64^)^) >&2
+exit /b 1
diff --git a/sign.bat b/sign.bat
index 67e3dc2..9955ac2 100644
--- a/sign.bat
+++ b/sign.bat
@@ -8,15 +8,15 @@
set cert_name=windows7_drivers
-if [%1] == [] (
- echo Usage: %0 SYS_PATH
+if "%~1" == "" (
+ echo Usage: %~nx0 SYS_PATH >&2
exit /b 1
)
-set sys_path=%~f1
+set "sys_path=%~f1"
echo ============================ CERT INFO ============================
-echo Certificate name: "%cert_name%"
+echo Certificate name: %cert_name%
echo ========================== END CERT INFO ==========================
echo.
echo ============================= SIGNING =============================