2 # SPDX-License-Identifier: GPL-2.0
4 # This script generates an archive consisting of kernel headers
5 # for CONFIG_IKHEADERS.
7 spath="$(dirname "$(readlink -f "$0")")"
11 cpio_dir=$outdir/$tarfile.tmp
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.
16 sfile="$(realpath --relative-to $kroot "$(readlink -f "$0")")"
20 arch/$SRCARCH/include/
26 arch/$SRCARCH/include/
29 # Support incremental builds by skipping archive generation
30 # if timestamps of files being archived are not changed.
32 # This block is useful for debugging the incremental builds.
33 # Uncomment it for debugging.
34 # if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter;
35 # else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi
36 # find $src_file_list -type f | xargs ls -lR > /tmp/src-ls-$iter
37 # find $obj_file_list -type f | xargs ls -lR > /tmp/obj-ls-$iter
39 # include/generated/compile.h is ignored because it is touched even when none
40 # of the source files changed. This causes pointless regeneration, so let us
41 # ignore them for md5 calculation.
42 pushd $kroot > /dev/null
43 src_files_md5="$(find $src_file_list -type f |
44 grep -v "include/generated/compile.h" |
45 grep -v "include/generated/autoconf.h" |
46 grep -v "include/config/auto.conf" |
47 grep -v "include/config/auto.conf.cmd" |
48 grep -v "include/config/tristate.conf" |
49 xargs ls -lR | md5sum | cut -d ' ' -f1)"
51 obj_files_md5="$(find $obj_file_list -type f |
52 grep -v "include/generated/compile.h" |
53 grep -v "include/generated/autoconf.h" |
54 grep -v "include/config/auto.conf" |
55 grep -v "include/config/auto.conf.cmd" |
56 grep -v "include/config/tristate.conf" |
57 xargs ls -lR | md5sum | cut -d ' ' -f1)"
59 if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
60 if [ -f kernel/kheaders.md5 ] &&
61 [ "$(cat kernel/kheaders.md5|head -1)" == "$src_files_md5" ] &&
62 [ "$(cat kernel/kheaders.md5|head -2|tail -1)" == "$obj_files_md5" ] &&
63 [ "$(cat kernel/kheaders.md5|tail -1)" == "$tarfile_md5" ]; then
67 if [ "${quiet}" != "silent_" ]; then
74 pushd $kroot > /dev/null
75 for f in $src_file_list;
76 do find "$f" ! -name "*.cmd" ! -name ".*";
77 done | cpio --quiet -pd $cpio_dir
80 # The second CPIO can complain if files already exist which can
81 # happen with out of tree builds. Just silence CPIO for now.
82 for f in $obj_file_list;
83 do find "$f" ! -name "*.cmd" ! -name ".*";
84 done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1
86 # Remove comments except SDPX lines
87 find $cpio_dir -type f -print0 |
88 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
90 tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null
92 echo "$src_files_md5" > kernel/kheaders.md5
93 echo "$obj_files_md5" >> kernel/kheaders.md5
94 echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5