win-standalone-build.cmd 5.2 KB

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