Minor improvements of desktop build scripts.
[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 function applyPatch {
14   directory=$1
15   shift
16   patchfile=$1
17   shift
18   echo Applying $patchfile in $directory
19   pushd "$directory" > /dev/null
20   patch -p1 $@ < "$patchfile"
21   popd > /dev/null
22 }
23
24 function getHostOs() {
25   echo $(uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
26 }
27
28 function getHostArch() {
29   echo $(uname -m | sed -e \
30         's/i.86/ia32/;s/x86_64/x64/;s/amd64/x64/;s/arm.*/arm/;s/i86pc/ia32/')
31 }
32
33 function getPythonVersion() {
34   echo $(python --version  2>&1 | sed -e 's/Python \([0-9]\+\.[0-9]\+\)\.[0-9]\+/\1/')
35 }
36
37 function setIfUndef() {
38     eval original=\$$1
39     new=$2
40     if [ -n "$original" ]; then
41         echo $original
42     else
43         echo $new
44     fi
45 }
46
47
48 function hostBuldScriptUsage() {
49 cat << EOF
50 usage: $1 [OPTIONS]
51
52 Build non gbs version of chromium-efl
53
54 OPTIONS:
55    -h, --help            Show this message
56    --build-ewk-unittests Build ewk unittests
57    --ccache              Configure ccache installed in your system
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 FORCE_JHBUILD=0
77   export SKIP_NINJA=0
78   export BUILD_EWK_UNITTESTS=0
79   export BUILD_CONTENT_SHELL=0
80   export BUILD_SUBDIRECTORY=Release
81
82   local platform="$1"
83   shift
84
85   while [[ $# > 0 ]]; do
86     case "$1" in
87       -h|--help)
88         hostBuldScriptUsage ${0}
89         ;;
90       --skip-gyp)
91         export SKIP_GYP=1
92         ;;
93       --ccache)
94         echo using ccache
95         export USE_CCACHE=1
96         source $TOPDIR/build/ccache_env.sh ${platform}
97         ;;
98       --content-shell)
99         export BUILD_CONTENT_SHELL=1
100         ;;
101       --force-jhbuild)
102         export FORCE_JHBUILD=1
103         ;;
104       --skip-ninja)
105         export SKIP_NINJA=1
106         ;;
107       --build-ewk-unittests)
108         export BUILD_EWK_UNITTESTS=1
109         ;;
110       --debug)
111         export BUILD_SUBDIRECTORY="Debug"
112         ;;
113       -j*)
114         export JOBS="$1"
115         ;;
116       *)
117         echo "Unknown argument: $1"
118         exit 1
119         ;;
120     esac
121     shift;
122   done
123 }
124
125 function hostGypChromiumEfl() {
126   if [[ $SKIP_GYP == 0 ]]; then
127     ${TOPDIR}/build/gyp_chromiumefl.sh $@
128   fi
129 }
130
131 function hostNinja() {
132   if [[ $SKIP_NINJA == 0 ]]; then
133     TARGETS="chromium-efl efl_webprocess chromium-ewk efl_webview_app"
134     if [[ $BUILD_EWK_UNITTESTS == 1 ]]; then
135       TARGETS="$TARGETS ewk_unittests"
136     fi
137     if [[ $BUILD_CONTENT_SHELL == 1 ]]; then
138       TARGETS="$TARGETS content_shell_efl"
139     fi
140     BUILDDIR=${GYP_GENERATOR_OUTPUT}/${BUILD_SUBDIRECTORY}
141     ninja -C $BUILDDIR ${JOBS} ${TARGETS}
142   fi
143 }
144
145 function error_report() {
146   echo "Error: File:$1 Line:$2"
147   exit 1
148 }