install_headers.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 '*/.*' | sed -e 's/^\.\///' -e '/^config\//d' \
  30. -e '/^config$/d'
  31. ) | \
  32. (
  33. IFS=''
  34. while read -r filename; do
  35. if test -d "$1/$filename"; then
  36. mkdir -p "$2/$filename" 2>/dev/null
  37. continue
  38. fi
  39. if test x"${filename##libc-*.h}" = x""; then
  40. # Do not install libc-XXXX.h files
  41. continue
  42. fi
  43. # NB: unifdef exits with 1 if output is not
  44. # exactly the same as input. That's ok.
  45. # Do not abort the script if unifdef "fails"!
  46. # NB2: careful with sed command arguments, they contain tab character
  47. "$top_builddir/extra/scripts/unifdef" \
  48. -U_LIBC \
  49. -U__UCLIBC_GEN_LOCALE \
  50. -U__NO_CTYPE \
  51. "$1/$filename" \
  52. | sed -e '/^rtld_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  53. | sed -e '/^lib\(c\|m\|resolv\|dl\|intl\|rt\|nsl\|util\|crypt\|pthread\)_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  54. >"$2/$filename"
  55. done
  56. )
  57. # Fix mode/owner bits
  58. cd "$2" || exit 1
  59. chmod -R u=rwX,go=rX . >/dev/null 2>&1
  60. chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1