#
# This file is subject to the terms and conditions of the GNU General Public
# License.  See the file "COPYING" in the main directory of this archive
# for more details.
#
# Copyright (C) 1995, 1998, 2001, 2002 by Ralf Baechle
# Copyright (C) 2004  Maciej W. Rozycki
#

#
# Some DECstations need all possible sections of an ECOFF executable
#
ifdef CONFIG_MACH_DECSTATION
  E2EFLAGS = -a
else
  E2EFLAGS =
endif

#
# Drop some uninteresting sections in the kernel.
# This is only relevant for ELF kernels but doesn't hurt a.out
#
drop-sections	= .reginfo .mdebug .comment .note .pdr .options .MIPS.options
strip-flags	= $(addprefix --remove-section=,$(drop-sections))

VMLINUX = $(TOPDIR)/vmlinux

boot: vmlinux.ecoff vmlinux.srec addinitrd

all:

piggy.gzip: $(CONFIGURE) $(VMLINUX)
	$(OBJCOPY) -O binary -R .note -R .comment -S $(TOPDIR)/vmlinux piggy
	gzip -9 < piggy > piggy.gzip

piggy.bz2: $(CONFIGURE) $(VMLINUX)
	$(OBJCOPY) -O binary -R .note -R .comment -S $(TOPDIR)/vmlinux piggy
	bzip2 -9 < piggy > piggy.bz2

piggy.lzma: $(CONFIGURE) $(VMLINUX)
	$(OBJCOPY) -O binary -R .note -R .comment -S $(TOPDIR)/vmlinux piggy
	lzma e piggy piggy.lzma

uImage.gzip : piggy.gzip
	mkimage -A mips -O linux -T kernel -C gzip -a $(LOADADDR) -e \
	0x$(shell grep kernel_entry $(TOPDIR)/System.map | awk '{ printf "%s", $$1 }') \
	-n 'MIPS Linux-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)' \
	-d piggy.gzip uImage

uImage.bzip2    : piggy.bz2
	mkimage -A mips -O linux -T kernel -C bzip2 -a $(LOADADDR) -e \
	0x$(shell grep kernel_entry $(TOPDIR)/System.map | awk '{ printf "%s", $$1 }') \
	-n 'MIPS Linux-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)' \
	-d piggy.bz2 uImage

uImage.lzma : piggy.lzma
	mkimage -A mips -O linux -T kernel -C lzma -a $(LOADADDR) -e \
	0x$(shell grep kernel_entry $(TOPDIR)/System.map | awk '{ printf "%s", $$1 }') \
	-n 'MIPS Linux-$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)' \
	-d piggy.lzma uImage

boot: vmlinux.ecoff vmlinux.srec addinitrd

vmlinux.ecoff:  $(CONFIGURE) elf2ecoff $(VMLINUX)
	./elf2ecoff $(VMLINUX) vmlinux.ecoff $(E2EFLAGS)

elf2ecoff: elf2ecoff.c
	$(HOSTCC) -o $@ $^

vmlinux.srec: $(CONFIGURE) $(VMLINUX)
	$(OBJCOPY) -S -O srec $(strip-flags) $(VMLINUX) vmlinux.srec

addinitrd: addinitrd.c
	$(HOSTCC) -o $@ $^
				
archhelp:
	@echo	'* vmlinux.ecoff	- ECOFF boot image'
	@echo	'* vmlinux.srec		- SREC boot image'

clean-files += addinitrd \
	       elf2ecoff \
	       vmlinux.bin \
	       vmlinux.ecoff \
	       vmlinux.srec
