Rev 24 | Rev 28 | 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 | |||
27 | pmbaty | 7 | rem // name of the QNX SDK root directory |
8 | set QNXSDK_DIRNAME=qnx800 |
||
9 | |||
23 | pmbaty | 10 | rem // list of Linux tools required by the cross-build script |
11 | set REQUIRED_TOOLS=wget python3 cmake gcc g++ ninja:ninja-build ccache |
||
12 | |||
13 | |||
14 | rem // make sure we have at least Windows 10 |
||
15 | for /f "tokens=4 delims=. " %%i in ('ver') do set VERSION=%%i |
||
24 | pmbaty | 16 | echo Detected Windows NT kernel version: %VERSION% |
23 | pmbaty | 17 | if %VERSION% LSS 10 ( |
18 | echo Error: you need at least Windows 10 to cross-build LLVM to QNX 8. |
||
24 | pmbaty | 19 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
20 | echo 19041 or a later version. |
||
23 | pmbaty | 21 | goto :exit_error |
22 | ) |
||
23 | |||
24 | rem // if WSL is not installed, do so |
||
25 | echo Checking WSL presence... |
||
26 | wsl --list -v > nul 2>&1 || goto :install_wsl |
||
27 | echo The Windows Subsystem for Linux is installed |
||
28 | |||
29 | rem // WSL is installed, make sure the Linux distribution we need is there |
||
30 | echo Checking for the presence of %WSL_DISTR% in WSL... |
||
31 | wsl --distribution %WSL_DISTR% -- cat /etc/os-release|find "%WSL_DISTR:-= %" > nul || goto :install_wsl |
||
32 | echo The GNU/Linux distribution %WSL_DISTR% is present |
||
33 | |||
34 | rem // WSL is installed, make sure it's running WSL2 |
||
35 | echo Checking WSL hypervisor version... |
||
36 | wsl --distribution %WSL_DISTR% -- cat /proc/version|find "WSL2" > nul || ( |
||
37 | echo This WSL distribution %WSL_DISTR% needs to be converted to WSL2. |
||
38 | rem // this distribution needs to be converted |
||
39 | wsl --set-version %WSL_DISTR% 2 || ( |
||
40 | echo Error: you need the Windows Subsystem for Linux to support WSL2 for this |
||
41 | echo cross-build script to work consistently. |
||
42 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
||
43 | echo 19041 or a later version. |
||
44 | goto :exit_error |
||
45 | ) |
||
46 | rem // alright, this distribution is on WSL2 |
||
47 | ) |
||
48 | echo The Windows Subsystem for Linux is version 2. |
||
49 | |||
50 | rem // make sure we have the required tools, install them if not |
||
51 | set APT_CACHE_UPDATED=0 |
||
52 | for %%i in (%REQUIRED_TOOLS%) do ( |
||
53 | rem // tool syntax: "<executable>:<optional APT package name>" |
||
54 | rem // if package name is not specified, it defaults to <executable> |
||
55 | set REQUIRED_TOOL_AND_PACKAGE=%%i |
||
56 | for /f "tokens=1-2 delims=:" %%j in ('echo !REQUIRED_TOOL_AND_PACKAGE!') do ( |
||
57 | set REQUIRED_TOOL=%%j |
||
58 | set REQUIRED_PACKAGE=%%k |
||
59 | if "!REQUIRED_PACKAGE!"=="" set REQUIRED_PACKAGE=!REQUIRED_TOOL! |
||
60 | ) |
||
61 | echo Checking for the presence of !REQUIRED_TOOL! from APT package !REQUIRED_PACKAGE!... |
||
62 | wsl --distribution %WSL_DISTR% -- !REQUIRED_TOOL! --version > nul 2>&1 && ( |
||
63 | echo !REQUIRED_TOOL! is available. |
||
64 | ) || ( |
||
65 | echo !REQUIRED_TOOL! needs installation. Attempting to install it. |
||
66 | if "!APT_CACHE_UPDATED!"=="0" ( |
||
67 | rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once. |
||
68 | wsl --distribution %WSL_DISTR% -- sudo sh -c ^"echo '%%sudo ALL=^(ALL^) NOPASSWD:ALL' ^>^> /etc/sudoers^" |
||
69 | rem // update APT cache before installing stuff, but just once. |
||
70 | wsl --distribution %WSL_DISTR% -- sudo apt-get -y update |
||
71 | set APT_CACHE_UPDATED=1 |
||
72 | ) |
||
73 | wsl --distribution %WSL_DISTR% sudo apt-get -y install !REQUIRED_PACKAGE! || ( |
||
74 | echo Error: the required Linux tool !REQUIRED_TOOL! can't be installed with apt-get. |
||
75 | pause |
||
76 | goto :exit_error |
||
77 | ) |
||
78 | ) |
||
79 | ) |
||
80 | |||
81 | rem // set the QNX8 SDP build environment, deploying the toolchain symlinks if necessary |
||
82 | set THISDIR=%CD% |
||
83 | cd ..\qnx800 |
||
84 | call qnxsdp-env.bat || goto :exit_error |
||
85 | cd "%THISDIR%" |
||
86 | |||
27 | pmbaty | 87 | rem // The build script will already recursively transfer the contents of $QNX_HOST and $QNX_TARGET to the WSL2 ext4 partition |
88 | rem // to avoid using the Plan9 NTFS to ext4 bridge (9p file protocol) implemented by Microsoft that is notoriously slow. |
||
89 | rem // However to make this faster, we could: |
||
90 | rem // 1. fire up a file packer and create a SINGLE FILE archive of the directory hierarchy to copy |
||
91 | rem // 2. copy the file over to WSL |
||
92 | rem // 3. unpack the archive in /tmp/qnxsdk and delete it - as it's much faster to migrate a single file than a folder hierarchy |
||
93 | rem // The prerequisite shall be that the archive format be *operable with the default tools on both systems*. |
||
94 | rem // We might be able to do this by using the "tar.exe" utility from the QNX8 Win64 host SDP tools and piping the data |
||
95 | rem // through a wsl instance which would in turn untar it directly at its location. Investigate. |
||
24 | pmbaty | 96 | |
27 | pmbaty | 97 | rem // NOTE: on WSL2, the QNX SDK will always be copied to $HOME, regardless of what xdg-user-dir DESKTOP says. |
98 | wsl --distribution %WSL_DISTR% -- mkdir -p ~/%QNXSDK_DIRNAME%/host ~/%QNXSDK_DIRNAME%/target |
||
99 | echo Deploying QNX8 Linux host SDK to WSL2 ext4 filesystem, please wait... |
||
100 | "%QNX_HOST%\usr\bin\tar.exe" c - ..\%QNXSDK_DIRNAME%\host\linux | wsl --distribution %WSL_DISTR% -- tar x --directory=~/%QNXSDK_DIRNAME%/host |
||
101 | echo Deploying QNX8 TARGET SDK to WSL2 ext4 filesystem, please wait... |
||
102 | "%QNX_HOST%\usr\bin\tar.exe" c - ..\%QNXSDK_DIRNAME%\target\qnx | wsl --distribution %WSL_DISTR% -- tar x --directory=~/%QNXSDK_DIRNAME%/target |
||
103 | |||
23 | pmbaty | 104 | rem // now run WSL from this directory and chain-call the POSIX Bourne shell build script |
105 | wsl --distribution %WSL_DISTR% -- ./cross-build.sh || goto :exit_error |
||
106 | |||
107 | rem // at this point, the story is supposed to have ended well. |
||
108 | rem // Keep calm, and I'll tell you another one tomorrow. |
||
109 | goto :exit_success |
||
110 | |||
111 | |||
112 | :install_wsl |
||
113 | echo Installing the Windows Subsystem for Linux... |
||
114 | echo ############################################################################ |
||
115 | echo # NOTE: please define a *non-root* Linux user name and password when asked # |
||
116 | echo # ^(for example: 'utilisateur' / 'utilisateur'^) # |
||
117 | echo # then type 'exit' at the Linux shell ^(green prompt^) to continue. # |
||
118 | echo ############################################################################ |
||
119 | wsl --install --distribution %WSL_DISTR% || ( |
||
120 | echo Error: you need at least a version of Windows 10 which has the "wsl" command. |
||
121 | echo Please upgrade your Windows operating system to Windows 10 version 2004 build |
||
122 | echo 19041 or a later version. |
||
123 | goto :exit_error |
||
124 | ) |
||
125 | echo The Windows Subsystem for Linux was successfully installed with the default |
||
126 | echo distribution. |
||
127 | echo Action required: please reboot your computer and run this script again. |
||
128 | pause |
||
129 | goto :exit_success |
||
130 | |||
131 | :exit_error |
||
132 | rem // failure exit |
||
133 | pause |
||
134 | exit /b 1 |
||
135 | |||
136 | :exit_success |
||
137 | rem // successful exit |
||
138 | exit /b 0 |