blob: 9a34e1d9bd7f97eb82e6ceb0042c7f5502742041 [file] [log] [blame]
Joel Fernandes (Google)9d3b23c2019-04-26 15:04:29 -04001#!/bin/bash
2# SPDX-License-Identifier: GPL-2.0
3
4# This script generates an archive consisting of kernel headers
Joel Fernandes (Google)59d642e2019-05-15 17:35:51 -04005# for CONFIG_IKHEADERS.
Joel Fernandes (Google)9d3b23c2019-04-26 15:04:29 -04006set -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.
Joel Fernandes (Google)414b5512019-05-15 17:35:52 -040034# if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter;
35# else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi
Joel Fernandes (Google)9d3b23c2019-04-26 15:04:29 -040036# 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
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.
42pushd $kroot > /dev/null
43src_files_md5="$(find $src_file_list -type f |
44 grep -v "include/generated/compile.h" |
Joel Fernandes (Google)414b5512019-05-15 17:35:52 -040045 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" |
Joel Fernandes (Google)9d3b23c2019-04-26 15:04:29 -040049 xargs ls -lR | md5sum | cut -d ' ' -f1)"
50popd > /dev/null
51obj_files_md5="$(find $obj_file_list -type f |
52 grep -v "include/generated/compile.h" |
Joel Fernandes (Google)414b5512019-05-15 17:35:52 -040053 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" |
Joel Fernandes (Google)9d3b23c2019-04-26 15:04:29 -040057 xargs ls -lR | md5sum | cut -d ' ' -f1)"
58
59if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
60if [ -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
65fi
66
67if [ "${quiet}" != "silent_" ]; then
68 echo " GEN $tarfile"
69fi
70
71rm -rf $cpio_dir
72mkdir $cpio_dir
73
74pushd $kroot > /dev/null
75for f in $src_file_list;
76 do find "$f" ! -name "*.cmd" ! -name ".*";
77done | cpio --quiet -pd $cpio_dir
78popd > /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.
82for f in $obj_file_list;
83 do find "$f" ! -name "*.cmd" ! -name ".*";
84done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1
85
86# Remove comments except SDPX lines
87find $cpio_dir -type f -print0 |
88 xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
89
90tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null
91
Joel Fernandes (Google)414b5512019-05-15 17:35:52 -040092echo "$src_files_md5" > kernel/kheaders.md5
Joel Fernandes (Google)9d3b23c2019-04-26 15:04:29 -040093echo "$obj_files_md5" >> kernel/kheaders.md5
94echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5
95
96rm -rf $cpio_dir