aboutsummaryrefslogtreecommitdiff
path: root/bootstrap-funcs.sh
blob: 75dd936581b2820422e45b4aeb9251e0266eff3e (plain)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#!/bin/sh
#
export CC=$HOST_CC
export CXX=$HOST_CXX

compile_binutils ()
{
   print_info "Cross compiling binutils"
   rm -rf "$BINUTILS_SRC".obj &&
   mkdir -p "$BINUTILS_SRC".obj &&
   cd "$BINUTILS_SRC".obj &&
   AR=$HOST_AR AS=$HOST_AS \
   $SOURCE/$BINUTILS_SRC/configure \
      --host="$HOST" \
      --target="$TARGET" \
      --prefix="$CROSS_TOOLS" \
      --with-sysroot="$SYSTEM" \
      --disable-static \
      --with-lib-path="$SYS_ROOT"/lib \
      --disable-multilib \
      --disable-nls &&
   make -j$PROCS all &&
   make -j$PROCS install &&
   cd ..
}

compile_gcc ()
{
   print_info "Cross compiling first phase of GCC"
   rm -rf $GCC_SRC.obj &&
   mkdir -p $GCC_SRC.obj &&
   cd $GCC_SRC.obj &&
   AR=$HOST_AR LDFLAGS="-Wl,-rpath,${CROSS_TOOLS}/lib" \
   $SOURCE/$GCC_SRC/configure \
      --prefix=$CROSS_TOOLS \
      --build="$HOST" \
      --host="$HOST" \
      --target="$TARGET" \
      --with-sysroot="$SYSTEM" \
      --with-local-prefix="$SYS_ROOT" \
      --with-native-system-header-dir="$SYS_ROOT"/include \
      --disable-nls \
      --disable-shared \
      --disable-threads \
      --disable-multilib \
      --disable-target-zlib \
      --with-system-zlib \
      --without-headers \
      --with-newlib \
      --disable-decimal-float \
      --disable-threads \
      --disable-libatomic \
      --disable-libgomp \
      --disable-libquadmath \
      --disable-libssp \
      --disable-libvtv \
      --disable-libstdcxx \
      --enable-languages=c &&
   make -j$PROCS all-gcc &&
   make -j$PROCS install-gcc &&
   make -j$PROCS configure-target-libgcc &&
   cd "$TARGET"/libgcc &&
   make -j$PROCS all &&
   make -j$PROCS install &&
   cd - &&
   mv config.status config.status.removed &&
   rm -f config.cache *config.cache */*/config.cache &&
   cd ..
}

install_gnumach_headers() {
   print_info "Installing GNU Mach Headers" &&
   cd $SOURCE/$GNUMACH_SRC &&
   autoreconf -i &&
   cd - &&
   mkdir -p "$GNUMACH_SRC".obj &&
   local disable_user32=""
   if [ -z "$USER32" ]; then
      disable_user32="--disable-user32"
   fi
   cd "$GNUMACH_SRC".obj &&
      $SOURCE/$GNUMACH_SRC/configure \
      --host="$TARGET" \
      --prefix="$SYS_ROOT" \
      $disable_user32 &&
   make -j$PROCS install-data &&
   cd ..
}

install_gnumig() {
   print_info "Installing cross GNU Mig" &&
   cd $SOURCE/$GNUMIG_SRC &&
   autoreconf -i &&
   cd - &&
   rm -rf $GNUMIG_SRC.host_obj &&
   mkdir -p $GNUMIG_SRC.host_obj &&
   cd $GNUMIG_SRC.host_obj &&
   $SOURCE/$GNUMIG_SRC/configure --target="$TARGET" \
      --prefix=$CROSS_TOOLS &&
   make -j$PROCS &&
   make -j$PROCS install &&
   cd ..
}

install_hurd_headers() {
   print_info "Installing Hurd headers" &&
   cd $SOURCE/$HURD_SRC &&
   autoreconf -i &&
   cd - &&
   rm -rf $HURD_SRC.obj &&
   mkdir -p $HURD_SRC.obj &&
   cd $HURD_SRC.obj &&
   $SOURCE/$HURD_SRC/configure \
      --host="$TARGET" \
      --target="$TARGET" \
      --prefix= \
      --disable-profile \
      --without-libbz2 \
      --without-libz \
      --without-rump \
      --disable-ncursesw \
      --without-parted &&
   make -j$PROCS prefix="$SYS_ROOT" no_deps=t install-headers &&
   cd ..
}

compile_first_glibc() {
   print_info "Installing glibc (first pass)" &&
   rm -rf $GLIBC_SRC.first_obj &&
   mkdir -p $GLIBC_SRC.first_obj &&
   cd $GLIBC_SRC.first_obj &&
   BUILD_CC=$HOST_CC CC=$TARGET-gcc \
   AR=$TARGET-ar CXX="cxx-not-found" RANLIB=$TARGET-ranlib \
   $SOURCE/$GLIBC_SRC/configure \
      --with-binutils=${CROSS_TOOLS}/bin \
      --build="$HOST" \
      --host="$TARGET" \
      --prefix="$SYS_ROOT" \
      --with-headers="$SYS_ROOT"/include \
      --cache-file=config.cache \
      --enable-obsolete-rpc \
      --disable-profile \
      --enable-add-ons=libpthread \
      --enable-obsolete-rpc \
      --disable-nscd \
      libc_cv_ctors_header=yes &&
   make -j$PROCS || # workaround for "fails first time"?
   make -j$PROCS &&
   make -j$PROCS install &&
   cd ..
}

compile_full_gcc () {
   print_info "Cross compiling GCC"
   rm -rf $GCC_SRC.obj &&
   mkdir -p $GCC_SRC.obj &&
   cd $GCC_SRC.obj &&
   AR=$HOST_AR \
   LDFLAGS="-Wl,-rpath,${CROSS_TOOLS}/lib" \
   $SOURCE/$GCC_SRC/configure \
      --prefix=$CROSS_TOOLS \
      --target="$TARGET" \
      --with-sysroot="$SYSTEM" \
      --with-local-prefix="$SYS_ROOT" \
      --with-native-system-header-dir="$SYS_ROOT"/include \
      --disable-static \
      --disable-nls \
      --enable-languages=c,c++ \
      --enable-threads=posix \
      --disable-multilib \
      --with-system-zlib \
      --with-libstdcxx-time \
      --disable-libstdcxx-pch \
      --disable-bootstrap \
      --disable-libcilkrts \
      --disable-libgomp &&
   make -j$PROCS AS_FOR_TARGET="$TARGET-as" LD_FOR_TARGET="$TARGET-ld" all &&
   make -j$PROCS install &&
   cd ..
}

compile_second_glibc() {
   print_info "Installing GLibC (second pass)" &&
   rm -rf $GLIBC_SRC.second_obj &&
   mkdir -p $GLIBC_SRC.second_obj &&
   cd $GLIBC_SRC.second_obj &&
   rm -f config.cache &&
   BUILD_CC=$HOST_CC CC=$TARGET-gcc CXX="" \
   AR=$TARGET-ar RANLIB=$TARGET-ranlib \
   $SOURCE/$GLIBC_SRC/configure \
      --with-binutils=$CROSS_TOOLS/bin \
      --build="$HOST" \
      --host="$TARGET" \
      --prefix="$SYS_ROOT" \
      --with-headers="$SYS_ROOT"/include \
      --enable-obsolete-rpc \
      --disable-profile \
      --enable-add-ons=libpthread \
      --enable-obsolete-rpc \
      --disable-nscd &&
   make -j$PROCS &&
   make -j$PROCS install &&
   cd ..
}

compile_pkgconfiglite() {
   # otherwise "ln pkg-config i586-pc-gnu-pkg-config" in the install step fails
   rm -fv $CROSS_TOOLS/bin/*-pkg-config &&
   rm -rf $PKGCONFIGLITE_SRC.obj &&
   mkdir -p $PKGCONFIGLITE_SRC.obj &&
   cd $PKGCONFIGLITE_SRC.obj &&
   $SOURCE/$PKGCONFIGLITE_SRC/configure \
      --prefix=$CROSS_TOOLS --host=$TARGET \
      --with-pc-path=$SYS_ROOT/lib/pkgconfig &&
   make -j$PROCS &&
   make -j$PROCS install &&
   cd ..
}

create_tools_symlink() {
    if [ ! -e $SYS_ROOT ]; then
       sudo ln -sf "$PWD"/$(basename $SYS_ROOT) $SYS_ROOT
    fi
    if [ ! -e $CROSS_TOOLS ]; then
       sudo ln -sf "$PWD"/$(basename $CROSS_TOOLS) $CROSS_TOOLS
    fi
}

setup_directories() {
   mkdir -p "$SYSTEM" && cd "$SYSTEM" &&
   mkdir -p bin boot "$(basename $SYS_ROOT)/include" "$(basename $SYS_ROOT)/lib" "$(basename $CROSS_TOOLS)/$TARGET" &&
	create_tools_symlink &&
	ln -sfn $SYS_ROOT/include $SYS_ROOT/lib $CROSS_TOOLS/$TARGET/ &&
   cd -
}