VERBOSE		=	@

BUILD_DIR		=	../build
L4_BIN_DIR		=	$(BUILD_DIR)/l4/bin/x86_586/l4v2
FIASCO_BUILD_DIR	=	$(BUILD_DIR)/fiasco_ia32
L4LINUX_BUILD_DIR	=	$(BUILD_DIR)/linux


MNT_POINT	=	test_mnt
IMG_NAME	=	l4-demo-image-20070630

DEMO_CFG_DIR	=	config


L4_CONFIGS	= \
		  roottask.config	\
		  ipcmon_test.cfg	\
		  loader_lx_drv.conf	\
		  loader_lx.conf	\
		  lx_ore.rd


L4ENV_OPENTC_BINS		= \
				  bmodfs		\
				  ../bootstrap		\
				  dde26_test		\
				  ddekit_test		\
				  dm_phys		\
				  events		\
				  ipcmon		\
				  ipcmon_test		\
				  ipcmon_test2		\
				  l4io			\
				  libld-l4.s.so		\
				  libloader.s.so 	\
				  loader		\
				  log			\
				  names			\
				  names_demo		\
				  ore			\
				  ore_test_arping	\
				  roottask		\
				  rtc			\
				  semaphore_bench	\
				  sigma0		\
				  simple_ts		\
				  ulockflex


FIASCO_OPENTC_BINS	= \
			  main		\
			  Lines		\
			  Symbols
			
L4LINUX_OPENTC_BINS	= vmlinux


all: demo_opentc

# Mount the img. 
mount_img:
	$(VERBOSE)mkdir $(MNT_POINT)
	$(VERBOSE)sudo mount -o loop,offset=32256 $(IMG_NAME) $(MNT_POINT) 

# Update the L4Env binaries for OpenTC on the img.
update_l4env_opentc: $(MNT_POINT)
	$(VERBOSE)for i in $(L4ENV_OPENTC_BINS); do \
		sudo cp $(L4_BIN_DIR)/$$i $(MNT_POINT)/boot/bin ; \
	done

# Update the Kernel binaries on the img.
update_fiasco: $(MNT_POINT)
	$(VERBOSE)for i in $(FIASCO_OPENTC_BINS); do \
		sudo cp $(FIASCO_BUILD_DIR)/$$i $(MNT_POINT)/boot/bin ; \
	done

# Update the L4Linux binaries for OpenTC on the img.
update_l4lx_opentc: $(MNT_POINT)
	$(VERBOSE)for i in $(L4LINUX_OPENTC_BINS); do \
		sudo cp $(L4LINUX_BUILD_DIR)/$$i $(MNT_POINT)/boot/bin ; \
	done
	$(VERBOSE) sudo cp $(L4LINUX_BUILD_DIR)/vmlinux $(MNT_POINT)/boot/bin/vmlinux-drv

# Update the config files on the img.
update_l4_configs: $(MNT_POINT)
	$(VERBOSE)for i in $(L4_CONFIGS); do \
		sudo cp $(DEMO_CFG_DIR)/$$i $(MNT_POINT)/boot/bin ; \
	done

# Update the Grub boot menu for OpenTC.
update_menu_opentc: $(MNT_POINT)
	$(VERBOSE)sudo cp $(DEMO_CFG_DIR)/menu.lst $(MNT_POINT)/boot/grub

# Umount the img.
umount_img:
	$(VERBOSE)sudo umount $(MNT_POINT)
	$(VERBOSE)rm -rf $(MNT_POINT)

# Start the img with qemu.
start_img:
	qemu -m 384 -serial stdio $(IMG_NAME) 

start_img_ore:
	qemu -m 384 -serial stdio -net nic,vlan=0,model=ne2k_pci -net tap,vlan=0,ifname=tap0 $(IMG_NAME) 
	
update_main: update_fiasco update_l4_configs

update_opentc: update_l4env_opentc update_l4lx_opentc update_menu_opentc

demo_opentc: mount_img update_main update_opentc umount_img start_img

demo_ore: mount_img update_main update_opentc umount_img start_img_ore	
