OSDN Git Service

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