Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0
0003 
0004 # This script generates an archive consisting of kernel headers
0005 # for CONFIG_IKHEADERS.
0006 set -e
0007 sfile="$(readlink -f "$0")"
0008 outdir="$(pwd)"
0009 tarfile=$1
0010 cpio_dir=$outdir/$tarfile.tmp
0011 
0012 dir_list="
0013 include/
0014 arch/$SRCARCH/include/
0015 "
0016 
0017 # Support incremental builds by skipping archive generation
0018 # if timestamps of files being archived are not changed.
0019 
0020 # This block is useful for debugging the incremental builds.
0021 # Uncomment it for debugging.
0022 # if [ ! -f /tmp/iter ]; then iter=1; echo 1 > /tmp/iter;
0023 # else iter=$(($(cat /tmp/iter) + 1)); echo $iter > /tmp/iter; fi
0024 # find $all_dirs -name "*.h" | xargs ls -l > /tmp/ls-$iter
0025 
0026 all_dirs=
0027 if [ "$building_out_of_srctree" ]; then
0028         for d in $dir_list; do
0029                 all_dirs="$all_dirs $srctree/$d"
0030         done
0031 fi
0032 all_dirs="$all_dirs $dir_list"
0033 
0034 # include/generated/compile.h is ignored because it is touched even when none
0035 # of the source files changed.
0036 #
0037 # When Kconfig regenerates include/generated/autoconf.h, its timestamp is
0038 # updated, but the contents might be still the same. When any CONFIG option is
0039 # changed, Kconfig touches the corresponding timestamp file include/config/*.
0040 # Hence, the md5sum detects the configuration change anyway. We do not need to
0041 # check include/generated/autoconf.h explicitly.
0042 #
0043 # Ignore them for md5 calculation to avoid pointless regeneration.
0044 headers_md5="$(find $all_dirs -name "*.h"                       |
0045                 grep -v "include/generated/compile.h"   |
0046                 grep -v "include/generated/autoconf.h"  |
0047                 xargs ls -l | md5sum | cut -d ' ' -f1)"
0048 
0049 # Any changes to this script will also cause a rebuild of the archive.
0050 this_file_md5="$(ls -l $sfile | md5sum | cut -d ' ' -f1)"
0051 if [ -f $tarfile ]; then tarfile_md5="$(md5sum $tarfile | cut -d ' ' -f1)"; fi
0052 if [ -f kernel/kheaders.md5 ] &&
0053         [ "$(head -n 1 kernel/kheaders.md5)" = "$headers_md5" ] &&
0054         [ "$(head -n 2 kernel/kheaders.md5 | tail -n 1)" = "$this_file_md5" ] &&
0055         [ "$(tail -n 1 kernel/kheaders.md5)" = "$tarfile_md5" ]; then
0056                 exit
0057 fi
0058 
0059 echo "  GEN     $tarfile"
0060 
0061 rm -rf $cpio_dir
0062 mkdir $cpio_dir
0063 
0064 if [ "$building_out_of_srctree" ]; then
0065         (
0066                 cd $srctree
0067                 for f in $dir_list
0068                         do find "$f" -name "*.h";
0069                 done | cpio --quiet -pd $cpio_dir
0070         )
0071 fi
0072 
0073 # The second CPIO can complain if files already exist which can happen with out
0074 # of tree builds having stale headers in srctree. Just silence CPIO for now.
0075 for f in $dir_list;
0076         do find "$f" -name "*.h";
0077 done | cpio --quiet -pdu $cpio_dir >/dev/null 2>&1
0078 
0079 # Remove comments except SDPX lines
0080 find $cpio_dir -type f -print0 |
0081         xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
0082 
0083 # Create archive and try to normalize metadata for reproducibility.
0084 # For compatibility with older versions of tar, files are fed to tar
0085 # pre-sorted, as --sort=name might not be available.
0086 find $cpio_dir -printf "./%P\n" | LC_ALL=C sort | \
0087     tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \
0088     --owner=0 --group=0 --numeric-owner --no-recursion \
0089     -I $XZ -cf $tarfile -C $cpio_dir/ -T - > /dev/null
0090 
0091 echo $headers_md5 > kernel/kheaders.md5
0092 echo "$this_file_md5" >> kernel/kheaders.md5
0093 echo "$(md5sum $tarfile | cut -d ' ' -f1)" >> kernel/kheaders.md5
0094 
0095 rm -rf $cpio_dir