Move EWK implementation code into ewk/ directory where it belongs.
[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
62 examples:
63 $0 --skip-gyp
64 $0 --skip-gyp --ccache
65 $0 --skip-ninja
66 EOF
67   exit
68 }
69
70 function parseHostBuildScriptParams() {
71
72   export SKIP_GYP=0
73   export USE_CCACHE=0
74   export USE_CLANG=0
75   export FORCE_JHBUILD=0
76   export SKIP_NINJA=0
77   export BUILD_EWK_UNITTESTS=0
78   export BUILD_CONTENT_SHELL=0
79   export BUILD_SUBDIRECTORY=Release
80
81   local platform="$1"
82   shift
83
84   while [[ $# > 0 ]]; do
85     case "$1" in
86       -h|--help)
87         hostBuldScriptUsage ${0}
88         ;;
89       --skip-gyp)
90         export SKIP_GYP=1
91         ;;
92       --ccache)
93         echo using ccache
94         export USE_CCACHE=1
95         source $TOPDIR/build/ccache_env.sh ${platform}
96         ;;
97       --clang)
98         export USE_CLANG=1
99         ;;
100       --content-shell)
101         export BUILD_CONTENT_SHELL=1
102         ;;
103       --force-jhbuild)
104         export FORCE_JHBUILD=1
105         ;;
106       --skip-ninja)
107         export SKIP_NINJA=1
108         ;;
109       --build-ewk-unittests)
110         export BUILD_EWK_UNITTESTS=1
111         ;;
112       --debug)
113         export BUILD_SUBDIRECTORY="Debug"
114         ;;
115       -j*)
116         export JOBS="$1"
117         ;;
118       *)
119         echo "Unknown argument: $1"
120         exit 1
121         ;;
122     esac
123     shift;
124   done
125 }
126
127 function hostGypChromiumEfl() {
128   if [[ $SKIP_GYP == 0 ]]; then
129     ${TOPDIR}/tizen_src/build/gyp_chromiumefl.sh $@
130   fi
131 }
132
133 function hostNinja() {
134   if [[ $SKIP_NINJA == 0 ]]; then
135     TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
136     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
137       TARGETS="$TARGETS ewk_unittests"
138     fi
139     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
140       TARGETS="$TARGETS content_shell"
141     fi
142     BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
143     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
144   fi
145 }
146
147 function error_report() {
148   echo "Error: File:$1 Line:$2"
149   exit 1
150 }
151
152 function findElementInArray() {
153   local elm
154   for elm in "${@:2}"; do
155     [[ "$elm" = "$1" ]] && return 0;
156   done
157   return 1;
158 }
159
160 function setupAndExecuteTargetBuild() {
161
162   local platform="$1"
163   shift
164
165   local PROFILE_NAME
166   local DEFAULT_PROFILE_NAME
167   local ARCHITECTURE
168   local CONF_FLAG
169   local -a ARGS
170
171   # "|| :" means "or always succeeding built-in command"
172   PROFILE_NAME=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" || :)
173
174   if [[ $platform == "mobile" ]]; then
175     DEFAULT_PROFILE_NAME=tizenmb_v2.4
176     ARCHITECTURE=armv7l
177   elif [[ $platform == "tv" ]]; then
178     DEFAULT_PROFILE_NAME=tztv_v2.2.1_prehawk
179     ARCHITECTURE=armv7l
180   elif [[ $platform == "emulator" ]]; then
181     DEFAULT_PROFILE_NAME=tizen_emulator_v2.4
182     ARCHITECTURE=i586
183   fi
184
185   if [ "$PROFILE_NAME" == "" ]; then
186     PROFILE_NAME=$DEFAULT_PROFILE_NAME
187   fi
188
189   PROFILE_FLAG="-P $PROFILE_NAME"
190
191   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
192     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
193   fi
194
195   gbs $CONF_FLAG build $PROFILE_FLAG -A $ARCHITECTURE --incremental "${@}"
196 }