Skip to content

Commit

Permalink
Build script major refactoring
Browse files Browse the repository at this point in the history
- before doing anything check the dependencies availability including Meson;
- add code comments;
- improve python 2/3 awareness;
- hard fail if Python or Visual Studio are missing.

Completes #7 tasks 1-2.
  • Loading branch information
pal1000 committed Mar 31, 2018
1 parent 3690b46 commit 5f04ad0
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 68 deletions.
2 changes: 1 addition & 1 deletion buildenvconf.md
Expand Up @@ -17,7 +17,7 @@ Windows 10 SDK install method | standalone
| | |
|-|-|
LLVM Version | 6.0.0
CMake version | 3.10.3
CMake version | 3.11.0
CMake ARCH | x64
Ninja version[4] | 1.8.2
LLVM build configure x64[5] | cd llvm-6.0.0.src & md cmake-x64 & cd cmake-x64 & cmake -G "Visual Studio 15 Win64" -Thost=x64 -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_CRT_RELEASE=MT -DLLVM_ENABLE_RTTI=1 -DLLVM_ENABLE_TERMINFO=OFF -DCMAKE_INSTALL_PREFIX=../x64 ..
Expand Down
173 changes: 108 additions & 65 deletions buildscript/build.cmd
@@ -1,30 +1,74 @@
@TITLE Building Mesa3D

@rem Determine Mesa3D build environment root folder and convert the path to it into DOS 8.3 format to avoid quotes mess.
@cd "%~dp0"
@cd ..\..\
@for %%I in ("%cd%") do @set mesa=%%~sI

@rem Analyze environment. Get each dependency status: 0=missing, 1=standby, 2=loaded manually, 3=preloaded.
@rem Not all dependencies can have all these states.

@rem Search for Visual Studio environment. Hard fail if missing.
@set abi=x86
@set /p x64=Do you want to build for x64? (y/n) Otherwise build for x86:
@if /I "%x64%"=="y" set abi=x64
@set longabi=%abi%
@if %abi%==x64 set longabi=x86_64
@set vsabi=%abi%
@IF /I %PROCESSOR_ARCHITECTURE%==AMD64 IF %abi%==x86 set vsabi=x64_x86
@IF /I %PROCESSOR_ARCHITECTURE%==x86 IF %abi%==x64 set vsabi=x86_x64
@echo %vsabi%
@set vsenv="%ProgramFiles%
@IF /I %PROCESSOR_ARCHITECTURE%==AMD64 set vsenv=%vsenv% (x86)
@set vsenv=%vsenv%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat"
@set toolset=0
@if EXIST %vsenv% set toolset=15
@if %toolset% EQU 0 (
@echo Error: No Visual Studio installed.
@GOTO exit
)
@set vsenv=%vsenv% %vsabi% %*
@TITLE Building Mesa3D %abi%

@rem Python. State restriction: cannot stay in standby since it is used everwhere. Hard fail if is missing.
@SET ERRORLEVEL=0
@SET pythonloc=python.exe
@set pythonstate=3
@where /q python.exe
@IF ERRORLEVEL 1 set PATH=%mesa%\Python\;%PATH%
@SET ERRORLEVEL=0
@where /q python.exe
@IF ERRORLEVEL 1 echo Python is unreachable. Cannot continue.
@SET ERRORLEVEL=0
@where /q python.exe
@IF ERRORLEVEL 1 GOTO exit
@set ERRORLEVEL=0
@set oldpath=%PATH%
@FOR /F "tokens=* USEBACKQ" %%F IN (`where python.exe`) DO @SET pythonloc=%%F
@set pythonloc=%pythonloc:python.exe=%
@IF ERRORLEVEL 1 set pythonloc=%mesa%\python\python.exe
@IF %pythonloc%==%mesa%\python\python.exe set pythonstate=1
@IF %pythonstate%==1 IF NOT EXIST %pythonloc% set pythonstate=0
@IF %pythonstate%==3 FOR /F "tokens=* USEBACKQ" %%a IN (`where python.exe`) DO @SET pythonloc=%%a
@IF %pythonstate%==0 (
@echo Python is unreachable. Cannot continue.
@GOTO exit
)
@IF %pythonstate%==1 (
@SET PATH=%mesa%\python\;%PATH%
@SET pythonstate=2
)

@rem Identify Python version
@set pythonver=2
@IF EXIST "%pythonloc%python3.dll" set pythonver=3
@set pyupd=n
@set makoloc="%pythonloc%Lib\site-packages\mako"
@set mesonloc=meson.exe
@SET ERRORLEVEL=0
@IF EXIST "%pythonloc:python.exe=%python3.dll" set pythonver=3

@rem Look for python modules
@rem Mako - python 2 only
@set makoloc="%pythonloc:python.exe=%Lib\site-packages\mako"

@rem Meson - python 3 only
@SET mesonloc=meson.exe
@set mesonstate=3
@where /q meson.exe
@IF ERRORLEVEL 1 set mesonloc="%pythonloc%Scripts\meson.py"
@if %pythonver% GEQ 3 IF %mesonloc%==meson.exe FOR /F "tokens=* USEBACKQ" %%a IN (`where meson.exe`) DO @SET mesonloc=%%a
@set sconsloc="%pythonloc%Scripts\scons.py"
@IF ERRORLEVEL 1 set mesonloc="%pythonloc:python.exe=%Scripts\meson.py"
@IF %mesonloc%=="%pythonloc:python.exe=%Scripts\meson.py" set mesonstate=2
@IF %mesonstate%==2 IF NOT EXIST %mesonloc% set mesonstate=0

@rem Scons - python 2 only
@set sconsloc="%pythonloc:python.exe=%Scripts\scons.py"

@rem Check for python updates
@set pyupd=n
@if %pythonver% GEQ 3 echo WARNING: Python 3.x support is experimental.
@if %pythonver% GEQ 3 echo.
@if %pythonver%==2 if NOT EXIST %makoloc% (
Expand All @@ -36,7 +80,7 @@
@set pyupd=y
@echo.
)
@if %pythonver% GEQ 3 if NOT EXIST %mesonloc% (
@if %pythonver% GEQ 3 IF %mesonstate%==0 (
@python -m pip install -U setuptools
@python -m pip install -U pip
@python -m pip install -U meson
Expand All @@ -48,29 +92,41 @@
@for /F "delims= " %%i in ('python -m pip list -o --format=legacy') do @if NOT "%%i"=="pywin32" python -m pip install -U "%%i"
@echo.
)
@set abi=x86
@set /p x64=Do you want to build for x64? (y/n) Otherwise build for x86:
@if /I "%x64%"=="y" set abi=x64
@set longabi=%abi%
@if %abi%==x64 set longabi=x86_64
@set minabi=32
@if %abi%==x64 set minabi=64
@set targetabi=x86
@if %abi%==x64 set targetabi=amd64
@set hostabi=x86
@if NOT "%ProgramW6432%"=="" set hostabi=amd64
@set vsabi=%minabi%
@if NOT %targetabi%==%hostabi% set vsabi=%hostabi%_%targetabi%
@set vsenv="%ProgramFiles%
@if NOT "%ProgramW6432%"=="" set vsenv=%vsenv% (x86)
@set vsenv=%vsenv%\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars%vsabi%.bat"
@set toolset=0
@if EXIST %vsenv% set toolset=15
@TITLE Building Mesa3D %abi%
@if %toolset% EQU 0 (
@echo Error: No Visual Studio installed.
@GOTO exit
)

@rem Ninja build system. This is optional
@SET ERRORLEVEL=0
@SET ninjaloc=ninja.exe
@set ninjastate=3
@where /q ninja.exe
@IF ERRORLEVEL 1 set ninjaloc=%mesa%\ninja\ninja.exe
@IF %ninjaloc%==%mesa%\ninja\ninja.exe set ninjastate=1
@IF %ninjastate%==1 IF NOT EXIST %ninjaloc% set ninjastate=0

@rem CMake build generator. Alterntive to Meson
@SET ERRORLEVEL=0
@SET cmakeloc=cmake.exe
@set cmakestate=3
@where /q cmake.exe
@IF ERRORLEVEL 1 set cmakeloc=%mesa%\cmake\bin\cmake.exe
@IF %cmakeloc%==%mesa%\cmake\bin\cmake.exe set cmakestate=1
@IF %cmakestate%==1 IF NOT EXIST %cmakeloc% set cmakestate=0

@rem Git version control
@SET ERRORLEVEL=0
@SET gitloc=git.exe
@set gitstate=3
@where /q git.exe
@IF ERRORLEVEL 1 set gitstate=0

@rem winflexbison
@SET ERRORLEVEL=0
@SET flexloc=win_flex.exe
@set flexstate=3
@where /q win_flex.exe
@IF ERRORLEVEL 1 set flexloc=%mesa%\flexbison\win_flex.exe
@IF %flexloc%==%mesa%\flexbison\win_flex.exe set flexstate=1
@IF %flexstate%==1 IF NOT EXIST %flexloc% set flexstate=0


:build_llvm
@if EXIST %mesa%\llvm set /p buildllvm=Begin LLVM build. Only needs to run once for each ABI and version. Proceed (y/n):
Expand All @@ -83,19 +139,17 @@
@cd cmake-%abi%
@set ninja=n
@set toolchain=Visual Studio %toolset%
@if EXIST %mesa%\ninja set /p ninja=Use Ninja build system instead of MsBuild (y/n); less storage device strain and maybe faster build:
@if EXIST "%ninjaloc%" set /p ninja=Use Ninja build system instead of MsBuild (y/n); less storage device strain and maybe faster build:
@if /I "%ninja%"=="y" set toolchain=Ninja
@if /I "%ninja%"=="y" set PATH=%mesa%\ninja\;%PATH%
@if %abi%==x64 set toolchain=%toolchain% Win64
@if "%toolchain%"=="Ninja Win64" set toolchain=Ninja
@if /I NOT "%ninja%"=="y" if %hostabi%==amd64 set x64compiler= -Thost=x64
@if /I NOT "%ninja%"=="y" IF /I %PROCESSOR_ARCHITECTURE%==AMD64 set x64compiler= -Thost=x64
@set llvmbuildsys=%CD%
@if "%toolchain%"=="Ninja" call %vsenv%
@if "%toolchain%"=="Ninja" cd %llvmbuildsys%
@echo.
@where /q cmake.exe
@IF ERRORLEVEL 1 set PATH=%mesa%\cmake\bin\;%PATH%
@set ERRORLEVEL=0
@IF %cmakestate%==1 set PATH=%mesa%\cmake\bin\;%PATH%
@cmake -G "%toolchain%"%x64compiler% -DLLVM_TARGETS_TO_BUILD=X86 -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_CRT_RELEASE=MT -DLLVM_ENABLE_RTTI=1 -DLLVM_ENABLE_TERMINFO=OFF -DCMAKE_INSTALL_PREFIX=../%abi% ..
@echo.
@pause
Expand All @@ -109,15 +163,9 @@
@cd %mesa%
@set mesapatched=0
@set haltmesabuild=n
@set prepfail=0
@where /q git.exe
@IF ERRORLEVEL 1 (
@set ERRORLEVEL=0
@echo Error: Git not found. Auto-patching disabled.
@set prepfail=1
)
@if NOT EXIST mesa if %prepfail%==1 echo Fatal: Both Mesa code and Git are missing. At least one is required. Execution halted.
@if NOT EXIST mesa if %prepfail%==1 GOTO distcreate
@if %gitstate%==0 echo Error: Git not found. Auto-patching disabled.
@if NOT EXIST mesa if %gitstate%==0 echo Fatal: Both Mesa code and Git are missing. At least one is required. Execution halted.
@if NOT EXIST mesa if %gitstate%==0 GOTO distcreate
@if NOT EXIST mesa echo Warning: Mesa3D source code not found.
@if NOT EXIST mesa set /p haltmesabuild=Press Y to abort execution. Press any other key to download Mesa via Git:
@if /I "%haltmesabuild%"=="y" GOTO distcreate
Expand All @@ -132,7 +180,7 @@
@rem if "%mesaver:~5,4%"=="0-rc" set /a intmesaver=%mesaver:~0,2%%mesaver:~3,1%00+%mesaver:~9%
@rem if NOT "%mesaver:~5,2%"=="0-" set /a intmesaver=%mesaver:~0,2%%mesaver:~3,1%50+%mesaver:~5%
@if EXIST mesapatched.ini GOTO build_mesa
@if %prepfail% EQU 1 GOTO build_mesa
@if %gitstate%==0 GOTO build_mesa
@git apply -v ..\mesa-dist-win\patches\s3tc.patch
@set mesapatched=1
@echo %mesapatched% > mesapatched.ini
Expand Down Expand Up @@ -165,14 +213,9 @@
@echo.
@if /I "%osmesa%"=="y" set sconscmd=%sconscmd% osmesa

:build_with_vs
@set ERRORLEVEL=0
@where /q win_flex.exe
@IF ERRORLEVEL 1 set PATH=%mesa%\flexbison\;%PATH%
@set ERRORLEVEL=0
@cd %mesa%\mesa

:build_mesa_exec
@IF %flexstate%==1 set PATH=%mesa%\flexbison\;%PATH%
@cd %mesa%\mesa
@set cleanbuild=n
@if EXIST build\windows-%longabi% set /p cleanbuild=Do you want to clean build (y/n):
@if EXIST build\windows-%longabi% echo.
Expand Down
7 changes: 5 additions & 2 deletions releasenotes.md
Expand Up @@ -3,9 +3,12 @@
- Per app deployment: Make text fit into Windows 7 default Command Prompt size.
### Build script
- Made the script aware of Python 2 and 3 variants;
- Before doing anything check the dependencies availability including Meson, both Pypi and standalone versions being recognized;
- Always load Python in PATH as it is used everywhere;
- Hard fail if Python is missing;
- Support both Pypi and standalone version of Meson.
- Hard fail if Python or Visual Studio are missing;
- Add code comments to make code easy to read.
### Environment updates
- cmake 3.10.3 -> 3.11.0
# 18.0.0.600-1
- Updated Mesa3D to [18.0.0](https://www.mesa3d.org/relnotes/18.0.0.html)
### Build environment updates
Expand Down

0 comments on commit 5f04ad0

Please sign in to comment.