3 ARCH_DIR
= $(if
$(filter $(ARCH
),x86_64 i386
),x86
,$(ARCH
))
4 ARCH_CONFIG
:= $(shell echo
$(ARCH_DIR
) | tr
'[:lower:]' '[:upper:]')
6 KVERREL
= $(patsubst /lib
/modules
/%/build
,%,$(KERNELDIR
))
10 MAKEFILE_PRE
= $(ARCH_DIR
)/Makefile.pre
12 INSTALLDIR
= $(patsubst %/build
,%/extra
,$(KERNELDIR
))
13 ORIGMODDIR
= $(patsubst %/build
,%/kernel
,$(KERNELDIR
))
19 version
= $(shell cd
$(LINUX
); git describe
)
21 _hack
= mv
$1 $1.orig
&& \
22 gawk
-v version
=$(version
) -f
$(ARCH_DIR
)/hack-module.awk
$1.orig \
23 | sed
'/\#include/! s/\blapic\b/l_apic/g' > $1 && rm $1.orig
25 unifdef
= mv
$1 $1.orig
&& \
26 unifdef
-DCONFIG_
$(ARCH_CONFIG
) $1.orig
> $1; \
27 [ $$?
-le
1 ] && rm $1.orig
29 hack
= $(call _hack
,$T/$(strip $1))
31 hack-files-x86
= kvm_main.c mmu.c vmx.c svm.c x86.c irq.h lapic.c i8254.c
32 hack-files-ia64
= kvm_main.c kvm_fw.c
34 hack-files
= $(hack-files-
$(ARCH_DIR
))
36 all:: header-link prerequisite
37 # include header priority 1) $LINUX 2) $KERNELDIR 3) include-compat
38 $(MAKE
) -C
$(KERNELDIR
) M
=`pwd` \
39 LINUXINCLUDE
="-I`pwd`/include -Iinclude -Iarch/${ARCH_DIR}/include -I`pwd`/include-compat \
40 -include include/linux/autoconf.h \
41 -include `pwd`/$(ARCH_DIR)/external-module-compat.h"
44 sync
: header-sync source-sync header-link
48 ln
-sf asm-
$(ARCH_DIR
) include/asm
49 ln
-sf asm-
$(ARCH_DIR
) include-compat
/asm
51 T
= $(subst -sync
,,$@
)-tmp
56 "$(LINUX)"/.
/include/linux
/kvm
*.h \
57 "$(LINUX)"/.
/include/asm-
*/kvm
*.h \
60 "$(LINUX)"/arch
/$(ARCH_DIR
)/include/asm
/.
/kvm
*.h \
61 $T/include/asm-
$(ARCH_DIR
)/
63 set
-e
&& for i in
$(find
$T -name
'*.h'); do \
64 $(call unifdef
,$$i); done
65 $(call hack
, include/linux
/kvm.h
)
66 set
-e
&& for i in
$$(find
$T -type f
-printf
'%P '); \
67 do mkdir
-p
$$(dirname
$$i); cmp
-s
$$i $T/$$i || cp
$T/$$i $$i; done
72 rsync
--exclude
='*.mod.c' -R \
73 "$(LINUX)"/arch
/$(ARCH_DIR
)/kvm
/.
/*.
[cSh
] \
74 "$(LINUX)"/virt
/kvm
/.
/*.
[cSh
] \
77 set
-e
&& for i in
$(find
$T -name
'*.c'); do \
78 $(call unifdef
,$$i); done
80 for i in
$(hack-files
); \
81 do
$(call hack
, $$i); done
83 for i in
$$(find
$T -type f
-printf
'%P '); \
84 do cmp
-s
$(ARCH_DIR
)/$$i $T/$$i || cp
$T/$$i $(ARCH_DIR
)/$$i; done
87 include $(MAKEFILE_PRE
)
90 mkdir
-p
$(DESTDIR
)/$(INSTALLDIR
)
91 cp
$(ARCH_DIR
)/*.ko
$(DESTDIR
)/$(INSTALLDIR
)
92 for i in
$(ORIGMODDIR
)/drivers
/kvm
/*.ko \
93 $(ORIGMODDIR
)/arch
/$(ARCH_DIR
)/kvm
/*.ko
; do \
94 if
[ -f
"$$i" ]; then mv
"$$i" "$$i.orig"; fi
; \
98 tmpspec
= .tmp.kvm-kmod.spec
100 rpm-topdir
:= $$(pwd
)/..
/rpmtop
102 RPMDIR
= $(rpm-topdir
)/RPMS
105 mkdir
-p
$(rpm-topdir
)/BUILD
$(RPMDIR
)/$$(uname
-i
)
106 sed
's/^Release:.*/Release: $(rpmrelease)/; s/^%define kverrel.*/%define kverrel $(KVERREL)/' \
107 kvm-kmod.spec
> $(tmpspec
)
108 rpmbuild
--define="kverrel $(KVERREL)" \
109 --define="objdir $$(pwd)/$(ARCH_DIR)" \
110 --define="_rpmdir $(RPMDIR)" \
111 --define="_topdir $(rpm-topdir)" \
115 $(MAKE
) -C
$(KERNELDIR
) M
=`pwd` $@