devtools/cross/pkgs/gcc/build.sh

122 lines
5.0 KiB
Bash
Raw Normal View History

2018-11-26 00:57:13 +01:00
#!/bin/bash
echo "Cross compiling GCC and dependencies"
export WORKING_DIR="$JEHANNE/hacking/cross/pkgs/gcc"
# include x86_64-jehanne-pkg-config in PATH
export PATH="$JEHANNE/hacking/cross/:$PATH"
function failOnError {
# $1 -> exit status on a previous command
# $2 -> task description
if [ $1 -ne 0 ]; then
echo "ERROR $2"
echo
echo BUILD LOG:
echo
cat $WORKING_DIR/gcc.build.log
2018-11-26 00:57:13 +01:00
exit $1
fi
}
function dynpatch {
# $1 -> path from $WORKING_DIR/src
# $2 -> string to search
( cd $WORKING_DIR/src &&
grep -q jehanne $1 ||
sed -n -i -e "/$2/r ../patch/$1" -e '1x' -e '2,${x;p}' -e '${x;p}' $1
)
}
2018-11-26 00:57:13 +01:00
date > $WORKING_DIR/gcc.build.log
2018-11-29 02:38:34 +01:00
# verify libtool is installed
libtool --version >> /dev/null
failOnError $? "libtool installation check"
2018-11-28 11:47:24 +01:00
2018-11-26 00:57:13 +01:00
(cd src && fetch) >> $WORKING_DIR/gcc.build.log
failOnError $? "fetching sources"
2018-11-28 18:32:39 +01:00
echo -n Building libgmp... | tee -a $WORKING_DIR/gcc.build.log
2018-11-26 00:57:13 +01:00
(
cd src/libgmp &&
2018-11-29 02:38:34 +01:00
( grep -q jehanne configfsf.sub || patch -p0 < $WORKING_DIR/patch/libgmp.patch ) &&
./configure --host=x86_64-jehanne --prefix=/posix/ --with-sysroot=$JEHANNE &&
make &&
2018-11-29 02:38:34 +01:00
make DESTDIR=$JEHANNE/pkgs/libgmp/6.1.2/ install &&
libtool --mode=finish $JEHANNE/posix/lib
) >> $WORKING_DIR/gcc.build.log 2>&1
2018-11-26 00:57:13 +01:00
failOnError $? "Building libgmp"
echo done.
2018-11-29 02:38:34 +01:00
#2 Copy to /posix (to emulate bind during cross compilation)
2018-11-28 11:47:24 +01:00
cp -pfr $JEHANNE/pkgs/libgmp/6.1.2/posix/* $JEHANNE/posix
2018-11-28 18:32:39 +01:00
echo -n Building libmpfr... | tee -a $WORKING_DIR/gcc.build.log
(
cd src/libmpfr &&
2018-11-29 02:38:34 +01:00
( grep -q jehanne config.sub || patch -p0 < $WORKING_DIR/patch/libmpfr.patch ) &&
./configure --host=x86_64-jehanne --prefix=/posix/ --with-sysroot=$JEHANNE --with-gmp=$JEHANNE/pkgs/libgmp/6.1.2/posix/ &&
cp ../../../../patch/MakeNothing.in doc/Makefile &&
make &&
2018-11-29 02:38:34 +01:00
make DESTDIR=$JEHANNE/pkgs/libmpfr/4.0.1/ install &&
libtool --mode=finish $JEHANNE/posix/lib
) >> $WORKING_DIR/gcc.build.log 2>&1
failOnError $? "Building libmpfr"
echo done.
2018-11-27 01:46:03 +01:00
# Copy to /posix (to emulate bind during cross compilation)
2018-11-28 11:47:24 +01:00
cp -pfr $JEHANNE/pkgs/libmpfr/4.0.1/posix/* $JEHANNE/posix
2018-11-27 01:46:03 +01:00
2018-11-28 18:32:39 +01:00
echo -n Building libmpc... | tee -a $WORKING_DIR/gcc.build.log
(
cd src/libmpc &&
2018-11-29 02:38:34 +01:00
( grep -q jehanne config.sub || ( chmod u+w config.sub &&
2018-11-28 18:32:39 +01:00
patch -p0 < $WORKING_DIR/patch/libmpc.patch &&
2018-11-29 02:38:34 +01:00
chmod u-w config.sub ) ) &&
2018-11-28 18:32:39 +01:00
./configure --host=x86_64-jehanne --prefix=/posix/ --with-sysroot=$JEHANNE --with-gmp=$JEHANNE/pkgs/libgmp/6.1.2/posix/ --with-mpfr=$JEHANNE/pkgs/libmpfr/4.0.1/posix/ &&
cp ../../../../patch/MakeNothing.in doc/Makefile &&
make &&
2018-11-29 02:38:34 +01:00
make DESTDIR=$JEHANNE/pkgs/libmpc/1.1.0/ install &&
libtool --mode=finish $JEHANNE/posix/lib
) >> $WORKING_DIR/gcc.build.log 2>&1
2018-11-28 18:32:39 +01:00
failOnError $? "Building libmpc"
echo done.
# Copy to /posix (to emulate bind during cross compilation)
cp -pfr $JEHANNE/pkgs/libmpc/1.1.0/posix/* $JEHANNE/posix
echo -n Building binutils... | tee -a $WORKING_DIR/gcc.build.log
# Patch and build binutils
if [ "$BINUTILS_BUILD_DIR" = "" ]; then
export BINUTILS_BUILD_DIR=$WORKING_DIR/build-binutils
fi
2019-11-05 00:19:53 +01:00
( ( grep -q jehanne src/binutils/config.sub || (
sed -i '/jehanne/b; /ELF_TARGET_ID/,/elf_backend_can_gc_sections/s/0x200000/0x1000 \/\/ jehanne hack/g' src/binutils/bfd/elf64-x86-64.c &&
2019-11-05 00:22:29 +01:00
sed -i '/jehanne/b; s/| midnightbsd\*/| midnightbsd* | jehanne*/g' src/binutils/config.sub &&
dynpatch 'binutils/bfd/config.bfd' '\# END OF targmatch.h' &&
2019-11-05 00:22:29 +01:00
dynpatch 'binutils/gas/configure.tgt' ' i386-\*-darwin\*)' &&
( grep -q jehanne src/binutils/ld/configure.tgt || patch -p1 < patch/binutils/ld/configure.tgt ) &&
cp patch/binutils/ld/emulparams/elf_x86_64_jehanne.sh src/binutils/ld/emulparams/ &&
cp patch/binutils/ld/emulparams/elf_i386_jehanne.sh src/binutils/ld/emulparams/ &&
dynpatch 'binutils/ld/Makefile.am' 'eelf_x86_64.c: ' &&
(grep 'eelf_i386_jehanne.c \\' src/binutils/ld/Makefile.am || sed -i 's/.*ALL_EMULATION_SOURCES = \\.*/&\n\teelf_i386_jehanne.c \\/' src/binutils/ld/Makefile.am) &&
(grep 'eelf_x86_64_jehanne.c \\' src/binutils/ld/Makefile.am || sed -i 's/.*ALL_64_EMULATION_SOURCES = \\.*/&\n\teelf_x86_64_jehanne.c \\/' src/binutils/ld/Makefile.am) &&
cd src/binutils/ld && automake && cd ../ ) ) &&
2019-11-05 00:22:29 +01:00
mkdir -p $BINUTILS_BUILD_DIR && cd $BINUTILS_BUILD_DIR &&
$WORKING_DIR/src/binutils/configure --prefix=/posix --with-sysroot=$JEHANNE --target=x86_64-jehanne --enable-interwork --enable-multilib --disable-nls --disable-werror &&
2019-11-05 00:22:29 +01:00
cp $WORKING_DIR/../../patch/MakeNothing.in $WORKING_DIR/src/binutils/bfd/doc/Makefile &&
cp $WORKING_DIR/../../patch/MakeNothing.in $WORKING_DIR/src/binutils/bfd/po/Makefile &&
cp $WORKING_DIR/../../patch/MakeNothing.in $WORKING_DIR/src/binutils/gas/doc/Makefile &&
cp $WORKING_DIR/../../patch/MakeNothing.in $WORKING_DIR/src/binutils/binutils/doc/Makefile &&
make MAKEINFO=true MAKEINFOHTML=true TEXI2DVI=true TEXI2PDF=true DVIPS=true &&
make MAKEINFO=true MAKEINFOHTML=true TEXI2DVI=true TEXI2PDF=true DVIPS=true DESTDIR=$JEHANNE/pkgs/binutils/2.31/ install
) >> $WORKING_DIR/gcc.build.log 2>&1
failOnError $? "Building binutils"
fi
echo done.
# Copy to /posix (to emulate bind during cross compilation)
cp -pfr $JEHANNE/pkgs/binutils/2.31/posix/* $JEHANNE/posix