-
Notifications
You must be signed in to change notification settings - Fork 10
/
macos-build-toolchain.sh
executable file
·61 lines (48 loc) · 2.21 KB
/
macos-build-toolchain.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
#! /usr/bin/env bash
###############################################################################
# Credit for this script goes to https://github.com/deplinenoise
#
# Original source:
# https://gist.github.com/deplinenoise/bcfa4fb9964f90a5f3e9d69f08ca4464
#
# I have modified it only to use more recent versions of gcc and binutils, to
# include libmpc in the list of packages for brew to install, and create
# directories within the toolchain directory instead of the working directory.
###############################################################################
echo Building GCC m68k toolchain...
mkdir -p toolchain
mkdir -p toolchain/sources
mkdir -p toolchain/build
CORES=8
TARGET=m68k-eabi-elf
PREFIX=$PWD/toolchain/$TARGET
MIRROR=http://ftpmirror.gnu.org
BINUTILS=binutils-2.37
BINUTILS_URL=$MIRROR/binutils/$BINUTILS.tar.xz
GCCVER=11.2.0
GCC=gcc-$GCCVER
GCC_URL=$MIRROR/gcc/$GCC/$GCC.tar.xz
brew install wget mpfr mpc libmpc gmp # Can't check this, because brew errors if things are already installed.
if [ ! -f toolchain/sources/$BINUTILS.tar.xz ]; then
echo Fetching $BINUTILS_URL
(cd toolchain/sources && wget $BINUTILS_URL) || exit 1
fi
if [ ! -f toolchain/sources/$GCC.tar.xz ]; then
echo Fetching $GCC_URL
(cd toolchain/sources && wget $GCC_URL) || exit 1
fi
test -d toolchain/sources/$BINUTILS || (cd toolchain/sources && tar xjvf ../sources/$BINUTILS.tar.xz) || exit 1
test -d toolchain/sources/$GCC || (cd toolchain/sources && tar xjvf ../sources/$GCC.tar.xz) || exit 1
mkdir -p toolchain/build
if [ ! -f $PREFIX-$GCCVER/bin/$TARGET-nm ]; then
echo Building binutils
rm -rf toolchain/build/binutils
mkdir -p toolchain/build/binutils
(cd toolchain/build/binutils && ../../sources/$BINUTILS/configure --target=$TARGET --disable-werror --prefix=$PREFIX-$GCCVER && make -j $CORES && make install) || exit 1
fi
if [ ! -f $PREFIX-$GCCVER/bin/$TARGET-gcc ]; then
echo Building GCC
rm -rf toolchain/build/gcc
mkdir -p toolchain/build/gcc
(cd toolchain/build/gcc && ../../sources/$GCC/configure --target=$TARGET --disable-werror --prefix=$PREFIX-$GCCVER --enable-languages=c --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local && make -j $CORES all-gcc && make install-gcc) || exit 1
fi