kvm: external module: remove x86-specific file from common code in make sync
[kvm-userspace.git] / kernel / Makefile
blobf8b341ff1d81d36b48e29ddb667f73f934dd299d
1 include ../config.mak
2 include config.kbuild
4 ARCH_DIR = $(if $(filter $(ARCH),x86_64 i386),x86,$(ARCH))
5 ARCH_CONFIG := $(shell echo $(ARCH_DIR) | tr '[:lower:]' '[:upper:]')
6 # NONARCH_CONFIG used for unifdef, and only cover X86 and IA64 now
7 NONARCH_CONFIG = $(filter-out $(ARCH_CONFIG),X86 IA64)
9 KVERREL = $(patsubst /lib/modules/%/build,%,$(KERNELDIR))
11 DESTDIR=
13 MAKEFILE_PRE = $(ARCH_DIR)/Makefile.pre
15 INSTALLDIR = $(patsubst %/build,%/extra,$(KERNELDIR))
16 ORIGMODDIR = $(patsubst %/build,%/kernel,$(KERNELDIR))
18 rpmrelease = devel
20 LINUX = ../linux-2.6
22 version = $(shell cd $(LINUX); git describe)
24 _hack = mv $1 $1.orig && \
25 gawk -v version=$(version) -f $(ARCH_DIR)/hack-module.awk $1.orig \
26 | sed '/\#include/! s/\blapic\b/l_apic/g' > $1 && rm $1.orig
28 unifdef = mv $1 $1.orig && cat unifdef.h $1.orig > $1 && rm $1.orig
30 hack = $(call _hack,$T/$(strip $1))
32 hack-files-x86 = kvm_main.c mmu.c vmx.c svm.c x86.c irq.h lapic.c i8254.c kvm_trace.c
33 hack-files-ia64 = kvm_main.c kvm_fw.c kvm_lib.c
35 hack-files = $(hack-files-$(ARCH_DIR))
37 ifeq ($(EXT_CONFIG_KVM_TRACE),y)
38 module_defines += -DEXT_CONFIG_KVM_TRACE=y
39 endif
41 all:: header-link prerequisite
42 # include header priority 1) $LINUX 2) $KERNELDIR 3) include-compat
43 $(MAKE) -C $(KERNELDIR) M=`pwd` \
44 LINUXINCLUDE="-I`pwd`/include -Iinclude \
45 $(if $(KERNELSOURCEDIR),-Iinclude2 -I$(KERNELSOURCEDIR)/include) \
46 -Iarch/${ARCH_DIR}/include -I`pwd`/include-compat \
47 -include include/linux/autoconf.h \
48 -include `pwd`/$(ARCH_DIR)/external-module-compat.h $(module_defines)"
49 "$$@"
51 sync: header-sync source-sync header-link
53 header-link:
54 rm -f include/asm include-compat/asm
55 ln -sf asm-$(ARCH_DIR) include/asm
56 ln -sf asm-$(ARCH_DIR) include-compat/asm
58 T = $(subst -sync,,$@)-tmp
60 headers-old = $(LINUX)/./include/asm-$(ARCH_DIR)/kvm*.h
61 headers-new = $(LINUX)/arch/$(ARCH_DIR)/include/asm/./kvm*.h \
62 $(LINUX)/arch/$(ARCH_DIR)/include/asm/./vmx*.h \
63 $(LINUX)/arch/$(ARCH_DIR)/include/asm/./svm*.h \
64 $(LINUX)/arch/$(ARCH_DIR)/include/asm/./virtext*.h
66 header-sync:
67 rm -rf $T
68 rsync -R -L \
69 "$(LINUX)"/./include/linux/kvm*.h \
70 $(if $(wildcard $(headers-old)), $(headers-old)) \
71 $T/
72 $(if $(wildcard $(headers-new)), \
73 rsync -R -L \
74 $(wildcard $(headers-new)) \
75 $T/include/asm-$(ARCH_DIR)/)
77 for i in $$(find $T -name '*.h'); do \
78 $(call unifdef,$$i); done
79 $(call hack, include/linux/kvm.h)
80 $(call hack, include/asm-$(ARCH_DIR)/kvm.h)
81 set -e && for i in $$(find $T -type f -printf '%P '); \
82 do mkdir -p $$(dirname $$i); cmp -s $$i $T/$$i || cp $T/$$i $$i; done
83 rm -rf $T
85 source-sync:
86 rm -rf $T
87 rsync --exclude='*.mod.c' -R \
88 "$(LINUX)"/arch/$(ARCH_DIR)/kvm/./*.[cSh] \
89 "$(LINUX)"/virt/kvm/./*.[cSh] \
90 $T/
92 for i in $$(find $T -name '*.c'); do \
93 $(call unifdef,$$i); done
95 for i in $(hack-files); \
96 do $(call hack, $$i); done
98 for i in $$(find $T -type f -printf '%P '); \
99 do cmp -s $(ARCH_DIR)/$$i $T/$$i || cp $T/$$i $(ARCH_DIR)/$$i; done
100 rm -rf $T
102 include $(MAKEFILE_PRE)
104 install:
105 mkdir -p $(DESTDIR)/$(INSTALLDIR)
106 cp $(ARCH_DIR)/*.ko $(DESTDIR)/$(INSTALLDIR)
107 for i in $(ORIGMODDIR)/drivers/kvm/*.ko \
108 $(ORIGMODDIR)/arch/$(ARCH_DIR)/kvm/*.ko; do \
109 if [ -f "$$i" ]; then mv "$$i" "$$i.orig"; fi; \
110 done
111 /sbin/depmod -a $(DEPMOD_VERSION)
113 tmpspec = .tmp.kvm-kmod.spec
115 rpm-topdir := $$(pwd)/../rpmtop
117 RPMDIR = $(rpm-topdir)/RPMS
119 rpm: all
120 mkdir -p $(rpm-topdir)/BUILD $(RPMDIR)/$$(uname -i)
121 sed 's/^Release:.*/Release: $(rpmrelease)/; s/^%define kverrel.*/%define kverrel $(KVERREL)/' \
122 kvm-kmod.spec > $(tmpspec)
123 rpmbuild --define="kverrel $(KVERREL)" \
124 --define="objdir $$(pwd)/$(ARCH_DIR)" \
125 --define="_rpmdir $(RPMDIR)" \
126 --define="_topdir $(rpm-topdir)" \
127 -bb $(tmpspec)
129 clean:
130 $(MAKE) -C $(KERNELDIR) M=`pwd` $@