Merge pull request #4896 from sportica/mac_fix_space
[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 as they're copied by their own script
221   Echo addons\skin.touched\>>exclude.txt
222   Echo addons\skin.confluence\>>exclude.txt
223   rem other platform stuff
224   Echo lib-osx>>exclude.txt
225   Echo players\mplayer>>exclude.txt
226   Echo FileZilla Server.xml>>exclude.txt
227   Echo asound.conf>>exclude.txt
228   Echo voicemasks.xml>>exclude.txt
229   Echo Lircmap.xml>>exclude.txt
230   
231   md BUILD_WIN32\Xbmc
232
233   xcopy %EXE% BUILD_WIN32\Xbmc > NUL
234   xcopy ..\..\userdata BUILD_WIN32\Xbmc\userdata /E /Q /I /Y /EXCLUDE:exclude.txt > NUL
235   copy ..\..\copying.txt BUILD_WIN32\Xbmc > NUL
236   copy ..\..\LICENSE.GPL BUILD_WIN32\Xbmc > NUL
237   copy ..\..\known_issues.txt BUILD_WIN32\Xbmc > NUL
238   xcopy dependencies\*.* BUILD_WIN32\Xbmc /Q /I /Y /EXCLUDE:exclude.txt  > NUL
239   
240   xcopy ..\..\language BUILD_WIN32\Xbmc\language /E /Q /I /Y /EXCLUDE:exclude.txt  > NUL
241   xcopy ..\..\addons BUILD_WIN32\Xbmc\addons /E /Q /I /Y /EXCLUDE:exclude.txt > NUL
242   xcopy ..\..\system BUILD_WIN32\Xbmc\system /E /Q /I /Y /EXCLUDE:exclude.txt  > NUL
243   xcopy ..\..\media BUILD_WIN32\Xbmc\media /E /Q /I /Y /EXCLUDE:exclude.txt  > NUL
244   xcopy ..\..\sounds BUILD_WIN32\Xbmc\sounds /E /Q /I /Y /EXCLUDE:exclude.txt  > NUL
245   
246   ECHO ------------------------------------------------------------
247   call buildpvraddons.bat %NET%
248   IF %errorlevel%==1 (
249     set DIETEXT="failed to build pvr addons"
250     goto DIE
251   )
252     
253   IF EXIST error.log del error.log > NUL
254   SET build_path=%CD%
255   ECHO ------------------------------------------------------------
256   ECHO Building Confluence Skin...
257   cd ..\..\addons\skin.confluence
258   call build.bat > NUL
259   cd %build_path%
260   
261   IF EXIST  ..\..\addons\skin.touched\build.bat (
262     ECHO Building Touched Skin...
263     cd ..\..\addons\skin.touched
264     call build.bat > NUL
265     cd %build_path%
266   )
267   
268   rem restore color and title, some scripts mess these up
269   COLOR 1B
270   TITLE XBMC for Windows Build Script
271
272   IF EXIST exclude.txt del exclude.txt  > NUL
273   del /s /q /f BUILD_WIN32\Xbmc\*.so  > NUL
274   del /s /q /f BUILD_WIN32\Xbmc\*.h  > NUL
275   del /s /q /f BUILD_WIN32\Xbmc\*.cpp  > NUL
276   del /s /q /f BUILD_WIN32\Xbmc\*.exp  > NUL
277   del /s /q /f BUILD_WIN32\Xbmc\*.lib  > NUL
278   
279   ECHO ------------------------------------------------------------
280   ECHO Build Succeeded!
281   GOTO NSIS_EXE
282
283 :NSIS_EXE
284   ECHO ------------------------------------------------------------
285   ECHO Generating installer includes...
286   call genNsisIncludes.bat
287   ECHO ------------------------------------------------------------
288   call getdeploydependencies.bat
289   CALL extract_git_rev.bat > NUL
290   SET XBMC_SETUPFILE=XBMCSetup-%GIT_REV%-%BRANCH%.exe
291   SET XBMC_PDBFILE=XBMCSetup-%GIT_REV%-%BRANCH%.pdb
292   ECHO Creating installer %XBMC_SETUPFILE%...
293   IF EXIST %XBMC_SETUPFILE% del %XBMC_SETUPFILE% > NUL
294   rem get path to makensis.exe from registry, first try tab delim
295   FOR /F "tokens=2* delims=     " %%A IN ('REG QUERY "HKLM\Software\NSIS" /ve') DO SET NSISExePath=%%B
296
297   IF NOT EXIST "%NSISExePath%" (
298     rem try with space delim instead of tab
299     FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\Software\NSIS" /ve') DO SET NSISExePath=%%B
300   )
301       
302   IF NOT EXIST "%NSISExePath%" (
303     rem fails on localized windows (Default) becomes (Par D�faut)
304     FOR /F "tokens=3* delims=   " %%A IN ('REG QUERY "HKLM\Software\NSIS" /ve') DO SET NSISExePath=%%B
305   )
306
307   IF NOT EXIST "%NSISExePath%" (
308     FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "HKLM\Software\NSIS" /ve') DO SET NSISExePath=%%B
309   )
310   
311   rem proper x64 registry checks
312   IF NOT EXIST "%NSISExePath%" (
313     ECHO using x64 registry entries
314     FOR /F "tokens=2* delims=   " %%A IN ('REG QUERY "HKLM\Software\Wow6432Node\NSIS" /ve') DO SET NSISExePath=%%B
315   )
316   IF NOT EXIST "%NSISExePath%" (
317     rem try with space delim instead of tab
318     FOR /F "tokens=2* delims= " %%A IN ('REG QUERY "HKLM\Software\Wow6432Node\NSIS" /ve') DO SET NSISExePath=%%B
319   )
320   IF NOT EXIST "%NSISExePath%" (
321     rem on win 7 x64, the previous fails
322     FOR /F "tokens=3* delims=   " %%A IN ('REG QUERY "HKLM\Software\Wow6432Node\NSIS" /ve') DO SET NSISExePath=%%B
323   )
324   IF NOT EXIST "%NSISExePath%" (
325     rem try with space delim instead of tab
326     FOR /F "tokens=3* delims= " %%A IN ('REG QUERY "HKLM\Software\Wow6432Node\NSIS" /ve') DO SET NSISExePath=%%B
327   )
328
329   SET NSISExe=%NSISExePath%\makensis.exe
330   "%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"
331   IF NOT EXIST "%XBMC_SETUPFILE%" (
332           set DIETEXT=Failed to create %XBMC_SETUPFILE%. NSIS installed?
333           goto DIE
334   )
335   copy %PDB% %XBMC_PDBFILE% > nul
336   ECHO ------------------------------------------------------------
337   ECHO Done!
338   ECHO Setup is located at %CD%\%XBMC_SETUPFILE%
339   ECHO ------------------------------------------------------------
340   GOTO VIEWLOG_EXE
341   
342 :DIE
343   ECHO ------------------------------------------------------------
344   ECHO !-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-
345   ECHO    ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR ERROR
346   ECHO !-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-!-
347   set DIETEXT=ERROR: %DIETEXT%
348   echo %DIETEXT%
349   SET exitcode=1
350   ECHO ------------------------------------------------------------
351   GOTO END
352
353 :VIEWLOG_EXE
354   SET log="%CD%\..\vs2010express\XBMC\%buildconfig%\objs\XBMC.log"
355   IF NOT EXIST %log% goto END
356   
357   copy %log% ./buildlog.html > NUL
358
359   IF %promptlevel%==noprompt (
360   goto END
361   )
362
363   set /P XBMC_BUILD_ANSWER=View the build log in your HTML browser? [y/n]
364   if /I %XBMC_BUILD_ANSWER% NEQ y goto END
365   
366   SET log="%CD%\..\vs2010express\XBMC\%buildconfig%\objs\" XBMC.log
367   
368   start /D%log%
369   goto END
370
371 :END
372   IF %promptlevel% NEQ noprompt (
373   ECHO Press any key to exit...
374   pause > NUL
375   )
376   EXIT /B %exitcode%