[M67 Dev][Tizen] Remove GYP dependencies in tizen_src
[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 # Please set DEFAULT_TIZEN_VERSION to empty value for the latest tizen version
7 # or set DEFAULT_TIZEN_VERSION to current tizen version for the others.
8 export DEFAULT_TIZEN_VERSION=
9
10 if [ "$(echo "$@" | grep -e "--tizen")" != "" ]; then
11   tizen_version=$(echo $@ | sed -e 's#.*--tizen_\([0-9.]*\).*#\1#')
12   if $(echo $tizen_version | grep -qe "^[-\?[0-9]\+\.\?[0-9]*$" && echo true || echo false); then
13     DEFAULT_TIZEN_VERSION=$tizen_version
14   else
15     DEFAULT_TIZEN_VERSION=
16   fi
17 fi
18
19 supported_targets=("tizen" "desktop")
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/;s/aarch64/arm64/')
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    --no-content-shell    Don't 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-ninja          Skip ninja step
60
61 examples:
62 $0 --ccache
63 $0 --skip-ninja
64 EOF
65   exit
66 }
67
68 function parseHostBuildScriptParams() {
69
70   export USE_CCACHE=0
71   export USE_CLANG=0
72   export FORCE_JHBUILD=0
73   export SKIP_NINJA=0
74   export BUILD_EWK_UNITTESTS=0
75   export BUILD_CONTENT_SHELL=1
76   export BUILD_SUBDIRECTORY=Release
77   export COMPONENT_BUILD=0
78
79   local platform="$1"
80   shift
81
82   while [[ $# > 0 ]]; do
83     case "$1" in
84       -h|--help)
85         hostBuldScriptUsage ${0}
86         ;;
87       --skip-gn)
88         export SKIP_GN=1
89         ;;
90       --ccache)
91         echo using ccache
92         export USE_CCACHE=1
93         source $TOPDIR/tizen_src/build/ccache_env.sh ${platform}
94         ;;
95       --clang)
96         export USE_CLANG=1
97         ;;
98       --no-content-shell)
99         export BUILD_CONTENT_SHELL=0
100         ;;
101       --force-jhbuild)
102         export FORCE_JHBUILD=1
103         ;;
104       --skip-ninja)
105         export SKIP_NINJA=1
106         ;;
107       --build-ewk-unittests)
108         export BUILD_EWK_UNITTESTS=1
109         ;;
110       --debug)
111         export BUILD_SUBDIRECTORY="Debug"
112         ;;
113       --component-build)
114         export COMPONENT_BUILD=1
115         ;;
116       -j*)
117         export JOBS="$1"
118         ;;
119       *)
120         echo "Unknown argument: $1"
121         exit 1
122         ;;
123     esac
124     shift;
125   done
126 }
127
128 function hostGnChromiumEfl() {
129   if [[ $SKIP_GN != 1 ]]; then
130     local XWALK_ARG=""
131     local COMPONENT_ARG=""
132     if [[ $COMPONENT_BUILD == 1 ]]; then
133       COMPONENT_ARG="component=shared_library"
134     fi
135     ${TOPDIR}/tizen_src/build/gn_chromiumefl.sh \
136       $XWALK_ARG \
137       $COMPONENT_ARG \
138       "outdir=\"$TOPDIR/out.$(getHostArch)\"" \
139       "chromium_efl_tizen_version=30" \
140       $@
141   fi
142 }
143
144 function hostNinja() {
145   if [[ $SKIP_NINJA == 0 ]]; then
146     TARGETS="chromium-ewk efl_webprocess efl_webview_app ubrowser"
147     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
148       TARGETS="$TARGETS ewk_unittests"
149     fi
150     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
151       TARGETS="$TARGETS content_shell dump_syms minidump_stackwalk"
152     fi
153     if [[ $BUILD_CHROMEDRIVER == 1 ]]; then
154       TARGETS="$TARGETS chromedriver"
155     fi
156     export BUILD_SUBDIRECTORY=""
157     BUILDDIR=${GN_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
158     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
159   fi
160 }
161
162 function error_report() {
163   echo "Error: File:$1 Line:$2"
164   exit 1
165 }
166
167 function findElementInArray() {
168   local elm
169   for elm in "${@:2}"; do
170     [[ "$elm" = "$1" ]] && return 0;
171   done
172   return 1;
173 }
174
175 function setupAndExecuteTargetBuild() {
176   local platform="$1"
177   shift
178
179   local PROFILE
180   local ARCHITECTURE
181   local CONF_FLAG
182   local -a ARGS
183
184   local count=0
185   local exclusive_options=0
186   local RPMLINT=0
187   local NOINIT=0
188   local MIRROR=0
189
190   # "|| :" means "or always succeeding built-in command"
191   PROFILE=$(echo "$@" | grep -Po "(?<=\-P\s)[^\s]*" | uniq || :)
192   ARCHITECTURE=$(echo "$@" | grep -Po "(?<=\-A\s)[^\s]*" | uniq || :)
193
194   while [[ $# > 0 ]]; do
195     count=$(( $count + 1 ))
196     case "$1" in
197     --debug)
198         ARGS[$count]=--define
199         count=$(( $count + 1 ))
200         ARGS[$count]="_debug_mode 1"
201     ;;
202     --skip-ninja)
203         ARGS[$count]=--define
204         count=$(( $count + 1 ))
205         ARGS[$count]="_skip_ninja 1"
206     ;;
207     --skip-gn)
208         ARGS[$count]=--define
209         count=$(( $count + 1 ))
210         ARGS[$count]="_skip_gn 1"
211     ;;
212     --component-build)
213         ARGS[$count]=--define
214         count=$(( $count + 1 ))
215         ARGS[$count]="component_build 1"
216     ;;
217     --gbs-debug)
218         ARGS[$count]=--debug
219     ;;
220     --rpmlint)
221         RPMLINT=1
222         count=$(( $count + 1 ))
223     ;;
224     --noinit)
225         NOINIT=1
226         ARGS[$count]="$1"
227         count=$(( $count + 1 ))
228     ;;
229     --mirror)
230         MIRROR=1
231     ;;
232     --standard*)
233         if [ "$DEFAULT_TIZEN_VERSION" == "" ]; then
234           echo $1
235           PROFILE=tz_$(echo $1 | sed 's/--//g')
236         elif [ "$DEFAULT_TIZEN_VERSION" == "4.0" ]; then
237           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')_$(echo $ARCHITECTURE | grep "i586" -q && echo "ia32" || echo $ARCHITECTURE)
238         else
239           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')
240         fi
241     ;;
242     --emulator*)
243         if [ "$DEFAULT_TIZEN_VERSION" == "" ]; then
244           PROFILE=tz_$(echo $1 | sed 's/--//g')
245         elif [ "$DEFAULT_TIZEN_VERSION" == "4.0" ]; then
246           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')_$(echo $ARCHITECTURE | grep "i586" -q && echo "ia32" || echo $ARCHITECTURE)
247         else
248           PROFILE=tz_${DEFAULT_TIZEN_VERSION}_$(echo $1 | sed 's/--//g')
249         fi
250     ;;
251     --tizen*)
252     ;;
253     *)
254       ARGS[$count]="$1"
255     ;;
256     esac
257     shift;
258   done
259
260   if [ "$exclusive_options" -gt 1 ]; then
261     echo "ERROR: --libs and --crosswalk-bin are mutually exclusive parameters."
262     exit 1
263   fi
264
265   if [ "$target" == "libs" ]; then
266     SPEC_FILE="chromium-efl-libs.spec"
267   elif [ "$target" == "crosswalk-bin" ]; then
268     SPEC_FILE="crosswalk-bin.spec"
269   fi
270
271   if [ "$PROFILE" == "" ]; then
272     if [[ $platform == "mobile" ]]; then
273       PROFILE=tzmb_3.0_target-TM1
274     elif [[ $platform == "tv" ]]; then
275       if [ "$DEFAULT_TIZEN_VERSION" == "" ]; then
276         PROFILE=tztv_arm-kantm
277       else
278         PROFILE=tztv_${DEFAULT_TIZEN_VERSION}_arm-kantm
279       fi
280     elif [[ $platform == "da" ]]; then
281       if [ "$DEFAULT_TIZEN_VERSION" == "" ]; then
282         PROFILE=tzda_arm-kantm
283       else
284         PROFILE=tzda_${DEFAULT_TIZEN_VERSION}_arm-kantm
285       fi
286     else
287       echo "Cannot set default PROFILE for platform=${platform}"
288       exit 1
289     fi
290   fi
291
292   if [ "$MIRROR" == "1" ]; then
293     PROFILE=${PROFILE}_mirror
294   fi
295
296   echo "Set the profile : $PROFILE"
297
298   if [ "$ARCHITECTURE" == "" ]; then
299     if [[ $platform == "mobile" ]]; then
300       ARCHITECTURE=armv7l
301     elif [[ $platform == "mobile_emulator" ]]; then
302       ARCHITECTURE=i586
303     elif [[ $platform == "tv" ]]; then
304       ARCHITECTURE=armv7l
305     elif [[ $platform == "tv_emulator" ]]; then
306       ARCHITECTURE=i586
307     else
308       echo "Cannot set default ARCHITECTURE for platform=${platform}"
309       exit 1
310     fi
311   fi
312   echo "Set the architecture : $ARCHITECTURE"
313
314   if [ "$USE_GLOBAL_GBS_CONF" == "" ]; then
315     CONF_FLAG="--conf ${SCRIPTDIR}/gbs.conf"
316   fi
317
318   EXTRA_PACK_OPTS=""
319   if [ "$PROFILE" == "tztv_v2.4_product" ]; then
320     EXTRA_PACK_OPTS="--extra-packs python-base-x86-arm,python-x86-arm,python-xml-x86-arm"
321   fi
322
323   if [ "$(echo "${PROFILE}" | grep -P "kant|jazz|hawk|product")" == "" -a "$NOINIT" == 0 ]; then
324     processRpmlintOption $PROFILE $RPMLINT
325   fi
326
327   gbs $CONF_FLAG build -P $PROFILE --include-all -A $ARCHITECTURE "${ARGS[@]}" $BUILD_CONF_OPTS $EXTRA_PACK_OPTS --incremental
328 }
329
330 function processRpmlintOption() {
331   local PROFILE=$1
332   local RPMLINT=$2
333   local URL_TARGET=
334   export BUILD_CONF_OPTS=
335
336   echo "** Process rpmlint option"
337
338   local PREVIOUS_RPMLINT="!rpmlint"
339   if [ ! -f "$PREVIOUS_BUILD_CONF_PATH" ]; then
340     # Never built before
341     PREVIOUS_RPMLINT=""
342   elif [ "$(grep -Po "\!rpmlint" "$PREVIOUS_BUILD_CONF_PATH" | uniq -d)" != "!rpmlint" ]; then
343     # Once built with rpmlint
344     PREVIOUS_RPMLINT="rpmlint"
345   fi
346
347   # Disable rpmlint
348   if [ "$RPMLINT" == 0 ]; then
349     echo "** Disable rpmlint"
350     BUILD_CONF_DIR=$SCRIPTDIR/build_conf
351     rm -rf $BUILD_CONF_DIR
352     mkdir $BUILD_CONF_DIR
353     URL_TARGET=$(echo $PROFILE | sed -e 's#.*\.[0-9]*_\([-a-zA-Z0-9]*\).*#\1#;s/tz_//g')
354     # The latest version doesn't have tizen version in snapshot repository url.
355     if [ "$(echo $DEFAULT_TIZEN_VERSION)" == "" ]; then
356       URL_TIZEN_VERSION=
357     else
358       URL_TIZEN_VERSION=$DEFAULT_TIZEN_VERSION-
359     fi
360     REPO=http://download.tizen.org/snapshots/tizen/$URL_TIZEN_VERSION$platform/latest/repos/$URL_TARGET/packages/repodata/
361     echo "** Repo : $REPO"
362     wget $REPO -O $BUILD_CONF_DIR/index.html > /dev/null 2>&1
363     BUILD_CONF_GZ=$(grep "build.conf.gz" $BUILD_CONF_DIR/index.html | sed -e 's#.*\=\"\(.*\)\".*#\1#')
364     BUILD_CONF=$(basename $BUILD_CONF_GZ .gz)
365     wget $REPO$BUILD_CONF_GZ -P $BUILD_CONF_DIR > /dev/null 2>&1
366     if [ ! -f "$BUILD_CONF_DIR/$BUILD_CONF_GZ" ]; then
367       echo "It's failed to donwload build.conf. Please contact system administrator."
368       exit 1
369     fi
370     gunzip $BUILD_CONF_DIR/$BUILD_CONF_GZ
371     sed -i 's/rpmlint-mini\ rpmlint-tizen/!rpmlint-mini\ !rpmlint-tizen/g' $BUILD_CONF_DIR/$BUILD_CONF
372     BUILD_CONF_OPTS="-D $BUILD_CONF_DIR/$BUILD_CONF"
373     if [ "$PREVIOUS_RPMLINT" == "rpmlint" ]; then
374       echo "** Once built with rpmlint"
375       BUILD_CONF_OPTS+=" --clean"
376     fi
377   else # Enable rpmlint
378     echo "** Enable rpmlint"
379     BUILD_CONF_OPTS=""
380     if [ "$PREVIOUS_RPMLINT" == "!rpmlint" ]; then
381       BUILD_CONF_OPTS="--clean"
382     fi
383   fi
384 }