Added support for new MSVC compiler version.
[DynamicAudioNormalizer.git] / z_build.bat
blob62eac3b108869609ec991c9572a221d466aaf2b7
1 @echo off
2 setlocal enabledelayedexpansion
4 REM ///////////////////////////////////////////////////////////////////////////
5 REM // Set Paths
6 REM ///////////////////////////////////////////////////////////////////////////
7 set "MSVC_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC"
8 set "TOOLS_VER=141"
9 set "SLN_SUFFX=VS2017"
11 REM ###############################################
12 REM # DO NOT MODIFY ANY LINES BELOW THIS LINE !!! #
13 REM ###############################################
15 REM ///////////////////////////////////////////////////////////////////////////
16 REM // Check environment
17 REM ///////////////////////////////////////////////////////////////////////////
18 if not exist "%MSVC_PATH%\vcvarsall.bat" (
19         if not exist "%MSVC_PATH%\Auxiliary\Build\vcvarsall.bat" (
20                 echo MSVC compiler not found. Please check your MSVC_PATH var^^!
21                 goto BuildError
22         )
25 if not exist "%QTDIR%\bin\moc.exe" (
26         echo Qt could not be found. Please check your QTDIR var^^!
27         goto BuildError
29 if not exist "%QTDIR%\include\QtCore\qglobal.h" (
30         echo Qt could not be found. Please check your QTDIR var^^!
31         goto BuildError
34 if not exist "%JAVA_HOME%\bin\java.exe" (
35         echo JDK could not be found. Please check your JAVA_HOME var^^!
36         goto BuildError
38 if not exist "%JAVA_HOME%\lib\tools.jar" (
39         echo JDK could not be found. Please check your JAVA_HOME var^^!
40         goto BuildError
42 if not exist "%JAVA_HOME%\include\jni.h" (
43         echo JDK could not be found. Please check your JAVA_HOME var^^!
44         goto BuildError
47 if not exist "%~dp0\..\Prerequisites\README.txt" (
48         echo Prerequisites not found. Repair your build environment^^!
49         goto BuildError
52 REM ///////////////////////////////////////////////////////////////////////////
53 REM // Setup environment
54 REM ///////////////////////////////////////////////////////////////////////////
55 set "ANT_HOME=%~dp0\..\Prerequisites\Ant"
56 set "PATH=%QTDIR%\bin;%JAVA_HOME%\bin;%ANT_HOME%\bin;%PATH%"
58 if exist "%MSVC_PATH%\vcvarsall.bat" (
59         call "%MSVC_PATH%\vcvarsall.bat" x86
60 ) else (
61         if exist "%MSVC_PATH%\Auxiliary\Build\vcvarsall.bat" (
62                 call "%MSVC_PATH%\Auxiliary\Build\vcvarsall.bat" x86
63         )
66 if not exist "%VCINSTALLDIR%\bin\cl.exe" (
67         if not exist "%VCToolsInstallDir%\bin\Hostx64\x86\cl.exe" (
68                 echo MSVC compiler not found. Please check your MSVC_PATH var^^!
69                 goto BuildError
70         )
73 REM ///////////////////////////////////////////////////////////////////////////
74 REM // Get current date and time (in ISO format)
75 REM ///////////////////////////////////////////////////////////////////////////
76 set "ISO_DATE="
77 set "ISO_TIME="
79 if not exist "%~dp0\..\Prerequisites\GnuWin32\date.exe" goto BuildError
81 for /F "tokens=1,2 delims=:" %%a in ('"%~dp0\..\Prerequisites\GnuWin32\date.exe" +ISODATE:%%Y-%%m-%%d') do (
82         if "%%a"=="ISODATE" set "ISO_DATE=%%b"
84 for /F "tokens=1,2,3,4 delims=:" %%a in ('"%~dp0\..\Prerequisites\GnuWin32\date.exe" +ISOTIME:%%T') do (
85         if "%%a"=="ISOTIME" set "ISO_TIME=%%b:%%c:%%d"
88 if "%ISO_DATE%"=="" goto BuildError
89 if "%ISO_TIME%"=="" goto BuildError
91 REM ///////////////////////////////////////////////////////////////////////////
92 REM // Detect version number
93 REM ///////////////////////////////////////////////////////////////////////////
94 set "VER_MAJOR="
95 set "VER_MINOR="
96 set "VER_PATCH="
98 for /F "tokens=1,2,3" %%a in (%~dp0\DynamicAudioNormalizerShared\res\version.inc) do (
99         if "%%a"=="#define" (
100                 if "%%b"=="VER_DYNAUDNORM_MAJOR"    set "VER_MAJOR=%%c"
101                 if "%%b"=="VER_DYNAUDNORM_MINOR_HI" set "VER_MINOR=%%c!VER_MINOR!"
102                 if "%%b"=="VER_DYNAUDNORM_MINOR_LO" set "VER_MINOR=!VER_MINOR!%%c"
103                 if "%%b"=="VER_DYNAUDNORM_PATCH"    set "VER_PATCH=%%c"
104         )
107 if "%VER_MAJOR%"=="" goto BuildError
108 if "%VER_MINOR%"=="" goto BuildError
109 if "%VER_PATCH%"=="" goto BuildError
111 REM ///////////////////////////////////////////////////////////////////////////
112 REM // Clean Binaries
113 REM ///////////////////////////////////////////////////////////////////////////
114 for /d %%d in (%~dp0\bin\*) do (rmdir /S /Q "%%~d")
115 for /d %%d in (%~dp0\obj\*) do (rmdir /S /Q "%%~d")
117 REM ///////////////////////////////////////////////////////////////////////////
118 REM // Build the binaries
119 REM ///////////////////////////////////////////////////////////////////////////
120 for %%c in (DLL, Static) do (
121         for %%p in (Win32, x64) do (
122                 echo ---------------------------------------------------------------------
123                 echo BEGIN BUILD [%%p/Release_%%c]
124                 echo ---------------------------------------------------------------------
126                 MSBuild.exe /property:Platform=%%p /property:Configuration=Release_%%c /target:clean   "%~dp0\DynamicAudioNormalizer_%SLN_SUFFX%.sln"
127                 if not "!ERRORLEVEL!"=="0" goto BuildError
128                 MSBuild.exe /property:Platform=%%p /property:Configuration=Release_%%c /target:rebuild "%~dp0\DynamicAudioNormalizer_%SLN_SUFFX%.sln"
129                 if not "!ERRORLEVEL!"=="0" goto BuildError
130                 MSBuild.exe /property:Platform=%%p /property:Configuration=Release_%%c /target:build   "%~dp0\DynamicAudioNormalizer_%SLN_SUFFX%.sln"
131                 if not "!ERRORLEVEL!"=="0" goto BuildError
132         )
135 call "%ANT_HOME%\bin\ant.bat" -buildfile "%~dp0\DynamicAudioNormalizerJNI\build.xml"
136 if not "!ERRORLEVEL!"=="0" goto BuildError
138 REM ///////////////////////////////////////////////////////////////////////////
139 REM // Copy program files
140 REM ///////////////////////////////////////////////////////////////////////////
141 set "PACK_PATH=%TMP%\~%RANDOM%%RANDOM%.tmp"
142 mkdir "%PACK_PATH%"
144 for %%c in (DLL, Static) do (
145         echo ---------------------------------------------------------------------
146         echo BEGIN PACKAGING [Release_%%c]
147         echo ---------------------------------------------------------------------
148         
149         mkdir "%PACK_PATH%\%%c"
150         mkdir "%PACK_PATH%\%%c\x64"
151         mkdir "%PACK_PATH%\%%c\img"
152         mkdir "%PACK_PATH%\%%c\img\dyauno"
153         mkdir "%PACK_PATH%\%%c\include"
154         mkdir "%PACK_PATH%\%%c\samples"
155         mkdir "%PACK_PATH%\%%c\samples\python"
157         copy "%~dp0\bin\Win32\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerCLI.exe"            "%PACK_PATH%\%%c"
158         if not "!ERRORLEVEL!"=="0" goto BuildError
159         copy "%~dp0\bin\Win32\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerGUI.exe"            "%PACK_PATH%\%%c"
160         if not "!ERRORLEVEL!"=="0" goto BuildError
161         copy "%~dp0\bin\Win32\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerPYD.pyd"            "%PACK_PATH%\%%c"
162         if not "!ERRORLEVEL!"=="0" goto BuildError
163         copy "%~dp0\bin\x64\.\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerPYD.pyd"            "%PACK_PATH%\%%c\x64"
164         if not "!ERRORLEVEL!"=="0" goto BuildError
165         copy "%~dp0\bin\Win32\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerVST.dll"            "%PACK_PATH%\%%c"
166         if not "!ERRORLEVEL!"=="0" goto BuildError
167         copy "%~dp0\bin\x64\.\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerVST.dll"            "%PACK_PATH%\%%c\x64"
168         if not "!ERRORLEVEL!"=="0" goto BuildError
169         copy "%~dp0\bin\Win32\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerWA5.dll"            "%PACK_PATH%\%%c"
170         if not "!ERRORLEVEL!"=="0" goto BuildError
171         
172         copy "%~dp0\DynamicAudioNormalizerPYD\include\*.py"                                         "%PACK_PATH%\%%c\include"
173         if not "!ERRORLEVEL!"=="0" goto BuildError
174         copy "%~dp0\DynamicAudioNormalizerPYD\samples\*.py"                                         "%PACK_PATH%\%%c\samples\python"
175         if not "!ERRORLEVEL!"=="0" goto BuildError
177         if /I "%%c"=="DLL" (
178                 mkdir "%PACK_PATH%\%%c\redist"
179                 mkdir "%PACK_PATH%\%%c\samples\delphi"
180                 mkdir "%PACK_PATH%\%%c\samples\dotNet"
181                 mkdir "%PACK_PATH%\%%c\samples\java"
182                 
183                 copy "%~dp0\bin\Win32\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerAPI.dll"        "%PACK_PATH%\%%c"
184                 if not "!ERRORLEVEL!"=="0" goto BuildError
185                 copy "%~dp0\bin\Win32\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerAPI.lib"        "%PACK_PATH%\%%c"
186                 if not "!ERRORLEVEL!"=="0" goto BuildError
187                 copy "%~dp0\bin\Win32\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerNET.dll"        "%PACK_PATH%\%%c"
188                 if not "!ERRORLEVEL!"=="0" goto BuildError
189                 copy "%~dp0\bin\x64\.\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerAPI.dll"        "%PACK_PATH%\%%c\x64"
190                 if not "!ERRORLEVEL!"=="0" goto BuildError
191                 copy "%~dp0\bin\x64\.\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerAPI.lib"        "%PACK_PATH%\%%c\x64"
192                 if not "!ERRORLEVEL!"=="0" goto BuildError
193                 copy "%~dp0\bin\x64\.\v%TOOLS_VER%_xp\Release_%%c\DynamicAudioNormalizerNET.dll"        "%PACK_PATH%\%%c\x64"
194                 if not "!ERRORLEVEL!"=="0" goto BuildError
195                 copy "%~dp0\DynamicAudioNormalizerAPI\include\*.h"                                      "%PACK_PATH%\%%c\include"
196                 if not "!ERRORLEVEL!"=="0" goto BuildError
197                 copy "%~dp0\DynamicAudioNormalizerPAS\include\*.pas"                                    "%PACK_PATH%\%%c\include"
198                 if not "!ERRORLEVEL!"=="0" goto BuildError
199                 copy "%~dp0\DynamicAudioNormalizerJNI\out\*.jar"                                        "%PACK_PATH%\%%c"
200                 if not "!ERRORLEVEL!"=="0" goto BuildError
201                 copy "%~dp0\..\Prerequisites\LibSndFile\bin\Win32\libsndfile-1.dll"                     "%PACK_PATH%\%%c"
202                 if not "!ERRORLEVEL!"=="0" goto BuildError
203                 copy "%~dp0\..\Prerequisites\LibMpg123\bin\Win32\libmpg123.v%TOOLS_VER%_xp.dll"         "%PACK_PATH%\%%c\libmpg123.dll"
204                 if not "!ERRORLEVEL!"=="0" goto BuildError
205                 copy "%~dp0\..\Prerequisites\XiphAudioLibs\bin\Win32\libopus.v%TOOLS_VER%_xp.dll"       "%PACK_PATH%\%%c\libopus.dll"
206                 if not "!ERRORLEVEL!"=="0" goto BuildError
207                 copy "%~dp0\..\Prerequisites\XiphAudioLibs\bin\Win32\libopusfile.v%TOOLS_VER%_xp.dll"   "%PACK_PATH%\%%c\libopusfile.dll"
208                 if not "!ERRORLEVEL!"=="0" goto BuildError
209                 copy "%~dp0\..\Prerequisites\XiphAudioLibs\bin\Win32\libogg.v%TOOLS_VER%_xp.dll"        "%PACK_PATH%\%%c\libogg.dll"
210                 if not "!ERRORLEVEL!"=="0" goto BuildError
211                 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtGui4.dll"                 "%PACK_PATH%\%%c"
212                 if not "!ERRORLEVEL!"=="0" goto BuildError
213                 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtCore4.dll"                "%PACK_PATH%\%%c"
214                 if not "!ERRORLEVEL!"=="0" goto BuildError
215                 copy "%~dp0\DynamicAudioNormalizerNET\samples\*.cs"                                     "%PACK_PATH%\%%c\samples\dotNet"
216                 if not "!ERRORLEVEL!"=="0" goto BuildError
217                 copy "%~dp0\DynamicAudioNormalizerNET\samples\*.vb"                                     "%PACK_PATH%\%%c\samples\dotNet"
218                 if not "!ERRORLEVEL!"=="0" goto BuildError
219                 copy "%~dp0\DynamicAudioNormalizerPAS\src\*.pas"                                        "%PACK_PATH%\%%c\samples\delphi"
220                 if not "!ERRORLEVEL!"=="0" goto BuildError
221                 copy "%~dp0\DynamicAudioNormalizerPAS\src\*.dfm"                                        "%PACK_PATH%\%%c\samples\delphi"
222                 if not "!ERRORLEVEL!"=="0" goto BuildError
223                 copy "%~dp0\DynamicAudioNormalizerJNI\samples\com\muldersoft\dynaudnorm\samples\*.java" "%PACK_PATH%\%%c\samples\java"
224                 if not "!ERRORLEVEL!"=="0" goto BuildError
225                 
226                 if %TOOLS_VER% GEQ 140 (
227                         if %TOOLS_VER% GEQ 141 (
228                                 copy "%VCToolsRedistDir%\x86\Microsoft.VC%TOOLS_VER%.CRT\*.dll"                 "%PACK_PATH%\%%c"
229                                 if not "!ERRORLEVEL!"=="0" goto BuildError
230                                 copy "%VCToolsRedistDir%\x64\Microsoft.VC%TOOLS_VER%.CRT\*.dll"                 "%PACK_PATH%\%%c\x64"
231                                 if not "!ERRORLEVEL!"=="0" goto BuildError
232                                 copy "%VCToolsRedistDir%\vcredist_*.exe"                                        "%PACK_PATH%\%%c\redist"
233                                 if not "!ERRORLEVEL!"=="0" goto BuildError
234                         ) else (
235                                 copy "%MSVC_PATH%\redist\x86\Microsoft.VC%TOOLS_VER%.CRT\*.dll"                 "%PACK_PATH%\%%c"
236                                 if not "!ERRORLEVEL!"=="0" goto BuildError
237                                 copy "%MSVC_PATH%\redist\x64\Microsoft.VC%TOOLS_VER%.CRT\*.dll"                 "%PACK_PATH%\%%c\x64"
238                                 if not "!ERRORLEVEL!"=="0" goto BuildError
239                                 copy "%MSVC_PATH%\redist\1033\vcredist_*.exe"                                   "%PACK_PATH%\%%c\redist"
240                                 if not "!ERRORLEVEL!"=="0" goto BuildError
241                         )
242                         copy "%~dp0\..\Prerequisites\MSVC\redist\ucrt\DLLs\x86\*.dll"                       "%PACK_PATH%\%%c"
243                         if not "!ERRORLEVEL!"=="0" goto BuildError
244                         copy "%~dp0\..\Prerequisites\MSVC\redist\ucrt\DLLs\x64\*.dll"                       "%PACK_PATH%\%%c\x64"
245                         if not "!ERRORLEVEL!"=="0" goto BuildError
246                 )
247         )
249         copy "%~dp0\LICENSE-LGPL.html"                                                              "%PACK_PATH%\%%c"
250         if not "!ERRORLEVEL!"=="0" goto BuildError
251         copy "%~dp0\LICENSE-GPL2.html"                                                              "%PACK_PATH%\%%c"
252         if not "!ERRORLEVEL!"=="0" goto BuildError
253         copy "%~dp0\LICENSE-GPL3.html"                                                              "%PACK_PATH%\%%c"
254         if not "!ERRORLEVEL!"=="0" goto BuildError
255         copy "%~dp0\img\dyauno\*.png"                                                               "%PACK_PATH%\%%c\img\dyauno"
256         if not "!ERRORLEVEL!"=="0" goto BuildError
258         "%~dp0\..\Prerequisites\Pandoc\pandoc.exe" --from markdown_github+pandoc_title_block+header_attributes+implicit_figures --to html5 --toc -N --standalone -H "%~dp0\..\Prerequisites\Pandoc\css\github-pandoc.inc" "%~dp0\README.md" | "%JAVA_HOME%\bin\java.exe" -jar "%~dp0\..\Prerequisites\HTMLCompressor\bin\htmlcompressor-1.5.3.jar" --compress-css -o "%PACK_PATH%\%%c\README.html"
259         if not "!ERRORLEVEL!"=="0" goto BuildError
262 REM ///////////////////////////////////////////////////////////////////////////
263 REM // Compress
264 REM ///////////////////////////////////////////////////////////////////////////
265 for %%c in (Static) do (
266         for %%i in (DynamicAudioNormalizerCLI.exe,DynamicAudioNormalizerGUI.exe,DynamicAudioNormalizerPYD.pyd,DynamicAudioNormalizerVST.dll,DynamicAudioNormalizerWA5.dll) do (
267                 "%~dp0\..\Prerequisites\UPX\upx.exe" --best "%PACK_PATH%\%%c\%%~i"
268                 if not "!ERRORLEVEL!"=="0" goto BuildError
269         )
270         for %%i in (DynamicAudioNormalizerPYD.pyd,DynamicAudioNormalizerVST.dll) do (
271                 "%~dp0\..\Prerequisites\UPX\upx.exe" --best "%PACK_PATH%\%%c\x64\%%~i"
272                 if not "!ERRORLEVEL!"=="0" goto BuildError
273         )
276 REM ///////////////////////////////////////////////////////////////////////////
277 REM // Create version tag
278 REM ///////////////////////////////////////////////////////////////////////////
279 echo Dynamic Audio Normalizer>                                                                                                                     "%PACK_PATH%\BUILD_TAG"
280 echo Copyright (c) 2014-2019 LoRd_MuldeR ^<MuldeR2@GMX.de^>. Some rights reserved.>>                                                               "%PACK_PATH%\BUILD_TAG"
281 echo.>>                                                                                                                                            "%PACK_PATH%\BUILD_TAG"
282 echo Version %VER_MAJOR%.%VER_MINOR%-%VER_PATCH%. Built on %ISO_DATE%, at %ISO_TIME%>>                                                             "%PACK_PATH%\BUILD_TAG"
283 echo.>>                                                                                                                                            "%PACK_PATH%\BUILD_TAG"
284 cl.exe 2>&1 | "%~dp0\..\Prerequisites\GnuWin32\head.exe" -n1 | "%~dp0\..\Prerequisites\GnuWin32\sed.exe" -e "/^$/d" -e "s/^/Compiler version: /">> "%PACK_PATH%\BUILD_TAG"
285 ver    2>&1 |                                                  "%~dp0\..\Prerequisites\GnuWin32\sed.exe" -e "/^$/d" -e "s/^/Build platform:   /">> "%PACK_PATH%\BUILD_TAG"
286 echo.>>                                                                                                                                            "%PACK_PATH%\BUILD_TAG"
287 echo This library is free software; you can redistribute it and/or>>                                                                               "%PACK_PATH%\BUILD_TAG"
288 echo modify it under the terms of the GNU Lesser General Public>>                                                                                  "%PACK_PATH%\BUILD_TAG"
289 echo License as published by the Free Software Foundation; either>>                                                                                "%PACK_PATH%\BUILD_TAG"
290 echo version 2.1 of the License, or (at your option) any later version.>>                                                                          "%PACK_PATH%\BUILD_TAG"
291 echo.>>                                                                                                                                            "%PACK_PATH%\BUILD_TAG"
292 echo This library is distributed in the hope that it will be useful,>>                                                                             "%PACK_PATH%\BUILD_TAG"
293 echo but WITHOUT ANY WARRANTY; without even the implied warranty of>>                                                                              "%PACK_PATH%\BUILD_TAG"
294 echo MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU>>                                                                           "%PACK_PATH%\BUILD_TAG"
295 echo Lesser General Public License for more details.>>                                                                                             "%PACK_PATH%\BUILD_TAG"
297 REM ///////////////////////////////////////////////////////////////////////////
298 REM // Attributes
299 REM ///////////////////////////////////////////////////////////////////////////
300 for %%c in (DLL, Static) do (
301         attrib +R "%PACK_PATH%\%%c\*"
302         attrib +R "%PACK_PATH%\%%c\x64\*"
303         attrib +R "%PACK_PATH%\%%c\img\dyauno\*"
304         if /I "%%c"=="DLL" (
305                 attrib +R "%PACK_PATH%\%%c\include\*"
306         )
309 REM ///////////////////////////////////////////////////////////////////////////
310 REM // Generate outfile name
311 REM ///////////////////////////////////////////////////////////////////////////
312 mkdir "%~dp0\out" 2> NUL
313 set "OUT_NAME=DynamicAudioNormalizer.%ISO_DATE%"
314 :CheckOutName
315 for %%c in (DLL, Static) do (
316         if exist "%~dp0\out\%OUT_NAME%.%%c.zip" (
317                 set "OUT_NAME=%OUT_NAME%.new"
318                 goto CheckOutName
319         )
322 REM ///////////////////////////////////////////////////////////////////////////
323 REM // Build the package
324 REM ///////////////////////////////////////////////////////////////////////////
325 for %%c in (DLL, Static) do (
326         copy "%PACK_PATH%\BUILD_TAG" "%PACK_PATH%\%%c"
327         pushd "%PACK_PATH%\%%c"
328         "%~dp0\..\Prerequisites\GnuWin32\zip.exe" -9 -r -z "%~dp0\out\%OUT_NAME%.%%c.zip" "*.*" < "%PACK_PATH%\BUILD_TAG"
329         popd
330         attrib +R "%~dp0\out\%OUT_NAME%.%%c.zip"
333 REM Clean up!
334 rmdir /Q /S "%PACK_PATH%"
336 REM ///////////////////////////////////////////////////////////////////////////
337 REM // COMPLETE
338 REM ///////////////////////////////////////////////////////////////////////////
339 echo.
340 echo Build completed.
341 echo.
342 pause
343 goto:eof
345 REM ///////////////////////////////////////////////////////////////////////////
346 REM // FAILED
347 REM ///////////////////////////////////////////////////////////////////////////
348 :BuildError
349 echo.
350 echo Build has failed ^^!^^!^^!
351 echo.
352 pause