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. CC=$5
  8. vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
  9. # If compile.h exists already and we don't own autoconf.h
  10. # (i.e. we're not the same user who did make *config), don't
  11. # modify compile.h
  12. # So "sudo make install" won't change the "compiled by <user>"
  13. # do "compiled by root"
  14. if [ -r $TARGET -a ! -O include/generated/autoconf.h ]; then
  15. vecho " SKIPPED $TARGET"
  16. exit 0
  17. fi
  18. # Do not expand names
  19. set -f
  20. # Fix the language to get consistent output
  21. LC_ALL=C
  22. export LC_ALL
  23. if [ -z "$KBUILD_BUILD_VERSION" ]; then
  24. VERSION=$(cat .version 2>/dev/null || echo 1)
  25. else
  26. VERSION=$KBUILD_BUILD_VERSION
  27. fi
  28. if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
  29. TIMESTAMP=`date`
  30. else
  31. TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
  32. fi
  33. if test -z "$KBUILD_BUILD_USER"; then
  34. LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
  35. else
  36. LINUX_COMPILE_BY=$KBUILD_BUILD_USER
  37. fi
  38. if test -z "$KBUILD_BUILD_HOST"; then
  39. LINUX_COMPILE_HOST=`hostname`
  40. else
  41. LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
  42. fi
  43. UTS_VERSION="#$VERSION"
  44. CONFIG_FLAGS=""
  45. if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  46. if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
  47. UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
  48. # Truncate to maximum length
  49. UTS_LEN=64
  50. UTS_TRUNCATE="cut -b -$UTS_LEN"
  51. # Generate a temporary compile.h
  52. ( echo /\* This file is auto generated, version $VERSION \*/
  53. if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
  54. echo \#define UTS_MACHINE \"$ARCH\"
  55. echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\"
  56. echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\"
  57. echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\"
  58. echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\"
  59. ) > .tmpcompile
  60. # Only replace the real compile.h if the new one is different,
  61. # in order to preserve the timestamp and avoid unnecessary
  62. # recompilations.
  63. # We don't consider the file changed if only the date/time changed.
  64. # A kernel config change will increase the generation number, thus
  65. # causing compile.h to be updated (including date/time) due to the
  66. # changed comment in the
  67. # first line.
  68. if [ -r $TARGET ] && \
  69. grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \
  70. grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \
  71. cmp -s .tmpver.1 .tmpver.2; then
  72. rm -f .tmpcompile
  73. else
  74. vecho " UPD $TARGET"
  75. mv -f .tmpcompile $TARGET
  76. fi
  77. rm -f .tmpver.1 .tmpver.2