]> git.ipfire.org Git - thirdparty/linux.git/blame - kernel/gen_ikh_data.sh
Linux 5.2-rc1
[thirdparty/linux.git] / kernel / gen_ikh_data.sh
CommitLineData
43d8ce9d
JFG
1#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This script generates an archive consisting of kernel headers
5# for CONFIG_IKHEADERS_PROC.
6set -e
7spath="$(dirname "$(readlink -f "$0")")"
8kroot="$spath/.."
9outdir="$(pwd)"
10tarfile=$1
11cpio_dir=$outdir/$tarfile.tmp
12
13# Script filename relative to the kernel source root
14# We add it to the archive because it is small and any changes
15# to this script will also cause a rebuild of the archive.
16sfile="$(realpath --relative-to $kroot "$(readlink -f "$0")")"
17
18src_file_list="
19include/
20arch/$SRCARCH/include/
21$sfile
22"
23
24obj_file_list="
25include/
26arch/$SRCARCH/include/
27"
28
29# Support incremental builds by skipping archive generation
30# if timestamps of files being archived are not changed.
31
32# This block is useful for debugging the incremental builds.
33# Uncomment it for debugging.
34# iter=1
35# if [ ! -f /tmp/iter ]; then echo 1 > /tmp/iter;
36# else; iter=$(($(cat /tmp/iter) + 1)); fi
37# find $src_file_list -type f | xargs ls -lR > /tmp/src-ls-$iter
38# find $obj_file_list -type f | xargs ls -lR > /tmp/obj-ls-$iter
39
40# include/generated/compile.h is ignored because it is touched even when none
41# of the source files changed. This causes pointless regeneration, so let us
42# ignore them for md5 calculation.
43pushd $kroot > /dev/null
44src_files_md5="$(find $src_file_list -type f |
45 grep -v "include/generated/compile.h" |
46 xargs ls -lR | md5sum | cut -d ' ' -f1)"
47popd > /dev/null
48obj_files_md5="$(find $obj_file_list -type f |
49 grep -v "include/generated/compile.h" |
50 xargs ls -lR | md5sum | cut -d ' ' -f1)"
51
52if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
53if [ -f kernel/kheaders.md5 ] &&
54 [ "$(cat kernel/kheaders.md5|head -1)" == "$src_files_md5" ] &&
55 [ "$(cat kernel/kheaders.md5|head -2|tail -1)" == "$obj_files_md5" ] &&
56 [ "$(cat kernel/kheaders.md5|tail -1)" == "$tarfile_md5" ]; then
57 exit
58fi
59
60if [ "${quiet}" != "silent_" ]; then
61 echo " GEN $tarfile"
62fi
63
64rm -rf $cpio_dir
65mkdir $cpio_dir
66
67pushd $kroot > /dev/null
68for f in $src_file_list;
69 do find "$f" ! -name "*.cmd" ! -name ".*";
70done | cpio --quiet -pd $cpio_dir
71popd > /dev/null
72
73# The second CPIO can complain if files already exist which can
74# happen with out of tree builds. Just silence CPIO for now.
75for f in $obj_file_list;
76 do find "$f" ! -name "*.cmd" ! -name ".*";
77done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1
78
79# Remove comments except SDPX lines
80find $cpio_dir -type f -print0 |
81 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
82
83tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null
84
85echo "$src_files_md5" > kernel/kheaders.md5
86echo "$obj_files_md5" >> kernel/kheaders.md5
87echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5
88
89rm -rf $cpio_dir