Allow building content shell when xwalk directory is absent
[platform/framework/web/chromium-efl.git] / tizen_src / build / common.sh
1 #!/bin/bash
2
3 pushd `dirname $0` > /dev/null
4 export SCRIPTDIR=`pwd -L`
5 popd > /dev/null
6
7 export TOPDIR=$(readlink -f "${SCRIPTDIR}/../..")
8 export CHROME_SRC="${TOPDIR}"
9
10 function applyPatch {
11   directory=$1
12   shift
13   patchfile=$1
14   shift
15   echo Applying $patchfile in $directory
16   pushd "$directory" > /dev/null
17   patch -p1 $@ < "$patchfile"
18   popd > /dev/null
19 }
20
21 function getHostOs() {
22   echo $(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
23 }
24
25 function getHostArch() {
26   echo $(uname -m | sed -e \
27         's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/')
28 }
29
30 function getPythonVersion() {
31   echo $(python --version  2>&1 | sed -e 's/Python \([0-9]\+\.[0-9]\+\)\.[0-9]\+/\1/')
32 }
33
34 function setIfUndef() {
35     eval original=\$$1
36     new=$2
37     if [ -n "$original" ]; then
38         echo $original
39     else
40         echo $new
41     fi
42 }
43
44
45 function hostBuldScriptUsage() {
46 cat << EOF
47 usage: $1 [OPTIONS]
48
49 Build non gbs version of chromium-efl
50
51 OPTIONS:
52    -h, --help            Show this message
53    --build-ewk-unittests Build ewk unittests
54    --ccache              Configure ccache installed in your system
55    --clang               Use chromium's clang compiler to build the sources
56    --content-shell       Build content_shell application
57    --debug               Build debug version of chromium-efl (out.${host_arch}/Debug instead of out.${host_arch}/Release)
58    -jN                   Set number of jobs, just like with make or ninja
59    --skip-gyp            Skip restore_gyp, jhbuild and gyp_chromium steps
60    --skip-ninja          Skip ninja step
61    --xwalk               Build crosswalk and friends
62
63 examples:
64 $0 --skip-gyp
65 $0 --skip-gyp --ccache
66 $0 --skip-ninja
67 EOF
68   exit
69 }
70
71 function parseHostBuildScriptParams() {
72
73   export SKIP_GYP=0
74   export USE_CCACHE=0
75   export USE_CLANG=0
76   export FORCE_JHBUILD=0
77   export SKIP_NINJA=0
78   export BUILD_EWK_UNITTESTS=0
79   export BUILD_CONTENT_SHELL=0
80   export BUILD_XWALK=0
81   export BUILD_SUBDIRECTORY=Release
82
83   local platform="$1"
84   shift
85
86   while [[ $# > 0 ]]; do
87     case "$1" in
88       -h|--help)
89         hostBuldScriptUsage ${0}
90         ;;
91       --skip-gyp)
92         export SKIP_GYP=1
93         ;;
94       --ccache)
95         echo using ccache
96         export USE_CCACHE=1
97         source $TOPDIR/build/ccache_env.sh ${platform}
98         ;;
99       --clang)
100         export USE_CLANG=1
101         ;;
102       --content-shell)
103         export BUILD_CONTENT_SHELL=1
104         ;;
105       --force-jhbuild)
106         export FORCE_JHBUILD=1
107         ;;
108       --skip-ninja)
109         export SKIP_NINJA=1
110         ;;
111       --build-ewk-unittests)
112         export BUILD_EWK_UNITTESTS=1
113         ;;
114       --debug)
115         export BUILD_SUBDIRECTORY="Debug"
116         ;;
117       --xwalk)
118         export BUILD_XWALK=1
119         ;;
120       -j*)
121         export JOBS="$1"
122         ;;
123       *)
124         echo "Unknown argument: $1"
125         exit 1
126         ;;
127     esac
128     shift;
129   done
130 }
131
132 function hostGypChromiumEfl() {
133   if [[ $SKIP_GYP == 0 ]]; then
134     local XWALK_ARG=""
135     if [[ $BUILD_XWALK == 1 ]]; then
136       XWALK_ARG="--xwalk"
137     fi
138     ${TOPDIR}/tizen_src/build/gyp_chromiumefl.sh $XWALK_ARG $@
139   fi
140 }
141
142 function hostNinja() {
143   if [[ $SKIP_NINJA == 0 ]]; then
144     TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
145     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
146       TARGETS="$TARGETS ewk_unittests"
147     fi
148     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
149       TARGETS="$TARGETS content_shell dump_syms minidump_stackwalk"
150     fi
151     if [[ $BUILD_XWALK == 1 ]]; then
152       TARGETS="$TARGETS xwalk"
153     fi
154     BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
155     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
156   fi
157 }
158
159 function error_report() {
160   echo "Error: File:$1 Line:$2"
161   exit 1
162 }
163
164 function findElementInArray() {
165   local elm
166   for elm in "${@:2}"; do
167     [[ "$elm" = "$1" ]] && return 0;
168   done
169   return 1;
170 }
171
172 function setupAndExecuteTargetBuild() {
173
174   local platform="$1"
175   shift
176
177   local PROFILE_NAME
178   local DEFAULT_PROFILE_NAME
179   local ARCHITECTURE
180   local CONF_FLAG
181   local -a ARGS
182
183   # "|| :" means "or always succeeding built-in command"
184   PROFILE_NAME=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" || :)
185
186   if [[ $platform == "mobile" ]]; then
187     DEFAULT_PROFILE_NAME=tizenmb_v2.4
188     ARCHITECTURE=armv7l
189   elif [[ $platform == "tv" ]]; then
190     DEFAULT_PROFILE_NAME=tztv_v3.0
191     ARCHITECTURE=armv7l
192   elif [[ $platform == "emulator" ]]; then
193     DEFAULT_PROFILE_NAME=tizen_emulator_v2.4
194     ARCHITECTURE=i586
195   fi
196
197   if [ "$PROFILE_NAME" == "" ]; then
198     PROFILE_NAME=$DEFAULT_PROFILE_NAME
199   fi
200
201   PROFILE_FLAG="-P $PROFILE_NAME"
202
203   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
204     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
205   fi
206
207   cd $TOPDIR
208   rm -f packaging
209   ln -sf tizen_src/packaging packaging
210   gbs $CONF_FLAG build $PROFILE_FLAG -A $ARCHITECTURE --incremental "${@}"
211 }