Fix parsing of txt record
[platform/core/api/vine.git] / build.sh
1 #!/bin/bash
2 BUILD_DIR="build"
3
4 function clean {
5         echo "Clean build directory"
6         rm -rf $BUILD_DIR
7 }
8
9 function build {
10         echo "Build vine library"
11         cd $BUILD_DIR
12         cmake .. -DLIB_DIR=/usr/lib -DINCLUDE_DIR=/usr/include -DBIN_DIR=/usr/bin \
13          -DWITH_UNITTEST=ON -DWITH_VINE_TEST=ON $1 $2
14         make
15         sudo make install
16         cd ..
17 }
18
19 function unittest {
20         echo "Test vine library"
21         ./$BUILD_DIR/tests/unittest/vine-unittest $1
22 }
23
24 function coding_rule {
25         git clone git@github.sec.samsung.net:RS-SA/coding-style-guides.git
26         chmod 777 ./coding-style-guides/c/*.sh ./coding-style-guides/c/*.pl
27         result_src+="$((`./coding-style-guides/c/checkpatchinit_tizen.sh src| tee /dev/tty | grep total | awk '{ sum+=$2+$4 }; END { print sum }'`))"
28         result_include+="$((`./coding-style-guides/c/checkpatchinit_tizen.sh include| tee /dev/tty | grep total | awk '{ sum+=$2+$4 }; END { print sum }'`))"
29         result_plugins+="$((`./coding-style-guides/c/checkpatchinit_tizen.sh plugins| tee /dev/tty | grep total | awk '{ sum+=$2+$4 }; END { print sum }'`))"
30         result=$(( $result_src + $result_include + $result_plugins ))
31         echo "result $result"
32         if [ "${result}" -gt "0" ]; then
33                 exit 1
34         fi
35 }
36
37 function install_certs {
38         echo "Installs test certificates"
39         cd $BUILD_DIR
40         cp -rf ../tests/vine-test/certs ./tests/vine-test/certs
41         cd tests/vine-test/certs
42         ./create-test-certs.sh
43         cd ../
44 }
45
46 MINSDKVERSION=24
47
48 #NDK_ROOT and NDK_DEP_ROOT_DIR should be defined.
49 #NDK_ROOT=/home/moon/Works/Devel/Vine/android-ndk-r21b
50 #NDK_DEP_ROOT_DIR=/home/moon/Works/Devel/Vine/ndk-deps
51
52 #Libraries that vine depends on should be located in a directory for each ABI.
53 #If you want to build for arm64-v8a ABI, libraries should be located in $NDK_DEP_ROOT_DIR/lib/arm64-v8a
54 #ABI: armeabi-v7a, arm64-v8a, x86, x86-64
55
56 OUTPUT_DIR=artifacts
57
58 function build_android {
59         ABI=$1
60         OUTPUT_LIB=$OUTPUT_DIR/lib/$ABI
61         OUTPUT_INC=$OUTPUT_DIR/include
62         OUTPUT_BIN=$OUTPUT_DIR/bin/$ABI
63         NDK_DEP_LIB=$NDK_DEP_ROOT_DIR/lib/$ABI
64         NDK_DEP_INC=$NDK_DEP_ROOT_DIR/include
65
66         echo "Build vine library (ABI=$ABI)"
67         echo "NDK_PATH $NDK_ROOT"
68         cd $BUILD_DIR
69         mkdir -p $OUTPUT_LIB
70         mkdir -p $OUTPUT_INC
71         mkdir -p $OUTPUT_BIN
72         cmake .. \
73                 -DCMAKE_TOOLCHAIN_FILE=$NDK_ROOT/build/cmake/android.toolchain.cmake \
74                 -DANDROID_ABI=$ABI \
75                 -DANDROID_NATIVE_API_LEVEL=$MINSDKVERSION \
76                 -DANDROID_STL=c++_static \
77                 -DANDROID=ON -DANDROID_NDK=$NDK_ROOT \
78                 -DNDK_LIB_DIR=$NDK_DEP_LIB -DNDK_INCLUDE_DIR=$NDK_DEP_INC \
79                 -DLIB_DIR=$OUTPUT_LIB -DINCLUDE_DIR=$OUTPUT_INC -DBIN_DIR=$OUTPUT_BIN \
80                 -DWITH_UNITTEST=ON -DWITH_VINE_TEST=ON \
81                 -DLWS_OPENSSL_INCLUDE_DIRS=$NDK_INCLUDE_DIR \
82                 -DLWS_OPENSSL_LIBRARIES="$NDK_DEP_LIB/libcrypto.so;$NDK_DEP_LIB/libssl.so"
83         make
84         make install
85         cd ..
86 }
87
88 if [ ! -d "$BUILD_DIR" ]; then
89         mkdir -p $BUILD_DIR
90 fi
91
92 if [ $# -eq 0 ]
93 then
94         build
95 fi
96
97 if [ $# -eq 1 ]
98 then
99 case $1 in
100         "clean")
101                 clean
102                 ;;
103         "build")
104                 build
105                 ;;
106         "test")
107                 unittest
108                 ;;
109         "test_log")
110                 unittest -d
111                 ;;
112         "check")
113                 coding_rule
114                 ;;
115         "debug")
116                 build -DENABLE_DATAPATH_PLUGIN_DEBUG=ON -DENABLE_INSTRUMENTATION_MODE=ON
117                 ;;
118         "doxygen")
119                 doxygen doxygen.conf
120                 ;;
121         "install_certs")
122                 install_certs
123                 ;;
124         "android")
125                 build_android arm64-v8a
126                 ;;
127 esac
128 fi
129
130 if [ $# -eq 2 ]
131 then
132         case $1 in
133                 "android")
134                         build_android $2
135                         ;;
136         esac
137 fi
138