# 
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
include $(INCLUDE_DIR)/image.mk

define Build/Clean
	$(MAKE) -C meraki-loader clean
endef

define Image/Prepare
	cp $(KDIR)/linux-*/vmlinux $(KDIR)/vmlinux.elf
	$(MAKE) -C meraki-loader \
		CFLAGS="-fno-builtin -Os -G 0 -mno-abicalls -fno-pic -Wall \
		-DKERNEL_ENTRY=0x80041000 -DLOAD_TEXT_START=0x80100000 \
		-DRUN_TEXT_START=0x81200000 -D_LZMA_IN_CB" \
		compile
endef

define Image/BuildKernel
	cp $(KDIR)/vmlinux.elf $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-vmlinux.elf
	$(STAGING_DIR)/bin/lzma e -so -eos -lc1 -lp2 -pb2 $(KDIR)/vmlinux > $(KDIR)/vmlinux.lzma
	./fonimage.pl $(KDIR)/vmlinux.image $(KDIR)/vmlinux.lzma
	dd of=$(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL)-vmlinux.image if=$(KDIR)/vmlinux.image bs=64k conv=sync
endef

define Image/Build/squashfs
	./fonimage.pl $(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL).image $(KDIR)/vmlinux.lzma $(KDIR)/root.$(1)
	$(call prepare_generic_squashfs,$(BIN_DIR)/openwrt-$(BOARD)-$(KERNEL).image)
endef

define Image/Build
	$(call Image/Build/$(1),$(1))
endef


$(eval $(call BuildImage))

define Require/digest-crc-perl
	perl -MDigest::CRC -e '' 
endef

$(eval $(call Require,digest-crc-perl, \
	The Fonera image build requires the perl module Digest::CRC \
))

