| 1 |
#!/bin/bash -e |
| 2 |
# |
| 3 |
# iproute2-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 |
|
| 9 |
sn="${0##*/}" |
| 10 |
export ARCH="x86_64" |
| 11 |
mkopt="-j$(nproc)" || mkopt='' |
| 12 |
|
| 13 |
if [ ! -d "$LINUX_GIT" ]; then |
| 14 |
echo "${sn}: please set LINUX_GIT to the location of kernel git" >&2 |
| 15 |
exit 1 |
| 16 |
fi |
| 17 |
|
| 18 |
pushd "$LINUX_GIT" |
| 19 |
if [ -n "$1" ]; then |
| 20 |
git checkout "$1" |
| 21 |
fi |
| 22 |
desc=$(git describe --exact-match 2>/dev/null \ |
| 23 |
|| git show -s --abbrev=12 --pretty='%h: ("%s")') |
| 24 |
kobj=$(mktemp -d) |
| 25 |
make $mkopt O="$kobj" allmodconfig |
| 26 |
make $mkopt O="$kobj" prepare |
| 27 |
make $mkopt O="$kobj" INSTALL_HDR_PATH="${kobj}/hdr" headers_install |
| 28 |
popd |
| 29 |
|
| 30 |
pushd include/uapi |
| 31 |
find . -type f -name '*.h' -exec cp -v "${kobj}/hdr/include/{}" {} \; |
| 32 |
|
| 33 |
go_on=true |
| 34 |
while $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 |
) |
| 57 |
done |
| 58 |
popd |
| 59 |
rm -rf "$kobj" |
| 60 |
|
| 61 |
git add include/uapi |
| 62 |
git commit -n -s -F - <<EOT |
| 63 |
Update kernel headers |
| 64 |
|
| 65 |
Update kernel headers to commit: |
| 66 |
${desc} |
| 67 |
EOT |