Rev 23 | Rev 27 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 23 | pmbaty | 1 | @echo off |
| 2 | setlocal enableextensions enabledelayedexpansion |
||
| 3 | |||
| 4 | rem // set the WSL distribution to use |
||
| 5 | set WSL_DISTR=Ubuntu-22.04 |
||
| 6 | |||
| 7 | rem // list of Linux tools required by the cross-build script |
||
| 8 | set REQUIRED_TOOLS=wget python3 cmake gcc g++ ninja:ninja-build ccache |
||
| 9 | |||
| 10 | |||
| 11 | rem // make sure we have at least Windows 10 |
||
| 12 | for /f "tokens=4 delims=. " %%i in ('ver') do set VERSION=%%i |
||
| 24 | pmbaty | 13 | echo Detected Windows NT kernel version: %VERSION% |
| 23 | pmbaty | 14 | if %VERSION% LSS 10 ( |
| 15 | echo Error: you need at least Windows 10 to cross-build LLVM to QNX 8. |
||
| 24 | pmbaty | 16 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
| 17 | echo 19041 or a later version. |
||
| 23 | pmbaty | 18 | goto :exit_error |
| 19 | ) |
||
| 20 | |||
| 21 | rem // if WSL is not installed, do so |
||
| 22 | echo Checking WSL presence... |
||
| 23 | wsl --list -v > nul 2>&1 || goto :install_wsl |
||
| 24 | echo The Windows Subsystem for Linux is installed |
||
| 25 | |||
| 26 | rem // WSL is installed, make sure the Linux distribution we need is there |
||
| 27 | echo Checking for the presence of %WSL_DISTR% in WSL... |
||
| 28 | wsl --distribution %WSL_DISTR% -- cat /etc/os-release|find "%WSL_DISTR:-= %" > nul || goto :install_wsl |
||
| 29 | echo The GNU/Linux distribution %WSL_DISTR% is present |
||
| 30 | |||
| 31 | rem // WSL is installed, make sure it's running WSL2 |
||
| 32 | echo Checking WSL hypervisor version... |
||
| 33 | wsl --distribution %WSL_DISTR% -- cat /proc/version|find "WSL2" > nul || ( |
||
| 34 | echo This WSL distribution %WSL_DISTR% needs to be converted to WSL2. |
||
| 35 | rem // this distribution needs to be converted |
||
| 36 | wsl --set-version %WSL_DISTR% 2 || ( |
||
| 37 | echo Error: you need the Windows Subsystem for Linux to support WSL2 for this |
||
| 38 | echo cross-build script to work consistently. |
||
| 39 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
||
| 40 | echo 19041 or a later version. |
||
| 41 | goto :exit_error |
||
| 42 | ) |
||
| 43 | rem // alright, this distribution is on WSL2 |
||
| 44 | ) |
||
| 45 | echo The Windows Subsystem for Linux is version 2. |
||
| 46 | |||
| 47 | rem // make sure we have the required tools, install them if not |
||
| 48 | set APT_CACHE_UPDATED=0 |
||
| 49 | for %%i in (%REQUIRED_TOOLS%) do ( |
||
| 50 | rem // tool syntax: "<executable>:<optional APT package name>" |
||
| 51 | rem // if package name is not specified, it defaults to <executable> |
||
| 52 | set REQUIRED_TOOL_AND_PACKAGE=%%i |
||
| 53 | for /f "tokens=1-2 delims=:" %%j in ('echo !REQUIRED_TOOL_AND_PACKAGE!') do ( |
||
| 54 | set REQUIRED_TOOL=%%j |
||
| 55 | set REQUIRED_PACKAGE=%%k |
||
| 56 | if "!REQUIRED_PACKAGE!"=="" set REQUIRED_PACKAGE=!REQUIRED_TOOL! |
||
| 57 | ) |
||
| 58 | echo Checking for the presence of !REQUIRED_TOOL! from APT package !REQUIRED_PACKAGE!... |
||
| 59 | wsl --distribution %WSL_DISTR% -- !REQUIRED_TOOL! --version > nul 2>&1 && ( |
||
| 60 | echo !REQUIRED_TOOL! is available. |
||
| 61 | ) || ( |
||
| 62 | echo !REQUIRED_TOOL! needs installation. Attempting to install it. |
||
| 63 | if "!APT_CACHE_UPDATED!"=="0" ( |
||
| 64 | rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once. |
||
| 65 | wsl --distribution %WSL_DISTR% -- sudo sh -c ^"echo '%%sudo ALL=^(ALL^) NOPASSWD:ALL' ^>^> /etc/sudoers^" |
||
| 66 | rem // update APT cache before installing stuff, but just once. |
||
| 67 | wsl --distribution %WSL_DISTR% -- sudo apt-get -y update |
||
| 68 | set APT_CACHE_UPDATED=1 |
||
| 69 | ) |
||
| 70 | wsl --distribution %WSL_DISTR% sudo apt-get -y install !REQUIRED_PACKAGE! || ( |
||
| 71 | echo Error: the required Linux tool !REQUIRED_TOOL! can't be installed with apt-get. |
||
| 72 | pause |
||
| 73 | goto :exit_error |
||
| 74 | ) |
||
| 75 | ) |
||
| 76 | ) |
||
| 77 | |||
| 78 | rem // set the QNX8 SDP build environment, deploying the toolchain symlinks if necessary |
||
| 79 | set THISDIR=%CD% |
||
| 80 | cd ..\qnx800 |
||
| 81 | call qnxsdp-env.bat || goto :exit_error |
||
| 82 | cd "%THISDIR%" |
||
| 83 | |||
| 24 | pmbaty | 84 | rem // TODO: a possible way to accelerate the build would be to copy $QNX_HOST and $QNX_TARGET into the WSL2 filesystem |
| 85 | rem // instead of having the GCC compiler continuously cross the bridge back and forth between NTFS and ext4. |
||
| 86 | rem // But hey. Let's see if the current way of doing things is acceptable first. |
||
| 87 | |||
| 23 | pmbaty | 88 | rem // now run WSL from this directory and chain-call the POSIX Bourne shell build script |
| 89 | wsl --distribution %WSL_DISTR% -- ./cross-build.sh || goto :exit_error |
||
| 90 | |||
| 91 | rem // at this point, the story is supposed to have ended well. |
||
| 92 | rem // Keep calm, and I'll tell you another one tomorrow. |
||
| 93 | goto :exit_success |
||
| 94 | |||
| 95 | |||
| 96 | :install_wsl |
||
| 97 | echo Installing the Windows Subsystem for Linux... |
||
| 98 | echo ############################################################################ |
||
| 99 | echo # NOTE: please define a *non-root* Linux user name and password when asked # |
||
| 100 | echo # ^(for example: 'utilisateur' / 'utilisateur'^) # |
||
| 101 | echo # then type 'exit' at the Linux shell ^(green prompt^) to continue. # |
||
| 102 | echo ############################################################################ |
||
| 103 | wsl --install --distribution %WSL_DISTR% || ( |
||
| 104 | echo Error: you need at least a version of Windows 10 which has the "wsl" command. |
||
| 105 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
||
| 106 | echo 19041 or a later version. |
||
| 107 | goto :exit_error |
||
| 108 | ) |
||
| 109 | echo The Windows Subsystem for Linux was successfully installed with the default |
||
| 110 | echo distribution. |
||
| 111 | echo Action required: please reboot your computer and run this script again. |
||
| 112 | pause |
||
| 113 | goto :exit_success |
||
| 114 | |||
| 115 | :exit_error |
||
| 116 | rem // failure exit |
||
| 117 | pause |
||
| 118 | exit /b 1 |
||
| 119 | |||
| 120 | :exit_success |
||
| 121 | rem // successful exit |
||
| 122 | exit /b 0 |