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