aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/km/build/wdk7.1/build_driver.bat
blob: 7d7bfb7ff59092a5bfceed8c56dbbd1389978285 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
@rem Copyright (c) 2015 Egor Tensin <Egor.Tensin@gmail.com>
@rem This file is part of the "Windows 7 drivers" project.
@rem For details, see https://github.com/egor-tensin/windows7-drivers.
@rem Distributed under the MIT License.

@setlocal enabledelayedexpansion
@echo off

if "%~1" == "" (
    echo Usage: %~nx0 DRIVER_SRC_DIR >&2
    exit /b 1
)

call check_env.bat || exit /b !errorlevel!

set "drv_src_dir=%~f1"

for /f %%i in ("%drv_src_dir%") do (
    set "drv_name=%%~ni"
    set "drv_subdir=%%~dpi"
)

call :make_relative drv_subdir "%proj_src_dir%"

set "sys_dist_dir=%proj_bin_dir%\%target_arch%\%target_config%\%drv_subdir%"
set "pdb_dist_dir=%proj_bin_dir%\%target_arch%\%target_config%\%drv_subdir%"
set "lib_dist_dir=%proj_lib_dir%\%target_arch%\%target_config%\%drv_subdir%"

echo =========================== DRIVER INFO ===========================
echo Driver source directory: %drv_src_dir%
echo Driver name: %drv_name%
echo ========================= END DRIVER INFO =========================
echo.
echo ============================== BUILD ==============================
set "LIBDISTDIR=%lib_dist_dir%"
pushd "%drv_src_dir%" && (
    build.exe /cegwZ
    popd
)
if errorlevel 0 (
    echo ========================== BUILD SUCCESS ==========================
) else (
    echo ========================== BUILD FAILURE ==========================
    exit /b %errorlevel%
)

if "%_BUILDARCH%" == "x86" (
    set buildarch_dir=i386
) else (
    set "buildarch_dir=%_BUILDARCH%"
)

set "sys_path=%drv_src_dir%\obj%BUILD_ALT_DIR%\%buildarch_dir%\%drv_name%.sys"
set "pdb_path=%drv_src_dir%\obj%BUILD_ALT_DIR%\%buildarch_dir%\%drv_name%.pdb"
set "lib_path=%drv_src_dir%\obj%BUILD_ALT_DIR%\%buildarch_dir%\%drv_name%.lib"

if exist "%sys_path%" (
    echo.
    call "%proj_build_dir%\sign.bat" "%sys_path%" || exit /b !errorlevel!
)

echo.
echo ============================== DISTR ==============================
if exist "%sys_path%" (
    call :distr_copy "%sys_path%" "%sys_dist_dir%" || goto :distr_failure
    call :distr_copy "%pdb_path%" "%pdb_dist_dir%" || goto :distr_failure
)
if exist "%lib_path%" (
    call :distr_copy "%lib_path%" "%lib_dist_dir%" || goto :distr_failure
)
echo ========================== DISTR SUCCESS ==========================
exit /b

:distr_mkdir
if not exist "%~1\" (
    echo mkdir "%~1"
         mkdir "%~1" >nul
    exit /b !errorlevel!
)
exit /b 0

:distr_copy
call :distr_mkdir "%~2" || exit /b !errorlevel!
echo copy "%~1" "%~2"
     copy "%~1" "%~2" >nul
exit /b %errorlevel%

:distr_failure
echo ========================== DISTR FAILURE ==========================
exit /b %errorlevel%

:make_relative
@setlocal enabledelayedexpansion

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 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 "match=!sub!"
    )
)

set "rel=%upper%!abs:%match%=!"

(endlocal & if defined %~1 (set "%~1=%rel%") else (echo.%rel%))

exit /b 0