@echo off
cd /d "%~dp0"

echo search.file /boot/grub/grub.cfg root>bootinfo.cfg
echo set prefix=($root)/boot/grub/>>bootinfo.cfg

mkdir res\boot\grub
mkdir res\efi\boot
xcopy /s /e /y /i i386-pc res\boot\grub\i386-pc

echo i386-efi
grub-mkimage.exe -d i386-efi -p /boot/grub -o res\efi\boot\bootia32.efi -O i386-efi -v newc iso9660 part_msdos part_gpt ext2 cpio memdisk blocklist minicmd loopback fat ntfs gfxterm reboot configfile normal test gfxmenu gfxterm search echo


echo x86_64-efi
grub-mkimage.exe -d x86_64-efi -p /boot/grub -o res\efi\boot\bootx64.efi -O x86_64-efi -v newc iso9660 part_msdos part_gpt ext2 cpio memdisk blocklist minicmd loopback fat ntfs gfxterm reboot configfile normal test gfxmenu gfxterm search echo


echo i386-pc
grub-mkimage.exe -d i386-pc -c bootinfo.cfg -p /boot/grub -o res\boot\grub\i386-pc\core.img -O i386-pc -v biosdisk loopback tar part_msdos fat exfat ntfs search_fs_file

copy /B res\boot\grub\i386-pc\boot.img + res\boot\grub\i386-pc\core.img res\g2ldr.mbr


echo menuentry "0.Windows"  --hotkey=0 {chainloader (${root})/EFI/Microsoft/Boot/bootmgfw.efi}>res\boot\grub\grub.cfg
echo menuentry "1.WinPE"    --hotkey=1 {search --file /grldr --set=root}>>res\boot\grub\grub.cfg
echo menuentry "3.Reboot"   --hotkey=3 {reboot;}>>res\boot\grub\grub.cfg
echo menuentry "4.Halt"     --hotkey=4 {halt;}>>res\boot\grub\grub.cfg

del /q bootinfo.cfg


