#
# Toplevel Makefile for the BCM947xx Linux Router release
#
# Copyright 2004, Broadcom Corporation
# All Rights Reserved.
#
# THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
# KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
# SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
#
# $Id$
#

SRCBASE := $(shell pwd)
RELEASEDIR := $(shell (cd $(SRCBASE)/.. && pwd -P))
PATH := $(RELEASEDIR)/tools:/opt/brcm/hndtools-mipsel-linux-3.2.3/bin:/opt/brcm/hndtools-mipsel-uclibc-3.2.3/bin/:$(PATH)

install: all
	install -d $(RELEASEDIR)/image
	$(MAKE) -C router install
#	-cp router/mipsel/linux.trx $(RELEASEDIR)/image/linux-glibc.trx
	-cp router/mipsel-uclibc/linux.trx $(RELEASEDIR)/image/linux.trx
	-cp router/mipsel-uclibc/linux.bin $(RELEASEDIR)/image/linux.bin
	echo -n -e '\001' >> $(RELEASEDIR)/image/linux.trx
ifneq ($(wildcard pmon),)
	cp pmon/pmon_lg.bin $(RELEASEDIR)/image/
endif
ifneq ($(wildcard cfe),)
	cp cfe/build/broadcom/bcm947xx/cfe.bin $(RELEASEDIR)/image/
        # Make CFE again for self-decompression support
	$(MAKE) -C cfe
	cp cfe/build/broadcom/bcm947xx/compressed/zImage $(RELEASEDIR)/image/cfez.bin
endif
	cp shared/nvram/*.txt $(RELEASEDIR)/image/

all clean:
	cp ezc.o router/httpd/
	cp ezc.o router/shared/
	$(MAKE) -C router $@
ifneq ($(wildcard pmon),)
	$(MAKE) -C pmon $@
endif
ifneq ($(wildcard cfe),)
	$(MAKE) -C cfe $@
endif
#DanielAdd
image:
        # Prepare filesystem
	cd router/mipsel-uclibc/target && ../../misc/rootprep.sh && mkcramfs . ../../mipsel-uclibc/target.cramfs
        # Package kernel and filesystem
	cd ../../../
	cp linux/linux/arch/mips/brcm-boards/bcm947xx/compressed/vmlinuz router/mipsel-uclibc/
	trx -o router/mipsel-uclibc/linux.trx router/mipsel-uclibc/vmlinuz router/mipsel-uclibc/target.cramfs
	cp -f router/mipsel-uclibc/linux.trx .
cfe_test:
	$(MAKE) -C cfe
	cp cfe/build/broadcom/bcm947xx/cfe.bin $(RELEASEDIR)/image/
	cd $(RELEASEDIR)/image && ./mkbin
	$(RELEASEDIR)/src/fw/fw-LinksysWAP54G4712 $(RELEASEDIR)/image/test.bin $(RELEASEDIR)/image/test-hdr.bin

.PHONY: all clean install
