Imported Debian patch 4.2.2-2-0ubuntu1
[deb_android-headers.git] / debian / extract-headers.sh
CommitLineData
aa41282e
RSA
1#! /bin/sh
2#
3# Original script available in the libhybris project:
4# https://github.com/libhybris/libhybris/blob/master/utils/extract-headers.sh
5#
6
7ANDROID_ROOT=$1
8HEADERPATH=$2
9MAJOR=$3
10MINOR=$4
11
12PATCH=$5
13PATCH2=$6
14PATCH3=$7
15
16if [ x$ANDROID_ROOT = x -o "x$HEADERPATH" = x ]; then
17 echo "Syntax: extract-headers.sh ANDROID_ROOT HEADERPATH [MAJOR] [MINOR] [PATCH] [PATCH2] [PATCH3]"
18 exit 1
19fi
20
21
22if [ x$MAJOR = x -o x$MINOR = x -o x$PATCH = x ]; then
23 VERSION_DEFAULTS=$ANDROID_ROOT/build/core/version_defaults.mk
24
25 parse_defaults_failed() {
26 echo "Error: Cannot read PLATFORM_VERSION from ${VERSION_DEFAULTS}."
27 echo "Please specify MAJOR, MINOR and PATCH manually to continue."
28 exit 1
29 }
30
31 if [ ! -f $VERSION_DEFAULTS ]; then
32 parse_defaults_failed
33 fi
34
35 PLATFORM_VERSION=$(egrep -o "PLATFORM_VERSION := [0-9.]+" $VERSION_DEFAULTS | awk '{ print $3 }')
36 if [ x$PLATFORM_VERSION = x ]; then
37 parse_defaults_failed
38 fi
39
40 MAJOR=$(echo $PLATFORM_VERSION | cut -d. -f1)
41 MINOR=$(echo $PLATFORM_VERSION | cut -d. -f2)
42 PATCH=$(echo $PLATFORM_VERSION | cut -d. -f3)
43 PATCH2=$(echo $PLATFORM_VERSION | cut -d. -f4)
44 PATCH3=$(echo $PLATFORM_VERSION | cut -d. -f5)
45
46 if [ x$MAJOR = x -o x$MINOR = x -o x$PATCH = x ]; then
47 parse_defaults_failed
48 fi
49
50 echo -n "Auto-detected version: ${MAJOR}.${MINOR}.${PATCH}"
51 if [ x$PATCH3 != x ]; then
52 echo ".${PATCH2}.${PATCH3}"
53 elif [ x$PATCH2 != x ]; then
54 echo ".${PATCH2}"
55 else
56 echo ""
57 fi
58fi
59
60# Make sure that the dir given contains at least some of the assumed structures.
61if [ ! -d "$ANDROID_ROOT/hardware/libhardware/include/hardware/" ]; then
62 echo "Given Android root dir '$ANDROID_ROOT/hardware/libhardware/include/hardware/' doesn't exist."
63 exit 1
64fi
65
66mkdir -p $HEADERPATH
67
68if [ x$PATCH2 = x ]; then
69 PATCH2=0
70fi
71
72if [ x$PATCH3 = x ]; then
73 PATCH3=0
74fi
75
76cat > $HEADERPATH/android-version.h << EOF
77#ifndef ANDROID_VERSION_H_
78#define ANDROID_VERSION_H_
79
80#define ANDROID_VERSION_MAJOR $MAJOR
81#define ANDROID_VERSION_MINOR $MINOR
82#define ANDROID_VERSION_PATCH $PATCH
83#define ANDROID_VERSION_PATCH2 $PATCH2
84#define ANDROID_VERSION_PATCH3 $PATCH3
85
86#endif
87EOF
88
89mkdir -p $HEADERPATH/hardware/
90cp $ANDROID_ROOT/hardware/libhardware/include/hardware/* $HEADERPATH/hardware/
91
92mkdir -p $HEADERPATH/hardware_legacy/
93cp $ANDROID_ROOT/hardware/libhardware_legacy/include/hardware_legacy/audio_policy_conf.h $HEADERPATH/hardware_legacy/
94
95mkdir -p $HEADERPATH/cutils/
96cp $ANDROID_ROOT/system/core/include/cutils/* $HEADERPATH/cutils/
97
98mkdir -p $HEADERPATH/system/
99cp $ANDROID_ROOT/system/core/include/system/* $HEADERPATH/system/
100
101mkdir -p $HEADERPATH/android/
102cp $ANDROID_ROOT/system/core/include/android/* $HEADERPATH/android/
103
104if [ -e $ANDROID_ROOT/external/kernel-headers/original/linux/sync.h ]; then
105 mkdir -p $HEADERPATH/linux
106 cp $ANDROID_ROOT/external/kernel-headers/original/linux/sync.h $HEADERPATH/linux
107 cp $ANDROID_ROOT/external/kernel-headers/original/linux/sw_sync.h $HEADERPATH/linux
108fi
109
110if [ -e $ANDROID_ROOT/system/core/include/sync/sync.h ]; then
111 mkdir -p $HEADERPATH/sync/
112 cp $ANDROID_ROOT/system/core/include/sync/* $HEADERPATH/sync/
113fi
114
115if [ -e $ANDROID_ROOT/external/libnfc-nxp/inc/phNfcConfig.h ]; then
116 mkdir -p $HEADERPATH/libnfc-nxp/
117 cp $ANDROID_ROOT/external/libnfc-nxp/inc/*.h $HEADERPATH/libnfc-nxp/
118 cp $ANDROID_ROOT/external/libnfc-nxp/src/*.h $HEADERPATH/libnfc-nxp/
119fi
120
121mkdir -p $HEADERPATH/private
122cp $ANDROID_ROOT/system/core/include/private/android_filesystem_config.h $HEADERPATH/private
123
124exit 0