win-standalone-build.bat 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. set PATH=%PATH%;%ProgramFiles%\7-Zip
  6. py -c "from awlsim.common.version import VERSION_STRING; print(VERSION_STRING)" > version.txt
  7. set /p version= < version.txt
  8. del version.txt
  9. set distdir=awlsim-win-standalone-%version%
  10. set sfxfile=awlsim-win-%version%.package.exe
  11. set bindir=%distdir%\awlsim-bin
  12. rd /S /Q build 2>NUL
  13. rd /S /Q %distdir% 2>NUL
  14. del %sfxfile% 2>NUL
  15. echo Building standalone Windows executable for awlsim 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. pause
  26. exit
  27. :framework_pyqt5
  28. echo Using PyQt5
  29. set excludes=PySide
  30. goto select_freezer
  31. :framework_pyside4
  32. echo Using PySide4
  33. set excludes=PyQt5
  34. goto select_freezer
  35. :select_freezer
  36. echo.
  37. echo Please select freezer:
  38. echo 1) Build 'cx_Freeze' based distribution (default)
  39. echo 2) Build 'py2exe' based distribution
  40. set /p buildtype=Selection:
  41. if "%buildtype%" == "" goto build_cxfreeze
  42. if "%buildtype%" == "1" goto build_cxfreeze
  43. if "%buildtype%" == "2" goto build_py2exe
  44. echo "Error: Invalid selection"
  45. pause
  46. exit
  47. :build_cxfreeze
  48. set buildtype=1
  49. echo === Creating the cx_Freeze distribution
  50. timeout /T 2 /NOBREAK >NUL
  51. mkdir %distdir%
  52. if ERRORLEVEL 1 goto error_prep
  53. mkdir %bindir%
  54. if ERRORLEVEL 1 goto error_prep
  55. py setup.py build_exe ^
  56. --build-exe=%bindir% ^
  57. --optimize=2 ^
  58. --excludes=%excludes% ^
  59. --silent
  60. if ERRORLEVEL 1 goto error_exe
  61. goto copy_files
  62. :build_py2exe
  63. set buildtype=2
  64. echo === Creating the py2exe distribution
  65. timeout /T 2 /NOBREAK >NUL
  66. mkdir %distdir%
  67. if ERRORLEVEL 1 goto error_prep
  68. mkdir %bindir%
  69. if ERRORLEVEL 1 goto error_prep
  70. py setup.py py2exe ^
  71. --dist-dir=%bindir% ^
  72. --optimize=2 ^
  73. --bundle-files=3 ^
  74. --ignores=win32api,win32con,readline,awlsim_cython ^
  75. --excludes=%excludes% ^
  76. --packages=awlsimhw_debug,awlsimhw_dummy,awlsim.library.iec ^
  77. --quiet
  78. if ERRORLEVEL 1 goto error_exe
  79. goto copy_files
  80. :copy_files
  81. echo === Copying additional files
  82. copy examples\EXAMPLE.awlpro %distdir%\
  83. if ERRORLEVEL 1 goto error_copy
  84. copy README.txt %distdir%\
  85. if ERRORLEVEL 1 goto error_copy
  86. copy COMPATIBILITY.txt %distdir%\
  87. if ERRORLEVEL 1 goto error_copy
  88. copy TODO.txt %distdir%\
  89. if ERRORLEVEL 1 goto error_copy
  90. xcopy doc\foreign-licenses %distdir%\licenses\ /E
  91. if ERRORLEVEL 1 goto error_copy
  92. copy COPYING.txt %distdir%\licenses\AWLSIM-LICENSE.txt
  93. if ERRORLEVEL 1 goto error_copy
  94. if %buildtype% == 1 goto no_servermod_rename
  95. move %bindir%\server.exe %bindir%\awlsim-server-module.exe
  96. if ERRORLEVEL 1 goto error_copy
  97. :no_servermod_rename
  98. echo === Generating startup wrapper
  99. set wrapper=%distdir%\awlsim.bat
  100. echo @echo off> %wrapper%
  101. if ERRORLEVEL 1 goto error_wrapper
  102. echo start /Dawlsim-bin awlsim-gui.exe %%1>> %wrapper%
  103. if ERRORLEVEL 1 goto error_wrapper
  104. echo === Creating the distribution archive
  105. 7z a -mx=9 -sfx7z.sfx %sfxfile% %distdir%
  106. if ERRORLEVEL 1 goto error_7z
  107. echo ---
  108. echo finished
  109. pause
  110. exit
  111. :error_prep
  112. echo FAILED to prepare environment
  113. goto error
  114. :error_exe
  115. echo FAILED to build exe
  116. goto error
  117. :error_copy
  118. echo FAILED to copy files
  119. goto error
  120. :error_wrapper
  121. echo FAILED to create wrapper
  122. goto error
  123. :error_7z
  124. echo FAILED to create archive
  125. goto error
  126. :error
  127. pause
  128. exit