Blame view

trunk/auto/depends.sh 23.7 KB
1 2
#!/bin/bash
3 4 5
# variables, parent script must set it:
# SRS_JOBS: the build jobs.
# SrsArmMakeOptions: the arm make options for ubuntu12(armhf, v7cpu)
6
# SRS_AUTO_HEADERS_H: the auto generated header file.
winlin authored
7
8 9 10 11 12 13 14 15 16 17
#####################################################################################
#####################################################################################
# prepare the depends tools and libraries
# DEPENDS: options.sh, only when user options parsed, the depends tools are known.
#####################################################################################
#####################################################################################

#####################################################################################
# utilities
#####################################################################################
18 19 20 21 22 23 24 25 26 27
function require_sudoer()
{
    sudo echo "" >/dev/null 2>&1
    
    ret=$?; if [[ 0 -ne $ret ]]; then 
        echo "\"$1\" require sudoer failed. ret=$ret";
        exit $ret; 
    fi
}
28
# TODO: check gcc/g++
29
echo "check gcc/g++/gdb/make"
30
echo "depends tools are ok"
31
#####################################################################################
32
# for Ubuntu, auto install tools by apt-get
33 34 35 36 37
#####################################################################################
function Ubuntu_prepare()
{
    uname -v|grep Ubuntu >/dev/null 2>&1
    ret=$?; if [[ 0 -ne $ret ]]; then
38
        return 0;
39 40 41 42
    fi

    echo "Ubuntu detected, install tools if needed"
    
43
    gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
44
        echo "install gcc"
45
        require_sudoer "sudo apt-get install -y --force-yes gcc"
46
        sudo apt-get install -y --force-yes gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
47 48 49
        echo "install gcc success"
    fi
    
50
    g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
51
        echo "install g++"
52
        require_sudoer "sudo apt-get install -y --force-yes g++"
53
        sudo apt-get install -y --force-yes g++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
54 55 56
        echo "install g++ success"
    fi
    
57
    make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
58
        echo "install make"
59
        require_sudoer "sudo apt-get install -y --force-yes make"
60
        sudo apt-get install -y --force-yes make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
61 62 63
        echo "install make success"
    fi
    
64
    autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
65
        echo "install autoconf"
66
        require_sudoer "sudo apt-get install -y --force-yes autoconf"
67
        sudo apt-get install -y --force-yes autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
68 69 70
        echo "install autoconf success"
    fi
    
71
    libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
72
        echo "install libtool"
73
        require_sudoer "sudo apt-get install -y --force-yes libtool"
74
        sudo apt-get install -y --force-yes libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
75 76 77
        echo "install libtool success"
    fi
    
78 79
    if [[ ! -f /usr/include/pcre.h ]]; then
        echo "install libpcre3-dev"
80
        require_sudoer "sudo apt-get install -y --force-yes libpcre3-dev"
81
        sudo apt-get install -y --force-yes libpcre3-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
82 83 84 85 86
        echo "install libpcre3-dev success"
    fi
    
    if [[ ! -f /usr/include/zlib.h ]]; then
        echo "install zlib1g-dev"
87
        require_sudoer "sudo apt-get install -y --force-yes zlib1g-dev"
88
        sudo apt-get install -y --force-yes zlib1g-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
89 90 91 92 93
        echo "install zlib1g-dev success"
    fi
    
    if [[ ! -d /usr/include/freetype2 ]]; then
        echo "install libfreetype6-dev"
94
        require_sudoer "sudo apt-get install -y --force-yes libfreetype6-dev"
95
        sudo apt-get install -y --force-yes libfreetype6-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
96 97 98
        echo "install libfreetype6-dev success"
    fi
    
99 100 101 102 103 104 105 106 107 108
    # for arm, install the cross build tool chain.
    if [ $SRS_ARM_UBUNTU12 = YES ]; then
        arm-linux-gnueabi-gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
            echo "install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi"
            require_sudoer "sudo apt-get install -y --force-yes gcc-arm-linux-gnueabi g++-arm-linux-gnueabi"
            sudo apt-get install -y --force-yes gcc-arm-linux-gnueabi g++-arm-linux-gnueabi; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            echo "install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi success"
        fi
    fi
    
109
    echo "Ubuntu install tools success"
110
    return 0
111
}
winlin authored
112
Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Ubuntu prepare failed, ret=$ret"; exit $ret; fi
113
#####################################################################################
114
# for Centos, auto install tools by yum
115 116 117 118
#####################################################################################
function Centos_prepare()
{
    if [[ ! -f /etc/redhat-release ]]; then
119
        return 0;
120 121 122 123 124 125 126
    fi

    echo "Centos detected, install tools if needed"
    
    gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
        echo "install gcc"
        require_sudoer "sudo yum install -y gcc"
127
        sudo yum install -y gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
128 129 130 131 132 133
        echo "install gcc success"
    fi
    
    g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
        echo "install gcc-c++"
        require_sudoer "sudo yum install -y gcc-c++"
134
        sudo yum install -y gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
135 136 137 138 139 140
        echo "install gcc-c++ success"
    fi
    
    make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
        echo "install make"
        require_sudoer "sudo yum install -y make"
141
        sudo yum install -y make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
142 143 144 145 146 147
        echo "install make success"
    fi
    
    automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
        echo "install automake"
        require_sudoer "sudo yum install -y automake"
148
        sudo yum install -y automake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
149 150 151 152 153 154
        echo "install automake success"
    fi
    
    autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
        echo "install autoconf"
        require_sudoer "sudo yum install -y autoconf"
155
        sudo yum install -y autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
156 157 158 159 160 161
        echo "install autoconf success"
    fi
    
    libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
        echo "install libtool"
        require_sudoer "sudo yum install -y libtool"
162
        sudo yum install -y libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
163 164 165
        echo "install libtool success"
    fi
    
166 167 168
    if [[ ! -f /usr/include/pcre.h ]]; then
        echo "install pcre-devel"
        require_sudoer "sudo yum install -y pcre-devel"
169
        sudo yum install -y pcre-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
170 171 172 173 174 175
        echo "install pcre-devel success"
    fi
    
    if [[ ! -f /usr/include/zlib.h ]]; then
        echo "install zlib-devel"
        require_sudoer "sudo yum install -y zlib-devel"
176
        sudo yum install -y zlib-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
177 178 179 180 181 182
        echo "install zlib-devel success"
    fi
    
    if [[ ! -d /usr/include/freetype2 ]]; then
        echo "install freetype-devel"
        require_sudoer "sudo yum install -y freetype-devel"
183
        sudo yum install -y freetype-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
184 185 186
        echo "install freetype-devel success"
    fi
    
187 188 189 190 191 192
    # for arm, install the cross build tool chain.
    if [ $SRS_ARM_UBUNTU12 = YES ]; then
        echo "arm-ubuntu12 is invalid for CentOS"
        return 1
    fi
    
193
    echo "Centos install tools success"
194
    return 0
195
}
winlin authored
196
Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "CentOS prepare failed, ret=$ret"; exit $ret; fi
197 198 199 200

#####################################################################################
# st-1.9
#####################################################################################
201 202 203
# check the arm flag file, if flag changed, need to rebuild the st.
if [ $SRS_ARM_UBUNTU12 = YES ]; then
    # ok, arm specified, if the flag filed does not exists, need to rebuild.
204
    if [[ -f ${SRS_OBJS}/_flag.st.arm.tmp && -f ${SRS_OBJS}/st/libst.a && -f ${SRS_OBJS}/st/libst.so ]]; then
205 206 207 208 209 210 211 212
        echo "st-1.9t for arm is ok.";
    else
        # TODO: FIXME: patch the bug.
        # patch st for arm, @see: https://github.com/winlinvip/simple-rtmp-server/wiki/SrsLinuxArm#st-arm-bug-fix
        echo "build st-1.9t for arm"; 
        (
            rm -rf ${SRS_OBJS}/st-1.9 && cd ${SRS_OBJS} && 
            unzip -q ../3rdparty/st-1.9.zip && cd st-1.9 && 
213
            patch -p0 < ../../3rdparty/patches/1.st.arm.patch &&
winlin authored
214
            make CC=${SrsArmCC} AR=${SrsArmAR} LD=${SrsArmLD} RANDLIB=${SrsArmRANDLIB} EXTRA_CFLAGS="-DMD_HAVE_EPOLL" linux-debug &&
215
            cd .. && rm -rf st && ln -sf st-1.9/obj st &&
216 217 218
            cd .. && touch ${SRS_OBJS}/_flag.st.arm.tmp
        )
    fi
219
else
220
    # arm not specified, if exists flag, need to rebuild for no-arm platform.
221
    if [[ ! -f ${SRS_OBJS}/_flag.st.arm.tmp && -f ${SRS_OBJS}/st/libst.a && -f ${SRS_OBJS}/st/libst.so ]]; then
222 223 224 225 226 227
        echo "st-1.9t is ok.";
    else
        echo "build st-1.9t"; 
        (
            rm -rf ${SRS_OBJS}/st-1.9 && cd ${SRS_OBJS} && 
            unzip -q ../3rdparty/st-1.9.zip && cd st-1.9 && 
228 229 230
            echo "we alaways patch the st, for we may build srs under arm directly" &&
            echo "the 1.st.arm.patch is ok for x86 because it's only modify code under macro linux arm" &&
            patch -p0 < ../../3rdparty/patches/1.st.arm.patch &&
winlin authored
231
            make EXTRA_CFLAGS="-DMD_HAVE_EPOLL" linux-debug &&
232
            cd .. && rm -rf st && ln -sf st-1.9/obj st &&
233 234 235
            cd .. && rm -f ${SRS_OBJS}/_flag.st.arm.tmp
        )
    fi
236 237 238
fi
# check status
ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi
239 240
if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "build st-1.9 failed."; exit -1; fi
if [ ! -f ${SRS_OBJS}/st/libst.so ]; then echo "build st-1.9 failed."; exit -1; fi
241 242 243 244

#####################################################################################
# http-parser-2.1
#####################################################################################
245
if [ $SRS_HTTP_CALLBACK = YES ]; then
246
    if [[ -f ${SRS_OBJS}/hp/http_parser.h && -f ${SRS_OBJS}/hp/libhttp_parser.a ]]; then
247 248 249 250 251 252 253 254
        echo "http-parser-2.1 is ok.";
    else
        echo "build http-parser-2.1";
        (
            rm -rf ${SRS_OBJS}/http-parser-2.1 && cd ${SRS_OBJS} && unzip -q ../3rdparty/http-parser-2.1.zip && 
            cd http-parser-2.1 && 
            sed -i "s/CPPFLAGS_FAST +=.*$/CPPFLAGS_FAST = \$\(CPPFLAGS_DEBUG\)/g" Makefile &&
            sed -i "s/CFLAGS_FAST =.*$/CFLAGS_FAST = \$\(CFLAGS_DEBUG\)/g" Makefile &&
winlin authored
255
            make package &&
256
            cd .. && rm -rf hp && ln -sf http-parser-2.1 hp
257 258 259 260
        )
    fi
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build http-parser-2.1 failed, ret=$ret"; exit $ret; fi
261 262
    if [[ ! -f ${SRS_OBJS}/hp/http_parser.h ]]; then echo "build http-parser-2.1 failed"; exit -1; fi
    if [[ ! -f ${SRS_OBJS}/hp/libhttp_parser.a ]]; then echo "build http-parser-2.1 failed"; exit -1; fi
263 264 265 266 267
fi

#####################################################################################
# nginx for HLS, nginx-1.5.0
#####################################################################################
268 269 270 271 272 273 274 275 276 277
function write_nginx_html5()
{
    cat<<END >> ${html_file}
<video width="640" height="360"
        autoplay controls autobuffer 
        src="${hls_stream}"
        type="application/vnd.apple.mpegurl">
</video>
END
}
278
__SRS_BUILD_NGINX=NO; if [ $SRS_ARM_UBUNTU12 = NO ]; then if [ $SRS_NGINX = YES ]; then __SRS_BUILD_NGINX=YES; fi fi
winlin authored
279 280 281 282 283 284 285 286 287
if [ $__SRS_BUILD_NGINX = YES ]; then
    if [[ -f ${SRS_OBJS}/nginx/sbin/nginx ]]; then
        echo "nginx-1.5.7 is ok.";
    else
        echo "build nginx-1.5.7"; 
        (
            rm -rf ${SRS_OBJS}/nginx-1.5.7 && cd ${SRS_OBJS} && 
            unzip -q ../3rdparty/nginx-1.5.7.zip && cd nginx-1.5.7 && 
            ./configure --prefix=`pwd`/_release && make ${SRS_JOBS} && make install &&
288
            cd .. && rm -rf nginx && ln -sf nginx-1.5.7/_release nginx
winlin authored
289
        )
290
    fi
winlin authored
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build nginx-1.5.7 failed, ret=$ret"; exit $ret; fi
    if [ ! -f ${SRS_OBJS}/nginx/sbin/nginx ]; then echo "build nginx-1.5.7 failed."; exit -1; fi

    # use current user to config nginx,
    # srs will write ts/m3u8 file use current user,
    # nginx default use nobody, so cannot read the ts/m3u8 created by srs.
    cp ${SRS_OBJS}/nginx/conf/nginx.conf ${SRS_OBJS}/nginx/conf/nginx.conf.bk
    sed -i "s/^.user  nobody;/user `whoami`;/g" ${SRS_OBJS}/nginx/conf/nginx.conf
    
    # create forward dir
    mkdir -p ${SRS_OBJS}/nginx/html/live &&
    mkdir -p ${SRS_OBJS}/nginx/html/forward/live
    
    # generate default html pages for android.
    html_file=${SRS_OBJS}/nginx/html/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
    html_file=${SRS_OBJS}/nginx/html/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
    html_file=${SRS_OBJS}/nginx/html/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
    html_file=${SRS_OBJS}/nginx/html/forward/live/livestream.html && hls_stream=livestream.m3u8 && write_nginx_html5
    html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_ld.html && hls_stream=livestream_ld.m3u8 && write_nginx_html5
    html_file=${SRS_OBJS}/nginx/html/forward/live/livestream_sd.html && hls_stream=livestream_sd.m3u8 && write_nginx_html5
    
    # copy players to nginx html dir.
    rm -rf ${SRS_OBJS}/nginx/html/players &&
    ln -sf `pwd`/research/players ${SRS_OBJS}/nginx/html/players &&
    rm -f ${SRS_OBJS}/nginx/crossdomain.xml &&
    ln -sf `pwd`/research/players/crossdomain.xml ${SRS_OBJS}/nginx/html/crossdomain.xml
    
    # nginx.html to detect whether nginx is alive
    echo "nginx is ok" > ${SRS_OBJS}/nginx/html/nginx.html
321 322
fi
323 324 325 326 327 328
if [ $SRS_NGINX = YES ]; then
    echo "#define SRS_NGINX" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_NGINX" >> $SRS_AUTO_HEADERS_H
fi
329 330 331 332 333 334 335
if [ $SRS_HLS = YES ]; then
    echo "#define SRS_HLS" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_HLS" >> $SRS_AUTO_HEADERS_H
fi

#####################################################################################
336 337
# cherrypy for http hooks callback, CherryPy-3.2.4
#####################################################################################
338
if [ $SRS_HTTP_CALLBACK = YES ]; then
339 340 341
    if [[ -f ${SRS_OBJS}/CherryPy-3.2.4/setup.py ]]; then
        echo "CherryPy-3.2.4 is ok.";
    else
342
        require_sudoer "configure --with-http-callback"
343 344 345 346 347 348 349 350 351
        echo "install CherryPy-3.2.4"; 
        (
            sudo rm -rf ${SRS_OBJS}/CherryPy-3.2.4 && cd ${SRS_OBJS} && 
            unzip -q ../3rdparty/CherryPy-3.2.4.zip && cd CherryPy-3.2.4 && 
            sudo python setup.py install
        )
    fi
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build CherryPy-3.2.4 failed, ret=$ret"; exit $ret; fi
winlin authored
352
    if [ ! -f ${SRS_OBJS}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi
353 354
fi
355 356
if [ $SRS_HTTP_CALLBACK = YES ]; then
    echo "#define SRS_HTTP_CALLBACK" >> $SRS_AUTO_HEADERS_H
357
else
358
    echo "#undef SRS_HTTP_CALLBACK" >> $SRS_AUTO_HEADERS_H
359 360
fi
361
echo "link players to cherrypy static-dir"
362
rm -rf research/api-server/static-dir/players &&
363 364
ln -sf `pwd`/research/players research/api-server/static-dir/players &&
rm -f research/api-server/static-dir/crossdomain.xml &&
winlin authored
365
ln -sf `pwd`/research/players/crossdomain.xml research/api-server/static-dir/crossdomain.xml &&
366
rm -rf research/api-server/static-dir/live && 
winlin authored
367 368
mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live &&
ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live &&
369
rm -rf research/api-server/static-dir/forward && 
winlin authored
370 371
mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward &&
ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward
372
ret=$?; if [[ $ret -ne 0 ]]; then echo "link players to cherrypy static-dir failed, ret=$ret"; exit $ret; fi
373
winlin authored
374 375
# only when the nginx is ok, 
# if api-server not enalbed, use nginx as demo.
winlin authored
376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
if [ $__SRS_BUILD_NGINX = YES ]; then
    if [ $SRS_HTTP_CALLBACK = YES ]; then
        # override the default index.
        rm -f ${SRS_OBJS}/nginx/html/index.html &&
        ln -sf `pwd`/research/players/nginx_index.html ${SRS_OBJS}/nginx/html/index.html
    else
        rm -f ${SRS_OBJS}/nginx/html/index.html &&
        cat<<END >> ${SRS_OBJS}/nginx/html/index.html
<!DOCTYPE html>
<html>
<head>
    <title>SRS</title>   
    <meta charset="utf-8">
</head>
<body>
    <script type="text/javascript">
        setTimeout(function(){
            window.location.href = "players/index.html" + window.location.search;
        }, 500);
    </script>
</body>
winlin authored
397 398 399 400
END
    fi
fi
401
#####################################################################################
402 403 404
# openssl, for rtmp complex handshake
#####################################################################################
if [ $SRS_SSL = YES ]; then
405 406 407 408 409 410 411 412 413 414 415
    # check the arm flag file, if flag changed, need to rebuild the st.
    if [ $SRS_ARM_UBUNTU12 = YES ]; then
        # ok, arm specified, if the flag filed does not exists, need to rebuild.
        if [[ -f ${SRS_OBJS}/_flag.ssl.arm.tmp && -f ${SRS_OBJS}/openssl/lib/libssl.a ]]; then
            echo "openssl-1.0.1f for arm is ok.";
        else
            echo "build openssl-1.0.1f for arm"; 
            (
                rm -rf ${SRS_OBJS}/openssl-1.0.1f && cd ${SRS_OBJS} && 
                unzip -q ../3rdparty/openssl-1.0.1f.zip && cd openssl-1.0.1f && 
                ./Configure --prefix=`pwd`/_release -no-shared no-asm linux-armv4 && 
416
                make CC=${SrsArmCC} GCC=${SrsArmGCC} AR="${SrsArmAR} r" LD=${SrsArmLD} LINK=${SrsArmGCC} RANDLIB=${SrsArmRANDLIB} && make install &&
417
                cd .. && rm -rf openssl && ln -sf openssl-1.0.1f/_release openssl &&
418 419 420
                cd .. && touch ${SRS_OBJS}/_flag.ssl.arm.tmp
            )
        fi
421
    else
422 423 424 425 426 427 428 429 430 431
        # arm not specified, if exists flag, need to rebuild for no-arm platform.
        if [[ ! -f ${SRS_OBJS}/_flag.ssl.arm.tmp && -f ${SRS_OBJS}/openssl/lib/libssl.a ]]; then
            echo "openssl-1.0.1f is ok.";
        else
            echo "build openssl-1.0.1f"; 
            (
                rm -rf ${SRS_OBJS}/openssl-1.0.1f && cd ${SRS_OBJS} && 
                unzip -q ../3rdparty/openssl-1.0.1f.zip && cd openssl-1.0.1f && 
                ./config --prefix=`pwd`/_release -no-shared && 
                make && make install &&
432
                cd .. && rm -rf openssl && ln -sf openssl-1.0.1f/_release openssl &&
433 434 435
                cd .. && rm -f ${SRS_OBJS}/_flag.ssl.arm.tmp
            )
        fi
436 437 438 439 440 441 442
    fi
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build openssl-1.0.1f failed, ret=$ret"; exit $ret; fi
    if [ ! -f ${SRS_OBJS}/openssl/lib/libssl.a ]; then echo "build openssl-1.0.1f failed."; exit -1; fi
fi

if [ $SRS_SSL = YES ]; then
443 444 445 446
    echo "#define SRS_SSL" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_SSL" >> $SRS_AUTO_HEADERS_H
fi
winlin authored
447 448 449 450 451 452 453 454 455 456

#####################################################################################
# live transcoding, ffmpeg-2.1, x264-core138, lame-3.99.5, libaacplus-2.0.2.
#####################################################################################
if [ $SRS_FFMPEG = YES ]; then
    if [[ -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then
        echo "ffmpeg-2.1 is ok.";
    else
        echo "build ffmpeg-2.1"; 
        (
winlin authored
457 458 459
            cd ${SRS_OBJS} && pwd_dir=`pwd` && 
            rm -rf ffmepg.src && mkdir -p ffmpeg.src && cd ffmpeg.src &&
            rm -f build_ffmpeg.sh && ln -sf ../../auto/build_ffmpeg.sh && . build_ffmpeg.sh &&
460
            cd ${pwd_dir} && rm -rf ffmpeg && ln -sf ffmpeg.src/_release ffmpeg
winlin authored
461 462 463 464 465 466 467 468 469 470 471 472
        )
    fi
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build ffmpeg-2.1 failed, ret=$ret"; exit $ret; fi
    if [ ! -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]; then echo "build ffmpeg-2.1 failed."; exit -1; fi
fi

if [ $SRS_FFMPEG = YES ]; then
    echo "#define SRS_FFMPEG" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_FFMPEG" >> $SRS_AUTO_HEADERS_H
fi
473 474 475 476

#####################################################################################
# build research code
#####################################################################################
477 478
if [ $SRS_RESEARCH = YES ]; then
    mkdir -p ${SRS_OBJS}/research
479
winlin authored
480
    (cd research/hls && make ${SRS_JOBS} && mv ts_info ../../${SRS_OBJS}/research)
481
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build research/hls failed, ret=$ret"; exit $ret; fi
482
winlin authored
483
    (cd research/ffempty && make ${SRS_JOBS} && mv ffempty ../../${SRS_OBJS}/research)
484 485
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build research/ffempty failed, ret=$ret"; exit $ret; fi
fi
winlin authored
486 487 488 489 490

#####################################################################################
# build utest code
#####################################################################################
if [ $SRS_UTEST = YES ]; then
491 492 493 494 495 496 497
    if [[ -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]]; then
        echo "gtest-1.6.0 is ok.";
    else
        echo "build gtest-1.6.0"; 
        (
            rm -rf ${SRS_OBJS}/gtest-1.6.0 && cd ${SRS_OBJS} && 
            unzip -q ../3rdparty/gtest-1.6.0.zip &&
498
            rm -rf gtest && ln -sf gtest-1.6.0 gtest
499 500 501 502 503
        )
    fi
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build gtest-1.6.0 failed, ret=$ret"; exit $ret; fi
    if [ ! -f ${SRS_OBJS}/gtest/include/gtest/gtest.h ]; then echo "build gtest-1.6.0 failed."; exit -1; fi
winlin authored
504
fi
winlin authored
505 506 507 508 509 510 511 512 513 514 515 516 517

#####################################################################################
# build gperf code
#####################################################################################
if [ $SRS_GPERF = YES ]; then
    if [[ -f ${SRS_OBJS}/gperf/bin/pprof ]]; then
        echo "gperftools-2.1 is ok.";
    else
        echo "build gperftools-2.1"; 
        (
            rm -rf ${SRS_OBJS}/gperftools-2.1 && cd ${SRS_OBJS} && 
            unzip -q ../3rdparty/gperftools-2.1.zip && cd gperftools-2.1 &&
            ./configure --prefix=`pwd`/_release --enable-frame-pointers && make ${SRS_JOBS} && make install &&
518 519
            cd .. && rm -rf gperf && ln -sf gperftools-2.1/_release gperf &&
            rm -rf pprof && ln -sf gperf/bin/pprof pprof
winlin authored
520 521 522 523 524 525
        )
    fi
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build gperftools-2.1 failed, ret=$ret"; exit $ret; fi
    if [ ! -f ${SRS_OBJS}/gperf/bin/pprof ]; then echo "build gperftools-2.1 failed."; exit -1; fi
fi
526 527 528 529 530

if [ $SRS_GPERF = YES ]; then
    echo "#define SRS_GPERF" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_GPERF" >> $SRS_AUTO_HEADERS_H
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545
fi
if [ $SRS_GPERF_MC = YES ]; then
    echo "#define SRS_GPERF_MC" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_GPERF_MC" >> $SRS_AUTO_HEADERS_H
fi
if [ $SRS_GPERF_MP = YES ]; then
    echo "#define SRS_GPERF_MP" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_GPERF_MP" >> $SRS_AUTO_HEADERS_H
fi
if [ $SRS_GPERF_CP = YES ]; then
    echo "#define SRS_GPERF_CP" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_GPERF_CP" >> $SRS_AUTO_HEADERS_H
546
fi
547 548 549 550 551 552 553 554 555

#####################################################################################
# for arm.
#####################################################################################
if [ $SRS_ARM_UBUNTU12 = YES ]; then
    echo "#define SRS_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H
fi
556
557 558 559 560
echo "" >> $SRS_AUTO_HEADERS_H
# prefix
echo "#define SRS_PREFIX \"${SRS_PREFIX}\"" >> $SRS_AUTO_HEADERS_H
561 562
# new empty line to auto headers file.
echo "" >> $SRS_AUTO_HEADERS_H