LingYun Studio embeded system framwork software, such as thirdparty build shell and lingyun library
guowenxue
2024-08-22 a41651b62ff13fd89aafefd5c1e0ef7a6e5b31ad
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#!/bin/bash
 
#+--------------------------------------------------------------------------------------------
#|Description:  This shell script used download and compile appweb for ARM
#|     Author:  GuoWenxue <guowenxue@gmail.com>
#|  ChangeLog:
#|           1, Initialize 1.0.0 on 2011.04.12
#+--------------------------------------------------------------------------------------------
 
PRJ_PATH=`pwd`
PREFIX_PATH=`pwd`/appweb
 
TFTP_PATH=/tftp
 
mkdir -p $PREFIX_PATH/{bin,modules}
 
LYFTP_SRC=http://master.weike-iot.com:2211/src/
 
CROSS_COMPILE=/opt/gcc-aarch32-10.3-2021.07/bin/arm-none-linux-gnueabihf-
 
TARBALL=appweb_cortexa5.tar.bz2
 
function msg_banner()
{
    echo ""
    echo "+-----------------------------------------------------------------------"
    echo "|  $1 "
    echo "+-----------------------------------------------------------------------"
    echo ""
}
 
function check_result()
{
    if [ $? != 0 ] ; then
       echo ""
       echo "+-----------------------------------------------------------------------"
       echo "|  $1 "
       echo "+-----------------------------------------------------------------------"
       echo ""
       exit ;
    fi
}
 
function export_cross()
{
    # export cross toolchain
    export CC=${CROSS_COMPILE}gcc
    export AS=${CROSS_COMPILE}as
    export AR=${CROSS_COMPILE}ar
    export LD=${CROSS_COMPILE}ld
    export NM=${CROSS_COMPILE}nm
    export RANLIB=${CROSS_COMPILE}ranlib
    export OBJDUMP=${CROSS_COMPILE}objdump
    export STRIP=${CROSS_COMPILE}strip
 
    # export cross configure 
    export CONFIG_CROSS=" --build=i686-pc-linux --host=arm-linux "
 
    # Clear LDFLAGS and CFLAGS
    export LDFLAGS=
    export CFLAGS=
}
 
PHP_SRC_NAME=php-5.4.10
function compile_php()
{
    SRC_NAME=${PHP_SRC_NAME}
    PACK_SUFIX=tar.bz2
 
    if [ -f ${PREFIX_PATH}/modules/libphp5.so  ] ; then
        msg_banner "$SRC_NAME already compile and installed"
        return 0;
    fi
 
    msg_banner "Start cross compile $SRC_NAME "
 
    if [ ! -f ${SRC_NAME}.${PACK_SUFIX} ] ; then
        #wget http://museum.php.net/php5/${SRC_NAME}.${PACK_SUFIX}
        wget $LYFTP_SRC/$SRC_NAME.$PACK_SUFIX
        check_result "ERROR: download ${SRC_NAME} failure"
    fi
 
    tar -xjf ${SRC_NAME}.${PACK_SUFIX}
    cd ${SRC_NAME}
 
    sed -i -e "s/uint _res/uint/g"  main/php_output.h
    line=`sed -n '/Your system seems to lack POSIX threads/=' configure`
    sed -i -e ${line}s'|.*|{ echo "configure: error: Your system seems to lack POSIX threads." 1>\&2;}|' configure
 
    ./configure --prefix=${PREFIX_PATH} ${CONFIG_CROSS}  --disable-rpath --disable-cli --enable-bcmath \
    --enable-calendar --enable-maintainer-zts -enable-embed=shared --enable-force-cgi-redirect --disable-ftp \
    --enable-inline-optimization  --disable-magic-quotes --enable-memory-limit --disable-safe-mode \
    --enable-sockets --enable-track-vars --enable-trans-sid -enable-wddx --sysconfdir=/apps/appWeb/etc --with-pic \
    --with-db --with-regex=system --with-pear --without-zlib --without-iconv --disable-dom --disable-libxml \
    --disable-simplexml --disable-xml --disable-wddx --disable-xmlreader --without-xmlrpc --disable-xmlwriter \
    --with-config-file-path=/apps/appweb  
    check_result "ERROR: configure ${SRC_NAME} failure"
 
    export LDFLAGS+="-lpthread -ldl" 
    make  && make install
    check_result "ERROR: compile ${SRC_NAME} failure"
 
    # install and clear PHP
    ${STRIP} ${PREFIX_PATH}/lib/libphp5.so 
    cp -rf $PREFIX_PATH/lib/libphp5.so $PREFIX_PATH/modules
    rm -rf ${PREFIX_PATH}/bin/*
    rm -rf $PREFIX_PATH/include
    rm -rf $PREFIX_PATH/lib
    rm -rf $PREFIX_PATH/php
 
    cd -
}
 
 
 
function compile_appweb()
{
    SRC_NAME=appweb-3.4.2
    PACK_SUFIX=-0-src.tgz
 
    if [ -f ${PREFIX_PATH}/bin/appweb ] ; then
        msg_banner "$SRC_NAME already compiled"
        return 0;
    fi
 
    msg_banner "Start cross compile $SRC_NAME "
 
    if [ ! -f ${SRC_NAME}${PACK_SUFIX} ] ; then
        #wget https://embedthis.com/software/${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}
 
    ./configure --prefix=${PREFIX_PATH} ${CONFIG_CROSS} --type=RELEASE --static --port=80 --enable-assert \
    --enable-complete-cross --enable-legacy-api --enable-log --enable-multi-thread --enable-samples \
    --enable-test --enable-send --enable-upload --enable-file --enable-regex --with-php=${PRJ_PATH}/${PHP_SRC_NAME}
    check_result "ERROR: configure ${SRC_NAME} failure"
 
    make TRACE=1  
    check_result "ERROR: compile ${SRC_NAME} failure"
 
 
    cp bin/arm-unknown-linux/appweb $PREFIX_PATH/bin
    cp modules/arm-unknown-linux/* $PREFIX_PATH/modules
    $STRIP $PREFIX_PATH/bin/*
    cp -rf test/{appweb.conf,groups.db,mime.types,users.db} $PREFIX_PATH
 
    cd -
}
 
function install_appweb()
{
    cd ${PRJ_PATH}
 
    if [ -f ${TARBALL} ] ; then
        msg_banner "$SRC_NAME already installed"
        return 0;
    fi
 
    msg_banner "Start install webserver appweb "
 
    # install web page
    rm -rf $PREFIX_PATH/web
    cp -rf web $PREFIX_PATH
 
    sed -i -e "s|^Listen 4100|Listen 80|g" $PREFIX_PATH/appweb.conf
    sed -i -e 's|^LoadModulePath "../modules"|LoadModulePath "./modules"|g' $PREFIX_PATH/appweb.conf
    sed -i -e "s|^DirectoryIndex.*|DirectoryIndex index.php|g" $PREFIX_PATH/appweb.conf
 
    set -x
 
 cat << EOF > run.sh
#!/bin/sh
APPWEB_PATH=/apps/appweb
export LD_LIBRARY_PATH=\${LD_LIBRARY_PATH}:\${APPWEB_PATH}/modules
cd \${APPWEB_PATH}
./bin/appweb --config appweb.conf &
EOF
 
    chmod 755 run.sh 
    mv run.sh $PREFIX_PATH/
 
    tar -cjf ${TARBALL} `basename $PREFIX_PATH`
 
    if [ -d $TFTP_PATH -a -w $TFTP_PATH ] ; then
        cp ${TARBALL} $TFTP_PATH
    fi
}
 
 
export_cross
 
compile_php
 
compile_appweb
 
install_appweb