xref: /kvmtool/util/update_headers.sh (revision 393e2187cf68a14e107f9fa75b1da4f5632b379b)
1#!/bin/sh
2
3########################################################################
4# Updates the kvmtool tree with up-to-date public header files from
5# a Linux source tree.
6# If no directory is given on the command line, it will try to find one
7# using the lib/modules/`uname -r`/source link.
8########################################################################
9
10set -ue
11
12VIRTIO_LIST="virtio_9p.h virtio_balloon.h virtio_blk.h virtio_config.h \
13	     virtio_console.h virtio_ids.h virtio_mmio.h virtio_net.h \
14	     virtio_pci.h virtio_ring.h virtio_rng.h virtio_scsi.h \
15	     virtio_vsock.h"
16
17if [ "$#" -ge 1 ]
18then
19	LINUX_ROOT="$1"
20else
21	LINUX_ROOT="/lib/modules/$(uname -r)/source"
22fi
23
24if [ ! -d "$LINUX_ROOT/include/uapi/linux" ]
25then
26	echo "$LINUX_ROOT does not seem to be valid Linux source tree."
27	echo "usage: $0 [path-to-Linux-source-tree]"
28	exit 1
29fi
30
31cp -- "$LINUX_ROOT/include/uapi/linux/kvm.h" include/linux
32
33for header in $VIRTIO_LIST
34do
35	cp -- "$LINUX_ROOT/include/uapi/linux/$header" include/linux
36done
37
38unset KVMTOOL_PATH
39
40copy_optional_arch () {
41	local src="$LINUX_ROOT/arch/$arch/include/uapi/$1"
42
43	if [ -r "$src" ]
44	then
45		cp -- "$src" "$KVMTOOL_PATH/include/asm/"
46	fi
47}
48
49for arch in arm64 mips powerpc riscv x86
50do
51	case "$arch" in
52		arm64)	KVMTOOL_PATH=arm/aarch64
53			copy_optional_arch asm/sve_context.h ;;
54		*) KVMTOOL_PATH=$arch ;;
55	esac
56	cp -- "$LINUX_ROOT/arch/$arch/include/uapi/asm/kvm.h" \
57		"$KVMTOOL_PATH/include/asm"
58done
59