install_headers.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/bin/sh
  2. # Parameters:
  3. # $1 = source dir
  4. # $2 = dst dir
  5. # $top_builddir = well you guessed it
  6. srcdir=${1:-include}
  7. dstdir=${2:-`. ./.config 2>/dev/null && echo ${DEVEL_PREFIX}/include`}
  8. : ${top_builddir:=.}
  9. die_if_not_dir()
  10. {
  11. for dir in "$@"; do
  12. test -d "$dir" && continue
  13. echo "Error: '$dir' is not a directory"
  14. exit 1
  15. done
  16. }
  17. # Ensure that created dirs/files have 755/644 perms
  18. umask 022
  19. # Sanity tests
  20. die_if_not_dir "${srcdir}"
  21. mkdir -p "${dstdir}" 2>/dev/null
  22. die_if_not_dir "${dstdir}"
  23. die_if_not_dir "$top_builddir"
  24. if ! test -x "$top_builddir/extra/scripts/unifdef"; then
  25. echo "Error: need '$top_builddir/extra/scripts/unifdef' executable"
  26. exit 1
  27. fi
  28. # Sanitize and copy uclibc headers
  29. (
  30. # We must cd, or else we'll prepend "${srcdir}" to filenames!
  31. cd "${srcdir}" || exit 1
  32. find . ! -name '.' -a ! -path '*/.*' | sed -e 's/^\.\///' -e '/^config\//d' \
  33. -e '/^config$/d'
  34. ) | \
  35. (
  36. IFS=''
  37. while read -r filename; do
  38. if test -d "${srcdir}/$filename"; then
  39. mkdir -p "${dstdir}/$filename" 2>/dev/null
  40. continue
  41. fi
  42. if test x"${filename##libc-*.h}" = x""; then
  43. # Do not install libc-XXXX.h files
  44. continue
  45. fi
  46. # NB: unifdef exits with 1 if output is not
  47. # exactly the same as input. That's ok.
  48. # Do not abort the script if unifdef "fails"!
  49. # NB2: careful with sed command arguments, they contain tab character
  50. "$top_builddir/extra/scripts/unifdef" \
  51. -U_LIBC \
  52. -U__UCLIBC_GEN_LOCALE \
  53. -U__NO_CTYPE \
  54. "${srcdir}/$filename" \
  55. | sed -e '/^rtld_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  56. | sed -e '/^lib\(c\|m\|resolv\|dl\|intl\|rt\|nsl\|util\|crypt\|pthread\)_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  57. >"${dstdir}/$filename"
  58. done
  59. )
  60. # Fix mode/owner bits
  61. cd "${dstdir}" || exit 1
  62. chmod -R u=rwX,go=rX . >/dev/null 2>&1
  63. chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1
  64. # ignore errors on unrelated files
  65. exit 0