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
))
13 MAKEFILE_PRE
= $(ARCH_DIR
)/Makefile.pre
15 INSTALLDIR
= $(patsubst %/build
,%/extra
,$(KERNELDIR
))
16 ORIGMODDIR
= $(patsubst %/build
,%/kernel
,$(KERNELDIR
))
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 timer.c
33 hack-files-ia64
= kvm_main.c kvm_fw.c kvm_lib.c kvm-ia64.c
35 hack-files
= $(hack-files-
$(ARCH_DIR
))
37 ifeq ($(EXT_CONFIG_KVM_TRACE
),y
)
38 module_defines
+= -DEXT_CONFIG_KVM_TRACE
=y
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)"
51 sync
: header-sync source-sync
53 T
= $(subst -sync
,,$@
)-tmp
55 headers-old
= $(LINUX
)/.
/include/asm-
$(ARCH_DIR
)/kvm
*.h
56 headers-new
= $(LINUX
)/arch
/$(ARCH_DIR
)/include/asm
/.
/kvm
*.h \
57 $(LINUX
)/arch
/$(ARCH_DIR
)/include/asm
/.
/vmx
*.h \
58 $(LINUX
)/arch
/$(ARCH_DIR
)/include/asm
/.
/svm
*.h \
59 $(LINUX
)/arch
/$(ARCH_DIR
)/include/asm
/.
/virtext
*.h
64 "$(LINUX)"/.
/include/linux
/kvm
*.h \
65 $(if
$(wildcard $(headers-old
)), $(headers-old
)) \
67 $(if
$(wildcard $(headers-new
)), \
69 $(wildcard $(headers-new
)) \
70 $T/include/asm-
$(ARCH_DIR
)/)
72 for i in
$$(find
$T -name
'*.h'); do \
73 $(call unifdef
,$$i); done
74 $(call hack
, include/linux
/kvm.h
)
75 $(call hack
, include/asm-
$(ARCH_DIR
)/kvm.h
)
76 set
-e
&& for i in
$$(find
$T -type f
-printf
'%P '); \
77 do mkdir
-p
$$(dirname
$$i); cmp
-s
$$i $T/$$i || cp
$T/$$i $$i; done
82 rsync
--exclude
='*.mod.c' -R \
83 "$(LINUX)"/arch
/$(ARCH_DIR
)/kvm
/.
/*.
[cSh
] \
84 "$(LINUX)"/virt
/kvm
/.
/*.
[cSh
] \
87 for i in
$$(find
$T -name
'*.c'); do \
88 $(call unifdef
,$$i); done
90 for i in
$(hack-files
); \
91 do
$(call hack
, $$i); done
93 for i in
$$(find
$T -type f
-printf
'%P '); \
94 do cmp
-s
$(ARCH_DIR
)/$$i $T/$$i || cp
$T/$$i $(ARCH_DIR
)/$$i; done
97 include $(MAKEFILE_PRE
)
100 mkdir
-p
$(DESTDIR
)/$(INSTALLDIR
)
101 cp
$(ARCH_DIR
)/*.ko
$(DESTDIR
)/$(INSTALLDIR
)
102 for i in
$(ORIGMODDIR
)/drivers
/kvm
/*.ko \
103 $(ORIGMODDIR
)/arch
/$(ARCH_DIR
)/kvm
/*.ko
; do \
104 if
[ -f
"$$i" ]; then mv
"$$i" "$$i.orig"; fi
; \
106 /sbin
/depmod
-a
$(DEPMOD_VERSION
)
108 tmpspec
= .tmp.kvm-kmod.spec
110 rpm-topdir
:= $$(pwd
)/..
/rpmtop
112 RPMDIR
= $(rpm-topdir
)/RPMS
115 mkdir
-p
$(rpm-topdir
)/BUILD
$(RPMDIR
)/$$(uname
-i
)
116 sed
's/^Release:.*/Release: $(rpmrelease)/; s/^%define kverrel.*/%define kverrel $(KVERREL)/' \
117 kvm-kmod.spec
> $(tmpspec
)
118 rpmbuild
--define="kverrel $(KVERREL)" \
119 --define="objdir $$(pwd)/$(ARCH_DIR)" \
120 --define="_rpmdir $(RPMDIR)" \
121 --define="_topdir $(rpm-topdir)" \
125 $(MAKE
) -C
$(KERNELDIR
) M
=`pwd` $@