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