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