install_headers.sh 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. 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" \
  42. | sed -e '/^\(rtld\|lib\(c\|m\|resolv\|dl\|intl\|rt\|nsl\|util\|crypt\|pthread\)\)_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' >"$2/$filename"
  43. fi
  44. done
  45. )
  46. # Fix mode/owner bits
  47. cd "$2" || exit 1
  48. chmod -R u=rwX,go=rX . >/dev/null 2>&1
  49. chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1