###############################################################################
# This file is part of the IPCop Firewall.                                    #
#                                                                             #
# IPCop is free software; you can redistribute it and/or modify               #
# it under the terms of the GNU General Public License as published by        #
# the Free Software Foundation; either version 2 of the License, or           #
# (at your option) any later version.                                         #
#                                                                             #
# IPCop is distributed in the hope that it will be useful,                    #
# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
# GNU General Public License for more details.                                #
#                                                                             #
# You should have received a copy of the GNU General Public License           #
# along with IPCop; if not, write to the Free Software                        #
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA    #
#                                                                             #
# Makefiles are based on LFSMake, which is                                    #
# Copyright (C) 2002 Rod Roard <rod@sunsetsystems.com>                        #
#                                                                             #
# Modifications by:                                                           #
# ??-12-2003 Mark Wormgoor < mark@wormgoor.com>                               #
#          - Modified Makefile for IPCop build                                #
#                                                                             #
# $Id: ipcop-boot-floppy 7540 2014-05-17 08:08:23Z owes $
#                                                                             #
###############################################################################

###############################################################################
# Definitions
###############################################################################

include Config

PKG_NAME   = boot.img
HOST_ARCH  = alpha,i486,ppc
OTHER_SRC  = no

THISAPP    = boot-$(VERSION).img
TARGET     = $(DIR_INFO)/$(STAGE_ORDER)_$(STAGE)/$(THISAPP)

###############################################################################
# Top-level Rules
###############################################################################

install : $(TARGET)

check :

download :

md5 :

###############################################################################
# Installation Details
###############################################################################

$(TARGET) : $(firstword $(MAKEFILE_LIST))

ifeq "$(MACHINE)" "i486"
	dd if=/dev/zero of=/$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-boot.img bs=1024 count=1440
	mkdosfs -f 1 -r 16 /$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-boot.img
	syslinux -s /$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-boot.img
	echo "drive i: file=\"/$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-boot.img\" exclusive mformat_only" > \
		/etc/mtools.conf
	sed -e 's/boot IPCop/boot IPCop $(VERSION)/' $(DIR_SRC)/config/arch/$(MACHINE)/install-message \
		| mcopy - i:message
	mcopy $(DIR_SRC)/config/arch/$(MACHINE)/syslinux-fdinitrd.cfg i:syslinux.cfg
	mcopy /boot/vmlinuz-$(KVER) i:vmlinuz
	mcopy /$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-mini-initramfs.img i:initrd.img
	mcopy $(DIR_SRC)/config/arch/$(MACHINE)/splash.rle i:splash.rle

	# show size used
	mdir i:
endif

ifeq "$(MACHINE)" "ppc"
	# First make coff image, bootable directly from Open Firmware as some machines may need this
	#dd if=/dev/zero of=/$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-bootofw.img bs=1024 count=1440
	#hformat -l "IPCop OF Boot Disk" /$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-bootofw.img
	#hmount /$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-bootofw.img
	#hcopy -r /boot/vmlinuz.coff :ipcop-install
	#humount

	# Next, prepare the miboot floppy which ideally should boot on any OldWorld Mac
	dd if=/dev/zero of=/$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-boot.img bs=1024 count=1440
	hformat -l "IPCop Boot Disk" /$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-boot.img
	rm -f /etc/miboot.conf
	echo device /$(INSTALLER_DIR)/images/$(SNAME)-$(VERSION)-boot.img > /etc/miboot.conf
	echo kernel /boot/vmlinuz.strip.gz root=0200 load_ramdisk=1 prompt_ramdisk=1 init=/init >> /etc/miboot.conf
	miboot -f -c /etc/miboot.conf
endif

	# yes we want it rebuilt each time, so no POSTBUILD
