Blame view

trunk/auto/depends.sh 30.8 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
OS_IS_UBUNTU=NO
35 36
function Ubuntu_prepare()
{
37 38 39 40 41 42 43
    if [ $SRS_CUBIE = YES ]; then
        echo "for cubieboard, use ubuntu prepare"
    else
        uname -v|grep Ubuntu >/dev/null 2>&1
        ret=$?; if [[ 0 -ne $ret ]]; then
            return 0;
        fi
44 45
    fi
46
    OS_IS_UBUNTU=YES
47 48
    echo "Ubuntu detected, install tools if needed"
    
49
    gcc --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
50
        echo "install gcc"
51
        require_sudoer "sudo apt-get install -y --force-yes gcc"
52
        sudo apt-get install -y --force-yes gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
53 54 55
        echo "install gcc success"
    fi
    
56
    g++ --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
57
        echo "install g++"
58
        require_sudoer "sudo apt-get install -y --force-yes g++"
59
        sudo apt-get install -y --force-yes g++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
60 61 62
        echo "install g++ success"
    fi
    
63
    make --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
64
        echo "install make"
65
        require_sudoer "sudo apt-get install -y --force-yes make"
66
        sudo apt-get install -y --force-yes make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
67 68 69
        echo "install make success"
    fi
    
winlin authored
70 71 72 73 74 75 76
    patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
        echo "install patch"
        require_sudoer "sudo apt-get install -y --force-yes patch"
        sudo apt-get install -y --force-yes patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
        echo "install patch success"
    fi
    
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
    if [ $SRS_FFMPEG_TOOL = YES ]; then
        autoconf --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
            echo "install autoconf"
            require_sudoer "sudo apt-get install -y --force-yes autoconf"
            sudo apt-get install -y --force-yes autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            echo "install autoconf success"
        fi
        
        libtool --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
            echo "install libtool"
            require_sudoer "sudo apt-get install -y --force-yes libtool"
            sudo apt-get install -y --force-yes libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            echo "install libtool success"
        fi
        
        if [[ ! -f /usr/include/pcre.h ]]; then
            echo "install libpcre3-dev"
            require_sudoer "sudo apt-get install -y --force-yes libpcre3-dev"
            sudo apt-get install -y --force-yes libpcre3-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            echo "install libpcre3-dev success"
        fi
        
        if [[ ! -f /usr/include/zlib.h ]]; then
            echo "install zlib1g-dev"
            require_sudoer "sudo apt-get install -y --force-yes zlib1g-dev"
            sudo apt-get install -y --force-yes zlib1g-dev; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            echo "install zlib1g-dev success"
        fi
105 106
    fi
    
107 108
    # for arm, install the cross build tool chain.
    if [ $SRS_ARM_UBUNTU12 = YES ]; then
winlin authored
109
        $SrsArmCC --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
110 111 112 113 114 115 116
            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
    
winlin authored
117 118
    # for mips, user must installed the tool chain.
    if [ $SRS_MIPS_UBUNTU12 = YES ]; then
winlin authored
119
        $SrsArmCC --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
winlin authored
120 121 122 123 124
            echo "user must install the tool chain: $SrsArmCC"
            return 2
        fi
    fi
    
125
    echo "Ubuntu install tools success"
126
    return 0
127
}
128
# donot prepare tools, for srs-librtmp depends only gcc and g++.
129
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
130 131
    Ubuntu_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "Ubuntu prepare failed, ret=$ret"; exit $ret; fi
fi
132
#####################################################################################
133
# for Centos, auto install tools by yum
134
#####################################################################################
135
OS_IS_CENTOS=NO
136 137 138
function Centos_prepare()
{
    if [[ ! -f /etc/redhat-release ]]; then
139
        return 0;
140 141
    fi
142
    OS_IS_CENTOS=YES
143 144 145 146 147
    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"
148
        sudo yum install -y gcc; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
149 150 151 152 153 154
        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++"
155
        sudo yum install -y gcc-c++; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
156 157 158 159 160 161
        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"
162
        sudo yum install -y make; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
163 164 165
        echo "install make success"
    fi
    
winlin authored
166 167 168 169 170 171 172
    patch --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
        echo "install patch"
        require_sudoer "sudo yum install -y patch"
        sudo yum install -y patch; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
        echo "install patch success"
    fi
    
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 201 202 203 204 205 206 207
    if [ $SRS_FFMPEG_TOOL = YES ]; then
        automake --help >/dev/null 2>&1; ret=$?; if [[ 0 -ne $ret ]]; then
            echo "install automake"
            require_sudoer "sudo yum install -y automake"
            sudo yum install -y automake; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            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"
            sudo yum install -y autoconf; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            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"
            sudo yum install -y libtool; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            echo "install libtool success"
        fi
        
        if [[ ! -f /usr/include/pcre.h ]]; then
            echo "install pcre-devel"
            require_sudoer "sudo yum install -y pcre-devel"
            sudo yum install -y pcre-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            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"
            sudo yum install -y zlib-devel; ret=$?; if [[ 0 -ne $ret ]]; then return $ret; fi
            echo "install zlib-devel success"
        fi
208 209
    fi
    
210
    # for arm, install the cross build tool chain.
winlin authored
211 212
    if [ $SRS_EMBEDED_CPU = YES ]; then
        echo "embeded(arm/mips) is invalid for CentOS"
213 214 215
        return 1
    fi
    
216
    echo "Centos install tools success"
217
    return 0
218
}
219
# donot prepare tools, for srs-librtmp depends only gcc and g++.
220
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
221 222
    Centos_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "CentOS prepare failed, ret=$ret"; exit $ret; fi
fi
223 224 225 226

#####################################################################################
# st-1.9
#####################################################################################
227
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
228 229
    # check the arm flag file, if flag changed, need to rebuild the st.
    _ST_MAKE=linux-debug
winlin authored
230 231
    # memory leak for linux-optimized
    # @see: https://github.com/winlinvip/simple-rtmp-server/issues/197
232 233 234 235 236 237 238 239 240 241 242 243
    if [ $SRS_EMBEDED_CPU = YES ]; then
        # ok, arm specified, if the flag filed does not exists, need to rebuild.
        if [[ -f ${SRS_OBJS}/_flag.st.arm.tmp && -f ${SRS_OBJS}/st/libst.a ]]; then
            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/v1_CN_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 && 
                patch -p0 < ../../3rdparty/patches/1.st.arm.patch &&
244 245
                make CC=${SrsArmCC} AR=${SrsArmAR} LD=${SrsArmLD} RANDLIB=${SrsArmRANDLIB} \
                    EXTRA_CFLAGS="-DMD_HAVE_EPOLL" ${_ST_MAKE} &&
246 247 248 249
                cd .. && rm -rf st && ln -sf st-1.9/obj st &&
                cd .. && touch ${SRS_OBJS}/_flag.st.arm.tmp
            )
        fi
250
    else
251 252 253 254 255 256 257
        if [[ ! -f ${SRS_OBJS}/_flag.st.arm.tmp && -f ${SRS_OBJS}/st/libst.a ]]; then
            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 && 
258
                make ${_ST_MAKE} EXTRA_CFLAGS="-DMD_HAVE_EPOLL" &&
259 260 261 262
                cd .. && rm -rf st && ln -sf st-1.9/obj st &&
                cd .. && rm -f ${SRS_OBJS}/_flag.st.arm.tmp
            )
        fi
263
    fi
264 265 266
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build st-1.9 failed, ret=$ret"; exit $ret; fi
    if [ ! -f ${SRS_OBJS}/st/libst.a ]; then echo "build st-1.9 static lib failed."; exit -1; fi
267 268 269 270 271
fi

#####################################################################################
# http-parser-2.1
#####################################################################################
272
# check the arm flag file, if flag changed, need to rebuild the st.
winlin authored
273
if [ $SRS_HTTP_PARSER = YES ]; then
274
    # ok, arm specified, if the flag filed does not exists, need to rebuild.
275
    if [ $SRS_EMBEDED_CPU = YES ]; then
276 277 278 279 280 281 282 283 284 285 286 287 288 289
        if [[ -f ${SRS_OBJS}/_flag.st.hp.tmp && -f ${SRS_OBJS}/hp/http_parser.h && -f ${SRS_OBJS}/hp/libhttp_parser.a ]]; then
            echo "http-parser-2.1 for arm is ok.";
        else
            echo "build http-parser-2.1 for arm";
            (
                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 &&
                make CC=${SrsArmCC} AR=${SrsArmAR} package &&
                cd .. && rm -rf hp && ln -sf http-parser-2.1 hp &&
                cd .. && touch ${SRS_OBJS}/_flag.st.hp.tmp
            )
        fi
290
    else
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
        # arm not specified, if exists flag, need to rebuild for no-arm platform.
        if [[ ! -f ${SRS_OBJS}/_flag.st.hp.tmp && -f ${SRS_OBJS}/hp/http_parser.h && -f ${SRS_OBJS}/hp/libhttp_parser.a ]]; then
            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 &&
                make package &&
                cd .. && rm -rf hp && ln -sf http-parser-2.1 hp &&
                cd .. && rm -f ${SRS_OBJS}/_flag.st.hp.tmp
            )
        fi
306
    fi
307
308 309
    # check status
    ret=$?; if [[ $ret -ne 0 ]]; then echo "build http-parser-2.1 failed, ret=$ret"; exit $ret; fi
310 311
    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
312 313
fi
winlin authored
314
if [ $SRS_HTTP_PARSER = YES ]; then
315
    echo "#define SRS_AUTO_HTTP_PARSER" >> $SRS_AUTO_HEADERS_H
winlin authored
316
else
317
    echo "#undef SRS_AUTO_HTTP_PARSER" >> $SRS_AUTO_HEADERS_H
winlin authored
318 319 320
fi

if [ $SRS_HTTP_SERVER = YES ]; then
321
    echo "#define SRS_AUTO_HTTP_SERVER" >> $SRS_AUTO_HEADERS_H
winlin authored
322
else
323
    echo "#undef SRS_AUTO_HTTP_SERVER" >> $SRS_AUTO_HEADERS_H
winlin authored
324 325
fi
winlin authored
326
if [ $SRS_HTTP_API = YES ]; then
327
    echo "#define SRS_AUTO_HTTP_API" >> $SRS_AUTO_HEADERS_H
winlin authored
328
else
329
    echo "#undef SRS_AUTO_HTTP_API" >> $SRS_AUTO_HEADERS_H
winlin authored
330 331
fi
332 333 334
#####################################################################################
# nginx for HLS, nginx-1.5.0
#####################################################################################
335 336
function write_nginx_html5()
{
winlin authored
337
    cat<<END > ${html_file}
338 339 340 341 342 343 344
<video width="640" height="360"
        autoplay controls autobuffer 
        src="${hls_stream}"
        type="application/vnd.apple.mpegurl">
</video>
END
}
345
# create the nginx dir, for http-server if not build nginx
346
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
347 348
    mkdir -p ${SRS_OBJS}/nginx
fi
349
# make nginx
winlin authored
350
__SRS_BUILD_NGINX=NO; if [ $SRS_EMBEDED_CPU = NO ]; then if [ $SRS_NGINX = YES ]; then __SRS_BUILD_NGINX=YES; fi fi
winlin authored
351 352 353 354 355 356 357 358 359
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 &&
360
            cd .. && rm -rf nginx && ln -sf nginx-1.5.7/_release nginx
winlin authored
361
        )
362
    fi
winlin authored
363 364 365 366 367 368 369 370 371
    # 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
372 373
fi
374
# the demo dir.
375
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
376 377 378
    # create forward dir
    mkdir -p ${SRS_OBJS}/nginx/html/live &&
    mkdir -p ${SRS_OBJS}/nginx/html/forward/live
379
380 381 382 383 384 385 386 387
    # generate default html pages for android.
    html_file=${SRS_OBJS}/nginx/html/live/demo.html && hls_stream=demo.m3u8 && write_nginx_html5
    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
388
389 390 391 392 393
    # 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
394
395 396 397
    # for favicon.ico
    rm -rf ${SRS_OBJS}/nginx/html/favicon.ico &&
    ln -sf `pwd`/research/api-server/static-dir/favicon.ico ${SRS_OBJS}/nginx/html/favicon.ico
398
399 400 401
    # nginx.html to detect whether nginx is alive
    echo "nginx is ok" > ${SRS_OBJS}/nginx/html/nginx.html
fi
402
403
if [ $SRS_NGINX = YES ]; then
404
    echo "#define SRS_AUTO_NGINX" >> $SRS_AUTO_HEADERS_H
405
else
406 407 408 409 410 411 412
    echo "#undef SRS_AUTO_NGINX" >> $SRS_AUTO_HEADERS_H
fi

if [ $SRS_DVR = YES ]; then
    echo "#define SRS_AUTO_DVR" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_AUTO_DVR" >> $SRS_AUTO_HEADERS_H
413 414
fi
415
if [ $SRS_HLS = YES ]; then
416
    echo "#define SRS_AUTO_HLS" >> $SRS_AUTO_HEADERS_H
417
else
418
    echo "#undef SRS_AUTO_HLS" >> $SRS_AUTO_HEADERS_H
419 420 421
fi

#####################################################################################
422 423
# cherrypy for http hooks callback, CherryPy-3.2.4
#####################################################################################
424
if [ $SRS_HTTP_CALLBACK = YES ]; then
425 426 427
    if [[ -f ${SRS_OBJS}/CherryPy-3.2.4/setup.py ]]; then
        echo "CherryPy-3.2.4 is ok.";
    else
428
        require_sudoer "configure --with-http-callback"
429 430 431 432 433 434 435 436 437
        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
438
    if [ ! -f ${SRS_OBJS}/CherryPy-3.2.4/setup.py ]; then echo "build CherryPy-3.2.4 failed."; exit -1; fi
439 440
fi
441
if [ $SRS_HTTP_CALLBACK = YES ]; then
442
    echo "#define SRS_AUTO_HTTP_CALLBACK" >> $SRS_AUTO_HEADERS_H
443
else
444
    echo "#undef SRS_AUTO_HTTP_CALLBACK" >> $SRS_AUTO_HEADERS_H
445 446
fi
447 448 449 450 451 452 453 454 455 456 457 458 459 460
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
    echo "link players to cherrypy static-dir"
    rm -rf research/api-server/static-dir/players &&
    ln -sf `pwd`/research/players research/api-server/static-dir/players &&
    rm -f research/api-server/static-dir/crossdomain.xml &&
    ln -sf `pwd`/research/players/crossdomain.xml research/api-server/static-dir/crossdomain.xml &&
    rm -rf research/api-server/static-dir/live && 
    mkdir -p `pwd`/${SRS_OBJS}/nginx/html/live &&
    ln -sf `pwd`/${SRS_OBJS}/nginx/html/live research/api-server/static-dir/live &&
    rm -rf research/api-server/static-dir/forward && 
    mkdir -p `pwd`/${SRS_OBJS}/nginx/html/forward &&
    ln -sf `pwd`/${SRS_OBJS}/nginx/html/forward research/api-server/static-dir/forward
    ret=$?; if [[ $ret -ne 0 ]]; then echo "link players to cherrypy static-dir failed, ret=$ret"; exit $ret; fi
fi
461
462 463 464 465
#####################################################################################
# generate demo index.html
#####################################################################################
# if nginx enalbed, generate nginx index file.
winlin authored
466
if [ $__SRS_BUILD_NGINX = YES ]; then
467 468 469 470 471 472 473 474 475 476 477 478
    rm -f ${SRS_OBJS}/nginx/html/index.html &&
    ln -sf `pwd`/research/players/nginx_index.html ${SRS_OBJS}/nginx/html/index.html
fi
# if http-server enalbed, use srs embeded http-server
if [ $SRS_HTTP_SERVER = YES ]; then
    rm -f ${SRS_OBJS}/nginx/html/index.html &&
    ln -sf `pwd`/research/players/srs-http-server_index.html ${SRS_OBJS}/nginx/html/index.html
fi
# if api-server enabled, generate for api server.
if [ $SRS_HTTP_CALLBACK = YES ]; then
    rm -f ${SRS_OBJS}/nginx/html/index.html &&
    ln -sf `pwd`/research/players/api-server_index.html ${SRS_OBJS}/nginx/html/index.html
winlin authored
479 480
fi
481
#####################################################################################
482 483
# openssl, for rtmp complex handshake
#####################################################################################
484
# extra configure options
winlin authored
485
CONFIGURE_TOOL="./config"
486
EXTRA_CONFIGURE=""
winlin authored
487 488
if [ $SRS_EMBEDED_CPU = YES ]; then
    CONFIGURE_TOOL="./Configure"
489
fi
490 491 492
# @see http://www.openssl.org/news/secadv_20140407.txt
# Affected users should upgrade to OpenSSL 1.0.1g. Users unable to immediately
# upgrade can alternatively recompile OpenSSL with -DOPENSSL_NO_HEARTBEATS.
493
if [ $SRS_SSL = YES ]; then
494 495
    if [ $SRS_USE_SYS_SSL = YES ]; then
        echo "warning: donot compile ssl, use system ssl"
496
    else
497
        # check the arm flag file, if flag changed, need to rebuild the st.
winlin authored
498
        if [ $SRS_EMBEDED_CPU = YES ]; then
499 500 501 502 503 504 505 506
            # 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 && 
winlin authored
507
                    $CONFIGURE_TOOL --prefix=`pwd`/_release -no-shared no-asm linux-armv4 -DOPENSSL_NO_HEARTBEATS ${EXTRA_CONFIGURE} && 
508 509
                    make CC=${SrsArmCC} GCC=${SrsArmGCC} AR="${SrsArmAR} r" \
                        LD=${SrsArmLD} LINK=${SrsArmGCC} RANDLIB=${SrsArmRANDLIB} && 
510
                    make install_sw &&
511 512 513 514
                    cd .. && rm -rf openssl && ln -sf openssl-1.0.1f/_release openssl &&
                    cd .. && touch ${SRS_OBJS}/_flag.ssl.arm.tmp
                )
            fi
515
        else
516 517 518 519 520 521 522 523
            # 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 && 
winlin authored
524
                    $CONFIGURE_TOOL --prefix=`pwd`/_release -no-shared -DOPENSSL_NO_HEARTBEATS ${EXTRA_CONFIGURE} && 
525
                    make && make install_sw &&
526 527 528 529
                    cd .. && rm -rf openssl && ln -sf openssl-1.0.1f/_release openssl &&
                    cd .. && rm -f ${SRS_OBJS}/_flag.ssl.arm.tmp
                )
            fi
530
        fi
531 532 533
        # 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
534 535 536 537
    fi
fi

if [ $SRS_SSL = YES ]; then
538
    echo "#define SRS_AUTO_SSL" >> $SRS_AUTO_HEADERS_H
539
else
540
    echo "#undef SRS_AUTO_SSL" >> $SRS_AUTO_HEADERS_H
541
fi
winlin authored
542 543 544 545

#####################################################################################
# live transcoding, ffmpeg-2.1, x264-core138, lame-3.99.5, libaacplus-2.0.2.
#####################################################################################
546
if [ $SRS_FFMPEG_TOOL = YES ]; then
winlin authored
547 548 549 550 551
    if [[ -f ${SRS_OBJS}/ffmpeg/bin/ffmpeg ]]; then
        echo "ffmpeg-2.1 is ok.";
    else
        echo "build ffmpeg-2.1"; 
        (
winlin authored
552 553 554
            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 &&
555
            cd ${pwd_dir} && rm -rf ffmpeg && ln -sf ffmpeg.src/_release ffmpeg
winlin authored
556 557 558 559 560 561 562
        )
    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
563 564 565 566 567 568 569
# whether compile ffmpeg tool
if [ $SRS_FFMPEG_TOOL = YES ]; then
    echo "#define SRS_AUTO_FFMPEG_TOOL" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_AUTO_FFMPEG_TOOL" >> $SRS_AUTO_HEADERS_H
fi
winlin authored
570 571
# whatever the FFMPEG tools, if transcode and ingest specified,
# srs always compile the FFMPEG tool stub which used to start the FFMPEG process.
572
if [ $SRS_FFMPEG_STUB = YES ]; then
573
    echo "#define SRS_AUTO_FFMPEG_STUB" >> $SRS_AUTO_HEADERS_H
winlin authored
574
else
575
    echo "#undef SRS_AUTO_FFMPEG_STUB" >> $SRS_AUTO_HEADERS_H
winlin authored
576
fi
577
578
if [ $SRS_TRANSCODE = YES ]; then
579
    echo "#define SRS_AUTO_TRANSCODE" >> $SRS_AUTO_HEADERS_H
580
else
581
    echo "#undef SRS_AUTO_TRANSCODE" >> $SRS_AUTO_HEADERS_H
582 583
fi
winlin authored
584
if [ $SRS_INGEST = YES ]; then
585
    echo "#define SRS_AUTO_INGEST" >> $SRS_AUTO_HEADERS_H
winlin authored
586
else
587
    echo "#undef SRS_AUTO_INGEST" >> $SRS_AUTO_HEADERS_H
winlin authored
588 589
fi
590 591 592 593 594 595 596
# for statistic.
if [ $SRS_STAT = YES ]; then
    echo "#define SRS_AUTO_STAT" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_AUTO_STAT" >> $SRS_AUTO_HEADERS_H
fi
597
#####################################################################################
598
# build research code, librtmp
599
#####################################################################################
600
if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
601 602
    if [ $SRS_RESEARCH = YES ]; then
        mkdir -p ${SRS_OBJS}/research
603
604 605
        (cd ${SRS_WORKDIR}/research/hls && make ${SRS_JOBS} && mv ts_info ../../${SRS_OBJS_DIR}/research)
        ret=$?; if [[ $ret -ne 0 ]]; then echo "build research/hls failed, ret=$ret"; exit $ret; fi
606
607 608 609
        (cd research/ffempty && make ${SRS_JOBS} && mv ffempty ../../${SRS_OBJS_DIR}/research)
        ret=$?; if [[ $ret -ne 0 ]]; then echo "build research/ffempty failed, ret=$ret"; exit $ret; fi
    fi
610 611 612 613
fi

if [ $SRS_LIBRTMP = YES ]; then
    mkdir -p ${SRS_OBJS}/research
winlin authored
614 615
    
    # librtmp
616
    (cd ${SRS_WORKDIR}/research/librtmp && mkdir -p objs && ln -sf `pwd`/objs ../../${SRS_OBJS_DIR}/research/librtmp)
winlin authored
617
    ret=$?; if [[ $ret -ne 0 ]]; then echo "link research/librtmp failed, ret=$ret"; exit $ret; fi
618
fi
winlin authored
619 620 621 622 623

#####################################################################################
# build utest code
#####################################################################################
if [ $SRS_UTEST = YES ]; then
624 625 626 627 628 629 630
    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 &&
631
            rm -rf gtest && ln -sf gtest-1.6.0 gtest
632 633 634 635 636
        )
    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
637
fi
winlin authored
638 639 640 641 642 643 644 645 646 647 648 649 650

#####################################################################################
# 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 &&
651 652
            cd .. && rm -rf gperf && ln -sf gperftools-2.1/_release gperf &&
            rm -rf pprof && ln -sf gperf/bin/pprof pprof
winlin authored
653 654 655 656 657 658
        )
    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
659 660

if [ $SRS_GPERF = YES ]; then
661
    echo "#define SRS_AUTO_GPERF" >> $SRS_AUTO_HEADERS_H
662
else
663
    echo "#undef SRS_AUTO_GPERF" >> $SRS_AUTO_HEADERS_H
664 665
fi
if [ $SRS_GPERF_MC = YES ]; then
666
    echo "#define SRS_AUTO_GPERF_MC" >> $SRS_AUTO_HEADERS_H
667
else
668
    echo "#undef SRS_AUTO_GPERF_MC" >> $SRS_AUTO_HEADERS_H
669 670
fi
if [ $SRS_GPERF_MP = YES ]; then
671
    echo "#define SRS_AUTO_GPERF_MP" >> $SRS_AUTO_HEADERS_H
672
else
673
    echo "#undef SRS_AUTO_GPERF_MP" >> $SRS_AUTO_HEADERS_H
674 675
fi
if [ $SRS_GPERF_CP = YES ]; then
676
    echo "#define SRS_AUTO_GPERF_CP" >> $SRS_AUTO_HEADERS_H
677
else
678
    echo "#undef SRS_AUTO_GPERF_CP" >> $SRS_AUTO_HEADERS_H
679
fi
680 681

#####################################################################################
winlin authored
682
# for embeded.
683
#####################################################################################
winlin authored
684 685 686 687 688 689 690
if [ $SRS_EMBEDED_CPU = YES ]; then
    echo "#define SRS_AUTO_EMBEDED_CPU" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_AUTO_EMBEDED_CPU" >> $SRS_AUTO_HEADERS_H
fi

# arm
691
if [ $SRS_ARM_UBUNTU12 = YES ]; then
692
    echo "#define SRS_AUTO_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H
693
else
694
    echo "#undef SRS_AUTO_ARM_UBUNTU12" >> $SRS_AUTO_HEADERS_H
695
fi
696
winlin authored
697 698 699 700 701 702 703
# mips
if [ $SRS_MIPS_UBUNTU12 = YES ]; then
    echo "#define SRS_AUTO_MIPS_UBUNTU12" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_AUTO_MIPS_UBUNTU12" >> $SRS_AUTO_HEADERS_H
fi
704
echo "" >> $SRS_AUTO_HEADERS_H
winlin authored
705
706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722
# for log level compile settings
if [ $SRS_LOG_VERBOSE = YES ]; then
    echo "#define SRS_AUTO_VERBOSE" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_AUTO_VERBOSE" >> $SRS_AUTO_HEADERS_H
fi
if [ $SRS_LOG_INFO = YES ]; then
    echo "#define SRS_AUTO_INFO" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_AUTO_INFO" >> $SRS_AUTO_HEADERS_H
fi
if [ $SRS_LOG_TRACE = YES ]; then
    echo "#define SRS_AUTO_TRACE" >> $SRS_AUTO_HEADERS_H
else
    echo "#undef SRS_AUTO_TRACE" >> $SRS_AUTO_HEADERS_H
fi
723
# prefix
724
echo "" >> $SRS_AUTO_HEADERS_H
725
echo "#define SRS_AUTO_PREFIX \"${SRS_PREFIX}\"" >> $SRS_AUTO_HEADERS_H
726
727 728 729 730 731
echo "" >> $SRS_AUTO_HEADERS_H

#####################################################################################
# generated the contributors from AUTHORS.txt
#####################################################################################
732
SRS_CONSTRIBUTORS=`cat ../AUTHORS.txt|grep "*"|awk '{print $2}'`
733
echo "#define SRS_AUTO_CONSTRIBUTORS \"\\" >> $SRS_AUTO_HEADERS_H
734 735 736 737 738
for CONTRIBUTOR in $SRS_CONSTRIBUTORS; do
    echo "${CONTRIBUTOR} \\" >> $SRS_AUTO_HEADERS_H
done
echo "\"" >> $SRS_AUTO_HEADERS_H
739 740
# new empty line to auto headers file.
echo "" >> $SRS_AUTO_HEADERS_H
741 742 743 744

#####################################################################################
# generated the test script
#####################################################################################
745
rm -rf ${SRS_OBJS}/srs.test && ln -sf `pwd`/scripts/srs.test objs/srs.test