mkcompile_h 2.8 KB

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