54eab2a013868eaab675bd20a229244e94c592f3
[vuplus_xbmc] / project / Win32BuildSetup / BuildSetup.bat
1 @ECHO OFF
2 SETLOCAL ENABLEDELAYEDEXPANSION
3 rem ----Usage----
4 rem BuildSetup [gl|dx] [clean|noclean]
5 rem vs2010 for compiling with visual studio 2010
6 rem gl for opengl build
7 rem dx for directx build (default)
8 rem clean to force a full rebuild
9 rem noclean to force a build without clean
10 rem noprompt to avoid all prompts
11 rem nomingwlibs to skip building all libs built with mingw
12 CLS
13 COLOR 1B
14 TITLE XBMC for Windows Build Script
15 rem ----PURPOSE----
16 rem - Create a working XBMC build with a single click
17 rem -------------------------------------------------------------
18 rem Config
19 rem If you get an error that Visual studio was not found, SET your path for VSNET main executable.
20 rem -------------------------------------------------------------
21 rem     CONFIG START
22 SET comp=vs2010
23 SET target=dx
24 SET buildmode=ask
25 SET promptlevel=prompt
26 SET buildmingwlibs=true
27 SET exitcode=0
28 SET useshell=rxvt
29 SET BRANCH=na
30 FOR %%b in (%1, %2, %3, %4, %5) DO (
31         IF %%b==vs2010 SET comp=vs2010
32         IF %%b==dx SET target=dx
33         IF %%b==gl SET target=gl
34         IF %%b==clean SET buildmode=clean
35         IF %%b==noclean SET buildmode=noclean
36         IF %%b==noprompt SET promptlevel=noprompt
37         IF %%b==nomingwlibs SET buildmingwlibs=false
38         IF %%b==sh SET useshell=sh
39 )
40
41 SET buildconfig=Release (DirectX)
42 IF %target%==gl SET buildconfig=Release (OpenGL)
43
44 IF %comp%==vs2010 (
45         REM look for MSBuild.exe in .NET Framework 4.x
46         FOR /F "tokens=3* delims=       " %%A IN ('REG QUERY HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0 /v MSBuildToolsPath') DO SET NET=%%AMSBuild.exe
47         IF NOT EXIST "!NET!" (
48                 FOR /F "tokens=3* delims= " %%A IN ('REG QUERY HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0 /v MSBuildToolsPath') DO SET NET=%%AMSBuild.exe
49         )
50
51         IF EXIST "!NET!" (
52                 set msbuildemitsolution=1
53                 set OPTS_EXE="..\VS2010Express\XBMC for Windows.sln" /t:Build /p:Configuration="%buildconfig%"
54                 set CLEAN_EXE="..\VS2010Express\XBMC for Windows.sln" /t:Clean /p:Configuration="%buildconfig%"
55         ) ELSE (
56                 IF EXIST "%VS100COMNTOOLS%\..\IDE\devenv.com" (
57                         set NET="%VS100COMNTOOLS%\..\IDE\devenv.com"
58                 ) ELSE IF EXIST "%VS100COMNTOOLS%\..\IDE\devenv.exe" (
59                         set NET="%VS100COMNTOOLS%\..\IDE\devenv.exe"
60                 ) ELSE IF "%VS100COMNTOOLS%"=="" (
61                         set NET="%ProgramFiles%\Microsoft Visual Studio 10.0\Common7\IDE\VCExpress.exe"
62                 ) ELSE IF EXIST "%VS100COMNTOOLS%\..\IDE\VCExpress.exe" (
63                         set NET="%VS100COMNTOOLS%\..\IDE\VCExpress.exe"
64                 )
65
66                 set OPTS_EXE="..\VS2010Express\XBMC for Windows.sln" /build "%buildconfig%"
67                 set CLEAN_EXE="..\VS2010Express\XBMC for Windows.sln" /clean "%buildconfig%"
68         )
69 )
70
71   IF NOT EXIST %NET% (
72      set DIETEXT=Visual Studio .NET 2010 Express was not found.
73          goto DIE
74   )
75   
76   set EXE= "..\VS2010Express\XBMC\%buildconfig%\XBMC.exe"
77   set PDB= "..\VS2010Express\XBMC\%buildconfig%\XBMC.pdb"
78   
79   :: sets the BRANCH env var
80   call getbranch.bat
81
82   rem   CONFIG END
83   rem -------------------------------------------------------------
84
85   echo                         :                                                  
86   echo                        :::                                                 
87   echo                        ::::                                                
88   echo                        ::::                                                
89   echo    :::::::       :::::::::::::::::        ::::::      ::::::        :::::::
90   echo    :::::::::   ::::::::::::::::::::     ::::::::::  ::::::::::    :::::::::
91   echo     ::::::::: ::::::::::::::::::::::   ::::::::::::::::::::::::  ::::::::: 
92   echo          :::::::::     :::      ::::: :::::    ::::::::    :::: :::::      
93   echo           ::::::      ::::       :::: ::::      :::::       :::::::        
94   echo           :::::       ::::        :::::::       :::::       ::::::         
95   echo           :::::       :::         ::::::         :::        ::::::         
96   echo           ::::        :::         ::::::        ::::        ::::::         
97   echo           ::::        :::        :::::::        ::::        ::::::         
98   echo          :::::        ::::       :::::::        ::::        ::::::         
99   echo         :::::::       ::::      ::::::::        :::         :::::::        
100   echo     :::::::::::::::    :::::  ::::: :::         :::         :::::::::      
101   echo  :::::::::  :::::::::  :::::::::::  :::         :::         ::: :::::::::  
102   echo  ::::::::    :::::::::  :::::::::   :::         :::         :::  ::::::::  
103   echo ::::::         :::::::    :::::     :            ::          ::    ::::::  
104   goto EXE_COMPILE
105
106 :EXE_COMPILE
107   IF EXIST buildlog.html del buildlog.html /q
108   IF %buildmode%==clean goto COMPILE_EXE
109   IF %buildmode%==noclean goto COMPILE_NO_CLEAN_EXE
110   rem ---------------------------------------------
111   rem   check for existing exe
112   rem ---------------------------------------------
113   
114   IF EXIST %EXE% (
115     goto EXE_EXIST
116   )
117   goto COMPILE_EXE
118
119 :EXE_EXIST
120   IF %promptlevel%==noprompt goto COMPILE_EXE
121   ECHO ------------------------------------------------------------
122   ECHO Found a previous Compiled WIN32 EXE!
123   ECHO [1] a NEW EXE will be compiled for the BUILD_WIN32
124   ECHO [2] existing EXE will be updated (quick mode compile) for the BUILD_WIN32
125   ECHO ------------------------------------------------------------
126   set /P XBMC_COMPILE_ANSWER=Compile a new EXE? [1/2]:
127   if /I %XBMC_COMPILE_ANSWER% EQU 1 goto COMPILE_EXE
128   if /I %XBMC_COMPILE_ANSWER% EQU 2 goto COMPILE_NO_CLEAN_EXE
129   
130 :COMPILE_EXE
131   ECHO Wait while preparing the build.
132   ECHO ------------------------------------------------------------
133   ECHO Cleaning Solution...
134   %NET% %CLEAN_EXE%
135   ECHO Compiling XBMC branch %BRANCH%...
136   %NET% %OPTS_EXE%
137   IF %errorlevel%==1 (
138         set DIETEXT="XBMC.EXE failed to build!  See %CD%\..\vs2010express\XBMC\%buildconfig%\objs\XBMC.log"
139         IF %promptlevel%==noprompt (
140                 type "%CD%\..\vs2010express\XBMC\%buildconfig%\objs\XBMC.log"
141         )
142         goto DIE
143   )
144   ECHO Done!
145   ECHO ------------------------------------------------------------
146   set buildmode=clean
147   GOTO MAKE_BUILD_EXE
148   
149 :COMPILE_NO_CLEAN_EXE
150   ECHO Wait while preparing the build.
151   ECHO ------------------------------------------------------------
152   ECHO Compiling XBMC branch %BRANCH%...
153   %NET% %OPTS_EXE%
154   IF %errorlevel%==1 (
155         set DIETEXT="XBMC.EXE failed to build!  See %CD%\..\vs2010express\XBMC\%buildconfig%\objs\XBMC.log"
156         IF %promptlevel%==noprompt (
157                 type "%CD%\..\vs2010express\XBMC\%buildconfig%\objs\XBMC.log"
158         )
159         goto DIE
160   )
161   ECHO Done!
162   ECHO ------------------------------------------------------------
163   GOTO MAKE_BUILD_EXE
164
165 :MAKE_BUILD_EXE
166   IF %buildmingwlibs%==true (
167     ECHO Compiling mingw libs
168     ECHO bla>noprompt
169     IF EXIST errormingw del errormingw > NUL
170         IF %buildmode%==clean (
171           ECHO bla>makeclean
172         )
173     rem only use sh to please jenkins
174     IF %useshell%==sh (
175       call buildmingwlibs.bat sh
176     ) ELSE (
177       call buildmingwlibs.bat
178     )
179     IF EXIST errormingw (
180         set DIETEXT="failed to build mingw libs"
181         goto DIE
182     )
183   )
184   
185   ECHO Copying files...
186   IF EXIST BUILD_WIN32 rmdir BUILD_WIN32 /S /Q
187   rem Add files to exclude.txt that should not be included in the installer
188   
189   Echo Thumbs.db>>exclude.txt
190   Echo Desktop.ini>>exclude.txt
191   Echo dsstdfx.bin>>exclude.txt
192   Echo exclude.txt>>exclude.txt
193   Echo xbmc.log>>exclude.txt
194   Echo xbmc.old.log>>exclude.txt
195   rem Exclude userdata files
196   Echo userdata\advancedsettings.xml>>exclude.txt
197   Echo userdata\guisettings.xml>>exclude.txt
198   Echo userdata\mediasources.xml>>exclude.txt
199   Echo userdata\passwords.xml>>exclude.txt
200   Echo userdata\profiles.xml>>exclude.txt
201   Echo userdata\sources.xml>>exclude.txt
202   Echo userdata\upnpserver.xml>>exclude.txt
203   rem Exclude userdata folders
204   Echo userdata\addon_data\>>exclude.txt
205   Echo userdata\cache\>>exclude.txt
206   Echo userdata\database\>>exclude.txt
207   Echo userdata\playlists\>>exclude.txt
208   Echo userdata\thumbnails\>>exclude.txt
209   rem Exclude non Windows addons
210   Echo addons\repository.pvr-android.xbmc.org\>>exclude.txt
211   Echo addons\repository.pvr-ios.xbmc.org\>>exclude.txt
212   Echo addons\repository.pvr-osx32.xbmc.org\>>exclude.txt
213   Echo addons\repository.pvr-osx64.xbmc.org\>>exclude.txt
214   Echo addons\screensaver.rsxs.euphoria\>>exclude.txt
215   Echo addons\screensaver.rsxs.plasma\>>exclude.txt
216   Echo addons\screensaver.rsxs.solarwinds\>>exclude.txt
217   Echo addons\visualization.fishbmc\>>exclude.txt
218   Echo addons\visualization.projectm\>>exclude.txt
219   Echo addons\visualization.glspectrum\>>exclude.txt
220   rem Exclude skins if not present
221   IF NOT EXIST  addons\skin.touched\addon.xml (
222     Echo addons\skin.touched\>>exclude.txt
223   )
224   rem other platform stuff
225   Echo lib-osx>>exclude.txt
226   Echo players\mplayer>>exclude.txt
227   Echo FileZilla Server.xml>>exclude.txt
228   Echo asound.conf>>exclude.txt
229   Echo voicemasks.xml>>exclude.txt
230   Echo Lircmap.xml>>exclude.txt
231   
232   md BUILD_WIN32\Xbmc
233
234   xcopy %EXE% BUILD_WIN32\Xbmc > NUL
235   xcopy ..\..\userdata BUILD_WIN32\Xbmc\userdata /E /Q /I /Y /EXCLUDE:exclude.txt > NUL
236   copy ..\..\copying.txt BUILD_WIN32\Xbmc > NUL
237   copy ..\..\LICENSE.GPL BUILD_WIN32\Xbmc > NUL
238   copy ..\..\known_issues.txt BUILD_WIN32\Xbmc > NUL
239   xcopy dependencies\*.* BUILD_WIN32\Xbmc /Q /I /Y /EXCLUDE:exclude.txt  > NUL
240   
241   xcopy ..\..\language BUILD_WIN32\Xbmc\language /E /Q /I /Y /EXCLUDE:exclude.txt  > NUL
242   xcopy ..\..\addons BUILD_WIN32\Xbmc\addons /E /Q /I /Y /EXCLUDE:exclude.txt > NUL
243   xcopy ..\..\system BUILD_WIN32\Xbmc\system /E /Q /I /Y /EXCLUDE:exclude.txt  > NUL
244   xcopy ..\..\media BUILD_WIN32\Xbmc\media /E /Q /I /Y /EXCLUDE:exclude.txt  > NUL
245   xcopy ..\..\sounds BUILD_WIN32\Xbmc\sounds /E /Q /I /Y /EXCLUDE:exclude.txt  > NUL
246   
247   ECHO ------------------------------------------------------------
248   call buildpvraddons.bat %NET%
249     
250   IF EXIST error.log del error.log > NUL
251   SET build_path=%CD%
252   ECHO ------------------------------------------------------------
253   ECHO Building Confluence Skin...
254   cd ..\..\addons\skin.confluence
255   call build.bat > NUL
256   cd %build_path%
257   
258   IF EXIST  ..\..\addons\skin.touched\build.bat (
259     ECHO Building Touched Skin...
260     cd ..\..\addons\skin.touched
261     call build.bat > NUL
262     cd %build_path%
263   )
264   
265   rem restore color and title, some scripts mess these up
266   COLOR 1B
267   TITLE XBMC for Windows Build Script
268
269   IF EXIST exclude.txt del exclude.txt  > NUL
270   del /s /q /f BUILD_WIN32\Xbmc\*.so  > NUL
271   del /s /q /f BUILD_WIN32\Xbmc\*.h  > NUL
272   del /s /q /f BUILD_WIN32\Xbmc\*.cpp  > NUL
273   del /s /q /f BUILD_WIN32\Xbmc\*.exp  > NUL
274   del /s /q /f BUILD_WIN32\Xbmc\*.lib  > NUL
275   
276   ECHO ------------------------------------------------------------
277   ECHO Build Succeeded!
278   GOTO NSIS_EXE
279
280 :NSIS_EXE
281   ECHO ------------------------------------------------------------
282   ECHO Generating installer includes...
283   call genNsisIncludes.bat
284   ECHO ------------------------------------------------------------
285   call getdeploydependencies.bat
286   CALL extract_git_rev.bat > NUL
287   SET XBMC_SETUPFILE=XBMCSetup-%GIT_REV%-%BRANCH%.exe
288   SET XBMC_PDBFILE=XBMCSetup-%GIT_REV%-%BRANCH%.pdb
289   ECHO Creating installer %XBMC_SETUPFILE%...
290   IF EXIST %XBMC_SETUPFILE% del %XBMC_SETUPFILE% > NUL
291   rem get path to makensis.exe from registry, first try tab delim
292   FOR /F "tokens=2* delims=     " %%A IN ('REG QUERY "HKLM\Software\NSIS" /ve') DO SET NSISExePath=%%B
293
294   IF NOT EXIST "%NSISExePath%" (
295     rem try with space delim instead of tab
296     FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\Software\NSIS" /ve') DO SET NSISExePath=%%B
297   )
298       
299   IF NOT EXIST "%NSISExePath%" (
300     rem fails on localized windows (Default) becomes (Par D�faut)
301     FOR /F "tokens=3* delims=   " %%A IN ('REG QUERY "HKLM\Software\NSIS" /ve') DO SET NSISExePath=%%B
302   )
303
304   IF NOT EXIST "%NSISExePath%" (
305     FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "HKLM\Software\NSIS" /ve') DO SET NSISExePath=%%B
306   )
307   
308   rem proper x64 registry checks
309   IF NOT EXIST "%NSISExePath%" (
310     ECHO using x64 registry entries
311     FOR /F "tokens=2* delims=   " %%A IN ('REG QUERY "HKLM\Software\Wow6432Node\NSIS" /ve') DO SET NSISExePath=%%B
312   )
313   IF NOT EXIST "%NSISExePath%" (
314     rem try with space delim instead of tab
315     FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\Software\Wow6432Node\NSIS" /ve') DO SET NSISExePath=%%B
316   )
317   IF NOT EXIST "%NSISExePath%" (
318     rem on win 7 x64, the previous fails
319     FOR /F "tokens=3* delims=   " %%A IN ('REG QUERY "HKLM\Software\Wow6432Node\NSIS" /ve') DO SET NSISExePath=%%B
320   )
321   IF NOT EXIST "%NSISExePath%" (
322     rem try with space delim instead of tab
323     FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "HKLM\Software\Wow6432Node\NSIS" /ve') DO SET NSISExePath=%%B
324   )
325
326   SET NSISExe=%NSISExePath%\makensis.exe
327   "%NSISExe%" /V1 /X"SetCompressor /FINAL lzma" /Dxbmc_root="%CD%\BUILD_WIN32" /Dxbmc_revision="%GIT_REV%" /Dxbmc_target="%target%" /Dxbmc_branch="%BRANCH%" "XBMC for Windows.nsi"
328   IF NOT EXIST "%XBMC_SETUPFILE%" (
329           set DIETEXT=Failed to create %XBMC_SETUPFILE%. NSIS installed?
330           goto DIE
331   )
332   copy %PDB% %XBMC_PDBFILE% > nul
333   ECHO ------------------------------------------------------------
334   ECHO Done!
335   ECHO Setup is located at %CD%\%XBMC_SETUPFILE%
336   ECHO ------------------------------------------------------------
337   GOTO VIEWLOG_EXE
338   
339 :DIE
340   ECHO ------------------------------------------------------------
341   ECHO !-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-
342   ECHO    ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR
343   ECHO !-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-
344   set DIETEXT=ERROR: %DIETEXT%
345   echo %DIETEXT%
346   SET exitcode=1
347   ECHO ------------------------------------------------------------
348   GOTO END
349
350 :VIEWLOG_EXE
351   SET log="%CD%\..\vs2010express\XBMC\%buildconfig%\objs\XBMC.log"
352   IF NOT EXIST %log% goto END
353   
354   copy %log% ./buildlog.html > NUL
355
356   IF %promptlevel%==noprompt (
357   goto END
358   )
359
360   set /P XBMC_BUILD_ANSWER=View the build log in your HTML browser? [y/n]
361   if /I %XBMC_BUILD_ANSWER% NEQ y goto END
362   
363   SET log="%CD%\..\vs2010express\XBMC\%buildconfig%\objs\" XBMC.log
364   
365   start /D%log%
366   goto END
367
368 :END
369   IF %promptlevel% NEQ noprompt (
370   ECHO Press any key to exit...
371   pause > NUL
372   )
373   EXIT /B %exitcode%