158d086fdb479ae9df6438b636a71bad9d5b0f1e
[platform/framework/web/chromium-efl.git] / tizen_src / build / common.sh
1 #!/bin/bash
2
3 export SCRIPTDIR=$(readlink -e $(dirname $0))
4 export TOPDIR=$(readlink -f "${SCRIPTDIR}/../..")
5 export CHROME_SRC="${TOPDIR}"
6
7 function applyPatch {
8   directory=$1
9   shift
10   patchfile=$1
11   shift
12   echo Applying $patchfile in $directory
13   pushd "$directory" > /dev/null
14   patch -p1 $@ < "$patchfile"
15   popd > /dev/null
16 }
17
18 function getHostOs() {
19   echo $(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
20 }
21
22 function getHostArch() {
23   echo $(uname -m | sed -e \
24         's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/;s/aarch64/arm64/')
25 }
26
27 function getPythonVersion() {
28   echo $(python --version  2>&1 | sed -e 's/Python \([0-9]\+\.[0-9]\+\)\.[0-9]\+/\1/')
29 }
30
31 function setIfUndef() {
32     eval original=\$$1
33     new=$2
34     if [ -n "$original" ]; then
35         echo $original
36     else
37         echo $new
38     fi
39 }
40
41
42 function hostBuldScriptUsage() {
43 cat << EOF
44 usage: $1 [OPTIONS]
45
46 Build non gbs version of chromium-efl
47
48 OPTIONS:
49    -h, --help            Show this message
50    --build-ewk-unittests Build ewk unittests
51    --ccache              Configure ccache installed in your system
52    --clang               Use chromium's clang compiler to build the sources
53    --content-shell       Build content_shell application
54    --debug               Build debug version of chromium-efl (out.${host_arch}/Debug instead of out.${host_arch}/Release)
55    -jN                   Set number of jobs, just like with make or ninja
56    --skip-gyp            Skip restore_gyp, jhbuild and gyp_chromium steps
57    --skip-ninja          Skip ninja step
58    --xwalk               Build crosswalk and friends
59
60 examples:
61 $0 --skip-gyp
62 $0 --skip-gyp --ccache
63 $0 --skip-ninja
64 EOF
65   exit
66 }
67
68 function parseHostBuildScriptParams() {
69
70   export SKIP_GYP=0
71   export USE_CCACHE=0
72   export USE_CLANG=0
73   export FORCE_JHBUILD=0
74   export SKIP_NINJA=0
75   export BUILD_EWK_UNITTESTS=0
76   export BUILD_CONTENT_SHELL=0
77   export BUILD_XWALK=0
78   export BUILD_SUBDIRECTORY=Release
79
80   local platform="$1"
81   shift
82
83   while [[ $# > 0 ]]; do
84     case "$1" in
85       -h|--help)
86         hostBuldScriptUsage ${0}
87         ;;
88       --skip-gyp)
89         export SKIP_GYP=1
90         ;;
91       --ccache)
92         echo using ccache
93         export USE_CCACHE=1
94         source $TOPDIR/tizen_src/build/ccache_env.sh ${platform}
95         ;;
96       --clang)
97         export USE_CLANG=1
98         ;;
99       --content-shell)
100         export BUILD_CONTENT_SHELL=1
101         ;;
102       --force-jhbuild)
103         export FORCE_JHBUILD=1
104         ;;
105       --skip-ninja)
106         export SKIP_NINJA=1
107         ;;
108       --build-ewk-unittests)
109         export BUILD_EWK_UNITTESTS=1
110         ;;
111       --debug)
112         export BUILD_SUBDIRECTORY="Debug"
113         ;;
114       --xwalk)
115         export BUILD_XWALK=1
116         ;;
117       -j*)
118         export JOBS="$1"
119         ;;
120       *)
121         echo "Unknown argument: $1"
122         exit 1
123         ;;
124     esac
125     shift;
126   done
127 }
128
129 function hostGypChromiumEfl() {
130   if [[ $SKIP_GYP == 0 ]]; then
131     local XWALK_ARG=""
132     if [[ $BUILD_XWALK == 1 ]]; then
133       XWALK_ARG="--xwalk"
134     fi
135     ${TOPDIR}/tizen_src/build/gyp_chromiumefl.sh $XWALK_ARG $@
136   fi
137 }
138
139 function hostNinja() {
140   if [[ $SKIP_NINJA == 0 ]]; then
141     TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
142     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
143       TARGETS="$TARGETS ewk_unittests"
144     fi
145     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
146       TARGETS="$TARGETS content_shell dump_syms minidump_stackwalk"
147     fi
148     if [[ $BUILD_XWALK == 1 ]]; then
149       TARGETS="$TARGETS xwalk"
150     fi
151     BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
152     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
153   fi
154 }
155
156 function error_report() {
157   echo "Error: File:$1 Line:$2"
158   exit 1
159 }
160
161 function findElementInArray() {
162   local elm
163   for elm in "${@:2}"; do
164     [[ "$elm" = "$1" ]] && return 0;
165   done
166   return 1;
167 }
168
169 function setupAndExecuteTargetBuild() {
170
171   local platform="$1"
172   shift
173
174   local PROFILE_NAME
175   local DEFAULT_PROFILE_NAME
176   local ARCHITECTURE
177   local CONF_FLAG
178   local -a ARGS
179
180   # "|| :" means "or always succeeding built-in command"
181   PROFILE_NAME=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" || :)
182
183   if [[ $platform == "mobile" ]]; then
184     DEFAULT_PROFILE_NAME=tizenmb_v2.4
185     ARCHITECTURE=armv7l
186   elif [[ $platform == "tv" ]]; then
187     DEFAULT_PROFILE_NAME=tztv_v3.0_arm-wayland
188     ARCHITECTURE=armv7l
189   elif [[ $platform == "emulator" ]]; then
190     DEFAULT_PROFILE_NAME=tizen_emulator_v2.4
191     ARCHITECTURE=i586
192   fi
193
194   if [ "$PROFILE_NAME" == "" ]; then
195     PROFILE_NAME=$DEFAULT_PROFILE_NAME
196   fi
197
198   PROFILE_FLAG="-P $PROFILE_NAME"
199
200   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
201     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
202   fi
203
204   EXTRA_PACK_OPTS=""
205   if [ "$PROFILE_NAME" == "tztv_v2.2.1_prehawk" ]; then
206     EXTRA_PACK_OPTS="--extra-packs python-base-x86-arm,python-x86-arm,python-xml-x86-arm"
207   fi
208
209   if [ "$(echo "${PROFILE_NAME}" | grep -Po "v3.0")" != "" ]; then
210     prepareTizen3Build $PROFILE_NAME
211   fi
212
213   local count=0
214   while [[ $# > 0 ]]; do
215     count=$(( $count + 1 ))
216     case "$1" in
217     --debug)
218         ARGS[$count]=--define
219         count=$(( $count + 1 ))
220         ARGS[$count]="_debug_mode 1"
221     ;;
222     --skip-ninja)
223         ARGS[$count]=--define
224         count=$(( $count + 1 ))
225         ARGS[$count]="_skip_ninja 1"
226     ;;
227     --skip-gyp)
228         ARGS[$count]=--define
229         count=$(( $count + 1 ))
230         ARGS[$count]="_skip_gyp 1"
231     ;;
232     --gbs-debug)
233         ARGS[$count]=--debug
234     ;;
235     *)
236       ARGS[$count]="$1"
237     ;;
238     esac
239     shift;
240   done
241
242   cd $TOPDIR
243   rm -f packaging
244   ln -sf tizen_src/packaging packaging
245
246   gbs $CONF_FLAG build $PROFILE_FLAG --include-all -A $ARCHITECTURE --incremental "${ARGS[@]}" $BUILD_CONF_OPTS $EXTRA_PACK_OPTS
247 }
248
249 function prepareTizen3Build() {
250   local PROFILE_NAME=$1
251   BUILD_CONF_OPTS=""
252
253   # In case of '_rpmlint 1', build.conf of gbs repo will be used, enabling rpmlint.
254   # Otherwise, locally prepared build.conf will be used, disabling rpmlint.
255   local PREVIOUS_BUILD_CONF_PATH=""
256   local LOCAL_BUILD_CONF_PATH=""
257
258   if [ "$PROFILE_NAME" == "tztv_v3.0" ]; then
259     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tztv_v3.0_arm-x11.conf"
260     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tztv_v3.0_arm-x11.conf"
261   elif [ "$PROFILE_NAME" == "tzmb_v3.0" ]; then
262     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm-x11.conf"
263     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tzmb_v3.0_arm-x11.conf"
264   elif [ "$PROFILE_NAME" == "tztv_v3.0_arm-wayland" ]; then
265     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tztv_v3.0_arm-walynad.conf"
266     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tztv_v3.0_arm-wayland.conf"
267   elif [ "$PROFILE_NAME" == "tzmb_v3.0_arm-wayland" ]; then
268     PREVIOUS_BUILD_CONF_PATH="/var/tmp/$USER-gbs/tzmb_v3.0_arm-walynad.conf"
269     LOCAL_BUILD_CONF_PATH="$TOPDIR/tizen_src/build/tzmb_v3.0_arm-wayland.conf"
270   fi
271
272   local PREVIOUS_RPMLINT="!rpmlint"
273   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
274     PREVIOUS_RPMLINT=""
275   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
276     PREVIOUS_RPMLINT="rpmlint"
277   fi
278
279   if [ "$LOCAL_BUILD_CONF_PATH" != "" ]; then
280     BUILD_CONF_OPTS="-D $LOCAL_BUILD_CONF_PATH"
281   fi
282
283   if [ "$(echo "$@" | grep -Po "_rpmlint\ 1")" == "" ]; then
284     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
285       BUILD_CONF_OPTS+=" --clean"
286     fi
287   else
288     BUILD_CONF_OPTS=""
289     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
290       BUILD_CONF_OPTS="--clean"
291     fi
292   fi
293 }