mkcompile_h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_VERSION_TIMESTAMP" ]; then
  29. if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
  30. TIMESTAMP=`date`
  31. else
  32. TIMESTAMP=$KBUILD_BUILD_TIMESTAMP
  33. fi
  34. else
  35. TIMESTAMP=$KBUILD_BUILD_VERSION_TIMESTAMP
  36. fi
  37. if test -z "$KBUILD_BUILD_USER"; then
  38. LINUX_COMPILE_BY=$(whoami | sed 's/\\/\\\\/')
  39. else
  40. LINUX_COMPILE_BY=$KBUILD_BUILD_USER
  41. fi
  42. if test -z "$KBUILD_BUILD_HOST"; then
  43. LINUX_COMPILE_HOST=`hostname`
  44. else
  45. LINUX_COMPILE_HOST=$KBUILD_BUILD_HOST
  46. fi
  47. UTS_VERSION="#$VERSION"
  48. CONFIG_FLAGS=""
  49. if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  50. if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
  51. UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS $TIMESTAMP"
  52. # Truncate to maximum length
  53. UTS_LEN=64
  54. UTS_TRUNCATE="cut -b -$UTS_LEN"
  55. # Generate a temporary compile.h
  56. ( echo /\* This file is auto generated, version $VERSION \*/
  57. if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
  58. echo \#define UTS_MACHINE \"$ARCH\"
  59. echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\"
  60. echo \#define LINUX_COMPILE_BY \"`echo $LINUX_COMPILE_BY | $UTS_TRUNCATE`\"
  61. echo \#define LINUX_COMPILE_HOST \"`echo $LINUX_COMPILE_HOST | $UTS_TRUNCATE`\"
  62. echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | grep ' version ' | sed 's/[[:space:]]*$//'`\"
  63. ) > .tmpcompile
  64. # Only replace the real compile.h if the new one is different,
  65. # in order to preserve the timestamp and avoid unnecessary
  66. # recompilations.
  67. # We don't consider the file changed if only the date/time changed.
  68. # A kernel config change will increase the generation number, thus
  69. # causing compile.h to be updated (including date/time) due to the
  70. # changed comment in the
  71. # first line.
  72. if [ -r $TARGET ] && \
  73. grep -v 'UTS_VERSION' $TARGET > .tmpver.1 && \
  74. grep -v 'UTS_VERSION' .tmpcompile > .tmpver.2 && \
  75. cmp -s .tmpver.1 .tmpver.2; then
  76. rm -f .tmpcompile
  77. else
  78. vecho " UPD $TARGET"
  79. mv -f .tmpcompile $TARGET
  80. fi
  81. rm -f .tmpver.1 .tmpver.2