Guest User

Untitled

a guest
Oct 16th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.49 KB | None | 0 0
  1. #! /bin/sh
  2.  
  3. error() {
  4. echo "Error: $1" >&2
  5. }
  6. usage() {
  7. echo "Usage: extract-headers.sh [Options] <ANDROID_ROOT> <HEADER_PATH>"
  8. echo
  9. echo " ANDROID_ROOT: Directory containing the Android source tree."
  10. echo " HEADER_PATH: Where the headers will be extracted to."
  11. echo
  12. echo "Options:"
  13. echo " -v|--version MAJOR.MINOR.PATCH.[PATCH2].[PATCH3]]"
  14. echo " Override the Android version detected by this script"
  15. echo " -p|--pkgconfigpath <path>"
  16. echo " pkgconfig path for the headers installed location"
  17. exit 1
  18. }
  19.  
  20. ##############
  21. while [ $# -gt 0 ]; do
  22. case $1 in
  23. *-version|-v)
  24. if [ x$2 = x ]; then error "--version needs an argument"; usage; fi
  25. IFS="." read MAJOR MINOR PATCH PATCH2 PATCH3 <<EOF
  26. $2
  27. EOF
  28. echo "Using version ${MAJOR}.${MINOR}.${PATCH}.${PATCH2}.${PATCH3}"
  29. shift 2
  30. ;;
  31. *-pkgconfigpath|-p)
  32. if [ "$2" = "" ]; then error "--pkgconfigpath needs an argument"; usage; fi
  33. PKGCONFIGPATH=$2
  34. shift 2
  35. ;;
  36. *)
  37. break
  38. ;;
  39. esac
  40. done
  41.  
  42. ##############
  43. ANDROID_ROOT=$1
  44. HEADER_PATH=$2
  45.  
  46. # Required arguments
  47. [ x$ANDROID_ROOT = x ] && error "missing argument ANDROID_ROOT" && usage
  48. [ x$HEADER_PATH = x ] && error "missing argument HEADER_PATH" && usage
  49.  
  50. shift 2
  51.  
  52. # check if android source exists
  53. if [ ! -e "$ANDROID_ROOT" ]; then
  54. error "Cannot extract headers: '$ANDROID_ROOT' does not exist."
  55. exit 1
  56. fi
  57.  
  58. # In case one of the version number is missing,
  59. # try to extract if from the version_defaults.mk
  60. if [ x$MAJOR = x -o x$MINOR = x -o x$PATCH = x ]; then
  61. VERSION_DEFAULTS=$ANDROID_ROOT/build/core/version_defaults.mk
  62.  
  63. echo "not all version fields supplied: trying to extract from $VERSION_DEFAULTS"
  64. if [ ! -f $VERSION_DEFAULTS ]; then
  65. error "$VERSION_DEFAULTS not found"
  66. fi
  67.  
  68. IFS="." read MAJOR MINOR PATCH PATCH2 PATCH3 <<EOF
  69. $(IFS="." awk '/PLATFORM_VERSION := ([0-9.]+)/ { print $3; }' < $VERSION_DEFAULTS)
  70. EOF
  71. if [ x$PATCH = x ]; then
  72. PATCH=0
  73. fi
  74. if [ x$MAJOR = x -o x$MINOR = x -o x$PATCH = x ]; then
  75. error "Cannot read PLATFORM_VERSION from ${VERSION_DEFAULTS}."
  76. error "Please specify MAJOR, MINOR and PATCH manually to continue."
  77. exit 1
  78. fi
  79.  
  80. echo -n "Auto-detected version: ${MAJOR}.${MINOR}.${PATCH}";echo "${PATCH2:+.${PATCH2}}${PATCH3:+.${PATCH3}}"
  81. fi
  82.  
  83. ##############
  84. require_sources() {
  85. # require_sources [FILE|DIR] ...
  86. # Check if the given paths exist in the Android source
  87. while [ $# -gt 0 ]; do
  88. SOURCE_PATH=$ANDROID_ROOT/$1
  89. shift
  90.  
  91. if [ ! -e "$SOURCE_PATH" ]; then
  92. error "Cannot extract headers: '$SOURCE_PATH' does not exist."
  93. exit 1
  94. fi
  95. done
  96. }
  97.  
  98. extract_headers_to() {
  99. # extract_headers_to <TARGET> [FILE|DIR] ...
  100. # For each FILE argument, copy it to TARGET
  101. # For each DIR argument, copy all its contents to TARGET
  102. TARGET_DIRECTORY=$HEADER_PATH/$1
  103. if [ ! -d "$TARGET_DIRECTORY" ]; then
  104. mkdir -p "$TARGET_DIRECTORY"
  105. fi
  106. echo " $1"
  107. shift
  108.  
  109. while [ $# -gt 0 ]; do
  110. SOURCE_PATH=$ANDROID_ROOT/$1
  111. if [ -d $SOURCE_PATH ]; then
  112. for file in $SOURCE_PATH/*; do
  113. echo " $1/$(basename $file)"
  114. cp $file $TARGET_DIRECTORY/
  115. done
  116. else
  117. echo " $1"
  118. cp $SOURCE_PATH $TARGET_DIRECTORY/
  119. fi
  120. shift
  121. done
  122. }
  123.  
  124. check_header_exists() {
  125. # check_header_exists <FILENAME>
  126. HEADER_FILE=$ANDROID_ROOT/$1
  127. if [ ! -e "$HEADER_FILE" ]; then
  128. return 1
  129. fi
  130.  
  131. return 0
  132. }
  133.  
  134. ##############
  135.  
  136. # Make sure that the dir given contains at least some of the assumed structures.
  137. require_sources \
  138. hardware/libhardware/include/hardware
  139.  
  140. mkdir -p $HEADER_PATH
  141.  
  142. # Default PATCH2,3 to 0
  143. PATCH2=${PATCH2:-0}
  144. PATCH3=${PATCH3:-0}
  145.  
  146. cat > $HEADER_PATH/android-version.h << EOF
  147. #ifndef ANDROID_VERSION_H_
  148. #define ANDROID_VERSION_H_
  149.  
  150. #define ANDROID_VERSION_MAJOR $MAJOR
  151. #define ANDROID_VERSION_MINOR $MINOR
  152. #define ANDROID_VERSION_PATCH $PATCH
  153. #define ANDROID_VERSION_PATCH2 $PATCH2
  154. #define ANDROID_VERSION_PATCH3 $PATCH3
  155.  
  156. #endif
  157. EOF
  158.  
  159. cat > $HEADER_PATH/android-config.h << EOF
  160. #ifndef HYBRIS_CONFIG_H_
  161. #define HYBRIS_CONFIG_H_
  162.  
  163. /* When android is built for a specific device the build is
  164. modified by BoardConfig.mk and possibly other mechanisms.
  165. eg
  166. device/samsung/i9305/BoardConfig.mk:
  167. COMMON_GLOBAL_CFLAGS += -DCAMERA_WITH_CITYID_PARAM
  168. device/samsung/smdk4412-common/BoardCommonConfig.mk:
  169. COMMON_GLOBAL_CFLAGS += -DEXYNOS4_ENHANCEMENTS
  170.  
  171. This file allows those global configurations, which are not
  172. otherwise defined in the build headers, to be available in
  173. hybris builds.
  174.  
  175. Typically it is generated at hardware adaptation time.
  176.  
  177. The CONFIG GOES... line below can be used by automation to modify
  178. this file.
  179. */
  180.  
  181. #include <android-version.h>
  182.  
  183. /* CONFIG GOES HERE */
  184.  
  185. #endif
  186. EOF
  187.  
  188. extract_headers_to hardware \
  189. hardware/libhardware/include/hardware
  190.  
  191. extract_headers_to hardware_legacy \
  192. hardware/libhardware_legacy/include/hardware_legacy/vibrator.h \
  193. hardware/libhardware_legacy/include/hardware_legacy/audio_policy_conf.h \
  194. hardware/libhardware_legacy/include/hardware_legacy/wifi.h
  195.  
  196. extract_headers_to cutils \
  197. system/core/include/cutils
  198.  
  199. extract_headers_to log \
  200. system/core/include/log
  201.  
  202. extract_headers_to system \
  203. system/core/include/system
  204.  
  205. check_header_exists system/media/audio/include/system/audio.h && \
  206. extract_headers_to system \
  207. system/media/audio/include/system
  208.  
  209. extract_headers_to android \
  210. system/core/include/android
  211.  
  212. check_header_exists bionic/libc/kernel/common/linux/sync.h && \
  213. extract_headers_to linux \
  214. bionic/libc/kernel/common/linux/sync.h \
  215. bionic/libc/kernel/common/linux/sw_sync.h
  216.  
  217. check_header_exists system/core/include/sync/sync.h && \
  218. extract_headers_to sync \
  219. system/core/include/sync
  220.  
  221. check_header_exists bionic/libc/kernel/uapi/linux/sync.h && \
  222. extract_headers_to linux \
  223. bionic/libc/kernel/uapi/linux/sync.h \
  224. bionic/libc/kernel/uapi/linux/sw_sync.h
  225.  
  226. check_header_exists system/core/libsync/include/sync/sync.h && \
  227. extract_headers_to sync \
  228. system/core/libsync/include/sync
  229.  
  230. check_header_exists external/libnfc-nxp/inc/phNfcConfig.h && \
  231. extract_headers_to libnfc-nxp \
  232. external/libnfc-nxp/inc \
  233. external/libnfc-nxp/src
  234.  
  235. extract_headers_to private \
  236. system/core/include/private/android_filesystem_config.h
  237.  
  238.  
  239. # In order to make it easier to trace back the origins of headers, fetch
  240. # some repository information from the Git source tree (if available).
  241. # Tested with AOSP and CM.
  242. NOW=$(LC_ALL=C date)
  243.  
  244. # Add here all sub-projects of AOSP/CM from which headers are extracted
  245. GIT_PROJECTS="
  246. hardware/libhardware
  247. hardware/libhardware_legacy
  248. system/core
  249. external/kernel-headers
  250. external/libnfc-nxp
  251. "
  252.  
  253. echo "Extracting Git revision information"
  254. if ! which repo >/dev/null 2>&1; then
  255. echo "Can't extract Git info: missing 'repo'"
  256. SKIPGIT=1
  257. fi
  258. if ! which git >/dev/null 2>&1; then
  259. echo "Can't extract Git info: missing 'git'"
  260. SKIPGIT=1
  261. fi
  262.  
  263.  
  264. rm -f $HEADER_PATH/SOURCE_GIT_REVISION_INFO
  265. if [ x$SKIPGIT != x1 ]; then
  266. (for GIT_PROJECT in $GIT_PROJECTS; do
  267. TARGET_DIR=$ANDROID_ROOT/$GIT_PROJECT
  268. echo "================================================"
  269. echo "$GIT_PROJECT @ $NOW"
  270. echo "================================================"
  271. if [ -e $TARGET_DIR/.git ]; then
  272. (
  273. set -x
  274. cd $ANDROID_ROOT
  275. repo status $GIT_PROJECT
  276. cd $TARGET_DIR
  277. git show-ref --head
  278. git remote -v
  279. )
  280. echo ""
  281. echo ""
  282. else
  283. echo "WARNING: $GIT_PROJECT does not contain a Git repository"
  284. fi
  285. done) > $HEADER_PATH/git-revisions.txt 2>&1
  286.  
  287. # Repo manifest that can be used to fetch the sources for re-extracting headers
  288. if [ -e $ANDROID_ROOT/.repo/manifest.xml ]; then
  289. cp $ANDROID_ROOT/.repo/manifest.xml $HEADER_PATH/
  290. fi
  291. fi
  292.  
  293. find "$HEADER_PATH" -type f -exec chmod 0644 {} \;
  294.  
  295.  
  296. # Create a pkconfig if we know the final installation path otherwise
  297. # make a Makefile and a pc.in file for it to handle
  298. if [ x$PKGCONFIGPATH = x ]; then
  299. # Add a makefile to make packaging easier
  300. cat > ${HEADER_PATH}/Makefile << EOF
  301. PREFIX?=/usr/local
  302. INCLUDEDIR?=\$(PREFIX)/include/android
  303. all:
  304. @echo "Use '\$(MAKE) install' to install"
  305.  
  306. install:
  307. mkdir -p \$(DESTDIR)/\$(INCLUDEDIR)
  308. cp -r * \$(DESTDIR)/\$(INCLUDEDIR)
  309. rm -f \$(DESTDIR)/\$(INCLUDEDIR)/Makefile
  310. rm -f \$(DESTDIR)/\$(INCLUDEDIR)/android-headers.pc.in
  311. mkdir -p \$(DESTDIR)/\$(PREFIX)/lib/pkgconfig
  312. sed -e 's;@prefix@;\$(PREFIX)/;g; s;@includedir@;\$(INCLUDEDIR);g' android-headers.pc.in > \$(DESTDIR)/\$(PREFIX)/lib/pkgconfig/android-headers.pc
  313. EOF
  314.  
  315. echo "Creating ${HEADER_PATH}/android-headers.pc.in"
  316. cat > ${HEADER_PATH}/android-headers.pc.in << EOF
  317. Name: android-headers
  318. Description: Provides the headers for the droid system
  319. Version: ${MAJOR}.${MINOR}.${PATCH}
  320. Cflags: -I@includedir@
  321. EOF
  322. else
  323. echo "Creating ${HEADER_PATH}/android-headers.pc"
  324. cat > ${HEADER_PATH}/android-headers.pc << EOF
  325. Name: android-headers
  326. Description: Provides the headers for the droid system
  327. Version: ${MAJOR}.${MINOR}.${PATCH}
  328. Cflags: -I$PKGCONFIGPATH
  329. EOF
  330. fi
  331. # vim: noai:ts=4:sw=4:ss=4:expandtab
Add Comment
Please, Sign In to add comment