mkcompile_h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. if [ -r .version ]; then
  18. VERSION=`cat .version`
  19. else
  20. VERSION=0
  21. echo 0 > .version
  22. fi
  23. UTS_VERSION="#$VERSION"
  24. CONFIG_FLAGS=""
  25. if [ -n "$SMP" ] ; then CONFIG_FLAGS="SMP"; fi
  26. if [ -n "$PREEMPT" ] ; then CONFIG_FLAGS="$CONFIG_FLAGS PREEMPT"; fi
  27. UTS_VERSION="$UTS_VERSION $CONFIG_FLAGS `LC_ALL=C LANG=C date`"
  28. # Truncate to maximum length
  29. UTS_LEN=64
  30. UTS_TRUNCATE="sed -e s/\(.\{1,$UTS_LEN\}\).*/\1/"
  31. # Generate a temporary compile.h
  32. ( echo /\* This file is auto generated, version $VERSION \*/
  33. if [ -n "$CONFIG_FLAGS" ] ; then echo "/* $CONFIG_FLAGS */"; fi
  34. echo \#define UTS_MACHINE \"$ARCH\"
  35. echo \#define UTS_VERSION \"`echo $UTS_VERSION | $UTS_TRUNCATE`\"
  36. echo \#define LINUX_COMPILE_TIME \"`LC_ALL=C LANG=C date +%T`\"
  37. echo \#define LINUX_COMPILE_BY \"`whoami`\"
  38. echo \#define LINUX_COMPILE_HOST \"`hostname | $UTS_TRUNCATE`\"
  39. if [ -x /bin/dnsdomainname ]; then
  40. echo \#define LINUX_COMPILE_DOMAIN \"`dnsdomainname | $UTS_TRUNCATE`\"
  41. elif [ -x /bin/domainname ]; then
  42. echo \#define LINUX_COMPILE_DOMAIN \"`domainname | $UTS_TRUNCATE`\"
  43. else
  44. echo \#define LINUX_COMPILE_DOMAIN
  45. fi
  46. echo \#define LINUX_COMPILER \"`LC_ALL=C LANG=C $CC -v 2>&1 | tail -n 1`\"
  47. ) > .tmpcompile
  48. # Only replace the real compile.h if the new one is different,
  49. # in order to preserve the timestamp and avoid unnecessary
  50. # recompilations.
  51. # We don't consider the file changed if only the date/time changed.
  52. # A kernel config change will increase the generation number, thus
  53. # causing compile.h to be updated (including date/time) due to the
  54. # changed comment in the
  55. # first line.
  56. if [ -r $TARGET ] && \
  57. grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' $TARGET > .tmpver.1 && \
  58. grep -v 'UTS_VERSION\|LINUX_COMPILE_TIME' .tmpcompile > .tmpver.2 && \
  59. cmp -s .tmpver.1 .tmpver.2; then
  60. rm -f .tmpcompile
  61. else
  62. echo " UPD $TARGET"
  63. mv -f .tmpcompile $TARGET
  64. fi
  65. rm -f .tmpver.1 .tmpver.2