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