Warning, /graphics/krita/packaging/windows/package-complete.cmd is written in an unsupported language. File is not indexed.

0001 @echo off
0002 :: This batch script is meant to prepare a Krita package folder to be zipped or
0003 :: to be a base for the installer.
0004 
0005 :: --------
0006 
0007 setlocal enabledelayedexpansion
0008 goto begin
0009 
0010 
0011 :: Subroutines
0012 
0013 :find_on_path out_variable file_name
0014 set %1=%~f$PATH:2
0015 goto :EOF
0016 
0017 
0018 :get_dir_path out_variable file_path
0019 set %1=%~dp2
0020 goto :EOF
0021 
0022 
0023 :get_full_path out_variable file_path
0024 setlocal
0025 set FULL_PATH=%~f2
0026 if not exist "%FULL_PATH%" (
0027     set FULL_PATH=
0028 ) else (
0029     if exist "%FULL_PATH%\" (
0030         set FULL_PATH=
0031     )
0032 )
0033 endlocal & set "%1=%FULL_PATH%"
0034 goto :EOF
0035 
0036 
0037 :get_full_path_dir out_variable file_path
0038 setlocal
0039 set FULL_PATH=%~dp2
0040 if not exist "%FULL_PATH%" (
0041     set FULL_PATH=
0042 )
0043 endlocal & set "%1=%FULL_PATH%"
0044 goto :EOF
0045 
0046 
0047 :prompt_for_string out_variable prompt
0048 set /p %1=%~2^>
0049 goto :EOF
0050 
0051 
0052 :prompt_for_positive_integer out_variable prompt
0053 setlocal
0054 call :prompt_for_string USER_INPUT "%~2"
0055 if "%USER_INPUT%" == "" set USER_INPUT=0
0056 set /a RESULT=%USER_INPUT%
0057 if not %RESULT% GTR 0 (
0058     set RESULT=
0059 )
0060 endlocal & set "%1=%RESULT%"
0061 goto :EOF
0062 
0063 
0064 :prompt_for_file out_variable prompt
0065 setlocal
0066 :prompt_for_file__retry
0067 call :prompt_for_string USER_INPUT "%~2"
0068 if "%USER_INPUT%" == "" (
0069     endlocal
0070     set %1=
0071     goto :EOF
0072 )
0073 call :get_full_path RESULT "%USER_INPUT%"
0074 if "%RESULT%" == "" (
0075     echo Input does not point to valid file!
0076     set USER_INPUT=
0077     goto prompt_for_file__retry
0078 )
0079 endlocal & set "%1=%RESULT%"
0080 goto :EOF
0081 
0082 
0083 :prompt_for_dir out_variable prompt
0084 setlocal
0085 :prompt_for_dir__retry
0086 call :prompt_for_string USER_INPUT "%~2"
0087 if "%USER_INPUT%" == "" (
0088     endlocal
0089     set %1=
0090     goto :EOF
0091 )
0092 call :get_full_path_dir RESULT "%USER_INPUT%\"
0093 if "%RESULT%" == "" (
0094     echo Input does not point to valid dir!
0095     set USER_INPUT=
0096     goto prompt_for_dir__retry
0097 )
0098 endlocal & set "%1=%RESULT%"
0099 goto :EOF
0100 
0101 
0102 :usage
0103 echo Usage:
0104 echo %~n0 [--no-interactive --package-name ^<name^>] [ OPTIONS ... ]
0105 echo.
0106 echo Basic options:
0107 echo --no-interactive                Run without interactive prompts
0108 echo                                 When not specified, the script will prompt
0109 echo                                 for some of the parameters.
0110 echo --package-name ^<name^>           Specify the package name
0111 echo.
0112 echo Path options:
0113 echo --src-dir ^<dir_path^>            Specify Krita source dir
0114 echo                                 If unspecified, this will be determined from
0115 echo                                 the script location
0116 echo --deps-install-dir ^<dir_path^>   Specify deps install dir
0117 echo --krita-install-dir ^<dir_path^>  Specify Krita install dir
0118 echo.
0119 echo Special options:
0120 echo --pre-zip-hook ^<script_path^>    Specify a script to be called before
0121 echo                                 packaging the zip archive, can be used to
0122 echo                                 sign the binaries
0123 echo.
0124 goto :EOF
0125 :usage_and_exit
0126 call :usage
0127 exit /b
0128 :usage_and_fail
0129 call :usage
0130 exit /b 100
0131 
0132 
0133 :: ----------------------------
0134 :begin
0135 
0136 echo Krita Windows packaging script
0137 echo.
0138 
0139 
0140 :: command-line args parsing
0141 set ARG_NO_INTERACTIVE=
0142 set ARG_PACKAGE_NAME=
0143 set ARG_SRC_DIR=
0144 set ARG_DEPS_INSTALL_DIR=
0145 set ARG_KRITA_INSTALL_DIR=
0146 set ARG_PRE_ZIP_HOOK=
0147 :args_parsing_loop
0148 set CURRENT_MATCHED=
0149 if not "%1" == "" (
0150     if "%1" == "--no-interactive" (
0151         set ARG_NO_INTERACTIVE=1
0152         set CURRENT_MATCHED=1
0153     )
0154     if "%1" == "--package-name" (
0155         if not "%ARG_PACKAGE_NAME%" == "" (
0156             echo ERROR: Arg --package-name specified more than once 1>&2
0157             echo.
0158             goto usage_and_fail
0159         )
0160         if "%~2" == "" (
0161             echo ERROR: Arg --package-name is empty 1>&2
0162             echo.
0163             goto usage_and_fail
0164         )
0165         set "ARG_PACKAGE_NAME=%~2"
0166         shift /2
0167         set CURRENT_MATCHED=1
0168     )
0169     if "%1" == "--src-dir" (
0170         if not "%ARG_SRC_DIR%" == "" (
0171             echo ERROR: Arg --src-dir specified more than once 1>&2
0172             echo.
0173             goto usage_and_fail
0174         )
0175         if not exist "%~f2\" (
0176             echo ERROR: Arg --src-dir does not point to a directory 1>&2
0177             echo.
0178             goto usage_and_fail
0179         )
0180         call :get_dir_path ARG_SRC_DIR "%~f2\"
0181         shift /2
0182         set CURRENT_MATCHED=1
0183     )
0184     if "%1" == "--deps-install-dir" (
0185         if not "%ARG_DEPS_INSTALL_DIR%" == "" (
0186             echo ERROR: Arg --deps-install-dir specified more than once 1>&2
0187             echo.
0188             goto usage_and_fail
0189         )
0190         if "%~f2" == "" (
0191             echo ERROR: Arg --deps-install-dir does not point to a valid path 1>&2
0192             echo.
0193             goto usage_and_fail
0194         )
0195         call :get_dir_path ARG_DEPS_INSTALL_DIR "%~f2\"
0196         shift /2
0197         set CURRENT_MATCHED=1
0198     )
0199     if "%1" == "--krita-install-dir" (
0200         if not "%ARG_KRITA_INSTALL_DIR%" == "" (
0201             echo ERROR: Arg --krita-install-dir specified more than once 1>&2
0202             echo.
0203             goto usage_and_fail
0204         )
0205         if "%~f2" == "" (
0206             echo ERROR: Arg --krita-install-dir does not point to a valid path 1>&2
0207             echo.
0208             goto usage_and_fail
0209         )
0210         call :get_dir_path ARG_KRITA_INSTALL_DIR "%~f2\"
0211         shift /2
0212         set CURRENT_MATCHED=1
0213     )
0214     if "%1" == "--pre-zip-hook" (
0215         if not "%ARG_PRE_ZIP_HOOK%" == "" (
0216             echo ERROR: Arg --pre-zip-hook specified more than once 1>&2
0217             echo.
0218             goto usage_and_fail
0219         )
0220         if "%~f2" == "" (
0221             echo ERROR: Arg --pre-zip-hook does not point to a valid path 1>&2
0222             echo.
0223             goto usage_and_fail
0224         )
0225         call :get_full_path ARG_PRE_ZIP_HOOK "%~f2"
0226         if "!ARG_PRE_ZIP_HOOK!" == "" (
0227             echo ERROR: Arg --pre-zip-hook does not point to a valid file 1>&2
0228             echo.
0229             goto usage_and_fail
0230         )
0231         shift /2
0232         set CURRENT_MATCHED=1
0233     )
0234     if "%1" == "--help" (
0235         goto usage_and_exit
0236     )
0237     if not "!CURRENT_MATCHED!" == "1" (
0238         echo ERROR: Unknown option %1 1>&2
0239         echo.
0240         goto usage_and_fail
0241     )
0242     shift /1
0243     goto args_parsing_loop
0244 )
0245 
0246 if "%ARG_NO_INTERACTIVE%" == "1" (
0247     if "%ARG_PACKAGE_NAME%" == "" (
0248         echo ERROR: Required arg --package-name not specified! 1>&2
0249         echo.
0250         goto usage_and_fail
0251     )
0252 )
0253 
0254 if "%ARG_NO_INTERACTIVE%" == "1" (
0255     echo Non-interactive mode
0256 ) else (
0257     echo Interactive mode
0258     :: Trick to pause on exit
0259     call :real_begin
0260     pause
0261     exit /b !ERRORLEVEL!
0262 )
0263 :real_begin
0264 echo.
0265 
0266 
0267 if "%ARG_PACKAGE_NAME%" == "" (
0268     call :prompt_for_string ARG_PACKAGE_NAME "Provide package name"
0269     if "ARG_PACKAGE_NAME" == "" (
0270         echo ERROR: Package name not set! 1>&2
0271         exit /b 102
0272     )
0273 )
0274 
0275 
0276 :: Check environment config
0277 
0278 if "%SEVENZIP_EXE%" == "" (
0279     call :find_on_path SEVENZIP_EXE 7z.exe
0280 )
0281 if "%SEVENZIP_EXE%" == "" (
0282     call :find_on_path SEVENZIP_EXE 7za.exe
0283 )
0284 if "!SEVENZIP_EXE!" == "" (
0285     set "SEVENZIP_EXE=%ProgramFiles%\7-Zip\7z.exe"
0286     if not exist "!SEVENZIP_EXE!" (
0287         set "SEVENZIP_EXE=%ProgramFiles(x86)%\7-Zip\7z.exe"
0288     )
0289     if not exist "!SEVENZIP_EXE!" (
0290         echo 7-Zip not found! 1>&2
0291         exit /b 102
0292     )
0293 )
0294 echo 7-Zip: %SEVENZIP_EXE%
0295 
0296 if "%MINGW_BIN_DIR%" == "" (
0297     call :find_on_path MINGW_BIN_DIR_MAKE_EXE mingw32-make.exe
0298     if "!MINGW_BIN_DIR_MAKE_EXE!" == "" (
0299         if not "%ARG_NO_INTERACTIVE%" == "1" (
0300             call :prompt_for_file MINGW_BIN_DIR_MAKE_EXE "Provide path to mingw32-make.exe of mingw-w64"
0301         )
0302         if "!MINGW_BIN_DIR_MAKE_EXE!" == "" (
0303             echo ERROR: mingw-w64 not found! 1>&2
0304             exit /b 102
0305         )
0306         call :get_dir_path MINGW_BIN_DIR "!MINGW_BIN_DIR_MAKE_EXE!"
0307     ) else (
0308         call :get_dir_path MINGW_BIN_DIR "!MINGW_BIN_DIR_MAKE_EXE!"
0309         echo Found mingw on PATH: !MINGW_BIN_DIR!
0310         if not "%ARG_NO_INTERACTIVE%" == "1" (
0311             choice /c ny /n /m "Is this correct? [y/n] "
0312             if errorlevel 3 exit 255
0313             if not errorlevel 2 (
0314                 call :prompt_for_file MINGW_BIN_DIR_MAKE_EXE "Provide path to mingw32-make.exe of mingw-w64"
0315                 if "!MINGW_BIN_DIR_MAKE_EXE!" == "" (
0316                     echo ERROR: mingw-w64 not found! 1>&2
0317                     exit /b 102
0318                 )
0319                 call :get_dir_path MINGW_BIN_DIR "!MINGW_BIN_DIR_MAKE_EXE!"
0320             )
0321         )
0322     )
0323 )
0324 echo mingw-w64: %MINGW_BIN_DIR%
0325 
0326 :: Windows SDK is needed for windeployqt to get d3dcompiler_xx.dll
0327 if "%WindowsSdkDir%" == "" if not "%ProgramFiles(x86)%" == "" set "WindowsSdkDir=%ProgramFiles(x86)%\Windows Kits\10"
0328 if "%WindowsSdkDir%" == "" set "WindowsSdkDir=%ProgramFiles(x86)%\Windows Kits\10"
0329 if exist "%WindowsSdkDir%\" (
0330     pushd "%WindowsSdkDir%"
0331     if exist "bin\x64\fxc.exe" (
0332         set HAVE_FXC_EXE=1
0333     ) else (
0334         for /f "delims=" %%a in ('dir /a:d /b "bin\10.*"') do (
0335             if exist "bin\%%a\x64\fxc.exe" (
0336                 set HAVE_FXC_EXE=1
0337             )
0338         )
0339     )
0340     popd
0341 )
0342 if not "%HAVE_FXC_EXE%" == "1" (
0343     set WindowsSdkDir=
0344     echo Windows SDK 10 with fxc.exe not found
0345     echo If Qt was built with ANGLE ^(dynamic OpenGL^) support, the package might not work properly on some systems!
0346 ) else echo Windows SDK 10 with fxc.exe found on %WindowsSdkDir%
0347 
0348 if not "%ARG_SRC_DIR%" == "" (
0349     set "KRITA_SRC_DIR=%ARG_SRC_DIR%"
0350 )
0351 if "%KRITA_SRC_DIR%" == "" (
0352     :: Check whether this looks like to be in the source tree
0353         set "_temp=%~dp0"
0354         if "!_temp:~-19!" == "\packaging\windows\" (
0355         if exist "!_temp:~0,-19!\CMakeLists.txt" (
0356             if exist "!_temp:~0,-19!\3rdparty\CMakeLists.txt" (
0357                 set "KRITA_SRC_DIR=!_temp:~0,-19!\"
0358                 echo Script is running inside Krita src dir
0359             )
0360         )
0361     )
0362 )
0363 if "%KRITA_SRC_DIR%" == "" (
0364     if not "%ARG_NO_INTERACTIVE%" == "1" (
0365         call :prompt_for_dir KRITA_SRC_DIR "Provide path of Krita src dir"
0366     )
0367     if "!KRITA_SRC_DIR!" == "" (
0368         echo ERROR: Krita src dir not found! 1>&2
0369         exit /b 102
0370     )
0371 )
0372 echo Krita src: %KRITA_SRC_DIR%
0373 
0374 if not "%ARG_DEPS_INSTALL_DIR%" == "" (
0375     set "DEPS_INSTALL_DIR=%ARG_DEPS_INSTALL_DIR%"
0376 )
0377 if "%DEPS_INSTALL_DIR%" == "" (
0378     set DEPS_INSTALL_DIR=%CD%\i_deps\
0379     echo Using default deps install dir: !DEPS_INSTALL_DIR!
0380     if not "%ARG_NO_INTERACTIVE%" == "1" (
0381         choice /c ny /n /m "Is this ok? [y/n] "
0382         if errorlevel 3 exit 255
0383         if not errorlevel 2 (
0384             call :prompt_for_dir DEPS_INSTALL_DIR "Provide path of deps install dir"
0385         )
0386     )
0387     if "!DEPS_INSTALL_DIR!" == "" (
0388         echo ERROR: Deps install dir not set! 1>&2
0389         exit /b 102
0390     )
0391 )
0392 echo Deps install dir: %DEPS_INSTALL_DIR%
0393 
0394 if not "%ARG_KRITA_INSTALL_DIR%" == "" (
0395     set "KRITA_INSTALL_DIR=%ARG_KRITA_INSTALL_DIR%"
0396 )
0397 if "%KRITA_INSTALL_DIR%" == "" (
0398     set KRITA_INSTALL_DIR=%CD%\i\
0399     echo Using default Krita install dir: !KRITA_INSTALL_DIR!
0400     if not "%ARG_NO_INTERACTIVE%" == "1" (
0401         choice /c ny /n /m "Is this ok? [y/n] "
0402         if errorlevel 3 exit 255
0403         if not errorlevel 2 (
0404             call :prompt_for_dir KRITA_INSTALL_DIR "Provide path of Krita install dir"
0405         )
0406     )
0407     if "!KRITA_INSTALL_DIR!" == "" (
0408         echo ERROR: Krita install dir not set! 1>&2
0409         exit /b 102
0410     )
0411 )
0412 echo Krita install dir: %KRITA_INSTALL_DIR%
0413 
0414 
0415 :: Simple checking
0416 if not exist "%DEPS_INSTALL_DIR%\" (
0417         echo ERROR: Cannot find the deps install folder! 1>&2
0418         exit /B 1
0419 )
0420 if not exist "%KRITA_INSTALL_DIR%\" (
0421         echo ERROR: Cannot find the krita install folder! 1>&2
0422         exit /B 1
0423 )
0424 if not "%DEPS_INSTALL_DIR: =%" == "%DEPS_INSTALL_DIR%" (
0425         echo ERROR: Deps install path contains space, which will not work properly! 1>&2
0426         exit /B 1
0427 )
0428 if not "%KRITA_INSTALL_DIR: =%" == "%KRITA_INSTALL_DIR%" (
0429         echo ERROR: Krita install path contains space, which will not work properly! 1>&2
0430         exit /B 1
0431 )
0432 
0433 set pkg_name=%ARG_PACKAGE_NAME%
0434 echo Package name is "%pkg_name%"
0435 
0436 set pkg_root=%CD%\%pkg_name%
0437 echo Packaging dir is %pkg_root%
0438 echo.
0439 if exist %pkg_root% (
0440         echo ERROR: Packaging dir already exists! Please remove or rename it first.
0441         exit /B 1
0442 )
0443 if exist %pkg_root%.zip (
0444         echo ERROR: Packaging zip already exists! Please remove or rename it first.
0445         exit /B 1
0446 )
0447 if exist %pkg_root%-dbg.zip (
0448         echo ERROR: Packaging debug zip already exists! Please remove or rename it first.
0449         exit /B 1
0450 )
0451 
0452 echo.
0453 
0454 
0455 if not "%ARG_NO_INTERACTIVE%" == "1" (
0456     choice /c ny /n /m "Is the above ok? [y/n] "
0457     if errorlevel 3 exit 255
0458     if not errorlevel 2 (
0459         exit /b 1
0460     )
0461     echo.
0462 )
0463 
0464 
0465 :: Initialize clean PATH
0466 set "PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\"
0467 set "PATH=%MINGW_BIN_DIR%;%DEPS_INSTALL_DIR%\bin;%PATH%"
0468 
0469 
0470 echo.
0471 echo Trying to guess compiler version...
0472 for %%a in (g++ clang++) do (
0473     %%a --version > NUL
0474     if not errorlevel 1 (
0475         set CC=%%a
0476     )
0477 )
0478 if "%CC%" == "" (
0479     echo ERROR: No working compiler.
0480     exit /B 1
0481 )
0482 %CC% --version > NUL
0483 for /f "delims=" %%a in ('%CC% --version ^| find "g++"') do set GCC_VERSION_LINE=%%a
0484 :: The space in "clang " is essential to detect
0485 :: the version line and not the InstalledDir
0486 if "%GCC_VERSION_LINE%" == "" (
0487     for /f "delims=" %%a in ('%CC% --version ^| find "clang "') do set GCC_VERSION_LINE=%%a
0488 )
0489 if "%GCC_VERSION_LINE%" == "" (
0490         echo ERROR: Failed to get version of g++.
0491         exit /B 1
0492 )
0493 echo -- %GCC_VERSION_LINE%
0494 set IS_TDM=
0495 set IS_MSYS=
0496 set IS_CLANG=
0497 if not "%GCC_VERSION_LINE:tdm64=%" == "%GCC_VERSION_LINE%" (
0498         echo Compiler looks like TDM64-GCC
0499         set IS_TDM=1
0500 ) else if not "%GCC_VERSION_LINE:MSYS=%" == "%GCC_VERSION_LINE%" (
0501     echo Compiler looks like MSYS GCC
0502     set IS_MSYS=1
0503 ) else if not "%GCC_VERSION_LINE:clang=%" == "%GCC_VERSION_LINE%" (
0504     echo Compiler looks like Clang
0505     set IS_CLANG=1
0506 ) else (
0507     echo Compiler looks like plain old MinGW64
0508 )
0509 set IS_LLVM_MINGW=
0510 set IS_MSYS_CLANG=
0511 if not x%IS_CLANG% == x (
0512     rem Look for the multiarch target binary dirs. Unfortunately there is
0513     rem no surefire way to detect a llvm-mingw toolchain.
0514     if exist "%MINGW_BIN_DIR%\..\i686-w64-mingw32\bin\" (
0515         if exist "%MINGW_BIN_DIR%\..\x86_64-w64-mingw32\bin\" (
0516             echo Toolchain looks like llvm-mingw
0517             set IS_LLVM_MINGW=1
0518         )
0519     )
0520     if "!IS_LLVM_MINGW!" == "" (
0521         echo Toolchain does not look like llvm-mingw, assuming MSYS Clang
0522         set IS_MSYS_CLANG=1
0523     )
0524 )
0525 
0526 echo.
0527 echo Trying to guess target architecture...
0528 set OBJDUMP=
0529 for %%a in (objdump llvm-objdump) do (
0530     %%a --version > NUL
0531     if not errorlevel 1 (
0532         set OBJDUMP=%%a
0533     )
0534 )
0535 if "%OBJDUMP%" == "" (
0536     echo ERROR: objdump is not working.
0537     exit /B 1
0538 )
0539 for /f "delims=, tokens=1" %%a in ('%OBJDUMP% -f %KRITA_INSTALL_DIR%\bin\krita.exe ^| find "i386"') do set TARGET_ARCH_LINE=%%a
0540 if "%TARGET_ARCH_LINE%" == "" (
0541     echo Possible LLVM objdump, trying to detect architecture...
0542     for /f "delims=" %%a in ('%OBJDUMP% -f %KRITA_INSTALL_DIR%\bin\krita.exe ^| find "coff"') do set TARGET_ARCH_LINE=%%a
0543 )
0544 echo -- %TARGET_ARCH_LINE%
0545 if "%TARGET_ARCH_LINE:x86-64=%" == "%TARGET_ARCH_LINE%" (
0546         echo Target looks like x86
0547         set IS_X64=
0548 ) else (
0549         echo Target looks like x64
0550         set IS_x64=1
0551 )
0552 
0553 echo.
0554 echo Testing for objcopy...
0555 objcopy --version > NUL
0556 if errorlevel 1 (
0557         echo ERROR: objcopy is not working.
0558         exit /B 1
0559 )
0560 
0561 echo.
0562 echo Testing for strip...
0563 strip --version > NUL
0564 if errorlevel 1 (
0565         echo ERROR: strip is not working.
0566         exit /B 1
0567 )
0568 
0569 echo.
0570 echo Creating base directories...
0571 mkdir %pkg_root% && ^
0572 mkdir %pkg_root%\bin && ^
0573 mkdir %pkg_root%\etc && ^
0574 mkdir %pkg_root%\lib && ^
0575 mkdir %pkg_root%\share
0576 if errorlevel 1 (
0577         echo ERROR: Cannot create packaging dir tree!
0578         %PAUSE%
0579         exit /B 1
0580 )
0581 
0582 echo.
0583 echo Copying GCC libraries...
0584 set "STDLIBS_DIR=%MINGW_BIN_DIR%"
0585 if not x%IS_TDM% == x (
0586         if x%is_x64% == x (
0587                 :: TDM-GCC x86
0588                 set "STDLIBS=libgomp-1"
0589         ) else (
0590                 :: TDM-GCC x64
0591                 set "STDLIBS=libgomp_64-1"
0592         )
0593 ) else if not x%IS_MSYS% == x (
0594         if x%is_x64% == x (
0595                 :: msys-mingw-w64 x86
0596                 set "STDLIBS=libgcc_s_dw2-1 libgomp-1 libstdc++-6 libwinpthread-1 libatomic-1 libiconv-2 zlib1 libexpat-1 libintl-8 libssl-1_1 libcrypto-1_1"
0597         ) else (
0598                 :: msys-mingw-w64 x64
0599                 set "STDLIBS=libgcc_s_seh-1 libgomp-1 libstdc++-6 libwinpthread-1 libatomic-1 libiconv-2 zlib1 libexpat-1 libintl-8 libssl-1_1-x64 libcrypto-1_1-x64"
0600         )
0601 ) else if not x%IS_MSYS_CLANG% == x (
0602         if x%is_x64% == x (
0603                 :: msys-mingw-w64-clang64 x86
0604                 set "STDLIBS=libomp libssp-0 libunwind libc++ libwinpthread-1 libiconv-2 zlib1 libexpat-1 libintl-8 libssl-1_1 libcrypto-1_1"
0605         ) else (
0606                 :: msys-mingw-w64-clang64 x64
0607                 set "STDLIBS=libomp libssp-0 libunwind libc++ libwinpthread-1 libiconv-2 zlib1 libexpat-1 libintl-8 libssl-1_1-x64 libcrypto-1_1-x64"
0608         )
0609 ) else if not x%IS_LLVM_MINGW% == x (
0610     :: llvm-mingw
0611     set "STDLIBS=libc++ libomp libssp-0 libunwind libwinpthread-1"
0612     rem The toolchain does not include all of the DLLs in the compiler bin dir,
0613     rem so we need to copy them from the cross target bin dir.
0614     if x%is_x64% == x (
0615         set "STDLIBS_DIR=%MINGW_BIN_DIR%\..\i686-w64-mingw32\bin"
0616     ) else (
0617         set "STDLIBS_DIR=%MINGW_BIN_DIR%\..\x86_64-w64-mingw32\bin"
0618     )
0619 ) else (    
0620     if x%is_x64% == x (
0621                 :: mingw-w64 x86
0622                 set "STDLIBS=libgcc_s_dw2-1 libgomp-1 libstdc++-6 libwinpthread-1"
0623         ) else (
0624                 :: mingw-w64 x64
0625                 set "STDLIBS=libgcc_s_seh-1 libgomp-1 libstdc++-6 libwinpthread-1"
0626         )
0627 )
0628 
0629 for %%L in (%STDLIBS%) do copy "%STDLIBS_DIR%\%%L.dll" %pkg_root%\bin
0630 
0631 echo.
0632 echo Copying files...
0633 :: krita.exe
0634 copy %KRITA_INSTALL_DIR%\bin\krita.exe %pkg_root%\bin
0635 copy %KRITA_INSTALL_DIR%\bin\krita.com %pkg_root%\bin
0636 :: kritarunner.exe
0637 copy %KRITA_INSTALL_DIR%\bin\kritarunner.exe %pkg_root%\bin
0638 copy %KRITA_INSTALL_DIR%\bin\kritarunner.com %pkg_root%\bin
0639 
0640 if exist %KRITA_INSTALL_DIR%\bin\FreehandStrokeBenchmark.exe (
0641     :: FreehandStrokeBenchmark.exe
0642     copy %KRITA_INSTALL_DIR%\bin\FreehandStrokeBenchmark.exe %pkg_root%\bin
0643     xcopy /S /Y /I %DEPS_INSTALL_DIR%\bin\data %pkg_root%\bin\data
0644 )
0645 
0646 :: qt.conf -- to specify the location to Qt translations
0647 copy %KRITA_SRC_DIR%\packaging\windows\qt.conf %pkg_root%\bin
0648 :: DLLs from bin/
0649 echo INFO: Copying all DLLs except Qt5* from bin/
0650 setlocal enableextensions enabledelayedexpansion
0651 for /f "delims=" %%F in ('dir /b "%KRITA_INSTALL_DIR%\bin\*.dll"') do (
0652         set file=%%F
0653         set file=!file:~0,3!
0654         if not x!file! == xQt5 copy "%KRITA_INSTALL_DIR%\bin\%%F" %pkg_root%\bin
0655 )
0656 for /f "delims=" %%F in ('dir /b "%DEPS_INSTALL_DIR%\bin\*.dll"') do (
0657         set file=%%F
0658         set file=!file:~0,3!
0659         if not x!file! == xQt5 copy "%DEPS_INSTALL_DIR%\bin\%%F" %pkg_root%\bin
0660 )
0661 endlocal
0662 :: symsrv.yes for Dr. Mingw
0663 copy %DEPS_INSTALL_DIR%\bin\symsrv.yes %pkg_root%\bin
0664 :: DLLs from lib/
0665 echo INFO: Copying all DLLs from lib/ (deps)
0666 copy %DEPS_INSTALL_DIR%\lib\*.dll %pkg_root%\bin
0667 :: Boost, there might be more than one leftover but we can't really do much
0668 copy %DEPS_INSTALL_DIR%\bin\libboost_system-*.dll %pkg_root%\bin
0669 :: KF5 plugins may be placed at different locations depending on how Qt is built
0670 xcopy /S /Y /I %DEPS_INSTALL_DIR%\lib\plugins\imageformats %pkg_root%\bin\imageformats
0671 xcopy /S /Y /I %DEPS_INSTALL_DIR%\plugins\imageformats %pkg_root%\bin\imageformats
0672 xcopy /S /Y /I %DEPS_INSTALL_DIR%\lib\plugins\kf5 %pkg_root%\bin\kf5
0673 xcopy /S /Y /I %DEPS_INSTALL_DIR%\plugins\kf5 %pkg_root%\bin\kf5
0674 
0675 :: Copy the sql drivers explicitly
0676 xcopy /S /Y /I %DEPS_INSTALL_DIR%\plugins\sqldrivers %pkg_root%\bin\sqldrivers
0677 
0678 :: Qt Translations
0679 :: it seems that windeployqt does these, but only *some* of these???
0680 mkdir %pkg_root%\bin\translations
0681 setlocal enableextensions enabledelayedexpansion
0682 for /f "delims=" %%F in ('dir /b "%DEPS_INSTALL_DIR%\translations\qt_*.qm"') do (
0683         :: Exclude qt_help_*.qm
0684         set temp=%%F
0685         set temp2=!temp:_help=!
0686         if x!temp2! == x!temp! copy %DEPS_INSTALL_DIR%\translations\!temp! %pkg_root%\bin\translations\!temp!
0687 )
0688 endlocal
0689 :: Krita plugins
0690 xcopy /Y %KRITA_INSTALL_DIR%\lib\kritaplugins\*.dll %pkg_root%\lib\kritaplugins\
0691 xcopy /Y /S /I %DEPS_INSTALL_DIR%\lib\krita-python-libs %pkg_root%\lib\krita-python-libs
0692 xcopy /Y /S /I %KRITA_INSTALL_DIR%\lib\krita-python-libs %pkg_root%\lib\krita-python-libs
0693 
0694 :: MLT plugins and their data
0695 xcopy /S /Y /I %DEPS_INSTALL_DIR%\lib\mlt %pkg_root%\lib\mlt
0696 xcopy /S /Y /I %DEPS_INSTALL_DIR%\share\mlt %pkg_root%\share\mlt
0697 
0698 :: Fontconfig
0699 xcopy /Y /S /I %DEPS_INSTALL_DIR%\etc\fonts %pkg_root%\etc\fonts
0700 
0701 :: Share
0702 xcopy /Y /S /I %KRITA_INSTALL_DIR%\share\color %pkg_root%\share\color
0703 xcopy /Y /S /I %KRITA_INSTALL_DIR%\share\color-schemes %pkg_root%\share\color-schemes
0704 xcopy /Y /S /I %KRITA_INSTALL_DIR%\share\icons %pkg_root%\share\icons
0705 xcopy /Y /S /I %KRITA_INSTALL_DIR%\share\krita %pkg_root%\share\krita
0706 xcopy /Y /S /I %KRITA_INSTALL_DIR%\share\kritaplugins %pkg_root%\share\kritaplugins
0707 xcopy /Y /S /I %DEPS_INSTALL_DIR%\share\kf5 %pkg_root%\share\kf5
0708 xcopy /Y /S /I %DEPS_INSTALL_DIR%\share\mime %pkg_root%\share\mime
0709 :: Python libs
0710 xcopy /Y /S /I %DEPS_INSTALL_DIR%\share\krita\pykrita %pkg_root%\share\krita\pykrita
0711 robocopy %DEPS_INSTALL_DIR%\lib\site-packages %pkg_root%\lib\site-packages /S /E ^
0712     /XF "setuptools.pth" "easy-install.pth" ^
0713     /XD "packaging*" "pip*" "ply*" "pyparsing*" "PyQt_builder*" "sip*" "toml*" "meson*"
0714 :: Not useful on Windows it seems
0715 rem xcopy /Y /S /I %KRITA_INSTALL_DIR%\share\appdata %pkg_root%\share\appdata
0716 rem xcopy /Y /S /I %KRITA_INSTALL_DIR%\share\applications %pkg_root%\share\applications
0717 rem xcopy /Y /S /I %DEPS_INSTALL_DIR%\share\doc %pkg_root%\share\doc
0718 rem xcopy /Y /S /I %DEPS_INSTALL_DIR%\share\kservices5 %pkg_root%\share\kservices5
0719 rem xcopy /Y /S /I %DEPS_INSTALL_DIR%\share\man %pkg_root%\share\man
0720 rem xcopy /Y /S /I %DEPS_INSTALL_DIR%\share\ocio %pkg_root%\share\ocio
0721 
0722 :: Copy locale to bin
0723 xcopy /Y /S /I %KRITA_INSTALL_DIR%\share\locale %pkg_root%\bin\locale
0724 xcopy /Y /S /I %DEPS_INSTALL_DIR%\share\locale %pkg_root%\bin\locale
0725 
0726 :: Copy shortcut link from source (can't create it dynamically)
0727 copy %KRITA_SRC_DIR%\packaging\windows\krita.lnk %pkg_root%
0728 copy %KRITA_SRC_DIR%\packaging\windows\krita-minimal.lnk %pkg_root%
0729 copy %KRITA_SRC_DIR%\packaging\windows\krita-animation.lnk %pkg_root%
0730 
0731 set "QMLDIR_ARGS=--qmldir %DEPS_INSTALL_DIR%\qml"
0732 if exist "%KRITA_INSTALL_DIR%\lib\qml" (
0733     xcopy /Y /S /I %KRITA_INSTALL_DIR%\lib\qml %pkg_root%\bin
0734     :: This doesn't really seem to do anything
0735     set "QMLDIR_ARGS=%QMLDIR_ARGS% --qmldir %KRITA_INSTALL_DIR%\lib\qml"
0736 )
0737 
0738 :: windeployqt
0739 windeployqt.exe %QMLDIR_ARGS% --release -gui -core -concurrent -network -printsupport -svg -xml -sql -qml -quick -quickwidgets %pkg_root%\bin\krita.exe %pkg_root%\bin\krita.dll
0740 if errorlevel 1 (
0741         echo ERROR: WinDeployQt failed! 1>&2
0742         exit /B 1
0743 )
0744 
0745 :: ffmpeg
0746 copy %DEPS_INSTALL_DIR%\bin\ffmpeg.exe %pkg_root%\bin
0747 copy %DEPS_INSTALL_DIR%\bin\ffprobe.exe %pkg_root%\bin
0748 copy %DEPS_INSTALL_DIR%\bin\ffmpeg_LICENSE.txt %pkg_root%\bin
0749 copy %DEPS_INSTALL_DIR%\bin\ffmpeg_README.txt %pkg_root%\bin
0750 
0751 
0752 :: Copy embedded Python
0753 xcopy /Y /S /I %DEPS_INSTALL_DIR%\python %pkg_root%\python
0754 del /q %pkg_root%\python\python.exe %pkg_root%\python\pythonw.exe
0755 
0756 :: For chopping relative path
0757 :: 512 should be enough
0758 :: n+2 to also account for a trailing backslash
0759 setlocal enableextensions enabledelayedexpansion
0760 for /L %%n in (1 1 512) do if "!pkg_root:~%%n,1!" neq "" set /a "pkg_root_len_plus_one=%%n+2"
0761 endlocal & set pkg_root_len_plus_one=%pkg_root_len_plus_one%
0762 
0763 echo.
0764 setlocal enableextensions enabledelayedexpansion
0765 :: Remove Python cache files
0766 for /d /r "%pkg_root%" %%F in (__pycache__\) do (
0767         if EXIST "%%F" (
0768                 set relpath=%%F
0769                 set relpath=!relpath:~%pkg_root_len_plus_one%!
0770                 echo Deleting Python cache !relpath!
0771                 rmdir /S /Q "%%F"
0772         )
0773 )
0774 endlocal
0775 
0776 echo.
0777 echo Splitting debug info from binaries...
0778 call :split-debug "%pkg_root%\bin\krita.exe" bin\krita.exe
0779 call :split-debug "%pkg_root%\bin\krita.com" bin\krita.com
0780 call :split-debug "%pkg_root%\bin\kritarunner.exe" bin\kritarunner.exe
0781 call :split-debug "%pkg_root%\bin\kritarunner.com" bin\kritarunner.com
0782 setlocal enableextensions enabledelayedexpansion
0783 :: Find all DLLs
0784 for /r "%pkg_root%" %%F in (*.dll) do (
0785         set relpath=%%F
0786         set relpath=!relpath:~%pkg_root_len_plus_one%!
0787         call :split-debug "%%F" !relpath!
0788 )
0789 endlocal
0790 setlocal enableextensions enabledelayedexpansion
0791 :: Find all Python native modules
0792 for /r "%pkg_root%\share\krita\pykrita\" %%F in (*.pyd) do (
0793         set relpath=%%F
0794         set relpath=!relpath:~%pkg_root_len_plus_one%!
0795         call :split-debug "%%F" !relpath!
0796 )
0797 for /r "%pkg_root%\lib\krita-python-libs\" %%F in (*.pyd) do (
0798         set relpath=%%F
0799         set relpath=!relpath:~%pkg_root_len_plus_one%!
0800         call :split-debug "%%F" !relpath!
0801 )
0802 for /r "%pkg_root%\lib\site-packages\" %%F in (*.pyd) do (
0803         set relpath=%%F
0804         set relpath=!relpath:~%pkg_root_len_plus_one%!
0805         call :split-debug "%%F" !relpath!
0806 )
0807 endlocal
0808 
0809 if not "%ARG_PRE_ZIP_HOOK%" == "" (
0810     echo Running pre-zip-hook...
0811     setlocal
0812     cmd /c ""%ARG_PRE_ZIP_HOOK%" "%pkg_root%\""
0813     if errorlevel 1 (
0814         echo ERROR: Got exit code !errorlevel! from pre-zip-hook! 1>&2
0815         exit /b 1
0816     )
0817     endlocal
0818 )
0819 
0820 echo.
0821 echo Packaging stripped binaries...
0822 "%SEVENZIP_EXE%" a -tzip %pkg_name%.zip %pkg_root%\ "-xr^!.debug"
0823 echo --------
0824 
0825 if "%KRITA_SKIP_DEBUG_PACKAGE%" == "" (
0826     echo.
0827     echo Packaging debug info...
0828     :: (note that the top-level package dir is not included)
0829     "%SEVENZIP_EXE%" a -tzip %pkg_name%-dbg.zip -r %pkg_root%\*.debug
0830     echo --------
0831 )
0832 
0833 echo.
0834 echo.
0835 echo Krita packaged as %pkg_name%.zip
0836 if exist %pkg_name%-dbg.zip echo Debug info packaged as %pkg_name%-dbg.zip
0837 echo Packaging dir is %pkg_root%
0838 echo NOTE: Do not create installer with packaging dir. Extract from
0839 echo           %pkg_name%.zip instead,
0840 echo       and do _not_ run krita inside the extracted directory because it will
0841 echo       create extra unnecessary files.
0842 echo.
0843 echo Please remember to actually test the package before releasing it.
0844 echo.
0845 %PAUSE%
0846 
0847 exit /b
0848 
0849 :split-debug
0850 echo Splitting debug info of %2
0851 objcopy --only-keep-debug %~1 %~1.debug
0852 if ERRORLEVEL 1 exit /b %ERRORLEVEL%
0853 :: If the debug file is small enough then consider there being no debug info.
0854 :: Discard these files since they somehow make gdb crash.
0855 call :getfilesize %~1.debug
0856 if /i %getfilesize_retval% LEQ 2048 (
0857         echo Discarding %2.debug
0858         del %~1.debug
0859         exit /b 0
0860 )
0861 if not exist %~dp1.debug mkdir %~dp1.debug
0862 move %~1.debug %~dp1.debug\ > NUL
0863 strip --strip-debug %~1
0864 :: Add debuglink
0865 :: FIXME: There is a problem with gdb that cause it to output this warning
0866 :: FIXME: "warning: section .gnu_debuglink not found in xxx.debug"
0867 :: FIXME: I tried adding a link to itself but this kills drmingw :(
0868 objcopy --add-gnu-debuglink="%~dp1.debug\%~nx1.debug" %~1
0869 exit /b %ERRORLEVEL%
0870 
0871 :getfilesize
0872 set getfilesize_retval=%~z1
0873 goto :eof
0874 
0875 :relpath_dirpath
0876 call :relpath_dirpath_internal "" "%~1"
0877 goto :eof
0878 
0879 :relpath_dirpath_internal
0880 for /f "tokens=1* delims=\" %%a in ("%~2") do (
0881         :: If part 2 is empty, it means part 1 is probably the file name
0882         if x%%b==x (
0883                 set relpath_dirpath_retval=%~1
0884         ) else (
0885                 call :relpath_dirpath_internal "%~1%%a\" %%b
0886         )
0887 )
0888 goto :eof