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