mkcompile_h 2.4 KB

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