Subversion Repositories QNX 8.QNX8 GNU binutils

Rev

Rev 14 | Rev 16 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 15
Line 2... Line 2...
2
setlocal enableextensions enabledelayedexpansion
2
setlocal enableextensions enabledelayedexpansion
3
 
3
 
-
 
4
rem // what we're building
-
 
5
set PRODUCT_NAME=the GNU binary utilities
-
 
6
 
4
rem // set the WSL distribution to use
7
rem // the WSL distribution to use
5
set WSL_DISTR=Ubuntu-22.04
8
set WSL_DISTR=Ubuntu-22.04
-
 
9
 
-
 
10
rem // name of the QNX SDK root directory
-
 
11
set QNXSDK_DIRNAME=qnx800
6
 
12
 
7
rem // list of Linux tools required by the cross-build script
13
rem // list of Linux tools required by the cross-build script
8
set REQUIRED_TOOLS=wget python3 gcc g++ make m4
14
set REQUIRED_TOOLS=wget python3 gcc g++ make m4
9
 
15
 
-
 
16
 
-
 
17
rem // welcome the wary user
-
 
18
echo QNX8 toolchain cross-build script for WSL by Pierre-Marie Baty ^<pm@pmbaty.com^>
-
 
19
echo.
10
 
20
 
11
rem // make sure we have at least Windows 10
21
rem // make sure we have at least Windows 10
12
for /f "tokens=4 delims=. " %%i in ('ver') do set VERSION=%%i
22
for /f "tokens=4 delims=. " %%i in ('ver') do set VERSION=%%i
13
echo Detected Windows NT kernel version: %VERSION%
23
echo Detected Windows NT kernel version: %VERSION%
14
if %VERSION% LSS 10 (
24
if %VERSION% LSS 10 (
15
        echo Error: you need at least Windows 10 to cross-build LLVM to QNX 8.
25
        echo Error: you need at least Windows 10 to cross-build %PRODUCT_NAME% to QNX 8.
16
        echo Please upgrade your Windows operating system to Windows 10 version 2004 build
26
        echo Please upgrade your Windows operating system to Windows 10 version 2004 build
17
        echo 19041 or a later version.
27
        echo 19041 or a later version.
18
        goto :exit_error
28
        goto :exit_error
19
)
29
)
20
 
30
 
21
rem // if WSL is not installed, do so
31
rem // if WSL is not installed, do so
22
echo Checking WSL presence...
32
echo|set /p=Checking whether the Windows Subsystem for Linux is installed...
23
wsl --list -v > nul 2>&1 || goto :install_wsl
33
wsl --list -v > nul 2>&1 || ( echo no & goto :install_wsl )
24
echo The Windows Subsystem for Linux is installed
34
echo yes
25
 
35
 
26
rem // WSL is installed, make sure the Linux distribution we need is there
36
rem // WSL is installed, make sure the Linux distribution we need is there
27
echo Checking for the presence of %WSL_DISTR% in WSL...
37
echo|set /p=Checking for the presence of the GNU/Linux distribution %WSL_DISTR% in WSL...
28
wsl --distribution %WSL_DISTR% -- cat /etc/os-release|find "%WSL_DISTR:-= %" > nul || goto :install_wsl
38
wsl --distribution %WSL_DISTR% -- cat /etc/os-release|find "%WSL_DISTR:-= %" > nul || ( echo no & goto :install_wsl )
29
echo The GNU/Linux distribution %WSL_DISTR% is present
39
echo yes
30
 
40
 
31
rem // WSL is installed, make sure it's running WSL2
41
rem // WSL is installed with the right Linux distribution, make sure it's running WSL2
32
echo Checking WSL hypervisor version...
42
echo|set /p=Checking whether the WSL hypervisor is version 2...
33
wsl --distribution %WSL_DISTR% -- cat /proc/version|find "WSL2" > nul || (
43
wsl --distribution %WSL_DISTR% -- cat /proc/version|find "WSL2" > nul || (
-
 
44
        echo no
34
        echo This WSL distribution %WSL_DISTR% needs to be converted to WSL2.
45
        echo|set /p=Attempting to convert the WSL distribution %WSL_DISTR% to WSL2...
35
        rem // this distribution needs to be converted
46
        rem // this distribution needs to be converted
36
        wsl --set-version %WSL_DISTR% 2 || (
47
        wsl --set-version %WSL_DISTR% 2 || (
-
 
48
                echo failed
37
                echo Error: you need the Windows Subsystem for Linux to support WSL2 for this
49
                echo Error: you need the Windows Subsystem for Linux to support WSL2 for this
38
                echo cross-build script to work consistently.
50
                echo cross-build script to work consistently.
39
                echo Please upgrade your Windows operating system to Windows 10 version 2004 build
51
                echo Please upgrade your Windows operating system to Windows 10 version 2004 build
40
                echo 19041 or a later version.
52
                echo 19041 or a later version.
41
                goto :exit_error
53
                goto :exit_error
42
        )
54
        )
43
        rem // alright, this distribution is on WSL2
55
        rem // alright, this distribution is on WSL2
44
)
56
)
45
echo The Windows Subsystem for Linux is version 2.
57
echo ok
46
 
58
 
47
rem // make sure we have the required tools, install them if not
59
rem // make sure we have the required tools, install them if not
48
set APT_CACHE_UPDATED=0
60
set APT_CACHE_UPDATED=0
49
for %%i in (%REQUIRED_TOOLS%) do (
61
for %%i in (%REQUIRED_TOOLS%) do (
50
        rem // tool syntax: "<executable>:<optional APT package name>"
62
        rem // tool syntax: "<executable>:<optional APT package name>"
Line 53... Line 65...
53
        for /f "tokens=1-2 delims=:" %%j in ('echo !REQUIRED_TOOL_AND_PACKAGE!') do (
65
        for /f "tokens=1-2 delims=:" %%j in ('echo !REQUIRED_TOOL_AND_PACKAGE!') do (
54
                set REQUIRED_TOOL=%%j
66
                set REQUIRED_TOOL=%%j
55
                set REQUIRED_PACKAGE=%%k
67
                set REQUIRED_PACKAGE=%%k
56
                if "!REQUIRED_PACKAGE!"=="" set REQUIRED_PACKAGE=!REQUIRED_TOOL!
68
                if "!REQUIRED_PACKAGE!"=="" set REQUIRED_PACKAGE=!REQUIRED_TOOL!
57
        )
69
        )
58
        echo Checking for the presence of !REQUIRED_TOOL! from APT package !REQUIRED_PACKAGE!...
70
        echo|set /p=Checking for the presence of !REQUIRED_TOOL! from APT package !REQUIRED_PACKAGE!...
59
        wsl --distribution %WSL_DISTR% -- !REQUIRED_TOOL! --version > nul 2>&1 && (
71
        wsl --distribution %WSL_DISTR% -- !REQUIRED_TOOL! --version > nul 2>&1 && (
60
                echo !REQUIRED_TOOL! is available.
72
                echo yes
61
        ) || (
73
        ) || (
-
 
74
                echo no
62
                echo !REQUIRED_TOOL! needs installation. Attempting to install it.
75
                echo !REQUIRED_TOOL! needs installation. Attempting to install it.
63
                if "!APT_CACHE_UPDATED!"=="0" (
76
                if "!APT_CACHE_UPDATED!"=="0" (
64
                        rem // allow ourselves to run any commands by patching /etc/sudoers. Do this once.
77
                        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^"
78
                        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.
79
                        rem // update APT cache before installing stuff, but just once.
Line 73... Line 86...
73
                        goto :exit_error
86
                        goto :exit_error
74
                )
87
                )
75
        )
88
        )
76
)
89
)
77
 
90
 
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
91
rem // setup the QNX SDP on the WSL side
82
cd "%THISDIR%"
-
 
83
 
92
 
84
rem // TODO: a possible way to accelerate the build would be to copy $QNX_HOST and $QNX_TARGET into the WSL2 filesystem
93
rem // The build script initially recursively transferred the contents of $QNX_HOST and $QNX_TARGET to the WSL2 ext4 partition
-
 
94
rem // when necessary using the Plan9 NTFS to ext4 bridge (9p file protocol) implemented by Microsoft to transfer files
-
 
95
rem // from Windows to WSL2. The only problem with this is, and Microsoft admits it, that 9p is *catastrophically slow*.
-
 
96
rem // See https://learn.microsoft.com/en-us/windows/wsl/compare-versions - And when Microsoft says "slow", hear "unusable".
-
 
97
rem // To make this faster, here's what I do:
-
 
98
rem //   1. fire up an archiver and create a SINGLE FILE archive of the directory hierarchy to copy
-
 
99
rem //   2. hand the file over to WSL2
-
 
100
rem //   3. unpack the archive in place - as it's much faster to migrate a single file than a folder hierarchy.
-
 
101
rem // The only prerequisite shall be that the archive format be *operable with the tools at hand on both systems*.
-
 
102
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
-
 
103
rem // the Linux version of /usr/bin/tar to untar it directly at its location, we achieve 10x faster transfer speeds than 9p.
85
rem // instead of having the GCC compiler continuously cross the bridge back and forth between NTFS and ext4.
104
rem // This is just ridiculous. I scoured the web for hours looking for an acceptable file transfer solution from Windows to WSL2
86
rem // But hey. Let's see if the current way of doing things is acceptable first.
105
rem // and it looks just like nobody found that one yet. Ah well...
87
 
106
 
-
 
107
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.
-
 
108
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.
-
 
109
rem // NOTE: on WSL2, the QNX SDK will always be copied to $HOME, regardless of what xdg-user-dir DESKTOP says.
-
 
110
echo|set /p=Checking if the %QNXSDK_DIRNAME% directory is present in WSL and up to date...
-
 
111
wsl --distribution %WSL_DISTR% -- test -f "${HOME}/%QNXSDK_DIRNAME%/.symlinks-state" -a "${HOME}/%QNXSDK_DIRNAME%" -nt "../%QNXSDK_DIRNAME%" || (
-
 
112
        echo no
-
 
113
 
-
 
114
        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
-
 
115
        echo|set /p=Preparing to copy QNX8 SDK files to WSL2 ext4 filesystem...
-
 
116
        wsl --distribution %WSL_DISTR% -- rm -rf "${HOME}/%QNXSDK_DIRNAME%"; mkdir -p "${HOME}/%QNXSDK_DIRNAME%/host" "${HOME}/%QNXSDK_DIRNAME%/target" 2>nul
-
 
117
        echo done
-
 
118
 
-
 
119
        rem // transfer the QNX SDK host files: tar on Windows, pipe to WSL2, untar on Linux - or die
-
 
120
        echo|set /p=Deploying QNX8 SDK Linux host files to WSL2 ext4 filesystem ^(this can take some time^)...
-
 
121
        "..\%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 )
-
 
122
        echo done
-
 
123
 
-
 
124
        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.
-
 
125
        echo|set /p=Setting executable permissions to QNX8 SDK toolchain files...
-
 
126
        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
-
 
127
        echo done
-
 
128
 
-
 
129
        rem // transfer the QNX SDK target files: tar on Windows, pipe to WSL2, untar on Linux - or die
-
 
130
        echo|set /p=Deploying QNX8 SDK target sysroot files to WSL2 ext4 filesystem ^(this WILL take some time^)...
-
 
131
        "..\%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 )
-
 
132
        echo done
-
 
133
 
-
 
134
        rem // setup the toolchain symlinks
-
 
135
        echo Setting up the QNX SDP platform-specific symlinks...
-
 
136
        "..\%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 )
-
 
137
        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
-
 
138
)
-
 
139
echo ok
-
 
140
 
88
rem // now run WSL from this directory and chain-call the POSIX Bourne shell build script
141
rem // now chain-call the POSIX Bourne shell build script
-
 
142
echo Running POSIX build script...
89
wsl --distribution %WSL_DISTR% -- ./cross-build.sh || goto :exit_error
143
wsl --distribution %WSL_DISTR% -- ./cross-build.sh || goto :exit_error
90
 
144
 
91
rem // at this point, the story is supposed to have ended well.
145
rem // at this point, the story is supposed to have ended well.
92
rem // Keep calm, and I'll tell you another one tomorrow.
146
rem // Keep calm, and I'll tell you another one tomorrow.
-
 
147
echo.
-
 
148
echo The build ended successfully.
93
goto :exit_success
149
goto :exit_success
94
 
150
 
95
 
151
 
96
:install_wsl
152
:install_wsl
97
        echo Installing the Windows Subsystem for Linux...
153
        echo Installing the Windows Subsystem for Linux...
Line 104... Line 160...
104
                echo Error: you need at least a version of Windows 10 which has the "wsl" command.
160
                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
161
                echo Please upgrade your Windows operating system to Windows 10 version 2004 build
106
                echo 19041 or a later version.
162
                echo 19041 or a later version.
107
                goto :exit_error
163
                goto :exit_error
108
        )
164
        )
109
        echo The Windows Subsystem for Linux was successfully installed with the default
165
        echo The Windows Subsystem for Linux was successfully installed with the %WSL_DISTR%
110
        echo distribution.
166
        echo distribution.
111
        echo Action required: please reboot your computer and run this script again.
167
        echo Action required: please reboot your computer and run this script again.
112
        pause
168
        pause
113
        goto :exit_success
169
        goto :exit_success
114
 
170
 
Line 117... Line 173...
117
pause
173
pause
118
exit /b 1
174
exit /b 1
119
 
175
 
120
:exit_success
176
:exit_success
121
rem // successful exit
177
rem // successful exit
-
 
178
pause
122
exit /b 0
179
exit /b 0