win-standalone-build.cmd 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. @echo off
  2. rem
  3. rem Windows frozen package build script
  4. rem
  5. rem Copyright 2012-2019 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=piccol
  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. call :detect_version
  28. if "%PROCESSOR_ARCHITECTURE%" == "x86" (
  29. set winprefix=win32
  30. ) else (
  31. set winprefix=win64
  32. )
  33. set distdir=%project%-%winprefix%-standalone-%version%
  34. set sfxfile=%project%-%winprefix%-%version%.package.exe
  35. set bindirname=%project%-bin
  36. set bindir=%distdir%\%bindirname%
  37. set builddir=%bindir%\build
  38. set licensedirname=licenses
  39. set licensedir=%distdir%\%licensedirname%
  40. echo Building standalone Windows executable for %project% v%version%...
  41. echo.
  42. call :prepare_env
  43. call :build_cxfreeze
  44. call :copy_files
  45. call :gen_startup_wrapper
  46. call :make_archive
  47. echo ---
  48. echo finished
  49. pause
  50. exit /B 0
  51. :detect_version
  52. py -c "import re; print(re.match(r'.*^\s*PICCOL_VERSION\s*=\s*\"([\w\d\.\-_]+)\"\s*$.*', open('piccol').read(), re.DOTALL | re.MULTILINE).group(1))" > version.txt
  53. if ERRORLEVEL 1 goto error_version
  54. set /p version= < version.txt
  55. del version.txt
  56. exit /B 0
  57. :prepare_env
  58. echo === Preparing distribution environment
  59. rd /S /Q build 2>NUL
  60. rd /S /Q %distdir% 2>NUL
  61. del %sfxfile% 2>NUL
  62. timeout /T 2 /NOBREAK >NUL
  63. mkdir %distdir%
  64. if ERRORLEVEL 1 goto error_prep
  65. mkdir %bindir%
  66. if ERRORLEVEL 1 goto error_prep
  67. exit /B 0
  68. :build_cxfreeze
  69. echo === Creating the cx_Freeze distribution
  70. py setup.py ^
  71. build ^
  72. --build-base=%builddir% ^
  73. build_exe ^
  74. --build-exe=%bindir%
  75. if ERRORLEVEL 1 goto error_exe
  76. exit /B 0
  77. :copy_files
  78. echo === Copying additional files
  79. mkdir %licensedir%
  80. if ERRORLEVEL 1 goto error_copy
  81. copy README.* %distdir%\
  82. if ERRORLEVEL 1 goto error_copy
  83. copy foreign-licenses\*.txt %licensedir%\
  84. if ERRORLEVEL 1 goto error_copy
  85. copy COPYING %licensedir%\%project%-LICENSE.txt
  86. if ERRORLEVEL 1 goto error_copy
  87. exit /B 0
  88. :gen_startup_wrapper
  89. echo === Generating startup wrapper
  90. set wrapper=%distdir%\%project%.cmd
  91. echo @set PATH=%bindirname%;%bindirname%\lib;%bindirname%\platforms;%bindirname%\imageformats;%%PATH%% > %wrapper%
  92. echo @start %project%-bin\%project%.exe %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 >> %wrapper%
  93. if ERRORLEVEL 1 goto error_wrapper
  94. exit /B 0
  95. :make_archive
  96. echo === Creating the distribution archive
  97. 7z a -mx=9 -sfx7z.sfx %sfxfile% %distdir%
  98. if ERRORLEVEL 1 goto error_7z
  99. exit /B 0
  100. :error_basedir
  101. echo FAILED to CD to base directory
  102. goto error
  103. :error_version
  104. echo FAILED to detect version
  105. goto error
  106. :error_prep
  107. echo FAILED to prepare environment
  108. goto error
  109. :error_exe
  110. echo FAILED to build exe
  111. goto error
  112. :error_copy
  113. echo FAILED to copy files
  114. goto error
  115. :error_wrapper
  116. echo FAILED to create wrapper
  117. goto error
  118. :error_7z
  119. echo FAILED to create archive
  120. goto error
  121. :error
  122. pause
  123. exit 1