#!/bin/bash
|
|
#+--------------------------------------------------------------------------------------------
|
#|Description: This shell script used download and compile mosquitto for RaspberryPi
|
#| Author: GuoWenxue <guowenxue@gmail.com>
|
#| ChangeLog:
|
#| 1, Initialize 1.0.0 on 2011.04.12
|
#+--------------------------------------------------------------------------------------------
|
|
JOBS=`cat /proc/cpuinfo |grep "processor"|wc -l`
|
|
PRJ_PATH=`pwd`
|
LIBS_PATH=$PRJ_PATH/../install
|
|
LYFTP_SRC=ftp://master.iot-yun.club/src/
|
|
|
CROSSTOOL=arm-linux-gnueabihf-
|
|
# display in red
|
function pr_error() {
|
echo -e "\033[40;31m --E-- $1 \033[0m"
|
}
|
|
# display in yellow
|
function pr_warn() {
|
echo -e "\033[40;33m --W-- $1 \033[0m"
|
}
|
|
# display in green
|
function pr_info() {
|
echo -e "\033[40;32m --I-- $1 \033[0m"
|
}
|
|
function msg_banner()
|
{
|
echo ""
|
echo "+-----------------------------------------------------------------------"
|
echo -e "|\033[40;33m $1 \033[0m"
|
echo "+-----------------------------------------------------------------------"
|
echo ""
|
}
|
|
function check_result()
|
{
|
if [ $? != 0 ] ; then
|
pr_error $1
|
fi
|
}
|
|
|
function compile_mosquitto()
|
{
|
SRC_NAME=mosquitto-2.0.14
|
PACK_SUFIX=tar.gz
|
|
if [ -f ${LIBS_PATH}/lib/libmosquitto.so ] ; then
|
msg_banner "$SRC_NAME already compile and installed"
|
return 0;
|
fi
|
|
msg_banner "Start compile $SRC_NAME "
|
|
if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
|
#wget https://mosquitto.org/files/source//${SRC_NAME}.${PACK_SUFIX}
|
wget ${LYFTP_SRC}/${SRC_NAME}.${PACK_SUFIX}
|
check_result "ERROR: download ${SRC_NAME} failure"
|
fi
|
|
tar -xzf ${SRC_NAME}.${PACK_SUFIX}
|
check_result "ERROR: decompress ${SRC_NAME} failure"
|
|
cd ${SRC_NAME}
|
SRC_PATH=`pwd`
|
|
export CROSS_COMPILE=${CROSSTOOL}
|
export CC=gcc
|
|
make -j ${JOBS} LIB_LDFLAGS="-L${LIBS_PATH}/lib" LOCAL_LDFLAGS+="-L${LIBS_PATH}/lib" \
|
LIB_CPPFLAGS+="-I ${LIBS_PATH}/include -I${SRC_PATH} -I${SRC_PATH}/src -I${SRC_PATH}/include" \
|
LIB_CPPFLAGS+="-I${SRC_PATH}/lib -I${SRC_PATH}/lib/cpp -I${SRC_PATH}/deps" \
|
LOCAL_CPPFLAGS+="-I ${LIBS_PATH}/include -I${SRC_PATH}/src -I${SRC_PATH}/apps/mosquitto_passwd/ -DVERSION=\\\"\"2.0.14\\\"\" " \
|
APP_CFLAGS+="-I ${LIBS_PATH}/include -I${SRC_PATH}/src" APP_LDFLAGS="-L ${LIBS_PATH}/lib" \
|
CLIENT_CFLAGS="-I ${LIBS_PATH}/include -I${SRC_PATH} -I${SRC_PATH}/include -DVERSION=\\\"\"2.0.14\\\"\" " \
|
CLIENT_LDFLAGS="-L ${LIBS_PATH}/lib" PLUGIN_LDFLAGS="-L ${LIBS_PATH}/lib" BROKER_LDFLAGS="-L ${LIBS_PATH}/lib"
|
|
check_result "ERROR: compile ${SRC_NAME} failure"
|
|
make DESTDIR=${LIBS_PATH} install
|
check_result "ERROR: install ${SRC_NAME} failure"
|
}
|
|
# compile cjson first
|
cd ../cjson && ./build.sh && cd ${PRJ_PATH}
|
cd ../openssl && ./build.sh && cd ${PRJ_PATH}
|
|
compile_mosquitto
|