install_headers.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 will 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. # Do not abort the script if unifdef "fails"!
  47. # NB2: careful with sed command arguments, they contain tab character
  48. "$top_builddir/extra/scripts/unifdef" \
  49. -B \
  50. -t \
  51. -x 2 \
  52. -f "$top_builddir/include/generated/unifdef_config.h" \
  53. -U_LIBC \
  54. -U__UCLIBC_GEN_LOCALE \
  55. -U__NO_CTYPE \
  56. "${srcdir}/$filename" \
  57. | sed -e '/^rtld_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  58. | sed -e '/^lib\(c\|m\|resolv\|dl\|intl\|rt\|nsl\|util\|crypt\|pthread\)_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  59. > "${dstdir}/$filename"
  60. done
  61. )
  62. # Fix mode/owner bits
  63. cd "${dstdir}" || exit 1
  64. chmod -R u=rwX,go=rX . >/dev/null 2>&1
  65. chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1
  66. # ignore errors on unrelated files
  67. exit 0