Imported Debian patch 0.1.0+git20131207+e452e83-0ubuntu12
[deb_libhybris.git] / utils / extract-headers.sh
1 #! /bin/sh
2
3 ANDROID_ROOT=$1
4 HEADERPATH=$2
5 MAJOR=$3
6 MINOR=$4
7
8 PATCH=$5
9 PATCH2=$6
10 PATCH3=$7
11
12 if [ x$ANDROID_ROOT = x -o "x$HEADERPATH" = x ]; then
13 echo "Syntax: extract-headers.sh ANDROID_ROOT HEADERPATH [MAJOR] [MINOR] [PATCH] [PATCH2] [PATCH3]"
14 exit 1
15 fi
16
17
18 if [ x$MAJOR = x -o x$MINOR = x -o x$PATCH = x ]; then
19 VERSION_DEFAULTS=$ANDROID_ROOT/build/core/version_defaults.mk
20
21 parse_defaults_failed() {
22 echo "Error: Cannot read PLATFORM_VERSION from ${VERSION_DEFAULTS}."
23 echo "Please specify MAJOR, MINOR and PATCH manually to continue."
24 exit 1
25 }
26
27 if [ ! -f $VERSION_DEFAULTS ]; then
28 parse_defaults_failed
29 fi
30
31 PLATFORM_VERSION=$(egrep -o "PLATFORM_VERSION := [0-9.]+" $VERSION_DEFAULTS | awk '{ print $3 }')
32 if [ x$PLATFORM_VERSION = x ]; then
33 parse_defaults_failed
34 fi
35
36 MAJOR=$(echo $PLATFORM_VERSION | cut -d. -f1)
37 MINOR=$(echo $PLATFORM_VERSION | cut -d. -f2)
38 PATCH=$(echo $PLATFORM_VERSION | cut -d. -f3)
39 PATCH2=$(echo $PLATFORM_VERSION | cut -d. -f4)
40 PATCH3=$(echo $PLATFORM_VERSION | cut -d. -f5)
41
42 if [ x$MAJOR = x -o x$MINOR = x -o x$PATCH = x ]; then
43 parse_defaults_failed
44 fi
45
46 echo -n "Auto-detected version: ${MAJOR}.${MINOR}.${PATCH}"
47 if [ x$PATCH3 != x ]; then
48 echo ".${PATCH2}.${PATCH3}"
49 elif [ x$PATCH2 != x ]; then
50 echo ".${PATCH2}"
51 else
52 echo ""
53 fi
54 fi
55
56 require_sources() {
57 # require_sources [FILE|DIR] ...
58 # Check if the given paths exist in the Android source
59 while [ $# -gt 0 ]; do
60 SOURCE_PATH=$ANDROID_ROOT/$1
61 shift
62
63 if [ ! -e "$SOURCE_PATH" ]; then
64 echo "Cannot extract headers: '$SOURCE_PATH' does not exist."
65 exit 1
66 fi
67 done
68 }
69
70 extract_headers_to() {
71 # extract_headers_to <TARGET> [FILE|DIR] ...
72 # For each FILE argument, copy it to TARGET
73 # For each DIR argument, copy all its contents to TARGET
74 TARGET_DIRECTORY=$HEADERPATH/$1
75 if [ ! -d "$TARGET_DIRECTORY" ]; then
76 mkdir -p "$TARGET_DIRECTORY"
77 fi
78 echo " $1"
79 shift
80
81 while [ $# -gt 0 ]; do
82 SOURCE_PATH=$ANDROID_ROOT/$1
83 if [ -d $SOURCE_PATH ]; then
84 for file in $SOURCE_PATH/*; do
85 echo " $1/$(basename $file)"
86 cp $file $TARGET_DIRECTORY/
87 done
88 else
89 echo " $1"
90 cp $SOURCE_PATH $TARGET_DIRECTORY/
91 fi
92 shift
93 done
94 }
95
96 check_header_exists() {
97 # check_header_exists <FILENAME>
98 HEADER_FILE=$ANDROID_ROOT/$1
99 if [ ! -e "$HEADER_FILE" ]; then
100 return 1
101 fi
102
103 return 0
104 }
105
106
107 # Make sure that the dir given contains at least some of the assumed structures.
108 require_sources \
109 hardware/libhardware/include/hardware
110
111 mkdir -p $HEADERPATH
112
113 if [ x$PATCH2 = x ]; then
114 PATCH2=0
115 fi
116
117 if [ x$PATCH3 = x ]; then
118 PATCH3=0
119 fi
120
121 cat > $HEADERPATH/android-version.h << EOF
122 #ifndef ANDROID_VERSION_H_
123 #define ANDROID_VERSION_H_
124
125 #define ANDROID_VERSION_MAJOR $MAJOR
126 #define ANDROID_VERSION_MINOR $MINOR
127 #define ANDROID_VERSION_PATCH $PATCH
128 #define ANDROID_VERSION_PATCH2 $PATCH2
129 #define ANDROID_VERSION_PATCH3 $PATCH3
130
131 #endif
132 EOF
133
134 extract_headers_to hardware \
135 hardware/libhardware/include/hardware
136
137 extract_headers_to hardware_legacy \
138 hardware/libhardware_legacy/include/hardware_legacy/audio_policy_conf.h
139
140 extract_headers_to cutils \
141 system/core/include/cutils
142
143 extract_headers_to system \
144 system/core/include/system
145
146 extract_headers_to android \
147 system/core/include/android
148
149 check_header_exists external/kernel-headers/original/linux/sync.h && \
150 extract_headers_to linux \
151 external/kernel-headers/original/linux/sync.h \
152 external/kernel-headers/original/linux/sw_sync.h
153
154 check_header_exists system/core/include/sync/sync.h && \
155 extract_headers_to sync \
156 system/core/include/sync
157
158 check_header_exists external/libnfc-nxp/inc/phNfcConfig.h && \
159 extract_headers_to libnfc-nxp \
160 external/libnfc-nxp/inc \
161 external/libnfc-nxp/src
162
163 extract_headers_to private \
164 system/core/include/private/android_filesystem_config.h
165
166
167 # In order to make it easier to trace back the origins of headers, fetch
168 # some repository information from the Git source tree (if available).
169 # Tested with AOSP and CM.
170 NOW=$(LC_ALL=C date)
171
172 # Add here all sub-projects of AOSP/CM from which headers are extracted
173 GIT_PROJECTS="
174 hardware/libhardware
175 hardware/libhardware_legacy
176 system/core
177 external/kernel-headers
178 external/libnfc-nxp
179 "
180
181 echo "Extracting Git revision information"
182 rm -f $HEADERPATH/SOURCE_GIT_REVISION_INFO
183 (for GIT_PROJECT in $GIT_PROJECTS; do
184 TARGET_DIR=$ANDROID_ROOT/$GIT_PROJECT
185 echo "================================================"
186 echo "$GIT_PROJECT @ $NOW"
187 echo "================================================"
188 if [ -e $TARGET_DIR/.git ]; then
189 (
190 set -x
191 cd $ANDROID_ROOT
192 repo status $GIT_PROJECT
193 cd $TARGET_DIR
194 git show-ref --head
195 git remote -v
196 )
197 echo ""
198 echo ""
199 else
200 echo "WARNING: $GIT_PROJECT does not contain a Git repository"
201 fi
202 done) > $HEADERPATH/git-revisions.txt 2>&1
203
204 # Repo manifest that can be used to fetch the sources for re-extracting headers
205 if [ -e $ANDROID_ROOT/.repo/manifest.xml ]; then
206 cp $ANDROID_ROOT/.repo/manifest.xml $HEADERPATH/
207 fi
208
209 exit 0