OSDN Git Service

dc5744b93f8c5ba00e19db31c5efabf6cd446c4b
[tomoyo/tomoyo-test1.git] / kernel / gen_kheaders.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
3
4 # This script generates an archive consisting of kernel headers
5 # for CONFIG_IKHEADERS.
6 set -e
7 sfile="$(readlink -f "$0")"
8 outdir="$(pwd)"
9 tarfile=$1
10 cpio_dir=$outdir/$tarfile.tmp
11
12 dir_list="
13 include/
14 arch/$SRCARCH/include/
15 "
16
17 # Support incremental builds by skipping archive generation
18 # if timestamps of files being archived are not changed.
19
20 # This block is useful for debugging the incremental builds.
21 # Uncomment it for debugging.
22 # if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter;
23 # else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi
24 # find $all_dirs -name "*.h" | xargs ls -l > /tmp/ls-$iter
25
26 all_dirs=
27 if [ "$building_out_of_srctree" ]; then
28         for d in $dir_list; do
29                 all_dirs="$all_dirs $srctree/$d"
30         done
31 fi
32 all_dirs="$all_dirs $dir_list"
33
34 # include/generated/compile.h is ignored because it is touched even when none
35 # of the source files changed. This causes pointless regeneration, so let us
36 # ignore them for md5 calculation.
37 headers_md5="$(find $all_dirs -name "*.h"                       |
38                 grep -v "include/generated/compile.h"   |
39                 grep -v "include/generated/autoconf.h"  |
40                 xargs ls -l | md5sum | cut -d ' ' -f1)"
41
42 # Any changes to this script will also cause a rebuild of the archive.
43 this_file_md5="$(ls -l $sfile | md5sum | cut -d ' ' -f1)"
44 if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
45 if [ -f kernel/kheaders.md5 ] &&
46         [ "$(head -n 1 kernel/kheaders.md5)" = "$headers_md5" ] &&
47         [ "$(head -n 2 kernel/kheaders.md5 | tail -n 1)" = "$this_file_md5" ] &&
48         [ "$(tail -n 1 kernel/kheaders.md5)" = "$tarfile_md5" ]; then
49                 exit
50 fi
51
52 if [ "${quiet}" != "silent_" ]; then
53        echo "  GEN     $tarfile"
54 fi
55
56 rm -rf $cpio_dir
57 mkdir $cpio_dir
58
59 if [ "$building_out_of_srctree" ]; then
60         (
61                 cd $srctree
62                 for f in $dir_list
63                         do find "$f" -name "*.h";
64                 done | cpio --quiet -pd $cpio_dir
65         )
66 fi
67
68 # The second CPIO can complain if files already exist which can happen with out
69 # of tree builds having stale headers in srctree. Just silence CPIO for now.
70 for f in $dir_list;
71         do find "$f" -name "*.h";
72 done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1
73
74 # Remove comments except SDPX lines
75 find $cpio_dir -type f -print0 |
76         xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
77
78 # Create archive and try to normalize metadata for reproducibility.
79 # For compatibility with older versions of tar, files are fed to tar
80 # pre-sorted, as --sort=name might not be available.
81 find $cpio_dir -printf "./%P\n" | LC_ALL=C sort | \
82     tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \
83     --owner=0 --group=0 --numeric-owner --no-recursion \
84     -Jcf $tarfile -C $cpio_dir/ -T - > /dev/null
85
86 echo $headers_md5 > kernel/kheaders.md5
87 echo "$this_file_md5" >> kernel/kheaders.md5
88 echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5
89
90 rm -rf $cpio_dir