guowenxue
2021-11-03 220397d6e51dd15d74fbd41cfdc9c72aced45119
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
#!/bin/bash
 
LYFTP_SRC=ftp://master.iot-yun.club/src/
 
function msg_banner()
    echo "" 
    echo "+-----------------------------------------------------------------------" 
    echo "|  $1 " 
    echo "+-----------------------------------------------------------------------"
           echo ""
}
 
function check_result()
{
           if [ $? != 0 ] ; then
               echo ""
               echo "+-----------------------------------------------------------------------"
               echo "|  $1 "
               echo "+-----------------------------------------------------------------------"
               echo ""
               exit ;
           fi
}
 
 
function compile_libgpiod()
{
    PREFIX_PATH=/usr
    SRC_NAME=libgpiod-1.6.2
    PACK_SUFIX=tar.gz
    IMG_NAME=libgpiod.so
 
    if [ -f ${PREFIX_PATH}/lib/${IMG_NAME} ] ; 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://git.kernel.org/pub/scm/libs/libgpiod/libgpiod.git/snapshot/$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}
 
    cd ${SRC_NAME}
 
    ./autogen.sh
    ./configure --enable-tools=yes --prefix=$PREFIX_PATH
    make && sudo make install
 
    cd -
}
 
function compile_cJson()
{
    PREFIX_PATH=/usr
    SRC_NAME=cJSON-1.7.14
    PACK_SUFIX=tar.gz
    IMG_NAME=libcjson.so
 
    if [ -f ${PREFIX_PATH}/lib/${IMG_NAME} ] ; 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
        # official site: https://github.com/DaveGamble/cJSON
        wget $LYFTP_SRC/$SRC_NAME.$PACK_SUFIX 
        check_result "ERROR: download ${SRC_NAME} failure"
    fi
 
 
    tar -xzf ${SRC_NAME}.${PACK_SUFIX}
 
    cd ${SRC_NAME}
    make && sudo make PREFIX=$PREFIX_PATH install
    cd -
}
 
 
function compile_mosquitto()
{
    PREFIX_PATH=/usr
    SRC_NAME=mosquitto-2.0.5
    PACK_SUFIX=tar.gz
    IMG_NAME=libmosquitto.so
 
    if [ -f ${PREFIX_PATH}/lib/${IMG_NAME} ] ; then
        msg_banner "$SRC_NAME already compile and installed"
        return 0;
    fi
 
    # mosquitto depends on openssl 
    msg_banner "Using apt install openssl library now..."
    sudo apt install -y libssl-dev
 
 
    msg_banner "Start compile $SRC_NAME "
    if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
        wget $LYFTP_SRC/$SRC_NAME.$PACK_SUFIX 
        #wget https://mosquitto.org/files/source/$SRC_NAME.$PACK_SUFIX 
        check_result "ERROR: download ${SRC_NAME} failure"
    fi
 
 
    tar -xzf ${SRC_NAME}.${PACK_SUFIX}
 
    cd ${SRC_NAME}
 
    make && sudo make DESTDIR=${PREFIX_PATH} prefix=/ install
 
    cd -
}
 
compile_libgpiod
 
compile_cJson
 
compile_mosquitto