xref: /qemu/scripts/update-linux-headers.sh (revision 2879636d55312b5391ec46c7dee5d3a07714c222)
187fdd476SJan Kiszka#!/bin/sh -e
287fdd476SJan Kiszka#
387fdd476SJan Kiszka# Update Linux kernel headers QEMU requires from a specified kernel tree.
487fdd476SJan Kiszka#
587fdd476SJan Kiszka# Copyright (C) 2011 Siemens AG
687fdd476SJan Kiszka#
787fdd476SJan Kiszka# Authors:
887fdd476SJan Kiszka#  Jan Kiszka        <jan.kiszka@siemens.com>
987fdd476SJan Kiszka#
1087fdd476SJan Kiszka# This work is licensed under the terms of the GNU GPL version 2.
1187fdd476SJan Kiszka# See the COPYING file in the top-level directory.
1287fdd476SJan Kiszka
1387fdd476SJan Kiszkatmpdir=`mktemp -d`
1487fdd476SJan Kiszkalinux="$1"
1587fdd476SJan Kiszkaoutput="$2"
1687fdd476SJan Kiszka
1787fdd476SJan Kiszkaif [ -z "$linux" ] || ! [ -d "$linux" ]; then
1887fdd476SJan Kiszka    cat << EOF
1987fdd476SJan Kiszkausage: update-kernel-headers.sh LINUX_PATH [OUTPUT_PATH]
2087fdd476SJan Kiszka
2187fdd476SJan KiszkaLINUX_PATH      Linux kernel directory to obtain the headers from
2287fdd476SJan KiszkaOUTPUT_PATH     output directory, usually the qemu source tree (default: $PWD)
2387fdd476SJan KiszkaEOF
2487fdd476SJan Kiszka    exit 1
2587fdd476SJan Kiszkafi
2687fdd476SJan Kiszka
2787fdd476SJan Kiszkaif [ -z "$output" ]; then
2887fdd476SJan Kiszka    output="$PWD"
2987fdd476SJan Kiszkafi
3087fdd476SJan Kiszka
31*2879636dSPeter Maydell# This will pick up non-directories too (eg "Kconfig") but we will
32*2879636dSPeter Maydell# ignore them in the next loop.
33*2879636dSPeter MaydellARCHLIST=$(cd "$linux/arch" && echo *)
34*2879636dSPeter Maydell
35*2879636dSPeter Maydellfor arch in $ARCHLIST; do
36*2879636dSPeter Maydell    # Discard anything which isn't a KVM-supporting architecture
37*2879636dSPeter Maydell    if ! [ -e "$linux/arch/$arch/include/asm/kvm.h" ]; then
38*2879636dSPeter Maydell        continue
39*2879636dSPeter Maydell    fi
40*2879636dSPeter Maydell
41*2879636dSPeter Maydell    # Blacklist architectures which have KVM headers but are actually dead
42*2879636dSPeter Maydell    if [ "$arch" = "ia64" ]; then
43*2879636dSPeter Maydell        continue
44*2879636dSPeter Maydell    fi
45*2879636dSPeter Maydell
4687fdd476SJan Kiszka    make -C "$linux" INSTALL_HDR_PATH="$tmpdir" SRCARCH=$arch headers_install
4787fdd476SJan Kiszka
4887fdd476SJan Kiszka    rm -rf "$output/linux-headers/asm-$arch"
4987fdd476SJan Kiszka    mkdir -p "$output/linux-headers/asm-$arch"
5087fdd476SJan Kiszka    for header in kvm.h kvm_para.h; do
5187fdd476SJan Kiszka        cp "$tmpdir/include/asm/$header" "$output/linux-headers/asm-$arch"
5287fdd476SJan Kiszka    done
5387fdd476SJan Kiszka    if [ $arch = x86 ]; then
5487fdd476SJan Kiszka        cp "$tmpdir/include/asm/hyperv.h" "$output/linux-headers/asm-x86"
5587fdd476SJan Kiszka    fi
5687fdd476SJan Kiszkadone
5787fdd476SJan Kiszka
5887fdd476SJan Kiszkarm -rf "$output/linux-headers/linux"
5987fdd476SJan Kiszkamkdir -p "$output/linux-headers/linux"
6087fdd476SJan Kiszkafor header in kvm.h kvm_para.h vhost.h virtio_config.h virtio_ring.h; do
6187fdd476SJan Kiszka    cp "$tmpdir/include/linux/$header" "$output/linux-headers/linux"
6287fdd476SJan Kiszkadone
63256d046cSPeter Maydellrm -rf "$output/linux-headers/asm-generic"
64256d046cSPeter Maydellmkdir -p "$output/linux-headers/asm-generic"
65256d046cSPeter Maydellfor header in kvm_para.h; do
66256d046cSPeter Maydell    cp "$tmpdir/include/asm-generic/$header" "$output/linux-headers/asm-generic"
67256d046cSPeter Maydelldone
6887fdd476SJan Kiszkaif [ -L "$linux/source" ]; then
6987fdd476SJan Kiszka    cp "$linux/source/COPYING" "$output/linux-headers"
7087fdd476SJan Kiszkaelse
7187fdd476SJan Kiszka    cp "$linux/COPYING" "$output/linux-headers"
7287fdd476SJan Kiszkafi
7387fdd476SJan Kiszka
7487fdd476SJan Kiszkarm -rf "$tmpdir"
75