Subversion Repositories QNX 8.QNX8 LLVM/Clang compiler suite

Rev

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