Enable chrome with aura for tizen
[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                       proprietary_codecs=false
107                       rtc_enable_sctp=false
108                       use_alsa=false
109                       use_aura=true
110                       use_kerberos=false
111                       use_ozone=true
112                       toolkit_views=true
113                       use_pango=false
114                       use_cairo=false
115                       enable_plugins=true
116                       enable_extensions=true
117                       use_cups=false
118                       use_allocator=\"none\"
119                       depth=\"${TOPDIR}\"
120                       use_libpci=false
121                      "
122
123 add_desktop_flags() {
124   local is_clang=false
125   if [ $USE_CLANG == 1 ]; then
126     is_clang=true
127   else
128      ADDITIONAL_GN_PARAMETERS+="use_system_libjpeg=true
129                                "
130   fi
131   ADDITIONAL_GN_PARAMETERS+="gcc_ver=\"$(getGccVersion)\"
132                              is_clang=${is_clang}
133                              is_tizen=false
134                              target_cpu=\"${host_arch}\"
135                              target_os="\"linux\""
136                              use_sysroot=false
137                              use_wayland=false
138                              werror=false
139                              dcheck_always_on=false
140                              enable_nacl=false
141                             "
142 }
143
144 add_arm_flags() {
145   ADDITIONAL_GN_PARAMETERS+="arm_use_neon=false
146                             "
147   if [ "$host_arch" == "arm64" ]; then
148     ADDITIONAL_GN_PARAMETERS+="system_libdir=\"lib64\"
149                                deps_lib_path=\"/usr/lib64\"
150                               "
151   fi
152 }
153
154 add_emulator_flags() {
155   if [ "$host_arch" == "x64" ]; then
156     ADDITIONAL_GN_PARAMETERS+="system_libdir=\"lib64\"
157                                deps_lib_path=\"/usr/lib64\"
158                               "
159   fi
160 }
161
162 add_tizen_flags() {
163   ADDITIONAL_GN_PARAMETERS+="is_tizen=true
164                              use_zygote_handle=true
165                              gcc_ver=\"$(getGccVersion)\"
166                              python_ver=\"$(getPythonVersion)\"
167                              is_official_build=true
168                              enable_nacl=false
169                              enable_basic_printing=true
170                              enable_print_preview=true
171                              tizen_multimedia_eme_support=false
172                              use_xkbcommon=true
173                              target_os="\"tizen\""
174                              target_sysroot=\"/\"
175                              current_cpu=\"${host_arch}\"
176                              host_cpu=\"${host_arch}\"
177                              target_cpu=\"${host_arch}\"
178                              use_real_dbus_clients=false
179                              use_nss_certs=true
180                              use_system_libwayland=true
181                             "
182
183   # FIXME : Note that the v8_snapshot_toolchain has been set to wrong
184   # toolchain clang in x64 build even is_clang is false.
185   # This sets it to toolchain gcc forcibly as workaround.
186   # It needs to be set to the toolchain gcc under is_clang is false.
187   if [ "$host_arch" == "x64" ]; then
188     ADDITIONAL_GN_PARAMETERS+="v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_x64\"
189                               "
190   fi
191
192   if [ "$is_clang" == "true" ]; then
193     ADDITIONAL_GN_PARAMETERS+="host_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_clang_$host_arch\"
194                                v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_clang_$host_arch\"
195                                use_lld=true
196                                use_thin_lto=true
197                               "
198   else
199     ADDITIONAL_GN_PARAMETERS+="host_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_$host_arch\"
200                                v8_snapshot_toolchain=\"//tizen_src/build/toolchain/tizen:tizen_$host_arch\"
201                                use_system_libjpeg=true
202                               "
203   fi
204
205   if [[ "${system_deps[@]}" =~ "icu" ]]; then
206     ADDITIONAL_GN_PARAMETERS+="icu_use_data_file=false
207                                use_system_icu=true
208                               "
209                 processICU replace_icu
210   else
211     ADDITIONAL_GN_PARAMETERS+="icu_use_data_file=true
212                               "
213   fi
214
215   # [M49_2623] Temporary disabling the flag.
216   #            FIXME: http://165.213.149.170/jira/browse/TWF-610
217   ADDITIONAL_GN_PARAMETERS+="tizen_multimedia_support=false
218                              tizen_tbm_support=false
219                             "
220 }
221
222 add_wayland_flags() {
223   if [ "$use_wayland" == "true" ]; then
224     ADDITIONAL_GN_PARAMETERS+="use_wayland=true
225                                wayland_bringup=true
226                               "
227   else
228     ADDITIONAL_GN_PARAMETERS+="use_wayland=false
229                                wayland_bringup=false
230                               "
231   fi
232 }
233
234 add_gbs_flags() {
235   # To reduce binary size, O2 is only applied to major components
236   # and Os is applied to the others.
237   local lto_level="s"
238
239   if [ "$is_clang" == "true" ]; then
240    lto_level="z"
241   fi
242
243   ADDITIONAL_GN_PARAMETERS+="lto_level=\"$lto_level\"
244                             "
245
246   # TODO(youngsoo):
247   # Due to large file size issue of libchromium-ewk.so,
248   # The symbol level is set to 1 by default.
249   # Once the issue is fixed, set it to the level from platform.
250   local symbol_level=$(echo " $CFLAGS" | sed -e 's#.* -g\([0-9]\).*#\1#')
251   if [ "$host_arch" == "x86" ]; then
252     symbol_level="0"
253   elif [ "$symbol_level" != "0" ]; then
254     symbol_level="1"
255   fi
256
257   if [[ $symbol_level =~ ^[0-9]$ ]]; then
258     ADDITIONAL_GN_PARAMETERS+="symbol_level=$symbol_level
259                               "
260   else
261     ADDITIONAL_GN_PARAMETERS+="symbol_level=1
262                               "
263   fi
264   # target_arch changed to target_cpu but not changed because it seems that
265   # it is used for gbs and added target_cpu also.
266   ADDITIONAL_GN_PARAMETERS+="target_cpu=\"${host_arch}\"
267                             "
268 }
269
270 add_cross_flags() {
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=\"arm\"
274                              sysroot=\"$SYSROOTDIR\"
275                              arm_tune=\"arm7\"
276                             "
277
278   # Compiling yasm with crosscompile + icecc leads to some strange errors (one file is built for target instead of host).
279   # Yasm is an assembler used only by the build (not at runtime) and it is generally available in Linux distros so let's just
280   # use it from the system.
281   ADDITIONAL_GN_PARAMETERS+="use_system_yasm=true"
282 }
283
284 if [ "$target" == "desktop" ]; then
285   add_desktop_flags
286 else
287   add_tizen_flags
288   if [ "$host_arch" == "arm" -o "$host_arch" == "arm64" ]; then
289     add_arm_flags
290   elif [ "$host_arch" == "x86" -o "$host_arch" == "x64" ]; then
291     add_emulator_flags
292   fi
293   if [ "$buildType" == "gbs" ]; then
294     add_gbs_flags
295   elif [ "$buildType" == "crosscompile" ]; then
296     add_cross_flags
297   fi
298 fi
299
300 if [ "$system_deps" != "" ]; then
301   echo "** use system lib : replace **"
302   #replacing original files with correct ones according to $system_deps
303   $TOPDIR/build/linux/unbundle/replace_gn_files.py $system_deps
304 fi
305
306 _GN_ARGS="
307     gen
308     $GN_GENERATOR_FLAG
309     --root=${TOPDIR}
310     --dotfile=${TOPDIR}/tizen_src/.gn
311     --args=
312     $COMMON_GN_PARAMETERS
313     $ADDITIONAL_GN_PARAMETERS
314     $EXTRA_GN_ARGS
315     "
316
317 echo $target > target.txt
318 echo $target > third_party/node/target.txt
319
320 printf "GN_ARGUMENTS:\n"
321 for arg in $_GN_ARGS; do
322   printf "    * ${arg##-D}\n"
323 done
324 for arg in $system_deps; do
325   printf "    * ${arg##-D}\n"
326 done
327
328 ${TOPDIR}/tizen_src/build/gn_chromiumefl \
329     ${_GN_ARGS}
330
331 ret=$?
332
333 exit $ret