Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.83 KB | None | 0 0
  1. Packaging:
  2.  
  3. @echo off
  4. :: This batch script is meant to prepare a Krita package folder to be zipped or
  5. :: to be a base for the installer.
  6. ::
  7. :: Just drop it next to the "i" install folder where the dependencies and Krita
  8. :: binaries are.
  9. ::
  10. :: Also copy filelist_bin_dll.txt and filelist_lib_dll.txt if you want more
  11. :: fine-grained DLL dependencies copying.
  12. ::
  13. :: You may want to review the following parameters.
  14. ::
  15. :: Configuration parameters:
  16. ::
  17. :: MINGW_GCC_BIN: Path to the mingw-w64/bin dir
  18. :: SEVENZIP_EXE: Path to 7-Zip executable (either 7z.exe or 7zG.exe)
  19. :: BUILDDIR_SRC: Path to krita source dir (for package shortcut)
  20. :: BUILDDIR_INSTALL: Path to INSTALL prefix of the build
  21. ::
  22. :: Note that paths should only contain alphanumeric, _ and -, except for the
  23. :: path to 7-Zip, which is fine if quoted.
  24. ::
  25. set MINGW_GCC_BIN=C:\TDM-GCC-64\bin\
  26. set SEVENZIP_EXE="C:\Program Files\7-Zip\7z.exe"
  27. rem set BUILDDIR_SRC=%CD%\krita
  28. set BUILDDIR_SRC=%CD%\krita
  29. set BUILDDIR_INSTALL=%CD%\i
  30.  
  31. :: --------
  32.  
  33. set PATH=%MINGW_GCC_BIN%;%PATH%
  34.  
  35. echo Krita Windows packaging script
  36. echo.
  37. echo Configurations:
  38. echo MINGW_GCC_BIN: %MINGW_GCC_BIN%
  39. echo SEVENZIP_EXE: %SEVENZIP_EXE%
  40. echo BUILDDIR_SRC: %BUILDDIR_SRC%
  41. echo BUILDDIR_INSTALL: %BUILDDIR_INSTALL%
  42. echo.
  43.  
  44. if "%1" == "" (
  45. set PAUSE=pause
  46. ) else (
  47. set "PAUSE= "
  48. )
  49.  
  50. :: Simple checking
  51. if not exist %BUILDDIR_INSTALL% (
  52. echo ERROR: Cannot find the install folder!
  53. %PAUSE%
  54. exit /B 1
  55. )
  56. if not "%BUILDDIR_INSTALL: =%" == "%BUILDDIR_INSTALL%" (
  57. echo ERROR: Install path contains space, which will not work properly!
  58. %PAUSE%
  59. exit /B 1
  60. )
  61.  
  62. :: Decide package name to use
  63. if "%1" == "" (
  64. echo Please input a package name. It will be used for the output directory, package
  65. echo file name and as the top-level directory of the package.
  66. echo Alternatively, you can pass it as the first argument to this script.
  67. echo You should only use alphanumeric, _ and -
  68. echo.
  69. set /P pkg_name=Package name^>
  70. setlocal
  71. if "!pkg_name!" == "" (
  72. echo ERROR: You cannot choose an empty name!
  73. %PAUSE%
  74. exit /B 1
  75. )
  76. endlocal
  77. ) else (
  78. set pkg_name=%1
  79. )
  80. echo Package name is "%pkg_name%"
  81.  
  82. set pkg_root=%CD%\%pkg_name%
  83. echo Packaging dir is %pkg_root%
  84. echo.
  85. if exist %pkg_root% (
  86. echo ERROR: Packaging dir already exists! Please remove or rename it first.
  87. %PAUSE%
  88. exit /B 1
  89. )
  90.  
  91. echo.
  92. echo Trying to guess GCC version...
  93. g++ --version > NUL
  94. if errorlevel 1 (
  95. echo ERROR: g++ is not working.
  96. %PAUSE%
  97. exit /B 1
  98. )
  99. for /f "delims=" %%a in ('g++ --version ^| find "g++"') do set GCC_VERSION_LINE=%%a
  100. echo -- %GCC_VERSION_LINE%
  101. if "%GCC_VERSION_LINE:tdm64=%" == "%GCC_VERSION_LINE%" (
  102. echo Compiler doesn't look like TDM64-GCC, assuming simple mingw-w64
  103. set IS_TDM=
  104. ) else (
  105. echo Compiler looks like TDM64-GCC
  106. set IS_TDM=1
  107. )
  108.  
  109. echo.
  110. echo Trying to guess target architecture...
  111. objdump --version > NUL
  112. if errorlevel 1 (
  113. echo ERROR: objdump is not working.
  114. %PAUSE%
  115. exit /B 1
  116. )
  117. for /f "delims=, tokens=1" %%a in ('objdump -f %BUILDDIR_INSTALL%\bin\krita.exe ^| find "architecture"') do set TARGET_ARCH_LINE=%%a
  118. echo -- %TARGET_ARCH_LINE%
  119. if "%TARGET_ARCH_LINE:x86-64=%" == "%TARGET_ARCH_LINE%" (
  120. echo Target looks like x86
  121. set IS_X64=
  122. ) else (
  123. echo Target looks like x64
  124. set IS_x64=1
  125. )
  126.  
  127. echo.
  128. echo Testing for objcopy...
  129. objcopy --version > NUL
  130. if errorlevel 1 (
  131. echo ERROR: objcopy is not working.
  132. %PAUSE%
  133. exit /B 1
  134. )
  135.  
  136. echo.
  137. echo Testing for strip...
  138. strip --version > NUL
  139. if errorlevel 1 (
  140. echo ERROR: strip is not working.
  141. %PAUSE%
  142. exit /B 1
  143. )
  144.  
  145. echo.
  146. echo Creating base directories...
  147. mkdir %pkg_root% && ^
  148. mkdir %pkg_root%\bin && ^
  149. mkdir %pkg_root%\lib && ^
  150. mkdir %pkg_root%\share
  151. if errorlevel 1 (
  152. echo ERROR: Cannot create packaging dir tree!
  153. %PAUSE%
  154. exit /B 1
  155. )
  156.  
  157. echo.
  158. echo Copying GCC libraries...
  159. if x%IS_TDM% == x (
  160. if x%is_x64% == x (
  161. :: mingw-w64 x86
  162. set "STDLIBS=gcc_s_dw2-1 gomp-1 stdc++-6 winpthread-1"
  163. ) else (
  164. :: mingw-w64 x64
  165. set "STDLIBS=gcc_s_seh-1 gomp-1 stdc++-6 winpthread-1"
  166. )
  167. ) else (
  168. if x%is_x64% == x (
  169. :: TDM-GCC x86
  170. set "STDLIBS=gomp-1"
  171. ) else (
  172. :: TDM-GCC x64
  173. set "STDLIBS=gomp_64-1"
  174. )
  175. )
  176. for %%L in (%STDLIBS%) do copy "%MINGW_GCC_BIN%\lib%%L.dll" %pkg_root%\bin
  177.  
  178. echo.
  179. echo Copying files...
  180. :: krita.exe
  181. copy %BUILDDIR_INSTALL%\bin\krita.exe %pkg_root%\bin
  182. copy %BUILDDIR_INSTALL%\bin\gmic_krita_qt.exe %pkg_root%\bin
  183. :: DLLs from bin/
  184. if exist filelist_bin_dll.txt (
  185. for /f %%F in (filelist_bin_dll.txt) do copy %BUILDDIR_INSTALL%\bin\%%F %pkg_root%\bin
  186. ) else (
  187. echo INFO: filelist_bin_dll.txt not found, copying all DLLs except Qt5 from bin/
  188. setlocal enableextensions enabledelayedexpansion
  189. for /f "delims=" %%F in ('dir /b "%BUILDDIR_INSTALL%\bin\*.dll"') do (
  190. set file=%%F
  191. set file=!file:~0,3!
  192. if not x!file! == xQt5 copy %BUILDDIR_INSTALL%\bin\%%F %pkg_root%\bin
  193. )
  194. endlocal
  195. )
  196. :: symsrv.yes for Dr. Mingw
  197. copy %BUILDDIR_INSTALL%\bin\symsrv.yes %pkg_root%\bin
  198. :: DLLs from lib/
  199. if exist filelist_lib_dll.txt (
  200. for /f %%F in (filelist_lib_dll.txt) do copy %BUILDDIR_INSTALL%\lib\%%F %pkg_root%\bin
  201. ) else (
  202. echo INFO: filelist_lib_dll.txt not found, copying all DLLs from lib/
  203. copy %BUILDDIR_INSTALL%\lib\*.dll %pkg_root%\bin
  204. )
  205. :: Boost, there might be more than one leftover but we can't really do much
  206. copy %BUILDDIR_INSTALL%\bin\libboost_system-*.dll %pkg_root%\bin
  207. :: KF5 plugins may be placed at different locations depending on how Qt is built
  208. xcopy /S /Y /I %BUILDDIR_INSTALL%\lib\plugins\imageformats %pkg_root%\bin\imageformats
  209. xcopy /S /Y /I %BUILDDIR_INSTALL%\plugins\imageformats %pkg_root%\bin\imageformats
  210. xcopy /S /Y /I %BUILDDIR_INSTALL%\lib\plugins\kf5 %pkg_root%\bin\kf5
  211. xcopy /S /Y /I %BUILDDIR_INSTALL%\plugins\kf5 %pkg_root%\bin\kf5
  212. :: Qt Translations
  213. :: it seems that windeployqt does these, but only *some* of these???
  214. mkdir %pkg_root%\bin\translations
  215. setlocal enableextensions enabledelayedexpansion
  216. for /f "delims=" %%F in ('dir /b "%BUILDDIR_INSTALL%\translations\qt_*.qm"') do (
  217. :: Exclude qt_help_*.qm
  218. set temp=%%F
  219. set temp2=!temp:_help=!
  220. if x!temp2! == x!temp! copy %BUILDDIR_INSTALL%\translations\!temp! %pkg_root%\bin\translations\!temp!
  221. )
  222. endlocal
  223. :: Krita plugins
  224. xcopy /Y %BUILDDIR_INSTALL%\lib\kritaplugins\*.dll %pkg_root%\lib\kritaplugins\
  225.  
  226. :: Share
  227. xcopy /Y /S /I %BUILDDIR_INSTALL%\share\color %pkg_root%\share\color
  228. xcopy /Y /S /I %BUILDDIR_INSTALL%\share\color-schemes %pkg_root%\share\color-schemes
  229. xcopy /Y /S /I %BUILDDIR_INSTALL%\share\icons %pkg_root%\share\icons
  230. xcopy /Y /S /I %BUILDDIR_INSTALL%\share\kf5 %pkg_root%\share\kf5
  231. xcopy /Y /S /I %BUILDDIR_INSTALL%\share\krita %pkg_root%\share\krita
  232. xcopy /Y /S /I %BUILDDIR_INSTALL%\share\kritaplugins %pkg_root%\share\kritaplugins
  233. xcopy /Y /S /I %BUILDDIR_INSTALL%\share\mime %pkg_root%\share\mime
  234. :: Not useful on Windows it seems
  235. rem xcopy /Y /S /I %BUILDDIR_INSTALL%\share\appdata %pkg_root%\share\appdata
  236. rem xcopy /Y /S /I %BUILDDIR_INSTALL%\share\applications %pkg_root%\share\applications
  237. rem xcopy /Y /S /I %BUILDDIR_INSTALL%\share\doc %pkg_root%\share\doc
  238. rem xcopy /Y /S /I %BUILDDIR_INSTALL%\share\kservices5 %pkg_root%\share\kservices5
  239. rem xcopy /Y /S /I %BUILDDIR_INSTALL%\share\man %pkg_root%\share\man
  240. rem xcopy /Y /S /I %BUILDDIR_INSTALL%\share\ocio %pkg_root%\share\ocio
  241.  
  242. :: Copy locale to bin
  243. xcopy /Y /S /I %BUILDDIR_INSTALL%\share\locale %pkg_root%\bin\locale
  244.  
  245. :: Copy shortcut link from source (can't create it dynamically)
  246. copy %BUILDDIR_SRC%\packaging\windows\krita.lnk %pkg_root%
  247.  
  248. :: windeployqt
  249. %BUILDDIR_INSTALL%\bin\windeployqt.exe --release -concurrent -network -printsupport -svg -xml -multimedia %pkg_root%\bin\krita.exe
  250.  
  251. c:\dev\signtool.exe sign /f krita.pfx /p PASSWORD %pkg_root%\bin\*.exe
  252. c:\dev\signtool.exe sign /f krita.pfx /p PASSWORD %pkg_root%\bin\*.dll
  253. c:\dev\signtool.exe sign /f krita.pfx /p PASSWORD %pkg_root%\lib\kritaplugins\*.dll
  254.  
  255. :: For chopping relative path
  256. :: 512 should be enough
  257. :: n+2 to also account for a trailing backslash
  258. setlocal enableextensions enabledelayedexpansion
  259. for /L %%n in (1 1 512) do if "!pkg_root:~%%n,1!" neq "" set /a "pkg_root_len_plus_one=%%n+2"
  260. endlocal & set pkg_root_len_plus_one=%pkg_root_len_plus_one%
  261.  
  262. echo.
  263. echo Splitting debug info from binaries...
  264. call :split-debug "%pkg_root%\bin\krita.exe" bin\krita.exe
  265. setlocal enableextensions enabledelayedexpansion
  266. :: Find all DLLs
  267. for /r "%pkg_root%" %%F in (*.dll) do (
  268. set relpath=%%F
  269. set relpath=!relpath:~%pkg_root_len_plus_one%!
  270. call :split-debug "%%F" !relpath!
  271. )
  272. endlocal
  273.  
  274. echo.
  275. echo Packaging debug info...
  276. :: (note that the top-level package dir is not included)
  277. %SEVENZIP_EXE% a -tzip %pkg_name%-dbg.zip -r %pkg_root%\*.debug
  278. echo --------
  279.  
  280. echo.
  281. echo Packaging stripped binaries...
  282. %SEVENZIP_EXE% a -tzip %pkg_name%.zip %pkg_root%\ -xr!.debug
  283. echo --------
  284.  
  285. echo.
  286. echo.
  287. echo Krita packaged as %pkg_name%.zip
  288. if exist %pkg_name%-dbg.zip echo Debug info packaged as %pkg_name%-dbg.zip
  289. echo Packaging dir is %pkg_root%
  290. echo NOTE: Do not create installer with packaging dir unless you removed all debug
  291. echo info from it!
  292. echo.
  293. echo Please remember to actually test the package before releasing it.
  294. echo.
  295. %PAUSE%
  296.  
  297. exit /b
  298.  
  299. :split-debug
  300. echo Splitting debug info of %2
  301. objcopy --only-keep-debug %~1 %~1.debug
  302. if ERRORLEVEL 1 exit /b %ERRORLEVEL%
  303. :: If the debug file is small enough then consider there being no debug info.
  304. :: Discard these files since they somehow make gdb crash.
  305. call :getfilesize %~1.debug
  306. if /i %getfilesize_retval% LEQ 2048 (
  307. echo Discarding %2.debug
  308. del %~1.debug
  309. exit /b 0
  310. )
  311. if not exist %~dp1.debug mkdir %~dp1.debug
  312. move %~1.debug %~dp1.debug\ > NUL
  313. strip %~1
  314. :: Add debuglink
  315. :: FIXME: There is a problem with gdb that cause it to output this warning
  316. :: FIXME: "warning: section .gnu_debuglink not found in xxx.debug"
  317. :: FIXME: I tried adding a link to itself but this kills drmingw :(
  318. objcopy --add-gnu-debuglink="%~dp1.debug\%~nx1.debug" %~1
  319. exit /b %ERRORLEVEL%
  320.  
  321. :getfilesize
  322. set getfilesize_retval=%~z1
  323. goto :eof
  324.  
  325. :relpath_dirpath
  326. call :relpath_dirpath_internal "" "%~1"
  327. goto :eof
  328.  
  329. :relpath_dirpath_internal
  330. for /f "tokens=1* delims=\" %%a in ("%~2") do (
  331. :: If part 2 is empty, it means part 1 is probably the file name
  332. if x%%b==x (
  333. set relpath_dirpath_retval=%~1
  334. ) else (
  335. call :relpath_dirpath_internal "%~1%%a\" %%b
  336. )
  337. )
  338. goto :eof
  339.  
  340.  
  341. Installer:
  342.  
  343. "C:\Program Files (x86)\NSIS\makensis.exe" ^
  344. /DKRITA_INSTALLER_64 ^
  345. /DKRITA_VERSION=3.2.0.6 ^
  346. /DKRITA_VERSION_DISPLAY="3.2.0.6" ^
  347. /DKRITA_INSTALLER_OUTPUT_DIR="" ^
  348. /DKRITA_INSTALLER_OUTPUT_NAME="krita-3.2.0-x64-setup.exe" ^
  349. /DKRITA_PACKAGE_ROOT="c:\dev\krita-3.2.0-x64" ^
  350. /X"SetCompressor /SOLID lzma" ^
  351. installer_krita.nsi
  352. cd c:\dev
  353. c:\dev\signtool.exe sign /f krita.pfx /p PASSWORD KritaShellExtension\installer\nsis\krita-3.2.0-x64-setup.exe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement