1#!/bin/bash -e 2# 3# ethtool-import-uapi [commit] 4# 5# Imports sanitized copies of kernel uapi headers from <commit> (can be 6# a commit id, a tag or a branch name). If the argument is omitted, 7# commit currently checked out in the kernel repository is used. 8 9sn="${0##*/}" 10export ARCH="x86_64" 11mkopt="-j$(nproc)" || mkopt='' 12 13if [ ! -d "$LINUX_GIT" ]; then 14 echo "${sn}: please set LINUX_GIT to the location of kernel git" >&2 15 exit 1 16fi 17 18pushd "$LINUX_GIT" 19if [ -n "$1" ]; then 20 git checkout "$1" 21fi 22desc=$(git describe --exact-match 2>/dev/null \ 23 || git show -s --abbrev=12 --pretty='commit %h') 24kobj=$(mktemp -d) 25make $mkopt O="$kobj" allmodconfig 26make $mkopt O="$kobj" prepare 27make $mkopt O="$kobj" INSTALL_HDR_PATH="${kobj}/hdr" headers_install 28popd 29 30pushd uapi 31find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \; 32 33go_on=true 34while $go_on; do 35 go_on=false 36 while read f; do 37 if [ "${f#asm/}" != "$f" ]; then 38 # skip architecture dependent asm/ headers 39 continue 40 fi 41 if [ -f "$f" ]; then 42 # already present 43 continue 44 fi 45 if [ ! -f "${kobj}/hdr/include/${f}" ]; then 46 # not a kernel header 47 continue 48 fi 49 echo "+ add $f" 50 go_on=true 51 mkdir -p "${f%/*}" 52 cp "${kobj}/hdr/include/${f}" "${f}" 53 done < <( 54 find . -type f -name '*.[ch]' -exec sed -nre '\_^[[:blank:]]*#include[[:blank:]]<.+>_ { s_^[[:blank:]]*#include[[:blank:]]<([^>]*)>.*$_\1_ ; p }' {} \; \ 55 | LC_ALL=C sort -u 56 ) 57done 58popd 59rm -rf "$kobj" 60 61git add uapi 62git commit -s -F - <<EOT 63update UAPI header copies 64 65Update to kernel ${desc}. 66 67EOT 68