mkcompile_h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #!/bin/sh
  2. TARGET=$1
  3. ARCH=$2
  4. SMP=$3
  5. PREEMPT=$4
  6. CC=$5
  7. vecho() { [ "${quiet}" = "silent_" ] || echo "$@" ; }
  8. # If compile.h exists already and we don't own autoconf.h
  9. # (i.e. we're not the same user who did make *config), don't
  10. # modify compile.h
  11. # So "sudo make install" won't change the "compiled by <user>"
  12. # do "compiled by root"
  13. if [ -r $TARGET -a ! -O include/generated/autoconf.h ]; then
  14. vecho " SKIPPED $TARGET"
  15. exit 0
  16. fi
  17. # Do not expand names
  18. set -f
  19. # Fix the language to get consistent output
  20. LC_ALL=C
  21. export LC_ALL
  22. if [ -z "$KBUILD_BUILD_VERSION" ]; then
  23. if [ -r .version ]; then
  24. VERSION=`cat .version`
  25. else
  26. VERSION=0
  27. echo 0 > .version
  28. fi
  29. else
  30. VERSION=$KBUILD_BUILD_VERSION
  31. fi
  32. if [ -z "$KBUILD_BUILD_TIMESTAMP" ]; then
  33. TIMESTAMP=`date`
  34. else
  35. TIMESTAMP=$KBUILD_BUILD_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 '`\"
  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