summaryrefslogtreecommitdiffstats
path: root/d/gcc/gcc.SlackBuild
blob: ecadc68f48a9a122910441cbf716154f41ca0ee8 (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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
#!/bin/sh
# GCC package build script (written by volkerdi@slackware.com)
#
# Copyright 2003, 2004  Slackware Linux, Inc., Concord, California, USA
# Copyright 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014  Patrick J. Volkerding, Sebeka, MN, USA
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#

# Modified 2011 by Eric Hameleers <alien at slackware.com> for OpenJDK.

# Some notes, Fri May 16 12:31:32 PDT 2003:
#
# Why i486 and not i386?  Because the shared C++ libraries in gcc-3.2.x will
# require 486 opcodes even when a 386 target is used (so we already weren't
# compatible with the i386 for Slackware 9.0, didn't notice, and nobody
# complained :-).  gcc-3.3 fixes this issue and allows you to build a 386
# compiler, but the fix is done in a way that produces binaries that are not
# compatible with gcc-3.2.x compiled binaries.  To retain compatibility with
# Slackware 9.0, we'll have to use i486 (or better) as the compiler target
# for gcc-3.3.
#
# It's time to say goodbye to i386 support in Slackware.  I've surveyed 386
# usage online, and the most common thing I see people say when someone asks
# about running Linux on a 386 is to "run Slackware", but then they also 
# usually go on to say "be sure to get an OLD version, like 4.0, before glibc,
# because it'll be more efficient."  Now, if that's the general advice, then
# I see no reason to continue 386 support in the latest Slackware (and indeed
# it's no longer easily possible).

PKGNAM="gcc"
VERSION=${VERSION:-$(echo $PKGNAM-*.tar.xz | rev | cut -f 3- -d . | cut -f 1 -d - | rev)}
BUILD=${BUILD:-1}
PREFIX=${PREFIX:-usr}

# How many jobs to run in parallel:
NUMJOBS=" -j 7 "

# Automatically determine the architecture we're building on:
if [ -z "$ARCH" ]; then
  case "$(uname -m)" in
    i?86) ARCH=i486 ;;
    arm*) readelf /usr/bin/file -A | egrep -q "Tag_CPU.*[4,5]" && ARCH=arm || ARCH=armv7lh ;;
    # Unless $ARCH is already set, use uname -m for all other archs:
    *) ARCH=$(uname -m) ;;
  esac
  export ARCH
fi

if [ "$ARCH" = "i486" -o "$ARCH" = "i586" -o "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=$ARCH -mtune=i686"
  LIB_ARCH=i386
elif [ "$ARCH" = "s390" ]; then
  SLKCFLAGS="-O2"
  LIB_ARCH=s390
elif [ "$ARCH" = "x86_64" ]; then
  SLKCFLAGS="-O2"
  LIB_ARCH=amd64
elif [ "$ARCH" = "armv7hl" ]; then
  SLKCFLAGS="-O3 -march=armv7-a -mfpu=vfpv3-d16"
  LIB_ARCH=armv7hl
else
  SLKCFLAGS="-O2"
  LIB_ARCH=$ARCH
fi

if [ -z "${TARGET_TRIPLET}" ]; then
  case "$ARCH" in
    arm*) TARGET_TRIPLET=$ARCH-slackware-linux-gnueabi ;;
    *)    TARGET_TRIPLET=$ARCH-slackware-linux ;;
  esac
fi

BUILD_TRIPLET=${BUILD_TRIPLET:-${TARGET_TRIPLET}}
HOST_TRIPLET=${HOST_TRIPLET:-${TARGET_TRIPLET}}

GCC_CORE="${GCC_CORE:-"no"}"
if [ x"${GCC_CORE}" = x"yes" ]; then
  GCC_LANGUAGES=${GCC_LANGUAGES:-"c,c++"}
else
  GCC_LANGUAGES=${GCC_LANGUAGES:-"c,c++,ada,fortran,go,java,objc"}
fi

HOST_STRIP=${HOST_STRIP:-"strip"}
TARGET_STRIP=${TARGET_STRIP:-"strip"}

libdirsuffix_of_triplet() {
  case "${1}" in
    i?86-*-*)   echo ""   ;;
    x86_64-*-*) echo "64" ;;
  esac
}

LIBDIRSUFFIX_TGT="$(libdirsuffix_of_triplet "${TARGET_TRIPLET}")"
LIBDIRSUFFIX_HST="$(libdirsuffix_of_triplet "${HOST_TRIPLET}")"

GCC_ARCHOPTS="--disable-multilib"

case "${TARGET_TRIPLET}" in
  i686-*-mingw*)
    GCC_ARCHOPTS+=" --with-arch=pentium3"
    ;;
  x86_64-*-mingw*)
    ;;
  *)
    GCC_ARCHOPTS+=" --with-arch=$(echo "${TARGET_TRIPLET}" | cut -f1 -d-)"
    WITH_OBJC_GC="--enable-objc-gc"
    ;;
esac

case "${HOST_TRIPLET}" in
  *-*-mingw*) EXE=".exe" ;;
  *)          EXE="" ;;
esac

if [ "${BUILD_TRIPLET}" != "${TARGET_TRIPLET}" ]; then
  GCC_BOOTSTRAP="--disable-bootstrap"
else
  GCC_BOOTSTRAP="--enable-bootstrap"
fi

CWD=$(pwd)
# Temporary build location.  This should *NOT* be a directory
# path a non-root user could create later...
TMP=${TMP:-"/gcc-$(mcookie)"}/gcc

# This is the main DESTDIR target:
PKG_GCC=$TMP/package-gcc

ALL_PKGS="${PKG_GCC}"
ALL_COMPILERS="gcc"
ALL_LIBS="libmudflap libgomp"

if echo ${GCC_LANGUAGES} | grep -q 'c++'; then
  PKG_GCC_GPP=$TMP/package-gcc-g++
  ALL_PKGS+=" ${PKG_GCC_GPP}"
  ALL_COMPILERS+=" gcc-g++"
  ALL_LIBS+=" libstdc++-v3"
fi
if echo ${GCC_LANGUAGES} | grep -q 'fortran'; then
  PKG_GCC_GFORTRAN=$TMP/package-gcc-gfortran
  ALL_PKGS+=" ${PKG_GCC_GFORTRAN}"
  ALL_COMPILERS+=" gcc-gfortran"
  ALL_LIBS+=" libgfortran"
fi
if echo ${GCC_LANGUAGES} | grep -q 'ada'; then
  PKG_GCC_GNAT=$TMP/package-gcc-gnat
  ALL_PKGS+=" ${PKG_GCC_GNAT}"
  ALL_COMPILERS+=" gcc-gnat"
  ALL_LIBS+=" libada"
fi
if echo ${GCC_LANGUAGES} | grep -q 'java'; then
  PKG_GCC_JAVA=$TMP/package-gcc-java
  ALL_PKGS+=" ${PKG_GCC_JAVA}"
  ALL_COMPILERS+=" gcc-java"
  ALL_LIBS+=" libffi libjava"
  WITH_LIBGCJ="--enable-libgcj"
fi
if echo ${GCC_LANGUAGES} | grep -q 'objc'; then
  PKG_GCC_OBJC=$TMP/package-gcc-objc
  ALL_PKGS+=" ${PKG_GCC_OBJC}"
  ALL_COMPILERS+=" gcc-objc"
  ALL_LIBS+=" libobjc"
fi
if echo ${GCC_LANGUAGES} | grep -q 'go'; then
  PKG_GCC_GO=$TMP/package-gcc-go
  ALL_PKGS+=" ${PKG_GCC_GO}"
  ALL_COMPILERS+=" gcc-go"
  # ALL_LIBS+=" libgo"
fi

ALL_ELEMENTS="main ${ALL_COMPILERS} ${ALL_LIBS}"

# pkg_of_element "${ELEMENT}"
# Given an "element" (which is a member of ${ALL_ELEMENTS}), return its
# destination package
pkg_of_element() {
  case "$1" in
    gcc | libmudflap | libgomp | main) echo "${PKG_GCC}";;
    gcc-g++ | libstdc++-v3) echo "${PKG_GCC_GPP}" ;;
    gcc-gfortran | libgfortran) echo "${PKG_GCC_GFORTRAN}" ;;
    gcc-gnat | libada) echo "${PKG_GCC_GNAT}" ;;
    gcc-java | libffi | libjava) echo "${PKG_GCC_JAVA}" ;;
    gcc-objc | libobjc) echo "${PKG_GCC_OBJC}" ;;
    gcc-go) echo "${PKG_GCC_GO}" ;;
  esac
}

# doc_dir_of_element "${ELEMENT}"
# Given an "element" (which is a member of ${ALL_ELEMENTS}", return the path
# to the corresponding documentation inside the build directory
doc_dir_of_element() {
  case "$1" in
    main) echo "." ;;
    gcc) echo "gcc" ;;
    gcc-g++) echo "NONE" ;;
    gcc-gfortran) echo "gcc/fortran" ;;
    gcc-gnat) echo "gcc/ada" ;;
    gcc-java) echo "gcc/java" ;;
    gcc-objc | libobjc) echo "gcc/objc" ;;
    gcc-go) echo "gcc/go" ;;
    lib*) echo "$1" ;;
    # I would have liked to write the following but it's not valid syntax:
    # lib{omp,mudflap,java,ffi,ada,gfortran,stdc++-v3,objc}) echo "$1" ;;
  esac
}

# If there's a new file, installing at least part of the recent history
# is useful, but don't let it get totally out of control:
install_with_length_limit() {
  local FILE="$1"
  local DOCSDIR="$2"
  if [ -r "$FILE" ]; then
    cat "$FILE" | head -n 1000 > "${DOCSDIR}/${FILE}"
    touch -r "$FILE" "${DOCSDIR}/${FILE}"
  fi
}

# move_from_pkg_gcc "${GLOB}"
# When issuing "make install", everything gets installed in a single directory
# and then moved to the corresponding package. This function moves files
# matching expression (given as $*) from ${PKG_GCC} to the current package
# directory.
move_from_pkg_gcc() {
  local SRC_DIR="$(dirname "$1")"
  mkdir -p "${SRC_DIR}"
  local DEST_DIR="$(cd "${SRC_DIR}" && pwd)"
  (cd "${PKG_GCC}" && eval mv $* "${DEST_DIR}")
}

# symlink_to "${LINK_TARGET}" file1 file2 file3
# A common operation is to symlink several files to one in order to be able to
# use several names for it: gcc, x86_64-slackware-linux-gcc, cc, ...
symlink_to() {
  local LINK_TARGET="$1"
  shift
  for bin in $*; do
    ln -sf "${LINK_TARGET}" "${bin}"
  done
}

# compress_info_files ${PREFIX}
# Compress info files in ${PREFIX}/info if any.
compress_info_files() {
  [ -d $1/${PREFIX}/info ] && ( cd $1/${PREFIX}/info && rm -f dir && gzip -9 *)
}

description_of_compiler() {
  local PKG="${1}"
  cat "${CWD}/slack-desc.${PKG}" \
    | sed -e 's;/;\\/;g' \
    | sed -n "/^${PKG}:/ s#^${PKG}: ##p" \
    | sed -e 's;";\\\\";g' \
    | tr -d '()#' \
    | tr '\n' ' '
}

# Clear the build locations:
if [ -d $TMP ]; then
  rm -rf $TMP
fi
for PKG in ${ALL_PKGS}; do
  mkdir -p ${PKG}/${PREFIX}/doc/gcc-${VERSION}
done

# Insert package descriptions:
for COMPILER in ${ALL_COMPILERS}; do
  PKG="$(pkg_of_element "${COMPILER}")"
  if [ -e "slack-desc.${COMPILER}" ]; then
    mkdir -p ${PKG}/install
    cat $CWD/slack-desc.${COMPILER} > $PKG/install/slack-desc
  fi
done

set -e

cd $TMP
tar xvf $CWD/gcc-$VERSION.tar.?z*
# (cd gcc-$VERSION
# mv boehm-gc boehm-gc.orig
# tar xvf $CWD/gc-7.2d.tar.gz
# cp boehm-gc.orig/gc_ext_config.h.in gc-7.2
# mv gc-7.2 boehm-gc)

#( cd gcc-$VERSION
#  If we had any patches, we would apply them here, but we're .diff free now.
#) || exit 1

# Copy ecj.jar into the TLD of the source. Needed for java compiler.
# This can be retrieved from ftp://sourceware.org/pub/java
# cp $CWD/ecj-4.5.jar gcc-$VERSION/ecj.jar

# Use an antlr runtime to compile javadoc.
# The runtime can be obtained from:
#https://oss.sonatype.org/content/repositories/releases/org/antlr/antlr-runtime/
ANTLJAR=$(echo $CWD/antlr-*.jar | tail -1)

# install docs
if [ x"$GCC_CORE" != x"yes" ]; then ( cd gcc-$VERSION
  # Smite the fixincludes:
  zcat $CWD/gcc-no_fixincludes.diff.gz | patch -p1 --verbose --backup --suffix=.orig || exit 1
  # Fix perms/owners
  chown -R root:root .
  chmod -R u+w,go+r-w,a-s .

  for ELEMENT in ${ALL_ELEMENTS}; do
    DOC_DIR="$(doc_dir_of_element "${ELEMENT}")"
    if [ "${DOC_DIR}" = "NONE" ]; then
      continue
    fi
    PKG="$(pkg_of_element "${ELEMENT}")"
    PKG_DOC_DIR="${PKG}/${PREFIX}/doc/gcc-${VERSION}/${DOC_DIR}"
    unset FULL_FILES
    LIMITED_FILES=ChangeLog
    case "${ELEMENT}" in
      main)
        FULL_FILES="COPYING* ChangeLog* INSTALL LAST_UPDATED MAINTAINERS README*"
        LIMITED_FILES="${LIMITED_FILES} NEWS"
        ;;
      gcc) FULL_FILES="ABOUT* COPYING* DATESTAMP DEV-PHASE LANG* ONEWS README*" ;;
      gcc-gnat | gcc-java) FULL_FILES="ChangeLog.tree-ssa" ;;
      gcc-go) FULL_FILES="README* gofrontend/{LICENSE,PATENTS,README}" ;;
      libffi) FULL_FILES="ChangeLog.libgcj ChangeLog.v1 LICENSE* README*" ;;
      libjava) FULL_FILES="COPYING* HACKING LIBGCJ_LICENSE NEWS README* THANKS" ;;
      libstdc++-v3) FULL_FILES="README* doc/html/faq.html" ;;
    esac
    mkdir -p "${PKG_DOC_DIR}"
    (cd ${DOC_DIR}
      if [ -n "${FULL_FILES}" ]; then
        eval cp -a "${FULL_FILES}" "${PKG_DOC_DIR}"
      fi
      for FILE in $(eval echo "${LIMITED_FILES}"); do
        install_with_length_limit "${FILE}" "${PKG_DOC_DIR}"
      done)
  done
)
fi

# Mingw requires a kludge known as "winsup". It seems it's only needed when
# cross-compiling a native compiler that targets i686-*-mingw32 (and runs on
# that same triplet).
case "${HOST_TRIPLET},${TARGET_TRIPLET}" in
  "i686-w64-mingw32","i686-w64-mingw32")
    mkdir -p winsup/mingw
    ln -s ${YYPREFIX_CROSS_TOOLCHAIN}/${TARGET_TRIPLET}/include winsup/mingw/include
    ;;
esac

if [ -n "${LIBDIRSUFFIX_TGT}" ]; then
  ln -s /${PREFIX}/${TARGET_TRIPLET}/lib{,${LIBDIRSUFFIX_TGT}}
fi

# build gcc
  mkdir gcc.build.lnx;
  cd gcc.build.lnx;

  CFLAGS="$SLKCFLAGS" \
  CXXFLAGS="$SLKCFLAGS" \
  ../gcc-$VERSION/configure --prefix=/${PREFIX} --with-sysroot=/${PREFIX} \
     --libdir=/${PREFIX}/lib$LIBDIRSUFFIX_HST \
     --mandir=/${PREFIX}/man \
     --infodir=/${PREFIX}/info \
     --enable-shared \
     ${GCC_BOOTSTRAP} \
     ${GCC_ARCHOPTS} \
     --enable-threads=posix \
     --enable-languages=${GCC_LANGUAGES} \
     --enable-checking=release \
     ${WITH_OBJC_GC} \
     --enable-libgomp \
     --with-system-zlib \
     --with-python-dir=/lib$LIBDIRSUFFIX_HST/python2.7/site-packages \
     --disable-libunwind-exceptions \
     --enable-__cxa_atexit \
     --enable-libssp \
     --with-gnu-ld \
     --verbose \
     --enable-java-home \
     --with-java-home=/${PREFIX}/lib$LIBDIRSUFFIX_HST/jvm/jre \
     --with-jvm-root-dir=/${PREFIX}/lib$LIBDIRSUFFIX_HST/jvm \
     --with-jvm-jar-dir=/${PREFIX}/lib$LIBDIRSUFFIX_HST/jvm/jvm-exports \
     --with-arch-directory=$LIB_ARCH \
     --with-antlr-jar=$ANTLJAR \
     --disable-java-awt \
     --disable-gtktest \
     ${WITH_LIBGCJ} \
     --build=$BUILD_TRIPLET \
     --host=$HOST_TRIPLET \
     --target=$TARGET_TRIPLET || exit 1

  # WIP attempt to get a more up-to-date boehm in GCC
  # (
  # mkdir -p -- ${TARGET_TRIPLET}/boehm-gc
  # cd ${TARGET_TRIPLET}/boehm-gc

  # CFLAGS="-O2" \
  # CXXFLAGS="-O2" \
  # ../../../gcc-$VERSION/boehm-gc/configure \
  #   --prefix=/${PREFIX} \
  #   --libdir=/${PREFIX}/lib${LIBDIRSUFFIX} \
  #   --mandir=/${PREFIX}/man \
  #   --enable-static=no \
  #   --host=${TARGET_TRIPLET} \
  #   --build=$ARCH-slackware-linux

  # mv configure configure.real
  # ln -s /bin/true configure
  # )

  # Start the build:

  # Include all debugging info (for now):
  if [ x"$GCC_CORE" = x"yes" ]; then
    make all-gcc $NUMJOBS
    make install-gcc DESTDIR=$PKG_GCC
  else
    make $NUMJOBS
    make info
    # Set GCCCHECK=something to run the tests
    if [ -n "$GCCCHECK" ]; then
      make $NUMJOBS check
    fi
    make install DESTDIR=$PKG_GCC
    make install-info DESTDIR=$PKG_GCC
  fi

  # KLUDGE ALERT
  # These *gdb.py files are causing ldconfig to complain, so they are going
  # to be REMOVED for now...  at some point, they might be moved somewhere
  # else, in which case things should Just Work(tm).  Keep an eye on it.
  rm -f $PKG_GCC/${PREFIX}/lib${LIBDIRSUFFIX_HST}/*gdb.py

  # Be sure the "specs" file is installed.

  SPECS="${PREFIX}/lib${LIBDIRSUFFIX_HST}/gcc/${TARGET_TRIPLET}/${VERSION}/specs"
  if [ ! -r $PKG_GCC/${SPECS} ]; then
    cat gcc/specs > $PKG_GCC/${SPECS}
  fi

  # Add, e.g., /opt/windows_32/{include,lib} to default search paths
  if [ x"${HOST_TRIPLET}" != x"${TARGET_TRIPLET}" ]; then
    prefix_dir="/${YYPREFIX_TARGET}"

    sed -i \
      -e "/^\*lib:$/ { N; s;$; -L${prefix_dir}/lib${LIBDIRSUFFIX_TGT}; }" \
      -e "/^\*cpp:$/ { N; s;$; -I${prefix_dir}/include; }" \
      -e "/^\*cc1plus:$/ { N; s;$; -I${prefix_dir}/include; }" \
      ${PKG_GCC}/${SPECS}
  fi

  # Make our 64bit gcc look for 32bit gcc binaries in ./32 subdirectory:
  if [ "$ARCH" = "x86_64" ]; then
    sed -i 's#;.\(:../lib !m64 m32;\)$#;32\1#' ${PKG_GCC}/${SPECS}
  fi

  chmod 755 $PKG_GCC/${PREFIX}/lib${LIBDIRSUFFIX_HST}/libgcc_s.so.1

  # The (huge) static GNU java libraries are not packaged.  In nearly all
  # cases one or more dependencies will not be available as static anyway.
  rm -f $PKG_GCC/${PREFIX}/lib${LIBDIRSUFFIX_HST}/libgcj.a
  rm -f $PKG_GCC/${PREFIX}/lib${LIBDIRSUFFIX_HST}/libgcj-tools.a

  # Fix stuff up:
  compress_info_files ${PKG_GCC}
  ( cd $PKG_GCC
    # *not* ${LIBDIRSUFFIX_HST}
    mkdir -p ${PREFIX}/lib
    ln -sf /${PREFIX}/bin/cpp ${PREFIX}/lib/cpp
    # GCC puts its files in $(toolexeclibdir) which is $(libdir)/../lib in the
    # case of cross-compilation. There is no way to change it. A particular
    # thought to Cygwin people who said it didn't matter since you're going to
    # build an installer for Windows anyway and you can move the files in it,
    # i.e. they ignore this need because you're going to be able to work-around
    # the issue in the installer.
    mv ${PREFIX}/lib/lib*.dll ${PREFIX}/bin/
  )

  ( cd $PKG_GCC/${PREFIX}/bin
    mv ${TARGET_TRIPLET}-gfortran ${TARGET_TRIPLET}-gfortran-gcc
    for bin in gcc g++ gfortran-gcc gcc-{ar,nm,ranlib} gcj gcjh; do
      if [ -e ${bin}${EXE} ]; then
        mv ${bin}${EXE} ${TARGET_TRIPLET}-${bin}-${VERSION}${EXE}
      elif [ -e "${bin}" ]; then
        mv ${bin} ${TARGET_TRIPLET}-${bin}-${VERSION}${EXE}
      fi
      if [ -e ${TARGET_TRIPLET}-${bin}${EXE} ]; then
        mv ${TARGET_TRIPLET}-${bin}${EXE} ${TARGET_TRIPLET}-${bin}-${VERSION}${EXE}
      fi
    done
    symlink_to "${TARGET_TRIPLET}-gcc-${VERSION}${EXE}" ${TARGET_TRIPLET}-gcc${EXE}
    symlink_to "${TARGET_TRIPLET}-g++-${VERSION}${EXE}" ${TARGET_TRIPLET}-{c++,g++}${EXE}
    if [ -n "${PKG_GCC_GFORTRAN}" ]; then
      symlink_to "${TARGET_TRIPLET}-gfortran-gcc-${VERSION}${EXE}" ${TARGET_TRIPLET}-{gfortran,g95,g77}${EXE}
    fi
    if [ x"${HOST_TRIPLET}" = x"${TARGET_TRIPLET}" ]; then
      for bin in gcc gcc-{ar,nm,ranlib}; do
        symlink_to "${TARGET_TRIPLET}-${bin}-${VERSION}${EXE}" ${bin}${EXE} ${bin}-${VERSION}${EXE}
      done
      symlink_to "${TARGET_TRIPLET}-gcc-${VERSION}${EXE}" cc${EXE}
      symlink_to "${TARGET_TRIPLET}-g++-${VERSION}${EXE}" g++${EXE} c++${EXE}
      if [ -n "${PKG_GCC_JAVA}" ]; then
        symlink_to "${TARGET_TRIPLET}-gcj-${VERSION}${EXE}${EXE}" gcj gcj-${VERSION}${EXE}
        symlink_to "${TARGET_TRIPLET}-gcjh-${VERSION}${EXE}${EXE}" gcjh gcjh-${VERSION}${EXE}
      fi
      if [ -n "${PKG_GCC_GFORTRAN}" ]; then
        symlink_to "${TARGET_TRIPLET}-gfortran-${VERSION}${EXE}" gfortran${EXE} fortran${EXE} {f,g}{95,77}${EXE}
      fi
    fi
  )

  ( cd $PKG_GCC/${PREFIX}/man
    gzip -9 */*
    cd man1
    # For cross-toolchains, the g++ and gcc manpages are prefixed with the
    # target triplet; we could create ${TARGET_TRIPLET}-cc manpages but I don't
    # think anyone would try to read them so skip them entirely.
    if [ "${HOST_TRIPLET}" = "${TARGET_TRIPLET}" ]; then
      ln -sf g++.1.gz c++.1.gz
      ln -sf gcc.1.gz cc.1.gz
    fi
  )

# OK, time to split the big package where needed:

# gcc-g++:
if [ -n "${PKG_GCC_GPP}" ]; then ( cd $PKG_GCC_GPP
  move_from_pkg_gcc "${PREFIX}/bin/*++*"
  move_from_pkg_gcc "${PREFIX}/libexec/gcc/$TARGET_TRIPLET/$VERSION/cc1plus"
  move_from_pkg_gcc "${PREFIX}/man/man1/*++*"
  if [ x"${HOST_TRIPLET}" = x"${TARGET_TRIPLET}" ]; then
    move_from_pkg_gcc "${PREFIX}/include/c++"
    move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/*++*"
  else
    move_from_pkg_gcc "${PREFIX}/${TARGET_TRIPLET}/include/c++"
    move_from_pkg_gcc "${PREFIX}/${TARGET_TRIPLET}/lib${LIBDIRSUFFIX_TGT}/*++*"
  fi
); fi

# gcc-gfortran:
if [ -n "${PKG_GCC_GFORTRAN}" ]; then ( cd $PKG_GCC_GFORTRAN
  move_from_pkg_gcc "${PREFIX}/bin/{*gfortran*,*95*,*77*}"
  move_from_pkg_gcc "${PREFIX}/info/gfortran*"
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/gcc/$TARGET_TRIPLET/$VERSION/{finclude,libgfortran*}"
  move_from_pkg_gcc "${PREFIX}/libexec/gcc/$TARGET_TRIPLET/$VERSION/f951"
  move_from_pkg_gcc "${PREFIX}/man/man1/*gfortran*"
  if [ x"${HOST_TRIPLET}" = x"${TARGET_TRIPLET}" ]; then
    move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_TGT}/libgfortran*"
  else
    move_from_pkg_gcc "${PREFIX}/${TARGET_TRIPLET}/lib${LIBDIRSUFFIX_TGT}/libgfortran*"
  fi
); fi

# gcc-gnat:
# First, relocate ${PREFIX}/bin/gnative2ascii to the gcc-java package so it
# isn't matched and accidentally put in gcc-gnat:
if [ -n "${PKG_GCC_JAVA}" ]; then
  mkdir -p $PKG_GCC_JAVA/${PREFIX}/bin
  mv $PKG_GCC/${PREFIX}/bin/gnative2ascii $PKG_GCC_JAVA/${PREFIX}/bin
fi
# Now make the gcc-gnat package tree:
if [ -n "${PKG_GCC_GNAT}" ]; then ( cd $PKG_GCC_GNAT
  move_from_pkg_gcc "${PREFIX}/bin/*gnat*"
  move_from_pkg_gcc "${PREFIX}/info/*gnat*"
  move_from_pkg_gcc "${PREFIX}/libexec/gcc/$TARGET_TRIPLET/$VERSION/gnat1"
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/gcc/$TARGET_TRIPLET/$VERSION/ada{include,lib}"
); fi

# gcc-java:
if [ -n "${PKG_GCC_JAVA}" ]; then ( cd $PKG_GCC_JAVA
  # this used to mv fastjar too
  move_from_pkg_gcc "${PREFIX}/bin/{aot-compile,gappletviewer,gc-analyze,*gcj*,gij,gjar,gjarsigner,gjdoc,gkeytool,grmid,grmic,grmiregistry,gserialver,gtnameserv,gjavah,gorbd,jcf-dump,jv-*}"
  # Move some Java only C++ headers from the C++ package:
  (DIR="${PREFIX}/include/c++/$VERSION";
    mkdir -p ${DIR} && mv $PKG_GCC_GPP/$DIR/{gcj,gnu,java,javax,org,sun} $DIR)
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/gcc/$TARGET_TRIPLET/$VERSION/include/{jawt,ffi,ffitarget,jawt_md,jni,jni_md,jvmpi}.h"
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/gcc/$TARGET_TRIPLET/$VERSION/include/gcj"
  # aot-compile Python plugins:
  if [ ! -d $PKG_GCC/${PREFIX}/lib${LIBDIRSUFFIX_HST}/python2.7 ]; then
    echo "NO $PKG_GCC/${PREFIX}/lib${LIBDIRSUFFIX_HST}/python2.7 !"
    exit 1
  fi
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/python2.7"
  move_from_pkg_gcc "${PREFIX}/info/gcj.*"
  # move_from_pkg_gcc ${PREFIX}/info/fastjar.*"
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/{libffi*,logging.properties,gcj*,libgcj*,libgij*,security}"
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/pkgconfig/libgcj*.pc"
  rmdir $PKG_GCC/${PREFIX}/lib${LIBDIRSUFFIX_HST}/pkgconfig 2> /dev/null
  move_from_pkg_gcc "${PREFIX}/libexec/gcc/$TARGET_TRIPLET/$VERSION/{jc1,ecj1,jvgenmain}"
  move_from_pkg_gcc "${PREFIX}/man/man1/{aot-compile,gappletviewer,gc-analyze,gcj,gcjh,gcj-dbtool,gij,gjar,gjarsigner,gjavah,gjdoc,gkeytool,gnative2ascii,gorbd,grmic,grmid,grmiregistry,gserialver,gtnameserv,jcf-dump,jv-convert,rebuild-gcj-db}.1.gz"
  move_from_pkg_gcc "${PREFIX}/man/man3/ffi*"
  move_from_pkg_gcc "${PREFIX}/share/java"
  # The ecj wrapper script:
  cat $CWD/ecj.sh | sed -e "s,@JAVADIR@,/${PREFIX}/share/java," > ${PREFIX}/bin/ecj
  chmod 755 ${PREFIX}/bin/ecj
  # The JAVA_HOME compatibility links.
  # Caution: non-multilib arch-independent stuff! No lib64 here.
  move_from_pkg_gcc ${PREFIX}/lib${LIBDIRSUFFIX_HST}/jvm*
  # And add the missing javac symlink:
  ln -s ../../../bin/ecj ${PREFIX}/lib$LIBDIRSUFFIX_HST/jvm/bin/javac
  # Don't package libffi stuff anymore.  GCC will link the internal version
  # statically, and we'll need a newer one elsewhere.
  find . \( -name "ffi*.h" -o -name "libffi*" \) -exec rm -f {} +
  rm -f ${PREFIX}/man/man3/ffi*
  rm -f ${PREFIX}/info/libffi*
) || exit 1; fi

# gcc-objc:
if [ -n "${PKG_GCC_OBJC}" ]; then ( cd $PKG_GCC_OBJC
  if [ x"${HOST_TRIPLET}" = x"${TARGET_TRIPLET}" ]; then
    move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_TGT}/libobjc*"
  else
    move_from_pkg_gcc "${PREFIX}/${TARGET_TRIPLET}/lib${LIBDIRSUFFIX_TGT}/libobjc*"
  fi
  move_from_pkg_gcc "${PREFIX}/libexec/gcc/$TARGET_TRIPLET/$VERSION/cc1obj"
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/gcc/$TARGET_TRIPLET/$VERSION/include/objc"
); fi

# gcc-go:
if [ -n "${PKG_GCC_GO}" ]; then ( cd $PKG_GCC_GO
  move_from_pkg_gcc "${PREFIX}/bin/*gccgo*"
  move_from_pkg_gcc "${PREFIX}/libexec/gcc/$TARGET_TRIPLET/$VERSION/go1"
  move_from_pkg_gcc "${PREFIX}/info/gccgo.info.gz"
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/{go,libgo.la,libgo.so*,libgobegin.a}"
  (cd ${PREFIX}/lib${LIBDIRSUFFIX_HST} && [ -e libgo.la -a -e libgo.so.0.* -a -e libgobegin.a ])
  # Ordinarily Slackware does not package static libraries, but in this case
  # it is useful for deploying compiled binaries on machines that do not yet
  # have libgo.so.0.0.0.
  move_from_pkg_gcc "${PREFIX}/lib${LIBDIRSUFFIX_HST}/libgo.a"
  move_from_pkg_gcc "${PREFIX}/man/man1/gccgo.1.gz"
); fi

# Filter all .la files (thanks much to Mark Post for the sed script):
find $TMP -type f -name "*.la" | xargs sed -i -e 's%-L/gcc-[[:graph:]]* % %g'

# Strip bloated binaries and libraries:
strip_f() {
  find ${ALL_PKGS} -type f | xargs file | egrep "${1}" | grep "${2}"| cut -f 1 -d : | xargs ${3} 2> /dev/null
}

strip_f "executable|shared object" "${HOST_EXE_FORMAT}" "${HOST_STRIP} --strip-unneeded"

if echo "$TARGET_TRIPLET" | grep -q mingw; then
  strip_f "DLL" "${TARGET_EXE_FORMAT}" "${TARGET_STRIP} --strip-unneeded"
else
  strip_f "shared object" "${TARGET_EXE_FORMAT}" "${TARGET_STRIP} --strip-unneeded"
fi

strip_f "current ar archive" "" "${TARGET_STRIP} -g"

# for COMPILER in ${ALL_COMPILERS}; do
#   ( cd "$(pkg_of_element "${COMPILER}")"
#     makepkg -l y -c n $TMP/${COMPILER}-${VERSION}-${ARCH}-${BUILD}.txz )
# done

for COMPILER in ${ALL_COMPILERS}; do
  cat ${CWD}/$PKGNAM.yypkg.script | sed \
    -e "s/%{PKG}/${COMPILER}/" \
    -e "s/%{HST}/${HOST_TRIPLET}/" \
    -e "s/%{TGT}/${TARGET_TRIPLET}/" \
    -e "s/%{VER}/${VERSION}/" \
    -e "s/%{BUILD}/${BUILD}/" \
    -e "s/%{DESCR}/$(description_of_compiler "${COMPILER}")/" \
    | yypkg --makepkg --output ${YYOUTPUT} --script - --directory "$(pkg_of_element "${COMPILER}")/${PREFIX}"
done

echo
echo "Slackware GCC package build complete!"
echo