mkcompile_h 2.5 KB

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