1#!/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# Sanitize and copy uclibc headers
36(
37# We must cd, or else we will prepend "${srcdir}" to filenames!
38cd "${srcdir}" || exit 1
39find . ! -name '.' -a ! -path '*/.*' | sed -e 's/^\.\///' -e '/^config\//d' \
40	-e '/^config$/d'
41) | \
42(
43IFS=''
44while read -r filename; do
45	if test -d "${srcdir}/$filename"; then
46		mkdir -p "${dstdir}/$filename" 2>/dev/null
47		continue
48	fi
49	if test x"${filename##libc-*.h}" = x""; then
50		# Do not install libc-XXXX.h files
51		continue
52	fi
53	# Do not abort the script if unifdef "fails"!
54	# NB2: careful with sed command arguments, they contain tab character
55	"$top_builddir/extra/scripts/unifdef" \
56		-B \
57		-t \
58		-x 2 \
59		-f "$top_builddir/include/generated/unifdef_config.h" \
60		-U_LIBC \
61		-U__UCLIBC_GEN_LOCALE \
62		-U__NO_CTYPE \
63		"${srcdir}/$filename" \
64	| sed -e '/^rtld_hidden_proto[ 	]*([a-zA-Z0-9_]*)$/d' \
65	| sed -e '/^lib\(c\|m\|resolv\|dl\|intl\|rt\|nsl\|util\|crypt\|pthread\)_hidden_proto[ 	]*([a-zA-Z0-9_]*)$/d' \
66	> "${dstdir}/$filename"
67done
68)
69
70
71# Fix mode/owner bits
72cd "${dstdir}" || exit 1
73chmod -R u=rwX,go=rX . >/dev/null 2>&1
74chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1
75
76# ignore errors on unrelated files
77exit 0
78