forked from montagao/device-cloud-lib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·176 lines (165 loc) · 5.27 KB
/
build.sh
File metadata and controls
executable file
·176 lines (165 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/bash -x
#
# Copyright (C) 2017-2018 Wind River Systems, Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES
# OR CONDITIONS OF ANY KIND, either express or implied.
#
# --------------------------------------------------------------------
# Description:
# This script downloads, builds and installs project dependencies for the
# device-cloud-lib into sub-directory called "deps". Once the script completes,
# there will be a directory called "build". Setup cmake in that directory and
# run "make" in the build directory. For more information See README.md.
#
# Usage:
# $ ./build.sh
# --------------------------------------------------------------------
# exit on error
set -e
# Required system dependencies:
# See README.md for list of dependencies from the build host
#
SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )"
export DEPS_DIR=`pwd`/deps
mkdir -p "$DEPS_DIR"
mkdir -p "$DEPS_DIR/include"
mkdir -p "$DEPS_DIR/lib"
CMAKE_ARGS=""
# Get the name of current branch
if [ ! -z "$TRAVIS_PULL_REQUEST_BRANCH" ]; then
BRANCH_NAME="$TRAVIS_PULL_REQUEST_BRANCH"
elif [ ! -z "$TRAVIS_BRANCH" ]; then
BRANCH_NAME="$TRAVIS_BRANCH"
else
CWD=`pwd`
cd "$SCRIPT_PATH"
BRANCH_NAME=`git symbolic-ref --short HEAD || true`
cd "$CWD"
fi
# operating system abstraction layer
git clone https://github.com/Wind-River/device-cloud-osal.git device-cloud-osal
cd device-cloud-osal
# test if branch exists on osal layer matching current branch, if so, change to
if [ ! -z "$BRANCH_NAME" ]; then
git checkout "$BRANCH_NAME" 2>/dev/null || true
fi
if [ ! -e cmake_build ]; then
mkdir cmake_build
fi
cd cmake_build
cmake -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH="$DEPS_DIR" -DOSAL_THREAD_SUPPORT:BOOL=$THREAD_SUPPORT -DOSAL_WRAP:BOOL=ON ..
make
make install
cd ../..
rm -rf device-cloud-osal
if [ "$USE_CMOCKA" != "" ]; then
# cmocka
wget https://cmocka.org/files/1.1/cmocka-1.1.1.tar.xz
tar -xvf cmocka-1.1.1.tar.xz
if [ -e cmocka-1.1.1 ]; then
cd cmocka-1.1.1
if [ ! -e cmake_build ]; then
mkdir cmake_build
fi
cd cmake_build
cmake -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH="$DEPS_DIR" ..
make
make install
cd ../..
rm -rf cmocka-1.1.1
fi
fi
if [ "$USE_JANSSON" != "" ]; then
# jansson
CMAKE_ARGS="${CMAKE_ARGS} -DIOT_JSON_LIBRARY:STRING=jansson"
else
# jsmn
git clone https://github.com/zserge/jsmn.git jsmn
cd jsmn
make clean
make "CFLAGS=-DJSMN_PARENT_LINKS=1 -DJSMN_STRICT=1 -fPIC"
make test
cmake -E copy "jsmn.h" "$DEPS_DIR/include/"
cmake -E copy "libjsmn.a" "$DEPS_DIR/lib/"
cd ..
rm -rf jsmn
fi
if [ "$USE_CIVETWEB" != "" ]; then
# civetweb
export CIVETWEB_GIT_TAG="f04a9f7411731f69751255b1e1a97157fe3cc812"
#export CIVETWEB_GIT_TAG="tags/v1.11" # Version 1.11 doesn't exist yet
git clone https://github.com/civetweb/civetweb.git
cd civetweb
git checkout -b build_version $CIVETWEB_GIT_TAG
if [ ! -e cmake_build ]; then
mkdir cmake_build
fi
cd cmake_build
cmake -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH="$DEPS_DIR" -DCIVETWEB_ENABLE_WEBSOCKETS:BOOL=ON -DCIVETWEB_ENABLE_IPV6:BOOL=ON -DCIVETWEB_ENABLE_SSL:BOOL=ON -DCIVETWEB_SSL_OPENSSL_API_1_1:BOOL=ON ..
make
make install
cd ../..
rm -rf civetweb
CMAKE_ARGS="${CMAKE_ARGS} -DIOT_WEBSOCKET_LIBRARY:STRING=civetweb"
else
# libwebsockets
export LWS_GIT_TAG="tags/v2.3.0"
git clone https://github.com/warmcat/libwebsockets.git libwebsockets
cd libwebsockets
git checkout -b build_version $LWS_GIT_TAG
if [ ! -e cmake_build ]; then
mkdir cmake_build
fi
cd cmake_build
cmake -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH="$DEPS_DIR" ..
make
make install
cd ../..
rm -rf libwebsockets
fi
if [ "${USE_MOSQUITTO}" != "" ]; then
# mosquitto
export MOSQUITTO_GIT_TAG="tags/v1.4.14"
git clone https://github.com/eclipse/mosquitto.git
cd mosquitto
git checkout -b build_version $MOSQUITTO_GIT_TAG
find . -name CMakeLists.txt | xargs sed -i 's/ldconfig/ldconfig ARGS -N/'
sed -i 's/add_subdirectory(man)//' CMakeLists.txt
if [ ! -e cmake_build ]; then
mkdir cmake_build
fi
cd cmake_build
cmake -DWITH_SRV:BOOL=NO -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH="$DEPS_DIR" ..
make
make install
cd ../..
rm -fr mosquitto
CMAKE_ARGS="${CMAKE_ARGS} -DIOT_MQTT_LIBRARY:STRING=mosquitto"
else
# paho
export PAHO_GIT_TAG="tags/v1.2.0"
git clone https://github.com/eclipse/paho.mqtt.c.git paho
cd paho
git checkout -b build_version $PAHO_GIT_TAG
if [ ! -e cmake_build ]; then
mkdir cmake_build
fi
cd cmake_build
cmake -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX:PATH="$DEPS_DIR" -DPAHO_WITH_SSL:BOOL=TRUE -DPAHO_BUILD_STATIC:BOOL=TRUE -DCMAKE_C_FLAGS:STRING=-fPIC ..
make
make install
cd ../..
rm -rf paho
fi
cmake $CMAKE_ARGS -DCMAKE_BUILD_TYPE:STRING=$BUILD_TYPE -DIOT_THREAD_SUPPORT:BOOL=$THREAD_SUPPORT -DIOT_STACK_ONLY:BOOL=$STACK_ONLY -DDEPENDS_ROOT_DIR:PATH="$DEPS_DIR" "$SCRIPT_PATH"
echo
echo "device-cloud-lib is ready to build."
echo