win-standalone-build.cmd 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. set PATH=%PATH%;C:\WINDOWS;C:\WINDOWS\SYSTEM32
  4. for /D %%f in ( "C:\PYTHON*" ) do set PATH=!PATH!;%%f
  5. for /D %%f in ( "%USERPROFILE%\AppData\Local\Programs\Python\Python*" ) do set PATH=!PATH!;%%f;%%f\Scripts
  6. set PATH=%PATH%;%ProgramFiles%\7-Zip
  7. set version=0.1
  8. set project=piccol
  9. set distdir=%project%-win64-standalone-%version%
  10. set sfxfile=%project%-win64-%version%.package.exe
  11. set bindirname=%project%-bin
  12. set bindir=%distdir%\%bindirname%
  13. set licensedirname=licenses
  14. set licensedir=%distdir%\%licensedirname%
  15. echo Building standalone Windows executable for %project% v%version%...
  16. echo.
  17. echo Please select GUI framework:
  18. echo 1) Build with PyQt5 (default)
  19. echo 2) Build with PySide4
  20. set /p framework=Selection:
  21. if "%framework%" == "" goto framework_pyqt5
  22. if "%framework%" == "1" goto framework_pyqt5
  23. if "%framework%" == "2" goto framework_pyside4
  24. echo "Error: Invalid selection"
  25. goto error
  26. :framework_pyqt5
  27. echo Using PyQt5
  28. set excludes=PySide
  29. goto select_freezer
  30. :framework_pyside4
  31. echo Using PySide4
  32. set excludes=PyQt5
  33. goto select_freezer
  34. :select_freezer
  35. echo.
  36. echo Please select freezer:
  37. echo 1) Build 'cx_Freeze' based distribution (default)
  38. echo 2) Build 'py2exe' based distribution
  39. set /p buildtype=Selection:
  40. if "%buildtype%" == "" goto build_cxfreeze
  41. if "%buildtype%" == "1" goto build_cxfreeze
  42. if "%buildtype%" == "2" goto build_py2exe
  43. echo "Error: Invalid selection"
  44. goto error
  45. :build_cxfreeze
  46. set buildtype=1
  47. echo === Creating the cx_Freeze distribution
  48. call :prepare_env
  49. py setup.py build_exe ^
  50. --build-exe=%bindir% ^
  51. --excludes=%excludes% ^
  52. --silent
  53. if ERRORLEVEL 1 goto error_exe
  54. goto copy_files
  55. :build_py2exe
  56. set buildtype=2
  57. echo === Creating the py2exe distribution
  58. call :prepare_env
  59. py setup.py py2exe ^
  60. --dist-dir=%bindir% ^
  61. --bundle-files=3 ^
  62. --ignores=win32api,win32con,readline ^
  63. --excludes=%excludes% ^
  64. --quiet
  65. if ERRORLEVEL 1 goto error_exe
  66. goto copy_files
  67. :copy_files
  68. echo === Copying additional files
  69. mkdir %licensedir%
  70. if ERRORLEVEL 1 goto error_copy
  71. copy README.* %distdir%\
  72. if ERRORLEVEL 1 goto error_copy
  73. copy foreign-licenses\*.txt %licensedir%\
  74. if ERRORLEVEL 1 goto error_copy
  75. copy COPYING %licensedir%\%project%-LICENSE.txt
  76. if ERRORLEVEL 1 goto error_copy
  77. echo === Generating startup wrapper
  78. set wrapper=%distdir%\%project%.cmd
  79. echo @set PATH=%bindirname%;%%PATH%%> %wrapper%
  80. echo @start %project%-bin\%project%.exe %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>> %wrapper%
  81. if ERRORLEVEL 1 goto error_wrapper
  82. echo === Creating the distribution archive
  83. 7z a -mx=9 -sfx7z.sfx %sfxfile% %distdir%
  84. if ERRORLEVEL 1 goto error_7z
  85. echo ---
  86. echo finished
  87. pause
  88. exit /B 0
  89. :prepare_env
  90. echo === Preparing distribution environment
  91. rd /S /Q build 2>NUL
  92. rd /S /Q %distdir% 2>NUL
  93. del %sfxfile% 2>NUL
  94. timeout /T 2 /NOBREAK >NUL
  95. mkdir %distdir%
  96. if ERRORLEVEL 1 goto error_prep
  97. mkdir %bindir%
  98. if ERRORLEVEL 1 goto error_prep
  99. exit /B 0
  100. :error_prep
  101. echo FAILED to prepare environment
  102. goto error
  103. :error_exe
  104. echo FAILED to build exe
  105. goto error
  106. :error_copy
  107. echo FAILED to copy files
  108. goto error
  109. :error_wrapper
  110. echo FAILED to create wrapper
  111. goto error
  112. :error_7z
  113. echo FAILED to create archive
  114. goto error
  115. :error
  116. pause
  117. exit 1