1::------------------------------------------------------------------------------------- 2:: LICENSE ------------------------------------------------------------------------- 3::------------------------------------------------------------------------------------- 4:: This Windows Batchscript is for setup a compiler environment for building ffmpeg and other media tools under Windows. 5:: 6:: Copyright (C) 2013 jb_alvarado 7:: 8:: This program is free software: you can redistribute it and/or modify 9:: it under the terms of the GNU General Public License as published by 10:: the Free Software Foundation, either version 3 of the License, or 11:: (at your option) any later version. 12:: 13:: This program is distributed in the hope that it will be useful, 14:: but WITHOUT ANY WARRANTY; without even the implied warranty of 15:: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16:: GNU General Public License for more details. 17:: 18:: You should have received a copy of the GNU General Public License 19:: along with this program. If not, see <http://www.gnu.org/licenses/>. 20::------------------------------------------------------------------------------------- 21 22@echo off 23title msys2 24 25PUSHD %~dp0\..\..\.. 26SET WORKSPACE=%CD% 27POPD 28 29set msysver=20161025 30set msys2=msys64 31set instdir=%WORKSPACE%\project\BuildDependencies 32set msyspackages=diffutils gcc make patch perl tar yasm 33set gaspreprocurl=https://github.com/FFmpeg/gas-preprocessor/archive/master.tar.gz 34set usemirror=yes 35set opt=mintty 36 37:: if KODI_MIRROR is not set externally to this script, set it to the default mirror URL 38if "%KODI_MIRROR%"=="" set KODI_MIRROR=http://mirrors.kodi.tv 39if "%usemirror%"=="yes" ( 40 echo ------------------------------------------------------------------------------- 41 echo. Downloading will be performed from mirror %KODI_MIRROR% 42 echo ------------------------------------------------------------------------------- 43 set MSYS_MIRROR=%KODI_MIRROR%/build-deps/win32/msys2 44) 45 46set downloaddir=%instdir%\downloads2 47set unpack_exe=%instdir%\..\Win32BuildSetup\tools\7z\7za.exe 48 49for %%b in (%*) do ( 50 if %%b==sh (set opt=sh) 51) 52 53:: use 32bit msys2 on x86 machine 54if %PROCESSOR_ARCHITECTURE%=="x86" set msys2=msys32 55if %msys2%==msys32 (set arch=i686) else (set arch=x86_64) 56set msysfile=msys2-base-%arch%-%msysver%.tar.xz 57if %opt%==mintty ( 58 set sh=%instdir%\%msys2%\usr\bin\mintty.exe -d -i /msys2.ico /usr/bin/bash 59) else ( 60 set sh=%instdir%\%msys2%\usr\bin\sh.exe 61) 62 63::------------------------------------------------------------------ 64::download and install basic msys2 system: 65::------------------------------------------------------------------ 66if exist "%instdir%\%msys2%\msys2_shell.cmd" GOTO minttySettings 67 if not exist %downloaddir% mkdir %downloaddir% 68 69:download 70if exist "%downloaddir%\%msysfile%" ( 71 setlocal EnableDelayedExpansion 72 for /F "tokens=*" %%A in ("%downloaddir%\%msysfile%") do set fileSize=%%~zA 73 if !fileSize!==0 del %downloaddir%\%msysfile% 74 endlocal 75 ) 76 77if exist "%downloaddir%\%msysfile%" GOTO unpack 78 echo ------------------------------------------------------------------------------- 79 echo.- Download msys2 basic system (Kodi mirrors: %usemirror%) 80 echo ------------------------------------------------------------------------------- 81 82 set msysurl=http://sourceforge.net/projects/msys2/files/Base/%arch%/%msysfile%/download 83 if %usemirror%==yes ( 84 ::download msys2 from our mirror 85 set msysurl=%MSYS_MIRROR%/%msysfile% 86 ) 87 %instdir%\bin\wget --tries=20 --retry-connrefused --waitretry=2 --no-check-certificate -c -O %downloaddir%\%msysfile% %msysurl% 88 if errorlevel == 1 ( 89 if exist "%downloaddir%\%msysfile%" del %downloaddir%\%msysfile% 90 if %usemirror%==yes ( 91 set usemirror=no 92 goto download 93 ) 94 echo ERROR: Unable to download msys2! 95 exit /B 1 96 ) 97 98:unpack 99if exist "%downloaddir%\%msysfile%" ( 100 echo ------------------------------------------------------------------------------- 101 echo.- Installing msys2 basic system 102 echo ------------------------------------------------------------------------------- 103 %unpack_exe% x %downloaddir%\%msysfile% -so 2>NUL | %unpack_exe% x -aoa -si -ttar -o%instdir% >NUL 2>NUL 104 ) 105 106if not exist %instdir%\%msys2%\usr\bin\msys-2.0.dll ( 107 echo ------------------------------------------------------------------------------- 108 echo.- Installing msys2 basic system failed, 109 echo ------------------------------------------------------------------------------- 110 exit /B 1 111 ) 112 113:minttySettings 114if exist "%instdir%\%msys2%\home\%USERNAME%\.minttyrc" GOTO updatemirrors 115if not exist "%instdir%\%msys2%\home\%USERNAME%" mkdir "%instdir%\%msys2%\home\%USERNAME%" 116 ( 117 echo.BoldAsFont=no 118 echo.BackgroundColour=57,57,57 119 echo.ForegroundColour=221,221,221 120 echo.Transparency=medium 121 echo.FontHeight=^9 122 echo.FontSmoothing=full 123 echo.AllowBlinking=yes 124 echo.Columns=120 125 echo.Rows=30 126 echo.Term=xterm-256color 127 echo.CursorType=block 128 echo.ClicksPlaceCursor=yes 129 echo.Black=38,39,41 130 echo.Red=249,38,113 131 echo.Green=166,226,46 132 echo.Yellow=253,151,31 133 echo.Blue=102,217,239 134 echo.Magenta=158,111,254 135 echo.Cyan=94,113,117 136 echo.White=248,248,242 137 echo.BoldBlack=85,68,68 138 echo.BoldRed=249,38,113 139 echo.BoldGreen=166,226,46 140 echo.BoldYellow=253,151,31 141 echo.BoldBlue=102,217,239 142 echo.BoldMagenta=158,111,254 143 echo.BoldCyan=163,186,191 144 echo.BoldWhite=248,248,242 145 )>>"%instdir%\%msys2%\home\%USERNAME%\.minttyrc" 146 147:updatemirrors 148if not "%usemirror%"=="yes" GOTO rebase 149 echo.------------------------------------------------------------------------------- 150 echo.update pacman mirrors 151 echo.------------------------------------------------------------------------------- 152 setlocal EnableDelayedExpansion 153 154 for %%f in (msys,mingw32,mingw64) do ( 155 set filename=%instdir%\%msys2%\etc\pacman.d\mirrorlist.%%f 156 set oldfile=!filename!.old 157 if not exist !oldfile! if exist !filename! ( 158 set mirror=%MSYS_MIRROR%/repos/%%f 159 if %%f==msys set mirror=!mirror!2/$arch 160 move !filename! !oldfile!>nul 161 for /F "usebackq delims=" %%a in (!oldfile!) do ( 162 echo %%a | find /i "server = http://repo.msys2.org/">nul && ( 163 echo.Server = !mirror! 164 )>>!filename! 165 echo %%a>>!filename! 166 ) 167 ) 168 ) 169 endlocal 170 171:rebase 172if %msys2%==msys32 ( 173 echo.------------------------------------------------------------------------------- 174 echo.rebase msys32 system 175 echo.------------------------------------------------------------------------------- 176 call %instdir%\msys32\autorebase.bat 177 ) 178 179:preparedirs 180if not exist %instdir%\build mkdir %instdir%\build 181if not exist %instdir%\downloads2 mkdir %instdir%\downloads2 182if not exist %instdir%\locals mkdir %instdir%\locals 183if not exist %instdir%\locals\win32 mkdir %instdir%\locals\win32 184if not exist %instdir%\locals\x64 mkdir %instdir%\locals\x64 185 186if not exist %instdir%\locals\win32\share ( 187 echo.------------------------------------------------------------------------------- 188 echo.create local win32 folders 189 echo.------------------------------------------------------------------------------- 190 mkdir %instdir%\locals\win32\bin 191 mkdir %instdir%\locals\win32\etc 192 mkdir %instdir%\locals\win32\include 193 mkdir %instdir%\locals\win32\lib 194 mkdir %instdir%\locals\win32\lib\pkgconfig 195 mkdir %instdir%\locals\win32\share 196 ) 197 198if not exist %instdir%\locals\x64\share ( 199 echo.------------------------------------------------------------------------------- 200 echo.create local x64 folders 201 echo.------------------------------------------------------------------------------- 202 mkdir %instdir%\locals\x64\bin 203 mkdir %instdir%\locals\x64\etc 204 mkdir %instdir%\locals\x64\include 205 mkdir %instdir%\locals\x64\lib 206 mkdir %instdir%\locals\x64\lib\pkgconfig 207 mkdir %instdir%\locals\x64\share 208 ) 209 210if not exist %instdir%\%msys2%\etc\fstab. GOTO writeFstab 211for /f "tokens=2 delims=/" %%a in ('findstr /i xbmc %instdir%\%msys2%\etc\fstab.') do set searchRes=%%a 212if "%searchRes%"=="xbmc" GOTO installbase 213 214:writeFstab 215echo ------------------------------------------------------------------------------- 216echo.- write fstab mount file 217echo ------------------------------------------------------------------------------- 218set cygdrive=no 219if exist %instdir%\%msys2%\etc\fstab. ( 220 for /f %%b in ('findstr /i binary %instdir%\%msys2%\etc\fstab.') do set cygdrive=yes 221 ) 222if "%cygdrive%"=="no" echo.none / cygdrive binary,posix=0,noacl,user 0 ^0>>%instdir%\%msys2%\etc\fstab. 223( 224 echo. 225 echo.%instdir%\build\ /build 226 echo.%instdir%\downloads\ /downloads 227 echo.%instdir%\locals\win32\ /local32 228 echo.%instdir%\locals\x64\ /local64 229 echo.%instdir%\%msys2%\mingw32\ /mingw32 230 echo.%instdir%\%msys2%\mingw64\ /mingw64 231 echo.%instdir%\downloads2\ /var/cache/pacman/pkg 232 echo.%instdir%\win32\ /depends/win32 233 echo.%instdir%\x64\ /depends/x64 234 echo.%instdir%\win10-arm\ /depends/win10-arm 235 echo.%instdir%\win10-win32\ /depends/win10-win32 236 echo.%instdir%\win10-x64\ /depends/win10-x64 237 echo.%instdir%\..\..\ /xbmc 238)>>%instdir%\%msys2%\etc\fstab. 239 240:installbase 241if exist "%instdir%\%msys2%\etc\pac-base-old.pk" del "%instdir%\%msys2%\etc\pac-base-old.pk" 242if exist "%instdir%\%msys2%\etc\pac-base-new.pk" ren "%instdir%\%msys2%\etc\pac-base-new.pk" pac-base-old.pk 243 244for %%i in (%msyspackages%) do echo.%%i>>%instdir%\%msys2%\etc\pac-base-new.pk 245 246if exist %instdir%\%msys2%\usr\bin\make.exe GOTO rebase2 247 echo.------------------------------------------------------------------------------- 248 echo.install msys2 base system 249 echo.------------------------------------------------------------------------------- 250 if exist %instdir%\pacman.sh del %instdir%\pacman.sh 251 ( 252 echo.echo -ne "\033]0;install base system\007" 253 echo.pacman --noconfirm -S $(cat /etc/pac-base-new.pk ^| sed -e 's#\\##'^) 254 echo.sleep ^3 255 echo.exit 256 )>>%instdir%\pacman.sh 257 %sh% --login %instdir%\pacman.sh & 258 del %instdir%\pacman.sh 259 260 for %%i in (%instdir%\%msys2%\usr\ssl\cert.pem) do ( 261 if %%~zi==0 ( 262 echo.update-ca-trust>>cert.sh 263 echo.sleep ^3>>cert.sh 264 echo.exit>>cert.sh 265 %sh% --login %instdir%\cert.sh 266 del cert.sh 267 ) 268 ) 269 270:rebase2 271if %msys2%==msys32 ( 272 echo.------------------------------------------------------------------------------- 273 echo.second rebase msys32 system 274 echo.------------------------------------------------------------------------------- 275 call %instdir%\msys32\autorebase.bat 276 ) 277 278::------------------------------------------------------------------ 279:: write config profiles: 280::------------------------------------------------------------------ 281 282:writeProfile32 283if exist %instdir%\locals\win32\etc\profile.local GOTO writeProfile64 284 echo ------------------------------------------------------------------------------- 285 echo.- write profile for 32 bit compiling 286 echo ------------------------------------------------------------------------------- 287 ( 288 echo.# 289 echo.# /local32/etc/profile.local 290 echo.# 291 echo. 292 echo.MSYSTEM=MINGW32 293 echo. 294 echo.alias dir='ls -la --color=auto' 295 echo.alias ls='ls --color=auto' 296 echo.export CC=gcc 297 echo.export python=/usr/bin/python 298 echo. 299 echo.MSYS2_PATH="/usr/local/bin:/usr/bin" 300 echo.MANPATH="/usr/share/man:/mingw32/share/man:/local32/man:/local32/share/man" 301 echo.INFOPATH="/usr/local/info:/usr/share/info:/usr/info:/mingw32/share/info" 302 echo.MINGW_PREFIX="/mingw32" 303 echo.MINGW_CHOST="i686-w64-mingw32" 304 echo.export MSYSTEM MINGW_PREFIX MINGW_CHOST 305 echo. 306 echo.DXSDK_DIR="/mingw32/i686-w64-mingw32" 307 echo.ACLOCAL_PATH="/mingw32/share/aclocal:/usr/share/aclocal" 308 echo.PKG_CONFIG_LOCAL_PATH="/local32/lib/pkgconfig" 309 echo.PKG_CONFIG_PATH="/local32/lib/pkgconfig:/mingw32/lib/pkgconfig" 310 echo.CPPFLAGS="-I/local32/include -D_FORTIFY_SOURCE=2" 311 echo.CFLAGS="-I/local32/include -mms-bitfields -mthreads -mtune=generic -pipe" 312 echo.CXXFLAGS="-I/local32/include -mms-bitfields -mthreads -mtune=generic -pipe" 313 echo.LDFLAGS="-L/local32/lib -mthreads -pipe" 314 echo.export DXSDK_DIR ACLOCAL_PATH PKG_CONFIG_PATH PKG_CONFIG_LOCAL_PATH CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MSYSTEM 315 echo. 316 echo.PYTHONHOME=/usr 317 echo.PYTHONPATH="/usr/lib/python2.7:/usr/lib/python2.7/Tools/Scripts" 318 echo. 319 echo.PATH=".:/local32/bin:/mingw32/bin:${MSYS2_PATH}:${INFOPATH}:${PYTHONHOME}:${PYTHONPATH}:${PATH}" 320 echo.PS1='\[\033[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ ' 321 echo.export PATH PS1 322 echo. 323 echo.# package build directory 324 echo.LOCALBUILDDIR=/build 325 echo.# package installation prefix 326 echo.LOCALDESTDIR=/local32 327 echo.export LOCALBUILDDIR LOCALDESTDIR 328 )>>%instdir%\locals\win32\etc\profile.local 329 ) 330 331:writeProfile64 332if exist %instdir%\locals\x64\etc\profile.local GOTO loadGasPreproc 333 echo ------------------------------------------------------------------------------- 334 echo.- write profile for 64 bit compiling 335 echo ------------------------------------------------------------------------------- 336 ( 337 echo.# 338 echo.# /local64/etc/profile.local 339 echo.# 340 echo. 341 echo.MSYSTEM=MINGW64 342 echo. 343 echo.alias dir='ls -la --color=auto' 344 echo.alias ls='ls --color=auto' 345 echo.export CC=gcc 346 echo.export python=/usr/bin/python 347 echo. 348 echo.MSYS2_PATH="/usr/local/bin:/usr/bin" 349 echo.MANPATH="/usr/share/man:/mingw64/share/man:/local64/man:/local64/share/man" 350 echo.INFOPATH="/usr/local/info:/usr/share/info:/usr/info:/mingw64/share/info" 351 echo.MINGW_PREFIX="/mingw64" 352 echo.MINGW_CHOST="x86_64-w64-mingw32" 353 echo.export MSYSTEM MINGW_PREFIX MINGW_CHOST 354 echo. 355 echo.DXSDK_DIR="/mingw64/x86_64-w64-mingw32" 356 echo.ACLOCAL_PATH="/mingw64/share/aclocal:/usr/share/aclocal" 357 echo.PKG_CONFIG_LOCAL_PATH="/local64/lib/pkgconfig" 358 echo.PKG_CONFIG_PATH="/local64/lib/pkgconfig:/mingw64/lib/pkgconfig" 359 echo.CPPFLAGS="-I/local64/include -D_FORTIFY_SOURCE=2" 360 echo.CFLAGS="-I/local64/include -mms-bitfields -mthreads -mtune=generic -pipe" 361 echo.CXXFLAGS="-I/local64/include -mms-bitfields -mthreads -mtune=generic -pipe" 362 echo.LDFLAGS="-L/local64/lib -pipe" 363 echo.export DXSDK_DIR ACLOCAL_PATH PKG_CONFIG_PATH PKG_CONFIG_LOCAL_PATH CPPFLAGS CFLAGS CXXFLAGS LDFLAGS MSYSTEM 364 echo. 365 echo.PYTHONHOME=/usr 366 echo.PYTHONPATH="/usr/lib/python2.7:/usr/lib/python2.7/Tools/Scripts" 367 echo. 368 echo.PATH=".:/local64/bin:/mingw64/bin:${MSYS2_PATH}:${INFOPATH}:${PYTHONHOME}:${PYTHONPATH}:${PATH}" 369 echo.PS1='\[\033[32m\]\u@\h \[\e[33m\]\w\[\e[0m\]\n\$ ' 370 echo.export PATH PS1 371 echo. 372 echo.# package build directory 373 echo.LOCALBUILDDIR=/build 374 echo.# package installation prefix 375 echo.LOCALDESTDIR=/local64 376 echo.export LOCALBUILDDIR LOCALDESTDIR 377 )>>%instdir%\locals\x64\etc\profile.local 378 ) 379 380:loadGasPreproc 381set gaspreprocfile=gas-preprocessor.tar.gz 382if exist %downloaddir%\%gaspreprocfile% goto extractGasPreproc 383 echo ------------------------------------------------------------------------------- 384 echo.- Downloading gas-preprocessor.pl 385 echo ------------------------------------------------------------------------------- 386 %instdir%\bin\wget --tries=20 --retry-connrefused --waitretry=2 --no-check-certificate -c -O %downloaddir%\%gaspreprocfile% %gaspreprocurl% 387 388:extractGasPreproc 389if exist %instdir%\%msys2%\usr\bin\gas-preprocessor.pl goto end 390 echo ------------------------------------------------------------------------------- 391 echo.- Installing gas-preprocessor.pl 392 echo ------------------------------------------------------------------------------- 393 %unpack_exe% x %downloaddir%\%gaspreprocfile% -so 2>NUL | %unpack_exe% e -si -ttar -o%instdir%\%msys2%\usr\bin *.pl -r >NUL 2>NUL 394 395:end 396cd %instdir% 397IF ERRORLEVEL == 1 ( 398 ECHO Something goes wrong... 399 exit /B 1 400 ) 401 402echo.------------------------------------------------------------------------------- 403echo.install msys2 system done 404echo.------------------------------------------------------------------------------- 405 406@echo on 407