1#!/bin/sh 2# Check if some platform headers can be included alone 3# See b.android.com/64679 for one of them 4# 5 6export ANDROID_NDK_ROOT=$NDK 7 8NDK_BUILDTOOLS_PATH=$NDK/build/tools 9. $NDK/build/tools/prebuilt-common.sh 10 11JOBS=1 12for OPT; do 13 case $OPT in 14 -j*) 15 JOBS=${OPT##-j} 16 ;; 17 --jobs=*) 18 JOBS=${OPT##--jobs=} 19 ;; 20 APP_ABI=*) 21 eval readonly "$OPT" 22 ;; 23 esac 24done 25 26INTERNAL_HEADERS="sys/_errdefs.h sys/_sigdefs.h sys/_system_properties.h" 27INVALID_HEADERS_FOR_64BIT="time64.h sys/user.h" # ToDo: remove sys/user.h later once __u64 and __u32 are defined for x86_64 28 29# This header doesn't compile unless included from C++ with 30# --std=c++-0x or higher, so skip it here. 31INTERNAL_HEADERS="$INTERNAL_HEADERS uchar.h" 32 33if [ -n "$APP_ABI" ]; then 34 readonly APP_ARCH="$(convert_abi_to_arch "$APP_ABI")" 35 enabled_test_arch () { [ "$APP_ARCH" == "$1" ]; } 36else 37 enabled_test_arch () { true; } 38fi 39 40for ARCH in $DEFAULT_ARCHS; do 41 enabled_test_arch "$ARCH" || continue 42 for API_LEVEL in $API_LEVELS; do 43 if [ ! -d $ANDROID_NDK_ROOT/platforms/android-$API_LEVEL/arch-$ARCH ]; then 44 continue 45 fi 46 HEADERS=$(cd $ANDROID_NDK_ROOT/platforms/android-$API_LEVEL/arch-$ARCH/usr/include ; ls *.h sys/*.h android/*.h EGL/*.h GLES/*.h GLES2/*.h GLES3/*.h OMXAL/*.h SLES/*.h 2> /dev/null) 47 #echo $API_LEVEL $ARCH HEADERS=$HEADERS 48 ABIS=$(commas_to_spaces $(convert_arch_to_abi $ARCH)) 49 for ABI in $ABIS; do 50 # Create temporary project 51 PROJECT_DIR=${TMPDIR:-/tmp}/$USER-ndk-test-system-headers/android-$API_LEVEL-$ABI 52 (mkdir -p "$PROJECT_DIR" && rm -rf "$PROJECT_DIR"/*) || panic "Can't create dir: $PROJECT_DIR" 53 mkdir "$PROJECT_DIR"/jni 54 cat > $PROJECT_DIR/jni/Application.mk <<EOF 55# Auto-generated - DO NOT EDIT 56APP_PLATFORM=android-$API_LEVEL 57APP_ABI=$ABI 58APP_MODULES=libfoo 59EOF 60 ANDROID_MK=$PROJECT_DIR/jni/Android.mk 61 cat > $ANDROID_MK <<EOF 62# Auto-generated - DO NOT EDIT 63LOCAL_PATH := \$(call my-dir) 64 65include \$(CLEAR_VARS) 66LOCAL_MODULE := libfoo 67LOCAL_SRC_FILES := \\ 68EOF 69 for HEADER in $HEADERS; do 70 if [ "$INTERNAL_HEADERS" != "${INTERNAL_HEADERS%%$HEADER*}" ] ; then 71 continue; 72 fi 73 if [ "$ABI" != "${ABI%%64*}" ] ; then 74 if [ "$INVALID_HEADERS_FOR_64BIT" != "${INVALID_HEADERS_FOR_64BIT%%$HEADER*}" ] ; then 75 continue; 76 fi 77 fi 78 NAME=$(echo "$HEADER" | tr '/' '__' | tr '.' '_' | tr '-' '_') 79 SRC=$NAME.c 80 SRC_FILE=$PROJECT_DIR/jni/$SRC 81 cat > $PROJECT_DIR/jni/$SRC <<EOF 82/* Auto-generated - DO NOT EDIT */ 83#include <$HEADER> 84 85char dummy_$NAME = 0; 86EOF 87 echo " $SRC \\" >> $ANDROID_MK 88 done 89 cat >> $ANDROID_MK <<EOF 90 91include \$(BUILD_STATIC_LIBRARY) 92 93EOF 94 echo "Checking headers for android-$API_LEVEL/$ABI" 95 $ANDROID_NDK_ROOT/ndk-build -C "$PROJECT_DIR" -B -j$JOBS V=1 1>/dev/null 2>&1 96 fail_panic "Can't compile header for android-$API_LEVEL/$ABI, to reproduce: $ANDROID_NDK_ROOT/ndk-build -C $PROJECT_DIR" 97 98 rm -rf "$PROJECT_DIR" 99 done # for ABI 100 done # for ARCH 101done # for API_LEVEL 102