-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmingw-build.sh
executable file
·125 lines (106 loc) · 2.91 KB
/
mingw-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#!/bin/bash
set -euo pipefail
BINUTILS_VERSION=2.42
GCC_VERSION=13.2.0
MINGW_VERSION=12.0.0
mkdir mingw
pushd mingw
# Download source code
echo "@@@ Downloading source code"
mkdir src
pushd src
## Binutils
wget https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.xz
tar Jxf binutils-${BINUTILS_VERSION}.tar.xz
## GCC
wget https://ftp.gnu.org/gnu/gcc/gcc-${GCC_VERSION}/gcc-${GCC_VERSION}.tar.xz
tar Jxf gcc-${GCC_VERSION}.tar.xz
pushd gcc-${GCC_VERSION}
contrib/download_prerequisites
popd
## MinGW-w64
wget https://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/mingw-w64-v${MINGW_VERSION}.tar.bz2
tar jxf mingw-w64-v${MINGW_VERSION}.tar.bz2
popd
build_mingw_toolchain() {
local old_path=$PATH
local thread_model=$1
local prefix=/opt/mingw-w64-${thread_model}
echo "@@@ Building MinGW-w64 toolchain with '${thread_model}' thread model"
# Add prefix bin directory to PATH to aid toolchain discovery
export PATH="${prefix}/bin:${PATH}"
# Create build directory
mkdir build-${thread_model}
pushd build-${thread_model}
# Build Binutils
mkdir binutils
pushd binutils
../../src/binutils-${BINUTILS_VERSION}/configure \
--prefix=${prefix} \
--target=x86_64-w64-mingw32 \
--disable-multilib
make -j$(nproc)
make install
popd
# Install MinGW headers
mkdir mingw-headers
pushd mingw-headers
../../src/mingw-w64-v${MINGW_VERSION}/mingw-w64-headers/configure \
--prefix=${prefix}/x86_64-w64-mingw32 \
--host=x86_64-w64-mingw32 \
--with-default-msvcrt=ucrt
make install
popd
# Build core GCC
mkdir gcc
pushd gcc
../../src/gcc-${GCC_VERSION}/configure \
--prefix=${prefix} \
--target=x86_64-w64-mingw32 \
--disable-multilib \
--enable-languages=c,c++ \
--enable-threads=${thread_model} \
--with-headers
make -j$(nproc) all-gcc
make install-gcc
popd
# Build MinGW
mkdir mingw
pushd mingw
../../src/mingw-w64-v${MINGW_VERSION}/configure \
--prefix=${prefix}/x86_64-w64-mingw32 \
--host=x86_64-w64-mingw32 \
--with-default-msvcrt=ucrt
make -j$(nproc)
make install -j$(nproc)
popd
# Build MinGW winpthreads
mkdir mingw-winpthreads
pushd mingw-winpthreads
../../src/mingw-w64-v${MINGW_VERSION}/mingw-w64-libraries/winpthreads/configure \
--prefix=${prefix}/x86_64-w64-mingw32 \
--host=x86_64-w64-mingw32
make -j$(nproc)
make install
popd
# Build final GCC
pushd gcc
make -j$(nproc)
make install
popd
# Place libwinpthread-1.dll in 'lib' directory so that it can be discovered
# using 'clang -print-file-name=libwinpthread-1.dll'.
pushd ${prefix}/x86_64-w64-mingw32
cp bin/libwinpthread-1.dll lib
popd
# Restore environment
popd
export PATH=${old_path}
}
# Build MinGW toolchain with 'win32' thread model
build_mingw_toolchain win32
# Build MinGW toolchain with 'posix' thread model
build_mingw_toolchain posix
# Clean up build directories
popd
rm -rf mingw