forked from MaxKellermann/cegcc-build
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_cf.sh
executable file
·134 lines (107 loc) · 3.38 KB
/
build_cf.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
126
127
128
129
130
131
132
133
134
#!/bin/bash
#
# Builds a Binutils & GCC toolchain for Windows CE software development.
#
# Usage:
# ./build_cf.sh PREFIX_DIRECTORY
#
# GNU tools can be confusing enough, so this script is meant to be simple:
# No branches, no options, just rebuilds the entire toolchain in the right order.
# If you want to skip a few steps, just comment them out.
#
# Written by Colin Finck for ENLYZE GmbH
#
set -eu
if [[ $# -ne 2 ]]; then
echo "Usage: ./build_cf.sh PREFIXDIR TARGET"
echo
echo "Supported targets are":
echo " - arm-mingw32ce"
echo " - i386-mingw32ce"
exit 1
fi
J="-j `nproc`"
OLDPATH="$PATH"
PREFIXDIR="$1"
TARGET="$2"
rm -rf ${PREFIXDIR}
mkdir ${PREFIXDIR}
# --enable-threads=win32 of our GCC build wants to include <windows.h> from w32api.
# But building w32api requires a target GCC.
#
# GCC solves this circular dependency by considering the optional directory "winsup".
# "winsup/mingw/include" and "winsup/w32api/include" are added to the include path when
# building target components.
cd gcc
rm -rf winsup
mkdir winsup
cd winsup
ln -s ../../mingw
ln -s ../../w32api
cd ../..
echo "##################################"
echo "# BINUTILS #"
echo "##################################"
rm -rf binutils-build
mkdir binutils-build
cd binutils-build
../binutils/configure --prefix="${PREFIXDIR}" --target="${TARGET}" --with-pkgversion="ENLYZE" \
--disable-multilib --disable-werror --enable-lto --enable-plugins \
--with-zlib=yes --disable-nls --disable-unit-tests --disable-shared
make $J
make install
cd ..
echo "##################################"
echo "# INITIAL GCC #"
echo "##################################"
ADDITIONAL_GCC_PARAMETERS=""
if [[ "$TARGET" = "arm-mingw32ce" ]]; then
ADDITIONAL_GCC_PARAMETERS+="--disable-__cxa_atexit"
fi
rm -rf gcc-build
mkdir gcc-build
cd gcc-build
../gcc/configure --prefix="${PREFIXDIR}" --target="${TARGET}" --with-pkgversion="ENLYZE" \
--enable-languages=c,c++ --disable-shared --disable-multilib --disable-nls \
--disable-werror --disable-win32-registry --disable-libstdcxx-verbose \
--enable-threads=win32 ${ADDITIONAL_GCC_PARAMETERS}
# Only build and install GCC so far to let us build low-level CE binaries.
make $J all-gcc
make install-gcc
make install-lto-plugin
# Building anything with GCC also requires libgcc.
make $J all-target-libgcc
make install-target-libgcc
cd ..
# mingw and w32api need to find the toolchain we just built.
export PATH="${PREFIXDIR}/bin:$PATH"
echo "##################################"
echo "# MINGW #"
echo "##################################"
rm -rf mingw-build
mkdir mingw-build
cd mingw-build
../mingw/configure --prefix="${PREFIXDIR}" --host="${TARGET}" --target="${TARGET}"
make $J
make install
cd ..
echo "##################################"
echo "# W32API #"
echo "##################################"
rm -rf w32api-build
mkdir w32api-build
cd w32api-build
../w32api/configure --prefix="${PREFIXDIR}" --host="${TARGET}" --target="${TARGET}"
make $J
make install
cd ..
# Continue building the rest of GCC as before.
# The remaining components (like libstdc++) can now depend on all headers and libraries
# of mingw and w32api.
export PATH="$OLDPATH"
echo "##################################"
echo "# REST OF GCC #"
echo "##################################"
cd gcc-build
make $J
make install