1#!/bin/bash 2 3# Originally from the Galileo port in contiki 4# https://github.com/otcshare/contiki-x86 5 6set -e 7unset CFLAGS 8 9JOBS=5 10SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) 11 12if [ "x$1" == "x" ]; then 13 echo "Usage: $0 [i386|x86_64]" 14 exit 1 15fi 16 17TARGET_ARCH=$1 18 19export PYTHON=python3 20 21prepare() { 22 if [[ ! -d ./src ]]; then 23 git clone http://git.savannah.gnu.org/r/grub.git src 24 fi 25 26 pushd src 27 git checkout grub-2.04 28 git clean -fdx 29 popd 30} 31 32build() { 33 pushd src 34 35 ./bootstrap 36 ./autogen.sh 37 ./configure --with-platform=efi --target=${TARGET_ARCH} --disable-werror 38 39 make -j${JOBS} 40 41 ./grub-mkimage -p /EFI/BOOT -d ./grub-core/ -O ${TARGET_ARCH}-efi \ 42 -o grub_${TARGET_ARCH}.efi \ 43 boot efifwsetup efi_gop efinet efi_uga lsefimmap lsefi lsefisystab \ 44 exfat fat multiboot2 multiboot terminal part_msdos part_gpt normal \ 45 all_video aout configfile echo file fixvideo fshelp gfxterm gfxmenu \ 46 gfxterm_background gfxterm_menu legacycfg video_bochs video_cirrus \ 47 video_colors video_fb videoinfo video net tftp 48 49 popd 50} 51 52setup() { 53 mkdir -p bin 54 cp src/grub_${TARGET_ARCH}.efi bin/ 55} 56 57cleanup() { 58 rm -rf ./src 59 rm -rf ./bin 60} 61 62# This script will always run on its own basepath, no matter where you call it from. 63mkdir -p ${SCRIPT_DIR}/grub 64pushd ${SCRIPT_DIR}/grub 65 66case $1 in 67 -c | --cleanup) 68 cleanup 69 ;; 70 *) 71 prepare && build && setup 72 ;; 73esac 74 75popd 76