OSDN Git Service

Refactored code to better manage the encoder binary paths: They are now handled by...
[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\Microsoft Visual Studio 12.0\VC"
6 set "NSIS_PATH=C:\Program Files\NSIS\Unicode"
7 set "UPX3_PATH=C:\Program Files\UPX"
8 set "PDOC_PATH=C:\Program Files\Pandoc"
9 set "TOOLS_VER=120"
10
11 REM ###############################################
12 REM # DO NOT MODIFY ANY LINES BELOW THIS LINE !!! #
13 REM ###############################################
14
15 REM ///////////////////////////////////////////////////////////////////////////
16 REM // Setup environment
17 REM ///////////////////////////////////////////////////////////////////////////
18 call "%MSVC_PATH%\vcvarsall.bat" x86
19
20 REM ///////////////////////////////////////////////////////////////////////////
21 REM // Check environment
22 REM ///////////////////////////////////////////////////////////////////////////
23 if "%VCINSTALLDIR%"=="" (
24         echo %%VCINSTALLDIR%% not specified. Please check your MSVC_PATH var!
25         goto BuildError
26 )
27 if "%QTDIR%"=="" (
28         echo %%QTDIR%% not specified. Please check your MSVC_PATH var!
29         goto BuildError
30 )
31 if not exist "%VCINSTALLDIR%\bin\cl.exe" (
32         echo C++ compiler not found. Please check your MSVC_PATH var!
33         goto BuildError
34 )
35 if not exist "%PDOC_PATH%\pandoc.exe" (
36         echo Pandoc binary could not be found. Please check your PDOC_PATH var!
37         goto BuildError
38 )
39
40 REM ///////////////////////////////////////////////////////////////////////////
41 REM // Get current date and time (in ISO format)
42 REM ///////////////////////////////////////////////////////////////////////////
43 set "ISO_DATE="
44 set "ISO_TIME="
45 if not exist "%~dp0\etc\date.exe" BuildError
46 for /F "tokens=1,2 delims=:" %%a in ('"%~dp0\etc\date.exe" +ISODATE:%%Y-%%m-%%d') do (
47         if "%%a"=="ISODATE" set "ISO_DATE=%%b"
48 )
49 for /F "tokens=1,2,3,4 delims=:" %%a in ('"%~dp0\etc\date.exe" +ISOTIME:%%T') do (
50         if "%%a"=="ISOTIME" set "ISO_TIME=%%b:%%c:%%d"
51 )
52 if "%ISO_DATE%"=="" goto BuildError
53 if "%ISO_TIME%"=="" goto BuildError
54
55 REM ///////////////////////////////////////////////////////////////////////////
56 REM // Build the binaries
57 REM ///////////////////////////////////////////////////////////////////////////
58 echo ---------------------------------------------------------------------
59 echo BEGIN BUILD
60 echo ---------------------------------------------------------------------
61 MSBuild.exe /property:Configuration=release /target:clean   "%~dp0\x264_launcher_MSVC2013.sln"
62 if not "%ERRORLEVEL%"=="0" goto BuildError
63 MSBuild.exe /property:Configuration=release /target:rebuild "%~dp0\x264_launcher_MSVC2013.sln"
64 if not "%ERRORLEVEL%"=="0" goto BuildError
65
66 REM ///////////////////////////////////////////////////////////////////////////
67 REM // Detect build number
68 REM ///////////////////////////////////////////////////////////////////////////
69 set "BUILD_NO="
70 for /F "tokens=2,*" %%s in (%~dp0\src\version.h) do (
71         if "%%s"=="VER_X264_BUILD" set "BUILD_NO=%%~t"
72 )
73 if "%BUILD_NO%"=="" goto BuildError
74
75 REM ///////////////////////////////////////////////////////////////////////////
76 REM // Copy base files
77 REM ///////////////////////////////////////////////////////////////////////////
78 echo ---------------------------------------------------------------------
79 echo BEGIN PACKAGING
80 echo ---------------------------------------------------------------------
81 set "PACK_PATH=%TMP%\~%RANDOM%%RANDOM%.tmp"
82 mkdir "%PACK_PATH%"
83 mkdir "%PACK_PATH%\imageformats"
84 mkdir "%PACK_PATH%\toolset\x86"
85 mkdir "%PACK_PATH%\toolset\x64"
86 mkdir "%PACK_PATH%\toolset\common"
87 mkdir "%PACK_PATH%\sources"
88 copy "%~dp0\bin\Win32\Release\x264_launcher.exe"    "%PACK_PATH%"
89 copy "%~dp0\bin\Win32\Release\MUtils32-?.dll"       "%PACK_PATH%"
90 copy "%~dp0\bin\Win32\Release\toolset\x86\*.exe"    "%PACK_PATH%\toolset\x86"
91 copy "%~dp0\bin\Win32\Release\toolset\x86\*.dll"    "%PACK_PATH%\toolset\x86"
92 copy "%~dp0\bin\Win32\Release\toolset\x64\*.exe"    "%PACK_PATH%\toolset\x64"
93 copy "%~dp0\bin\Win32\Release\toolset\x64\*.dll"    "%PACK_PATH%\toolset\x64"
94 copy "%~dp0\bin\Win32\Release\toolset\common\*.exe" "%PACK_PATH%\toolset\common"
95 copy "%~dp0\bin\Win32\Release\toolset\common\*.gpg" "%PACK_PATH%\toolset\common"
96 copy "%~dp0\etc\sources\*.xz"                       "%PACK_PATH%\sources"
97 copy "%~dp0\LICENSE.html"                           "%PACK_PATH%"
98 copy "%~dp0\*.txt"                                  "%PACK_PATH%"
99
100 REM ///////////////////////////////////////////////////////////////////////////
101 REM // Copy dependencies
102 REM ///////////////////////////////////////////////////////////////////////////
103 copy "%MSVC_PATH%\redist\x86\Microsoft.VC%TOOLS_VER%.CRT\*.dll"                     "%PACK_PATH%"
104 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtCore4.dll"            "%PACK_PATH%"
105 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtGui4.dll"             "%PACK_PATH%"
106 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtSvg4.dll"             "%PACK_PATH%"
107 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtXml4.dll"             "%PACK_PATH%"
108 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\bin\QtXml4.dll"             "%PACK_PATH%"
109 copy "%~dp0\..\Prerequisites\Qt4\v%TOOLS_VER%_xp\Shared\plugins\imageformats\*.dll" "%PACK_PATH%\imageformats"
110 del "%PACK_PATH%\imageformats\*d4.dll" 2> NUL
111
112 REM ///////////////////////////////////////////////////////////////////////////
113 REM // Generate Docs
114 REM ///////////////////////////////////////////////////////////////////////////
115 "%PDOC_PATH%\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"
116
117 REM ///////////////////////////////////////////////////////////////////////////
118 REM // Compress
119 REM ///////////////////////////////////////////////////////////////////////////
120 "%UPX3_PATH%\upx.exe" --brute "%PACK_PATH%\*.exe"
121 "%UPX3_PATH%\upx.exe" --best  "%PACK_PATH%\*.dll"
122
123 REM ///////////////////////////////////////////////////////////////////////////
124 REM // Attributes
125 REM ///////////////////////////////////////////////////////////////////////////
126 attrib +R "%PACK_PATH%\*.exe"
127 attrib +R "%PACK_PATH%\*.dll"
128 attrib +R "%PACK_PATH%\*.txt"
129 attrib +R "%PACK_PATH%\*.html"
130
131 REM ///////////////////////////////////////////////////////////////////////////
132 REM // Setup install parameters
133 REM ///////////////////////////////////////////////////////////////////////////
134 mkdir "%~dp0\out" 2> NUL
135 set "OUT_PATH=%~dp0\out\x264_launcher.%ISO_DATE%"
136 :GenerateOutfileName
137 if exist "%OUT_PATH%.exe" (
138         set "OUT_PATH=%OUT_PATH%.new"
139         goto GenerateOutfileName
140 )
141 if exist "%OUT_PATH%.sfx" (
142         set "OUT_PATH=%OUT_PATH%.new"
143         goto GenerateOutfileName
144 )
145 if exist "%OUT_PATH%.zip" (
146         set "OUT_PATH=%OUT_PATH%.new"
147         goto GenerateOutfileName
148 )
149
150 REM ///////////////////////////////////////////////////////////////////////////
151 REM // Create Tag
152 REM ///////////////////////////////////////////////////////////////////////////
153 echo Simple x264/x265 Launcher - graphical front-end for x264 and x265 > "%PACK_PATH%\BUILD_TAG.txt"
154 echo Copyright (C) 2004-2015 LoRd_MuldeR ^<MuldeR2@GMX.de^> >> "%PACK_PATH%\BUILD_TAG.txt"
155 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
156 echo Build #%BUILD_NO%, created on %ISO_DATE% at %ISO_TIME% >> "%PACK_PATH%\BUILD_TAG.txt"
157 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
158 echo. >> "%PACK_PATH%\BUILD_TAG.txt"
159 "%~dp0\etc\cat.exe" "%~dp0\etc\setup\build.nfo" >> "%PACK_PATH%\BUILD_TAG.txt"
160
161 REM ///////////////////////////////////////////////////////////////////////////
162 REM // Build the installer
163 REM ///////////////////////////////////////////////////////////////////////////
164 "%NSIS_PATH%\makensis.exe" "/DX264_UPX_PATH=%UPX3_PATH%" "/DX264_DATE=%ISO_DATE%" "/DX264_BUILD=%BUILD_NO%" "/DX264_OUTPUT_FILE=%OUT_PATH%.sfx" "/DX264_SOURCE_PATH=%PACK_PATH%"    "%~dp0\etc\setup\setup.nsi"
165 if not "%ERRORLEVEL%"=="0" goto BuildError
166
167 "%NSIS_PATH%\makensis.exe" "/DX264_UPX_PATH=%UPX3_PATH%" "/DX264_DATE=%ISO_DATE%" "/DX264_BUILD=%BUILD_NO%" "/DX264_OUTPUT_FILE=%OUT_PATH%.exe" "/DX264_SOURCE_FILE=%OUT_PATH%.sfx" "%~dp0\etc\setup\wrapper.nsi"
168 if not "%ERRORLEVEL%"=="0" goto BuildError
169
170 attrib +R "%OUT_PATH%.exe"
171 attrib +R "%OUT_PATH%.sfx"
172
173 REM ///////////////////////////////////////////////////////////////////////////
174 REM // Build ZIP package
175 REM ///////////////////////////////////////////////////////////////////////////
176 pushd "%PACK_PATH%"
177 "%~dp0\etc\zip.exe" -r -9 -z "%OUT_PATH%.zip" "*.*" < "%PACK_PATH%\BUILD_TAG.txt"
178 popd
179
180 if not "%ERRORLEVEL%"=="0" goto BuildError
181 attrib +R "%OUT_PATH%.zip"
182
183 REM ///////////////////////////////////////////////////////////////////////////
184 REM // Clean up
185 REM ///////////////////////////////////////////////////////////////////////////
186 rmdir /Q /S "%PACK_PATH%"
187
188 REM ///////////////////////////////////////////////////////////////////////////
189 REM // COMPLETE
190 REM ///////////////////////////////////////////////////////////////////////////
191 echo.
192 echo Build completed.
193 echo.
194 pause
195 goto:eof
196
197 REM ///////////////////////////////////////////////////////////////////////////
198 REM // FAILED
199 REM ///////////////////////////////////////////////////////////////////////////
200 :BuildError
201 echo.
202 echo Build has failed !!!
203 echo.
204 pause