mkcompile_h 2.5 KB

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