summaryrefslogtreecommitdiff
path: root/cross-gnu
blob: cb08ed0f7794df15d8826f5076d70daa6d7178e1 (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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#!/bin/sh

# Cross compile a GNU build environment,
# <http://www.gnu.org/software/hurd/toolchain/cross-gnu.html>.

# Copyright (C) 2006, 2007, 2008, 2010, 2011, 2012 Free Software Foundation,
# Inc.

# Written by Thomas Schwinge <thomas@schwinge.name>.

# This file is part of the GNU Hurd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# There are several parts marked with `TODO' in this file; feel free to have a
# look at these issues and send the outcome back to me.


# Functions from Paul Jarc's prjlibs available at
# <http://code.dogmap.org/prjlibs/>.

# sh/set_default.sh
case $? in 0) :;; *) (exit "$?");; esac &&
prj_set_default() {
  : "${2?}" &&
  eval "
  if test \"\${$1+x}\" = x; then :; else
    $1=\$2
  fi"
}


# Check for `cross-gnu-env' having been ran.

if [ x"${CROSS_GNU_REINSTALL_GLIBC-not_set}" = xnot_set ]; then
  cat >&2 <<"EOT" &&
See <http://www.gnu.org/software/hurd/toolchain/cross-gnu.html> for usage
information.
EOT
  exit 100
EOF
else :
fi &&


# Be verbose.

set -x &&


# Run-time configuration.

if test -f "$GLIBC_SRC"/elf/static-stubs.c; then
  prj_set_default GLIBC_have_static_stubs true
else
  prj_set_default GLIBC_have_static_stubs false
fi &&


# Create directories.

mkdir -p "$ROOT" &&
cd "$ROOT" &&
# TODO.  Are all these needed?
mkdir -p \
  bin \
  "$SYS_ROOT""$CROSS_GNU_USR"/include \
  "$SYS_ROOT""$CROSS_GNU_USR"/lib \
  "$TARGET" &&
# TODO.  Use relative links.
ln -sfn \
  "$SYS_ROOT""$CROSS_GNU_USR"/include \
  "$SYS_ROOT""$CROSS_GNU_USR"/lib \
  "$TARGET"/ &&


# Install the cross GNU Binutils.

mkdir -p "$BINUTILS_SRC".obj &&
cd "$BINUTILS_SRC".obj &&
# We use `config.status''s existence as an indicator whether the package was
# configured already.  (E.g. when running cross-gnu a second time to update the
# tool chain.)  Force the use of .init_array/.fini_array sections until
# auto-detection has been fixed.
if ./config.status --version > /dev/null 2>&1; then :; else
  "$BINUTILS_SRC"/configure \
    --target="$TARGET" \
    --prefix="$ROOT" \
    --with-sysroot="$SYS_ROOT" \
    --disable-nls \
    --enable-initfini-array
fi &&
"$MAKE" \
  all \
  install &&


# Install a minimal cross GCC to build a cross MIG and the GNU C Library.

mkdir -p "$GCC_SRC".obj &&
cd "$GCC_SRC".obj &&
# Perhaps we already have a complete cross GCC?
if "$TARGET"-gcc --version > /dev/null 2>&1; then :; else
  if ./config.status --version > /dev/null 2>&1; then :; else
    # TODO.  Why ``--with-newlib''?
    # TODO.  Decimal float support (``--disable-decimal-float'') is manually
    # deactivated, as there is no fenv.h yet (glibc), and there is no autoconf
    # test for its presence.
    "$GCC_SRC"/configure \
      --enable-build-with-cxx \
      --target="$TARGET" \
      --prefix="$ROOT" \
      --with-sysroot="$SYS_ROOT" \
      --disable-nls \
      --disable-shared \
      --disable-threads \
      --without-headers \
      --with-newlib \
      --disable-decimal-float \
      --enable-languages=c \
      --with-arch=i686
  fi &&

# TODO: GCC 3.3 and GCC 3.4 need this for building libgcc.a.  Not needed for
# GCC 4.0.  Get rid of this?
  : > "$SYS_ROOT""$CROSS_GNU_USR"/include/signal.h &&
  mkdir -p "$SYS_ROOT""$CROSS_GNU_USR"/include/sys &&
  : > "$SYS_ROOT""$CROSS_GNU_USR"/include/sys/ucontext.h &&

  if "$MAKE" \
      all-gcc \
      install-gcc &&
    if ! test -d "$GCC_SRC"/libgcc/; then :; else
      # libgcc is new with GCC 4.3.
      "$MAKE" \
	all-target-libgcc \
	install-target-libgcc
    fi &&
    if ! $GLIBC_have_static_stubs; then
# TODO: Make glibc happy.  We can not yet build libgcc_eh, but glibc's build
# system wants to link against that library.
# <http://sources.redhat.com/ml/libc-alpha/2003-09/msg00100.html>.  With
# $GLIBC_have_static_stubs, this is no longer necessary, as per
# id:"87txyoksdr.fsf@schwinge.name".
      echo '/* Empty.  */' > "$SYS_ROOT""$CROSS_GNU_USR"/lib/libgcc_eh.a
    fi
  then
    mv config.status config.status.removed &&
    # TODO.
    rm -f config.cache */config.cache */*/config.cache &&
    # Remove the bogus files if building the cross compiler succeeded.
    rm \
      "$SYS_ROOT""$CROSS_GNU_USR"/include/signal.h \
      "$SYS_ROOT""$CROSS_GNU_USR"/include/sys/ucontext.h
  else
    # That indication file might already have been installed, but we do not yet
    # have a complete, working cross compiler.
    rm -f "$ROOT"/bin/"$TARGET"-gcc &&
    exit 100
  fi
fi &&


# Install GNU Mach's header files.

mkdir -p "$GNUMACH_SRC".obj &&
cd "$GNUMACH_SRC".obj &&
if ./config.status --version > /dev/null 2>&1; then :; else
  # `$TARGET-gcc' doesn't work yet (to satisfy the Autoconf checks), but isn't
  # needed either.
  CC=gcc \
  "$GNUMACH_SRC"/configure \
    --host="$TARGET" \
    --prefix="$CROSS_GNU_USR"
fi &&
"$MAKE" \
  DESTDIR="$SYS_ROOT" \
  install-data &&


# Install a cross GNU MIG.

mkdir -p "$MIG_SRC".obj &&
cd "$MIG_SRC".obj &&
if ./config.status --version > /dev/null 2>&1; then :; else
  "$MIG_SRC"/configure \
    --target="$TARGET" \
    --prefix="$ROOT"
fi &&
"$MAKE" \
  all \
  install &&


# Install the GNU Hurd's core libraries' header files.

mkdir -p "$HURD_SRC".obj &&
cd "$HURD_SRC".obj &&
if ./config.status --version > /dev/null 2>&1; then :; else
  # `$TARGET-gcc' doesn't work yet (to satisfy the Autoconf checks), but isn't
  # needed either.
  CC=gcc \
  "$HURD_SRC"/configure \
    --host="$TARGET" \
    --prefix="$CROSS_GNU_USR" \
    --disable-profile \
    --without-parted
fi &&
"$MAKE" \
  prefix="$SYS_ROOT""$CROSS_GNU_USR" \
  no_deps=t \
  install-headers &&
# Below, we will reconfigure for allowing to build libpthread.
if grep -q '^CC = gcc$' config.make
then rm config.status
else :
fi &&

mkdir -p "$LIBPTHREAD_SRC".obj &&
cd "$LIBPTHREAD_SRC".obj &&
if ./config.status --version > /dev/null 2>&1; then :; else
  # `$TARGET-gcc' doesn't work yet (to satisfy the Autoconf checks), but isn't
  # needed either.
  CC=gcc \
  "$LIBPTHREAD_SRC"/configure \
    --host="$TARGET" \
    --prefix="$CROSS_GNU_USR" \
    ac_cv_lib_ihash_hurd_ihash_create=yes
fi &&
"$MAKE" \
  DESTDIR="$SYS_ROOT" \
  install-data-local-headers &&
# Below, we will reconfigure for allowing to build libpthread.
if grep -q '^CC = gcc$' Makefile
then rm config.status
else :
fi &&


# Install the GNU C Library.

# Do we already have the GNU C library installed?
if test -h "$SYS_ROOT"/lib/ld.so; then :; else
  mkdir -p "$GLIBC_SRC".obj &&
  cd "$GLIBC_SRC".obj &&
  if ./config.status --version > /dev/null 2>&1; then :; else
    # `--build' has to be set to make sure that glibc is cross compiled.
    # TODO: --disable-multi-arch
    "$GLIBC_SRC"/configure \
      AUTOCONF=: \
      --without-cvs \
      --build="$("$GLIBC_SRC"/scripts/config.guess)" \
      --host="$TARGET" \
      --prefix="$CROSS_GNU_USR" \
      --with-headers="$SYS_ROOT""$CROSS_GNU_USR"/include \
      --disable-profile \
      --disable-multi-arch
  fi &&
  # Set an invalid/obfuscated install_root in order to work around the
  # ``/usr/include/pthread.h overwrite issue''; see open_issues/glibc.
  if "$MAKE" \
       install_root=/INVALID \
       all &&
     "$MAKE" \
       install_root=/"$SYS_ROOT" \
       install
  then
    # TODO: Why doesn't `make install' do that?
    ln -sf ld.so.1 "$SYS_ROOT"/lib/ld.so &&
    if [ "$CROSS_GNU_REINSTALL_GLIBC" = n ]; then :; else
      # Force re-linking files once libgcc and libgcc_eh are available.  TODO: Is the
      # following enough?
      rm -f "$GLIBC_SRC".obj/config.status
#      rm -rf "$GLIBC_SRC".obj
    fi
  else
    # That indication file might already have been installed, but we do not yet
    # have a complete, working installation of the GNU C library.
    rm -f "$SYS_ROOT"/lib/ld.so
    exit 100
  fi
fi &&


# Install the GNU Hurd's core libraries.

cd "$HURD_SRC".obj &&
if ./config.status --version > /dev/null 2>&1; then :; else
  "$HURD_SRC"/configure \
    --host="$TARGET" \
    --prefix="$CROSS_GNU_USR" \
    --disable-profile \
    --without-parted
fi &&
"$MAKE" \
  libihash &&
"$MAKE" \
  prefix="$SYS_ROOT""$CROSS_GNU_USR" \
  libihash-install &&

mkdir -p "$LIBPTHREAD_SRC".obj &&
cd "$LIBPTHREAD_SRC".obj &&
if ./config.status --version > /dev/null 2>&1; then :; else
  "$LIBPTHREAD_SRC"/configure \
    --host="$TARGET" \
    --prefix="$CROSS_GNU_USR"
fi &&
"$MAKE" \
  all &&
"$MAKE" \
  DESTDIR="$SYS_ROOT" \
  install &&


# Install a complete cross GCC.

cd "$GCC_SRC".obj &&
if ./config.status --version > /dev/null 2>&1; then :; else
  # TODO: At the moment we only configure for creating a C compiler.
  # GCC 4.1 (and also the newer ones without patching) don't default to
  # enabling threading support for `$TARGET', thus ``--enable-threads=posix''
  # is given.
  "$GCC_SRC"/configure \
    --enable-build-with-cxx \
    --target="$TARGET" \
    --prefix="$ROOT" \
    --with-sysroot="$SYS_ROOT" \
    --disable-nls \
    --enable-threads=posix \
    --enable-languages=c,c++ \
    --with-arch=i686
fi &&
if [ x"$CROSS_GNU_USR" = x/usr ]; then :; else
  # ``The directory that should contain system headers does not exist:
  # $SYS_ROOT/usr/include''.
  mkdir -p "$SYS_ROOT"/usr/include
fi &&
"$MAKE" \
  all &&
if ! $GLIBC_have_static_stubs; then
# Remove the bogus libgcc_eh, libgcc and libgcov that may have been installed
# earlier.  TODO.  Why are libgcc.a and libgcov.a handled here?
  rm -f "$SYS_ROOT""$CROSS_GNU_USR"/lib/libgcc_eh.a \
    "$ROOT"/lib/gcc/"$TARGET"/*/libgcc.a "$ROOT"/lib/gcc/"$TARGET"/*/libgcov.a
fi &&
"$MAKE" \
  install &&


# Install the GNU C Library.

# TODO.  With $GLIBC_have_static_stubs, this may no longer be necessary, as per
# id:"87txyoksdr.fsf@schwinge.name".
mkdir -p "$GLIBC_SRC".obj &&
cd "$GLIBC_SRC".obj &&
if ./config.status --version > /dev/null 2>&1; then :; else
  # `--build' has to be set to make sure that glibc is cross compiled.
  # TODO: --disable-multi-arch
  "$GLIBC_SRC"/configure \
    AUTOCONF=: \
    --without-cvs \
    --build="$("$GLIBC_SRC"/scripts/config.guess)" \
    --host="$TARGET" \
    --prefix="$CROSS_GNU_USR" \
    --with-headers="$SYS_ROOT""$CROSS_GNU_USR"/include \
    --disable-profile \
    --disable-multi-arch
fi &&
# Set an invalid/obfuscated install_root in order to work around the
# ``/usr/include/pthread.h overwrite issue''; see open_issues/glibc.
"$MAKE" \
  install_root=/INVALID \
  all &&
"$MAKE" \
  install_root=/"$SYS_ROOT" \
  install &&


# Install a cross GDB, if requested.

if test -d "$GDB_SRC"/; then
  mkdir -p "$GDB_SRC".obj &&
  cd "$GDB_SRC".obj &&
  if ./config.status --version > /dev/null 2>&1; then :; else
    "$GDB_SRC"/configure \
      --target="$TARGET" \
      --prefix="$ROOT" \
      --with-sysroot="$SYS_ROOT" \
      --disable-nls
  fi &&
  "$MAKE" \
    all \
    install &&


  # If possible, install a cross compiled `gdbserver' to be ran on the TARGET
  # system.

  if grep -q '86-\*-gnu\*' "$GDB_SRC"/gdb/gdbserver/README; then
    mkdir -p gdb/gdbserver &&
    cd gdb/gdbserver &&
    if ./config.status --version > /dev/null 2>&1; then :; else
      "$GDB_SRC"/gdb/gdbserver/configure \
        --host="$TARGET" \
        --prefix="$SYS_ROOT"
    fi &&
    "$MAKE" \
      all \
      install
  else :
  fi
fi &&


# Success.

echo "$0"': Everything should be in place now.'