Last active
January 25, 2024 04:25
-
-
Save emkay/a1214c753e8c975d95b4 to your computer and use it in GitHub Desktop.
Build Grub on OSX
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
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 | |
CONTINUE=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 | |
CONTINUE=true | |
fi | |
if ! $CONTINUE; then | |
# Bail if response is not yes | |
echo "Exiting..." | |
exit | |
fi | |
# 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 http://brew.sh/ 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 http://ftp.gnu.org/gnu/binutils/binutils-2.25.tar.gz > 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 | |
make install | |
fi | |
# gcc | |
cd $HOME/src | |
if [ ! -d "gcc-5.3.0" ]; then | |
curl http://www.netgull.com/gcc/releases/gcc-5.3.0/gcc-5.3.0.tar.gz > 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 | |
fi | |
# objconv | |
cd $HOME/src | |
if [ ! -d "objconv" ]; then | |
curl http://www.agner.org/optimize/objconv.zip > objconv.zip | |
mkdir -p build-objconv | |
unzip objconv.zip -d build-objconv | |
cd build-objconv | |
unzip source.zip -d src | |
g++ -o objconv -O2 src/*.cpp --prefix="$PREFIX" | |
cp objconv $PREFIX/bin | |
fi | |
# grub | |
cd $HOME/src | |
if [ ! -d "grub" ]; then | |
git clone --depth 1 git://git.savannah.gnu.org/grub.git | |
cd grub | |
sh autogen.sh | |
mkdir -p build-grub | |
cd build-grub | |
../configure --disable-werror TARGET_CC=$TARGET-gcc TARGET_OBJCOPY=$TARGET-objcopy \ | |
TARGET_STRIP=$TARGET-strip TARGET_NM=$TARGET-nm TARGET_RANLIB=$TARGET-ranlib --target=$TARGET --prefix=$PREFIX | |
make | |
make install | |
fi |
in my mac m1, the TARGET should set to x86_64-elf, and it can build successful.
git clone https://git.savannah.gnu.org/git/grub.git
cd grub
export TARGET=x86_64-elf
export PREFIX=$HOME/tools/grub
./bootstrap
mkdir build
cd build
../configure --disable-werror TARGET_CC=$TARGET-gcc TARGET_OBJCOPY=$TARGET-objcopy TARGET_STRIP=$TARGET-strip TARGET_NM=$TARGET-nm TARGET_RANLIB=$TARGET-ranlib --target=$TARGET --prefix=$PREFIX
make
make install
In case someone has issues withawk
, do a little
brew install gawk
alias awk=gawk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?