setlocal enableextensions enabledelayedexpansion
rem // set the WSL distribution to use
set WSL_DISTR=Ubuntu-22.04
rem // list of Linux tools required by the cross-build script
set REQUIRED_TOOLS=wget python3 gcc g++ make m4
rem // make sure we have at least Windows 10
for /f "tokens=4 delims=. "
%%i in ('ver'
) do set VERSION=
%%i
echo Detected Windows NT kernel version:
%VERSION%
echo Error: you need at least Windows 10 to cross-build LLVM to QNX 8.
echo Please upgrade your Windows operating system to Windows 10 version 2004 build
echo 19041 or a later version.
)
rem // if WSL is not installed, do so
echo Checking WSL presence...
wsl --list -v
> nul 2
>&1
|| goto :
install_wsl
echo The Windows Subsystem
for Linux is installed
rem // WSL is installed, make sure the Linux distribution we need is there
echo Checking
for the presence of
%WSL_DISTR% in WSL...
wsl --distribution
%WSL_DISTR% -- cat /etc/os-release
|find "
%WSL_DISTR:-= %"
> nul || goto :
install_wsl
echo The GNU/Linux distribution
%WSL_DISTR% is present
rem // WSL is installed, make sure it's running WSL2
echo Checking WSL hypervisor version...
wsl --distribution
%WSL_DISTR% -- cat /proc/version
|find "WSL2"
> nul || (
echo This WSL distribution
%WSL_DISTR% needs to be converted to WSL2.
rem // this distribution needs to be converted
wsl --set-version %WSL_DISTR% 2 || (
echo Error: you need the Windows Subsystem
for Linux to support WSL2
for this
echo cross-build script to work consistently.
echo Please upgrade your Windows operating system to Windows 10 version 2004 build
echo 19041 or a later version.
)
rem // alright, this distribution is on WSL2
)
echo The Windows Subsystem
for Linux is version 2.
rem // make sure we have the required tools, install them if not
rem // tool syntax: "<executable>:<optional APT package name>"
rem // if package name is not specified, it defaults to <executable>
set REQUIRED_TOOL_AND_PACKAGE=
%%i
for /f "tokens=1-2 delims=:"
%%j in ('
echo !REQUIRED_TOOL_AND_PACKAGE!'
) do (
if "
!REQUIRED_PACKAGE!"==""
set REQUIRED_PACKAGE=
!REQUIRED_TOOL!
)
echo Checking
for the presence of
!REQUIRED_TOOL! from APT package !REQUIRED_PACKAGE!...
wsl --distribution
%WSL_DISTR% --
!REQUIRED_TOOL! --version
> nul 2
>&1
&& (
echo !REQUIRED_TOOL! is available.
) || (
echo !REQUIRED_TOOL! needs installation. Attempting to install it.
if "
!APT_CACHE_UPDATED!"=="0"
(
rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once.
wsl --distribution
%WSL_DISTR% -- sudo sh -c
^"echo '
%%sudo ALL=
^(ALL
^) NOPASSWD:ALL'
^>^> /etc/sudoers
^"
rem // update APT cache before installing stuff, but just once.
wsl --distribution %WSL_DISTR% -- sudo apt-get -y update
)
wsl --distribution %WSL_DISTR% sudo apt-get -y install !REQUIRED_PACKAGE! || (
echo Error: the required Linux tool
!REQUIRED_TOOL! can't be installed with apt-get.
)
)
)
rem // set the QNX8 SDP build environment, deploying the toolchain symlinks if necessary
rem // TODO: a possible way to accelerate the build would be to copy $QNX_HOST and $QNX_TARGET into the WSL2 filesystem
rem // instead of having the GCC compiler continuously cross the bridge back and forth between NTFS and ext4.
rem // But hey. Let's see if the current way of doing things is acceptable first.
rem // now run WSL from this directory and chain-call the POSIX Bourne shell build script
wsl --distribution
%WSL_DISTR% -- ./cross-build.sh
|| goto :
exit_error
rem // at this point, the story is supposed to have ended well.
rem // Keep calm, and I'll tell you another one tomorrow.
:install_wsl
echo Installing the Windows Subsystem
for Linux...
echo ############################################################################
echo # NOTE: please define a *non-root* Linux user name and password when asked #
echo #
^(for example: 'utilisateur' / 'utilisateur'
^) #
echo # then type '
exit' at the Linux shell
^(green prompt
^) to continue. #
echo ############################################################################
wsl --install --distribution %WSL_DISTR% || (
echo Error: you need at least a version of Windows 10 which has the "wsl" command.
echo Please upgrade your Windows operating system to Windows 10 version 2004 build
echo 19041 or a later version.
)
echo The Windows Subsystem
for Linux was successfully installed with the default
echo Action required: please reboot your computer and run this script again.
:exit_error
rem // failure exit
:exit_success
rem // successful exit