[M108 Migration][MM] Migrate AudioIO related patches
[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_audio_io=true
225                              tizen_web_speech_recognition=true
226                              tizen_tbm_support=true
227                             "
228 }
229
230 add_wayland_flags() {
231   if [ "$use_wayland" == "true" ]; then
232     ADDITIONAL_GN_PARAMETERS+="use_wayland=true
233                                wayland_bringup=true
234                               "
235   else
236     ADDITIONAL_GN_PARAMETERS+="use_wayland=false
237                                wayland_bringup=false
238                               "
239   fi
240 }
241
242 add_gbs_flags() {
243   # To reduce binary size, O2 is only applied to major components
244   # and Os is applied to the others.
245   local lto_level="s"
246
247   if [ "$is_clang" == "true" ]; then
248    lto_level="z"
249   fi
250
251   ADDITIONAL_GN_PARAMETERS+="lto_level=\"$lto_level\"
252                             "
253
254   # TODO(youngsoo):
255   # Due to large file size issue of libchromium-ewk.so,
256   # The symbol level is set to 1 by default.
257   # Once the issue is fixed, set it to the level from platform.
258   local symbol_level=$(echo " $CFLAGS" | sed -e 's#.* -g\([0-9]\).*#\1#')
259   if [ "$host_arch" == "x86" ]; then
260     symbol_level="0"
261   elif [ "$symbol_level" != "0" ]; then
262     symbol_level="1"
263   fi
264
265   if [[ $symbol_level =~ ^[0-9]$ ]]; then
266     ADDITIONAL_GN_PARAMETERS+="symbol_level=$symbol_level
267                               "
268   else
269     ADDITIONAL_GN_PARAMETERS+="symbol_level=1
270                               "
271   fi
272   # target_arch changed to target_cpu but not changed because it seems that
273   # it is used for gbs and added target_cpu also.
274   ADDITIONAL_GN_PARAMETERS+="target_cpu=\"${host_arch}\"
275                             "
276 }
277
278 add_cross_flags() {
279   # target_arch changed to target_cpu but not changed because it seems that
280   # it is used for gbs and added target_cpu also.
281   ADDITIONAL_GN_PARAMETERS+="target_cpu=\"arm\"
282                              sysroot=\"$SYSROOTDIR\"
283                              arm_tune=\"arm7\"
284                             "
285
286   # Compiling yasm with crosscompile + icecc leads to some strange errors (one file is built for target instead of host).
287   # Yasm is an assembler used only by the build (not at runtime) and it is generally available in Linux distros so let's just
288   # use it from the system.
289   ADDITIONAL_GN_PARAMETERS+="use_system_yasm=true"
290 }
291
292 if [ "$target" == "desktop" ]; then
293   add_desktop_flags
294 else
295   add_tizen_flags
296   if [ "$host_arch" == "arm" -o "$host_arch" == "arm64" ]; then
297     add_arm_flags
298   elif [ "$host_arch" == "x86" -o "$host_arch" == "x64" ]; then
299     add_emulator_flags
300   fi
301   if [ "$buildType" == "gbs" ]; then
302     add_gbs_flags
303   elif [ "$buildType" == "crosscompile" ]; then
304     add_cross_flags
305   fi
306 fi
307
308 if [ "$system_deps" != "" ]; then
309   echo "** use system lib : replace **"
310   #replacing original files with correct ones according to $system_deps
311   $TOPDIR/build/linux/unbundle/replace_gn_files.py $system_deps
312 fi
313
314 _GN_ARGS="
315     gen
316     $GN_GENERATOR_FLAG
317     --root=${TOPDIR}
318     --dotfile=${TOPDIR}/tizen_src/.gn
319     --args=
320     $COMMON_GN_PARAMETERS
321     $ADDITIONAL_GN_PARAMETERS
322     $EXTRA_GN_ARGS
323     "
324
325 echo $target > target.txt
326 echo $target > third_party/node/target.txt
327
328 printf "GN_ARGUMENTS:\n"
329 for arg in $_GN_ARGS; do
330   printf "    * ${arg##-D}\n"
331 done
332 for arg in $system_deps; do
333   printf "    * ${arg##-D}\n"
334 done
335
336 ${TOPDIR}/tizen_src/build/gn_chromiumefl \
337     ${_GN_ARGS}
338
339 ret=$?
340
341 exit $ret