install_kernel_headers.sh 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/sh
  2. # Parameters:
  3. # $1 = source dir
  4. # $2 = dst dir
  5. # $top_builddir = well you guessed it
  6. die_if_not_dir()
  7. {
  8. local dir
  9. for dir in "$@"; do
  10. test -d "$dir" && continue
  11. echo "Error: '$dir' is not a directory"
  12. exit 1
  13. done
  14. }
  15. # Ensure that created dirs/files have 755/644 perms
  16. umask 022
  17. # Sanity tests
  18. die_if_not_dir "$1"
  19. mkdir -p "$2" 2>/dev/null
  20. die_if_not_dir "$2"
  21. die_if_not_dir "$top_builddir"
  22. # Just copy (no sanitization) some kernel headers.
  23. eval `grep ^KERNEL_HEADERS "$top_builddir/.config"`
  24. if ! test "$KERNEL_HEADERS" \
  25. || ! test -d "$KERNEL_HEADERS/asm" \
  26. || ! test -d "$KERNEL_HEADERS/linux" \
  27. ; then
  28. echo "Error: '$KERNEL_HEADERS' is not a directory containing kernel headers."
  29. echo "Check KERNEL_HEADERS= in your .config file."
  30. exit 1
  31. fi
  32. # Do the copying only if src and dst dirs are not the same.
  33. # Be thorough: do not settle just for textual compare,
  34. # and guard against "pwd" being handled as shell builtin.
  35. # Double quoting looks weird, but it works (even bbox ash too).
  36. if test "`(cd "$KERNEL_HEADERS"; env pwd)`" != "`(cd "$2"; env pwd)`"; then
  37. # NB: source or target files and directories may be symlinks,
  38. # and for all we know, good reasons.
  39. # We must work correctly in these cases. This includes "do not replace
  40. # target symlink with real directory" rule. So, no rm -rf here please.
  41. mkdir -p "$2/asm" 2>/dev/null
  42. mkdir -p "$2/linux" 2>/dev/null
  43. # Exists, but is not a dir? That's bad, bail out
  44. die_if_not_dir "$2/asm" "$2/linux"
  45. # cp -HL creates regular destination files even if sources are symlinks.
  46. # This is intended.
  47. # (NB: you need busybox 1.11.x for this. earlier ones are slightly buggy)
  48. cp -RHL "$KERNEL_HEADERS/asm"/* "$2/asm" || exit 1
  49. cp -RHL "$KERNEL_HEADERS/linux"/* "$2/linux" || exit 1
  50. # Linux 2.4 doesn't have it
  51. if test -d "$KERNEL_HEADERS/asm-generic"; then
  52. mkdir -p "$2/asm-generic" 2>/dev/null
  53. die_if_not_dir "$2/asm-generic"
  54. cp -RHL "$KERNEL_HEADERS/asm-generic"/* "$2/asm-generic" || exit 1
  55. fi
  56. # For paranoid reasons, we use explicit list of directories
  57. # which may be found in kernel's "sanitized headers" directory after
  58. # "make defconfig; make headers_install" was run in kernel tree.
  59. # List last updated for linux-2.6.27:
  60. for dir in drm mtd rdma sound video; do
  61. if test -d "$KERNEL_HEADERS/$dir"; then
  62. mkdir -p "$2/$dir" 2>/dev/null
  63. die_if_not_dir "$2/$dir"
  64. cp -RHL "$KERNEL_HEADERS/$dir"/* "$2/$dir" || exit 1
  65. fi
  66. done
  67. if ! test -f "$2/linux/version.h"; then
  68. echo "Warning: '$KERNEL_HEADERS/linux/version.h' is not found"
  69. echo "in kernel headers directory specified in .config."
  70. echo "Some programs won't like that. Consider fixing it by hand."
  71. fi
  72. fi
  73. # Fix mode/owner bits
  74. cd "$2" || exit 1
  75. chmod -R u=rwX,go=rX . >/dev/null 2>&1
  76. chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1