#!/bin/bash
# restructure directories to match future drivers/xen plan
# and move aside xen/x86 specific changes
# WARNING!: This directory movement really confuses hg which makes
# it difficult to do development in a directory which is being used
# for building (as all files in mv'd directories are thought by hg
# to have been deleted).  I don't know how to avoid this right now,
# but if someone has a better way, I'm all ears
if [ ! -e mm.xen-x86 ]
then
	mv mm mm.xen-x86
	mkdir mm
	mv net net.xen-x86
	mv kernel kernel.xen-x86
	mv drivers/acpi/tables.c drivers/acpi/tables.c.xen-x86
#	mv arch/xen/kernel drivers/xen/core
#	mv arch/xen arch/xen.xen-x86
#	mkdir arch/xen
#	mv arch/xen.xen-x86/configs arch/xen
#	mv include/asm-generic include/asm-generic.xen-x86
	mv include/linux include/linux.xen-x86
	mkdir include/linux
fi

# need to grab a couple of xen-modified files for generic_page_range and
# typedef pte_fn_t which are used by driver/xen blkif
cp mm.xen-x86/memory.c mm/memory.c
cp include/linux.xen-x86/mm.h include/linux/mm.h

#eventually asm-xsi-offsets needs to be part of hypervisor.h/hypercall.h
cp ../xen/include/asm-ia64/asm-xsi-offsets.h include/asm-ia64/xen/

#ia64 drivers/xen isn't fully functional yet, workaround...
#also ignore core/evtchn.c which uses a different irq mechanism than ia64
#(warning: there be dragons here if these files diverge)
cp arch/ia64/xen/drivers/Makefile drivers/xen/Makefile
cp arch/ia64/xen/drivers/coreMakefile drivers/xen/core/Makefile

#not sure where these ia64-specific files will end up in the future
cp arch/ia64/xen/drivers/xenia64_init.c drivers/xen/core
cp arch/ia64/xen/drivers/evtchn_ia64.c drivers/xen/core

#still a few x86-ism's in various drivers/xen files, patch them
#cd drivers/xen
#if [ ! -e ia64.patch.semaphore ]
#then
#	cat ../../arch/ia64/xen/drivers/patches/* | patch -p1 -b
#fi
#touch ia64.patch.semaphore
#cd ../..
