install_headers.sh 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. for dir in "$@"; do
  9. test -d "$dir" && continue
  10. echo "Error: '$dir' is not a directory"
  11. exit 1
  12. done
  13. }
  14. # Ensure that created dirs/files have 755/644 perms
  15. umask 022
  16. # Sanity tests
  17. die_if_not_dir "$1"
  18. mkdir -p "$2" 2>/dev/null
  19. die_if_not_dir "$2"
  20. die_if_not_dir "$top_builddir"
  21. if ! test -x "$top_builddir/extra/scripts/unifdef"; then
  22. echo "Error: need '$top_builddir/extra/scripts/unifdef' executable"
  23. exit 1
  24. fi
  25. # Sanitize and copy uclibc headers
  26. (
  27. # We must cd, or else we'll prepend "$1" to filenames!
  28. cd "$1" || exit 1
  29. find ! -name '.' -a ! -path '*/.*'
  30. ) | \
  31. (
  32. IFS=''
  33. while read -r filename; do
  34. filename="${filename#./}"
  35. if test -d "$1/$filename"; then
  36. mkdir -p "$2/$filename" 2>/dev/null
  37. else
  38. # NB: unifdef exits with 1 if output is not
  39. # exactly the same as input. That's ok.
  40. # Do not abort the script if unifdef "fails"!
  41. "$top_builddir/extra/scripts/unifdef" -UUCLIBC_INTERNAL "$1/$filename" >"$2/$filename"
  42. fi
  43. done
  44. )
  45. # Just copy (no sanitization) some kernel headers.
  46. eval `grep ^KERNEL_HEADERS "$top_builddir/.config"`
  47. if ! test "$KERNEL_HEADERS" \
  48. || ! test -d "$KERNEL_HEADERS/asm" \
  49. || ! test -d "$KERNEL_HEADERS/asm-generic" \
  50. || ! test -d "$KERNEL_HEADERS/linux" \
  51. ; then
  52. echo "Error: '$KERNEL_HEADERS' is not a directory containing kernel headers."
  53. echo "Check KERNEL_HEADERS= in your .config file."
  54. exit 1
  55. fi
  56. # Do the copying only if src and dst dirs are not the same.
  57. # Be thorough: do not settle just for textual compare,
  58. # and guard against "pwd" being handled as shell builtin.
  59. # Double quoting looks weird, but it works (even bbox ash too).
  60. if test "`(cd "$KERNEL_HEADERS"; env pwd)`" != "`(cd "$2"; env pwd)`"; then
  61. # NB: source or target files and directories may be symlinks,
  62. # and for all we know, good reasons.
  63. # We must work correctly in these cases. This includes "do not replace
  64. # target symlink with real directory" rule. So, no rm -rf here please.
  65. mkdir -p "$2/asm" 2>/dev/null
  66. mkdir -p "$2/asm-generic" 2>/dev/null
  67. mkdir -p "$2/linux" 2>/dev/null
  68. # Exists, but is not a dir? That's bad, bail out
  69. die_if_not_dir "$2/asm" "$2/asm-generic" "$2/linux"
  70. # cp -HL creates regular destination files even if sources are symlinks.
  71. # This is intended.
  72. # (NB: you need busybox 1.11.x for this. earlier ones are slightly buggy)
  73. cp -RHL "$KERNEL_HEADERS/asm"/* "$2/asm" || exit 1
  74. cp -RHL "$KERNEL_HEADERS/asm-generic"/* "$2/asm-generic" || exit 1
  75. cp -RHL "$KERNEL_HEADERS/linux"/* "$2/linux" || exit 1
  76. if ! test -f "$2/linux/version.h"; then
  77. echo "Warning: '$KERNEL_HEADERS/linux/version.h' is not found"
  78. echo "in kernel headers directory specified in .config."
  79. echo "Some programs won't like that. Consider fixing it by hand."
  80. fi
  81. fi
  82. # Fix mode/owner bits
  83. cd "$2" || exit 1
  84. chmod -R u=rwX,go=rX . >/dev/null 2>&1
  85. chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1