install_headers.sh 1.6 KB

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