win-standalone-build.cmd 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 bindirname=awlsim-bin
  12. set bindir=%distdir%\%bindirname%
  13. set licensedirname=licenses
  14. set licensedir=%distdir%\%licensedirname%
  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. 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. --optimize=2 ^
  52. --excludes=%excludes% ^
  53. --silent
  54. if ERRORLEVEL 1 goto error_exe
  55. goto copy_files
  56. :build_py2exe
  57. set buildtype=2
  58. echo === Creating the py2exe distribution
  59. call :prepare_env
  60. py setup.py py2exe ^
  61. --dist-dir=%bindir% ^
  62. --optimize=2 ^
  63. --bundle-files=3 ^
  64. --ignores=win32api,win32con,readline,awlsim_cython ^
  65. --excludes=%excludes% ^
  66. --packages=awlsimhw_debug,awlsimhw_dummy,awlsim.library.iec ^
  67. --quiet
  68. if ERRORLEVEL 1 goto error_exe
  69. goto copy_files
  70. :copy_files
  71. echo === Copying additional files
  72. mkdir %licensedir%
  73. if ERRORLEVEL 1 goto error_copy
  74. copy examples\EXAMPLE.awlpro %distdir%\
  75. if ERRORLEVEL 1 goto error_copy
  76. copy README.* %distdir%\
  77. if ERRORLEVEL 1 goto error_copy
  78. copy COMPATIBILITY.* %distdir%\
  79. if ERRORLEVEL 1 goto error_copy
  80. copy TODO.* %distdir%\
  81. if ERRORLEVEL 1 goto error_copy
  82. copy doc\foreign-licenses\*.txt %licensedir%\
  83. if ERRORLEVEL 1 goto error_copy
  84. copy COPYING.txt %licensedir%\AWLSIM-LICENSE.txt
  85. if ERRORLEVEL 1 goto error_copy
  86. for /D %%f in ( "progs\putty\*" ) do (
  87. copy %%f\putty\PUTTY.EXE %bindir%\
  88. if ERRORLEVEL 1 goto error_copy
  89. copy %%f\putty\PLINK.EXE %bindir%\
  90. if ERRORLEVEL 1 goto error_copy
  91. copy %%f\LICENCE %licensedir%\PUTTY-LICENSE.txt
  92. if ERRORLEVEL 1 goto error_copy
  93. )
  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.cmd
  100. echo @set PATH=%bindirname%;%%PATH%%> %wrapper%
  101. echo @start awlsim-bin\awlsim-gui.exe %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>> %wrapper%
  102. if ERRORLEVEL 1 goto error_wrapper
  103. echo === Creating the distribution archive
  104. 7z a -mx=9 -sfx7z.sfx %sfxfile% %distdir%
  105. if ERRORLEVEL 1 goto error_7z
  106. echo ---
  107. echo finished
  108. pause
  109. exit /B 0
  110. :prepare_env
  111. echo === Preparing distribution environment
  112. rd /S /Q build 2>NUL
  113. rd /S /Q %distdir% 2>NUL
  114. del %sfxfile% 2>NUL
  115. timeout /T 2 /NOBREAK >NUL
  116. mkdir %distdir%
  117. if ERRORLEVEL 1 goto error_prep
  118. mkdir %bindir%
  119. if ERRORLEVEL 1 goto error_prep
  120. exit /B 0
  121. :error_prep
  122. echo FAILED to prepare environment
  123. goto error
  124. :error_exe
  125. echo FAILED to build exe
  126. goto error
  127. :error_copy
  128. echo FAILED to copy files
  129. goto error
  130. :error_wrapper
  131. echo FAILED to create wrapper
  132. goto error
  133. :error_7z
  134. echo FAILED to create archive
  135. goto error
  136. :error
  137. pause
  138. exit 1