Commit | Line | Data |
---|---|---|
43d8ce9d JFG |
1 | #!/bin/bash |
2 | # SPDX-License-Identifier: GPL-2.0 | |
3 | ||
4 | # This script generates an archive consisting of kernel headers | |
f7b101d3 | 5 | # for CONFIG_IKHEADERS. |
43d8ce9d JFG |
6 | set -e |
7 | spath="$(dirname "$(readlink -f "$0")")" | |
8 | kroot="$spath/.." | |
9 | outdir="$(pwd)" | |
10 | tarfile=$1 | |
11 | cpio_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. | |
16 | sfile="$(realpath --relative-to $kroot "$(readlink -f "$0")")" | |
17 | ||
18 | src_file_list=" | |
19 | include/ | |
20 | arch/$SRCARCH/include/ | |
21 | $sfile | |
22 | " | |
23 | ||
24 | obj_file_list=" | |
25 | include/ | |
26 | arch/$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. | |
1457dc9e JFG |
34 | # if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter; |
35 | # else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi | |
b60b7c2e MY |
36 | # find $src_file_list -type f | xargs ls -l > /tmp/src-ls-$iter |
37 | # find $obj_file_list -type f | xargs ls -l > /tmp/obj-ls-$iter | |
43d8ce9d JFG |
38 | |
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" | | |
1457dc9e JFG |
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" | | |
b60b7c2e | 49 | xargs ls -l | md5sum | cut -d ' ' -f1)" |
43d8ce9d JFG |
50 | popd > /dev/null |
51 | obj_files_md5="$(find $obj_file_list -type f | | |
52 | grep -v "include/generated/compile.h" | | |
1457dc9e JFG |
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" | | |
b60b7c2e | 57 | xargs ls -l | md5sum | cut -d ' ' -f1)" |
43d8ce9d JFG |
58 | |
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 | |
64 | exit | |
65 | fi | |
66 | ||
67 | if [ "${quiet}" != "silent_" ]; then | |
68 | echo " GEN $tarfile" | |
69 | fi | |
70 | ||
71 | rm -rf $cpio_dir | |
72 | mkdir $cpio_dir | |
73 | ||
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 | |
78 | popd > /dev/null | |
79 | ||
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 | |
85 | ||
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;' | |
89 | ||
90 | tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null | |
91 | ||
1457dc9e | 92 | echo "$src_files_md5" > kernel/kheaders.md5 |
43d8ce9d JFG |
93 | echo "$obj_files_md5" >> kernel/kheaders.md5 |
94 | echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5 | |
95 | ||
96 | rm -rf $cpio_dir |