Use third party libxml
[platform/framework/web/chromium-efl.git] / tizen_src / scripts / deploy2device.sh
1 #! /bin/bash
2
3 SCRIPT_PATH=$(readlink -f $(dirname $0))
4
5 [ -n "$DEPLOY_DIR" ] || DEPLOY_DIR="/opt/usr/dev"
6 [ -n "$OUT_DIR" ] || OUT_DIR=$(readlink -f "$SCRIPT_PATH/../out.mobile.arm")
7 [ -n "$DEPLOY_STRIPPED_LIBS" ] || DEPLOY_STRIPPED_LIBS=1
8 [ -n "$TIZEN_SDK_PATH" ] || TIZEN_SDK_PATH="$HOME/tizen-sdk"
9
10 # Globals.
11 out_dir=$OUT_DIR
12 out_subdir=""
13 deploy_subdir=""
14 arm_strip=""
15
16 usage() {
17     cat << EOF
18 Usage: $0 debug|release [-o outdir] [lib|ewk]
19
20     default outdir: out.mobile.arm
21
22 ENVIRONMENT
23     DEPLOY_DIR
24         default: /opt/usr/dev
25     OUT_DIR
26         default: out.mobile.arm
27     DEPLOY_STRIPPED_LIBS
28         default: 1
29     TIZEN_SDK_PATH
30         default: ~/tizen-sdk
31
32 EOF
33 }
34
35 dieTrap() {
36     echo "ERROR at $0:$1"
37     usage
38     exit 1
39 }
40
41 trap 'die $0 $LINENO' ERR SIGINT SIGTERM SIGQUIT
42
43 fastpush() {
44     src=$1
45     dst=$2
46     size=$(ls -1s --block-size=1 $src | cut -f 1 -d ' ')
47     trashold="524288" # 512K
48     # Avoid setup overhead for small files.
49     if [ "$size" -le "$trashold" ]; then
50         sdb push $src $dst
51     else
52         $SCRIPT_PATH/tizensync.sh push $src $dst
53         # Print a report that is somewhat consistent with sdb push.
54         echo "fast-pushed           $src"
55     fi
56 }
57
58 _setupDevice() {
59     # Do a quick heuristic check that it was already installed via package.
60     # We don't handle everything so the package has to be installed once.
61     lsout=$(sdb shell "ls /usr/lib/chromium-efl/icudtl.dat 2>/dev/null")
62     if [ -z "$lsout" ]; then
63         >&2 echo "It seems like you have never installed chromium-efl via package."
64         >&2 echo "Sorry but it won't work, exiting..."
65         exit 1
66     fi
67
68     sdb start-server
69     sdb root on
70     sdb shell << EOF
71 mkdir -p "$DEPLOY_DIR/lib/release"
72 mkdir -p "$DEPLOY_DIR/lib/debug"
73 [ -f /var/run/sshd.pid ] || /usr/sbin/sshd
74 exit
75 EOF
76     sdb push "$SCRIPT_PATH/device_envsetup.sh" $DEPLOY_DIR
77 }
78
79 setupDevice() {
80     _setupDevice > /dev/null
81 }
82
83 get_arm_strip() {
84     if [ -n "$CROSS_COMPILE" ] && type "${CROSS_COMPILE}strip" &> /dev/null; then
85         echo "${CROSS_COMPILE}strip"
86         return 0
87     fi
88
89     # Try to use the one from tizen sdk.
90     for _dummy in $(seq 1 1); do # dummy loop for bailing on error to print message.
91         # Glob (*) to handle different versions.
92         pushd $TIZEN_SDK_PATH/tools/arm-linux-gnueabi-gcc*/bin > /dev/null || break
93         path="$(pwd)/arm-linux-gnueabi-strip"
94         [ -x "$path" ] || break
95         popd > /dev/null || break
96         return 0
97     done
98
99     >&2 echo "Cannot find usable strip binary. Hint: try setting TIZEN_SDK_PATH to your installation."
100     return 1
101 }
102
103 deploylib() {
104     lib=$1
105     target_dir=$2
106     [ -f "$lib" ]
107     stripped="$1.0"
108     if [ "$DEPLOY_STRIPPED_LIBS" != "1" ]; then
109         stripped=$lib
110     elif [  ! -e "$stripped" -o "$stripped" -ot "$lib" ]; then
111         echo "stripping $lib to $stripped..."
112         $arm_strip -s $lib -o $stripped
113     fi
114
115     fastpush $stripped $target_dir/$(basename $lib)
116 }
117
118 deploychromiumlib() {
119     lib="$out_subdir/lib/libchromium-efl.so"
120     echo "deploying $lib..."
121     deploylib $lib $deploy_subdir
122
123     web_proc=$out_subdir/efl_webprocess
124     echo "deploying $web_proc..."
125     fastpush $web_proc $deploy_subdir
126 }
127
128 deployewk() {
129     lib="$out_subdir/lib/libchromium-ewk.so"
130     echo "deploying $lib..."
131     deploylib $lib $deploy_subdir
132
133     webview_app="$out_subdir/efl_webview_app"
134     if [ -f "$webview_app" ]; then
135         echo "deploying $webview_app..."
136         fastpush "$webview_app" $DEPLOY_DIR
137     fi
138     minibrowser="$out_subdir/mini_browser"
139     if [ -f "$minibrowser" ]; then
140         echo "deploying $minibrowser..."
141         fastpush "$minibrowser" $DEPLOY_DIR
142     fi
143 }
144
145 # Off we go...
146
147 if echo "$@" | grep -Eqw "\-h|\-\-help"; then
148     usage
149     exit 0
150 fi
151
152 buildtype=$1
153 [ "$buildtype" == "release" -o "$buildtype" == "debug" ]
154 shift
155
156 deploy_part="all"
157
158 while [ "$#" -gt "0" ]; do
159     if [ "$1" == "-o" ]; then
160         out_dir=$2
161         shift
162     else
163         [ -z "$deploy_part" ]
164         deploy_part=$1
165     fi
166     shift
167 done
168
169 [ -d "$out_dir" ]
170 [ "$deploy_part" == "all" -o "$deploy_part" == "lib" -o "$deploy_part" == "ewk" ]
171
172 if [ "$buildtype" == "release" ]; then
173     deploy_subdir="$DEPLOY_DIR/lib/release"
174     out_subdir="${out_dir}/Release"
175 elif [ "$buildtype" == "debug" ]; then
176     deploy_subdir="$DEPLOY_DIR/lib/debug"
177     out_subdir="${out_dir}/Debug"
178 fi
179
180 [ -d "$out_subdir" ]
181
182 if [ "$DEPLOY_STRIPPED_LIBS" == "1" ]; then
183     arm_strip="$(get_arm_strip)"
184 fi
185
186 setupDevice
187
188 case "$deploy_part" in
189     lib)
190         deploychromiumlib
191         ;;
192     ewk)
193         deployewk
194         ;;
195     all)
196         deploychromiumlib && deployewk
197         ;;
198 esac
199
200 echo ""
201 echo "SUCCESS!"
202 echo "Build has been deployed to device."
203 echo "Source in device_envsetup.sh in $DEPLOY_DIR before starting application."