[PATCH 6/6] Provide a mechanism to build virtio drivers as modules (v2)

Anthony Liguori
2007-11-11T03:20:40Z

This provides a make sync within the drivers/ directory to allow virtio drivers
to be built as third-party modules much as we do with the KVM driver.

Signed-off-by: Anthony Liguori <aliguori-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>

diff --git a/.gitignore b/.gitignore
index 600508a..f9b95f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,4 +26,11 @@ kernel/x86_emulate.[ch]
kernel/include/linux/kvm*.h
kernel/Module.symvers
kernel/Modules.symvers
-kernel/.tmp_versions
\ No newline at end of file
+kernel/.tmp_versions
+drivers/config.c
+drivers/virtio.c
+drivers/virtio_ring.c
+drivers/virtio_pci.c
+drivers/virtio_blk.c
+drivers/virtio_net.c
+drivers/include/linux/virtio*.h
diff --git a/Makefile b/Makefile
index 776ff01..dd1da6e 100644
--- a/Makefile
+++ b/Makefile
@@ -68,7 +68,7 @@ srpm:
$(RM) $(tmpspec)

clean:
- for i in $(if $(WANT_MODULE), kernel) user libkvm qemu; do \
+ for i in $(if $(WANT_MODULE), kernel drivers) user libkvm qemu; do \
make -C $$i clean; \
done
rm -f config.mak user/config.mak
diff --git a/drivers/Kbuild b/drivers/Kbuild
new file mode 100644
index 0000000..74d1ed0
--- /dev/null
+++ b/drivers/Kbuild
@@ -0,0 +1,2 @@
+EXTRA_CFLAGS := -I$(src)/include -include $(src)/external-module-compat.h
+obj-m := virtio.o virtio_ring.o virtio_pci.o virtio_net.o virtio_blk.o
diff --git a/drivers/Makefile b/drivers/Makefile
new file mode 100644
index 0000000..a0d232c
--- /dev/null
+++ b/drivers/Makefile
@@ -0,0 +1,23 @@
+include ../config.mak
+
+KVERREL = $(patsubst /lib/modules/%/build,%,$(KERNELDIR))
+
+DESTDIR=
+
+INSTALLDIR = $(patsubst %/build,%/extra,$(KERNELDIR))
+ORIGMODDIR = $(patsubst %/build,%/kernel,$(KERNELDIR))
+
+LINUX = ../linux-2.6
+
+all::
+ $(MAKE) -C $(KERNELDIR) M=`pwd` "$$@"
+
+sync:
+ mkdir -p include/linux
+ rsync --exclude='*.mod.c' "$(LINUX)"/drivers/virtio/*.[ch] .
+ rsync "$(LINUX)"/include/linux/virtio*.h include/linux
+ rsync "$(LINUX)"/drivers/block/virtio_blk.c .
+ rsync "$(LINUX)"/drivers/net/virtio_net.c .
+
+clean:
+ $(MAKE) -C $(KERNELDIR) M=`pwd` $@
diff --git a/drivers/external-module-compat.h b/drivers/external-module-compat.h
new file mode 100644
index 0000000..f0e4868
--- /dev/null
+++ b/drivers/external-module-compat.h
@@ -0,0 +1,14 @@
+#ifndef _VIRTIO_EXT_MOD_COMPAT_H
+#define _VIRTIO_EXT_MOD_COMPAT_H
+
+/* make sure out copies of the headers get included */
+
+#include "include/linux/virtio.h"
+#include "include/linux/virtio_config.h"
+#include "include/linux/virtio_ring.h"
+#include "include/linux/virtio_pci.h"
+#include "include/linux/virtio_blk.h"
+#include "include/linux/virtio_net.h"
+#include "include/linux/virtio_9p.h"
+
+#endif