Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Build Grub on OSX
set -e
# First we are going to make sure that you understand this is sort of experimental and we will be compiling stuff.
# by default CONTINUE will be false
echo ""
echo "You are about to download, compile, and install stuff on your computer."
echo "Please read through the source script to know what is being done."
echo "Do you want to continue? (y/n)"
read -r response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]; then
if ! $CONTINUE; then
# Bail if response is not yes
echo "Exiting..."
# check if `brew` is installed
command -v brew >/dev/null 2>&1 || { echo >&2 "It seems you do not have \`brew\` installed. Head on over to to install it."; exit 1; }
export PREFIX="$HOME/opt/"
export TARGET=x86_64-pc-elf
export PATH="$PREFIX/bin:$PATH"
mkdir -p $HOME/src
mkdir -p $PREFIX
# gmp mpfr libmpc
brew install gmp mpfr libmpc autoconf automake
# binutils
echo ""
echo "Installing \`binutils\`"
echo ""
cd $HOME/src
if [ ! -d "binutils-2.25" ]; then
curl > binutils-2.25.tar.gz
tar xfz binutils-2.25.tar.gz
rm binutils-2.25.tar.gz
mkdir -p build-binutils
cd build-binutils
../binutils-2.25/configure --target=$TARGET --prefix="$PREFIX" --with-sysroot --disable-nls --disable-werror
make install
# gcc
cd $HOME/src
if [ ! -d "gcc-5.3.0" ]; then
curl > gcc-5.3.0.tar.gz
tar xfz gcc-5.3.0.tar.gz
rm gcc-5.3.0.tar.gz
mkdir -p build-gcc
cd build-gcc
../gcc-5.3.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers --with-gmp=/usr/local/Cellar/gmp/6.1.0 --with-mpfr=/usr/local/Cellar/mpfr/3.1.3 --with-mpc=/usr/local/Cellar/libmpc/1.0.3
make all-gcc
make all-target-libgcc
make install-gcc
make install-target-libgcc
# objconv
cd $HOME/src
if [ ! -d "objconv" ]; then
curl >
mkdir -p build-objconv
unzip -d build-objconv
cd build-objconv
unzip -d src
g++ -o objconv -O2 src/*.cpp --prefix="$PREFIX"
cp objconv $PREFIX/bin
# grub
cd $HOME/src
if [ ! -d "grub" ]; then
git clone --depth 1 git://
cd grub
mkdir -p build-grub
cd build-grub
../configure --disable-werror TARGET_CC=$TARGET-gcc TARGET_OBJCOPY=$TARGET-objcopy \
make install

This comment has been minimized.

Copy link

@ScottA38 ScottA38 commented Oct 24, 2018

This failed with errors for me, can't really say what the output log is telling me, however if I know how to reverse the process I could run it again and redirect all output to a log file if required.

As for the actual errors they are
13 warnings and 1 error generated. make[1]: *** [auto-profile.o] Error 1 make: *** [all-gcc] Error 2

pretty sure it's generated when trying to run make - at one point it said something along the lines of invalid argument 'install'. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment