119 lines
3.6 KiB
Batchfile
119 lines
3.6 KiB
Batchfile
@echo off
|
|
setlocal
|
|
cd /d "%~dp0"
|
|
|
|
REM Note, this script uses XP-friendly settings.
|
|
REM Needs curl: https://curl.se/windows/ - Extract in your %path% or here.
|
|
REM
|
|
REM If something doesn't work, delete the build folder.
|
|
|
|
REM Check prerequisites
|
|
echo -- Checking prerequisites:
|
|
echo|set /p="curl: "
|
|
where curl
|
|
if "%errorlevel%" == "1" goto exit
|
|
echo.
|
|
|
|
REM Universal build settings
|
|
set "build-home=%cd%"
|
|
set "build-folder=%cd%\build"
|
|
set "build-pip=https://bootstrap.pypa.io/pip/3.4/get-pip.py"
|
|
if not exist "%build-folder%" mkdir "%build-folder%"
|
|
|
|
REM Check if OS is 32-bit or 64-bit
|
|
set 64bit=0
|
|
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" set 64bit=1
|
|
if "%PROCESSOR_ARCHITEW6432%" == "AMD64" set 64bit=1
|
|
|
|
REM Build 32-bit version
|
|
echo -- Building (32-bit):
|
|
set "build-arch=x86"
|
|
set "build-python=https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi"
|
|
set "build-modules="pefile==2019.4.18" "PyInstaller==3.4" "pypiwin32==219" "pillow" "QtPy" "PySide""
|
|
set "build-output=%build-folder%\%build-arch%"
|
|
call :prebuild
|
|
call :build
|
|
echo.
|
|
|
|
REM Build 64-bit version
|
|
if "%64bit%" == "0" goto exit
|
|
echo -- Building (64-bit):
|
|
set "build-arch=AMD64"
|
|
set "build-python=https://www.python.org/ftp/python/3.4.4/python-3.4.4.amd64.msi"
|
|
set "build-modules="pefile==2019.4.18" "PyInstaller==3.4" "pypiwin32==219" "pillow" "QtPy""
|
|
set "build-output=%build-folder%\%build-arch%"
|
|
call :prebuild
|
|
call :downloadFile "https://download.qt.io/official_releases/pyside/PySide-1.2.4-cp34-none-win_amd64.whl" "%build-output%\PySide-1.2.4-cp34-none-win_amd64.whl"
|
|
call :python -m pip install "%build-output%\PySide-1.2.4-cp34-none-win_amd64.whl"
|
|
call :build
|
|
|
|
REM All done
|
|
echo.
|
|
goto exit
|
|
|
|
REM Ready prerequisites and folder structure
|
|
:prebuild
|
|
setlocal
|
|
set "build-downloadpython=1"
|
|
set "path=%build-output%\python;%path%"
|
|
if not exist "%build-output%" mkdir "%build-output%"
|
|
if exist "%build-output%\python\python.exe" (
|
|
set build-downloadpython=0
|
|
) else (
|
|
set build-downloadpython=1
|
|
)
|
|
|
|
if "%build-downloadpython%" == "1" (
|
|
echo Downloading Python...
|
|
if exist "%build-output%\python" rmdir /s /q "%build-output%\python"
|
|
call :downloadFile "%build-python%" "%build-output%\python.msi"
|
|
call :downloadFile "%build-pip%" "%build-output%\get-pip.py"
|
|
msiexec /a "%build-output%\python.msi" /qb targetdir="%build-output%\python"
|
|
|
|
echo.
|
|
echo Installing pip...
|
|
call :python "%build-output%\get-pip.py"
|
|
)
|
|
|
|
echo Installing prerequisites...
|
|
call :python -m pip install %build-modules%
|
|
exit /b
|
|
|
|
REM Compile executable
|
|
:build
|
|
setlocal
|
|
if not exist "%build-output%\pyinstaller" mkdir "%build-output%\pyinstaller"
|
|
cd /d "%build-output%\pyinstaller"
|
|
call :python -m PyInstaller "%build-home%\batchprint.pyw" --onefile --noconsole
|
|
cd /d "%build-home%"
|
|
if exist "__pycache__" rmdir /s /q "__pycache__"
|
|
if exist "%build-output%\dist" rmdir /s /q "%build-output%\dist"
|
|
|
|
move "%build-output%\pyinstaller\dist" "%build-output%\dist"
|
|
mkdir "%build-output%\dist\src"
|
|
|
|
copy "LICENSE" "%build-output%\dist"
|
|
copy "README.md" "%build-output%\dist"
|
|
xcopy "docs" "%build-output%\dist\docs" /h /i /c /k /e /r /y
|
|
|
|
copy "LICENSE" "%build-output%\dist\src"
|
|
copy "README.md" "%build-output%\dist\src"
|
|
xcopy "docs" "%build-output%\dist\src\docs" /h /i /c /k /e /r /y
|
|
copy "batchprint.pyw" "%build-output%\dist\src"
|
|
exit /b
|
|
|
|
REM Download file
|
|
:downloadFile
|
|
if exist "%~2" exit /b 0
|
|
if exist "%~2.tmp" del /f /q "%~2.tmp"
|
|
curl -L "%~1" --output "%~2.tmp"
|
|
move "%~2.tmp" "%~2"
|
|
exit /b %errorlevel%
|
|
|
|
REM Run build-specific python
|
|
:python
|
|
call "%build-output%\python\python.exe" %*
|
|
exit /b %errorlevel%
|
|
|
|
:exit
|
|
pause |