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
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
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)"
51 sync
: header-sync source-sync 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
69 "$(LINUX)"/.
/include/linux
/kvm
*.h \
70 $(if
$(wildcard $(headers-old
)), $(headers-old
)) \
72 $(if
$(wildcard $(headers-new
)), \
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
87 rsync
--exclude
='*.mod.c' -R \
88 "$(LINUX)"/arch
/$(ARCH_DIR
)/kvm
/.
/*.
[cSh
] \
89 "$(LINUX)"/virt
/kvm
/.
/*.
[cSh
] \
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
102 include $(MAKEFILE_PRE
)
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
; \
111 /sbin
/depmod
-a
$(DEPMOD_VERSION
)
113 tmpspec
= .tmp.kvm-kmod.spec
115 rpm-topdir
:= $$(pwd
)/..
/rpmtop
117 RPMDIR
= $(rpm-topdir
)/RPMS
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)" \
130 $(MAKE
) -C
$(KERNELDIR
) M
=`pwd` $@