c0b905abdd08f7326cd9ca3dff2492c620f74f5f
[platform/upstream/libusb.git] / msvc / ddk_build.cmd
1 @echo off
2 ::# default builds static library. 
3 ::# you can pass the following arguments (case insensitive):
4 ::# - "DLL" to build a DLL instead of a static library
5 ::# - "/MT" to build a static library compatible with MSVC's /MT option (LIBCMT vs MSVCRT)
6 ::# - "USBDK" to build with UsbDk backend
7
8 if Test%BUILD_ALT_DIR%==Test goto usage
9
10 ::# process commandline parameters
11 set TARGET=LIBRARY
12 set STATIC_LIBC=
13 set WITH_USBDK=
14 set version=1.0
15 set PWD=%~dp0
16 set BUILD_CMD=build -bcwgZ -M2
17
18 :more_args
19
20 if "%1" == "" goto no_more_args
21 ::# /I for case insensitive
22 if /I Test%1==TestDLL set TARGET=DYNLINK
23 if /I Test%1==Test/MT set STATIC_LIBC=1
24 if /I Test%1==TestUSBDK set WITH_USBDK=1
25
26 shift
27 goto more_args
28
29 :no_more_args
30
31 cd ..\libusb\os
32 echo TARGETTYPE=%TARGET% > target
33 copy target+..\..\msvc\libusb_sources sources >NUL 2>&1
34 del target
35 @echo on
36 %BUILD_CMD%
37 @echo off
38 if errorlevel 1 goto builderror
39 cd ..\..
40
41 set cpudir=i386
42 set destType=Win32
43 if %_BUILDARCH%==x86 goto isI386
44 set cpudir=amd64
45 set destType=x64
46 :isI386
47
48 set srcPath=libusb\os\obj%BUILD_ALT_DIR%\%cpudir%
49
50 set dstPath=%destType%\Debug
51 if %DDKBUILDENV%==chk goto isDebug
52 set dstPath=%destType%\Release
53 :isDebug
54
55 if exist %destType% goto md2
56 mkdir %destType%
57 :md2
58 if exist %dstPath% goto md3
59 mkdir %dstPath%
60 :md3
61 if exist %dstPath%\dll goto md4
62 mkdir %dstPath%\dll
63 :md4
64 if exist %dstPath%\lib goto md5
65 md %dstPath%\lib
66 :md5
67 if exist %dstPath%\examples goto md6
68 md %dstPath%\examples
69 :md6
70 @echo on
71
72 @if /I NOT Test%1==TestDLL goto copylib
73 copy %srcPath%\libusb-%version%.dll %dstPath%\dll
74 copy %srcPath%\libusb-%version%.pdb %dstPath%\dll
75 :copylib
76 copy %srcPath%\libusb-%version%.lib %dstPath%\lib
77
78 @echo off
79
80 if exist examples\listdevs_ddkbuild goto md7
81 md examples\listdevs_ddkbuild
82 :md7
83
84 cd examples\listdevs_ddkbuild
85 copy ..\..\msvc\listdevs_sources sources >NUL 2>&1
86 @echo on
87 %BUILD_CMD%
88 @echo off
89 if errorlevel 1 goto builderror
90 cd ..\..
91
92 set srcPath=examples\listdevs_ddkbuild\obj%BUILD_ALT_DIR%\%cpudir%
93 @echo on
94
95 copy %srcPath%\listdevs.exe %dstPath%\examples
96 copy %srcPath%\listdevs.pdb %dstPath%\examples
97
98 @echo off
99
100 if exist examples\xusb_ddkbuild goto md8
101 md examples\xusb_ddkbuild
102 :md8
103
104 cd examples\xusb_ddkbuild
105 copy ..\..\msvc\xusb_sources sources >NUL 2>&1
106 @echo on
107 %BUILD_CMD%
108 @echo off
109 if errorlevel 1 goto builderror
110 cd ..\..
111
112 set srcPath=examples\xusb_ddkbuild\obj%BUILD_ALT_DIR%\%cpudir%
113 @echo on
114
115 copy %srcPath%\xusb.exe %dstPath%\examples
116 copy %srcPath%\xusb.pdb %dstPath%\examples
117
118 @echo off
119
120 if exist examples\getopt\getopt_ddkbuild goto md9
121 md examples\getopt\getopt_ddkbuild
122 :md9
123
124 cd examples\getopt\getopt_ddkbuild
125 copy ..\..\..\msvc\getopt_sources sources >NUL 2>&1
126 @echo on
127 %BUILD_CMD%
128 @echo off
129 if errorlevel 1 goto builderror
130 cd ..\..\..
131
132 if exist examples\fxload_ddkbuild goto md10
133 md examples\fxload_ddkbuild
134 :md10
135
136 cd examples\fxload_ddkbuild
137 copy ..\..\msvc\fxload_sources sources >NUL 2>&1
138 @echo on
139 %BUILD_CMD%
140 @echo off
141 if errorlevel 1 goto builderror
142 cd ..\..
143
144 set srcPath=examples\fxload_ddkbuild\obj%BUILD_ALT_DIR%\%cpudir%
145 @echo on
146
147 copy %srcPath%\fxload.exe %dstPath%\examples
148 copy %srcPath%\fxload.pdb %dstPath%\examples
149
150 @echo off
151
152 if exist examples\hotplugtest_ddkbuild goto md11
153 md examples\hotplugtest_ddkbuild
154 :md11
155
156 cd examples\hotplugtest_ddkbuild
157 copy ..\..\msvc\hotplugtest_sources sources >NUL 2>&1
158 @echo on
159 %BUILD_CMD%
160 @echo off
161 if errorlevel 1 goto builderror
162 cd ..\..
163
164 set srcPath=examples\hotplugtest_ddkbuild\obj%BUILD_ALT_DIR%\%cpudir%
165 @echo on
166
167 copy %srcPath%\hotplugtest.exe %dstPath%\examples
168 copy %srcPath%\hotplugtest.pdb %dstPath%\examples
169
170 @echo off
171
172 cd msvc
173 goto done
174
175 :usage
176 echo ddk_build must be run in a WDK build environment
177 pause
178 goto done
179
180 :builderror
181 echo Build failed
182
183 :done
184 cd %PWD%