kvm: external module: Make KVM compile on split source/object kernel configurations
[qemu-kvm/fedora.git] / kvm / kernel / Makefile
blobef18fa6b9dee18ee604ad0b6c648cc7518a2627a
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:]')
7 KVERREL = $(patsubst /lib/modules/%/build,%,$(KERNELDIR))
9 DESTDIR=
11 MAKEFILE_PRE = $(ARCH_DIR)/Makefile.pre
13 INSTALLDIR = $(patsubst %/build,%/extra,$(KERNELDIR))
14 ORIGMODDIR = $(patsubst %/build,%/kernel,$(KERNELDIR))
16 rpmrelease = devel
18 LINUX = ../linux-2.6
20 version = $(shell cd $(LINUX); git describe)
22 _hack = mv $1 $1.orig && \
23 gawk -v version=$(version) -f $(ARCH_DIR)/hack-module.awk $1.orig \
24 | sed '/\#include/! s/\blapic\b/l_apic/g' > $1 && rm $1.orig
26 unifdef = mv $1 $1.orig && \
27 unifdef -DCONFIG_$(ARCH_CONFIG) $1.orig > $1; \
28 [ $$? -le 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
35 hack-files = $(hack-files-$(ARCH_DIR))
37 ifeq ($(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 header-sync:
61 rm -rf $T
62 rsync -R \
63 "$(LINUX)"/./include/linux/kvm*.h \
64 "$(LINUX)"/./include/asm-*/kvm*.h \
65 $T/
66 -rsync -R \
67 "$(LINUX)"/arch/$(ARCH_DIR)/include/asm/./kvm*.h \
68 $T/include/asm-$(ARCH_DIR)/
70 set -e && for i in $(find $T -name '*.h'); do \
71 $(call unifdef,$$i); done
72 $(call hack, include/linux/kvm.h)
73 set -e && for i in $$(find $T -type f -printf '%P '); \
74 do mkdir -p $$(dirname $$i); cmp -s $$i $T/$$i || cp $T/$$i $$i; done
75 rm -rf $T
77 source-sync:
78 rm -rf $T
79 rsync --exclude='*.mod.c' -R \
80 "$(LINUX)"/arch/$(ARCH_DIR)/kvm/./*.[cSh] \
81 "$(LINUX)"/virt/kvm/./*.[cSh] \
82 $T/
84 set -e && for i in $(find $T -name '*.c'); do \
85 $(call unifdef,$$i); done
87 for i in $(hack-files); \
88 do $(call hack, $$i); done
90 for i in $$(find $T -type f -printf '%P '); \
91 do cmp -s $(ARCH_DIR)/$$i $T/$$i || cp $T/$$i $(ARCH_DIR)/$$i; done
92 rm -rf $T
94 include $(MAKEFILE_PRE)
96 install:
97 mkdir -p $(DESTDIR)/$(INSTALLDIR)
98 cp $(ARCH_DIR)/*.ko $(DESTDIR)/$(INSTALLDIR)
99 for i in $(ORIGMODDIR)/drivers/kvm/*.ko \
100 $(ORIGMODDIR)/arch/$(ARCH_DIR)/kvm/*.ko; do \
101 if [ -f "$$i" ]; then mv "$$i" "$$i.orig"; fi; \
102 done
103 /sbin/depmod -a
105 tmpspec = .tmp.kvm-kmod.spec
107 rpm-topdir := $$(pwd)/../rpmtop
109 RPMDIR = $(rpm-topdir)/RPMS
111 rpm: all
112 mkdir -p $(rpm-topdir)/BUILD $(RPMDIR)/$$(uname -i)
113 sed 's/^Release:.*/Release: $(rpmrelease)/; s/^%define kverrel.*/%define kverrel $(KVERREL)/' \
114 kvm-kmod.spec > $(tmpspec)
115 rpmbuild --define="kverrel $(KVERREL)" \
116 --define="objdir $$(pwd)/$(ARCH_DIR)" \
117 --define="_rpmdir $(RPMDIR)" \
118 --define="_topdir $(rpm-topdir)" \
119 -bb $(tmpspec)
121 clean:
122 $(MAKE) -C $(KERNELDIR) M=`pwd` $@