[M108 Migration][MM] Migrate Tbm feature for Tizen Multimedia
[platform/framework/web/chromium-efl.git] / tizen_src / build / gn_chromiumefl.sh
1 #!/bin/bash
2
3 tizen_build_conf="/etc/tizen-build.conf"
4 get_profile() {
5   local profile=
6   # TV has something different.
7   if [ ! -f "$tizen_build_conf" ]; then
8     profile=desktop
9   elif [ "$(grep "TZ_BUILD_PROJECT" "$tizen_build_conf" | grep "Unified")" != "" ]; then
10     profile=unified
11   elif [ "$(grep "TZ_BUILD_RELEASE_NAME" "$tizen_build_conf" | grep "TV")" != "" ]; then
12     profile=tv
13   elif [ "$(grep "TZ_BUILD_PROJECT" "$tizen_build_conf" | grep "Wearable")" != "" ]; then
14     profile=wearable
15   elif [ "$(grep "TZ_BUILD_PROJECT" "$tizen_build_conf" | grep "DA")" != "" ]; then
16     profile=da
17   else
18     echo "There isn't proper profile."
19     return 1;
20   fi
21   echo $profile
22 }
23
24 get_tizen_version() {
25   echo $(grep "TZ_BUILD_VERSION" "$tizen_build_conf" | sed -e "s/TZ_BUILD_VERSION=//g")
26 }
27
28 source $(dirname $0)/common.sh --tizen_$(get_tizen_version)
29 trap 'error_report $0 $LINENO' ERR SIGINT SIGTERM SIGQUIT
30 host_arch=$(getHostArch)
31 system_deps=$(getSystemDeps $(get_profile))
32 export HOST_ARCH=$host_arch
33
34 supported_targets=("tizen" "desktop")
35
36 if [ -z "$GN_GENERATOR_OUTPUT" ]; then
37   GN_GENERATOR_OUTPUT="out.${host_arch}"
38 fi
39
40 echo ${host_arch}
41 echo $GN_GENERATOR_OUTPUT
42
43 if [ -z "$GN_GENERATOR_FLAG" ]; then
44   export GN_GENERATOR_FLAG=$GN_GENERATOR_OUTPUT
45 fi
46
47 EXTRA_GN_ARGS="$@"
48
49 # __GN_CHROMIUMEFL_TARGET is defined when we are called from build_desktop.sh.
50 # Otherwise we are called by gbs which already passes the is_tizen flag.
51 if [ "$__GN_CHROMIUMEFL_TARGET" == "desktop" ]; then
52   target=desktop
53 fi
54
55 while [[ $# > 0 ]]; do
56   case "$1" in
57     is_tizen=true)
58       buildType="gbs"
59       target="tizen"
60       ;;
61     tizen_version=*)
62       tizen_version=$(echo $1 | sed -e 's#tizen_version\=\([0-9.]*\)#\1#')
63       ;;
64     tizen_emulator_support=true)
65       tizen_emulator_support=true
66       ;;
67     tizen_product_tv=true)
68       tizen_product_tv=true
69       ;;
70     tizen_product_da=true)
71       tizen_product_da=true
72       ;;
73     use_system_icu=true)
74       system_deps=("${system_deps[@]/icu/}")
75       system_deps+=" icu"
76       ;;
77     use_system_icu=false)
78       system_deps=("${system_deps[@]/icu/}")
79       ;;
80     is_clang=true)
81       is_clang=true
82       ;;
83   esac
84   shift;
85 done
86
87 findElementInArray "$target" "${supported_targets[@]}"
88 if [[ $? == 1 ]]; then
89   echo "Unsupported target: $target"
90   exit 1
91 fi
92
93 if [ "$__GN_CHROMIUMEFL_TARGET" == "crosscompile" ]; then
94   buildType=crosscompile
95   EXTRA_GN_ARGS+=" edje_compiler=${TOPDIR}/out.${host_arch}/Dependencies/Root/bin/edje_cc"
96 fi
97
98 ORIGINAL_GN_DEFINES="$GN_DEFINES"
99 export GN_DEFINES=$(echo "$GN_DEFINES" | sed -e 's/component\s*=\s*shared_library//g')
100 if [ "$ORIGINAL_GN_DEFINES" != "$GN_DEFINES" ]; then
101     echo "WARNING: component build is not supported."
102     echo "Removing component=shared_library from GN_DEFINES."
103 fi
104
105 COMMON_GN_PARAMETERS="use_libjpeg_turbo=true
106                       rtc_enable_sctp=false
107                       use_alsa=false
108                       use_aura=true
109                       use_kerberos=false
110                       use_ozone=true
111                       toolkit_views=true
112                       use_pango=false
113                       use_cairo=false
114                       enable_plugins=true
115                       enable_extensions=true
116                       use_cups=false
117                       use_allocator=\"none\"
118                       depth=\"${TOPDIR}\"
119                       use_libpci=false
120                      "
121
122 add_desktop_flags() {
123   local is_clang=false
124   if [ $USE_CLANG == 1 ]; then
125     is_clang=true
126   else
127      ADDITIONAL_GN_PARAMETERS+="use_system_libjpeg=true
128                                "
129   fi
130
131   local build_chrome=false
132   if [ $BUILD_CHROME == 1 ]; then
133     build_chrome=true
134   fi
135
136   ADDITIONAL_GN_PARAMETERS+="gcc_ver=\"$(getGccVersion)\"
137                              is_clang=${is_clang}
138                              is_tizen=false
139                              target_cpu=\"${host_arch}\"
140                              target_os="\"linux\""
141                              use_sysroot=false
142                              use_wayland=false
143                              werror=false
144                              dcheck_always_on=false
145                              enable_nacl=false
146                              build_chrome=${build_chrome}
147                             "
148 }
149
150 add_arm_flags() {
151   ADDITIONAL_GN_PARAMETERS+="arm_use_neon=false
152                             "
153   if [ "$host_arch" == "arm64" ]; then
154     ADDITIONAL_GN_PARAMETERS+="system_libdir=\"lib64\"
155                                deps_lib_path=\"/usr/lib64\"
156                               "
157   fi
158 }
159
160 add_emulator_flags() {
161   if [ "$host_arch" == "x64" ]; then
162     ADDITIONAL_GN_PARAMETERS+="system_libdir=\"lib64\"
163                                deps_lib_path=\"/usr/lib64\"
164                               "
165   fi
166 }
167
168 add_tizen_flags() {
169   ADDITIONAL_GN_PARAMETERS+="is_tizen=true
170                              use_zygote_handle=true
171                              gcc_ver=\"$(getGccVersion)\"
172                              python_ver=\"$(getPythonVersion)\"
173                              is_official_build=true
174                              enable_nacl=false
175                              enable_basic_printing=true
176                              enable_print_preview=true
177                              use_xkbcommon=true
178                              target_os="\"tizen\""
179                              target_sysroot=\"/\"
180                              current_cpu=\"${host_arch}\"
181                              host_cpu=\"${host_arch}\"
182                              target_cpu=\"${host_arch}\"
183                              use_real_dbus_clients=false
184                              use_nss_certs=true
185                              use_system_libwayland=true
186                             "
187
188   # FIXME : Note that the v8_snapshot_toolchain has been set to wrong
189   # toolchain clang in x64 build even is_clang is false.
190   # This sets it to toolchain gcc forcibly as workaround.
191   # It needs to be set to the toolchain gcc under is_clang is false.
192   if [ "$host_arch" == "x64" ]; then
193     ADDITIONAL_GN_PARAMETERS+="v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_x64\"
194                               "
195   fi
196
197   if [ "$is_clang" == "true" ]; then
198     ADDITIONAL_GN_PARAMETERS+="host_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_clang_$host_arch\"
199                                v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_clang_$host_arch\"
200                                use_lld=true
201                                use_thin_lto=true
202                               "
203   else
204     ADDITIONAL_GN_PARAMETERS+="host_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_$host_arch\"
205                                v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_$host_arch\"
206                                use_system_libjpeg=true
207                               "
208   fi
209
210   if [[ "${system_deps[@]}" =~ "icu" ]]; then
211     ADDITIONAL_GN_PARAMETERS+="icu_use_data_file=false
212                                use_system_icu=true
213                               "
214                 processICU replace_icu
215   else
216     ADDITIONAL_GN_PARAMETERS+="icu_use_data_file=true
217                               "
218   fi
219
220   # [M49_2623] Temporary disabling the flag.
221   #            FIXME: http://165.213.149.170/jira/browse/TWF-610
222   ADDITIONAL_GN_PARAMETERS+="tizen_multimedia=true
223                              proprietary_codecs=true
224                              tizen_web_speech_recognition=true
225                              tizen_tbm_support=true
226                             "
227 }
228
229 add_wayland_flags() {
230   if [ "$use_wayland" == "true" ]; then
231     ADDITIONAL_GN_PARAMETERS+="use_wayland=true
232                                wayland_bringup=true
233                               "
234   else
235     ADDITIONAL_GN_PARAMETERS+="use_wayland=false
236                                wayland_bringup=false
237                               "
238   fi
239 }
240
241 add_gbs_flags() {
242   # To reduce binary size, O2 is only applied to major components
243   # and Os is applied to the others.
244   local lto_level="s"
245
246   if [ "$is_clang" == "true" ]; then
247    lto_level="z"
248   fi
249
250   ADDITIONAL_GN_PARAMETERS+="lto_level=\"$lto_level\"
251                             "
252
253   # TODO(youngsoo):
254   # Due to large file size issue of libchromium-ewk.so,
255   # The symbol level is set to 1 by default.
256   # Once the issue is fixed, set it to the level from platform.
257   local symbol_level=$(echo " $CFLAGS" | sed -e 's#.* -g\([0-9]\).*#\1#')
258   if [ "$host_arch" == "x86" ]; then
259     symbol_level="0"
260   elif [ "$symbol_level" != "0" ]; then
261     symbol_level="1"
262   fi
263
264   if [[ $symbol_level =~ ^[0-9]$ ]]; then
265     ADDITIONAL_GN_PARAMETERS+="symbol_level=$symbol_level
266                               "
267   else
268     ADDITIONAL_GN_PARAMETERS+="symbol_level=1
269                               "
270   fi
271   # target_arch changed to target_cpu but not changed because it seems that
272   # it is used for gbs and added target_cpu also.
273   ADDITIONAL_GN_PARAMETERS+="target_cpu=\"${host_arch}\"
274                             "
275 }
276
277 add_cross_flags() {
278   # target_arch changed to target_cpu but not changed because it seems that
279   # it is used for gbs and added target_cpu also.
280   ADDITIONAL_GN_PARAMETERS+="target_cpu=\"arm\"
281                              sysroot=\"$SYSROOTDIR\"
282                              arm_tune=\"arm7\"
283                             "
284
285   # Compiling yasm with crosscompile + icecc leads to some strange errors (one file is built for target instead of host).
286   # Yasm is an assembler used only by the build (not at runtime) and it is generally available in Linux distros so let's just
287   # use it from the system.
288   ADDITIONAL_GN_PARAMETERS+="use_system_yasm=true"
289 }
290
291 if [ "$target" == "desktop" ]; then
292   add_desktop_flags
293 else
294   add_tizen_flags
295   if [ "$host_arch" == "arm" -o "$host_arch" == "arm64" ]; then
296     add_arm_flags
297   elif [ "$host_arch" == "x86" -o "$host_arch" == "x64" ]; then
298     add_emulator_flags
299   fi
300   if [ "$buildType" == "gbs" ]; then
301     add_gbs_flags
302   elif [ "$buildType" == "crosscompile" ]; then
303     add_cross_flags
304   fi
305 fi
306
307 if [ "$system_deps" != "" ]; then
308   echo "** use system lib : replace **"
309   #replacing original files with correct ones according to $system_deps
310   $TOPDIR/build/linux/unbundle/replace_gn_files.py $system_deps
311 fi
312
313 _GN_ARGS="
314     gen
315     $GN_GENERATOR_FLAG
316     --root=${TOPDIR}
317     --dotfile=${TOPDIR}/tizen_src/.gn
318     --args=
319     $COMMON_GN_PARAMETERS
320     $ADDITIONAL_GN_PARAMETERS
321     $EXTRA_GN_ARGS
322     "
323
324 echo $target > target.txt
325 echo $target > third_party/node/target.txt
326
327 printf "GN_ARGUMENTS:\n"
328 for arg in $_GN_ARGS; do
329   printf "    * ${arg##-D}\n"
330 done
331 for arg in $system_deps; do
332   printf "    * ${arg##-D}\n"
333 done
334
335 ${TOPDIR}/tizen_src/build/gn_chromiumefl \
336     ${_GN_ARGS}
337
338 ret=$?
339
340 exit $ret