# -*- makefile -*- : Force emacs to use Makefile mode

# BIOS-specific directories containing source files
#
SRCDIRS		+= arch/x86/drivers/net

# The linker scripts
#
LDSCRIPT	= arch/x86/scripts/pcbios.lds
LDSCRIPT_PREFIX	= arch/x86/scripts/prefixonly.lds

# Stop ld from complaining about our customised linker script
#
LDFLAGS		+= -N --no-check-sections

# Do not warn about RWX segments (required by most prefixes)
#
WRWX_TEST	= $(LD) --warn-rwx-segments --version 2>&1 > /dev/null
WRWX_FLAGS	:= $(shell [ -z "`$(WRWX_TEST)`" ] && \
		     $(ECHO) '--no-warn-rwx-segments')
LDFLAGS		+= $(WRWX_FLAGS)

# Media types.
#
MEDIA		+= rom
MEDIA		+= mrom
MEDIA		+= pcirom
MEDIA		+= isarom
MEDIA		+= pxe
MEDIA		+= kpxe
MEDIA		+= kkpxe
MEDIA		+= kkkpxe
MEDIA		+= lkrn
MEDIA		+= dsk
MEDIA		+= nbi
MEDIA		+= hd
MEDIA		+= raw
MEDIA		+= exe

# Padding rules
#
PAD_rom		= $(PERL) $(PADIMG) --blksize=512 --byte=0xff
PAD_mrom	= $(PAD_rom)
PAD_pcirom	= $(PAD_rom)
PAD_isarom	= $(PAD_rom)
PAD_dsk		= $(PERL) $(PADIMG) --blksize=512
PAD_hd		= $(PERL) $(PADIMG) --blksize=32768
PAD_exe		= $(PERL) $(PADIMG) --blksize=512

# Finalisation rules
#
FINALISE_rom	= $(PERL) $(FIXROM)
FINALISE_mrom	= $(FINALISE_rom)
FINALISE_pcirom	= $(FINALISE_rom)
FINALISE_isarom	= $(FINALISE_rom)

# Use $(ROMS) rather than $(DRIVERS) for "allroms", "allmroms", etc.
#
LIST_NAME_rom := ROMS
LIST_NAME_mrom := ROMS
LIST_NAME_pcirom := ROMS
LIST_NAME_isarom := ROMS

# ISO images
NON_AUTO_MEDIA	+= iso
$(BIN)/%.iso : $(BIN)/%.lkrn util/genfsimg
	$(QM)$(ECHO) "  [GENFSIMG] $@"
	$(Q)util/genfsimg -o $@ $<

# FAT filesystem images (via syslinux)
NON_AUTO_MEDIA	+= sdsk
$(BIN)/%.sdsk : $(BIN)/%.lkrn util/genfsimg
	$(QM)$(ECHO) "  [GENFSIMG] $@"
	$(Q)util/genfsimg -o $@ $<

# rule to write disk images to /dev/fd0
NON_AUTO_MEDIA	+= fd0
%fd0 : %dsk
	$(QM)$(ECHO) "  [DD] $@"
	$(Q)dd if=$< bs=512 conv=sync of=/dev/fd0
	$(Q)sync

# Special target for building Master Boot Record binary
$(BIN)/mbr.tmp : $(BIN)/mbr.o
	$(QM)$(ECHO) "  [LD] $@"
	$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT_PREFIX) -o $@ -e mbr $<

# rule to make a USB disk image
$(BIN)/usbdisk.tmp : $(BIN)/usbdisk.o
	$(QM)$(ECHO) "  [LD] $@"
	$(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT_PREFIX) -o $@ -e mbr $<

NON_AUTO_MEDIA	+= usb
%usb: $(BIN)/usbdisk.bin %hd
	$(QM)$(ECHO) "  [FINISH] $@"
	$(Q)cat $^ > $@

NON_AUTO_MEDIA	+= vhd
%vhd: %usb
	$(QM)$(ECHO) "  [FINISH] $@"
	$(Q)$(QEMUIMG) convert -f raw -O vpc $< $@

# Padded floppy image (e.g. for iLO)
NON_AUTO_MEDIA += pdsk
%pdsk : %dsk
	$(Q)cp $< $@
	$(Q)$(PADIMG) --blksize=1474560 $@

# Include PCI drivers in the all-drivers build
#
DRIVERS_ipxe	+= $(DRIVERS_pci_net)
DRIVERS_ipxe	+= $(DRIVERS_pci_infiniband)

# Include USB drivers in the all-drivers build
#
DRIVERS_ipxe	+= $(DRIVERS_usb_net)

# Include Xen and Hyper-V drivers in the all-drivers build
#
DRIVERS_ipxe	+= $(DRIVERS_xen_net)
DRIVERS_ipxe	+= $(DRIVERS_vmbus_net)
