#
#	Makefile for Fastwel CPU686E card flash image
#

# The network node number that the CPU686e board is assigned now
TARGET = 4

EKIT_BIN_DIR= ../../../bin
BONE_DIR = ./root_bone
ROOT_DIR = ./root_flash

# Extract file and directory list from local 'root_bone' directory
DIRS = $(shell (cd $(BONE_DIR) ; find ./ -name '*' -type d -print -follow))
FILES = $(shell (cd $(BONE_DIR) ; find ./ -name '*' -type f -print -follow))

#DIRS = $(shell (find $(BONE_DIR)/ -name '*' -type d -print))
#FILES = $(shell (find $(BONE_DIR)/ -name '*' -type f -print))

default:
	@echo "\nThe CPU686E Makefile supports the following targets:\n\n" \
	"make all           Make all targets, but don't reprogram the CPU686E flash.\n" \
	"make os_romqnx     Make the OS to be built into the rom image.\n" \
	"make efs           Make the FFS image to be built into the rom image.\n" \
	"make image         Make a new rom image. Includes OS and FFS.\n" \
	"make reflash       Write a rom image into the CPU686E flash memory. The\n" \
	"                   CPU686E must be connected via Ethernet and booted into\n" \
	"                   QNX 4.2x.\n" \
	"make clean         Delete all files built by this Makefile except\n" \
	"                   the rom image.\n" \
	"make spotless      Delete totally all files built by this Makefile.\n" \

all : image
	@echo "All done"

os_romqnx : os.build
	buildqnx -c -V os.build os_buildqnx | tee build.lst
	$(EKIT_BIN_DIR)/romqnx -v -d0 os_buildqnx os_romqnx | tee romqnx.lst
	
efs :
	# Make all the directories needed in the runtime filesystem
	(for i in $(DIRS); do (echo $$i ; mkdir $(ROOT_DIR)/$$i) ; done)
	# Compress the files into the runtime filesystem
	(for i in $(FILES); do (echo $$i ; cp -v $(BONE_DIR)/$$i $(ROOT_DIR)/$$i) ; done)
	$(EKIT_BIN_DIR)/mkffs -v -b8k -s4M -o efs $(ROOT_DIR) | tee ffs.lst
	
image : os_romqnx efs flash.info
	$(EKIT_BIN_DIR)/mkcis -f image flash.info | tee flash.lst
	
reflash : image
	on -n$(TARGET) slay -fQ Efsys.686e
	on -n$(TARGET) ../efs/Efsys.686e &
	sleep 1
	$(EKIT_BIN_DIR)/efsinit //$(TARGET)/dev/skt1
	cp -V image //$(TARGET)/dev/skt1
	
clean :
	rm -rf efs os_buildqnx os_romqnx ./*.map ./*.lst ./*~ $(ROOT_DIR)/*
	
spotless : clean
	rm -f image
