mkcompile_h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. domain=`dnsdomainname 2> /dev/null`
  54. elif [ -x /bin/domainname ]; then
  55. domain=`domainname 2> /dev/null`
  56. fi
  57. if [ -n "$domain" ]; then
  58. echo \#define LINUX_COMPILE_DOMAIN \"`echo $domain | $UTS_TRUNCATE`\"
  59. else
  60. echo \#define LINUX_COMPILE_DOMAIN
  61. fi
  62. echo \#define LINUX_COMPILER \"`$CC -v 2>&1 | tail -n 1`\"
  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\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \
  74. grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .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