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