OSDN Git Service

Adapt for latest changes in MUtilities library.
[x264-launcher/x264-launcher.git] / z_build.bat
1 @echo off
2 REM ///////////////////////////////////////////////////////////////////////////
3 REM // Set Paths
4 REM ///////////////////////////////////////////////////////////////////////////
5 set "MSVC_PATH=C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build"
6 set "TOOLS_VER=141"
7
8 REM ###############################################
9 REM # DO NOT MODIFY ANY LINES BELOW THIS LINE !!! #
10 REM ###############################################
11
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
18
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
25 )
26 if not exist "%VCToolsInstallDir%\bin\HostX86\x86\cl.exe" (
27         echo C++ compiler not found. Please check your MSVC_PATH var!
28         goto BuildError
29 )
30 if "%QTDIR%"=="" (
31         echo %%QTDIR%% not specified. Please check your QTDIR var!
32         goto BuildError
33 )
34 if not exist "%QTDIR%\bin\moc.exe" (
35         echo Qt meta compiler not found. Please check your QTDIR var!
36         goto BuildError
37 )
38 if not exist "%QTDIR%\include\QtCore\qglobal.h" (
39         echo %%QTDIR%% header files not found. Please check your QTDIR var!
40         goto BuildError
41 )
42 if not exist "%JAVA_HOME%\bin\java.exe" (
43         echo Java runtime not found. Please check your JAVA_HOME var!
44         goto BuildError
45 )
46
47 REM ///////////////////////////////////////////////////////////////////////////
48 REM // Get current date and time (in ISO format)
49 REM ///////////////////////////////////////////////////////////////////////////
50 set "ISO_DATE="
51 set "ISO_TIME="
52 if not exist "%~dp0\..\Prerequisites\GnuWin32\date.exe" BuildError
53 for /F "tokens=1,2 delims=:" %%a in ('"%~dp0\..\Prerequisites\GnuWin32\date.exe" +ISODATE:%%Y-%%m-%%d') do (
54         if "%%a"=="ISODATE" set "ISO_DATE=%%b"
55 )
56 for /F "tokens=1,2,3,4 delims=:" %%a in ('"%~dp0\..\Prerequisites\GnuWin32\date.exe" +ISOTIME:%%T') do (
57         if "%%a"=="ISOTIME" set "ISO_TIME=%%b:%%c:%%d"
58 )
59 if "%ISO_DATE%"=="" goto BuildError
60 if "%ISO_TIME%"=="" goto BuildError
61
62 REM ///////////////////////////////////////////////////////////////////////////
63 REM // Clean up temp files
64 REM ///////////////////////////////////////////////////////////////////////////
65 echo ---------------------------------------------------------------------
66 echo CLEAN UP
67 echo ---------------------------------------------------------------------
68 for %%i in (bin,obj,tmp) do (
69         del /Q /S /F "%~dp0\%%i\*.*"
70 )
71
72 REM ///////////////////////////////////////////////////////////////////////////
73 REM // Build the binaries
74 REM ///////////////////////////////////////////////////////////////////////////
75 echo ---------------------------------------------------------------------
76 echo BEGIN BUILD
77 echo ---------------------------------------------------------------------
78 MSBuild.exe /property:Configuration=release /property:Platform=win32 /target:clean   "%~dp0\x264_launcher_MSVC2017.sln"
79 if not "%ERRORLEVEL%"=="0" goto BuildError
80 MSBuild.exe /property:Configuration=release /property:Platform=win32 /target:rebuild "%~dp0\x264_launcher_MSVC2017.sln"
81 if not "%ERRORLEVEL%"=="0" goto BuildError
82
83 REM ///////////////////////////////////////////////////////////////////////////
84 REM // Detect build number
85 REM ///////////////////////////////////////////////////////////////////////////
86 set "BUILD_NO="
87 for /F "tokens=2,*" %%s in (%~dp0\src\version.h) do (
88         if "%%s"=="VER_X264_BUILD" set "BUILD_NO=%%~t"
89 )
90 if "%BUILD_NO%"=="" goto BuildError
91
92 REM ///////////////////////////////////////////////////////////////////////////
93 REM // Copy base files
94 REM ///////////////////////////////////////////////////////////////////////////
95 echo ---------------------------------------------------------------------
96 echo BEGIN PACKAGING
97 echo ---------------------------------------------------------------------
98 set "PACK_PATH=%TMP%\~%RANDOM%%RANDOM%.tmp"
99 mkdir "%PACK_PATH%"
100 mkdir "%PACK_PATH%\imageformats"
101 mkdir "%PACK_PATH%\toolset\x86"
102 mkdir "%PACK_PATH%\toolset\x64"
103 mkdir "%PACK_PATH%\toolset\common"
104 mkdir "%PACK_PATH%\sources"
105 copy "%~dp0\bin\Win32\Release\x264_launcher.exe"    "%PACK_PATH%"
106 copy "%~dp0\bin\Win32\Release\MUtils32-?.dll"       "%PACK_PATH%"
107 copy "%~dp0\bin\Win32\Release\toolset\x86\*.exe"    "%PACK_PATH%\toolset\x86"
108 copy "%~dp0\bin\Win32\Release\toolset\x86\*.dll"    "%PACK_PATH%\toolset\x86"
109 copy "%~dp0\bin\Win32\Release\toolset\x64\*.exe"    "%PACK_PATH%\toolset\x64"
110 copy "%~dp0\bin\Win32\Release\toolset\x64\*.dll"    "%PACK_PATH%\toolset\x64"
111 copy "%~dp0\bin\Win32\Release\toolset\common\*.exe" "%PACK_PATH%\toolset\common"
112 copy "%~dp0\bin\Win32\Release\toolset\common\*.gpg" "%PACK_PATH%\toolset\common"
113 copy "%~dp0\etc\sources\*.xz"                       "%PACK_PATH%\sources"
114 copy "%~dp0\LICENSE.html"                           "%PACK_PATH%"
115 copy "%~dp0\*.txt"                                  "%PACK_PATH%"
116
117 REM ///////////////////////////////////////////////////////////////////////////
118 REM // Copy dependencies
119 REM ///////////////////////////////////////////////////////////////////////////
120 copy "%~dp0\..\Prerequisites\MSVC\redist\vc\v%TOOLS_VER%_xp\x86\*.dll"              "%PACK_PATH%"
121 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtCore4.dll"            "%PACK_PATH%"
122 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtGui4.dll"             "%PACK_PATH%"
123 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtSvg4.dll"             "%PACK_PATH%"
124 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtXml4.dll"             "%PACK_PATH%"
125 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtXml4.dll"             "%PACK_PATH%"
126 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\plugins\imageformats\*.dll" "%PACK_PATH%\imageformats"
127 del "%PACK_PATH%\imageformats\*d4.dll" 2> NUL
128 if %TOOLS_VER% GEQ 140 (
129         copy "%~dp0\..\Prerequisites\MSVC\redist\ucrt\DLLs\x86\*.dll" "%PACK_PATH%"
130 )
131
132 REM ///////////////////////////////////////////////////////////////////////////
133 REM // Generate Docs
134 REM ///////////////////////////////////////////////////////////////////////////
135 "%~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" "%~dp0\README.md" | "%JAVA_HOME%\bin\java.exe" -jar "%~dp0\..\Prerequisites\HTMLCompressor\bin\htmlcompressor-1.5.3.jar" --compress-css -o "%PACK_PATH%\README.html"
136
137 REM ///////////////////////////////////////////////////////////////////////////
138 REM // Compress
139 REM ///////////////////////////////////////////////////////////////////////////
140 "%~dp0\..\Prerequisites\UPX\upx.exe" --best "%PACK_PATH%\x264_launcher.exe"
141 "%~dp0\..\Prerequisites\UPX\upx.exe" --best "%PACK_PATH%\MUtils32-1.dll"
142 "%~dp0\..\Prerequisites\UPX\upx.exe" --best "%PACK_PATH%\Qt*.dll"
143
144 REM ///////////////////////////////////////////////////////////////////////////
145 REM // Attributes
146 REM ///////////////////////////////////////////////////////////////////////////
147 attrib +R "%PACK_PATH%\*.exe"
148 attrib +R "%PACK_PATH%\*.dll"
149 attrib +R "%PACK_PATH%\*.txt"
150 attrib +R "%PACK_PATH%\*.html"
151
152 REM ///////////////////////////////////////////////////////////////////////////
153 REM // Setup install parameters
154 REM ///////////////////////////////////////////////////////////////////////////
155 mkdir "%~dp0\out" 2> NUL
156 set "OUT_PATH=%~dp0\out\x264_launcher.%ISO_DATE%"
157 :GenerateOutfileName
158 if exist "%OUT_PATH%.exe" (
159         set "OUT_PATH=%OUT_PATH%.new"
160         goto GenerateOutfileName
161 )
162 if exist "%OUT_PATH%.sfx" (
163         set "OUT_PATH=%OUT_PATH%.new"
164         goto GenerateOutfileName
165 )
166 if exist "%OUT_PATH%.zip" (
167         set "OUT_PATH=%OUT_PATH%.new"
168         goto GenerateOutfileName
169 )
170
171 REM ///////////////////////////////////////////////////////////////////////////
172 REM // Create Tag
173 REM ///////////////////////////////////////////////////////////////////////////
174 echo Simple x264/x265 Launcher - graphical front-end for x264 and x265 > "%PACK_PATH%\BUILD_TAG.txt"
175 echo Copyright (C) 2004-2018 LoRd_MuldeR ^<MuldeR2@GMX.de^> >> "%PACK_PATH%\BUILD_TAG.txt"
176 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
177 echo Build #%BUILD_NO%, created on %ISO_DATE% at %ISO_TIME% >> "%PACK_PATH%\BUILD_TAG.txt"
178 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
179 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
180 "%~dp0\..\Prerequisites\GnuWin32\cat.exe" "%~dp0\etc\setup\build.nfo" >> "%PACK_PATH%\BUILD_TAG.txt"
181
182 REM ///////////////////////////////////////////////////////////////////////////
183 REM // Build the installer
184 REM ///////////////////////////////////////////////////////////////////////////
185 "%~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"
186 if not "%ERRORLEVEL%"=="0" goto BuildError
187
188 "%~dp0\..\Prerequisites\NSIS\peheader.exe" "%OUT_PATH%.sfx"
189 if not "%ERRORLEVEL%"=="0" goto BuildError
190
191 call "%~dp0\..\Prerequisites\SevenZip\7zSD.cmd" "%OUT_PATH%.sfx" "%OUT_PATH%.exe" "Simple x264/x265 Launcher" "x264_launcher-setup-r%BUILD_NO%"
192 if not "%ERRORLEVEL%"=="0" goto BuildError
193
194 set "VERPATCH_PRODUCT=Simple x264/x265 Launcher (Setup)"
195 set "VERPATCH_FILEVER=%ISO_DATE:-=.%.%BUILD_NO%"
196 "%~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-2018 LoRd_MuldeR" /s company "Free Software Foundation"
197 if not "%ERRORLEVEL%"=="0" goto BuildError
198
199 "%~dp0\..\Prerequisites\NSIS\peheader.exe" "%OUT_PATH%.exe"
200 if not "%ERRORLEVEL%"=="0" goto BuildError
201
202 attrib +R "%OUT_PATH%.exe"
203 attrib +R "%OUT_PATH%.sfx"
204
205 REM ///////////////////////////////////////////////////////////////////////////
206 REM // Build ZIP package
207 REM ///////////////////////////////////////////////////////////////////////////
208 pushd "%PACK_PATH%"
209 "%~dp0\..\Prerequisites\GnuWin32\zip.exe" -r -9 -z "%OUT_PATH%.zip" "*.*" < "%PACK_PATH%\BUILD_TAG.txt"
210 popd
211
212 if not "%ERRORLEVEL%"=="0" goto BuildError
213 attrib +R "%OUT_PATH%.zip"
214
215 REM ///////////////////////////////////////////////////////////////////////////
216 REM // Clean up
217 REM ///////////////////////////////////////////////////////////////////////////
218 rmdir /Q /S "%PACK_PATH%"
219
220 REM ///////////////////////////////////////////////////////////////////////////
221 REM // COMPLETE
222 REM ///////////////////////////////////////////////////////////////////////////
223 echo.
224 echo Build completed.
225 echo.
226 pause
227 goto:eof
228
229 REM ///////////////////////////////////////////////////////////////////////////
230 REM // FAILED
231 REM ///////////////////////////////////////////////////////////////////////////
232 :BuildError
233 echo.
234 echo Build has failed !!!
235 echo.
236 pause