From: Avi Kivity <[email protected]>
Signed-off-by: Avi Kivity <[email protected]>
diff --git a/Makefile b/Makefile
index ff6945e..1e0420e 100644
--- a/Makefile
+++ b/Makefile
@@ -35,7 +35,10 @@ all:: prerequisite
include $(MAKEFILE_PRE)
-include sync.mak
+.PHONY: sync
+
+sync:
+ ./sync $(KVM_VERSION)
install:
mkdir -p $(DESTDIR)/$(INSTALLDIR)
diff --git a/scripts/make-release b/scripts/make-release
index 246b851..09b4ba3 100755
--- a/scripts/make-release
+++ b/scripts/make-release
@@ -64,8 +64,7 @@ git --git-dir="$linux_git"
--work-tree="$tmpdir/$name/linux-2.6" \
cd "$tmpdir/$name"
-make -f sync.mak ARCH_DIR=x86 KVM_VERSION="$name"
-make -f sync.mak ARCH_DIR=ia64 KVM_VERSION="$name"
+./sync "$name"
rm -rf "$tmpdir/$name/linux-2.6"
diff --git a/sync b/sync
new file mode 100755
index 0000000..54dcfcd
--- /dev/null
+++ b/sync
@@ -0,0 +1,115 @@
+#!/usr/bin/python
+
+import sys, os, glob, os.path, shutil
+
+glob = glob.glob
+
+def cmd(c):
+ if os.system(c) != 0:
+ raise Exception('command execution failed: ' + c)
+
+version = 'kvm-devel'
+if len(sys.argv) >= 2:
+ version = sys.argv[1]
+
+linux = 'linux-2.6'
+
+def _hack(file, arch):
+ cmd('mv "%(file)s" "%(file)s.orig"'
+ ' && gawk -v version="%(version)s" '
+ ' -f "%(arch)s/hack-module.awk" "%(file)s.orig"'
+ ' | sed "/\#include/! s/\blapic\b/l_apic/g"'
+ ' > "%(file)s" && rm "%(file)s.orig"'
+ % { 'file': file, 'arch': arch, 'version': version })
+
+def unifdef(file):
+ cmd('mv "%(file)s" "%(file)s".orig'
+ ' && cat unifdef.h "%(file)s".orig > "%(file)s"'
+ ' && rm "%(file)s".orig' % { 'file': file })
+
+def hack(T, arch, file):
+ _hack(T + '/' + file, arch)
+
+hack_files = {
+ 'x86': str.split('kvm_main.c mmu.c vmx.c svm.c x86.c irq.h lapic.c'
+ ' i8254.c kvm_trace.c timer.c'),
+ 'ia64': str.split('kvm_main.c kvm_fw.c kvm_lib.c kvm-ia64.c'),
+}
+
+def mkdir(dir):
+ if not os.path.exists(dir):
+ os.makedirs(dir)
+
+def cp(src, dst):
+ mkdir(os.path.dirname(dst))
+ file(dst, 'w').write(file(src).read())
+
+def copy_if_changed(src, dst):
+ for dir, subdirs, files in os.walk(src):
+ ndir = dst + '/' + dir[len(src)+1:]
+ mkdir(ndir)
+ for fname in files:
+ old = ndir + '/' + fname
+ new = dir + '/' + fname
+ try:
+ if file(old).read() != file(new).read():
+ raise Exception('different.')
+ except:
+ cp(new, old)
+
+def rmtree(path):
+ if os.path.exists(path):
+ shutil.rmtree(path)
+
+def header_sync(arch):
+ T = 'header'
+ rmtree(T)
+ for file in glob('%(linux)s/include/linux/kvm*.h' % { 'linux': linux }):
+ out = ('%(T)s/include/linux/%(name)s'
+ % { 'T': T, 'name': os.path.basename(file) })
+ cp(file, out)
+ unifdef(out)
+ arch_headers = (
+ [x
+ for dir in ['%(linux)s/arch/%(arch)s/include/asm/./kvm*.h',
+ '%(linux)s/arch/%(arch)s/include/asm/./vmx*.h',
+ '%(linux)s/arch/%(arch)s/include/asm/./svm*.h',
+ '%(linux)s/arch/%(arch)s/include/asm/./virtext*.h']
+ for x in glob(dir % { 'arch': arch, 'linux': linux })
+ ])
+ for file in arch_headers:
+ out = ('%(T)s/include/asm-%(arch)s/%(name)s'
+ % { 'T': T, 'name': os.path.basename(file), 'arch': arch })
+ cp(file, out)
+ unifdef(out)
+ hack(T, 'x86', 'include/linux/kvm.h')
+ hack(T, arch, 'include/asm-%(arch)s/kvm.h' % { 'arch': arch })
+ copy_if_changed(T, '.')
+ rmtree(T)
+
+def source_sync(arch):
+ T = 'source'
+ rmtree(T)
+ sources = [file
+ for pattern in ['%(linux)s/arch/%(arch)s/kvm/*.[cSh]',
+ '%(linux)s/virt/kvm/*.[cSh]']
+ for file in glob(pattern % { 'linux': linux, 'arch': arch })
+ if not file.endswith('.mod.c')
+ ]
+ for file in sources:
+ out = ('%(T)s/%(name)s'
+ % { 'T': T, 'name': os.path.basename(file) })
+ cp(file, out)
+
+ for i in glob(T + '/*.c'):
+ unifdef(i)
+
+ for i in hack_files[arch]:
+ hack(T, arch, i)
+
+ copy_if_changed(T, arch)
+ rmtree(T)
+
+for arch in ['x86', 'ia64']:
+ header_sync(arch)
+ source_sync(arch)
diff --git a/sync.mak b/sync.mak
deleted file mode 100644
index 801772f..0000000
--- a/sync.mak
+++ /dev/null
@@ -1,63 +0,0 @@
-LINUX = ./linux-2.6
-
-version = $(KVM_VERSION)
-
-_hack = mv $1 $1.orig && \
- gawk -v version=$(version) -f $(ARCH_DIR)/hack-module.awk $1.orig \
- | sed '/\#include/! s/\blapic\b/l_apic/g' > $1 && rm $1.orig
-
-unifdef = mv $1 $1.orig && cat unifdef.h $1.orig > $1 && rm $1.orig
-
-hack = $(call _hack,$T/$(strip $1))
-
-hack-files-x86 = kvm_main.c mmu.c vmx.c svm.c x86.c irq.h lapic.c i8254.c
kvm_trace.c timer.c
-hack-files-ia64 = kvm_main.c kvm_fw.c kvm_lib.c kvm-ia64.c
-
-hack-files = $(hack-files-$(ARCH_DIR))
-
-sync: header-sync source-sync
-
-T = $(subst -sync,,$@)-tmp
-
-headers-old = $(LINUX)/./include/asm-$(ARCH_DIR)/kvm*.h
-headers-new = $(LINUX)/arch/$(ARCH_DIR)/include/asm/./kvm*.h \
- $(LINUX)/arch/$(ARCH_DIR)/include/asm/./vmx*.h \
- $(LINUX)/arch/$(ARCH_DIR)/include/asm/./svm*.h \
- $(LINUX)/arch/$(ARCH_DIR)/include/asm/./virtext*.h
-
-header-sync:
- rm -rf $T
- rsync -R -L \
- "$(LINUX)"/./include/linux/kvm*.h \
- $(if $(wildcard $(headers-old)), $(headers-old)) \
- $T/
- $(if $(wildcard $(headers-new)), \
- rsync -R -L \
- $(wildcard $(headers-new)) \
- $T/include/asm-$(ARCH_DIR)/)
-
- for i in $$(find $T -name '*.h'); do \
- $(call unifdef,$$i); done
- $(call hack, include/linux/kvm.h)
- $(call hack, include/asm-$(ARCH_DIR)/kvm.h)
- set -e && for i in $$(find $T -type f -printf '%P '); \
- do mkdir -p $$(dirname $$i); cmp -s $$i $T/$$i || cp $T/$$i
$$i; done
- rm -rf $T
-
-source-sync:
- rm -rf $T
- rsync --exclude='*.mod.c' -R \
- "$(LINUX)"/arch/$(ARCH_DIR)/kvm/./*.[cSh] \
- "$(LINUX)"/virt/kvm/./*.[cSh] \
- $T/
-
- for i in $$(find $T -name '*.c'); do \
- $(call unifdef,$$i); done
-
- for i in $(hack-files); \
- do $(call hack, $$i); done
-
- for i in $$(find $T -type f -printf '%P '); \
- do cmp -s $(ARCH_DIR)/$$i $T/$$i || cp $T/$$i $(ARCH_DIR)/$$i;
done
- rm -rf $T
-
--
To unsubscribe from this list: send the line "unsubscribe kvm-commits" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html