install_headers.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. -UUCLIBC_INTERNAL \
  49. -U_LIBC \
  50. -U__UCLIBC_GEN_LOCALE \
  51. -U__NO_CTYPE \
  52. "$1/$filename" \
  53. | sed -e '/^rtld_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  54. | sed -e '/^lib\(c\|m\|resolv\|dl\|intl\|rt\|nsl\|util\|crypt\|pthread\)_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  55. >"$2/$filename"
  56. done
  57. )
  58. # Fix mode/owner bits
  59. cd "$2" || exit 1
  60. chmod -R u=rwX,go=rX . >/dev/null 2>&1
  61. chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1