win-standalone-build.cmd 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. @echo off
  2. setlocal ENABLEDELAYEDEXPANSION
  3. set project=awlsim
  4. set PATH=%PATH%;C:\WINDOWS;C:\WINDOWS\SYSTEM32
  5. for /D %%f in ( "C:\PYTHON*" ) do set PATH=!PATH!;%%f
  6. for /D %%f in ( "%USERPROFILE%\AppData\Local\Programs\Python\Python*" ) do set PATH=!PATH!;%%f;%%f\Scripts
  7. set PATH=%PATH%;%ProgramFiles%\7-Zip
  8. cd ..
  9. if ERRORLEVEL 1 goto error_basedir
  10. py -c "from awlsim.common.version import VERSION_STRING; print(VERSION_STRING)" > version.txt
  11. if ERRORLEVEL 1 goto error_version
  12. set /p version= < version.txt
  13. del version.txt
  14. if "%PROCESSOR_ARCHITECTURE%" == "x86" (
  15. set winprefix=win32
  16. ) else (
  17. set winprefix=win64
  18. )
  19. set distdir=%project%-%winprefix%-standalone-%version%
  20. set sfxfile=%project%-%winprefix%-%version%.package.exe
  21. set bindirname=%project%-bin
  22. set bindir=%distdir%\%bindirname%
  23. set licensedirname=licenses
  24. set licensedir=%distdir%\%licensedirname%
  25. echo Building standalone Windows executable for %project% v%version%...
  26. echo.
  27. echo Please select GUI framework:
  28. echo 1) Build with PyQt5 (default)
  29. echo 2) Build with PySide4
  30. set /p framework=Selection:
  31. if "%framework%" == "" goto framework_pyqt5
  32. if "%framework%" == "1" goto framework_pyqt5
  33. if "%framework%" == "2" goto framework_pyside4
  34. echo "Error: Invalid selection"
  35. goto error
  36. :framework_pyqt5
  37. echo Using PyQt5
  38. set excludes=PySide
  39. goto select_freezer
  40. :framework_pyside4
  41. echo Using PySide4
  42. set excludes=PyQt5
  43. goto select_freezer
  44. :select_freezer
  45. echo.
  46. echo Please select freezer:
  47. echo 1) Build 'cx_Freeze' based distribution (default)
  48. echo 2) Build 'py2exe' based distribution
  49. set /p buildtype=Selection:
  50. if "%buildtype%" == "" goto build_cxfreeze
  51. if "%buildtype%" == "1" goto build_cxfreeze
  52. if "%buildtype%" == "2" goto build_py2exe
  53. echo "Error: Invalid selection"
  54. goto error
  55. :build_cxfreeze
  56. set buildtype=1
  57. echo === Creating the cx_Freeze distribution
  58. call :prepare_env
  59. py setup.py build_exe ^
  60. --build-exe=%bindir% ^
  61. --excludes=%excludes% ^
  62. --silent
  63. if ERRORLEVEL 1 goto error_exe
  64. goto copy_files
  65. :build_py2exe
  66. set buildtype=2
  67. echo === Creating the py2exe distribution
  68. call :prepare_env
  69. py setup.py py2exe ^
  70. --dist-dir=%bindir% ^
  71. --bundle-files=3 ^
  72. --ignores=win32api,win32con,readline,awlsim_cython ^
  73. --excludes=%excludes% ^
  74. --packages=awlsimhw_debug,awlsimhw_dummy,awlsimhw_linuxcnc,awlsimhw_pyprofibus,awlsimhw_rpigpio,awlsimhw_pixtend,awlsim.library.iec ^
  75. --quiet
  76. if ERRORLEVEL 1 goto error_exe
  77. goto copy_files
  78. :copy_files
  79. echo === Copying additional files
  80. mkdir %licensedir%
  81. if ERRORLEVEL 1 goto error_copy
  82. copy examples\EXAMPLE.awlpro %distdir%\
  83. if ERRORLEVEL 1 goto error_copy
  84. copy README.* %distdir%\
  85. if ERRORLEVEL 1 goto error_copy
  86. copy COMPATIBILITY.* %distdir%\
  87. if ERRORLEVEL 1 goto error_copy
  88. copy TODO.* %distdir%\
  89. if ERRORLEVEL 1 goto error_copy
  90. copy QUICK-START.* %distdir%\
  91. if ERRORLEVEL 1 goto error_copy
  92. xcopy /E /I doc %distdir%\doc
  93. if ERRORLEVEL 1 goto error_copy
  94. rmdir /S /Q %distdir%\doc\foreign-licenses
  95. if ERRORLEVEL 1 goto error_copy
  96. copy doc\foreign-licenses\*.txt %licensedir%\
  97. if ERRORLEVEL 1 goto error_copy
  98. copy COPYING.txt %licensedir%\AWLSIM-LICENSE.txt
  99. if ERRORLEVEL 1 goto error_copy
  100. for /D %%f in ( "progs\putty\*" ) do (
  101. copy %%f\putty\PUTTY.EXE %bindir%\
  102. if ERRORLEVEL 1 goto error_copy
  103. copy %%f\putty\PLINK.EXE %bindir%\
  104. if ERRORLEVEL 1 goto error_copy
  105. copy %%f\LICENCE %licensedir%\PUTTY-LICENSE.txt
  106. if ERRORLEVEL 1 goto error_copy
  107. )
  108. if %buildtype% == 1 goto no_servermod_rename
  109. move %bindir%\server.exe %bindir%\awlsim-server-module.exe
  110. if ERRORLEVEL 1 goto error_copy
  111. :no_servermod_rename
  112. echo === Generating startup wrapper
  113. set wrapper=%distdir%\%project%.cmd
  114. echo @set PATH=%bindirname%;%bindirname%\lib;%bindirname%\platforms;%bindirname%\imageformats;%%PATH%%> %wrapper%
  115. echo @start %project%-bin\awlsim-gui.exe %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9>> %wrapper%
  116. if ERRORLEVEL 1 goto error_wrapper
  117. echo === Creating the distribution archive
  118. 7z a -mx=9 -sfx7z.sfx %sfxfile% %distdir%
  119. if ERRORLEVEL 1 goto error_7z
  120. echo ---
  121. echo finished
  122. pause
  123. exit /B 0
  124. :prepare_env
  125. echo === Preparing distribution environment
  126. rd /S /Q build 2>NUL
  127. rd /S /Q %distdir% 2>NUL
  128. del %sfxfile% 2>NUL
  129. timeout /T 2 /NOBREAK >NUL
  130. mkdir %distdir%
  131. if ERRORLEVEL 1 goto error_prep
  132. mkdir %bindir%
  133. if ERRORLEVEL 1 goto error_prep
  134. exit /B 0
  135. :error_basedir
  136. echo FAILED to CD to base directory
  137. goto error
  138. :error_version
  139. echo FAILED to detect version
  140. goto error
  141. :error_prep
  142. echo FAILED to prepare environment
  143. goto error
  144. :error_exe
  145. echo FAILED to build exe
  146. goto error
  147. :error_copy
  148. echo FAILED to copy files
  149. goto error
  150. :error_wrapper
  151. echo FAILED to create wrapper
  152. goto error
  153. :error_7z
  154. echo FAILED to create archive
  155. goto error
  156. :error
  157. pause
  158. exit 1