win-standalone-build.cmd 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. @echo off
  2. rem
  3. rem Copyright 2022 Michael Buesch <m@bues.ch>
  4. rem
  5. rem This program is free software; you can redistribute it and/or modify
  6. rem it under the terms of the GNU General Public License as published by
  7. rem the Free Software Foundation; either version 2 of the License, or
  8. rem (at your option) any later version.
  9. rem
  10. rem This program is distributed in the hope that it will be useful,
  11. rem but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. rem MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. rem GNU General Public License for more details.
  14. rem
  15. rem You should have received a copy of the GNU General Public License along
  16. rem with this program; if not, write to the Free Software Foundation, Inc.,
  17. rem 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. rem
  19. setlocal ENABLEDELAYEDEXPANSION
  20. set project=partmgr
  21. set PATH=%PATH%;C:\WINDOWS;C:\WINDOWS\SYSTEM32
  22. for /D %%f in ( "C:\PYTHON*" ) do set PATH=!PATH!;%%f
  23. for /D %%f in ( "%USERPROFILE%\AppData\Local\Programs\Python\Python*" ) do set PATH=!PATH!;%%f;%%f\Scripts
  24. set PATH=%PATH%;%ProgramFiles%\7-Zip
  25. cd ..
  26. if ERRORLEVEL 1 goto error_basedir
  27. call :detect_version
  28. if "%PROCESSOR_ARCHITECTURE%" == "x86" (
  29. set winprefix=win32
  30. ) else (
  31. set winprefix=win64
  32. )
  33. set distdir=%project%-%winprefix%-standalone-%version%
  34. set sfxfile=%project%-%winprefix%-%version%.package.exe
  35. set bindirname=%project%-bin
  36. set bindir=%distdir%\%bindirname%
  37. set builddir=%bindir%\build
  38. set licensedirname=licenses
  39. set licensedir=%distdir%\%licensedirname%
  40. echo Building standalone Windows executable for %project%-%version%
  41. call :prepare_env
  42. call :build_cxfreeze
  43. rem call :build_doc
  44. call :copy_files
  45. call :gen_startup_wrapper
  46. call :make_archive
  47. echo ---
  48. echo finished
  49. pause
  50. exit /B 0
  51. :detect_version
  52. py -c "from partmgr.core.version import VERSION_STRING; print(VERSION_STRING)" > version.txt
  53. if ERRORLEVEL 1 goto error_version
  54. set /p version= < version.txt
  55. del version.txt
  56. exit /B 0
  57. :prepare_env
  58. echo === Preparing distribution environment
  59. rd /S /Q build 2>NUL
  60. rd /S /Q %distdir% 2>NUL
  61. del %sfxfile% 2>NUL
  62. timeout /T 2 /NOBREAK >NUL
  63. mkdir %distdir%
  64. if ERRORLEVEL 1 goto error_prep
  65. mkdir %bindir%
  66. if ERRORLEVEL 1 goto error_prep
  67. exit /B 0
  68. :build_cxfreeze
  69. echo === Creating the cx_Freeze distribution
  70. py setup.py ^
  71. build ^
  72. --build-base=%builddir% ^
  73. build_exe ^
  74. --build-exe=%bindir%
  75. if ERRORLEVEL 1 goto error_exe
  76. exit /B 0
  77. :build_doc
  78. for %%i in (*.rst) do (
  79. echo Generating %%~ni.html from %%i ...
  80. py -m readme_renderer -o %%~ni.html %%i
  81. if ERRORLEVEL 1 goto error_doc
  82. )
  83. exit /B 0
  84. :copy_files
  85. echo === Copying additional files
  86. mkdir %licensedir%
  87. if ERRORLEVEL 1 goto error_copy
  88. rem copy *.html %distdir%\
  89. rem if ERRORLEVEL 1 goto error_copy
  90. rem xcopy /E /I doc %distdir%\doc
  91. rem if ERRORLEVEL 1 goto error_copy
  92. rem rmdir /S /Q %distdir%\doc\foreign-licenses
  93. rem if ERRORLEVEL 1 goto error_copy
  94. copy doc\foreign-licenses\*.txt %licensedir%\
  95. if ERRORLEVEL 1 goto error_copy
  96. copy COPYING %licensedir%\PARTMGR-LICENSE.txt
  97. if ERRORLEVEL 1 goto error_copy
  98. rd /S /Q %builddir%
  99. if ERRORLEVEL 1 goto error_copy
  100. exit /B 0
  101. :gen_startup_wrapper
  102. echo === Generating startup wrapper
  103. set wrapper=%distdir%\%project%.cmd
  104. echo @set PATH=%bindirname%;%bindirname%\lib;%bindirname%\platforms;%bindirname%\imageformats;%%PATH%% > %wrapper%
  105. echo @start %project%-bin\partmgr-gui.exe %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >> %wrapper%
  106. if ERRORLEVEL 1 goto error_wrapper
  107. exit /B 0
  108. :make_archive
  109. echo === Creating the distribution archive
  110. 7z a -mx=9 -sfx7z.sfx %sfxfile% %distdir%
  111. if ERRORLEVEL 1 goto error_7z
  112. exit /B 0
  113. :error_basedir
  114. echo FAILED to CD to base directory
  115. goto error
  116. :error_version
  117. echo FAILED to detect version
  118. goto error
  119. :error_prep
  120. echo FAILED to prepare environment
  121. goto error
  122. :error_exe
  123. echo FAILED to build exe
  124. goto error
  125. :error_doc
  126. echo FAILED to build doc
  127. goto error
  128. :error_copy
  129. echo FAILED to copy files
  130. goto error
  131. :error_wrapper
  132. echo FAILED to create wrapper
  133. goto error
  134. :error_7z
  135. echo FAILED to create archive
  136. goto error
  137. :error
  138. pause
  139. exit 1