Make it possible to compile chromium-efl on desktop using clang
[platform/framework/web/chromium-efl.git] / tizen_src / build / common.sh
1 #!/bin/bash
2
3 pushd `dirname $0` > /dev/null
4 export SCRIPTDIR=`pwd -L`
5 popd > /dev/null
6
7 export TOPDIR=$(readlink -f "${SCRIPTDIR}/..")
8 if [[ -z "${CHROME_SRC}" ]]; then
9   # If $CHROME_SRC was not set, assume src subfolder in project directory is CHROME_SRC.
10   export CHROME_SRC="${TOPDIR}/src"
11 fi
12
13 export CLANG_DIR="${TOPDIR}/src/third_party/llvm-build/Release+Asserts/"
14
15 function applyPatch {
16   directory=$1
17   shift
18   patchfile=$1
19   shift
20   echo Applying $patchfile in $directory
21   pushd "$directory" > /dev/null
22   patch -p1 $@ < "$patchfile"
23   popd > /dev/null
24 }
25
26 function getHostOs() {
27   echo $(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
28 }
29
30 function getHostArch() {
31   echo $(uname -m | sed -e \
32         's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/')
33 }
34
35 function getPythonVersion() {
36   echo $(python --version  2>&1 | sed -e 's/Python \([0-9]\+\.[0-9]\+\)\.[0-9]\+/\1/')
37 }
38
39 function setIfUndef() {
40     eval original=\$$1
41     new=$2
42     if [ -n "$original" ]; then
43         echo $original
44     else
45         echo $new
46     fi
47 }
48
49
50 function hostBuldScriptUsage() {
51 cat << EOF
52 usage: $1 [OPTIONS]
53
54 Build non gbs version of chromium-efl
55
56 OPTIONS:
57    -h, --help            Show this message
58    --build-ewk-unittests Build ewk unittests
59    --ccache              Configure ccache installed in your system
60    --clang               Use chromium's clang compiler to build the sources
61    --content-shell       Build content_shell application
62    --debug               Build debug version of chromium-efl (out.${host_arch}/Debug instead of out.${host_arch}/Release)
63    -jN                   Set number of jobs, just like with make or ninja
64    --skip-gyp            Skip restore_gyp, jhbuild and gyp_chromium steps
65    --skip-ninja          Skip ninja step
66
67 examples:
68 $0 --skip-gyp
69 $0 --skip-gyp --ccache
70 $0 --skip-ninja
71 EOF
72   exit
73 }
74
75 function parseHostBuildScriptParams() {
76
77   export SKIP_GYP=0
78   export USE_CCACHE=0
79   export USE_CLANG=0
80   export FORCE_JHBUILD=0
81   export SKIP_NINJA=0
82   export BUILD_EWK_UNITTESTS=0
83   export BUILD_CONTENT_SHELL=0
84   export BUILD_SUBDIRECTORY=Release
85
86   local platform="$1"
87   shift
88
89   while [[ $# > 0 ]]; do
90     case "$1" in
91       -h|--help)
92         hostBuldScriptUsage ${0}
93         ;;
94       --skip-gyp)
95         export SKIP_GYP=1
96         ;;
97       --ccache)
98         echo using ccache
99         export USE_CCACHE=1
100         source $TOPDIR/build/ccache_env.sh ${platform}
101         ;;
102       --clang)
103         export USE_CLANG=1
104         ;;
105       --content-shell)
106         export BUILD_CONTENT_SHELL=1
107         ;;
108       --force-jhbuild)
109         export FORCE_JHBUILD=1
110         ;;
111       --skip-ninja)
112         export SKIP_NINJA=1
113         ;;
114       --build-ewk-unittests)
115         export BUILD_EWK_UNITTESTS=1
116         ;;
117       --debug)
118         export BUILD_SUBDIRECTORY="Debug"
119         ;;
120       -j*)
121         export JOBS="$1"
122         ;;
123       *)
124         echo "Unknown argument: $1"
125         exit 1
126         ;;
127     esac
128     shift;
129   done
130 }
131
132 function hostGypChromiumEfl() {
133   if [[ $SKIP_GYP == 0 ]]; then
134     ${TOPDIR}/build/gyp_chromiumefl.sh $@
135   fi
136 }
137
138 function hostNinja() {
139   if [[ $SKIP_NINJA == 0 ]]; then
140     TARGETS="chromium-efl efl_webprocess chromium-ewk efl_webview_app"
141     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
142       TARGETS="$TARGETS ewk_unittests"
143     fi
144     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
145       TARGETS="$TARGETS content_shell_efl"
146     fi
147     BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
148     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
149   fi
150 }
151
152 function error_report() {
153   echo "Error: File:$1 Line:$2"
154   exit 1
155 }