#
# 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

PART_LIST := tools linux busybox rootfs 

#

.PHONY: all toolchain $(PART_LIST)

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

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

linux:
	@echo "PRODUCT_ID=$(PRODUCT_ID)";
	@echo "WAN_PORT4=$(WANPORT_4)"
	TARGET=mips-linux make -f Makefile -C linux all

tools rootfs busybox:
	make -C $@ all

boot:
	make -C bootloader
	make -C rootfs boot

romdisk:
	make -C rootfs/glue/

menuconfig:
	@make -C project_config clean
	@make -C project_config menuconfig
	@make -s clean

#

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

.PHONY: clean $(CLEAN_LIST)

clean: $(CLEAN_LIST)
	rm -f image/*.bin
	rm -f image/zImage.lzma
	rm -f image/squashfs.o

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

#

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