modify build script to maintain build date of liborchestration.a library
[platform/core/system/edge-orchestration.git] / build.sh
1 #! /bin/bash
2
3 export BASE_DIR=$( cd "$(dirname "$0")" ; pwd )
4
5 BINARY_FILE="edge-orchestration"
6 SERVICE_DIR="/etc/systemd/system"
7 BINARY_DIR=$BASE_DIR/"src/CMain/bin"
8 RPM_SPEC_FILE="edge-orchestration.spec"
9 SERVICE_FILE="edge-orchestration.service"
10 SERVICE_FILE_x86="edge-orchestration.service.amd64"
11 DBUS_CONF_FILE="org.tizen.orchestration.conf"
12 DBUS_CONF_FILE_x86="org.tizen.orchestration.conf.amd64"
13 DBUS_SERVICE_FILE="org.tizen.orchestration.service"
14 DBUS_SERVICE_FILE_x86="org.tizen.orchestration.service.amd64"
15 DBUS_CONF_DIR="/etc/dbus-1/system.d"
16 DBUS_SERVICE_DIR="/usr/share/dbus-1/system-services"
17
18 export VERSION=`grep -w "Version" $BASE_DIR/packaging/$RPM_SPEC_FILE | awk -F ':' '{print $2}' | tr -d ' '`
19 export BUILD_DATE=$(date +%Y%m%d.%H%M)
20
21 export GOPATH=$GOPATH:$BASE_DIR:$BASE_DIR/vendor
22
23 ORG_VENDOR_DIR='vendor'
24 CUR_VENDOR_DIR='vendor/src'
25 if [ ! -d $BASE_DIR/$CUR_VENDOR_DIR ]; then
26     ln -s $BASE_DIR/$ORG_VENDOR_DIR $BASE_DIR/$CUR_VENDOR_DIR
27 fi
28
29 function install_prerequisite() {
30     echo ""
31     echo "-----------------------------------"
32     echo " Install prerequisite packages"
33     echo "-----------------------------------"
34     go get github.com/axw/gocov/gocov
35     go get github.com/matm/gocov-html
36     go get github.com/Songmu/make2help/cmd/make2help
37 }
38
39 function build_clean() {
40     echo ""
41     echo "-----------------------------------"
42     echo " Build clean"
43     echo "-----------------------------------"
44     make clean
45 }
46
47 function build_binary() {
48     echo ""
49     echo "----------------------------------------"
50     echo " Create Executable binary from GoMain"
51     echo "----------------------------------------"
52     make build-binary
53 }
54
55 function build_object() {
56     echo ""
57     echo "----------------------------------------"
58     echo " Create Static object of Orchestration"
59     echo "----------------------------------------"
60     make build-object
61 }
62
63 function build_dbus() {
64     echo ""
65     echo "----------------------------------------"
66     echo " Create Executable binary from CMain"
67     echo "----------------------------------------"
68     make build-dbus-server
69
70     echo ""
71     echo "--------------------------------------------------"
72     echo " Create Shared Object from libedge-orchestration"
73     echo "--------------------------------------------------"
74     make build-dbus-client
75 }
76
77 function build_test() {
78     echo ""
79     echo "-------------------------------------"
80     echo " Build test to calculate Coverage"
81     echo "-------------------------------------"
82     sudo systemctl stop ${SERVICE_FILE}
83     sudo systemctl status ${SERVICE_FILE}
84     mkdir -p /tmp/foo
85     make test
86 }
87
88 function lint_src_code() {
89     echo ""
90     echo "---------------------------------------"
91     echo " Analysis source code golint & go vet"
92     echo "---------------------------------------"
93     make lint
94 }
95
96 function build_package() {
97     echo ""
98     echo "------------------------------------------"
99     echo " Create Packages for Tizen from gbs build"
100     echo "------------------------------------------"
101
102     gbs -c ./.tizen.gbs.conf build -A armv7l --include-all
103
104     ### build through go toolchain
105     #gbs -c ./.tizen.gbs.conf build -A armv7l --include-all --define 'go_build ON'
106 }
107
108 function register_service() {
109     echo ""
110     echo "-----------------------------------"
111     echo "  Create Service File [SuperUser]"
112     echo "-----------------------------------"
113
114     sudo systemctl stop $SERVICE_FILE
115     sudo cp $BINARY_DIR/$BINARY_FILE /usr/bin
116     sudo cp $BASE_DIR/packaging/$SERVICE_FILE_x86 $SERVICE_DIR/$SERVICE_FILE
117     sudo cp $BASE_DIR/packaging/$DBUS_CONF_FILE_x86 $DBUS_CONF_DIR/$DBUS_CONF_FILE
118     sudo cp $BASE_DIR/packaging/$DBUS_SERVICE_FILE_x86 $DBUS_SERVICE_DIR/$DBUS_SERVICE_FILE
119     ls -al $SERVICE_DIR | grep $SERVICE_FILE
120
121     echo ""
122     echo "----------------------------------------"
123     echo "  Register Edge-Orchestration Service"
124     echo "----------------------------------------"
125
126     sudo systemctl daemon-reload
127     sudo systemctl restart $SERVICE_FILE
128     sudo systemctl status $SERVICE_FILE
129 }
130
131 function build_object_arm() {
132     echo ""
133     echo ""
134     echo "**********************************"
135     echo " Target Binary arch is armv7 "
136     echo "**********************************"
137     export GOARCH=arm GOARM=7
138     export CC="arm-linux-gnueabi-gcc"
139     export ARCH=arm
140
141     build_clean
142     build_object
143 }
144
145
146 # Always executed for creating orchestration library
147 build_object_arm
148
149 if [ "$1" == "tizen" ]; then
150     build_package
151 else
152     echo ""
153     echo ""
154     echo "**********************************"
155     echo " Target Binary arch is amd64 "
156     echo "**********************************"
157     export GOARCH=amd64
158     export CC="gcc"
159     export ARCH=x86_64
160
161     case "$1" in
162         "all")
163             build_clean
164             install_prerequisite
165             build_test
166             build_object
167             build_dbus
168             build_binary
169             lint_src_code
170             register_service
171             ;;
172         "test")
173             build_test
174             ;;
175         "status")
176             sudo systemctl status ${SERVICE_FILE}
177             ;;
178         "start")
179             sudo systemctl daemon-reload
180             sudo systemctl start ${SERVICE_FILE}
181             sudo systemctl status ${SERVICE_FILE}
182             ;;
183         "stop")
184             sudo systemctl stop ${SERVICE_FILE}
185             sudo systemctl status ${SERVICE_FILE}
186             ;;
187         "restart")
188             sudo systemctl daemon-reload
189             sudo systemctl restart ${SERVICE_FILE}
190             sudo systemctl status ${SERVICE_FILE}
191             ;;
192         "")
193             build_clean
194             build_object
195             build_dbus
196             register_service
197             ;;
198         *)
199             echo "build script"
200             echo "Usage:"
201             echo "--------------------------------------------------------------"
202             echo "  $0          : build Go executable binary for amd64 "
203             echo "  $0 all      : build C executable binary for amd64  "
204             echo "  $0 tizen    : build arm packages for Tizen"
205             echo "--------------------------------------------------------------"
206             exit 0
207             ;;
208     esac
209 fi