build: Add mbedtls to prep script
[platform/upstream/iotivity.git] / prep.sh
1 #!/bin/sh
2
3 set -f
4
5 [ ! -z ${EXEC_MODE} ] || EXEC_MODE=false
6
7 topdir="${PWD}"
8
9 do_()
10 {
11     set +f
12     if $EXEC_MODE; then
13         echo "warning: fetching online resources may not be reproductible"
14         printf "%s\n" "trying: \"$@\""
15         eval "$@"
16     else
17         echo "# Please manually execute from shell:"
18         printf "%s\n" "$@"
19     fi
20     sleep 5
21     set -f
22 }
23
24
25 main_()
26 {
27     cat<<EOF
28 #
29 # WARNING: This helper script is DISCOURAGED to be used
30 #
31 #  Instead please use the supported build tool "scons"
32 #
33 #  However in some specific cases it's not possible
34 #  so this script is providing a fallback option.
35 #
36 #  Reminder: it's not safe to access online resources at build time,
37 #  so by default the script will tell what to do (like scons),
38 #  to enable tasks executions it should be run with EXEC_MODE enabled:
39 #
40 #  EXEC_MODE=true ./prep.sh
41 #
42 #  More details at:
43 #  https://wiki.iotivity.org/build
44 #
45 EOF
46
47     which git > /dev/null
48     which unzip > /dev/null
49     which wget > /dev/null
50
51     echo "# Checking for tinycbor presence:"
52     tinycbor_url='https://github.com/01org/tinycbor.git'
53     tinycbor_rev='v0.3.1'
54     if [ ! -e 'extlibs/tinycbor/tinycbor' ] ; then
55         do_ "git clone --depth 1 -b "${tinycbor_rev}" "$tinycbor_url" extlibs/tinycbor/tinycbor"
56     fi
57
58     echo "# Checking for gtest presence:"
59     gtest_url='http://pkgs.fedoraproject.org/repo/pkgs/gtest/gtest-1.7.0.zip/2d6ec8ccdf5c46b05ba54a9fd1d130d7/gtest-1.7.0.zip'
60     gtest_dir="${topdir}/extlibs/gtest/"
61     gtest_archive=$(basename -- "${gtest_url}")
62     gtest_file="${gtest_dir}/gtest-1.7.0/CMakeLists.txt"
63     if [ ! -e "${gtest_file}" ] ; then
64         do_ "cd ${gtest_dir} && wget -nc -O ${gtest_archive} ${gtest_url} && unzip ${gtest_archive}"
65         cd "${topdir}"
66     fi
67
68     echo "# Checking for sqlite presence:"
69     sqlite_url='http://www.sqlite.org/2015/sqlite-amalgamation-3081101.zip'
70     sqlite_dir="${topdir}/extlibs/sqlite3"
71     sqlite_file="${sqlite_dir}/sqlite3.c"
72     sqlite_archive=$(basename -- "${sqlite_url}")
73     if [ ! -e 'extlibs/sqlite3/$sqlite_file' ] ; then
74         do_ "cd ${sqlite_dir} && wget -nc $sqlite_url && unzip ${sqlite_archive} && mv */* ."
75         cd "${topdir}"
76     fi
77
78     echo "# Checking for mbedtls presence:"
79     mbedtls_url='https://github.com/ARMmbed/mbedtls.git'
80     mbedtls_dir="${topdir}/extlibs/mbedtls/mbedtls"
81     mbedtls_rev="ad249f509fd62a3bbea7ccd1fef605dbd482a7bd" # in "yotta-2.3.2"
82     if [ ! -e "${mbedtls_dir}" ] ; then
83         do_ "git clone ${mbedtls_url} ${mbedtls_dir}"
84     fi
85     cd "${mbedtls_dir}"
86     do_ "git reset --hard ${mbedtls_rev}"
87     echo "# Checking for mbedtls patches:"
88     file="${mbedtls_dir}/../ocf.patch"
89     do_ "git apply ${file}" ||:
90     cd "${topdir}"
91 }
92
93
94 main_
95