#
# Makefile for full system
#
include ./makefile.envars

export TARGET   ?= mips-linux-uclibc
export TOPDIR   := $(shell pwd)
#export TOOLPATH ?= $(shell cat TOOLPATH)

export PATH := $(TOOLPATH):$(PATH)

#

ifneq ($(wildcard ROM_ID),)
export ROM_ID := `cat $(TOPDIR)/ROM_ID`
endif

ifeq ($(GPL),)
PART_LIST := tools linux busybox rootfs 
else
PART_LIST := linux busybox rootfs 
endif

#

.PHONY: all toolchain $(PART_LIST)

#all: toolchain $(PART_LIST) 
all: $(PART_LIST) 

toolchain:
	@if [ ! -f `cat TOOLPATH`/README ]; then \
		make -C toolchain; \
	fi

linux:

ifeq ($(KERNEL_VERSION),)
	@echo "error, Kernel_VERSION not define!";
	@echo "PRODUCT_ID=$(PRODUCT_ID)";
	@echo "WAN_PORT4=$(WANPORT_4)";
	exit;
else
	@echo "PRODUCT_ID=$(PRODUCT_ID)";
	@echo "WAN_PORT4=$(WANPORT_4)"
    ifeq ($(KERNEL_VERSION),2.6.x)
		TARGET=mips-linux make -f Makefile.2.6 -C linux all
    else
		TARGET=mips-linux make -f Makefile -C linux all
		#./makebin_src/make_wir294_bin kernel ./image/bzImage ./image/linux.bin
    endif
endif

tools rootfs busybox:
	ROMID=$(ROMID) make -C $@ all

boot:
	make -C bootloader
	make -C rootfs boot

romdisk:
	make -C rootfs/glue/

ui:
	make -C rootfs/amit_priv/WebUI.90.mk
	make -C rootfs/ ui

tja:
	make all
	make boot
	make -C rootfs/ ui
	make -C rootfs/glue/ tja
	ls $(TOPDIR)/image/*.bin -al
#

CLEAN_LIST := $(patsubst %,clean-%,$(PART_LIST))

.PHONY: clean $(CLEAN_LIST)

clean: $(CLEAN_LIST)

$(CLEAN_LIST):
	@echo "*** Cleaning $(patsubst clean-%,%,$@)..."
	@make -C $(patsubst clean-%,%,$@) clean

#

ifneq ($(wildcard makefile.corner),)
include makefile.corner
endif
