Small build script update.
[simple-x264-launcher.git] / z_build.bat
blob37227b054c43e2c700e0329c42dcaa0a63610174
1 @echo off
2 REM ///////////////////////////////////////////////////////////////////////////
3 REM // Set Paths
4 REM ///////////////////////////////////////////////////////////////////////////
5 set "MSVC_PATH=C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC"
6 set "TOOLS_VER=140"
8 REM ###############################################
9 REM # DO NOT MODIFY ANY LINES BELOW THIS LINE !!! #
10 REM ###############################################
12 REM ///////////////////////////////////////////////////////////////////////////
13 REM // Setup environment
14 REM ///////////////////////////////////////////////////////////////////////////
15 if exist "%QTVC_PATH%\bin\qtvars.bat" ( call "%QTVC_PATH%\bin\qtvars.bat" )
16 if exist "%QTVC_PATH%\bin\qtenv2.bat" ( call "%QTVC_PATH%\bin\qtenv2.bat" )
17 call "%MSVC_PATH%\vcvarsall.bat" x86
19 REM ///////////////////////////////////////////////////////////////////////////
20 REM // Check environment
21 REM ///////////////////////////////////////////////////////////////////////////
22 if "%VCINSTALLDIR%"=="" (
23         echo %%VCINSTALLDIR%% not specified. Please check your MSVC_PATH var!
24         goto BuildError
26 if not exist "%VCINSTALLDIR%\bin\cl.exe" (
27         echo C++ compiler not found. Please check your MSVC_PATH var!
28         goto BuildError
30 if "%QTDIR%"=="" (
31         echo %%QTDIR%% not specified. Please check your QTDIR var!
32         goto BuildError
34 if not exist "%QTDIR%\bin\moc.exe" (
35         echo Qt meta compiler not found. Please check your QTDIR var!
36         goto BuildError
38 if not exist "%QTDIR%\include\QtCore\qglobal.h" (
39         echo %%QTDIR%% header files not found. Please check your QTDIR var!
40         goto BuildError
43 REM ///////////////////////////////////////////////////////////////////////////
44 REM // Get current date and time (in ISO format)
45 REM ///////////////////////////////////////////////////////////////////////////
46 set "ISO_DATE="
47 set "ISO_TIME="
48 if not exist "%~dp0\..\Prerequisites\GnuWin32\date.exe" BuildError
49 for /F "tokens=1,2 delims=:" %%a in ('"%~dp0\..\Prerequisites\GnuWin32\date.exe" +ISODATE:%%Y-%%m-%%d') do (
50         if "%%a"=="ISODATE" set "ISO_DATE=%%b"
52 for /F "tokens=1,2,3,4 delims=:" %%a in ('"%~dp0\..\Prerequisites\GnuWin32\date.exe" +ISOTIME:%%T') do (
53         if "%%a"=="ISOTIME" set "ISO_TIME=%%b:%%c:%%d"
55 if "%ISO_DATE%"=="" goto BuildError
56 if "%ISO_TIME%"=="" goto BuildError
58 REM ///////////////////////////////////////////////////////////////////////////
59 REM // Clean up temp files
60 REM ///////////////////////////////////////////////////////////////////////////
61 echo ---------------------------------------------------------------------
62 echo CLEAN UP
63 echo ---------------------------------------------------------------------
64 for %%i in (bin,obj,tmp) do (
65         del /Q /S /F "%~dp0\%%i\*.*"
68 REM ///////////////////////////////////////////////////////////////////////////
69 REM // Build the binaries
70 REM ///////////////////////////////////////////////////////////////////////////
71 echo ---------------------------------------------------------------------
72 echo BEGIN BUILD
73 echo ---------------------------------------------------------------------
74 MSBuild.exe /property:Configuration=release /target:clean   "%~dp0\x264_launcher_MSVC2015.sln"
75 if not "%ERRORLEVEL%"=="0" goto BuildError
76 MSBuild.exe /property:Configuration=release /target:rebuild "%~dp0\x264_launcher_MSVC2015.sln"
77 if not "%ERRORLEVEL%"=="0" goto BuildError
79 REM ///////////////////////////////////////////////////////////////////////////
80 REM // Detect build number
81 REM ///////////////////////////////////////////////////////////////////////////
82 set "BUILD_NO="
83 for /F "tokens=2,*" %%s in (%~dp0\src\version.h) do (
84         if "%%s"=="VER_X264_BUILD" set "BUILD_NO=%%~t"
86 if "%BUILD_NO%"=="" goto BuildError
88 REM ///////////////////////////////////////////////////////////////////////////
89 REM // Copy base files
90 REM ///////////////////////////////////////////////////////////////////////////
91 echo ---------------------------------------------------------------------
92 echo BEGIN PACKAGING
93 echo ---------------------------------------------------------------------
94 set "PACK_PATH=%TMP%\~%RANDOM%%RANDOM%.tmp"
95 mkdir "%PACK_PATH%"
96 mkdir "%PACK_PATH%\imageformats"
97 mkdir "%PACK_PATH%\toolset\x86"
98 mkdir "%PACK_PATH%\toolset\x64"
99 mkdir "%PACK_PATH%\toolset\common"
100 mkdir "%PACK_PATH%\sources"
101 copy "%~dp0\bin\Win32\Release\x264_launcher.exe"    "%PACK_PATH%"
102 copy "%~dp0\bin\Win32\Release\MUtils32-?.dll"       "%PACK_PATH%"
103 copy "%~dp0\bin\Win32\Release\toolset\x86\*.exe"    "%PACK_PATH%\toolset\x86"
104 copy "%~dp0\bin\Win32\Release\toolset\x86\*.dll"    "%PACK_PATH%\toolset\x86"
105 copy "%~dp0\bin\Win32\Release\toolset\x64\*.exe"    "%PACK_PATH%\toolset\x64"
106 copy "%~dp0\bin\Win32\Release\toolset\x64\*.dll"    "%PACK_PATH%\toolset\x64"
107 copy "%~dp0\bin\Win32\Release\toolset\common\*.exe" "%PACK_PATH%\toolset\common"
108 copy "%~dp0\bin\Win32\Release\toolset\common\*.gpg" "%PACK_PATH%\toolset\common"
109 copy "%~dp0\etc\sources\*.xz"                       "%PACK_PATH%\sources"
110 copy "%~dp0\LICENSE.html"                           "%PACK_PATH%"
111 copy "%~dp0\*.txt"                                  "%PACK_PATH%"
113 REM ///////////////////////////////////////////////////////////////////////////
114 REM // Copy dependencies
115 REM ///////////////////////////////////////////////////////////////////////////
116 copy "%MSVC_PATH%\redist\x86\Microsoft.VC%TOOLS_VER%.CRT\*.dll"                     "%PACK_PATH%"
117 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtCore4.dll"            "%PACK_PATH%"
118 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtGui4.dll"             "%PACK_PATH%"
119 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtSvg4.dll"             "%PACK_PATH%"
120 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtXml4.dll"             "%PACK_PATH%"
121 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtXml4.dll"             "%PACK_PATH%"
122 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\plugins\imageformats\*.dll" "%PACK_PATH%\imageformats"
123 del "%PACK_PATH%\imageformats\*d4.dll" 2> NUL
124 if %TOOLS_VER% GEQ 140 (
125         copy "%~dp0\..\Prerequisites\MSVC\redist\ucrt\DLLs\x86\*.dll" "%PACK_PATH%"
128 REM ///////////////////////////////////////////////////////////////////////////
129 REM // Generate Docs
130 REM ///////////////////////////////////////////////////////////////////////////
131 "%~dp0\..\Prerequisites\Pandoc\pandoc.exe" --from markdown_github+pandoc_title_block+header_attributes+implicit_figures --to html5 --toc -N --standalone -H "%~dp0\etc\css\style.inc" --output "%PACK_PATH%\README.html" "%~dp0\README.md"
133 REM ///////////////////////////////////////////////////////////////////////////
134 REM // Compress
135 REM ///////////////////////////////////////////////////////////////////////////
136 "%~dp0\..\Prerequisites\UPX\upx.exe" --best "%PACK_PATH%\x264_launcher.exe"
137 "%~dp0\..\Prerequisites\UPX\upx.exe" --best "%PACK_PATH%\MUtils32-1.dll"
138 "%~dp0\..\Prerequisites\UPX\upx.exe" --best "%PACK_PATH%\Qt*.dll"
140 REM ///////////////////////////////////////////////////////////////////////////
141 REM // Attributes
142 REM ///////////////////////////////////////////////////////////////////////////
143 attrib +R "%PACK_PATH%\*.exe"
144 attrib +R "%PACK_PATH%\*.dll"
145 attrib +R "%PACK_PATH%\*.txt"
146 attrib +R "%PACK_PATH%\*.html"
148 REM ///////////////////////////////////////////////////////////////////////////
149 REM // Setup install parameters
150 REM ///////////////////////////////////////////////////////////////////////////
151 mkdir "%~dp0\out" 2> NUL
152 set "OUT_PATH=%~dp0\out\x264_launcher.%ISO_DATE%"
153 :GenerateOutfileName
154 if exist "%OUT_PATH%.exe" (
155         set "OUT_PATH=%OUT_PATH%.new"
156         goto GenerateOutfileName
158 if exist "%OUT_PATH%.sfx" (
159         set "OUT_PATH=%OUT_PATH%.new"
160         goto GenerateOutfileName
162 if exist "%OUT_PATH%.zip" (
163         set "OUT_PATH=%OUT_PATH%.new"
164         goto GenerateOutfileName
167 REM ///////////////////////////////////////////////////////////////////////////
168 REM // Create Tag
169 REM ///////////////////////////////////////////////////////////////////////////
170 echo Simple x264/x265 Launcher - graphical front-end for x264 and x265 > "%PACK_PATH%\BUILD_TAG.txt"
171 echo Copyright (C) 2004-2017 LoRd_MuldeR ^<MuldeR2@GMX.de^> >> "%PACK_PATH%\BUILD_TAG.txt"
172 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
173 echo Build #%BUILD_NO%, created on %ISO_DATE% at %ISO_TIME% >> "%PACK_PATH%\BUILD_TAG.txt"
174 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
175 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
176 "%~dp0\..\Prerequisites\GnuWin32\cat.exe" "%~dp0\etc\setup\build.nfo" >> "%PACK_PATH%\BUILD_TAG.txt"
178 REM ///////////////////////////////////////////////////////////////////////////
179 REM // Build the installer
180 REM ///////////////////////////////////////////////////////////////////////////
181 "%~dp0\..\Prerequisites\NSIS\makensis.exe" "/DX264_DATE=%ISO_DATE%" "/DX264_BUILD=%BUILD_NO%" "/DX264_OUTPUT_FILE=%OUT_PATH%.sfx" "/DX264_SOURCE_PATH=%PACK_PATH%" "%~dp0\etc\setup\setup.nsi"
182 if not "%ERRORLEVEL%"=="0" goto BuildError
184 call "%~dp0\..\Prerequisites\SevenZip\7zSD.cmd" "%OUT_PATH%.sfx" "%OUT_PATH%.exe" "Simple x264/x265 Launcher" "x264_launcher-setup-r%BUILD_NO%"
185 if not "%ERRORLEVEL%"=="0" goto BuildError
187 set "VERPATCH_PRODUCT=Simple x264/x265 Launcher (Setup)"
188 set "VERPATCH_FILEVER=%ISO_DATE:-=.%.%BUILD_NO%"
189 "%~dp0\..\Prerequisites\VerPatch\verpatch.exe" "%OUT_PATH%.exe" "%VERPATCH_FILEVER%" /pv "%VERPATCH_FILEVER%" /fn /s desc "%VERPATCH_PRODUCT%" /s product "%VERPATCH_PRODUCT%" /s title "x264 Launcher Installer SFX" /s copyright "Copyright (C) 2004-2017 LoRd_MuldeR" /s company "Free Software Foundation"
190 if not "%ERRORLEVEL%"=="0" goto BuildError
192 attrib +R "%OUT_PATH%.exe"
193 attrib +R "%OUT_PATH%.sfx"
195 REM ///////////////////////////////////////////////////////////////////////////
196 REM // Build ZIP package
197 REM ///////////////////////////////////////////////////////////////////////////
198 pushd "%PACK_PATH%"
199 "%~dp0\..\Prerequisites\GnuWin32\zip.exe" -r -9 -z "%OUT_PATH%.zip" "*.*" < "%PACK_PATH%\BUILD_TAG.txt"
200 popd
202 if not "%ERRORLEVEL%"=="0" goto BuildError
203 attrib +R "%OUT_PATH%.zip"
205 REM ///////////////////////////////////////////////////////////////////////////
206 REM // Clean up
207 REM ///////////////////////////////////////////////////////////////////////////
208 rmdir /Q /S "%PACK_PATH%"
210 REM ///////////////////////////////////////////////////////////////////////////
211 REM // COMPLETE
212 REM ///////////////////////////////////////////////////////////////////////////
213 echo.
214 echo Build completed.
215 echo.
216 pause
217 goto:eof
219 REM ///////////////////////////////////////////////////////////////////////////
220 REM // FAILED
221 REM ///////////////////////////////////////////////////////////////////////////
222 :BuildError
223 echo.
224 echo Build has failed !!!
225 echo.
226 pause