#
# Makefile for the Baget specific kernel interface routines
# under Linux.
#

obj-y			:= baget.o print.o setup.o time.o irq.o bagetIRQ.o \
			   reset.o
obj-$(CONFIG_VAC_RTC)	+= vacrtc.o

EXTRA_AFLAGS := $(CFLAGS)

bagetIRQ.o : bagetIRQ.S
	$(CC) $(CFLAGS) -c -o $@ $<

##################### Baget Loader stuff ########################

image: ../../../vmlinux
	cp -f $< $@

image.bin: image
	$(OBJCOPY) -O binary $< $@

ramdisk.bin:
	echo "Dummy ramdisk used. Provide your own if needed !" > $@

dummy.c:
	touch $@

dummy.o: dummy.c image.bin ramdisk.bin
	$(CC) $(CFLAGS) -c -o $@ $<
	$(OBJCOPY) --add-section=.vmlinux=image.bin \
                   --add-section=.ramdisk=ramdisk.bin   $@

balo.h: image
	$(NM) $< | awk ' \
	BEGIN               { printf "/* DO NOT EDIT THIS FILE */\n" }    \
	/_ftext/            { printf "#define LOADADDR 0x%s\n", $$1     } \
	/kernel_entry/      { printf "#define START 0x%s\n", $$1 }        \
	/balo_ramdisk_base/ { printf "#define RAMDISK_BASE 0x%s\n", $$1 } \
	/balo_ramdisk_size/ { printf "#define RAMDISK_SIZE 0x%s\n", $$1 } \
                       ' > $@
balo.o:   balo.c balo.h
	$(CC) $(CFLAGS) -c $<

balo_supp.o: balo_supp.S
	$(CC) $(CFLAGS) -c $<

balo:   balo.o dummy.o balo_supp.o print.o
	$(LD) $(LDFLAGS) -T ld.script.balo -o $@ $^

clean:
	rm -f balo balo.h dummy.c image image.bin

