mkcompile_h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. TARGET=$1
  4. ARCH=$2
  5. SMP=$3
  6. PREEMPT=$4
  7. PREEMPT_RT=$5
  8. CC_VERSION="$6"
  9. LD=$7
  10. vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
  11. # Do not expand names
  12. set -f
  13. # Fix the language to get consistent output
  14. LC_ALL=C
  15. export LC_ALL
  16. if [ -z "$KBUILD_BUILD_VERSION" ]; then
  17. VERSION=$(cat .version 2>/dev/null || echo 1)
  18. else
  19. VERSION=$KBUILD_BUILD_VERSION
  20. fi
  21. if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
  22. TIMESTAMP=`date`
  23. else
  24. TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
  25. fi
  26. if test -z "$KBUILD_BUILD_USER"; then
  27. LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
  28. else
  29. LINUX_COMPILE_BY=$KBUILD_BUILD_USER
  30. fi
  31. if test -z "$KBUILD_BUILD_HOST"; then
  32. LINUX_COMPILE_HOST=`uname -n`
  33. else
  34. LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
  35. fi
  36. UTS_VERSION="#$VERSION"
  37. CONFIG_FLAGS=""
  38. if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  39. if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
  40. if [ -n "$PREEMPT_RT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT_RT"; fi
  41. # Truncate to maximum length
  42. UTS_LEN=64
  43. UTS_VERSION="$(echo $UTS_VERSION $CONFIG_FLAGS $TIMESTAMP | cut -b -$UTS_LEN)"
  44. # Generate a temporary compile.h
  45. { echo /\* This file is auto generated, version $VERSION \*/
  46. if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
  47. echo \#define UTS_MACHINE \"$ARCH\"
  48. echo \#define UTS_VERSION \"$UTS_VERSION\"
  49. printf '#define LINUX_COMPILE_BY "%s"\n' "$LINUX_COMPILE_BY"
  50. echo \#define LINUX_COMPILE_HOST \"$LINUX_COMPILE_HOST\"
  51. LD_VERSION=$($LD -v | head -n1 | sed 's/(compatible with [^)]*)//' \
  52. | sed 's/[[:space:]]*$//')
  53. printf '#define LINUX_COMPILER "%s"\n' "$CC_VERSION, $LD_VERSION"
  54. } > .tmpcompile
  55. # Only replace the real compile.h if the new one is different,
  56. # in order to preserve the timestamp and avoid unnecessary
  57. # recompilations.
  58. # We don't consider the file changed if only the date/time changed,
  59. # unless KBUILD_BUILD_TIMESTAMP was explicitly set (e.g. for
  60. # reproducible builds with that value referring to a commit timestamp).
  61. # A kernel config change will increase the generation number, thus
  62. # causing compile.h to be updated (including date/time) due to the
  63. # changed comment in the
  64. # first line.
  65. if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
  66. IGNORE_PATTERN="UTS_VERSION"
  67. else
  68. IGNORE_PATTERN="NOT_A_PATTERN_TO_BE_MATCHED"
  69. fi
  70. if [ -r $TARGET ] && \
  71. grep -v $IGNORE_PATTERN $TARGET > .tmpver.1 && \
  72. grep -v $IGNORE_PATTERN .tmpcompile > .tmpver.2 && \
  73. cmp -s .tmpver.1 .tmpver.2; then
  74. rm -f .tmpcompile
  75. else
  76. vecho " UPD $TARGET"
  77. mv -f .tmpcompile $TARGET
  78. fi
  79. rm -f .tmpver.1 .tmpver.2