all: mkfs
include $(APPS_PATH)/.config

mkfs:
	rm -rf target

################ restore drivers ####################	
	
	tar -jxf ../platform/$(PLATFORM)/rootfs_rt3052.tar.bz2
	
	rm -rf $(KERNEL_PATH)/drivers/net/raeth
	
	echo $(KERNEL_PATH)
	tar -jxvf $(KERNEL_PATH)/drivers/net/raeth.tar.bz2
	
	mv raeth $(KERNEL_PATH)/drivers/net/raeth

ifeq ($(CONFIG_SW5_WIMAX), y)
	install -d target/mnt/gct 
	install -d target/usr/bin/gct
	install -d target/usr/bin/sdk
endif
ifeq ($(CONFIG_SW5_CVKK_API), y)
	install -d target/usr/local/cmr
	install -d target/usr/local/cmr/lib
endif
ifeq ($(CONFIG_DHCP3),y)
	install -d target/var/state/dhcp
endif	
	sed -e '/^#/d' $(KERNEL_PATH)/.config > $(FS_PATH)/mnt/scripts/config.sh
	chmod 775 $(FS_PATH)/mnt/scripts/config.sh

install:
	install -d $(IMG_PATH)

ifeq ($(CONFIG_DHCP3),y)
	rm -f $(FS_PATH)/sbin/dhclient-script
endif
ifeq ($(CONFIG_3G_USB_TOOLS),y)	
	rm -f $(FS_PATH)/sbin/hotplug
endif
	rm -rf $(FS_PATH)/man/
	$(APPS_CROSS)strip $(FS_PATH)/bin/*
	$(APPS_CROSS)strip $(FS_PATH)/lib/*
	$(APPS_CROSS)strip $(FS_PATH)/sbin/*

ifeq ($(CONFIG_3G_USB_TOOLS),y)	
	cp -f $(APPS_PATH)/usb-tools/usb_monitor/hotplug/hotplug $(FS_PATH)/sbin
endif

	cp $(KERNEL_PATH)/arch/mips/boot/vmlinux.* /$(IMG_PATH)/

ifeq ($(CONFIG_SW5_KCODES_SHAREPORT), y)
ifneq ($(CONFIG_IPV6_SUPPORT), y)
	cp -f $(APPS_PATH)/kcodes/NetUSB_strip_noipv6.ko $(FS_PATH)/lib/NetUSB_strip.ko
else
	cp -f $(APPS_PATH)/kcodes/NetUSB_strip.ko $(FS_PATH)/lib/
endif	
endif

ifeq ($(CONFIG_DHCP3),y)
	install $(APPS_PATH)/dhcp-3.1.3rc1/client/scripts/linux $(FS_PATH)/sbin/dhclient-script
endif

	$(TOOL_PATH)/../tools/mkuImage.sh $(KERNEL_PATH) $(IMG_PATH)
	$(TOOL_PATH)/../tools/release_rootfs.sh $(AP_TYPE)
	$(TOOL_PATH)/../tools/release_image.sh $(CONFIG_MODEL_NAME)_$(AP_TYPE)_

clean:
	rm -fr target 
	rm -fr tmp
	rm -fr $(IMG_PATH)
	
