install_headers.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. -B \
  52. -t \
  53. -f "$top_builddir/include/generated/unifdef_config.h" \
  54. -U_LIBC \
  55. -U__UCLIBC_GEN_LOCALE \
  56. -U__NO_CTYPE \
  57. "${srcdir}/$filename" \
  58. | sed -e '/^rtld_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  59. | sed -e '/^lib\(c\|m\|resolv\|dl\|intl\|rt\|nsl\|util\|crypt\|pthread\)_hidden_proto[ ]*([a-zA-Z0-9_]*)$/d' \
  60. >"${dstdir}/$filename"
  61. done
  62. )
  63. # Fix mode/owner bits
  64. cd "${dstdir}" || exit 1
  65. chmod -R u=rwX,go=rX . >/dev/null 2>&1
  66. chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1
  67. # ignore errors on unrelated files
  68. exit 0