aboutsummaryrefslogtreecommitdiff
path: root/clear_header.sh
blob: ced98050626c856440bc134f28a422b5987dae33 (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
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/bash
#
# clear_header.sh
#
# This script removes the installed header files from include-fix direcotry,
# if these headers files have been defined in Android. 

usage ()
{
  echo "Usage: $0 --prefix=<toolchain prefix> --sysroot=<Android sysroot> [--force]"
  echo "  <toolchain prefix>: the prefix path when you configure the install"
  echo "                      the toolchain."
  echo "   <Android sysroot>: the sysroot directory that is extracted from "
  echo "                      an Android tree."
  echo "             <force>: if specified, the headers found by this script "
  echo "                      will be deleted without confirmation."
}

if [[ $# -lt 1 ]]; then
  usage
  exit 1
fi

force=0
PREFIX=""
SYSROOT=""

for option in $@; do
  optarg=$(expr "x$option" : 'x[^=]*=\(.*\)')

  case "$option" in
    --prefix=*)
      PREFIX=${optarg}
      if [[ ! -d ${PREFIX}/lib/gcc/arm-eabi ]]; then
        if [[ ! -d ${PREFIX}/lib/gcc/arm-linux-androideabi ]]; then
          echo "Error: ${PREFIX} is not a correct toolchain prefix path!"
          usage
          exit 1
        else
          build_target="arm-linux-androideabi"
        fi
      else
        build_target="arm-eabi"
      fi
      ;;
    --sysroot=*)
      SYSROOT=${optarg}
      ;;
    --force)
      force=1
      ;;
    *)
      echo "Error: unknown options ${option}"
      usage
      exit 1
      ;;
  esac
done

if [[ "x${PREFIX}" = "x" ]]; then
  echo "Error: you must specify the toolchain prefix path."
  usage
  exit 1
fi

if [[ "x${SYSROOT}" = "x" ]]; then
  SYSROOT="/home/jingyu/projects/gcc/toolchain_build/cupcake_rel_root2"
  echo "Warning: SYSROOT can't be empty. Set SYSROOT=${SYSROOT}."
fi

INCLUDE_ROOT=$SYSROOT/usr/include
if [[ ! -d ${INCLUDE_ROOT} ]]; then
  echo "Error: ${SYSROOT} is not a correct Android sysroot path!"
  usage
  exit 1
fi

installed_headers=`find ${PREFIX}/lib/gcc/${build_target}/*/include-fixed -name "*\.h"`

for one_header in ${installed_headers}; do
  header_name=${one_header##*/}
  defined_headers=`find ${INCLUDE_ROOT} -name ${header_name}`

  # If the installed header file has been defined in android sysroot,
  # we need to remove the installed file.
  if [[ -n ${defined_headers} ]]; then
    echo -n "Delete ${one_header}?(Y/N):"
    if [[ ${force} = 0 ]]; then
      read text
    else
      text="Y"
    fi
    if [[ "${text}" = "Y" || "${text}" = "y" ]]; then
      rm -f ${one_header}
      echo "... Removed!"
    fi
  fi
done