summaryrefslogtreecommitdiff
path: root/extra/scripts/install_headers.sh
blob: 5f57695cbba53b84fe43dc9041b2b242779f86ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#!/bin/sh
# Parameters:
# $1 = source dir
# $2 = dst dir
# $top_builddir = well you guessed it

die_if_not_dir()
{
	for dir in "$@"; do
		test -d "$dir" && continue
		echo "Error: '$dir' is not a directory"
		exit 1
	done
}


# Ensure that created dirs/files have 755/644 perms
umask 022


# Sanity tests
die_if_not_dir "$1"
mkdir -p "$2" 2>/dev/null
die_if_not_dir "$2"
die_if_not_dir "$top_builddir"
if ! test -x "$top_builddir/extra/scripts/unifdef"; then
	echo "Error: need '$top_builddir/extra/scripts/unifdef' executable"
	exit 1
fi


# Sanitize and copy uclibc headers
(
# We must cd, or else we'll prepend "$1" to filenames!
cd "$1" || exit 1
find ! -name '.' -a ! -path '*/.*'
) | \
(
IFS=''
while read -r filename; do
	filename="${filename#./}"
	if test -d "$1/$filename"; then
		mkdir -p "$2/$filename" 2>/dev/null
	else
		"$top_builddir/extra/scripts/unifdef" -UUCLIBC_INTERNAL "$1/$filename" >"$2/$filename" || exit
	fi
done
)


# Just copy (no sanitization) some kernel headers.
eval `grep ^KERNEL_HEADERS "$top_builddir/.config"`
if ! test -d "$KERNEL_HEADERS/asm" \
|| ! test -d "$KERNEL_HEADERS/asm-generic" \
|| ! test -d "$KERNEL_HEADERS/linux" \
; then
	echo "Error: '$KERNEL_HEADERS' is not a directory containing kernel headers."
	echo "Check KERNEL_HEADERS= in your .config file."
	exit 1
fi
# NB: source or target files and directories may be symlinks,
# and for all we know, good reasons.
# We must work correctly in these cases. This includes "do not replace
# target symlink with real directory" rule. So, no rm -rf here please.
mkdir -p "$2/asm"         2>/dev/null
mkdir -p "$2/asm-generic" 2>/dev/null
mkdir -p "$2/linux"       2>/dev/null
# Exists, but is not a dir? That's bad, bail out
die_if_not_dir "$2/asm" "$2/asm-generic" "$2/linux"
# cp -HL creates regular destination files even if sources are symlinks.
# This is intended.
# (NB: you need busybox 1.11.x for this. earlier ones are slightly buggy)
cp -RHL "$KERNEL_HEADERS/asm"/*         "$2/asm"         || exit 1
cp -RHL "$KERNEL_HEADERS/asm-generic"/* "$2/asm-generic" || exit 1
cp -RHL "$KERNEL_HEADERS/linux"/*       "$2/linux"       || exit 1
if ! test -f "$2/linux/version.h"; then
	echo "Warning: '$KERNEL_HEADERS/linux/version.h' is not found"
	echo "in kernel headers directory specified in .config."
	echo "Some programs won't like that. Consider fixing it by hand."
fi


# Fix mode/owner bits
cd "$2" || exit 1
chmod -R u=rwX,go=rX . >/dev/null 2>&1
chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$/\1:\2/'` . >/dev/null 2>&1