- setlocal-  enableextensions enabledelayedexpansion 
 
-   
- rem // what we're building 
- set-  PRODUCT_NAME=the LLVM compiler suite 
 
-   
- rem // the WSL distribution to use 
- set-  WSL_DISTR=Ubuntu-22.04 
 
-   
- rem // name of the QNX SDK root directory 
- set-  QNXSDK_DIRNAME=qnx800 
 
-   
- rem // list of Linux tools required by the cross-build script 
- set-  REQUIRED_TOOLS=wget python3 cmake gcc g++ ninja:ninja-build ccache 
 
-   
-   
- rem // welcome the wary user 
- echo-  QNX8 toolchain cross-build script  for-  WSL by Pierre-Marie Baty  ^<- pm @- pmbaty.com ^>
 
-   
- 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  %PRODUCT_NAME%-  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|set-  /p=Checking whether the Windows Subsystem  for-  Linux is installed...  
 
- wsl --list -v  > nul-  2 >&- 1  || ( echo-  no  & goto-  : install_wsl )
-   
- rem // WSL is installed, make sure the Linux distribution we need is there 
- echo|set-  /p=Checking  for-  the presence of the GNU/Linux distribution  %WSL_DISTR% in-  WSL...  
 
- wsl --distribution  %WSL_DISTR%-  -- cat /etc/os-release |- find " %WSL_DISTR:-= %- "  > nul || ( echo-  no  & goto-  : install_wsl )
-   
- rem // WSL is installed with the right Linux distribution, make sure it's running WSL2 
- echo|set-  /p=Checking whether the WSL hypervisor is version 2...  
 
- wsl --distribution  %WSL_DISTR%-  -- cat /proc/version |- find "WSL2"  > nul || (
-         echo|set-  /p=Attempting to convert the WSL distribution  %WSL_DISTR%-  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 
- ) 
-   
- rem // make sure we have the required tools, install them if not 
- set-  ETC_SUDOERS_PATCHED=0 
 
-         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|set-  /p=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!-  needs installation. Attempting to install it. 
 
-                 if-  " !ETC_SUDOERS_PATCHED!- "=="0"  (
 
-                         rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once, and only if necessary. 
-                         wsl --distribution  %WSL_DISTR%-  -- sudo sh -c  ^"- grep ' %%- sudo  ALL= ^(- ALL ^)-  NOPASSWD:ALL' /etc/sudoers  ^|^| echo-  ' %%- sudo  ALL= ^(- ALL ^)-  NOPASSWD:ALL'  ^>^>-  /etc/sudoers ^"
- rem                     rem // update APT cache before installing stuff, but just once. 
- rem                     wsl --distribution %WSL_DISTR% -- sudo apt-get -y update 
-                         set-  ETC_SUDOERS_PATCHED=1 
 
-                 ) 
- rem             wsl --distribution %WSL_DISTR% sudo apt-get -y install !REQUIRED_PACKAGE! || ( 
-                 wsl --distribution  %WSL_DISTR%-  sudo apt-get -y install "../../Third-party software/Ubuntu 22.04 Debian packages  for-  WSL2/ !REQUIRED_PACKAGE!- .deb"  || (
-                         echo-  Error: the required Linux tool  !REQUIRED_TOOL!-  can't be installed with apt-get. 
 
-                 ) 
-         ) 
- ) 
-   
- rem // setup the QNX SDP on the WSL side 
-   
- rem // The build script initially recursively transferred the contents of $QNX_HOST and $QNX_TARGET to the WSL2 ext4 partition 
- rem // when necessary using the Plan9 NTFS to ext4 bridge (9p file protocol) implemented by Microsoft to transfer files 
- rem // from Windows to WSL2. The only problem with this is, and Microsoft admits it, that 9p is *catastrophically slow*. 
- rem // See https://learn.microsoft.com/en-us/windows/wsl/compare-versions - And when Microsoft says "slow", hear "unusable". 
- rem // To make this faster, here's what I do: 
- rem //   1. fire up an archiver and create a SINGLE FILE archive of the directory hierarchy to copy 
- rem //   2. hand the file over to WSL2 
- rem //   3. unpack the archive in place - as it's much faster to migrate a single file than a folder hierarchy. 
- rem // The only prerequisite shall be that the archive format be *operable with the tools at hand on both systems*. 
- rem // By using the "usr\bin\tar.exe" utility from the QNX8 Win64 host SDP tools and piping the data through a WSL2 instance running 
- rem // the Linux version of /usr/bin/tar to untar it directly at its location, we achieve 10x faster transfer speeds than 9p. 
- rem // This is just ridiculous. I scoured the web for hours looking for an acceptable file transfer solution from Windows to WSL2 
- rem // and it looks just like nobody found that one yet. Ah well... 
-   
- rem // see if the SDP needs to be copied at all. Only do this when the modification time of the SDP directory on Windows is more recent than the one on Linux. 
- rem // So test for the presence of the symlinks state file as it's the last file that's created (this ensures a complete copy), then check for the directory mtimes. 
- rem // NOTE: on WSL2, the QNX SDK will always be copied to $HOME, regardless of what xdg-user-dir DESKTOP says. 
- echo|set-  /p=Checking  if-  the  %QNXSDK_DIRNAME%-  directory is present  in-  WSL and up to date...  
 
- wsl --distribution %WSL_DISTR% -- test ! -f "${HOME}/%QNXSDK_DIRNAME%/.symlinks-state" -o "../%QNXSDK_DIRNAME%" -nt "${HOME}/%QNXSDK_DIRNAME%" && ( 
-   
-         rem // copy needed - cleanup and create the directories we'll need in $HOME to accomodate the QNX SDK. We want the Linux host tools, and the QNX target sysroot files 
-         echo|set-  /p=Preparing to  copy-  QNX8 SDK files to WSL2 ext4 filesystem...  
 
-         wsl --distribution  %WSL_DISTR%-  -- rm -rf "${HOME}/ %QNXSDK_DIRNAME%- ";  mkdir-  -p "${HOME}/ %QNXSDK_DIRNAME%- /host" "${HOME}/ %QNXSDK_DIRNAME%- /target" 2 >nul
-   
-         rem // transfer the QNX SDK host files: tar on Windows, pipe to WSL2, untar on Linux - or die 
-         echo|set-  /p=Deploying QNX8 SDK Linux host files to WSL2 ext4 filesystem  ^(- this can take some time ^)- ...  
 
-         "..\ %QNXSDK_DIRNAME%- \host\win64\x86_64\usr\bin\tar.exe" -c --directory="..\ %QNXSDK_DIRNAME%- \host" linux  |-  wsl --distribution  %WSL_DISTR%-  -- tar -x --directory="${HOME}/ %QNXSDK_DIRNAME%- /host"  || ( echo-  failed  & goto-  : exit_error )
-   
-         rem // Windows has absolutely no notion of UNIX permissions. The best we can do here is to arbitrarily set the executable flags on relevant parts of the migrated tree. 
-         echo|set-  /p=Setting executable permissions to QNX8 SDK toolchain files...  
 
-         wsl --distribution  %WSL_DISTR%-  -- chmod -R +x "${HOME}/ %QNXSDK_DIRNAME%- /host/linux/x86_64/usr/bin" "${HOME}/ %QNXSDK_DIRNAME%- /host/linux/x86_64/usr/lib/gcc"  || goto-  : exit_error
-   
-         rem // transfer the QNX SDK target files: tar on Windows, pipe to WSL2, untar on Linux - or die 
-         echo|set-  /p=Deploying QNX8 SDK target sysroot files to WSL2 ext4 filesystem  ^(- this WILL take some time ^)- ...  
 
-         "..\ %QNXSDK_DIRNAME%- \host\win64\x86_64\usr\bin\tar.exe" -c --directory="..\ %QNXSDK_DIRNAME%- \target" qnx  |-  wsl --distribution  %WSL_DISTR%-  -- tar -x --directory="${HOME}/ %QNXSDK_DIRNAME%- /target"  || ( echo-  failed  & goto-  : exit_error )
-   
-         rem // setup the toolchain symlinks 
-         echo-  Setting up the QNX SDP platform-specific symlinks...  
 
-         "..\ %QNXSDK_DIRNAME%- \host\win64\x86_64\usr\bin\tar.exe" -c --directory="..\ %QNXSDK_DIRNAME%- " symlinks.sh  |-  wsl --distribution  %WSL_DISTR%-  -- tar -x --directory="${HOME}/ %QNXSDK_DIRNAME%- "  || ( echo-  failed  & goto-  : exit_error )
-         wsl --distribution  %WSL_DISTR%-  --  cd-  "${HOME}/ %QNXSDK_DIRNAME%- "  ^&^&-  find . -name symlinks.lst -exec ./symlinks.sh {} create $1 \;  ^&^&-  printf 'present-v2'  ^>-  "${HOME}/ %QNXSDK_DIRNAME%- /.symlinks-state"  || goto-  : exit_error
- ) 
-   
- rem // now chain-call the POSIX Bourne shell build script 
- echo-  Running POSIX 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. 
- echo-  The build ended successfully. 
 
-   
-   
- :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  %WSL_DISTR%
 
-         echo-  Action required: please reboot your computer and run this script again. 
 
-   
- :exit_error 
- rem // failure exit 
-   
- :exit_success 
- rem // successful exit 
-