blob: 14d64dc9de52ab32513b7cdcf5694f3dcc17a88f [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001#!/bin/sh
2# Parameters:
3# $1 = source dir
4# $2 = dst dir
5# $top_builddir = well you guessed it
6
7srcdir=${1:-include}
8dstdir=${2:-`. ./.config 2>/dev/null && echo ${DEVEL_PREFIX}/include`}
9: ${top_builddir:=.}
10
11die_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
22umask 022
23
24
25# Sanity tests
26die_if_not_dir "${srcdir}"
27mkdir -p "${dstdir}" 2>/dev/null
28die_if_not_dir "${dstdir}"
29die_if_not_dir "$top_builddir"
30if ! test -x "$top_builddir/extra/scripts/unifdef"; then
31 echo "Error: need '$top_builddir/extra/scripts/unifdef' executable"
32 exit 1
33fi
34
35
36# Sanitize and copy uclibc headers
37(
38# We must cd, or else we'll prepend "${srcdir}" to filenames!
39cd "${srcdir}" || exit 1
40find . ! -name '.' -a ! -path '*/.*' | sed -e 's/^\.\///' -e '/^config\//d' \
41 -e '/^config$/d'
42) | \
43(
44IFS=''
45while 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"
66done
67)
68
69
70# Fix mode/owner bits
71cd "${dstdir}" || exit 1
72chmod -R u=rwX,go=rX . >/dev/null 2>&1
73chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1
74
75# ignore errors on unrelated files
76exit 0